{"question_id": 1638, "task_id": "count-substrings-that-differ-by-one-character", "difficulty": "Medium", "problem_description": "Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.\n\nFor example, the underlined substrings in \"computer\" and \"computation\" only differ by the 'e'/'a', so this is a valid way.\n\nReturn the number of substrings that satisfy the condition above.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aba\", t = \"baba\"\nOutput: 6\nExplanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\nThe underlined portions are the substrings that are chosen from s and t.\n\nExample 2:\n\nInput: s = \"ab\", t = \"bb\"\nOutput: 3\nExplanation: The following are the pairs of substrings from s and t that differ by 1 character:\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\nThe underlined portions are the substrings that are chosen from s and t.\n\nConstraints:\n\n- 1 <= s.length, t.length <= 100\n- s and t consist of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",t = \"abcd\") == 9\n assert candidate(s = \"abcde\",t = \"bcdef\") == 21\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 16\n assert candidate(s = \"xyz\",t = \"xya\") == 9\n assert candidate(s = \"python\",t = \"typhon\") == 40\n assert candidate(s = \"xyz\",t = \"xyy\") == 9\n assert candidate(s = \"zzz\",t = \"zzz\") == 0\n assert candidate(s = \"same\",t = \"same\") == 12\n assert candidate(s = \"abcd\",t = \"abcf\") == 16\n assert candidate(s = \"abcde\",t = \"fghij\") == 25\n assert candidate(s = \"abcabc\",t = \"abcabc\") == 24\n assert candidate(s = \"aaaa\",t = \"aaab\") == 10\n assert candidate(s = \"mississippi\",t = \"misissippi\") == 126\n assert candidate(s = \"xyz\",t = \"xyw\") == 9\n assert candidate(s = \"a\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"dcba\") == 16\n assert candidate(s = \"abc\",t = \"def\") == 9\n assert candidate(s = \"a\",t = \"b\") == 1\n assert candidate(s = \"test\",t = \"tast\") == 16\n assert candidate(s = \"aba\",t = \"baba\") == 6\n assert candidate(s = \"aaa\",t = \"aaa\") == 0\n assert candidate(s = \"test\",t = \"text\") == 16\n assert candidate(s = \"abcd\",t = \"abce\") == 16\n assert candidate(s = \"hello\",t = \"hallo\") == 30\n assert candidate(s = \"code\",t = \"cide\") == 18\n assert candidate(s = \"ab\",t = \"bb\") == 3\n assert candidate(s = \"same\",t = \"sane\") == 18\n assert candidate(s = \"abcdefg\",t = \"abcdxyz\") == 49\n assert candidate(s = \"aaaaaab\",t = \"aaaaaac\") == 49\n assert candidate(s = \"qwertyuiop\",t = \"qwertuiopq\") == 99\n assert candidate(s = \"banana\",t = \"banane\") == 38\n assert candidate(s = \"asdfghjkl\",t = \"asdfghjkl\") == 72\n assert candidate(s = \"substring\",t = \"substrung\") == 94\n assert candidate(s = \"aaaaabbbbb\",t = \"bbbbbbaaaa\") == 91\n assert candidate(s = \"banana\",t = \"anana\") == 21\n assert candidate(s = \"algorithm\",t = \"algorihm\") == 72\n assert candidate(s = \"racecar\",t = \"racecdr\") == 55\n assert candidate(s = \"abacaba\",t = \"abacabb\") == 50\n assert candidate(s = \"aabbcc\",t = \"aabbcz\") == 41\n assert candidate(s = \"abcdefg\",t = \"gfedcba\") == 52\n assert candidate(s = \"aabbccddeeff\",t = \"aaabccddeeff\") == 177\n assert candidate(s = \"hellohello\",t = \"hellohelll\") == 101\n assert candidate(s = \"aabbccdd\",t = \"bbccddaa\") == 64\n assert candidate(s = \"racecar\",t = \"racecars\") == 52\n assert candidate(s = \"xyzxyzxyz\",t = \"zyxzyxzyx\") == 96\n assert candidate(s = \"programming\",t = \"programminh\") == 125\n assert candidate(s = \"banana\",t = \"bandana\") == 44\n assert candidate(s = \"abcdefg\",t = \"abcdefgh\") == 49\n assert candidate(s = \"qwert\",t = \"qwqrt\") == 29\n assert candidate(s = \"abcdefg\",t = \"abcdeff\") == 49\n assert candidate(s = \"abcdefghij\",t = \"abcdefghjk\") == 100\n assert candidate(s = \"abcabcabc\",t = \"abcabcabd\") == 72\n assert candidate(s = \"aaaaabbbbb\",t = \"aaaabbbbbb\") == 123\n assert candidate(s = \"abcdefghij\",t = \"abcdefghib\") == 100\n assert candidate(s = \"abcdefghi\",t = \"abcfghi\") == 63\n assert candidate(s = \"hellohello\",t = \"hallohallo\") == 134\n assert candidate(s = \"abcdefgh\",t = \"abcdefgha\") == 63\n assert candidate(s = \"qwert\",t = \"qwera\") == 25\n assert candidate(s = \"programming\",t = \"progrcmming\") == 150\n assert candidate(s = \"banana\",t = \"banama\") == 42\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",t = \"pneumonoultramicroscopicsilicovolcanoconiosus\") == 2250\n assert candidate(s = \"abcdabcd\",t = \"abceabcd\") == 72\n assert candidate(s = \"abcdefghij\",t = \"abcdefghix\") == 100\n assert candidate(s = \"example\",t = \"exampel\") == 48\n assert candidate(s = \"abcdefgh\",t = \"abxdefgh\") == 74\n assert candidate(s = \"abcabcabc\",t = \"defdefdef\") == 81\n assert candidate(s = \"programming\",t = \"prognamming\") == 149\n assert candidate(s = \"abcdefghij\",t = \"jihgfedcba\") == 106\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",t = \"pneumonoultramicroscopicsilicovolcanoconiosi\") == 2118\n assert candidate(s = \"abcdef\",t = \"fedcba\") == 38\n assert candidate(s = \"abcdabcd\",t = \"dcbaabcd\") == 66\n assert candidate(s = \"abcdefgh\",t = \"fedcbagh\") == 68\n assert candidate(s = \"abcdefgh\",t = \"abcdexyz\") == 64\n assert candidate(s = \"abcdefg\",t = \"fghijkl\") == 47\n assert candidate(s = \"abcdefg\",t = \"abcdefh\") == 49\n assert candidate(s = \"abcdefghij\",t = \"abcdefghia\") == 99\n assert candidate(s = \"abcdef\",t = \"abcxef\") == 42\n assert candidate(s = \"abcdeabcde\",t = \"abcdeabcda\") == 94\n assert candidate(s = \"xyzzyx\",t = \"zyxzyx\") == 38\n assert candidate(s = \"zxcvbnm\",t = \"zxsvbnm\") == 57\n assert candidate(s = \"abcdabcd\",t = \"abxdabcd\") == 72\n assert candidate(s = \"mississippi\",t = \"misssissippi\") == 155\n assert candidate(s = \"longerstring\",t = \"longerstirng\") == 148\n assert candidate(s = \"pqrstuvw\",t = \"pqrsvwxy\") == 64\n assert candidate(s = \"zzzzzzzzzz\",t = \"zzzzzzzzza\") == 55\n assert candidate(s = \"abcdefg\",t = \"abcdefi\") == 49\n assert candidate(s = \"substring\",t = \"substrang\") == 93\n assert candidate(s = \"abacaba\",t = \"abaxaba\") == 56\n assert candidate(s = \"abcabcabc\",t = \"abcabcab\") == 48\n assert candidate(s = \"abcdefgh\",t = \"abcefgih\") == 67\n assert candidate(s = \"abcdefgabcdefg\",t = \"abcdefgabcdeff\") == 189\n assert candidate(s = \"python\",t = \"pythpn\") == 40\n assert candidate(s = \"abcdabcd\",t = \"abcddcba\") == 66\n assert candidate(s = \"abcdefg\",t = \"abcdefj\") == 49\n assert candidate(s = \"testtest\",t = \"tasttest\") == 68\n assert candidate(s = \"algorithm\",t = \"algorithr\") == 81\n assert candidate(s = \"aaaaab\",t = \"aaaabb\") == 35\n assert candidate(s = \"programming\",t = \"programming\") == 114\n assert candidate(s = \"banana\",t = \"bananas\") == 40\n assert candidate(s = \"testcase\",t = \"tastcase\") == 73\n assert candidate(s = \"aabbcc\",t = \"aabbbcc\") == 54\n assert candidate(s = \"qwertyuiop\",t = \"qwertuiop\") == 90\n assert candidate(s = \"programming\",t = \"programmimg\") == 136\n assert candidate(s = \"aabbccddeeff\",t = \"aabbccddeegg\") == 160\n assert candidate(s = \"abcdefg\",t = \"abcdefa\") == 48\n assert candidate(s = \"abcabcabc\",t = \"abcababc\") == 66\n assert candidate(s = \"abcabcabc\",t = \"abcabcbca\") == 71\n assert candidate(s = \"abcdefghij\",t = \"abcdefghja\") == 99\n assert candidate(s = \"testtest\",t = \"settsett\") == 83\n assert candidate(s = \"abcdefgh\",t = \"efghabcd\") == 56\n assert candidate(s = \"abacaba\",t = \"abacaba\") == 40\n assert candidate(s = \"abcdxyz\",t = \"xyzabcd\") == 42\n assert candidate(s = \"zzzzzz\",t = \"zzzzzz\") == 0\n assert candidate(s = \"pqrstuv\",t = \"qrsuvwp\") == 48\n assert candidate(s = \"abcabcabc\",t = \"ababcabc\") == 63\n assert candidate(s = \"abcdefghijk\",t = \"abcdefghijx\") == 121\n assert candidate(s = \"algorithm\",t = \"algorihtm\") == 83\n assert candidate(s = \"abcdabcd\",t = \"abacabad\") == 74\n assert candidate(s = \"zzzzz\",t = \"zzzzz\") == 0\n assert candidate(s = \"xyzz\",t = \"xyyz\") == 18\n assert candidate(s = \"banana\",t = \"bananna\") == 44\n assert candidate(s = \"aaaaabbbb\",t = \"aaaabbbbb\") == 98\n assert candidate(s = \"pattern\",t = \"patterr\") == 51\n assert candidate(s = \"abacax\",t = \"abacay\") == 40\n assert candidate(s = \"mississippi\",t = \"mississippa\") == 141\n assert candidate(s = \"programming\",t = \"progranning\") == 125\n assert candidate(s = \"substrings\",t = \"substraings\") == 108\n assert candidate(s = \"abcdefgh\",t = \"abcdefga\") == 63\n assert candidate(s = \"mississippi\",t = \"mississipp\") == 119\n assert candidate(s = \"zzzzzzzzzz\",t = \"zzzzzzzzzz\") == 0\n assert candidate(s = \"abcdefghij\",t = \"abcegijhif\") == 104\n assert candidate(s = \"aaaaaaaaaa\",t = \"bbbbbbbbbb\") == 100\n assert candidate(s = \"programming\",t = \"programminq\") == 125\n assert candidate(s = \"xyzzyx\",t = \"zyxzyz\") == 39\n assert candidate(s = \"aabbcc\",t = \"bbaacc\") == 38\n assert candidate(s = \"abcabcabcabc\",t = \"abababababab\") == 166\n assert candidate(s = \"mnopqr\",t = \"mnopqs\") == 36\n assert candidate(s = \"abacabadabacaba\",t = \"abacabadabacaba\") == 272\n assert candidate(s = \"racecar\",t = \"racecer\") == 56\n assert candidate(s = \"abacaba\",t = \"babcaba\") == 47\n assert candidate(s = \"abcdefgh\",t = \"abcdefgi\") == 64\n assert candidate(s = \"abababa\",t = \"bababab\") == 25\n assert candidate(s = \"abcd\",t = \"abdc\") == 16\n assert candidate(s = \"qwerty\",t = \"qwertyuiop\") == 54\n assert candidate(s = \"interview\",t = \"interviww\") == 89\n assert candidate(s = \"mississippi\",t = \"mississipxy\") == 140\n assert candidate(s = \"qwertyuiop\",t = \"poiuytrewq\") == 106\n assert candidate(s = \"abcdefg\",t = \"abacdef\") == 49\n assert candidate(s = \"abcdefg\",t = \"abcxefg\") == 58\n assert candidate(s = \"aaaaabbbbb\",t = \"aaaabbbbba\") == 128\n assert candidate(s = \"aaaaab\",t = \"aaabaa\") == 39\n assert candidate(s = \"aaaaaaab\",t = \"aaaaaaax\") == 64\n assert candidate(s = \"abcdefgh\",t = \"hgfedcba\") == 68\n assert candidate(s = \"abababab\",t = \"babababa\") == 32\n assert candidate(s = \"abcdef\",t = \"abcdeg\") == 36\n", "comparison": "exact"}, "public_tests": ["\"aba\"\n\"baba\"", "\"ab\"\n\"bb\""], "hints": ["Take every substring of s, change a character, and see how many substrings of t match that substring.", "Use a Trie to store all substrings of t as a dictionary."], "metadata": {"canonical_parameter_names": ["s", "t"], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:02+00:00", "tests_total": 156, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countSubstrings($s, $t) {", "container": "Solution", "callable": "countSubstrings", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1639, "task_id": "number-of-ways-to-form-a-target-string-given-a-dictionary", "difficulty": "Hard", "problem_description": "You are given a list of strings of the same length words and a string target.\n\nYour task is to form target using the given words under the following rules:\n\n- target should be formed from left to right.\n- To form the i^th character (0-indexed) of target, you can choose the k^th character of the j^th string in words if target[i] = words[j][k].\n- Once you use the k^th character of the j^th string of words, you can no longer use the x^th character of any string in words where x <= k. In other words, all characters to the left of or at index k become unusuable for every string.\n- Repeat the process until you form the string target.\n\nNotice that you can use multiple characters from the same string in words provided the conditions above are met.\n\nReturn the number of ways to form target from words. Since the answer may be too large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: words = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\"\nOutput: 6\nExplanation: There are 6 ways to form target.\n\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"caca\")\n\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"caca\")\n\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"caca\")\n\nExample 2:\n\nInput: words = [\"abba\",\"baab\"], target = \"bab\"\nOutput: 4\nExplanation: There are 4 ways to form target.\n\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 2 (\"abba\")\n\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 3 (\"baab\")\n\"bab\" -> index 0 (\"baab\"), index 2 (\"baab\"), index 3 (\"baab\")\n\"bab\" -> index 1 (\"abba\"), index 2 (\"baab\"), index 3 (\"baab\")\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length <= 1000\n- All strings in words have the same length.\n- 1 <= target.length <= 1000\n- words[i] and target contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['a', 'b', 'c'],target = \"abc\") == 0\n assert candidate(words = ['abc', 'def'],target = \"ad\") == 0\n assert candidate(words = ['mississippi'],target = \"issi\") == 15\n assert candidate(words = ['aaa', 'aaa', 'aaa'],target = \"aaa\") == 27\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'],target = \"abc\") == 8\n assert candidate(words = ['abc', 'bcd', 'cde'],target = \"abc\") == 1\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi'],target = \"miss\") == 567\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi'],target = \"issi\") == 1215\n assert candidate(words = ['acca', 'bbbb', 'caca'],target = \"aba\") == 6\n assert candidate(words = ['leetcode', 'leetcode', 'leetcode'],target = \"leet\") == 81\n assert candidate(words = ['aaa', 'aaa', 'aaa'],target = \"a\") == 9\n assert candidate(words = ['zzz', 'zzz', 'zzz'],target = \"zzz\") == 27\n assert candidate(words = ['abc', 'bcd', 'cde'],target = \"aab\") == 0\n assert candidate(words = ['abc', 'bcd', 'cde'],target = \"abd\") == 1\n assert candidate(words = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa'],target = \"aaaa\") == 17010\n assert candidate(words = ['abc', 'def', 'ghi'],target = \"adg\") == 0\n assert candidate(words = ['abba', 'baab'],target = \"bab\") == 4\n assert candidate(words = ['mississippi'],target = \"sip\") == 12\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghijk\") == 0\n assert candidate(words = ['abcdef', 'bcadef', 'cdefgh'],target = \"abcd\") == 2\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"mnop\") == 1\n assert candidate(words = ['abcdefgh', 'ijklmnop', 'qrstuvwx', 'yzabcdef'],target = \"aceg\") == 1\n assert candidate(words = ['abcdefg', 'xyzabc', 'mnopqr', 'stuvwx'],target = \"abc\") == 4\n assert candidate(words = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd'],target = \"abcd\") == 15\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd'],target = \"abcd\") == 1\n assert candidate(words = ['xyzxyz', 'yzxyzy', 'zxyzxy', 'yzyxzy'],target = \"zyx\") == 26\n assert candidate(words = ['thisisanexample', 'thisisanexample', 'thisisanexample'],target = \"example\") == 2187\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi', 'mississippi'],target = \"miss\") == 1792\n assert candidate(words = ['hello', 'hello', 'hello', 'hello', 'hello'],target = \"hello\") == 3125\n assert candidate(words = ['xylophone', 'xylophone', 'xylophone'],target = \"xylo\") == 162\n assert candidate(words = ['hellohellohello', 'worldworldworld', 'hellohellohello'],target = \"helloworld\") == 2496\n assert candidate(words = ['ababababab', 'bababababa', 'ababababab'],target = \"ababab\") == 4339\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"aceg\") == 81\n assert candidate(words = ['lloremipsumdolorsitamet', 'lloremipsumdolorsitamet', 'lloremipsumdolorsitamet'],target = \"lorem\") == 1458\n assert candidate(words = ['abacabadabacaba', 'bacabadabacabab', 'acabadabacababa'],target = \"abacaba\") == 13252\n assert candidate(words = ['abcabc', 'bcabca', 'cababc'],target = \"abc\") == 39\n assert candidate(words = ['aabbccddeeff', 'bbaacceeddff', 'ccaabbeedddf', 'ddaabbccdeff'],target = \"abcde\") == 1496\n assert candidate(words = ['zzzz', 'zzzz', 'zzzz', 'zzzz', 'zzzz'],target = \"zz\") == 150\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"abcd\") == 5\n assert candidate(words = ['zzzzzz', 'yyyyyy', 'xxxxxx', 'wwwwww', 'vvvvvv'],target = \"zyxwv\") == 6\n assert candidate(words = ['abcabcabcabc', 'defdefdefdef', 'ghighighighi', 'jkljkljkljkl'],target = \"adgj\") == 1\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 999999937\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst'],target = \"afkp\") == 0\n assert candidate(words = ['zzzz', 'zzzz', 'zzzz', 'zzzz'],target = \"zzz\") == 256\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"ijkl\") == 1\n assert candidate(words = ['xyzxyzxyzxyz', 'yzxyzyzyzx', 'zxyzxyzxyz'],target = \"xyzxyz\") == 770\n assert candidate(words = ['aabbccddeeff', 'bbccddeeffgg', 'ccddeeffgghh'],target = \"abcdeffg\") == 414\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"acfi\") == 256\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"mnopqr\") == 1\n assert candidate(words = ['hello', 'hello', 'hello', 'hello', 'hello'],target = \"hello\") == 3125\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccaabb'],target = \"abc\") == 40\n assert candidate(words = ['banana', 'banana', 'banana', 'banana'],target = \"ban\") == 192\n assert candidate(words = ['abcdefghi', 'jklmnopqr', 'stuvwxyz'],target = \"adgt\") == 0\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij'],target = \"abcde\") == 1\n assert candidate(words = ['abcabcabc', 'abcabcabc', 'abcabcabc'],target = \"abc\") == 270\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi'],target = \"mississippi\") == 177147\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi', 'mississippi', 'mississippi', 'mississippi'],target = \"issipi\") == 746496\n assert candidate(words = ['zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz'],target = \"zzzz\") == 131250\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhii', 'jjkkll', 'mmnnoo'],target = \"abcd\") == 0\n assert candidate(words = ['aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa', 'aaaaaaaaaa'],target = \"aaaa\") == 53760\n assert candidate(words = ['zzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzz'],target = \"zzzz\") == 392445\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"afg\") == 0\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"acegi\") == 3125\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij'],target = \"efghij\") == 1\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'],target = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(words = ['abacaba', 'bacabab', 'cacabac', 'dacabad'],target = \"abac\") == 81\n assert candidate(words = ['zzzzzzzzzz', 'yyyyyyyyyy', 'xxxxxxxxxx', 'wwwwwwwwww', 'vvvvvvvvvv'],target = \"zyxwv\") == 252\n assert candidate(words = ['aaaaaaaaaa', 'bbbbbbbbbb', 'cccccccccc'],target = \"abc\") == 120\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij'],target = \"defg\") == 15\n assert candidate(words = ['target', 'target', 'target', 'target', 'target'],target = \"target\") == 15625\n assert candidate(words = ['abcdefghij', 'jihgfedcba', 'abcdefghij', 'jihgfedcba'],target = \"abcdefghij\") == 1024\n assert candidate(words = ['abcdefghij', 'klmnopqr', 'stuvwxyz', 'abcdefghij', 'klmnopqr'],target = \"mnop\") == 16\n assert candidate(words = ['banana', 'banana', 'banana', 'banana', 'banana'],target = \"ban\") == 375\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 59049\n assert candidate(words = ['aaaa', 'abbb', 'accc', 'addd'],target = \"abcd\") == 4\n assert candidate(words = ['aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz', 'aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz'],target = \"abcdefghijklmnopqrstu\") == 46480318\n assert candidate(words = ['abcdefg', 'abcdefg', 'abcdefg', 'abcdefg', 'abcdefg'],target = \"abcdefg\") == 78125\n assert candidate(words = ['abcdefghijklmnop', 'qrstuvwxyzab', 'cdefghijklmnop', 'qrstuvwxyzab'],target = \"abcde\") == 1\n assert candidate(words = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd'],target = \"abcd\") == 15\n assert candidate(words = ['abcdefghijk', 'abcdefghij', 'abcdefghi', 'abcdefgh', 'abcdefg', 'abcdef', 'abcde', 'abcd', 'abc'],target = \"abcdefg\") == 1224720\n assert candidate(words = ['aabbccdd', 'aabbccdd', 'aabbccdd', 'aabbccdd'],target = \"abcd\") == 4096\n assert candidate(words = ['abcd', 'abcf', 'acdf', 'adef'],target = \"ace\") == 4\n assert candidate(words = ['abcdefghij', 'klmnopqr', 'stuvwxyz', 'abcdefghij', 'klmnopqr'],target = \"mnopqrst\") == 0\n assert candidate(words = ['aaaaaaaabaaaaaa', 'baaaaaaaabaaaaa', 'caaaaaaabaaaaaa'],target = \"aaaaaabaaaaaa\") == 9920232\n assert candidate(words = ['abacabadabacaba', 'bcbdbecbdbecb', 'dcdcdcddcdcdc'],target = \"abc\") == 110\n assert candidate(words = ['abababababababab', 'bababababababa', 'abababababababab'],target = \"abab\") == 9394\n assert candidate(words = ['abcdef', 'fedcba', 'abcdef'],target = \"abcdef\") == 64\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"stuvwx\") == 1\n assert candidate(words = ['qwerty', 'qwerty', 'qwerty', 'qwerty', 'qwerty'],target = \"qwe\") == 125\n assert candidate(words = ['abcabcabc', 'defdefdef', 'ghighighi'],target = \"adg\") == 1\n assert candidate(words = ['abcdefghijk', 'abcdefghij', 'abcdefghi', 'abcdefgh', 'abcdefg', 'abcdef', 'abcde', 'abcd', 'abc'],target = \"abc\") == 729\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghijabcdefghij\") == 0\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhii', 'jjkkgg'],target = \"abgi\") == 4\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'],target = \"zyxwvutsrqponmlkjihgfedcba\") == 67108864\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyz'],target = \"abcdefghijklmnopqrstuvwxyz\") == 67108864\n assert candidate(words = ['aaaa', 'abab', 'acac', 'adad', 'aeae'],target = \"aa\") == 46\n assert candidate(words = ['programming', 'is', 'fun'],target = \"pin\") == 1\n assert candidate(words = ['sequence', 'sequence', 'sequence', 'sequence', 'sequence'],target = \"seq\") == 125\n assert candidate(words = ['abcd', 'abcd', 'abcd', 'abcd', 'abcd'],target = \"abcd\") == 625\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi'],target = \"ssss\") == 81\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"abc\") == 4\n assert candidate(words = ['abcdefghijkl', 'mnopqrstuv', 'wxyzabcdef', 'ghijklmnop'],target = \"mnop\") == 5\n assert candidate(words = ['abcdefghijabcdefghij', 'jihgfedcbaabcdef', 'abcdefghijjihgfe'],target = \"abcdefghij\") == 3536\n assert candidate(words = ['abacaba', 'bcbcbcb', 'cacacac'],target = \"abcabc\") == 10\n assert candidate(words = ['aabbccddeeff', 'gghhiijjkkll', 'mmnnooppqqrr', 'ssttuuvvwwxx'],target = \"abcdefff\") == 0\n assert candidate(words = ['abcde', 'abfgh', 'acjkl'],target = \"abac\") == 0\n assert candidate(words = ['algorithm', 'algorithm', 'algorithm', 'algorithm', 'algorithm'],target = \"algo\") == 625\n assert candidate(words = ['aaaaaaaaaa', 'aaaaaaaaab', 'aaaaaaaaac', 'aaaaaaaaad'],target = \"aaa\") == 5952\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"yzabcd\") == 1\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 9765625\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"abcde\") == 1\n assert candidate(words = ['abcdefg', 'bcdefgh', 'cdefghi'],target = \"efg\") == 10\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 9765625\n assert candidate(words = ['racecar', 'racecar', 'racecar', 'racecar', 'racecar'],target = \"race\") == 625\n assert candidate(words = ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'],target = \"zzzzzzzzzz\") == 277520636\n assert candidate(words = ['abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd'],target = \"abcdabcd\") == 0\n assert candidate(words = ['abcabcabcabc', 'bcabcabcabca', 'cabcabcabcab'],target = \"abcabc\") == 924\n assert candidate(words = ['aabbccdd', 'bbaaddcc', 'ccddaabb', 'ddbbaacc'],target = \"abcd\") == 77\n assert candidate(words = ['aaaaaaaaa', 'bbbbbbbbb', 'ccccccccc', 'ddddddddd', 'eeeeeeeee', 'fffffff', 'ggggggggg', 'hhhhhhhhh', 'iiiiiiiii'],target = \"abcdefghi\") == 1\n assert candidate(words = ['zzzzzz', 'zzzzzz', 'zzzzzz'],target = \"zzz\") == 540\n assert candidate(words = ['quickbrownfox', 'quickbrownfox', 'quickbrownfox'],target = \"quickfox\") == 6561\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 59049\n assert candidate(words = ['abacabadabacaba', 'bcbdbecbdbecb', 'dcdcdcddcdcdc', 'efefegfefegfe', 'ghighighihighi'],target = \"abcdefg\") == 40\n assert candidate(words = ['abcdabcdabcd', 'abcdabcdabcd', 'abcdabcdabcd'],target = \"abcd\") == 1215\n assert candidate(words = ['abcdabcdabcd', 'bcdbcdbcdb', 'cdcdcdcdcd'],target = \"abcdabcd\") == 184\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"abcdef\") == 1\n assert candidate(words = ['abcabcabc', 'defdefdef', 'ghighighi'],target = \"adg\") == 1\n assert candidate(words = ['abcdefg', 'hijklmn', 'opqrstu', 'vwxyzab', 'cdefghi'],target = \"abcde\") == 1\n assert candidate(words = ['abcdef', 'ghijkl', 'mnopqr'],target = \"abcghi\") == 0\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy', 'zabcd'],target = \"ace\") == 4\n assert candidate(words = ['aaaaaaaaaa', 'bbbbbbbbbb', 'cccccccccc', 'dddddddddd', 'eeeeeeeeee'],target = \"abcde\") == 252\n assert candidate(words = ['zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz'],target = \"zzz\") == 7680\n assert candidate(words = ['aabbcc', 'ddeeff', 'gghhii', 'jjkkll'],target = \"abcd\") == 0\n assert candidate(words = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'],target = \"abcde\") == 1\n assert candidate(words = ['abcdefgh', 'efghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],target = \"efgh\") == 5\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],target = \"zyxwvut\") == 0\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst'],target = \"afk\") == 0\n assert candidate(words = ['leetcode', 'leetcode', 'leetcode', 'leetcode'],target = \"leet\") == 256\n assert candidate(words = ['abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'],target = \"abcdefgh\") == 390625\n assert candidate(words = ['thisisalongstring', 'thisisalongstring', 'thisisalongstring', 'thisisalongstring'],target = \"thisisalongstring\") == 179869065\n assert candidate(words = ['zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz'],target = \"zzzz\") == 53760\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"afik\") == 0\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abcdefghij\") == 1048576\n assert candidate(words = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij'],target = \"abc\") == 125\n assert candidate(words = ['mississippi', 'mississippi', 'mississippi'],target = \"missi\") == 3645\n assert candidate(words = ['abracadabra', 'abracadabra', 'abracadabra', 'abracadabra'],target = \"abrac\") == 1024\n assert candidate(words = ['ababababab', 'bababababa', 'ababababab', 'bababababa'],target = \"abab\") == 3360\n assert candidate(words = ['xylophone', 'xylophone', 'xylophone', 'xylophone', 'xylophone'],target = \"xyl\") == 125\n", "comparison": "exact"}, "public_tests": ["[\"acca\",\"bbbb\",\"caca\"]\n\"aba\"", "[\"abba\",\"baab\"]\n\"bab\""], "hints": ["For each index i, store the frequency of each character in the ith row.", "Use dynamic programing to calculate the number of ways to get the target string using the frequency array."], "metadata": {"canonical_parameter_names": ["words", "target"], "leetcode_dataset_entry_point": "Solution().numWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:05+00:00", "tests_total": 148, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function numWays($words, $target) {", "container": "Solution", "callable": "numWays", "parameters": [{"name": "words", "type": "String[]"}, {"name": "target", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1640, "task_id": "check-array-formation-through-concatenation", "difficulty": "Easy", "problem_description": "You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].\n\nReturn true if it is possible to form the array arr from pieces. Otherwise, return false.\n\nExample 1:\n\nInput: arr = [15,88], pieces = [[88],[15]]\nOutput: true\nExplanation: Concatenate [15] then [88]\n\nExample 2:\n\nInput: arr = [49,18,16], pieces = [[16,18,49]]\nOutput: false\nExplanation: Even though the numbers match, we cannot reorder pieces[0].\n\nExample 3:\n\nInput: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]\nOutput: true\nExplanation: Concatenate [91] then [4,64] then [78]\n\nConstraints:\n\n- 1 <= pieces.length <= arr.length <= 100\n- sum(pieces[i].length) == arr.length\n- 1 <= pieces[i].length <= arr.length\n- 1 <= arr[i], pieces[i][j] <= 100\n- The integers in arr are distinct.\n- The integers in pieces are distinct (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [10, 20, 30, 40, 50],pieces = [[10, 20], [30, 40, 50]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5],pieces = [[2, 3], [1, 4], [5]]) == False\n assert candidate(arr = [91, 4, 64, 78],pieces = [[78], [4, 64], [91]]) == True\n assert candidate(arr = [49, 18, 16],pieces = [[16, 18, 49]]) == False\n assert candidate(arr = [15, 88],pieces = [[88], [15]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5],pieces = [[2], [4, 5], [3], [1]]) == True\n assert candidate(arr = [5, 9, 13, 17, 21, 25],pieces = [[5, 9, 13], [17, 21, 25]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14],pieces = [[2, 4], [6, 8], [10, 12], [14]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],pieces = [[100, 99], [98, 97], [96, 95, 94], [93, 92], [91]]) == True\n assert candidate(arr = [91, 4, 64, 78, 100, 50],pieces = [[78, 100], [91, 4], [64], [50]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],pieces = [[1, 3, 5, 7], [9, 11], [13, 15, 17, 19], [21, 23, 25], [27, 29]]) == True\n assert candidate(arr = [8, 16, 24, 32, 40, 48, 56, 64],pieces = [[8, 16, 24], [32, 40, 48], [56, 64]]) == True\n assert candidate(arr = [11, 22, 33, 44, 55, 66, 77, 88, 99],pieces = [[11, 22], [33, 44, 55], [66, 77, 88, 99]]) == True\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40],pieces = [[5, 10, 15], [20, 25], [30, 35, 40]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pieces = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],pieces = [[1, 3, 5], [7, 9, 11], [13, 15, 17, 19]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1, 2, 3], [4, 5], [6, 7, 8, 9, 10]]) == True\n assert candidate(arr = [23, 32, 45, 54, 67, 76, 89, 98],pieces = [[23, 32], [45, 54, 67], [76, 89], [98]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],pieces = [[1, 3], [5, 7, 9], [11, 13], [15, 17, 19]]) == True\n assert candidate(arr = [3, 1, 2, 5, 4],pieces = [[3, 1], [2, 5], [4]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],pieces = [[1, 2], [3, 4, 5], [6], [7, 8, 9]]) == True\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pieces = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],pieces = [[100, 99], [98, 97, 96], [95, 94, 93], [92, 91]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pieces = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11], [12, 13, 14, 15]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pieces = [[2, 4], [6, 8, 10], [12, 14], [16, 18, 20]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pieces = [[1, 2, 3], [4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14, 15]]) == True\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],pieces = [[9], [8], [7], [6], [5], [4], [3], [2], [1]]) == True\n assert candidate(arr = [42, 13, 56, 78, 91, 100],pieces = [[42], [13, 56], [78], [91, 100]]) == True\n assert candidate(arr = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30],pieces = [[21, 22], [23, 24], [25, 26], [27, 28], [29, 30]]) == True\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90],pieces = [[10, 20, 30], [40, 50], [60, 70, 80, 90]]) == True\n assert candidate(arr = [12, 14, 16, 18, 20, 22, 24, 26, 28, 30],pieces = [[12, 14, 16], [18, 20], [22, 24, 26, 28, 30]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == True\n assert candidate(arr = [99, 88, 77, 66, 55, 44, 33, 22, 11],pieces = [[99], [88], [77], [66], [55], [44], [33], [22], [11]]) == True\n assert candidate(arr = [20, 30, 10, 50, 40],pieces = [[20, 30], [10, 50], [40]]) == True\n assert candidate(arr = [7, 14, 28, 21, 42],pieces = [[7, 14, 28], [21, 42]]) == True\n assert candidate(arr = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],pieces = [[100, 90], [80, 70, 60, 50], [40, 30, 20, 10]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[3, 4], [1, 2], [7, 8], [5, 6], [9, 10]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],pieces = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == True\n assert candidate(arr = [42, 43, 44, 45, 46, 47, 48, 49, 50],pieces = [[42, 43], [44, 45, 46], [47, 48], [49, 50]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],pieces = [[1, 3, 5], [7, 9], [11, 13], [15, 17, 19]]) == True\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40],pieces = [[5], [10, 15], [20, 25, 30], [35, 40]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15],pieces = [[1, 3, 5], [7, 9], [11, 13, 15]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],pieces = [[1], [3, 5], [7, 9], [11, 13], [15, 17, 19]]) == True\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90],pieces = [[10], [20], [30], [40], [50], [60], [70], [80], [90]]) == True\n assert candidate(arr = [2, 5, 3, 8, 9, 4],pieces = [[2, 5], [3], [8, 9], [4]]) == True\n assert candidate(arr = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],pieces = [[99, 98, 97], [96, 95, 94], [93, 92, 91, 90]]) == True\n assert candidate(arr = [3, 6, 9, 12, 15, 18, 21, 24, 27],pieces = [[3, 6, 9], [12, 15], [18, 21, 24, 27]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],pieces = [[1, 2], [3, 4, 5], [6, 7, 8], [9]]) == True\n assert candidate(arr = [3, 5, 7, 9, 11, 13, 15],pieces = [[3, 5, 7], [9, 11], [13, 15]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1, 2], [3, 4, 5], [6, 7], [8, 9, 10]]) == True\n assert candidate(arr = [3, 5, 7, 9, 11, 13, 15],pieces = [[3, 5, 7], [9], [11, 13, 15]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96],pieces = [[97, 98], [96], [99], [100]]) == False\n assert candidate(arr = [7, 14, 21, 28, 35, 42],pieces = [[7], [14], [21], [28], [35], [42]]) == True\n assert candidate(arr = [5, 10, 15, 20, 25, 30],pieces = [[10, 15], [5], [20, 25, 30]]) == True\n assert candidate(arr = [5, 6, 1, 2, 3, 4],pieces = [[5, 6], [1, 2], [3, 4]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96, 95],pieces = [[100], [99, 98], [97, 96, 95]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1, 2], [3, 4, 5], [6, 7, 8, 9, 10]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96, 95],pieces = [[100, 99], [98, 97], [96, 95]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],pieces = [[1, 3, 5], [7, 9, 11], [13, 15, 17], [19, 21]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pieces = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == True\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35],pieces = [[5, 10, 15], [20], [25, 30, 35]]) == True\n assert candidate(arr = [11, 22, 33, 44, 55, 66, 77, 88, 99],pieces = [[11, 22, 33], [44, 55], [66, 77, 88, 99]]) == True\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70],pieces = [[10, 20], [30, 40, 50], [60, 70]]) == True\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pieces = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]]) == True\n assert candidate(arr = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34],pieces = [[25, 26], [27, 28, 29], [30, 31, 32, 33], [34]]) == True\n assert candidate(arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],pieces = [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16],pieces = [[2, 4], [6, 8, 10], [12, 14, 16]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pieces = [[2, 4], [6, 8, 10], [12, 14], [16, 18, 20]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pieces = [[2, 4, 6], [8, 10, 12], [14, 16, 18], [20]]) == True\n assert candidate(arr = [3, 6, 9, 12, 15, 18, 21],pieces = [[3, 6], [9, 12], [15, 18], [21]]) == True\n assert candidate(arr = [5, 4, 3, 2, 1],pieces = [[5], [4, 3], [2, 1]]) == True\n assert candidate(arr = [31, 32, 33, 34, 35, 36, 37, 38, 39, 40],pieces = [[31, 32], [33, 34], [35, 36], [37, 38], [39, 40]]) == True\n assert candidate(arr = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],pieces = [[100, 99], [98, 97], [96, 95], [94, 93], [92, 91]]) == True\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pieces = [[2, 4, 6], [8, 10], [12, 14, 16, 18, 20]]) == True\n assert candidate(arr = [23, 29, 20, 32, 45, 67],pieces = [[23, 29, 20], [32], [45, 67]]) == True\n assert candidate(arr = [7, 14, 21, 28, 35, 42, 49, 56],pieces = [[7, 14, 21, 28], [35, 42], [49, 56]]) == True\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9],pieces = [[1, 2], [3, 4], [5, 6], [7, 8], [9]]) == True\n assert candidate(arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],pieces = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]) == True\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],pieces = [[9, 8, 7], [6, 5], [4, 3, 2], [1]]) == True\n assert candidate(arr = [5, 1, 3, 7, 8, 2, 4, 9, 6],pieces = [[1, 3], [5], [7, 8], [2, 4], [9, 6]]) == True\n assert candidate(arr = [5, 3, 8, 9, 10, 15, 20],pieces = [[5], [3, 8, 9], [10, 15], [20]]) == True\n assert candidate(arr = [4, 2, 5, 3, 6, 1, 7],pieces = [[4, 2], [5], [3, 6], [1, 7]]) == True\n assert candidate(arr = [11, 22, 33, 44, 55, 66, 77, 88, 99],pieces = [[11, 22], [33, 44], [55, 66], [77, 88, 99]]) == True\n assert candidate(arr = [42, 24, 66, 33, 55, 77],pieces = [[42], [24, 66], [33, 55], [77]]) == True\n assert candidate(arr = [5, 1, 3, 9, 7, 6],pieces = [[5, 1], [3, 9], [7, 6]]) == True\n assert candidate(arr = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100],pieces = [[11, 22], [33, 44], [55, 66], [77, 88], [99, 100]]) == True\n assert candidate(arr = [23, 45, 67, 89, 90, 12, 34, 56],pieces = [[23, 45], [67, 89, 90], [12, 34, 56]]) == True\n", "comparison": "exact"}, "public_tests": ["[15,88]\n[[88],[15]]", "[49,18,16]\n[[16,18,49]]", "[91,4,64,78]\n[[78],[4,64],[91]]"], "hints": ["Note that the distinct part means that every position in the array belongs to only one piece", "Note that you can get the piece every position belongs to naively"], "metadata": {"canonical_parameter_names": ["arr", "pieces"], "leetcode_dataset_entry_point": "Solution().canFormArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:07+00:00", "tests_total": 99, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "php", "interface": {"raw_signature": "function canFormArray($arr, $pieces) {", "container": "Solution", "callable": "canFormArray", "parameters": [{"name": "arr", "type": "Integer[]"}, {"name": "pieces", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1641, "task_id": "count-sorted-vowel-strings", "difficulty": "Medium", "problem_description": "Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.\n\nA string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.\n\nExample 1:\n\nInput: n = 1\nOutput: 5\nExplanation: The 5 sorted strings that consist of vowels only are [\"a\",\"e\",\"i\",\"o\",\"u\"].\n\nExample 2:\n\nInput: n = 2\nOutput: 15\nExplanation: The 15 sorted strings that consist of vowels only are\n[\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"].\nNote that \"ea\" is not a valid string since 'e' comes after 'a' in the alphabet.\n\nExample 3:\n\nInput: n = 33\nOutput: 66045\n\nConstraints:\n\n- 1 <= n <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 35\n assert candidate(n = 4) == 70\n assert candidate(n = 33) == 66045\n assert candidate(n = 2) == 15\n assert candidate(n = 20) == 10626\n assert candidate(n = 1) == 5\n assert candidate(n = 50) == 316251\n assert candidate(n = 10) == 1001\n assert candidate(n = 5) == 126\n assert candidate(n = 45) == 211876\n assert candidate(n = 49) == 292825\n assert candidate(n = 12) == 1820\n assert candidate(n = 28) == 35960\n assert candidate(n = 30) == 46376\n assert candidate(n = 40) == 135751\n assert candidate(n = 8) == 495\n assert candidate(n = 22) == 14950\n assert candidate(n = 27) == 31465\n assert candidate(n = 35) == 82251\n assert candidate(n = 15) == 3876\n assert candidate(n = 9) == 715\n assert candidate(n = 6) == 210\n assert candidate(n = 7) == 330\n assert candidate(n = 25) == 23751\n", "comparison": "exact"}, "public_tests": ["1", "2", "33"], "hints": ["For each character, its possible values will depend on the value of its previous character, because it needs to be not smaller than it.", "Think backtracking. Build a recursive function count(n, last_character) that counts the number of valid strings of length n and whose first characters are not less than last_character.", "In this recursive function, iterate on the possible characters for the first character, which will be all the vowels not less than last_character, and for each possible value c, increase the answer by count(n-1, c)."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().countVowelStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:09+00:00", "tests_total": 24, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "dynamic-programming", "combinatorics"]}, "language": "php", "interface": {"raw_signature": "function countVowelStrings($n) {", "container": "Solution", "callable": "countVowelStrings", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1642, "task_id": "furthest-building-you-can-reach", "difficulty": "Medium", "problem_description": "You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.\n\nYou start your journey from building 0 and move to the next building by possibly using bricks or ladders.\n\nWhile moving from building i to building i+1 (0-indexed),\n\n- If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.\n- If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.\n\nReturn the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.\n\nExample 1:\n\nInput: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\nOutput: 4\nExplanation: Starting at building 0, you can follow these steps:\n- Go to building 1 without using ladders nor bricks since 4 >= 2.\n- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n- Go to building 3 without using ladders nor bricks since 7 >= 6.\n- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\nIt is impossible to go beyond building 4 because you do not have any more bricks or ladders.\n\nExample 2:\n\nInput: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\nOutput: 7\n\nExample 3:\n\nInput: heights = [14,3,19,3], bricks = 17, ladders = 0\nOutput: 3\n\nConstraints:\n\n- 1 <= heights.length <= 10^5\n- 1 <= heights[i] <= 10^6\n- 0 <= bricks <= 10^9\n- 0 <= ladders <= heights.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(heights = [10, 15, 20, 25, 30],bricks = 0,ladders = 2) == 2\n assert candidate(heights = [3, 1, 2, 1, 5],bricks = 2,ladders = 1) == 4\n assert candidate(heights = [5, 5, 5, 5, 5],bricks = 0,ladders = 0) == 4\n assert candidate(heights = [1, 1000000, 1, 1000000, 1],bricks = 1000000,ladders = 1) == 4\n assert candidate(heights = [10, 15, 20, 25, 30],bricks = 30,ladders = 2) == 4\n assert candidate(heights = [1, 1000000],bricks = 999999,ladders = 0) == 1\n assert candidate(heights = [14, 3, 19, 3],bricks = 17,ladders = 0) == 3\n assert candidate(heights = [1, 2, 3, 4, 5],bricks = 10,ladders = 0) == 4\n assert candidate(heights = [5, 4, 3, 2, 1],bricks = 0,ladders = 0) == 4\n assert candidate(heights = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],bricks = 100,ladders = 5) == 9\n assert candidate(heights = [100, 90, 80, 70, 60],bricks = 50,ladders = 0) == 4\n assert candidate(heights = [10, 15, 20, 25, 30],bricks = 30,ladders = 0) == 4\n assert candidate(heights = [1, 3, 5, 7, 9],bricks = 20,ladders = 2) == 4\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],bricks = 0,ladders = 5) == 5\n assert candidate(heights = [3, 14, 3, 14, 3, 3, 14, 3, 14],bricks = 1,ladders = 1) == 2\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15],bricks = 20,ladders = 3) == 7\n assert candidate(heights = [1, 3, 5, 7, 9],bricks = 10,ladders = 0) == 4\n assert candidate(heights = [1, 1, 1, 1, 1],bricks = 0,ladders = 0) == 4\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],bricks = 18,ladders = 1) == 9\n assert candidate(heights = [4, 2, 7, 6, 9, 14, 12],bricks = 5,ladders = 1) == 4\n assert candidate(heights = [1, 5, 1, 2, 3, 4, 10000],bricks = 4,ladders = 1) == 5\n assert candidate(heights = [5, 1, 3, 4, 2],bricks = 0,ladders = 1) == 2\n assert candidate(heights = [4, 2, 3],bricks = 0,ladders = 1) == 2\n assert candidate(heights = [5, 18, 22, 33, 8, 26, 48, 29, 55, 46],bricks = 83,ladders = 3) == 9\n assert candidate(heights = [1, 2],bricks = 0,ladders = 0) == 0\n assert candidate(heights = [4, 12, 2, 7, 3, 18, 20, 3, 19],bricks = 10,ladders = 2) == 7\n assert candidate(heights = [1, 3, 5, 7, 9],bricks = 100,ladders = 0) == 4\n assert candidate(heights = [9, 8, 7, 6, 5],bricks = 0,ladders = 5) == 4\n assert candidate(heights = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105],bricks = 100,ladders = 2) == 13\n assert candidate(heights = [1, 3, 5, 4, 2, 1, 3, 5, 4, 2, 1, 3, 5, 4, 2, 1, 3, 5, 4, 2, 1],bricks = 20,ladders = 3) == 20\n assert candidate(heights = [5, 18, 3, 14, 5, 19, 2, 13, 11, 18, 23, 25, 28, 30, 35],bricks = 30,ladders = 4) == 14\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bricks = 200,ladders = 3) == 9\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],bricks = 10,ladders = 0) == 9\n assert candidate(heights = [1, 2, 3, 100, 101, 102, 103, 104, 105],bricks = 10,ladders = 3) == 8\n assert candidate(heights = [1, 5, 3, 6, 7, 3, 8, 4, 9, 2, 10, 6, 11, 7, 12, 8, 13, 9, 14, 10],bricks = 20,ladders = 4) == 17\n assert candidate(heights = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],bricks = 50,ladders = 2) == 9\n assert candidate(heights = [4, 12, 2, 7, 3, 18, 20, 3, 19, 10, 5, 21, 17, 8, 15],bricks = 15,ladders = 3) == 13\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],bricks = 100,ladders = 3) == 15\n assert candidate(heights = [5, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36],bricks = 50,ladders = 5) == 19\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],bricks = 0,ladders = 0) == 19\n assert candidate(heights = [4, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50],bricks = 20,ladders = 4) == 10\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],bricks = 100,ladders = 3) == 9\n assert candidate(heights = [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],bricks = 0,ladders = 0) == 49\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, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],bricks = 100,ladders = 10) == 59\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],bricks = 0,ladders = 0) == 9\n assert candidate(heights = [5, 8, 17, 14, 12, 19, 21, 16, 18, 25, 27, 22, 24, 26, 30],bricks = 30,ladders = 4) == 14\n assert candidate(heights = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],bricks = 50,ladders = 5) == 9\n assert candidate(heights = [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],bricks = 100,ladders = 5) == 24\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],bricks = 50,ladders = 5) == 19\n assert candidate(heights = [10, 15, 20, 25, 30, 35, 40],bricks = 30,ladders = 2) == 6\n assert candidate(heights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000],bricks = 0,ladders = 0) == 8\n assert candidate(heights = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],bricks = 15,ladders = 3) == 19\n assert candidate(heights = [3, 17, 9, 16, 14, 3, 17, 13, 19, 20, 15, 2, 18, 12, 1, 12, 14, 9, 1, 19],bricks = 20,ladders = 3) == 14\n assert candidate(heights = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],bricks = 25,ladders = 3) == 9\n assert candidate(heights = [5, 18, 3, 14, 5, 19, 2, 13, 11, 18],bricks = 20,ladders = 3) == 9\n assert candidate(heights = [40, 20, 30, 10, 50, 60, 70, 80, 90],bricks = 100,ladders = 2) == 8\n assert candidate(heights = [1, 2, 3, 4, 5, 15, 20, 25, 30, 35],bricks = 10,ladders = 0) == 4\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, 3],bricks = 0,ladders = 0) == 29\n assert candidate(heights = [1, 1, 2, 1, 1, 2, 1, 1, 2, 1],bricks = 1,ladders = 1) == 7\n assert candidate(heights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],bricks = 10,ladders = 0) == 19\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1],bricks = 10,ladders = 5) == 10\n assert candidate(heights = [10, 16, 18, 15, 12, 19, 20, 18, 17, 16],bricks = 15,ladders = 2) == 9\n assert candidate(heights = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],bricks = 0,ladders = 5) == 10\n assert candidate(heights = [1, 3, 6, 7, 8, 10, 12, 13, 14, 15, 17],bricks = 15,ladders = 2) == 10\n assert candidate(heights = [1, 3, 6, 7, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54],bricks = 100,ladders = 5) == 19\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],bricks = 30,ladders = 5) == 19\n assert candidate(heights = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],bricks = 30,ladders = 1) == 8\n assert candidate(heights = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],bricks = 5,ladders = 0) == 9\n assert candidate(heights = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],bricks = 100,ladders = 5) == 9\n assert candidate(heights = [4, 10, 15, 20, 25, 30, 35, 40, 45, 50],bricks = 50,ladders = 2) == 9\n assert candidate(heights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],bricks = 50,ladders = 4) == 9\n assert candidate(heights = [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],bricks = 0,ladders = 0) == 24\n assert candidate(heights = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],bricks = 10,ladders = 1) == 9\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],bricks = 100,ladders = 3) == 19\n assert candidate(heights = [100, 150, 200, 250, 300, 350, 400, 450, 500],bricks = 1000,ladders = 3) == 8\n assert candidate(heights = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5],bricks = 20,ladders = 3) == 9\n assert candidate(heights = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55],bricks = 100,ladders = 2) == 9\n assert candidate(heights = [1, 5, 20, 30, 40, 50, 60, 70, 80, 90],bricks = 150,ladders = 2) == 9\n assert candidate(heights = [1, 100, 2, 101, 3, 102, 4, 103, 5],bricks = 100,ladders = 2) == 6\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],bricks = 100,ladders = 5) == 24\n assert candidate(heights = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105],bricks = 100,ladders = 5) == 13\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],bricks = 50,ladders = 5) == 9\n assert candidate(heights = [1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000],bricks = 1000000,ladders = 4) == 9\n assert candidate(heights = [5, 18, 12, 15, 20, 10, 19, 21],bricks = 50,ladders = 3) == 7\n assert candidate(heights = [4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],bricks = 20,ladders = 2) == 19\n assert candidate(heights = [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],bricks = 1,ladders = 1) == 29\n assert candidate(heights = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9],bricks = 30,ladders = 5) == 15\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],bricks = 150,ladders = 5) == 29\n assert candidate(heights = [10, 15, 20, 25, 30, 35, 40, 45, 50],bricks = 30,ladders = 2) == 8\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],bricks = 45,ladders = 0) == 9\n assert candidate(heights = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105],bricks = 100,ladders = 1) == 13\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],bricks = 50,ladders = 5) == 14\n assert candidate(heights = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],bricks = 20,ladders = 3) == 16\n assert candidate(heights = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11],bricks = 50,ladders = 3) == 19\n assert candidate(heights = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],bricks = 100,ladders = 3) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],bricks = 200,ladders = 15) == 39\n assert candidate(heights = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],bricks = 25,ladders = 2) == 8\n assert candidate(heights = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1],bricks = 15,ladders = 2) == 19\n assert candidate(heights = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],bricks = 20,ladders = 3) == 19\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],bricks = 100,ladders = 10) == 19\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],bricks = 30,ladders = 2) == 19\n assert candidate(heights = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],bricks = 4000,ladders = 5) == 9\n assert candidate(heights = [5, 8, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],bricks = 50,ladders = 3) == 19\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],bricks = 50,ladders = 4) == 19\n assert candidate(heights = [1, 5, 7, 8, 10, 12, 15, 20, 25, 30],bricks = 15,ladders = 3) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],bricks = 150,ladders = 10) == 29\n assert candidate(heights = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bricks = 55,ladders = 3) == 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],bricks = 50,ladders = 2) == 19\n assert candidate(heights = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55],bricks = 20,ladders = 2) == 6\n assert candidate(heights = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119],bricks = 50,ladders = 5) == 19\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],bricks = 50,ladders = 3) == 9\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],bricks = 0,ladders = 0) == 31\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],bricks = 100,ladders = 0) == 9\n assert candidate(heights = [5, 10, 15, 10, 5, 10, 15, 20, 25, 30],bricks = 40,ladders = 1) == 9\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bricks = 150,ladders = 3) == 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, 21, 22, 23, 24, 25],bricks = 100,ladders = 4) == 24\n", "comparison": "exact"}, "public_tests": ["[4,2,7,6,9,14,12]\n5\n1", "[4,12,2,7,3,18,20,3,19]\n10\n2", "[14,3,19,3]\n17\n0"], "hints": ["Assume the problem is to check whether you can reach the last building or not.", "You'll have to do a set of jumps, and choose for each one whether to do it using a ladder or bricks. It's always optimal to use ladders in the largest jumps.", "Iterate on the buildings, maintaining the largest r jumps and the sum of the remaining ones so far, and stop whenever this sum exceeds b."], "metadata": {"canonical_parameter_names": ["heights", "bricks", "ladders"], "leetcode_dataset_entry_point": "Solution().furthestBuilding", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:12+00:00", "tests_total": 118, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function furthestBuilding($heights, $bricks, $ladders) {", "container": "Solution", "callable": "furthestBuilding", "parameters": [{"name": "heights", "type": "Integer[]"}, {"name": "bricks", "type": "Integer"}, {"name": "ladders", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1643, "task_id": "kth-smallest-instructions", "difficulty": "Hard", "problem_description": "Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination.\n\nThe instructions are represented as a string, where each character is either:\n\n- 'H', meaning move horizontally (go right), or\n- 'V', meaning move vertically (go down).\n\nMultiple instructions will lead Bob to destination. For example, if destination is (2, 3), both \"HHHVV\" and \"HVHVH\" are valid instructions.\n\nHowever, Bob is very picky. Bob has a lucky number k, and he wants the k^th lexicographically smallest instructions that will lead him to destination. k is 1-indexed.\n\nGiven an integer array destination and an integer k, return the k^th lexicographically smallest instructions that will take Bob to destination.\n\nExample 1:\n\nInput: destination = [2,3], k = 1\nOutput: \"HHHVV\"\nExplanation: All the instructions that reach (2, 3) in lexicographic order are as follows:\n[\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].\n\nExample 2:\n\nInput: destination = [2,3], k = 2\nOutput: \"HHVHV\"\n\nExample 3:\n\nInput: destination = [2,3], k = 3\nOutput: \"HHVVH\"\n\nConstraints:\n\n- destination.length == 2\n- 1 <= row, column <= 15\n- 1 <= k <= nCr(row + column, row), where nCr(a, b) denotes a choose b.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(destination = [3, 3],k = 5) == \"HVHHVV\"\n assert candidate(destination = [2, 3],k = 1) == \"HHHVV\"\n assert candidate(destination = [4, 4],k = 10) == \"HHVVHHVV\"\n assert candidate(destination = [3, 3],k = 10) == \"HVVVHH\"\n assert candidate(destination = [2, 3],k = 2) == \"HHVHV\"\n assert candidate(destination = [2, 3],k = 3) == \"HHVVH\"\n assert candidate(destination = [4, 4],k = 20) == \"HVHVHHVV\"\n assert candidate(destination = [4, 5],k = 10) == \"HHHVVHHVV\"\n assert candidate(destination = [15, 15],k = 1) == \"HHHHHHHHHHHHHHHVVVVVVVVVVVVVVV\"\n assert candidate(destination = [3, 2],k = 4) == \"HVVVH\"\n assert candidate(destination = [3, 4],k = 5) == \"HHVHHVV\"\n assert candidate(destination = [5, 5],k = 100) == \"HVVHHVVHVH\"\n assert candidate(destination = [3, 2],k = 1) == \"HHVVV\"\n assert candidate(destination = [3, 10],k = 175) == \"HVHHHHHHVVHHH\"\n assert candidate(destination = [7, 8],k = 1716) == \"HHVVVVVVVHHHHHH\"\n assert candidate(destination = [12, 12],k = 50000) == \"HHHHHVVVVVVVHVVHHVHHVVHH\"\n assert candidate(destination = [15, 5],k = 2000) == \"HVVHVVVVVVVHVVVVVVHH\"\n assert candidate(destination = [9, 5],k = 252) == \"HVHHVVVVHVHVVV\"\n assert candidate(destination = [5, 7],k = 1000) == \"VVVVVVVVVVVV\"\n assert candidate(destination = [7, 9],k = 300) == \"HHHHHVVVVHHVHHVV\"\n assert candidate(destination = [9, 7],k = 5678) == \"VHHVHVHVVHVHVVVH\"\n assert candidate(destination = [10, 10],k = 5000) == \"HHHHVHVVVVVVVVHHHHHV\"\n assert candidate(destination = [9, 9],k = 1000) == \"HHHHVHVHVVVVVVVHHH\"\n assert candidate(destination = [3, 4],k = 15) == \"HVHVHVH\"\n assert candidate(destination = [14, 10],k = 5000) == \"HHHHHVHVVVVVHVHVHVHVVVVV\"\n assert candidate(destination = [15, 15],k = 10000) == \"HHHHHHHHHHVVVHVHVVVHVVVHVVVVVH\"\n assert candidate(destination = [15, 15],k = 500000) == \"HHHHHHVHHHHVVVVVHHVHHVVVVHVVVV\"\n assert candidate(destination = [8, 12],k = 250) == \"HHHHHHHHVHVVHVVVVVHH\"\n assert candidate(destination = [15, 15],k = 40116600) == \"HVHHHVHVHVVHHVVHHVVVVHVHHHVVHV\"\n assert candidate(destination = [10, 5],k = 200) == \"HHVVVHVVVVVVHHV\"\n assert candidate(destination = [12, 5],k = 1234) == \"HVVVHVVHVVVVHVVHV\"\n assert candidate(destination = [5, 15],k = 3003) == \"HHHHHVVVVVHHHHHHHHHH\"\n assert candidate(destination = [12, 8],k = 500) == \"HHHHVHHVVVVHVVHVVVVV\"\n assert candidate(destination = [7, 6],k = 150) == \"HHVHVHHVHVVVV\"\n assert candidate(destination = [3, 7],k = 123) == \"VVVVVVVVVV\"\n assert candidate(destination = [13, 7],k = 4000) == \"HHVHVVVVVVHHVHVVHVVV\"\n assert candidate(destination = [12, 12],k = 100000) == \"HHHHVVHVVVVHHHHVVHVHVHVV\"\n assert candidate(destination = [2, 13],k = 150) == \"VVVVVVVVVVVVVVV\"\n assert candidate(destination = [10, 10],k = 500) == \"HHHHHHVHVVVVVVVHVHHV\"\n assert candidate(destination = [10, 10],k = 1000) == \"HHHHHHVVVVVVVVVHVHHH\"\n assert candidate(destination = [7, 5],k = 30) == \"HHHVVVVHVVVH\"\n assert candidate(destination = [6, 6],k = 500) == \"VHHHVVHHVHVV\"\n assert candidate(destination = [9, 9],k = 10000) == \"HHVVVHHVHVHHVVHHVV\"\n assert candidate(destination = [6, 7],k = 120) == \"HHHVHVHVVVVHH\"\n assert candidate(destination = [8, 9],k = 500) == \"HHHHVHHHHVVVVHVVV\"\n assert candidate(destination = [15, 15],k = 1000000) == \"HHHHHHVVHVVVVHVVVVHHHVHVVVHHHV\"\n assert candidate(destination = [1, 15],k = 1) == \"HHHHHHHHHHHHHHHV\"\n assert candidate(destination = [10, 10],k = 10000) == \"HHHVHHVVVVVVVHVHHHHV\"\n assert candidate(destination = [10, 10],k = 1000) == \"HHHHHHVVVVVVVVVHVHHH\"\n assert candidate(destination = [7, 8],k = 3000) == \"HVVHVHVVHHHHVVH\"\n assert candidate(destination = [3, 10],k = 100) == \"HHHVHHVHHHHHV\"\n assert candidate(destination = [12, 8],k = 5000) == \"HHHVVVVHHVVHVVHVVVVH\"\n assert candidate(destination = [10, 5],k = 200) == \"HHVVVHVVVVVVHHV\"\n assert candidate(destination = [10, 10],k = 50000) == \"HVHHVHHVVVVVHHHVHVHV\"\n assert candidate(destination = [7, 7],k = 343) == \"HHVHHHVHVVVVVH\"\n assert candidate(destination = [7, 8],k = 1000) == \"HHVHHVVVVVHHVHH\"\n assert candidate(destination = [5, 4],k = 50) == \"HVVVHVHHV\"\n assert candidate(destination = [7, 8],k = 2000) == \"HVHHVHVHVHHVVHV\"\n assert candidate(destination = [3, 12],k = 200) == \"HHHVHHVHVHHHHHH\"\n assert candidate(destination = [6, 14],k = 10000) == \"HHHVHHVVVHVVHHHHHHHH\"\n assert candidate(destination = [8, 9],k = 15000) == \"VHHVHHVVVHHHVVHHV\"\n assert candidate(destination = [12, 4],k = 250) == \"HVVVHVHVVVVHVVVV\"\n assert candidate(destination = [7, 8],k = 1234) == \"HHVHVVVVHHHHHVV\"\n assert candidate(destination = [8, 7],k = 3456) == \"VHHVHVHVVHHVVHV\"\n assert candidate(destination = [13, 2],k = 100) == \"VVVVVVVVVVVHHVV\"\n assert candidate(destination = [11, 11],k = 6000) == \"HHHHHVHVHVVVVHVVHVHVHV\"\n assert candidate(destination = [7, 7],k = 200) == \"HHHVHVVVVHVVHH\"\n assert candidate(destination = [15, 15],k = 12345) == \"HHHHHHHHHHVVVVHVVVVVHVVHHVVVVH\"\n assert candidate(destination = [8, 12],k = 3456) == \"HHHHHVHHVHVHVVHHVVHV\"\n assert candidate(destination = [6, 9],k = 300) == \"HHHHVHVHVVVHVHH\"\n assert candidate(destination = [14, 6],k = 5000) == \"HVHVVVVVHVHVHVHVVVVV\"\n assert candidate(destination = [10, 6],k = 8316) == \"VVVVVVVVVVVVVVVV\"\n assert candidate(destination = [15, 15],k = 10000) == \"HHHHHHHHHHVVVHVHVVVHVVVHVVVVVH\"\n assert candidate(destination = [12, 12],k = 123456) == \"HHHHVVVVVVHHVHHHVHVHHVVV\"\n assert candidate(destination = [10, 10],k = 12870) == \"HHHVHVVVVVHHVVVHHHVH\"\n assert candidate(destination = [14, 6],k = 98765) == \"VVVVVVVVVVVVVVVVVVVV\"\n assert candidate(destination = [8, 6],k = 150) == \"HHHVVVVVHVHHVV\"\n assert candidate(destination = [7, 6],k = 300) == \"HHVVVVHHVHHVV\"\n assert candidate(destination = [12, 8],k = 2500) == \"HHHVHVVHHVVVHVVHVVVV\"\n assert candidate(destination = [5, 6],k = 120) == \"HHVVVHVHVHH\"\n assert candidate(destination = [6, 7],k = 500) == \"HVHHHVVHHVHVV\"\n assert candidate(destination = [9, 7],k = 200) == \"HHHHVVVVVHVVVVHH\"\n assert candidate(destination = [8, 6],k = 500) == \"HVHHHHVVVVHVVV\"\n assert candidate(destination = [15, 15],k = 6435678) == \"HHHHVVVHHHVHHVVVVHVVHHHVHVHVVV\"\n assert candidate(destination = [4, 12],k = 500) == \"HHHVHHHHHHHVHHVV\"\n assert candidate(destination = [8, 7],k = 650) == \"HHVHVHVHVHHVVVV\"\n assert candidate(destination = [6, 7],k = 123) == \"HHHVHVVHHVVHV\"\n assert candidate(destination = [12, 3],k = 200) == \"VVHVVVHHVVVVVVV\"\n assert candidate(destination = [5, 12],k = 500) == \"HHHHHVHHHVHHHVVHV\"\n assert candidate(destination = [5, 7],k = 30) == \"HHHHVHVHVVVH\"\n assert candidate(destination = [6, 4],k = 45) == \"HVHVVVHVHV\"\n assert candidate(destination = [15, 1],k = 1) == \"HVVVVVVVVVVVVVVV\"\n assert candidate(destination = [6, 8],k = 300) == \"HHHVHVHVVVHVHH\"\n", "comparison": "exact"}, "public_tests": ["[2,3]\n1", "[2,3]\n2", "[2,3]\n3"], "hints": ["There are nCr(row + column, row) possible instructions to reach (row, column).", "Try building the instructions one step at a time. How many instructions start with \"H\", and how does this compare with k?"], "metadata": {"canonical_parameter_names": ["destination", "k"], "leetcode_dataset_entry_point": "Solution().kthSmallestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:14+00:00", "tests_total": 93, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "dynamic-programming", "combinatorics"]}, "language": "php", "interface": {"raw_signature": "function kthSmallestPath($destination, $k) {", "container": "Solution", "callable": "kthSmallestPath", "parameters": [{"name": "destination", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1646, "task_id": "get-maximum-in-generated-array", "difficulty": "Easy", "problem_description": "You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:\n\n- nums[0] = 0\n- nums[1] = 1\n- nums[2 * i] = nums[i] when 2 <= 2 * i <= n\n- nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n\n\nReturn the maximum integer in the array nums.\n\nExample 1:\n\nInput: n = 7\nOutput: 3\nExplanation: According to the given rules:\n nums[0] = 0\n nums[1] = 1\n nums[(1 * 2) = 2] = nums[1] = 1\n nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n nums[(2 * 2) = 4] = nums[2] = 1\n nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n nums[(3 * 2) = 6] = nums[3] = 2\n nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.\n\nExample 2:\n\nInput: n = 2\nOutput: 1\nExplanation: According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.\n\nExample 3:\n\nInput: n = 3\nOutput: 2\nExplanation: According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2.\n\nConstraints:\n\n- 0 <= n <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == 0\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 21\n assert candidate(n = 99) == 21\n assert candidate(n = 2) == 1\n assert candidate(n = 20) == 7\n assert candidate(n = 1) == 1\n assert candidate(n = 50) == 13\n assert candidate(n = 7) == 3\n assert candidate(n = 10) == 4\n assert candidate(n = 88) == 21\n assert candidate(n = 97) == 21\n assert candidate(n = 63) == 13\n assert candidate(n = 45) == 13\n assert candidate(n = 49) == 13\n assert candidate(n = 47) == 13\n assert candidate(n = 60) == 13\n assert candidate(n = 64) == 13\n assert candidate(n = 37) == 11\n assert candidate(n = 17) == 5\n assert candidate(n = 42) == 11\n assert candidate(n = 90) == 21\n assert candidate(n = 22) == 8\n assert candidate(n = 89) == 21\n assert candidate(n = 75) == 18\n assert candidate(n = 81) == 18\n assert candidate(n = 24) == 8\n assert candidate(n = 11) == 5\n assert candidate(n = 15) == 5\n assert candidate(n = 31) == 8\n assert candidate(n = 25) == 8\n", "comparison": "exact"}, "public_tests": ["7", "2", "3"], "hints": ["Try generating the array.", "Make sure not to fall in the base case of 0."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().getMaximumGenerated", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:18+00:00", "tests_total": 31, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function getMaximumGenerated($n) {", "container": "Solution", "callable": "getMaximumGenerated", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1647, "task_id": "minimum-deletions-to-make-character-frequencies-unique", "difficulty": "Medium", "problem_description": "A string s is called good if there are no two different characters in s that have the same frequency.\n\nGiven a string s, return the minimum number of characters you need to delete to make s good.\n\nThe frequency of a character in a string is the number of times it appears in the string. For example, in the string \"aab\", the frequency of 'a' is 2, while the frequency of 'b' is 1.\n\nExample 1:\n\nInput: s = \"aab\"\nOutput: 0\nExplanation: s is already good.\n\nExample 2:\n\nInput: s = \"aaabbbcc\"\nOutput: 2\nExplanation: You can delete two 'b's resulting in the good string \"aaabcc\".\nAnother way it to delete one 'b' and one 'c' resulting in the good string \"aaabbc\".\n\nExample 3:\n\nInput: s = \"ceabaacb\"\nOutput: 2\nExplanation: You can delete both 'c's resulting in the good string \"eabaab\".\nNote that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s contains only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aab\") == 0\n assert candidate(s = \"aabacabadabaeabafabagabahabaiabajabakabalabamabanabaoabapabaqabarabasabataabuabavabawabaxabayabajabaz\") == 22\n assert candidate(s = \"abcabcabc\") == 3\n assert candidate(s = \"aabbbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiii\") == 2\n assert candidate(s = \"zzzzzzzzzz\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzz\") == 24\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 49\n assert candidate(s = \"ceabaacb\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aaabbbcc\") == 2\n assert candidate(s = \"aabbccddeeffgghhii\") == 15\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"zzzzzzzzzzyyyyyyyyyxxxxxxxwwwwwwvvvvuuuuutttttsssssrrrrqqqqppppooooonnnnmmmmlllkkkjjjiii\") == 41\n assert candidate(s = \"aabbccddeeefffggg\") == 11\n assert candidate(s = \"aabbccddeeefffhhhiiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 48\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzz\") == 47\n assert candidate(s = \"pppppppppooooooonnnnnmmmllllllkkkkjjjjiiiiiiiihhhhhhhggggggg\") == 15\n assert candidate(s = \"aabbbccccddddeeeee\") == 3\n assert candidate(s = \"abababababababababab\") == 1\n assert candidate(s = \"zzzzzzzzzzzyyyyyyyxxxxxxxwwwwwwvvvvuuuutttssrrqponmlkjihgfedcba\") == 24\n assert candidate(s = \"aabbbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiiijjjjjjjjjj\") == 2\n", "comparison": "exact"}, "public_tests": ["\"aab\"", "\"aaabbbcc\"", "\"ceabaacb\""], "hints": ["As we can only delete characters, if we have multiple characters having the same frequency, we must decrease all the frequencies of them, except one.", "Sort the alphabet characters by their frequencies non-increasingly.", "Iterate on the alphabet characters, keep decreasing the frequency of the current character until it reaches a value that has not appeared before."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:21+00:00", "tests_total": 23, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minDeletions($s) {", "container": "Solution", "callable": "minDeletions", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1648, "task_id": "sell-diminishing-valued-colored-balls", "difficulty": "Medium", "problem_description": "You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.\n\nThe customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color you currently have in your inventory. For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball. After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.e., the value of the balls decreases as you sell more to the customer).\n\nYou are given an integer array, inventory, where inventory[i] represents the number of balls of the i^th color that you initially own. You are also given an integer orders, which represents the total number of balls that the customer wants. You can sell the balls in any order.\n\nReturn the maximum total value that you can attain after selling orders colored balls. As the answer may be too large, return it modulo 10^9+ 7.\n\nExample 1:\n\nInput: inventory = [2,5], orders = 4\nOutput: 14\nExplanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).\nThe maximum total value is 2 + 5 + 4 + 3 = 14.\n\nExample 2:\n\nInput: inventory = [3,5], orders = 6\nOutput: 19\nExplanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).\nThe maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.\n\nConstraints:\n\n- 1 <= inventory.length <= 10^5\n- 1 <= inventory[i] <= 10^9\n- 1 <= orders <= min(sum(inventory[i]), 10^9)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(inventory = [10, 10, 10],orders = 5) == 48\n assert candidate(inventory = [3, 5],orders = 6) == 19\n assert candidate(inventory = [1, 2, 3, 4, 5],orders = 10) == 30\n assert candidate(inventory = [1, 1, 1, 1, 1],orders = 3) == 3\n assert candidate(inventory = [7],orders = 7) == 28\n assert candidate(inventory = [1000000000, 1000000000],orders = 1000000000) == 250000035\n assert candidate(inventory = [1000000000],orders = 1) == 1000000000\n assert candidate(inventory = [5, 5, 5, 5, 5],orders = 20) == 70\n assert candidate(inventory = [1000000000],orders = 1000000000) == 21\n assert candidate(inventory = [2, 5],orders = 4) == 14\n assert candidate(inventory = [100],orders = 10) == 955\n assert candidate(inventory = [9, 9, 9, 9, 9, 9],orders = 25) == 185\n assert candidate(inventory = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],orders = 350) == 4110\n assert candidate(inventory = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],orders = 5) == 5\n assert candidate(inventory = [100, 90, 80, 70, 60],orders = 200) == 12600\n assert candidate(inventory = [1000000, 2000000, 3000000],orders = 5000000) == 335785502\n assert candidate(inventory = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],orders = 100) == 500\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],orders = 50) == 215\n assert candidate(inventory = [1000, 2000, 3000, 4000, 5000],orders = 10000) == 25005000\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],orders = 55) == 220\n assert candidate(inventory = [5, 15, 25, 35, 45],orders = 35) == 1138\n assert candidate(inventory = [100000000, 100000000, 100000000],orders = 299999997) == 44999997\n assert candidate(inventory = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],orders = 50) == 150\n assert candidate(inventory = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],orders = 900) == 70200\n assert candidate(inventory = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],orders = 500) == 37750\n assert candidate(inventory = [1000000000, 500000000, 250000000, 125000000, 62500000],orders = 999999999) == 312500027\n assert candidate(inventory = [500000000, 400000000, 300000000, 200000000, 100000000],orders = 1500000000) == 825000014\n assert candidate(inventory = [100, 200, 300, 400, 500],orders = 1000) == 250500\n assert candidate(inventory = [100000000, 200000000, 300000000, 400000000, 500000000],orders = 900000000) == 778750014\n assert candidate(inventory = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],orders = 50) == 400\n assert candidate(inventory = [999999999, 999999999, 999999999, 999999999, 999999999],orders = 500000000) == 425000028\n assert candidate(inventory = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],orders = 500) == 37750\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],orders = 190) == 1520\n assert candidate(inventory = [50, 40, 30, 20, 10],orders = 100) == 2550\n assert candidate(inventory = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],orders = 1500) == 134972\n assert candidate(inventory = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],orders = 5000) == 1915000\n assert candidate(inventory = [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],orders = 500) == 6080\n assert candidate(inventory = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],orders = 10) == 10\n assert candidate(inventory = [3, 5, 7, 9],orders = 15) == 79\n assert candidate(inventory = [500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000],orders = 4500000) == 502241341\n assert candidate(inventory = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],orders = 550) == 19525\n assert candidate(inventory = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],orders = 10000) == 6071070\n assert candidate(inventory = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81],orders = 1000) == 66330\n assert candidate(inventory = [1, 3, 5, 7, 9],orders = 15) == 79\n assert candidate(inventory = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],orders = 7500) == 5500000\n assert candidate(inventory = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],orders = 50) == 110\n assert candidate(inventory = [10, 10, 20, 20, 30, 30],orders = 50) == 1012\n assert candidate(inventory = [10, 20, 30, 40, 50],orders = 100) == 2550\n assert candidate(inventory = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],orders = 20) == 20\n assert candidate(inventory = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],orders = 10) == 10\n assert candidate(inventory = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],orders = 300) == 16124\n assert candidate(inventory = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],orders = 200) == 9100\n assert candidate(inventory = [10, 20, 30, 40, 50],orders = 50) == 1708\n assert candidate(inventory = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],orders = 1500) == 94500\n assert candidate(inventory = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],orders = 40) == 110\n assert candidate(inventory = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],orders = 100) == 715\n assert candidate(inventory = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],orders = 25000) == 144369642\n assert candidate(inventory = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],orders = 1000000000) == 46\n assert candidate(inventory = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],orders = 40) == 200\n assert candidate(inventory = [10, 8, 6, 4, 2],orders = 15) == 94\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],orders = 45) == 210\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],orders = 50) == 465\n assert candidate(inventory = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],orders = 50) == 50\n assert candidate(inventory = [50, 20, 10, 5, 1],orders = 50) == 1375\n assert candidate(inventory = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],orders = 500) == 19375\n assert candidate(inventory = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],orders = 100) == 1155\n assert candidate(inventory = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],orders = 100) == 800\n assert candidate(inventory = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],orders = 10000) == 75005000\n assert candidate(inventory = [1000000000, 500000000, 250000000, 125000000, 62500000],orders = 1000000000) == 562500028\n assert candidate(inventory = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],orders = 1000000) == 499475\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],orders = 30) == 174\n assert candidate(inventory = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990],orders = 1000000000) == 350000124\n assert candidate(inventory = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],orders = 50) == 460\n assert candidate(inventory = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],orders = 1000) == 750500\n assert candidate(inventory = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],orders = 200) == 14627\n assert candidate(inventory = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],orders = 45) == 145\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],orders = 190) == 1520\n assert candidate(inventory = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],orders = 1000) == 175234\n assert candidate(inventory = [50, 40, 30, 20, 10],orders = 150) == 2825\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],orders = 150) == 1416\n assert candidate(inventory = [10, 20, 30, 40, 50],orders = 100) == 2550\n assert candidate(inventory = [500000000, 500000000, 500000000, 500000000, 500000000],orders = 2000000000) == 800000028\n assert candidate(inventory = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],orders = 55) == 220\n", "comparison": "exact"}, "public_tests": ["[2,5]\n4", "[3,5]\n6"], "hints": ["Greedily sell the most expensive ball.", "There is some value k where all balls of value > k are sold, and some, (maybe 0) of balls of value k are sold.", "Use binary search to find this value k, and use maths to find the total sum."], "metadata": {"canonical_parameter_names": ["inventory", "orders"], "leetcode_dataset_entry_point": "Solution().maxProfit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:23+00:00", "tests_total": 88, "tests_dropped": 5, "flags": ["has_images"], "topic_tags": ["array", "math", "binary-search", "greedy", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maxProfit($inventory, $orders) {", "container": "Solution", "callable": "maxProfit", "parameters": [{"name": "inventory", "type": "Integer[]"}, {"name": "orders", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1649, "task_id": "create-sorted-array-through-instructions", "difficulty": "Hard", "problem_description": "Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following:\n\n- The number of elements currently in nums that are strictly less than instructions[i].\n- The number of elements currently in nums that are strictly greater than instructions[i].\n\nFor example, if inserting element 3 into nums = [1,2,3,5], the cost of insertion is min(2, 1) (elements 1 and 2 are less than 3, element 5 is greater than 3) and nums will become [1,2,3,3,5].\n\nReturn the total cost to insert all elements from instructions into nums. Since the answer may be large, return it modulo 10^9 + 7\n\nExample 1:\n\nInput: instructions = [1,5,6,2]\nOutput: 1\nExplanation: Begin with nums = [].\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\nThe total cost is 0 + 0 + 0 + 1 = 1.\n\nExample 2:\n\nInput: instructions = [1,2,3,6,5,4]\nOutput: 3\nExplanation: Begin with nums = [].\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\n\nExample 3:\n\nInput: instructions = [1,3,3,3,2,4,2,1,2]\nOutput: 4\nExplanation: Begin with nums = [].\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\nInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\nInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\nInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\n\nConstraints:\n\n- 1 <= instructions.length <= 10^5\n- 1 <= instructions[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(instructions = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(instructions = [50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009]) == 0\n assert candidate(instructions = [1, 2, 3, 6, 5, 4]) == 3\n assert candidate(instructions = [1, 5, 6, 2]) == 1\n assert candidate(instructions = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 20\n assert candidate(instructions = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 20\n assert candidate(instructions = [1, 3, 3, 3, 2, 4, 2, 1, 2]) == 4\n assert candidate(instructions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(instructions = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(instructions = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9]) == 5\n assert candidate(instructions = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == 10\n assert candidate(instructions = [50000, 40000, 30000, 20000, 10000, 60000, 70000, 80000, 90000, 100000]) == 0\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(instructions = [5, 3, 8, 6, 2, 7, 4, 1, 10, 9]) == 5\n assert candidate(instructions = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 0\n assert candidate(instructions = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 10\n assert candidate(instructions = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 32\n assert candidate(instructions = [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]) == 75\n assert candidate(instructions = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 4\n assert candidate(instructions = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 0\n assert candidate(instructions = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 27\n assert candidate(instructions = [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(instructions = [9, 3, 8, 3, 7, 3, 6, 3, 5, 3, 4, 3, 2, 3, 1, 3]) == 18\n assert candidate(instructions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 24\n assert candidate(instructions = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 75\n assert candidate(instructions = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(instructions = [1, 2, 3, 6, 5, 4, 1, 2, 3, 6, 5, 4]) == 14\n assert candidate(instructions = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15]) == 10\n assert candidate(instructions = [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]) == 75\n assert candidate(instructions = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 30\n assert candidate(instructions = [5, 4, 3, 2, 1]) == 0\n assert candidate(instructions = [1, 3, 2, 6, 5, 4, 9, 8, 7, 10, 1, 3, 2, 6, 5, 4, 9, 8, 7, 10, 1, 3, 2, 6, 5, 4, 9, 8, 7, 10]) == 88\n assert candidate(instructions = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 0\n assert candidate(instructions = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 60\n assert candidate(instructions = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10]) == 16\n assert candidate(instructions = [10, 20, 30, 40, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 40, 30, 20, 10]) == 22\n assert candidate(instructions = [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]) == 75\n assert candidate(instructions = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(instructions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 27\n assert candidate(instructions = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 0\n assert candidate(instructions = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(instructions = [100000, 99999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == 33\n assert candidate(instructions = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 27\n assert candidate(instructions = [50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 14\n assert candidate(instructions = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 36\n assert candidate(instructions = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993]) == 56\n assert candidate(instructions = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1]) == 0\n assert candidate(instructions = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 0\n assert candidate(instructions = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(instructions = [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(instructions = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 20\n assert candidate(instructions = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 10\n assert candidate(instructions = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == 60\n assert candidate(instructions = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16]) == 25\n assert candidate(instructions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 0\n assert candidate(instructions = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(instructions = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(instructions = [1, 3, 2, 4, 2, 3, 1, 4, 2, 3]) == 7\n assert candidate(instructions = [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]) == 0\n assert candidate(instructions = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1]) == 0\n assert candidate(instructions = [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]) == 75\n assert candidate(instructions = [3, 1, 2, 5, 4, 6, 9, 7, 10, 8]) == 5\n assert candidate(instructions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 30\n assert candidate(instructions = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 0\n assert candidate(instructions = [50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009, 50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009]) == 27\n assert candidate(instructions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 30\n assert candidate(instructions = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 45\n assert candidate(instructions = [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]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(instructions = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 0\n assert candidate(instructions = [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]) == 317\n assert candidate(instructions = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 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(instructions = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9]) == 9\n assert candidate(instructions = [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(instructions = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 27\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 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(instructions = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 21\n assert candidate(instructions = [100000, 50000, 75000, 25000, 62500, 37500, 87500, 12500, 93750, 43750, 68750, 31250, 81250, 18750, 90625, 46875, 71875, 28125, 89062, 40625, 65625, 34375, 84375, 21875, 82812, 45312, 70312, 29687, 88281, 49218, 74218, 32187, 86171, 42187, 67187, 35156, 83125, 23437, 85937, 50312, 75312, 37812, 81562, 44531, 69531, 33437, 87968, 47968, 72968, 30937, 90468, 52968, 77968, 38906, 85468, 55468, 80468, 43437, 92460, 57460, 82460, 47460, 91718, 61718, 86718, 52656, 94359, 66359, 91359, 57359, 93671, 69671, 94671, 73671, 86913, 64406, 93406, 68406, 92406, 65406, 95507, 70507, 90507, 67507, 92753, 75253, 87753, 62753, 94753, 78753, 83753, 71753, 88281, 53281, 88281, 58281, 83281, 50281, 81281, 45281, 86281, 51281, 82281, 46281, 84281, 48281, 85281, 50281, 87281, 52281, 89281, 54281, 90281, 56281, 91281, 58281, 92281, 60281, 93281, 62281, 94281, 64281, 95281, 66281, 96281, 68281, 97281, 70281, 98281, 72281, 99281, 74281, 100000]) == 2291\n assert candidate(instructions = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(instructions = [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]) == 65\n assert candidate(instructions = [5, 1, 4, 2, 3, 8, 6, 7, 10, 9, 5, 5, 5, 5, 5]) == 27\n assert candidate(instructions = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 0\n assert candidate(instructions = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 27\n assert candidate(instructions = [7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(instructions = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 27\n assert candidate(instructions = [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]) == 0\n assert candidate(instructions = [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]) == 84\n assert candidate(instructions = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 15\n assert candidate(instructions = [2, 3, 1, 4, 5, 1, 3, 2, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 27\n assert candidate(instructions = [100000, 100000, 100000, 1, 1, 1, 50000, 50000, 50000, 25000]) == 12\n assert candidate(instructions = [1, 2, 3, 4, 5, 100000, 99999, 99998, 99997, 99996]) == 10\n assert candidate(instructions = [5, 4, 3, 2, 1, 100000, 99999, 99998, 99997, 99996]) == 10\n assert candidate(instructions = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 0\n assert candidate(instructions = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5, 600, 6, 700, 7, 800, 8, 900, 9, 1000, 10]) == 45\n assert candidate(instructions = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 27\n assert candidate(instructions = [50000, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009]) == 0\n assert candidate(instructions = [5, 3, 1, 2, 4, 6, 8, 7, 10, 9]) == 4\n assert candidate(instructions = [100, 200, 300, 400, 500, 500, 400, 300, 200, 100]) == 5\n assert candidate(instructions = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 95000, 92500, 90000, 87500, 85000, 82500, 80000, 77500, 75000, 72500]) == 52\n assert candidate(instructions = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1]) == 0\n assert candidate(instructions = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10]) == 12\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(instructions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 100000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 32\n", "comparison": "exact"}, "public_tests": ["[1,5,6,2]", "[1,2,3,6,5,4]", "[1,3,3,3,2,4,2,1,2]"], "hints": ["This problem is closely related to finding the number of inversions in an array", "if i know the position in which i will insert the i-th element in I can find the minimum cost to insert it"], "metadata": {"canonical_parameter_names": ["instructions"], "leetcode_dataset_entry_point": "Solution().createSortedArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:26+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "divide-and-conquer", "binary-indexed-tree", "segment-tree", "merge-sort", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function createSortedArray($instructions) {", "container": "Solution", "callable": "createSortedArray", "parameters": [{"name": "instructions", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1652, "task_id": "defuse-the-bomb", "difficulty": "Easy", "problem_description": "You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k.\n\nTo decrypt the code, you must replace every number. All the numbers are replaced simultaneously.\n\n- If k > 0, replace the i^th number with the sum of the next k numbers.\n- If k < 0, replace the i^th number with the sum of the previous -k numbers.\n- If k == 0, replace the i^th number with 0.\n\nAs code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].\n\nGiven the circular array code and an integer key k, return the decrypted code to defuse the bomb!\n\nExample 1:\n\nInput: code = [5,7,1,4], k = 3\nOutput: [12,10,16,13]\nExplanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.\n\nExample 2:\n\nInput: code = [1,2,3,4], k = 0\nOutput: [0,0,0,0]\nExplanation: When k is zero, the numbers are replaced by 0.\n\nExample 3:\n\nInput: code = [2,4,9,3], k = -2\nOutput: [12,5,6,13]\nExplanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.\n\nConstraints:\n\n- n == code.length\n- 1 <= n <= 100\n- 1 <= code[i] <= 100\n- -(n - 1) <= k <= n - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(code = [7, 8, 9],k = 1) == [8, 9, 7]\n assert candidate(code = [6, 5, 4, 3, 2, 1],k = -1) == [1, 6, 5, 4, 3, 2]\n assert candidate(code = [1, 1, 1, 1, 1],k = -1) == [1, 1, 1, 1, 1]\n assert candidate(code = [5, 7, 1, 4],k = 3) == [12, 10, 16, 13]\n assert candidate(code = [8, 6, 4, 2],k = -3) == [12, 14, 16, 18]\n assert candidate(code = [6, 5, 4, 3, 2, 1],k = -3) == [6, 9, 12, 15, 12, 9]\n assert candidate(code = [2, 4, 9, 3],k = -2) == [12, 5, 6, 13]\n assert candidate(code = [10, 20, 30, 40, 50],k = -1) == [50, 10, 20, 30, 40]\n assert candidate(code = [3, 3, 3, 3],k = 1) == [3, 3, 3, 3]\n assert candidate(code = [5, 5, 5, 5, 5],k = -1) == [5, 5, 5, 5, 5]\n assert candidate(code = [10, 20, 30, 40, 50],k = 2) == [50, 70, 90, 60, 30]\n assert candidate(code = [15, 20, 25],k = 0) == [0, 0, 0]\n assert candidate(code = [1, 2, 3, 4],k = 0) == [0, 0, 0, 0]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = -3) == [6, 12, 18, 24, 21, 18, 15, 12, 9]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = -5) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(code = [3, 3, 3, 3],k = 0) == [0, 0, 0, 0]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 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) == [410, 400, 390, 380, 370, 360, 350, 340, 330, 320, 310, 300, 290, 280, 270, 260, 250, 240, 230, 220, 210, 230, 250, 270, 290, 310, 330, 350, 370, 390]\n assert candidate(code = [7, 14, 21, 28, 35, 42],k = 3) == [63, 84, 105, 84, 63, 42]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = -4) == [170, 140, 110, 80, 50, 70, 90, 110, 130, 150]\n assert candidate(code = [50, 40, 30, 20, 10],k = -4) == [100, 110, 120, 130, 140]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == [20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 75, 60, 45, 30, 15]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = -18) == [396, 392, 388, 384, 380, 376, 372, 368, 364, 360, 356, 352, 348, 344, 340, 336, 332, 328, 324, 360]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == [14, 18, 22, 26, 30, 34, 28, 22, 16, 10]\n assert candidate(code = [7, 8, 9, 10, 11, 12, 13, 14, 15],k = -4) == [54, 49, 44, 39, 34, 38, 42, 46, 50]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == [5, 7, 9, 11, 13, 15, 17, 19, 11, 3]\n assert candidate(code = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == [450, 460, 470, 480, 490, 500, 510, 520, 530, 540]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 5) == [35, 45, 55, 65, 75, 85, 95, 81, 67, 53, 39, 25]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = -10) == [105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 65, 75, 85, 95]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == [20, 25, 30, 35, 40, 35, 30, 25, 20, 15]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 3) == [45, 60, 75, 90, 105, 120, 135, 100, 65, 30]\n assert candidate(code = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = -5) == [80, 70, 60, 50, 40, 30, 40, 50, 60, 70]\n assert candidate(code = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26],k = -6) == [126, 112, 98, 84, 70, 56, 42, 54, 66, 78, 90, 102, 114]\n assert candidate(code = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == [540, 530, 520, 510, 500, 490, 480, 470, 460, 450]\n assert candidate(code = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == [140, 180, 220, 260, 300, 340, 280, 220, 160, 100]\n assert candidate(code = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 3) == [240, 210, 180, 150, 120, 90, 60, 130, 200, 270]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(code = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = -5) == [150, 200, 250, 300, 350, 400, 350, 300, 250, 200]\n assert candidate(code = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 0) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = -2) == [3, 10, 17, 15, 13, 11, 9, 7, 5]\n assert candidate(code = [7, 14, 21, 28, 35],k = -4) == [98, 91, 84, 77, 70]\n assert candidate(code = [9, 18, 27, 36, 45, 54, 63, 72, 81],k = 6) == [243, 297, 351, 324, 297, 270, 243, 216, 189]\n assert candidate(code = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = -4) == [34, 28, 22, 16, 10, 14, 18, 22, 26, 30]\n assert candidate(code = [10, 20, 30, 40, 50],k = 2) == [50, 70, 90, 60, 30]\n assert candidate(code = [97, 98, 99, 100],k = -1) == [100, 97, 98, 99]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 19) == [1045, 1040, 1035, 1030, 1025, 1020, 1015, 1010, 1005, 1000, 995, 990, 985, 980, 975, 970, 965, 960, 955, 950]\n assert candidate(code = [10, 20, 30, 40, 50],k = 4) == [140, 130, 120, 110, 100]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 19) == [19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = -2) == [3, 10, 17, 15, 13, 11, 9, 7, 5]\n assert candidate(code = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == [350, 300, 250, 200, 150, 200, 250, 300, 350, 400]\n assert candidate(code = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = -4) == [102, 84, 66, 48, 30, 42, 54, 66, 78, 90]\n assert candidate(code = [10, 20, 30, 40, 50],k = -2) == [90, 60, 30, 50, 70]\n assert candidate(code = [26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12],k = -9) == [144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 189, 180, 171, 162, 153]\n assert candidate(code = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = -5) == [150, 200, 250, 300, 350, 400, 350, 300, 250, 200]\n assert candidate(code = [3, 6, 9, 12, 15, 18, 21, 24, 27],k = -4) == [90, 75, 60, 45, 30, 42, 54, 66, 78]\n assert candidate(code = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 7) == [75, 95, 119, 114, 106, 98, 88, 80, 70, 58]\n assert candidate(code = [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],k = -20) == [1690, 1695, 1700, 1705, 1710, 1715, 1720, 1725, 1730, 1735, 1740, 1745, 1750, 1755, 1760, 1765, 1770, 1775, 1780, 1785, 1790, 1770, 1750, 1730, 1710]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40],k = 7) == [175, 170, 165, 160, 155, 150, 145, 140]\n assert candidate(code = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],k = 8) == [124, 132, 140, 148, 156, 164, 172, 165, 158, 151, 144, 137, 130, 123, 116]\n assert candidate(code = [100, 100, 100, 100, 100, 100, 100, 100],k = 3) == [300, 300, 300, 300, 300, 300, 300, 300]\n assert candidate(code = [50, 40, 30, 20, 10],k = 0) == [0, 0, 0, 0, 0]\n assert candidate(code = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = -5) == [400, 350, 300, 250, 200, 150, 200, 250, 300, 350]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(code = [31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],k = -8) == [77, 89, 101, 111, 119, 129, 137, 145, 150, 124, 98]\n assert candidate(code = [23, 45, 12, 67, 34, 89, 23, 56, 78, 90, 12, 34, 56, 78, 90, 23, 45, 67, 89, 10],k = 10) == [506, 495, 539, 550, 606, 540, 562, 573, 584, 504, 515, 526, 482, 471, 415, 481, 459, 448, 437, 517]\n assert candidate(code = [11, 22, 33, 44, 55, 66],k = 0) == [0, 0, 0, 0, 0, 0]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13],k = 4) == [24, 32, 40, 34, 28, 22, 16]\n assert candidate(code = [30, 20, 10, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = -5) == [35, 60, 74, 77, 74, 66, 38, 21, 15, 15, 20, 25, 30]\n assert candidate(code = [9, 1, 2, 3, 4, 5, 6, 7, 8, 10],k = 4) == [10, 14, 18, 22, 26, 31, 34, 28, 22, 15]\n assert candidate(code = [3, 6, 9, 12, 15, 18, 21],k = -2) == [39, 24, 9, 15, 21, 27, 33]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40],k = -4) == [130, 110, 90, 70, 50, 70, 90, 110]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == [26, 22, 18, 14, 10, 15, 20, 25, 30]\n assert candidate(code = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 19) == [418, 416, 414, 412, 410, 408, 406, 404, 402, 400, 398, 396, 394, 392, 390, 388, 386, 384, 382, 380]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40],k = 5) == [100, 125, 150, 135, 120, 105, 90, 75]\n assert candidate(code = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == [200, 250, 300, 350, 400, 350, 300, 250, 200, 150]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 9) == [99, 117, 135, 153, 171, 189, 207, 225, 243, 261, 279, 257, 235, 213, 191, 169, 147, 125, 103, 81]\n assert candidate(code = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = -7) == [455, 425, 395, 365, 335, 305, 275, 245, 315, 385]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == [36, 37, 38, 39, 40, 41, 42, 43, 44]\n assert candidate(code = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = -15) == [390, 380, 370, 360, 350, 340, 330, 320, 310, 300, 290, 280, 270, 260, 250, 240, 270, 300, 330, 360]\n assert candidate(code = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == [20, 21, 23, 27, 25, 21, 22, 17, 16, 14, 14]\n assert candidate(code = [50, 40, 30, 20, 10],k = -2) == [30, 60, 90, 70, 50]\n assert candidate(code = [5, 10, 15, 20, 25, 30, 35, 40],k = 0) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(code = [7, 14, 21, 28, 35, 42, 49],k = -3) == [126, 98, 70, 42, 63, 84, 105]\n assert candidate(code = [7, 14, 21, 28, 35, 42],k = -5) == [140, 133, 126, 119, 112, 105]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 6) == [48, 60, 72, 84, 96, 108, 96, 84, 72, 60, 48, 36]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == [15, 13, 11, 9, 7, 5, 3, 10, 17]\n assert candidate(code = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],k = 7) == [70, 84, 98, 112, 104, 96, 88, 80, 72, 64, 56]\n assert candidate(code = [10, 20, 30, 40, 50, 60],k = 2) == [50, 70, 90, 110, 70, 30]\n assert candidate(code = [23, 45, 12, 67, 34, 89, 23, 56, 78, 90, 12, 34, 56, 78, 90, 23, 45, 67, 89, 10],k = -10) == [504, 515, 526, 482, 471, 415, 481, 459, 448, 437, 517, 506, 495, 539, 550, 606, 540, 562, 573, 584]\n assert candidate(code = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 5) == [485, 480, 475, 470, 465, 470, 475, 480, 485, 490]\n assert candidate(code = [7, 14, 21, 28, 35, 42, 49],k = 3) == [63, 84, 105, 126, 98, 70, 42]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = -5) == [95, 81, 67, 53, 39, 25, 35, 45, 55, 65, 75, 85]\n assert candidate(code = [21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],k = -8) == [64, 70, 76, 82, 88, 94, 100, 106, 112, 96, 80]\n assert candidate(code = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 7) == [63, 77, 91, 105, 97, 89, 81, 73, 65, 57, 49]\n assert candidate(code = [23, 17, 15, 9, 2],k = 1) == [17, 15, 9, 2, 23]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 9) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(code = [3, 6, 9, 12, 15, 18, 21, 24],k = -2) == [45, 27, 9, 15, 21, 27, 33, 39]\n assert candidate(code = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = -19) == [19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]\n assert candidate(code = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = -4) == [10, 15, 20, 25, 30, 26, 22, 18, 14]\n", "comparison": "exact"}, "public_tests": ["[5,7,1,4]\n3", "[1,2,3,4]\n0", "[2,4,9,3]\n-2"], "hints": ["As the array is circular, use modulo to find the correct index.", "The constraints are low enough for a brute-force solution."], "metadata": {"canonical_parameter_names": ["code", "k"], "leetcode_dataset_entry_point": "Solution().decrypt", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:28+00:00", "tests_total": 119, "tests_dropped": 19, "flags": [], "topic_tags": ["array", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function decrypt($code, $k) {", "container": "Solution", "callable": "decrypt", "parameters": [{"name": "code", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1653, "task_id": "minimum-deletions-to-make-string-balanced", "difficulty": "Medium", "problem_description": "You are given a string s consisting only of characters 'a' and 'b'.\n\nYou can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.\n\nReturn the minimum number of deletions needed to make s balanced.\n\nExample 1:\n\nInput: s = \"aababbab\"\nOutput: 2\nExplanation: You can either:\nDelete the characters at 0-indexed positions 2 and 6 (\"aababbab\" -> \"aaabbb\"), or\nDelete the characters at 0-indexed positions 3 and 6 (\"aababbab\" -> \"aabbbb\").\n\nExample 2:\n\nInput: s = \"bbaaaaabb\"\nOutput: 2\nExplanation: The only solution is to delete the first two characters.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s[i] is 'a' or 'b'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaaaabbbb\") == 0\n assert candidate(s = \"bbbaaaaa\") == 3\n assert candidate(s = \"bbbaaaaabbbb\") == 3\n assert candidate(s = \"aabbaa\") == 2\n assert candidate(s = \"abababab\") == 3\n assert candidate(s = \"aaaaa\") == 0\n assert candidate(s = \"aabbaabb\") == 2\n assert candidate(s = \"aababbaa\") == 3\n assert candidate(s = \"baabbaab\") == 3\n assert candidate(s = \"abababa\") == 3\n assert candidate(s = \"aabbaaab\") == 2\n assert candidate(s = \"aabbbbbaa\") == 2\n assert candidate(s = \"bbaabb\") == 2\n assert candidate(s = \"babababababababab\") == 8\n assert candidate(s = \"bbbbb\") == 0\n assert candidate(s = \"bababab\") == 3\n assert candidate(s = \"aababbab\") == 2\n assert candidate(s = \"ababababa\") == 4\n assert candidate(s = \"baabbaabba\") == 4\n assert candidate(s = \"bbaaaaabb\") == 2\n assert candidate(s = \"bbbbaaaa\") == 4\n assert candidate(s = \"aabbaaabbbaaabbb\") == 5\n assert candidate(s = \"baababababa\") == 5\n assert candidate(s = \"aaaa\") == 0\n assert candidate(s = \"bbbb\") == 0\n assert candidate(s = \"bbaabbaabbaa\") == 6\n assert candidate(s = \"aabbaaabbbaa\") == 4\n assert candidate(s = \"baba\") == 2\n assert candidate(s = \"abbaaabbbbba\") == 3\n assert candidate(s = \"aabbabba\") == 2\n assert candidate(s = \"bbbbbaaaaa\") == 5\n assert candidate(s = \"bbabbaab\") == 3\n assert candidate(s = \"aaabbbba\") == 1\n assert candidate(s = \"aaaaaaaa\") == 0\n assert candidate(s = \"bbbbbbbb\") == 0\n assert candidate(s = \"baabaa\") == 2\n assert candidate(s = \"bbbbbaaaaaabbbbaaaaabbbbbbaaaabbbaaaaabbbb\") == 18\n assert candidate(s = \"aaaaaaaaaabbbaaabbbbaaaaaaaaa\") == 7\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\") == 0\n assert candidate(s = \"aaaaabbbbaaaaabbbb\") == 4\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababababababababababab\") == 53\n assert candidate(s = \"babababababababa\") == 8\n assert candidate(s = \"abbbbbaaaabbbab\") == 5\n assert candidate(s = \"abbbabbaabbbaabaaabababbbaaabbbaaaabbbabbbaaabbabbaabbaabaabbabbaabbabbaabbbaabb\") == 36\n assert candidate(s = \"abbbbbaaaabbbb\") == 4\n assert candidate(s = \"abababababababa\") == 7\n assert candidate(s = \"bbbbaaaaabbbbbbbba\") == 5\n assert candidate(s = \"aaaaaaaaaabbbabb\") == 1\n assert candidate(s = \"bababababababababab\") == 9\n assert candidate(s = \"ababababaababababa\") == 8\n assert candidate(s = \"baabbabababaabbabababaabbabababaabb\") == 16\n assert candidate(s = \"bbbbbbaaaaaa\") == 6\n assert candidate(s = \"bbbbbbaaaaaabbbb\") == 6\n assert candidate(s = \"aaaabbbaaaaabbbb\") == 3\n assert candidate(s = \"aaaaabbbbbbbbbaaaa\") == 4\n assert candidate(s = \"abbaabbaabbaabbaabbaabba\") == 11\n assert candidate(s = \"baabbaabbaabbaabba\") == 8\n assert candidate(s = \"baaaabbbbaaabbbbaaaaabbbbbaaaaaabbbbbbaaaaabbbbbaaaaaabbbbbbaaaaabbbbbaaaaaabbbbbbaaaaabbbbbaaaaaabbbbbbaaaaabbbbbaaaaaabbbbbbaaaaabb\") == 63\n assert candidate(s = \"baaabbaaabbaabab\") == 6\n assert candidate(s = \"abababababababababababababababababababababababababababababababab\") == 31\n assert candidate(s = \"abbbabbbabbbabbbabbbabbbabbbabbbab\") == 8\n assert candidate(s = \"baaaababababbbabba\") == 6\n assert candidate(s = \"abbbabaaaababbbaaaabbaaababbabaaaabbabaaaaabaa\") == 18\n assert candidate(s = \"bbbbbaaaaabbbbbaaaa\") == 9\n assert candidate(s = \"abababababbababb\") == 6\n assert candidate(s = \"bababababababababababababababababababa\") == 19\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbbbb\") == 0\n assert candidate(s = \"bbbbabbaaababbaaababbaaababbaaababbaaab\") == 18\n assert candidate(s = \"bbbbbbbbbaaaaaaaaa\") == 9\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbbbbaaaaaaabbbbaaaaaaa\") == 14\n assert candidate(s = \"aaaaaabbbbbbaaaaaaabbbbbaaaaabbbbb\") == 11\n assert candidate(s = \"aaabbaabbaabbaabbaabbaabbaabbaabbaa\") == 16\n assert candidate(s = \"baaaaaabbbbbbb\") == 1\n assert candidate(s = \"bbbbbaaaabbbbaaabbbbaa\") == 9\n assert candidate(s = \"aabbbbaaaabbbbbb\") == 4\n assert candidate(s = \"aababbabbaababba\") == 6\n assert candidate(s = \"bbaabbabbaabbabbaa\") == 8\n assert candidate(s = \"abababbababababa\") == 7\n assert candidate(s = \"aabbaaababababba\") == 6\n assert candidate(s = \"aabbaabbaabbaabb\") == 6\n assert candidate(s = \"aaaaaabbbbbbaaabbb\") == 3\n assert candidate(s = \"bbbbbaaaaaabbbbbbaaaaaaabbbbbbbaaaaaaaaa\") == 18\n assert candidate(s = \"bbbaaabbaaabbaabbaaabbaaabbaabbaabbaa\") == 17\n assert candidate(s = \"bbaababbabababbababaababababababaababababababaababababababaababababababaababababababaabababaabababa\") == 47\n assert candidate(s = \"bbaaaaabaaaaabaaaaabaaaaabaaaaabaaaa\") == 7\n assert candidate(s = \"aabbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaaabbbaa\") == 25\n assert candidate(s = \"abbaabbaabbaabba\") == 7\n assert candidate(s = \"bbbbbbbaaaabbbbbbbaa\") == 6\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbaabbbbaaaaaaaaa\") == 11\n assert candidate(s = \"bbabbababbaaab\") == 6\n assert candidate(s = \"bababababa\") == 5\n assert candidate(s = \"ababababababab\") == 6\n assert candidate(s = \"aabbbabbbabbbabbbabba\") == 5\n assert candidate(s = \"abababababab\") == 5\n assert candidate(s = \"ababababababababab\") == 8\n assert candidate(s = \"bbbbbaaaaabbbbb\") == 5\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaa\") == 17\n assert candidate(s = \"aaaaaaaaaabbbbbb\") == 0\n assert candidate(s = \"baaaaaaaaaaaaaaaaaab\") == 1\n assert candidate(s = \"bbbbaaaabaaaab\") == 5\n assert candidate(s = \"baaaaaabbbbb\") == 1\n assert candidate(s = \"bbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 21\n assert candidate(s = \"bbbbbbbbbaaaaaa\") == 6\n assert candidate(s = \"aaaaaaaaabbbbbbbbbbbaa\") == 2\n assert candidate(s = \"bbbbbaaaaabbaaab\") == 7\n assert candidate(s = \"abbaababbaababbaababbaababbaababbaabab\") == 18\n assert candidate(s = \"aaaaaabbbbbbaaaaaabbbbbbaaaaaabbbbbb\") == 12\n assert candidate(s = \"bbbbaaaabbbbba\") == 5\n assert candidate(s = \"bbbbbbbbbaaaabbb\") == 4\n assert candidate(s = \"baababababaabbaa\") == 7\n assert candidate(s = \"aaaaaaaaaabbbbba\") == 1\n assert candidate(s = \"aabbaaabbaaabbaaabbaaabbaaabbaaabbaaabbb\") == 14\n assert candidate(s = \"abababababababababab\") == 9\n assert candidate(s = \"aaaaabbbbaaaaabbbbbaaa\") == 7\n assert candidate(s = \"aaaaaaaaaabbbaaaaaaaaa\") == 3\n assert candidate(s = \"aababababababababa\") == 8\n assert candidate(s = \"bababababababa\") == 7\n assert candidate(s = \"babbaabbbaabbaabbbaabbaabbbaabbaabba\") == 16\n assert candidate(s = \"aaabbaabbaabbbbb\") == 4\n assert candidate(s = \"aabbaaabbbabbaaabb\") == 6\n assert candidate(s = \"bbbbbbbbbaaaaaaaaaaa\") == 9\n assert candidate(s = \"aaabbbbaaaaabba\") == 5\n assert candidate(s = \"baaaaaabbaaabbbaaa\") == 6\n assert candidate(s = \"bbbaaaaabbbaaaa\") == 6\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbb\") == 0\n assert candidate(s = \"aabbaabbbaaabb\") == 5\n assert candidate(s = \"babababababababababa\") == 10\n assert candidate(s = \"bababababababababababababababab\") == 15\n assert candidate(s = \"baaababbababab\") == 5\n assert candidate(s = \"baabababababababababab\") == 10\n assert candidate(s = \"bbbbbbbbbaaaaaaaaaa\") == 9\n assert candidate(s = \"bbbbbbbbbaaaaa\") == 5\n assert candidate(s = \"bbbbbbbbbbbbbaaaaaaaaa\") == 9\n assert candidate(s = \"baaaaaabbbbbbbaaaaaaaaaabbbbbbbaaaaaaaaaaabbbbbbbaaaaaaaaaaabbbbbbbaaaaaaaaaa\") == 29\n assert candidate(s = \"baaaaaabbbbbbbbba\") == 2\n assert candidate(s = \"abbaabbaabbaabbaab\") == 8\n assert candidate(s = \"babbabbabbabbabbabba\") == 7\n assert candidate(s = \"aababababababababababababababababababababababa\") == 22\n assert candidate(s = \"bbbbbaaaaabbbb\") == 5\n assert candidate(s = \"baabababaabababa\") == 7\n assert candidate(s = \"aaaaabbbbbabbbbb\") == 1\n assert candidate(s = \"babababababababaab\") == 8\n assert candidate(s = \"bbbbbbbbbaaaaaaabbbbbbbbbaaaaaaa\") == 14\n assert candidate(s = \"aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == 0\n assert candidate(s = \"bbbbaaaaabbaaabb\") == 6\n assert candidate(s = \"aaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaa\") == 36\n assert candidate(s = \"bbbbbbaaabaaabbaab\") == 8\n assert candidate(s = \"aabbaabbbaabba\") == 5\n assert candidate(s = \"abbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\") == 46\n assert candidate(s = \"abbaabbaabba\") == 5\n assert candidate(s = \"baaabbbbaaabbbbaaabbbbaaabbbbaaabbb\") == 13\n assert candidate(s = \"aaaaaaaaaabbbbbbaa\") == 2\n assert candidate(s = \"aabbaaabbaabbaa\") == 6\n assert candidate(s = \"ababbababbabab\") == 5\n assert candidate(s = \"bbbbbaaabbaabb\") == 5\n assert candidate(s = \"abababababababababa\") == 9\n assert candidate(s = \"babbbbbaaabbbbaabb\") == 6\n assert candidate(s = \"bbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa\") == 20\n assert candidate(s = \"abbbbaaababaaaabbaaabaaabbaaaabbbaaabbaaaabbaaabbaaabbbbaaaaa\") == 24\n assert candidate(s = \"bbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa\") == 26\n assert candidate(s = \"bbaaabbaaabbaaabbaaabbaaabbaaabbaaab\") == 14\n assert candidate(s = \"aaabbbaaababba\") == 5\n assert candidate(s = \"ababababab\") == 4\n assert candidate(s = \"aaaaabbbbaaaabbbba\") == 5\n assert candidate(s = \"bbbbaaaaabbaaaab\") == 6\n assert candidate(s = \"aabbaaabbaaabbaaabbaa\") == 8\n assert candidate(s = \"bbbbbbaaabbbbaaaa\") == 7\n assert candidate(s = \"bbbbbaaaaaaaaaaa\") == 5\n assert candidate(s = \"baabaaabbaabaaabbaabaa\") == 8\n assert candidate(s = \"aabbbbbbaabbaaaabb\") == 6\n assert candidate(s = \"aababbbaaababbab\") == 6\n assert candidate(s = \"bbbbabbbbbaaaaa\") == 6\n assert candidate(s = \"bbaaaaaaaaaabbbbaaaabbbba\") == 7\n assert candidate(s = \"aabbaabbabbaabbabbbaaabbaa\") == 11\n assert candidate(s = \"aaaaaaaaaabbbaaa\") == 3\n assert candidate(s = \"aaaaaaaaaabbbaaaabbbbbaaabbbbaaabbbbbaaa\") == 12\n assert candidate(s = \"babababaabab\") == 5\n assert candidate(s = \"bbbbbbbbbaaaaabbbb\") == 5\n assert candidate(s = \"aabbaaabbbaaabbbaaabbbaaabbaa\") == 13\n assert candidate(s = \"aaaabababababbbbba\") == 5\n assert candidate(s = \"aaabbaaabbaaabba\") == 5\n assert candidate(s = \"bbbbbbaaaaaabbbbaaa\") == 9\n assert candidate(s = \"bbbbbbbbaaaaabaaaaabbaaaabbaaaabbbaaaabbbbbbb\") == 16\n assert candidate(s = \"baaaaabbbbaaaaabba\") == 6\n assert candidate(s = \"abababaabababaab\") == 6\n assert candidate(s = \"bbbaaabbaaabbaab\") == 7\n assert candidate(s = \"aaaabaaaabaaaa\") == 2\n assert candidate(s = \"ababababababababababababababababababab\") == 18\n assert candidate(s = \"bbabbbbaaabbbbaaab\") == 7\n assert candidate(s = \"abbaabbaabbbaabb\") == 6\n", "comparison": "exact"}, "public_tests": ["\"aababbab\"", "\"bbaaaaabb\""], "hints": ["You need to find for every index the number of Bs before it and the number of A's after it", "You can speed up the finding of A's and B's in suffix and prefix using preprocessing"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:30+00:00", "tests_total": 190, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "stack"]}, "language": "php", "interface": {"raw_signature": "function minimumDeletions($s) {", "container": "Solution", "callable": "minimumDeletions", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1654, "task_id": "minimum-jumps-to-reach-home", "difficulty": "Medium", "problem_description": "A certain bug's home is on the x-axis at position x. Help them get there from position 0.\n\nThe bug jumps according to the following rules:\n\n- It can jump exactly a positions forward (to the right).\n- It can jump exactly b positions backward (to the left).\n- It cannot jump backward twice in a row.\n- It cannot jump to any forbidden positions.\n\nThe bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.\n\nGiven an array of integers forbidden, where forbidden[i] means that the bug cannot jump to the position forbidden[i], and integers a, b, and x, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x, return -1.\n\nExample 1:\n\nInput: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\nOutput: 3\nExplanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.\n\nExample 2:\n\nInput: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\nOutput: -1\n\nExample 3:\n\nInput: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\nOutput: 2\nExplanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.\n\nConstraints:\n\n- 1 <= forbidden.length <= 1000\n- 1 <= a, b, forbidden[i] <= 2000\n- 0 <= x <= 2000\n- All the elements in forbidden are distinct.\n- Position x is not forbidden.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(forbidden = [2, 4, 6, 8, 10],a = 2,b = 1,x = 1) == -1\n assert candidate(forbidden = [5, 6, 7],a = 1,b = 1,x = 10) == -1\n assert candidate(forbidden = [1, 6, 2, 14, 5, 17, 4],a = 16,b = 9,x = 7) == 2\n assert candidate(forbidden = [8, 3, 16, 6, 12, 20],a = 15,b = 13,x = 11) == -1\n assert candidate(forbidden = [14, 4, 18, 1, 15],a = 3,b = 15,x = 9) == 3\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],a = 3,b = 5,x = 20) == -1\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],a = 1,b = 3,x = 50) == -1\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],a = 1,b = 2,x = 25) == -1\n assert candidate(forbidden = [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],a = 2,b = 4,x = 58) == 29\n assert candidate(forbidden = [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],a = 5,b = 10,x = 195) == -1\n assert candidate(forbidden = [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],a = 2,b = 1,x = 51) == -1\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],a = 2,b = 4,x = 41) == -1\n assert candidate(forbidden = [200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000],a = 100,b = 50,x = 1950) == 21\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],a = 2,b = 3,x = 20) == 10\n assert candidate(forbidden = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900],a = 100,b = 200,x = 1999) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],a = 10,b = 20,x = 210) == -1\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],a = 2,b = 1,x = 21) == 12\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],a = 1,b = 2,x = 21) == -1\n assert candidate(forbidden = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],a = 100,b = 50,x = 1000) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],a = 10,b = 5,x = 199) == -1\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],a = 2,b = 1,x = 28) == 14\n assert candidate(forbidden = [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519],a = 100,b = 50,x = 600) == 9\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],a = 10,b = 5,x = 210) == -1\n assert candidate(forbidden = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],a = 25,b = 50,x = 600) == -1\n assert candidate(forbidden = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],a = 15,b = 25,x = 100) == -1\n assert candidate(forbidden = [1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990],a = 1,b = 2,x = 2000) == -1\n assert candidate(forbidden = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1500],a = 250,b = 125,x = 2000) == 11\n assert candidate(forbidden = [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],a = 2,b = 4,x = 50) == 25\n assert candidate(forbidden = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],a = 5,b = 3,x = 20) == -1\n assert candidate(forbidden = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],a = 100,b = 50,x = 1001) == -1\n assert candidate(forbidden = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],a = 3,b = 6,x = 63) == -1\n assert candidate(forbidden = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],a = 10,b = 5,x = 195) == 21\n assert candidate(forbidden = [199, 399, 599, 799, 999, 1199, 1399, 1599, 1799, 1999],a = 200,b = 100,x = 1998) == -1\n assert candidate(forbidden = [500, 1000, 1500],a = 100,b = 50,x = 2000) == 23\n assert candidate(forbidden = [2000],a = 1000,b = 500,x = 1500) == 3\n assert candidate(forbidden = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],a = 10,b = 5,x = 200) == 20\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],a = 2,b = 4,x = 30) == -1\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],a = 1,b = 2,x = 25) == -1\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],a = 2,b = 4,x = 21) == -1\n assert candidate(forbidden = [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],a = 5,b = 3,x = 140) == -1\n assert candidate(forbidden = [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],a = 5,b = 10,x = 135) == -1\n assert candidate(forbidden = [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],a = 50,b = 100,x = 350) == -1\n assert candidate(forbidden = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],a = 100,b = 200,x = 1500) == -1\n assert candidate(forbidden = [5, 15, 25, 35, 45],a = 10,b = 5,x = 100) == 10\n assert candidate(forbidden = [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],a = 3,b = 9,x = 88) == -1\n assert candidate(forbidden = [100, 150, 200, 250, 300],a = 50,b = 20,x = 180) == 5\n assert candidate(forbidden = [101, 201, 301, 401, 501, 601, 701, 801, 901, 1001, 1101, 1201, 1301, 1401, 1501, 1601, 1701, 1801, 1901],a = 100,b = 50,x = 1899) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],a = 10,b = 5,x = 195) == -1\n assert candidate(forbidden = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],a = 2,b = 4,x = 20) == 10\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],a = 1,b = 2,x = 31) == -1\n assert candidate(forbidden = [150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500, 1650, 1800, 1950],a = 150,b = 100,x = 1000) == -1\n assert candidate(forbidden = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597],a = 7,b = 5,x = 400) == 64\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],a = 1,b = 3,x = 21) == -1\n assert candidate(forbidden = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],a = 20,b = 10,x = 199) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50],a = 5,b = 10,x = 15) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],a = 10,b = 20,x = 200) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],a = 10,b = 5,x = 210) == -1\n assert candidate(forbidden = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],a = 5,b = 10,x = 105) == -1\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],a = 2,b = 1,x = 19) == -1\n assert candidate(forbidden = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],a = 5,b = 3,x = 48) == -1\n assert candidate(forbidden = [3, 6, 9, 12, 15, 18, 21, 24, 27],a = 3,b = 2,x = 30) == -1\n assert candidate(forbidden = [300, 600, 900, 1200, 1500, 1800, 2000],a = 100,b = 200,x = 1900) == -1\n assert candidate(forbidden = [150, 300, 450, 600, 750, 900, 1050, 1200, 1350, 1500, 1650, 1800, 1950],a = 150,b = 75,x = 1995) == -1\n assert candidate(forbidden = [199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180],a = 1,b = 2,x = 175) == 175\n assert candidate(forbidden = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],a = 10,b = 5,x = 199) == -1\n assert candidate(forbidden = [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, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 175, 179, 183, 187, 191, 195, 199],a = 4,b = 8,x = 197) == -1\n assert candidate(forbidden = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],a = 2,b = 3,x = 50) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],a = 5,b = 10,x = 150) == -1\n assert candidate(forbidden = [50, 100, 150, 200],a = 50,b = 25,x = 200) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],a = 10,b = 5,x = 145) == -1\n assert candidate(forbidden = [100, 200, 300, 400, 500],a = 100,b = 200,x = 600) == -1\n assert candidate(forbidden = [10, 25, 40, 55, 70, 85, 100, 115, 130, 145, 160, 175, 190, 205, 220, 235, 250, 265, 280, 295],a = 15,b = 30,x = 290) == -1\n assert candidate(forbidden = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],a = 1,b = 1,x = 110) == -1\n assert candidate(forbidden = [10, 15, 20, 25, 30],a = 5,b = 10,x = 40) == -1\n assert candidate(forbidden = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],a = 5,b = 10,x = 55) == -1\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 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],a = 3,b = 1,x = 45) == -1\n assert candidate(forbidden = [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],a = 2,b = 4,x = 62) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],a = 10,b = 5,x = 185) == -1\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],a = 2,b = 1,x = 39) == -1\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],a = 1,b = 2,x = 21) == -1\n assert candidate(forbidden = [2, 5, 7, 10, 15, 20],a = 2,b = 4,x = 25) == -1\n assert candidate(forbidden = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119],a = 1,b = 1,x = 120) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90],a = 10,b = 5,x = 100) == -1\n assert candidate(forbidden = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],a = 10,b = 20,x = 105) == -1\n assert candidate(forbidden = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],a = 1,b = 2,x = 30) == -1\n assert candidate(forbidden = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],a = 2,b = 3,x = 42) == -1\n assert candidate(forbidden = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190],a = 10,b = 5,x = 195) == -1\n assert candidate(forbidden = [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],a = 10,b = 20,x = 299) == -1\n", "comparison": "exact"}, "public_tests": ["[14,4,18,1,15]\n3\n15\n9", "[8,3,16,6,12,20]\n15\n13\n11", "[1,6,2,14,5,17,4]\n16\n9\n7"], "hints": ["Think of the line as a graph", "to handle the no double back jumps condition you can handle it by holding the state of your previous jump"], "metadata": {"canonical_parameter_names": ["forbidden", "a", "b", "x"], "leetcode_dataset_entry_point": "Solution().minimumJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:32+00:00", "tests_total": 98, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "hash-table", "breadth-first-search"]}, "language": "php", "interface": {"raw_signature": "function minimumJumps($forbidden, $a, $b, $x) {", "container": "Solution", "callable": "minimumJumps", "parameters": [{"name": "forbidden", "type": "Integer[]"}, {"name": "a", "type": "Integer"}, {"name": "b", "type": "Integer"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1655, "task_id": "distribute-repeating-integers", "difficulty": "Hard", "problem_description": "You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the i^th customer ordered. Determine if it is possible to distribute nums such that:\n\n- The i^th customer gets exactly quantity[i] integers,\n- The integers the i^th customer gets are all equal, and\n- Every customer is satisfied.\n\nReturn true if it is possible to distribute nums according to the above conditions.\n\nExample 1:\n\nInput: nums = [1,2,3,4], quantity = [2]\nOutput: false\nExplanation: The 0^th customer cannot be given two different integers.\n\nExample 2:\n\nInput: nums = [1,2,3,3], quantity = [2]\nOutput: true\nExplanation: The 0^th customer is given [3,3]. The integers [1,2] are not used.\n\nExample 3:\n\nInput: nums = [1,1,2,2], quantity = [2,2]\nOutput: true\nExplanation: The 0^th customer is given [1,1], and the 1st customer is given [2,2].\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- 1 <= nums[i] <= 1000\n- m == quantity.length\n- 1 <= m <= 10\n- 1 <= quantity[i] <= 10^5\n- There are at most 50 unique values in nums.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2],quantity = [2, 2]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],quantity = [3, 3]) == True\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],quantity = [3, 3, 3, 3, 3]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],quantity = [10, 10]) == True\n assert candidate(nums = [1, 1, 1, 1, 1],quantity = [5]) == True\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],quantity = [2, 2, 2, 2]) == True\n assert candidate(nums = [1, 2, 3, 4],quantity = [2]) == False\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],quantity = [4, 4, 4]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],quantity = [2, 2, 2]) == True\n assert candidate(nums = [1, 2, 3, 3],quantity = [2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],quantity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50],quantity = [2, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4],quantity = [3, 3, 3, 4]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],quantity = [3, 3, 3]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],quantity = [2, 2, 3, 4, 5]) == 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],quantity = [5, 5, 5]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 3],quantity = [2, 3]) == True\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],quantity = [10]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4],quantity = [3, 3, 3, 4]) == True\n assert candidate(nums = [1, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [2, 3, 3, 4, 4]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],quantity = [10, 10, 10, 10]) == True\n assert candidate(nums = [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],quantity = [5, 5, 5, 5]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 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, 8, 8, 8, 8, 8, 8],quantity = [3, 3, 3, 5, 5]) == True\n assert candidate(nums = [1, 1, 2, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [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, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],quantity = [5, 7, 4]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5],quantity = [7, 7, 7, 7]) == 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, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [10, 10, 10, 10]) == True\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, 3, 3, 3, 3, 3, 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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],quantity = [5, 5, 5, 5, 5, 5, 5]) == True\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],quantity = [2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 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],quantity = [10, 10, 10]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],quantity = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 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],quantity = [3, 3, 3, 3, 3, 3]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [3, 4, 5, 3]) == 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, 2, 2],quantity = [5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 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],quantity = [4, 6, 6, 8]) == True\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],quantity = [3, 3, 3, 3, 3]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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],quantity = [5, 5, 5, 10, 5]) == True\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, 7, 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],quantity = [2, 2, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],quantity = [4, 4, 4, 4]) == True\n assert candidate(nums = [1, 1, 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, 4],quantity = [2, 2, 2, 2, 2, 2, 2]) == 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],quantity = [15, 15, 15, 15]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10],quantity = [6, 6, 6, 6, 6]) == True\n assert candidate(nums = [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, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [10, 10, 10, 10, 10]) == 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],quantity = [5, 5, 5, 5]) == True\n assert candidate(nums = [1, 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, 6],quantity = [5, 5, 6]) == True\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10],quantity = [3, 3, 4, 4]) == True\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],quantity = [5, 5, 5, 5, 10]) == True\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],quantity = [3, 4, 5, 6]) == True\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],quantity = [10, 10, 10]) == 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],quantity = [10, 10, 10]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],quantity = [5, 5, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],quantity = [5, 5, 5, 5, 5]) == True\n assert candidate(nums = [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],quantity = [10, 10, 10, 10, 10]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 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, 4, 4, 4],quantity = [7, 7, 7, 5]) == True\n assert candidate(nums = [7, 7, 7, 7, 7, 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],quantity = [5, 5, 5, 5, 5]) == True\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],quantity = [2, 2, 3, 3, 3]) == True\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 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],quantity = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\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],quantity = [2, 2, 3, 3, 4]) == True\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50, 50],quantity = [2, 4, 6]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5],quantity = [3, 5, 4]) == True\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n[2]", "[1,2,3,3]\n[2]", "[1,1,2,2]\n[2,2]"], "hints": ["Count the frequencies of each number. For example, if nums = [4,4,5,5,5], frequencies = [2,3].", "Each customer wants all of their numbers to be the same. This means that each customer will be assigned to one number.", "Use dynamic programming. Iterate through the numbers' frequencies, and choose some subset of customers to be assigned to this number."], "metadata": {"canonical_parameter_names": ["nums", "quantity"], "leetcode_dataset_entry_point": "Solution().canDistribute", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:35+00:00", "tests_total": 62, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming", "backtracking", "bit-manipulation", "counting", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function canDistribute($nums, $quantity) {", "container": "Solution", "callable": "canDistribute", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "quantity", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1657, "task_id": "determine-if-two-strings-are-close", "difficulty": "Medium", "problem_description": "Two strings are considered close if you can attain one from the other using the following operations:\n\n- Operation 1: Swap any two existing characters.\n - For example, abcde -> aecdb\n- Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.\n - For example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)\n\nYou can use the operations on either string as many times as necessary.\n\nGiven two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.\n\nExample 1:\n\nInput: word1 = \"abc\", word2 = \"bca\"\nOutput: true\nExplanation: You can attain word2 from word1 in 2 operations.\nApply Operation 1: \"abc\" -> \"acb\"\nApply Operation 1: \"acb\" -> \"bca\"\n\nExample 2:\n\nInput: word1 = \"a\", word2 = \"aa\"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.\n\nExample 3:\n\nInput: word1 = \"cabbba\", word2 = \"abbccc\"\nOutput: true\nExplanation: You can attain word2 from word1 in 3 operations.\nApply Operation 1: \"cabbba\" -> \"caabbb\"\nApply Operation 2: \"caabbb\" -> \"baaccc\"\nApply Operation 2: \"baaccc\" -> \"abbccc\"\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 10^5\n- word1 and word2 contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"leetcode\",word2 = \"coeddlet\") == False\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == False\n assert candidate(word1 = \"aaabbbbccdddd\",word2 = \"bbbbaacdddd\") == False\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"ccbbaa\") == True\n assert candidate(word1 = \"abc\",word2 = \"bca\") == True\n assert candidate(word1 = \"abcabcabc\",word2 = \"bcbcbcbcb\") == False\n assert candidate(word1 = \"abcde\",word2 = \"edcba\") == True\n assert candidate(word1 = \"cabbba\",word2 = \"abbccc\") == True\n assert candidate(word1 = \"xyzz\",word2 = \"zzxy\") == True\n assert candidate(word1 = \"xyz\",word2 = \"zyx\") == True\n assert candidate(word1 = \"abcd\",word2 = \"abce\") == False\n assert candidate(word1 = \"aaabbbbcc\",word2 = \"bbbcccaaa\") == False\n assert candidate(word1 = \"uau\",word2 = \"ssx\") == False\n assert candidate(word1 = \"aaabbbbccddd\",word2 = \"bbbccdddcccc\") == False\n assert candidate(word1 = \"aabbbbccc\",word2 = \"bbcccaaaa\") == True\n assert candidate(word1 = \"abab\",word2 = \"baba\") == True\n assert candidate(word1 = \"aaabbbbcc\",word2 = \"aaaabbbcc\") == True\n assert candidate(word1 = \"a\",word2 = \"aa\") == False\n assert candidate(word1 = \"aab\",word2 = \"bba\") == True\n assert candidate(word1 = \"abcd\",word2 = \"dcba\") == True\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\") == False\n assert candidate(word1 = \"aaaabbbbccccdddd\",word2 = \"ddddeeeeffffgggg\") == False\n assert candidate(word1 = \"aaabbcccddeeefffggghhhhiiiii\",word2 = \"iiiiihhhgggfffeeedddcccbbaaa\") == False\n assert candidate(word1 = \"xyzxyzxyz\",word2 = \"zyxzyxzyx\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"bbacabadabacaba\") == False\n assert candidate(word1 = \"aaabbcccddddeeeeeffffffgggggghhhhhiiiijjjjkkkkklllllmmmmnnooooppqqrrsstttuuuuuvvvvvvvwwxxxxxyyyyzzzzz\",word2 = \"zzzzzyyyyxxxwwwvvvvvvuuuuutttssrrqqppoonnmmllkkjjiihhhgggfffddddccccbbbbaaa\") == False\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"ffeeddccbbaa\") == True\n assert candidate(word1 = \"aaabbbcccdddeeefff\",word2 = \"ffeeeedddcccbbbaaa\") == False\n assert candidate(word1 = \"mississippi\",word2 = \"ppissimissi\") == True\n assert candidate(word1 = \"abcdabcabcabcd\",word2 = \"dcbaababdcbaabab\") == False\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"bacabacababacab\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzxxyywwvvuuttssrrqqppoonnmmllkkjjiihhggffeeeeddccbbaa\") == False\n assert candidate(word1 = \"ppppoooonnnnmmmlllkkeeeeeddcccbbbaaa\",word2 = \"aaaaaaaaabbbbbbccccdddddeeeeeeeekkkkkklllllmmmmmmmnnnnnnnnoooooooooppppppp\") == False\n assert candidate(word1 = \"qqqwwwweeerrrttt\",word2 = \"tttwwweerrrqqq\") == False\n assert candidate(word1 = \"abcabcabc\",word2 = \"ccbbbaaa\") == False\n assert candidate(word1 = \"qwertypoiuytrewq\",word2 = \"poiuytrewqqwertypo\") == False\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(word1 = \"abcdefabcdefabcdef\",word2 = \"fedcbafedcbafedcba\") == True\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcba\") == True\n assert candidate(word1 = \"abcdefgh\",word2 = \"hgfedcba\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"cbacbacbcacbacb\") == False\n assert candidate(word1 = \"abcdefg\",word2 = \"gfedcba\") == True\n assert candidate(word1 = \"loooooonnnngggggwwwoooorrrrddddsssaaammmmeeeerrttttyyyyyyyyyyyynnnnnnnnnn\",word2 = \"nnnnnnnnnnyyyyyyyyyyyttttyyyyymmmeeraatttddddsssaaawwwggggnnnllllloooooo\") == False\n assert candidate(word1 = \"xylophone\",word2 = \"phonexylo\") == True\n assert candidate(word1 = \"abcdefghijklopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(word1 = \"abcdefabcabc\",word2 = \"abcabcabcdef\") == True\n assert candidate(word1 = \"aaaaabbbbcccccccdddddddd\",word2 = \"ddddddddcccccccbbbbaaaaa\") == True\n assert candidate(word1 = \"mnopqr\",word2 = \"rpqomn\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"ppiimssisss\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzyyxxwwvvuuttssrrqppoonnmlkkjjiihhggffeeeeddccbbaa\") == False\n assert candidate(word1 = \"anotherexample\",word2 = \"mpleaxarnothee\") == True\n assert candidate(word1 = \"aaaaabbbbbccccc\",word2 = \"bbbbbcccccaaaaa\") == True\n assert candidate(word1 = \"zzzzzzyyyxxx\",word2 = \"yyyxxxzzzzzy\") == False\n assert candidate(word1 = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"yzxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\") == False\n assert candidate(word1 = \"xyzxyzxyzxyzxyzxyzxyz\",word2 = \"zyxzyxzyxzyxzyxzyxzyxzyxzyx\") == False\n assert candidate(word1 = \"aabccddddeeeeefffffff\",word2 = \"eeeeeeffffffdddddcccbaaa\") == False\n assert candidate(word1 = \"mnopqr\",word2 = \"rstuvw\") == False\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == False\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"abcdeffedcba\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"abcdefghijklmnopqrstuvxyzmnopqrstuvwxyzabcdefg\") == False\n assert candidate(word1 = \"uniqueletters\",word2 = \"letterniquesu\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzxxyywwvvuuttssrrqqlloonnmmllkkjjiihhggeeddbbaa\") == False\n assert candidate(word1 = \"abcabcabcabcabcabcabcabcabcabc\",word2 = \"bcabacabcabacabcabacabcabacabcabac\") == False\n assert candidate(word1 = \"abcdefghijk\",word2 = \"abcdefghijl\") == False\n assert candidate(word1 = \"thisisatest\",word2 = \"esttasisthi\") == True\n assert candidate(word1 = \"qqwweerrttyyuuiiooppllaaassddffgg\",word2 = \"ggffddssaallooppuiiyyttreeewwqq\") == False\n assert candidate(word1 = \"abacabadaba\",word2 = \"dabacababad\") == False\n assert candidate(word1 = \"pneumonoultramicroscopicsilicovolcanoconiosis\",word2 = \"oconsinolpnacirosccvilcooimmutapernovulcrosmicn\") == False\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"cccbbbaaabbb\") == False\n assert candidate(word1 = \"leetcode\",word2 = \"codeleet\") == True\n assert candidate(word1 = \"z\",word2 = \"z\") == True\n assert candidate(word1 = \"aabbaa\",word2 = \"bbaabb\") == True\n assert candidate(word1 = \"aaabbbccc\",word2 = \"bbbaaacc\") == False\n assert candidate(word1 = \"transform\",word2 = \"rmorfnapt\") == False\n assert candidate(word1 = \"aaaabbbbccccddddeeeeeffffffgggggg\",word2 = \"ggggggffffffeeeeeeeeeccccbbbbaaaa\") == False\n assert candidate(word1 = \"abacabadabacabad\",word2 = \"badacabdacabad\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == True\n assert candidate(word1 = \"hello\",word2 = \"ollhe\") == True\n assert candidate(word1 = \"uniquestring\",word2 = \"stringunique\") == True\n assert candidate(word1 = \"abcdef\",word2 = \"gfedcb\") == False\n assert candidate(word1 = \"xyxyxyxyxyxyxyxyxyxy\",word2 = \"yyxyxyxyxyxyxyxyxyxxyx\") == False\n assert candidate(word1 = \"aaaaabbbbccccdddd\",word2 = \"ddddccccbbbbaaa\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(word1 = \"abcde\",word2 = \"fghij\") == False\n assert candidate(word1 = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",word2 = \"ddddccccbbbbaaaaaaddddccccbbbbaaaaaa\") == False\n assert candidate(word1 = \"aabbbcccc\",word2 = \"cccbbbaaa\") == False\n assert candidate(word1 = \"aabbccddeee\",word2 = \"eeeedddccbbbaaa\") == False\n assert candidate(word1 = \"thisisatest\",word2 = \"esttisita\") == False\n assert candidate(word1 = \"aaabbbcccddd\",word2 = \"ddddcccbbbbaaa\") == False\n assert candidate(word1 = \"abcdefghijabcdefghijabcdefghij\",word2 = \"abcdefghijabcdefghijabcdefghij\") == True\n assert candidate(word1 = \"zzzzzzzzzz\",word2 = \"zzzzzzzzzz\") == True\n assert candidate(word1 = \"abcdeabcde\",word2 = \"edcbaedcba\") == True\n assert candidate(word1 = \"abcdabcdabcdabcdabcdabcd\",word2 = \"dcbaabcdabcdabcdabcdabcd\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzzyyxwwvvuuttrrqqppoonnmmllkkiijjgghhffeeeeddccbbaa\") == False\n assert candidate(word1 = \"abcdexyz\",word2 = \"zyxwvuts\") == False\n assert candidate(word1 = \"qqwweerrttyyuuiiooppaassddffgg\",word2 = \"ggffddssaappoouuiittyyerrrwwqq\") == False\n assert candidate(word1 = \"abcdefg\",word2 = \"ghijklm\") == False\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzxxwwvvuuttssrrqqlloonnmmllkkjjiihhggeeddbbaa\") == False\n assert candidate(word1 = \"aaaabbbbccccddddeee\",word2 = \"eeedddccccbbbbaaaa\") == False\n assert candidate(word1 = \"abcdabcd\",word2 = \"dcbaabcd\") == True\n assert candidate(word1 = \"closestrings\",word2 = \"stringsclose\") == True\n assert candidate(word1 = \"aaaabbbbccccdddd\",word2 = \"ddddccccbbbbaaaa\") == True\n assert candidate(word1 = \"xyzzzz\",word2 = \"zzzzxy\") == True\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"bca\"", "\"a\"\n\"aa\"", "\"cabbba\"\n\"abbccc\""], "hints": ["Operation 1 allows you to freely reorder the string.", "Operation 2 allows you to freely reassign the letters' frequencies."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().closeStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:37+00:00", "tests_total": 106, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function closeStrings($word1, $word2) {", "container": "Solution", "callable": "closeStrings", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1658, "task_id": "minimum-operations-to-reduce-x-to-zero", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.\n\nReturn the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.\n\nExample 1:\n\nInput: nums = [1,1,4,2,3], x = 5\nOutput: 2\nExplanation: The optimal solution is to remove the last two elements to reduce x to zero.\n\nExample 2:\n\nInput: nums = [5,6,7,8,9], x = 4\nOutput: -1\n\nExample 3:\n\nInput: nums = [3,2,20,1,1,3], x = 10\nOutput: 5\nExplanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^4\n- 1 <= x <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],x = 15) == 5\n assert candidate(nums = [1, 1, 4, 2, 3],x = 5) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],x = 100) == 3\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000],x = 30000) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 10) == 10\n assert candidate(nums = [3, 2, 20, 1, 1, 3],x = 10) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],x = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1],x = 3) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 15) == 5\n assert candidate(nums = [2, 3, 1, 2, 4, 3],x = 7) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 11) == 2\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000],x = 50000) == 5\n assert candidate(nums = [5, 6, 7, 8, 9],x = 4) == -1\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],x = 25000) == 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],x = 15) == 10\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],x = 5000) == 5\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],x = 1400000) == -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],x = 10) == 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],x = 1000) == 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],x = 190) == 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],x = 190) == 15\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],x = 55000) == 10\n assert candidate(nums = [3, 5, 10, 7, 15, 1, 4, 2, 8, 6],x = 29) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 21) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 5) == 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],x = 95) == 15\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],x = 55000) == 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],x = 30) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 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],x = 55) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 15) == 4\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],x = 15) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 85) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 100) == -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],x = 10) == 10\n assert candidate(nums = [1, 2, 3, 4, 5],x = 15) == 5\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],x = 35000) == 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],x = 10) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 50) == 50\n assert candidate(nums = [3, 2, 20, 1, 1, 3, 5, 10, 1, 1],x = 29) == 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, 1, 1, 1, 1, 1],x = 1000) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 150) == 5\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],x = 50000) == 5\n assert candidate(nums = [5, 3, 2, 5, 3, 2, 5, 3, 2, 5, 3, 2, 5, 3, 2],x = 20) == 6\n assert candidate(nums = [1, 3, 2, 4, 5, 2, 3, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],x = 150) == 12\n assert candidate(nums = [5, 2, 3, 1, 1, 2, 3, 4, 5],x = 9) == 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],x = 1225) == 45\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],x = 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],x = 100) == 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, 5, 5, 5, 5, 5, 5, 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 = 100) == 20\n assert candidate(nums = [3, 5, 2, 1, 4, 7, 8, 9, 6, 10],x = 18) == 3\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],x = 45000) == 6\n assert candidate(nums = [3, 2, 2, 2, 3, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 3, 3, 3, 3, 2, 3, 3, 2, 3, 2, 2, 3, 3, 3, 3],x = 30) == 11\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],x = 370) == 6\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 50) == 5\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 9) == 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, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300],x = 1500) == 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],x = 210) == 20\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],x = 55000) == 10\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 90) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],x = 45) == 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],x = 275) == 20\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],x = 60) == 20\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],x = 100000) == 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],x = 55) == 10\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],x = 30) == -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],x = 50) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 100) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 15) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 55) == 10\n assert candidate(nums = [10000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9000],x = 20000) == -1\n assert candidate(nums = [10000, 9999, 10000, 9999, 10000, 9999],x = 59996) == -1\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],x = 3000) == 5\n assert candidate(nums = [9, 1, 2, 3, 9, 3, 2, 1, 9],x = 18) == 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, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],x = 80) == 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],x = 25) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 105) == 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],x = 1275) == 50\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],x = 50) == 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],x = 435) == 25\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 550) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],x = 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],x = 100) == 9\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 100) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],x = 45) == 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],x = 20) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],x = 120) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],x = 450) == 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],x = 55) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],x = 5500) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],x = 55) == 10\n assert candidate(nums = [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999],x = 49995) == 5\n assert candidate(nums = [5, 2, 3, 1, 1, 5, 5, 3, 2, 5],x = 10) == 2\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],x = 90) == 30\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],x = 80) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],x = 950) == 10\n assert candidate(nums = [3, 5, 2, 4, 1, 9, 6, 7, 8, 10],x = 25) == 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],x = 100) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],x = 120) == 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],x = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],x = 20) == 20\n assert candidate(nums = [5000, 3000, 2000, 4000, 1000, 6000],x = 21000) == 6\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],x = 70000) == 7\n", "comparison": "exact"}, "public_tests": ["[1,1,4,2,3]\n5", "[5,6,7,8,9]\n4", "[3,2,20,1,1,3]\n10"], "hints": ["Think in reverse; instead of finding the minimum prefix + suffix, find the maximum subarray.", "Finding the maximum subarray is standard and can be done greedily."], "metadata": {"canonical_parameter_names": ["nums", "x"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:39+00:00", "tests_total": 107, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minOperations($nums, $x) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1659, "task_id": "maximize-grid-happiness", "difficulty": "Hard", "problem_description": "You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts.\n\nYou should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you do not have to have all the people living in the grid.\n\nThe happiness of each person is calculated as follows:\n\n- Introverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert).\n- Extroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert).\n\nNeighbors live in the directly adjacent cells north, east, south, and west of a person's cell.\n\nThe grid happiness is the sum of each person's happiness. Return the maximum possible grid happiness.\n\nExample 1:\n\nInput: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\nOutput: 240\nExplanation: Assume the grid is 1-indexed with coordinates (row, column).\nWe can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120\n- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\nThe grid happiness is 120 + 60 + 60 = 240.\nThe above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.\n\nExample 2:\n\nInput: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\nOutput: 260\nExplanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80\n- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\nThe grid happiness is 90 + 80 + 90 = 260.\n\nExample 3:\n\nInput: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\nOutput: 240\n\nConstraints:\n\n- 1 <= m, n <= 5\n- 0 <= introvertsCount, extrovertsCount <= min(m * n, 6)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 5,n = 5,introvertsCount = 6,extrovertsCount = 6) == 1240\n assert candidate(m = 1,n = 1,introvertsCount = 0,extrovertsCount = 1) == 40\n assert candidate(m = 5,n = 1,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 2,n = 3,introvertsCount = 1,extrovertsCount = 2) == 240\n assert candidate(m = 1,n = 1,introvertsCount = 1,extrovertsCount = 0) == 120\n assert candidate(m = 4,n = 4,introvertsCount = 6,extrovertsCount = 0) == 720\n assert candidate(m = 2,n = 2,introvertsCount = 4,extrovertsCount = 0) == 240\n assert candidate(m = 3,n = 1,introvertsCount = 2,extrovertsCount = 1) == 260\n assert candidate(m = 1,n = 1,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 5,n = 1,introvertsCount = 0,extrovertsCount = 5) == 360\n assert candidate(m = 4,n = 4,introvertsCount = 3,extrovertsCount = 3) == 560\n assert candidate(m = 5,n = 5,introvertsCount = 3,extrovertsCount = 3) == 560\n assert candidate(m = 1,n = 5,introvertsCount = 5,extrovertsCount = 0) == 360\n assert candidate(m = 4,n = 5,introvertsCount = 3,extrovertsCount = 2) == 480\n assert candidate(m = 2,n = 5,introvertsCount = 5,extrovertsCount = 5) == 770\n assert candidate(m = 3,n = 5,introvertsCount = 0,extrovertsCount = 6) == 520\n assert candidate(m = 2,n = 5,introvertsCount = 2,extrovertsCount = 4) == 560\n assert candidate(m = 5,n = 2,introvertsCount = 4,extrovertsCount = 2) == 590\n assert candidate(m = 3,n = 3,introvertsCount = 4,extrovertsCount = 1) == 520\n assert candidate(m = 4,n = 3,introvertsCount = 4,extrovertsCount = 3) == 680\n assert candidate(m = 5,n = 2,introvertsCount = 5,extrovertsCount = 1) == 620\n assert candidate(m = 5,n = 2,introvertsCount = 3,extrovertsCount = 2) == 480\n assert candidate(m = 5,n = 5,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 4,n = 4,introvertsCount = 3,extrovertsCount = 4) == 680\n assert candidate(m = 4,n = 4,introvertsCount = 1,extrovertsCount = 6) == 640\n assert candidate(m = 4,n = 4,introvertsCount = 6,extrovertsCount = 6) == 1140\n assert candidate(m = 3,n = 2,introvertsCount = 0,extrovertsCount = 6) == 520\n assert candidate(m = 5,n = 5,introvertsCount = 6,extrovertsCount = 5) == 1120\n assert candidate(m = 4,n = 4,introvertsCount = 2,extrovertsCount = 2) == 360\n assert candidate(m = 1,n = 5,introvertsCount = 1,extrovertsCount = 4) == 390\n assert candidate(m = 4,n = 4,introvertsCount = 4,extrovertsCount = 4) == 800\n assert candidate(m = 2,n = 5,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 5,n = 2,introvertsCount = 4,extrovertsCount = 1) == 520\n assert candidate(m = 3,n = 5,introvertsCount = 3,extrovertsCount = 3) == 560\n assert candidate(m = 2,n = 5,introvertsCount = 2,extrovertsCount = 2) == 360\n assert candidate(m = 3,n = 3,introvertsCount = 4,extrovertsCount = 3) == 640\n assert candidate(m = 3,n = 4,introvertsCount = 2,extrovertsCount = 4) == 560\n assert candidate(m = 5,n = 3,introvertsCount = 1,extrovertsCount = 4) == 440\n assert candidate(m = 4,n = 3,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 3,n = 2,introvertsCount = 0,extrovertsCount = 3) == 200\n assert candidate(m = 5,n = 4,introvertsCount = 3,extrovertsCount = 2) == 480\n assert candidate(m = 3,n = 3,introvertsCount = 0,extrovertsCount = 6) == 520\n assert candidate(m = 3,n = 3,introvertsCount = 5,extrovertsCount = 1) == 610\n assert candidate(m = 5,n = 1,introvertsCount = 5,extrovertsCount = 1) == 380\n assert candidate(m = 5,n = 5,introvertsCount = 5,extrovertsCount = 1) == 640\n assert candidate(m = 4,n = 4,introvertsCount = 2,extrovertsCount = 4) == 560\n assert candidate(m = 4,n = 3,introvertsCount = 5,extrovertsCount = 1) == 640\n assert candidate(m = 4,n = 2,introvertsCount = 4,extrovertsCount = 2) == 520\n assert candidate(m = 5,n = 3,introvertsCount = 2,extrovertsCount = 4) == 560\n assert candidate(m = 4,n = 3,introvertsCount = 3,extrovertsCount = 3) == 560\n assert candidate(m = 3,n = 5,introvertsCount = 3,extrovertsCount = 2) == 480\n assert candidate(m = 3,n = 3,introvertsCount = 3,extrovertsCount = 3) == 550\n assert candidate(m = 4,n = 2,introvertsCount = 3,extrovertsCount = 2) == 470\n assert candidate(m = 5,n = 3,introvertsCount = 4,extrovertsCount = 2) == 600\n assert candidate(m = 4,n = 2,introvertsCount = 2,extrovertsCount = 4) == 550\n assert candidate(m = 5,n = 3,introvertsCount = 6,extrovertsCount = 0) == 720\n assert candidate(m = 5,n = 2,introvertsCount = 0,extrovertsCount = 6) == 520\n assert candidate(m = 4,n = 2,introvertsCount = 1,extrovertsCount = 5) == 520\n assert candidate(m = 4,n = 5,introvertsCount = 1,extrovertsCount = 4) == 440\n assert candidate(m = 4,n = 4,introvertsCount = 4,extrovertsCount = 3) == 680\n assert candidate(m = 4,n = 1,introvertsCount = 2,extrovertsCount = 2) == 340\n assert candidate(m = 4,n = 3,introvertsCount = 5,extrovertsCount = 2) == 710\n assert candidate(m = 5,n = 3,introvertsCount = 3,extrovertsCount = 3) == 560\n assert candidate(m = 2,n = 5,introvertsCount = 1,extrovertsCount = 5) == 520\n assert candidate(m = 5,n = 3,introvertsCount = 3,extrovertsCount = 4) == 680\n assert candidate(m = 4,n = 4,introvertsCount = 4,extrovertsCount = 2) == 600\n assert candidate(m = 4,n = 5,introvertsCount = 6,extrovertsCount = 2) == 840\n assert candidate(m = 3,n = 4,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 3,n = 4,introvertsCount = 0,extrovertsCount = 6) == 520\n assert candidate(m = 3,n = 3,introvertsCount = 4,extrovertsCount = 4) == 700\n assert candidate(m = 2,n = 2,introvertsCount = 2,extrovertsCount = 2) == 280\n assert candidate(m = 5,n = 4,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 3,n = 3,introvertsCount = 6,extrovertsCount = 0) == 600\n assert candidate(m = 4,n = 3,introvertsCount = 2,extrovertsCount = 4) == 560\n assert candidate(m = 5,n = 1,introvertsCount = 5,extrovertsCount = 0) == 360\n assert candidate(m = 2,n = 4,introvertsCount = 3,extrovertsCount = 2) == 470\n assert candidate(m = 2,n = 2,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 3,n = 3,introvertsCount = 1,extrovertsCount = 1) == 160\n assert candidate(m = 1,n = 5,introvertsCount = 3,extrovertsCount = 3) == 420\n assert candidate(m = 3,n = 3,introvertsCount = 2,extrovertsCount = 2) == 360\n assert candidate(m = 3,n = 3,introvertsCount = 2,extrovertsCount = 4) == 550\n assert candidate(m = 2,n = 2,introvertsCount = 0,extrovertsCount = 1) == 40\n assert candidate(m = 2,n = 2,introvertsCount = 0,extrovertsCount = 2) == 120\n assert candidate(m = 3,n = 3,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 3,n = 3,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 5,n = 2,introvertsCount = 5,extrovertsCount = 5) == 770\n assert candidate(m = 5,n = 1,introvertsCount = 3,extrovertsCount = 3) == 420\n assert candidate(m = 5,n = 2,introvertsCount = 5,extrovertsCount = 0) == 600\n assert candidate(m = 4,n = 4,introvertsCount = 2,extrovertsCount = 3) == 440\n assert candidate(m = 5,n = 1,introvertsCount = 1,extrovertsCount = 0) == 120\n assert candidate(m = 2,n = 2,introvertsCount = 1,extrovertsCount = 1) == 160\n assert candidate(m = 1,n = 5,introvertsCount = 0,extrovertsCount = 5) == 360\n assert candidate(m = 4,n = 4,introvertsCount = 0,extrovertsCount = 0) == 0\n assert candidate(m = 4,n = 4,introvertsCount = 3,extrovertsCount = 2) == 480\n assert candidate(m = 4,n = 5,introvertsCount = 5,extrovertsCount = 4) == 920\n assert candidate(m = 1,n = 1,introvertsCount = 1,extrovertsCount = 1) == 120\n assert candidate(m = 5,n = 5,introvertsCount = 1,extrovertsCount = 1) == 160\n assert candidate(m = 1,n = 5,introvertsCount = 1,extrovertsCount = 0) == 120\n assert candidate(m = 1,n = 5,introvertsCount = 0,extrovertsCount = 1) == 40\n assert candidate(m = 5,n = 1,introvertsCount = 0,extrovertsCount = 1) == 40\n assert candidate(m = 2,n = 5,introvertsCount = 3,extrovertsCount = 2) == 480\n", "comparison": "exact"}, "public_tests": ["2\n3\n1\n2", "3\n1\n2\n1", "2\n2\n4\n0"], "hints": ["For each cell, it has 3 options, either it is empty, or contains an introvert, or an extrovert.", "You can do DP where you maintain the state of the previous row, the number of remaining introverts and extroverts, the current row and column, and try the 3 options for each cell.", "Assume that the previous columns in the current row already belong to the previous row."], "metadata": {"canonical_parameter_names": ["m", "n", "introvertsCount", "extrovertsCount"], "leetcode_dataset_entry_point": "Solution().getMaxGridHappiness", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:42+00:00", "tests_total": 102, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "bit-manipulation", "memoization", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function getMaxGridHappiness($m, $n, $introvertsCount, $extrovertsCount) {", "container": "Solution", "callable": "getMaxGridHappiness", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "introvertsCount", "type": "Integer"}, {"name": "extrovertsCount", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1662, "task_id": "check-if-two-string-arrays-are-equivalent", "difficulty": "Easy", "problem_description": "Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.\n\nA string is represented by an array if the array elements concatenated in order forms the string.\n\nExample 1:\n\nInput: word1 = [\"ab\", \"c\"], word2 = [\"a\", \"bc\"]\nOutput: true\nExplanation:\nword1 represents string \"ab\" + \"c\" -> \"abc\"\nword2 represents string \"a\" + \"bc\" -> \"abc\"\nThe strings are the same, so return true.\n\nExample 2:\n\nInput: word1 = [\"a\", \"cb\"], word2 = [\"ab\", \"c\"]\nOutput: false\n\nExample 3:\n\nInput: word1 = [\"abc\", \"d\", \"defg\"], word2 = [\"abcddefg\"]\nOutput: true\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 10^3\n- 1 <= word1[i].length, word2[i].length <= 10^3\n- 1 <= sum(word1[i].length), sum(word2[i].length) <= 10^3\n- word1[i] and word2[i] consist of lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = ['abc', 'd', 'defg'],word2 = ['abcddefg']) == True\n assert candidate(word1 = ['x'],word2 = ['y']) == False\n assert candidate(word1 = ['different'],word2 = ['string']) == False\n assert candidate(word1 = ['hello', 'world'],word2 = ['helloworld']) == True\n assert candidate(word1 = ['one', 'two', 'three'],word2 = ['onetwothree']) == True\n assert candidate(word1 = ['abc'],word2 = ['a', 'b', 'c']) == True\n assert candidate(word1 = ['abc'],word2 = ['ab', 'c']) == True\n assert candidate(word1 = ['xyz'],word2 = ['x', 'y', 'z']) == True\n assert candidate(word1 = ['ab', 'c'],word2 = ['a', 'bc']) == True\n assert candidate(word1 = ['a'],word2 = ['a']) == True\n assert candidate(word1 = ['a', 'cb'],word2 = ['ab', 'c']) == False\n assert candidate(word1 = ['hello'],word2 = ['hello']) == True\n assert candidate(word1 = ['test'],word2 = ['t', 'es', 't']) == True\n assert candidate(word1 = ['a', 'b'],word2 = ['ab']) == True\n assert candidate(word1 = ['same', 'string'],word2 = ['same', 'string']) == True\n assert candidate(word1 = ['a', 'b', 'c'],word2 = ['a', 'b', 'c']) == True\n assert candidate(word1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],word2 = ['abcdefg']) == True\n assert candidate(word1 = ['split', 'in', 'pieces'],word2 = ['spli', 'tin', 'pi', 'eces']) == True\n assert candidate(word1 = ['a', 'b', 'c', 'd', 'e', 'f'],word2 = ['abcdef']) == True\n assert candidate(word1 = ['complex', 'string', 'example'],word2 = ['com', 'plex', 'string', 'ex', 'ample']) == True\n assert candidate(word1 = ['a', 'b', 'c'],word2 = ['ab', 'c']) == True\n assert candidate(word1 = ['same', 'same', 'same'],word2 = ['same', 'same', 'same']) == True\n assert candidate(word1 = ['split', 'this', 'up'],word2 = ['splitthis', 'up']) == True\n assert candidate(word1 = ['a', 'b', 'c'],word2 = ['d', 'e', 'f']) == False\n assert candidate(word1 = ['abcdef'],word2 = ['abc', 'd', 'e', 'f']) == True\n assert candidate(word1 = ['abcd', 'efgh', 'ijkl'],word2 = ['abcdefgh', 'ijkl']) == True\n assert candidate(word1 = ['abc', 'def'],word2 = ['abcdefg']) == False\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['abc', 'd', 'efghi']) == True\n assert candidate(word1 = ['complex', 'word'],word2 = ['c', 'o', 'm', 'p', 'l', 'e', 'x', 'word']) == True\n assert candidate(word1 = ['partial', 'match'],word2 = ['partialm', 'atch']) == True\n assert candidate(word1 = ['a', 'bc', 'def', 'ghij'],word2 = ['abc', 'defghij']) == True\n assert candidate(word1 = ['equal', 'strings'],word2 = ['equalstrings']) == True\n assert candidate(word1 = ['example'],word2 = ['ex', 'ample']) == True\n assert candidate(word1 = ['complex', 'example'],word2 = ['com', 'plexex', 'ample']) == True\n assert candidate(word1 = ['abcdefg', 'hijklmn'],word2 = ['abc', 'defghijklmn']) == True\n assert candidate(word1 = ['same'],word2 = ['s', 'a', 'm', 'e']) == True\n assert candidate(word1 = ['long', 'word', 'sequence'],word2 = ['l', 'ongw', 'ordsequ', 'ence']) == True\n assert candidate(word1 = ['a', 'very', 'long', 'string', 'here'],word2 = ['averylongstringhere']) == True\n assert candidate(word1 = ['same', 'string'],word2 = ['sam', 'e', 'string']) == True\n assert candidate(word1 = ['abc', 'defg', 'hijkl'],word2 = ['abcdefg', 'hijkl']) == True\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['abcdef', 'ghi']) == True\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['abcdefg', 'hi']) == True\n assert candidate(word1 = ['long', 'string', 'here'],word2 = ['longstring', 'here']) == True\n assert candidate(word1 = ['x', 'y', 'z'],word2 = ['xyz']) == True\n assert candidate(word1 = ['z'],word2 = ['z']) == True\n assert candidate(word1 = ['one', 'two', 'three', 'four'],word2 = ['onetwo', 'three', 'four']) == True\n assert candidate(word1 = ['one', 'two', 'three', 'four'],word2 = ['onetwo', 'threefour']) == True\n assert candidate(word1 = ['x', 'y', 'z'],word2 = ['x', 'yz']) == True\n assert candidate(word1 = ['xyz', 'uvw'],word2 = ['xy', 'zu', 'vw']) == True\n assert candidate(word1 = ['a', 'b', 'c', 'd', 'e'],word2 = ['abcd', 'e']) == True\n assert candidate(word1 = ['longerstring', 'here'],word2 = ['longerstringhere']) == True\n assert candidate(word1 = ['onetwothree'],word2 = ['one', 'two', 'three']) == True\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['ab', 'cdef', 'ghi']) == True\n assert candidate(word1 = ['abcd'],word2 = ['ab', 'c', 'd']) == True\n assert candidate(word1 = ['one', 'two', 'three', 'four'],word2 = ['onetwothreefour']) == True\n assert candidate(word1 = ['almost', 'thesame'],word2 = ['almostthesame', 'extra']) == False\n assert candidate(word1 = ['split', 'into', 'multiple', 'parts'],word2 = ['splitint', 'omulti', 'pleparts']) == True\n assert candidate(word1 = ['ab', 'cde', 'f'],word2 = ['abc', 'def']) == True\n assert candidate(word1 = ['same', 'string', 'here'],word2 = ['samestringhere']) == True\n assert candidate(word1 = ['xyz', 'uvw', 'mnop'],word2 = ['xyzu', 'vw', 'mnop']) == True\n assert candidate(word1 = ['xyz', 'uvw', 'qrst'],word2 = ['xyzuvw', 'qrst']) == True\n assert candidate(word1 = ['same', 'string', 'here'],word2 = ['sam', 'e', 'stringhere']) == True\n assert candidate(word1 = ['longstringhere', 'another'],word2 = ['longstringhereanother']) == True\n assert candidate(word1 = ['this', 'is', 'a', 'test'],word2 = ['thi', 'sisa', 'test']) == True\n assert candidate(word1 = ['abc', 'defg', 'hijk', 'lmnop'],word2 = ['abcdefg', 'hijklmnop']) == True\n assert candidate(word1 = ['longstringhere', 'anotherlongstringhere'],word2 = ['longstringhereanotherlongstringhere']) == True\n assert candidate(word1 = ['a', 'b', 'c', 'd', 'e'],word2 = ['abcde']) == True\n assert candidate(word1 = ['a', 'longer', 'string', 'here'],word2 = ['a', 'longerstring', 'here']) == True\n assert candidate(word1 = ['a', 'b', 'c'],word2 = ['abc']) == True\n assert candidate(word1 = ['different', 'length'],word2 = ['differentlen', 'gth']) == True\n assert candidate(word1 = ['longstringone', 'longstringtwo'],word2 = ['longstringone', 'long', 'string', 'two']) == True\n assert candidate(word1 = ['same', 'string', 'here'],word2 = ['samestring', 'here']) == True\n assert candidate(word1 = ['short'],word2 = ['loooooooonger']) == False\n assert candidate(word1 = ['hello', 'world'],word2 = ['he', 'll', 'o', 'wor', 'ld']) == True\n assert candidate(word1 = ['hello', 'world', 'python'],word2 = ['hello', 'wor', 'ldpy', 'thon']) == True\n assert candidate(word1 = ['another', 'example', 'with', 'spaces'],word2 = ['anotherexam', 'plewithspaces']) == True\n assert candidate(word1 = ['xyz', 'uvw', 'rst'],word2 = ['xyzuvw', 'rst']) == True\n assert candidate(word1 = ['abc', 'def'],word2 = ['a', 'bc', 'd', 'ef']) == True\n assert candidate(word1 = ['this', 'is', 'a', 'test'],word2 = ['thisisatest']) == True\n assert candidate(word1 = ['samestringhere'],word2 = ['same', 'string', 'here']) == True\n assert candidate(word1 = ['abcd'],word2 = ['a', 'b', 'c', 'd']) == True\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['abcdefghi']) == True\n assert candidate(word1 = ['a', 'a', 'a', 'a', 'a'],word2 = ['a', 'a', 'a', 'a', 'a']) == True\n assert candidate(word1 = ['a', 'a', 'a', 'a', 'a'],word2 = ['aaaaa']) == True\n assert candidate(word1 = ['mismatch', 'here'],word2 = ['mismatch', 'there']) == False\n assert candidate(word1 = ['one', 'two', 'three'],word2 = ['on', 'etwothree']) == True\n assert candidate(word1 = ['part', 'one'],word2 = ['p', 'artone']) == True\n assert candidate(word1 = ['equal', 'length', 'words'],word2 = ['equal', 'length', 'word']) == False\n assert candidate(word1 = ['abc', 'def', 'ghi'],word2 = ['abc', 'def', 'ghi']) == True\n assert candidate(word1 = ['equal', 'length'],word2 = ['equal', 'length']) == True\n assert candidate(word1 = ['longwordhere'],word2 = ['l', 'on', 'g', 'wo', 'rd', 'here']) == True\n assert candidate(word1 = ['longer', 'string', 'example'],word2 = ['longerstringexample']) == True\n assert candidate(word1 = ['singleword'],word2 = ['single', 'word']) == True\n assert candidate(word1 = ['different', 'sizes'],word2 = ['different', 'siz', 'es']) == True\n assert candidate(word1 = ['a'],word2 = ['b']) == False\n assert candidate(word1 = ['one', 'two', 'three'],word2 = ['one', 'twothree']) == True\n assert candidate(word1 = ['split', 'this', 'way'],word2 = ['sp', 'lit', 'thi', 'sway']) == True\n assert candidate(word1 = ['one', 'two', 'three'],word2 = ['onetwo', 'three']) == True\n assert candidate(word1 = ['this', 'is', 'a', 'test'],word2 = ['thisis', 'atest']) == True\n assert candidate(word1 = ['a', 'b', 'c', 'd'],word2 = ['abcd']) == True\n assert candidate(word1 = ['split', 'across', 'multiple', 'parts'],word2 = ['splitacrossmultip', 'leparts']) == True\n", "comparison": "exact"}, "public_tests": ["[\"ab\", \"c\"]\n[\"a\", \"bc\"]", "[\"a\", \"cb\"]\n[\"ab\", \"c\"]", "[\"abc\", \"d\", \"defg\"]\n[\"abcddefg\"]"], "hints": ["Concatenate all strings in the first array into a single string in the given order, the same for the second array.", "Both arrays represent the same string if and only if the generated strings are the same."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().arrayStringsAreEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:44+00:00", "tests_total": 105, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function arrayStringsAreEqual($word1, $word2) {", "container": "Solution", "callable": "arrayStringsAreEqual", "parameters": [{"name": "word1", "type": "String[]"}, {"name": "word2", "type": "String[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1663, "task_id": "smallest-string-with-a-given-numeric-value", "difficulty": "Medium", "problem_description": "The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.\n\nThe numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string \"abe\" is equal to 1 + 2 + 5 = 8.\n\nYou are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.\n\nNote that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.\n\nExample 1:\n\nInput: n = 3, k = 27\nOutput: \"aay\"\nExplanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.\n\nExample 2:\n\nInput: n = 5, k = 73\nOutput: \"aaszz\"\n\nConstraints:\n\n- 1 <= n <= 10^5\n- n <= k <= 26 * n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,k = 100) == \"aaaszzz\"\n assert candidate(n = 1,k = 26) == \"z\"\n assert candidate(n = 4,k = 40) == \"aalz\"\n assert candidate(n = 5,k = 73) == \"aaszz\"\n assert candidate(n = 10,k = 260) == \"zzzzzzzzzz\"\n assert candidate(n = 2,k = 2) == \"aa\"\n assert candidate(n = 1,k = 1) == \"a\"\n assert candidate(n = 2,k = 26) == \"ay\"\n assert candidate(n = 4,k = 52) == \"aaxz\"\n assert candidate(n = 3,k = 27) == \"aay\"\n assert candidate(n = 10,k = 100) == \"aaaaaapzzz\"\n assert candidate(n = 50,k = 650) == \"aaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 100,k = 1000) == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 12,k = 300) == \"nzzzzzzzzzzz\"\n assert candidate(n = 6,k = 156) == \"zzzzzz\"\n assert candidate(n = 10,k = 131) == \"aaaaavzzzz\"\n assert candidate(n = 5,k = 67) == \"aamzz\"\n assert candidate(n = 15,k = 350) == \"akzzzzzzzzzzzzz\"\n assert candidate(n = 25,k = 650) == \"zzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 12,k = 150) == \"aaaaaanzzzzz\"\n assert candidate(n = 7,k = 145) == \"anzzzzz\"\n assert candidate(n = 6,k = 45) == \"aaaaoz\"\n assert candidate(n = 3,k = 51) == \"axz\"\n assert candidate(n = 11,k = 260) == \"ayzzzzzzzzz\"\n assert candidate(n = 15,k = 180) == \"aaaaaaaapzzzzzz\"\n assert candidate(n = 9,k = 150) == \"aaaqzzzzz\"\n assert candidate(n = 7,k = 104) == \"aaawzzz\"\n assert candidate(n = 7,k = 150) == \"aszzzzz\"\n assert candidate(n = 8,k = 175) == \"arzzzzzz\"\n assert candidate(n = 10,k = 150) == \"aaaapzzzzz\"\n assert candidate(n = 20,k = 400) == \"aaaafzzzzzzzzzzzzzzz\"\n assert candidate(n = 10,k = 52) == \"aaaaaaaarz\"\n assert candidate(n = 6,k = 100) == \"aatzzz\"\n assert candidate(n = 12,k = 200) == \"aaaanzzzzzzz\"\n assert candidate(n = 8,k = 208) == \"zzzzzzzz\"\n assert candidate(n = 3,k = 25) == \"aaw\"\n assert candidate(n = 20,k = 200) == \"aaaaaaaaaaaafzzzzzzz\"\n assert candidate(n = 15,k = 150) == \"aaaaaaaaakzzzzz\"\n assert candidate(n = 100,k = 2600) == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 6,k = 78) == \"aaawzz\"\n assert candidate(n = 15,k = 225) == \"aaaaaakzzzzzzzz\"\n assert candidate(n = 26,k = 676) == \"zzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 3,k = 30) == \"acz\"\n assert candidate(n = 12,k = 312) == \"zzzzzzzzzzzz\"\n assert candidate(n = 9,k = 182) == \"aaxzzzzzz\"\n assert candidate(n = 7,k = 91) == \"aaajzzz\"\n assert candidate(n = 5,k = 130) == \"zzzzz\"\n assert candidate(n = 8,k = 120) == \"aaamzzzz\"\n assert candidate(n = 9,k = 234) == \"zzzzzzzzz\"\n assert candidate(n = 5,k = 125) == \"uzzzz\"\n assert candidate(n = 30,k = 780) == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 20,k = 520) == \"zzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 50,k = 1300) == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(n = 4,k = 50) == \"aavz\"\n assert candidate(n = 11,k = 286) == \"zzzzzzzzzzz\"\n assert candidate(n = 15,k = 200) == \"aaaaaaakzzzzzzz\"\n assert candidate(n = 9,k = 230) == \"vzzzzzzzz\"\n assert candidate(n = 4,k = 10) == \"aaag\"\n assert candidate(n = 2,k = 27) == \"az\"\n assert candidate(n = 7,k = 42) == \"aaaaakz\"\n assert candidate(n = 4,k = 90) == \"lzzz\"\n", "comparison": "exact"}, "public_tests": ["3\n27", "5\n73"], "hints": ["Think greedily.", "If you build the string from the end to the beginning, it will always be optimal to put the highest possible character at the current index."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().getSmallestString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:46+00:00", "tests_total": 65, "tests_dropped": 4, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function getSmallestString($n, $k) {", "container": "Solution", "callable": "getSmallestString", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1664, "task_id": "ways-to-make-a-fair-array", "difficulty": "Medium", "problem_description": "You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.\n\nFor example, if nums = [6,1,7,4,1]:\n\n- Choosing to remove index 1 results in nums = [6,7,4,1].\n- Choosing to remove index 2 results in nums = [6,1,4,1].\n- Choosing to remove index 4 results in nums = [6,1,7,4].\n\nAn array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.\n\nReturn the number of indices that you could choose such that after the removal, nums is fair.\n\nExample 1:\n\nInput: nums = [2,1,6,4]\nOutput: 1\nExplanation:\nRemove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.\nRemove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.\nRemove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.\nRemove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.\nThere is 1 index that you can remove to make nums fair.\n\nExample 2:\n\nInput: nums = [1,1,1]\nOutput: 3\nExplanation: You can remove any index and the remaining array is fair.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: You cannot make a fair array after removing any index.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 0\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [2, 1, 6, 4]) == 1\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000]) == 5\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [1, 1, 1]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [4, 5, 6, 7, 8]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 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]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 0\n assert candidate(nums = [9999, 1, 9999, 1, 9999, 1, 9999, 1, 9999, 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\n assert candidate(nums = [23, 17, 14, 6, 9, 4, 3, 10, 13, 2, 11, 1, 5, 15, 7, 12, 8, 16, 19, 18]) == 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, 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 = [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 = [23, 45, 67, 89, 12, 34, 56, 78, 90, 11, 33, 55, 77, 99, 22, 44, 66, 88, 10]) == 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 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 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]) == 0\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 0\n assert candidate(nums = [7, 10, 5, 8, 6, 3, 2, 9, 4, 1]) == 0\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]) == 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 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 0\n assert candidate(nums = [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, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 0\n assert candidate(nums = [10000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\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]) == 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]) == 0\n assert candidate(nums = [10000]) == 1\n assert candidate(nums = [5, 3, 2, 4, 1, 6, 7, 8, 9, 10, 11, 12]) == 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, 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 = [10000, 9999, 10000, 9999, 10000, 9999, 10000, 9999, 10000, 9999]) == 0\n assert candidate(nums = [42]) == 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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1]) == 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]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 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]) == 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 0\n assert candidate(nums = [5, 3, 5, 3, 5, 3]) == 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 = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == 0\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 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]) == 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 = [2468, 1357, 2468, 1357, 2468, 1357, 2468, 1357, 2468, 1357, 2468, 1357, 2468, 1357, 2468]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 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, 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, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(nums = [10000, 1, 10000, 1, 10000, 1, 10000, 1, 10000, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 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 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 0\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]) == 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 = [10000, 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, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 13\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 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]) == 0\n assert candidate(nums = [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, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 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]) == 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\n assert candidate(nums = [1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3]) == 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, 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]) == 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, 45, 46, 47, 48, 49, 50]) == 0\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986]) == 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]) == 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]) == 5\n assert candidate(nums = [2, 1, 6, 4, 3, 5, 7, 8]) == 0\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985]) == 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, 1, 1, 1, 1, 1]) == 0\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]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 91\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, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == 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, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029]) == 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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 0\n assert candidate(nums = [10000, 1, 10000, 1, 10000, 1]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,1,6,4]", "[1,1,1]", "[1,2,3]"], "hints": ["The parity of the indices after the removed element changes.", "Calculate prefix sums for even and odd indices separately to calculate for each index in O(1)."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().waysToMakeFair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:49+00:00", "tests_total": 100, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function waysToMakeFair($nums) {", "container": "Solution", "callable": "waysToMakeFair", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1665, "task_id": "minimum-initial-energy-to-finish-tasks", "difficulty": "Hard", "problem_description": "You are given an array tasks where tasks[i] = [actual_i, minimum_i]:\n\n- actual_i is the actual amount of energy you spend to finish the i^th task.\n- minimum_i is the minimum amount of energy you require to begin the i^th task.\n\nFor example, if the task is [10, 12] and your current energy is 11, you cannot start this task. However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.\n\nYou can finish the tasks in any order you like.\n\nReturn the minimum initial amount of energy you will need to finish all the tasks.\n\nExample 1:\n\nInput: tasks = [[1,2],[2,4],[4,8]]\nOutput: 8\nExplanation:\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.\n\nExample 2:\n\nInput: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\nOutput: 32\nExplanation:\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.\n\nExample 3:\n\nInput: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\nOutput: 27\nExplanation:\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n\nConstraints:\n\n- 1 <= tasks.length <= 10^5\n- 1 <= actual_i <= minimum_i <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [[10, 15], [20, 25], [30, 35]]) == 65\n assert candidate(tasks = [[10, 15], [5, 10], [3, 7]]) == 22\n assert candidate(tasks = [[10, 10], [15, 15], [5, 5]]) == 30\n assert candidate(tasks = [[1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12]]) == 27\n assert candidate(tasks = [[5, 10], [1, 2], [3, 4]]) == 10\n assert candidate(tasks = [[1, 2], [2, 4], [4, 8]]) == 8\n assert candidate(tasks = [[3, 3], [2, 5], [1, 4]]) == 6\n assert candidate(tasks = [[1, 100], [2, 99], [3, 98]]) == 101\n assert candidate(tasks = [[10, 10], [10, 10], [10, 10], [10, 10]]) == 40\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3]]) == 6\n assert candidate(tasks = [[1, 3], [2, 4], [10, 11], [10, 12], [8, 9]]) == 32\n assert candidate(tasks = [[1, 50], [2, 51], [3, 52], [4, 53], [5, 54], [6, 55], [7, 56], [8, 57], [9, 58], [10, 59], [11, 60], [12, 61], [13, 62], [14, 63], [15, 64], [16, 65], [17, 66], [18, 67], [19, 68], [20, 69], [21, 70], [22, 71], [23, 72], [24, 73], [25, 74]]) == 374\n assert candidate(tasks = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995]]) == 10010\n assert candidate(tasks = [[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]]) == 191\n assert candidate(tasks = [[1, 2], [2, 4], [4, 8], [8, 16], [16, 32]]) == 32\n assert candidate(tasks = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 56\n assert candidate(tasks = [[1, 10000], [10000, 10000], [1, 10000], [10000, 10000], [1, 10000]]) == 20003\n assert candidate(tasks = [[10000, 10000], [1, 2], [10000, 10000], [1, 2], [10000, 10000], [1, 2]]) == 30003\n assert candidate(tasks = [[100, 150], [50, 100], [30, 70], [20, 50], [10, 30], [5, 15]]) == 230\n assert candidate(tasks = [[10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10]]) == 100\n assert candidate(tasks = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25]]) == 45\n assert candidate(tasks = [[100, 120], [200, 220], [300, 320], [400, 420], [500, 520]]) == 1520\n assert candidate(tasks = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 59\n assert candidate(tasks = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == 100\n assert candidate(tasks = [[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]]) == 165\n assert candidate(tasks = [[100, 100], [90, 90], [80, 80], [70, 70], [60, 60], [50, 50], [40, 40], [30, 30], [20, 20], [10, 10], [5, 5]]) == 555\n assert candidate(tasks = [[9999, 10000], [9998, 10001], [9997, 10002], [9996, 10003], [9995, 10004], [9994, 10005], [9993, 10006], [9992, 10007], [9991, 10008], [9990, 10009]]) == 99946\n assert candidate(tasks = [[100, 105], [10, 15], [1, 2], [5, 7], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65], [70, 75]]) == 387\n assert candidate(tasks = [[5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19]]) == 79\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 55\n assert candidate(tasks = [[9999, 10000], [9998, 9999], [9997, 9998], [9996, 9997], [9995, 9996]]) == 49986\n assert candidate(tasks = [[100, 101], [99, 100], [98, 99], [97, 98], [96, 97], [95, 96]]) == 586\n assert candidate(tasks = [[1000, 1000], [900, 950], [800, 850], [700, 750], [600, 650]]) == 4000\n assert candidate(tasks = [[100, 200], [100, 300], [100, 400], [100, 500], [100, 600], [100, 700], [100, 800], [100, 900], [100, 1000]]) == 1000\n assert candidate(tasks = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]]) == 55\n assert candidate(tasks = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == 136\n assert candidate(tasks = [[1000, 1001], [2000, 2002], [3000, 3003], [4000, 4004], [5000, 5005], [6000, 6006], [7000, 7007], [8000, 8008], [9000, 9009], [10000, 10001]]) == 55001\n assert candidate(tasks = [[500, 1000], [400, 900], [300, 800], [200, 700], [100, 600], [50, 500], [25, 400], [12, 300], [7, 200], [5, 100], [3, 50]]) == 2000\n assert candidate(tasks = [[1, 10000], [10000, 10000], [1, 10000], [10000, 10000], [1, 10000], [10000, 10000]]) == 30003\n assert candidate(tasks = [[10000, 10000], [9999, 9999], [9998, 9998], [9997, 9997], [9996, 9996], [9995, 9995], [9994, 9994], [9993, 9993], [9992, 9992], [9991, 9991]]) == 99955\n assert candidate(tasks = [[1000, 1001], [999, 1002], [998, 1003], [997, 1004], [996, 1005], [995, 1006], [994, 1007], [993, 1008], [992, 1009], [991, 1010], [990, 1011], [989, 1012], [988, 1013], [987, 1014], [986, 1015], [985, 1016], [984, 1017], [983, 1018], [982, 1019], [981, 1020]]) == 19811\n assert candidate(tasks = [[1, 2], [100, 101], [1, 2], [100, 101], [1, 2], [100, 101]]) == 304\n assert candidate(tasks = [[500, 500], [500, 500], [500, 500], [500, 500], [500, 500]]) == 2500\n assert candidate(tasks = [[5, 10], [2, 8], [3, 5], [4, 7]]) == 16\n assert candidate(tasks = [[5000, 5000], [4999, 4999], [4998, 4998], [4997, 4997], [4996, 4996], [4995, 4995], [4994, 4994], [4993, 4993], [4992, 4992], [4991, 4991], [4990, 4990], [4989, 4989], [4988, 4988], [4987, 4987], [4986, 4986], [4985, 4985], [4984, 4984], [4983, 4983], [4982, 4982], [4981, 4981], [4980, 4980], [4979, 4979], [4978, 4978], [4977, 4977], [4976, 4976], [4975, 4975], [4974, 4974], [4973, 4973], [4972, 4972], [4971, 4971], [4970, 4970], [4969, 4969], [4968, 4968], [4967, 4967], [4966, 4966], [4965, 4965], [4964, 4964], [4963, 4963], [4962, 4962], [4961, 4961], [4960, 4960]]) == 204180\n assert candidate(tasks = [[5, 10], [4, 9], [3, 8], [2, 7], [1, 6], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15]]) == 60\n assert candidate(tasks = [[10, 11], [20, 21], [30, 31], [40, 41], [50, 51], [60, 61], [70, 71]]) == 281\n assert candidate(tasks = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65], [70, 75], [80, 85], [90, 95], [100, 105]]) == 555\n assert candidate(tasks = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [110, 110], [120, 120]]) == 780\n assert candidate(tasks = [[1000, 1000], [2000, 2000], [3000, 3000], [4000, 4000]]) == 10000\n assert candidate(tasks = [[1, 10000], [10000, 10000], [1, 10000], [10000, 10000], [1, 10000], [10000, 10000], [1, 10000], [10000, 10000]]) == 40004\n assert candidate(tasks = [[100, 150], [50, 100], [25, 75], [12, 60], [7, 35], [5, 25], [3, 15]]) == 235\n assert candidate(tasks = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 10\n assert candidate(tasks = [[100, 101], [102, 203], [204, 305], [306, 407], [408, 509], [510, 611], [612, 713], [714, 815], [816, 917], [918, 1019]]) == 4691\n assert candidate(tasks = [[9, 10], [8, 9], [7, 8], [6, 7], [5, 6], [4, 5], [3, 4], [2, 3], [1, 2]]) == 46\n assert candidate(tasks = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 56\n assert candidate(tasks = [[9000, 10000], [8000, 9000], [7000, 8000], [6000, 7000], [5000, 6000], [4000, 5000]]) == 40000\n assert candidate(tasks = [[100, 110], [50, 60], [30, 40], [10, 20], [5, 15], [1, 3]]) == 205\n assert candidate(tasks = [[100, 200], [50, 150], [25, 125], [12, 112], [6, 106], [3, 103], [1, 101], [7, 107], [8, 108], [9, 109], [10, 110]]) == 331\n assert candidate(tasks = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996]]) == 10006\n assert candidate(tasks = [[500, 510], [400, 410], [300, 310], [200, 210], [100, 110], [50, 60], [10, 20], [1, 2], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 1658\n assert candidate(tasks = [[100, 200], [150, 250], [50, 100], [300, 400], [200, 300], [1000, 1200], [500, 600]]) == 2350\n assert candidate(tasks = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995], [7, 9994], [8, 9993], [9, 9992], [10, 9991], [11, 9990], [12, 9989], [13, 9988], [14, 9987], [15, 9986]]) == 10091\n assert candidate(tasks = [[5, 10], [10, 15], [20, 25], [30, 35], [40, 45]]) == 110\n assert candidate(tasks = [[10000, 10000], [9000, 9000], [8000, 8000], [7000, 7000], [6000, 6000], [5000, 5000], [4000, 4000], [3000, 3000], [2000, 2000], [1000, 1000]]) == 55000\n assert candidate(tasks = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995]]) == 10010\n assert candidate(tasks = [[8, 12], [15, 20], [5, 7], [10, 15], [3, 6]]) == 43\n assert candidate(tasks = [[7, 10], [4, 8], [6, 12], [2, 5], [1, 3]]) == 22\n assert candidate(tasks = [[1, 2], [3, 6], [5, 10], [7, 14], [9, 18], [11, 22], [13, 26], [15, 30], [17, 34], [19, 38], [21, 42], [23, 46], [25, 50], [27, 54], [29, 58], [31, 62], [33, 66], [35, 70], [37, 74], [39, 78]]) == 402\n assert candidate(tasks = [[5, 5], [5, 5], [5, 5], [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(tasks = [[1000, 2000], [500, 1500], [250, 750], [125, 375], [63, 188], [31, 95], [16, 48], [8, 25], [4, 13], [2, 7], [1, 4]]) == 2500\n assert candidate(tasks = [[1000, 1010], [999, 1009], [998, 1008], [997, 1007], [996, 1006], [995, 1005], [994, 1004], [993, 1003], [992, 1002], [991, 1001]]) == 9965\n assert candidate(tasks = [[100, 200], [50, 200], [30, 200], [10, 200], [5, 200], [1, 200], [100, 300], [50, 300], [30, 300], [10, 300], [5, 300], [1, 300]]) == 492\n assert candidate(tasks = [[20, 25], [10, 13], [5, 6], [15, 20], [2, 3], [7, 10]]) == 60\n assert candidate(tasks = [[100, 150], [50, 100], [25, 50], [10, 20], [5, 10]]) == 200\n assert candidate(tasks = [[50, 60], [40, 70], [30, 80], [20, 90], [10, 100], [5, 110], [1, 120]]) == 166\n assert candidate(tasks = [[1000, 1010], [900, 910], [800, 810], [700, 710], [600, 610], [500, 510], [400, 410], [300, 310], [200, 210], [100, 110], [50, 60], [10, 20], [1, 2]]) == 5570\n assert candidate(tasks = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95]]) == 110\n assert candidate(tasks = [[500, 1000], [400, 900], [300, 800], [200, 700], [100, 600], [50, 500], [40, 400], [30, 300], [20, 200], [10, 100]]) == 2000\n assert candidate(tasks = [[1000, 2000], [500, 1500], [300, 1200], [200, 1100], [100, 1000]]) == 3000\n assert candidate(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]]) == 226\n assert candidate(tasks = [[5, 7], [8, 10], [12, 14], [15, 18], [20, 22]]) == 62\n assert candidate(tasks = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]]) == 37\n assert candidate(tasks = [[1, 20], [2, 21], [3, 22], [4, 23], [5, 24], [6, 25]]) == 40\n assert candidate(tasks = [[2, 5], [3, 6], [4, 7], [5, 8], [1, 3]]) == 17\n assert candidate(tasks = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0]]) == 55\n assert candidate(tasks = [[100, 200], [150, 250], [200, 300], [50, 100], [25, 50], [75, 150], [30, 60], [40, 80], [60, 120], [80, 160]]) == 835\n assert candidate(tasks = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == 460\n assert candidate(tasks = [[10, 20], [10, 30], [10, 40], [10, 50], [10, 60], [10, 70], [10, 80], [10, 90], [10, 100], [10, 110], [10, 120]]) == 120\n assert candidate(tasks = [[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]]) == 16\n assert candidate(tasks = [[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]]) == 121\n assert candidate(tasks = [[5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20]]) == 60\n assert candidate(tasks = [[5, 7], [8, 12], [10, 15], [3, 4], [6, 9], [2, 3]]) == 35\n assert candidate(tasks = [[2, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 80\n assert candidate(tasks = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 10\n assert candidate(tasks = [[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]]) == 210\n assert candidate(tasks = [[5000, 5005], [4000, 4007], [3000, 3009], [2000, 2011], [1000, 1013], [500, 517], [100, 121], [50, 130], [10, 140], [1, 150]]) == 15666\n assert candidate(tasks = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]]) == 160\n assert candidate(tasks = [[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]]) == 191\n assert candidate(tasks = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992], [10, 991]]) == 1036\n assert candidate(tasks = [[7, 10], [5, 7], [4, 5], [3, 6], [2, 4]]) == 22\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [100, 100]]) == 115\n assert candidate(tasks = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]]) == 25\n assert candidate(tasks = [[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]]) == 91\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,4],[4,8]]", "[[1,3],[2,4],[10,11],[10,12],[8,9]]", "[[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]"], "hints": ["We can easily figure that the f(x) : does x solve this array is monotonic so binary Search is doable", "Figure a sorting pattern"], "metadata": {"canonical_parameter_names": ["tasks"], "leetcode_dataset_entry_point": "Solution().minimumEffort", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:51+00:00", "tests_total": 104, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumEffort($tasks) {", "container": "Solution", "callable": "minimumEffort", "parameters": [{"name": "tasks", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1668, "task_id": "maximum-repeating-substring", "difficulty": "Easy", "problem_description": "For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.\n\nGiven strings sequence and word, return the maximum k-repeating value of word in sequence.\n\nExample 1:\n\nInput: sequence = \"ababc\", word = \"ab\"\nOutput: 2\nExplanation: \"abab\" is a substring in \"ababc\".\n\nExample 2:\n\nInput: sequence = \"ababc\", word = \"ba\"\nOutput: 1\nExplanation: \"ba\" is a substring in \"ababc\". \"baba\" is not a substring in \"ababc\".\n\nExample 3:\n\nInput: sequence = \"ababc\", word = \"ac\"\nOutput: 0\nExplanation: \"ac\" is not a substring in \"ababc\".\n\nConstraints:\n\n- 1 <= sequence.length <= 100\n- 1 <= word.length <= 100\n- sequence and word contains only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sequence = \"ababc\",word = \"ac\") == 0\n assert candidate(sequence = \"banana\",word = \"ana\") == 1\n assert candidate(sequence = \"abcabcabc\",word = \"abc\") == 3\n assert candidate(sequence = \"aaaa\",word = \"aa\") == 2\n assert candidate(sequence = \"abc\",word = \"d\") == 0\n assert candidate(sequence = \"ababc\",word = \"ab\") == 2\n assert candidate(sequence = \"mississippi\",word = \"issi\") == 1\n assert candidate(sequence = \"aaaabaaa\",word = \"aa\") == 2\n assert candidate(sequence = \"ababc\",word = \"ba\") == 1\n assert candidate(sequence = \"a\",word = \"a\") == 1\n assert candidate(sequence = \"abcabcabc\",word = \"abcd\") == 0\n assert candidate(sequence = \"hellohellohello\",word = \"llohe\") == 2\n assert candidate(sequence = \"abababababab\",word = \"abab\") == 3\n assert candidate(sequence = \"abababababababab\",word = \"ababab\") == 2\n assert candidate(sequence = \"aabbccddeeff\",word = \"aabbcc\") == 1\n assert candidate(sequence = \"ababababab\",word = \"ababab\") == 1\n assert candidate(sequence = \"xyxxyxyxyxyxyxyxyxyxyx\",word = \"xyxxy\") == 1\n assert candidate(sequence = \"abcabcabcabc\",word = \"abcd\") == 0\n assert candidate(sequence = \"ababababab\",word = \"ab\") == 5\n assert candidate(sequence = \"abcdabcdabcdabcdabcdabcdabcdabcd\",word = \"abcd\") == 8\n assert candidate(sequence = \"abacabadabacaba\",word = \"dab\") == 1\n assert candidate(sequence = \"abcabcabcabcabcabc\",word = \"abcabcabc\") == 2\n assert candidate(sequence = \"abababababababababab\",word = \"ababab\") == 3\n assert candidate(sequence = \"banana\",word = \"ban\") == 1\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"cab\") == 4\n assert candidate(sequence = \"abacabadabacaba\",word = \"cab\") == 1\n assert candidate(sequence = \"hellohellohellohello\",word = \"hello\") == 4\n assert candidate(sequence = \"banana\",word = \"na\") == 2\n assert candidate(sequence = \"abababababab\",word = \"baba\") == 2\n assert candidate(sequence = \"ababababababababab\",word = \"ababab\") == 3\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"abcd\") == 0\n assert candidate(sequence = \"xyzyzyzyzyzyzyzy\",word = \"zyzyzyzyzyzyzyzy\") == 0\n assert candidate(sequence = \"zzzxxzzzxxzzzxx\",word = \"zzzxx\") == 3\n assert candidate(sequence = \"aabbccddeeffgghhiijj\",word = \"ccdd\") == 1\n assert candidate(sequence = \"xyzxyzxyzxyzxyz\",word = \"zyx\") == 0\n assert candidate(sequence = \"abcabcabcabc\",word = \"cab\") == 3\n assert candidate(sequence = \"ababababababababab\",word = \"bab\") == 1\n assert candidate(sequence = \"bananaananabana\",word = \"ana\") == 2\n assert candidate(sequence = \"aaaaabaaa\",word = \"aaaa\") == 1\n assert candidate(sequence = \"abacabadabacaba\",word = \"bac\") == 1\n assert candidate(sequence = \"aaaaabbbbbcccc\",word = \"abc\") == 0\n assert candidate(sequence = \"aaaaaaa\",word = \"aaa\") == 2\n assert candidate(sequence = \"zzzzzzzzzzzz\",word = \"zzzz\") == 3\n assert candidate(sequence = \"ababababa\",word = \"aba\") == 1\n assert candidate(sequence = \"abababcabababc\",word = \"ababc\") == 1\n assert candidate(sequence = \"ababababababababababababababab\",word = \"abab\") == 7\n assert candidate(sequence = \"aaaabaaaabaaaab\",word = \"aaab\") == 1\n assert candidate(sequence = \"abababababababab\",word = \"baba\") == 3\n assert candidate(sequence = \"xyzyzyzyzyzyzyzy\",word = \"zyzy\") == 3\n assert candidate(sequence = \"abcabcabcabc\",word = \"abcabc\") == 2\n assert candidate(sequence = \"aaaabaaaabaaaabaaaab\",word = \"aaaab\") == 4\n assert candidate(sequence = \"abcabcabc\",word = \"cab\") == 2\n assert candidate(sequence = \"abababababababababab\",word = \"abab\") == 5\n assert candidate(sequence = \"abacabadabacaba\",word = \"abaca\") == 1\n assert candidate(sequence = \"aaaaaaa\",word = \"a\") == 7\n assert candidate(sequence = \"aabbccddeeff\",word = \"abc\") == 0\n assert candidate(sequence = \"abcabcabcabcabcabcabc\",word = \"abca\") == 1\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"abcabcab\") == 1\n assert candidate(sequence = \"abcdefabcdefabcdef\",word = \"defabc\") == 2\n assert candidate(sequence = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word = \"aabbccddeeffgghhiijjkkll\") == 1\n assert candidate(sequence = \"abcdefabcdefabcdef\",word = \"abcdef\") == 3\n assert candidate(sequence = \"zzzzzzzzzzzzzzzzzzzz\",word = \"zzzzzz\") == 3\n assert candidate(sequence = \"xyzxyzxyzxyzxyzxyz\",word = \"xyzxyzxyz\") == 2\n assert candidate(sequence = \"abababab\",word = \"ab\") == 4\n assert candidate(sequence = \"abacabacabacabacabac\",word = \"abac\") == 5\n assert candidate(sequence = \"aaaaab\",word = \"aaa\") == 1\n assert candidate(sequence = \"aaaaaaa\",word = \"aaaa\") == 1\n assert candidate(sequence = \"ababababababababababab\",word = \"babab\") == 1\n assert candidate(sequence = \"abababab\",word = \"aba\") == 1\n assert candidate(sequence = \"aaaaaabaaa\",word = \"aaa\") == 2\n assert candidate(sequence = \"aaaaabaaaa\",word = \"aaa\") == 1\n assert candidate(sequence = \"ababababab\",word = \"aba\") == 1\n assert candidate(sequence = \"hellohellohellohellohello\",word = \"hellohello\") == 2\n assert candidate(sequence = \"abcabcabcabcabcabcabcabcabcabc\",word = \"abcabcabc\") == 3\n assert candidate(sequence = \"aabbccddeeefffggghhh\",word = \"eefffggg\") == 1\n assert candidate(sequence = \"mississippi\",word = \"iss\") == 2\n assert candidate(sequence = \"abacabacabac\",word = \"abac\") == 3\n assert candidate(sequence = \"xyxyxyxyxyxyxyxy\",word = \"xyxyxyxyxyxyxy\") == 1\n assert candidate(sequence = \"abcabcabcabcabcabcabcabc\",word = \"abcabcabc\") == 2\n assert candidate(sequence = \"aabbccddeeffgghhiijj\",word = \"aabbcc\") == 1\n assert candidate(sequence = \"xyxyxyxyxyxyxyxyxyxy\",word = \"xyxy\") == 5\n assert candidate(sequence = \"xyxyxyxyxyxyxy\",word = \"xyxy\") == 3\n assert candidate(sequence = \"zzzzzzzzzzzzzzzzzzzz\",word = \"zzzz\") == 5\n assert candidate(sequence = \"mississippi\",word = \"miss\") == 1\n assert candidate(sequence = \"ababababababababab\",word = \"ab\") == 9\n assert candidate(sequence = \"hellohellohellohello\",word = \"hellohello\") == 2\n assert candidate(sequence = \"banana\",word = \"nan\") == 1\n assert candidate(sequence = \"abababaaba\",word = \"aba\") == 2\n assert candidate(sequence = \"hellohellohello\",word = \"lohel\") == 2\n assert candidate(sequence = \"qqqqqqqqqqqq\",word = \"qqqq\") == 3\n assert candidate(sequence = \"xyxxyxyxyxyxyx\",word = \"xyxyx\") == 1\n assert candidate(sequence = \"abcdabcdabcdabcd\",word = \"abcdabcd\") == 2\n assert candidate(sequence = \"sequencewordsequenceword\",word = \"word\") == 1\n assert candidate(sequence = \"abababa\",word = \"aba\") == 1\n assert candidate(sequence = \"xyxyxyxyxyxyxyxy\",word = \"xyxy\") == 4\n assert candidate(sequence = \"abcdefgabcdefgabcdefg\",word = \"abcdefg\") == 3\n assert candidate(sequence = \"abababababababababababab\",word = \"abababab\") == 3\n assert candidate(sequence = \"aaaabaaaabaaaabaaaab\",word = \"aaab\") == 1\n assert candidate(sequence = \"ababababababababab\",word = \"abab\") == 4\n assert candidate(sequence = \"abcdefghijabcdefghij\",word = \"cde\") == 1\n assert candidate(sequence = \"mamamamamamama\",word = \"mama\") == 3\n assert candidate(sequence = \"ababababababab\",word = \"abab\") == 3\n assert candidate(sequence = \"hellohellohello\",word = \"hello\") == 3\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"abcabcabcabc\") == 1\n assert candidate(sequence = \"xyzxyzxyzxyz\",word = \"xyz\") == 4\n assert candidate(sequence = \"abcabcabcabcabcabc\",word = \"bcabc\") == 1\n assert candidate(sequence = \"abababababababab\",word = \"abab\") == 4\n assert candidate(sequence = \"abcdabcdabcdabcdabcdabcdabcdabcd\",word = \"dabc\") == 7\n assert candidate(sequence = \"mississippiissippi\",word = \"issi\") == 1\n assert candidate(sequence = \"xyzxyzxyz\",word = \"xy\") == 1\n assert candidate(sequence = \"abcabcabcabcabcabcabc\",word = \"abcabcabcabcabc\") == 1\n assert candidate(sequence = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word = \"zzzz\") == 7\n assert candidate(sequence = \"abcabcabcabcabcabc\",word = \"abcabc\") == 3\n assert candidate(sequence = \"abcdabcdabcdabcdabcdabcdabcdabcd\",word = \"dcba\") == 0\n assert candidate(sequence = \"qwertyqwertyqwerty\",word = \"qwerty\") == 3\n assert candidate(sequence = \"acacacacacac\",word = \"acac\") == 3\n assert candidate(sequence = \"ababababa\",word = \"bab\") == 1\n assert candidate(sequence = \"ababcabcababc\",word = \"abcab\") == 1\n assert candidate(sequence = \"aaaaaaaaaa\",word = \"aaa\") == 3\n assert candidate(sequence = \"aaaaaaaaaa\",word = \"aaaa\") == 2\n assert candidate(sequence = \"mississippi\",word = \"sip\") == 1\n assert candidate(sequence = \"aaaaaaa\",word = \"aa\") == 3\n assert candidate(sequence = \"aaaaaabaaaaa\",word = \"aaaaa\") == 1\n assert candidate(sequence = \"xyzxyzxyzxyz\",word = \"xyzxyz\") == 2\n assert candidate(sequence = \"ababababc\",word = \"aba\") == 1\n assert candidate(sequence = \"abcabcabcabcabcabc\",word = \"cab\") == 5\n assert candidate(sequence = \"abacabacabacabac\",word = \"abacabac\") == 2\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"abcabcabc\") == 1\n assert candidate(sequence = \"abcabcabcabcabc\",word = \"abcabc\") == 2\n assert candidate(sequence = \"xyzxyzyzyzxzyzyzxzyzyz\",word = \"zyz\") == 1\n assert candidate(sequence = \"xyzxyzxyzxyz\",word = \"zyxzyx\") == 0\n assert candidate(sequence = \"xyzxyzxyzxyz\",word = \"xyzxyzxyz\") == 1\n assert candidate(sequence = \"aaaaaa\",word = \"aa\") == 3\n assert candidate(sequence = \"abcdabcdabcdabcdabcdabcdabcdabcd\",word = \"abcdabcdabcdabcd\") == 2\n assert candidate(sequence = \"abcdabcdabcdabcd\",word = \"cdab\") == 3\n assert candidate(sequence = \"zzzzzzzz\",word = \"zzzz\") == 2\n assert candidate(sequence = \"abcdefgabcdefgabcdefg\",word = \"efg\") == 1\n assert candidate(sequence = \"zzzzzzzzzzzzzzzzzzzz\",word = \"zzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(sequence = \"abcdefgabcdefg\",word = \"abcdefg\") == 2\n assert candidate(sequence = \"bananaananabananananabanananananana\",word = \"anana\") == 2\n assert candidate(sequence = \"qwertyqwertyqwerty\",word = \"erty\") == 1\n assert candidate(sequence = \"pqrspqrspqrspqrspqr\",word = \"pqrs\") == 4\n assert candidate(sequence = \"ababababababa\",word = \"bab\") == 1\n assert candidate(sequence = \"abcbabcabcbabcabc\",word = \"abcabc\") == 1\n assert candidate(sequence = \"qwertyqwertyqwerty\",word = \"qwertyqwerty\") == 1\n assert candidate(sequence = \"zzzzzzzzzzzz\",word = \"zzz\") == 4\n assert candidate(sequence = \"zzzzzzzzzzzzzzz\",word = \"zzzz\") == 3\n assert candidate(sequence = \"xyzxyzxyz\",word = \"xyz\") == 3\n assert candidate(sequence = \"aabbccddeeff\",word = \"eeff\") == 1\n assert candidate(sequence = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word = \"mmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(sequence = \"ababababab\",word = \"abab\") == 2\n assert candidate(sequence = \"xyxyxyxyxyxyxyxy\",word = \"xyxyxyxyxyxyxyxy\") == 1\n assert candidate(sequence = \"abcdabcdabcdabcdabcdabcd\",word = \"abcdabcd\") == 3\n assert candidate(sequence = \"qwertyqwertyqwertyqwerty\",word = \"qwertyqwerty\") == 2\n", "comparison": "exact"}, "public_tests": ["\"ababc\"\n\"ab\"", "\"ababc\"\n\"ba\"", "\"ababc\"\n\"ac\""], "hints": ["The constraints are low enough for a brute force approach.", "Try every k value from 0 upwards until word is no longer k-repeating."], "metadata": {"canonical_parameter_names": ["sequence", "word"], "leetcode_dataset_entry_point": "Solution().maxRepeating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:53+00:00", "tests_total": 154, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "string-matching"]}, "language": "php", "interface": {"raw_signature": "function maxRepeating($sequence, $word) {", "container": "Solution", "callable": "maxRepeating", "parameters": [{"name": "sequence", "type": "String"}, {"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1671, "task_id": "minimum-number-of-removals-to-make-mountain-array", "difficulty": "Hard", "problem_description": "You may recall that an array arr is a mountain array if and only if:\n\n- arr.length >= 3\n- There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n - arr[0] < arr[1] < ... < arr[i - 1] < arr[i]\n - arr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\nGiven an integer array nums, return the minimum number of elements to remove to make nums a mountain array.\n\nExample 1:\n\nInput: nums = [1,3,1]\nOutput: 0\nExplanation: The array itself is a mountain array so we do not need to remove any elements.\n\nExample 2:\n\nInput: nums = [2,1,1,5,6,2,3,1]\nOutput: 3\nExplanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n\nConstraints:\n\n- 3 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^9\n- It is guaranteed that you can make a mountain array out of nums.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 1]) == 0\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 = [100, 92, 89, 77, 74, 66, 64, 66, 64]) == 6\n assert candidate(nums = [1, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [4, 3, 2, 1, 1, 2, 3, 1]) == 4\n assert candidate(nums = [2, 1, 1, 5, 6, 2, 3, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 1, 5, 7, 6, 3, 2]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [9, 8, 1, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 3, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 10, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2, 3, 5, 7, 9, 11]) == 5\n assert candidate(nums = [20, 40, 30, 50, 60, 70, 35, 10, 5, 45, 65, 75, 25, 55, 85, 95, 15, 25, 35, 45]) == 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, 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]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 8, 6, 4, 2]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 10\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, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 7\n assert candidate(nums = [10, 20, 15, 20, 25, 30, 25, 20, 15, 10, 5, 10, 15, 20]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 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]) == 54\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 19\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, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 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]) == 14\n assert candidate(nums = [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]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 16, 17, 18, 19, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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]) == 27\n assert candidate(nums = [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, 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, 3, 5, 7, 9, 7, 5, 3, 1, 3, 5, 7, 9, 7, 5, 3, 1]) == 8\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100, 5, 10, 15]) == 11\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]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 24\n assert candidate(nums = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [2, 3, 1, 4, 3, 2, 5, 4, 3, 2, 1, 6, 7, 8, 7, 6, 5, 4, 3]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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, 3, 2, 1]) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5]) == 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, 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, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 29\n assert candidate(nums = [1, 5, 3, 7, 5, 9, 7, 11, 9, 13, 11, 15, 13, 17, 15, 19, 17]) == 7\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, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 14\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\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]) == 20\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 9\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]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 9\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]) == 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, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 10\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]) == 11\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 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, 6, 7, 8, 9, 10]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\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]) == 13\n assert candidate(nums = [1, 5, 3, 4, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 13\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, 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\n assert candidate(nums = [1, 2, 1, 2, 3, 4, 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]) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 0\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]) == 12\n assert candidate(nums = [1, 5, 3, 4, 6, 7, 8, 9, 10, 8, 7, 6, 5, 4, 3, 2, 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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [3, 5, 4, 5, 4, 3, 5, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 5]) == 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, 2, 3, 4, 5, 6, 7, 8, 9, 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]) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 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]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 125, 120, 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15]) == 7\n assert candidate(nums = [1, 1000000000, 999999999, 1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,3,1]", "[2,1,1,5,6,2,3,1]"], "hints": ["Think the opposite direction instead of minimum elements to remove the maximum mountain subsequence", "Think of LIS it's kind of close"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumMountainRemovals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:26:58+00:00", "tests_total": 107, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumMountainRemovals($nums) {", "container": "Solution", "callable": "minimumMountainRemovals", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1672, "task_id": "richest-customer-wealth", "difficulty": "Easy", "problem_description": "You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i^th customer has in the j^th bank. Return the wealth that the richest customer has.\n\nA customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.\n\nExample 1:\n\nInput: accounts = [[1,2,3],[3,2,1]]\nOutput: 6\nExplanation:\n1st customer has wealth = 1 + 2 + 3 = 6\n2nd customer has wealth = 3 + 2 + 1 = 6\nBoth customers are considered the richest with a wealth of 6 each, so return 6.\n\nExample 2:\n\nInput: accounts = [[1,5],[7,3],[3,5]]\nOutput: 10\nExplanation:\n1st customer has wealth = 6\n2nd customer has wealth = 10\n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.\n\nExample 3:\n\nInput: accounts = [[2,8,7],[7,1,3],[1,9,5]]\nOutput: 17\n\nConstraints:\n\n- m == accounts.length\n- n == accounts[i].length\n- 1 <= m, n <= 50\n- 1 <= accounts[i][j] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(accounts = [[10, 10], [20, 20], [30, 30], [40, 40]]) == 80\n assert candidate(accounts = [[100], [100], [100]]) == 100\n assert candidate(accounts = [[10, 20, 30], [5, 15, 25], [1, 2, 3]]) == 60\n assert candidate(accounts = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(accounts = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == 25\n assert candidate(accounts = [[50, 50], [50, 50], [50, 50]]) == 100\n assert candidate(accounts = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 15\n assert candidate(accounts = [[1, 5], [7, 3], [3, 5]]) == 10\n assert candidate(accounts = [[10, 10, 10], [5, 5, 5], [1, 1, 1]]) == 30\n assert candidate(accounts = [[1], [2], [3]]) == 3\n assert candidate(accounts = [[2, 8, 7], [7, 1, 3], [1, 9, 5]]) == 17\n assert candidate(accounts = [[1, 2, 3], [3, 2, 1]]) == 6\n assert candidate(accounts = [[1], [2], [3], [4], [5]]) == 5\n assert candidate(accounts = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]]) == 190\n assert candidate(accounts = [[1, 100, 1], [10, 50, 10], [100, 1, 100], [50, 10, 50]]) == 201\n assert candidate(accounts = [[99, 1, 2, 3], [4, 5, 6, 99], [7, 8, 9, 10]]) == 114\n assert candidate(accounts = [[10, 20, 30, 40, 50], [90, 80, 70, 60, 50], [1, 2, 3, 4, 5]]) == 350\n assert candidate(accounts = [[50, 1, 50], [1, 50, 50], [50, 50, 1], [50, 1, 50], [1, 50, 50], [50, 50, 1]]) == 101\n assert candidate(accounts = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 2, 3, 4, 5]]) == 150\n assert candidate(accounts = [[99, 1, 1, 1, 1], [1, 99, 1, 1, 1], [1, 1, 99, 1, 1], [1, 1, 1, 99, 1], [1, 1, 1, 1, 99]]) == 103\n assert candidate(accounts = [[90, 5], [5, 90], [45, 55], [55, 45], [75, 25], [25, 75], [60, 40], [40, 60]]) == 100\n assert candidate(accounts = [[100, 100, 100, 100, 100], [99, 99, 99, 99, 99], [98, 98, 98, 98, 98], [97, 97, 97, 97, 97], [96, 96, 96, 96, 96]]) == 500\n assert candidate(accounts = [[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(accounts = [[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(accounts = [[10, 20, 30], [50, 60, 70], [80, 90, 100], [10, 10, 10]]) == 270\n assert candidate(accounts = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50], [60, 60, 60], [70, 70, 70], [80, 80, 80], [90, 90, 90], [100, 100, 100]]) == 300\n assert candidate(accounts = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]]) == 190\n assert candidate(accounts = [[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(accounts = [[99, 1], [1, 99], [49, 51], [51, 49], [50, 50]]) == 100\n assert candidate(accounts = [[30, 20, 10], [10, 20, 30], [20, 30, 10], [30, 10, 20], [10, 30, 20]]) == 60\n assert candidate(accounts = [[50, 50, 50], [50, 50, 50], [50, 50, 50], [50, 50, 50], [50, 50, 50]]) == 150\n assert candidate(accounts = [[99, 1], [98, 2], [97, 3], [96, 4], [95, 5], [94, 6], [93, 7], [92, 8], [91, 9], [90, 10]]) == 100\n assert candidate(accounts = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]]) == 90\n assert candidate(accounts = [[1, 99], [2, 98], [3, 97], [4, 96], [5, 95]]) == 100\n assert candidate(accounts = [[45, 55], [46, 54], [47, 53], [48, 52], [49, 51]]) == 100\n assert candidate(accounts = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [10, 9, 8, 7, 6], [6, 7, 8, 9, 10]]) == 40\n assert candidate(accounts = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 55\n assert candidate(accounts = [[99, 1, 100], [100, 1, 99], [50, 50, 50]]) == 200\n assert candidate(accounts = [[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]]) == 55\n assert candidate(accounts = [[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]]) == 120\n assert candidate(accounts = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]]) == 500\n assert candidate(accounts = [[100, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 100, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 100, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 100, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 100, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 100, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 100, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 100, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 100, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 100]]) == 109\n assert candidate(accounts = [[90, 90, 90, 90, 90], [80, 80, 80, 80, 80], [70, 70, 70, 70, 70], [60, 60, 60, 60, 60], [50, 50, 50, 50, 50]]) == 450\n assert candidate(accounts = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]]) == 20\n assert candidate(accounts = [[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]]) == 40\n assert candidate(accounts = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 2, 3, 4, 5], [50, 40, 30, 20, 10]]) == 150\n assert candidate(accounts = [[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]]) == 100\n assert candidate(accounts = [[10, 10, 10, 10], [20, 20, 20, 20], [30, 30, 30, 30], [40, 40, 40, 40]]) == 160\n assert candidate(accounts = [[10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 100\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[3,2,1]]", "[[1,5],[7,3],[3,5]]", "[[2,8,7],[7,1,3],[1,9,5]]"], "hints": ["Calculate the wealth of each customer", "Find the maximum element in array."], "metadata": {"canonical_parameter_names": ["accounts"], "leetcode_dataset_entry_point": "Solution().maximumWealth", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:00+00:00", "tests_total": 85, "tests_dropped": 36, "flags": [], "topic_tags": ["array", "matrix"]}, "language": "php", "interface": {"raw_signature": "function maximumWealth($accounts) {", "container": "Solution", "callable": "maximumWealth", "parameters": [{"name": "accounts", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1673, "task_id": "find-the-most-competitive-subsequence", "difficulty": "Medium", "problem_description": "Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.\n\nAn array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.\n\nWe define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position where a and b differ, subsequence a has a number less than the corresponding number in b. For example, [1,3,4] is more competitive than [1,3,5] because the first position they differ is at the final number, and 4 is less than 5.\n\nExample 1:\n\nInput: nums = [3,5,2,6], k = 2\nOutput: [2,6]\nExplanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.\n\nExample 2:\n\nInput: nums = [2,4,3,3,5,4,9,6], k = 4\nOutput: [2,3,3,4]\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^9\n- 1 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 8, 7, 6, 5, 4, 3, 2],k = 1) == [1]\n assert candidate(nums = [2, 4, 3, 3, 5, 4, 9, 6],k = 4) == [2, 3, 3, 4]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == [5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7],k = 3) == [1, 2, 3]\n assert candidate(nums = [1, 3, 1, 1, 2, 3, 1],k = 4) == [1, 1, 1, 1]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],k = 3) == [3, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7],k = 5) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == [1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == [1, 2, 3]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],k = 2) == [1, 1]\n assert candidate(nums = [3, 5, 2, 6],k = 2) == [2, 6]\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 2) == [1, 2]\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1],k = 2) == [1, 1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == [9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == [4, 3, 2, 1, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9, 10],k = 5) == [2, 1, 8, 9, 10]\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == [50, 40, 30, 20, 10]\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == [1, 2, 3, 4, 5]\n assert candidate(nums = [100, 200, 150, 250, 300, 100, 200, 300, 100, 200],k = 6) == [100, 100, 200, 300, 100, 200]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2],k = 5) == [1, 1, 2, 1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 6) == [1, 1, 2, 3, 4, 5]\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10],k = 10) == [5, 6, 7, 8, 9, 1, 2, 3, 4, 10]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9],k = 5) == [3, 2, 1, 8, 9]\n assert candidate(nums = [5, 1, 4, 3, 2, 6, 7, 8, 9, 10],k = 5) == [1, 2, 6, 7, 8]\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10],k = 7) == [5, 6, 1, 2, 3, 4, 10]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 4) == [1, 1, 1, 1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == [10, 20, 30, 40, 50]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == [4, 3, 2, 1, 0]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 3) == [10, 10, 10]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 4) == [1, 1, 2, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == [2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == [1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],k = 3) == [1, 1, 1]\n assert candidate(nums = [9, 1, 9, 2, 9, 3, 9, 4, 9, 5],k = 5) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, 5, 6, 3, 2, 1, 8, 7],k = 3) == [1, 8, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],k = 5) == [1, 2, 3, 4, 0]\n assert candidate(nums = [5, 3, 1, 2, 4, 6, 8, 7, 9, 0],k = 5) == [1, 2, 4, 6, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [8, 6, 9, 2, 5, 7, 8, 8],k = 4) == [2, 5, 7, 8]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 3) == [1, 2, 3]\n assert candidate(nums = [1, 3, 1, 1, 2, 3, 4, 1, 5, 6],k = 3) == [1, 1, 1]\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 5) == [3, 3, 3, 3, 3]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == [3, 2, 1]\n assert candidate(nums = [1, 3, 1, 1, 2, 3, 1, 2, 3, 1],k = 4) == [1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1],k = 4) == [1, 1, 1, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10],k = 5) == [1, 6, 7, 8, 9]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 6) == [1, 1, 2, 3, 5, 9]\n assert candidate(nums = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == [1, 2, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6],k = 5) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10],k = 7) == [1, 2, 3, 4, 6, 5, 10]\n assert candidate(nums = [5, 3, 1, 2, 4, 1, 3, 2, 1, 4, 2, 3],k = 6) == [1, 1, 1, 4, 2, 3]\n assert candidate(nums = [5, 1, 4, 3, 5, 9, 2, 1, 4, 7, 8, 1],k = 7) == [1, 2, 1, 4, 7, 8, 1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 8) == [1, 1, 2, 2, 3, 3, 4, 4]\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 = 10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7],k = 8) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [100, 200, 150, 100, 50, 250, 300, 200, 150],k = 5) == [50, 250, 300, 200, 150]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == [0, 0, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == [1, 1, 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],k = 10) == [0, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 7) == [10, 20, 30, 40, 50, 60, 70]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 5) == [10, 10, 10, 10, 10]\n assert candidate(nums = [1, 5, 4, 3, 2, 6],k = 3) == [1, 2, 6]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 7) == [3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [5, 6, 1, 2, 3, 4, 10, 9, 8, 7],k = 4) == [1, 2, 3, 4]\n assert candidate(nums = [8, 9, 7, 6, 5, 4, 3, 2, 1],k = 4) == [4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 6) == [1, 1, 1, 1, 2, 3]\n assert candidate(nums = [5, 1, 1, 1, 5, 1, 1, 1, 5, 1, 1, 1, 5],k = 6) == [1, 1, 1, 1, 1, 1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == [5, 5, 5, 5, 5]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 0],k = 5) == [1, 2, 3, 4, 0]\n assert candidate(nums = [7, 1, 5, 3, 6, 4],k = 3) == [1, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 14, 4, 14, 13, 2, 6, 13],k = 5) == [4, 13, 2, 6, 13]\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 4, 3, 2, 1],k = 4) == [1, 1, 2, 1]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 6) == [1, 2, 4, 6, 8, 10]\n assert candidate(nums = [5, 1, 9, 7, 3, 8, 2, 4, 6],k = 4) == [1, 2, 4, 6]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 5) == [1, 1, 2, 2, 3]\n assert candidate(nums = [8, 6, 5, 7, 3, 4, 1, 2, 9, 0],k = 4) == [1, 2, 9, 0]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 4) == [1, 1, 2, 2]\n assert candidate(nums = [4, 3, 5, 1, 2, 3, 6, 7, 8, 9],k = 5) == [1, 2, 3, 6, 7]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9],k = 5) == [1, 6, 7, 8, 9]\n assert candidate(nums = [4, 3, 2, 1, 2, 3, 4, 3, 2, 1],k = 5) == [1, 2, 3, 2, 1]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 0],k = 6) == [1, 2, 3, 4, 5, 0]\n assert candidate(nums = [1, 3, 2, 1, 2, 1, 3, 2, 1],k = 3) == [1, 1, 1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5],k = 10) == [4, 3, 2, 1, 0, 9, 8, 7, 6, 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],k = 15) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9],k = 3) == [1, 1, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 6) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == [100, 200, 300, 400, 500]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],k = 3) == [1, 2, 0]\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 = 10) == [0, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 8, 9],k = 5) == [2, 1, 0, 8, 9]\n assert candidate(nums = [1, 3, 2, 4, 1, 2, 3, 1, 2, 3],k = 4) == [1, 1, 1, 2]\n assert candidate(nums = [5, 2, 6, 3, 4, 1],k = 2) == [2, 1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == [7, 7, 7, 7, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 12) == [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0],k = 5) == [4, 3, 2, 1, 0]\n assert candidate(nums = [5, 3, 1, 4, 2, 6, 8, 7, 9, 0, 11, 10, 12, 13, 14],k = 10) == [1, 2, 6, 7, 0, 11, 10, 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],k = 10) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n", "comparison": "exact"}, "public_tests": ["[3,5,2,6]\n2", "[2,4,3,3,5,4,9,6]\n4"], "hints": ["In lexicographical order, the elements to the left have higher priority than those that come after. Can you think of a strategy that incrementally builds the answer from left to right?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().mostCompetitive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:03+00:00", "tests_total": 106, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "stack", "greedy", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function mostCompetitive($nums, $k) {", "container": "Solution", "callable": "mostCompetitive", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1674, "task_id": "minimum-moves-to-make-array-complementary", "difficulty": "Medium", "problem_description": "You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.\n\nThe array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.\n\nReturn the minimum number of moves required to make nums complementary.\n\nExample 1:\n\nInput: nums = [1,2,4,3], limit = 4\nOutput: 1\nExplanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\nTherefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.\n\nExample 2:\n\nInput: nums = [1,2,2,1], limit = 2\nOutput: 2\nExplanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.\n\nExample 3:\n\nInput: nums = [1,2,1,2], limit = 2\nOutput: 0\nExplanation: nums is already complementary.\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 10^5\n- 1 <= nums[i] <= limit <= 10^5\n- n is even.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3],limit = 5) == 0\n assert candidate(nums = [1, 1, 1, 1],limit = 10) == 0\n assert candidate(nums = [5, 3, 5, 3],limit = 10) == 0\n assert candidate(nums = [1, 5, 5, 1],limit = 5) == 2\n assert candidate(nums = [1, 2, 2, 1],limit = 2) == 2\n assert candidate(nums = [100000, 1, 100000, 1],limit = 100000) == 0\n assert candidate(nums = [100000, 1, 1, 100000],limit = 100000) == 2\n assert candidate(nums = [100000, 1, 1, 100000, 1, 1, 100000, 1],limit = 100000) == 1\n assert candidate(nums = [3, 5, 5, 3],limit = 5) == 1\n assert candidate(nums = [1, 1, 1, 1],limit = 1) == 0\n assert candidate(nums = [1, 5, 9, 13],limit = 15) == 0\n assert candidate(nums = [1, 3, 5, 7],limit = 10) == 0\n assert candidate(nums = [2, 5, 6, 5, 2, 2],limit = 7) == 2\n assert candidate(nums = [1, 9, 9, 1, 1, 9, 9, 1],limit = 9) == 4\n assert candidate(nums = [10, 1, 10, 1],limit = 10) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000],limit = 100000) == 0\n assert candidate(nums = [10, 15, 15, 10],limit = 20) == 1\n assert candidate(nums = [2, 3, 4, 3, 2, 1],limit = 6) == 2\n assert candidate(nums = [1, 9, 9, 1],limit = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6],limit = 6) == 0\n assert candidate(nums = [10, 1, 1, 10],limit = 10) == 2\n assert candidate(nums = [5, 5, 5, 5],limit = 10) == 0\n assert candidate(nums = [50000, 50000, 50000, 50000],limit = 100000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6],limit = 7) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5],limit = 5) == 0\n assert candidate(nums = [1, 3, 2, 4],limit = 5) == 0\n assert candidate(nums = [1, 2, 4, 3],limit = 4) == 1\n assert candidate(nums = [5, 5, 5, 5],limit = 5) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3],limit = 6) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3],limit = 3) == 0\n assert candidate(nums = [1, 2, 1, 2],limit = 2) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],limit = 20) == 0\n assert candidate(nums = [1, 100000, 50000, 50000, 100000, 1],limit = 100000) == 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],limit = 2) == 0\n assert candidate(nums = [30000, 30000, 30000, 30000, 30000, 30000, 30000, 30000, 30000, 30000, 30000, 30000],limit = 60000) == 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],limit = 6) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],limit = 16) == 0\n assert candidate(nums = [25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000],limit = 50000) == 0\n assert candidate(nums = [100000, 1, 2, 99999, 3, 99998, 4, 99997],limit = 100000) == 3\n assert candidate(nums = [1, 100000, 1, 100000, 2, 99999, 2, 99999],limit = 100000) == 2\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1],limit = 100000) == 0\n assert candidate(nums = [1, 100000, 100000, 1],limit = 100000) == 2\n assert candidate(nums = [10000, 90000, 20000, 80000, 30000, 70000],limit = 100000) == 2\n assert candidate(nums = [25000, 25001, 25002, 24999, 25003, 24998, 25004, 24997],limit = 50000) == 3\n assert candidate(nums = [30000, 70000, 40000, 60000, 50000, 50000, 40000, 60000, 30000, 70000],limit = 100000) == 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],limit = 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],limit = 21) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 100) == 0\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1],limit = 100000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],limit = 12) == 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],limit = 10) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],limit = 10) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80],limit = 80) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 100000) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 50, 40, 30, 20, 10, 1],limit = 100) == 5\n assert candidate(nums = [1, 99999, 99999, 1, 1, 99999, 99999, 1, 1, 99999, 99999, 1],limit = 100000) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],limit = 4) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 10) == 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],limit = 30) == 0\n assert candidate(nums = [5, 3, 5, 3, 2, 8, 8, 2],limit = 10) == 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],limit = 1) == 0\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],limit = 6) == 0\n assert candidate(nums = [1, 2, 3, 3, 2, 1, 4, 4, 3, 3, 2, 2, 1, 1],limit = 5) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 2) == 0\n assert candidate(nums = [25, 75, 25, 75, 25, 75, 25, 75, 25, 75, 25, 75, 25, 75, 25, 75],limit = 100) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],limit = 100) == 0\n assert candidate(nums = [50000, 1, 50000, 1, 50000, 1, 50000, 1],limit = 100000) == 0\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],limit = 84) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],limit = 5) == 0\n assert candidate(nums = [1, 100000, 1, 100000],limit = 100000) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],limit = 15) == 0\n assert candidate(nums = [10000, 20000, 30000, 40000, 40000, 30000, 20000, 10000],limit = 50000) == 3\n assert candidate(nums = [99999, 1, 1, 99999],limit = 100000) == 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],limit = 10) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],limit = 13) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],limit = 20) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1) == 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],limit = 11) == 9\n assert candidate(nums = [90000, 10000, 80000, 20000, 70000, 30000, 60000, 40000],limit = 100000) == 3\n assert candidate(nums = [1, 5, 9, 13, 17, 21],limit = 22) == 0\n assert candidate(nums = [50000, 40000, 30000, 20000, 10000, 10000, 20000, 30000, 40000, 50000],limit = 100000) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],limit = 110) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],limit = 5) == 0\n assert candidate(nums = [1, 99999, 99998, 2, 99997, 3, 99996, 4],limit = 100000) == 3\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],limit = 12) == 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],limit = 20) == 0\n assert candidate(nums = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5],limit = 100000) == 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],limit = 10) == 0\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],limit = 50000) == 0\n assert candidate(nums = [99999, 99998, 1, 2, 3, 4, 5, 6],limit = 100000) == 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],limit = 5) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],limit = 10) == 0\n assert candidate(nums = [50, 51, 52, 49, 53, 48, 54, 47],limit = 100) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],limit = 16) == 0\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996],limit = 100000) == 3\n assert candidate(nums = [100000, 1, 2, 99998, 3, 99997, 4, 99996],limit = 100000) == 3\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],limit = 100000) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2],limit = 5) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],limit = 25) == 0\n assert candidate(nums = [10000, 90000, 10000, 90000, 10000, 90000, 10000, 90000],limit = 100000) == 0\n assert candidate(nums = [10, 20, 30, 40, 40, 30, 20, 10],limit = 50) == 3\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40],limit = 50) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],limit = 110) == 9\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],limit = 21) == 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],limit = 15) == 0\n assert candidate(nums = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],limit = 100000) == 0\n assert candidate(nums = [3, 7, 11, 11, 7, 3],limit = 14) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],limit = 15) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800],limit = 900) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],limit = 20) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],limit = 10) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,4,3]\n4", "[1,2,2,1]\n2", "[1,2,1,2]\n2"], "hints": ["Given a target sum x, each pair of nums[i] and nums[n-1-i] would either need 0, 1, or 2 modifications.", "Can you find the optimal target sum x value such that the sum of modifications is minimized?", "Create a difference array to efficiently sum all the modifications."], "metadata": {"canonical_parameter_names": ["nums", "limit"], "leetcode_dataset_entry_point": "Solution().minMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:05+00:00", "tests_total": 112, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minMoves($nums, $limit) {", "container": "Solution", "callable": "minMoves", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "limit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1675, "task_id": "minimize-deviation-in-array", "difficulty": "Hard", "problem_description": "You are given an array nums of n positive integers.\n\nYou can perform two types of operations on any element of the array any number of times:\n\n- If the element is even, divide it by 2.\n - For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].\n- If the element is odd, multiply it by 2.\n - For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].\n\nThe deviation of the array is the maximum difference between any two elements in the array.\n\nReturn the minimum deviation the array can have after performing some number of operations.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.\n\nExample 2:\n\nInput: nums = [4,1,5,20,3]\nOutput: 3\nExplanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.\n\nExample 3:\n\nInput: nums = [2,10,8]\nOutput: 3\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 5 * 10^4\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1000000000]) == 1953123\n assert candidate(nums = [3, 9, 6, 12]) == 3\n assert candidate(nums = [3, 9, 7, 3]) == 3\n assert candidate(nums = [2, 10, 8]) == 3\n assert candidate(nums = [5, 3, 11, 24, 2]) == 9\n assert candidate(nums = [1000000000, 1, 1000000000]) == 1953123\n assert candidate(nums = [1, 3, 5, 7, 9]) == 7\n assert candidate(nums = [15, 15, 15, 15]) == 0\n assert candidate(nums = [1, 2, 3, 4]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 15\n assert candidate(nums = [6, 1, 3, 4, 2, 8]) == 1\n assert candidate(nums = [8, 12, 24, 6]) == 1\n assert candidate(nums = [6, 10, 18, 24]) == 4\n assert candidate(nums = [4, 1, 5, 20, 3]) == 3\n assert candidate(nums = [7, 4, 1, 8, 12]) == 5\n assert candidate(nums = [10, 10, 10]) == 0\n assert candidate(nums = [3, 5, 6, 10, 15]) == 9\n assert candidate(nums = [10, 4, 3, 5]) == 2\n assert candidate(nums = [7, 4, 3, 7]) == 3\n assert candidate(nums = [1, 2, 9, 16]) == 7\n assert candidate(nums = [5, 17, 100, 1]) == 23\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 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]) == 29\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 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]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 275\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360, 16384, 17408, 18432, 19456, 20480]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020]) == 1717\n assert candidate(nums = [17, 23, 31, 37, 41, 43, 47, 53, 59, 61]) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 13\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 27\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555]) == 765432099\n assert candidate(nums = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000]) == 12500\n assert candidate(nums = [2, 14, 18, 26, 34, 42, 50, 58, 66, 74]) == 35\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(nums = [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]) == 135\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150]) == 105\n assert candidate(nums = [64, 32, 16, 8, 4, 2, 1, 2, 4, 8, 16, 32, 64]) == 0\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997]) == 3\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78]) == 37\n assert candidate(nums = [1, 1000000000, 2, 500000000, 3, 333333333, 4, 250000000, 5, 200000000]) == 333333331\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 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 = [1000000000, 500000000, 250000000, 125000000, 62500000]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]) == 187\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 17\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 9\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000]) == 31250\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 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]) == 69\n assert candidate(nums = [123456789, 987654321, 456789123, 321987654, 654321987, 789123456]) == 740740743\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165]) == 143\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 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]) == 51\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195]) == 169\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 13\n assert candidate(nums = [2, 6, 18, 54, 162, 486, 1458, 4374, 13122, 39366, 118098, 354294, 1062882, 3188646, 9565938]) == 4782967\n assert candidate(nums = [13579, 24681, 35791, 46813, 57915, 68137, 79159, 81379, 91591, 113791]) == 86633\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]) == 525\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383]) == 14337\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625]) == 9765615\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 17\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == 59043\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 275\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 39\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) == 71\n assert candidate(nums = [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 65\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287]) == 522241\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 21\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 999999997\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 85\n assert candidate(nums = [5, 15, 25, 35, 45, 55]) == 45\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 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]) == 37\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995]) == 4\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5]) == 1953123\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 63\n assert candidate(nums = [1024, 2048, 512, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5]) == 1953123\n assert candidate(nums = [1023, 2046, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1021\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54]) == 27\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums = [83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181]) == 84\n assert candidate(nums = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34]) == 9\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 707\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 65\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[4,1,5,20,3]", "[2,10,8]"], "hints": ["Assume you start with the minimum possible value for each number so you can only multiply a number by 2 till it reaches its maximum possible value.", "If there is a better solution than the current one, then it must have either its maximum value less than the current maximum value, or the minimum value larger than the current minimum value.", "Since that we only increase numbers (multiply them by 2), we cannot decrease the current maximum value, so we must multiply the current minimum number by 2."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumDeviation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:08+00:00", "tests_total": 105, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function minimumDeviation($nums) {", "container": "Solution", "callable": "minimumDeviation", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1678, "task_id": "goal-parser-interpretation", "difficulty": "Easy", "problem_description": "You own a Goal Parser that can interpret a string command. The command consists of an alphabet of \"G\", \"()\" and/or \"(al)\" in some order. The Goal Parser will interpret \"G\" as the string \"G\", \"()\" as the string \"o\", and \"(al)\" as the string \"al\". The interpreted strings are then concatenated in the original order.\n\nGiven the string command, return the Goal Parser's interpretation of command.\n\nExample 1:\n\nInput: command = \"G()(al)\"\nOutput: \"Goal\"\nExplanation: The Goal Parser interprets the command as follows:\nG -> G\n() -> o\n(al) -> al\nThe final concatenated result is \"Goal\".\n\nExample 2:\n\nInput: command = \"G()()()()(al)\"\nOutput: \"Gooooal\"\n\nExample 3:\n\nInput: command = \"(al)G(al)()()G\"\nOutput: \"alGalooG\"\n\nConstraints:\n\n- 1 <= command.length <= 100\n- command consists of \"G\", \"()\", and/or \"(al)\" in some order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(command = \"G()()()()(al)\") == \"Gooooal\"\n assert candidate(command = \"G\") == \"G\"\n assert candidate(command = \"()\") == \"o\"\n assert candidate(command = \"(al)G(al)()()G\") == \"alGalooG\"\n assert candidate(command = \"G()(G)()\") == \"Go(G)o\"\n assert candidate(command = \"G(al)G(al)\") == \"GalGal\"\n assert candidate(command = \"G()(al)\") == \"Goal\"\n assert candidate(command = \"()()()()\") == \"oooo\"\n assert candidate(command = \"G()G(al)G()\") == \"GoGalGo\"\n assert candidate(command = \"G(al)G(al)G(al)\") == \"GalGalGal\"\n assert candidate(command = \"(al)(al)(al)\") == \"alalal\"\n assert candidate(command = \"(al)\") == \"al\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGalGalGalGal\"\n assert candidate(command = \"G(al)()()G(al)()()G(al)()()\") == \"GalooGalooGaloo\"\n assert candidate(command = \"G(al)(al)G(al)(al)G(al)(al)\") == \"GalalGalalGalal\"\n assert candidate(command = \"()()()()G(al)G(al)G(al)G(al)\") == \"ooooGalGalGalGal\"\n assert candidate(command = \"()()()G(al)G(al)G(al)G(al)G(al)G(al)\") == \"oooGalGalGalGalGalGal\"\n assert candidate(command = \"()G(al)G()G(al)()\") == \"oGalGoGalo\"\n assert candidate(command = \"()G(al)()G(al)()G(al)()\") == \"oGaloGaloGalo\"\n assert candidate(command = \"G()G()G()G()G()G()G()G()G()G()G()G()G()G()G(al)\") == \"GoGoGoGoGoGoGoGoGoGoGoGoGoGoGal\"\n assert candidate(command = \"G(al)(al)(al)\") == \"Galalal\"\n assert candidate(command = \"()(G(al)G(al))(G(al)G(al))\") == \"o(GalGal)(GalGal)\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGalGalGal\"\n assert candidate(command = \"()G(al)G(al)G(al)G(al)G(al)G(al)\") == \"oGalGalGalGalGalGal\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGalGal\"\n assert candidate(command = \"G(al)G()G(al)G()G(al)\") == \"GalGoGalGoGal\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGalGalGalGalGalGal\"\n assert candidate(command = \"G()(al)G()(al)G()(al)\") == \"GoalGoalGoal\"\n assert candidate(command = \"(al)G(al)()G(al)()G(al)()G(al)()G(al)()\") == \"alGaloGaloGaloGaloGalo\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGalGalGal\"\n assert candidate(command = \"()G(al)G()G(al)\") == \"oGalGoGal\"\n assert candidate(command = \"(al)G(al)()()G(al)G(al)()()G(al)G(al)()()G\") == \"alGalooGalGalooGalGalooG\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGal\"\n assert candidate(command = \"G(al)(al)(al)(al)\") == \"Galalalal\"\n assert candidate(command = \"(al)G(al)(G(al)(G(al)G(al)))G(al)\") == \"alGal(Gal(GalGal))Gal\"\n assert candidate(command = \"G()()G()()G()()\") == \"GooGooGoo\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)()\") == \"GaloGaloGaloGaloGalo\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()\") == \"GaloGaloGaloGaloGaloGaloGaloGaloGaloGaloGalo\"\n assert candidate(command = \"G()G()G(al)(al)G()\") == \"GoGoGalalGo\"\n assert candidate(command = \"G(al)G(al)()()G(al)G(al)G(al)\") == \"GalGalooGalGalGal\"\n assert candidate(command = \"G()(G()(G()(G())))\") == \"Go(Go(Go(Go)))\"\n assert candidate(command = \"()G()G(al)()G(al)()G(al)\") == \"oGoGaloGaloGal\"\n assert candidate(command = \"()G()()G()()G()()G(al)G()\") == \"oGooGooGooGalGo\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)\") == \"GalGalGalGal\"\n assert candidate(command = \"G()(al)G()(al)G()(al)G()(al)\") == \"GoalGoalGoalGoal\"\n assert candidate(command = \"G()()()()(al)G(al)G(al)G(al)\") == \"GooooalGalGalGal\"\n assert candidate(command = \"G(al)G(al)()()G(al)G(al)()()\") == \"GalGalooGalGaloo\"\n assert candidate(command = \"G()(G(al))(G(al))G()(G(al))(G(al))\") == \"Go(Gal)(Gal)Go(Gal)(Gal)\"\n assert candidate(command = \"(al)(al)G(al)(al)G(al)(al)\") == \"alalGalalGalal\"\n assert candidate(command = \"G(al)(al)(al)G\") == \"GalalalG\"\n assert candidate(command = \"(al)G(al)()G(al)()G(al)()G(al)()\") == \"alGaloGaloGaloGalo\"\n assert candidate(command = \"G(al)(al)(al)G(al)(al)(al)G(al)(al)(al)G\") == \"GalalalGalalalGalalalG\"\n assert candidate(command = \"G(al)(G(al)G(al))(G(al))\") == \"Gal(GalGal)(Gal)\"\n assert candidate(command = \"G()(G(al))G()(G(al))\") == \"Go(Gal)Go(Gal)\"\n assert candidate(command = \"G()G()G()G()G()G()G()G()\") == \"GoGoGoGoGoGoGoGo\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()\") == \"GaloGaloGaloGaloGaloGalo\"\n assert candidate(command = \"()()()G(al)G(al)G(al)()()()\") == \"oooGalGalGalooo\"\n assert candidate(command = \"(al)()G(al)()G(al)G(al)\") == \"aloGaloGalGal\"\n assert candidate(command = \"(al)(al)(al)(al)G(al)G()\") == \"alalalalGalGo\"\n assert candidate(command = \"(al)(G)(al)(G)(al)(G)(al)\") == \"al(G)al(G)al(G)al\"\n assert candidate(command = \"G(al)(al)G(al)\") == \"GalalGal\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGalGal\"\n assert candidate(command = \"()G(al)G(al)G(al)G(al)G(al)\") == \"oGalGalGalGalGal\"\n assert candidate(command = \"G(al)G()(al)G()(al)G()(al)G()\") == \"GalGoalGoalGoalGo\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGalGalGalGalGal\"\n assert candidate(command = \"G()(G()(G)())\") == \"Go(Go(G)o)\"\n assert candidate(command = \"()()()()()()()()()()()()()()()()()()()()()G(al)\") == \"oooooooooooooooooooooGal\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)\") == \"GaloGaloGaloGaloGal\"\n assert candidate(command = \"(al)G(al)(al)G(al)G\") == \"alGalalGalG\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGal\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGalGalGalGal\"\n assert candidate(command = \"(al)()G(al)()G(al)()G(al)()\") == \"aloGaloGaloGalo\"\n assert candidate(command = \"G(al)(G()(G)(G)())G(al)\") == \"Gal(Go(G)(G)o)Gal\"\n assert candidate(command = \"G()G(al)G()G(al)\") == \"GoGalGoGal\"\n assert candidate(command = \"(al)(al)(al)G(al)\") == \"alalalGal\"\n assert candidate(command = \"G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"GalGalGalGalGalGalGalGalGalGalGalGal\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGal\"\n assert candidate(command = \"(al)(G(al))(G(al))(G(al))(G(al))(G(al))\") == \"al(Gal)(Gal)(Gal)(Gal)(Gal)\"\n assert candidate(command = \"()()()()()G(al)()()\") == \"oooooGaloo\"\n assert candidate(command = \"()G(al)()G(al)()\") == \"oGaloGalo\"\n assert candidate(command = \"(al)(al)(al)(al)(al)(al)(al)(al)\") == \"alalalalalalalal\"\n assert candidate(command = \"()()()()(al)()()()(al)()()()\") == \"ooooaloooalooo\"\n assert candidate(command = \"G(al)G()G(al)G()G(al)G()\") == \"GalGoGalGoGalGo\"\n assert candidate(command = \"G()(G()(G()(G)())())\") == \"Go(Go(Go(G)o)o)\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()G(al)()\") == \"GaloGaloGaloGaloGaloGaloGaloGalo\"\n assert candidate(command = \"G(al)(al)G(al)G(al)\") == \"GalalGalGal\"\n assert candidate(command = \"G(al)(G(al))(G(al))(G(al))G(al)\") == \"Gal(Gal)(Gal)(Gal)Gal\"\n assert candidate(command = \"G()()()()(al)G(al)G(al)G(al)G(al)\") == \"GooooalGalGalGalGal\"\n assert candidate(command = \"G()(G()(G()(G()())))\") == \"Go(Go(Go(Goo)))\"\n assert candidate(command = \"G(al)()G(al)()G(al)()G(al)()G(al)G(al)\") == \"GaloGaloGaloGaloGalGal\"\n assert candidate(command = \"(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)G(al)\") == \"alGalGalGalGalGalGalGalGalGalGalGal\"\n assert candidate(command = \"G()G()G()G()G()G()G()G()G()G()G()G()G()G()G()G()\") == \"GoGoGoGoGoGoGoGoGoGoGoGoGoGoGoGo\"\n assert candidate(command = \"(al)()()()()()()()()()()()()()()()()()()()()()()()()()()()()\") == \"aloooooooooooooooooooooooooooo\"\n assert candidate(command = \"G()G()G()G()G(al)G(al)G(al)\") == \"GoGoGoGoGalGalGal\"\n assert candidate(command = \"()()()()()()()()()()G(al)G(al)G(al)G(al)G(al)\") == \"ooooooooooGalGalGalGalGal\"\n", "comparison": "exact"}, "public_tests": ["\"G()(al)\"", "\"G()()()()(al)\"", "\"(al)G(al)()()G\""], "hints": ["You need to check at most 2 characters to determine which character comes next."], "metadata": {"canonical_parameter_names": ["command"], "leetcode_dataset_entry_point": "Solution().interpret", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:10+00:00", "tests_total": 95, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function interpret($command) {", "container": "Solution", "callable": "interpret", "parameters": [{"name": "command", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1679, "task_id": "max-number-of-k-sum-pairs", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer k.\n\nIn one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.\n\nReturn the maximum number of operations you can perform on the array.\n\nExample 1:\n\nInput: nums = [1,2,3,4], k = 5\nOutput: 2\nExplanation: Starting with nums = [1,2,3,4]:\n- Remove numbers 1 and 4, then nums = [2,3]\n- Remove numbers 2 and 3, then nums = []\nThere are no more pairs that sum up to 5, hence a total of 2 operations.\n\nExample 2:\n\nInput: nums = [3,1,3,4,3], k = 6\nOutput: 1\nExplanation: Starting with nums = [3,1,3,4,3]:\n- Remove the first two 3's, then nums = [1,4,3]\nThere are no more pairs that sum up to 6, hence a total of 1 operation.\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 = [3, 1, 3, 4, 3],k = 6) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 5\n assert candidate(nums = [1000000000],k = 1000000000) == 0\n assert candidate(nums = [1, 5, 4, 2, 9, 6, 5, 3, 4, 7, 8, 10],k = 11) == 5\n assert candidate(nums = [1, 3, 5, 7, 9],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 10) == 3\n assert candidate(nums = [1, 5, 7, 8, 2, 6, 3, 4],k = 9) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 11) == 5\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 2\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 4) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 3) == 3\n assert candidate(nums = [1, 2, 3, 4],k = 5) == 2\n assert candidate(nums = [1, 3, 2, 2, 2, 3, 1],k = 4) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 10) == 4\n assert candidate(nums = [1, 3, 2, 2, 2, 3, 1],k = 4) == 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],k = 26) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 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],k = 42) == 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],k = 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 21) == 20\n assert candidate(nums = [1, 3, 3, 5, 7, 7, 5, 9, 9, 11, 11, 13],k = 12) == 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 = 21) == 10\n assert candidate(nums = [1, 5, 7, 3, 5, 7, 9, 11, 13, 15],k = 12) == 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 = 15) == 7\n assert candidate(nums = [1, 3, 2, 2, 2, 2, 2, 3, 1, 3, 3, 2, 2, 2, 3, 2, 2, 1, 3, 2],k = 4) == 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 = 11) == 10\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],k = 100) == 5\n assert candidate(nums = [1, 5, 7, 1, 5, 7, 1, 5, 7, 1, 5, 7, 1, 5, 7, 1, 5, 7, 1, 5, 7],k = 6) == 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 = 300) == 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, 15, 15],k = 16) == 15\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 25\n assert candidate(nums = [999999999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 1000000000) == 1\n assert candidate(nums = [1, 5, 7, 1, 5, 9, 5, 5, 5, 5],k = 10) == 4\n assert candidate(nums = [5, 1, 4, 8, 6, 9, 7, 2, 3, 10],k = 15) == 3\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 = 200) == 10\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8],k = 6) == 6\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 20) == 7\n assert candidate(nums = [1, 5, 4, 2, 8, 6, 7, 3, 9],k = 10) == 4\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, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 300) == 11\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, 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 = 400) == 21\n assert candidate(nums = [2, 5, 4, 4, 1, 3, 4, 4, 1, 4, 4, 1, 2, 1, 2, 2, 3, 2, 4, 2],k = 6) == 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 = 21) == 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, 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 = 21) == 30\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, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 300) == 11\n assert candidate(nums = [2, 4, 3, 5, 7, 8, 1, 9, 10, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 31) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 32) == 8\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 27) == 7\n assert candidate(nums = [3, 6, 3, 3, 6, 6, 3, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6],k = 9) == 15\n assert candidate(nums = [1, 5, 7, 1, 5, 9, 7, 5, 11, 1],k = 10) == 2\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 12) == 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, 1, 1, 1, 1, 1, 1, 1],k = 2) == 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 = 11) == 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],k = 41) == 20\n assert candidate(nums = [3, 1, 3, 4, 3, 5, 6, 2, 3, 1],k = 6) == 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, 41, 43, 45, 47, 49],k = 50) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 16) == 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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 18) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 5\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n5", "[3,1,3,4,3]\n6"], "hints": ["The abstract problem asks to count the number of disjoint pairs with a given sum k.", "For each possible value x, it can be paired up with k - x.", "The number of such pairs equals to min(count(x), count(k-x)), unless that x = k / 2, where the number of such pairs will be floor(count(x) / 2)."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:13+00:00", "tests_total": 68, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxOperations($nums, $k) {", "container": "Solution", "callable": "maxOperations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1680, "task_id": "concatenation-of-consecutive-binary-numbers", "difficulty": "Medium", "problem_description": "Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9+ 7.\n\nExample 1:\n\nInput: n = 1\nOutput: 1\nExplanation: \"1\" in binary corresponds to the decimal value 1.\n\nExample 2:\n\nInput: n = 3\nOutput: 27\nExplanation: In binary, 1, 2, and 3 corresponds to \"1\", \"10\", and \"11\".\nAfter concatenating them, we have \"11011\", which corresponds to the decimal value 27.\n\nExample 3:\n\nInput: n = 12\nOutput: 505379714\nExplanation: The concatenation results in \"1101110010111011110001001101010111100\".\nThe decimal value of that is 118505380540.\nAfter modulo 10^9 + 7, the result is 505379714.\n\nConstraints:\n\n- 1 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 27\n assert candidate(n = 100000) == 757631812\n assert candidate(n = 100) == 310828084\n assert candidate(n = 12) == 505379714\n assert candidate(n = 10000) == 356435599\n assert candidate(n = 20) == 632668867\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == 499361981\n assert candidate(n = 10) == 462911642\n assert candidate(n = 5) == 1765\n assert candidate(n = 15000) == 760107204\n assert candidate(n = 99999) == 880407397\n assert candidate(n = 12345) == 836722104\n assert candidate(n = 67890) == 121883656\n assert candidate(n = 32767) == 351669993\n assert candidate(n = 90000) == 333354001\n assert candidate(n = 50000) == 305317209\n assert candidate(n = 60000) == 841047212\n assert candidate(n = 30000) == 789968936\n assert candidate(n = 80000) == 801174769\n assert candidate(n = 8192) == 853721666\n assert candidate(n = 65536) == 273282097\n assert candidate(n = 5000) == 754628255\n assert candidate(n = 75000) == 363627085\n assert candidate(n = 40000) == 162370743\n assert candidate(n = 65535) == 183542430\n assert candidate(n = 500) == 715412131\n assert candidate(n = 25000) == 110872861\n", "comparison": "exact"}, "public_tests": ["1", "3", "12"], "hints": ["Express the nth number value in a recursion formula and think about how we can do a fast evaluation."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().concatenatedBinary", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:15+00:00", "tests_total": 28, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "bit-manipulation", "simulation"]}, "language": "php", "interface": {"raw_signature": "function concatenatedBinary($n) {", "container": "Solution", "callable": "concatenatedBinary", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1681, "task_id": "minimum-incompatibility", "difficulty": "Hard", "problem_description": "You are given an integer array nums and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.\n\nA subset's incompatibility is the difference between the maximum and minimum elements in that array.\n\nReturn the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.\n\nA subset is a group integers that appear in the array with no particular order.\n\nExample 1:\n\nInput: nums = [1,2,1,4], k = 2\nOutput: 4\nExplanation: The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.\n\nExample 2:\n\nInput: nums = [6,3,8,1,3,1,2,2], k = 4\nOutput: 6\nExplanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n\nExample 3:\n\nInput: nums = [5,3,3,6,3,3], k = 3\nOutput: -1\nExplanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n\nConstraints:\n\n- 1 <= k <= nums.length <= 16\n- nums.length is divisible by k\n- 1 <= nums[i] <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 1) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 8) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == 4\n assert candidate(nums = [6, 3, 8, 1, 3, 1, 2, 2],k = 4) == 6\n assert candidate(nums = [1, 2, 1, 4],k = 2) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 4) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 16) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4],k = 4) == 4\n assert candidate(nums = [5, 3, 3, 6, 3, 3],k = 3) == -1\n assert candidate(nums = [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, 11, 12, 13, 14, 15, 16],k = 2) == 14\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4],k = 8) == 0\n assert candidate(nums = [1, 2, 3, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14],k = 2) == 18\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 12\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7],k = 4) == 14\n assert candidate(nums = [1, 2, 3, 3, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10],k = 2) == -1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6],k = 4) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 1],k = 2) == 14\n assert candidate(nums = [3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6],k = 4) == 12\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11],k = 4) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 2) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7],k = 2) == -1\n assert candidate(nums = [1, 3, 2, 6, 4, 5, 7, 8, 10, 9, 12, 11, 14, 13, 16, 15],k = 4) == 12\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9],k = 4) == 13\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14],k = 4) == 15\n assert candidate(nums = [1, 3, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10, 11, 12],k = 4) == 15\n assert candidate(nums = [1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 12],k = 8) == 11\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6],k = 4) == -1\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13],k = 4) == 17\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8],k = 4) == 13\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 4) == 13\n assert candidate(nums = [1, 1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 11, 11],k = 4) == 22\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],k = 4) == 13\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 4) == 12\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9],k = 8) == 8\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16],k = 4) == 16\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7],k = 8) == 8\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6],k = 4) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 8) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 9, 10, 11, 12, 13, 13],k = 4) == 16\n assert candidate(nums = [3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13],k = 4) == 15\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 8) == 9\n assert candidate(nums = [6, 3, 8, 1, 3, 1, 2, 2, 4, 5, 7, 9, 10, 11, 12, 13],k = 4) == 13\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9],k = 2) == 14\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],k = 4) == 12\n assert candidate(nums = [1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 13],k = 4) == 16\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15],k = 8) == 9\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11],k = 4) == 14\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 4) == 16\n assert candidate(nums = [2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 12],k = 8) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7],k = 4) == 12\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],k = 4) == 12\n assert candidate(nums = [1, 3, 3, 3, 3, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9],k = 2) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 14, 15, 16],k = 8) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 1) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8],k = 4) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10, 10, 11, 12, 13],k = 4) == 13\n", "comparison": "exact"}, "public_tests": ["[1,2,1,4]\n2", "[6,3,8,1,3,1,2,2]\n4", "[5,3,3,6,3,3]\n3"], "hints": ["The constraints are small enough for a backtrack solution but not any backtrack solution", "If we use a naive n^k don't you think it can be optimized"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minimumIncompatibility", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:17+00:00", "tests_total": 91, "tests_dropped": 28, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function minimumIncompatibility($nums, $k) {", "container": "Solution", "callable": "minimumIncompatibility", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1684, "task_id": "count-the-number-of-consistent-strings", "difficulty": "Easy", "problem_description": "You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.\n\nReturn the number of consistent strings in the array words.\n\nExample 1:\n\nInput: allowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]\nOutput: 2\nExplanation: Strings \"aaab\" and \"baa\" are consistent since they only contain characters 'a' and 'b'.\n\nExample 2:\n\nInput: allowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]\nOutput: 7\nExplanation: All strings are consistent.\n\nExample 3:\n\nInput: allowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]\nOutput: 4\nExplanation: Strings \"cc\", \"acd\", \"ac\", and \"d\" are consistent.\n\nConstraints:\n\n- 1 <= words.length <= 10^4\n- 1 <= allowed.length <=26\n- 1 <= words[i].length <= 10\n- The characters in allowed are distinct.\n- words[i] and allowed contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(allowed = \"ijkl\",words = ['i', 'j', 'k', 'l', 'ij', 'ik', 'il', 'jk', 'jl', 'kl', 'ijkl']) == 11\n assert candidate(allowed = \"abcdef\",words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef']) == 6\n assert candidate(allowed = \"cad\",words = ['cc', 'acd', 'b', 'ba', 'bac', 'bad', 'ac', 'd']) == 4\n assert candidate(allowed = \"gh\",words = ['g', 'h', 'gh']) == 3\n assert candidate(allowed = \"xyz\",words = ['xy', 'yz', 'xzy', 'zxy', 'zyx', 'xyz']) == 6\n assert candidate(allowed = \"xyz\",words = ['x', 'y', 'z', 'xy', 'xz', 'yz', 'xyz']) == 7\n assert candidate(allowed = \"uvw\",words = ['u', 'v', 'w', 'uv', 'uw', 'vw', 'uvw']) == 7\n assert candidate(allowed = \"mnop\",words = ['m', 'n', 'o', 'p', 'mn', 'mo', 'mp', 'no', 'np', 'op', 'mno', 'mnp', 'mop', 'nop', 'mnop']) == 15\n assert candidate(allowed = \"mnop\",words = ['m', 'n', 'o', 'p', 'mn', 'mo', 'mp', 'no', 'np', 'op', 'mno', 'mnp', 'mop', 'nop', 'mnop']) == 15\n assert candidate(allowed = \"ab\",words = ['ad', 'bd', 'aaab', 'baa', 'badab']) == 2\n assert candidate(allowed = \"abc\",words = ['a', 'b', 'c', 'ab', 'ac', 'bc', 'abc']) == 7\n assert candidate(allowed = \"qrst\",words = ['qr', 'qs', 'qt', 'rs', 'rt', 'st', 'qrs', 'qrt', 'qst', 'rst', 'qrst']) == 11\n assert candidate(allowed = \"qwerty\",words = ['q', 'w', 'e', 'r', 't', 'y', 'qw', 'we', 'er', 'rt', 'ty', 'yq', 'qr', 're', 'et', 'ty', 'yr', 're', 'et', 'ty', 'qwer', 'wert', 'erty', 'rtye', 'tyer', 'yert', 'erty', 'rtye', 'tyer', 'yert']) == 30\n assert candidate(allowed = \"xyz\",words = ['xzy', 'zyx', 'xyzz', 'zyzzx', 'xzyzyx', 'zyzxzy', 'xyzxyz', 'zyxzyxzyx']) == 8\n assert candidate(allowed = \"abcdef\",words = ['abc', 'bcd', 'cde', 'def', 'abcf', 'bcde', 'cdef', 'abcdef', 'af', 'bf', 'cf', 'df', 'ef', 'f', 'a', 'b', 'c', 'd', 'e']) == 19\n assert candidate(allowed = \"abcdefg\",words = ['abc', 'def', 'ghi', 'abcd', 'efg', 'abdefg', 'abcdef', 'abcdefg', 'xyz']) == 7\n assert candidate(allowed = \"mnopqr\",words = ['mnop', 'opqr', 'mnqr', 'mpqr', 'mnoq', 'mnpq', 'mnopq', 'mnopqr', 'mnoqr', 'mnopqr', 'qrmpno', 'rpmnqo', 'qrmp', 'mnpqr', 'pqmno']) == 15\n assert candidate(allowed = \"xyz\",words = ['x', 'y', 'z', 'xy', 'xz', 'yz', 'xyz', 'xyzz', 'zxy', 'yxz', 'zyx', 'zzz']) == 12\n assert candidate(allowed = \"abcdef\",words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'fedcba', 'defabc', 'cbadef', 'abcdefg', 'abcdefh', 'abcdefi', 'abcdefj', 'abcdefk', 'abcdefl', 'abcdefm', 'abef', 'acd', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', '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', 'abab', 'acac', 'adad', 'aeae', 'afaf', 'agag', 'ahah', 'aiai', 'ajaj', 'akak', 'alal', 'amam', 'anan', 'aoao', 'apap', 'aqaq', 'arar', 'asas', 'atat', 'auau', 'avav', 'awaw', 'axax', 'ayay', 'azaz']) == 24\n assert candidate(allowed = \"tuvwxy\",words = ['tuv', 'uvw', 'vwx', 'wxy', 'tuvw', 'uvwx', 'vwx', 'wxy', 'tuvwx', 'uvwxy', 'tuvwxy', 'tuvwxyu', 'tuvwxyv', 'tuvwxyw', 'tuvwxyx', 'tuvwxyy']) == 16\n assert candidate(allowed = \"qrstuv\",words = ['qrst', 'uv', 'qrs', 'tu', 'rqs', 'vut', 'qrtuv', 'tuvqr', 'usvrtq', 'rqstuv', 'uvtqrs', 'qrsutv', 'rqvstu']) == 13\n assert candidate(allowed = \"pqrs\",words = ['pq', 'qr', 'rs', 'sp', 'pqrs', 'prqs', 'psrq', 'sqrp', 'rqps', 'rspq', 'pqs', 'qsr', 'rsq', 'spq', 'qrp', 'rps', 'sqr', 'prq', 'qsp', 'rqs', 'spr', 'psr', 'qrs', 'rsq', 'spq', 'pqr', 'qrs', 'rsp', 'spr', 'psr', 'srp', 'rps', 'qsp', 'psq']) == 34\n assert candidate(allowed = \"mnopqr\",words = ['mno', 'mnp', 'mqr', 'npr', 'opq', 'orq', 'pqr', 'mnop', 'mnoq', 'mnopqr', 'pqor', 'nopr', 'mnopq', 'nopqr', 'mnopqrs', 'mnoprq', 'mnopqrr', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs', 'mnopqrs']) == 16\n assert candidate(allowed = \"jklm\",words = ['jj', 'kk', 'll', 'mm', 'jk', 'jl', 'jm', 'kl', 'km', 'lm', 'jkl', 'jkm', 'jlm', 'klm', 'jklm', 'jkll', 'jjkkllmm', 'klmklm', 'jkljkl', 'mnop', 'qrst', 'uvwxy', 'z']) == 19\n assert candidate(allowed = \"mno\",words = ['m', 'n', 'o', 'mn', 'no', 'om', 'mno', 'mon', 'nom', 'omn', 'nmo', 'nom', 'omn', 'mon', 'mno', 'mno', 'nom', 'omn', 'mon', 'mno', 'nom', 'omn', 'mon', 'mno', 'nom', 'omn', 'mon', 'mno', 'nom', 'omn', 'mon', 'mno']) == 32\n assert candidate(allowed = \"ijkl\",words = ['ij', 'kl', 'ik', 'jl', 'ikl', 'jkl', 'ijk', 'ijkl', 'ijl', 'ikjl', 'likj', 'ljk', 'lkij', 'lijk', 'ilkj', 'lkji']) == 16\n assert candidate(allowed = \"xyz\",words = ['xy', 'yz', 'xz', 'xyz', 'zyx', 'yxz', 'xzy', 'zy', 'yx', 'zx']) == 10\n assert candidate(allowed = \"xyz\",words = ['x', 'y', 'z', 'xy', 'xz', 'yz', 'xyz', 'xzy', 'yzx', 'zyx', 'zyz', 'zxz', 'yzy', 'xyx', 'xxy', 'xxz', 'xyy', 'xzz', 'yyy', 'yzz', 'zzz']) == 21\n assert candidate(allowed = \"xyz\",words = ['xyzzy', 'zyx', 'zxyx', 'zzyzxzy', 'xyzabc', 'xzyz']) == 5\n assert candidate(allowed = \"fv\",words = ['f', 'v', 'fv', 'vf', 'ff', 'vv', 'ffff', 'vvvv', 'fvfv', 'vfvf', 'fvvf', 'vvff', 'fvff', 'vvvf', 'fvvv', 'ffvv', 'f', 'v', 'fv', 'vf', 'ff', 'vv', 'ffff', 'vvvv', 'fvfv', 'vfvf', 'fvvf', 'vvff', 'fvff', 'vvvf', 'fvvv', 'ffvv', 'f', 'v', 'fv', 'vf', 'ff', 'vv', 'ffff', 'vvvv']) == 40\n assert candidate(allowed = \"qrst\",words = ['qqqq', 'rrrr', 'ssss', 'tttt', 'qqrr', 'qqss', 'qqtt', 'rrss', 'rrtt', 'sstt', 'qqrrss', 'qqrrtt', 'qqsstt', 'rrsstt', 'qqrrsstt', 'qqrrssttt']) == 16\n assert candidate(allowed = \"xyz\",words = ['xy', 'xz', 'yz', 'xyz', 'xx', 'yy', 'zz', 'xyx', 'yzy', 'zxz', 'xyxy', 'xzyz', 'yzxy', 'xyzx', 'xzyzx', 'yzxyz', 'xyzyx', 'zxyxz', 'yxzyz', 'zyxzy']) == 20\n assert candidate(allowed = \"abcdef\",words = ['a', 'b', 'c', 'd', 'e', 'f', 'ab', 'cd', 'ef', 'abc', 'def', 'abcdef', 'abcdefg', 'abcdefabc']) == 13\n assert candidate(allowed = \"qrstuv\",words = ['qrst', 'qrsu', 'rstuv', 'qrstu', 'quv', 'qrs', 'qrtuv', 'qru', 'quvtsr', 'quvz']) == 9\n assert candidate(allowed = \"abcdef\",words = ['abc', 'def', 'abcdef', 'aabbcc', 'ddeeff', 'abcdeff', 'abcdefg']) == 6\n assert candidate(allowed = \"ijklmnop\",words = ['ijkl', 'mnop', 'ijkm', 'klnm', 'ijlmo', 'ijkmnop', 'ijklmnopq', 'ijklmno', 'ijklnop']) == 8\n assert candidate(allowed = \"jklmno\",words = ['jk', 'kl', 'lm', 'mn', 'no', 'jkl', 'klm', 'lmn', 'mno', 'jklm', 'klmn', 'lmno', 'jklmo', 'klmno', 'jklmno', 'jklmnou', 'klmnop', 'jklmnop']) == 15\n assert candidate(allowed = \"abcdef\",words = ['abc', 'def', 'abcd', 'abef', 'acdf', 'bcde', 'acde', 'bcdf', 'abcf', 'abcdef', 'afecbd', 'fedcba']) == 12\n assert candidate(allowed = \"qrst\",words = ['q', 'r', 's', 't', 'qr', 'qs', 'qt', 'rs', 'rt', 'st', 'qrs', 'qrt', 'qst', 'rst', 'qrst']) == 15\n assert candidate(allowed = \"wxyz\",words = ['w', 'x', 'y', 'z', 'wx', 'wxyz', 'xy', 'yz', 'wxy', 'wxyz', 'wxzy', 'xywz', 'yzwx', 'zxyw']) == 14\n assert candidate(allowed = \"abcd\",words = ['a', 'b', 'c', 'd', 'ab', 'bc', 'cd', 'da', 'abc', 'bcd', 'cda', 'dab', 'abcd', 'bcda', 'cdab', 'dabc', 'abdc', 'bacd', 'cabd', 'dabc', 'acbd', 'badc', 'cabd', 'dacb', 'acdb', 'bdac', 'cadb', 'dbac', 'dcab', 'dcba']) == 30\n assert candidate(allowed = \"xyz\",words = ['xyzz', 'zyx', 'zxy', 'xxxyyyzzz', 'zzzz', 'yyyxxx', 'abc', 'xyzzyx', 'zzzxxx', 'xyxyxy']) == 9\n assert candidate(allowed = \"abcdef\",words = ['abc', 'def', 'abcdef', 'abcd', 'abcf', 'defa', 'bcde', 'fabc', 'aabbccdd', 'fedcba']) == 10\n assert candidate(allowed = \"qz\",words = ['qqqz', 'zqq', 'q', 'z', 'zzzz', 'qqqq', 'qzqz', 'zqzq', 'zzzq', 'zqqz']) == 10\n assert candidate(allowed = \"xyz\",words = ['xy', 'yz', 'xz', 'xyz', 'xzy', 'yxz', 'zxy', 'zyx', 'yzz', 'zzz']) == 10\n assert candidate(allowed = \"jkl\",words = ['j', 'k', 'l', 'jk', 'kl', 'lj', 'jkl', 'klj', 'lkj', 'kjl', 'jlk', 'lk', 'kj', 'jl', 'kl', 'jk', 'lj', 'kl', 'jl', 'kj', 'jl', 'kj', 'lk', 'jk', 'kl', 'jl', 'kj', 'lk', 'jk', 'kl', 'jl', 'kj']) == 32\n assert candidate(allowed = \"uvw\",words = ['uvw', 'uv', 'uw', 'vw', 'u', 'v', 'w', 'uvvw', 'uwwv', 'vwwu', 'vvvuuuwww', 'wuvuvuvuv']) == 12\n assert candidate(allowed = \"pqrstuvw\",words = ['pqrs', 'qrst', 'rstu', 'stuv', 'tuvw', 'pqrsrstuvw', 'uvws', 'uvwpqr', 'rstuvwq', 'pqrstuvwz', 'uvwstu', 'qrpstu', 'vwstupqr']) == 12\n assert candidate(allowed = \"pqrst\",words = ['p', 'q', 'r', 's', 't', 'pq', 'qr', 'rs', 'st', 'pqrs', 'qrst', 'pqrst', 'pqrs', 'pqst', 'prst', 'qrstu', 'pqrstv']) == 15\n assert candidate(allowed = \"lmnopq\",words = ['lmn', 'opq', 'lmnop', 'lmnopq', 'pqonm', 'qlmnp', 'pqlno', 'opqmn', 'nopql', 'mnopq', 'lmnopqrr', 'plmqon', 'opqlnm', 'qponml', 'mnopql']) == 14\n assert candidate(allowed = \"xyz\",words = ['xx', 'yy', 'zz', 'xy', 'yz', 'zx', 'xyz', 'zxy', 'yxz']) == 9\n assert candidate(allowed = \"xyz\",words = ['xzy', 'zyx', 'zyzx', 'xxxyyyzzz', 'xzyxzyxzy']) == 5\n", "comparison": "exact"}, "public_tests": ["\"ab\"\n[\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]", "\"abc\"\n[\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]", "\"cad\"\n[\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]"], "hints": ["A string is incorrect if it contains a character that is not allowed", "Constraints are small enough for brute force"], "metadata": {"canonical_parameter_names": ["allowed", "words"], "leetcode_dataset_entry_point": "Solution().countConsistentStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:22+00:00", "tests_total": 66, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "hash-table", "string", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function countConsistentStrings($allowed, $words) {", "container": "Solution", "callable": "countConsistentStrings", "parameters": [{"name": "allowed", "type": "String"}, {"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1685, "task_id": "sum-of-absolute-differences-in-a-sorted-array", "difficulty": "Medium", "problem_description": "You are given an integer array nums sorted in non-decreasing order.\n\nBuild and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.\n\nIn other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).\n\nExample 1:\n\nInput: nums = [2,3,5]\nOutput: [4,3,5]\nExplanation: Assuming the arrays are 0-indexed, then\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.\n\nExample 2:\n\nInput: nums = [1,4,6,8,10]\nOutput: [24,15,13,15,21]\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= nums[i + 1] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [100, 200, 300, 400, 500]) == [1000, 700, 600, 700, 1000]\n assert candidate(nums = [1, 1, 1, 1]) == [0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 4, 6, 8, 10]) == [24, 15, 13, 15, 21]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(nums = [2, 3, 5]) == [4, 3, 5]\n assert candidate(nums = [1, 2, 3, 100, 101, 102, 103, 104, 105, 106]) == [717, 709, 703, 315, 313, 313, 315, 319, 325, 333]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 10, 10, 15, 15, 15, 20, 20, 20, 20]) == [100, 100, 100, 70, 70, 60, 60, 60, 80, 80, 80, 80]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == [19000, 17200, 15600, 14200, 13000, 12000, 11200, 10600, 10200, 10000, 10000, 10200, 10600, 11200, 12000, 13000, 14200, 15600, 17200, 19000]\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == [441, 369, 309, 269, 249, 249, 269, 309, 369, 449]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == [45000, 37000, 31000, 27000, 25000, 25000, 27000, 31000, 37000, 45000]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [950, 860, 780, 710, 650, 600, 560, 530, 510, 500, 500, 510, 530, 560, 600, 650, 710, 780, 860, 950]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == [570, 516, 468, 426, 390, 360, 336, 318, 306, 300, 300, 306, 318, 336, 360, 390, 426, 468, 516, 570]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [135, 117, 101, 87, 75, 65, 57, 51, 47, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == [137, 137, 137, 123, 123, 113, 105, 99, 95, 93, 93, 95, 99, 105, 113, 123, 135, 149, 165, 183]\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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]) == [380, 344, 312, 284, 260, 240, 224, 212, 204, 200, 200, 204, 212, 224, 240, 260, 284, 312, 344, 380]\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101]) == [816, 726, 648, 582, 528, 486, 456, 438, 432, 438, 456, 486, 528, 582, 648, 726, 816]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == [1900, 1720, 1560, 1420, 1300, 1200, 1120, 1060, 1020, 1000, 1000, 1020, 1060, 1120, 1200, 1300, 1420, 1560, 1720, 1900]\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [210, 194, 176, 160, 150, 150, 164, 196, 250, 330]\n assert candidate(nums = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [5490, 4599, 3899, 3399, 3099, 2999, 3099, 3399, 3899, 4599, 5499]\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [210, 194, 176, 160, 150, 150, 164, 196, 250, 330]\n assert candidate(nums = [3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9, 11, 11, 11, 11]) == [80, 80, 80, 80, 56, 56, 56, 56, 48, 48, 48, 48, 56, 56, 56, 56, 80, 80, 80, 80]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [20, 20, 14, 14, 12, 12, 14, 14, 20, 20]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [210, 184, 162, 144, 130, 120, 114, 112, 114, 120, 130, 144, 162, 184, 210]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == [210, 184, 162, 144, 130, 120, 114, 112, 114, 120, 130, 144, 162, 184, 210]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]) == [2567, 2554, 2543, 2525, 2504, 2479, 2455, 2442, 2463, 2565, 2840, 3463, 4759, 7322, 12223]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [450, 370, 310, 270, 250, 250, 270, 310, 370, 450]\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == [2850, 2796, 2716, 2618, 2510, 2400, 2296, 2206, 2138, 2100, 2100, 2146, 2246, 2408, 2640, 2950, 3346, 3836, 4428, 5130]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7]) == [15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 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, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8]) == [130, 102, 102, 78, 78, 78, 60, 60, 60, 60, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 80, 80, 80, 80, 80]\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7]) == [12, 12, 12, 12, 8, 8, 8, 8, 12, 12, 12, 12]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [90, 74, 62, 54, 50, 50, 54, 62, 74, 90]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5]) == [24, 15, 15, 10, 10, 10, 11, 11, 11, 11, 20]\n assert candidate(nums = [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, 1, 1, 1, 1, 1, 1, 1, 1]) == [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]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [2026, 2010, 1986, 1954, 1922, 1922, 2050, 2562, 4098, 8194]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == [1900, 1720, 1560, 1420, 1300, 1200, 1120, 1060, 1020, 1000, 1000, 1020, 1060, 1120, 1200, 1300, 1420, 1560, 1720, 1900]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [380, 344, 312, 284, 260, 240, 224, 212, 204, 200, 200, 204, 212, 224, 240, 260, 284, 312, 344, 380]\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]) == [300, 277, 256, 237, 220, 205, 192, 181, 172, 165, 160, 157, 156, 157, 160, 165, 172, 181, 192, 205, 220, 237, 256, 277, 300]\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 5, 6]) == [24, 17, 17, 14, 13, 14, 14, 14, 21]\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [540, 459, 389, 339, 309, 299, 309, 339, 389, 459, 549]\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]) == [2175, 2035, 1905, 1785, 1675, 1575, 1485, 1405, 1335, 1275, 1225, 1185, 1155, 1135, 1125, 1125, 1135, 1155, 1185, 1225, 1275, 1335, 1405, 1485, 1575, 1675, 1785, 1905, 2035, 2175]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == [15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [20, 12, 12, 8, 8, 8, 10, 10, 10, 10]\n assert candidate(nums = [5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010, 5011, 5012, 5013, 5014, 5015, 5016, 5017, 5018, 5019]) == [190, 172, 156, 142, 130, 120, 112, 106, 102, 100, 100, 102, 106, 112, 120, 130, 142, 156, 172, 190]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [275, 230, 195, 170, 155, 150, 155, 170, 195, 230, 275]\n assert candidate(nums = [1, 2, 5, 7, 9, 11, 13, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49]) == [437, 419, 371, 343, 319, 299, 283, 265, 257, 253, 253, 259, 271, 289, 313, 343, 379, 421, 469, 523]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [1050, 920, 810, 720, 650, 600, 570, 560, 570, 600, 650, 720, 810, 920, 1050]\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [540, 459, 389, 339, 309, 299, 309, 339, 389, 459, 549]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == [45000, 37000, 31000, 27000, 25000, 25000, 27000, 31000, 37000, 45000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [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, 4, 8, 16, 32, 64, 128, 256, 512]) == [1013, 1005, 993, 977, 961, 961, 1025, 1281, 2049, 4097]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [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]) == [105, 92, 81, 72, 65, 60, 57, 56, 57, 60, 65, 72, 81, 92, 105]\n", "comparison": "exact"}, "public_tests": ["[2,3,5]", "[1,4,6,8,10]"], "hints": ["Absolute difference is the same as max(a, b) - min(a, b). How can you use this fact with the fact that the array is sorted?", "For nums[i], the answer is (nums[i] - nums[0]) + (nums[i] - nums[1]) + ... + (nums[i] - nums[i-1]) + (nums[i+1] - nums[i]) + (nums[i+2] - nums[i]) + ... + (nums[n-1] - nums[i]).", "It can be simplified to (nums[i] * i - (nums[0] + nums[1] + ... + nums[i-1])) + ((nums[i+1] + nums[i+2] + ... + nums[n-1]) - nums[i] * (n-i-1)). One can build prefix and suffix sums to compute this quickly."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().getSumAbsoluteDifferences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:24+00:00", "tests_total": 69, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "math", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function getSumAbsoluteDifferences($nums) {", "container": "Solution", "callable": "getSumAbsoluteDifferences", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1686, "task_id": "stone-game-vi", "difficulty": "Medium", "problem_description": "Alice and Bob take turns playing a game, with Alice starting first.\n\nThere are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.\n\nYou are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the i^th stone.\n\nThe winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally. Both players know the other's values.\n\nDetermine the result of the game, and:\n\n- If Alice wins, return 1.\n- If Bob wins, return -1.\n- If the game results in a draw, return 0.\n\nExample 1:\n\nInput: aliceValues = [1,3], bobValues = [2,1]\nOutput: 1\nExplanation:\nIf Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.\nBob can only choose stone 0, and will only receive 2 points.\nAlice wins.\n\nExample 2:\n\nInput: aliceValues = [1,2], bobValues = [3,1]\nOutput: 0\nExplanation:\nIf Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.\nDraw.\n\nExample 3:\n\nInput: aliceValues = [2,4,3], bobValues = [1,6,7]\nOutput: -1\nExplanation:\nRegardless of how Alice plays, Bob will be able to have more points than Alice.\nFor example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.\nBob wins.\n\nConstraints:\n\n- n == aliceValues.length == bobValues.length\n- 1 <= n <= 10^5\n- 1 <= aliceValues[i], bobValues[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(aliceValues = [1, 2],bobValues = [3, 1]) == 0\n assert candidate(aliceValues = [1, 2, 3, 4, 5],bobValues = [5, 4, 3, 2, 1]) == 1\n assert candidate(aliceValues = [9, 9, 9, 9, 9],bobValues = [1, 1, 1, 1, 1]) == 1\n assert candidate(aliceValues = [5, 3, 1, 4],bobValues = [4, 1, 2, 3]) == 1\n assert candidate(aliceValues = [10, 20, 30],bobValues = [30, 20, 10]) == 1\n assert candidate(aliceValues = [1, 3],bobValues = [2, 1]) == 1\n assert candidate(aliceValues = [2, 2, 2, 2, 2],bobValues = [3, 3, 3, 3, 3]) == 0\n assert candidate(aliceValues = [1, 1, 1, 1],bobValues = [1, 1, 1, 1]) == 0\n assert candidate(aliceValues = [1, 1, 1, 1, 1],bobValues = [9, 9, 9, 9, 9]) == -1\n assert candidate(aliceValues = [7, 8, 9],bobValues = [9, 8, 7]) == 1\n assert candidate(aliceValues = [2, 4, 3],bobValues = [1, 6, 7]) == -1\n assert candidate(aliceValues = [10, 10, 10, 10],bobValues = [10, 10, 10, 10]) == 0\n assert candidate(aliceValues = [5, 3, 8, 2],bobValues = [4, 1, 7, 3]) == 1\n assert candidate(aliceValues = [100, 100, 100],bobValues = [100, 100, 100]) == 1\n assert candidate(aliceValues = [99, 98, 97],bobValues = [1, 2, 3]) == 1\n assert candidate(aliceValues = [100, 1, 1, 1],bobValues = [1, 100, 1, 1]) == 0\n assert candidate(aliceValues = [30, 20, 10],bobValues = [10, 20, 30]) == 1\n assert candidate(aliceValues = [5, 5, 5, 5],bobValues = [5, 5, 5, 5]) == 0\n assert candidate(aliceValues = [1, 1, 1, 1, 1],bobValues = [1, 1, 1, 1, 1]) == 1\n assert candidate(aliceValues = [99, 1, 99, 1, 99, 1],bobValues = [1, 99, 1, 99, 1, 99]) == 0\n assert candidate(aliceValues = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],bobValues = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 0\n assert candidate(aliceValues = [80, 70, 60, 50, 40, 30, 20, 10],bobValues = [10, 20, 30, 40, 50, 60, 70, 80]) == 0\n assert candidate(aliceValues = [99, 50, 25, 10, 5],bobValues = [1, 1, 1, 1, 1]) == 1\n assert candidate(aliceValues = [100, 50, 25, 12, 6],bobValues = [5, 20, 40, 60, 80]) == 1\n assert candidate(aliceValues = [100, 1, 100, 1, 100],bobValues = [1, 100, 1, 100, 1]) == 1\n assert candidate(aliceValues = [5, 8, 7, 12, 9],bobValues = [4, 6, 5, 10, 7]) == 1\n assert candidate(aliceValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],bobValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(aliceValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],bobValues = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 1\n assert candidate(aliceValues = [3, 2, 3, 4, 5],bobValues = [5, 4, 3, 2, 3]) == 1\n assert candidate(aliceValues = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],bobValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(aliceValues = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1],bobValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100]) == 0\n assert candidate(aliceValues = [50, 30, 20],bobValues = [1, 20, 30]) == 1\n assert candidate(aliceValues = [100, 99, 98, 97, 96],bobValues = [95, 94, 93, 92, 91]) == 1\n assert candidate(aliceValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],bobValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(aliceValues = [5, 5, 5, 5],bobValues = [6, 6, 6, 6]) == -1\n assert candidate(aliceValues = [23, 45, 67, 89, 10],bobValues = [10, 89, 67, 45, 23]) == 1\n assert candidate(aliceValues = [23, 45, 67, 89, 12],bobValues = [12, 89, 67, 45, 23]) == 1\n assert candidate(aliceValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],bobValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(aliceValues = [50, 30, 20, 10, 1],bobValues = [10, 20, 30, 40, 50]) == 1\n assert candidate(aliceValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],bobValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(aliceValues = [99, 98, 97, 96, 95],bobValues = [1, 2, 3, 4, 5]) == 1\n assert candidate(aliceValues = [50, 50, 50, 50, 50],bobValues = [50, 50, 50, 50, 50]) == 1\n assert candidate(aliceValues = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],bobValues = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == 0\n assert candidate(aliceValues = [5, 2, 3, 3, 4],bobValues = [4, 3, 2, 3, 5]) == 1\n assert candidate(aliceValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],bobValues = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(aliceValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],bobValues = [75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 1\n assert candidate(aliceValues = [100, 50, 25, 10, 5],bobValues = [5, 10, 25, 50, 100]) == 1\n assert candidate(aliceValues = [30, 20, 10, 50, 40, 60, 70],bobValues = [70, 60, 50, 40, 30, 20, 10]) == 1\n assert candidate(aliceValues = [50, 50, 50],bobValues = [100, 100, 100]) == 0\n assert candidate(aliceValues = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5],bobValues = [5, 95, 4, 96, 3, 97, 2, 98, 1, 99]) == 0\n assert candidate(aliceValues = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86],bobValues = [86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == 1\n assert candidate(aliceValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bobValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(aliceValues = [100, 100, 100, 100, 100],bobValues = [99, 99, 99, 99, 99]) == 1\n assert candidate(aliceValues = [80, 20, 60, 40, 100, 50, 70],bobValues = [70, 50, 100, 60, 20, 40, 80]) == 1\n assert candidate(aliceValues = [7, 14, 21, 28, 35, 42],bobValues = [6, 12, 18, 24, 30, 36]) == 1\n assert candidate(aliceValues = [10, 10, 10, 10],bobValues = [20, 20, 20, 20]) == -1\n assert candidate(aliceValues = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],bobValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(aliceValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],bobValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(aliceValues = [100, 90, 80, 70, 60],bobValues = [60, 70, 80, 90, 100]) == 1\n assert candidate(aliceValues = [100, 100, 1, 1, 1],bobValues = [1, 1, 100, 100, 100]) == 1\n assert candidate(aliceValues = [2, 4, 6, 8, 10],bobValues = [1, 3, 5, 7, 9]) == 1\n assert candidate(aliceValues = [5, 15, 25, 35, 45, 55],bobValues = [55, 45, 35, 25, 15, 5]) == 0\n assert candidate(aliceValues = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],bobValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(aliceValues = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],bobValues = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(aliceValues = [100, 100, 100, 100, 100],bobValues = [50, 50, 50, 50, 50]) == 1\n assert candidate(aliceValues = [90, 20, 30, 10, 50],bobValues = [50, 90, 10, 30, 20]) == 1\n assert candidate(aliceValues = [10, 10, 10, 10, 10, 10],bobValues = [9, 9, 9, 9, 9, 9]) == 1\n assert candidate(aliceValues = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],bobValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(aliceValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],bobValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(aliceValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],bobValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(aliceValues = [100, 1, 2, 3, 4],bobValues = [1, 100, 2, 3, 4]) == 1\n assert candidate(aliceValues = [100, 1, 50, 25, 75],bobValues = [90, 99, 5, 20, 70]) == 1\n assert candidate(aliceValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bobValues = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(aliceValues = [90, 90, 90, 90, 90, 90, 90, 90, 90, 90],bobValues = [91, 91, 91, 91, 91, 91, 91, 91, 91, 91]) == -1\n assert candidate(aliceValues = [2, 3, 5, 7, 11],bobValues = [11, 7, 5, 3, 2]) == 1\n assert candidate(aliceValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],bobValues = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(aliceValues = [30, 30, 30, 30, 30],bobValues = [30, 30, 30, 30, 30]) == 1\n assert candidate(aliceValues = [30, 20, 10],bobValues = [10, 20, 30]) == 1\n assert candidate(aliceValues = [10, 1, 10, 1, 10, 1, 10, 1],bobValues = [1, 10, 1, 10, 1, 10, 1, 10]) == 0\n assert candidate(aliceValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],bobValues = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(aliceValues = [1, 3, 5, 7, 9, 11, 13],bobValues = [2, 4, 6, 8, 10, 12, 14]) == 1\n assert candidate(aliceValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],bobValues = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(aliceValues = [10, 20, 30, 40, 50],bobValues = [50, 40, 30, 20, 10]) == 1\n assert candidate(aliceValues = [50, 50, 50, 50, 50],bobValues = [40, 40, 40, 40, 60]) == 1\n assert candidate(aliceValues = [50, 40, 30, 20, 10, 10, 20, 30, 40, 50],bobValues = [10, 20, 30, 40, 50, 50, 40, 30, 20, 10]) == 0\n assert candidate(aliceValues = [99, 1, 2, 3, 4],bobValues = [4, 3, 2, 1, 99]) == 1\n assert candidate(aliceValues = [50, 40, 30, 20, 10],bobValues = [10, 20, 30, 40, 50]) == 1\n assert candidate(aliceValues = [10, 30, 20, 50, 40],bobValues = [40, 20, 30, 10, 50]) == 1\n assert candidate(aliceValues = [50, 50, 50, 50, 50],bobValues = [50, 50, 50, 50, 51]) == 1\n assert candidate(aliceValues = [5, 15, 25, 35, 45, 55, 65],bobValues = [65, 55, 45, 35, 25, 15, 5]) == 1\n assert candidate(aliceValues = [10, 20, 30, 40, 50],bobValues = [50, 40, 30, 20, 10]) == 1\n assert candidate(aliceValues = [50, 25, 50, 75, 25],bobValues = [75, 50, 25, 25, 50]) == 1\n assert candidate(aliceValues = [1, 1, 1, 2, 2, 2, 3, 3, 3],bobValues = [3, 3, 3, 2, 2, 2, 1, 1, 1]) == 1\n assert candidate(aliceValues = [100, 1, 1, 1, 1],bobValues = [1, 1, 1, 1, 100]) == 1\n assert candidate(aliceValues = [90, 80, 70, 60, 50, 40, 30, 20, 10],bobValues = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 1\n assert candidate(aliceValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],bobValues = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(aliceValues = [90, 10, 90, 10, 90],bobValues = [10, 90, 10, 90, 10]) == 1\n assert candidate(aliceValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],bobValues = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(aliceValues = [42, 23, 17, 5, 99],bobValues = [99, 5, 17, 23, 42]) == 1\n assert candidate(aliceValues = [100, 50, 1, 1, 1, 1, 1, 1, 1, 1],bobValues = [1, 1, 99, 99, 99, 99, 99, 99, 99, 99]) == -1\n assert candidate(aliceValues = [70, 60, 50, 40, 30, 20, 10],bobValues = [10, 20, 30, 40, 50, 60, 70]) == 1\n assert candidate(aliceValues = [90, 10, 20, 30, 40, 50, 60, 70, 80],bobValues = [10, 90, 80, 70, 60, 50, 40, 30, 20]) == 1\n assert candidate(aliceValues = [100],bobValues = [1]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,3]\n[2,1]", "[1,2]\n[3,1]", "[2,4,3]\n[1,6,7]"], "hints": ["When one takes the stone, they not only get the points, but they take them away from the other player too.", "Greedily choose the stone with the maximum aliceValues[i] + bobValues[i]."], "metadata": {"canonical_parameter_names": ["aliceValues", "bobValues"], "leetcode_dataset_entry_point": "Solution().stoneGameVI", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:27+00:00", "tests_total": 106, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "math", "greedy", "minimax-algorithm", "sorting", "heap-priority-queue", "game-theory", "zero-sum-game"]}, "language": "php", "interface": {"raw_signature": "function stoneGameVI($aliceValues, $bobValues) {", "container": "Solution", "callable": "stoneGameVI", "parameters": [{"name": "aliceValues", "type": "Integer[]"}, {"name": "bobValues", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1687, "task_id": "delivering-boxes-from-storage-to-ports", "difficulty": "Hard", "problem_description": "You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.\n\nYou are given an array boxes, where boxes[i] = [ports_i, weight_i], and three integers portsCount, maxBoxes, and maxWeight.\n\n- ports_i is the port where you need to deliver the i^th box and weights_i is the weight of the i^th box.\n- portsCount is the number of ports.\n- maxBoxes and maxWeight are the respective box and weight limits of the ship.\n\nThe boxes need to be delivered in the order they are given. The ship will follow these steps:\n\n- The ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.\n- For each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.\n- The ship then makes a return trip to storage to take more boxes from the queue.\n\nThe ship must end at storage after all the boxes have been delivered.\n\nReturn the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.\n\nExample 1:\n\nInput: boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\nOutput: 4\nExplanation: The optimal strategy is as follows:\n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n\nExample 2:\n\nInput: boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\nOutput: 6\nExplanation: The optimal strategy is as follows:\n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n\nExample 3:\n\nInput: boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\nOutput: 6\nExplanation: The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n\nConstraints:\n\n- 1 <= boxes.length <= 10^5\n- 1 <= portsCount, maxBoxes, maxWeight <= 10^5\n- 1 <= ports_i <= portsCount\n- 1 <= weights_i <= maxWeight\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 5,maxWeight = 5) == 4\n assert candidate(boxes = [[2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4]],portsCount = 4,maxBoxes = 2,maxWeight = 4) == 10\n assert candidate(boxes = [[1, 2], [2, 2], [1, 2], [2, 2], [1, 2]],portsCount = 2,maxBoxes = 3,maxWeight = 6) == 7\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],portsCount = 5,maxBoxes = 1,maxWeight = 5) == 10\n assert candidate(boxes = [[1, 5], [1, 5], [1, 5], [2, 5], [2, 5], [2, 5]],portsCount = 2,maxBoxes = 2,maxWeight = 10) == 7\n assert candidate(boxes = [[1, 5], [2, 5], [1, 5], [2, 5], [1, 5], [2, 5]],portsCount = 2,maxBoxes = 2,maxWeight = 10) == 9\n assert candidate(boxes = [[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]],portsCount = 15,maxBoxes = 5,maxWeight = 15) == 18\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],portsCount = 5,maxBoxes = 5,maxWeight = 15) == 12\n assert candidate(boxes = [[1, 2], [2, 2], [1, 2], [2, 2], [1, 2], [2, 2], [1, 2], [2, 2], [1, 2], [2, 2]],portsCount = 2,maxBoxes = 4,maxWeight = 10) == 13\n assert candidate(boxes = [[1, 1], [2, 1], [1, 1]],portsCount = 2,maxBoxes = 3,maxWeight = 3) == 4\n assert candidate(boxes = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]],portsCount = 5,maxBoxes = 5,maxWeight = 5) == 6\n assert candidate(boxes = [[1, 100], [2, 100], [3, 100], [4, 100], [5, 100]],portsCount = 5,maxBoxes = 5,maxWeight = 500) == 6\n assert candidate(boxes = [[2, 2], [3, 3], [4, 4], [5, 5], [1, 1], [2, 2], [3, 3]],portsCount = 5,maxBoxes = 3,maxWeight = 10) == 10\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 3,maxWeight = 30) == 7\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],portsCount = 9,maxBoxes = 3,maxWeight = 15) == 13\n assert candidate(boxes = [[1, 5], [2, 3], [3, 2], [2, 1], [1, 4]],portsCount = 3,maxBoxes = 5,maxWeight = 15) == 6\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 2,maxWeight = 2) == 6\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 3,maxWeight = 5) == 4\n assert candidate(boxes = [[1, 4], [1, 2], [2, 1], [2, 1], [3, 2], [3, 4]],portsCount = 3,maxBoxes = 6,maxWeight = 7) == 6\n assert candidate(boxes = [[1, 1], [1, 1], [2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4], [5, 5], [5, 5]],portsCount = 5,maxBoxes = 3,maxWeight = 5) == 16\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],portsCount = 10,maxBoxes = 10,maxWeight = 55) == 11\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10]],portsCount = 3,maxBoxes = 2,maxWeight = 20) == 5\n assert candidate(boxes = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],portsCount = 5,maxBoxes = 2,maxWeight = 10) == 8\n assert candidate(boxes = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],portsCount = 1,maxBoxes = 3,maxWeight = 9) == 4\n assert candidate(boxes = [[1, 3], [2, 5], [3, 7], [4, 9]],portsCount = 4,maxBoxes = 2,maxWeight = 12) == 7\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],portsCount = 5,maxBoxes = 2,maxWeight = 5) == 9\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 5,maxWeight = 50) == 6\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 5,maxWeight = 25) == 8\n assert candidate(boxes = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],portsCount = 5,maxBoxes = 2,maxWeight = 5) == 10\n assert candidate(boxes = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],portsCount = 5,maxBoxes = 5,maxWeight = 15) == 6\n assert candidate(boxes = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2]],portsCount = 5,maxBoxes = 2,maxWeight = 4) == 8\n assert candidate(boxes = [[1, 5], [2, 2], [3, 3], [1, 1]],portsCount = 3,maxBoxes = 3,maxWeight = 11) == 6\n assert candidate(boxes = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [8, 3], [9, 3], [10, 3]],portsCount = 10,maxBoxes = 10,maxWeight = 30) == 11\n assert candidate(boxes = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3]],portsCount = 5,maxBoxes = 5,maxWeight = 15) == 6\n assert candidate(boxes = [[1, 3], [2, 2], [3, 1]],portsCount = 3,maxBoxes = 5,maxWeight = 6) == 4\n assert candidate(boxes = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],portsCount = 10,maxBoxes = 1,maxWeight = 1) == 20\n assert candidate(boxes = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3]],portsCount = 5,maxBoxes = 5,maxWeight = 15) == 12\n assert candidate(boxes = [[1, 1], [1, 1], [2, 2], [2, 2], [3, 3], [3, 3], [4, 4], [4, 4], [5, 5], [5, 5]],portsCount = 5,maxBoxes = 2,maxWeight = 4) == 0\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 5,maxWeight = 10) == 4\n assert candidate(boxes = [[1, 3], [2, 2], [1, 4], [2, 2], [3, 1]],portsCount = 3,maxBoxes = 3,maxWeight = 10) == 7\n assert candidate(boxes = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5]],portsCount = 1,maxBoxes = 5,maxWeight = 25) == 2\n assert candidate(boxes = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],portsCount = 10,maxBoxes = 5,maxWeight = 10) == 12\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 5,maxWeight = 30) == 7\n assert candidate(boxes = [[1, 5], [2, 5], [3, 5], [4, 5]],portsCount = 4,maxBoxes = 4,maxWeight = 20) == 5\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [1, 10], [2, 10], [3, 10]],portsCount = 3,maxBoxes = 3,maxWeight = 20) == 9\n assert candidate(boxes = [[1, 5], [1, 5], [2, 5], [2, 5], [3, 5], [3, 5]],portsCount = 3,maxBoxes = 3,maxWeight = 15) == 6\n assert candidate(boxes = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],portsCount = 5,maxBoxes = 2,maxWeight = 100) == 8\n assert candidate(boxes = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],portsCount = 1,maxBoxes = 5,maxWeight = 15) == 2\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 5,maxWeight = 5) == 2\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 5,maxWeight = 40) == 7\n assert candidate(boxes = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5]],portsCount = 10,maxBoxes = 5,maxWeight = 15) == 2\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]],portsCount = 7,maxBoxes = 4,maxWeight = 8) == 12\n assert candidate(boxes = [[1, 3], [1, 3], [2, 3], [2, 3], [3, 3], [3, 3]],portsCount = 3,maxBoxes = 4,maxWeight = 9) == 6\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 1,maxWeight = 10) == 10\n assert candidate(boxes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],portsCount = 5,maxBoxes = 5,maxWeight = 15) == 6\n assert candidate(boxes = [[2, 3], [2, 3], [3, 2], [3, 2], [3, 2]],portsCount = 3,maxBoxes = 2,maxWeight = 5) == 7\n assert candidate(boxes = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],portsCount = 5,maxBoxes = 10,maxWeight = 50) == 11\n assert candidate(boxes = [[1, 5], [2, 2], [3, 1], [4, 4], [5, 3]],portsCount = 5,maxBoxes = 2,maxWeight = 10) == 8\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [2, 10], [1, 10]],portsCount = 3,maxBoxes = 2,maxWeight = 20) == 8\n assert candidate(boxes = [[1, 3], [2, 3], [3, 3], [2, 3], [1, 3]],portsCount = 3,maxBoxes = 2,maxWeight = 9) == 8\n assert candidate(boxes = [[1, 2], [3, 3], [3, 1], [3, 1], [2, 4]],portsCount = 3,maxBoxes = 3,maxWeight = 6) == 6\n assert candidate(boxes = [[1, 5], [2, 5], [1, 5], [2, 5], [1, 5], [2, 5], [1, 5], [2, 5], [1, 5], [2, 5]],portsCount = 2,maxBoxes = 5,maxWeight = 25) == 12\n assert candidate(boxes = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],portsCount = 5,maxBoxes = 2,maxWeight = 20) == 8\n assert candidate(boxes = [[1, 5], [2, 3], [3, 2], [4, 1], [2, 2]],portsCount = 4,maxBoxes = 5,maxWeight = 10) == 7\n assert candidate(boxes = [[1, 3], [2, 2], [3, 2], [4, 2], [5, 2]],portsCount = 5,maxBoxes = 3,maxWeight = 5) == 8\n assert candidate(boxes = [[1, 5], [2, 5], [1, 5], [2, 5], [1, 5]],portsCount = 2,maxBoxes = 3,maxWeight = 15) == 7\n assert candidate(boxes = [[1, 5], [2, 6], [3, 7]],portsCount = 3,maxBoxes = 2,maxWeight = 12) == 5\n assert candidate(boxes = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],portsCount = 10,maxBoxes = 10,maxWeight = 10) == 11\n assert candidate(boxes = [[2, 5], [2, 4], [5, 1], [5, 1], [5, 1], [1, 5], [1, 5], [1, 5], [1, 5], [5, 1]],portsCount = 5,maxBoxes = 5,maxWeight = 10) == 10\n assert candidate(boxes = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],portsCount = 1,maxBoxes = 2,maxWeight = 2) == 6\n assert candidate(boxes = [[1, 5], [2, 3], [3, 2], [4, 1], [2, 2]],portsCount = 4,maxBoxes = 4,maxWeight = 10) == 7\n assert candidate(boxes = [[1, 1], [1, 1], [2, 2], [2, 2], [3, 3], [3, 3]],portsCount = 3,maxBoxes = 3,maxWeight = 10) == 6\n assert candidate(boxes = [[1, 10], [1, 10], [1, 10], [1, 10]],portsCount = 1,maxBoxes = 2,maxWeight = 20) == 4\n assert candidate(boxes = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],portsCount = 10,maxBoxes = 5,maxWeight = 5) == 12\n assert candidate(boxes = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],portsCount = 5,maxBoxes = 1,maxWeight = 5) == 10\n assert candidate(boxes = [[2, 10], [2, 10], [3, 10], [3, 10]],portsCount = 3,maxBoxes = 3,maxWeight = 20) == 4\n", "comparison": "exact"}, "public_tests": ["[[1,1],[2,1],[1,1]]\n2\n3\n3", "[[1,2],[3,3],[3,1],[3,1],[2,4]]\n3\n3\n6", "[[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]]\n3\n6\n7"], "hints": ["Try to think of the most basic dp which is n^2 now optimize it", "Think of any range query data structure to optimize"], "metadata": {"canonical_parameter_names": ["boxes", "portsCount", "maxBoxes", "maxWeight"], "leetcode_dataset_entry_point": "Solution().boxDelivering", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:30+00:00", "tests_total": 76, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "segment-tree", "queue", "heap-priority-queue", "prefix-sum", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function boxDelivering($boxes, $portsCount, $maxBoxes, $maxWeight) {", "container": "Solution", "callable": "boxDelivering", "parameters": [{"name": "boxes", "type": "Integer[][]"}, {"name": "portsCount", "type": "Integer"}, {"name": "maxBoxes", "type": "Integer"}, {"name": "maxWeight", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1688, "task_id": "count-of-matches-in-tournament", "difficulty": "Easy", "problem_description": "You are given an integer n, the number of teams in a tournament that has strange rules:\n\n- If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.\n- If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.\n\nReturn the number of matches played in the tournament until a winner is decided.\n\nExample 1:\n\nInput: n = 7\nOutput: 6\nExplanation: Details of the tournament:\n- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 3 + 2 + 1 = 6.\n\nExample 2:\n\nInput: n = 14\nOutput: 13\nExplanation: Details of the tournament:\n- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.\n- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 7 + 3 + 2 + 1 = 13.\n\nConstraints:\n\n- 1 <= n <= 200\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 100) == 99\n assert candidate(n = 14) == 13\n assert candidate(n = 200) == 199\n assert candidate(n = 17) == 16\n assert candidate(n = 2) == 1\n assert candidate(n = 199) == 198\n assert candidate(n = 1) == 0\n assert candidate(n = 7) == 6\n assert candidate(n = 13) == 12\n assert candidate(n = 97) == 96\n assert candidate(n = 63) == 62\n assert candidate(n = 29) == 28\n assert candidate(n = 45) == 44\n assert candidate(n = 135) == 134\n assert candidate(n = 183) == 182\n assert candidate(n = 49) == 48\n assert candidate(n = 130) == 129\n assert candidate(n = 163) == 162\n assert candidate(n = 111) == 110\n assert candidate(n = 10) == 9\n assert candidate(n = 197) == 196\n assert candidate(n = 50) == 49\n assert candidate(n = 157) == 156\n assert candidate(n = 5) == 4\n assert candidate(n = 123) == 122\n assert candidate(n = 59) == 58\n assert candidate(n = 87) == 86\n assert candidate(n = 173) == 172\n assert candidate(n = 4) == 3\n assert candidate(n = 99) == 98\n assert candidate(n = 16) == 15\n assert candidate(n = 177) == 176\n assert candidate(n = 64) == 63\n assert candidate(n = 33) == 32\n assert candidate(n = 143) == 142\n assert candidate(n = 98) == 97\n assert candidate(n = 73) == 72\n assert candidate(n = 133) == 132\n assert candidate(n = 175) == 174\n assert candidate(n = 128) == 127\n assert candidate(n = 101) == 100\n assert candidate(n = 181) == 180\n assert candidate(n = 8) == 7\n assert candidate(n = 131) == 130\n assert candidate(n = 27) == 26\n assert candidate(n = 169) == 168\n assert candidate(n = 32) == 31\n assert candidate(n = 149) == 148\n assert candidate(n = 127) == 126\n assert candidate(n = 81) == 80\n assert candidate(n = 150) == 149\n assert candidate(n = 151) == 150\n assert candidate(n = 198) == 197\n assert candidate(n = 11) == 10\n assert candidate(n = 15) == 14\n assert candidate(n = 189) == 188\n assert candidate(n = 85) == 84\n assert candidate(n = 31) == 30\n assert candidate(n = 25) == 24\n", "comparison": "exact"}, "public_tests": ["7", "14"], "hints": ["Simulate the tournament as given in the statement.", "Be careful when handling odd integers."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().numberOfMatches", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:32+00:00", "tests_total": 60, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function numberOfMatches($n) {", "container": "Solution", "callable": "numberOfMatches", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1689, "task_id": "partitioning-into-minimum-number-of-deci-binary-numbers", "difficulty": "Medium", "problem_description": "A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.\n\nGiven a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.\n\nExample 1:\n\nInput: n = \"32\"\nOutput: 3\nExplanation: 10 + 11 + 11 = 32\n\nExample 2:\n\nInput: n = \"82734\"\nOutput: 8\n\nExample 3:\n\nInput: n = \"27346209830709182346\"\nOutput: 9\n\nConstraints:\n\n- 1 <= n.length <= 10^5\n- n consists of only digits.\n- n does not contain any leading zeros and represents a positive integer.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = \"9876543210\") == 9\n assert candidate(n = \"111\") == 1\n assert candidate(n = \"123456789\") == 9\n assert candidate(n = \"1\") == 1\n assert candidate(n = \"82734\") == 8\n assert candidate(n = \"32\") == 3\n assert candidate(n = \"11111\") == 1\n assert candidate(n = \"555555555\") == 5\n assert candidate(n = \"9\") == 9\n assert candidate(n = \"27346209830709182346\") == 9\n assert candidate(n = \"1000000000\") == 1\n assert candidate(n = \"55555\") == 5\n assert candidate(n = \"987654321\") == 9\n assert candidate(n = \"987654321098765432109876543210\") == 9\n assert candidate(n = \"1999199919991999199919991999199919991999199919991999\") == 9\n assert candidate(n = \"11111111112222222222333333333333444444444444555555555\") == 5\n assert candidate(n = \"111999888777666555444333222111\") == 9\n assert candidate(n = \"8888888888888888888888888888888888888888\") == 8\n assert candidate(n = \"87654321098765432109\") == 9\n assert candidate(n = \"999999999\") == 9\n assert candidate(n = \"11111111111111111111\") == 1\n assert candidate(n = \"11111111111111111111111111111111111111111111111111111111111111111111111111111111111\") == 1\n assert candidate(n = \"999999999999999999999999999999\") == 9\n assert candidate(n = \"44444444444444444444444444444444444444444444444444\") == 4\n assert candidate(n = \"101010101010101010101010101010\") == 1\n assert candidate(n = \"5432105432105432105432105432105432105432105432105432\") == 5\n assert candidate(n = \"10000000000000000000\") == 1\n assert candidate(n = \"19191919191919191919\") == 9\n assert candidate(n = \"77777777777777777777777777777777777777777777777777\") == 7\n assert candidate(n = \"222222222222222222222222222222222222222222222222222\") == 2\n assert candidate(n = \"99999999999999999999\") == 9\n assert candidate(n = \"8456391728391657813265813265\") == 9\n assert candidate(n = \"9999999999\") == 9\n assert candidate(n = \"918273645091827364509182736450\") == 9\n assert candidate(n = \"12345678901234567890\") == 9\n assert candidate(n = \"9999111199991111999911119999111199991111999911119999\") == 9\n assert candidate(n = \"19191919191919191919191919191919191919191919191919191919191919191919191919191919\") == 9\n assert candidate(n = \"10000000000000000000000000000000000000000000\") == 1\n assert candidate(n = \"55555555555555555555\") == 5\n assert candidate(n = \"888888888888888888888888888888888888888888888888888\") == 8\n assert candidate(n = \"99999\") == 9\n assert candidate(n = \"1111111111\") == 1\n assert candidate(n = \"987654321012345678987654321\") == 9\n assert candidate(n = \"10101010101010101010101010101010\") == 1\n assert candidate(n = \"24681357924681357924\") == 9\n assert candidate(n = \"123456789876543210000000000000000000000000000000000\") == 9\n assert candidate(n = \"12345678987654321\") == 9\n assert candidate(n = \"10101010101010101010\") == 1\n assert candidate(n = \"111222333444555666777888999\") == 9\n assert candidate(n = \"18181818181818181818\") == 8\n assert candidate(n = \"13579135791357913579\") == 9\n assert candidate(n = \"101010101010101010101010101\") == 1\n assert candidate(n = \"100000000000000000000000000000\") == 1\n assert candidate(n = \"765432101023456765432101023456765432101023456765432\") == 7\n assert candidate(n = \"8765432109876543210987654321\") == 9\n assert candidate(n = \"918273645432187654321\") == 9\n assert candidate(n = \"2468135791113151719\") == 9\n assert candidate(n = \"1234567890\") == 9\n assert candidate(n = \"22222222222222222222\") == 2\n assert candidate(n = \"98765432109876543210\") == 9\n assert candidate(n = \"123123123123123123123123123\") == 3\n assert candidate(n = \"191919191919191919191919191919191919191919191919191\") == 9\n assert candidate(n = \"24680246802468024680\") == 8\n assert candidate(n = \"111122223333444455556666777788889999\") == 9\n assert candidate(n = \"50505050505050505050505050505050505050505050\") == 5\n assert candidate(n = \"123456789012345678901234567890\") == 9\n assert candidate(n = \"50000000000000000005\") == 5\n assert candidate(n = \"5555555555\") == 5\n assert candidate(n = \"192837465056473829109876543210\") == 9\n assert candidate(n = \"87654321987654321098\") == 9\n assert candidate(n = \"90000000000000000000900000000000000000000009\") == 9\n assert candidate(n = \"987654321987654321987654321987654321\") == 9\n", "comparison": "exact"}, "public_tests": ["\"32\"", "\"82734\"", "\"27346209830709182346\""], "hints": ["Think about if the input was only one digit. Then you need to add up as many ones as the value of this digit.", "If the input has multiple digits, then you can solve for each digit independently, and merge the answers to form numbers that add up to that input.", "Thus the answer is equal to the max digit."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().minPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:34+00:00", "tests_total": 72, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minPartitions($n) {", "container": "Solution", "callable": "minPartitions", "parameters": [{"name": "n", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1690, "task_id": "stone-game-vii", "difficulty": "Medium", "problem_description": "Alice and Bob take turns playing a game, with Alice starting first.\n\nThere are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.\n\nBob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.\n\nGiven an array of integers stones where stones[i] represents the value of the i^th stone from the left, return the difference in Alice and Bob's score if they both play optimally.\n\nExample 1:\n\nInput: stones = [5,3,1,4,2]\nOutput: 6\nExplanation:\n- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].\n- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].\n- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].\n- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].\n- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].\nThe score difference is 18 - 12 = 6.\n\nExample 2:\n\nInput: stones = [7,90,5,1,100,10,10,2]\nOutput: 122\n\nConstraints:\n\n- n == stones.length\n- 2 <= n <= 1000\n- 1 <= stones[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stones = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 30\n assert candidate(stones = [2, 3, 4, 1, 5, 6, 7, 8, 9, 10]) == 28\n assert candidate(stones = [1, 2, 3, 4, 5]) == 6\n assert candidate(stones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 30\n assert candidate(stones = [7, 90, 5, 1, 100, 10, 10, 2]) == 122\n assert candidate(stones = [1, 2, 3, 100, 4, 5, 6, 7, 8, 9]) == 123\n assert candidate(stones = [10, 20, 30, 40, 50]) == 60\n assert candidate(stones = [1, 100, 1, 100, 1, 100]) == 300\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 30\n assert candidate(stones = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(stones = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 30\n assert candidate(stones = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 5000\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 15\n assert candidate(stones = [3, 9, 4, 2, 10, 3, 2, 5]) == 22\n assert candidate(stones = [5, 3, 1, 4, 2]) == 6\n assert candidate(stones = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 210\n assert candidate(stones = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 210\n assert candidate(stones = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 105\n assert candidate(stones = [500, 250, 750, 1000, 125, 375, 875, 625, 300, 700, 150, 450, 900, 550, 200, 600, 800, 400, 950, 100]) == 5950\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 156\n assert candidate(stones = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 110\n assert candidate(stones = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5, 600, 6, 700, 7, 800, 8, 900, 9, 1000, 10]) == 5500\n assert candidate(stones = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 56\n assert candidate(stones = [500, 2, 100, 400, 3, 800, 7, 600, 9, 50]) == 1852\n assert candidate(stones = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980]) == 9900\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 1100\n assert candidate(stones = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993]) == 7972\n assert candidate(stones = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 2000\n assert candidate(stones = [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]) == 650\n assert candidate(stones = [5, 2, 9, 4, 6, 3, 8, 1, 7, 10]) == 35\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 450\n assert candidate(stones = [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]) == 11844\n assert candidate(stones = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 600\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 420\n assert candidate(stones = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 136\n assert candidate(stones = [500, 400, 300, 200, 100, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5]) == 696\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 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]) == 650\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 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]) == 650\n assert candidate(stones = [2, 1, 3, 4, 1, 5, 7, 8, 1, 9, 6, 10, 12, 11, 13, 14, 15, 16, 17, 18]) == 96\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000]) == 7\n assert candidate(stones = [500, 250, 750, 125, 625, 375, 875, 125, 625, 375, 875, 125, 625, 375, 875, 125, 625, 375, 875, 125]) == 7250\n assert candidate(stones = [500, 250, 750, 200, 1000, 150, 300, 850, 600, 400]) == 3150\n assert candidate(stones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 3000\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 110\n assert candidate(stones = [999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1]) == 9990\n assert candidate(stones = [200, 300, 100, 400, 500, 150, 250, 350, 450, 550]) == 1850\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 450\n assert candidate(stones = [50, 20, 30, 10, 40, 60, 70, 80, 90, 100]) == 280\n assert candidate(stones = [1, 10, 100, 1000, 10, 1, 1000, 100, 10, 1, 10, 100, 1000, 10, 1, 100, 100, 10, 1, 10, 100]) == 1342\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 830\n assert candidate(stones = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 72\n assert candidate(stones = [5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5]) == 35\n assert candidate(stones = [5, 5, 5, 5, 5, 5, 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(stones = [100, 200, 300, 400, 500, 400, 300, 200, 100, 50, 40, 30, 20, 10, 1]) == 1090\n assert candidate(stones = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991, 11, 990, 12, 989, 13, 988, 14, 987, 15, 986]) == 14895\n assert candidate(stones = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 14\n assert candidate(stones = [500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1, 1, 3, 6, 12, 25, 50, 100, 200, 300, 400, 500]) == 1597\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(stones = [50, 10, 50, 10, 50, 10, 50, 10, 50, 10]) == 250\n assert candidate(stones = [2, 2, 2, 2, 2, 2, 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(stones = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\n assert candidate(stones = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996]) == 4990\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 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(stones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 4500\n assert candidate(stones = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 490\n assert candidate(stones = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991]) == 9955\n assert candidate(stones = [1000, 1, 999, 2, 998, 3, 997, 4, 996, 5, 995, 6, 994, 7, 993, 8, 992, 9, 991, 10]) == 9955\n assert candidate(stones = [1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000]) == 10000\n assert candidate(stones = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 8]) == 28\n assert candidate(stones = [300, 100, 250, 150, 200, 50, 100, 300, 250, 150, 200, 50, 100]) == 800\n assert candidate(stones = [100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100]) == 350\n assert candidate(stones = [5, 3, 1, 4, 2, 5, 3, 1, 4, 2, 5, 3, 1, 4, 2, 5, 3, 1, 4, 2, 5, 3, 1, 4, 2, 5, 3, 1, 4, 2]) == 48\n assert candidate(stones = [1000, 1, 2, 1000, 3, 1000, 4, 1000, 5, 1000, 6, 1000, 7, 1000, 8, 1000, 9, 1000, 10, 1000]) == 9001\n assert candidate(stones = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 560\n assert candidate(stones = [1, 10, 100, 1000, 10, 100, 1000, 10, 100, 1000, 10, 100, 1000, 10, 100]) == 2230\n assert candidate(stones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3030\n assert candidate(stones = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 105\n assert candidate(stones = [145, 135, 125, 115, 105, 95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 525\n assert candidate(stones = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5]) == 4985\n assert candidate(stones = [100, 50, 200, 150, 250, 100, 300, 50, 200, 150, 250, 100, 300]) == 600\n assert candidate(stones = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 16\n assert candidate(stones = [700, 100, 500, 200, 600, 300, 400, 800, 900, 100, 200, 300, 400, 500, 600]) == 2300\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 410\n assert candidate(stones = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 992]) == 28\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 560\n assert candidate(stones = [50, 40, 30, 20, 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]) == 141\n assert candidate(stones = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(stones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 60\n assert candidate(stones = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145]) == 525\n assert candidate(stones = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 10\n assert candidate(stones = [314, 159, 265, 358, 979, 323, 846, 264, 338, 327, 950, 288, 419, 716, 939]) == 2435\n assert candidate(stones = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 105\n assert candidate(stones = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 29\n assert candidate(stones = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 2, 4, 8, 16]) == 674\n", "comparison": "exact"}, "public_tests": ["[5,3,1,4,2]", "[7,90,5,1,100,10,10,2]"], "hints": ["The constraints are small enough for an N^2 solution.", "Try using dynamic programming."], "metadata": {"canonical_parameter_names": ["stones"], "leetcode_dataset_entry_point": "Solution().stoneGameVII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:36+00:00", "tests_total": 109, "tests_dropped": 13, "flags": [], "topic_tags": ["array", "math", "dynamic-programming", "minimax-algorithm", "game-theory", "zero-sum-game"]}, "language": "php", "interface": {"raw_signature": "function stoneGameVII($stones) {", "container": "Solution", "callable": "stoneGameVII", "parameters": [{"name": "stones", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1691, "task_id": "maximum-height-by-stacking-cuboids", "difficulty": "Hard", "problem_description": "Given n cuboids where the dimensions of the i^th cuboid is cuboids[i] = [width_i, length_i, height_i] (0-indexed). Choose a subset of cuboids and place them on each other.\n\nYou can place cuboid i on cuboid j if width_i <= width_j and length_i <= length_j and height_i <= height_j. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.\n\nReturn the maximum height of the stacked cuboids.\n\nExample 1:\n\nInput: cuboids = [[50,45,20],[95,37,53],[45,23,12]]\nOutput: 190\nExplanation:\nCuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\nCuboid 0 is placed next with the 45x20 side facing down with height 50.\nCuboid 2 is placed next with the 23x12 side facing down with height 45.\nThe total height is 95 + 50 + 45 = 190.\n\nExample 2:\n\nInput: cuboids = [[38,25,45],[76,35,3]]\nOutput: 76\nExplanation:\nYou can't place any of the cuboids on the other.\nWe choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.\n\nExample 3:\n\nInput: cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\nOutput: 102\nExplanation:\nAfter rearranging the cuboids, you can see that all cuboids have the same dimension.\nYou can place the 11x7 side down on all cuboids so their heights are 17.\nThe maximum height of stacked cuboids is 6 * 17 = 102.\n\nConstraints:\n\n- n == cuboids.length\n- 1 <= n <= 100\n- 1 <= width_i, length_i, height_i <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(cuboids = [[4, 6, 7], [1, 2, 3], [4, 5, 6], [10, 12, 32]]) == 48\n assert candidate(cuboids = [[10, 10, 10], [5, 5, 5], [20, 20, 20]]) == 35\n assert candidate(cuboids = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 6\n assert candidate(cuboids = [[50, 45, 20], [95, 37, 53], [45, 23, 12]]) == 190\n assert candidate(cuboids = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 18\n assert candidate(cuboids = [[38, 25, 45], [76, 35, 3]]) == 76\n assert candidate(cuboids = [[10, 10, 10], [9, 9, 9], [8, 8, 8], [7, 7, 7], [6, 6, 6]]) == 40\n assert candidate(cuboids = [[100, 100, 1], [100, 100, 1], [100, 100, 1]]) == 300\n assert candidate(cuboids = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 4\n assert candidate(cuboids = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) == 10\n assert candidate(cuboids = [[1, 2, 2], [3, 4, 4], [5, 6, 6]]) == 12\n assert candidate(cuboids = [[10, 10, 10], [9, 9, 9], [8, 8, 8], [7, 7, 7]]) == 34\n assert candidate(cuboids = [[10, 10, 10], [9, 9, 9], [8, 8, 8]]) == 27\n assert candidate(cuboids = [[7, 11, 17], [7, 17, 11], [11, 7, 17], [11, 17, 7], [17, 7, 11], [17, 11, 7]]) == 102\n assert candidate(cuboids = [[1, 1, 100], [1, 1, 100], [1, 1, 100]]) == 300\n assert candidate(cuboids = [[100, 100, 100], [99, 99, 99], [98, 98, 98]]) == 297\n assert candidate(cuboids = [[10, 20, 30], [30, 20, 10], [20, 10, 30]]) == 90\n assert candidate(cuboids = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50], [60, 60, 60]]) == 210\n assert candidate(cuboids = [[3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 10, 11]]) == 56\n assert candidate(cuboids = [[9, 8, 7], [6, 5, 4], [3, 2, 1], [12, 11, 10], [15, 14, 13]]) == 45\n assert candidate(cuboids = [[10, 10, 10], [20, 20, 20], [15, 15, 15], [25, 25, 25], [30, 30, 30]]) == 100\n assert candidate(cuboids = [[20, 20, 20], [20, 20, 15], [20, 15, 10], [15, 10, 5]]) == 75\n assert candidate(cuboids = [[3, 4, 5], [1, 2, 6], [4, 5, 3], [5, 3, 4], [6, 2, 1]]) == 15\n assert candidate(cuboids = [[50, 50, 50], [49, 49, 49], [48, 48, 48], [47, 47, 47], [46, 46, 46], [45, 45, 45], [44, 44, 44]]) == 329\n assert candidate(cuboids = [[10, 1, 1], [9, 2, 2], [8, 3, 3], [7, 4, 4], [6, 5, 5], [5, 6, 6], [4, 7, 7], [3, 8, 8], [2, 9, 9], [1, 10, 10], [10, 9, 8], [9, 8, 7], [8, 7, 6], [7, 6, 5], [6, 5, 4], [5, 4, 3], [4, 3, 2], [3, 2, 1], [2, 1, 10], [1, 10, 9]]) == 64\n assert candidate(cuboids = [[30, 20, 10], [20, 10, 5], [10, 5, 2], [5, 2, 1], [2, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 70\n assert candidate(cuboids = [[20, 30, 40], [40, 30, 20], [10, 5, 15], [5, 10, 15]]) == 110\n assert candidate(cuboids = [[1, 3, 5], [1, 4, 6], [1, 5, 7], [2, 4, 8], [2, 5, 9], [3, 5, 11]]) == 39\n assert candidate(cuboids = [[10, 10, 10], [9, 9, 9], [8, 8, 8], [7, 7, 7], [6, 6, 6], [5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1]]) == 55\n assert candidate(cuboids = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50], [60, 60, 60], [70, 70, 70], [80, 80, 80]]) == 360\n assert candidate(cuboids = [[60, 50, 40], [50, 40, 30], [40, 30, 20], [30, 20, 10], [20, 10, 5], [10, 5, 2], [5, 2, 1]]) == 215\n assert candidate(cuboids = [[1, 3, 2], [2, 1, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]]) == 33\n assert candidate(cuboids = [[1, 2, 2], [2, 2, 1], [2, 1, 2], [2, 2, 3], [3, 2, 2], [2, 3, 2]]) == 15\n assert candidate(cuboids = [[10, 20, 30], [15, 25, 40], [20, 30, 50], [25, 40, 60], [30, 50, 70]]) == 250\n assert candidate(cuboids = [[10, 11, 12], [12, 10, 11], [11, 12, 10], [10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40]]) == 136\n assert candidate(cuboids = [[1, 2, 3], [3, 2, 1], [2, 1, 3], [1, 3, 2], [3, 1, 2], [2, 3, 1]]) == 18\n assert candidate(cuboids = [[3, 6, 5], [4, 4, 7], [5, 6, 7], [3, 5, 8], [2, 3, 4]]) == 18\n assert candidate(cuboids = [[99, 99, 99], [98, 98, 98], [97, 97, 97], [96, 96, 96], [95, 95, 95], [94, 94, 94]]) == 579\n assert candidate(cuboids = [[50, 40, 30], [40, 30, 20], [30, 20, 10], [20, 10, 5], [10, 5, 1], [9, 8, 7], [8, 7, 6], [7, 6, 5], [6, 5, 4], [5, 4, 3], [4, 3, 2], [3, 2, 1]]) == 165\n assert candidate(cuboids = [[20, 30, 40], [10, 20, 30], [15, 25, 35], [5, 10, 15], [25, 35, 45]]) == 165\n assert candidate(cuboids = [[8, 8, 8], [9, 9, 9], [7, 7, 7], [6, 6, 6], [10, 10, 10]]) == 40\n assert candidate(cuboids = [[10, 20, 30], [20, 30, 10], [30, 10, 20], [10, 10, 10]]) == 100\n assert candidate(cuboids = [[10, 20, 30], [5, 15, 25], [40, 60, 70], [15, 25, 5]]) == 150\n assert candidate(cuboids = [[2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]]) == 30\n assert candidate(cuboids = [[40, 50, 60], [20, 30, 40], [10, 20, 30], [5, 10, 15], [25, 35, 45]]) == 190\n assert candidate(cuboids = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 22\n assert candidate(cuboids = [[50, 30, 20], [40, 25, 15], [60, 35, 25], [70, 40, 30], [80, 45, 35]]) == 300\n assert candidate(cuboids = [[10, 20, 30], [30, 20, 10], [20, 30, 10], [10, 30, 20], [30, 10, 20], [20, 10, 30]]) == 180\n assert candidate(cuboids = [[1, 2, 3], [3, 2, 1], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [4, 5, 6], [6, 5, 4], [5, 4, 6], [6, 4, 5], [5, 6, 4], [4, 6, 5]]) == 54\n assert candidate(cuboids = [[20, 20, 20], [19, 19, 19], [18, 18, 18], [17, 17, 17], [16, 16, 16], [15, 15, 15]]) == 105\n assert candidate(cuboids = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50]]) == 150\n assert candidate(cuboids = [[1, 1, 100], [1, 100, 1], [100, 1, 1], [1, 1, 50], [1, 50, 1], [50, 1, 1]]) == 450\n assert candidate(cuboids = [[5, 5, 5], [5, 5, 6], [5, 5, 7], [5, 5, 8], [5, 5, 9]]) == 35\n assert candidate(cuboids = [[7, 8, 9], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20]]) == 71\n assert candidate(cuboids = [[10, 10, 10], [10, 10, 5], [10, 5, 10], [5, 10, 10], [10, 5, 5], [5, 10, 5], [5, 5, 10]]) == 70\n assert candidate(cuboids = [[50, 45, 20], [95, 37, 53], [45, 23, 12], [53, 37, 95], [23, 12, 45], [12, 45, 23]]) == 375\n assert candidate(cuboids = [[90, 10, 10], [10, 90, 10], [10, 10, 90], [45, 45, 45], [60, 60, 60], [80, 80, 80]]) == 270\n assert candidate(cuboids = [[5, 12, 2], [2, 9, 12], [12, 3, 4], [8, 6, 10], [7, 12, 5], [1, 15, 15], [15, 1, 15], [15, 15, 1]]) == 45\n assert candidate(cuboids = [[5, 3, 1], [7, 5, 3], [9, 7, 5], [11, 9, 7], [13, 11, 9], [15, 13, 11]]) == 60\n assert candidate(cuboids = [[7, 3, 1], [8, 4, 2], [9, 5, 3], [10, 6, 4], [11, 7, 5], [12, 8, 6]]) == 57\n assert candidate(cuboids = [[10, 10, 10], [15, 15, 15], [20, 20, 20], [25, 25, 25], [30, 30, 30], [35, 35, 35], [40, 40, 40], [45, 45, 45]]) == 220\n assert candidate(cuboids = [[8, 1, 6], [3, 5, 7], [4, 9, 2], [2, 6, 8], [5, 7, 3], [9, 4, 1]]) == 18\n assert candidate(cuboids = [[30, 20, 10], [25, 20, 10], [20, 15, 5], [15, 10, 5], [10, 6, 3], [5, 3, 1]]) == 105\n assert candidate(cuboids = [[50, 45, 20], [95, 37, 53], [45, 23, 12], [60, 60, 60], [10, 10, 10], [20, 20, 20], [30, 30, 30]]) == 200\n assert candidate(cuboids = [[5, 12, 17], [3, 8, 9], [1, 2, 3], [6, 7, 8], [4, 10, 11], [2, 5, 6]]) == 46\n assert candidate(cuboids = [[1, 2, 3], [3, 2, 1], [2, 1, 3], [3, 1, 2], [2, 3, 1], [1, 3, 2]]) == 18\n assert candidate(cuboids = [[100, 1, 1], [99, 2, 2], [98, 3, 3], [97, 4, 4], [96, 5, 5], [95, 6, 6], [94, 7, 7], [93, 8, 8], [92, 9, 9], [91, 10, 10]]) == 100\n assert candidate(cuboids = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 30\n assert candidate(cuboids = [[8, 8, 8], [7, 7, 9], [6, 6, 10], [5, 5, 11], [4, 4, 12], [3, 3, 13], [2, 2, 14], [1, 1, 15]]) == 15\n assert candidate(cuboids = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60], [50, 60, 70]]) == 250\n assert candidate(cuboids = [[100, 50, 25], [50, 25, 12], [25, 12, 6], [12, 6, 3], [6, 3, 1], [3, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 199\n assert candidate(cuboids = [[10, 20, 30], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 57\n assert candidate(cuboids = [[4, 6, 7], [1, 2, 3], [4, 5, 6], [10, 12, 32], [1, 1, 4]]) == 49\n assert candidate(cuboids = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6]]) == 21\n assert candidate(cuboids = [[7, 11, 17], [11, 7, 17], [17, 11, 7], [7, 17, 11], [11, 17, 7], [17, 7, 11], [7, 11, 17], [11, 7, 17], [17, 11, 7]]) == 153\n assert candidate(cuboids = [[20, 20, 20], [10, 10, 10], [30, 30, 30], [15, 15, 15]]) == 75\n assert candidate(cuboids = [[1, 1, 100], [2, 2, 99], [3, 3, 98], [4, 4, 97], [5, 5, 96], [6, 6, 95]]) == 100\n assert candidate(cuboids = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]]) == 33\n assert candidate(cuboids = [[8, 8, 8], [8, 8, 7], [8, 7, 6], [7, 6, 5], [6, 5, 4], [5, 4, 3], [4, 3, 2], [3, 2, 1]]) == 49\n assert candidate(cuboids = [[3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9], [10, 10, 10]]) == 52\n assert candidate(cuboids = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3]]) == 18\n assert candidate(cuboids = [[10, 12, 3], [1, 3, 5], [6, 7, 8], [5, 4, 3], [7, 8, 9], [8, 9, 10]]) == 37\n assert candidate(cuboids = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 40\n assert candidate(cuboids = [[9, 8, 7], [8, 7, 6], [7, 6, 5], [6, 5, 4], [5, 4, 3], [4, 3, 2], [3, 2, 1]]) == 42\n assert candidate(cuboids = [[23, 28, 32], [28, 32, 23], [32, 23, 28], [11, 29, 31], [29, 31, 11], [31, 11, 29], [12, 16, 24], [16, 24, 12], [24, 12, 16], [16, 24, 14]]) == 192\n assert candidate(cuboids = [[15, 12, 8], [8, 12, 15], [12, 15, 8], [9, 10, 7], [7, 10, 9], [10, 7, 9]]) == 75\n assert candidate(cuboids = [[1, 1, 10], [1, 2, 9], [1, 3, 8], [1, 4, 7], [1, 5, 6], [1, 6, 5], [1, 7, 4], [1, 8, 3], [1, 9, 2], [1, 10, 1]]) == 20\n assert candidate(cuboids = [[30, 50, 70], [20, 40, 60], [10, 30, 50], [5, 15, 25], [1, 2, 3]]) == 208\n assert candidate(cuboids = [[25, 15, 10], [15, 10, 5], [10, 5, 2], [5, 3, 1], [3, 2, 1], [2, 1, 1], [1, 1, 1]]) == 61\n assert candidate(cuboids = [[12, 34, 56], [34, 12, 78], [56, 78, 12], [78, 12, 34]]) == 290\n assert candidate(cuboids = [[100, 1, 1], [1, 100, 1], [1, 1, 100], [99, 2, 2], [2, 99, 2], [2, 2, 99], [50, 50, 50], [75, 75, 75]]) == 300\n assert candidate(cuboids = [[3, 4, 5], [3, 3, 3], [3, 5, 5], [2, 3, 4], [2, 2, 2], [1, 1, 1], [1, 2, 3]]) == 18\n assert candidate(cuboids = [[15, 10, 5], [10, 8, 4], [5, 4, 2], [30, 20, 10], [20, 15, 5], [10, 6, 3]]) == 90\n assert candidate(cuboids = [[5, 4, 3], [4, 3, 2], [3, 2, 1], [2, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 18\n assert candidate(cuboids = [[1, 1, 1], [1, 2, 2], [2, 2, 2], [1, 3, 3], [2, 3, 3], [3, 3, 3], [1, 4, 4], [2, 4, 4], [3, 4, 4], [4, 4, 4]]) == 22\n assert candidate(cuboids = [[10, 20, 30], [30, 20, 10], [20, 10, 30], [10, 30, 20], [30, 10, 20], [20, 30, 10]]) == 180\n assert candidate(cuboids = [[5, 5, 5], [10, 10, 10], [15, 15, 15], [20, 20, 20], [25, 25, 25]]) == 75\n assert candidate(cuboids = [[5, 20, 30], [20, 30, 5], [30, 5, 20], [5, 30, 20], [30, 20, 5], [20, 5, 30]]) == 180\n assert candidate(cuboids = [[10, 10, 10], [9, 9, 9], [8, 8, 8], [7, 7, 7], [6, 6, 6], [5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1]]) == 55\n assert candidate(cuboids = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) == 26\n assert candidate(cuboids = [[4, 5, 6], [6, 5, 4], [7, 8, 9], [9, 8, 7], [1, 2, 3], [3, 2, 1]]) == 36\n assert candidate(cuboids = [[40, 40, 40], [30, 30, 30], [20, 20, 20], [10, 10, 10], [5, 5, 5], [1, 1, 1], [40, 30, 20], [30, 20, 10], [20, 10, 5], [10, 5, 1]]) == 141\n assert candidate(cuboids = [[9, 9, 9], [8, 8, 8], [7, 7, 7], [6, 6, 6], [5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1]]) == 45\n assert candidate(cuboids = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]]) == 42\n assert candidate(cuboids = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24]]) == 108\n assert candidate(cuboids = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50], [60, 60, 60], [70, 70, 70], [80, 80, 80], [90, 90, 90], [100, 100, 100]]) == 550\n assert candidate(cuboids = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60], [50, 60, 70], [60, 70, 80], [70, 80, 90], [80, 90, 100]]) == 520\n", "comparison": "exact"}, "public_tests": ["[[50,45,20],[95,37,53],[45,23,12]]", "[[38,25,45],[76,35,3]]", "[[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]"], "hints": ["Does the dynamic programming sound like the right algorithm after sorting?", "Let's say box1 can be placed on top of box2. No matter what orientation box2 is in, we can rotate box1 so that it can be placed on top. Why don't we orient everything such that height is the biggest?"], "metadata": {"canonical_parameter_names": ["cuboids"], "leetcode_dataset_entry_point": "Solution().maxHeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:38+00:00", "tests_total": 108, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxHeight($cuboids) {", "container": "Solution", "callable": "maxHeight", "parameters": [{"name": "cuboids", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1694, "task_id": "reformat-phone-number", "difficulty": "Easy", "problem_description": "You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.\n\nYou would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:\n\n- 2 digits: A single block of length 2.\n- 3 digits: A single block of length 3.\n- 4 digits: Two blocks of length 2 each.\n\nThe blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.\n\nReturn the phone number after formatting.\n\nExample 1:\n\nInput: number = \"1-23-45 6\"\nOutput: \"123-456\"\nExplanation: The digits are \"123456\".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\nStep 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is \"456\".\nJoining the blocks gives \"123-456\".\n\nExample 2:\n\nInput: number = \"123 4-567\"\nOutput: \"123-45-67\"\nExplanation: The digits are \"1234567\".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\nStep 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are \"45\" and \"67\".\nJoining the blocks gives \"123-45-67\".\n\nExample 3:\n\nInput: number = \"123 4-5678\"\nOutput: \"123-456-78\"\nExplanation: The digits are \"12345678\".\nStep 1: The 1st block is \"123\".\nStep 2: The 2nd block is \"456\".\nStep 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is \"78\".\nJoining the blocks gives \"123-456-78\".\n\nConstraints:\n\n- 2 <= number.length <= 100\n- number consists of digits and the characters '-' and ' '.\n- There are at least two digits in number.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(number = \"12 345 678\") == \"123-456-78\"\n assert candidate(number = \"1234-5678-9012\") == \"123-456-789-012\"\n assert candidate(number = \"12 345 678 90\") == \"123-456-78-90\"\n assert candidate(number = \"123456789\") == \"123-456-789\"\n assert candidate(number = \"12 345 678 901\") == \"123-456-789-01\"\n assert candidate(number = \"12 345-6789\") == \"123-456-789\"\n assert candidate(number = \"123456789012\") == \"123-456-789-012\"\n assert candidate(number = \"1234567890123\") == \"123-456-789-01-23\"\n assert candidate(number = \"12-345 67-89--01\") == \"123-456-789-01\"\n assert candidate(number = \"1234\") == \"12-34\"\n assert candidate(number = \"1 2 3 4 5 6 7 8 9 0\") == \"123-456-78-90\"\n assert candidate(number = \"1234567\") == \"123-45-67\"\n assert candidate(number = \"1 234 567 8901\") == \"123-456-789-01\"\n assert candidate(number = \"123 4567\") == \"123-45-67\"\n assert candidate(number = \"12 345 6789\") == \"123-456-789\"\n assert candidate(number = \"1-23-45 6\") == \"123-456\"\n assert candidate(number = \"12\") == \"12\"\n assert candidate(number = \"1234567890\") == \"123-456-78-90\"\n assert candidate(number = \"123 4-5678\") == \"123-456-78\"\n assert candidate(number = \"123 4-567\") == \"123-45-67\"\n assert candidate(number = \"123-4567890123\") == \"123-456-789-01-23\"\n assert candidate(number = \"1 234-567 890\") == \"123-456-78-90\"\n assert candidate(number = \"123-456-7890\") == \"123-456-78-90\"\n assert candidate(number = \"123\") == \"123\"\n assert candidate(number = \"123-456-789-012-345-678-901-234-567-890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"12 34-56-78-90\") == \"123-456-78-90\"\n assert candidate(number = \"12345 67890 123456 7890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12345678901234567890123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0-1-2-3\") == \"123-456-789-01-23\"\n assert candidate(number = \"1234-5678-9012-3456-7890-12\") == \"123-456-789-012-345-678-90-12\"\n assert candidate(number = \"1234-5678-9012-3456-7890-1234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \" 1-23-45-67-89-01-23 \") == \"123-456-789-01-23\"\n assert candidate(number = \"12345678-90123456-78901234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890 1234567890 12\") == \"123-456-789-012-345-678-901-234-567-890-123-456-789-012-345-678-90-12\"\n assert candidate(number = \"123 4567 890 1234 56\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"123-456-789-012-345-678-901-234-56\") == \"123-456-789-012-345-678-901-234-56\"\n assert candidate(number = \"123 456 7890 1234567890 1234567890 123\") == \"123-456-789-012-345-678-901-234-567-890-123\"\n assert candidate(number = \"12345678901234567890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12345678901234567890123456789012345\") == \"123-456-789-012-345-678-901-234-567-890-123-45\"\n assert candidate(number = \"12 34 56 78 90 12 34 56\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"1234567890-12345-678-9\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"1-234-56789-012345\") == \"123-456-789-012-345\"\n assert candidate(number = \"123 456 7890 12345 678 90\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1234567890123456789012\") == \"123-456-789-012-345-678-90-12\"\n assert candidate(number = \"12-345-6789-012345-6789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"12 3456 789 012 3456 78\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"1-23-45-67-89-01-23-45-67-89-01-23\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1 2345678901234567890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"123 456 789 012 345 678 901 234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0-1\") == \"123-456-789-012-345-678-901\"\n assert candidate(number = \"12 345 678 901 234 567\") == \"123-456-789-012-345-67\"\n assert candidate(number = \"12345678901234567890123456789012345678\") == \"123-456-789-012-345-678-901-234-567-890-123-456-78\"\n assert candidate(number = \"12345678901234567890123456789012\") == \"123-456-789-012-345-678-901-234-567-890-12\"\n assert candidate(number = \"1234 5678 9012 3456 7890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1 234 567 890 123 456 789 012 345\") == \"123-456-789-012-345-678-901-23-45\"\n assert candidate(number = \"123-45678901234567890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890\") == \"123-456-789-012-345-678-901-234-567-890-123-456-78-90\"\n assert candidate(number = \"123-45 67-89 01 2\") == \"123-456-789-012\"\n assert candidate(number = \"1 2 3 4 5 6 7 8 9 0 1 2 3 4 5\") == \"123-456-789-012-345\"\n assert candidate(number = \"1234567890 123 4567 890 1234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"1234-567890-1234567890-12345\") == \"123-456-789-012-345-678-901-23-45\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"123456789012345678901234567890123456\") == \"123-456-789-012-345-678-901-234-567-890-123-456\"\n assert candidate(number = \"1234567890-1234567890-1234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"12345-6789-0123-456\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12-345-678-90\") == \"123-456-78-90\"\n assert candidate(number = \"-12 34 56 78 90 -\") == \"123-456-78-90\"\n assert candidate(number = \"123 456-789-0123-4567-8901\") == \"123-456-789-012-345-678-901\"\n assert candidate(number = \"12-345-678-901-234\") == \"123-456-789-012-34\"\n assert candidate(number = \"1234567890-1234567890-1234567890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"12 345 678 901 234 56\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"123-456-7890-1234-567\") == \"123-456-789-012-345-67\"\n assert candidate(number = \"123 4567 8901 2345\") == \"123-456-789-012-345\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234\") == \"123-456-789-012-345-678-901-234-567-890-12-34\"\n assert candidate(number = \"1-23-456-7890-1234\") == \"123-456-789-012-34\"\n assert candidate(number = \"123456789-0123456789-0123456789-0123\") == \"123-456-789-012-345-678-901-234-567-890-123\"\n assert candidate(number = \"123 456 7890 1234567890 123456\") == \"123-456-789-012-345-678-901-234-56\"\n assert candidate(number = \"123-4567890123456789012345678901234567890\") == \"123-456-789-012-345-678-901-234-567-890-123-456-78-90\"\n assert candidate(number = \"12-345-67890123456789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"1 23 456 7890 1234567890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"1234567890-1234567890-1234567890-1234567890\") == \"123-456-789-012-345-678-901-234-567-890-123-456-78-90\"\n assert candidate(number = \"1234-56789-012345-678\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"-1-23-456-7890-12345-6789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"-1-2-3-4-5-6-7-8-9-0-\") == \"123-456-78-90\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890 1234567890 123\") == \"123-456-789-012-345-678-901-234-567-890-123-456-789-012-345-678-901-23\"\n assert candidate(number = \"12-34-56-78-90-12-34-56-78-90-12-34\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"1234567890 1234567890 1234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"123-4567-8901-2345-6789-012\") == \"123-456-789-012-345-678-90-12\"\n assert candidate(number = \"123 456 7890 123 456 7890 123 456 7890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890 123\") == \"123-456-789-012-345-678-901-234-567-890-123-456-789-01-23\"\n assert candidate(number = \"-12- 345-678-9012-3456-\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"1-23-45-67-89-01\") == \"123-456-789-01\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890 12\") == \"123-456-789-012-345-678-901-234-567-890-123-456-789-012\"\n assert candidate(number = \"12345 67890 1234 56\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"12-345-67-89-01-23\") == \"123-456-789-01-23\"\n assert candidate(number = \"1234567890-123456-789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"1-23-45 67-890\") == \"123-456-78-90\"\n assert candidate(number = \"-1--2--3--4--5--6--7--8--9--0-\") == \"123-456-78-90\"\n assert candidate(number = \"123-456-789-012-345-678\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"123 456 789 012\") == \"123-456-789-012\"\n assert candidate(number = \"123456789012345678901234567890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"123-456 789-012 345-678\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"1-23-45-67-89-01-23-45-67-89-01\") == \"123-456-789-012-345-678-901\"\n assert candidate(number = \"123456789-0123456789012345\") == \"123-456-789-012-345-678-901-23-45\"\n assert candidate(number = \"123 456789 01234 567\") == \"123-456-789-012-345-67\"\n assert candidate(number = \"123-4567-8901-2345-6789-0123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1234-5678-9012-3456-7890-1234-56\") == \"123-456-789-012-345-678-901-234-56\"\n assert candidate(number = \"1-234 567-89 0\") == \"123-456-78-90\"\n assert candidate(number = \"1 2 3 4 5 6 7 8 9 0 1 2 3\") == \"123-456-789-01-23\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1234-5678-9012-3456\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"123456789-0123456789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"123 456 7890 1234567890 123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"-123-456-789-012-345-678-90\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12 34 56 78 90 12 34 56 78\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"123-456-789-012-3456-7890-123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1234567890 1234567890 1234567890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"12-34-56-78-90-12-34\") == \"123-456-789-012-34\"\n assert candidate(number = \"1234567890123456789012345678901234\") == \"123-456-789-012-345-678-901-234-567-890-12-34\"\n assert candidate(number = \"123-4567-89012345-6789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0-1-2-3-4\") == \"123-456-789-012-34\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9\") == \"123-456-789\"\n assert candidate(number = \"123-4567-89012-3456\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"12 34 56 78 90 12 34\") == \"123-456-789-012-34\"\n assert candidate(number = \"123-456-789-012-345-6789-0123-4567-8901\") == \"123-456-789-012-345-678-901-234-567-89-01\"\n assert candidate(number = \"123456789012345678901234567890123\") == \"123-456-789-012-345-678-901-234-567-890-123\"\n assert candidate(number = \"123 456 789 012 345 678 9012\") == \"123-456-789-012-345-678-90-12\"\n assert candidate(number = \"123-456-789-012-345-678-90\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"-123-456-789-012-345-678-901-\") == \"123-456-789-012-345-678-901\"\n assert candidate(number = \"1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890\") == \"123-456-789-012-345-678-901-234-567-890-123-456-789-012-345-678-901-234-567-890-123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"1234567890-1234567890-1234567890-1234\") == \"123-456-789-012-345-678-901-234-567-890-12-34\"\n assert candidate(number = \"123 456 7890 1234 5678\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"123 4567 8901 2345 6789 0123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1234 5678 9012 3456\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"12345 67890 123 456 7890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"1-2-3-4-5-6-7-8-9-0\") == \"123-456-78-90\"\n assert candidate(number = \"1 234 567 890 123 456 789 012\") == \"123-456-789-012-345-678-90-12\"\n assert candidate(number = \"12345-67890-12345-67890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12-345 678 901-234\") == \"123-456-789-012-34\"\n assert candidate(number = \"123-4567-8901-2345-6789-0123-4567-8901-2345\") == \"123-456-789-012-345-678-901-234-567-890-123-45\"\n assert candidate(number = \"12 34 56 78 90 12 34 56 78 90 12 34 56 78 90\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"1234-567890-1234567-890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"123 4567 89012 3456 789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"12 34 567 890 123-4\") == \"123-456-789-012-34\"\n assert candidate(number = \"123 456 789 012 345\") == \"123-456-789-012-345\"\n assert candidate(number = \"123 4567 890 123 45 6789\") == \"123-456-789-012-345-67-89\"\n assert candidate(number = \"12-34-56-78-90-12-34-56-78\") == \"123-456-789-012-345-678\"\n assert candidate(number = \"1234567890-1234-5678901234\") == \"123-456-789-012-345-678-901-234\"\n assert candidate(number = \"123-45-678901234567890\") == \"123-456-789-012-345-678-90\"\n assert candidate(number = \"12-34-56-78-90-12-34-56\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"123 456 789 012 345 678 901 234 567 890\") == \"123-456-789-012-345-678-901-234-567-890\"\n assert candidate(number = \"1-23-45-67-89-01-23-45-67\") == \"123-456-789-012-345-67\"\n assert candidate(number = \"12-345-678-9012-34\") == \"123-456-789-012-34\"\n assert candidate(number = \"12-345-6789-0123-4567-8901-2345-6789\") == \"123-456-789-012-345-678-901-234-567-89\"\n assert candidate(number = \"12345-6789-01234-5678-90123\") == \"123-456-789-012-345-678-901-23\"\n assert candidate(number = \"1234567890123456\") == \"123-456-789-012-34-56\"\n assert candidate(number = \"123-456-7890-123456\") == \"123-456-789-012-34-56\"\n", "comparison": "exact"}, "public_tests": ["\"1-23-45 6\"", "\"123 4-567\"", "\"123 4-5678\""], "hints": ["Discard all the spaces and dashes.", "Use a while loop. While the string still has digits, check its length and see which rule to apply."], "metadata": {"canonical_parameter_names": ["number"], "leetcode_dataset_entry_point": "Solution().reformatNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:43+00:00", "tests_total": 161, "tests_dropped": 2, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function reformatNumber($number) {", "container": "Solution", "callable": "reformatNumber", "parameters": [{"name": "number", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1695, "task_id": "maximum-erasure-value", "difficulty": "Medium", "problem_description": "You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.\n\nReturn the maximum score you can get by erasing exactly one subarray.\n\nAn array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).\n\nExample 1:\n\nInput: nums = [4,2,4,5,6]\nOutput: 17\nExplanation: The optimal subarray here is [2,4,5,6].\n\nExample 2:\n\nInput: nums = [5,2,1,2,5,2,1,2,5]\nOutput: 8\nExplanation: The optimal subarray here is [5,2,1] or [1,2,5].\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 18\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 6]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [10, 5, 2, 7, 8, 7, 4, 5]) == 32\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 6, 5, 7, 8, 9, 8, 10]) == 35\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1, 2, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996]) == 49990\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8, 9]) == 42\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [9, 9, 9, 9, 10, 9, 9, 9]) == 19\n assert candidate(nums = [4, 2, 4, 5, 6]) == 17\n assert candidate(nums = [5, 2, 1, 2, 5, 2, 1, 2, 5]) == 8\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]) == 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, 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 = [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]) == 45\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 19\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]) == 21\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 110\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 210\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]) == 210\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]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 99955\n assert candidate(nums = [400, 300, 200, 100, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 12000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1]) == 595\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, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 15]) == 54\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\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]) == 55\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 324\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550\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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 210\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 99955\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]) == 45\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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, 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]) == 210\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]) == 3\n assert candidate(nums = [1, 2, 3, 1, 4, 5, 6, 2, 3, 7, 8, 9, 10, 1, 2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 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, 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, 2, 3, 4, 3, 5, 6, 5, 7, 8, 9, 8, 10, 11, 10, 12, 13, 12, 14, 15]) == 54\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]) == 45\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 = [1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 324\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996, 6, 9995, 7, 9994, 8, 9993, 9, 9992, 10, 9991]) == 100010\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 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]) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 3, 5, 7, 9, 1]) == 55\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 = [10, 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, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 465\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 10000]) == 99955\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]) == 55\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12]) == 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]) == 325\n assert candidate(nums = [9999, 10000, 9999, 10000, 9999, 10000, 9999, 10000, 9999, 10000, 9999, 10000]) == 19999\n assert candidate(nums = [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]) == 31\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 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, 11]) == 66\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\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 204\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]) == 55\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]) == 55\n assert candidate(nums = [3, 1, 2, 4, 5, 3, 6, 7, 8, 9, 1, 2, 3, 4]) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 39\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]) == 19\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 55\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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, 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, 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 = [100, 200, 100, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 12000\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\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]) == 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, 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 = [2, 2, 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, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 2, 2, 2, 2]) == 819\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\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 300\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]) == 55\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\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) == 5000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5000]) == 50045\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984, 9983, 9982, 9981]) == 199810\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [3, 1, 2, 4, 2, 3, 5, 6, 7, 8, 9, 1]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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, 1, 2, 3, 4, 5]) == 55\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 3, 2, 1, 4, 2, 3, 1, 5, 6, 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, 10, 100, 1000, 10000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 10, 100, 1000, 10000, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11155\n assert candidate(nums = [5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2]) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n", "comparison": "exact"}, "public_tests": ["[4,2,4,5,6]", "[5,2,1,2,5,2,1,2,5]"], "hints": ["The main point here is for the subarray to contain unique elements for each index. Only the first subarrays starting from that index have unique elements.", "This can be solved using the two pointers technique"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumUniqueSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:45+00:00", "tests_total": 105, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function maximumUniqueSubarray($nums) {", "container": "Solution", "callable": "maximumUniqueSubarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1696, "task_id": "jump-game-vi", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer k.\n\nYou are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.\n\nYou want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.\n\nReturn the maximum score you can get.\n\nExample 1:\n\nInput: nums = [1,-1,-2,4,-7,3], k = 2\nOutput: 7\nExplanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.\n\nExample 2:\n\nInput: nums = [10,-5,-2,4,0,3], k = 3\nOutput: 17\nExplanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.\n\nExample 3:\n\nInput: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2\nOutput: 0\n\nConstraints:\n\n- 1 <= nums.length, k <= 10^5\n- -10^4 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 55\n assert candidate(nums = [1, -1, -2, 4, -7, 3],k = 2) == 7\n assert candidate(nums = [10, -5, -2, 4, 0, 3],k = 3) == 17\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 4) == -6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 50\n assert candidate(nums = [-10000, -10000, -10000, -10000, -10000],k = 2) == -30000\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 2) == -9\n assert candidate(nums = [5, -1, 5],k = 2) == 10\n assert candidate(nums = [1],k = 1) == 1\n assert candidate(nums = [5, 4, 3, 2, 1],k = 1) == 15\n assert candidate(nums = [100, -100, 100, -100, 100],k = 2) == 300\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000],k = 5) == 50000\n assert candidate(nums = [5, 6, -4, 2, 1],k = 3) == 14\n assert candidate(nums = [1, -5, -20, 4, -1, 3, -6, -3],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 15\n assert candidate(nums = [-5, -1, -5],k = 1) == -11\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],k = 2) == 4000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 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],k = 2) == 9\n assert candidate(nums = [1000, -500, 2000, -100, 4000, -200, 3000, -300, 5000, -400],k = 5) == 14600\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 5) == -16\n assert candidate(nums = [1, -10, 5, 6, -4, -5, 10, 1, 2],k = 4) == 25\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 55\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 4) == -19\n assert candidate(nums = [5, -1, -2, -3, -4, -5, 6, -1, 2, -3, -4, -5, 10],k = 5) == 22\n assert candidate(nums = [1000, -2000, 3000, -4000, 5000, -6000, 7000, -8000, 9000],k = 6) == 25000\n assert candidate(nums = [10, 20, 30, 40, 50, -60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 4) == 1140\n assert candidate(nums = [3, 2, -6, 5, 0, -3, 2, 1],k = 3) == 13\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == 5500\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 550\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 55\n assert candidate(nums = [10000, -5000, 5000, 6000, -2000, 3000, 7000, -8000, 4000, 10000],k = 5) == 45000\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],k = 4) == 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 = 5) == 9\n assert candidate(nums = [1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000],k = 10) == 2000\n assert candidate(nums = [-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000],k = 5) == 40000\n assert candidate(nums = [1, -10, 5, 6, -2, 3, 7, -8, 4, 10],k = 3) == 36\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1) == 550\n assert candidate(nums = [10000, -9999, 10000, -9999, 10000, -9999, 10000, -9999, 10000, -9999],k = 2) == 40001\n assert candidate(nums = [5, -1, 3, -2, 7, 1, -4, 8, -3, 2],k = 4) == 26\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 0\n assert candidate(nums = [3, -2, -2, 2, -1, 2, 1, -5, 4],k = 3) == 12\n assert candidate(nums = [100, -100, 100, -100, 100, -100, 100],k = 2) == 400\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],k = 5) == 4000\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 3) == 1000\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 4) == 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 = 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],k = 1) == 210\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 = 15) == 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 = 2) == 55\n assert candidate(nums = [3, -1, 2, -5, 6, 2, -1, 4],k = 4) == 17\n assert candidate(nums = [1, -5, 4, 2, -2, -1, 3, 1, -1, 2, -3, 4, -5, 6],k = 3) == 23\n assert candidate(nums = [5, -10, 4, -2, 3, 100, -100, 200, -200, 300],k = 4) == 612\n assert candidate(nums = [10, 5, 2, 7, 8, 9, 3, 5, 2, 1, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5],k = 3) == 102\n assert candidate(nums = [10, -5, -20, 4, -1, 3, -6, -3, 5, 2],k = 4) == 24\n assert candidate(nums = [1, -10, 100, -1000, 10000],k = 3) == 10101\n assert candidate(nums = [-1, -5, -2, -4, -10, -20],k = 2) == -27\n assert candidate(nums = [5, -10, 15, -20, 25, -30, 35, -40, 45, -50, 55, -60, 65, -70, 75, -80],k = 5) == 240\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 15\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 3) == -220\n assert candidate(nums = [3, -1, -1, -1, 10, 5],k = 2) == 17\n assert candidate(nums = [10, -1, 10, -1, 10, -1, 10, -1, 10, -1],k = 5) == 49\n assert candidate(nums = [3, -1, 2, 1, -4, 2, 3, -5, 4],k = 4) == 15\n assert candidate(nums = [100, -100, 50, -50, 25, -25, 12, -12, 6, -6],k = 4) == 187\n assert candidate(nums = [1, -5, 10, 20, -30, 5, 15],k = 4) == 51\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 55\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250, 125, -125, 62, -62, 31, -31],k = 5) == 1937\n assert candidate(nums = [5, 3, 2, 1, 7, 6, 4, 8, 9],k = 3) == 45\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 10) == -110\n assert candidate(nums = [1, -10, 2, -20, 3, -30, 4, -40, 5, -50],k = 4) == -35\n assert candidate(nums = [100, -50, 200, -300, 400, -500, 600, -700, 800],k = 3) == 2100\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 = 10) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 2) == 4\n assert candidate(nums = [100, -50, -100, 200, -300, 400, 500],k = 3) == 1200\n assert candidate(nums = [10000, -5000, 2000, -1000, 5000, 2000, -2000, 3000, 4000, -1000],k = 3) == 25000\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) == 109\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],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) == 20\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 2) == 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) == 210\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],k = 5) == 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],k = 20) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 55\n assert candidate(nums = [10, -10, 10, -10, 10, -10, 10, -10, 10, -10],k = 2) == 40\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 4) == 10\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110, -120, -130, -140, -150],k = 3) == -460\n assert candidate(nums = [100, 200, 300, 400, 500],k = 5) == 1500\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 5) == 1000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 55\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 10) == 0\n", "comparison": "exact"}, "public_tests": ["[1,-1,-2,4,-7,3]\n2", "[10,-5,-2,4,0,3]\n3", "[1,-5,-20,4,-1,3,-6,-3]\n2"], "hints": ["Let dp[i] be \"the maximum score to reach the end starting at index i\". The answer for dp[i] is nums[i] + max{dp[i+j]} for 1 <= j <= k. That gives an O(n*k) solution.", "Instead of checking every j for every i, keep track of the largest dp[i] values in a heap and calculate dp[i] from right to left. When the largest value in the heap is out of bounds of the current index, remove it and keep checking."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxResult", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:48+00:00", "tests_total": 92, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "queue", "heap-priority-queue", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function maxResult($nums, $k) {", "container": "Solution", "callable": "maxResult", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1697, "task_id": "checking-existence-of-edge-length-limited-paths", "difficulty": "Hard", "problem_description": "An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [u_i, v_i, dis_i] denotes an edge between nodes u_i and v_i with distance dis_i. Note that there may be multiple edges between two nodes.\n\nGiven an array queries, where queries[j] = [p_j, q_j, limit_j], your task is to determine for each queries[j] whether there is a path between p_j and q_jsuch that each edge on the path has a distance strictly less than limit_j .\n\nReturn a boolean array answer, where answer.length == queries.length and the j^th value of answer is true if there is a path for queries[j] is true, and false otherwise.\n\nExample 1:\n\nInput: n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\nOutput: [false,true]\nExplanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.\nFor the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.\nFor the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.\n\nExample 2:\n\nInput: n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\nOutput: [true,false]\nExplanation: The above figure shows the given graph.\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 1 <= edgeList.length, queries.length <= 10^5\n- edgeList[i].length == 3\n- queries[j].length == 3\n- 0 <= u_i, v_i, p_j, q_j <= n - 1\n- u_i != v_i\n- p_j != q_j\n- 1 <= dis_i, limit_j <= 10^9\n- There may be multiple edges between two nodes.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,edgeList = [[0, 1, 2], [1, 2, 4], [2, 0, 8], [1, 0, 16]],queries = [[0, 1, 2], [0, 2, 5]]) == [False, True]\n assert candidate(n = 7,edgeList = [[0, 1, 5], [1, 2, 7], [2, 3, 10], [3, 4, 3], [4, 5, 2], [5, 6, 6], [6, 0, 1]],queries = [[0, 6, 8], [3, 5, 4]]) == [True, True]\n assert candidate(n = 6,edgeList = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],queries = [[0, 5, 6], [0, 5, 10], [0, 5, 3]]) == [True, True, False]\n assert candidate(n = 7,edgeList = [[0, 1, 9], [0, 2, 3], [1, 3, 2], [2, 3, 8], [2, 4, 6], [3, 4, 5], [3, 5, 7], [4, 5, 1]],queries = [[0, 4, 8], [1, 2, 4], [3, 5, 6]]) == [True, False, True]\n assert candidate(n = 6,edgeList = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]],queries = [[0, 5, 6], [1, 4, 5], [2, 3, 4]]) == [True, True, True]\n assert candidate(n = 4,edgeList = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 0, 20]],queries = [[0, 3, 15], [1, 2, 8]]) == [False, False]\n assert candidate(n = 2,edgeList = [[0, 1, 1]],queries = [[0, 1, 2], [0, 1, 1]]) == [True, False]\n assert candidate(n = 6,edgeList = [[0, 1, 4], [1, 2, 3], [2, 3, 1], [3, 4, 5], [4, 5, 6]],queries = [[0, 5, 10], [1, 4, 8]]) == [True, True]\n assert candidate(n = 4,edgeList = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]],queries = [[0, 3, 2], [1, 2, 1]]) == [True, False]\n assert candidate(n = 4,edgeList = [[0, 1, 3], [1, 2, 1], [2, 3, 2], [3, 0, 4]],queries = [[0, 2, 4], [1, 3, 5]]) == [True, True]\n assert candidate(n = 5,edgeList = [[0, 1, 10], [1, 2, 5], [2, 3, 9], [3, 4, 13]],queries = [[0, 4, 14], [1, 4, 13]]) == [True, False]\n assert candidate(n = 10,edgeList = [[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], [0, 9, 5]],queries = [[0, 9, 4], [0, 9, 5], [0, 9, 6], [0, 9, 7], [0, 9, 8]]) == [False, False, True, True, True]\n assert candidate(n = 12,edgeList = [[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], [9, 10, 1000], [10, 11, 1100], [11, 0, 1200], [0, 2, 150], [2, 4, 250], [4, 6, 350], [6, 8, 450], [8, 10, 550], [10, 1, 650], [1, 3, 750], [3, 5, 850], [5, 7, 950], [7, 9, 1050], [9, 11, 1150], [11, 3, 1250]],queries = [[0, 11, 700], [2, 10, 550], [4, 8, 400], [6, 0, 250]]) == [False, False, False, False]\n assert candidate(n = 6,edgeList = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [5, 0, 5], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 0, 10], [5, 1, 10]],queries = [[0, 3, 6], [1, 4, 7], [2, 5, 8]]) == [True, True, True]\n assert candidate(n = 50,edgeList = [[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], [9, 10, 1000], [10, 11, 1100], [11, 12, 1200], [12, 13, 1300], [13, 14, 1400], [14, 15, 1500], [15, 16, 1600], [16, 17, 1700], [17, 18, 1800], [18, 19, 1900], [19, 20, 2000], [20, 21, 2100], [21, 22, 2200], [22, 23, 2300], [23, 24, 2400], [24, 25, 2500], [25, 26, 2600], [26, 27, 2700], [27, 28, 2800], [28, 29, 2900], [29, 30, 3000], [30, 31, 3100], [31, 32, 3200], [32, 33, 3300], [33, 34, 3400], [34, 35, 3500], [35, 36, 3600], [36, 37, 3700], [37, 38, 3800], [38, 39, 3900], [39, 40, 4000], [40, 41, 4100], [41, 42, 4200], [42, 43, 4300], [43, 44, 4400], [44, 45, 4500], [45, 46, 4600], [46, 47, 4700], [47, 48, 4800], [48, 49, 4900], [49, 0, 5000]],queries = [[0, 49, 5010], [1, 48, 5020], [2, 47, 5030], [3, 46, 5040], [4, 45, 5050], [5, 44, 5060], [6, 43, 5070], [7, 42, 5080], [8, 41, 5090], [9, 40, 5100], [10, 39, 5110], [11, 38, 5120], [12, 37, 5130], [13, 36, 5140], [14, 35, 5150], [15, 34, 5160], [16, 33, 5170], [17, 32, 5180], [18, 31, 5190], [19, 30, 5200], [20, 29, 5210], [21, 28, 5220], [22, 27, 5230], [23, 26, 5240], [24, 25, 5250], [0, 25, 2600], [1, 24, 2700], [2, 23, 2800], [3, 22, 2900], [4, 21, 3000], [5, 20, 3100], [6, 19, 3200], [7, 18, 3300], [8, 17, 3400], [9, 16, 3500], [10, 15, 3600], [11, 14, 3700], [12, 13, 3800]]) == [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, True, True, True, True, True, True, True, True]\n assert candidate(n = 20,edgeList = [[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], [10, 11, 22], [11, 12, 24], [12, 13, 26], [13, 14, 28], [14, 15, 30], [15, 16, 32], [16, 17, 34], [17, 18, 36], [18, 19, 38]],queries = [[0, 19, 40], [1, 18, 39], [2, 17, 38], [3, 16, 37], [4, 15, 36], [5, 14, 35], [6, 13, 34], [7, 12, 33], [8, 11, 32], [9, 10, 31]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 15,edgeList = [[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], [9, 10, 1000], [10, 11, 1100], [11, 12, 1200], [12, 13, 1300], [13, 14, 1400], [14, 0, 1500]],queries = [[0, 14, 1200], [1, 13, 1100], [2, 12, 1000], [3, 11, 900], [4, 10, 800]]) == [False, False, False, False, False]\n assert candidate(n = 6,edgeList = [[0, 1, 100], [0, 2, 200], [1, 3, 300], [2, 3, 400], [1, 4, 500], [2, 5, 600], [3, 5, 700]],queries = [[0, 5, 800], [0, 5, 400], [0, 3, 350], [0, 4, 600]]) == [True, False, True, True]\n assert candidate(n = 12,edgeList = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [0, 4, 10], [4, 5, 20], [5, 6, 25], [6, 7, 30], [7, 8, 35], [8, 9, 40], [9, 10, 45], [10, 11, 50], [0, 11, 60]],queries = [[0, 11, 65], [0, 11, 55], [0, 5, 25], [5, 10, 45]]) == [True, True, True, False]\n assert candidate(n = 8,edgeList = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [6, 7, 70], [7, 0, 80], [0, 3, 5], [1, 4, 15], [2, 5, 25], [3, 6, 35], [4, 7, 45], [5, 0, 55], [6, 1, 65], [7, 2, 75]],queries = [[0, 7, 40], [2, 6, 35], [4, 0, 60], [1, 5, 75]]) == [False, False, True, True]\n assert candidate(n = 10,edgeList = [[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], [0, 9, 10]],queries = [[0, 9, 5], [0, 9, 15], [2, 7, 6]]) == [False, True, False]\n assert candidate(n = 8,edgeList = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [0, 7, 9], [0, 6, 10], [1, 5, 11], [2, 4, 12]],queries = [[0, 7, 8], [1, 5, 9], [2, 4, 10], [3, 6, 11], [0, 5, 12], [1, 6, 13], [2, 7, 14], [0, 4, 15], [3, 5, 16], [0, 6, 17]]) == [False, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[0, 1, 2], [0, 2, 3], [1, 2, 4], [2, 3, 5], [3, 4, 6], [4, 5, 7], [5, 6, 8], [6, 7, 9], [7, 8, 10], [8, 9, 11], [9, 0, 12]],queries = [[0, 9, 13], [1, 8, 15], [2, 7, 17], [3, 6, 19], [4, 5, 21]]) == [True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[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]],queries = [[0, 9, 10], [0, 5, 6], [3, 7, 5]]) == [True, True, False]\n assert candidate(n = 25,edgeList = [[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], [0, 24, 250]],queries = [[0, 24, 200], [0, 24, 251], [2, 23, 225], [5, 20, 160]]) == [False, True, False, False]\n assert candidate(n = 10,edgeList = [[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]],queries = [[0, 9, 11], [2, 6, 6], [1, 8, 15]]) == [True, False, True]\n assert candidate(n = 15,edgeList = [[0, 1, 100], [1, 2, 200], [2, 3, 150], [3, 4, 250], [4, 5, 300], [5, 6, 350], [6, 7, 400], [7, 8, 450], [8, 9, 500], [9, 10, 550], [10, 11, 600], [11, 12, 650], [12, 13, 700], [13, 14, 750]],queries = [[0, 14, 800], [1, 13, 900], [2, 12, 1000], [3, 11, 1100], [4, 10, 1200], [5, 9, 1300]]) == [True, True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[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, 0, 1]],queries = [[0, 9, 15], [2, 6, 8], [4, 7, 12]]) == [True, True, True]\n assert candidate(n = 20,edgeList = [[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], [9, 10, 50], [10, 11, 55], [11, 12, 60], [12, 13, 65], [13, 14, 70], [14, 15, 75], [15, 16, 80], [16, 17, 85], [17, 18, 90], [18, 19, 95], [19, 0, 100]],queries = [[0, 19, 200], [5, 15, 150], [10, 15, 100]]) == [True, True, True]\n assert candidate(n = 10,edgeList = [[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, 5, 11], [5, 1, 12]],queries = [[0, 9, 11], [1, 8, 10], [2, 7, 9], [3, 6, 8], [4, 5, 7]]) == [True, True, True, True, True]\n assert candidate(n = 11,edgeList = [[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], [0, 10, 11]],queries = [[0, 10, 12], [0, 10, 6], [0, 5, 8], [5, 10, 7], [2, 8, 9], [3, 7, 10]]) == [True, False, True, False, True, True]\n assert candidate(n = 20,edgeList = [[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, 0, 20]],queries = [[0, 19, 15], [1, 18, 14], [2, 17, 13], [3, 16, 12], [4, 15, 11]]) == [False, False, False, False, False]\n assert candidate(n = 50,edgeList = [[0, 1, 5], [1, 2, 15], [2, 3, 25], [3, 4, 35], [4, 5, 45], [5, 6, 55], [6, 7, 65], [7, 8, 75], [8, 9, 85], [9, 10, 95], [10, 11, 105], [11, 12, 115], [12, 13, 125], [13, 14, 135], [14, 15, 145], [15, 16, 155], [16, 17, 165], [17, 18, 175], [18, 19, 185], [19, 20, 195], [20, 21, 205], [21, 22, 215], [22, 23, 225], [23, 24, 235], [24, 25, 245], [25, 26, 255], [26, 27, 265], [27, 28, 275], [28, 29, 285], [29, 30, 295], [30, 31, 305], [31, 32, 315], [32, 33, 325], [33, 34, 335], [34, 35, 345], [35, 36, 355], [36, 37, 365], [37, 38, 375], [38, 39, 385], [39, 40, 395], [40, 41, 405], [41, 42, 415], [42, 43, 425], [43, 44, 435], [44, 45, 445], [45, 46, 455], [46, 47, 465], [47, 48, 475], [48, 49, 485]],queries = [[0, 49, 500], [10, 30, 310], [20, 40, 410]]) == [True, True, True]\n assert candidate(n = 20,edgeList = [[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], [0, 19, 20]],queries = [[0, 19, 10], [0, 19, 21], [2, 18, 15], [5, 15, 10]]) == [False, True, False, False]\n assert candidate(n = 50,edgeList = [[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], [0, 49, 50]],queries = [[0, 49, 40], [0, 49, 51], [2, 48, 45], [5, 45, 30]]) == [False, True, False, False]\n assert candidate(n = 15,edgeList = [[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], [0, 2, 16], [2, 4, 17], [4, 6, 18], [6, 8, 19], [8, 10, 20], [10, 12, 21], [12, 14, 22], [14, 1, 23], [1, 3, 24], [3, 5, 25], [5, 7, 26], [7, 9, 27], [9, 11, 28], [11, 13, 29], [13, 0, 30]],queries = [[0, 14, 15], [2, 12, 13], [4, 10, 11], [6, 8, 9], [8, 6, 8], [10, 4, 10], [12, 2, 16], [14, 0, 14]]) == [True, True, True, True, False, False, True, False]\n assert candidate(n = 20,edgeList = [[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], [9, 10, 1000], [10, 11, 1100], [11, 12, 1200], [12, 13, 1300], [13, 14, 1400], [14, 15, 1500], [15, 16, 1600], [16, 17, 1700], [17, 18, 1800], [18, 19, 1900], [0, 19, 2000]],queries = [[0, 19, 1900], [0, 19, 2000], [1, 18, 3800], [2, 17, 5400], [3, 16, 6900]]) == [False, True, True, True, True]\n assert candidate(n = 15,edgeList = [[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], [0, 7, 20], [1, 8, 21], [2, 9, 22], [3, 10, 23], [4, 11, 24], [5, 12, 25], [6, 13, 26], [7, 14, 27], [8, 0, 28], [9, 1, 29], [10, 2, 30], [11, 3, 31], [12, 4, 32], [13, 5, 33], [14, 6, 34]],queries = [[0, 14, 16], [1, 13, 17], [2, 12, 18], [3, 11, 19], [4, 10, 20], [5, 9, 21], [6, 8, 22], [7, 0, 23], [8, 1, 24], [9, 2, 25], [10, 3, 26], [11, 4, 27], [12, 5, 28], [13, 6, 29], [0, 7, 35], [1, 8, 36], [2, 9, 37], [3, 10, 38], [4, 11, 39], [5, 12, 40], [6, 13, 41], [7, 14, 42]]) == [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(n = 15,edgeList = [[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], [0, 14, 15]],queries = [[0, 14, 10], [0, 14, 16], [2, 12, 8]]) == [False, True, False]\n assert candidate(n = 10,edgeList = [[0, 1, 1], [0, 2, 3], [1, 2, 2], [3, 4, 5], [4, 5, 4], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9]],queries = [[0, 9, 10], [2, 5, 5], [4, 7, 12], [1, 8, 15]]) == [False, False, True, False]\n assert candidate(n = 8,edgeList = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [1, 5, 5], [2, 6, 6], [2, 7, 7], [3, 4, 8], [3, 5, 9], [4, 6, 10], [5, 7, 11]],queries = [[0, 7, 12], [1, 6, 10], [2, 5, 9], [3, 4, 8], [0, 4, 7]]) == [True, True, True, True, True]\n assert candidate(n = 15,edgeList = [[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], [9, 10, 1000], [10, 11, 1100], [11, 12, 1200], [12, 13, 1300], [13, 14, 1400]],queries = [[0, 14, 1500], [5, 10, 800], [3, 7, 600]]) == [True, False, False]\n assert candidate(n = 15,edgeList = [[0, 1, 20], [1, 2, 30], [2, 3, 40], [3, 4, 50], [4, 5, 60], [5, 6, 70], [6, 7, 80], [7, 8, 90], [8, 9, 100], [9, 10, 110], [10, 11, 120], [11, 12, 130], [12, 13, 140], [13, 14, 150], [14, 0, 160]],queries = [[0, 14, 300], [3, 7, 200], [6, 10, 150]]) == [True, True, True]\n assert candidate(n = 15,edgeList = [[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]],queries = [[0, 7, 8], [1, 8, 9], [2, 9, 10], [3, 10, 11], [4, 11, 12], [5, 12, 13], [6, 13, 14]]) == [True, True, True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[0, 1, 3], [1, 2, 2], [2, 3, 1], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9], [0, 9, 10]],queries = [[0, 9, 9], [0, 9, 11], [1, 8, 15], [2, 7, 20]]) == [False, True, True, True]\n assert candidate(n = 20,edgeList = [[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, 0, 20]],queries = [[0, 10, 11], [1, 11, 12], [2, 12, 13], [3, 13, 14], [4, 14, 15], [5, 15, 16], [6, 16, 17], [7, 17, 18], [8, 18, 19], [9, 19, 20]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[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, 9, 2], [1, 8, 2], [2, 7, 2], [3, 6, 2], [4, 5, 2]],queries = [[0, 4, 2], [5, 9, 2], [3, 7, 2]]) == [True, True, True]\n assert candidate(n = 8,edgeList = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 3, 4], [1, 4, 5], [2, 5, 6], [3, 6, 7], [4, 7, 8], [5, 7, 9]],queries = [[0, 7, 15], [1, 6, 10], [2, 5, 7], [3, 4, 4]]) == [True, True, True, False]\n assert candidate(n = 7,edgeList = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]],queries = [[0, 6, 7], [0, 5, 6], [0, 4, 5], [0, 3, 4], [0, 2, 3], [0, 1, 2]]) == [True, True, True, True, True, True]\n assert candidate(n = 15,edgeList = [[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, 15], [1, 13, 25], [2, 12, 30], [3, 11, 35], [4, 10, 40]]) == [True, True, True, True, True]\n assert candidate(n = 8,edgeList = [[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, 3], [1, 3, 4], [2, 4, 5], [3, 5, 6], [4, 6, 7], [5, 7, 8]],queries = [[0, 7, 9], [1, 6, 10], [2, 5, 11]]) == [True, True, True]\n assert candidate(n = 12,edgeList = [[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]],queries = [[0, 6, 7], [1, 7, 8], [2, 8, 9], [3, 9, 10], [4, 10, 11], [5, 11, 12]]) == [True, True, True, True, True, True]\n assert candidate(n = 9,edgeList = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [0, 8, 9], [1, 7, 10], [2, 6, 11], [3, 5, 12]],queries = [[0, 8, 13], [1, 7, 11], [2, 6, 9], [3, 5, 7]]) == [True, True, True, True]\n assert candidate(n = 12,edgeList = [[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, 0, 120], [0, 6, 130], [1, 7, 140], [2, 8, 150], [3, 9, 160], [4, 10, 170], [5, 11, 180]],queries = [[0, 11, 125], [1, 10, 135], [2, 9, 145], [3, 8, 155], [4, 7, 165], [5, 6, 175], [0, 7, 185], [1, 8, 195], [2, 11, 205], [3, 0, 215]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 20,edgeList = [[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, 0, 200]],queries = [[0, 19, 210], [1, 18, 220], [2, 17, 230], [3, 16, 240], [4, 15, 250], [5, 14, 260], [6, 13, 270], [7, 12, 280], [8, 11, 290], [9, 10, 300]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,edgeList = [[0, 1, 3], [1, 2, 1], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 0, 2]],queries = [[0, 9, 15], [2, 5, 12], [1, 8, 6]]) == [True, True, False]\n assert candidate(n = 20,edgeList = [[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]],queries = [[0, 19, 200], [5, 15, 120], [3, 10, 80]]) == [True, False, False]\n assert candidate(n = 10,edgeList = [[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]],queries = [[0, 9, 11], [0, 9, 5], [0, 4, 10]]) == [True, False, True]\n assert candidate(n = 10,edgeList = [[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], [9, 0, 50], [0, 5, 55], [5, 1, 60], [1, 6, 65], [6, 2, 70], [2, 7, 75]],queries = [[0, 9, 60], [1, 8, 55], [2, 7, 50], [3, 6, 45], [4, 5, 40]]) == [True, True, True, True, True]\n assert candidate(n = 18,edgeList = [[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], [9, 10, 50], [10, 11, 55], [11, 12, 60], [12, 13, 65], [13, 14, 70], [14, 15, 75], [15, 16, 80], [16, 17, 85], [17, 0, 90], [0, 8, 95], [1, 9, 100], [2, 10, 105], [3, 11, 110], [4, 12, 115], [5, 13, 120], [6, 14, 125], [7, 15, 130], [8, 16, 135], [9, 17, 140], [10, 0, 145], [11, 1, 150], [12, 2, 155], [13, 3, 160], [14, 4, 165], [15, 5, 170], [16, 6, 175], [17, 7, 180]],queries = [[0, 17, 175], [1, 16, 180], [2, 15, 185], [3, 14, 190], [4, 13, 195], [5, 12, 200], [6, 11, 205], [7, 10, 210], [8, 9, 215], [0, 15, 220], [1, 14, 225], [2, 13, 230], [3, 12, 235], [4, 11, 240], [5, 10, 245], [6, 9, 250], [7, 8, 255], [0, 14, 260], [1, 13, 265], [2, 12, 270], [3, 11, 275], [4, 10, 280], [5, 9, 285], [6, 8, 290], [0, 13, 295], [1, 12, 300], [2, 11, 305], [3, 10, 310], [4, 9, 315], [5, 8, 320], [0, 12, 325], [1, 11, 330], [2, 10, 335], [3, 9, 340], [4, 8, 345], [0, 11, 350], [1, 10, 355], [2, 9, 360], [3, 8, 365], [0, 10, 370], [1, 9, 375], [2, 8, 380], [0, 9, 385], [1, 8, 390], [0, 8, 395]]) == [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, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 15,edgeList = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [2, 4, 40], [3, 5, 50], [4, 6, 60], [5, 7, 70], [6, 8, 80], [7, 9, 90], [8, 10, 100], [9, 11, 110], [10, 12, 120], [11, 13, 130], [12, 14, 140]],queries = [[0, 14, 150], [0, 14, 75], [0, 7, 85], [7, 14, 110]]) == [True, False, True, False]\n assert candidate(n = 6,edgeList = [[0, 1, 20], [1, 2, 30], [2, 3, 40], [3, 4, 50], [4, 5, 60], [5, 0, 70], [0, 2, 15], [2, 4, 25], [4, 1, 35], [1, 3, 45], [3, 5, 55], [5, 2, 65]],queries = [[0, 5, 50], [1, 4, 40], [2, 3, 30]]) == [False, True, False]\n", "comparison": "exact"}, "public_tests": ["3\n[[0,1,2],[1,2,4],[2,0,8],[1,0,16]]\n[[0,1,2],[0,2,5]]", "5\n[[0,1,10],[1,2,5],[2,3,9],[3,4,13]]\n[[0,4,14],[1,4,13]]"], "hints": ["All the queries are given in advance. Is there a way you can reorder the queries to avoid repeated computations?"], "metadata": {"canonical_parameter_names": ["n", "edgeList", "queries"], "leetcode_dataset_entry_point": "Solution().distanceLimitedPathsExist", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:50+00:00", "tests_total": 62, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "union-find", "graph", "sorting"]}, "language": "php", "interface": {"raw_signature": "function distanceLimitedPathsExist($n, $edgeList, $queries) {", "container": "Solution", "callable": "distanceLimitedPathsExist", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edgeList", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1700, "task_id": "number-of-students-unable-to-eat-lunch", "difficulty": "Easy", "problem_description": "The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.\n\nThe number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:\n\n- If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.\n- Otherwise, they will leave it and go to the queue's end.\n\nThis continues until none of the queue students want to take the top sandwich and are thus unable to eat.\n\nYou are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i^th sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j^th student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.\n\nExample 1:\n\nInput: students = [1,1,0,0], sandwiches = [0,1,0,1]\nOutput: 0\nExplanation:\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.\n\nExample 2:\n\nInput: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\nOutput: 3\n\nConstraints:\n\n- 1 <= students.length, sandwiches.length <= 100\n- students.length == sandwiches.length\n- sandwiches[i] is 0 or 1.\n- students[i] is 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(students = [0, 1, 0, 1],sandwiches = [1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 0, 0, 1],sandwiches = [1, 0, 0, 0, 1, 1]) == 3\n assert candidate(students = [0, 0, 1, 1],sandwiches = [1, 1, 0, 0]) == 0\n assert candidate(students = [1, 0, 1, 0],sandwiches = [0, 1, 0, 1]) == 0\n assert candidate(students = [0, 0, 0, 0],sandwiches = [0, 0, 0, 0]) == 0\n assert candidate(students = [0, 1, 0, 1],sandwiches = [0, 1, 0, 1]) == 0\n assert candidate(students = [1, 1, 0, 0],sandwiches = [0, 1, 0, 1]) == 0\n assert candidate(students = [1, 1, 1, 1],sandwiches = [1, 1, 1, 1]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 0, 0, 0, 0, 1, 1],sandwiches = [0, 0, 0, 1, 1, 1, 0, 1, 1]) == 0\n assert candidate(students = [1, 0, 0, 1, 1, 0, 0, 1],sandwiches = [1, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(students = [1, 0, 0, 1, 0, 1, 1, 0],sandwiches = [1, 1, 0, 0, 1, 1, 0, 0]) == 0\n assert candidate(students = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0],sandwiches = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(students = [0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 0, 1, 0, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 0, 1, 0],sandwiches = [0, 0, 1, 0, 1, 1, 0, 1]) == 0\n assert candidate(students = [0, 1, 1, 1, 0, 1, 0, 0, 1, 0],sandwiches = [0, 1, 0, 1, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(students = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0],sandwiches = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1],sandwiches = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 2\n assert candidate(students = [1, 0, 0, 1, 1, 0, 1, 0, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],sandwiches = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(students = [1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1],sandwiches = [1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1]) == 0\n assert candidate(students = [1, 1, 1, 0, 0, 0, 0, 1, 1],sandwiches = [1, 0, 0, 0, 1, 0, 0, 1, 0]) == 3\n assert candidate(students = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1],sandwiches = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 2\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [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(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],sandwiches = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 1, 0, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],sandwiches = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(students = [1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1],sandwiches = [0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],sandwiches = [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 assert candidate(students = [1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1],sandwiches = [1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],sandwiches = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == 3\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(students = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],sandwiches = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 0\n assert candidate(students = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sandwiches = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(students = [0, 0, 0, 1, 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],sandwiches = [1, 0, 1, 0, 1, 0, 1, 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(students = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 2\n assert candidate(students = [1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0],sandwiches = [0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 0, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 1, 0, 0, 1, 1, 0, 0, 0]) == 0\n assert candidate(students = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1],sandwiches = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0],sandwiches = [1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 0, 0, 1, 0, 0, 1, 1, 0, 1],sandwiches = [0, 1, 1, 0, 1, 1, 0, 1, 0, 0]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 0, 1, 1, 0, 0, 1, 1],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 0, 0, 1, 1, 0],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 1\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],sandwiches = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]) == 4\n assert candidate(students = [1, 1, 0, 0, 0, 0, 1, 1],sandwiches = [1, 1, 0, 0, 0, 0, 1, 1]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],sandwiches = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 0\n assert candidate(students = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],sandwiches = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 0, 1, 1, 0, 0],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 0, 0, 1, 1, 0, 0, 1],sandwiches = [1, 0, 1, 0, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1],sandwiches = [1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0]) == 1\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(students = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],sandwiches = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(students = [1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1],sandwiches = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0]) == 1\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1, 1]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 1, 0, 0, 1],sandwiches = [1, 1, 0, 0, 1, 1, 0, 0, 1]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],sandwiches = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 0, 1, 1, 0, 0, 0, 1],sandwiches = [0, 1, 1, 0, 0, 0, 1, 1]) == 0\n assert candidate(students = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],sandwiches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(students = [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1],sandwiches = [1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1]) == 0\n assert candidate(students = [1, 1, 0, 0, 1, 1, 0, 0],sandwiches = [0, 0, 1, 1, 0, 0, 1, 1]) == 0\n assert candidate(students = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],sandwiches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0],sandwiches = [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0]) == 0\n assert candidate(students = [0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0],sandwiches = [1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0]) == 0\n assert candidate(students = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sandwiches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 69\n assert candidate(students = [1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0],sandwiches = [0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1]) == 0\n assert candidate(students = [0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(students = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],sandwiches = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,1,0,0]\n[0,1,0,1]", "[1,1,1,0,0,1]\n[1,0,0,0,1,1]"], "hints": ["Simulate the given in the statement", "Calculate those who will eat instead of those who will not."], "metadata": {"canonical_parameter_names": ["students", "sandwiches"], "leetcode_dataset_entry_point": "Solution().countStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:55+00:00", "tests_total": 88, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "stack", "queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countStudents($students, $sandwiches) {", "container": "Solution", "callable": "countStudents", "parameters": [{"name": "students", "type": "Integer[]"}, {"name": "sandwiches", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1701, "task_id": "average-waiting-time", "difficulty": "Medium", "problem_description": "There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrival_i, time_i]:\n\n- arrival_i is the arrival time of the i^th customer. The arrival times are sorted in non-decreasing order.\n- time_i is the time needed to prepare the order of the i^th customer.\n\nWhen a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.\n\nReturn the average waiting time of all customers. Solutions within 10^-5 from the actual answer are considered accepted.\n\nExample 1:\n\nInput: customers = [[1,2],[2,5],[4,3]]\nOutput: 5.00000\nExplanation:\n1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.\n2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.\n3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.\nSo the average waiting time = (2 + 6 + 7) / 3 = 5.\n\nExample 2:\n\nInput: customers = [[5,2],[5,4],[10,3],[20,1]]\nOutput: 3.25000\nExplanation:\n1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.\n2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.\n3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.\n4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.\nSo the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.\n\nConstraints:\n\n- 1 <= customers.length <= 10^5\n- 1 <= arrival_i, time_i <= 10^4\n- arrival_i<= arrival_{i+1}\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(customers=[[5, 2], [5, 4], [10, 3], [20, 1]]), 3.25)\n assert answers_match(candidate(customers=[[1, 1], [1, 1], [1, 1], [1, 1]]), 2.5)\n assert answers_match(candidate(customers=[[1, 1], [1, 1], [1, 1]]), 2.0)\n assert answers_match(candidate(customers=[[1, 3], [2, 3], [6, 3], [10, 3]]), 3.75)\n assert answers_match(candidate(customers=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]), 5.0)\n assert answers_match(candidate(customers=[[1, 3], [2, 3], [6, 3]]), 4.0)\n assert answers_match(candidate(customers=[[1, 2], [2, 5], [4, 3]]), 5.0)\n assert answers_match(candidate(customers=[[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]]), 28.0)\n assert answers_match(candidate(customers=[[2, 3], [6, 3], [10, 3], [15, 3]]), 3.0)\n assert answers_match(candidate(customers=[[1, 5], [2, 2], [3, 3], [4, 4], [5, 5]]), 9.0)\n assert answers_match(candidate(customers=[[1, 10], [10, 10], [20, 10], [30, 10], [40, 10]]), 10.8)\n assert answers_match(candidate(customers=[[1, 3], [2, 2], [3, 1]]), 3.6666666666666665)\n assert answers_match(candidate(customers=[[10, 5], [15, 2], [20, 3], [30, 1]]), 2.75)\n assert answers_match(candidate(customers=[[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]), 5.5)\n assert answers_match(candidate(customers=[[1, 1000], [1010, 500], [1510, 250], [1760, 125], [1885, 62], [1947, 31], [1978, 15], [1993, 7], [1999, 3], [2001, 1]]), 199.7)\n assert answers_match(candidate(customers=[[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], [27, 1], [29, 1]]), 1.0)\n assert answers_match(candidate(customers=[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]), 35.0)\n assert answers_match(candidate(customers=[[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.0)\n assert answers_match(candidate(customers=[[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [110, 11], [120, 12], [130, 13], [140, 14], [150, 15]]), 9.333333333333334)\n assert answers_match(candidate(customers=[[1, 100], [101, 50], [151, 200], [251, 100], [351, 300], [451, 150], [601, 50], [651, 100], [751, 250], [851, 50]]), 320.0)\n assert answers_match(candidate(customers=[[1, 5], [2, 3], [3, 4], [10, 2], [15, 5], [20, 1], [25, 3], [30, 4], [35, 2], [40, 5]]), 4.7)\n assert answers_match(candidate(customers=[[1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 2], [4, 3], [4, 4], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]), 13.692307692307692)\n assert answers_match(candidate(customers=[[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]), 14.0)\n assert answers_match(candidate(customers=[[1, 5], [2, 3], [3, 4], [4, 2], [5, 6], [6, 1]]), 10.833333333333334)\n assert answers_match(candidate(customers=[[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], [16, 2], [17, 2], [18, 2], [19, 2], [20, 2]]), 11.5)\n assert answers_match(candidate(customers=[[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], [16, 10], [17, 10], [18, 10], [19, 10], [20, 10], [21, 10], [22, 10], [23, 10], [24, 10], [25, 10], [26, 10], [27, 10], [28, 10], [29, 10], [30, 10]]), 140.5)\n assert answers_match(candidate(customers=[[1, 1000], [2000, 1000], [3000, 1000], [4000, 1000], [5000, 1000], [6000, 1000]]), 1000.0)\n assert answers_match(candidate(customers=[[1, 2], [2, 3], [3, 2], [4, 3], [5, 2], [6, 3], [7, 2], [8, 3], [9, 2], [10, 3], [11, 2], [12, 3], [13, 2], [14, 3], [15, 2], [16, 3], [17, 2], [18, 3], [19, 2], [20, 3]]), 16.5)\n assert answers_match(candidate(customers=[[1, 3], [2, 4], [5, 2], [6, 1], [8, 6], [10, 3], [11, 2]]), 7.0)\n assert answers_match(candidate(customers=[[1, 3], [2, 2], [4, 3], [5, 4], [6, 2], [8, 1], [10, 5]]), 6.857142857142857)\n assert answers_match(candidate(customers=[[10, 30], [20, 20], [30, 10], [40, 5], [50, 2], [60, 1], [70, 3], [80, 4], [90, 2], [100, 5], [110, 1], [120, 3], [130, 4], [140, 2], [150, 5]]), 15.2)\n assert answers_match(candidate(customers=[[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]]), 150.83333333333334)\n assert answers_match(candidate(customers=[[100, 50], [150, 20], [200, 30], [250, 10], [300, 40], [350, 5], [400, 15]]), 24.285714285714285)\n assert answers_match(candidate(customers=[[1, 1], [3, 3], [3, 3], [3, 3], [5, 5], [5, 5], [7, 7], [7, 7], [9, 9], [9, 9]]), 18.0)\n assert answers_match(candidate(customers=[[5, 3], [6, 4], [8, 2], [9, 5], [12, 3], [15, 1], [18, 2], [20, 4], [25, 3], [30, 1]]), 6.9)\n assert answers_match(candidate(customers=[[100, 100], [200, 50], [300, 25], [400, 12], [500, 6]]), 38.6)\n assert answers_match(candidate(customers=[[10, 10], [10, 20], [10, 30], [10, 40], [10, 50], [10, 60], [10, 70], [10, 80], [10, 90], [10, 100]]), 220.0)\n assert answers_match(candidate(customers=[[1, 100], [101, 50], [151, 25], [201, 10], [251, 5], [301, 1]]), 31.833333333333332)\n assert answers_match(candidate(customers=[[1, 1], [1, 1], [1, 1], [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.0)\n assert answers_match(candidate(customers=[[5, 10], [10, 10], [15, 10], [20, 10], [25, 10], [30, 10], [35, 10], [40, 10], [45, 10], [50, 10]]), 32.5)\n assert answers_match(candidate(customers=[[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]]), 77.0)\n assert answers_match(candidate(customers=[[1, 1], [2, 1], [2, 1], [3, 1], [3, 1], [4, 1], [4, 1], [5, 1], [5, 1]]), 2.7777777777777777)\n assert answers_match(candidate(customers=[[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]]), 34.0)\n assert answers_match(candidate(customers=[[1, 20], [1, 15], [2, 10], [2, 5], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]), 45.0)\n assert answers_match(candidate(customers=[[1, 1], [100, 100], [200, 100], [300, 100], [400, 100], [500, 100], [600, 100], [700, 100], [800, 100], [900, 100]]), 90.1)\n assert answers_match(candidate(customers=[[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]]), 6.5)\n assert answers_match(candidate(customers=[[1, 1000], [2, 1000], [3, 1000], [4, 1000], [5, 1000], [6, 1000], [7, 1000], [8, 1000], [9, 1000], [10, 1000]]), 5495.5)\n assert answers_match(candidate(customers=[[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]), 529.0)\n assert answers_match(candidate(customers=[[1, 5], [3, 7], [5, 2], [10, 1], [12, 3], [15, 2], [18, 5]]), 7.428571428571429)\n assert answers_match(candidate(customers=[[5, 10], [15, 15], [25, 20], [35, 25], [45, 30], [55, 35], [65, 40], [75, 45], [85, 50]]), 76.66666666666667)\n assert answers_match(candidate(customers=[[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]]), 1.0)\n assert answers_match(candidate(customers=[[1, 100], [1, 90], [1, 80], [1, 70], [1, 60], [1, 50], [1, 40], [1, 30], [1, 20], [1, 10]]), 385.0)\n assert answers_match(candidate(customers=[[5, 3], [5, 2], [5, 4], [5, 1], [5, 5]]), 8.4)\n assert answers_match(candidate(customers=[[2, 5], [2, 5], [2, 5], [2, 5], [2, 5], [2, 5], [2, 5], [2, 5], [2, 5], [2, 5]]), 27.5)\n assert answers_match(candidate(customers=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]), 17.5)\n assert answers_match(candidate(customers=[[1, 100], [20, 50], [40, 30], [60, 20], [80, 10], [100, 5], [120, 3], [140, 2], [160, 1]]), 111.33333333333333)\n assert answers_match(candidate(customers=[[1, 10], [5, 10], [10, 10], [15, 10], [20, 10], [25, 10], [30, 10], [35, 10], [40, 10], [45, 10], [50, 10], [55, 10], [60, 10], [65, 10], [70, 10], [75, 10], [80, 10], [85, 10], [90, 10], [95, 10]]), 58.45)\n assert answers_match(candidate(customers=[[1, 5], [6, 10], [12, 15], [18, 20], [24, 25], [30, 30], [36, 35], [42, 40], [48, 45], [54, 50]]), 83.9)\n assert answers_match(candidate(customers=[[1, 1], [2, 2], [3, 2], [4, 1], [5, 2], [6, 3], [7, 1], [8, 2], [9, 3], [10, 1], [11, 2], [12, 3], [13, 1], [14, 2], [15, 3]]), 7.466666666666667)\n assert answers_match(candidate(customers=[[1, 100], [101, 100], [201, 100], [301, 100], [401, 100], [501, 100], [601, 100], [701, 100], [801, 100], [901, 100]]), 100.0)\n assert answers_match(candidate(customers=[[100, 50], [200, 25], [300, 12], [400, 6], [500, 3], [600, 1], [700, 2], [800, 4], [900, 1]]), 11.555555555555555)\n assert answers_match(candidate(customers=[[1, 1000], [1001, 1000], [2001, 1000], [3001, 1000], [4001, 1000], [5001, 1000]]), 1000.0)\n assert answers_match(candidate(customers=[[1, 1], [3, 2], [6, 3], [10, 4], [15, 5], [21, 6], [28, 7], [36, 8], [45, 9], [55, 10]]), 5.5)\n assert answers_match(candidate(customers=[[1, 10], [10, 10], [20, 10], [30, 10], [40, 10], [50, 10]]), 10.833333333333334)\n assert answers_match(candidate(customers=[[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]), 21.0)\n assert answers_match(candidate(customers=[[1, 5], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5]]), 8.333333333333334)\n assert answers_match(candidate(customers=[[1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000], [1, 10000]]), 55000.0)\n assert answers_match(candidate(customers=[[1, 1], [2, 2], [4, 4], [8, 8], [16, 16], [32, 32], [64, 64], [128, 128], [256, 256], [512, 512]]), 102.3)\n assert answers_match(candidate(customers=[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]), 22.0)\n assert answers_match(candidate(customers=[[100, 200], [200, 300], [300, 400], [400, 500], [500, 600]]), 800.0)\n assert answers_match(candidate(customers=[[1, 100], [101, 50], [151, 20], [201, 10], [251, 5], [301, 1], [351, 2], [401, 3], [451, 4]]), 21.666666666666668)\n assert answers_match(candidate(customers=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]), 215.5)\n assert answers_match(candidate(customers=[[1, 1000], [1001, 1000], [2001, 1000], [3001, 1000], [4001, 1000]]), 1000.0)\n assert answers_match(candidate(customers=[[1, 5000], [100, 2000], [2000, 3000], [3000, 1000], [4000, 4000], [5000, 5000], [6000, 6000], [7000, 7000], [8000, 8000], [9000, 9000], [10000, 10000]]), 20355.454545454544)\n assert answers_match(candidate(customers=[[1, 2], [3, 3], [6, 2], [8, 1], [10, 3], [15, 4]]), 2.5)\n assert answers_match(candidate(customers=[[1, 1], [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], [16, 2], [17, 2], [18, 2], [19, 2], [20, 2]]), 10.5)\n assert answers_match(candidate(customers=[[1, 1000], [1001, 500], [1501, 250], [2001, 125], [2501, 62], [3001, 31], [3501, 15], [4001, 7], [4501, 3], [5001, 1]]), 199.4)\n assert answers_match(candidate(customers=[[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]]), 50.0)\n assert answers_match(candidate(customers=[[1000, 1], [2000, 1], [3000, 1], [4000, 1], [5000, 1], [6000, 1], [7000, 1], [8000, 1], [9000, 1], [10000, 1]]), 1.0)\n assert answers_match(candidate(customers=[[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]), 31.0)\n assert answers_match(candidate(customers=[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22]]), 42.0)\n assert answers_match(candidate(customers=[[1, 10], [11, 10], [21, 10], [31, 10], [41, 10], [51, 10], [61, 10], [71, 10], [81, 10], [91, 10]]), 10.0)\n assert answers_match(candidate(customers=[[1000, 100], [2000, 200], [3000, 300], [4000, 400], [5000, 500], [6000, 600], [7000, 700], [8000, 800], [9000, 900], [10000, 1000]]), 550.0)\n assert answers_match(candidate(customers=[[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]]), 40.5)\n assert answers_match(candidate(customers=[[1, 1], [2, 100], [3, 200], [4, 300], [5, 400], [6, 500], [7, 600], [8, 700], [9, 800], [10, 900]]), 1646.5)\n assert answers_match(candidate(customers=[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22], [23, 24], [25, 26], [27, 28], [29, 30]]), 76.66666666666667)\n assert answers_match(candidate(customers=[[100, 100], [200, 100], [300, 100], [400, 100], [500, 100], [600, 100], [700, 100], [800, 100], [900, 100], [1000, 100]]), 100.0)\n assert answers_match(candidate(customers=[[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]]), 38.333333333333336)\n assert answers_match(candidate(customers=[[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]]), 27.5)\n", "comparison": "float"}, "public_tests": ["[[1,2],[2,5],[4,3]]", "[[5,2],[5,4],[10,3],[20,1]]"], "hints": ["Iterate on the customers, maintaining the time the chef will finish the previous orders.", "If that time is before the current arrival time, the chef starts immediately. Else, the current customer waits till the chef finishes, and then the chef starts.", "Update the running time by the time when the chef starts preparing + preparation time."], "metadata": {"canonical_parameter_names": ["customers"], "leetcode_dataset_entry_point": "Solution().averageWaitingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:57+00:00", "tests_total": 92, "tests_dropped": 3, "flags": ["decimal_answer"], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function averageWaitingTime($customers) {", "container": "Solution", "callable": "averageWaitingTime", "parameters": [{"name": "customers", "type": "Integer[][]"}], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1702, "task_id": "maximum-binary-string-after-change", "difficulty": "Medium", "problem_description": "You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:\n\n- Operation 1: If the number contains the substring \"00\", you can replace it with \"10\".\n - For example, \"00010\" -> \"10010\"\n- Operation 2: If the number contains the substring \"10\", you can replace it with \"01\".\n - For example, \"00010\" -> \"00001\"\n\nReturn the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.\n\nExample 1:\n\nInput: binary = \"000110\"\nOutput: \"111011\"\nExplanation: A valid transformation sequence can be:\n\"000110\" -> \"000101\"\n\"000101\" -> \"100101\"\n\"100101\" -> \"110101\"\n\"110101\" -> \"110011\"\n\"110011\" -> \"111011\"\n\nExample 2:\n\nInput: binary = \"01\"\nOutput: \"01\"\nExplanation: \"01\" cannot be transformed any further.\n\nConstraints:\n\n- 1 <= binary.length <= 10^5\n- binary consist of '0' and '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(binary = \"01010101010\") == \"11111011111\"\n assert candidate(binary = \"01\") == \"01\"\n assert candidate(binary = \"000001\") == \"111101\"\n assert candidate(binary = \"1111\") == \"1111\"\n assert candidate(binary = \"10101010101010101010\") == \"11111111110111111111\"\n assert candidate(binary = \"000000000\") == \"111111110\"\n assert candidate(binary = \"010101\") == \"110111\"\n assert candidate(binary = \"111000011\") == \"111111011\"\n assert candidate(binary = \"00110011\") == \"11101111\"\n assert candidate(binary = \"00000\") == \"11110\"\n assert candidate(binary = \"000000\") == \"111110\"\n assert candidate(binary = \"1100101\") == \"1111011\"\n assert candidate(binary = \"001001\") == \"111011\"\n assert candidate(binary = \"101010\") == \"111011\"\n assert candidate(binary = \"0000\") == \"1110\"\n assert candidate(binary = \"0101010101\") == \"1111011111\"\n assert candidate(binary = \"000111000\") == \"111110111\"\n assert candidate(binary = \"10101010\") == \"11110111\"\n assert candidate(binary = \"1100110011\") == \"1111101111\"\n assert candidate(binary = \"0101010\") == \"1110111\"\n assert candidate(binary = \"111000\") == \"111110\"\n assert candidate(binary = \"0001010101\") == \"1111101111\"\n assert candidate(binary = \"000001111\") == \"111101111\"\n assert candidate(binary = \"111111\") == \"111111\"\n assert candidate(binary = \"00001111\") == \"11101111\"\n assert candidate(binary = \"11001000101\") == \"11111110111\"\n assert candidate(binary = \"0010101\") == \"1110111\"\n assert candidate(binary = \"11001100\") == \"11111011\"\n assert candidate(binary = \"11110000\") == \"11111110\"\n assert candidate(binary = \"011110\") == \"101111\"\n assert candidate(binary = \"110010\") == \"111101\"\n assert candidate(binary = \"000110\") == \"111011\"\n assert candidate(binary = \"100100100\") == \"111111011\"\n assert candidate(binary = \"1000000\") == \"1111110\"\n assert candidate(binary = \"11111\") == \"11111\"\n assert candidate(binary = \"100000000001\") == \"111111111101\"\n assert candidate(binary = \"10101001010100101\") == \"11111111101111111\"\n assert candidate(binary = \"00000000000000000000111111111111\") == \"11111111111111111110111111111111\"\n assert candidate(binary = \"01111111111111111111111111111111\") == \"01111111111111111111111111111111\"\n assert candidate(binary = \"00000000000000000\") == \"11111111111111110\"\n assert candidate(binary = \"01001001001001001\") == \"11111111110111111\"\n assert candidate(binary = \"0000000000\") == \"1111111110\"\n assert candidate(binary = \"0000111100001111\") == \"1111111011111111\"\n assert candidate(binary = \"000001111000001111000001111000001111000001111\") == \"111111111111111111111111011111111111111111111\"\n assert candidate(binary = \"001001001001001001001001001001001001001001001001001001\") == \"111111111111111111111111111111111110111111111111111111\"\n assert candidate(binary = \"000000000000\") == \"111111111110\"\n assert candidate(binary = \"11111011111011111011111011111011111011111011111\") == \"11111111111011111111111111111111111111111111111\"\n assert candidate(binary = \"10010010010010010\") == \"11111111111011111\"\n assert candidate(binary = \"111001001001001000\") == \"111111111111101111\"\n assert candidate(binary = \"00000011100000\") == \"11111111110111\"\n assert candidate(binary = \"111111111111111111111111111111111111111111111111111111111111111111111111\") == \"111111111111111111111111111111111111111111111111111111111111111111111111\"\n assert candidate(binary = \"00011001100110011\") == \"11111111011111111\"\n assert candidate(binary = \"010101010101010101010\") == \"111111111101111111111\"\n assert candidate(binary = \"00010101010100\") == \"11111111011111\"\n assert candidate(binary = \"000000000000000000000000000000000000000000000000000000000000000000000000\") == \"111111111111111111111111111111111111111111111111111111111111111111111110\"\n assert candidate(binary = \"000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111\") == \"111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111\"\n assert candidate(binary = \"1010101010101010101010101010101010101010101010101010101010101010\") == \"1111111111111111111111111111111101111111111111111111111111111111\"\n assert candidate(binary = \"11111100000000111\") == \"11111111111110111\"\n assert candidate(binary = \"01010101010101010101\") == \"11111111101111111111\"\n assert candidate(binary = \"10101010101010101010101010101010\") == \"11111111111111110111111111111111\"\n assert candidate(binary = \"0000111111110000\") == \"1111111011111111\"\n assert candidate(binary = \"00000000000011111111111111111111\") == \"11111111111011111111111111111111\"\n assert candidate(binary = \"001010101010\") == \"111111011111\"\n assert candidate(binary = \"1111111111111111\") == \"1111111111111111\"\n assert candidate(binary = \"1010101010\") == \"1111101111\"\n assert candidate(binary = \"0101010101010101\") == \"1111111011111111\"\n assert candidate(binary = \"00001111000011110000111100001111\") == \"11111111111111101111111111111111\"\n assert candidate(binary = \"0000000000000000000000000001\") == \"1111111111111111111111111101\"\n assert candidate(binary = \"11111111111111111111\") == \"11111111111111111111\"\n assert candidate(binary = \"000011110000\") == \"111111101111\"\n assert candidate(binary = \"000010101010101010101010101010101010101010101010\") == \"111111111111111111111111101111111111111111111111\"\n assert candidate(binary = \"11011011011011011\") == \"11111101111111111\"\n assert candidate(binary = \"00000010000000100000001000000010000000100000001\") == \"11111111111111111111111111111111111111110111111\"\n assert candidate(binary = \"11111100000000000000000000000000\") == \"11111111111111111111111111111110\"\n assert candidate(binary = \"11000000000000000000\") == \"11111111111111111110\"\n assert candidate(binary = \"1010101010101010\") == \"1111111101111111\"\n assert candidate(binary = \"110011001100\") == \"111111101111\"\n assert candidate(binary = \"00001111000011110000\") == \"11111111111011111111\"\n assert candidate(binary = \"00011110101010101010101010101010101010101010101\") == \"11111111111111111111110111111111111111111111111\"\n assert candidate(binary = \"11100001010101010100001111100001111000011110000\") == \"11111111111111111111111111101111111111111111111\"\n assert candidate(binary = \"001100110011\") == \"111110111111\"\n assert candidate(binary = \"01001001001001001001\") == \"11111111111101111111\"\n assert candidate(binary = \"0000001111110000001111\") == \"1111111111101111111111\"\n assert candidate(binary = \"111111111110\") == \"111111111110\"\n assert candidate(binary = \"00000000000001111\") == \"11111111111101111\"\n assert candidate(binary = \"101010100000\") == \"111111110111\"\n assert candidate(binary = \"11111111111111111\") == \"11111111111111111\"\n assert candidate(binary = \"00000000000000000000000000000000000000000000\") == \"11111111111111111111111111111111111111111110\"\n assert candidate(binary = \"00001010101010100\") == \"11111111110111111\"\n assert candidate(binary = \"01010101010101010\") == \"11111111011111111\"\n assert candidate(binary = \"10101010101010101\") == \"11111111011111111\"\n assert candidate(binary = \"0101010101010101010101010101010101010101010101010101\") == \"1111111111111111111111111011111111111111111111111111\"\n assert candidate(binary = \"00000000000000000000000000000001\") == \"11111111111111111111111111111101\"\n assert candidate(binary = \"010101010101010101010101010101010101010101010101\") == \"111111111111111111111110111111111111111111111111\"\n assert candidate(binary = \"1100000000000011\") == \"1111111111111011\"\n assert candidate(binary = \"11111111111111111111111111111111111111111111\") == \"11111111111111111111111111111111111111111111\"\n assert candidate(binary = \"00000000010000000000000000000000\") == \"11111111111111111111111111111101\"\n assert candidate(binary = \"11001100110011001\") == \"11111111101111111\"\n assert candidate(binary = \"101010101010101010101\") == \"111111111101111111111\"\n assert candidate(binary = \"111100001111\") == \"111111101111\"\n assert candidate(binary = \"00000000000000000000000000000000000000000000000000000000\") == \"11111111111111111111111111111111111111111111111111111110\"\n assert candidate(binary = \"1100110011001100\") == \"1111111110111111\"\n assert candidate(binary = \"111111111111\") == \"111111111111\"\n assert candidate(binary = \"0001100010001000\") == \"1111111111101111\"\n assert candidate(binary = \"0000000000000111111\") == \"1111111111110111111\"\n assert candidate(binary = \"1110000110001100\") == \"1111111111101111\"\n assert candidate(binary = \"111111111\") == \"111111111\"\n assert candidate(binary = \"0000000000000000000000000000000000000000000000000000000000000000000000000000\") == \"1111111111111111111111111111111111111111111111111111111111111111111111111110\"\n assert candidate(binary = \"11111111111111111111111111111111111111111111111111111111\") == \"11111111111111111111111111111111111111111111111111111111\"\n assert candidate(binary = \"1001001001001\") == \"1111111101111\"\n assert candidate(binary = \"000000000000000000000000000000000000000000000000\") == \"111111111111111111111111111111111111111111111110\"\n assert candidate(binary = \"010101010101\") == \"111110111111\"\n assert candidate(binary = \"00100100100100100100100100100100\") == \"11111111111111111111101111111111\"\n assert candidate(binary = \"11110000000000000\") == \"11111111111111110\"\n assert candidate(binary = \"11110000111100001111000011110000111100001111\") == \"11111111111111111111111011111111111111111111\"\n assert candidate(binary = \"0011001100110011\") == \"1111111011111111\"\n assert candidate(binary = \"11000000110000001100000011000000\") == \"11111111111111111111111110111111\"\n assert candidate(binary = \"01010101010101010101010101010101\") == \"11111111111111101111111111111111\"\n assert candidate(binary = \"111111111111111111111111111111111111111111111111\") == \"111111111111111111111111111111111111111111111111\"\n assert candidate(binary = \"00000000000000000000\") == \"11111111111111111110\"\n assert candidate(binary = \"110101010101\") == \"111111011111\"\n assert candidate(binary = \"01001010100101001\") == \"11111111101111111\"\n assert candidate(binary = \"1010101010101010101010101010101010101010101010101010\") == \"1111111111111111111111111101111111111111111111111111\"\n assert candidate(binary = \"0110110110110\") == \"1111011111111\"\n assert candidate(binary = \"00000000000000000000000000000000000000000000000000000000000000000000000\") == \"11111111111111111111111111111111111111111111111111111111111111111111110\"\n assert candidate(binary = \"11111111111111111111111111111110\") == \"11111111111111111111111111111110\"\n assert candidate(binary = \"0000000000000000\") == \"1111111111111110\"\n assert candidate(binary = \"1100101010100001\") == \"1111111111011111\"\n assert candidate(binary = \"01101101101101101\") == \"11111011111111111\"\n assert candidate(binary = \"11111111111111111111000000000000\") == \"11111111111111111111111111111110\"\n assert candidate(binary = \"11111111111111110\") == \"11111111111111110\"\n assert candidate(binary = \"000100010001\") == \"111111110111\"\n assert candidate(binary = \"1111111111\") == \"1111111111\"\n", "comparison": "exact"}, "public_tests": ["\"000110\"", "\"01\""], "hints": ["Note that with the operations, you can always make the string only contain at most 1 zero."], "metadata": {"canonical_parameter_names": ["binary"], "leetcode_dataset_entry_point": "Solution().maximumBinaryString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:27:59+00:00", "tests_total": 133, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumBinaryString($binary) {", "container": "Solution", "callable": "maximumBinaryString", "parameters": [{"name": "binary", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1703, "task_id": "minimum-adjacent-swaps-for-k-consecutive-ones", "difficulty": "Hard", "problem_description": "You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.\n\nReturn the minimum number of moves required so that nums has k consecutive 1's.\n\nExample 1:\n\nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: 1\nExplanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.\n\nExample 2:\n\nInput: nums = [1,0,0,0,0,0,1,1], k = 3\nOutput: 5\nExplanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].\n\nExample 3:\n\nInput: nums = [1,1,0,1], k = 2\nOutput: 0\nExplanation: nums already has 2 consecutive 1's.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- nums[i] is 0 or 1.\n- 1 <= k <= sum(nums)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 1, 0, 0, 1, 1, 1],k = 4) == 2\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 3) == 6\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 1],k = 3) == 5\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1],k = 4) == 4\n assert candidate(nums = [1, 1, 1, 1, 1],k = 3) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 6\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 2\n assert candidate(nums = [0, 0, 1, 0, 1, 1, 0, 0, 1],k = 3) == 1\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1],k = 5) == 6\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1],k = 3) == 2\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 3) == 2\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 4) == 4\n assert candidate(nums = [1, 1, 0, 1],k = 2) == 0\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 0, 1],k = 4) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1],k = 4) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0],k = 2) == 1\n assert candidate(nums = [1, 0, 0, 1, 0, 1],k = 2) == 1\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, 0, 0],k = 6) == 18\n assert candidate(nums = [1, 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 = 7) == 33\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1],k = 4) == 6\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1],k = 3) == 12\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],k = 9) == 54\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0],k = 7) == 16\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1],k = 4) == 6\n assert candidate(nums = [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],k = 4) == 28\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, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 10) == 75\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, 1, 1, 1, 1, 1, 1],k = 3) == 0\n assert candidate(nums = [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, 1],k = 3) == 10\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],k = 3) == 6\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],k = 5) == 24\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, 0, 0, 0, 1, 1, 1],k = 6) == 9\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0],k = 5) == 5\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1],k = 6) == 14\n assert candidate(nums = [1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1],k = 6) == 13\n assert candidate(nums = [1, 0, 0, 1, 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, 0, 1],k = 4) == 6\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 5) == 12\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 6) == 9\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 5) == 12\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1],k = 6) == 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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 8) == 16\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0],k = 5) == 15\n assert candidate(nums = [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],k = 7) == 12\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],k = 12) == 36\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 6\n assert candidate(nums = [1, 0, 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 = 8) == 32\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],k = 4) == 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],k = 10) == 25\n assert candidate(nums = [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],k = 4) == 4\n assert candidate(nums = [1, 0, 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) == 18\n assert candidate(nums = [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],k = 4) == 20\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],k = 5) == 24\n assert candidate(nums = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 5\n assert candidate(nums = [0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0],k = 5) == 12\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],k = 6) == 9\n assert candidate(nums = [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0],k = 4) == 5\n assert candidate(nums = [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, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 2) == 9\n assert candidate(nums = [1, 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],k = 4) == 20\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 = 6) == 9\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],k = 4) == 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],k = 6) == 9\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],k = 5) == 12\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1],k = 6) == 15\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],k = 6) == 24\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],k = 7) == 24\n assert candidate(nums = [0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 3) == 4\n assert candidate(nums = [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],k = 7) == 12\n assert candidate(nums = [1, 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],k = 10) == 25\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],k = 7) == 24\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],k = 7) == 24\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],k = 6) == 9\n assert candidate(nums = [1, 1, 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, 1, 1],k = 5) == 36\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1],k = 4) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 3) == 51\n assert candidate(nums = [1, 0, 0, 0, 1, 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, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1],k = 9) == 40\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],k = 5) == 12\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],k = 6) == 27\n assert candidate(nums = [0, 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 = 7) == 36\n assert candidate(nums = [1, 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, 1, 0, 0, 0, 1, 0, 0, 0, 1],k = 8) == 46\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],k = 15) == 56\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0],k = 5) == 15\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],k = 5) == 27\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1],k = 5) == 8\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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 10) == 0\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, 1],k = 2) == 14\n assert candidate(nums = [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],k = 11) == 30\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],k = 7) == 24\n assert candidate(nums = [1, 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],k = 6) == 26\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],k = 8) == 16\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 5) == 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, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 9) == 20\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],k = 10) == 25\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],k = 10) == 50\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],k = 4) == 8\n assert candidate(nums = [1, 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) == 15\n assert candidate(nums = [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],k = 8) == 15\n assert candidate(nums = [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, 1, 0, 0, 0],k = 3) == 10\n", "comparison": "exact"}, "public_tests": ["[1,0,0,1,0,1]\n2", "[1,0,0,0,0,0,1,1]\n3", "[1,1,0,1]\n2"], "hints": ["Choose k 1s and determine how many steps are required to move them into 1 group.", "Maintain a sliding window of k 1s, and maintain the steps required to group them.", "When you slide the window across, should you move the group to the right? Once you move the group to the right, it will never need to slide to the left again."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:02+00:00", "tests_total": 99, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minMoves($nums, $k) {", "container": "Solution", "callable": "minMoves", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1704, "task_id": "determine-if-string-halves-are-alike", "difficulty": "Easy", "problem_description": "You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.\n\nTwo strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.\n\nReturn true if a and b are alike. Otherwise, return false.\n\nExample 1:\n\nInput: s = \"book\"\nOutput: true\nExplanation: a = \"bo\" and b = \"ok\". a has 1 vowel and b has 1 vowel. Therefore, they are alike.\n\nExample 2:\n\nInput: s = \"textbook\"\nOutput: false\nExplanation: a = \"text\" and b = \"book\". a has 1 vowel whereas b has 2. Therefore, they are not alike.\nNotice that the vowel o is counted twice.\n\nConstraints:\n\n- 2 <= s.length <= 1000\n- s.length is even.\n- s consists of uppercase and lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aAeEiIoOuU\") == True\n assert candidate(s = \"Leetcode\") == True\n assert candidate(s = \"AbCdEfGh\") == True\n assert candidate(s = \"textbook\") == False\n assert candidate(s = \"cOdInGQuEsTiOn\") == False\n assert candidate(s = \"AaEeIiOoUu\") == True\n assert candidate(s = \"leetcode\") == True\n assert candidate(s = \"abcdefgH\") == True\n assert candidate(s = \"Margelet\") == False\n assert candidate(s = \"book\") == True\n assert candidate(s = \"MerryChristmas\") == False\n assert candidate(s = \"ArtificialIntelligence\") == False\n assert candidate(s = \"aAbBcCdDeEfFgG\") == True\n assert candidate(s = \"Supercalifragilisticexpialidocious\") == False\n assert candidate(s = \"InDiCoRn\") == False\n assert candidate(s = \"vowelvowelvowelvowelvowelvowel\") == True\n assert candidate(s = \"VowelCOnsonAnt\") == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == True\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\") == False\n assert candidate(s = \"bBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == True\n assert candidate(s = \"EqUiVaLeNt\") == False\n assert candidate(s = \"unevenNumberOfVowels\") == True\n assert candidate(s = \"QuantumComputing\") == True\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == False\n assert candidate(s = \"Internationalization\") == True\n assert candidate(s = \"AbcDeFgHiJkLmNoPqRsTuVwXyZ\") == False\n assert candidate(s = \"Electroencephalographies\") == True\n assert candidate(s = \"fAcEtImE\") == True\n assert candidate(s = \"AnALoGuIzAtIoN\") == True\n assert candidate(s = \"sImPlEVoWaElStRiNg\") == True\n assert candidate(s = \"VoWaElCoUnTiNg\") == True\n assert candidate(s = \"SiMpLy\") == False\n assert candidate(s = \"Electroencephalography\") == False\n assert candidate(s = \"abcdefghijABCDEFGHIJ\") == True\n assert candidate(s = \"METHINKSITISLIKEALITTLEIODEUCALYPTUS\") == False\n assert candidate(s = \"HumanComputerInteraction\") == True\n assert candidate(s = \"AmOrAnGe\") == True\n assert candidate(s = \"balancedString\") == False\n assert candidate(s = \"EuPoCrAtIc\") == False\n assert candidate(s = \"RoMaNiCa\") == True\n assert candidate(s = \"aAaAaAaAaAbBbBbBbB\") == False\n assert candidate(s = \"MaRiNo\") == False\n assert candidate(s = \"CloudComputing\") == False\n assert candidate(s = \"DataScienceAndML\") == False\n assert candidate(s = \"Hippopotomonstrosesquippedaliophobia\") == False\n assert candidate(s = \"Pseudopseudohypoparathyroidism\") == True\n assert candidate(s = \"DatabaseManagement\") == True\n assert candidate(s = \"ComplexExample\") == False\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == False\n assert candidate(s = \"AEIOUaeiouAEIOUaeiou\") == True\n assert candidate(s = \"SyMmEtrY\") == False\n assert candidate(s = \"PaLInDrOmE\") == True\n assert candidate(s = \"Floccinaucinihilipilifications\") == True\n assert candidate(s = \"AlphabetSymmetry\") == False\n assert candidate(s = \"VowelsInBoth\") == True\n assert candidate(s = \"FLUtTuAtIoNs\") == False\n assert candidate(s = \"MaLiNoUs\") == True\n assert candidate(s = \"InternetOfThings\") == False\n assert candidate(s = \"PeRuKkIa\") == True\n assert candidate(s = \"TrAnSaPoRt\") == False\n assert candidate(s = \"OddAndEven\") == True\n assert candidate(s = \"aEiOuUoIeA\") == True\n assert candidate(s = \"Alphabetical\") == False\n assert candidate(s = \"VowelsAEIOUaeiou\") == False\n assert candidate(s = \"aEiOuUeIoA\") == True\n assert candidate(s = \"SeNtEnCe\") == False\n assert candidate(s = \"RepetitionRepetition\") == True\n assert candidate(s = \"MississippiRiver\") == True\n assert candidate(s = \"vowelvowelvowelvowel\") == True\n assert candidate(s = \"MississippiRiverside\") == False\n assert candidate(s = \"aeiouAEIOUaeiouAEIOU\") == True\n assert candidate(s = \"PythonCoding\") == False\n assert candidate(s = \"aEiOuUaEiO\") == True\n assert candidate(s = \"ProgrammingIsFun\") == False\n assert candidate(s = \"aEiOuAeIoU\") == True\n assert candidate(s = \"Alphabetically\") == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(s = \"DataAnalysis\") == False\n assert candidate(s = \"VoCaBuLaRy\") == True\n assert candidate(s = \"AEIOUaeiou\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(s = \"CaThODoRiC\") == True\n assert candidate(s = \"Antidisestablishmentarianism\") == False\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == False\n assert candidate(s = \"BaLaNcEd\") == False\n assert candidate(s = \"BlockchainTechnology\") == True\n assert candidate(s = \"SystemAnalysis\") == True\n assert candidate(s = \"hAlFVaLuEs\") == False\n assert candidate(s = \"AlphabetSoup\") == False\n assert candidate(s = \"Unbelievable\") == True\n assert candidate(s = \"SplittingStrings\") == False\n assert candidate(s = \"GrApHiTe\") == False\n assert candidate(s = \"evenNumberOfVowels\") == False\n assert candidate(s = \"RoTiCoRn\") == False\n assert candidate(s = \"bYtEcOdE\") == False\n assert candidate(s = \"BigDataAnalytics\") == False\n assert candidate(s = \"FLYINGDUCK\") == True\n assert candidate(s = \"ComplexityAnalysis\") == True\n assert candidate(s = \"equalvowelcounts\") == False\n assert candidate(s = \"EnvironmentalStudies\") == True\n assert candidate(s = \"xyzXYZxyzXYZ\") == True\n", "comparison": "exact"}, "public_tests": ["\"book\"", "\"textbook\""], "hints": ["Create a function that checks if a character is a vowel, either uppercase or lowercase."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().halvesAreAlike", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:04+00:00", "tests_total": 175, "tests_dropped": 73, "flags": [], "topic_tags": ["string", "counting"]}, "language": "php", "interface": {"raw_signature": "function halvesAreAlike($s) {", "container": "Solution", "callable": "halvesAreAlike", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1705, "task_id": "maximum-number-of-eaten-apples", "difficulty": "Medium", "problem_description": "There is a special kind of apple tree that grows apples every day for n days. On the i^th day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.\n\nYou decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.\n\nGiven two integer arrays days and apples of length n, return the maximum number of apples you can eat.\n\nExample 1:\n\nInput: apples = [1,2,3,5,2], days = [3,2,1,4,2]\nOutput: 7\nExplanation: You can eat 7 apples:\n- On the first day, you eat an apple that grew on the first day.\n- On the second day, you eat an apple that grew on the second day.\n- On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.\n- On the fourth to the seventh days, you eat apples that grew on the fourth day.\n\nExample 2:\n\nInput: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\nOutput: 5\nExplanation: You can eat 5 apples:\n- On the first to the third day you eat apples that grew on the first day.\n- Do nothing on the fouth and fifth days.\n- On the sixth and seventh days you eat apples that grew on the sixth day.\n\nConstraints:\n\n- n == apples.length == days.length\n- 1 <= n <= 2 * 10^4\n- 0 <= apples[i], days[i] <= 2 * 10^4\n- days[i] = 0 if and only if apples[i] = 0.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(apples = [0, 0, 0, 0],days = [0, 0, 0, 0]) == 0\n assert candidate(apples = [1, 3, 2],days = [3, 5, 2]) == 6\n assert candidate(apples = [5, 5, 5, 5, 5],days = [1, 2, 3, 4, 5]) == 9\n assert candidate(apples = [5, 5, 5, 5, 5],days = [1, 1, 1, 1, 1]) == 5\n assert candidate(apples = [0, 0, 0, 5, 0, 6],days = [0, 0, 0, 5, 0, 4]) == 6\n assert candidate(apples = [5, 4, 3, 2, 1],days = [1, 2, 3, 4, 5]) == 8\n assert candidate(apples = [1, 2, 3, 5, 2],days = [3, 2, 1, 4, 2]) == 7\n assert candidate(apples = [3, 0, 0, 0, 0, 2],days = [3, 0, 0, 0, 0, 2]) == 5\n assert candidate(apples = [2, 1, 10],days = [2, 10, 1]) == 4\n assert candidate(apples = [4, 2, 2, 3, 1],days = [3, 2, 10, 1, 2]) == 7\n assert candidate(apples = [0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0]) == 0\n assert candidate(apples = [20, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(apples = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0],days = [2, 0, 2, 0, 2, 0, 2, 0, 2, 0]) == 10\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == 20\n assert candidate(apples = [3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0],days = [10, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0]) == 6\n assert candidate(apples = [10, 20, 30, 40, 50],days = [1, 2, 3, 4, 5]) == 9\n assert candidate(apples = [3, 2, 1, 0, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0],days = [5, 4, 3, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 5]) == 12\n assert candidate(apples = [10, 0, 20, 0, 30, 0, 40, 0, 50, 0],days = [5, 0, 4, 0, 3, 0, 2, 0, 1, 0]) == 9\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(apples = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],days = [2, 0, 2, 0, 2, 0, 2, 0, 2, 0]) == 5\n assert candidate(apples = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],days = [2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0]) == 10\n assert candidate(apples = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],days = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 79\n assert candidate(apples = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(apples = [10, 20, 0, 0, 15, 10],days = [5, 5, 0, 0, 3, 3]) == 8\n assert candidate(apples = [3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1],days = [2, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2, 2]) == 6\n assert candidate(apples = [0, 0, 10, 0, 0, 0, 0, 0, 10, 0],days = [0, 0, 1, 0, 0, 0, 0, 0, 2, 0]) == 3\n assert candidate(apples = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(apples = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(apples = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],days = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(apples = [1, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 4\n assert candidate(apples = [5, 4, 3, 2, 1],days = [5, 4, 3, 2, 1]) == 5\n assert candidate(apples = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],days = [20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 2\n assert candidate(apples = [3, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7],days = [2, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6]) == 17\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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(apples = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 29\n assert candidate(apples = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],days = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(apples = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],days = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(apples = [10, 15, 0, 20, 25, 0, 0, 30],days = [3, 4, 0, 5, 6, 0, 0, 7]) == 14\n assert candidate(apples = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10],days = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10]) == 27\n assert candidate(apples = [10, 0, 10, 0, 10, 0, 10],days = [3, 0, 3, 0, 3, 0, 3]) == 9\n assert candidate(apples = [3, 2, 1, 0, 0, 4, 2, 1, 0, 1],days = [2, 2, 2, 0, 0, 3, 2, 2, 0, 1]) == 9\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(apples = [4, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0],days = [5, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0]) == 9\n assert candidate(apples = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],days = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 13\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15]) == 17\n assert candidate(apples = [2, 4, 6, 8, 10],days = [1, 2, 3, 4, 5]) == 9\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(apples = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],days = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 13\n assert candidate(apples = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 5\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(apples = [10, 0, 5, 0, 0, 15],days = [10, 0, 4, 0, 0, 3]) == 10\n assert candidate(apples = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(apples = [5, 0, 0, 5, 0, 5, 0, 5, 0, 5],days = [1, 0, 0, 2, 0, 3, 0, 4, 0, 5]) == 12\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(apples = [2, 3, 1, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 0, 7],days = [2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 4]) == 13\n assert candidate(apples = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0],days = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 12\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(apples = [10, 20, 0, 0, 15, 10, 5],days = [5, 4, 0, 0, 6, 3, 2]) == 10\n assert candidate(apples = [10, 0, 20, 0, 30, 0, 40, 0, 50, 0, 60, 0, 70, 0, 80, 0, 90, 0, 100, 0],days = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == 23\n assert candidate(apples = [0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0]) == 7\n assert candidate(apples = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 32\n assert candidate(apples = [1, 2, 0, 4, 5, 0, 0, 6, 7, 0, 0, 8, 9],days = [3, 2, 0, 4, 5, 0, 0, 2, 3, 0, 0, 2, 3]) == 15\n assert candidate(apples = [100, 100, 100, 100, 100],days = [5, 5, 5, 5, 5]) == 9\n assert candidate(apples = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],days = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(apples = [2, 3, 1, 5, 4, 2, 3, 1, 1, 1, 1],days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 17\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(apples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100],days = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,2,3,5,2]\n[3,2,1,4,2]", "[3,0,0,0,0,2]\n[3,0,0,0,0,2]"], "hints": ["It's optimal to finish the apples that will rot first before those that will rot last", "You need a structure to keep the apples sorted by their finish time"], "metadata": {"canonical_parameter_names": ["apples", "days"], "leetcode_dataset_entry_point": "Solution().eatenApples", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:06+00:00", "tests_total": 72, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function eatenApples($apples, $days) {", "container": "Solution", "callable": "eatenApples", "parameters": [{"name": "apples", "type": "Integer[]"}, {"name": "days", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1706, "task_id": "where-will-the-ball-fall", "difficulty": "Medium", "problem_description": "You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.\n\nEach cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.\n\n- A board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.\n- A board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.\n\nWe drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a \"V\" shaped pattern between two boards or if a board redirects the ball into either wall of the box.\n\nReturn an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the i^th column at the top, or -1 if the ball gets stuck in the box.\n\nExample 1:\n\nInput: 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]]\nOutput: [1,-1,-1,-1,-1]\nExplanation: This example is shown in the photo.\nBall b0 is dropped at column 0 and falls out of the box at column 1.\nBall b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.\nBall b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.\nBall b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.\nBall b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.\n\nExample 2:\n\nInput: grid = [[-1]]\nOutput: [-1]\nExplanation: The ball gets stuck against the left wall.\n\nExample 3:\n\nInput: 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]]\nOutput: [0,1,2,3,4,-1]\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 100\n- grid[i][j] is 1 or -1.\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]\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]\n assert candidate(grid = [[-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]\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]\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 = [[-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]\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 = [[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, 2, 3, 4, -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, 1, 1, 1, 1, -1, 1, 1, 1, 1], [-1, -1, -1, -1, -1, 1, -1, -1, -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, -1, -1, -1, -1, 7, -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]\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, 2, -1, -1, -1, 6, -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]\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]\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, 1, 1, -1, -1, -1, 1, 1, 1, -1], [-1, -1, -1, 1, 1, 1, -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, 4, 5, 6, 7, -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, 2, -1, -1, 5, 6, -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, 1, 1, 1, 1, 1, 1, 1, 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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -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]\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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -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, 1, 1, 1, 1, 1, 1, 1, 1, 1], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [1, 1, 1, 1, 1, 1, 1, 1, 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, 6, 7, 8, 9, -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]\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, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1], [1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1], [-1, -1, 1, 1, -1, -1, 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, -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]\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]]) == [4, 5, -1, -1, -1, -1, -1, -1, -1, -1, 6]\n assert candidate(grid = [[1, 1, -1, -1, 1, 1, 1, -1], [1, -1, 1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, 1, -1, 1, -1], [1, 1, -1, 1, -1, 1, -1, 1]]) == [-1, -1, -1, -1, -1, -1, -1, -1]\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, 0, -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]\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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 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, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1], [1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1], [1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1], [-1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 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, -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]]) == [-1, -1, -1, 2, -1, -1, -1, 6, -1, 10, 11, -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, 6, -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]\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]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -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]]) == [-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]\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]\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, 1, 2, 3, 4, 5, 6, 7, 8, -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], [-1, 1, 1, -1, -1, 1, 1, -1, -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, 3, 6, 7, -1, -1, -1, 11, -1, -1, -1, -1, 18, -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]\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, 0, 1, 2, 5, 6, 7, 8, -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, 2, -1, -1, 5, 6, 7, 8, -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, -1, 1, -1, -1], [1, -1, 1, -1, 1, -1, 1, -1, 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, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1], [1, -1, 1, -1, 1, -1, 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, -1, -1, -1, -1, -1, -1, -1, -1, 18]\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]\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]]) == [4, -1, -1, -1, -1, -1, -1, -1, -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]\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]\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, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, 1, -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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -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, -1, 1, 1, -1, 1, -1, 1, 1, -1], [-1, 1, -1, -1, 1, -1, 1, -1, -1, 1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [-1, 1, -1, 1, -1, 1, -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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1], [1, -1, 1, -1, 1, -1, 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, -1, -1, -1, 1, 1, 1, 1, -1, -1], [-1, -1, 1, 1, 1, 1, -1, -1, 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]\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]]) == [0, 1, -1, -1, 4, 5, 6, -1, -1, 9, 10, 11, -1, -1, 14, 15, 16, -1, -1, 19]\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]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, -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, 2, -1, -1, 3, 4, 7, 8, -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]\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", "comparison": "exact"}, "public_tests": ["[[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]", "[[-1]]", "[[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]"], "hints": ["Use DFS.", "Traverse the path of the ball downwards until you reach the bottom or get stuck."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().findBall", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:08+00:00", "tests_total": 65, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function findBall($grid) {", "container": "Solution", "callable": "findBall", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1707, "task_id": "maximum-xor-with-an-element-from-array", "difficulty": "Hard", "problem_description": "You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [x_i, m_i].\n\nThe answer to the i^th query is the maximum bitwise XOR value of x_i and any element of nums that does not exceed m_i. In other words, the answer is max(nums[j] XOR x_i) for all j such that nums[j] <= m_i. If all elements in nums are larger than m_i, then the answer is -1.\n\nReturn an integer array answer where answer.length == queries.length and answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\nOutput: [3,3,7]\nExplanation:\n1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n\nExample 2:\n\nInput: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\nOutput: [15,-1,5]\n\nConstraints:\n\n- 1 <= nums.length, queries.length <= 10^5\n- queries[i].length == 2\n- 0 <= nums[j], x_i, m_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4, 8, 16],queries = [[10, 15], [30, 20], [5, 5]]) == [14, 31, 7]\n assert candidate(nums = [100, 200, 300, 400],queries = [[150, 250], [10, 100], [450, 500]]) == [242, 110, 422]\n assert candidate(nums = [7, 8, 9],queries = [[1, 5], [6, 8], [10, 12]]) == [-1, 14, 13]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[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]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[1, 10], [2, 5], [3, 3], [4, 4], [5, 2], [6, 6], [7, 7], [8, 8], [9, 9], [10, 1]]) == [11, 7, 2, 7, 7, 7, 6, 15, 15, 11]\n assert candidate(nums = [1000000000],queries = [[1000000000, 1000000000], [999999999, 999999999]]) == [0, -1]\n assert candidate(nums = [5, 2, 4, 6, 6, 3],queries = [[12, 4], [8, 1], [6, 3]]) == [15, -1, 5]\n assert candidate(nums = [0, 1, 2, 3, 4],queries = [[3, 1], [1, 3], [5, 6]]) == [3, 3, 7]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [[9, 10], [99, 100], [999, 1000], [9999, 10000], [99999, 100000], [999999, 1000000], [9999999, 10000000], [99999999, 100000000], [999999999, 1000000000], [0, 1]]) == [8, 105, 1005, 10091, 106895, 1008943, 10031327, 100311743, 1047472383, 1]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],queries = [[1000000000, 999999999], [999999998, 999999997], [999999996, 999999995], [999999995, 1000000000]]) == [1023, 3, -1, 1019]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 0], [1, 0], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]) == [-1, -1, 3, 2, 5, 4, 7, 6, 9, 8]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],queries = [[7, 7], [7, 6], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15]]) == [0, -1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384],queries = [[1024, 2047], [2048, 4095], [4096, 8191], [8192, 16383], [16384, 32767], [32768, 16384], [65536, 8192]]) == [0, 3072, 6144, 12288, 24576, 49152, 73728]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],queries = [[1000000000, 999999999], [999999998, 999999997], [999999996, 999999995], [999999994, 999999993], [999999992, 999999991], [999999990, 999999989], [999999988, 999999987], [999999986, 999999985], [999999984, 999999983], [999999982, 999999981]]) == [1023, 9, 11, 13, 15, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400],queries = [[10, 100], [150, 200], [250, 300], [350, 400], [400, 450], [500, 550]]) == [110, 242, 470, 456, 500, 400]\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216],queries = [[512, 1024], [1536, 2048], [2560, 3072], [3584, 4096], [4608, 5120], [5632, 6144], [6656, 7168], [7680, 8192], [8704, 9216]]) == [1536, 3584, 3584, 7680, 7680, 7680, 7680, 15872, 15872]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[10, 90], [20, 80], [30, 70], [40, 60], [50, 50], [60, 40], [70, 30], [80, 20], [90, 10], [100, 0]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],queries = [[0, 31], [1, 30], [2, 29], [3, 28], [4, 27], [5, 26], [6, 25], [7, 24], [8, 23], [9, 22], [10, 21], [11, 20], [12, 19], [13, 18], [14, 17], [15, 16]]) == [31, 28, 31, 26, 31, 28, 31, 22, 31, 28, 31, 26, 31, 28, 31, 14]\n assert candidate(nums = [1000000000, 900000000, 800000000, 700000000, 600000000],queries = [[1000000000, 1000000000], [900000000, 900000000], [800000000, 800000000], [700000000, 700000000], [600000000, 600000000], [500000000, 500000000]]) == [408521728, 471715328, 208424448, 175792384, 0, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[50, 350], [150, 450], [250, 550], [350, 650], [450, 750], [550, 850], [650, 950], [750, 1050], [850, 1150], [950, 1250]]) == [286, 442, 470, 774, 922, 978, 934, 962, 922, 978]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],queries = [[1024, 512], [512, 256], [256, 128], [128, 64], [64, 32], [32, 16], [16, 8], [8, 4], [4, 2], [2, 1], [1, 1]]) == [1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 0]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [0, 3, 2, 7, 6, 7, 6, 15, 14, 15]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[2, 1], [4, 3], [6, 5], [8, 7], [10, 9], [12, 11], [14, 13], [16, 15], [18, 17], [20, 19]]) == [3, 7, 7, 15, 15, 15, 15, 31, 31, 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],queries = [[0, 1], [1, 2], [3, 4], [7, 8], [15, 16], [31, 32], [63, 64], [127, 128], [255, 256], [511, 512], [1023, 1024], [2047, 2048], [4095, 4096], [8191, 8192], [16383, 16384], [32767, 32768], [65535, 65536], [131071, 131072], [262143, 262144], [524287, 524288], [1048575, 1048576]]) == [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],queries = [[1, 2], [3, 4], [7, 8], [15, 16], [31, 32], [63, 64], [127, 128], [255, 256], [511, 512], [1023, 1024]]) == [3, 7, 15, 31, 63, 127, 255, 511, 1023, 1022]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],queries = [[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]]) == [3, 7, 7, 15, 15, 15, 15, 31, 31, 31, 31, 31, 31, 31, 31, 63]\n assert candidate(nums = [23, 31, 12, 22, 19, 30, 27, 14, 29, 25],queries = [[10, 30], [35, 35], [23, 23], [19, 20], [30, 31]]) == [29, 62, 27, 31, 18]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[5, 10], [15, 25], [25, 35], [35, 45], [45, 55], [55, 65], [65, 75], [75, 85], [85, 95], [95, 105]]) == [15, 27, 19, 61, 57, 61, 125, 121, 125, 119]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[50, 150], [250, 350], [450, 550], [650, 750], [850, 950], [1050, 1150]]) == [86, 470, 422, 934, 922, 2034]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000],queries = [[1, 5], [10, 50], [100, 500], [1000, 5000], [10000, 50000], [100000, 500000], [1000000, 1500000]]) == [0, 11, 110, 1001, 10100, 106928, 1008976]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19]]) == [-1, 1, 7, 5, 15, 15, 15, 13, 31, 31]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [5, 100], [105, 100]]) == [0, 30, 20, 60, 56, 54, 122, 120, 114, 122, 97, 125]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[2, 10], [4, 20], [6, 30], [8, 40], [10, 50], [12, 60], [14, 70], [16, 80], [18, 90], [20, 100]]) == [11, 23, 23, 27, 27, 31, 31, 31, 31, 31]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == [0, 2, 6, 6, 14, 14, 14, 14, 30, 30]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [[1, 1], [5, 10], [50, 100], [500, 1000], [5000, 10000], [50000, 100000], [500000, 1000000], [5000000, 10000000], [50000000, 100000000], [500000000, 1000000000]]) == [0, 15, 86, 540, 13464, 83440, 582496, 13950400, 118428032, 643280640]\n assert candidate(nums = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22],queries = [[32, 31], [33, 30], [34, 29], [35, 28], [36, 27], [37, 26], [38, 25], [39, 24], [40, 23], [41, 22]]) == [63, 63, 63, 63, 63, 63, 63, 63, 63, 63]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],queries = [[100, 100], [101, 101], [102, 102], [103, 103], [104, 104], [105, 105], [106, 106], [107, 107], [108, 108], [109, 109]]) == [0, 1, 3, 3, 15, 15, 15, 15, 11, 11]\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505],queries = [[100, 200], [300, 400], [500, 600], [700, 800], [800, 700], [900, 1000]]) == [31, 486, 401, 915, 1002, 1023]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[5, 50], [15, 30], [25, 40], [35, 60], [45, 70], [55, 80], [65, 90], [75, 100], [85, 20], [95, 10]]) == [55, 27, 49, 61, 107, 113, 125, 121, 95, 85]\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],queries = [[500, 1024], [256, 256], [1025, 1025], [10, 20], [2, 3]]) == [1524, 384, 1537, 26, 3]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],queries = [[1, 1], [2, 2], [3, 4], [5, 8], [9, 16], [17, 32], [33, 64], [65, 128], [129, 256], [257, 512], [513, 1024], [1025, 2048], [2049, 4096], [4097, 8192], [8193, 16384], [16385, 32768]]) == [0, 3, 7, 13, 25, 49, 97, 193, 385, 769, 1537, 3073, 6145, 12289, 24577, 49153]\n assert candidate(nums = [50, 40, 30, 20, 10],queries = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90], [95, 100]]) == [15, 27, 19, 61, 57, 61, 115, 121, 125, 119]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[101, 99], [201, 199], [301, 299], [401, 399], [501, 499], [601, 599], [701, 699], [801, 799], [901, 899], [1001, 999]]) == [-1, 173, 485, 501, 401, 969, 913, 1001, 993, 909]\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384],queries = [[512, 1024], [1536, 2048], [2560, 4096], [4608, 8192], [8704, 16384], [32768, 65536]]) == [1536, 3584, 6656, 12800, 25088, 49152]\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930],queries = [[100, 123], [400, 456], [700, 789], [100000, 101112], [130000, 131415], [160000, 161718], [190000, 192021], [220000, 222324], [250000, 252627], [280000, 282930]]) == [31, 491, 884, 100200, 260743, 261112, 224456, 219931, 250757, 499475]\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500],queries = [[50, 100], [250, 350], [375, 400], [500, 500], [100, 99]]) == [86, 470, 481, 400, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[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]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [1, 3, 3, 7, 7, 7, 7, 15, 15, 15]\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],queries = [[8, 9], [17, 18], [26, 27], [35, 36], [44, 45], [53, 54], [62, 63], [71, 72], [80, 81], [89, 90], [98, 99]]) == [1, 24, 19, 56, 62, 60, 55, 120, 125, 125, 121]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],queries = [[999, 1000], [1999, 2000], [2999, 3000], [3999, 4000], [4999, 5000], [5999, 6000], [6999, 7000], [7999, 8000], [8999, 9000], [9999, 10000]]) == [15, 1063, 3175, 3191, 7207, 7383, 7303, 7383, 15463, 15447]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100], [11, 100], [12, 100], [13, 100], [14, 100], [15, 100], [16, 100], [17, 100], [18, 100], [19, 100], [20, 100]]) == [11, 22, 29, 44, 55, 58, 65, 88, 89, 110, 111, 104, 105, 106, 107, 116, 117, 118, 119, 112]\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],queries = [[8, 9], [17, 18], [26, 27], [35, 36], [44, 45], [53, 54], [62, 63], [71, 72], [80, 81], [89, 90], [91, 90]]) == [1, 24, 19, 56, 62, 60, 55, 120, 125, 125, 127]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[2, 5], [4, 9], [6, 13], [8, 17], [10, 19], [12, 21], [14, 23], [16, 25], [18, 27], [20, 29]]) == [7, 13, 15, 25, 27, 31, 31, 31, 31, 31]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [[10, 9], [7, 6], [1, 10], [8, 5], [0, 0]]) == [15, 6, 8, 13, -1]\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021],queries = [[122, 123], [455, 456], [788, 789], [101111, 101112], [131414, 131415], [161717, 161718], [192020, 192021], [200000, 210000]]) == [1, 444, 879, 101183, 232366, 261453, 222444, 200277]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000],queries = [[1000000000, 1000000000], [500000000, 500000000], [250000000, 250000000], [125000000, 125000000], [62500000, 62500000], [31250000, 31250000], [15625000, 15625000]]) == [1021940544, 510970272, 255485136, 127742568, 56084360, 20102520, 0]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],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]]) == [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [[2, 10], [4, 12], [6, 14], [8, 16], [10, 18], [12, 20], [14, 22], [16, 24], [18, 26], [20, 28], [22, 30], [24, 10], [26, 12], [28, 14], [30, 16]]) == [11, 15, 15, 15, 27, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31]\n assert candidate(nums = [100, 200, 300, 400, 500],queries = [[150, 200], [250, 350], [350, 450], [50, 150], [450, 500]]) == [242, 470, 406, 86, 422]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],queries = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],queries = [[1, 1000000000], [2, 100000000], [3, 10000000], [4, 1000000], [5, 100000], [6, 10000], [7, 1000], [8, 100], [9, 10], [10, 1]]) == [1000000001, 100000002, 10000003, 1000004, 100005, 10006, 1007, 108, 8, 11]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],queries = [[1000000000, 1000000000], [1, 1000000000], [1000000000, 999999999], [1, 999999999], [1000000000, 999999998]]) == [1023, 1000000001, 1023, 999999999, 1022]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],queries = [[1, 2], [2, 4], [3, 8], [4, 16], [5, 32], [6, 64], [7, 128], [8, 256], [9, 512], [10, 1024], [11, 2048], [12, 4096], [13, 8192], [14, 16384], [15, 32768]]) == [3, 6, 11, 20, 37, 70, 135, 264, 521, 1034, 2059, 4108, 8205, 16398, 16399]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],queries = [[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, 16384]]) == [0, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152]\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109],queries = [[11, 30], [22, 40], [33, 50], [44, 60], [55, 70], [66, 80], [77, 90], [88, 100], [99, 110], [100, 120]]) == [30, 54, 52, 57, 118, 116, 123, 120, 118, 113]\n assert candidate(nums = [8, 4, 2, 1, 16, 32, 64, 128, 256, 512],queries = [[7, 8], [3, 4], [1, 2], [15, 16], [31, 32], [63, 64], [127, 128], [255, 256], [511, 512], [1023, 1024]]) == [15, 7, 3, 31, 63, 127, 255, 511, 1023, 1022]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],queries = [[2, 3], [5, 6], [8, 9], [11, 12], [14, 15], [17, 18], [20, 21], [23, 24], [26, 27], [29, 30], [31, 32]]) == [1, 6, 14, 13, 13, 30, 29, 30, 28, 30, 28]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[15, 10], [25, 20], [35, 30], [45, 40], [55, 50], [65, 60], [75, 70], [85, 80], [95, 90], [105, 100]]) == [5, 19, 61, 57, 61, 125, 121, 125, 119, 125]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],queries = [[1, 1], [2, 2], [3, 4], [5, 8], [9, 16], [17, 32], [33, 64], [65, 128], [129, 256], [257, 512]]) == [0, 3, 7, 13, 25, 49, 97, 193, 385, 769]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],queries = [[1000000000, 999999999], [999999998, 999999998], [999999997, 999999996], [999999996, 999999995]]) == [1023, 3, 1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],queries = [[2, 10], [4, 12], [6, 14], [8, 16], [10, 18], [12, 20], [14, 22], [16, 24], [18, 26], [20, 28], [22, 30], [24, 32], [26, 34], [28, 36], [30, 38]]) == [11, 15, 15, 15, 27, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[1, 1], [2, 1], [0, 1], [10, 1], [100, 1]]) == [0, 3, 1, 11, 101]\n assert candidate(nums = [23, 45, 67, 89, 111, 135, 159, 183, 207, 231],queries = [[22, 23], [44, 45], [66, 67], [88, 89], [110, 111], [134, 135], [158, 159], [182, 183], [206, 207], [230, 231]]) == [1, 59, 111, 117, 121, 233, 241, 245, 227, 241]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],queries = [[100, 105], [101, 101], [102, 103], [103, 107], [104, 104], [105, 108], [106, 106], [107, 109], [108, 110], [109, 100], [110, 102]]) == [13, 1, 3, 15, 15, 15, 15, 15, 11, 9, 11]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[99, 100], [150, 300], [250, 250], [350, 400], [450, 500], [550, 600], [650, 700], [750, 800], [850, 900], [950, 1000]]) == [7, 442, 158, 406, 422, 978, 934, 962, 922, 978]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],queries = [[1, 2], [2, 3], [3, 5], [4, 7], [5, 11], [6, 13], [7, 17], [8, 19], [9, 23], [10, 29]]) == [3, 1, 6, 7, 14, 13, 22, 27, 30, 29]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],queries = [[3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21], [21, 23]]) == [7, 7, 15, 15, 15, 15, 31, 31, 31, 31]\n", "comparison": "exact"}, "public_tests": ["[0,1,2,3,4]\n[[3,1],[1,3],[5,6]]", "[5,2,4,6,6,3]\n[[12,4],[8,1],[6,3]]"], "hints": ["In problems involving bitwise operations, we often think on the bits level. In this problem, we can think that to maximize the result of an xor operation, we need to maximize the most significant bit, then the next one, and so on.", "If there's some number in the array that is less than m and whose the most significant bit is different than that of x, then xoring with this number maximizes the most significant bit, so I know this bit in the answer is 1.", "To check the existence of such numbers and narrow your scope for further bits based on your choice, you can use trie.", "You can sort the array and the queries, and maintain the trie such that in each query the trie consists exactly of the valid elements."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().maximizeXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:11+00:00", "tests_total": 83, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "bit-manipulation", "trie"]}, "language": "php", "interface": {"raw_signature": "function maximizeXor($nums, $queries) {", "container": "Solution", "callable": "maximizeXor", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1710, "task_id": "maximum-units-on-a-truck", "difficulty": "Easy", "problem_description": "You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxes_i, numberOfUnitsPerBox_i]:\n\n- numberOfBoxes_i is the number of boxes of type i.\n- numberOfUnitsPerBox_iis the number of units in each box of the type i.\n\nYou are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed truckSize.\n\nReturn the maximum total number of units that can be put on the truck.\n\nExample 1:\n\nInput: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\nOutput: 8\nExplanation: There are:\n- 1 box of the first type that contains 3 units.\n- 2 boxes of the second type that contain 2 units each.\n- 3 boxes of the third type that contain 1 unit each.\nYou can take all the boxes of the first and second types, and one box of the third type.\nThe total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.\n\nExample 2:\n\nInput: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\nOutput: 91\n\nConstraints:\n\n- 1 <= boxTypes.length <= 1000\n- 1 <= numberOfBoxes_i, numberOfUnitsPerBox_i <= 1000\n- 1 <= truckSize <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(boxTypes = [[1, 3], [2, 2], [3, 1]],truckSize = 4) == 8\n assert candidate(boxTypes = [[1, 1], [2, 2], [3, 3], [4, 4]],truckSize = 1) == 4\n assert candidate(boxTypes = [[2, 1], [4, 4], [3, 3]],truckSize = 5) == 19\n assert candidate(boxTypes = [[10, 1], [20, 2], [30, 3]],truckSize = 50) == 130\n assert candidate(boxTypes = [[5, 10], [2, 5], [4, 7], [3, 9]],truckSize = 10) == 91\n assert candidate(boxTypes = [[1, 100], [2, 99], [3, 98], [4, 97]],truckSize = 10) == 980\n assert candidate(boxTypes = [[10, 1], [5, 2], [3, 3]],truckSize = 10) == 21\n assert candidate(boxTypes = [[100, 1], [99, 2], [98, 3], [97, 4]],truckSize = 200) == 692\n assert candidate(boxTypes = [[10, 1]],truckSize = 10) == 10\n assert candidate(boxTypes = [[1, 1000], [1000, 1]],truckSize = 500) == 1499\n assert candidate(boxTypes = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60]],truckSize = 10) == 800\n assert candidate(boxTypes = [[5, 5], [5, 5], [5, 5], [5, 5]],truckSize = 15) == 75\n assert candidate(boxTypes = [[2, 1], [3, 2], [4, 3], [5, 4], [6, 5]],truckSize = 15) == 62\n assert candidate(boxTypes = [[2, 1000], [1, 900], [2, 800], [1, 700], [2, 600], [1, 500], [2, 400], [1, 300], [2, 200], [1, 100]],truckSize = 10) == 7300\n assert candidate(boxTypes = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]],truckSize = 20) == 115\n assert candidate(boxTypes = [[5, 10], [1, 15], [3, 12], [2, 14], [4, 8]],truckSize = 15) == 161\n assert candidate(boxTypes = [[7, 10], [5, 3], [2, 6], [8, 1]],truckSize = 20) == 103\n assert candidate(boxTypes = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5]],truckSize = 15) == 35\n assert candidate(boxTypes = [[5, 10], [4, 20], [3, 30], [2, 40], [1, 50]],truckSize = 15) == 350\n assert candidate(boxTypes = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],truckSize = 5) == 40\n assert candidate(boxTypes = [[9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]],truckSize = 30) == 174\n assert candidate(boxTypes = [[999, 1], [1, 999], [500, 500], [250, 250], [125, 125]],truckSize = 1000) == 329248\n assert candidate(boxTypes = [[1, 5], [2, 3], [3, 2], [4, 1]],truckSize = 10) == 21\n assert candidate(boxTypes = [[50, 10], [100, 9], [150, 8], [200, 7], [250, 6], [300, 5]],truckSize = 800) == 5750\n assert candidate(boxTypes = [[50, 5], [30, 6], [20, 7]],truckSize = 100) == 570\n assert candidate(boxTypes = [[3, 100], [2, 200], [1, 300], [5, 400]],truckSize = 5) == 2000\n assert candidate(boxTypes = [[20, 5], [15, 10], [10, 15], [5, 20], [1, 25]],truckSize = 35) == 445\n assert candidate(boxTypes = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]],truckSize = 20) == 18900\n assert candidate(boxTypes = [[10, 10], [10, 20], [10, 30], [10, 40], [10, 50]],truckSize = 40) == 1400\n assert candidate(boxTypes = [[50, 10], [30, 20], [20, 30], [10, 40], [5, 50]],truckSize = 120) == 2350\n assert candidate(boxTypes = [[200, 1], [100, 2], [150, 3], [50, 4], [250, 5]],truckSize = 500) == 2000\n assert candidate(boxTypes = [[100, 1], [50, 2], [25, 3], [10, 4], [5, 5], [1, 6]],truckSize = 150) == 305\n assert candidate(boxTypes = [[20, 25], [15, 30], [10, 35], [5, 40]],truckSize = 50) == 1500\n assert candidate(boxTypes = [[10, 10], [5, 7], [15, 5], [20, 3]],truckSize = 25) == 185\n assert candidate(boxTypes = [[50, 10], [30, 20], [20, 30], [10, 40]],truckSize = 100) == 2000\n assert candidate(boxTypes = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],truckSize = 150) == 5500\n assert candidate(boxTypes = [[1, 900], [2, 800], [3, 700], [4, 600], [5, 500], [6, 400], [7, 300], [8, 200], [9, 100]],truckSize = 15) == 9500\n assert candidate(boxTypes = [[1, 999], [2, 998], [3, 997], [4, 996], [5, 995], [6, 994], [7, 993], [8, 992], [9, 991], [10, 990]],truckSize = 20) == 19915\n assert candidate(boxTypes = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]],truckSize = 55) == 220\n assert candidate(boxTypes = [[30, 20], [20, 15], [10, 10], [40, 5], [50, 2]],truckSize = 100) == 1200\n assert candidate(boxTypes = [[10, 30], [20, 20], [30, 10], [40, 5], [50, 1]],truckSize = 60) == 1000\n assert candidate(boxTypes = [[50, 10], [40, 20], [30, 30], [20, 40], [10, 50]],truckSize = 120) == 3200\n assert candidate(boxTypes = [[500, 1000], [400, 900], [300, 800], [200, 700], [100, 600]],truckSize = 1200) == 1100000\n assert candidate(boxTypes = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],truckSize = 150) == 1450\n assert candidate(boxTypes = [[100, 10], [200, 9], [150, 8], [50, 7], [25, 6]],truckSize = 300) == 2800\n assert candidate(boxTypes = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],truckSize = 50) == 215\n assert candidate(boxTypes = [[500, 100], [300, 200], [200, 300], [100, 400]],truckSize = 800) == 180000\n assert candidate(boxTypes = [[50, 100], [25, 200], [75, 50], [100, 250]],truckSize = 200) == 36250\n assert candidate(boxTypes = [[1, 999], [999, 1]],truckSize = 1000) == 1998\n assert candidate(boxTypes = [[7, 9], [7, 8], [7, 7], [7, 6], [7, 5], [7, 4], [7, 3], [7, 2], [7, 1]],truckSize = 20) == 161\n assert candidate(boxTypes = [[3, 8], [5, 7], [2, 9], [6, 10], [4, 5]],truckSize = 15) == 130\n assert candidate(boxTypes = [[5, 10], [4, 20], [3, 30], [2, 40], [1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [1, 100]],truckSize = 20) == 750\n assert candidate(boxTypes = [[50, 20], [100, 15], [150, 10], [200, 5], [250, 1]],truckSize = 500) == 5000\n assert candidate(boxTypes = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996]],truckSize = 15) == 14960\n assert candidate(boxTypes = [[5, 10], [5, 20], [5, 30], [5, 40], [5, 50], [5, 60], [5, 70], [5, 80], [5, 90], [5, 100]],truckSize = 25) == 2000\n assert candidate(boxTypes = [[10, 1000], [9, 900], [8, 800], [7, 700], [6, 600], [5, 500], [4, 400], [3, 300], [2, 200], [1, 100]],truckSize = 25) == 22900\n assert candidate(boxTypes = [[100, 5], [200, 2], [50, 10], [150, 3]],truckSize = 350) == 1550\n assert candidate(boxTypes = [[50, 100], [40, 99], [30, 98], [20, 97], [10, 96], [5, 95]],truckSize = 160) == 15275\n assert candidate(boxTypes = [[1, 500], [1, 400], [1, 300], [1, 200], [1, 100]],truckSize = 2) == 900\n assert candidate(boxTypes = [[3, 9], [2, 8], [5, 7], [1, 6], [4, 5]],truckSize = 15) == 104\n assert candidate(boxTypes = [[10, 20], [20, 10], [30, 5], [40, 2], [50, 1]],truckSize = 100) == 630\n assert candidate(boxTypes = [[300, 1], [200, 2], [100, 3], [50, 4], [25, 5]],truckSize = 700) == 1325\n assert candidate(boxTypes = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996]],truckSize = 15) == 14960\n assert candidate(boxTypes = [[5, 15], [10, 12], [20, 9], [30, 7], [40, 5], [50, 3]],truckSize = 150) == 920\n assert candidate(boxTypes = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],truckSize = 500) == 3740\n assert candidate(boxTypes = [[5, 15], [20, 3], [5, 20], [10, 7]],truckSize = 25) == 260\n assert candidate(boxTypes = [[100, 10], [50, 20], [20, 30], [10, 40]],truckSize = 200) == 3000\n assert candidate(boxTypes = [[100, 2], [200, 3], [300, 4], [400, 5], [500, 6]],truckSize = 1000) == 5400\n assert candidate(boxTypes = [[100, 1], [50, 2], [25, 3], [12, 4], [6, 5], [3, 6], [1, 7]],truckSize = 200) == 378\n assert candidate(boxTypes = [[50, 10], [40, 9], [30, 8], [20, 7], [10, 6], [5, 5], [1, 4]],truckSize = 160) == 1329\n assert candidate(boxTypes = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],truckSize = 50) == 374\n assert candidate(boxTypes = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],truckSize = 500) == 37400\n assert candidate(boxTypes = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],truckSize = 10) == 55\n assert candidate(boxTypes = [[1, 500], [2, 400], [3, 300], [4, 200], [5, 100]],truckSize = 10) == 3000\n assert candidate(boxTypes = [[30, 4], [10, 20], [15, 5]],truckSize = 50) == 375\n assert candidate(boxTypes = [[100, 10], [200, 9], [300, 8], [400, 7]],truckSize = 1000) == 8000\n assert candidate(boxTypes = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],truckSize = 1) == 50\n assert candidate(boxTypes = [[10, 100], [5, 200], [3, 300], [2, 400], [1, 500]],truckSize = 20) == 4100\n assert candidate(boxTypes = [[10, 5], [5, 10], [15, 3]],truckSize = 18) == 109\n assert candidate(boxTypes = [[10, 5], [20, 8], [30, 2], [5, 9]],truckSize = 40) == 265\n assert candidate(boxTypes = [[10, 10], [20, 9], [30, 8], [40, 7], [50, 6], [60, 5], [70, 4], [80, 3], [90, 2], [100, 1]],truckSize = 250) == 1560\n assert candidate(boxTypes = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5]],truckSize = 30) == 120\n assert candidate(boxTypes = [[1, 1000], [2, 900], [3, 800], [4, 700], [5, 600], [6, 500], [7, 400], [8, 300], [9, 200], [10, 100]],truckSize = 15) == 11000\n assert candidate(boxTypes = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500], [60, 600], [70, 700], [80, 800], [90, 900]],truckSize = 300) == 230000\n assert candidate(boxTypes = [[500, 500], [500, 500], [500, 500]],truckSize = 1000) == 500000\n assert candidate(boxTypes = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],truckSize = 1000) == 4400\n assert candidate(boxTypes = [[50, 20], [30, 15], [40, 10], [20, 5]],truckSize = 100) == 1650\n assert candidate(boxTypes = [[10, 5], [20, 3], [30, 4], [40, 2], [50, 1]],truckSize = 100) == 310\n assert candidate(boxTypes = [[10, 500], [20, 450], [30, 400], [40, 350], [50, 300], [60, 250], [70, 200], [80, 150], [90, 100], [100, 50]],truckSize = 200) == 67500\n assert candidate(boxTypes = [[3, 2], [2, 5], [6, 1], [10, 3]],truckSize = 12) == 40\n assert candidate(boxTypes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],truckSize = 30) == 266\n assert candidate(boxTypes = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [10, 6], [9, 7], [8, 8], [7, 9], [6, 10]],truckSize = 50) == 340\n assert candidate(boxTypes = [[100, 10], [200, 5], [300, 1]],truckSize = 500) == 2200\n assert candidate(boxTypes = [[10, 5], [9, 4], [8, 3], [7, 2], [6, 1]],truckSize = 20) == 89\n assert candidate(boxTypes = [[100, 1], [100, 2], [100, 3], [100, 4], [100, 5]],truckSize = 250) == 1050\n assert candidate(boxTypes = [[50, 10], [50, 20], [50, 30], [50, 40], [50, 50]],truckSize = 150) == 6000\n assert candidate(boxTypes = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],truckSize = 15) == 145\n assert candidate(boxTypes = [[50, 1], [200, 2], [100, 3], [30, 4], [10, 5]],truckSize = 250) == 690\n assert candidate(boxTypes = [[1, 1000], [1, 999], [1, 998], [1, 997], [1, 996], [1, 995], [1, 994], [1, 993], [1, 992], [1, 991]],truckSize = 10) == 9955\n assert candidate(boxTypes = [[10, 100], [20, 90], [30, 80], [40, 70], [50, 60]],truckSize = 200) == 11000\n assert candidate(boxTypes = [[100, 100], [90, 90], [80, 80], [70, 70], [60, 60], [50, 50]],truckSize = 500) == 35500\n assert candidate(boxTypes = [[20, 1], [20, 2], [20, 3], [20, 4], [20, 5], [20, 6], [20, 7], [20, 8], [20, 9], [20, 10]],truckSize = 100) == 800\n", "comparison": "exact"}, "public_tests": ["[[1,3],[2,2],[3,1]]\n4", "[[5,10],[2,5],[4,7],[3,9]]\n10"], "hints": ["If we have space for at least one box, it's always optimal to put the box with the most units.", "Sort the box types with the number of units per box non-increasingly.", "Iterate on the box types and take from each type as many as you can."], "metadata": {"canonical_parameter_names": ["boxTypes", "truckSize"], "leetcode_dataset_entry_point": "Solution().maximumUnits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:16+00:00", "tests_total": 104, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maximumUnits($boxTypes, $truckSize) {", "container": "Solution", "callable": "maximumUnits", "parameters": [{"name": "boxTypes", "type": "Integer[][]"}, {"name": "truckSize", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1711, "task_id": "count-good-meals", "difficulty": "Medium", "problem_description": "A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.\n\nYou can pick any two different foods to make a good meal.\n\nGiven an array of integers deliciousness where deliciousness[i] is the deliciousness of the i^th item of food, return the number of different good meals you can make from this list modulo 10^9 + 7.\n\nNote that items with different indices are considered different even if they have the same deliciousness value.\n\nExample 1:\n\nInput: deliciousness = [1,3,5,7,9]\nOutput: 4\nExplanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n\nExample 2:\n\nInput: deliciousness = [1,1,1,3,3,3,7]\nOutput: 15\nExplanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.\n\nConstraints:\n\n- 1 <= deliciousness.length <= 10^5\n- 0 <= deliciousness[i] <= 2^20\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(deliciousness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(deliciousness = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 15\n assert candidate(deliciousness = [0, 0, 0, 0, 0, 0]) == 0\n assert candidate(deliciousness = [0, 0]) == 0\n assert candidate(deliciousness = [2, 2, 2, 3, 3, 3, 4, 4, 4]) == 6\n assert candidate(deliciousness = [1048576, 1048576, 524288, 524288, 262144, 262144]) == 3\n assert candidate(deliciousness = [1]) == 0\n assert candidate(deliciousness = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(deliciousness = [1048576, 1048576]) == 1\n assert candidate(deliciousness = [13, 100, 13]) == 0\n assert candidate(deliciousness = [1, 3, 5, 7, 9]) == 4\n assert candidate(deliciousness = [1, 1, 1, 3, 3, 3, 7]) == 15\n assert candidate(deliciousness = [1, 0, 0, 0, 0]) == 4\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32]) == 0\n assert candidate(deliciousness = [1023, 1024, 512, 512, 256, 256, 128, 128, 64, 64, 32, 32, 16, 16, 8, 8, 4, 4, 2, 2, 1, 1]) == 12\n assert candidate(deliciousness = [1048576, 1, 1, 1, 1]) == 6\n assert candidate(deliciousness = [1, 1048575, 1048575, 1048576]) == 2\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 0\n assert candidate(deliciousness = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) == 5\n assert candidate(deliciousness = [1, 100000, 200000, 300000, 400000]) == 0\n assert candidate(deliciousness = [220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220]) == 0\n assert candidate(deliciousness = [0, 0, 0, 0]) == 0\n assert candidate(deliciousness = [1048576, 1048576]) == 1\n assert candidate(deliciousness = [2, 2, 2, 2, 2]) == 10\n assert candidate(deliciousness = [1, 1048575]) == 1\n assert candidate(deliciousness = [0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 9]) == 10\n assert candidate(deliciousness = [31, 1, 4, 3, 12, 13, 8, 16, 7]) == 5\n assert candidate(deliciousness = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(deliciousness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(deliciousness = [1048575, 1048576, 524287, 524288, 262143, 262144, 131071, 131072, 65535, 65536, 32767, 32768, 16383, 16384, 8191, 8192, 4095, 4096, 2047, 2048, 1023, 1024, 511, 512, 255, 256, 127, 128, 63, 64, 31, 32, 15, 16, 7, 8, 3, 4, 1, 2, 0, 0, 0, 0, 0, 0]) == 145\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(deliciousness = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(deliciousness = [1048575, 1048574, 1048573, 1048572, 1048571, 1048570]) == 0\n assert candidate(deliciousness = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 28\n assert candidate(deliciousness = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 11\n assert candidate(deliciousness = [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]) == 249\n assert candidate(deliciousness = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]) == 3\n assert candidate(deliciousness = [5, 1, 4, 3, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 15\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 0\n assert candidate(deliciousness = [21, 1, 17, 3, 9, 18, 25, 33]) == 1\n assert candidate(deliciousness = [1023, 1024, 2047, 2048, 3071, 3072, 4095, 4096]) == 1\n assert candidate(deliciousness = [1023, 1024, 1025, 2047, 2048, 2049, 4095, 4096, 4097]) == 3\n assert candidate(deliciousness = [1023, 1024, 2047, 2048, 4095, 4096, 8191, 8192]) == 0\n assert candidate(deliciousness = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127]) == 0\n assert candidate(deliciousness = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 14\n assert candidate(deliciousness = [5, 15, 1, 3, 7, 9, 11, 13]) == 7\n assert candidate(deliciousness = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047]) == 0\n assert candidate(deliciousness = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 19\n assert candidate(deliciousness = [1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575]) == 0\n assert candidate(deliciousness = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0]) == 10\n assert candidate(deliciousness = [1023, 1024, 2047, 2048, 4095, 4096]) == 0\n assert candidate(deliciousness = [21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845]) == 0\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(deliciousness = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == 0\n assert candidate(deliciousness = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 16\n assert candidate(deliciousness = [1, 1048575, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 1\n assert candidate(deliciousness = [0, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845, 21845]) == 0\n assert candidate(deliciousness = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 15\n assert candidate(deliciousness = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512]) == 10\n assert candidate(deliciousness = [1, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 13\n assert candidate(deliciousness = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]) == 3\n assert candidate(deliciousness = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(deliciousness = [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(deliciousness = [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(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128]) == 0\n assert candidate(deliciousness = [3, 5, 7, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 154\n assert candidate(deliciousness = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) == 5\n assert candidate(deliciousness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 90\n assert candidate(deliciousness = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 0\n assert candidate(deliciousness = [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]) == 12\n assert candidate(deliciousness = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000]) == 0\n assert candidate(deliciousness = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(deliciousness = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]) == 61\n assert candidate(deliciousness = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 0\n assert candidate(deliciousness = [1, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 11\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(deliciousness = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 19\n assert candidate(deliciousness = [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]) == 26\n assert candidate(deliciousness = [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]) == 65\n assert candidate(deliciousness = [1, 1, 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, 27, 28, 29, 30, 31, 32]) == 41\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 0\n assert candidate(deliciousness = [1, 2, 3, 4, 5, 6, 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]) == 26\n assert candidate(deliciousness = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128]) == 8\n assert candidate(deliciousness = [15, 9, 8, 7, 3, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 135\n assert candidate(deliciousness = [2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1, 1, 1]) == 6\n assert candidate(deliciousness = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 190\n assert candidate(deliciousness = [22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22]) == 0\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 0\n assert candidate(deliciousness = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0]) == 20\n assert candidate(deliciousness = [65535, 65536, 131071, 131072, 262143, 262144]) == 0\n assert candidate(deliciousness = [2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(deliciousness = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]) == 3\n assert candidate(deliciousness = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 12\n assert candidate(deliciousness = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,3,5,7,9]", "[1,1,1,3,3,3,7]"], "hints": ["Note that the number of powers of 2 is at most 21 so this turns the problem to a classic find the number of pairs that sum to a certain value but for 21 values", "You need to use something fasters than the NlogN approach since there is already the log of iterating over the powers so one idea is two pointers"], "metadata": {"canonical_parameter_names": ["deliciousness"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:18+00:00", "tests_total": 101, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "php", "interface": {"raw_signature": "function countPairs($deliciousness) {", "container": "Solution", "callable": "countPairs", "parameters": [{"name": "deliciousness", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1712, "task_id": "ways-to-split-array-into-three-subarrays", "difficulty": "Medium", "problem_description": "A split of an integer array is good if:\n\n- The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.\n- The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.\n\nGiven nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 10^9+ 7.\n\nExample 1:\n\nInput: nums = [1,1,1]\nOutput: 1\nExplanation: The only good way to split nums is [1] [1] [1].\n\nExample 2:\n\nInput: nums = [1,2,2,2,5,0]\nOutput: 3\nExplanation: There are three good ways of splitting nums:\n[1] [2] [2,2,5,0]\n[1] [2,2] [2,5,0]\n[1,2] [2,2] [5,0]\n\nExample 3:\n\nInput: nums = [3,2,1]\nOutput: 0\nExplanation: There is no good way to split nums.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10000, 10000, 10000]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 12\n assert candidate(nums = [1, 3, 2, 3, 1, 1, 1, 3, 2, 3]) == 9\n assert candidate(nums = [9, 4, 2, 5, 1]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 15\n assert candidate(nums = [1, 3, 2, 4, 1, 2, 3, 4]) == 6\n assert candidate(nums = [1, 1, 1]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 8\n assert candidate(nums = [10, 10, 10, 10, 10]) == 2\n assert candidate(nums = [1, 3, 1, 1, 2]) == 1\n assert candidate(nums = [3, 2, 1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 6\n assert candidate(nums = [1, 2, 2, 2, 5, 0]) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 2]) == 0\n assert candidate(nums = [1, 3, 2, 2, 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]) == 160\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 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]) == 74\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 292\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]) == 37\n assert candidate(nums = [1000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000]) == 34\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]) == 463\n assert candidate(nums = [10000, 10000, 10000, 10000, 0, 10000, 10000, 10000, 10000]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 184\n assert candidate(nums = [10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == 4\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 28\n assert candidate(nums = [1, 3, 5, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 163\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 171\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 320\n assert candidate(nums = [1, 3, 2, 4, 2, 3, 4, 2, 5, 1]) == 9\n assert candidate(nums = [9, 3, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 3, 5, 7, 3]) == 26\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 33\n assert candidate(nums = [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]) == 108\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 33\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 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]) == 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, 21, 22, 23, 24, 25]) == 110\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 24\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 16\n assert candidate(nums = [100, 50, 50, 25, 25, 25, 25, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 8\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 53\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]) == 71\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]) == 406\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 33\n assert candidate(nums = [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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 184\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 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]) == 171\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 71\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 385\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]) == 91\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 36\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 163\n assert candidate(nums = [1, 3, 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]) == 39\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 31\n assert candidate(nums = [5, 1, 4, 2, 2, 1]) == 1\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 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]) == 75\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]) == 75\n assert candidate(nums = [1, 10000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 31\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 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]) == 154\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984, 9983, 9982, 9981, 9980]) == 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]) == 70\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 16\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 21\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]) == 161\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 70\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 19\n assert candidate(nums = [100, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 46\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 37\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 21\n", "comparison": "exact"}, "public_tests": ["[1,1,1]", "[1,2,2,2,5,0]", "[3,2,1]"], "hints": ["Create a prefix array to efficiently find the sum of subarrays.", "As we are dividing the array into three subarrays, there are two \"walls\". Iterate over the right wall positions and find where the left wall could be for each right wall position.", "Use binary search to find the left-most position and right-most position the left wall could be."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().waysToSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:21+00:00", "tests_total": 93, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function waysToSplit($nums) {", "container": "Solution", "callable": "waysToSplit", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1713, "task_id": "minimum-operations-to-make-a-subsequence", "difficulty": "Hard", "problem_description": "You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.\n\nIn one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.\n\nReturn the minimum number of operations needed to make target a subsequence of arr.\n\nA 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. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.\n\nExample 1:\n\nInput: target = [5,1,3], arr = [9,4,2,3,4]\nOutput: 2\nExplanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.\n\nExample 2:\n\nInput: target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\nOutput: 3\n\nConstraints:\n\n- 1 <= target.length, arr.length <= 10^5\n- 1 <= target[i], arr[i] <= 10^9\n- target contains no duplicates.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 4, 3, 2, 1]) == 4\n assert candidate(target = [3, 1, 5, 8, 9],arr = [1, 5, 3, 8, 9]) == 1\n assert candidate(target = [1],arr = [1, 1, 1, 1]) == 0\n assert candidate(target = [6, 4, 8, 1, 3, 2],arr = [4, 7, 6, 2, 3, 8, 6, 1]) == 3\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(target = [1, 2, 3],arr = [1, 2, 3, 1, 2, 3]) == 0\n assert candidate(target = [1, 3, 5, 7],arr = [2, 4, 6, 8]) == 4\n assert candidate(target = [1, 2, 3, 4, 5],arr = [1, 2, 3, 4, 5]) == 0\n assert candidate(target = [1, 3, 5, 7, 9],arr = [2, 4, 6, 8, 10]) == 5\n assert candidate(target = [1, 2, 3],arr = [4, 5, 6]) == 3\n assert candidate(target = [10, 20, 30],arr = [10, 15, 20, 25, 30]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 4\n assert candidate(target = [1],arr = [1]) == 0\n assert candidate(target = [10, 20, 30, 40],arr = [10, 20, 5, 30, 40]) == 0\n assert candidate(target = [100, 200, 300],arr = [1, 2, 3, 100, 200, 300]) == 0\n assert candidate(target = [1, 2, 3],arr = [3, 2, 1]) == 2\n assert candidate(target = [5, 1, 3],arr = [9, 4, 2, 3, 4]) == 2\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [100, 200, 300, 400, 500],arr = [100, 500, 200, 400, 300, 100, 500, 200, 400, 300]) == 1\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],arr = [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]) == 12\n assert candidate(target = [1, 2, 3, 4, 5],arr = [2, 3, 1, 4, 5, 2, 3, 1, 4, 5, 2, 3, 1, 4, 5]) == 0\n assert candidate(target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(target = [100, 200, 300, 400, 500],arr = [50, 150, 250, 350, 450, 550, 650, 100, 200, 300, 400, 500]) == 0\n assert candidate(target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [7, 14, 21, 28, 35],arr = [35, 28, 21, 14, 7, 35, 28, 21, 14, 7]) == 3\n assert candidate(target = [1, 2, 3, 4, 5],arr = [3, 1, 2, 4, 5, 3, 1, 2, 4, 5, 3, 1, 2, 4, 5, 3, 1, 2, 4, 5]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(target = [1, 3, 5, 7, 9],arr = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 0\n assert candidate(target = [1, 3, 2, 4],arr = [4, 3, 2, 1, 1, 2, 3, 4]) == 1\n assert candidate(target = [7, 11, 13, 17, 19, 23, 29, 31],arr = [19, 23, 31, 7, 11, 13, 17, 29, 37, 41, 43, 47]) == 3\n assert candidate(target = [7, 11, 15, 20, 25, 30, 35, 40, 45, 50],arr = [50, 45, 40, 35, 30, 25, 20, 15, 11, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49]) == 9\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(target = [1, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41],arr = [41, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 1, 43, 45, 47, 49, 51]) == 19\n assert candidate(target = [5, 3, 8, 12, 9, 11],arr = [3, 5, 8, 12, 9, 11, 14, 15, 16, 17, 18, 19]) == 1\n assert candidate(target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],arr = [10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(target = [1000000000, 999999999, 999999998, 999999997, 999999996],arr = [999999998, 999999997, 999999996, 1000000000, 999999999]) == 2\n assert candidate(target = [7, 5, 3, 1],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 10, 20, 30, 40, 50]) == 5\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 2\n assert candidate(target = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],arr = [1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 10\n assert candidate(target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],arr = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 9\n assert candidate(target = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 1, 9, 7, 3, 2, 8]) == 4\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 1, 3, 2, 4]) == 2\n assert candidate(target = [5, 3, 8, 6, 2, 7, 4, 1],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 1\n assert candidate(target = [1, 10, 100, 1000, 10000, 100000],arr = [10, 100, 1000, 10000, 100000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(target = [1, 5, 9, 13, 17, 21],arr = [21, 17, 13, 9, 5, 1, 14, 10, 6, 2, 18, 12, 8, 4]) == 5\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [10, 90, 20, 80, 30, 70, 40, 60, 50, 100]) == 4\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(target = [5, 1, 4, 2, 3],arr = [1, 5, 4, 2, 3, 1, 5, 4, 2, 3, 1, 5, 4, 2, 3, 1, 5, 4, 2, 3]) == 0\n assert candidate(target = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],arr = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 0\n assert candidate(target = [10, 20, 30, 40, 50, 60],arr = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 0\n assert candidate(target = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991],arr = [1000000000, 999999998, 999999996, 999999994, 999999992, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(target = [1, 10, 100, 1000, 10000],arr = [1, 1, 1, 1, 10, 10, 10, 10, 100, 100, 100, 100, 1000, 1000, 1000, 1000, 10000, 10000, 10000, 10000]) == 0\n assert candidate(target = [1, 5, 10, 15, 20],arr = [1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 10, 10, 10, 15, 15, 20]) == 0\n assert candidate(target = [100, 200, 300, 400, 500],arr = [500, 400, 300, 200, 100, 150, 250, 350, 450, 550]) == 4\n assert candidate(target = [100, 200, 300, 400, 500],arr = [100, 100, 100, 100, 100, 200, 200, 200, 200, 200, 300, 300, 300, 400, 500]) == 0\n assert candidate(target = [5, 7, 9, 11, 13, 15, 17, 19, 21, 23],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) == 0\n assert candidate(target = [1, 5, 3, 4, 2],arr = [2, 3, 1, 4, 5, 1, 2, 3, 4, 5]) == 1\n assert candidate(target = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],arr = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 40, 35, 30, 25, 20, 15, 10, 5, 2, 1]) == 1\n assert candidate(target = [7, 5, 3, 1],arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 3\n assert candidate(target = [1, 3, 5, 7, 9],arr = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 0\n assert candidate(target = [1, 4, 7, 10, 13, 16, 19],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 0\n assert candidate(target = [1, 2, 3, 4, 5],arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 0\n assert candidate(target = [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],arr = [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, 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]) == 0\n assert candidate(target = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],arr = [100, 300, 500, 700, 200, 400, 600, 800, 100, 300, 500, 700]) == 5\n assert candidate(target = [5, 1, 2, 6, 3, 7, 4, 8, 9],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2\n assert candidate(target = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],arr = [3, 5, 1, 6, 2, 9, 4, 1, 5, 3, 5]) == 7\n assert candidate(target = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 1, 2, 3, 4, 5]) == 0\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 8\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [10, 20, 30, 40, 50],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 0\n assert candidate(target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],arr = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == 9\n assert candidate(target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 10\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 0\n assert candidate(target = [23, 1, 7, 11, 2, 14, 6],arr = [7, 14, 4, 14, 13, 2, 6, 1, 23, 13]) == 4\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(target = [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],arr = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 2, 91, 87, 85, 81, 77, 75, 74, 72, 69, 65, 64, 62, 58, 57, 55, 52, 50, 49, 48, 46, 45, 44, 42, 40, 39, 38, 36, 35, 34, 33, 32, 30, 28, 27, 26, 25, 24, 22, 21, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(target = [5, 3, 8, 12, 7],arr = [12, 8, 3, 7, 5, 12, 8, 3, 7, 5]) == 2\n assert candidate(target = [2, 1, 4, 3, 6, 5, 8, 7],arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 4\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],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]) == 24\n assert candidate(target = [5, 1, 3, 2, 4, 6],arr = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == 1\n assert candidate(target = [100, 200, 300, 400, 500, 600, 700, 800, 900],arr = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 9\n assert candidate(target = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],arr = [500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500]) == 4\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 1, 4, 2, 3, 1, 5, 2, 4, 3, 1, 5, 2, 4, 3]) == 0\n assert candidate(target = [100, 200, 300, 400, 500],arr = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 200, 300, 400, 500]) == 0\n assert candidate(target = [1, 2, 3, 4, 5],arr = [3, 1, 2, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 9\n assert candidate(target = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],arr = [5, 6, 10, 11, 15, 16, 20, 21, 25, 26, 30, 31, 35, 36, 40, 41, 45, 46, 50, 51]) == 0\n assert candidate(target = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],arr = [5, 15, 25, 35, 45, 55, 65, 10, 20, 30, 40, 50]) == 4\n assert candidate(target = [1, 2, 3, 4, 5],arr = [5, 1, 4, 2, 3, 5, 1, 4, 2, 3, 5, 1, 4, 2, 3, 5, 1, 4, 2, 3]) == 0\n assert candidate(target = [10, 20, 30, 40, 50],arr = [10, 25, 30, 35, 50, 40]) == 2\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],arr = [1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14]) == 7\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr = [10, 8, 6, 4, 2, 1, 3, 5, 7, 9]) == 5\n assert candidate(target = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],arr = [27, 24, 21, 18, 15, 12, 9, 6, 3, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3]) == 8\n assert candidate(target = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],arr = [1, 9, 17, 25, 33, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 5, 13, 21, 29, 37]) == 4\n assert candidate(target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],arr = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 110, 120]) == 9\n", "comparison": "exact"}, "public_tests": ["[5,1,3]\n[9,4,2,3,4]", "[6,4,8,1,3,2]\n[4,7,6,2,3,8,6,1]"], "hints": ["The problem can be reduced to computing Longest Common Subsequence between both arrays.", "Since one of the arrays has distinct elements, we can consider that these elements describe an arrangement of numbers, and we can replace each element in the other array with the index it appeared at in the first array.", "Then the problem is converted to finding Longest Increasing Subsequence in the second array, which can be done in O(n log n)."], "metadata": {"canonical_parameter_names": ["target", "arr"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:24+00:00", "tests_total": 111, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "greedy", "longest-increasing-subsequence"]}, "language": "php", "interface": {"raw_signature": "function minOperations($target, $arr) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "target", "type": "Integer[]"}, {"name": "arr", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1716, "task_id": "calculate-money-in-leetcode-bank", "difficulty": "Easy", "problem_description": "Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.\n\nHe starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.\n\nGiven n, return the total amount of money he will have in the Leetcode bank at the end of the n^th day.\n\nExample 1:\n\nInput: n = 4\nOutput: 10\nExplanation: After the 4^th day, the total is 1 + 2 + 3 + 4 = 10.\n\nExample 2:\n\nInput: n = 10\nOutput: 37\nExplanation: After the 10^th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2^nd Monday, Hercy only puts in $2.\n\nExample 3:\n\nInput: n = 20\nOutput: 96\nExplanation: After the 20^th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.\n\nConstraints:\n\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 30) == 165\n assert candidate(n = 4) == 10\n assert candidate(n = 20) == 96\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == 74926\n assert candidate(n = 7) == 28\n assert candidate(n = 10) == 37\n assert candidate(n = 29) == 159\n assert candidate(n = 63) == 504\n assert candidate(n = 210) == 3885\n assert candidate(n = 49) == 343\n assert candidate(n = 125) == 1551\n assert candidate(n = 21) == 105\n assert candidate(n = 70) == 595\n assert candidate(n = 100) == 1060\n assert candidate(n = 50) == 351\n assert candidate(n = 300) == 7476\n assert candidate(n = 28) == 154\n assert candidate(n = 60) == 462\n assert candidate(n = 56) == 420\n assert candidate(n = 40) == 250\n assert candidate(n = 600) == 27810\n assert candidate(n = 99) == 1044\n assert candidate(n = 98) == 1029\n assert candidate(n = 2) == 3\n assert candidate(n = 365) == 10791\n assert candidate(n = 80) == 732\n assert candidate(n = 700) == 37450\n assert candidate(n = 8) == 30\n assert candidate(n = 250) == 5335\n assert candidate(n = 777) == 45843\n assert candidate(n = 999) == 74778\n assert candidate(n = 22) == 109\n assert candidate(n = 35) == 210\n assert candidate(n = 140) == 1890\n assert candidate(n = 91) == 910\n assert candidate(n = 150) == 2127\n assert candidate(n = 15) == 66\n assert candidate(n = 180) == 2940\n assert candidate(n = 899) == 60870\n assert candidate(n = 85) == 811\n assert candidate(n = 200) == 3552\n assert candidate(n = 14) == 63\n assert candidate(n = 400) == 12826\n assert candidate(n = 120) == 1446\n assert candidate(n = 500) == 19602\n assert candidate(n = 52) == 370\n assert candidate(n = 90) == 891\n assert candidate(n = 25) == 127\n assert candidate(n = 84) == 798\n", "comparison": "exact"}, "public_tests": ["4", "10", "20"], "hints": ["Simulate the process by keeping track of how much money Hercy is putting in and which day of the week it is, and use this information to deduce how much money Hercy will put in the next day."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().totalMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:29+00:00", "tests_total": 50, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function totalMoney($n) {", "container": "Solution", "callable": "totalMoney", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1717, "task_id": "maximum-score-from-removing-substrings", "difficulty": "Medium", "problem_description": "You are given a string s and two integers x and y. You can perform two types of operations any number of times.\n\n- Remove substring \"ab\" and gain x points.\n - For example, when removing \"ab\" from \"cabxbae\" it becomes \"cxbae\".\n- Remove substring \"ba\" and gain y points.\n - For example, when removing \"ba\" from \"cabxbae\" it becomes \"cabxe\".\n\nReturn the maximum points you can gain after applying the above operations on s.\n\nExample 1:\n\nInput: s = \"cdbcbbaaabab\", x = 4, y = 5\nOutput: 19\nExplanation:\n- Remove the \"ba\" underlined in \"cdbcbbaaabab\". Now, s = \"cdbcbbaaab\" and 5 points are added to the score.\n- Remove the \"ab\" underlined in \"cdbcbbaaab\". Now, s = \"cdbcbbaa\" and 4 points are added to the score.\n- Remove the \"ba\" underlined in \"cdbcbbaa\". Now, s = \"cdbcba\" and 5 points are added to the score.\n- Remove the \"ba\" underlined in \"cdbcba\". Now, s = \"cdbc\" and 5 points are added to the score.\nTotal score = 5 + 4 + 5 + 5 = 19.\n\nExample 2:\n\nInput: s = \"aabbaaxybbaabb\", x = 5, y = 4\nOutput: 20\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- 1 <= x, y <= 10^4\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"ababababababababababababababababababababab\",x = 1,y = 1) == 21\n assert candidate(s = \"abbaabba\",x = 7,y = 8) == 31\n assert candidate(s = \"abababab\",x = 10,y = 10) == 40\n assert candidate(s = \"ababab\",x = 10,y = 10) == 30\n assert candidate(s = \"babaabab\",x = 3,y = 2) == 11\n assert candidate(s = \"aabbcc\",x = 2,y = 2) == 4\n assert candidate(s = \"babaabab\",x = 10,y = 5) == 35\n assert candidate(s = \"abcde\",x = 1,y = 2) == 1\n assert candidate(s = \"baabaa\",x = 3,y = 2) == 5\n assert candidate(s = \"aaaaabbbbb\",x = 7,y = 8) == 35\n assert candidate(s = \"ba\",x = 1,y = 1) == 1\n assert candidate(s = \"aabbcc\",x = 1,y = 1) == 2\n assert candidate(s = \"ab\",x = 1,y = 1) == 1\n assert candidate(s = \"abbaabba\",x = 7,y = 3) == 24\n assert candidate(s = \"abcabcabcabc\",x = 2,y = 3) == 8\n assert candidate(s = \"abababab\",x = 1,y = 1) == 4\n assert candidate(s = \"aabbaaxybbaabb\",x = 5,y = 4) == 20\n assert candidate(s = \"ababababab\",x = 1,y = 1) == 5\n assert candidate(s = \"abcde\",x = 10,y = 20) == 10\n assert candidate(s = \"babaabab\",x = 2,y = 3) == 11\n assert candidate(s = \"cdbcbbaaabab\",x = 4,y = 5) == 19\n assert candidate(s = \"abcde\",x = 100,y = 200) == 100\n assert candidate(s = \"baabbaabba\",x = 500,y = 500) == 2500\n assert candidate(s = \"bbbbbbaaaa\",x = 8,y = 7) == 28\n assert candidate(s = \"ababababab\",x = 1000,y = 1000) == 5000\n assert candidate(s = \"babaab\",x = 10,y = 5) == 25\n assert candidate(s = \"aaaabbbbbaaaaabbbb\",x = 10,y = 15) == 115\n assert candidate(s = \"babababababababababababab\",x = 7,y = 3) == 84\n assert candidate(s = \"abababababababab\",x = 10000,y = 10000) == 80000\n assert candidate(s = \"babbbabbbabbbabbbabbbabb\",x = 15,y = 25) == 150\n assert candidate(s = \"ababbaabababababab\",x = 6,y = 7) == 62\n assert candidate(s = \"aabbaabbaabbba\",x = 1000,y = 1000) == 7000\n assert candidate(s = \"bbabaabababbabaabababbba\",x = 100,y = 50) == 1050\n assert candidate(s = \"babababababa\",x = 10,y = 15) == 90\n assert candidate(s = \"abbaabbaabba\",x = 3,y = 2) == 17\n assert candidate(s = \"bbbbbaaaabbbbbaaaabbbb\",x = 4,y = 6) == 48\n assert candidate(s = \"bbaabbbaaabbba\",x = 10,y = 5) == 55\n assert candidate(s = \"babababababa\",x = 7,y = 7) == 42\n assert candidate(s = \"baabababababab\",x = 5,y = 5) == 35\n assert candidate(s = \"bababababababababababa\",x = 20,y = 20) == 220\n assert candidate(s = \"bababababababababababababababababababababa\",x = 2,y = 3) == 63\n assert candidate(s = \"babababaabababababababab\",x = 1000,y = 1000) == 12000\n assert candidate(s = \"aaaabbbbbaaaaabbbb\",x = 6,y = 9) == 69\n assert candidate(s = \"babaabababab\",x = 1000,y = 500) == 5500\n assert candidate(s = \"abbbabbaaa\",x = 10,y = 5) == 35\n assert candidate(s = \"ababababababababababababababababababababababababa\",x = 1,y = 10000) == 240000\n assert candidate(s = \"aaaaaabbaaabbaaa\",x = 5,y = 5) == 20\n assert candidate(s = \"babbbbabbbbabbbbabbb\",x = 12,y = 15) == 60\n assert candidate(s = \"abababababbababbaabab\",x = 4,y = 4) == 40\n assert candidate(s = \"ababbbbaababba\",x = 100,y = 200) == 1100\n assert candidate(s = \"bbabababababababbaa\",x = 8,y = 6) == 68\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\",x = 100,y = 100) == 1000\n assert candidate(s = \"abababababababababababababababab\",x = 10000,y = 1) == 160000\n assert candidate(s = \"abbaabbaabba\",x = 10,y = 20) == 110\n assert candidate(s = \"zazbzabzbabzbabz\",x = 5,y = 6) == 17\n assert candidate(s = \"bababbbabababa\",x = 1,y = 10000) == 60000\n assert candidate(s = \"abababababababababababababababababab\",x = 2,y = 1) == 36\n assert candidate(s = \"aabbbaaabbbaaabbbaaabbbaa\",x = 15,y = 5) == 170\n assert candidate(s = \"bbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa\",x = 1000,y = 500) == 12000\n assert candidate(s = \"bbaabbabababbaabba\",x = 10,y = 5) == 75\n assert candidate(s = \"ababababababababababababababababababababababababababababa\",x = 10000,y = 10000) == 280000\n assert candidate(s = \"xyzababxyzbaaxyzbaxyz\",x = 15,y = 10) == 50\n assert candidate(s = \"zababxyzab\",x = 4,y = 5) == 13\n assert candidate(s = \"abbbabbbabbbabbbabbbabbb\",x = 20,y = 10) == 120\n assert candidate(s = \"aabbbaaabbbaaabbbaab\",x = 7,y = 3) == 66\n assert candidate(s = \"abababababababababababababababab\",x = 10,y = 10) == 160\n assert candidate(s = \"babababababababa\",x = 1,y = 2) == 16\n assert candidate(s = \"ababababababababababababab\",x = 1,y = 1) == 13\n assert candidate(s = \"abababababababababababababababab\",x = 90,y = 100) == 1590\n assert candidate(s = \"abbbbaabbbbaabbbbaab\",x = 200,y = 300) == 2000\n assert candidate(s = \"abababababababababababababababababababababababababababab\",x = 1,y = 1) == 28\n assert candidate(s = \"abababababababababababababababab\",x = 50,y = 50) == 800\n assert candidate(s = \"babaabababab\",x = 10,y = 15) == 85\n assert candidate(s = \"abbbabababba\",x = 500,y = 400) == 2400\n assert candidate(s = \"babaababbaab\",x = 10,y = 5) == 55\n assert candidate(s = \"xyxzyzyzxzyz\",x = 100,y = 200) == 0\n assert candidate(s = \"ababbaababba\",x = 3,y = 2) == 17\n assert candidate(s = \"ababababababababababababababababab\",x = 1,y = 1) == 17\n assert candidate(s = \"xyxyxyxyxy\",x = 3,y = 3) == 0\n assert candidate(s = \"ababababababababababababababababababababababababababababa\",x = 2,y = 3) == 84\n assert candidate(s = \"babababababababababababababababa\",x = 1000,y = 500) == 15500\n assert candidate(s = \"abbaabbaabbaabbaabbaabbaabbaabba\",x = 25,y = 30) == 475\n assert candidate(s = \"ababababababababababab\",x = 5,y = 5) == 55\n assert candidate(s = \"abababababababababababababababab\",x = 1,y = 100) == 1501\n assert candidate(s = \"abaabbaabbabab\",x = 10000,y = 1) == 70000\n assert candidate(s = \"babbababbababbababbababb\",x = 5,y = 4) == 45\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",x = 1000,y = 2000) == 0\n assert candidate(s = \"bababababababababa\",x = 1,y = 2) == 18\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbbbaaaaaaaaaaabbbbbbbbbbbbb\",x = 15,y = 25) == 425\n assert candidate(s = \"bbaabbababababababababab\",x = 1,y = 9999) == 109989\n assert candidate(s = \"abbaabbaabbaabba\",x = 10,y = 10) == 80\n assert candidate(s = \"aabbaaabaabbaaabaabbaabb\",x = 1,y = 1) == 10\n assert candidate(s = \"bbbababbaabbababbaabbbaabababbbabababababababa\",x = 8000,y = 9000) == 180000\n assert candidate(s = \"babababababababababababababababa\",x = 7,y = 7) == 112\n assert candidate(s = \"babababababababababababababababababababababababababababa\",x = 1000,y = 1000) == 28000\n assert candidate(s = \"abababababababababababababababab\",x = 10,y = 9) == 160\n assert candidate(s = \"bbababababababababababababababab\",x = 100,y = 90) == 1500\n assert candidate(s = \"abbaabbaabbaabbaabbaabbaabbaabba\",x = 6,y = 4) == 94\n assert candidate(s = \"ababbbababababba\",x = 20,y = 15) == 135\n assert candidate(s = \"babbbbabbbbabbaa\",x = 8,y = 6) == 36\n assert candidate(s = \"abbaabbaabbaabbaabba\",x = 8,y = 3) == 75\n assert candidate(s = \"aabababababa\",x = 20,y = 15) == 100\n assert candidate(s = \"ababbaababbaababba\",x = 7,y = 9) == 79\n assert candidate(s = \"ababbbabababbaababababab\",x = 20,y = 10) == 210\n assert candidate(s = \"ababbbbaabab\",x = 5,y = 10) == 45\n assert candidate(s = \"bbbbbaaaaabbbbbbaaaaabbbbb\",x = 1000,y = 500) == 10000\n assert candidate(s = \"baaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbb\",x = 500,y = 1000) == 12500\n assert candidate(s = \"babababababababa\",x = 1,y = 100) == 800\n assert candidate(s = \"bbaaabaaaaba\",x = 20,y = 10) == 60\n assert candidate(s = \"ababababababababababababab\",x = 7,y = 8) == 103\n assert candidate(s = \"aabbbaababaababbbbababba\",x = 3,y = 2) == 32\n assert candidate(s = \"baaababababababaabaababb\",x = 10,y = 20) == 200\n assert candidate(s = \"babababababababaabab\",x = 3,y = 2) == 29\n assert candidate(s = \"bababababababababababababababa\",x = 1,y = 2) == 30\n assert candidate(s = \"abbbbbbbbbaaaaaaaa\",x = 20,y = 18) == 164\n assert candidate(s = \"baabbaabbaabbaabbaabbaabbaabbaab\",x = 30,y = 25) == 475\n assert candidate(s = \"abcabcabcabc\",x = 5,y = 5) == 20\n assert candidate(s = \"ababababababababab\",x = 100,y = 1) == 900\n assert candidate(s = \"baabbaabbaabbaabbaab\",x = 4,y = 3) == 39\n assert candidate(s = \"bbaaabbaaabbaa\",x = 1,y = 10000) == 60000\n assert candidate(s = \"bbbbbaaaaabbbbbaaaaabbbbbaaaaa\",x = 100,y = 1) == 1005\n assert candidate(s = \"abababababababababababa\",x = 50,y = 25) == 550\n assert candidate(s = \"aababababaab\",x = 100,y = 100) == 500\n assert candidate(s = \"babababababa\",x = 2000,y = 2000) == 12000\n assert candidate(s = \"babbbabbaabababbababbaabbbbaabab\",x = 20,y = 15) == 255\n assert candidate(s = \"babababababaab\",x = 8,y = 7) == 55\n assert candidate(s = \"babababababababa\",x = 100,y = 90) == 790\n assert candidate(s = \"aabbbaabbaabbbaabbaabbba\",x = 2,y = 3) == 31\n assert candidate(s = \"babababababababababababababababababa\",x = 1,y = 2) == 36\n assert candidate(s = \"aabbaabbccddeeffgg\",x = 10,y = 20) == 60\n assert candidate(s = \"aaaabbbbbaaaaabbb\",x = 5,y = 3) == 38\n assert candidate(s = \"ababbaababbaab\",x = 6,y = 4) == 40\n assert candidate(s = \"babaababababba\",x = 3,y = 2) == 20\n assert candidate(s = \"abababababababababababab\",x = 9999,y = 1) == 119988\n assert candidate(s = \"baabaabaabaabaabaabaabaabaabaabaab\",x = 5000,y = 4000) == 59000\n assert candidate(s = \"abababababababababab\",x = 1,y = 2) == 19\n assert candidate(s = \"bababababa\",x = 2,y = 3) == 15\n assert candidate(s = \"abbaabbaabbaabbaabbaabba\",x = 10,y = 15) == 175\n assert candidate(s = \"babababababababababababababababababababababababa\",x = 5000,y = 4000) == 119000\n assert candidate(s = \"bbaabaaaabbbbbaaaab\",x = 3,y = 2) == 25\n assert candidate(s = \"ababababababababababababababababababababababababa\",x = 2000,y = 2000) == 48000\n assert candidate(s = \"baababababababababababababababab\",x = 4,y = 4) == 64\n assert candidate(s = \"babababababababababababababababababababababababababababa\",x = 3,y = 2) == 83\n assert candidate(s = \"ababbbabaabbbbab\",x = 7,y = 3) == 42\n assert candidate(s = \"abbaabbaabbaabbaabbaabbaabbaabba\",x = 1000,y = 1000) == 16000\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",x = 1000,y = 2000) == 2000\n assert candidate(s = \"abbbabaababaabbaaaabbbbaaabbabab\",x = 5,y = 6) == 93\n assert candidate(s = \"abababababababababababababababab\",x = 1000,y = 1000) == 16000\n assert candidate(s = \"babababababababababababa\",x = 5,y = 5) == 60\n assert candidate(s = \"ababaababbabbaab\",x = 3,y = 4) == 30\n assert candidate(s = \"babababababababababababababababababababababababababababa\",x = 8,y = 5) == 221\n", "comparison": "exact"}, "public_tests": ["\"cdbcbbaaabab\"\n4\n5", "\"aabbaaxybbaabb\"\n5\n4"], "hints": ["Note that it is always more optimal to take one type of substring before another", "You can use a stack to handle erasures"], "metadata": {"canonical_parameter_names": ["s", "x", "y"], "leetcode_dataset_entry_point": "Solution().maximumGain", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:31+00:00", "tests_total": 154, "tests_dropped": 3, "flags": [], "topic_tags": ["string", "stack", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumGain($s, $x, $y) {", "container": "Solution", "callable": "maximumGain", "parameters": [{"name": "s", "type": "String"}, {"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1718, "task_id": "construct-the-lexicographically-largest-valid-sequence", "difficulty": "Medium", "problem_description": "Given an integer n, find a sequence with elements in the range [1, n] that satisfies all of the following:\n\n- The integer 1 occurs once in the sequence.\n- Each integer between 2 and n occurs twice in the sequence.\n- For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.\n\nThe distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.\n\nReturn the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution.\n\nA sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.\n\nExample 1:\n\nInput: n = 3\nOutput: [3,1,2,3,2]\nExplanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.\n\nExample 2:\n\nInput: n = 5\nOutput: [5,3,1,4,3,5,2,4,2]\n\nConstraints:\n\n- 1 <= n <= 20\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == [3, 1, 2, 3, 2]\n assert candidate(n = 15) == [15, 13, 14, 10, 8, 12, 5, 3, 11, 9, 3, 5, 8, 10, 13, 15, 14, 12, 9, 11, 7, 4, 6, 1, 2, 4, 2, 7, 6]\n assert candidate(n = 4) == [4, 2, 3, 2, 4, 3, 1]\n assert candidate(n = 20) == [20, 18, 19, 15, 13, 17, 10, 16, 7, 5, 3, 14, 12, 3, 5, 7, 10, 13, 15, 18, 20, 19, 17, 16, 12, 14, 11, 9, 4, 6, 8, 2, 4, 2, 1, 6, 9, 11, 8]\n assert candidate(n = 2) == [2, 1, 2]\n assert candidate(n = 1) == [1]\n assert candidate(n = 10) == [10, 8, 6, 9, 3, 1, 7, 3, 6, 8, 10, 5, 9, 7, 4, 2, 5, 2, 4]\n assert candidate(n = 5) == [5, 3, 1, 4, 3, 5, 2, 4, 2]\n assert candidate(n = 8) == [8, 6, 4, 2, 7, 2, 4, 6, 8, 5, 3, 7, 1, 3, 5]\n assert candidate(n = 11) == [11, 9, 10, 6, 4, 1, 7, 8, 4, 6, 9, 11, 10, 7, 5, 8, 2, 3, 2, 5, 3]\n assert candidate(n = 12) == [12, 10, 11, 7, 5, 3, 8, 9, 3, 5, 7, 10, 12, 11, 8, 6, 9, 2, 4, 2, 1, 6, 4]\n assert candidate(n = 16) == [16, 14, 15, 11, 9, 13, 6, 4, 12, 10, 1, 4, 6, 9, 11, 14, 16, 15, 13, 10, 12, 8, 5, 7, 2, 3, 2, 5, 3, 8, 7]\n assert candidate(n = 14) == [14, 12, 13, 9, 7, 11, 4, 1, 10, 8, 4, 7, 9, 12, 14, 13, 11, 8, 10, 6, 3, 5, 2, 3, 2, 6, 5]\n assert candidate(n = 17) == [17, 15, 16, 12, 10, 14, 7, 5, 3, 13, 11, 3, 5, 7, 10, 12, 15, 17, 16, 14, 9, 11, 13, 8, 6, 2, 1, 2, 4, 9, 6, 8, 4]\n assert candidate(n = 18) == [18, 16, 17, 13, 11, 15, 8, 14, 4, 2, 12, 2, 4, 10, 8, 11, 13, 16, 18, 17, 15, 14, 12, 10, 9, 7, 5, 3, 6, 1, 3, 5, 7, 9, 6]\n assert candidate(n = 13) == [13, 11, 12, 8, 6, 4, 9, 10, 1, 4, 6, 8, 11, 13, 12, 9, 7, 10, 3, 5, 2, 3, 2, 7, 5]\n assert candidate(n = 6) == [6, 4, 2, 5, 2, 4, 6, 3, 5, 1, 3]\n assert candidate(n = 7) == [7, 5, 3, 6, 4, 3, 5, 7, 4, 6, 2, 1, 2]\n", "comparison": "exact"}, "public_tests": ["3", "5"], "hints": ["Heuristic algorithm may work."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().constructDistancedSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:33+00:00", "tests_total": 18, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "backtracking"]}, "language": "php", "interface": {"raw_signature": "function constructDistancedSequence($n) {", "container": "Solution", "callable": "constructDistancedSequence", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1719, "task_id": "number-of-ways-to-reconstruct-a-tree", "difficulty": "Hard", "problem_description": "You are given an array pairs, where pairs[i] = [x_i, y_i], and:\n\n- There are no duplicates.\n- x_i < y_i\n\nLet ways be the number of rooted trees that satisfy the following conditions:\n\n- The tree consists of nodes whose values appeared in pairs.\n- A pair [x_i, y_i] exists in pairs if and only if x_i is an ancestor of y_i or y_i is an ancestor of x_i.\n- Note: the tree does not have to be a binary tree.\n\nTwo ways are considered to be different if there is at least one node that has different parents in both ways.\n\nReturn:\n\n- 0 if ways == 0\n- 1 if ways == 1\n- 2 if ways > 1\n\nA rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.\n\nAn ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.\n\nExample 1:\n\nInput: pairs = [[1,2],[2,3]]\nOutput: 1\nExplanation: There is exactly one valid rooted tree, which is shown in the above figure.\n\nExample 2:\n\nInput: pairs = [[1,2],[2,3],[1,3]]\nOutput: 2\nExplanation: There are multiple valid rooted trees. Three of them are shown in the above figures.\n\nExample 3:\n\nInput: pairs = [[1,2],[2,3],[2,4],[1,5]]\nOutput: 0\nExplanation: There are no valid rooted trees.\n\nConstraints:\n\n- 1 <= pairs.length <= 10^5\n- 1 <= x_i< y_i <= 500\n- The elements in pairs are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 5]]) == 0\n assert candidate(pairs = [[1, 3], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2], [3, 4]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3]]) == 1\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [3, 5]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(pairs = [[1, 3], [2, 3], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [1, 4]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]) == 2\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [1, 5]]) == 1\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [4, 5]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [1, 3]]) == 2\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [1, 5]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 14], [4, 15], [4, 16], [4, 17], [5, 18], [5, 19], [5, 20], [5, 21], [6, 22], [6, 23], [6, 24], [7, 25], [7, 26], [7, 27], [8, 28], [8, 29], [8, 30], [9, 31], [9, 32], [9, 33], [10, 34], [10, 35], [10, 36], [11, 37], [11, 38], [11, 39], [12, 40], [12, 41], [12, 42], [13, 43], [13, 44], [13, 45], [14, 46], [14, 47], [14, 48], [15, 49], [15, 50], [15, 51]]) == 0\n assert candidate(pairs = [[1, 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]]) == 0\n assert candidate(pairs = [[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], [9, 17], [10, 18], [11, 19], [12, 20]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16], [9, 17], [9, 18], [10, 19], [10, 20], [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], [21, 41], [21, 42], [22, 43], [22, 44], [23, 45], [23, 46], [24, 47], [24, 48]]) == 0\n assert candidate(pairs = [[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(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17], [12, 18]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [4, 15], [4, 16], [5, 17], [5, 18], [5, 19], [5, 20], [6, 21], [6, 22], [6, 23], [6, 24], [7, 25], [7, 26]]) == 0\n assert candidate(pairs = [[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], [12, 26], [13, 27], [13, 28], [14, 29], [14, 30]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16], [9, 17], [9, 18], [10, 19], [10, 20], [11, 21], [11, 22], [12, 23], [12, 24]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 0\n assert candidate(pairs = [[1, 12], [1, 11], [1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2]]) == 1\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [3, 9], [3, 10], [3, 11], [4, 12], [4, 13], [4, 14], [5, 15], [5, 16], [5, 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], [13, 32], [13, 33], [14, 34], [14, 35], [15, 36], [15, 37], [16, 38], [16, 39], [17, 40], [17, 41]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9], [7, 10], [7, 11]]) == 0\n assert candidate(pairs = [[1, 6], [6, 7], [6, 8], [1, 9], [9, 10], [9, 11], [1, 12], [12, 13], [12, 14]]) == 0\n assert candidate(pairs = [[1, 2], [1, 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]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [4, 5], [1, 6], [6, 7], [6, 8], [8, 9], [9, 10], [1, 11], [11, 12], [12, 13]]) == 0\n assert candidate(pairs = [[1, 3], [3, 5], [5, 7], [3, 6], [6, 8], [1, 2], [2, 4], [4, 9], [9, 10]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 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]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [2, 5], [3, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 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]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 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], [17, 22], [18, 23], [19, 24], [20, 25], [21, 26], [22, 27], [23, 28], [24, 29], [25, 30], [26, 31], [27, 32], [28, 33], [29, 34], [30, 35], [31, 36], [32, 37], [33, 38], [34, 39], [35, 40], [36, 41], [37, 42], [38, 43], [39, 44], [40, 45], [41, 46], [42, 47], [43, 48], [44, 49], [45, 50]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7], [3, 8], [3, 9], [3, 10], [4, 11], [4, 12], [4, 13]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16], [9, 17], [9, 18], [10, 19], [11, 20], [11, 21], [12, 22], [12, 23], [13, 24], [13, 25], [14, 26], [14, 27], [15, 28], [15, 29], [16, 30], [16, 31], [17, 32], [17, 33], [18, 34], [18, 35], [19, 36], [19, 37], [20, 38], [20, 39], [21, 40], [21, 41], [22, 42], [22, 43], [23, 44], [23, 45]]) == 0\n assert candidate(pairs = [[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, 22], [8, 23], [8, 24], [8, 25], [9, 26], [9, 27], [9, 28], [10, 29], [10, 30], [10, 31]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 13], [4, 14], [4, 15], [4, 16], [5, 17], [5, 18], [5, 19], [5, 20], [6, 21], [6, 22], [6, 23], [6, 24], [7, 25], [7, 26], [7, 27], [7, 28], [8, 29], [8, 30], [8, 31], [8, 32]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [4, 10], [5, 11], [6, 12]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 11], [6, 12]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 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]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14], [7, 15], [8, 16], [8, 17]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 14], [4, 15], [4, 16], [4, 17], [5, 18], [5, 19], [5, 20], [5, 21]]) == 0\n assert candidate(pairs = [[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], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 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]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], [10, 11]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 14], [4, 15], [4, 16], [4, 17], [5, 18], [5, 19], [5, 20], [5, 21], [6, 22], [6, 23], [6, 24], [6, 25], [7, 26], [7, 27], [7, 28], [7, 29], [8, 30], [8, 31], [8, 32], [8, 33], [9, 34], [9, 35], [9, 36], [9, 37], [10, 38], [10, 39], [10, 40], [10, 41]]) == 0\n assert candidate(pairs = [[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], [10, 19], [11, 20], [12, 21], [13, 22], [14, 23], [15, 24], [16, 25], [17, 26], [18, 27], [19, 28], [20, 29], [21, 30], [22, 31], [23, 32], [24, 33], [25, 34], [26, 35], [27, 36], [28, 37], [29, 38], [30, 39], [31, 40]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[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], [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]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == 0\n assert candidate(pairs = [[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, 22], [8, 23], [8, 24]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 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], [17, 22], [18, 23], [19, 24], [20, 25]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[1, 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]]) == 0\n assert candidate(pairs = [[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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 26], [25, 27], [26, 28], [27, 29], [28, 30]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 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]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9], [7, 10], [7, 11], [10, 12], [11, 13]]) == 0\n assert candidate(pairs = [[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], [11, 22], [11, 23], [12, 24], [12, 25], [13, 26], [14, 27], [15, 28], [16, 29], [17, 30], [18, 31], [19, 32], [20, 33]]) == 0\n assert candidate(pairs = [[1, 3], [1, 2], [3, 5], [3, 6], [3, 7], [2, 4], [2, 8], [2, 9], [4, 10], [4, 11], [8, 12], [8, 13], [9, 14], [9, 15], [14, 16], [15, 17]]) == 0\n assert candidate(pairs = [[1, 6], [1, 7], [1, 8], [2, 6], [3, 7], [4, 8], [5, 8], [5, 6], [5, 7]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [2, 4], [2, 5], [3, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [5, 13]]) == 0\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == 0\n assert candidate(pairs = [[1, 6], [6, 7], [1, 2], [1, 3], [1, 4], [1, 5], [5, 8], [8, 9]]) == 0\n assert candidate(pairs = [[1, 3], [3, 5], [5, 7], [7, 9], [1, 4], [4, 6], [6, 8], [8, 10], [1, 11], [11, 12], [12, 13], [13, 14]]) == 0\n assert candidate(pairs = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 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]]) == 0\n assert candidate(pairs = [[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]]) == 0\n assert candidate(pairs = [[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\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,3]]", "[[1,2],[2,3],[1,3]]", "[[1,2],[2,3],[2,4],[1,5]]"], "hints": ["Think inductively. The first step is to get the root. Obviously, the root should be in pairs with all the nodes. If there isn't exactly one such node, then there are 0 ways.", "The number of pairs involving a node must be less than or equal to that number of its parent.", "Actually, if it's equal, then there is not exactly 1 way, because they can be swapped.", "Recursively, given a set of nodes, get the node with the most pairs, then this must be a root and have no parents in the current set of nodes."], "metadata": {"canonical_parameter_names": ["pairs"], "leetcode_dataset_entry_point": "Solution().checkWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:36+00:00", "tests_total": 80, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "tree", "graph", "simulation"]}, "language": "php", "interface": {"raw_signature": "function checkWays($pairs) {", "container": "Solution", "callable": "checkWays", "parameters": [{"name": "pairs", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1720, "task_id": "decode-xored-array", "difficulty": "Easy", "problem_description": "There is a hidden integer array arr that consists of n non-negative integers.\n\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].\n\nYou are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].\n\nReturn the original array arr. It can be proved that the answer exists and is unique.\n\nExample 1:\n\nInput: encoded = [1,2,3], first = 1\nOutput: [1,0,2,1]\nExplanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n\nExample 2:\n\nInput: encoded = [6,2,7,3], first = 4\nOutput: [4,2,0,7,4]\n\nConstraints:\n\n- 2 <= n <= 10^4\n- encoded.length == n - 1\n- 0 <= encoded[i] <= 10^5\n- 0 <= first <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(encoded = [10, 5, 15],first = 0) == [0, 10, 15, 0]\n assert candidate(encoded = [0, 0, 0],first = 7) == [7, 7, 7, 7]\n assert candidate(encoded = [9, 5, 6],first = 0) == [0, 9, 12, 10]\n assert candidate(encoded = [10, 5, 15, 20],first = 0) == [0, 10, 15, 0, 20]\n assert candidate(encoded = [3, 1, 2],first = 0) == [0, 3, 2, 0]\n assert candidate(encoded = [12345, 67890, 13579, 24680],first = 98765) == [98765, 111092, 47302, 36301, 60837]\n assert candidate(encoded = [1, 2, 3],first = 1) == [1, 0, 2, 1]\n assert candidate(encoded = [6, 2, 7, 3],first = 4) == [4, 2, 0, 7, 4]\n assert candidate(encoded = [0, 0, 0, 0],first = 5) == [5, 5, 5, 5, 5]\n assert candidate(encoded = [3, 1],first = 5) == [5, 6, 7]\n assert candidate(encoded = [10, 5, 15],first = 3) == [3, 9, 12, 3]\n assert candidate(encoded = [0, 0, 0],first = 5) == [5, 5, 5, 5]\n assert candidate(encoded = [3, 1],first = 2) == [2, 1, 0]\n assert candidate(encoded = [7, 9, 14, 2, 6],first = 8) == [8, 15, 6, 8, 10, 12]\n assert candidate(encoded = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],first = 0) == [0, 65535, 32768, 49151, 40960, 45055, 43008, 44031, 43520, 43775, 43648, 43711, 43680, 43695, 43688, 43691, 43690]\n assert candidate(encoded = [255, 128, 64, 32, 16, 8, 4, 2, 1],first = 255) == [255, 0, 128, 192, 224, 240, 248, 252, 254, 255]\n assert candidate(encoded = [255, 0, 255, 0, 255],first = 1) == [1, 254, 254, 1, 1, 254]\n assert candidate(encoded = [88, 99, 22, 15, 77, 44, 55, 11, 33, 66],first = 3) == [3, 91, 56, 46, 33, 108, 64, 119, 124, 93, 31]\n assert candidate(encoded = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],first = 1) == [1, 0, 2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046, 4094]\n assert candidate(encoded = [5, 5, 5, 5, 5],first = 10) == [10, 15, 10, 15, 10, 15]\n assert candidate(encoded = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],first = 1) == [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]\n assert candidate(encoded = [255, 128, 64, 32, 16, 8, 4, 2, 1],first = 0) == [0, 255, 127, 63, 31, 15, 7, 3, 1, 0]\n assert candidate(encoded = [8, 12, 5, 10, 15],first = 7) == [7, 15, 3, 6, 12, 3]\n assert candidate(encoded = [99, 142, 55, 231, 78, 102, 184, 33, 201, 127],first = 23) == [23, 116, 250, 205, 42, 100, 2, 186, 155, 82, 45]\n assert candidate(encoded = [15, 9, 12, 5, 6, 3, 14, 10],first = 8) == [8, 7, 14, 2, 7, 1, 2, 12, 6]\n assert candidate(encoded = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],first = 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(encoded = [123, 246, 369, 492, 615, 738, 861, 984],first = 100) == [100, 31, 233, 408, 116, 531, 241, 940, 116]\n assert candidate(encoded = [7, 9, 3, 10, 8],first = 2) == [2, 5, 12, 15, 5, 13]\n assert candidate(encoded = [12, 4, 6, 5, 11, 3],first = 8) == [8, 4, 0, 6, 3, 8, 11]\n assert candidate(encoded = [13, 26, 52, 104, 208, 416, 832, 1664, 3328, 6656],first = 7) == [7, 10, 16, 36, 76, 156, 316, 636, 1276, 2556, 5116]\n assert candidate(encoded = [15, 6, 9, 12, 23, 45],first = 10) == [10, 5, 3, 10, 6, 17, 60]\n assert candidate(encoded = [100000, 50000, 25000, 12500, 6250, 3125],first = 15625) == [15625, 113577, 96505, 72017, 76165, 78319, 81370]\n assert candidate(encoded = [4, 13, 5, 10, 3, 7, 1],first = 9) == [9, 13, 0, 5, 15, 12, 11, 10]\n assert candidate(encoded = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768],first = 128) == [128, 384, 896, 1920, 3968, 8064, 16256, 32640, 65408]\n assert candidate(encoded = [100, 200, 50, 250, 10, 300, 150, 225],first = 42) == [42, 78, 134, 180, 78, 68, 360, 510, 287]\n assert candidate(encoded = [5, 10, 15, 20, 25, 30, 35, 40, 45],first = 0) == [0, 5, 15, 0, 20, 13, 19, 48, 24, 53]\n assert candidate(encoded = [0, 0, 0, 0, 0],first = 0) == [0, 0, 0, 0, 0, 0]\n assert candidate(encoded = [255, 128, 64, 32, 16],first = 1) == [1, 254, 126, 62, 30, 14]\n assert candidate(encoded = [10, 10, 10, 10, 10, 10, 10, 10, 10],first = 10) == [10, 0, 10, 0, 10, 0, 10, 0, 10, 0]\n assert candidate(encoded = [0, 1, 0, 1, 0],first = 1) == [1, 1, 0, 0, 1, 1]\n assert candidate(encoded = [8, 3, 12, 5, 9],first = 6) == [6, 14, 13, 1, 4, 13]\n assert candidate(encoded = [99, 101, 97, 95, 103, 109, 100, 98, 94, 96, 92],first = 100) == [100, 7, 98, 3, 92, 59, 86, 50, 80, 14, 110, 50]\n assert candidate(encoded = [14, 7, 11, 12],first = 3) == [3, 13, 10, 1, 13]\n assert candidate(encoded = [31, 41, 59, 26, 53, 58, 97, 93, 23, 84, 62, 64, 33, 83, 27, 95, 8, 4],first = 271) == [271, 272, 313, 258, 280, 301, 279, 374, 299, 316, 360, 342, 278, 311, 356, 383, 288, 296, 300]\n assert candidate(encoded = [2, 3, 1, 4, 5],first = 7) == [7, 5, 6, 7, 3, 6]\n assert candidate(encoded = [231, 45, 67, 89, 101, 123, 145],first = 99) == [99, 132, 169, 234, 179, 214, 173, 60]\n assert candidate(encoded = [7, 5, 3, 1, 9, 11, 13, 15, 17, 19],first = 2) == [2, 5, 0, 3, 2, 11, 0, 13, 2, 19, 0]\n assert candidate(encoded = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],first = 2048) == [2048, 3072, 3584, 3840, 3968, 4032, 4064, 4080, 4088, 4092, 4094, 4095]\n assert candidate(encoded = [8, 6, 10, 12, 14, 16, 18, 20],first = 4) == [4, 12, 10, 0, 12, 2, 18, 0, 20]\n assert candidate(encoded = [2, 3, 2, 3, 2, 3],first = 1) == [1, 3, 0, 2, 1, 3, 0]\n assert candidate(encoded = [8, 13, 7, 10, 15],first = 2) == [2, 10, 7, 0, 10, 5]\n assert candidate(encoded = [7, 7, 7, 7, 7, 7, 7, 7],first = 3) == [3, 4, 3, 4, 3, 4, 3, 4, 3]\n assert candidate(encoded = [14, 11, 7, 15],first = 2) == [2, 12, 7, 0, 15]\n assert candidate(encoded = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],first = 3) == [3, 0, 6, 15, 3, 12, 30, 11, 19, 8, 22, 55, 19]\n assert candidate(encoded = [98765, 43210, 12345, 67890, 54321, 89012, 21043],first = 78901) == [78901, 46584, 7474, 11531, 74809, 126984, 43964, 63887]\n assert candidate(encoded = [7, 13, 14, 12, 17],first = 9) == [9, 14, 3, 13, 1, 16]\n assert candidate(encoded = [16, 32, 64, 128, 256, 512],first = 8) == [8, 24, 56, 120, 248, 504, 1016]\n assert candidate(encoded = [25, 15, 10, 13, 7, 4],first = 8) == [8, 17, 30, 20, 25, 30, 26]\n assert candidate(encoded = [128, 64, 32, 16, 8, 4, 2, 1],first = 255) == [255, 127, 63, 31, 15, 7, 3, 1, 0]\n assert candidate(encoded = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],first = 5) == [5, 0, 10, 5, 17, 8, 22, 53, 29, 48, 2]\n assert candidate(encoded = [255, 128, 64, 32, 16, 8, 4, 2, 1],first = 0) == [0, 255, 127, 63, 31, 15, 7, 3, 1, 0]\n assert candidate(encoded = [1000, 500, 250, 125, 62, 31, 15],first = 1) == [1, 1001, 541, 743, 666, 676, 699, 692]\n assert candidate(encoded = [15, 24, 32, 16, 8, 4, 2],first = 1) == [1, 14, 22, 54, 38, 46, 42, 40]\n assert candidate(encoded = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0],first = 65536) == [65536, 131071, 98304, 114687, 106496, 110591, 108544, 109567, 109056, 109311, 109184, 109247, 109216, 109231, 109224, 109227, 109226, 109226]\n assert candidate(encoded = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],first = 0) == [0, 1, 2, 5, 10, 21, 42, 85, 170, 341, 682]\n assert candidate(encoded = [1, 2, 4, 8, 16, 32, 64, 128],first = 256) == [256, 257, 259, 263, 271, 287, 319, 383, 511]\n assert candidate(encoded = [8, 2, 6, 4, 2, 6, 4],first = 7) == [7, 15, 13, 11, 15, 13, 11, 15]\n assert candidate(encoded = [1023, 2047, 4095, 8191, 16383, 32767, 65535],first = 1) == [1, 1022, 1025, 3070, 5121, 11262, 21505, 44030]\n assert candidate(encoded = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42],first = 1) == [1, 3, 5, 15, 1, 19, 5, 31, 1, 35, 5, 47]\n assert candidate(encoded = [100000, 50000, 25000, 12500, 6250, 3125],first = 1) == [1, 100001, 83441, 74841, 70797, 68839, 65746]\n assert candidate(encoded = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],first = 1) == [1, 4, 14, 1, 21, 12, 18, 49, 25, 52, 6, 49, 13, 76, 10, 65, 17]\n assert candidate(encoded = [1, 0, 1, 0, 1, 0, 1, 0],first = 0) == [0, 1, 1, 0, 0, 1, 1, 0, 0]\n assert candidate(encoded = [3, 5, 6, 1, 7, 4, 2, 8, 0],first = 3) == [3, 0, 5, 3, 2, 5, 1, 3, 11, 11]\n assert candidate(encoded = [9, 5, 7, 3, 8, 6, 2, 4, 1, 0],first = 11) == [11, 2, 7, 0, 3, 11, 13, 15, 11, 10, 10]\n assert candidate(encoded = [0, 1, 0, 1, 0, 1, 0, 1],first = 1) == [1, 1, 0, 0, 1, 1, 0, 0, 1]\n assert candidate(encoded = [2, 3, 1, 4, 5, 6, 7, 8, 9],first = 1) == [1, 3, 0, 1, 5, 0, 6, 1, 9, 0]\n assert candidate(encoded = [30, 15, 25, 35, 45, 55, 65],first = 5) == [5, 27, 20, 13, 46, 3, 52, 117]\n assert candidate(encoded = [23, 54, 12, 9, 17, 33, 20],first = 15) == [15, 24, 46, 34, 43, 58, 27, 15]\n assert candidate(encoded = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97],first = 1) == [1, 100001, 83441, 74841, 70797, 68839, 65746, 67272, 67013, 66627, 66688, 66785]\n assert candidate(encoded = [4, 6, 5, 7, 10, 13],first = 2) == [2, 6, 0, 5, 2, 8, 5]\n assert candidate(encoded = [100000, 90000, 80000, 70000, 60000],first = 50000) == [50000, 83440, 6752, 74464, 13200, 55792]\n assert candidate(encoded = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],first = 3) == [3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6]\n assert candidate(encoded = [12345, 67890, 12345, 67890, 12345],first = 98765) == [98765, 111092, 47302, 35071, 98765, 111092]\n assert candidate(encoded = [98765, 43210, 67890, 12345, 54321, 90123],first = 65432) == [65432, 97877, 120479, 57261, 61332, 15269, 89006]\n assert candidate(encoded = [25, 17, 31, 18, 29, 14],first = 10) == [10, 19, 2, 29, 15, 18, 28]\n assert candidate(encoded = [13, 11, 7, 14, 28, 16, 32],first = 8) == [8, 5, 14, 9, 7, 27, 11, 43]\n assert candidate(encoded = [14, 22, 36, 52, 72, 96, 124],first = 1) == [1, 15, 25, 61, 9, 65, 33, 93]\n assert candidate(encoded = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111],first = 10000) == [10000, 106895, 64183, 120166, 53516, 2063, 42387, 10150, 29032, 23055]\n assert candidate(encoded = [12, 15, 2, 8, 17, 5],first = 3) == [3, 15, 0, 2, 10, 27, 30]\n assert candidate(encoded = [4, 3, 2, 1],first = 5) == [5, 1, 2, 0, 1]\n assert candidate(encoded = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],first = 1) == [1, 0, 3, 4, 11, 20, 43, 84, 171, 340, 683]\n assert candidate(encoded = [2047, 4094, 2047, 4094, 2047, 4094, 2047],first = 4095) == [4095, 2048, 2046, 1, 4095, 2048, 2046, 1]\n assert candidate(encoded = [13, 9, 16, 22, 10, 19, 7, 12],first = 4) == [4, 9, 0, 16, 6, 12, 31, 24, 20]\n assert candidate(encoded = [32767, 16383, 8191, 4095, 2047],first = 1024) == [1024, 31743, 17408, 23551, 21504, 21503]\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n1", "[6,2,7,3]\n4"], "hints": ["Since that encoded[i] = arr[i] XOR arr[i+1], then arr[i+1] = encoded[i] XOR arr[i].", "Iterate on i from beginning to end, and set arr[i+1] = encoded[i] XOR arr[i]."], "metadata": {"canonical_parameter_names": ["encoded", "first"], "leetcode_dataset_entry_point": "Solution().decode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:38+00:00", "tests_total": 97, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function decode($encoded, $first) {", "container": "Solution", "callable": "decode", "parameters": [{"name": "encoded", "type": "Integer[]"}, {"name": "first", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1722, "task_id": "minimize-hamming-distance-after-swap-operations", "difficulty": "Medium", "problem_description": "You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [a_i, b_i] indicates that you are allowed to swap the elements at index a_i and index b_i (0-indexed) of array source. Note that you can swap elements at a specific pair of indices multiple times and in any order.\n\nThe Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different. Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).\n\nReturn the minimum Hamming distance of source and target after performing any amount of swap operations on array source.\n\nExample 1:\n\nInput: source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\nOutput: 1\nExplanation: source can be transformed the following way:\n- Swap indices 0 and 1: source = [2,1,3,4]\n- Swap indices 2 and 3: source = [2,1,4,3]\nThe Hamming distance of source and target is 1 as they differ in 1 position: index 3.\n\nExample 2:\n\nInput: source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\nOutput: 2\nExplanation: There are no allowed swaps.\nThe Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.\n\nExample 3:\n\nInput: source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\nOutput: 0\n\nConstraints:\n\n- n == source.length == target.length\n- 1 <= n <= 10^5\n- 1 <= source[i], target[i] <= 10^5\n- 0 <= allowedSwaps.length <= 10^5\n- allowedSwaps[i].length == 2\n- 0 <= a_i, b_i <= n - 1\n- a_i != b_i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(source = [4, 3, 2, 1],target = [1, 2, 3, 4],allowedSwaps = [[0, 3], [1, 2], [0, 1], [2, 3]]) == 0\n assert candidate(source = [4, 3, 2, 1],target = [1, 2, 3, 4],allowedSwaps = [[0, 2], [1, 3]]) == 4\n assert candidate(source = [1, 1, 1, 1],target = [1, 1, 1, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3]]) == 0\n assert candidate(source = [1, 2, 3, 4],target = [1, 3, 2, 4],allowedSwaps = []) == 2\n assert candidate(source = [1, 2, 3, 4],target = [2, 1, 4, 5],allowedSwaps = [[0, 1], [2, 3]]) == 1\n assert candidate(source = [5, 1, 2, 4, 3],target = [1, 5, 4, 2, 3],allowedSwaps = [[0, 4], [4, 2], [1, 3], [1, 4]]) == 0\n assert candidate(source = [4, 5, 6],target = [6, 4, 5],allowedSwaps = [[0, 1], [1, 2]]) == 0\n assert candidate(source = [10, 20, 30],target = [30, 20, 10],allowedSwaps = [[0, 2]]) == 0\n assert candidate(source = [1, 1, 1, 1],target = [2, 2, 2, 2],allowedSwaps = [[0, 1], [1, 2], [2, 3]]) == 4\n assert candidate(source = [1, 2, 2, 1],target = [2, 1, 1, 2],allowedSwaps = [[0, 1], [2, 3], [1, 2]]) == 0\n assert candidate(source = [1, 2, 2, 1, 3, 3, 4, 4],target = [4, 4, 3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 6], [1, 7], [2, 5], [3, 4], [0, 1], [2, 3], [4, 5], [6, 7]]) == 2\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],allowedSwaps = [[0, 2], [2, 4], [4, 6], [6, 8], [1, 3], [3, 5], [5, 7], [7, 9]]) == 4\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(source = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [1, 6], [2, 3], [3, 2], [4, 1], [5, 0]]) == 0\n assert candidate(source = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],target = [99991, 99992, 99993, 99994, 99995, 99996, 99997, 99998, 99999, 100000],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 2], [1, 3]]) == 0\n assert candidate(source = [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],allowedSwaps = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == 0\n assert candidate(source = [7, 8, 9, 10, 11, 12],target = [12, 11, 10, 9, 8, 7],allowedSwaps = [[0, 5], [1, 4], [2, 3]]) == 0\n assert candidate(source = [1, 3, 5, 7, 9, 11],target = [11, 9, 7, 5, 3, 1],allowedSwaps = [[0, 5], [1, 4], [2, 3]]) == 0\n assert candidate(source = [1, 3, 5, 7, 9, 11, 13, 15],target = [15, 13, 11, 9, 7, 5, 3, 1],allowedSwaps = [[0, 7], [1, 6], [2, 5], [3, 4]]) == 0\n assert candidate(source = [5, 5, 5, 5, 5, 5],target = [5, 5, 5, 5, 5, 5],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(source = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = []) == 10\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 1], [2, 3], [4, 6]]) == 0\n assert candidate(source = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],target = [8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 15], [1, 14], [2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8], [0, 7], [1, 6], [2, 5], [3, 4]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],allowedSwaps = [[0, 1]]) == 9\n assert candidate(source = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 4], [1, 3], [2, 8], [5, 7], [6, 9]]) == 8\n assert candidate(source = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 1], [2, 3], [4, 5], [6, 7]]) == 8\n assert candidate(source = [10, 20, 30, 40, 50, 60],target = [60, 20, 50, 40, 30, 10],allowedSwaps = [[0, 5], [2, 4], [0, 2]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9],target = [9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 8], [1, 7], [2, 6], [3, 5]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 6\n assert candidate(source = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],allowedSwaps = []) == 0\n assert candidate(source = [7, 8, 9, 10, 11, 12, 13],target = [13, 12, 11, 10, 9, 8, 7],allowedSwaps = [[0, 6], [1, 5], [2, 4], [0, 3]]) == 0\n assert candidate(source = [10, 20, 30, 40, 50],target = [50, 40, 30, 20, 10],allowedSwaps = [[0, 4], [1, 3]]) == 0\n assert candidate(source = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],allowedSwaps = []) == 10\n assert candidate(source = [1, 1, 2, 2, 3, 3],target = [3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 2], [0, 4], [1, 3], [1, 5]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == 20\n assert candidate(source = [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],allowedSwaps = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 7], [1, 6], [2, 5], [3, 4]]) == 0\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == 10\n assert candidate(source = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [1, 5], [2, 6], [3, 7], [0, 8], [1, 9], [2, 5], [3, 6], [4, 7]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],allowedSwaps = [[0, 1], [1, 9], [9, 8]]) == 7\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 1], [2, 3], [4, 6], [7, 8]]) == 0\n assert candidate(source = [3, 2, 1, 4, 5],target = [5, 4, 3, 2, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = [20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10],allowedSwaps = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 16\n assert candidate(source = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(source = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [4, 1, 3, 2],target = [2, 3, 1, 4],allowedSwaps = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3]]) == 0\n assert candidate(source = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 1], [2, 3], [4, 6], [7, 8]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],allowedSwaps = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 13], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == 0\n assert candidate(source = [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],allowedSwaps = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 13], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == 0\n assert candidate(source = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],target = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],allowedSwaps = [[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(source = [7, 8, 9, 10, 11, 12],target = [10, 11, 12, 7, 8, 9],allowedSwaps = [[0, 3], [1, 4], [2, 5]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],allowedSwaps = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == 10\n assert candidate(source = [1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [1, 5], [2, 6], [3, 7]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [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],allowedSwaps = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == 0\n assert candidate(source = [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],allowedSwaps = [[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(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],target = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],allowedSwaps = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == 0\n assert candidate(source = [10, 20, 30, 40, 50, 60],target = [60, 50, 40, 30, 20, 10],allowedSwaps = [[0, 5], [1, 4], [2, 3]]) == 0\n assert candidate(source = [1, 1, 2, 2, 3, 3, 4, 4],target = [4, 4, 3, 3, 2, 2, 1, 1],allowedSwaps = [[0, 6], [1, 7], [2, 5], [3, 4]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9],target = [9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 8], [1, 7], [2, 6], [3, 5]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],target = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],allowedSwaps = [[0, 15], [1, 14], [2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8]]) == 0\n assert candidate(source = [100000, 90000, 80000, 70000],target = [70000, 80000, 90000, 100000],allowedSwaps = [[0, 3], [1, 2], [0, 1], [2, 3]]) == 0\n assert candidate(source = [4, 4, 4, 4, 4],target = [1, 2, 3, 4, 5],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4\n assert candidate(source = [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],allowedSwaps = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [10, 2, 9, 3, 8, 4, 7, 5, 6, 1],allowedSwaps = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 5\n assert candidate(source = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == 10\n assert candidate(source = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],target = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5],allowedSwaps = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 1], [2, 3], [4, 8], [5, 7]]) == 0\n assert candidate(source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],allowedSwaps = []) == 0\n assert candidate(source = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],allowedSwaps = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n[2,1,4,5]\n[[0,1],[2,3]]", "[1,2,3,4]\n[1,3,2,4]\n[]", "[5,1,2,4,3]\n[1,5,4,2,3]\n[[0,4],[4,2],[1,3],[1,4]]"], "hints": ["The source array can be imagined as a graph where each index is a node and each allowedSwaps[i] is an edge.", "Nodes within the same component can be freely swapped with each other.", "For each component, find the number of common elements. The elements that are not in common will contribute to the total Hamming distance."], "metadata": {"canonical_parameter_names": ["source", "target", "allowedSwaps"], "leetcode_dataset_entry_point": "Solution().minimumHammingDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:43+00:00", "tests_total": 83, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "depth-first-search", "union-find"]}, "language": "php", "interface": {"raw_signature": "function minimumHammingDistance($source, $target, $allowedSwaps) {", "container": "Solution", "callable": "minimumHammingDistance", "parameters": [{"name": "source", "type": "Integer[]"}, {"name": "target", "type": "Integer[]"}, {"name": "allowedSwaps", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1723, "task_id": "find-minimum-time-to-finish-all-jobs", "difficulty": "Hard", "problem_description": "You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the i^th job.\n\nThere are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.\n\nReturn the minimum possible maximum working time of any assignment.\n\nExample 1:\n\nInput: jobs = [3,2,3], k = 3\nOutput: 3\nExplanation: By assigning each person one job, the maximum time is 3.\n\nExample 2:\n\nInput: jobs = [1,2,4,7,8], k = 2\nOutput: 11\nExplanation: Assign the jobs the following way:\nWorker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\nWorker 2: 4, 7 (working time = 4 + 7 = 11)\nThe maximum working time is 11.\n\nConstraints:\n\n- 1 <= k <= jobs.length <= 12\n- 1 <= jobs[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(jobs = [1, 2, 4, 7, 8],k = 2) == 11\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 4) == 20\n assert candidate(jobs = [6, 5, 4, 3, 2, 1],k = 6) == 6\n assert candidate(jobs = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 20\n assert candidate(jobs = [10, 20, 30, 40, 50, 60],k = 3) == 70\n assert candidate(jobs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 12) == 10\n assert candidate(jobs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 3\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 6) == 13\n assert candidate(jobs = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 6) == 18\n assert candidate(jobs = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 10\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 12) == 120\n assert candidate(jobs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 12) == 1\n assert candidate(jobs = [3, 2, 3],k = 3) == 3\n assert candidate(jobs = [5, 5, 3, 2, 4, 1],k = 3) == 7\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 26\n assert candidate(jobs = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 15\n assert candidate(jobs = [12, 3, 5, 8, 9, 4, 7, 6, 2, 10, 11, 1],k = 5) == 16\n assert candidate(jobs = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 6) == 100\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 5) == 160\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 7) == 12\n assert candidate(jobs = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000],k = 2) == 39000\n assert candidate(jobs = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 2) == 18\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 7) == 120\n assert candidate(jobs = [10000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 4) == 10000000\n assert candidate(jobs = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],k = 4) == 40\n assert candidate(jobs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 3) == 130\n assert candidate(jobs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 4) == 36\n assert candidate(jobs = [3, 7, 1, 10, 5, 2, 8, 6, 4, 9, 11, 12],k = 5) == 16\n assert candidate(jobs = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 4) == 11\n assert candidate(jobs = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000],k = 6) == 20000000\n assert candidate(jobs = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],k = 6) == 24\n assert candidate(jobs = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 1) == 36\n assert candidate(jobs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 5) == 1600\n assert candidate(jobs = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 8) == 12\n assert candidate(jobs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 12) == 23\n assert candidate(jobs = [30, 15, 40, 10, 25, 5, 60, 45, 20, 50, 55, 35],k = 5) == 80\n assert candidate(jobs = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 1) == 12000000\n assert candidate(jobs = [20, 10, 30, 25, 15, 5, 40, 35, 50, 100, 200, 50],k = 3) == 200\n assert candidate(jobs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14],k = 3) == 28\n assert candidate(jobs = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],k = 6) == 56\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 4) == 200\n assert candidate(jobs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 6) == 65\n assert candidate(jobs = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],k = 4) == 38\n assert candidate(jobs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 6) == 4\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 2) == 390\n assert candidate(jobs = [9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 10],k = 4) == 20\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 2) == 39\n assert candidate(jobs = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84],k = 4) == 140\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 1) == 78\n assert candidate(jobs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 11) == 1200\n assert candidate(jobs = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 7) == 12\n assert candidate(jobs = [1000, 1000, 1000, 1000, 2000, 2000, 2000, 2000, 3000, 3000, 3000, 3000],k = 8) == 3000\n assert candidate(jobs = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 4) == 200\n assert candidate(jobs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 3) == 8\n assert candidate(jobs = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],k = 4) == 60\n assert candidate(jobs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 5) == 30\n assert candidate(jobs = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 12\n assert candidate(jobs = [2, 5, 10, 17, 26, 37, 50, 65, 82, 101, 122, 145],k = 4) == 168\n assert candidate(jobs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 8) == 4\n assert candidate(jobs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 12) == 1200\n assert candidate(jobs = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000],k = 2) == 39000\n assert candidate(jobs = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84],k = 6) == 91\n assert candidate(jobs = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 13\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 2) == 390\n assert candidate(jobs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],k = 5) == 2048\n assert candidate(jobs = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 11],k = 6) == 13\n assert candidate(jobs = [1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000],k = 4) == 5000\n assert candidate(jobs = [7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1],k = 2) == 17\n assert candidate(jobs = [10000000, 10000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 10000000\n assert candidate(jobs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37],k = 3) == 66\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 3) == 260\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 4) == 200\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 12) == 12\n assert candidate(jobs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 8) == 20\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 3) == 260\n assert candidate(jobs = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 8) == 14\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 4) == 20\n assert candidate(jobs = [3, 5, 7, 12, 4, 8, 9, 11, 6, 10, 2, 1],k = 3) == 26\n assert candidate(jobs = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3],k = 5) == 11\n assert candidate(jobs = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 3) == 14\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 12) == 120\n assert candidate(jobs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 4) == 36\n assert candidate(jobs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 6) == 1300\n assert candidate(jobs = [10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, 1, 1, 1, 1],k = 7) == 10000000\n assert candidate(jobs = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5],k = 6) == 7\n assert candidate(jobs = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 4) == 11\n assert candidate(jobs = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115],k = 5) == 150\n assert candidate(jobs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],k = 3) == 2048\n assert candidate(jobs = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1],k = 5) == 10\n assert candidate(jobs = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 26\n assert candidate(jobs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 11],k = 4) == 20\n assert candidate(jobs = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 6) == 14\n assert candidate(jobs = [7, 2, 8, 9, 4, 3, 6, 1, 5, 10, 11, 12],k = 3) == 26\n assert candidate(jobs = [10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, 1, 1, 1, 1],k = 3) == 10000000\n assert candidate(jobs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 3) == 40\n assert candidate(jobs = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],k = 4) == 8\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 12) == 12\n assert candidate(jobs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 8) == 60\n assert candidate(jobs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 6) == 130\n assert candidate(jobs = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 5) == 18\n assert candidate(jobs = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],k = 4) == 14\n assert candidate(jobs = [9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 20, 25],k = 5) == 25\n assert candidate(jobs = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],k = 3) == 56\n assert candidate(jobs = [5, 7, 12, 18, 23, 30, 37, 40, 45, 50, 55, 60],k = 3) == 128\n assert candidate(jobs = [10000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 5) == 10000000\n assert candidate(jobs = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000, 100000, 10000],k = 6) == 10000000\n assert candidate(jobs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 1) == 78\n assert candidate(jobs = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144],k = 9) == 144\n assert candidate(jobs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37],k = 5) == 40\n assert candidate(jobs = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062, 19531, 9765, 4882],k = 3) == 10000000\n", "comparison": "exact"}, "public_tests": ["[3,2,3]\n3", "[1,2,4,7,8]\n2"], "hints": ["We can select a subset of tasks and assign it to a worker then solve the subproblem on the remaining tasks"], "metadata": {"canonical_parameter_names": ["jobs", "k"], "leetcode_dataset_entry_point": "Solution().minimumTimeRequired", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:45+00:00", "tests_total": 111, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function minimumTimeRequired($jobs, $k) {", "container": "Solution", "callable": "minimumTimeRequired", "parameters": [{"name": "jobs", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1725, "task_id": "number-of-rectangles-that-can-form-the-largest-square", "difficulty": "Easy", "problem_description": "You are given an array rectangles where rectangles[i] = [l_i, w_i] represents the i^th rectangle of length l_i and width w_i.\n\nYou can cut the i^th rectangle to form a square with a side length of k if both k <= l_i and k <= w_i. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.\n\nLet maxLen be the side length of the largest square you can obtain from any of the given rectangles.\n\nReturn the number of rectangles that can make a square with a side length of maxLen.\n\nExample 1:\n\nInput: rectangles = [[5,8],[3,9],[5,12],[16,5]]\nOutput: 3\nExplanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].\nThe largest possible square is of length 5, and you can get it out of 3 rectangles.\n\nExample 2:\n\nInput: rectangles = [[2,3],[3,7],[4,3],[3,7]]\nOutput: 3\n\nConstraints:\n\n- 1 <= rectangles.length <= 1000\n- rectangles[i].length == 2\n- 1 <= l_i, w_i <= 10^9\n- l_i != w_i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rectangles = [[1, 2], [2, 1], [3, 4], [4, 3]]) == 2\n assert candidate(rectangles = [[2, 3], [3, 7], [4, 3], [3, 7]]) == 3\n assert candidate(rectangles = [[5, 8], [3, 9], [5, 12], [16, 5]]) == 3\n assert candidate(rectangles = [[10, 1], [1, 10], [20, 2], [2, 20], [30, 3], [3, 30], [40, 4], [4, 40], [50, 5], [5, 50]]) == 2\n assert candidate(rectangles = [[1, 999999999], [2, 999999998], [3, 999999997], [4, 999999996], [5, 999999995]]) == 1\n assert candidate(rectangles = [[1, 999999999], [2, 999999998], [3, 999999997], [4, 999999996], [5, 999999995]]) == 1\n assert candidate(rectangles = [[2, 4], [4, 2], [3, 6], [6, 3], [4, 8], [8, 4], [5, 10], [10, 5], [6, 12], [12, 6], [7, 14], [14, 7], [8, 16], [16, 8], [9, 18], [18, 9], [10, 20], [20, 10]]) == 2\n assert candidate(rectangles = [[1, 1000000000], [1000000000, 1], [2, 500000000], [500000000, 2]]) == 2\n assert candidate(rectangles = [[3, 1], [1, 3], [4, 2], [2, 4], [5, 3], [3, 5], [6, 4], [4, 6], [7, 5], [5, 7], [8, 6], [6, 8]]) == 2\n assert candidate(rectangles = [[2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8], [10, 11], [11, 10]]) == 2\n assert candidate(rectangles = [[100, 200], [101, 199], [102, 198], [103, 197], [104, 196], [105, 195], [106, 194], [107, 193], [108, 192], [109, 191], [110, 190]]) == 1\n assert candidate(rectangles = [[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]]) == 1\n assert candidate(rectangles = [[1, 1000000000], [1000000000, 1], [2, 999999998], [999999998, 2], [3, 999999996], [999999996, 3], [4, 999999994], [999999994, 4], [5, 999999992], [999999992, 5]]) == 2\n assert candidate(rectangles = [[999999999, 1000000000], [1000000000, 999999999], [1, 1000000000], [1000000000, 1], [2, 999999999], [999999999, 2], [3, 999999998], [999999998, 3], [4, 999999997], [999999997, 4]]) == 2\n assert candidate(rectangles = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 2\n assert candidate(rectangles = [[2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1\n assert candidate(rectangles = [[2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6], [8, 7], [9, 8], [10, 9], [11, 10], [12, 11], [13, 12], [1, 12], [12, 1]]) == 1\n assert candidate(rectangles = [[11, 12], [12, 11], [13, 14], [14, 13], [15, 16], [16, 15], [17, 18], [18, 17], [19, 20], [20, 19]]) == 2\n assert candidate(rectangles = [[10, 20], [20, 10], [30, 40], [40, 30], [50, 60], [60, 50], [70, 80], [80, 70], [90, 100], [100, 90]]) == 2\n assert candidate(rectangles = [[15, 20], [20, 15], [25, 30], [30, 25], [35, 40], [40, 35], [45, 50], [50, 45]]) == 2\n assert candidate(rectangles = [[5, 10], [10, 5], [15, 20], [20, 15], [25, 30], [30, 25], [35, 40], [40, 35]]) == 2\n assert candidate(rectangles = [[1000000000, 1], [1000000000, 2], [1000000000, 3], [1000000000, 4], [1000000000, 5]]) == 1\n", "comparison": "exact"}, "public_tests": ["[[5,8],[3,9],[5,12],[16,5]]", "[[2,3],[3,7],[4,3],[3,7]]"], "hints": ["What is the length of the largest square the can be cut out of some rectangle? It'll be equal to min(rectangle.length, rectangle.width). Replace each rectangle with this value.", "Calculate maxSize by iterating over the given rectangles and maximizing the answer with their values denoted in the first hint.", "Then iterate again on the rectangles and calculate the number whose values = maxSize."], "metadata": {"canonical_parameter_names": ["rectangles"], "leetcode_dataset_entry_point": "Solution().countGoodRectangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:47+00:00", "tests_total": 83, "tests_dropped": 61, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function countGoodRectangles($rectangles) {", "container": "Solution", "callable": "countGoodRectangles", "parameters": [{"name": "rectangles", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1726, "task_id": "tuple-with-same-product", "difficulty": "Medium", "problem_description": "Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.\n\nExample 1:\n\nInput: nums = [2,3,4,6]\nOutput: 8\nExplanation: There are 8 valid tuples:\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\n\nExample 2:\n\nInput: nums = [1,2,4,5,10]\nOutput: 16\nExplanation: There are 16 valid tuples:\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^4\n- All elements in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 16\n assert candidate(nums = [7, 8, 9, 14, 21]) == 0\n assert candidate(nums = [7, 11, 13, 19, 23, 29, 31]) == 0\n assert candidate(nums = [2, 5, 10, 15, 20]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64]) == 56\n assert candidate(nums = [7, 8, 14, 21]) == 0\n assert candidate(nums = [2, 3, 4, 6]) == 8\n assert candidate(nums = [8, 12, 16, 20, 24]) == 8\n assert candidate(nums = [1, 2, 4, 5, 10]) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 72\n assert candidate(nums = [1, 10, 100, 1000]) == 8\n assert candidate(nums = [2, 3, 5, 7, 11, 13]) == 0\n assert candidate(nums = [10, 20, 30, 60]) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 72\n assert candidate(nums = [10, 15, 20, 30, 40, 50, 60, 75, 100, 150, 200, 300, 500, 1000]) == 600\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]) == 536\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 72\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 72\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729]) == 104\n assert candidate(nums = [1, 6, 9, 18, 27, 54, 81]) == 48\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120]) == 784\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 136\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]) == 1664\n assert candidate(nums = [3, 6, 9, 12, 18, 27, 36, 54, 72, 108]) == 256\n assert candidate(nums = [10, 20, 40, 50, 80, 100, 160, 200, 250, 400, 500, 800, 1000, 1600, 2000, 2500, 4000, 5000, 8000, 10000]) == 2784\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == 184\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]) == 248\n assert candidate(nums = [5, 10, 15, 25, 50, 75, 125, 250, 375, 625]) == 176\n assert candidate(nums = [12, 15, 20, 25, 30, 60, 100, 150]) == 40\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]) == 240\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 136\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]) == 536\n assert candidate(nums = [2, 6, 12, 18, 36, 72, 108, 216, 324, 432, 648, 1296]) == 472\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 400\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 400\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 32, 48, 64]) == 112\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120]) == 248\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) == 0\n assert candidate(nums = [2, 5, 10, 25, 50, 125, 250, 625, 1250, 3125, 6250]) == 400\n assert candidate(nums = [1, 2, 3, 4, 6, 8, 12, 24]) == 128\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132]) == 136\n assert candidate(nums = [1, 3, 9, 27, 81, 243, 729]) == 104\n assert candidate(nums = [1, 2, 3, 4, 6, 8, 12, 24]) == 128\n assert candidate(nums = [2, 3, 6, 12, 24, 48, 96, 192, 384, 768]) == 272\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]) == 968\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 72\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]) == 304\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]) == 968\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]) == 968\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209]) == 408\n assert candidate(nums = [2, 3, 5, 6, 10, 15, 30]) == 48\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154]) == 184\n assert candidate(nums = [12, 15, 20, 24, 30, 36, 40, 45, 48, 60, 72, 80, 90, 120, 144, 180, 240, 360, 720]) == 1592\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, 286, 297, 308, 319, 330, 341, 352, 363, 374, 385, 396, 407, 418, 429, 440, 451, 462, 473, 484, 495]) == 4592\n assert candidate(nums = [6, 12, 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]) == 1664\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 60, 100]) == 56\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 536\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 248\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, 529, 552, 575, 598, 621, 644, 667, 690, 713, 736, 759, 782, 805, 828, 851, 874, 897, 920, 943, 966, 989, 1012]) == 4200\n assert candidate(nums = [10, 15, 30, 45, 60, 90, 120, 135, 180, 225]) == 144\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260]) == 536\n assert candidate(nums = [5, 10, 15, 25, 50, 75, 125, 250, 375, 625]) == 176\n assert candidate(nums = [12, 15, 18, 20, 24, 30, 36, 40, 45, 48, 60, 72, 80, 90, 120, 144, 150, 180, 200, 240, 300, 360, 400, 450, 720, 900]) == 4112\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]) == 968\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561]) == 176\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 248\n assert candidate(nums = [5, 10, 15, 20, 25, 50, 100, 200]) == 72\n assert candidate(nums = [5, 10, 15, 20, 25, 50, 75, 100]) == 64\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == 184\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 24, 30, 40, 60, 120]) == 1168\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]) == 72\n assert candidate(nums = [2, 5, 10, 20, 25, 50, 100, 125, 250, 500, 1000, 2500, 5000]) == 608\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 209, 228, 247, 266, 285, 304, 323, 342, 361, 380, 399, 418, 437, 456, 475, 494, 513, 532, 551, 570, 589, 608, 627, 646, 665, 684, 703, 722, 741, 760]) == 3432\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132]) == 136\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 560\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, 754, 783, 812, 841, 870, 899, 928, 957, 986, 1015, 1044, 1073, 1102, 1131, 1160, 1189, 1218, 1247, 1276, 1305, 1334, 1363, 1392, 1421, 1450, 1479, 1508, 1537, 1566, 1595, 1624]) == 7912\n assert candidate(nums = [2, 5, 10, 20, 25, 50, 100, 125, 200, 250, 500, 1000]) == 472\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208]) == 304\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289, 306, 323, 340, 357, 374, 391, 408, 425]) == 968\n assert candidate(nums = [2, 5, 10, 20, 25, 50, 100, 125, 200, 250, 500, 1000, 1250, 2000, 2500, 5000, 10000]) == 1584\n assert candidate(nums = [12, 18, 24, 36, 48, 72, 96, 144, 216, 288, 432, 576, 720, 864, 1152, 1728, 2160, 2592, 3456, 4320]) == 1840\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 1000\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260, 273, 286, 299, 312, 325, 338, 351, 364, 377, 390]) == 1664\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289, 306, 323, 340]) == 536\n assert candidate(nums = [2, 5, 10, 25, 50, 125, 250, 625]) == 128\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60]) == 248\n assert candidate(nums = [5, 10, 15, 20, 25, 50, 100, 200]) == 72\n", "comparison": "exact"}, "public_tests": ["[2,3,4,6]", "[1,2,4,5,10]"], "hints": ["Note that all of the integers are distinct. This means that each time a product is formed it must be formed by two unique integers.", "Count the frequency of each product of 2 distinct numbers. Then calculate the permutations formed."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().tupleSameProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:50+00:00", "tests_total": 105, "tests_dropped": 16, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function tupleSameProduct($nums) {", "container": "Solution", "callable": "tupleSameProduct", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1727, "task_id": "largest-submatrix-with-rearrangements", "difficulty": "Medium", "problem_description": "You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.\n\nReturn the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.\n\nExample 1:\n\nInput: matrix = [[0,0,1],[1,1,1],[1,0,1]]\nOutput: 4\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 4.\n\nExample 2:\n\nInput: matrix = [[1,0,1,0,1]]\nOutput: 3\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 3.\n\nExample 3:\n\nInput: matrix = [[1,1,0],[1,0,1]]\nOutput: 2\nExplanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.\n\nConstraints:\n\n- m == matrix.length\n- n == matrix[i].length\n- 1 <= m * n <= 10^5\n- matrix[i][j] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[0, 1], [1, 0]]) == 1\n assert candidate(matrix = [[1, 1, 0], [1, 0, 1]]) == 2\n assert candidate(matrix = [[0, 0, 1], [1, 1, 1], [1, 0, 1]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 12\n assert candidate(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(matrix = [[1, 0, 1, 0, 1]]) == 3\n assert candidate(matrix = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1], [1, 0, 1, 0], [1, 1, 1, 0]]) == 6\n assert candidate(matrix = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1], [1, 1, 0, 1, 1, 0], [0, 0, 1, 1, 0, 1]]) == 4\n assert candidate(matrix = [[1, 0, 1, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 12\n assert candidate(matrix = [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 4\n assert candidate(matrix = [[1, 0, 0, 0, 0, 0, 1, 0, 1, 1], [0, 1, 1, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 15\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 20\n assert candidate(matrix = [[1, 1, 1, 0, 1, 1, 1], [0, 1, 1, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]]) == 6\n assert candidate(matrix = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1]]) == 4\n assert candidate(matrix = [[1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 0], [1, 0, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 1, 0, 1], [0, 0, 1, 1], [1, 1, 1, 1]]) == 4\n assert candidate(matrix = [[1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 1, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 0]]) == 8\n assert candidate(matrix = [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 0, 1, 1]]) == 4\n assert candidate(matrix = [[1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1]]) == 5\n assert candidate(matrix = [[1, 1, 1, 0, 0], [0, 1, 1, 1, 0], [1, 0, 1, 1, 1]]) == 4\n assert candidate(matrix = [[0, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 16\n assert candidate(matrix = [[1, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1]]) == 12\n assert candidate(matrix = [[1, 1, 1, 1, 0], [1, 0, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 0, 0, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [1, 1, 1, 0, 1]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 1, 1]]) == 10\n assert candidate(matrix = [[1, 1, 1, 0, 0, 1], [0, 1, 1, 1, 1, 0], [1, 1, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0]]) == 6\n assert candidate(matrix = [[1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1], [0, 1, 1, 0, 0, 1]]) == 6\n assert candidate(matrix = [[0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1]]) == 4\n assert candidate(matrix = [[0, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 0, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 12\n assert candidate(matrix = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]]) == 6\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 1, 0, 0, 1, 1], [0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 0, 1]]) == 5\n assert candidate(matrix = [[0, 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]]) == 15\n assert candidate(matrix = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]]) == 6\n assert candidate(matrix = [[1, 1, 1, 0, 1], [0, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[0, 1, 1, 0], [1, 1, 1, 1], [1, 0, 1, 1]]) == 6\n assert candidate(matrix = [[0, 0, 0, 0], [0, 1, 1, 0], [1, 1, 1, 1], [0, 1, 1, 0], [1, 1, 1, 1]]) == 8\n assert candidate(matrix = [[0, 0, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]]) == 4\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 5\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 1, 0], [1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1]]) == 10\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1]]) == 10\n assert candidate(matrix = [[1, 1, 0, 0, 1], [0, 1, 1, 1, 1], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [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(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]]) == 1\n assert candidate(matrix = [[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], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 6\n assert candidate(matrix = [[1, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]]) == 6\n assert candidate(matrix = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 3\n assert candidate(matrix = [[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]]) == 4\n assert candidate(matrix = [[1, 0, 0, 1], [0, 1, 1, 0], [1, 1, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0]]) == 6\n assert candidate(matrix = [[1, 1, 1, 0, 0], [1, 1, 1, 0, 0], [0, 1, 1, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1]]) == 6\n assert candidate(matrix = [[0, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 0, 1], [0, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[0, 0, 0, 1, 1, 1], [0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0]]) == 4\n assert candidate(matrix = [[1, 1, 1], [1, 0, 1], [1, 1, 1], [1, 0, 1], [1, 1, 1], [1, 0, 1]]) == 12\n assert candidate(matrix = [[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 12\n assert candidate(matrix = [[1, 1, 0, 1, 0, 1], [0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 1], [0, 1, 1, 1, 0, 1], [1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 1], [1, 1, 0, 1, 1, 1]]) == 6\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 0, 1]]) == 6\n assert candidate(matrix = [[0, 0, 0, 0, 0, 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]]) == 3\n assert candidate(matrix = [[1, 0, 1, 1, 1], [1, 1, 1, 0, 1], [0, 1, 1, 1, 1]]) == 6\n assert candidate(matrix = [[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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 10\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 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]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1], [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]]) == 8\n assert candidate(matrix = [[1, 0, 1, 1], [0, 1, 0, 1], [1, 1, 0, 0], [1, 1, 1, 1]]) == 4\n assert candidate(matrix = [[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]]) == 20\n assert candidate(matrix = [[1, 1, 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, 1, 1]]) == 12\n assert candidate(matrix = [[1, 0, 0, 1, 1], [1, 1, 1, 1, 0], [0, 1, 1, 1, 1], [1, 1, 0, 1, 1]]) == 6\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 1, 0, 0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1, 1]]) == 10\n assert candidate(matrix = [[0, 1, 1, 1, 0], [1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [1, 0, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 0, 1]]) == 9\n assert candidate(matrix = [[0, 0, 0, 1, 1], [1, 1, 1, 1, 1], [0, 1, 0, 1, 1], [1, 0, 1, 0, 1]]) == 6\n assert candidate(matrix = [[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, 1, 0, 1, 0, 1, 0, 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]]) == 12\n assert candidate(matrix = [[1, 1, 1, 1], [1, 0, 1, 0], [0, 1, 1, 1], [1, 1, 0, 1]]) == 4\n assert candidate(matrix = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0]]) == 7\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1]]) == 9\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 1, 1], [1, 0, 1, 0]]) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 1, 0, 0, 1], [1, 1, 1, 0, 1], [1, 0, 1, 1, 1]]) == 10\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1], [1, 1, 0, 1, 1, 1], [1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 0, 1]]) == 12\n assert candidate(matrix = [[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]]) == 5\n assert candidate(matrix = [[0, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1, 0, 1]]) == 5\n", "comparison": "exact"}, "public_tests": ["[[0,0,1],[1,1,1],[1,0,1]]", "[[1,0,1,0,1]]", "[[1,1,0],[1,0,1]]"], "hints": ["For each column, find the number of consecutive ones ending at each position.", "For each row, sort the cumulative ones in non-increasing order and \"fit\" the largest submatrix."], "metadata": {"canonical_parameter_names": ["matrix"], "leetcode_dataset_entry_point": "Solution().largestSubmatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:52+00:00", "tests_total": 83, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "greedy", "sorting", "matrix"]}, "language": "php", "interface": {"raw_signature": "function largestSubmatrix($matrix) {", "container": "Solution", "callable": "largestSubmatrix", "parameters": [{"name": "matrix", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1728, "task_id": "cat-and-mouse-ii", "difficulty": "Hard", "problem_description": "A game is played by a cat and a mouse named Cat and Mouse.\n\nThe environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.\n\n- Players are represented by the characters 'C'(Cat),'M'(Mouse).\n- Floors are represented by the character '.' and can be walked on.\n- Walls are represented by the character '#' and cannot be walked on.\n- Food is represented by the character 'F' and can be walked on.\n- There is only one of each character 'C', 'M', and 'F' in grid.\n\nMouse and Cat play according to the following rules:\n\n- Mouse moves first, then they take turns to move.\n- During each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.\n- catJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.\n- Staying in the same position is allowed.\n- Mouse can jump over Cat.\n\nThe game can end in 4 ways:\n\n- If Cat occupies the same position as Mouse, Cat wins.\n- If Cat reaches the food first, Cat wins.\n- If Mouse reaches the food first, Mouse wins.\n- If Mouse cannot get to the food within 1000 turns, Cat wins.\n\nGiven a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.\n\nExample 1:\n\nInput: grid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2\nOutput: true\nExplanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.\n\nExample 2:\n\nInput: grid = [\"M.C...F\"], catJump = 1, mouseJump = 4\nOutput: true\n\nExample 3:\n\nInput: grid = [\"M.C...F\"], catJump = 1, mouseJump = 3\nOutput: false\n\nConstraints:\n\n- rows == grid.length\n- cols = grid[i].length\n- 1 <= rows, cols <= 8\n- grid[i][j] consist only of characters 'C', 'M', 'F', '.', and '#'.\n- There is only one of each character 'C', 'M', and 'F' in grid.\n- 1 <= catJump, mouseJump <= 8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = ['...M.', '.F#C.', '.....'],catJump = 2,mouseJump = 2) == True\n assert candidate(grid = ['M....', '.....', 'C.F..'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['C.......', '........', '........', '........', '........', '........', '........', '.......M'],catJump = 5,mouseJump = 5) == False\n assert candidate(grid = ['M......', '#F.C.#.'],catJump = 2,mouseJump = 3) == False\n assert candidate(grid = ['M....', '.F.C.', '.....'],catJump = 1,mouseJump = 1) == True\n assert candidate(grid = ['M....', '.#C..', '..#F.', '.....'],catJump = 3,mouseJump = 1) == False\n assert candidate(grid = ['M....', '.....', '.F.C.'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M.C...F'],catJump = 1,mouseJump = 4) == True\n assert candidate(grid = ['####F', '#C...', 'M....'],catJump = 1,mouseJump = 2) == True\n assert candidate(grid = ['M......', '.......', '..F....', '....C..'],catJump = 3,mouseJump = 4) == True\n assert candidate(grid = ['MC..F', '.....', '.....'],catJump = 2,mouseJump = 2) == False\n assert candidate(grid = ['M.C...F'],catJump = 1,mouseJump = 3) == False\n assert candidate(grid = ['M...F', '#..C.', '......'],catJump = 2,mouseJump = 1) == False\n assert candidate(grid = ['MC..F', '#####'],catJump = 2,mouseJump = 2) == False\n assert candidate(grid = ['.......', '.#....#', '.#....#', '.#.....', '.#....#', '.#....#', 'C......'],catJump = 5,mouseJump = 3) == True\n assert candidate(grid = ['M...', '....', '#...', 'C.F.'],catJump = 1,mouseJump = 3) == True\n assert candidate(grid = ['M....', '.....', '#C.F.', '.....', '.....'],catJump = 3,mouseJump = 2) == False\n assert candidate(grid = ['M...#', '...C.', '.....', '.....', '..F..'],catJump = 2,mouseJump = 2) == True\n assert candidate(grid = ['M....', '.....', '.....', '..C..', '...F.'],catJump = 1,mouseJump = 4) == True\n assert candidate(grid = ['M.....', '......', '......', '......', '......', '......', '...F..', '....C.'],catJump = 4,mouseJump = 2) == False\n assert candidate(grid = ['M...F', '.#C.#', '...#.', '.....', '....#'],catJump = 2,mouseJump = 3) == True\n assert candidate(grid = ['M......', '.......', '.......', '....#..', '....C..', '.......', '....F..'],catJump = 4,mouseJump = 2) == False\n assert candidate(grid = ['M....', '.....', '.....', '...C.', '..#F.'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M......', '.......', '.......', '......#', '....C..', '.......', '....F..'],catJump = 2,mouseJump = 4) == False\n assert candidate(grid = ['M......', '.......', '.....#C', '......#', '.......', '#F.....', '.......'],catJump = 3,mouseJump = 3) == True\n assert candidate(grid = ['.......', '.M.....', '.#C..#.', '.#F..#.', '.#.....', '.#.....', '.......'],catJump = 4,mouseJump = 2) == False\n assert candidate(grid = ['M.......', '........', '........', '........', '........', '.....C..', '........', '........', '.......F'],catJump = 4,mouseJump = 4) == False\n assert candidate(grid = ['M...F', '..#C.', '.....', '.....', '.....'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M........', '........#', '.........', '#........', '........C', '.........', '.......F.'],catJump = 7,mouseJump = 2) == False\n assert candidate(grid = ['.......', '.#....#', '.#....#', '.#C.M#.', '.#....#', '.#....#', '.......'],catJump = 3,mouseJump = 3) == False\n assert candidate(grid = ['M......', '.#....#', '..#F...', '#......', '......C'],catJump = 4,mouseJump = 1) == False\n assert candidate(grid = ['######', '#M...#', '#.#F#.', '#.....', '######'],catJump = 2,mouseJump = 3) == False\n assert candidate(grid = ['M.......', '........', '.####...', '.....#..', '......#F', '........', '........', '.....C..'],catJump = 2,mouseJump = 1) == False\n assert candidate(grid = ['M......', '.......', '.......', '......#', '....C..', '.......', '....F..'],catJump = 4,mouseJump = 2) == False\n assert candidate(grid = ['M........', '.........', '.........', '.........', '.........', '.........', '......C..', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', 'F........'],catJump = 7,mouseJump = 7) == True\n assert candidate(grid = ['M....', '.....', '...C.', '#####', '....F'],catJump = 2,mouseJump = 1) == False\n assert candidate(grid = ['M....', '.....', '.....', '.....', '#....', 'C....', '..F..'],catJump = 4,mouseJump = 3) == False\n assert candidate(grid = ['M....', '.....', '....C', '....F', '.....'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M........', '.........', '.........', '.........', '.........', '.........', '........C', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', 'F........'],catJump = 5,mouseJump = 5) == True\n assert candidate(grid = ['M.....', '......', '......', '......', '......', '......', '...F..', '..C...'],catJump = 4,mouseJump = 2) == False\n assert candidate(grid = ['M....#.', '.#....#', '.#....#', '.#.....', '.#....#', '.#....#', '.F....C'],catJump = 3,mouseJump = 4) == False\n assert candidate(grid = ['M....', '.#C..', '..#F.', '.....'],catJump = 3,mouseJump = 2) == False\n assert candidate(grid = ['.......', '.......', '.......', '...C...', '...M...', '.......', '...F...'],catJump = 5,mouseJump = 5) == True\n assert candidate(grid = ['M..#....', '......#.', '......#C', '......#.', '......#.', '......F.', '........'],catJump = 3,mouseJump = 3) == False\n assert candidate(grid = ['M....', '.####', '..F..', '....C'],catJump = 2,mouseJump = 1) == False\n assert candidate(grid = ['M....F...', '.#..#....', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M.F....', '......C', '......#', '........', '........'],catJump = 3,mouseJump = 2) == True\n assert candidate(grid = ['M....', '.####', '..F..', '....C'],catJump = 1,mouseJump = 1) == False\n assert candidate(grid = ['M........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', 'F........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', 'C........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........'],catJump = 8,mouseJump = 8) == False\n assert candidate(grid = ['M....', '.....', '.F.C.', '.....', '.....'],catJump = 3,mouseJump = 3) == False\n assert candidate(grid = ['M....', '#....', '..C..', '....F', '.....'],catJump = 2,mouseJump = 2) == False\n assert candidate(grid = ['.......', '.#....#', '.#....#', '.#.....', '.#....#', '.#....#', 'F......'],catJump = 3,mouseJump = 3) == False\n assert candidate(grid = ['M......', '.......', '.......', '....C..', '.......', '.......', '......F'],catJump = 2,mouseJump = 3) == False\n assert candidate(grid = ['.........', '.........', '.........', '.........', '........C', '........M', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', 'F........'],catJump = 6,mouseJump = 6) == True\n assert candidate(grid = ['M.......', '........', '........', '...F....', '........', '........', '........', '.......C'],catJump = 6,mouseJump = 2) == False\n assert candidate(grid = ['M....', '#..C.', '...#F', '....#', '.....'],catJump = 2,mouseJump = 2) == False\n assert candidate(grid = ['M....', '.....', '#....', '..C..', '...F.'],catJump = 3,mouseJump = 1) == False\n", "comparison": "exact"}, "public_tests": ["[\"####F\",\"#C...\",\"M....\"]\n1\n2", "[\"M.C...F\"]\n1\n4", "[\"M.C...F\"]\n1\n3"], "hints": ["Try working backward: consider all trivial states you know to be winning or losing, and work backward to determine which other states can be labeled as winning or losing."], "metadata": {"canonical_parameter_names": ["grid", "catJump", "mouseJump"], "leetcode_dataset_entry_point": "Solution().canMouseWin", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:54+00:00", "tests_total": 57, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "dynamic-programming", "graph", "topological-sort", "memoization", "minimax-algorithm", "matrix", "game-theory", "zero-sum-game"]}, "language": "php", "interface": {"raw_signature": "function canMouseWin($grid, $catJump, $mouseJump) {", "container": "Solution", "callable": "canMouseWin", "parameters": [{"name": "grid", "type": "String[]"}, {"name": "catJump", "type": "Integer"}, {"name": "mouseJump", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1732, "task_id": "find-the-highest-altitude", "difficulty": "Easy", "problem_description": "There is a biker going on a road trip. The road trip consists of n + 1 points at various altitudes. The biker starts his trip on point 0 with altitude equal 0.\n\nYou are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1 for all (0 <= i < n). Return the highest altitude of a point.\n\nExample 1:\n\nInput: gain = [-5,1,5,0,-7]\nOutput: 1\nExplanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n\nExample 2:\n\nInput: gain = [-4,-3,-2,-1,4,3,2]\nOutput: 0\nExplanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n\nConstraints:\n\n- n == gain.length\n- 1 <= n <= 100\n- -100 <= gain[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(gain = [4, 3, 2, 1, 0, -1, -2, -3, -4]) == 10\n assert candidate(gain = [-1, -2, -3, -4]) == 0\n assert candidate(gain = [-10, -20, -30, -40, -50]) == 0\n assert candidate(gain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == 145\n assert candidate(gain = [-1, 1, -1, 1, -1, 1]) == 0\n assert candidate(gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(gain = [-5, -4, -3, -2, -1]) == 0\n assert candidate(gain = [5, 5, 5, 5]) == 20\n assert candidate(gain = [-100, 50, -50, 100, -100]) == 0\n assert candidate(gain = [-100, 100, -100, 100, -100]) == 0\n assert candidate(gain = [100, -100, 100, -100, 100]) == 100\n assert candidate(gain = [1, 2, 3, 4, 5]) == 15\n assert candidate(gain = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -100]) == 0\n assert candidate(gain = [-1, -2, -3, -4, -5]) == 0\n assert candidate(gain = [1, -1, 1, -1, 1, -1]) == 1\n assert candidate(gain = [-50, 50, -25, 25, -12, 12]) == 0\n assert candidate(gain = [10, 20, 30, 40, 50]) == 150\n assert candidate(gain = [0, 0, 0, 0, 0]) == 0\n assert candidate(gain = [100, -50, 50, -100, 50]) == 100\n assert candidate(gain = [100, -100, 50, -50, 25, -25]) == 100\n assert candidate(gain = [100, -100, 100, -100]) == 100\n assert candidate(gain = [-5, 1, 5, 0, -7]) == 1\n assert candidate(gain = [0, 0, 0, 0]) == 0\n assert candidate(gain = [50, 50, 50, 50, 50]) == 250\n assert candidate(gain = [-4, -3, -2, -1, 4, 3, 2]) == 0\n assert candidate(gain = [23, -15, 42, -5, 0, 17, -30, 29]) == 62\n assert candidate(gain = [-10, -20, 30, 40, -50, 60, -70, 80, -90, 100]) == 70\n assert candidate(gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(gain = [10, -5, 15, -20, 25, -30, 35, -40]) == 30\n assert candidate(gain = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -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(gain = [100, -100, 100, -100, 100, -100, 100, -100]) == 100\n assert candidate(gain = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5]) == 50\n assert candidate(gain = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20]) == 10\n assert candidate(gain = [100, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -98]) == 100\n assert candidate(gain = [10, -5, 3, 2, -3, 4, -2, 5, -6, 1]) == 14\n assert candidate(gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(gain = [100, -1, 99, -2, 98, -3, 97, -4, 96, -5, 95, -6, 94, -7, 93, -8, 92, -9, 91, -10]) == 910\n assert candidate(gain = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 15\n assert candidate(gain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 55\n assert candidate(gain = [-1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1]) == 0\n assert candidate(gain = [10, -5, 3, 2, -3, 4, -1, -2, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16]) == 18\n assert candidate(gain = [5, -3, 20, -20, 30, -10, 15, -5, 25, -15, 10, -5, 30, -30, 40]) == 87\n assert candidate(gain = [10, 15, 20, 25, 30, 35, 40, 45, 50, -100]) == 270\n assert candidate(gain = [50, -20, 30, -10, 40, -5, 60, -25, 70, -10]) == 190\n assert candidate(gain = [0, 25, -25, 50, -50, 100, -100]) == 100\n assert candidate(gain = [20, 30, -10, -40, 50, 10, -20, 30, -40, 50]) == 80\n assert candidate(gain = [5, 10, 15, 20, 25, -5, -10, -15, -20, -25, 5, 10, 15, 20, 25, -5, -10, -15, -20, -25]) == 75\n assert candidate(gain = [99, -50, 50, -100, 100, -99, 99, -49, 49, -51, 51, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5]) == 99\n assert candidate(gain = [100, -25, 25, -50, 50, -75, 75, -100, 100]) == 100\n assert candidate(gain = [10, -5, 3, -2, 8, -4, 6, -3, 5, -1, 7, -2, 9, -4, 11, -5, 13, -6, 15, -7]) == 55\n assert candidate(gain = [5, 5, 5, 5, 5, -5, -5, -5, -5, -5, 10, 10, -10, -10, 15]) == 25\n assert candidate(gain = [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]) == 210\n assert candidate(gain = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(gain = [5, -5, 5, -5, 5, -5, 5, -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(gain = [100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100, -100, 100]) == 100\n assert candidate(gain = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5]) == 0\n assert candidate(gain = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20]) == 10\n assert candidate(gain = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 15\n assert candidate(gain = [50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, 50, -50, 40, -40, 30, -30, 20, -20, 10, -10]) == 150\n assert candidate(gain = [-5, 5, -5, 5, -5, 5, -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(gain = [0, 20, -10, 5, -3, 15, -10]) == 27\n assert candidate(gain = [10, -5, 3, 8, -2, 15, -7, 20]) == 42\n assert candidate(gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(gain = [-10, -20, -30, -40, -50, 10, 20, 30, 40, 50, -1, -2, -3, -4, -5, 1, 2, 3, 4, 5]) == 0\n assert candidate(gain = [-5, -10, -15, 20, 25, -30, 35, -40, 45, -50, 55, -60, 65, -70, 75, -80, 85, -90, 95]) == 50\n assert candidate(gain = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 50\n assert candidate(gain = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 50\n assert candidate(gain = [99, -99, 98, -98, 97, -97, 96, -96, 95, -95]) == 99\n assert candidate(gain = [-1, 2, -3, 4, -5, 6, -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(gain = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(gain = [5, 10, 15, 20, 25, 30, -5, -10, -15, -20, -25, -30]) == 105\n assert candidate(gain = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == 5\n assert candidate(gain = [100, -50, 25, -12, 50, -25, 60, -30, 70, -35, 80, -40, 90, -45, 100]) == 338\n assert candidate(gain = [-10, 10, -10, 10, -10, 10, -10, 10, -10, 10]) == 0\n assert candidate(gain = [20, -10, 30, -15, 40, -20, 50, -25, 60, -30, 70, -35, 80, -40, 90]) == 265\n assert candidate(gain = [10, -10, 20, -20, 30, -30, 40, -40, 50]) == 50\n assert candidate(gain = [2, 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]) == 17\n assert candidate(gain = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -15, -20, -25, -30, -35, -40, -45, -50]) == 275\n assert candidate(gain = [-10, -20, -30, -40, -50, 50, 40, 30, 20, 10]) == 0\n assert candidate(gain = [1, 1, 1, 1, 1, 1, 1, 1, 1, -10]) == 9\n assert candidate(gain = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(gain = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -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(gain = [-50, 0, 50, 0, -50, 0, 50, 0, -50, 0, 50, 0, -50, 0, 50]) == 0\n assert candidate(gain = [0, 20, -10, 30, -20, 10, -30, 40, -50, 60]) == 50\n assert candidate(gain = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 50\n assert candidate(gain = [100, -50, 50, -50, 100, -50, 50, -50, 100]) == 200\n assert candidate(gain = [100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99, 100, -99]) == 114\n assert candidate(gain = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9]) == 9\n assert candidate(gain = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20]) == 10\n assert candidate(gain = [1, -2, 3, -4, 5, -6, 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(gain = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25]) == 25\n assert candidate(gain = [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]) == 210\n assert candidate(gain = [10, -20, 30, -40, 50, -60, 70]) == 40\n assert candidate(gain = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 50\n assert candidate(gain = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 15\n assert candidate(gain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 55\n assert candidate(gain = [-1, 2, -3, 4, -5, 6, -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]) == 15\n assert candidate(gain = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 10\n assert candidate(gain = [-1, 1, -1, 1, -1, 1, -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(gain = [100, -99, 98, -97, 96, -95, 94, -93, 92, -91, 90, -89, 88, -87, 86, -85, 84, -83, 82, -81, 80]) == 100\n assert candidate(gain = [2, 4, -3, 1, -2, 1, 5, -4, 3, -1, 0, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == 12\n assert candidate(gain = [100, -50, 50, -100, 50, -50, 100, -100, 50, -50]) == 100\n assert candidate(gain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(gain = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 100\n assert candidate(gain = [-50, 50, -50, 50, -50, 50, -50, 50]) == 0\n assert candidate(gain = [-1, 3, -2, 4, -3, 5, -4, 6, -5, 7]) == 10\n", "comparison": "exact"}, "public_tests": ["[-5,1,5,0,-7]", "[-4,-3,-2,-1,4,3,2]"], "hints": ["Let's note that the altitude of an element is the sum of gains of all the elements behind it", "Getting the altitudes can be done by getting the prefix sum array of the given array"], "metadata": {"canonical_parameter_names": ["gain"], "leetcode_dataset_entry_point": "Solution().largestAltitude", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:28:59+00:00", "tests_total": 110, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function largestAltitude($gain) {", "container": "Solution", "callable": "largestAltitude", "parameters": [{"name": "gain", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1733, "task_id": "minimum-number-of-people-to-teach", "difficulty": "Medium", "problem_description": "On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.\n\nYou are given an integer n, an array languages, and an array friendships where:\n\n- There are n languages numbered 1 through n,\n- languages[i] is the set of languages the i^th user knows, and\n- friendships[i] = [u_i, v_i] denotes a friendship between the users u_i and v_i.\n\nYou can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.\n\nNote that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z.\n\nExample 1:\n\nInput: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\nOutput: 1\nExplanation: You can either teach user 1 the second language or user 2 the first language.\n\nExample 2:\n\nInput: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\nOutput: 2\nExplanation: Teach the third language to users 1 and 3, yielding two users to teach.\n\nConstraints:\n\n- 2 <= n <= 500\n- languages.length == m\n- 1 <= m <= 500\n- 1 <= languages[i].length <= n\n- 1 <= languages[i][j] <= n\n- 1 <= u_i < v_i <= languages.length\n- 1 <= friendships.length <= 500\n- All tuples (u_i,v_i) are unique\n- languages[i] contains only unique values\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,languages = [[1], [2], [3], [4]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 3\n assert candidate(n = 3,languages = [[1, 2], [2, 3], [3, 1]],friendships = [[1, 2], [2, 3], [3, 1]]) == 0\n assert candidate(n = 5,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 2,languages = [[1], [2], [1, 2]],friendships = [[1, 2], [1, 3], [2, 3]]) == 1\n assert candidate(n = 4,languages = [[1, 3], [2, 4], [1, 2], [3, 4]],friendships = [[1, 2], [2, 3], [3, 4]]) == 2\n assert candidate(n = 4,languages = [[1], [2], [3], [4]],friendships = [[1, 2], [2, 3], [3, 4], [1, 4]]) == 3\n assert candidate(n = 5,languages = [[1], [2], [3], [4], [5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(n = 3,languages = [[2], [1, 3], [1, 2], [3]],friendships = [[1, 4], [1, 2], [3, 4], [2, 3]]) == 2\n assert candidate(n = 2,languages = [[1, 2], [1, 2]],friendships = [[1, 2]]) == 0\n assert candidate(n = 3,languages = [[1, 2, 3], [2, 3], [1, 3]],friendships = [[1, 2], [2, 3], [1, 3]]) == 0\n assert candidate(n = 5,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == 0\n assert candidate(n = 4,languages = [[1, 2], [3, 4], [1, 3], [2, 4]],friendships = [[1, 2], [1, 3], [2, 3], [3, 4]]) == 2\n assert candidate(n = 5,languages = [[1], [2], [3], [4], [5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == 4\n assert candidate(n = 4,languages = [[1], [2], [3], [4]],friendships = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]) == 3\n assert candidate(n = 10,languages = [[1, 2, 3], [4, 5], [6, 7], [8, 9], [10]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [2, 4], [3, 5]]) == 4\n assert candidate(n = 6,languages = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 1], [6, 2]],friendships = [[1, 2], [3, 4], [5, 6]]) == 4\n assert candidate(n = 4,languages = [[1, 2], [2, 3], [3, 4], [4, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1], [1, 3], [2, 4], [1, 4], [2, 3], [1, 2], [3, 4]]) == 2\n assert candidate(n = 10,languages = [[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, 1], [10, 1, 2]],friendships = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 3\n assert candidate(n = 12,languages = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 1]]) == 11\n assert candidate(n = 6,languages = [[1], [2], [3], [4], [5], [6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 1], [6, 2]]) == 5\n assert candidate(n = 3,languages = [[1, 3], [2], [1, 2], [3, 2]],friendships = [[1, 2], [1, 3], [2, 3], [2, 4], [3, 4]]) == 1\n assert candidate(n = 9,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 1], [9, 2]]) == 7\n assert candidate(n = 5,languages = [[1, 2, 3], [4, 5], [1, 4], [2, 5], [3]],friendships = [[1, 4], [2, 5], [3, 5], [1, 3], [2, 4]]) == 1\n assert candidate(n = 3,languages = [[1], [2], [3], [1, 2], [2, 3], [1, 3]],friendships = [[1, 2], [2, 3], [1, 3], [4, 5], [5, 6], [4, 6]]) == 2\n assert candidate(n = 10,languages = [[1, 2, 3], [4, 5], [6, 7, 8], [9, 10], [1, 5, 9], [2, 6, 10], [3, 7, 4], [8, 1]],friendships = [[1, 2], [3, 4], [5, 6], [7, 8], [1, 5], [2, 6], [3, 7], [4, 8], [5, 7], [6, 8]]) == 5\n assert candidate(n = 8,languages = [[1], [2], [3], [4], [5], [6], [7], [8]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 1], [8, 2]]) == 7\n assert candidate(n = 8,languages = [[1, 2], [3, 4], [5, 6], [7, 8], [1, 3], [2, 4], [5, 7], [6, 8]],friendships = [[1, 3], [2, 4], [5, 7], [6, 8], [1, 5], [2, 6], [3, 7], [4, 8]]) == 6\n assert candidate(n = 8,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 1], [8, 2]]) == 6\n assert candidate(n = 4,languages = [[1, 2], [3, 4], [2, 3], [1, 4]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 2\n assert candidate(n = 9,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1]]) == 0\n assert candidate(n = 5,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == 0\n assert candidate(n = 7,languages = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 1], [7, 1, 2]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 1], [7, 2]]) == 0\n assert candidate(n = 10,languages = [[1, 3, 5], [2, 4, 6], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [1, 4], [2, 5], [3, 6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == 7\n assert candidate(n = 10,languages = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 9\n assert candidate(n = 5,languages = [[1], [2], [3], [4], [5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [2, 4], [3, 5], [4, 1], [5, 2]]) == 4\n assert candidate(n = 3,languages = [[1], [1, 3], [2], [2, 3], [3]],friendships = [[1, 3], [2, 3], [4, 5]]) == 1\n assert candidate(n = 10,languages = [[1, 3, 5], [2, 4, 6], [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 1], [2, 3, 4]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 6\n assert candidate(n = 10,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 0\n assert candidate(n = 15,languages = [[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], [6, 7, 8, 9, 10], [7, 8, 9, 10, 11], [8, 9, 10, 11, 12], [9, 10, 11, 12, 13], [10, 11, 12, 13, 14], [11, 12, 13, 14, 15], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]],friendships = [[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], [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], [15, 2]]) == 2\n assert candidate(n = 5,languages = [[1], [2], [3], [4], [5], [1, 2], [3, 4], [4, 5], [1, 3], [2, 5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 7\n assert candidate(n = 7,languages = [[1, 2], [3, 4], [5, 6], [7], [1, 3], [2, 4], [5, 7]],friendships = [[1, 3], [1, 5], [1, 7], [2, 4], [2, 6], [3, 5], [3, 7], [4, 6], [4, 7], [5, 6]]) == 5\n assert candidate(n = 5,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [2, 4], [3, 5], [4, 1], [5, 2]]) == 3\n assert candidate(n = 10,languages = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],friendships = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 9\n assert candidate(n = 7,languages = [[1, 2, 3, 4], [5, 6], [7], [1, 2], [3, 4], [5, 6], [7]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1]]) == 5\n assert candidate(n = 4,languages = [[1, 2], [2, 3], [3, 4], [4, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 0\n assert candidate(n = 7,languages = [[1], [2], [3], [4], [5], [6], [7]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 1], [7, 2]]) == 6\n assert candidate(n = 8,languages = [[1], [1], [1], [1], [2], [2], [2], [2]],friendships = [[1, 5], [2, 6], [3, 7], [4, 8]]) == 4\n assert candidate(n = 7,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1]],friendships = [[1, 3], [3, 5], [5, 7], [7, 2], [2, 4], [4, 6]]) == 5\n assert candidate(n = 7,languages = [[1], [2], [3], [1, 4], [5, 6], [6, 7], [7]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1]]) == 4\n assert candidate(n = 5,languages = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1], [5, 1, 2]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == 0\n assert candidate(n = 7,languages = [[1, 3, 5], [2, 4, 6], [1, 2, 3], [4, 5, 6], [1, 4, 7], [2, 5, 7], [3, 6, 7]],friendships = [[1, 2], [3, 4], [5, 6], [7, 1], [2, 5], [4, 7], [6, 3]]) == 2\n assert candidate(n = 6,languages = [[1], [2], [3], [4], [5], [6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == 5\n assert candidate(n = 4,languages = [[1, 2], [2, 3], [3, 4], [1, 4]],friendships = [[1, 2], [2, 3], [3, 4], [1, 4]]) == 0\n assert candidate(n = 6,languages = [[1], [2], [3], [4], [5], [6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == 5\n assert candidate(n = 6,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == 0\n assert candidate(n = 3,languages = [[1, 2], [2, 3], [1, 3]],friendships = [[1, 2], [2, 3], [1, 3], [1, 2], [2, 3], [1, 3]]) == 0\n assert candidate(n = 3,languages = [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 0\n assert candidate(n = 4,languages = [[1, 2], [3, 4], [2, 3], [1, 4], [1, 3]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 5]]) == 2\n assert candidate(n = 4,languages = [[1, 2, 3], [2, 3, 4], [3, 4, 1], [4, 1, 2]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 0\n assert candidate(n = 5,languages = [[1, 2, 3, 4, 5]],friendships = [[1, 1], [1, 1], [1, 1]]) == 0\n assert candidate(n = 4,languages = [[1, 2], [2, 3], [3, 4], [1, 4]],friendships = [[1, 2], [2, 3], [3, 4], [4, 1], [1, 3], [2, 4]]) == 2\n assert candidate(n = 10,languages = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],friendships = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 9\n assert candidate(n = 8,languages = [[1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [1, 8]]) == 1\n assert candidate(n = 6,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 6], [1, 3], [2, 4], [3, 5], [4, 6], [1, 5], [2, 6]]) == 4\n assert candidate(n = 5,languages = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [1, 2], [4, 5]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 5]]) == 2\n assert candidate(n = 5,languages = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1], [5, 1, 2]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == 0\n assert candidate(n = 10,languages = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == 0\n assert candidate(n = 6,languages = [[1, 2, 3], [4, 5, 6], [1, 4], [2, 5], [3, 6], [1, 2, 3, 4, 5, 6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 3], [2, 4], [3, 5], [4, 6], [1, 5], [2, 6]]) == 3\n assert candidate(n = 6,languages = [[1], [2], [3], [4], [5], [6]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 1], [6, 2]]) == 5\n assert candidate(n = 12,languages = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12], [1, 5, 9, 12], [2, 6, 10, 11], [3, 4, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]],friendships = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12]]) == 7\n assert candidate(n = 7,languages = [[1], [2], [3], [4], [5], [6], [7]],friendships = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 1], [7, 2]]) == 6\n assert candidate(n = 8,languages = [[1, 2], [3, 4], [5, 6], [7, 8], [1, 3], [2, 4], [5, 7], [6, 8]],friendships = [[1, 2], [3, 4], [5, 6], [7, 8], [1, 3], [2, 4], [5, 7], [6, 8]]) == 6\n assert candidate(n = 5,languages = [[1, 2], [3, 4], [1, 3], [2, 5], [4, 5]],friendships = [[1, 2], [3, 4], [2, 3], [4, 5], [1, 3]]) == 2\n", "comparison": "exact"}, "public_tests": ["2\n[[1],[2],[1,2]]\n[[1,2],[1,3],[2,3]]", "3\n[[2],[1,3],[1,2],[3]]\n[[1,4],[1,2],[3,4],[2,3]]"], "hints": ["You can just use brute force and find out for each language the number of users you need to teach", "Note that a user can appear in multiple friendships but you need to teach that user only once"], "metadata": {"canonical_parameter_names": ["n", "languages", "friendships"], "leetcode_dataset_entry_point": "Solution().minimumTeachings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:01+00:00", "tests_total": 73, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumTeachings($n, $languages, $friendships) {", "container": "Solution", "callable": "minimumTeachings", "parameters": [{"name": "n", "type": "Integer"}, {"name": "languages", "type": "Integer[][]"}, {"name": "friendships", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1734, "task_id": "decode-xored-permutation", "difficulty": "Medium", "problem_description": "There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.\n\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].\n\nGiven the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.\n\nExample 1:\n\nInput: encoded = [3,1]\nOutput: [1,2,3]\nExplanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]\n\nExample 2:\n\nInput: encoded = [6,5,4,6]\nOutput: [2,4,1,5,3]\n\nConstraints:\n\n- 3 <= n < 10^5\n- n is odd.\n- encoded.length == n - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(encoded = [15, 8, 12, 4, 1]) == [11, 4, 12, 0, 4, 5]\n assert candidate(encoded = [1, 7, 6, 5, 4, 3]) == [1, 0, 7, 1, 4, 0, 3]\n assert candidate(encoded = [6, 5, 4, 6]) == [2, 4, 1, 5, 3]\n assert candidate(encoded = [8, 12, 4, 6, 1, 3, 5]) == [1, 9, 5, 1, 7, 6, 5, 0]\n assert candidate(encoded = [2, 3, 1, 4, 7]) == [0, 2, 1, 0, 4, 3]\n assert candidate(encoded = [8, 13, 10, 3, 7, 12, 9]) == [10, 2, 15, 5, 6, 1, 13, 4]\n assert candidate(encoded = [2, 3, 1, 6, 7, 0]) == [5, 7, 4, 5, 3, 4, 4]\n assert candidate(encoded = [1, 5, 7]) == [1, 0, 5, 2]\n assert candidate(encoded = [8, 9, 10, 11, 12, 13, 14]) == [7, 15, 6, 12, 7, 11, 6, 8]\n assert candidate(encoded = [7, 8, 9, 10, 11, 12]) == [14, 9, 1, 8, 2, 9, 5]\n assert candidate(encoded = [15, 10, 5, 2, 1, 4]) == [12, 3, 9, 12, 14, 15, 11]\n assert candidate(encoded = [2, 3, 2]) == [7, 5, 6, 4]\n assert candidate(encoded = [1, 0, 1, 0, 1]) == [7, 6, 6, 7, 7, 6]\n assert candidate(encoded = [7, 3, 5]) == [7, 0, 3, 6]\n assert candidate(encoded = [1, 6, 5, 4, 3, 2]) == [0, 1, 7, 2, 6, 5, 7]\n assert candidate(encoded = [2, 3, 1, 4, 5]) == [0, 2, 1, 0, 4, 1]\n assert candidate(encoded = [3, 1]) == [1, 2, 3]\n assert candidate(encoded = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1002]) == [788, 879, 901, 732, 788, 291, 901, 144, 1002, 111, 901]\n assert candidate(encoded = [14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58]) == [9, 7, 21, 3, 25, 7, 37, 3, 41, 7, 53, 3, 57]\n assert candidate(encoded = [15, 10, 5, 3, 2, 1, 4]) == [0, 15, 5, 0, 3, 1, 0, 4]\n assert candidate(encoded = [5, 10, 15, 20, 25, 30, 35]) == [8, 13, 7, 8, 28, 5, 27, 56]\n assert candidate(encoded = [2, 15, 18, 17, 20, 23, 22, 25, 28]) == [27, 25, 22, 4, 21, 1, 22, 0, 25, 5]\n assert candidate(encoded = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == [3, 2, 0, 3, 7, 2, 4, 3, 11, 2, 8, 3, 15, 2, 12, 3, 19, 2, 16, 3, 23, 2, 20, 3, 27, 2]\n assert candidate(encoded = [77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198]) == [95, 18, 74, 41, 71, 62, 186, 53, 175, 10, 186, 1, 199]\n assert candidate(encoded = [9, 20, 27, 34, 41, 48, 55]) == [14, 7, 19, 8, 42, 3, 51, 4]\n assert candidate(encoded = [7, 2, 5, 8, 3, 6, 1, 4, 9]) == [3, 4, 6, 3, 11, 8, 14, 15, 11, 2]\n assert candidate(encoded = [65, 131, 263, 527, 1055, 2111, 4223, 8447, 16895, 33791, 67583, 135167]) == [173645, 173580, 173711, 173960, 173447, 172440, 174503, 178648, 170279, 186584, 154407, 220376, 86823]\n assert candidate(encoded = [7, 18, 27, 34, 41, 48, 55]) == [8, 15, 29, 6, 36, 13, 61, 10]\n assert candidate(encoded = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323]) == [583287, 583284, 583293, 583270, 583223, 583364, 582685, 584854, 587063, 571860, 548733, 715910, 194423, 1746084]\n assert candidate(encoded = [2, 7, 13, 18, 24, 30, 36, 42, 48, 54, 60]) == [27, 25, 30, 19, 1, 25, 7, 35, 9, 57, 15, 51]\n assert candidate(encoded = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39]) == [39, 36, 35, 40, 39, 52, 35, 56, 39, 4, 35]\n assert candidate(encoded = [31, 34, 37, 40, 43, 46, 49]) == [44, 51, 17, 52, 28, 55, 25, 40]\n assert candidate(encoded = [255, 222, 199, 176, 153, 130, 107, 84]) == [185, 70, 152, 95, 239, 118, 244, 159, 203]\n assert candidate(encoded = [19, 22, 25, 28, 31, 34, 37]) == [32, 51, 37, 60, 32, 63, 29, 56]\n assert candidate(encoded = [15, 22, 13, 20, 9, 16, 11]) == [26, 21, 3, 14, 26, 19, 3, 8]\n assert candidate(encoded = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650]) == [93, 57, 175, 103, 157, 433, 239, 383, 189, 329, 879, 311, 957]\n assert candidate(encoded = [15, 22, 3, 26, 11, 28, 7, 30, 13, 32, 9, 34, 5, 36, 1]) == [56, 55, 33, 34, 56, 51, 47, 40, 54, 59, 27, 18, 48, 53, 17, 16]\n assert candidate(encoded = [8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [3267, 4924, 7363, 6972, 6339, 6460, 6595, 6588, 6531, 6556, 6547, 6548, 6551, 6550]\n assert candidate(encoded = [4, 12, 8, 16, 10, 18, 14]) == [6, 2, 14, 6, 22, 28, 14, 0]\n assert candidate(encoded = [42, 35, 26, 15, 4, 17, 38, 67, 114, 181, 278, 399]) == [325, 367, 332, 342, 345, 349, 332, 362, 297, 347, 494, 248, 375]\n assert candidate(encoded = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [968, 940, 868, 584, 984, 556, 116, 712, 488, 620, 388]\n assert candidate(encoded = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245]) == [250, 5, 251, 6, 250, 1, 251, 2, 250, 13, 251, 14]\n assert candidate(encoded = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304]) == [2796223, 2796219, 2796211, 2796195, 2796163, 2796227, 2796099, 2796355, 2795843, 2796867, 2794819, 2798915, 2790723, 2807107, 2774339, 2839875, 2708803, 2970947, 2446659, 3495235, 1398083, 5592387]\n assert candidate(encoded = [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]) == [14, 2, 12, 28, 14, 26, 12, 20, 14, 18, 12, 44, 14, 42, 12, 36, 14, 34, 12, 60, 14, 58, 12, 52, 14, 50, 12, 76, 14, 74, 12, 68, 14, 66, 12]\n assert candidate(encoded = [24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64]) == [16, 8, 20, 52, 16, 56, 20, 36, 16, 40, 20, 84]\n assert candidate(encoded = [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == [11, 14, 9, 0, 11, 6, 9, 24, 11, 30, 9, 16]\n assert candidate(encoded = [5, 8, 11, 14, 17, 20, 23, 26, 29, 32]) == [40, 45, 37, 46, 32, 49, 37, 50, 40, 53, 21]\n assert candidate(encoded = [17, 19, 21, 23, 25, 27, 29, 31]) == [1, 16, 3, 22, 1, 24, 3, 30, 1]\n assert candidate(encoded = [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [19, 22, 17, 24, 19, 30, 17, 0, 19, 6, 17, 8, 19, 14]\n assert candidate(encoded = [99, 198, 297, 396, 495, 594, 693, 792, 891, 990, 1089]) == [978, 945, 887, 606, 978, 573, 111, 730, 450, 697, 359, 1318]\n assert candidate(encoded = [2047, 4094, 2047, 4094, 2047, 4094, 2047, 4094, 2047, 4094, 2047]) == [4082, 2061, 2035, 12, 4082, 2061, 2035, 12, 4082, 2061, 2035, 12]\n assert candidate(encoded = [2, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == [2097151, 2097149, 2097147, 2097143, 2097135, 2097119, 2097087, 2097023, 2096895, 2096639, 2096127, 2095103, 2093055, 2088959, 2080767, 2064383, 2031615, 1966079, 1835007, 1572863, 1048575]\n assert candidate(encoded = [30, 10, 20, 15, 25, 12, 22, 17, 27, 14, 24, 19, 29, 16, 26]) == [5, 27, 17, 5, 10, 19, 31, 9, 24, 3, 13, 21, 6, 27, 11, 17]\n assert candidate(encoded = [255, 128, 64, 32, 16, 8, 4, 2, 1]) == [161, 94, 222, 158, 190, 174, 166, 162, 160, 161]\n assert candidate(encoded = [15, 22, 33, 46, 59, 74, 91, 110, 131, 154]) == [134, 137, 159, 190, 144, 171, 225, 186, 212, 87, 205]\n assert candidate(encoded = [14, 11, 12, 15, 16, 19, 20, 23, 24, 27]) == [27, 21, 30, 18, 29, 13, 30, 10, 29, 5, 30]\n assert candidate(encoded = [31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == [838849, 838878, 838881, 838814, 838753, 839070, 839265, 838046, 837217, 842142, 845409, 825758, 812641, 891294, 943713, 629150, 419425]\n assert candidate(encoded = [11, 24, 29, 36, 43, 50, 57]) == [6, 13, 21, 8, 44, 7, 53, 12]\n assert candidate(encoded = [13, 22, 31, 40, 49, 58, 67]) == [12, 1, 23, 8, 32, 17, 43, 104]\n assert candidate(encoded = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == [35, 38, 44, 35, 55, 46, 48, 19, 59, 22, 36, 19, 47, 110, 40, 99, 51, 102]\n assert candidate(encoded = [14, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [5, 11, 29, 9, 27, 11, 5, 9, 3, 11, 13, 9, 11]\n assert candidate(encoded = [7, 14, 21, 28, 35, 42, 49]) == [48, 55, 57, 44, 48, 19, 57, 8]\n assert candidate(encoded = [127, 63, 31, 15, 7, 3, 1]) == [59, 68, 123, 100, 107, 108, 111, 110]\n assert candidate(encoded = [27, 24, 21, 18, 15, 12, 9, 6, 3]) == [11, 16, 8, 29, 15, 0, 12, 5, 3, 0]\n assert candidate(encoded = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [409, 614, 921, 870, 793, 806, 825, 822, 817, 818, 819]\n assert candidate(encoded = [31, 28, 33, 30, 35, 32, 37]) == [42, 53, 41, 8, 22, 53, 21, 48]\n assert candidate(encoded = [15, 23, 19, 21, 17, 13, 9, 5, 1]) == [1, 14, 25, 10, 31, 14, 3, 10, 15, 14]\n assert candidate(encoded = [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, 6, 14, 7, 13, 6, 10, 7, 9, 6, 22, 7, 21, 6, 18, 7, 17, 6, 30, 7, 29, 6, 26, 7, 25]\n assert candidate(encoded = [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77]) == [29, 24, 17, 28, 13, 24, 1, 28, 61, 24, 49, 28, 45, 24, 33, 28, 93, 24, 81, 28]\n assert candidate(encoded = [4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [1639, 2456, 3687, 3480, 3175, 3224, 3303, 3288, 3271, 3272, 3279, 3276, 3277]\n assert candidate(encoded = [25, 30, 35, 40, 45, 50, 55]) == [12, 21, 11, 40, 0, 45, 31, 40]\n assert candidate(encoded = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34]) == [33, 37, 35, 43, 33, 45, 35, 51, 33, 53, 35, 59, 33, 61, 35, 3, 33]\n assert candidate(encoded = [32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [13091, 19676, 29475, 27868, 25379, 25820, 26403, 26332, 26147, 26204, 26211, 26236, 26227, 26228, 26231, 26230]\n assert candidate(encoded = [3, 10, 17, 24, 31, 38, 45]) == [60, 63, 53, 36, 60, 35, 5, 40]\n assert candidate(encoded = [13, 23, 37, 55, 77, 103, 133, 167, 205, 247, 293, 343, 397]) == [335, 322, 341, 368, 327, 266, 365, 488, 335, 386, 373, 80, 263, 138]\n assert candidate(encoded = [14, 23, 32, 41, 50, 59, 68]) == [13, 3, 20, 52, 29, 47, 20, 80]\n assert candidate(encoded = [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, 26, 2, 21, 3, 22, 2, 17, 3, 18, 2, 13, 3, 14, 2, 9, 3, 10, 2, 5, 3, 6, 2, 1, 3, 2]\n assert candidate(encoded = [10, 20, 15, 25, 30, 22, 28, 19, 29, 12]) == [4, 14, 26, 21, 12, 18, 4, 24, 11, 22, 26]\n assert candidate(encoded = [23, 45, 12, 34, 56, 78, 90, 112, 134]) == [58, 45, 0, 12, 46, 22, 88, 2, 114, 244]\n assert candidate(encoded = [15, 22, 30, 39, 45, 51, 57, 63, 69]) == [54, 57, 47, 49, 22, 59, 8, 49, 14, 75]\n assert candidate(encoded = [3, 9, 15, 21, 27, 33, 39]) == [53, 54, 63, 48, 37, 62, 31, 56]\n assert candidate(encoded = [5, 12, 19, 26, 33, 40, 47]) == [54, 51, 63, 44, 54, 23, 63, 16]\n assert candidate(encoded = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [8, 10, 14, 8, 0, 10, 6, 8, 24, 10, 30, 8]\n assert candidate(encoded = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143]) == [197, 206, 216, 249, 213, 226, 160, 237, 181, 214, 184, 193, 69, 202]\n assert candidate(encoded = [63, 66, 69, 72, 75, 78, 81]) == [76, 115, 49, 116, 60, 119, 57, 104]\n assert candidate(encoded = [29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == [109, 112, 111, 74, 99, 72, 103, 82, 105, 84, 23, 80]\n assert candidate(encoded = [1023, 511, 255, 127, 63, 31, 15, 7]) == [409, 614, 921, 870, 793, 806, 825, 822, 817]\n assert candidate(encoded = [31, 30, 29, 28, 27, 26, 25, 24, 23]) == [11, 20, 10, 23, 11, 16, 10, 19, 11, 28]\n assert candidate(encoded = [13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131077, 262149]) == [157301, 157304, 157285, 157272, 157221, 157400, 157477, 156888, 156453, 158936, 160549, 150744, 144165, 183512, 52445, 314584]\n assert candidate(encoded = [9, 19, 31, 45, 61, 79, 99, 121, 145, 171, 199, 229, 261, 295, 331]) == [369, 376, 363, 372, 345, 356, 299, 328, 305, 416, 267, 460, 297, 44, 267, 64]\n assert candidate(encoded = [31, 14, 17, 9, 22, 15, 26, 11, 24]) == [8, 23, 25, 8, 1, 23, 24, 2, 9, 17]\n assert candidate(encoded = [4, 13, 12, 15, 10, 19, 18, 21, 14, 23, 22]) == [31, 27, 22, 26, 21, 31, 12, 30, 11, 5, 18, 4]\n assert candidate(encoded = [7, 13, 21, 31, 43, 57, 73, 91, 111, 133, 157, 183, 211, 241, 273]) == [163, 164, 169, 188, 163, 136, 177, 248, 163, 204, 73, 212, 99, 176, 65, 336]\n assert candidate(encoded = [15, 22, 17, 24, 19, 26, 21, 28, 23]) == [3, 12, 26, 11, 19, 0, 26, 15, 19, 4]\n assert candidate(encoded = [2, 3, 1, 6, 5, 4, 11, 10, 9, 16, 15, 14, 21, 20, 19]) == [17, 19, 16, 17, 23, 18, 22, 29, 23, 30, 14, 1, 15, 26, 14, 29]\n assert candidate(encoded = [15, 20, 17, 23, 18, 24, 19]) == [19, 28, 8, 25, 14, 28, 4, 23]\n assert candidate(encoded = [31, 29, 27, 25, 23, 21, 19, 17, 15]) == [11, 20, 9, 18, 11, 28, 9, 26, 11, 4]\n assert candidate(encoded = [65, 68, 71, 74, 77, 80, 83]) == [86, 23, 83, 20, 94, 19, 67, 16]\n assert candidate(encoded = [15, 20, 25, 30, 35, 40, 45, 50, 55]) == [27, 20, 0, 25, 7, 36, 12, 33, 19, 36]\n assert candidate(encoded = [100, 200, 50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == [639, 539, 723, 737, 631, 653, 979, 529, 55, 701, 83, 769, 183]\n assert candidate(encoded = [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]) == [122, 5, 123, 6, 122, 1, 123, 2, 122, 13, 123, 14, 122, 9, 123, 10, 122, 21, 123, 22, 122, 17, 123, 18, 122, 29, 123, 30]\n assert candidate(encoded = [16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [6553, 9830, 14745, 13926, 12697, 12902, 13209, 13158, 13081, 13094, 13113, 13110, 13105, 13106, 13107]\n assert candidate(encoded = [127, 130, 133, 136, 139, 142, 145]) == [140, 243, 113, 244, 124, 247, 121, 232]\n assert candidate(encoded = [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45]) == [5, 0, 9, 4, 21, 0, 25, 4, 37, 0, 41, 4]\n assert candidate(encoded = [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]) == [1, 2, 4, 13, 1, 14, 28, 9, 17, 10, 20, 53, 17, 54, 28, 49, 1, 50, 4, 61, 1, 62, 124, 57, 113, 58, 116, 37, 113, 38, 124, 33, 65, 34, 68, 45, 65, 46, 92, 41, 81]\n assert candidate(encoded = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047]) == [831, 830, 829, 826, 821, 810, 789, 874, 917, 618, 405, 1642]\n assert candidate(encoded = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == [1, 101, 6, 100, 5, 101, 58, 100, 57, 101, 62, 100, 61, 101, 50, 100, 49]\n assert candidate(encoded = [31, 14, 7, 3, 1, 0, 2, 6, 14, 30, 62, 126, 254]) == [100, 123, 117, 114, 113, 112, 112, 114, 116, 122, 100, 90, 36, 218]\n assert candidate(encoded = [15, 27, 18, 23, 31, 45, 56, 67, 78]) == [105, 102, 125, 111, 120, 103, 74, 114, 49, 127]\n", "comparison": "exact"}, "public_tests": ["[3,1]", "[6,5,4,6]"], "hints": ["Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x.", "Think why n is odd.", "perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ...", "perm[i] = perm[i-1] XOR encoded[i-1]"], "metadata": {"canonical_parameter_names": ["encoded"], "leetcode_dataset_entry_point": "Solution().decode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:04+00:00", "tests_total": 110, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function decode($encoded) {", "container": "Solution", "callable": "decode", "parameters": [{"name": "encoded", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1736, "task_id": "latest-time-by-replacing-hidden-digits", "difficulty": "Easy", "problem_description": "You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).\n\nThe valid times are those inclusively between 00:00 and 23:59.\n\nReturn the latest valid time you can get from time by replacing the hidden digits.\n\nExample 1:\n\nInput: time = \"2?:?0\"\nOutput: \"23:50\"\nExplanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.\n\nExample 2:\n\nInput: time = \"0?:3?\"\nOutput: \"09:39\"\n\nExample 3:\n\nInput: time = \"1?:22\"\nOutput: \"19:22\"\n\nConstraints:\n\n- time is in the format hh:mm.\n- It is guaranteed that you can produce a valid time from the given string.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(time = \"?3:?0\") == \"23:50\"\n assert candidate(time = \"1?:22\") == \"19:22\"\n assert candidate(time = \"1?:??\") == \"19:59\"\n assert candidate(time = \"0?:59\") == \"09:59\"\n assert candidate(time = \"23:?9\") == \"23:59\"\n assert candidate(time = \"00:?0\") == \"00:50\"\n assert candidate(time = \"2?:5?\") == \"23:59\"\n assert candidate(time = \"2?:?0\") == \"23:50\"\n assert candidate(time = \"?:?:??\") == \"2:?:9?\"\n assert candidate(time = \"00:??\") == \"00:59\"\n assert candidate(time = \"1?:?5\") == \"19:55\"\n assert candidate(time = \"?9:5?\") == \"19:59\"\n assert candidate(time = \"??:??\") == \"23:59\"\n assert candidate(time = \"12:3?\") == \"12:39\"\n assert candidate(time = \"??:00\") == \"23:00\"\n assert candidate(time = \"0?:3?\") == \"09:39\"\n assert candidate(time = \"1?:?9\") == \"19:59\"\n assert candidate(time = \"00:?5\") == \"00:55\"\n assert candidate(time = \"?9:59\") == \"19:59\"\n assert candidate(time = \"2?:59\") == \"23:59\"\n assert candidate(time = \"12:?5\") == \"12:55\"\n assert candidate(time = \"1?:3?\") == \"19:39\"\n assert candidate(time = \"20:??\") == \"20:59\"\n assert candidate(time = \"?4:2?\") == \"14:29\"\n assert candidate(time = \"2?:3?\") == \"23:39\"\n assert candidate(time = \"??:45\") == \"23:45\"\n assert candidate(time = \"23:?0\") == \"23:50\"\n assert candidate(time = \"??:09\") == \"23:09\"\n assert candidate(time = \"0?:2?\") == \"09:29\"\n assert candidate(time = \"?4:?4\") == \"14:54\"\n assert candidate(time = \"23:?5\") == \"23:55\"\n assert candidate(time = \"23:?7\") == \"23:57\"\n assert candidate(time = \"20:?9\") == \"20:59\"\n assert candidate(time = \"?3:?2\") == \"23:52\"\n assert candidate(time = \"0?:?4\") == \"09:54\"\n assert candidate(time = \"?3:?8\") == \"23:58\"\n assert candidate(time = \"???:59\") == \"23?:59\"\n assert candidate(time = \"2??:5?\") == \"23?:5?\"\n assert candidate(time = \"2?:1?\") == \"23:19\"\n assert candidate(time = \"22:?8\") == \"22:58\"\n assert candidate(time = \"0?:?9\") == \"09:59\"\n assert candidate(time = \"2?:??\") == \"23:59\"\n assert candidate(time = \"0?:?2\") == \"09:52\"\n assert candidate(time = \"02:?7\") == \"02:57\"\n assert candidate(time = \"1?:?8\") == \"19:58\"\n assert candidate(time = \"09:?5\") == \"09:55\"\n assert candidate(time = \"???:??\") == \"23?:9?\"\n assert candidate(time = \"09:?3\") == \"09:53\"\n assert candidate(time = \"?2:?7\") == \"22:57\"\n assert candidate(time = \"1?:4?\") == \"19:49\"\n assert candidate(time = \"2?:0?\") == \"23:09\"\n assert candidate(time = \"??:59\") == \"23:59\"\n assert candidate(time = \"23:?4\") == \"23:54\"\n assert candidate(time = \"2??:3?\") == \"23?:3?\"\n assert candidate(time = \"0??:30\") == \"09?:30\"\n assert candidate(time = \"0?:?5\") == \"09:55\"\n assert candidate(time = \"0?:4?\") == \"09:49\"\n assert candidate(time = \"09:5?\") == \"09:59\"\n assert candidate(time = \"1?:?0\") == \"19:50\"\n assert candidate(time = \"00:?9\") == \"00:59\"\n assert candidate(time = \"2?:?5\") == \"23:55\"\n assert candidate(time = \"1?:5?\") == \"19:59\"\n assert candidate(time = \"19:?9\") == \"19:59\"\n assert candidate(time = \"1?:?4\") == \"19:54\"\n assert candidate(time = \"1?:0?\") == \"19:09\"\n assert candidate(time = \"2?:4?\") == \"23:49\"\n assert candidate(time = \"?0:?5\") == \"20:55\"\n assert candidate(time = \"??:?9\") == \"23:59\"\n assert candidate(time = \"???:00\") == \"23?:00\"\n assert candidate(time = \"?9:?8\") == \"19:58\"\n assert candidate(time = \"?3:?9\") == \"23:59\"\n assert candidate(time = \"0?:5?\") == \"09:59\"\n assert candidate(time = \"2?:?4\") == \"23:54\"\n assert candidate(time = \"?9:?9\") == \"19:59\"\n assert candidate(time = \"2?:00\") == \"23:00\"\n assert candidate(time = \"?2:3?\") == \"22:39\"\n assert candidate(time = \"0?:??\") == \"09:59\"\n assert candidate(time = \"?4:?8\") == \"14:58\"\n assert candidate(time = \"0?:?0\") == \"09:50\"\n assert candidate(time = \"20:?4\") == \"20:54\"\n assert candidate(time = \"1?:59\") == \"19:59\"\n assert candidate(time = \"0?:0?\") == \"09:09\"\n assert candidate(time = \"23:??\") == \"23:59\"\n assert candidate(time = \"?0:?0\") == \"20:50\"\n assert candidate(time = \"0?:1?\") == \"09:19\"\n assert candidate(time = \"1?:2?\") == \"19:29\"\n assert candidate(time = \"0?:?8\") == \"09:58\"\n assert candidate(time = \"19:?8\") == \"19:58\"\n assert candidate(time = \"?2:?5\") == \"22:55\"\n assert candidate(time = \"0?:45\") == \"09:45\"\n assert candidate(time = \"2?:?9\") == \"23:59\"\n assert candidate(time = \"?3:5?\") == \"23:59\"\n assert candidate(time = \"23:?8\") == \"23:58\"\n assert candidate(time = \"09:??\") == \"09:59\"\n assert candidate(time = \"2?:?8\") == \"23:58\"\n assert candidate(time = \"2?:2?\") == \"23:29\"\n", "comparison": "exact"}, "public_tests": ["\"2?:?0\"", "\"0?:3?\"", "\"1?:22\""], "hints": ["Trying out all possible solutions from biggest to smallest would fit in the time limit.", "To check if the solution is okay, you need to find out if it's valid and matches every character"], "metadata": {"canonical_parameter_names": ["time"], "leetcode_dataset_entry_point": "Solution().maximumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:06+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumTime($time) {", "container": "Solution", "callable": "maximumTime", "parameters": [{"name": "time", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1737, "task_id": "change-minimum-characters-to-satisfy-one-of-three-conditions", "difficulty": "Medium", "problem_description": "You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.\n\nYour goal is to satisfy one of the following three conditions:\n\n- Every letter in a is strictly less than every letter in b in the alphabet.\n- Every letter in b is strictly less than every letter in a in the alphabet.\n- Both a and b consist of only one distinct letter.\n\nReturn the minimum number of operations needed to achieve your goal.\n\nExample 1:\n\nInput: a = \"aba\", b = \"caa\"\nOutput: 2\nExplanation: Consider the best way to make each condition true:\n1) Change b to \"ccc\" in 2 operations, then every letter in a is less than every letter in b.\n2) Change a to \"bbb\" and b to \"aaa\" in 3 operations, then every letter in b is less than every letter in a.\n3) Change a to \"aaa\" and b to \"aaa\" in 2 operations, then a and b consist of one distinct letter.\nThe best way was done in 2 operations (either condition 1 or condition 3).\n\nExample 2:\n\nInput: a = \"dabadd\", b = \"cda\"\nOutput: 3\nExplanation: The best way is to make condition 1 true by changing b to \"eee\".\n\nConstraints:\n\n- 1 <= a.length, b.length <= 10^5\n- a and b consist only of lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = \"abc\",b = \"bcd\") == 2\n assert candidate(a = \"aba\",b = \"caa\") == 2\n assert candidate(a = \"xyzz\",b = \"zzzz\") == 2\n assert candidate(a = \"abcd\",b = \"dcba\") == 4\n assert candidate(a = \"aaaabbbb\",b = \"ccccdddd\") == 0\n assert candidate(a = \"xyz\",b = \"abc\") == 0\n assert candidate(a = \"abc\",b = \"def\") == 0\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyz\",b = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(a = \"zzz\",b = \"aaa\") == 0\n assert candidate(a = \"abc\",b = \"abc\") == 3\n assert candidate(a = \"a\",b = \"z\") == 0\n assert candidate(a = \"aaa\",b = \"zzz\") == 0\n assert candidate(a = \"abacabadabacaba\",b = \"zzzyzxzyzxzyzxz\") == 0\n assert candidate(a = \"aabbcc\",b = \"bbccdd\") == 4\n assert candidate(a = \"xyz\",b = \"xyz\") == 3\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyz\",b = \"zyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(a = \"xyz\",b = \"zyx\") == 3\n assert candidate(a = \"aaa\",b = \"bbb\") == 0\n assert candidate(a = \"dabadd\",b = \"cda\") == 3\n assert candidate(a = \"a\",b = \"b\") == 0\n assert candidate(a = \"aaaa\",b = \"bbbb\") == 0\n assert candidate(a = \"aaaaabbbbbccccc\",b = \"cccccbbaaaa\") == 11\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"aaaaa\") == 0\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zyxwvutsrqponmlkjihgfedcba\") == 27\n assert candidate(a = \"qwert\",b = \"asdfg\") == 2\n assert candidate(a = \"ababababababababababababababab\",b = \"bababababababababababababababa\") == 30\n assert candidate(a = \"algorithm\",b = \"datastructure\") == 7\n assert candidate(a = \"abcabcabcabcabcabcabcabcabcabc\",b = \"zzzzyyyxxxwwwwvvvvuuuuttttssssrrrrqqqqppppooooonnnnmmmmmlllllkkkkkjjjjjiiiii\") == 0\n assert candidate(a = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",b = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 0\n assert candidate(a = \"abcdabcdabcdabcdabcd\",b = \"dcbaabcdabcdabcdabcd\") == 20\n assert candidate(a = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcb\",b = \"abadabadabadabadabadabadabadabadabadabadabadabadabadabadabadabadabadabadabadab\") == 39\n assert candidate(a = \"aaabbbcccddd\",b = \"eefffgggg\") == 0\n assert candidate(a = \"aaaaaaaaaabbbbbbbbbbbccccccccc\",b = \"zzzzzzzzzzzyyyyyyyyyyxxxxxxxxxx\") == 0\n assert candidate(a = \"abababababababababab\",b = \"babababababababababa\") == 20\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 25\n assert candidate(a = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",b = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 52\n assert candidate(a = \"mnopmnopmnopmnopmnop\",b = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 0\n assert candidate(a = \"abacabadabacabadabacaba\",b = \"zyxzyxzyxzyxzyxzyxzyxzyx\") == 0\n assert candidate(a = \"aaaaa\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(a = \"aaaaaabbbbccccdddd\",b = \"eeeeefffffggggghhhhh\") == 0\n assert candidate(a = \"abcdefg\",b = \"hijklmnopqrstuvwxyz\") == 0\n assert candidate(a = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\",b = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 0\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 2\n assert candidate(a = \"mississippi\",b = \"bababababa\") == 0\n assert candidate(a = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",b = \"pppppppppppppppppppppppppppppppppppppppppp\") == 0\n assert candidate(a = \"mnop\",b = \"qrst\") == 0\n assert candidate(a = \"qazwsxedcrfvtgbyhnujmikolp\",b = \"ploikmjhunbygvtfredcxswqaz\") == 26\n assert candidate(a = \"hello\",b = \"world\") == 3\n assert candidate(a = \"mno\",b = \"jkl\") == 0\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(a = \"hellohellohello\",b = \"worldworldworld\") == 9\n assert candidate(a = \"mmmmmmmmmmmmmmmmmmmmmm\",b = \"nnnnnnnnnnnnnnnnnnnnnn\") == 0\n assert candidate(a = \"aabaaaacaba\",b = \"bcdef\") == 2\n assert candidate(a = \"zzzzzzzzzz\",b = \"aaaaaaaaaa\") == 0\n assert candidate(a = \"aaaaaaaaaaaaaabbbbbbbbbbbbbbcccccccccccccccccdddddddddddddddd\",b = \"eeeeeeeeeeeeeeeeffffffffgggggggggggggggggghhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiii\") == 0\n assert candidate(a = \"qwertqwertqwert\",b = \"mnbvmnbvmnbv\") == 6\n assert candidate(a = \"aaaabbbbccccddddeeeeffffgggghhhhiiii\",b = \"jkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 0\n assert candidate(a = \"qwertyuiop\",b = \"poiuytrewq\") == 10\n assert candidate(a = \"mno\",b = \"mnpq\") == 2\n assert candidate(a = \"llllllllllllllllllllllllllllllllllllllll\",b = \"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\") == 0\n assert candidate(a = \"programming\",b = \"contest\") == 4\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zzxxwwvvutssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == 48\n assert candidate(a = \"xyzzzzzxyzzzzz\",b = \"zzzzzxyzzzzzxy\") == 8\n assert candidate(a = \"zzzzz\",b = \"aaaaa\") == 0\n assert candidate(a = \"zzzzzzzzzzzzzz\",b = \"aaaaaaaaaaaaaa\") == 0\n assert candidate(a = \"ababababababababababababababababab\",b = \"bababababababababababababababababa\") == 34\n assert candidate(a = \"ppppqqqqqqrrrrrrsssssss\",b = \"tttttuuuuuuuuvvvvvvvvvvvvv\") == 0\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(a = \"qwerttyuiiopasdfghjklzzxcvbnm\",b = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 26\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 2\n assert candidate(a = \"python\",b = \"java\") == 2\n assert candidate(a = \"pqrstuv\",b = \"mnopq\") == 2\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(a = \"acabcbacbacbacbaca\",b = \"bdadbdadbdadbdad\") == 8\n assert candidate(a = \"abcdefghijklmnopqrstu\",b = \"vwxyzvwxyzvwxyzvwxyz\") == 0\n assert candidate(a = \"abcdefghijklmnop\",b = \"zyxwvutsrqponmlkjihgfedcba\") == 16\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyz\",b = \"abcdefghijklmnopqrstuvwxy\") == 25\n assert candidate(a = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",b = \"defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef\") == 0\n assert candidate(a = \"abcabcabcabcabcabcabcabcabcabc\",b = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 0\n assert candidate(a = \"aabbaacc\",b = \"zzzzyyxx\") == 0\n assert candidate(a = \"aaaabbbbcccc\",b = \"ccccbbbbaaaa\") == 12\n assert candidate(a = \"abcdefg\",b = \"zzzzzzz\") == 0\n assert candidate(a = \"abcdefghijklmnopqrstuvwxy\",b = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(a = \"acacacacacacacacacacacacacacaca\",b = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc\") == 15\n assert candidate(a = \"mnop\",b = \"qrstuvwxyza\") == 1\n assert candidate(a = \"abcdabcdabcd\",b = \"xyzxyzxyzxyz\") == 0\n assert candidate(a = \"abacabadabacaba\",b = \"zyxzyxzyxzyxzyxzyx\") == 0\n assert candidate(a = \"same\",b = \"same\") == 4\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(a = \"mnopqrstu\",b = \"vwxyzijkl\") == 4\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(a = \"mnopqrstuvwxy\",b = \"abcdefghijklmnopqrstuvwxyz\") == 14\n assert candidate(a = \"abcdabcabc\",b = \"zyxzxyzxyz\") == 0\n assert candidate(a = \"abacabadabacabad\",b = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == 0\n assert candidate(a = \"abcabcabcabcabcabcabcabcabcabc\",b = \"abcabcabcabcabcabcabcabcabcabc\") == 30\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(a = \"abcdefghijklm\",b = \"nopqrstuvwxyz\") == 0\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(a = \"mnopqrstuvwxyzmnopqrstu\",b = \"abcdefghijklmnopqrstuabcdefghijklmnopqrstu\") == 18\n assert candidate(a = \"aaabbbcccdddeeefffggghhhhiiiiijjjjjjkkkkkkkllllllllmmmmmmmmmmm\",b = \"mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz\") == 4\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(a = \"aaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccdddddddddddddddddddddd\",b = \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\") == 0\n assert candidate(a = \"xyxzyzxzyzxzyzxzyz\",b = \"zyxzyzxzyzxzyzxzyx\") == 18\n assert candidate(a = \"abcdefghijklmnop\",b = \"qrstuvwxyz\") == 0\n assert candidate(a = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",b = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(a = \"xyzz\",b = \"abcd\") == 0\n assert candidate(a = \"racecar\",b = \"madam\") == 5\n assert candidate(a = \"abcdefghijklmnopqrstu\",b = \"vwxyzabcdefghijklmnopqrstu\") == 21\n assert candidate(a = \"qwe\",b = \"qwer\") == 3\n assert candidate(a = \"pppppppppppppppppppppppppppppppppppppppppp\",b = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 0\n assert candidate(a = \"mnbvcxzlkjhgfdsapoiuytrewq\",b = \"qwertyuiopasdfghjklzxcvbnm\") == 26\n assert candidate(a = \"abcdabcdabcd\",b = \"dcbaabcdabcd\") == 12\n assert candidate(a = \"aaaaabbbbb\",b = \"bbbbbccccc\") == 5\n assert candidate(a = \"aaabbbcccdddeeefffggghhhiii\",b = \"kkklllmmmnnnooopppqqqrrrssstttuuuvvv\") == 0\n assert candidate(a = \"aaaaaaaaaaaaaaaaaaaaaaa\",b = \"bbbbbbbbbbbbbbbbbbbbbbbbb\") == 0\n assert candidate(a = \"abacabadabacabadabacabad\",b = \"zzzzyyyyxxxxyyyyzzzz\") == 0\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeeeddccbbbaa\") == 52\n assert candidate(a = \"abacabadabacaba\",b = \"zzzyyyxxxwwwwvvvvuuuuuuttttttsssssrrrrrqqqqqqpppppoonnnnmmmllllkkkkjjjjiiiihhhhhgggggffffffeeeeeeeedddddccccbbbaaaa\") == 10\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"zzzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == 52\n assert candidate(a = \"mnopqrstuvwxyz\",b = \"abcdefghijklm\") == 1\n assert candidate(a = \"one\",b = \"two\") == 1\n assert candidate(a = \"qwertyuiopasdfghjklzxcvbnm\",b = \"qwertyuiopasdfghjklzxcvbnm\") == 26\n assert candidate(a = \"mississippi\",b = \"delaware\") == 3\n assert candidate(a = \"abcdefghijklmnopqrstuvwxyz\",b = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 1\n assert candidate(a = \"abc\",b = \"xyz\") == 0\n assert candidate(a = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",b = \"abcdefghijklmnopqrstuvwxyz\") == 27\n assert candidate(a = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",b = \"mnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnopmnop\") == 0\n", "comparison": "exact"}, "public_tests": ["\"aba\"\n\"caa\"", "\"dabadd\"\n\"cda\""], "hints": ["Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter.", "For the first 2 conditions, take care that you can only change characters to lowercase letters, so you can't make 'z' the smallest letter in one of the strings or 'a' the largest letter in one of them."], "metadata": {"canonical_parameter_names": ["a", "b"], "leetcode_dataset_entry_point": "Solution().minCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:09+00:00", "tests_total": 128, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "counting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minCharacters($a, $b) {", "container": "Solution", "callable": "minCharacters", "parameters": [{"name": "a", "type": "String"}, {"name": "b", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1738, "task_id": "find-kth-largest-xor-coordinate-value", "difficulty": "Medium", "problem_description": "You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.\n\nThe value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).\n\nFind the k^th largest value (1-indexed) of all the coordinates of matrix.\n\nExample 1:\n\nInput: matrix = [[5,2],[1,6]], k = 1\nOutput: 7\nExplanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.\n\nExample 2:\n\nInput: matrix = [[5,2],[1,6]], k = 2\nOutput: 5\nExplanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.\n\nExample 3:\n\nInput: matrix = [[5,2],[1,6]], k = 3\nOutput: 4\nExplanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.\n\nConstraints:\n\n- m == matrix.length\n- n == matrix[i].length\n- 1 <= m, n <= 1000\n- 0 <= matrix[i][j] <= 10^6\n- 1 <= k <= m * n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[5, 2, 3], [1, 6, 4]],k = 5) == 4\n assert candidate(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],k = 9) == 0\n assert candidate(matrix = [[5, 2, 3], [1, 6, 4], [7, 8, 9]],k = 9) == 0\n assert candidate(matrix = [[10, 12, 3], [1, 6, 4], [7, 8, 9]],k = 4) == 10\n assert candidate(matrix = [[10, 20], [30, 40]],k = 1) == 40\n assert candidate(matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 5) == 2\n assert candidate(matrix = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 4) == 1\n assert candidate(matrix = [[0, 0], [0, 0]],k = 1) == 0\n assert candidate(matrix = [[5, 2], [1, 6]],k = 1) == 7\n assert candidate(matrix = [[5, 2, 3], [1, 6, 4]],k = 1) == 7\n assert candidate(matrix = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],k = 9) == 0\n assert candidate(matrix = [[1, 2], [3, 4], [5, 6]],k = 6) == 1\n assert candidate(matrix = [[5, 2], [1, 6]],k = 3) == 4\n assert candidate(matrix = [[5, 2], [1, 6]],k = 2) == 5\n assert candidate(matrix = [[1, 2], [3, 4], [5, 6]],k = 4) == 3\n assert candidate(matrix = [[1000000, 999999, 999998], [999997, 999996, 999995], [999994, 999993, 999992]],k = 6) == 126\n assert candidate(matrix = [[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]],k = 25) == 2\n assert candidate(matrix = [[5, 8, 9, 12, 15], [14, 11, 10, 7, 4], [3, 6, 7, 10, 13], [12, 15, 14, 11, 8], [1, 4, 5, 8, 11]],k = 18) == 5\n assert candidate(matrix = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],k = 5) == 1\n assert candidate(matrix = [[100, 200, 300], [400, 500, 600], [700, 800, 900], [1000, 1100, 1200]],k = 10) == 172\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 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(matrix = [[0, 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) == 0\n assert candidate(matrix = [[9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20]],k = 8) == 8\n assert candidate(matrix = [[8, 6, 2, 5, 8, 4, 9], [4, 5, 5, 6, 9, 8, 9], [7, 3, 8, 7, 5, 6, 2], [4, 3, 1, 2, 3, 4, 5], [5, 6, 7, 8, 9, 0, 1]],k = 15) == 11\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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) == 0\n assert candidate(matrix = [[1, 3, 5, 7, 9, 11, 13], [15, 17, 19, 21, 23, 25, 27], [29, 31, 33, 35, 37, 39, 41]],k = 12) == 14\n assert candidate(matrix = [[25, 10, 15, 20], [5, 30, 35, 40], [45, 50, 55, 60], [65, 70, 75, 80]],k = 15) == 8\n assert candidate(matrix = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],k = 13) == 0\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]],k = 25) == 1\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, 41, 42, 43, 44, 45, 46, 47, 48], [49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]],k = 30) == 7\n assert candidate(matrix = [[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5], [3, 5, 8, 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, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5]],k = 18) == 9\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 1) == 0\n assert candidate(matrix = [[9, 18, 27, 36, 45], [44, 35, 26, 17, 8], [7, 16, 25, 34, 43], [42, 33, 24, 15, 6], [5, 14, 23, 32, 41]],k = 20) == 8\n assert candidate(matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 10) == 3\n assert candidate(matrix = [[1000000, 999999, 999998], [999997, 999996, 999995], [999994, 999993, 999992]],k = 9) == 123\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]],k = 30) == 0\n assert candidate(matrix = [[5, 2, 15, 6, 3], [10, 1, 4, 7, 8], [3, 1, 9, 2, 12], [6, 14, 11, 13, 5], [1, 15, 8, 6, 7]],k = 20) == 6\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 16) == 0\n assert candidate(matrix = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]],k = 8) == 20\n assert candidate(matrix = [[7, 1, 4, 2], [9, 6, 3, 8], [5, 0, 10, 12], [15, 11, 14, 13]],k = 7) == 8\n assert candidate(matrix = [[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 = 14) == 8\n assert candidate(matrix = [[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 = 12) == 1\n assert candidate(matrix = [[5, 2, 15, 10], [1, 6, 8, 3], [12, 4, 7, 9], [14, 11, 13, 5]],k = 10) == 6\n assert candidate(matrix = [[8, 12, 7, 3, 15], [9, 6, 11, 14, 4], [13, 8, 2, 5, 9], [1, 10, 7, 12, 8], [6, 4, 14, 3, 13]],k = 13) == 7\n assert candidate(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],k = 1) == 0\n assert candidate(matrix = [[999999, 999999, 999999], [999999, 999999, 999999], [999999, 999999, 999999]],k = 9) == 0\n assert candidate(matrix = [[13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]],k = 14) == 12\n assert candidate(matrix = [[15, 9, 12, 3], [11, 6, 4, 14], [7, 8, 9, 13], [2, 5, 10, 1]],k = 7) == 8\n assert candidate(matrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],k = 10) == 1\n assert candidate(matrix = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]],k = 10) == 8\n assert candidate(matrix = [[3, 4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14], [15, 16, 17, 18]],k = 15) == 0\n assert candidate(matrix = [[1, 0, 0, 1, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],k = 12) == 1\n assert candidate(matrix = [[31, 41, 59, 26, 53], [58, 97, 93, 23, 84], [62, 64, 33, 83, 27], [95, 25, 43, 30, 48], [67, 47, 54, 90, 88]],k = 17) == 31\n assert candidate(matrix = [[256, 512, 1024], [128, 256, 512], [64, 128, 256]],k = 5) == 640\n assert candidate(matrix = [[3, 1, 2], [4, 1, 1], [5, 10, 6]],k = 6) == 3\n assert candidate(matrix = [[3, 6, 9, 12], [4, 7, 10, 13], [5, 8, 11, 14]],k = 7) == 5\n assert candidate(matrix = [[3, 8, 1], [9, 11, 13], [4, 7, 12]],k = 6) == 10\n assert candidate(matrix = [[1000000, 0, 0, 0, 0, 0, 0], [0, 1000000, 0, 0, 0, 0, 0], [0, 0, 1000000, 0, 0, 0, 0], [0, 0, 0, 1000000, 0, 0, 0], [0, 0, 0, 0, 1000000, 0, 0], [0, 0, 0, 0, 0, 1000000, 0], [0, 0, 0, 0, 0, 0, 1000000]],k = 25) == 1000000\n assert candidate(matrix = [[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]],k = 25) == 0\n assert candidate(matrix = [[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]],k = 30) == 0\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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(matrix = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],k = 14) == 0\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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) == 1\n assert candidate(matrix = [[1000000, 999999, 999998, 999997], [999996, 999995, 999994, 999993], [999992, 999991, 999990, 999989]],k = 6) == 124\n assert candidate(matrix = [[1, 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(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]],k = 20) == 7\n assert candidate(matrix = [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]],k = 15) == 5\n assert candidate(matrix = [[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]],k = 13) == 4\n assert candidate(matrix = [[0, 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 = 25) == 0\n assert candidate(matrix = [[1000000, 999999, 999998, 999997, 999996], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],k = 15) == 1000000\n assert candidate(matrix = [[7, 7, 7], [7, 7, 7], [7, 7, 7]],k = 4) == 7\n assert candidate(matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],k = 1) == 15\n assert candidate(matrix = [[1000000, 999999, 999998, 999997], [999996, 999995, 999994, 999993], [999992, 999991, 999990, 999989], [999988, 999987, 999986, 999985]],k = 10) == 120\n assert candidate(matrix = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],k = 3) == 7\n assert candidate(matrix = [[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]],k = 10) == 4\n assert candidate(matrix = [[1000000, 200000, 30000], [4000, 5000, 6000], [70, 80, 900]],k = 8) == 799482\n assert candidate(matrix = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [60, 70, 80, 90, 100], [55, 65, 75, 85, 95]],k = 15) == 10\n assert candidate(matrix = [[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 = 15) == 0\n assert candidate(matrix = [[2, 4, 6, 8, 10, 12], [14, 16, 18, 20, 22, 24], [26, 28, 30, 32, 34, 36]],k = 17) == 2\n assert candidate(matrix = [[15, 14, 13, 12], [11, 10, 9, 8], [7, 6, 5, 4], [3, 2, 1, 0]],k = 10) == 0\n assert candidate(matrix = [[23, 56, 12, 78], [34, 89, 56, 45], [12, 34, 56, 78], [89, 56, 23, 12]],k = 10) == 47\n assert candidate(matrix = [[1, 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(matrix = [[100, 200, 300], [400, 500, 600], [700, 800, 900]],k = 5) == 384\n assert candidate(matrix = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19], [20, 22, 24, 26, 28]],k = 12) == 7\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 16) == 0\n assert candidate(matrix = [[3, 5, 11, 13], [8, 2, 12, 7], [4, 6, 9, 15], [1, 10, 3, 8]],k = 6) == 11\n", "comparison": "exact"}, "public_tests": ["[[5,2],[1,6]]\n1", "[[5,2],[1,6]]\n2", "[[5,2],[1,6]]\n3"], "hints": ["Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix."], "metadata": {"canonical_parameter_names": ["matrix", "k"], "leetcode_dataset_entry_point": "Solution().kthLargestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:11+00:00", "tests_total": 87, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "divide-and-conquer", "bit-manipulation", "sorting", "heap-priority-queue", "matrix", "prefix-sum", "quickselect"]}, "language": "php", "interface": {"raw_signature": "function kthLargestValue($matrix, $k) {", "container": "Solution", "callable": "kthLargestValue", "parameters": [{"name": "matrix", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1739, "task_id": "building-boxes", "difficulty": "Hard", "problem_description": "You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:\n\n- You can place the boxes anywhere on the floor.\n- If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.\n\nGiven an integer n, return the minimum possible number of boxes touching the floor.\n\nExample 1:\n\nInput: n = 3\nOutput: 3\nExplanation: The figure above is for the placement of the three boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n\nExample 2:\n\nInput: n = 4\nOutput: 3\nExplanation: The figure above is for the placement of the four boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n\nExample 3:\n\nInput: n = 10\nOutput: 6\nExplanation: The figure above is for the placement of the ten boxes.\nThese boxes are placed in the corner of the room, where the corner is on the back side.\n\nConstraints:\n\n- 1 <= n <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 3) == 3\n assert candidate(n = 100) == 34\n assert candidate(n = 15) == 9\n assert candidate(n = 4) == 3\n assert candidate(n = 1000000) == 16443\n assert candidate(n = 20) == 10\n assert candidate(n = 1) == 1\n assert candidate(n = 1000000000) == 1650467\n assert candidate(n = 1000) == 161\n assert candidate(n = 10) == 6\n assert candidate(n = 329) == 75\n assert candidate(n = 344) == 77\n assert candidate(n = 729) == 130\n assert candidate(n = 567890) == 11279\n assert candidate(n = 324) == 75\n assert candidate(n = 300) == 71\n assert candidate(n = 333) == 76\n assert candidate(n = 316) == 74\n assert candidate(n = 23) == 12\n assert candidate(n = 303) == 72\n assert candidate(n = 334) == 76\n assert candidate(n = 35) == 15\n assert candidate(n = 347) == 77\n assert candidate(n = 5000) == 474\n assert candidate(n = 567890123) == 1131581\n assert candidate(n = 4913) == 464\n assert candidate(n = 200) == 53\n assert candidate(n = 500000000) == 1039682\n assert candidate(n = 313) == 73\n assert candidate(n = 500) == 100\n assert candidate(n = 317) == 74\n assert candidate(n = 3375) == 365\n assert candidate(n = 897543210) == 1535456\n assert candidate(n = 341) == 76\n assert candidate(n = 216) == 55\n assert candidate(n = 50000) == 2210\n assert candidate(n = 987654) == 16287\n assert candidate(n = 314) == 73\n assert candidate(n = 318) == 74\n assert candidate(n = 100000) == 3536\n assert candidate(n = 25) == 13\n assert candidate(n = 350) == 77\n assert candidate(n = 5000000) == 48159\n assert candidate(n = 325) == 75\n assert candidate(n = 305) == 72\n assert candidate(n = 123456789) == 408968\n assert candidate(n = 999999) == 16443\n assert candidate(n = 308) == 73\n assert candidate(n = 12167) == 857\n assert candidate(n = 342) == 77\n assert candidate(n = 666) == 120\n assert candidate(n = 315) == 74\n assert candidate(n = 999999999) == 1650467\n assert candidate(n = 2000) == 252\n assert candidate(n = 250000000) == 654763\n assert candidate(n = 30) == 14\n assert candidate(n = 23456789) == 135151\n assert candidate(n = 345) == 77\n assert candidate(n = 336) == 76\n assert candidate(n = 9261) == 719\n assert candidate(n = 311) == 73\n assert candidate(n = 310) == 73\n assert candidate(n = 337) == 76\n assert candidate(n = 343) == 77\n assert candidate(n = 339) == 76\n assert candidate(n = 320) == 74\n assert candidate(n = 332) == 76\n assert candidate(n = 987654321) == 1636751\n assert candidate(n = 307) == 72\n assert candidate(n = 309) == 73\n assert candidate(n = 500000) == 10365\n assert candidate(n = 328) == 75\n assert candidate(n = 348) == 77\n assert candidate(n = 304) == 72\n assert candidate(n = 1500) == 208\n assert candidate(n = 2197) == 272\n assert candidate(n = 1331) == 191\n assert candidate(n = 319) == 74\n assert candidate(n = 125) == 39\n assert candidate(n = 321) == 74\n assert candidate(n = 6859) == 586\n assert candidate(n = 50) == 20\n assert candidate(n = 323) == 75\n assert candidate(n = 331) == 75\n assert candidate(n = 40) == 18\n assert candidate(n = 327) == 75\n assert candidate(n = 349) == 77\n assert candidate(n = 10000) == 756\n assert candidate(n = 335) == 76\n assert candidate(n = 302) == 72\n assert candidate(n = 312) == 73\n assert candidate(n = 330) == 75\n assert candidate(n = 322) == 74\n assert candidate(n = 338) == 76\n assert candidate(n = 306) == 72\n assert candidate(n = 326) == 75\n assert candidate(n = 301) == 71\n assert candidate(n = 123456) == 4068\n assert candidate(n = 346) == 77\n assert candidate(n = 340) == 76\n", "comparison": "exact"}, "public_tests": ["3", "4", "10"], "hints": ["Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in?", "The first box should always start in the corner"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().minimumBoxes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:13+00:00", "tests_total": 101, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["math", "binary-search", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumBoxes($n) {", "container": "Solution", "callable": "minimumBoxes", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1742, "task_id": "maximum-number-of-balls-in-a-box", "difficulty": "Easy", "problem_description": "You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.\n\nYour job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.\n\nGiven two integers lowLimit and highLimit, return the number of balls in the box with the most balls.\n\nExample 1:\n\nInput: lowLimit = 1, highLimit = 10\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count: 2 1 1 1 1 1 1 1 1 0 0 ...\nBox 1 has the most number of balls with 2 balls.\n\nExample 2:\n\nInput: lowLimit = 5, highLimit = 15\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count: 1 1 1 1 2 2 1 1 1 0 0 ...\nBoxes 5 and 6 have the most number of balls with 2 balls in each.\n\nExample 3:\n\nInput: lowLimit = 19, highLimit = 28\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 12 ...\nBall Count: 0 1 1 1 1 1 1 1 1 2 0 0 ...\nBox 10 has the most number of balls with 2 balls.\n\nConstraints:\n\n- 1 <= lowLimit <= highLimit <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(lowLimit = 999,highLimit = 1000) == 1\n assert candidate(lowLimit = 1000,highLimit = 10000) == 615\n assert candidate(lowLimit = 50000,highLimit = 50500) == 44\n assert candidate(lowLimit = 99,highLimit = 999) == 70\n assert candidate(lowLimit = 500,highLimit = 550) == 6\n assert candidate(lowLimit = 9999,highLimit = 100000) == 5520\n assert candidate(lowLimit = 1,highLimit = 10) == 2\n assert candidate(lowLimit = 100,highLimit = 200) == 10\n assert candidate(lowLimit = 99,highLimit = 199) == 10\n assert candidate(lowLimit = 1,highLimit = 100) == 10\n assert candidate(lowLimit = 1,highLimit = 20) == 3\n assert candidate(lowLimit = 10,highLimit = 100) == 9\n assert candidate(lowLimit = 50,highLimit = 150) == 10\n assert candidate(lowLimit = 5,highLimit = 15) == 2\n assert candidate(lowLimit = 19,highLimit = 28) == 2\n assert candidate(lowLimit = 45678,highLimit = 98765) == 3544\n assert candidate(lowLimit = 40000,highLimit = 50000) == 670\n assert candidate(lowLimit = 10000,highLimit = 20000) == 670\n assert candidate(lowLimit = 33333,highLimit = 44444) == 782\n assert candidate(lowLimit = 67890,highLimit = 67990) == 11\n assert candidate(lowLimit = 54321,highLimit = 54421) == 10\n assert candidate(lowLimit = 88888,highLimit = 88988) == 10\n assert candidate(lowLimit = 100,highLimit = 100) == 1\n assert candidate(lowLimit = 99999,highLimit = 100000) == 1\n assert candidate(lowLimit = 9995,highLimit = 10005) == 1\n assert candidate(lowLimit = 43210,highLimit = 43250) == 5\n assert candidate(lowLimit = 30000,highLimit = 35000) == 365\n assert candidate(lowLimit = 98765,highLimit = 98865) == 10\n assert candidate(lowLimit = 54321,highLimit = 54341) == 3\n assert candidate(lowLimit = 11111,highLimit = 11115) == 1\n assert candidate(lowLimit = 10000,highLimit = 99999) == 5520\n assert candidate(lowLimit = 66666,highLimit = 66766) == 10\n assert candidate(lowLimit = 77777,highLimit = 77800) == 3\n assert candidate(lowLimit = 99990,highLimit = 100000) == 1\n assert candidate(lowLimit = 11111,highLimit = 11200) == 9\n assert candidate(lowLimit = 5000,highLimit = 6000) == 75\n assert candidate(lowLimit = 56789,highLimit = 56800) == 2\n assert candidate(lowLimit = 55555,highLimit = 66666) == 782\n assert candidate(lowLimit = 9990,highLimit = 10000) == 1\n assert candidate(lowLimit = 12345,highLimit = 54321) == 2854\n assert candidate(lowLimit = 50000,highLimit = 50100) == 10\n assert candidate(lowLimit = 23456,highLimit = 23460) == 1\n assert candidate(lowLimit = 500,highLimit = 5000) == 340\n assert candidate(lowLimit = 5000,highLimit = 5100) == 10\n assert candidate(lowLimit = 90000,highLimit = 95000) == 365\n assert candidate(lowLimit = 10000,highLimit = 100000) == 5520\n assert candidate(lowLimit = 9999,highLimit = 10000) == 1\n assert candidate(lowLimit = 999,highLimit = 1009) == 1\n assert candidate(lowLimit = 12345,highLimit = 12395) == 6\n assert candidate(lowLimit = 1,highLimit = 99999) == 6000\n assert candidate(lowLimit = 12345,highLimit = 12345) == 1\n assert candidate(lowLimit = 1,highLimit = 1000) == 75\n assert candidate(lowLimit = 22222,highLimit = 22322) == 10\n assert candidate(lowLimit = 12345,highLimit = 67890) == 3699\n assert candidate(lowLimit = 56789,highLimit = 56799) == 2\n assert candidate(lowLimit = 100,highLimit = 1000) == 70\n assert candidate(lowLimit = 11111,highLimit = 22222) == 754\n assert candidate(lowLimit = 77777,highLimit = 77877) == 10\n assert candidate(lowLimit = 100000,highLimit = 100000) == 1\n assert candidate(lowLimit = 250,highLimit = 750) == 46\n assert candidate(lowLimit = 30000,highLimit = 40000) == 670\n assert candidate(lowLimit = 12345,highLimit = 12445) == 11\n assert candidate(lowLimit = 5000,highLimit = 5050) == 6\n assert candidate(lowLimit = 995,highLimit = 1005) == 1\n assert candidate(lowLimit = 1000,highLimit = 1050) == 6\n assert candidate(lowLimit = 33333,highLimit = 33433) == 10\n assert candidate(lowLimit = 1234,highLimit = 5678) == 344\n assert candidate(lowLimit = 8888,highLimit = 8900) == 2\n assert candidate(lowLimit = 11111,highLimit = 11211) == 10\n assert candidate(lowLimit = 999,highLimit = 1001) == 1\n assert candidate(lowLimit = 67890,highLimit = 78900) == 749\n assert candidate(lowLimit = 20000,highLimit = 30000) == 670\n assert candidate(lowLimit = 50000,highLimit = 51000) == 75\n assert candidate(lowLimit = 99,highLimit = 101) == 1\n assert candidate(lowLimit = 88888,highLimit = 99999) == 736\n assert candidate(lowLimit = 1234,highLimit = 1244) == 2\n assert candidate(lowLimit = 44444,highLimit = 55555) == 785\n assert candidate(lowLimit = 300,highLimit = 600) == 28\n assert candidate(lowLimit = 12345,highLimit = 12355) == 2\n assert candidate(lowLimit = 70000,highLimit = 80000) == 670\n assert candidate(lowLimit = 88888,highLimit = 88999) == 11\n assert candidate(lowLimit = 20000,highLimit = 25000) == 365\n assert candidate(lowLimit = 123,highLimit = 456) == 33\n", "comparison": "exact"}, "public_tests": ["1\n10", "5\n15", "19\n28"], "hints": ["Note that both lowLimit and highLimit are of small constraints so you can iterate on all number between them", "You can simulate the boxes by counting for each box the number of balls with digit sum equal to that box number"], "metadata": {"canonical_parameter_names": ["lowLimit", "highLimit"], "leetcode_dataset_entry_point": "Solution().countBalls", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:18+00:00", "tests_total": 86, "tests_dropped": 3, "flags": [], "topic_tags": ["hash-table", "math", "counting"]}, "language": "php", "interface": {"raw_signature": "function countBalls($lowLimit, $highLimit) {", "container": "Solution", "callable": "countBalls", "parameters": [{"name": "lowLimit", "type": "Integer"}, {"name": "highLimit", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1743, "task_id": "restore-the-array-from-adjacent-pairs", "difficulty": "Medium", "problem_description": "There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.\n\nYou are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [u_i, v_i] indicates that the elements u_i and v_i are adjacent in nums.\n\nIt is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.\n\nReturn the original array nums. If there are multiple solutions, return any of them.\n\nExample 1:\n\nInput: adjacentPairs = [[2,1],[3,4],[3,2]]\nOutput: [1,2,3,4]\nExplanation: This array has all its adjacent pairs in adjacentPairs.\nNotice that adjacentPairs[i] may not be in left-to-right order.\n\nExample 2:\n\nInput: adjacentPairs = [[4,-2],[1,4],[-3,1]]\nOutput: [-2,4,1,-3]\nExplanation: There can be negative numbers.\nAnother solution is [-3,1,4,-2], which would also be accepted.\n\nExample 3:\n\nInput: adjacentPairs = [[100000,-100000]]\nOutput: [100000,-100000]\n\nConstraints:\n\n- nums.length == n\n- adjacentPairs.length == n - 1\n- adjacentPairs[i].length == 2\n- 2 <= n <= 10^5\n- -10^5 <= nums[i], u_i, v_i <= 10^5\n- There exists some nums that has adjacentPairs as its pairs.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(adjacentPairs = [[-1, 0], [0, 1], [1, 2], [2, 3], [3, -2]]) == [-1, 0, 1, 2, 3, -2]\n assert candidate(adjacentPairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]]) == [10, 20, 30, 40, 50, 60]\n assert candidate(adjacentPairs = [[2, 1], [3, 4], [3, 2]]) == [1, 2, 3, 4]\n assert candidate(adjacentPairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700]]) == [100, 200, 300, 400, 500, 600, 700]\n assert candidate(adjacentPairs = [[-1, -2], [-2, -3], [-3, -4], [-4, -5], [-5, -6]]) == [-1, -2, -3, -4, -5, -6]\n assert candidate(adjacentPairs = [[-1, 2], [2, 3], [3, 4], [4, 5]]) == [-1, 2, 3, 4, 5]\n assert candidate(adjacentPairs = [[5, 1], [1, 2], [2, 3], [3, 4]]) == [5, 1, 2, 3, 4]\n assert candidate(adjacentPairs = [[100000, -100000]]) == [100000, -100000]\n assert candidate(adjacentPairs = [[5, 3], [3, 1], [1, 2], [2, 4], [4, 6]]) == [5, 3, 1, 2, 4, 6]\n assert candidate(adjacentPairs = [[-1, 0], [0, 1], [1, 2], [-2, -1]]) == [2, 1, 0, -1, -2]\n assert candidate(adjacentPairs = [[4, -2], [1, 4], [-3, 1]]) == [-2, 4, 1, -3]\n assert candidate(adjacentPairs = [[1, 6], [2, 3], [3, 4], [4, 5], [5, 6]]) == [1, 6, 5, 4, 3, 2]\n assert candidate(adjacentPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [1, 2, 3, 4, 5, 6]\n assert candidate(adjacentPairs = [[-1, 0], [0, 1], [1, 2], [2, 3], [3, 4]]) == [-1, 0, 1, 2, 3, 4]\n assert candidate(adjacentPairs = [[1, 6], [6, 8], [8, 3], [3, 7], [7, 2], [2, 5], [5, 4]]) == [1, 6, 8, 3, 7, 2, 5, 4]\n assert candidate(adjacentPairs = [[-1, 1], [-2, -1], [-3, -2], [4, -3], [5, 4], [6, 5], [7, 6]]) == [1, -1, -2, -3, 4, 5, 6, 7]\n assert candidate(adjacentPairs = [[-10, -20], [-20, -30], [-30, -40], [-40, -50], [-50, -60]]) == [-10, -20, -30, -40, -50, -60]\n assert candidate(adjacentPairs = [[-10000, 10000], [10000, 20000], [20000, -10000], [-20000, -10000], [30000, 20000], [30000, 40000]]) == [-20000, -10000, 20000, 10000, -10000, 20000, 10000]\n assert candidate(adjacentPairs = [[-5, -4], [-4, -3], [-3, -2], [-2, -1], [-1, 0], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(adjacentPairs = [[100000, -100000], [99999, 100000], [-99999, -100000], [88888, 99999], [-88888, -99999]]) == [88888, 99999, 100000, -100000, -99999, -88888]\n assert candidate(adjacentPairs = [[-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(adjacentPairs = [[-5, 0], [0, 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]]) == [-5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]\n assert candidate(adjacentPairs = [[-10, -20], [-20, -30], [-30, -40], [-40, -50], [-50, -60], [-60, -70], [-70, -80], [-80, -90], [-90, -100]]) == [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]\n assert candidate(adjacentPairs = [[-10, -9], [-9, -8], [-8, -7], [-7, -6], [-6, -5], [-5, -4], [-4, -3], [-3, -2], [-2, -1], [-1, 0], [0, 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(adjacentPairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [1000, 1100], [1100, 1200], [1200, 1300], [1300, 1400], [1400, 1500]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]\n assert candidate(adjacentPairs = [[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]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(adjacentPairs = [[1, 2], [3, 4], [5, 6], [1, 3], [4, 5]]) == [2, 1, 3, 4, 5, 6]\n assert candidate(adjacentPairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110], [110, 120]]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]\n assert candidate(adjacentPairs = [[100000, -100000], [-99999, 100000], [-99998, -99999], [-99997, -99998], [-99996, -99997], [-99995, -99996], [-99994, -99995], [-99993, -99994], [-99992, -99993], [-99991, -99992]]) == [-100000, 100000, -99999, -99998, -99997, -99996, -99995, -99994, -99993, -99992, -99991]\n assert candidate(adjacentPairs = [[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(adjacentPairs = [[5, 15], [15, 25], [25, 35], [35, 45], [45, 55], [55, 65], [65, 75], [75, 85], [85, 95], [95, 105]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]\n assert candidate(adjacentPairs = [[50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110], [110, 120], [120, 130], [130, 140], [140, 150]]) == [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]\n assert candidate(adjacentPairs = [[-5, 0], [0, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [-5, -10], [-10, -15], [-15, -20], [-20, -25], [-25, -30], [-30, -35], [-35, -40], [-40, -45], [-45, -50]]) == [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15, -20, -25, -30, -35, -40, -45, -50]\n assert candidate(adjacentPairs = [[-5, -4], [-4, -3], [-3, -2], [-2, -1], [-1, 0], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]\n assert candidate(adjacentPairs = [[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, 31], [31, 33], [33, 35], [35, 37], [37, 39]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]\n assert candidate(adjacentPairs = [[100000, 99999], [99998, 99999], [99997, 99998], [99996, 99997], [99995, 99996]]) == [100000, 99999, 99998, 99997, 99996, 99995]\n assert candidate(adjacentPairs = [[-10, -20], [-20, -30], [-30, -40], [-40, -50], [-50, -60], [-60, -70], [-70, -80], [-80, -90]]) == [-10, -20, -30, -40, -50, -60, -70, -80, -90]\n assert candidate(adjacentPairs = [[-1, 1], [-2, -1], [-3, -2], [-4, -3], [-5, -4], [-6, -5], [-7, -6], [-8, -7], [-9, -8], [-10, -9]]) == [1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]\n assert candidate(adjacentPairs = [[10, 5], [5, -10], [-10, 15], [15, -15], [20, 10], [25, 20], [30, 25], [35, 30], [40, 35], [45, 40], [50, 45]]) == [-15, 15, -10, 5, 10, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(adjacentPairs = [[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]]) == [1, 2, 3, 4, 5, 6, 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(adjacentPairs = [[1, 2], [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]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(adjacentPairs = [[1, 2], [3, 2], [5, 4], [4, 3], [7, 6], [6, 5], [9, 8], [8, 7], [11, 10], [10, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(adjacentPairs = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]\n assert candidate(adjacentPairs = [[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]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(adjacentPairs = [[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]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]\n assert candidate(adjacentPairs = [[5, 3], [3, 1], [1, -2], [-2, -4], [-4, -6], [-6, -8], [-8, -10], [-10, -12], [-12, -14], [-14, -16], [-16, -18], [-18, -20], [-20, -22], [-22, -24], [-24, -26]]) == [5, 3, 1, -2, -4, -6, -8, -10, -12, -14, -16, -18, -20, -22, -24, -26]\n assert candidate(adjacentPairs = [[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(adjacentPairs = [[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]]) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]\n assert candidate(adjacentPairs = [[-1, 100], [100, 200], [200, -300], [-300, 400], [400, 500]]) == [-1, 100, 200, -300, 400, 500]\n assert candidate(adjacentPairs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 0]]) == [0, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(adjacentPairs = [[-1, -2], [-2, -3], [-3, -4], [-4, -5], [-5, -6], [-6, -7], [-7, -8], [-8, -9], [-9, -10], [-10, -11], [-11, -12]]) == [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12]\n assert candidate(adjacentPairs = [[500, 1000], [1000, 1500], [1500, 2000], [2000, 2500], [2500, 3000], [3000, 3500], [3500, 4000], [4000, 4500], [4500, 5000], [5000, 5500], [5500, 6000], [6000, 6500], [6500, 7000], [7000, 7500], [7500, 8000], [8000, 8500], [8500, 9000], [9000, 9500], [9500, 10000]]) == [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000]\n assert candidate(adjacentPairs = [[1, 5], [5, 9], [9, 13], [13, 17], [17, 21], [21, 25], [25, 29], [29, 33], [33, 37], [37, 41]]) == [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41]\n assert candidate(adjacentPairs = [[-10, -20], [-20, -30], [-30, -40], [-40, -50], [-50, -60], [-60, -70], [-70, -80], [-80, -90], [-90, -100]]) == [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]\n assert candidate(adjacentPairs = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55]]) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]\n assert candidate(adjacentPairs = [[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, 31], [31, 33], [33, 35], [35, 37], [37, 39], [39, 41]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]\n assert candidate(adjacentPairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(adjacentPairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [100, 150], [150, 250], [250, 350], [350, 450], [450, 550], [550, 650], [650, 750], [750, 850], [850, 950], [950, 1050]]) == [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]\n assert candidate(adjacentPairs = [[10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55], [55, 60], [60, 65], [65, 70]]) == [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]\n assert candidate(adjacentPairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(adjacentPairs = [[100000, 90000], [80000, 90000], [70000, 80000], [60000, 70000], [50000, 60000]]) == [100000, 90000, 80000, 70000, 60000, 50000]\n assert candidate(adjacentPairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(adjacentPairs = [[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(adjacentPairs = [[-50000, -40000], [-30000, -40000], [-20000, -30000], [-10000, -20000], [0, -10000]]) == [-50000, -40000, -30000, -20000, -10000, 0]\n assert candidate(adjacentPairs = [[-1, 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, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30]]) == [-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]\n assert candidate(adjacentPairs = [[-99999, 99999], [99999, -99998], [-99998, 99998], [99998, -99997], [-99997, 99997], [99997, -99996], [-99996, 99996], [99996, -99995]]) == [-99999, 99999, -99998, 99998, -99997, 99997, -99996, 99996, -99995]\n assert candidate(adjacentPairs = [[-5, 0], [-4, -5], [-3, -4], [-2, -3], [-1, -2], [0, -1], [1, 0], [2, 1], [3, 2], [4, 3], [5, 4]]) == [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, 0]\n assert candidate(adjacentPairs = [[0, 1], [2, 1], [4, 3], [3, 2], [6, 5], [5, 4], [8, 7], [7, 6], [10, 9], [9, 8], [12, 11], [11, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(adjacentPairs = [[-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(adjacentPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [2, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]\n assert candidate(adjacentPairs = [[-1, 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]]) == [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(adjacentPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(adjacentPairs = [[-100, -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, -84], [-84, -83], [-83, -82], [-82, -81], [-81, -80]]) == [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80]\n assert candidate(adjacentPairs = [[1, 6], [6, 11], [11, 16], [16, 21], [21, 26], [26, 31], [31, 36], [36, 41], [41, 46], [46, 51]]) == [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51]\n assert candidate(adjacentPairs = [[-100000, -90000], [-90000, -80000], [-80000, -70000], [-70000, -60000], [-60000, -50000], [-50000, -40000], [-40000, -30000], [-30000, -20000], [-20000, -10000], [-10000, 0], [0, 10000], [10000, 20000], [20000, 30000], [30000, 40000], [40000, 50000], [50000, 60000], [60000, 70000], [70000, 80000], [80000, 90000], [90000, 100000]]) == [-100000, -90000, -80000, -70000, -60000, -50000, -40000, -30000, -20000, -10000, 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]\n assert candidate(adjacentPairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(adjacentPairs = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [2, 3], [4, 5], [6, 7], [8, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(adjacentPairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110]]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]\n assert candidate(adjacentPairs = [[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", "comparison": "exact"}, "public_tests": ["[[2,1],[3,4],[3,2]]", "[[4,-2],[1,4],[-3,1]]", "[[100000,-100000]]"], "hints": ["Find the first element of nums - it will only appear once in adjacentPairs.", "The adjacent pairs are like edges of a graph. Perform a depth-first search from the first element."], "metadata": {"canonical_parameter_names": ["adjacentPairs"], "leetcode_dataset_entry_point": "Solution().restoreArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:20+00:00", "tests_total": 79, "tests_dropped": 0, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "depth-first-search"]}, "language": "php", "interface": {"raw_signature": "function restoreArray($adjacentPairs) {", "container": "Solution", "callable": "restoreArray", "parameters": [{"name": "adjacentPairs", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1744, "task_id": "can-you-eat-your-favorite-candy-on-your-favorite-day", "difficulty": "Medium", "problem_description": "You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the i^th type you have. You are also given a 2D array queries where queries[i] = [favoriteType_i, favoriteDay_i, dailyCap_i].\n\nYou play a game with the following rules:\n\n- You start eating candies on day 0.\n- You cannot eat any candy of type i unless you have eaten all candies of type i - 1.\n- You must eat at least one candy per day until you have eaten all the candies.\n\nConstruct a boolean array answer such that answer.length == queries.length and answer[i] is true if you can eat a candy of type favoriteType_i on day favoriteDay_i without eating more than dailyCap_i candies on any day, and false otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.\n\nReturn the constructed array answer.\n\nExample 1:\n\nInput: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\nOutput: [true,false,true]\nExplanation:\n1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.\n2- You can eat at most 4 candies each day.\n If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.\n On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.\n3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.\n\nExample 2:\n\nInput: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\nOutput: [false,true,true,false,false]\n\nConstraints:\n\n- 1 <= candiesCount.length <= 10^5\n- 1 <= candiesCount[i] <= 10^5\n- 1 <= queries.length <= 10^5\n- queries[i].length == 3\n- 0 <= favoriteType_i < candiesCount.length\n- 0 <= favoriteDay_i <= 10^9\n- 1 <= dailyCap_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(candiesCount = [7, 4, 5, 3, 8],queries = [[0, 2, 2], [4, 2, 4], [2, 13, 1000000000]]) == [True, False, True]\n assert candidate(candiesCount = [5, 2, 6, 4, 1],queries = [[3, 1, 2], [4, 10, 3], [3, 10, 100], [4, 100, 30], [1, 3, 1]]) == [False, True, True, False, False]\n assert candidate(candiesCount = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 0, 1], [1, 1, 2], [2, 3, 3], [3, 6, 4], [4, 10, 5], [5, 15, 6], [6, 21, 7], [7, 28, 8], [8, 36, 9], [9, 45, 10]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50],queries = [[0, 0, 10], [1, 1, 20], [2, 2, 30], [3, 3, 40], [4, 4, 50], [0, 5, 5], [1, 10, 10], [2, 15, 15], [3, 20, 20], [4, 25, 25]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]) == [True, False, False, False, False, False, False, False, False, False]\n assert candidate(candiesCount = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1, 1], [1, 3, 2], [2, 6, 3], [3, 10, 4], [4, 15, 5], [5, 21, 6], [6, 28, 7], [7, 36, 8], [8, 45, 9], [9, 55, 10]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(candiesCount = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 0, 10], [1, 10, 20], [2, 30, 30], [3, 60, 40], [4, 100, 50], [5, 150, 60], [6, 210, 70], [7, 280, 80], [8, 360, 90], [9, 450, 100]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[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]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [5, 4, 3, 2, 1],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [0, 4, 10], [1, 3, 10], [2, 2, 10], [3, 1, 10], [4, 0, 10]]) == [True, False, False, False, False, True, True, True, True, False]\n assert candidate(candiesCount = [10, 20, 30, 40, 50],queries = [[4, 49, 50], [3, 29, 40], [2, 19, 30], [1, 9, 20], [0, 9, 10]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 5, 5], [1, 15, 15], [2, 30, 25], [3, 45, 35], [4, 60, 45], [5, 75, 55], [6, 90, 65], [7, 105, 75], [8, 120, 85], [9, 135, 95]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [100, 200, 300, 400, 500],queries = [[0, 99, 100], [1, 199, 200], [2, 299, 300], [3, 399, 400], [4, 499, 500], [0, 1, 50], [1, 1, 100], [2, 1, 150], [3, 1, 200], [4, 1, 250]]) == [True, True, True, True, True, True, True, False, False, False]\n assert candidate(candiesCount = [100, 200, 300, 400, 500],queries = [[0, 99, 100], [1, 199, 200], [2, 299, 300], [3, 399, 400], [4, 499, 500]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],queries = [[0, 10000, 1000], [1, 20000, 2000], [2, 30000, 3000], [3, 40000, 4000], [4, 50000, 5000], [5, 60000, 6000], [6, 70000, 7000], [7, 80000, 8000], [8, 90000, 9000], [9, 100000, 10000]]) == [False, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[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]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[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], [0, 99, 1000], [1, 199, 1000], [2, 299, 1000], [3, 399, 1000], [4, 499, 1000], [5, 599, 1000], [6, 699, 1000], [7, 799, 1000], [8, 899, 1000], [9, 999, 1000]]) == [True, True, True, True, True, True, True, True, True, True, False, False, False, False, False, False, False, False, False, False]\n assert candidate(candiesCount = [10, 20, 30, 40, 50],queries = [[0, 5, 10], [1, 15, 10], [2, 25, 10], [3, 35, 10], [4, 45, 10], [0, 9, 9], [1, 19, 9], [2, 29, 9], [3, 39, 9], [4, 49, 9], [0, 1, 1], [1, 11, 1], [2, 21, 1], [3, 31, 1], [4, 41, 1]]) == [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False]\n assert candidate(candiesCount = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1], [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]]) == [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [1, 10, 100, 1000, 10000],queries = [[0, 0, 1], [1, 1, 10], [2, 2, 100], [3, 3, 1000], [4, 4, 10000], [0, 5, 5], [1, 10, 10], [2, 15, 15], [3, 20, 20], [4, 25, 25]]) == [True, True, True, True, True, False, True, True, True, False]\n assert candidate(candiesCount = [1000, 1000, 1000, 1000, 1000],queries = [[0, 0, 1], [1, 500, 1000], [2, 1000, 1000], [3, 1500, 1000], [4, 2000, 1000]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]) == [True, False, False, False, False, False, False, False, False, False]\n assert candidate(candiesCount = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 0, 1], [1, 1, 2], [2, 3, 3], [3, 6, 4], [4, 10, 5], [5, 15, 6], [6, 21, 7], [7, 28, 8], [8, 36, 9]]) == [True, False, False, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [[0, 0, 1], [1, 1, 1], [2, 3, 1], [3, 6, 1], [4, 10, 1], [5, 15, 1], [6, 21, 1], [7, 28, 1], [8, 36, 1], [9, 45, 1]]) == [True, False, False, False, False, False, False, False, False, False]\n assert candidate(candiesCount = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 99, 100], [1, 199, 200], [2, 299, 300], [3, 399, 400], [4, 499, 500], [5, 599, 600], [6, 699, 700], [7, 799, 800], [8, 899, 900], [9, 999, 1000]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 0, 10], [9, 494, 100], [5, 150, 60], [2, 30, 30], [8, 315, 90]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 0, 1], [9, 44, 10], [3, 9, 4], [5, 14, 5], [8, 35, 9]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [100, 200, 300, 400, 500],queries = [[0, 0, 100], [1, 100, 200], [2, 300, 300], [3, 600, 400], [4, 1000, 500]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 1, 50], [1, 51, 100], [2, 151, 150], [3, 301, 200], [4, 501, 250], [5, 751, 300], [6, 1051, 350], [7, 1401, 400], [8, 1801, 450], [9, 2251, 500]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50],queries = [[0, 0, 5], [1, 4, 10], [2, 19, 15], [3, 34, 20], [4, 49, 25]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [50, 50, 50, 50, 50],queries = [[0, 24, 50], [1, 49, 50], [2, 74, 50], [3, 99, 50], [4, 124, 50], [0, 25, 25], [1, 50, 25], [2, 75, 25], [3, 100, 25], [4, 125, 25]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [[0, 0, 100], [1, 199, 200], [2, 399, 300], [3, 599, 400], [4, 799, 500], [5, 999, 600], [6, 1199, 700], [7, 1399, 800], [8, 1599, 900], [9, 1799, 1000]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(candiesCount = [10, 20, 30, 40, 50],queries = [[0, 0, 10], [1, 10, 20], [2, 30, 30], [3, 60, 40], [4, 100, 50]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [100, 200, 300, 400, 500],queries = [[0, 0, 1], [1, 100, 100], [2, 200, 150], [3, 300, 200], [4, 400, 250]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [1, 1, 1, 1, 1],queries = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1]]) == [True, True, True, True, True]\n assert candidate(candiesCount = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],queries = [[0, 1000, 500], [1, 3000, 1000], [2, 5000, 1500], [3, 7000, 2000], [4, 9000, 2500], [5, 11000, 3000], [6, 13000, 3500], [7, 15000, 4000], [8, 17000, 4500], [9, 19000, 5000]]) == [False, False, True, True, True, True, True, True, True, True]\n", "comparison": "exact"}, "public_tests": ["[7,4,5,3,8]\n[[0,2,2],[4,2,4],[2,13,1000000000]]", "[5,2,6,4,1]\n[[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]"], "hints": ["The query is true if and only if your favorite day is in between the earliest and latest possible days to eat your favorite candy.", "To get the earliest day, you need to eat dailyCap candies every day. To get the latest day, you need to eat 1 candy every day.", "The latest possible day is the total number of candies with a smaller type plus the number of your favorite candy minus 1.", "The earliest possible day that you can eat your favorite candy is the total number of candies with a smaller type divided by dailyCap."], "metadata": {"canonical_parameter_names": ["candiesCount", "queries"], "leetcode_dataset_entry_point": "Solution().canEat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:23+00:00", "tests_total": 55, "tests_dropped": 19, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function canEat($candiesCount, $queries) {", "container": "Solution", "callable": "canEat", "parameters": [{"name": "candiesCount", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1745, "task_id": "palindrome-partitioning-iv", "difficulty": "Hard", "problem_description": "Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.\n\nA string is said to be palindrome if it the same string when reversed.\n\nExample 1:\n\nInput: s = \"abcbdd\"\nOutput: true\nExplanation: \"abcbdd\" = \"a\" + \"bcb\" + \"dd\", and all three substrings are palindromes.\n\nExample 2:\n\nInput: s = \"bcbddxy\"\nOutput: false\nExplanation: s cannot be split into 3 palindromes.\n\nConstraints:\n\n- 3 <= s.length <= 2000\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 = \"abcdcba\") == True\n assert candidate(s = \"aabbaa\") == True\n assert candidate(s = \"aaaaa\") == True\n assert candidate(s = \"abacdfgdcaba\") == False\n assert candidate(s = \"aabbbaa\") == True\n assert candidate(s = \"noonnoon\") == True\n assert candidate(s = \"aaa\") == True\n assert candidate(s = \"aabb\") == True\n assert candidate(s = \"racecar\") == True\n assert candidate(s = \"abba\") == True\n assert candidate(s = \"noon\") == True\n assert candidate(s = \"deeee\") == True\n assert candidate(s = \"abc\") == True\n assert candidate(s = \"abcbdd\") == True\n assert candidate(s = \"abcd\") == False\n assert candidate(s = \"aabbcc\") == True\n assert candidate(s = \"madamimadam\") == True\n assert candidate(s = \"aabaacaab\") == True\n assert candidate(s = \"bcbddxy\") == False\n assert candidate(s = \"aabbccddeeeffgghhii\") == False\n assert candidate(s = \"aabbccddeeefffggghhhiiii\") == False\n assert candidate(s = \"kayakmadamracecar\") == True\n assert candidate(s = \"levelracecar\") == False\n assert candidate(s = \"civicnooncivicnoon\") == False\n assert candidate(s = \"aaaaaabbaaaaa\") == True\n assert candidate(s = \"madamnoonmadamnoonmadam\") == True\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(s = \"rotordetartratedrotor\") == True\n assert candidate(s = \"tattarrattatmadamracecar\") == True\n assert candidate(s = \"abcabcabc\") == False\n assert candidate(s = \"rotorlevelrotor\") == True\n assert candidate(s = \"deifiedcivicdeified\") == True\n assert candidate(s = \"rotorrefer\") == False\n assert candidate(s = \"madamadam\") == True\n assert candidate(s = \"aaaabbbbcccc\") == True\n assert candidate(s = \"levellevellevellevellevellevel\") == True\n assert candidate(s = \"deifieddeifieddeified\") == True\n assert candidate(s = \"xyzzyxabcba\") == False\n assert candidate(s = \"tacocatdeified\") == False\n assert candidate(s = \"leveloneone\") == False\n assert candidate(s = \"aabbccddeeefffggghhhhiiiiijjjjkkkkllllmmmmnnnnoooo\") == False\n assert candidate(s = \"levelmadamrotor\") == True\n assert candidate(s = \"abccbaabccba\") == True\n assert candidate(s = \"abcdmadamracecar\") == False\n assert candidate(s = \"levellevellevellevel\") == True\n assert candidate(s = \"repaperdeified\") == False\n assert candidate(s = \"noonnoonnoonnoon\") == True\n assert candidate(s = \"racecarlevel\") == False\n assert candidate(s = \"revilerleveldeified\") == False\n assert candidate(s = \"aabbaabbaa\") == True\n assert candidate(s = \"deifieddeifieddeifieddeifieddeified\") == True\n assert candidate(s = \"kayakracecarkayak\") == True\n assert candidate(s = \"abbbcbbaabbcbba\") == False\n assert candidate(s = \"levelrotorabcddcba\") == True\n assert candidate(s = \"aabbccddeeeffgghhiiiii\") == False\n assert candidate(s = \"leveldeifiedlevel\") == True\n assert candidate(s = \"noonnoonnoonnoonnoonnoon\") == True\n assert candidate(s = \"abacabaabacabaabacabaabacaba\") == True\n assert candidate(s = \"rotorreferrotorrefer\") == False\n assert candidate(s = \"abccbaabccbaabccba\") == True\n assert candidate(s = \"abacdfgdcabaaa\") == False\n assert candidate(s = \"aabbaccd\") == False\n assert candidate(s = \"aabbccddeeefffggghhhiiiiijjjjkkkkllllmmmmnnnnooooppppqqqrrrssstttuuuuvvvwwwxxxxyyyyzzzz\") == False\n assert candidate(s = \"madammadammadam\") == True\n assert candidate(s = \"racecarracecarracecar\") == True\n assert candidate(s = \"madammadam\") == True\n assert candidate(s = \"aibohphobiamadamaibohphobia\") == True\n assert candidate(s = \"racecarbanana\") == True\n assert candidate(s = \"abaabbab\") == True\n assert candidate(s = \"racecarabacaba\") == False\n assert candidate(s = \"abcdeedcba\") == True\n assert candidate(s = \"aabbccddeeeeddcbaabbccdd\") == False\n assert candidate(s = \"deeeeefeee\") == True\n assert candidate(s = \"rotorleveldeifiedleveldeifiedrotor\") == False\n assert candidate(s = \"aabbccddeeeeedddccbbaa\") == False\n assert candidate(s = \"abccbaabccbaabccbaabccbaabccbaabccbaabccbaabccba\") == True\n assert candidate(s = \"deifiedcivic\") == False\n assert candidate(s = \"abcbaabcbabcba\") == True\n assert candidate(s = \"civicracecar\") == False\n assert candidate(s = \"wasitacaroracatisaw\") == True\n assert candidate(s = \"rotorcentralpalindromerotor\") == False\n assert candidate(s = \"abcdcbaabdcbaabcdcba\") == False\n assert candidate(s = \"aibohphobia\") == True\n assert candidate(s = \"leveldeifiedcivic\") == True\n assert candidate(s = \"referredder\") == False\n assert candidate(s = \"level\") == True\n assert candidate(s = \"aabbccdd\") == False\n assert candidate(s = \"rotorleveltwol\") == False\n assert candidate(s = \"levellevellevel\") == True\n assert candidate(s = \"rotorpusher\") == False\n assert candidate(s = \"abccbaabc\") == False\n assert candidate(s = \"referreferrefer\") == True\n assert candidate(s = \"xyzyzyxyz\") == True\n assert candidate(s = \"madamrotorlevel\") == True\n assert candidate(s = \"madam\") == True\n assert candidate(s = \"mammadmam\") == False\n assert candidate(s = \"ababababababa\") == True\n assert candidate(s = \"racecarlevelmadam\") == True\n assert candidate(s = \"abababab\") == False\n assert candidate(s = \"civiccivicciviccivicciviccivic\") == True\n assert candidate(s = \"wasitacaroracitisawreferredder\") == False\n assert candidate(s = \"xxyyxyyxxyyxyyxxyyxyy\") == True\n assert candidate(s = \"abababa\") == True\n assert candidate(s = \"racecarracecarracecarracecarracecar\") == True\n assert candidate(s = \"referredderreferredderreferredder\") == False\n assert candidate(s = \"levelonevenflow\") == False\n assert candidate(s = \"referreferreferreferreferrefer\") == True\n assert candidate(s = \"deifiedrotor\") == False\n assert candidate(s = \"abcbaababcbcabcba\") == False\n assert candidate(s = \"banana\") == False\n assert candidate(s = \"levelonevenone\") == False\n assert candidate(s = \"rotorrotorrotorrotorrotor\") == True\n assert candidate(s = \"aabbccddeeffgg\") == False\n assert candidate(s = \"detartrated\") == True\n assert candidate(s = \"abbcbba\") == True\n assert candidate(s = \"aabbabba\") == True\n assert candidate(s = \"racecarannakayak\") == True\n assert candidate(s = \"amanaplanacanalpanama\") == True\n assert candidate(s = \"refermadamrefermadam\") == False\n assert candidate(s = \"racecarleveldadlevel\") == False\n assert candidate(s = \"abbaeaeabba\") == True\n assert candidate(s = \"racecarracecar\") == True\n assert candidate(s = \"rotorreferredder\") == True\n assert candidate(s = \"noonnoonnoon\") == True\n assert candidate(s = \"levelrefercivic\") == True\n assert candidate(s = \"deified\") == True\n assert candidate(s = \"abbaabbaabba\") == True\n assert candidate(s = \"levelmadamatadammadam\") == False\n assert candidate(s = \"abcdedcba\") == True\n assert candidate(s = \"rotormadamrotor\") == True\n assert candidate(s = \"rotorrotorrotor\") == True\n assert candidate(s = \"xyxzyxyxzyx\") == False\n assert candidate(s = \"rotorresistor\") == False\n assert candidate(s = \"xylophonelevel\") == False\n assert candidate(s = \"deifiedrotordeified\") == True\n assert candidate(s = \"racecarrotorrotorcarcerac\") == False\n assert candidate(s = \"abccbaabcba\") == False\n assert candidate(s = \"noonnoonnoonnoonnoonnoonnoonnoonnoonnoonnoonnoonnoon\") == True\n assert candidate(s = \"abcddcba\") == True\n assert candidate(s = \"civic\") == True\n assert candidate(s = \"rotor\") == True\n assert candidate(s = \"civicnoon\") == False\n assert candidate(s = \"madamatadammadam\") == False\n assert candidate(s = \"repaperrepaperrepaper\") == True\n assert candidate(s = \"rotorracecarracecar\") == True\n assert candidate(s = \"civicciviccivic\") == True\n assert candidate(s = \"rotorabanana\") == False\n assert candidate(s = \"aabbccddeeefff\") == False\n assert candidate(s = \"referdeifiedrefer\") == True\n assert candidate(s = \"rotorotator\") == True\n assert candidate(s = \"aabbccddeeffgghh\") == False\n assert candidate(s = \"leveltwol\") == False\n assert candidate(s = \"rotorresistorresistor\") == False\n assert candidate(s = \"levelracecarlevel\") == True\n assert candidate(s = \"rotordetartratedleveldeifiedrotor\") == False\n assert candidate(s = \"madammadammadammadammadam\") == True\n assert candidate(s = \"deifiedrotorlevel\") == True\n assert candidate(s = \"refercivicrefer\") == True\n assert candidate(s = \"abccbaabccbaabccbaabccbaabccba\") == True\n assert candidate(s = \"leveldeified\") == False\n assert candidate(s = \"rotorlevelmadam\") == True\n assert candidate(s = \"neveroddoreven\") == True\n assert candidate(s = \"redividerleveldeified\") == True\n assert candidate(s = \"refer\") == True\n", "comparison": "exact"}, "public_tests": ["\"abcbdd\"", "\"bcbddxy\""], "hints": ["Preprocess checking palindromes in O(1)", "Note that one string is a prefix and another one is a suffix you can try brute forcing the rest"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().checkPartitioning", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:25+00:00", "tests_total": 165, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function checkPartitioning($s) {", "container": "Solution", "callable": "checkPartitioning", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1748, "task_id": "sum-of-unique-elements", "difficulty": "Easy", "problem_description": "You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.\n\nReturn the sum of all the unique elements of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,2]\nOutput: 4\nExplanation: The unique elements are [1,3], and the sum is 4.\n\nExample 2:\n\nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: There are no unique elements, and the sum is 0.\n\nExample 3:\n\nInput: nums = [1,2,3,4,5]\nOutput: 15\nExplanation: The unique elements are [1,2,3,4,5], and the sum is 15.\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, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 54\n assert candidate(nums = [10, 20, 20, 10, 30]) == 30\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 = [7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 100, 99, 98, 97, 96, 95]) == 485\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 955\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 8, 8, 8]) == 0\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1, 2, 3, 2]) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6]) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(nums = [7]) == 7\n assert candidate(nums = [5]) == 5\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 594\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]) == 155\n assert candidate(nums = [50, 50, 50, 50, 50, 51, 52, 52, 53, 53, 53, 54, 55, 55, 55, 55]) == 105\n assert candidate(nums = [10, 20, 20, 30, 30, 40, 50, 60, 60, 70, 80, 80, 90, 100]) == 360\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]) == 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, 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]) == 5050\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10]) == 37\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, 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]) == 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, 10, 10, 10]) == 0\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 40\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 10, 11]) == 42\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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50]) == 400\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 = [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]) == 2175\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10]) == 40\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 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, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 52, 53, 54, 55]) == 265\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, 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, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 6, 7, 6, 5, 8, 9, 10, 9, 8, 11, 12, 13, 12, 11, 14, 15, 16, 15, 14, 17, 18, 19, 18, 17, 20, 21, 22, 21, 20, 23, 24, 25, 24, 23]) == 119\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 955\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]) == 195\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 = [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]) == 0\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13]) == 0\n assert candidate(nums = [50, 50, 50, 51, 52, 53, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]) == 1157\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 650\n assert candidate(nums = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20]) == 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, 11, 11, 12, 12, 13, 13]) == 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]) == 465\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 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, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30]) == 490\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, 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 = [1, 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, 2, 3, 3, 4, 4, 5, 5, 5, 6]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 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]) == 0\n assert candidate(nums = [99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92, 91, 91]) == 0\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, 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 = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90]) == 855\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]) == 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]) == 210\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 0\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, 15, 14, 13, 12, 11]) == 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, 5, 10]) == 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, 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]) == 0\n assert candidate(nums = [50, 50, 50, 50, 50, 51, 52, 53, 54, 55]) == 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, 1, 2, 3, 4, 5]) == 195\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 6, 7]) == 22\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 = [5, 5, 5, 5, 5, 6, 7, 8, 8, 9, 10, 11, 12, 12, 13]) == 56\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 14, 15, 15, 16, 16, 17, 18, 18, 19, 20, 20]) == 85\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]) == 5050\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 100, 99]) == 756\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\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]) == 200\n assert candidate(nums = [10, 10, 10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20]) == 100\n assert candidate(nums = [10, 20, 10, 20, 30, 40, 30, 40, 50, 60, 50, 60, 70, 80, 70, 80, 90, 100, 90, 100]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 40\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 60, 70]) == 130\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]) == 2015\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]) == 0\n assert candidate(nums = [50, 50, 50, 50, 50, 49, 48, 47, 46, 45]) == 235\n", "comparison": "exact"}, "public_tests": ["[1,2,3,2]", "[1,1,1,1,1]", "[1,2,3,4,5]"], "hints": ["Use a dictionary to count the frequency of each number."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfUnique", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:30+00:00", "tests_total": 99, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function sumOfUnique($nums) {", "container": "Solution", "callable": "sumOfUnique", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1749, "task_id": "maximum-absolute-sum-of-any-subarray", "difficulty": "Medium", "problem_description": "You are given an integer array nums. The absolute sum of a subarray [nums_l, nums_{l+1}, ..., nums_{r-1}, nums_r] is abs(nums_l + nums_{l+1} + ... + nums_{r-1} + nums_r).\n\nReturn the maximum absolute sum of any (possibly empty) subarray of nums.\n\nNote that abs(x) is defined as follows:\n\n- If x is a negative integer, then abs(x) = -x.\n- If x is a non-negative integer, then abs(x) = x.\n\nExample 1:\n\nInput: nums = [1,-3,2,3,-4]\nOutput: 5\nExplanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.\n\nExample 2:\n\nInput: nums = [2,-5,1,-4,3,-2]\nOutput: 8\nExplanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^4 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [-10000, 10000, -10000, 10000]) == 10000\n assert candidate(nums = [1, -3, 2, 3, -4]) == 5\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [2, -5, 1, -4, 3, -2]) == 8\n assert candidate(nums = [10000, -10000, 10000, -10000, 10000]) == 10000\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [-1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [-10000, 10000, -10000, 10000, -10000]) == 10000\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\n assert candidate(nums = [1, 2, 3, 4, 5, -15, 6, 7, 8, 9, 10, -25, 11, 12, 13, 14, 15]) == 80\n assert candidate(nums = [10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 100\n assert candidate(nums = [5, 1, -2, 4, -1, -3, 6, -2, 1]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [-100, 101, -102, 103, -104, 105, -106, 107]) == 107\n assert candidate(nums = [100, -50, 25, -10, 5, -2, 1]) == 100\n assert candidate(nums = [-1, -2, -3, -4, -5, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, 5, 4, 3, 2, 1]) == 15\n assert candidate(nums = [5, -1, 3, -2, 4, -3, 6, -4, 7, -5]) == 15\n assert candidate(nums = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1]) == 1000\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000]) == 1000\n assert candidate(nums = [1, 2, 3, -6, 1, 2, 3, -6, 1, 2, 3, -6]) == 6\n assert candidate(nums = [5000, 4000, 3000, 2000, 1000, -5000, -4000, -3000, -2000, -1000]) == 15000\n assert candidate(nums = [10000, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10000]) == 10000\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -55]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 55\n assert candidate(nums = [43, 44, -87, 45, 46, 47, -135, 48, 49, 50, 51, -195, 52, 53, 54, 55, 56, -260, 57, 58]) == 276\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500]) == 500\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 15\n assert candidate(nums = [10, 20, 30, -60, 40, 50, -100, 60, 70, 80, -230, 90, 100, 110, -340, 120]) == 340\n assert candidate(nums = [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [5000, -1200, 3000, -1500, 2000, -1000, 4000]) == 10300\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 = [10000, -9999, 10000, -9999, 10000, -9999, 10000, -9999]) == 10003\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 = [5, -1, 4, -2, 3, -3, 2, -2, 1, -1, 0, 1, -1, 2, -2, 3, -3, 4, -4, 5]) == 11\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [-5, 10, -15, 20, -25, 30, -35, 40]) == 40\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 = [-5, 4, -3, 7, -8, 2, -6, 1, 9, -4]) == 12\n assert candidate(nums = [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, -3, 20, -40, 50, -60, 70, -80, 90]) == 90\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 50\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 = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120, -130, 140, -150, 160, -170, 180, -190, 200]) == 200\n assert candidate(nums = [23, -24, 25, -26, 27, -28, 29, -30, 31, -32, 33, -34, 35, -36, 37, -38, 39, -40, 41, -42]) == 42\n assert candidate(nums = [1, -100, 100, -50, 50, -25, 25, -12, 12, -6, 6]) == 100\n assert candidate(nums = [2, 3, -5, 4, 2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12]) == 13\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 100\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400]) == 400\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 15\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 5\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7]) == 7\n assert candidate(nums = [5000, -2000, 1500, -1000, 800, -700, 600, -500, 400, -300]) == 5000\n assert candidate(nums = [-3000, 4500, -5000, 6000, -7000, 8000, -9000]) == 9000\n assert candidate(nums = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000]) == 1000\n assert candidate(nums = [500, -500, 500, -500, 500, -500, 500, -500, 500, -500]) == 500\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13]) == 13\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]) == 20\n assert candidate(nums = [1, 2, -3, 4, -5, 6, -7, 8, -9, 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]) == 10\n assert candidate(nums = [3, 2, 1, 0, -1, -2, -3, 0, 3, 2, 1, 0, -1, -2, -3]) == 6\n assert candidate(nums = [9999, -9998, 9997, -9996, 9995, -9994, 9993, -9992, 9991, -9990]) == 9999\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [10000, 9000, 8000, -7000, -6000, -5000, 4000, 3000, 2000, -1000]) == 27000\n assert candidate(nums = [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, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5]) == 5\n assert candidate(nums = [5, -1, 3, -2, 7, -8, 2, -6, 4]) == 12\n assert candidate(nums = [100, 200, 300, -600, 400, 500, -1400, 600, 700, 800, 900, 1000]) == 4000\n assert candidate(nums = [-10, -20, -30, 60, -40, -50, 100, -60, -70, -80, 230, -90, -100, -110, 340, -120]) == 340\n assert candidate(nums = [-100, -200, -300, -400, -500, 1500, -600, -700, -800, -900, -1000]) == 4000\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000, 100, 200, 300, 400, 500]) == 5500\n assert candidate(nums = [5, -1, 4, -2, 3, -3, 2, -4, 1, -5, 0, 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]) == 210\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 100, -200, 300, -400, 500]) == 1200\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\n assert candidate(nums = [10000, -9000, 8000, -7000, 6000, -5000, 4000, -3000, 2000, -1000]) == 10000\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, 4, -5, 6, -7, 8, -9, 10]) == 10\n assert candidate(nums = [-5000, 5000, 0, -5000, 5000, 0, -5000, 5000, 0]) == 5000\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 15\n assert candidate(nums = [10000, -10000, 10000, -10000, 10000, -10000]) == 10000\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]) == 41\n assert candidate(nums = [5000, -2000, 1000, -500, 250, -125, 62, -31, 15, -7, 3, -1]) == 5000\n assert candidate(nums = [10000, 10000, 10000, -10000, -10000, -10000, 10000]) == 30000\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, -15, 6, 7, 8, 9, 10]) == 40\n assert candidate(nums = [1000, -2000, 3000, -4000, 5000]) == 5000\n assert candidate(nums = [100, 200, 300, 400, 500, -1500, 600, 700, 800, 900, 1000]) == 4000\n assert candidate(nums = [-9999, 9998, -9997, 9996, -9995, 9994]) == 9999\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 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\n assert candidate(nums = [100, -1, 200, -2, 300, -3, 400, -4, 500, -5]) == 1490\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -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\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110]) == 110\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, 11, -12, 13, -14, 15, -16, 17, -18, 19, 20, -21, 22]) == 40\n assert candidate(nums = [10000, -9999, 9998, -9997, 9996, -9995, 9994, -9993, 9992, -9991]) == 10000\n assert candidate(nums = [5, -3, 8, -1, 4, -7, 9, -2, 6, -10]) == 19\n assert candidate(nums = [10000, -9999, 9998, -9997, 9996, -9995, 9994]) == 10000\n assert candidate(nums = [5, -3, 8, -6, 2, -4, 7, -9, 1, -1]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,-3,2,3,-4]", "[2,-5,1,-4,3,-2]"], "hints": ["What if we asked for maximum sum, not absolute sum?", "It's a standard problem that can be solved by Kadane's algorithm.", "The key idea is the max absolute sum will be either the max sum or the min sum.", "So just run kadane twice, once calculating the max sum and once calculating the min sum."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxAbsoluteSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:32+00:00", "tests_total": 110, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function maxAbsoluteSum($nums) {", "container": "Solution", "callable": "maxAbsoluteSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1750, "task_id": "minimum-length-of-string-after-deleting-similar-ends", "difficulty": "Medium", "problem_description": "Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:\n\n1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.\n2. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.\n3. The prefix and the suffix should not intersect at any index.\n4. The characters from the prefix and suffix must be the same.\n5. Delete both the prefix and the suffix.\n\nReturn the minimum length of s after performing the above operation any number of times (possibly zero times).\n\nExample 1:\n\nInput: s = \"ca\"\nOutput: 2\nExplanation: You can't remove any characters, so the string stays as is.\n\nExample 2:\n\nInput: s = \"cabaabac\"\nOutput: 0\nExplanation: An optimal sequence of operations is:\n- Take prefix = \"c\" and suffix = \"c\" and remove them, s = \"abaaba\".\n- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"baab\".\n- Take prefix = \"b\" and suffix = \"b\" and remove them, s = \"aa\".\n- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"\".\n\nExample 3:\n\nInput: s = \"aabccabba\"\nOutput: 3\nExplanation: An optimal sequence of operations is:\n- Take prefix = \"aa\" and suffix = \"a\" and remove them, s = \"bccabb\".\n- Take prefix = \"b\" and suffix = \"bb\" and remove them, s = \"cca\".\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s only consists of characters 'a', 'b', and 'c'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == 1\n assert candidate(s = \"ca\") == 2\n assert candidate(s = \"abac\") == 4\n assert candidate(s = \"aabccabba\") == 3\n assert candidate(s = \"aabbaa\") == 0\n assert candidate(s = \"aaaaa\") == 0\n assert candidate(s = \"aababbaa\") == 1\n assert candidate(s = \"cabaabac\") == 0\n assert candidate(s = \"aabbccbaa\") == 0\n assert candidate(s = \"aaa\") == 0\n assert candidate(s = \"abcabc\") == 6\n assert candidate(s = \"aabbbcccbbaa\") == 0\n assert candidate(s = \"aababa\") == 1\n assert candidate(s = \"aabcccbaa\") == 0\n assert candidate(s = \"abc\") == 3\n assert candidate(s = \"abbaccaa\") == 5\n assert candidate(s = \"aaaa\") == 0\n assert candidate(s = \"abccba\") == 0\n assert candidate(s = \"aaabaaa\") == 1\n assert candidate(s = \"aabbcc\") == 6\n assert candidate(s = \"abca\") == 2\n assert candidate(s = \"cccccc\") == 0\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababab\") == 76\n assert candidate(s = \"aabacccbaa\") == 4\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabacab\") == 42\n assert candidate(s = \"aabbbcccbbbbaa\") == 0\n assert candidate(s = \"ccabbbcccabbbcccabbbcc\") == 18\n assert candidate(s = \"abccbaabccbaabccbaabccba\") == 0\n assert candidate(s = \"acabacabacabacabacabacabacabacab\") == 32\n assert candidate(s = \"cccaaaaabbb\") == 11\n assert candidate(s = \"aaaabbbbccccaaaabbbbcccc\") == 24\n assert candidate(s = \"aaabbbbbbbbccccccaaa\") == 14\n assert candidate(s = \"cbabcbabcb\") == 10\n assert candidate(s = \"bbbbbbaaaaa\") == 11\n assert candidate(s = \"abcabcabc\") == 9\n assert candidate(s = \"aaaabaaaabaaa\") == 0\n assert candidate(s = \"abcabcabcabc\") == 12\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbccccc\") == 24\n assert candidate(s = \"abccbaabcbaabccba\") == 1\n assert candidate(s = \"abacabacabaacaba\") == 1\n assert candidate(s = \"aaabaaaabbaaaabaa\") == 0\n assert candidate(s = \"abacaabacaabaca\") == 13\n assert candidate(s = \"abacbacbacbacbacba\") == 14\n assert candidate(s = \"aaaabaaaabaaaabaaa\") == 1\n assert candidate(s = \"aabccccbbaa\") == 0\n assert candidate(s = \"aaaabbbbcccc\") == 12\n assert candidate(s = \"aabccbaaab\") == 10\n assert candidate(s = \"aaabbbcccbbbbaaa\") == 0\n assert candidate(s = \"aabbbcccbbaaaabbbcccbbaaa\") == 0\n assert candidate(s = \"abbbbaaaaabbbaaaaabbbb\") == 22\n assert candidate(s = \"cccaaaaabbbcccbaaabccbaaabccbaaabccbaa\") == 38\n assert candidate(s = \"bbbbaaaaabbbb\") == 0\n assert candidate(s = \"abccbaabccba\") == 0\n assert candidate(s = \"aaabaaaabbbaaa\") == 0\n assert candidate(s = \"abacabacaba\") == 1\n assert candidate(s = \"aaabaaaabaaaabaaa\") == 1\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba\") == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabc\") == 36\n assert candidate(s = \"abacaba\") == 1\n assert candidate(s = \"cccbbbaaa\") == 9\n assert candidate(s = \"abcbaabcbacba\") == 7\n assert candidate(s = \"aaabaaaabba\") == 0\n assert candidate(s = \"aabbaabbaabbaabb\") == 16\n assert candidate(s = \"abcabcabcabcabcabcabc\") == 21\n assert candidate(s = \"ccabbbccbbbbcabcabbbccabc\") == 22\n assert candidate(s = \"cccccccccccccccccccccc\") == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 99\n assert candidate(s = \"acaacacaacac\") == 12\n assert candidate(s = \"aaabbbcccbbbaaa\") == 0\n assert candidate(s = \"abcbaabcbaabcbaabcbaabcbaabcbaabcba\") == 1\n assert candidate(s = \"abccbaabccbaabccba\") == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 30\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabb\") == 32\n assert candidate(s = \"aaaaabbbbbcccccaaaa\") == 10\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 48\n assert candidate(s = \"ababbababbababb\") == 15\n assert candidate(s = \"aabbbcccbaa\") == 0\n assert candidate(s = \"acaacaaca\") == 1\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 93\n assert candidate(s = \"aabbaaabbbaaabbbaaabbaa\") == 0\n assert candidate(s = \"accbabcbaccbacc\") == 15\n assert candidate(s = \"abcabcabcabcabcabc\") == 18\n assert candidate(s = \"abcbaabcba\") == 0\n assert candidate(s = \"aabbccbbccbbccaa\") == 12\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(s = \"aaaabbbcccbbbaaa\") == 0\n assert candidate(s = \"cbbccbbcc\") == 0\n assert candidate(s = \"abacbacbacbacbacbacbac\") == 22\n assert candidate(s = \"aaaaabccccbaaaa\") == 0\n assert candidate(s = \"ccccaaaabbbbaaaa\") == 16\n assert candidate(s = \"aaabbbcccbbbbaaabbbcccbbbbaaa\") == 0\n assert candidate(s = \"ababababababababababab\") == 22\n assert candidate(s = \"aaaabbbbccccccaaaabbbb\") == 22\n assert candidate(s = \"aabbaaabbbaaabbbaaabbaaa\") == 0\n assert candidate(s = \"abababababababababab\") == 20\n assert candidate(s = \"aaaabccccbbbbaaaa\") == 0\n assert candidate(s = \"aabbbbccccbbbbaaa\") == 0\n assert candidate(s = \"aabaaabaaa\") == 0\n assert candidate(s = \"aabccccbaa\") == 0\n assert candidate(s = \"acccba\") == 4\n assert candidate(s = \"abacbacbacbacbaba\") == 11\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 42\n assert candidate(s = \"aaaabbbaaabbbbaaaabbbaaaa\") == 0\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabac\") == 96\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 90\n assert candidate(s = \"aaabbbcccbbaaa\") == 0\n assert candidate(s = \"ccbaaaabbbcccbaaaabbbccc\") == 0\n assert candidate(s = \"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\") == 0\n assert candidate(s = \"cccccccccccccccccc\") == 0\n assert candidate(s = \"aaaabbaaabbbaaaa\") == 0\n assert candidate(s = \"aabbaabbaabbaabbaabb\") == 20\n assert candidate(s = \"ababaababa\") == 0\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(s = \"abcbaabcbaabcba\") == 1\n assert candidate(s = \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == 0\n assert candidate(s = \"aabbaaccbbbaa\") == 4\n assert candidate(s = \"ccccccc\") == 0\n assert candidate(s = \"abccbaabcba\") == 0\n assert candidate(s = \"ababababab\") == 10\n assert candidate(s = \"ccccaaaabbbbcccc\") == 8\n assert candidate(s = \"babbacabacababb\") == 1\n assert candidate(s = \"ccccccabbbbbbbcc\") == 8\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 24\n assert candidate(s = \"aabbaabbccbbccbbccaa\") == 16\n assert candidate(s = \"aaabbbcccbaabbbcccbaaabbb\") == 25\n assert candidate(s = \"ababa\") == 1\n assert candidate(s = \"acaabaaaca\") == 1\n assert candidate(s = \"aabbccbbccbbccbbccaa\") == 16\n assert candidate(s = \"ccccbaaaabbbcccbaaaabbbccc\") == 0\n assert candidate(s = \"aaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaab\") == 72\n assert candidate(s = \"aaaaabbbbbccccccccbbbbbbaaaaa\") == 0\n assert candidate(s = \"ccabbaacc\") == 0\n assert candidate(s = \"acbacbacbacbacba\") == 14\n assert candidate(s = \"abcabcabcabcabc\") == 15\n assert candidate(s = \"ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\") == 0\n assert candidate(s = \"caabaccaabaaccaaa\") == 17\n", "comparison": "exact"}, "public_tests": ["\"ca\"", "\"cabaabac\"", "\"aabccabba\""], "hints": ["If both ends have distinct characters, no more operations can be made. Otherwise, the only operation is to remove all of the same characters from both ends. We will do this as many times as we can.", "Note that if the length is equal 1 the answer is 1"], "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-30T20:29:34+00:00", "tests_total": 170, "tests_dropped": 34, "flags": [], "topic_tags": ["two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function minimumLength($s) {", "container": "Solution", "callable": "minimumLength", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1751, "task_id": "maximum-number-of-events-that-can-be-attended-ii", "difficulty": "Hard", "problem_description": "You are given an array of events where events[i] = [startDay_i, endDay_i, value_i]. The i^th event starts at startDay_iand ends at endDay_i, and if you attend this event, you will receive a value of value_i. You are also given an integer k which represents the maximum number of events you can attend.\n\nYou can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.\n\nReturn the maximum sum of values that you can receive by attending events.\n\nExample 1:\n\nInput: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2\nOutput: 7\nExplanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.\n\nExample 2:\n\nInput: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2\nOutput: 10\nExplanation: Choose event 2 for a total value of 10.\nNotice that you cannot attend any other event as they overlap, and that you do not have to attend k events.\n\nExample 3:\n\nInput: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\nOutput: 9\nExplanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.\n\nConstraints:\n\n- 1 <= k <= events.length\n- 1 <= k * events.length <= 10^6\n- 1 <= startDay_i <= endDay_i <= 10^9\n- 1 <= value_i <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(events = [[1, 5, 4], [11, 15, 1], [8, 10, 2], [2, 11, 6]],k = 3) == 7\n assert candidate(events = [[2, 8, 6], [4, 9, 10], [6, 8, 3]],k = 2) == 10\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [6, 10, 5], [2, 9, 4]],k = 2) == 11\n assert candidate(events = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500]],k = 3) == 900\n assert candidate(events = [[1, 2, 7], [2, 3, 10], [3, 4, 3], [1, 5, 5], [6, 7, 1]],k = 4) == 11\n assert candidate(events = [[1, 2, 4], [3, 5, 1], [5, 6, 2], [6, 7, 3]],k = 3) == 8\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [6, 10, 5], [2, 9, 8]],k = 2) == 11\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [6, 10, 5], [2, 7, 8], [9, 10, 4]],k = 3) == 12\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [6, 6, 5], [2, 7, 9]],k = 3) == 11\n assert candidate(events = [[2, 8, 6], [2, 9, 9], [1, 6, 1], [3, 5, 5], [1, 5, 3]],k = 2) == 9\n assert candidate(events = [[1, 2, 100], [2, 3, 100], [3, 4, 100]],k = 1) == 100\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [1, 5, 5], [2, 3, 5], [2, 3, 5]],k = 1) == 6\n assert candidate(events = [[1, 2, 4], [3, 4, 3], [2, 3, 1]],k = 2) == 7\n assert candidate(events = [[1, 2, 3], [4, 5, 4], [1, 5, 5]],k = 2) == 7\n assert candidate(events = [[1, 2, 4], [3, 4, 3], [2, 3, 10]],k = 2) == 10\n assert candidate(events = [[1, 3, 5], [2, 4, 6], [3, 5, 7], [4, 6, 8]],k = 2) == 13\n assert candidate(events = [[1, 5, 3], [1, 5, 6], [1, 5, 5]],k = 2) == 6\n assert candidate(events = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]],k = 3) == 9\n assert candidate(events = [[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]],k = 5) == 50\n assert candidate(events = [[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9], [2, 11, 10], [3, 12, 11], [4, 13, 12], [5, 14, 13], [6, 15, 14]],k = 5) == 18\n assert candidate(events = [[1, 3, 10], [2, 4, 20], [3, 5, 30], [4, 6, 40], [5, 7, 50], [6, 8, 60], [7, 9, 70], [8, 10, 80], [9, 11, 90], [10, 12, 100], [11, 13, 110], [12, 14, 120]],k = 4) == 300\n assert candidate(events = [[1, 1000000000, 1], [1, 1000000000, 2], [1, 1000000000, 3], [1, 1000000000, 4], [1, 1000000000, 5]],k = 5) == 5\n assert candidate(events = [[1, 2, 10], [10, 11, 10], [20, 21, 10], [30, 31, 10], [40, 41, 10], [50, 51, 10], [60, 61, 10], [70, 71, 10], [80, 81, 10], [90, 91, 10]],k = 5) == 50\n assert candidate(events = [[1, 1000000000, 1000000], [2, 999999999, 999999], [3, 888888888, 888888], [4, 777777777, 777777], [5, 666666666, 666666]],k = 3) == 1000000\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [15, 25, 150], [26, 35, 250]],k = 4) == 600\n assert candidate(events = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900], [10, 11, 1000], [11, 12, 1100], [12, 13, 1200], [13, 14, 1300]],k = 7) == 4900\n assert candidate(events = [[1, 10, 10], [2, 9, 8], [3, 8, 6], [4, 7, 4], [5, 6, 2]],k = 5) == 10\n assert candidate(events = [[1, 1, 1000000], [2, 2, 999999], [3, 3, 999998], [4, 4, 999997], [5, 5, 999996], [6, 6, 999995], [7, 7, 999994], [8, 8, 999993], [9, 9, 999992], [10, 10, 999991]],k = 5) == 4999990\n assert candidate(events = [[1, 2, 10], [3, 4, 20], [2, 3, 15], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40], [8, 9, 45], [9, 10, 50], [10, 11, 55]],k = 4) == 160\n assert candidate(events = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1, 7, 7], [1, 8, 8], [1, 9, 9], [1, 10, 10]],k = 1) == 10\n assert candidate(events = [[1, 1, 1000], [2, 2, 2000], [3, 3, 3000], [4, 4, 4000], [5, 5, 5000], [6, 6, 6000], [7, 7, 7000], [8, 8, 8000], [9, 9, 9000]],k = 5) == 35000\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120], [13, 14, 130], [14, 15, 140]],k = 7) == 560\n assert candidate(events = [[1, 10, 5], [2, 9, 6], [3, 8, 7], [4, 7, 8], [5, 6, 9], [11, 20, 10], [12, 19, 11], [13, 18, 12], [14, 17, 13], [15, 16, 14]],k = 4) == 23\n assert candidate(events = [[1, 3, 1000], [2, 5, 1000], [3, 7, 1000], [4, 8, 1000], [5, 10, 1000], [6, 11, 1000], [7, 12, 1000], [8, 13, 1000], [9, 14, 1000], [10, 15, 1000]],k = 5) == 3000\n assert candidate(events = [[1, 2, 1000000], [2, 3, 999999], [3, 4, 999998], [4, 5, 999997], [5, 6, 999996], [6, 7, 999995], [7, 8, 999994], [8, 9, 999993], [9, 10, 999992]],k = 5) == 4999980\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [31, 40, 400], [41, 50, 500], [51, 60, 600]],k = 3) == 1500\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110]],k = 6) == 360\n assert candidate(events = [[1, 10, 10], [2, 9, 20], [3, 8, 30], [4, 7, 40], [5, 6, 50], [1, 10, 60], [2, 9, 70], [3, 8, 80], [4, 7, 90], [5, 6, 100]],k = 5) == 100\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100]],k = 5) == 300\n assert candidate(events = [[1, 1000000000, 1000000], [2, 999999999, 900000], [3, 999999998, 800000], [4, 999999997, 700000], [5, 999999996, 600000], [6, 999999995, 500000], [7, 999999994, 400000], [8, 999999993, 300000], [9, 999999992, 200000], [10, 999999991, 100000]],k = 5) == 1000000\n assert candidate(events = [[1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10], [1, 2, 10]],k = 5) == 10\n assert candidate(events = [[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9]],k = 2) == 9\n assert candidate(events = [[1, 2, 5], [3, 5, 10], [5, 7, 15], [7, 9, 20], [9, 11, 25], [11, 13, 30]],k = 4) == 65\n assert candidate(events = [[1, 3, 50], [2, 4, 60], [3, 5, 70], [4, 6, 80], [5, 7, 90], [6, 8, 100], [7, 9, 110], [8, 10, 120], [9, 11, 130], [10, 12, 140]],k = 3) == 330\n assert candidate(events = [[1, 2, 1], [3, 4, 2], [5, 6, 3], [7, 8, 4], [9, 10, 5], [11, 12, 6], [13, 14, 7], [15, 16, 8], [17, 18, 9], [19, 20, 10], [21, 22, 11], [23, 24, 12]],k = 6) == 57\n assert candidate(events = [[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]],k = 13) == 91\n assert candidate(events = [[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, 9], [1, 20, 10], [11, 20, 11], [21, 30, 12], [31, 40, 13], [41, 50, 14]],k = 5) == 59\n assert candidate(events = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900]],k = 4) == 2400\n assert candidate(events = [[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) == 40\n assert candidate(events = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900], [10, 11, 1000], [11, 12, 1100], [12, 13, 1200], [13, 14, 1300]],k = 6) == 4800\n assert candidate(events = [[1, 10, 100], [2, 5, 200], [3, 8, 300], [6, 12, 400], [9, 15, 500]],k = 3) == 800\n assert candidate(events = [[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]],k = 10) == 30\n assert candidate(events = [[1, 10, 1], [11, 20, 2], [21, 30, 3], [31, 40, 4], [41, 50, 5], [51, 60, 6], [61, 70, 7], [71, 80, 8], [81, 90, 9]],k = 9) == 45\n assert candidate(events = [[1, 2, 4], [1, 2, 3], [1, 2, 2], [1, 2, 1], [3, 4, 5], [3, 4, 6], [5, 6, 7], [5, 6, 8]],k = 3) == 18\n assert candidate(events = [[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]],k = 9) == 50\n assert candidate(events = [[1, 1000000000, 1], [2, 1000000000, 2], [3, 1000000000, 3], [4, 1000000000, 4], [5, 1000000000, 5]],k = 3) == 5\n assert candidate(events = [[1, 2, 1000000], [10, 11, 999999], [20, 21, 999998], [30, 31, 999997], [40, 41, 999996], [50, 51, 999995], [60, 61, 999994], [70, 71, 999993], [80, 81, 999992], [90, 91, 999991]],k = 10) == 9999955\n assert candidate(events = [[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9], [1, 11, 10], [1, 12, 11], [1, 13, 12], [1, 14, 13], [1, 15, 14]],k = 7) == 14\n assert candidate(events = [[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5], [1, 5, 6], [1, 5, 7], [1, 5, 8], [1, 5, 9], [1, 5, 10], [1, 5, 11], [1, 5, 12], [1, 5, 13], [1, 5, 14], [1, 5, 15]],k = 5) == 15\n assert candidate(events = [[1, 10, 10], [11, 20, 20], [21, 30, 30], [31, 40, 40], [41, 50, 50], [51, 60, 60], [61, 70, 70], [71, 80, 80], [81, 90, 90], [91, 100, 100]],k = 10) == 550\n assert candidate(events = [[1, 3, 100], [2, 5, 200], [3, 6, 300], [4, 7, 400], [5, 8, 500], [6, 9, 600]],k = 3) == 800\n assert candidate(events = [[1, 2, 1], [3, 4, 2], [5, 6, 3], [7, 8, 4], [9, 10, 5], [11, 12, 6], [13, 14, 7], [15, 16, 8], [17, 18, 9], [19, 20, 10]],k = 5) == 40\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120]],k = 10) == 420\n assert candidate(events = [[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [2, 3, 6], [2, 4, 7], [2, 5, 8], [2, 6, 9], [3, 4, 10], [3, 5, 11], [3, 6, 12], [4, 5, 13], [4, 6, 14], [5, 6, 15]],k = 3) == 26\n assert candidate(events = [[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, 1]],k = 5) == 1\n assert candidate(events = [[1, 1, 100], [1, 1, 200], [1, 1, 300], [1, 1, 400], [1, 1, 500], [1, 1, 600], [1, 1, 700], [1, 1, 800], [1, 1, 900], [1, 1, 1000]],k = 5) == 1000\n assert candidate(events = [[1, 5, 5], [5, 10, 10], [10, 15, 15], [15, 20, 20], [20, 25, 25], [25, 30, 30], [30, 35, 35]],k = 3) == 75\n assert candidate(events = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [2, 2, 1], [2, 3, 2], [2, 4, 3], [2, 5, 4], [3, 3, 1], [3, 4, 2], [3, 5, 3], [4, 4, 1], [4, 5, 2], [5, 5, 1]],k = 3) == 5\n assert candidate(events = [[5, 10, 15], [5, 7, 10], [7, 12, 20], [9, 15, 18], [10, 17, 12], [13, 20, 30], [14, 20, 25]],k = 3) == 50\n assert candidate(events = [[1, 10, 1], [2, 9, 2], [3, 8, 3], [4, 7, 4], [5, 6, 5], [11, 20, 6], [12, 19, 7], [13, 18, 8], [14, 17, 9], [15, 16, 10]],k = 5) == 15\n assert candidate(events = [[1, 3, 100], [2, 5, 200], [3, 6, 300], [4, 7, 400], [5, 8, 500], [6, 9, 600]],k = 4) == 800\n assert candidate(events = [[1, 1, 100], [2, 2, 200], [3, 3, 300], [4, 4, 400], [5, 5, 500], [6, 6, 600], [7, 7, 700], [8, 8, 800], [9, 9, 900], [10, 10, 1000]],k = 10) == 5500\n assert candidate(events = [[1, 5, 5], [6, 10, 10], [11, 15, 15], [16, 20, 20], [21, 25, 25], [26, 30, 30], [31, 35, 35], [36, 40, 40], [41, 45, 45], [46, 50, 50]],k = 5) == 200\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120]],k = 6) == 420\n assert candidate(events = [[1, 1000000000, 1], [1, 1000000000, 2], [1, 1000000000, 3], [1, 1000000000, 4], [1, 1000000000, 5]],k = 2) == 5\n assert candidate(events = [[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]],k = 5) == 25\n assert candidate(events = [[1, 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]],k = 3) == 23\n assert candidate(events = [[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]],k = 7) == 63\n assert candidate(events = [[1, 1000000000, 1], [1000000000, 1000000000, 1000000]],k = 1) == 1000000\n assert candidate(events = [[1, 2, 1], [1, 2, 2], [1, 2, 3], [2, 3, 4], [2, 3, 5], [2, 3, 6], [3, 4, 7], [3, 4, 8], [3, 4, 9], [4, 5, 10]],k = 3) == 16\n assert candidate(events = [[1, 3, 50], [2, 5, 20], [4, 6, 40], [6, 9, 60], [8, 11, 80], [10, 12, 30]],k = 3) == 170\n assert candidate(events = [[1, 2, 1000000], [2, 3, 1000000], [3, 4, 1000000], [4, 5, 1000000], [5, 6, 1000000], [6, 7, 1000000]],k = 3) == 3000000\n assert candidate(events = [[1, 2, 100], [3, 4, 200], [5, 6, 300], [7, 8, 400], [9, 10, 500], [11, 12, 600], [13, 14, 700], [15, 16, 800], [17, 18, 900]],k = 5) == 3500\n assert candidate(events = [[1, 3, 10], [2, 5, 20], [3, 7, 30], [4, 8, 40], [5, 9, 50], [6, 10, 60], [7, 11, 70], [8, 12, 80], [9, 13, 90]],k = 4) == 140\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [31, 40, 400], [41, 50, 500], [51, 60, 600], [61, 70, 700], [71, 80, 800], [81, 90, 900], [91, 100, 1000]],k = 5) == 4000\n assert candidate(events = [[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9], [1, 11, 10]],k = 5) == 10\n assert candidate(events = [[1, 2, 1000], [2, 3, 2000], [3, 4, 3000], [4, 5, 4000], [5, 6, 5000], [6, 7, 6000], [7, 8, 7000], [8, 9, 8000], [9, 10, 9000]],k = 9) == 25000\n assert candidate(events = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1, 7, 7], [1, 8, 8], [1, 9, 9], [1, 10, 10], [1, 11, 11], [1, 12, 12], [1, 13, 13], [1, 14, 14], [1, 15, 15]],k = 15) == 15\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [31, 40, 400], [41, 50, 500], [51, 60, 600], [61, 70, 700], [71, 80, 800], [81, 90, 900], [91, 100, 1000]],k = 3) == 2700\n assert candidate(events = [[1, 20, 100], [2, 15, 80], [3, 10, 60], [4, 5, 40], [5, 6, 20], [6, 7, 10], [7, 8, 5], [8, 9, 3], [9, 10, 2], [10, 11, 1], [11, 12, 2], [12, 13, 3], [13, 14, 5], [14, 15, 10], [15, 16, 20], [16, 17, 40], [17, 18, 60], [18, 19, 80], [19, 20, 100]],k = 10) == 247\n assert candidate(events = [[1, 3, 5], [2, 5, 8], [4, 6, 6], [6, 8, 3], [5, 7, 10], [7, 9, 4]],k = 4) == 15\n assert candidate(events = [[1, 2, 100], [3, 5, 150], [6, 8, 200], [9, 11, 250], [12, 14, 300], [15, 17, 350]],k = 4) == 1100\n assert candidate(events = [[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]],k = 5) == 30\n assert candidate(events = [[1, 100, 1000], [2, 99, 900], [3, 98, 800], [4, 97, 700], [5, 96, 600], [6, 95, 500], [7, 94, 400], [8, 93, 300], [9, 92, 200], [10, 91, 100]],k = 5) == 1000\n assert candidate(events = [[1, 100, 1], [50, 150, 10], [100, 200, 50], [150, 250, 100], [200, 300, 200], [250, 350, 500], [300, 400, 1000], [350, 450, 2000], [400, 500, 5000]],k = 5) == 5550\n assert candidate(events = [[1, 2, 5], [1, 2, 5], [1, 2, 5], [1, 2, 5], [1, 2, 5], [1, 2, 5], [1, 2, 5]],k = 4) == 5\n assert candidate(events = [[1, 50, 500], [51, 100, 400], [101, 150, 300], [151, 200, 200], [201, 250, 100]],k = 3) == 1200\n assert candidate(events = [[1, 10, 50], [11, 20, 100], [21, 30, 150], [31, 40, 200], [41, 50, 250]],k = 3) == 600\n assert candidate(events = [[1, 3, 5], [2, 4, 6], [3, 5, 7], [4, 6, 8], [5, 7, 9], [6, 8, 10], [7, 9, 11], [8, 10, 12], [9, 11, 13]],k = 4) == 30\n assert candidate(events = [[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]],k = 7) == 77\n assert candidate(events = [[1, 2, 50], [1, 3, 40], [1, 4, 30], [1, 5, 20], [1, 6, 10], [2, 7, 60], [3, 8, 70], [4, 9, 80], [5, 10, 90], [6, 11, 100]],k = 4) == 150\n assert candidate(events = [[1, 2, 10], [1, 2, 20], [1, 2, 30], [1, 2, 40], [1, 2, 50], [1, 2, 60], [1, 2, 70], [1, 2, 80], [1, 2, 90], [1, 2, 100]],k = 3) == 100\n", "comparison": "exact"}, "public_tests": ["[[1,2,4],[3,4,3],[2,3,1]]\n2", "[[1,2,4],[3,4,3],[2,3,10]]\n2", "[[1,1,1],[2,2,2],[3,3,3],[4,4,4]]\n3"], "hints": ["Sort the events by its startTime.", "For every event, you can either choose it and consider the next event available, or you can ignore it. You can efficiently find the next event that is available using binary search."], "metadata": {"canonical_parameter_names": ["events", "k"], "leetcode_dataset_entry_point": "Solution().maxValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:37+00:00", "tests_total": 108, "tests_dropped": 6, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "dynamic-programming", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxValue($events, $k) {", "container": "Solution", "callable": "maxValue", "parameters": [{"name": "events", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1752, "task_id": "check-if-array-is-sorted-and-rotated", "difficulty": "Easy", "problem_description": "Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.\n\nThere may be duplicates in the original array.\n\nNote: An array A rotated by x positions results in an array B of the same length such that B[i] == A[(i+x) % A.length] for every valid index i.\n\nExample 1:\n\nInput: nums = [3,4,5,1,2]\nOutput: true\nExplanation: [1,2,3,4,5] is the original sorted array.\nYou can rotate the array by x = 2 positions to begin on the element of value 3: [3,4,5,1,2].\n\nExample 2:\n\nInput: nums = [2,1,3,4]\nOutput: false\nExplanation: There is no sorted array once rotated that can make nums.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: true\nExplanation: [1,2,3] is the original sorted array.\nYou can rotate the array by x = 0 positions (i.e. no rotation) to make nums.\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 = [2, 1, 3, 4]) == False\n assert candidate(nums = [1, 3, 2]) == False\n assert candidate(nums = [4, 5, 6, 1, 2, 3]) == True\n assert candidate(nums = [1, 3, 5, 7, 2, 4, 6, 8]) == False\n assert candidate(nums = [2, 2, 1, 1, 1]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [2, 1, 2]) == True\n assert candidate(nums = [1, 2, 3]) == True\n assert candidate(nums = [1, 1, 1]) == True\n assert candidate(nums = [2, 3, 4, 5, 1]) == True\n assert candidate(nums = [5, 1, 2, 3, 4]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == True\n assert candidate(nums = [100, 1, 100, 100]) == True\n assert candidate(nums = [3, 4, 5, 1, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 3, 2, 4, 5]) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 1, 3]) == False\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == True\n assert candidate(nums = [3, 3, 4, 4, 5, 5, 1, 1, 2, 2]) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == True\n assert candidate(nums = [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [1, 3, 4, 5, 6, 7, 8, 9, 10, 2]) == False\n assert candidate(nums = [5, 5, 5, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == True\n assert candidate(nums = [3, 2, 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]) == False\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3]) == True\n assert candidate(nums = [7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [2, 3, 4, 5, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8]) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 1, 2, 3, 3, 3]) == True\n assert candidate(nums = [6, 7, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [2, 3, 4, 5, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [1, 2, 1]) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == False\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == True\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 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, 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]) == True\n assert candidate(nums = [7, 8, 9, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == True\n assert candidate(nums = [1, 3, 2, 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]) == False\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == True\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]) == True\n assert candidate(nums = [1, 2, 3, 2, 1]) == False\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 1, 2]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1]) == True\n assert candidate(nums = [8, 9, 1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [99, 100, 1, 2, 3, 4, 5, 6, 7, 8, 98]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2]) == False\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1]) == True\n assert candidate(nums = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5]) == False\n assert candidate(nums = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == True\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 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, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4]) == True\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10]) == False\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == True\n assert candidate(nums = [5, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [9, 10, 11, 12, 13, 5, 6, 7, 8]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 1]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == False\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 1, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 1, 2, 3]) == False\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, 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, 2, 3, 4, 5, 6, 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]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == False\n assert candidate(nums = [2, 3, 1, 2, 3]) == 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]) == False\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3]) == True\n assert candidate(nums = [1, 3, 2, 2, 3, 4, 5]) == False\n assert candidate(nums = [100, 1, 100, 100, 100]) == True\n assert candidate(nums = [5, 6, 7, 8, 1, 2, 3, 4, 5, 6]) == False\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 99]) == True\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, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98]) == True\n assert candidate(nums = [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]) == False\n assert candidate(nums = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [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, 1]) == 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, 1, 1]) == True\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2]) == False\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3]) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 1, 1]) == True\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 1, 3, 3, 3]) == True\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 1]) == True\n assert candidate(nums = [9, 10, 1, 2, 3, 4, 5, 6, 7, 8]) == True\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]) == False\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1]) == False\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]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [3, 4, 5, 2, 1]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 3, 3, 3, 3]) == False\n assert candidate(nums = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [8, 9, 9, 9, 1, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [3, 1, 2]) == True\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 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, 2, 2]) == True\n assert candidate(nums = [2, 2, 2, 2, 1, 2, 2, 2, 2]) == True\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == False\n assert candidate(nums = [3, 4, 5, 1, 1, 2, 2]) == True\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 1]) == True\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == True\n assert candidate(nums = [6, 7, 8, 9, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [2, 2, 2, 2, 1, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [4, 5, 6, 7, 8, 1, 2, 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, 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 = [6, 10, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [100, 1, 100, 100, 100, 100]) == True\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]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == False\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]) == True\n", "comparison": "exact"}, "public_tests": ["[3,4,5,1,2]", "[2,1,3,4]", "[1,2,3]"], "hints": ["Brute force and check if it is possible for a sorted array to start from each position."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().check", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:39+00:00", "tests_total": 141, "tests_dropped": 7, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function check($nums) {", "container": "Solution", "callable": "check", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1753, "task_id": "maximum-score-from-removing-stones", "difficulty": "Medium", "problem_description": "You are playing a solitaire game with three piles of stones of sizes a, b, and c respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).\n\nGiven three integers a, b, and c, return the maximum score you can get.\n\nExample 1:\n\nInput: a = 2, b = 4, c = 6\nOutput: 6\nExplanation: The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.\n\nExample 2:\n\nInput: a = 4, b = 4, c = 6\nOutput: 7\nExplanation: The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.\n\nExample 3:\n\nInput: a = 1, b = 8, c = 8\nOutput: 8\nExplanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends.\n\nConstraints:\n\n- 1 <= a, b, c <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = 10,b = 10,c = 1) == 10\n assert candidate(a = 5,b = 7,c = 9) == 10\n assert candidate(a = 5,b = 5,c = 5) == 7\n assert candidate(a = 1,b = 8,c = 8) == 8\n assert candidate(a = 3,b = 3,c = 3) == 4\n assert candidate(a = 100000,b = 1,c = 1) == 2\n assert candidate(a = 100000,b = 100000,c = 100000) == 150000\n assert candidate(a = 4,b = 4,c = 6) == 7\n assert candidate(a = 30,b = 60,c = 90) == 90\n assert candidate(a = 1,b = 1,c = 100000) == 2\n assert candidate(a = 50000,b = 50000,c = 1) == 50000\n assert candidate(a = 10,b = 10,c = 10) == 15\n assert candidate(a = 2,b = 4,c = 6) == 6\n assert candidate(a = 5,b = 10,c = 15) == 15\n assert candidate(a = 20,b = 30,c = 40) == 45\n assert candidate(a = 7,b = 7,c = 14) == 14\n assert candidate(a = 10,b = 1,c = 1) == 2\n assert candidate(a = 7,b = 14,c = 10) == 15\n assert candidate(a = 1,b = 1,c = 2) == 2\n assert candidate(a = 7,b = 8,c = 9) == 12\n assert candidate(a = 33333,b = 33333,c = 33334) == 50000\n assert candidate(a = 50000,b = 50000,c = 50001) == 75000\n assert candidate(a = 1000,b = 1000,c = 1000) == 1500\n assert candidate(a = 80,b = 80,c = 40) == 100\n assert candidate(a = 7,b = 14,c = 21) == 21\n assert candidate(a = 10,b = 15,c = 20) == 22\n assert candidate(a = 5000,b = 5001,c = 5002) == 7501\n assert candidate(a = 33333,b = 66666,c = 100000) == 99999\n assert candidate(a = 50000,b = 1,c = 1) == 2\n assert candidate(a = 60000,b = 20000,c = 20000) == 40000\n assert candidate(a = 99999,b = 1,c = 1) == 2\n assert candidate(a = 5,b = 5,c = 100) == 10\n assert candidate(a = 80000,b = 80000,c = 1) == 80000\n assert candidate(a = 99998,b = 99999,c = 100000) == 149998\n assert candidate(a = 20,b = 20,c = 20) == 30\n assert candidate(a = 50000,b = 40000,c = 30000) == 60000\n assert candidate(a = 10000,b = 10000,c = 1) == 10000\n assert candidate(a = 5,b = 5,c = 10) == 10\n assert candidate(a = 10000,b = 10000,c = 10000) == 15000\n assert candidate(a = 42,b = 27,c = 19) == 44\n assert candidate(a = 45000,b = 45000,c = 10000) == 50000\n assert candidate(a = 2,b = 2,c = 100000) == 4\n assert candidate(a = 25,b = 25,c = 24) == 37\n assert candidate(a = 500,b = 500,c = 1500) == 1000\n assert candidate(a = 100,b = 200,c = 300) == 300\n assert candidate(a = 15,b = 15,c = 15) == 22\n assert candidate(a = 25,b = 75,c = 125) == 100\n assert candidate(a = 20,b = 20,c = 21) == 30\n assert candidate(a = 20000,b = 30000,c = 10000) == 30000\n assert candidate(a = 20,b = 40,c = 60) == 60\n assert candidate(a = 12345,b = 67890,c = 11111) == 23456\n assert candidate(a = 80000,b = 10000,c = 10000) == 20000\n assert candidate(a = 12345,b = 67890,c = 54321) == 66666\n assert candidate(a = 5,b = 15,c = 20) == 20\n assert candidate(a = 2,b = 2,c = 3) == 3\n assert candidate(a = 100,b = 100,c = 101) == 150\n assert candidate(a = 3,b = 3,c = 9) == 6\n assert candidate(a = 15,b = 25,c = 35) == 37\n assert candidate(a = 50000,b = 50000,c = 99999) == 99999\n assert candidate(a = 10000,b = 20000,c = 30000) == 30000\n assert candidate(a = 10000,b = 5000,c = 5000) == 10000\n assert candidate(a = 25000,b = 25000,c = 50000) == 50000\n assert candidate(a = 99999,b = 99998,c = 99997) == 149997\n assert candidate(a = 75,b = 25,c = 50) == 75\n assert candidate(a = 1,b = 2,c = 3) == 3\n assert candidate(a = 10,b = 20,c = 30) == 30\n assert candidate(a = 3,b = 9,c = 9) == 10\n assert candidate(a = 15,b = 10,c = 5) == 15\n assert candidate(a = 30,b = 5,c = 25) == 30\n assert candidate(a = 50,b = 50,c = 100) == 100\n assert candidate(a = 100,b = 100,c = 100) == 150\n assert candidate(a = 99999,b = 99999,c = 99999) == 149998\n assert candidate(a = 100,b = 100,c = 1) == 100\n assert candidate(a = 50000,b = 49999,c = 49998) == 74998\n assert candidate(a = 50,b = 25,c = 25) == 50\n assert candidate(a = 98765,b = 43210,c = 54321) == 97531\n assert candidate(a = 5000,b = 5000,c = 10000) == 10000\n assert candidate(a = 55,b = 15,c = 35) == 50\n assert candidate(a = 33333,b = 33334,c = 33335) == 50001\n assert candidate(a = 10000,b = 10000,c = 5000) == 12500\n assert candidate(a = 30,b = 50,c = 20) == 50\n assert candidate(a = 30,b = 30,c = 30) == 45\n assert candidate(a = 60000,b = 40000,c = 20000) == 60000\n assert candidate(a = 1,b = 1,c = 1) == 1\n assert candidate(a = 8,b = 8,c = 8) == 12\n assert candidate(a = 100000,b = 50000,c = 50000) == 100000\n", "comparison": "exact"}, "public_tests": ["2\n4\n6", "4\n4\n6", "1\n8\n8"], "hints": ["It's optimal to always remove one stone from the biggest 2 piles", "Note that the limits are small enough for simulation"], "metadata": {"canonical_parameter_names": ["a", "b", "c"], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:41+00:00", "tests_total": 88, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maximumScore($a, $b, $c) {", "container": "Solution", "callable": "maximumScore", "parameters": [{"name": "a", "type": "Integer"}, {"name": "b", "type": "Integer"}, {"name": "c", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1754, "task_id": "largest-merge-of-two-strings", "difficulty": "Medium", "problem_description": "You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:\n\n- If word1 is non-empty, append the first character in word1 to merge and delete it from word1.\n - For example, if word1 = \"abc\" and merge = \"dv\", then after choosing this operation, word1 = \"bc\" and merge = \"dva\".\n- If word2 is non-empty, append the first character in word2 to merge and delete it from word2.\n - For example, if word2 = \"abc\" and merge = \"\", then after choosing this operation, word2 = \"bc\" and merge = \"a\".\n\nReturn the lexicographically largest merge you can construct.\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. 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: word1 = \"cabaa\", word2 = \"bcaaa\"\nOutput: \"cbcabaaaaa\"\nExplanation: One way to get the lexicographically largest merge is:\n- Take from word1: merge = \"c\", word1 = \"abaa\", word2 = \"bcaaa\"\n- Take from word2: merge = \"cb\", word1 = \"abaa\", word2 = \"caaa\"\n- Take from word2: merge = \"cbc\", word1 = \"abaa\", word2 = \"aaa\"\n- Take from word1: merge = \"cbca\", word1 = \"baa\", word2 = \"aaa\"\n- Take from word1: merge = \"cbcab\", word1 = \"aa\", word2 = \"aaa\"\n- Append the remaining 5 a's from word1 and word2 at the end of merge.\n\nExample 2:\n\nInput: word1 = \"abcabc\", word2 = \"abdcaba\"\nOutput: \"abdcabcabcaba\"\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 3000\n- word1 and word2 consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"lexicographically\",word2 = \"largestmerge\") == \"llexicogrargestmergeaphically\"\n assert candidate(word1 = \"zyxw\",word2 = \"abcd\") == \"zyxwabcd\"\n assert candidate(word1 = \"abcdabcd\",word2 = \"zyxwzyxw\") == \"zyxwzyxwabcdabcd\"\n assert candidate(word1 = \"leetcode\",word2 = \"challenge\") == \"leetcodechallenge\"\n assert candidate(word1 = \"aaaab\",word2 = \"aaabb\") == \"aaabbaaaab\"\n assert candidate(word1 = \"lexicographic\",word2 = \"merge\") == \"mlexiergecographic\"\n assert candidate(word1 = \"aaaa\",word2 = \"bbbb\") == \"bbbbaaaa\"\n assert candidate(word1 = \"abcabc\",word2 = \"abdcaba\") == \"abdcabcabcaba\"\n assert candidate(word1 = \"abc\",word2 = \"defghijklmnopqrstuvwxyz\") == \"defghijklmnopqrstuvwxyzabc\"\n assert candidate(word1 = \"z\",word2 = \"z\") == \"zz\"\n assert candidate(word1 = \"hello\",word2 = \"world\") == \"worlhellod\"\n assert candidate(word1 = \"abcd\",word2 = \"zyxw\") == \"zyxwabcd\"\n assert candidate(word1 = \"leetcode\",word2 = \"etco\") == \"leteetcodeco\"\n assert candidate(word1 = \"xy\",word2 = \"xy\") == \"xyxy\"\n assert candidate(word1 = \"cabaa\",word2 = \"bcaaa\") == \"cbcabaaaaa\"\n assert candidate(word1 = \"aabbcc\",word2 = \"bbccdd\") == \"bbccddaabbcc\"\n assert candidate(word1 = \"zzz\",word2 = \"zzz\") == \"zzzzzz\"\n assert candidate(word1 = \"a\",word2 = \"b\") == \"ba\"\n assert candidate(word1 = \"aaaaa\",word2 = \"bbbbb\") == \"bbbbbaaaaa\"\n assert candidate(word1 = \"aabbcc\",word2 = \"abcabc\") == \"abcabcaabbcc\"\n assert candidate(word1 = \"xyz\",word2 = \"xyz\") == \"xyzxyz\"\n assert candidate(word1 = \"abcd\",word2 = \"efgh\") == \"efghabcd\"\n assert candidate(word1 = \"abcd\",word2 = \"dcba\") == \"dcbabcda\"\n assert candidate(word1 = \"same\",word2 = \"same\") == \"ssameame\"\n assert candidate(word1 = \"abcdabcd\",word2 = \"abcde\") == \"abcdeabcdabcd\"\n assert candidate(word1 = \"bca\",word2 = \"cab\") == \"cbcaba\"\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcbabcdefghijklmnopqrstuvwxyza\"\n assert candidate(word1 = \"mississippi\",word2 = \"missouri\") == \"mmissourississippii\"\n assert candidate(word1 = \"zzzzzzzz\",word2 = \"zzzzzzzz\") == \"zzzzzzzzzzzzzzzz\"\n assert candidate(word1 = \"complexity\",word2 = \"similarity\") == \"similcomplexityarity\"\n assert candidate(word1 = \"xyzzzzzzzzzzzzzzzz\",word2 = \"xyzzzzzzzzzzzzzz\") == \"xyzzzzzzzzzzzzzzzzxyzzzzzzzzzzzzzz\"\n assert candidate(word1 = \"aaaabbbbccccdddd\",word2 = \"aaaabbbbccccdddd\") == \"aaaabbbbccccddddaaaabbbbccccdddd\"\n assert candidate(word1 = \"zzzzzzz\",word2 = \"zzzzzzzz\") == \"zzzzzzzzzzzzzzz\"\n assert candidate(word1 = \"aaaaaaa\",word2 = \"bbbbbbb\") == \"bbbbbbbaaaaaaa\"\n assert candidate(word1 = \"zzzzz\",word2 = \"zzzz\") == \"zzzzzzzzz\"\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzzyyxxwwvvuuttssrrqqponmlkjihgfedcbbaa\") == \"zzzyyxxwwvvuuttssrrqqponmlkjihgfedcbbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaa\"\n assert candidate(word1 = \"zyxwvut\",word2 = \"utsrqponmlkjihgfedcba\") == \"zyxwvuuttsrqponmlkjihgfedcba\"\n assert candidate(word1 = \"pqrstuvwxyz\",word2 = \"nopqrstuvwxyz\") == \"pqrstuvwxyznopqrstuvwxyz\"\n assert candidate(word1 = \"zzzzzz\",word2 = \"zzzzzz\") == \"zzzzzzzzzzzz\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"feebdccbaa\") == \"feebdccbaabbccddeeffaa\"\n assert candidate(word1 = \"cccccccc\",word2 = \"dddddddd\") == \"ddddddddcccccccc\"\n assert candidate(word1 = \"a\",word2 = \"z\") == \"za\"\n assert candidate(word1 = \"aabbcc\",word2 = \"aaabbb\") == \"aabbccaaabbb\"\n assert candidate(word1 = \"abcdxyz\",word2 = \"xyzabcd\") == \"xyzabcdxyzabcd\"\n assert candidate(word1 = \"python\",word2 = \"java\") == \"pytjhonava\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"abcabcabc\") == \"abcdabcdabcdabcabcabc\"\n assert candidate(word1 = \"sameprefix\",word2 = \"sameprefixsuffix\") == \"ssameprefixsuffixameprefix\"\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcba\") == \"jihgfedcbabcdefghija\"\n assert candidate(word1 = \"onetwothreefour\",word2 = \"fivesixseveneightnine\") == \"onfivetwothresixseveneightnineefoure\"\n assert candidate(word1 = \"racecar\",word2 = \"racecar\") == \"rracecaracecar\"\n assert candidate(word1 = \"abcdabcdabcdabcdabcdabcd\",word2 = \"zyxwzyxwzyxwzyxwzyxwzyxw\") == \"zyxwzyxwzyxwzyxwzyxwzyxwabcdabcdabcdabcdabcdabcd\"\n assert candidate(word1 = \"xyxzyzyzyx\",word2 = \"zyzyzyzyxz\") == \"zyzyzyzyxzxyxzyzyzyx\"\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"xyzxyzxyzxyzxyz\") == \"xyzxyzxyzxyzxyzabacabadabacaba\"\n assert candidate(word1 = \"xyzz\",word2 = \"yxzz\") == \"yxzzxyzz\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"zyxwzyxwzyxw\") == \"zyxwzyxwzyxwabcdabcdabcd\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"zzzzyyyxxx\") == \"zzzzyyyxxxaabbccddeeff\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"zzyyxxwwvvuu\") == \"zzyyxxwwvvuuaabbccddeeff\"\n assert candidate(word1 = \"abcdefg\",word2 = \"hijklmnop\") == \"hijklmnopabcdefg\"\n assert candidate(word1 = \"banana\",word2 = \"bandana\") == \"bbandanananaa\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcbaabcdabcd\") == \"dcbabcdabcdabcdaabcdabcd\"\n assert candidate(word1 = \"abracadabra\",word2 = \"alakazam\") == \"alakazamabracadabra\"\n assert candidate(word1 = \"aaaabbbbcccc\",word2 = \"bbbbaaaacccc\") == \"bbbbaaaaccccaaaabbbbcccc\"\n assert candidate(word1 = \"leetcode\",word2 = \"edocteel\") == \"leetedocteelcode\"\n assert candidate(word1 = \"aaaaaaaabbbbbbbbcccccccc\",word2 = \"ccccccccbbbbbbbbbaaaaaaa\") == \"ccccccccbbbbbbbbbaaaaaaaabbbbbbbbccccccccaaaaaaa\"\n assert candidate(word1 = \"abcdxyz\",word2 = \"zyxcba\") == \"zyxcbabcdxyza\"\n assert candidate(word1 = \"ababababab\",word2 = \"bababababa\") == \"babababababababababa\"\n assert candidate(word1 = \"equalequal\",word2 = \"equal\") == \"equequalequalal\"\n assert candidate(word1 = \"abcabcabc\",word2 = \"abcabcabc\") == \"abcabcabcabcabcabc\"\n assert candidate(word1 = \"zzzzzzyyyy\",word2 = \"yyyyzzzzzz\") == \"zzzzzzyyyyzzzzzzyyyy\"\n assert candidate(word1 = \"racecar\",word2 = \"race\") == \"rracecarace\"\n assert candidate(word1 = \"programming\",word2 = \"challenges\") == \"progrchammingallenges\"\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzza\"\n assert candidate(word1 = \"abcdxyz\",word2 = \"zyxwvut\") == \"zyxwvutabcdxyz\"\n assert candidate(word1 = \"abacaxi\",word2 = \"abacax\") == \"abacaxiabacax\"\n assert candidate(word1 = \"aaaaaabbbbb\",word2 = \"cccccdddddeeeee\") == \"cccccdddddeeeeeaaaaaabbbbb\"\n assert candidate(word1 = \"abcdefg\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcbabcdefga\"\n assert candidate(word1 = \"samecharacters\",word2 = \"samecharacters\") == \"ssamecharamecharactersacters\"\n assert candidate(word1 = \"abababababab\",word2 = \"babababababa\") == \"babababababababababababa\"\n assert candidate(word1 = \"aaaaab\",word2 = \"bbbaaa\") == \"bbbaaaaabaaa\"\n assert candidate(word1 = \"aabbbccc\",word2 = \"aabbcc\") == \"aabbccaabbbccc\"\n assert candidate(word1 = \"zzzzz\",word2 = \"zzzzzz\") == \"zzzzzzzzzzz\"\n assert candidate(word1 = \"abcdefghijk\",word2 = \"abcdefghijl\") == \"abcdefghijlabcdefghijk\"\n assert candidate(word1 = \"nestednested\",word2 = \"nested\") == \"nnestesteednestedd\"\n assert candidate(word1 = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",word2 = \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n assert candidate(word1 = \"abcde\",word2 = \"edcba\") == \"edcbabcdea\"\n assert candidate(word1 = \"supercalifragilisticexpialidocious\",word2 = \"antidisestablishmentarianism\") == \"supercantidisestalifragilisticexpialidociousablishmentarianism\"\n assert candidate(word1 = \"xyzz\",word2 = \"zzxy\") == \"zzxyzzxy\"\n assert candidate(word1 = \"xyzz\",word2 = \"zzx\") == \"zzxyzzx\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"zzzzyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihghffeeddccbbaa\") == \"zzzzyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihghffeeddccbbaabbccddeeffaa\"\n assert candidate(word1 = \"abababab\",word2 = \"babababa\") == \"babababababababa\"\n assert candidate(word1 = \"xylophone\",word2 = \"xylophon\") == \"xyxyloplophonhone\"\n assert candidate(word1 = \"abcdabcdabcdabcd\",word2 = \"zyxwzyxwzyxwzyxw\") == \"zyxwzyxwzyxwzyxwabcdabcdabcdabcd\"\n assert candidate(word1 = \"zzzz\",word2 = \"zzzz\") == \"zzzzzzzz\"\n assert candidate(word1 = \"longwordone\",word2 = \"longwordtwo\") == \"lonlongworgwordtwodone\"\n assert candidate(word1 = \"aaaaaaaaaaaa\",word2 = \"bbbbbbbbbbba\") == \"bbbbbbbbbbbaaaaaaaaaaaaa\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcba\") == \"dcbabcdabcdabcda\"\n assert candidate(word1 = \"aaaabbbbcccc\",word2 = \"ddddccccbbbaaaa\") == \"ddddccccbbbaaaabbbbccccaaaa\"\n assert candidate(word1 = \"leetcode\",word2 = \"contest\") == \"leetcontestcode\"\n assert candidate(word1 = \"pneumonoultramicroscopicsilicovolcanoconiosis\",word2 = \"zoology\") == \"zpoonlogyeumonoultramicroscopicsilicovolcanoconiosis\"\n assert candidate(word1 = \"abcdabcdb\",word2 = \"abcdabcdb\") == \"abcdabcdbabcdabcdb\"\n assert candidate(word1 = \"amazing\",word2 = \"algorithm\") == \"amazingalgorithm\"\n assert candidate(word1 = \"b\",word2 = \"a\") == \"ba\"\n assert candidate(word1 = \"qwerqwerqwer\",word2 = \"qwertyuiop\") == \"qwqwertyuioperqwerqwer\"\n assert candidate(word1 = \"onesmallstring\",word2 = \"averylongstringwithmanycharactersandvariouslengthsandcombinations\") == \"onesmaverylongstringwithmanycharallstringactersandvariouslengthsandcombinations\"\n assert candidate(word1 = \"banana\",word2 = \"apple\") == \"bappleanana\"\n assert candidate(word1 = \"abcde\",word2 = \"fghij\") == \"fghijabcde\"\n assert candidate(word1 = \"zyxwvutsrqponmlkjihgfedcba\",word2 = \"abcdefghijklmnopqrstuvwxyz\") == \"zyxwvutsrqponmlkjihgfedcbabcdefghijklmnopqrstuvwxyza\"\n assert candidate(word1 = \"zzyzxzyzxzy\",word2 = \"xyxyxyxyxyx\") == \"zzyzxzyzxzyxyxyxyxyxyx\"\n assert candidate(word1 = \"aabbcc\",word2 = \"bbccaa\") == \"bbccaabbccaa\"\n assert candidate(word1 = \"appleapple\",word2 = \"banana\") == \"bappleappleanana\"\n assert candidate(word1 = \"abcdef\",word2 = \"fghijk\") == \"fghijkabcdef\"\n assert candidate(word1 = \"zzzzyyyyxxx\",word2 = \"zzzyyyyxx\") == \"zzzzzzzyyyyyyyyxxxxx\"\n assert candidate(word1 = \"aaaaaabbbb\",word2 = \"bbbbbaaaa\") == \"bbbbbaaaaaabbbbaaaa\"\n assert candidate(word1 = \"aaaaaa\",word2 = \"bbbbbbbb\") == \"bbbbbbbbaaaaaa\"\n assert candidate(word1 = \"lexicographically\",word2 = \"mergeable\") == \"mlexiergecographicallyable\"\n assert candidate(word1 = \"abcabcabc\",word2 = \"cbacbacba\") == \"cbacbacbabcabcabca\"\n assert candidate(word1 = \"samestart\",word2 = \"samestart\") == \"ssamestartamestart\"\n assert candidate(word1 = \"zzzzzzzzzz\",word2 = \"zzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzz\"\n assert candidate(word1 = \"abcdexyz\",word2 = \"zyxwvuts\") == \"zyxwvutsabcdexyz\"\n assert candidate(word1 = \"abcdefg\",word2 = \"ghijklm\") == \"ghijklmabcdefg\"\n assert candidate(word1 = \"longwordone\",word2 = \"evenlongerwordtwo\") == \"longworevenlongerwordtwodone\"\n assert candidate(word1 = \"aaaab\",word2 = \"aaabaaa\") == \"aaabaaaabaaa\"\n assert candidate(word1 = \"abcdabcd\",word2 = \"dcbaabcd\") == \"dcbabcdabcdaabcd\"\n assert candidate(word1 = \"pneumonoultramicroscopicsilicovolcanoconiosis\",word2 = \"supercalifragilisticexpialidocious\") == \"suppneumonoultrercamicroscopicsilicovolcanoconiosisalifragilisticexpialidocious\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"aabbccddeegf\") == \"aabbccddeegfaabbccddeeff\"\n assert candidate(word1 = \"zyxzyxzyx\",word2 = \"zyxzyxzyx\") == \"zzyyxzyxzyxzyxzyxx\"\n assert candidate(word1 = \"overlapover\",word2 = \"overlap\") == \"ovoverlerlapoverap\"\n assert candidate(word1 = \"aebcdefghijklmnopqrstuvwxyz\",word2 = \"zxcvbnmlkjihgfedcbaeb\") == \"zxcvbnmlkjihgfedcbaebcdefghijklmnopqrstuvwxyzaeb\"\n assert candidate(word1 = \"abcdef\",word2 = \"fedcba\") == \"fedcbabcdefa\"\n assert candidate(word1 = \"aaaabbbbcccc\",word2 = \"ddddeeeeffff\") == \"ddddeeeeffffaaaabbbbcccc\"\n assert candidate(word1 = \"hellohellohello\",word2 = \"worldworld\") == \"worlhellohellohellodworld\"\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"abcabc\") == \"abcabcabcabcabcabc\"\n assert candidate(word1 = \"zzzz\",word2 = \"zzz\") == \"zzzzzzz\"\n assert candidate(word1 = \"xyzzzzzzzzzzzz\",word2 = \"yyyyyyyyyyyyyy\") == \"yyyyyyyyyyyyyyxyzzzzzzzzzzzz\"\n assert candidate(word1 = \"aabaaa\",word2 = \"baabaa\") == \"baabaabaaaaa\"\n assert candidate(word1 = \"aaaaaaaaaabbbbbbbbbbcccccccccc\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaabbbbbbbbbbcccccccccc\"\n", "comparison": "exact"}, "public_tests": ["\"cabaa\"\n\"bcaaa\"", "\"abcabc\"\n\"abdcaba\""], "hints": ["Build the result character by character. At each step, you choose a character from one of the two strings.", "If the next character of the first string is larger than that of the second string, or vice versa, it's optimal to use the larger one.", "If both are equal, think of a criteria that lets you decide which string to consume the next character from.", "You should choose the next character from the larger string."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().largestMerge", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:43+00:00", "tests_total": 138, "tests_dropped": 2, "flags": [], "topic_tags": ["two-pointers", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function largestMerge($word1, $word2) {", "container": "Solution", "callable": "largestMerge", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1755, "task_id": "closest-subsequence-sum", "difficulty": "Hard", "problem_description": "You are given an integer array nums and an integer goal.\n\nYou want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).\n\nReturn the minimum possible value of abs(sum - goal).\n\nNote that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.\n\nExample 1:\n\nInput: nums = [5,-7,3,5], goal = 6\nOutput: 0\nExplanation: Choose the whole array as a subsequence, with a sum of 6.\nThis is equal to the goal, so the absolute difference is 0.\n\nExample 2:\n\nInput: nums = [7,-9,15,-2], goal = -5\nOutput: 1\nExplanation: Choose the subsequence [7,-9,-2], with a sum of -4.\nThe absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.\n\nExample 3:\n\nInput: nums = [1,2,3], goal = -7\nOutput: 7\n\nConstraints:\n\n- 1 <= nums.length <= 40\n- -10^7 <= nums[i] <= 10^7\n- -10^9 <= goal <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-10, -20, -30, -40, -50],goal = -100) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],goal = 100) == 0\n assert candidate(nums = [10, 22, 9, -24, -33, 21, 4, 19, 29, -14, 34, 10, -11, 8, -8, -7, 13, 24, -29, -10, -28, 10, -32, -23, 7, 31, 2, 25, -31, -40, -4, -23],goal = 100) == 0\n assert candidate(nums = [7, -9, 15, -2],goal = -5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],goal = 25) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],goal = 10) == 0\n assert candidate(nums = [10000000, -10000000, 10000000, -10000000],goal = 0) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000],goal = 0) == 0\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],goal = -255) == 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],goal = 0) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5],goal = -15) == 0\n assert candidate(nums = [1, 2, 3],goal = -7) == 7\n assert candidate(nums = [5, -7, 3, 5],goal = 6) == 0\n assert candidate(nums = [10000000, -10000000],goal = 0) == 0\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16],goal = 0) == 0\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50, -60, 60, -70, 70, -80, 80, -90, 90, -100, 100],goal = -500) == 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],goal = -1000) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],goal = 900) == 80\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80],goal = 5) == 5\n assert candidate(nums = [-1000, 1000, -500, 500, -250, 250, -125, 125, -62, 62, -31, 31, -15, 15, -7, 7, -3, 3, -1, 1],goal = -1000) == 0\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],goal = -450) == 0\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],goal = 0) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000],goal = 3000000) == 500000\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],goal = 50) == 0\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000, -1000000, -2000000, -3000000, -4000000, -5000000, -6000000, -7000000, -8000000, -9000000, -10000000],goal = 20000000) == 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],goal = 500) == 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],goal = 100) == 0\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],goal = 10000) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],goal = 10000) == 0\n assert candidate(nums = [10000000, -5000000, 3000000, -2000000, 1500000, -1000000, 750000, -500000, 250000, -125000, 62500, -31250, 15625, -7812, 3906, -1953, 976, -488, 244, -122],goal = 0) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100],goal = 50) == 0\n assert candidate(nums = [-10000, -20000, -30000, -40000, -50000, 10000, 20000, 30000, 40000, 50000],goal = -50000) == 0\n assert candidate(nums = [7, 3, 8, 4, 6, 2, 5, 1, 10, 9],goal = 42) == 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],goal = 100) == 0\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],goal = 5000) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],goal = 1500) == 0\n assert candidate(nums = [5, -3, 1, 7, -9, 10, -20, 15, -1, 4, 8, -6, 2, 11, -7, 13, -5, 9, -12, 6, 14, -4, 16, -8, 12, -11, 17, -13, 18, -9, 19, -14, 20, -15, 21, -16, 22, -17, 23, -18],goal = 50) == 0\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500, -600, 600, -700, 700, -800, 800, -900, 900, -1000, 1000],goal = 0) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],goal = -15) == 0\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8],goal = 1) == 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, -5, -10, -15, -20, -25, -30, -35, -40, -45, -50],goal = 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, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],goal = 800) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60],goal = 5) == 5\n assert candidate(nums = [5, -7, 3, 5, 9, -1, 2, -3, 8],goal = 6) == 0\n assert candidate(nums = [10000000, -5000000, 2500000, -1250000, 625000, -312500, 156250, -78125, 39062, -19531, 9765, -4882, 2441, -1220, 610, -305, 152, -76, 38, -19, 9, -4, 2, -1],goal = 5000000) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, -5, -15, -25, -35, -45, -55, -65, -75, -85, -95, -105],goal = 250) == 0\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],goal = 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, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],goal = 300) == 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, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20],goal = -100) == 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, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20],goal = 5) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000, 1250000, -1250000, 625000, -625000, 312500, -312500, 156250, -156250, 78125, -78125],goal = 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, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],goal = 1) == 0\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],goal = 1) == 0\n assert candidate(nums = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000, -1000000, -2000000, -3000000, -4000000, -5000000, -6000000, -7000000, -8000000, -9000000, -10000000],goal = 5000000) == 0\n assert candidate(nums = [3, -1, 4, 1, 5, -9, 2, 6, 5, 3, -5, 7, -7, 8, -8, 9, -9, 10, -10],goal = 0) == 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],goal = 1000000) == 0\n assert candidate(nums = [-10000000, 10000000, -5000000, 5000000, 2500000, -2500000, 1250000, -1250000],goal = 1234567) == 15433\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],goal = 0) == 0\n assert candidate(nums = [1000000, -1000000, 2000000, -2000000, 3000000, -3000000, 4000000, -4000000, 5000000, -5000000, 6000000, -6000000, 7000000, -7000000, 8000000, -8000000, 9000000, -9000000, 10000000, -10000000],goal = 5000000) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],goal = 0) == 0\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000],goal = 500) == 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],goal = 1000) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],goal = -1000) == 1000\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],goal = 0) == 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, -11, 11, -12, 12, -13, 13, -14, 14, -15, 15],goal = 50) == 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],goal = 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],goal = -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],goal = -50) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000, 1250000, -1250000],goal = 0) == 0\n assert candidate(nums = [-10000, 10000, -20000, 20000, -30000, 30000, -40000, 40000, -50000, 50000, -60000, 60000, -70000, 70000, -80000, 80000, -90000, 90000, -100000, 100000],goal = 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, 26, -27, 28, -29, 30, -31, 32, -33, 34, -35, 36, -37, 38, -39, 40],goal = 0) == 0\n assert candidate(nums = [9999999, 8888888, 7777777, 6666666, 5555555, 4444444, 3333333, 2222222, 1111111, -1111111, -2222222, -3333333, -4444444, -5555555, -6666666, -7777777, -8888888, -9999999],goal = 123456789) == 73456794\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],goal = 10000) == 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],goal = 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, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59],goal = 1000) == 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, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39, -40],goal = -1) == 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],goal = 1) == 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],goal = 10) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000],goal = 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, 26, -27, 28, -29, 30],goal = -150) == 0\n assert candidate(nums = [1000000, -1000000, 500000, -500000, 250000, -250000],goal = 0) == 0\n assert candidate(nums = [10000, -10000, 20000, -20000, 30000, -30000, 40000, -40000, 50000, -50000],goal = 25000) == 5000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],goal = 500) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],goal = 450) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],goal = 999) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],goal = 500) == 0\n", "comparison": "exact"}, "public_tests": ["[5,-7,3,5]\n6", "[7,-9,15,-2]\n-5", "[1,2,3]\n-7"], "hints": ["The naive solution is to check all possible subsequences. This works in O(2^n).", "Divide the array into two parts of nearly is equal size.", "Consider all subsets of one part and make a list of all possible subset sums and sort this list.", "Consider all subsets of the other part, and for each one, let its sum = x, do binary search to get the nearest possible value to goal - x in the first part."], "metadata": {"canonical_parameter_names": ["nums", "goal"], "leetcode_dataset_entry_point": "Solution().minAbsDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:46+00:00", "tests_total": 98, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "two-pointers", "dynamic-programming", "bit-manipulation", "meet-in-the-middle", "sorting", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function minAbsDifference($nums, $goal) {", "container": "Solution", "callable": "minAbsDifference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "goal", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1758, "task_id": "minimum-changes-to-make-alternating-binary-string", "difficulty": "Easy", "problem_description": "You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.\n\nThe string is called alternating if no two adjacent characters are equal. For example, the string \"010\" is alternating, while the string \"0100\" is not.\n\nReturn the minimum number of operations needed to make s alternating.\n\nExample 1:\n\nInput: s = \"0100\"\nOutput: 1\nExplanation: If you change the last character to '1', s will be \"0101\", which is alternating.\n\nExample 2:\n\nInput: s = \"10\"\nOutput: 0\nExplanation: s is already alternating.\n\nExample 3:\n\nInput: s = \"1111\"\nOutput: 2\nExplanation: You need two operations to reach \"0101\" or \"1010\".\n\nConstraints:\n\n- 1 <= s.length <= 10^4\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"101010\") == 0\n assert candidate(s = \"111000\") == 2\n assert candidate(s = \"1101101101\") == 4\n assert candidate(s = \"001100\") == 3\n assert candidate(s = \"10\") == 0\n assert candidate(s = \"110011\") == 3\n assert candidate(s = \"0100\") == 1\n assert candidate(s = \"0110101010\") == 2\n assert candidate(s = \"010101\") == 0\n assert candidate(s = \"0000\") == 2\n assert candidate(s = \"000111\") == 2\n assert candidate(s = \"101010101010101010\") == 0\n assert candidate(s = \"1100110011001100110011001100110011\") == 17\n assert candidate(s = \"01010101010101010\") == 0\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111\") == 30\n assert candidate(s = \"10101101010110101010\") == 7\n assert candidate(s = \"00000000000000000000000000000000\") == 16\n assert candidate(s = \"111110000111110000111110000111110000111110000111110000\") == 27\n assert candidate(s = \"1100110011001100\") == 8\n assert candidate(s = \"010101010101010101010101\") == 0\n assert candidate(s = \"111000111000111\") == 5\n assert candidate(s = \"0110101010101010\") == 2\n assert candidate(s = \"101010101010101010101010\") == 0\n assert candidate(s = \"1010101010101001\") == 2\n assert candidate(s = \"101010101010101010101\") == 0\n assert candidate(s = \"1000111010010101\") == 8\n assert candidate(s = \"0000000000\") == 5\n assert candidate(s = \"1100110011\") == 5\n assert candidate(s = \"111000111000111000111000111000\") == 10\n assert candidate(s = \"11110000000000001111\") == 10\n assert candidate(s = \"0000000000000000\") == 8\n assert candidate(s = \"11001100110011001100110011001100\") == 16\n assert candidate(s = \"1010101010101010\") == 0\n assert candidate(s = \"110011001100\") == 6\n assert candidate(s = \"110011001100110011\") == 9\n assert candidate(s = \"010101010110\") == 2\n assert candidate(s = \"0011001100110011\") == 8\n assert candidate(s = \"000001111000001111000011110000111100001111000011110000\") == 27\n assert candidate(s = \"1010100101010101010101010101010101\") == 6\n assert candidate(s = \"11111000001111100000\") == 8\n assert candidate(s = \"0101010101010101010101010101010101\") == 0\n assert candidate(s = \"100100100100100100100100\") == 12\n assert candidate(s = \"00110011001100110011001100110011\") == 16\n assert candidate(s = \"0110110110110110\") == 8\n assert candidate(s = \"10110101010101010101\") == 3\n assert candidate(s = \"1010010101010101\") == 4\n assert candidate(s = \"0101011010101010\") == 6\n assert candidate(s = \"010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"0011001100110\") == 6\n assert candidate(s = \"11111111111111111111\") == 10\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001\") == 26\n assert candidate(s = \"00001111111111110000\") == 10\n assert candidate(s = \"1111111111111111\") == 8\n assert candidate(s = \"01010101010\") == 0\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111\") == 19\n assert candidate(s = \"001100110011\") == 6\n assert candidate(s = \"11010011\") == 3\n assert candidate(s = \"00011100011100011100011100011100\") == 11\n assert candidate(s = \"011011011011011011011011\") == 12\n assert candidate(s = \"00000111110000011111\") == 8\n assert candidate(s = \"111000111000111000111\") == 7\n assert candidate(s = \"11001100110011001100\") == 10\n assert candidate(s = \"01010101010101010101010101010101\") == 0\n assert candidate(s = \"10010010010010010010\") == 9\n assert candidate(s = \"1010101010101010101010101010\") == 0\n assert candidate(s = \"1110000111000011\") == 8\n assert candidate(s = \"01110111011101110111\") == 5\n assert candidate(s = \"111100001111\") == 6\n assert candidate(s = \"1101101101101101\") == 7\n assert candidate(s = \"01100110011001100110\") == 10\n assert candidate(s = \"00110011001100\") == 7\n assert candidate(s = \"010101010101\") == 0\n assert candidate(s = \"1111111111111111111111111111\") == 14\n assert candidate(s = \"0101010101010101\") == 0\n assert candidate(s = \"0001110001\") == 3\n assert candidate(s = \"11111111111111111111111111111111\") == 16\n assert candidate(s = \"00000000\") == 4\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"01100110011001100110011001100110011\") == 17\n assert candidate(s = \"0101010101\") == 0\n assert candidate(s = \"1001001001001001001001001001001001\") == 17\n assert candidate(s = \"00001111000011110000111100001111\") == 16\n assert candidate(s = \"10101010101010101\") == 0\n assert candidate(s = \"111000111\") == 3\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000000000\") == 30\n assert candidate(s = \"0111000111000111\") == 5\n assert candidate(s = \"0001111000111100\") == 8\n assert candidate(s = \"1010101010101\") == 0\n assert candidate(s = \"00000000000000000000\") == 10\n assert candidate(s = \"1111000011110000\") == 8\n assert candidate(s = \"10101010101010101010101010101010\") == 0\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"010010010010\") == 6\n assert candidate(s = \"0111000101101010\") == 8\n assert candidate(s = \"0110110110110\") == 6\n assert candidate(s = \"01010101010101\") == 0\n assert candidate(s = \"001100110011001100110\") == 10\n assert candidate(s = \"1001001001001\") == 6\n assert candidate(s = \"010101010101010101010\") == 0\n assert candidate(s = \"1111111111\") == 5\n assert candidate(s = \"0110011001100110\") == 8\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\") == 32\n assert candidate(s = \"1001100110011001\") == 8\n assert candidate(s = \"01010101010101010101\") == 0\n assert candidate(s = \"11111111\") == 4\n assert candidate(s = \"1101001100\") == 4\n assert candidate(s = \"0001110001110001110001\") == 7\n assert candidate(s = \"110000111100001111000011110000\") == 15\n assert candidate(s = \"01101101101101101101\") == 9\n assert candidate(s = \"10101010101010101010\") == 0\n assert candidate(s = \"01010010101001010101\") == 7\n assert candidate(s = \"1101010101\") == 1\n assert candidate(s = \"111000111000111000111000\") == 8\n assert candidate(s = \"0000000000000000000000000000\") == 14\n assert candidate(s = \"000111000111000\") == 5\n assert candidate(s = \"0000111100001111\") == 8\n", "comparison": "exact"}, "public_tests": ["\"0100\"", "\"10\"", "\"1111\""], "hints": ["Think about how the final string will look like.", "It will either start with a '0' and be like '010101010..' or with a '1' and be like '10101010..'", "Try both ways, and check for each way, the number of changes needed to reach it from the given string. The answer is the minimum of both ways."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:48+00:00", "tests_total": 117, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function minOperations($s) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1759, "task_id": "count-number-of-homogenous-substrings", "difficulty": "Medium", "problem_description": "Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 10^9 + 7.\n\nA string is homogenous if all the characters of the string are the same.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"abbcccaa\"\nOutput: 13\nExplanation: The homogenous substrings are listed as below:\n\"a\" appears 3 times.\n\"aa\" appears 1 time.\n\"b\" appears 2 times.\n\"bb\" appears 1 time.\n\"c\" appears 3 times.\n\"cc\" appears 2 times.\n\"ccc\" appears 1 time.\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.\n\nExample 2:\n\nInput: s = \"xy\"\nOutput: 2\nExplanation: The homogenous substrings are \"x\" and \"y\".\n\nExample 3:\n\nInput: s = \"zzzzz\"\nOutput: 15\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaabbbccc\") == 18\n assert candidate(s = \"aabbccddeeefffggghhhiiii\") == 46\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"xy\") == 2\n assert candidate(s = \"aabbaa\") == 9\n assert candidate(s = \"aaaaa\") == 15\n assert candidate(s = \"pppppppppp\") == 55\n assert candidate(s = \"abcdeffffff\") == 26\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"qqqqqwwweeeerrrrtttttyyyyyuuuuuiooooo\") == 102\n assert candidate(s = \"abcabcabc\") == 9\n assert candidate(s = \"ababababab\") == 10\n assert candidate(s = \"abcde\") == 5\n assert candidate(s = \"ababababa\") == 9\n assert candidate(s = \"zzzzyyyyxxxwwwwvvvvuuuuttttsrrrqqqppoonnmlkjihgfedcba\") == 101\n assert candidate(s = \"ccccccccc\") == 45\n assert candidate(s = \"abbcccaa\") == 13\n assert candidate(s = \"abcd\") == 4\n assert candidate(s = \"zzzzz\") == 15\n assert candidate(s = \"ababab\") == 6\n assert candidate(s = \"aaaaaabb\") == 24\n assert candidate(s = \"aabbccddeeeeffff\") == 32\n assert candidate(s = \"abcabcabcabcabcabcabc\") == 21\n assert candidate(s = \"aabbbccccdddd\") == 29\n assert candidate(s = \"mmmmmlllllkkkkkkjjjjjjjjiiiiiiiiiiiihhhhhhhhhhhh\") == 243\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1326\n assert candidate(s = \"aaabaaaabaaaaabaaaaaaabaaaaaaaabaaaaaaaaabaaaaaaaaaabaaaaaaaaaa\") == 257\n assert candidate(s = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeee\") == 208\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 903\n assert candidate(s = \"aabbcccddddeeeee\") == 37\n assert candidate(s = \"pppppqqqqqqrrrrrrsssssstttttuuuuuuvvvvvvvvvwwwwwwwww\") == 204\n assert candidate(s = \"aabbbcccc\") == 19\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 676\n assert candidate(s = \"aaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaa\") == 252\n assert candidate(s = \"mmmmmmmmmmmmmmmnnnnnnnnnnnnnnnoooooooooooopppppppppppp\") == 396\n assert candidate(s = \"aabbccddeeefffggg\") == 30\n assert candidate(s = \"abcabcabcabc\") == 12\n assert candidate(s = \"aaabbaaaabbaaa\") == 28\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbcccccccccc\") == 165\n assert candidate(s = \"aabbccddeeefffggghhhh\") == 40\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 277140\n assert candidate(s = \"zzzzyyyyzzzz\") == 30\n assert candidate(s = \"aaaaabbbbccccc\") == 40\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 29403\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyz\") == 24\n assert candidate(s = \"aabbccddeeeeffffggggghhhhiiiii\") == 72\n assert candidate(s = \"pppppppppppppppppppppppppppppppppp\") == 595\n assert candidate(s = \"ababababababababababababababab\") == 30\n assert candidate(s = \"aaaaabbbbccccdddddeeeee\") == 65\n assert candidate(s = \"aabbccddeeefffggghhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\") == 145\n assert candidate(s = \"pppppppppppppppppppppppppppppppppppppppppppqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 1892\n assert candidate(s = \"ppppppppppppppppppppppp\") == 276\n assert candidate(s = \"xyzzyzxzyzxyz\") == 14\n assert candidate(s = \"ababababababab\") == 14\n assert candidate(s = \"aabbccddeeeefffghhhiiiijjjjkkkkllllmmmmmnnnnnooooo\") == 120\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\") == 27\n assert candidate(s = \"aabbccddeeefffggghhhiiiijjjjkkkkllllmmmmmnnnnnooooooo\") == 134\n assert candidate(s = \"aaaaaaaaabbbbbbbbbbcccccccccc\") == 155\n assert candidate(s = \"zzzzzyyyxxxwwwwvvvvuuuuu\") == 62\n assert candidate(s = \"aabbccddeeeeffffggggghhhiiijjjkkklllmmnnooopppqqqrrsssttuuuvvvwwwwwxxxxxyyyyyzzzz\") == 180\n assert candidate(s = \"abcdefffffffffffffffffffffffffghijklmnopqrstuvwxyz\") == 350\n assert candidate(s = \"abcdabcdbcdabcd\") == 15\n assert candidate(s = \"aabbbbccccc\") == 28\n assert candidate(s = \"aaaaaaaaaaaabbaaaaaaa\") == 109\n assert candidate(s = \"aabbbccccc\") == 24\n assert candidate(s = \"xyxyxyxyxyxyxyx\") == 15\n assert candidate(s = \"aabbaaabbbaaa\") == 24\n assert candidate(s = \"aabbaaabbcccddeee\") == 30\n assert candidate(s = \"aabbccddeeffgg\") == 21\n assert candidate(s = \"aaaaabbbbbbbbbbcccccccccc\") == 125\n assert candidate(s = \"pppppppppppppppppppppppppppppppppppppppp\") == 820\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 84\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 160\n assert candidate(s = \"qwerqwerqwerqwerqwerqwerqwer\") == 28\n assert candidate(s = \"aaabbaaa\") == 15\n assert candidate(s = \"aaabbaaabbaaa\") == 24\n assert candidate(s = \"abcabcabcabcabc\") == 15\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 21736\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1275\n assert candidate(s = \"abcdefg\") == 7\n", "comparison": "exact"}, "public_tests": ["\"abbcccaa\"", "\"xy\"", "\"zzzzz\""], "hints": ["A string of only 'a's of length k contains k + 1 choose 2 homogenous substrings.", "Split the string into substrings where each substring contains only one letter, and apply the formula on each substring's length."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countHomogenous", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:50+00:00", "tests_total": 80, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string"]}, "language": "php", "interface": {"raw_signature": "function countHomogenous($s) {", "container": "Solution", "callable": "countHomogenous", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1760, "task_id": "minimum-limit-of-balls-in-a-bag", "difficulty": "Medium", "problem_description": "You are given an integer array nums where the i^th bag contains nums[i] balls. You are also given an integer maxOperations.\n\nYou can perform the following operation at most maxOperations times:\n\n- Take any bag of balls and divide it into two new bags with a positive number of balls.\n - For example, a bag of 5 balls can become two new bags of 1 and 4 balls, or two new bags of 2 and 3 balls.\n\nYour penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.\n\nReturn the minimum possible penalty after performing the operations.\n\nExample 1:\n\nInput: nums = [9], maxOperations = 2\nOutput: 3\nExplanation:\n- Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].\n- Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].\nThe bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.\n\nExample 2:\n\nInput: nums = [2,4,8,2], maxOperations = 4\nOutput: 2\nExplanation:\n- Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].\nThe bag with the most number of balls has 2 balls, so your penalty is 2, and you should return 2.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= maxOperations, nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],maxOperations = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],maxOperations = 9) == 5\n assert candidate(nums = [1000000000],maxOperations = 1) == 500000000\n assert candidate(nums = [1, 2, 3, 4, 5],maxOperations = 5) == 2\n assert candidate(nums = [100, 100, 100, 100],maxOperations = 10) == 34\n assert candidate(nums = [1000000000],maxOperations = 999999999) == 1\n assert candidate(nums = [1000000000],maxOperations = 1000000000) == 1\n assert candidate(nums = [7, 17],maxOperations = 2) == 7\n assert candidate(nums = [9],maxOperations = 2) == 3\n assert candidate(nums = [10, 20, 30, 40, 50],maxOperations = 10) == 10\n assert candidate(nums = [2, 4, 8, 2],maxOperations = 4) == 2\n assert candidate(nums = [1000000000, 1000000000],maxOperations = 1) == 1000000000\n assert candidate(nums = [10, 10, 10],maxOperations = 6) == 4\n assert candidate(nums = [10, 10, 10],maxOperations = 3) == 5\n assert candidate(nums = [7, 14, 21, 28],maxOperations = 3) == 14\n assert candidate(nums = [1, 1, 1, 1],maxOperations = 2) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],maxOperations = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],maxOperations = 5) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],maxOperations = 5) == 50\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000],maxOperations = 9) == 100000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],maxOperations = 25) == 180\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000],maxOperations = 30) == 3449\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],maxOperations = 29) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000],maxOperations = 3) == 500000000\n assert candidate(nums = [999999999, 1],maxOperations = 1) == 500000000\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],maxOperations = 9) == 100\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],maxOperations = 10) == 142857143\n assert candidate(nums = [999, 999, 999, 999, 999, 999, 999, 999, 999, 999],maxOperations = 5) == 999\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],maxOperations = 3) == 333333334\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000],maxOperations = 5) == 250000000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],maxOperations = 20) == 44\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],maxOperations = 9) == 100000000\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],maxOperations = 15) == 10\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995],maxOperations = 10) == 333333333\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],maxOperations = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],maxOperations = 14) == 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],maxOperations = 50) == 18\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],maxOperations = 50) == 3\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],maxOperations = 19) == 1000\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],maxOperations = 10) == 500\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],maxOperations = 9) == 50\n assert candidate(nums = [1000000000, 500000000, 250000000],maxOperations = 3) == 333333334\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],maxOperations = 10) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],maxOperations = 15) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],maxOperations = 30) == 3\n assert candidate(nums = [1, 1000000000, 1],maxOperations = 1000000000) == 1\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999],maxOperations = 5) == 500000000\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],maxOperations = 5) == 166666667\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],maxOperations = 19) == 7\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999],maxOperations = 10) == 333333333\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],maxOperations = 50) == 10000\n assert candidate(nums = [1, 1, 1, 1, 1000000000],maxOperations = 999999) == 1000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],maxOperations = 30) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],maxOperations = 20) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],maxOperations = 20) == 20\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],maxOperations = 10) == 142857143\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000, 500000000],maxOperations = 1000000) == 2500\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],maxOperations = 15) == 7\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],maxOperations = 50) == 9\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000, 500000000],maxOperations = 10) == 166666667\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],maxOperations = 30) == 50\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],maxOperations = 45) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],maxOperations = 10) == 4\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],maxOperations = 20) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],maxOperations = 15) == 114\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999],maxOperations = 4) == 500000000\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],maxOperations = 20) == 5\n assert candidate(nums = [2, 3, 6, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],maxOperations = 100) == 6\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],maxOperations = 50) == 1171\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],maxOperations = 20) == 19\n assert candidate(nums = [100, 200, 300, 400, 500],maxOperations = 15) == 84\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],maxOperations = 10) == 74\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],maxOperations = 5) == 1\n assert candidate(nums = [999999999, 999999998, 999999997],maxOperations = 2) == 999999997\n assert candidate(nums = [100, 200, 300, 400, 500],maxOperations = 50) == 29\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],maxOperations = 5) == 5\n assert candidate(nums = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999],maxOperations = 10) == 500000000\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000],maxOperations = 5) == 500000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],maxOperations = 45) == 100\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],maxOperations = 10) == 10000000\n assert candidate(nums = [500000000, 500000000, 500000000, 500000000],maxOperations = 3) == 500000000\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000],maxOperations = 50) == 28572\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],maxOperations = 100) == 500\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],maxOperations = 20) == 6\n assert candidate(nums = [1000000000, 1000000000, 1000000000],maxOperations = 2) == 1000000000\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],maxOperations = 30) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],maxOperations = 10) == 350\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],maxOperations = 9) == 8\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],maxOperations = 25) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],maxOperations = 9) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],maxOperations = 10) == 7\n", "comparison": "exact"}, "public_tests": ["[9]\n2", "[2,4,8,2]\n4"], "hints": ["Let's change the question if we know the maximum size of a bag what is the minimum number of bags you can make", "note that as the maximum size increases the minimum number of bags decreases so we can binary search the maximum size"], "metadata": {"canonical_parameter_names": ["nums", "maxOperations"], "leetcode_dataset_entry_point": "Solution().minimumSize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:53+00:00", "tests_total": 99, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function minimumSize($nums, $maxOperations) {", "container": "Solution", "callable": "minimumSize", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "maxOperations", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1761, "task_id": "minimum-degree-of-a-connected-trio-in-a-graph", "difficulty": "Hard", "problem_description": "You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [u_i, v_i] indicates that there is an undirected edge between u_i and v_i.\n\nA connected trio is a set of three nodes where there is an edge between every pair of them.\n\nThe degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.\n\nReturn the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.\n\nExample 1:\n\nInput: n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\nOutput: 3\nExplanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.\n\nExample 2:\n\nInput: n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\nOutput: 0\nExplanation: There are exactly three trios:\n1) [1,4,3] with degree 0.\n2) [2,5,6] with degree 2.\n3) [5,6,7] with degree 2.\n\nConstraints:\n\n- 2 <= n <= 400\n- edges[i].length == 2\n- 1 <= edges.length <= n * (n-1) / 2\n- 1 <= 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 = 4,edges = [[1, 2], [1, 3], [2, 3]]) == 0\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 3\n assert candidate(n = 400,edges = [[1, 2], [2, 3], [3, 1]]) == 0\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [7, 8], [8, 9], [9, 7], [10, 1]]) == 0\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [6, 4], [7, 8]]) == 0\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [7, 8]]) == 0\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [3, 2], [4, 1], [5, 2], [3, 6]]) == 3\n assert candidate(n = 3,edges = [[1, 2], [2, 3], [3, 1]]) == 0\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 1], [1, 4], [4, 5], [5, 1]]) == 2\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5]]) == -1\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8]]) == 0\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [2, 4], [3, 5]]) == 4\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 4]]) == -1\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == -1\n assert candidate(n = 7,edges = [[1, 3], [4, 1], [4, 3], [2, 5], [5, 6], [6, 7], [7, 5], [2, 6]]) == 0\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 1], [3, 4], [4, 5]]) == 1\n assert candidate(n = 3,edges = [[1, 2], [2, 3]]) == -1\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 1], [1, 4], [2, 4], [3, 4]]) == 3\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [6, 7], [7, 8], [5, 7], [6, 8], [4, 7], [4, 8]]) == 0\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [1, 10], [2, 11], [3, 12]]) == 9\n assert candidate(n = 100,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 19], [1, 100], [100, 50], [50, 25], [25, 75], [75, 50], [50, 1], [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, 50], [16, 50], [17, 50], [18, 50], [19, 50], [21, 50], [22, 50], [23, 50], [24, 50], [25, 50], [26, 50], [27, 50], [28, 50], [29, 50], [30, 50], [31, 50], [32, 50], [33, 50], [34, 50], [35, 50], [36, 50], [37, 50], [38, 50], [39, 50], [40, 50], [41, 50], [42, 50], [43, 50], [44, 50], [45, 50], [46, 50], [47, 50], [48, 50], [49, 50], [51, 50], [52, 50], [53, 50], [54, 50], [55, 50], [56, 50], [57, 50], [58, 50], [59, 50], [60, 50], [61, 50], [62, 50], [63, 50], [64, 50], [65, 50], [66, 50], [67, 50], [68, 50], [69, 50], [70, 50], [71, 50], [72, 50], [73, 50], [74, 50], [75, 50], [76, 50], [77, 50], [78, 50], [79, 50], [80, 50], [81, 50], [82, 50], [83, 50], [84, 50], [85, 50], [86, 50], [87, 50], [88, 50], [89, 50], [90, 50], [91, 50], [92, 50], [93, 50], [94, 50], [95, 50], [96, 50], [97, 50], [98, 50], [99, 50], [100, 99]]) == 3\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 1], [2, 5], [3, 5]]) == 5\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [14, 15], [14, 16], [14, 17], [14, 18], [15, 16], [15, 17], [15, 18], [16, 17], [16, 18], [17, 18], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [20, 21], [20, 22], [20, 23], [20, 24], [21, 22], [21, 23], [21, 24], [22, 23], [22, 24], [23, 24], [1, 13], [2, 14], [3, 15], [4, 16], [5, 17], [6, 18], [7, 19], [8, 20], [9, 21], [10, 22], [11, 23], [12, 24]]) == 12\n assert candidate(n = 20,edges = [[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, 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], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [11, 20], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20]]) == 9\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 1]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10]]) == 3\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [13, 14], [13, 15], [13, 16], [14, 15], [14, 16], [15, 16], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20], [1, 5], [2, 6], [3, 7], [4, 8], [1, 9], [2, 10], [3, 11], [4, 12], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15], [12, 16], [13, 17], [14, 18], [15, 19], [16, 20]]) == 6\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1], [1, 3], [4, 6], [2, 7], [5, 8]]) == 3\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [13, 14], [13, 15], [13, 16], [14, 15], [14, 16], [15, 16], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20], [21, 22], [21, 23], [21, 24], [22, 23], [22, 24], [23, 24], [25, 26], [25, 27], [25, 28], [26, 27], [26, 28], [27, 28], [29, 30]]) == 3\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]]) == 3\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [13, 14], [13, 15], [13, 16], [14, 15], [14, 16], [15, 16], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20], [21, 22], [21, 23], [21, 24], [22, 23], [22, 24], [23, 24], [25, 26], [25, 27], [25, 28], [26, 27], [26, 28], [27, 28], [29, 30], [1, 5], [2, 6], [3, 7], [4, 8], [1, 9], [2, 10], [3, 11], [4, 12], [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]]) == 7\n assert candidate(n = 20,edges = [[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], [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, 1], [20, 2]]) == 6\n assert candidate(n = 35,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [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], [15, 21], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [17, 18], [17, 19], [17, 20], [17, 21], [18, 19], [18, 20], [18, 21], [19, 20], [19, 21], [20, 21], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 28], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [24, 25], [24, 26], [24, 27], [24, 28], [25, 26], [25, 27], [25, 28], [26, 27], [26, 28], [27, 28], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [31, 32], [31, 33], [31, 34], [31, 35], [32, 33], [32, 34], [32, 35], [33, 34], [33, 35], [34, 35], [1, 15], [2, 16], [3, 17], [4, 18], [5, 19], [6, 20], [7, 21], [8, 22], [9, 23], [10, 24], [11, 25], [12, 26], [13, 27], [14, 28], [15, 29], [16, 30], [17, 31], [18, 32], [19, 33], [20, 34], [21, 35]]) == 15\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [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, 5], [3, 5], [4, 7], [5, 7], [6, 9], [7, 9], [8, 11], [9, 11], [10, 13], [11, 13], [12, 14], [13, 14]]) == 5\n assert candidate(n = 20,edges = [[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], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == 3\n assert candidate(n = 20,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 19], [1, 4], [2, 5], [3, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17], [12, 18], [13, 19], [14, 20], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20]]) == 5\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [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]]) == 3\n assert candidate(n = 5,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5]]) == 5\n assert candidate(n = 40,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [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, 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, 31], [34, 35], [35, 36], [36, 34], [37, 38], [38, 39], [39, 37], [40, 1]]) == 0\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20]]) == 12\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [13, 14], [13, 15], [13, 16], [14, 15], [14, 16], [15, 16], [17, 18], [17, 19], [17, 20], [18, 19], [18, 20], [19, 20]]) == 3\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [1, 4], [2, 5], [3, 6], [1, 7], [2, 8], [3, 8]]) == 3\n assert candidate(n = 20,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 1], [20, 19]]) == 0\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [14, 15]]) == 3\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 1], [9, 2], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 1], [8, 2], [9, 3]]) == 12\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [9, 10]]) == 6\n assert candidate(n = 5,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [3, 5], [4, 5]]) == 4\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15]]) == 6\n assert candidate(n = 25,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [11, 16], [12, 17], [13, 18], [14, 19], [15, 20], [21, 2], [22, 3], [23, 4], [24, 5], [25, 1]]) == -1\n assert candidate(n = 25,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [6, 10], [7, 8], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [11, 15], [12, 13], [12, 14], [12, 15], [12, 16], [13, 14], [13, 15], [13, 16], [13, 17], [14, 15], [14, 16], [14, 17], [14, 18], [15, 16], [15, 17], [15, 18], [15, 19], [16, 17], [16, 18], [16, 19], [16, 20], [17, 18], [17, 19], [17, 20], [17, 21], [18, 19], [18, 20], [18, 21], [18, 22], [19, 20], [19, 21], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [20, 24], [21, 22], [21, 23], [21, 24], [21, 25], [22, 23], [22, 24], [22, 25], [23, 24], [23, 25], [24, 25], [25, 1]]) == 10\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 1], [10, 2]]) == 4\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [9, 10], [11, 12], [11, 13], [12, 13], [1, 5], [3, 6], [4, 8], [7, 11]]) == 1\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [26, 27], [26, 28], [26, 29], [26, 30], [27, 28], [27, 29], [27, 30], [28, 29], [28, 30], [29, 30], [30, 1]]) == 13\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13], [1, 4], [2, 5], [3, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 13], [11, 14], [12, 15]]) == 6\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [2, 5], [3, 4], [3, 6], [4, 5], [5, 6], [6, 7], [7, 8], [8, 4]]) == 4\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 21], [21, 19], [22, 23], [23, 24], [24, 22], [25, 26], [26, 27], [27, 25], [28, 29], [29, 30], [30, 28]]) == 0\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 6], [3, 4], [3, 7], [4, 8], [5, 6], [6, 7], [7, 8]]) == 6\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 21], [21, 19], [22, 23], [23, 24], [24, 22], [25, 26], [26, 27], [27, 25], [28, 29], [29, 30], [30, 28], [1, 13], [2, 14], [3, 15], [4, 16], [5, 17], [6, 18], [7, 19], [8, 20], [9, 21], [10, 22], [11, 23], [12, 24], [1, 25], [2, 26], [3, 27], [4, 28], [5, 29], [6, 30]]) == 3\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 1], [20, 19], [21, 22], [22, 23], [23, 21], [24, 25], [25, 26], [26, 24], [27, 28], [28, 29], [29, 27], [30, 21], [30, 25]]) == 0\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12], [1, 5], [2, 6], [3, 7], [4, 8], [1, 9], [2, 10], [3, 11], [4, 12]]) == 6\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [14, 15], [14, 16], [14, 17], [15, 16], [15, 17], [16, 17], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15], [11, 16], [12, 17], [1, 14], [2, 15], [3, 16], [4, 17], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17]]) == 11\n assert candidate(n = 15,edges = [[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], [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]]) == 5\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 1], [2, 5], [3, 5], [4, 7], [5, 7], [6, 9], [7, 9], [8, 11], [9, 11]]) == 5\n assert candidate(n = 40,edges = [[1, 2], [2, 3], [1, 3], [4, 5], [5, 6], [4, 6], [7, 8], [8, 9], [7, 9], [10, 11], [11, 12], [10, 12], [13, 14], [14, 15], [13, 15], [16, 17], [17, 18], [16, 18], [19, 20], [20, 21], [19, 21], [22, 23], [23, 24], [22, 24], [25, 26], [26, 27], [25, 27], [28, 29], [29, 30], [28, 30], [31, 32], [32, 33], [31, 33], [34, 35], [35, 36], [34, 36], [37, 38], [38, 39], [37, 39], [40, 1], [2, 4], [3, 5], [6, 8], [7, 9], [10, 12], [11, 13], [14, 16], [15, 17], [18, 20], [19, 21], [22, 24], [23, 25], [26, 28], [27, 29], [30, 32], [31, 33], [34, 36], [35, 37], [38, 40], [39, 1]]) == 3\n", "comparison": "exact"}, "public_tests": ["6\n[[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]", "7\n[[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]"], "hints": ["Consider a trio with nodes u, v, and w. The degree of the trio is just degree(u) + degree(v) + degree(w) - 6. The -6 comes from subtracting the edges u-v, u-w, and v-w, which are counted twice each in the vertex degree calculation.", "To get the trios (u,v,w), you can iterate on u, then iterate on each w,v such that w and v are neighbors of u and are neighbors of each other."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().minTrioDegree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:29:55+00:00", "tests_total": 64, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["graph", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function minTrioDegree($n, $edges) {", "container": "Solution", "callable": "minTrioDegree", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1763, "task_id": "longest-nice-substring", "difficulty": "Easy", "problem_description": "A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, \"abABB\" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, \"abA\" is not because 'b' appears, but 'B' does not.\n\nGiven a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.\n\nExample 1:\n\nInput: s = \"YazaAay\"\nOutput: \"aAa\"\nExplanation: \"aAa\" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.\n\"aAa\" is the longest nice substring.\n\nExample 2:\n\nInput: s = \"Bb\"\nOutput: \"Bb\"\nExplanation: \"Bb\" is a nice string because both 'B' and 'b' appear. The whole string is a substring.\n\nExample 3:\n\nInput: s = \"c\"\nOutput: \"\"\nExplanation: There are no nice substrings.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of uppercase and lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"Bb\") == \"Bb\"\n assert candidate(s = \"aAbBcCdDeEfFgG\") == \"aAbBcCdDeEfFgG\"\n assert candidate(s = \"c\") == \"\"\n assert candidate(s = \"aBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"BbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\"\n assert candidate(s = \"abcdefgHIJKlmnopQRStuVwxYZ\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"aAaBbCc\") == \"aAaBbCc\"\n assert candidate(s = \"QwertyuiopASDFGHJKLzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWq\") == \"zxcvbnmMNBVCXZ\"\n assert candidate(s = \"aaAAbbBBccCC\") == \"aaAAbbBBccCC\"\n assert candidate(s = \"aA\") == \"aA\"\n assert candidate(s = \"dDcCbBaA\") == \"dDcCbBaA\"\n assert candidate(s = \"AabbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"CcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\"\n assert candidate(s = \"aAb\") == \"aA\"\n assert candidate(s = \"aAbBcC\") == \"aAbBcC\"\n assert candidate(s = \"YazaAay\") == \"aAa\"\n assert candidate(s = \"dDfFgG\") == \"dDfFgG\"\n assert candidate(s = \"mnopQRstuvQR\") == \"\"\n assert candidate(s = \"aBcDef\") == \"\"\n assert candidate(s = \"abABB\") == \"abABB\"\n assert candidate(s = \"AbcDEdEfghIjklmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"\"\n assert candidate(s = \"abABcdCDefEF\") == \"abABcdCDefEF\"\n assert candidate(s = \"aabBcC\") == \"bBcC\"\n assert candidate(s = \"AaBbCcDd\") == \"AaBbCcDd\"\n assert candidate(s = \"xyzXYZ\") == \"xyzXYZ\"\n assert candidate(s = \"abcD\") == \"\"\n assert candidate(s = \"abcABCdefDEFghGHijIJklKLmnopMNOPqrstQRSTuvUVwxWXyzYZ\") == \"abcABCdefDEFghGHijIJklKLmnopMNOPqrstQRSTuvUVwxWXyzYZ\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefgHIJKLmnopQRstuvWxyz\") == \"\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbB\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbB\"\n assert candidate(s = \"aBcD\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdEFGH\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdEFGH\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmM\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmM\"\n assert candidate(s = \"xyzXYZaBcDedCbAz\") == \"xyzXYZ\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaBbCcdDeE\") == \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaBbCcdDeE\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdefghijklmnopqrstuvwxyzaA\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdefghijklmnopqrstuvwxyzaA\"\n assert candidate(s = \"aabbCCddEEffGGhhIIjjKKllMMnnOOppQQrrSSttuUvVwWxXyYzZ\") == \"uUvVwWxXyYzZ\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == \"\"\n assert candidate(s = \"abcdEFGHijklMNOpQRstUVwxyzZ\") == \"zZ\"\n assert candidate(s = \"abABcdCDefEFGghHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"abABcdCDefEFGghHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZxyzyxwvutVUtUrRqQpPnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZxyzyxwvutVUtUrRqQpPnNmMlLkKjJiIhHgGfFeEdDcCbBaA\"\n assert candidate(s = \"abcdEFGhijKLMnopQRStuVwXYz\") == \"\"\n assert candidate(s = \"abcdefGhijklMnopqrstuvwxyz\") == \"\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaBcDeFgHiJkLmNoPqRsTuVwXyZ\"\n assert candidate(s = \"abcdefABCDefghijklmnoMNOPQRSTuvwxyXYZ\") == \"mnoMNO\"\n assert candidate(s = \"abcdEFGHijklMNOPqrstUVWXyzABCDefghIJKLmnopQRstuVWXyz\") == \"\"\n assert candidate(s = \"aBcDabcdABCD\") == \"aBcDabcdABCD\"\n assert candidate(s = \"xYzZyXaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwW\") == \"xYzZyXaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwW\"\n assert candidate(s = \"aBcDEfGhIjKlMnOpQrStUvWxYz\") == \"\"\n assert candidate(s = \"xyzXYZabcABCdefDEFghijGHIJklmnopqrQRSTUVWstuvUVW\") == \"xyzXYZabcABCdefDEFghijGHIJ\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopQRstuVWXyz\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopQRstuVWXyz\"\n assert candidate(s = \"bBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaA\") == \"bBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaA\"\n assert candidate(s = \"abcdefABCDefgHIJKlMNOPqrSTUVwxYZaBcDefGhIjKlMnoPqrStUvWxYz\") == \"\"\n assert candidate(s = \"abABcdCDefEFghGHijIJklKLmnopMNOPqrstuvwxyzZXYwvuUVtsrSRQPONMLKJIHgfedcbaABab\") == \"abABcdCDefEFghGHijIJklKLmnopMNOP\"\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == \"\"\n assert candidate(s = \"abcdefghijABCDEFGHIJKLmnopqrstuvwxyz\") == \"abcdefghijABCDEFGHIJ\"\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\") == \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbB\") == \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbB\"\n assert candidate(s = \"aaabBBcccAAbbbCCC\") == \"aaabBBcccAAbbbCCC\"\n assert candidate(s = \"abcdefgHIJKLmnopQRstuvWxyzabcdefgHIJKLmnopQRstuvWxyz\") == \"\"\n assert candidate(s = \"aBcDabcdABCDzzZZyyYYxxXXwwWWvvVVuuUUttTTssSSrrQQppOOmmLLkkJJiiHHggFFddBBAA\") == \"aBcDabcdABCDzzZZyyYYxxXXwwWWvvVVuuUUttTTssSS\"\n assert candidate(s = \"aaAaAaBbBbBbCcCcCc\") == \"aaAaAaBbBbBbCcCcCc\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\"\n assert candidate(s = \"bAcBdCd\") == \"\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZxyzXYZabcABCdefDEFghiGHIjklJKLmnoMNOpqrPQRstuSTUvVwWxyXYzZ\") == \"aBcDeFgHiJkLmNoPqRsTuVwXyZxyzXYZabcABCdefDEFghiGHIjklJKLmnoMNOpqrPQRstuSTUvVwWxyXYzZ\"\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\"\n assert candidate(s = \"abcABCxyzXYZdefDEF\") == \"abcABCxyzXYZdefDEF\"\n assert candidate(s = \"abAcBdCdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"EeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZabcDEF\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZabcDEF\"\n assert candidate(s = \"aAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzABCdef\") == \"aAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzABCdef\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbB\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbB\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abcABCdefDEFghGHIjklKLmnopqrQRstuvUVwxyzXYZ\") == \"abcABCdefDEFghGH\"\n assert candidate(s = \"abABcdCDefEFghGHijIJklKLmnopMNOPqrstuvwxyzZXYwvuUVtsrSRQPONMLKJIHgfedcba\") == \"abABcdCDefEFghGHijIJklKLmnopMNOP\"\n assert candidate(s = \"abcdefABCDefgHIJKlMNOPqrSTUVwxYZ\") == \"\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopqrQRST\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopqrQRST\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZabcdEfghijklmnopqrstuVwxy\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZabcdEfghijklmnopqrstuVwxy\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZa\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZa\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZcC\") == \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZcC\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbBaAcCdD\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZbBaAcCdD\"\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"zZyYxXwWvVuUtTsSrRpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\"\n assert candidate(s = \"xYzZyXaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"xYzZyXaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCc\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCc\"\n assert candidate(s = \"abcABCdefDEFgGhHijIJklKLmMnopNOPqrQRstSTuUVwWXyYzZ\") == \"abcABCdefDEFgGhHijIJklKLmMnopNOPqrQRstSTuU\"\n assert candidate(s = \"AbcDeFgHiJklMnopqrStuvWxyzZ\") == \"zZ\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzXxYyZz\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzXxYyZz\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaBbCcdDeEfffGg\") == \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaBbCcdDeE\"\n assert candidate(s = \"abcdefABCDEFxyzXYZuvwUVWqQrRsStTuUvVwWxXyYzZ\") == \"abcdefABCDEFxyzXYZuvwUVWqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"abcdEFGHijklMNOPqrSTUVwxyz\") == \"\"\n assert candidate(s = \"abcXYZabcXYZabcXYZ\") == \"\"\n assert candidate(s = \"abcdEFGHijklMNOPqrstUVWXyzabcdEFGHijklMNOPqrstUVWXyz\") == \"\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzAA\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopQRstuVWXyzABCdefGHIjklMNOpQRstuVWXyz\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzmnopQRstuVWXyzABCdefGHIjklMNOpQRstuVWXyz\"\n assert candidate(s = \"aaBBccDDeeFFggHHiiJJKkllMMnnOoPPqqRRssTTuuVVwwXXyyZZ\") == \"Kk\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAbCdEfGhIjKlMnOpQrStUvWxYz\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAbCdEfGhIjKlMnOpQrStUvWxYz\"\n assert candidate(s = \"xyzXYZabcABCdefDEFghiGHIjklJKLmnoMNOpqrPQRstuSTUvVwWxyXYzZ\") == \"xyzXYZabcABCdefDEFghiGHIjklJKLmnoMNOpqrPQRstuSTUvVwWxyXYzZ\"\n assert candidate(s = \"AbcDefGhiJklMnoPqrStuVwxYzABCdefGHIjklMNOpQRstuVWXyz\") == \"\"\n assert candidate(s = \"abcdEFGHijklMNOPqrstUVWXyz\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbC\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbC\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzABCD\") == \"\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"aBcDeFgHiJkLmNoPqRsTuVwXyZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaA\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaA\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"abcdefgHIJKLmnopQRstUVwXYZ\") == \"\"\n assert candidate(s = \"abcdEFGHijkLmnopQRstUVwxYZ\") == \"\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZab\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZab\"\n assert candidate(s = \"abcdefgHIJKLmnopQRstuvWxyz\") == \"\"\n assert candidate(s = \"abcdefgHIJKLmnopQRstuvWxyzab\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdefghijklmnopqrstuvwxyza\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzabcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"abcdefGHIJkLmnopQRstuvWXYZ\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzABCDEF\") == \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzABCDEF\"\n assert candidate(s = \"xXyYzZwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"xXyYzZwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUvWxYz\") == \"\"\n assert candidate(s = \"aBcDcBaEeFfEgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"EeFfEgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaabbCCddeeffGG\") == \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaabbCCddeeffGG\"\n", "comparison": "exact"}, "public_tests": ["\"YazaAay\"", "\"Bb\"", "\"c\""], "hints": ["Brute force and check each substring to see if it is nice."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().longestNiceSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:00+00:00", "tests_total": 152, "tests_dropped": 30, "flags": [], "topic_tags": ["hash-table", "string", "divide-and-conquer", "bit-manipulation", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function longestNiceSubstring($s) {", "container": "Solution", "callable": "longestNiceSubstring", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1764, "task_id": "form-array-by-concatenating-subarrays-of-another-array", "difficulty": "Medium", "problem_description": "You are given a 2D integer array groups of length n. You are also given an integer array nums.\n\nYou are asked if you can choose n disjoint subarrays from the array nums such that the i^th subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)^th subarray appears before the i^th subarray in nums (i.e. the subarrays must be in the same order as groups).\n\nReturn true if you can do this task, and false otherwise.\n\nNote that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\nOutput: true\nExplanation: You can choose the 0^th subarray as [1,-1,0,1,-1,-1,3,-2,0] and the 1^st one as [1,-1,0,1,-1,-1,3,-2,0].\nThese subarrays are disjoint as they share no common nums[k] element.\n\nExample 2:\n\nInput: groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\nOutput: false\nExplanation: Note that choosing the subarrays [1,2,3,4,10,-2] and [1,2,3,4,10,-2] is incorrect because they are not in the same order as in groups.\n[10,-2] must come before [1,2,3,4].\n\nExample 3:\n\nInput: groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\nOutput: false\nExplanation: Note that choosing the subarrays [7,7,1,2,3,4,7,7] and [7,7,1,2,3,4,7,7] is invalid because they are not disjoint.\nThey share a common elements nums[4] (0-indexed).\n\nConstraints:\n\n- groups.length == n\n- 1 <= n <= 10^3\n- 1 <= groups[i].length, sum(groups[i].length) <= 10^3\n- 1 <= nums.length <= 10^3\n- -10^7 <= groups[i][j], nums[k] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(groups = [[1, 2, 3]],nums = [1, 2, 3, 1, 2, 3]) == True\n assert candidate(groups = [[1, 2], [3, 4]],nums = [1, 2, 4, 3]) == False\n assert candidate(groups = [[5, 5, 5], [5]],nums = [5, 5, 5, 5]) == True\n assert candidate(groups = [[1, 1, 1], [1, 1]],nums = [1, 1, 1, 1]) == False\n assert candidate(groups = [[1, 2], [3, 4]],nums = [1, 2, 3, 4]) == True\n assert candidate(groups = [[1, 2], [2, 1]],nums = [1, 2, 2, 1]) == True\n assert candidate(groups = [[-1, -2, -3], [-3, -2, -1]],nums = [-1, -2, -3, -3, -2, -1]) == True\n assert candidate(groups = [[1, -1, -1], [3, -2, 0]],nums = [1, -1, 0, 1, -1, -1, 3, -2, 0]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2, 3]],nums = [1, 2, 3, 1, 2, 3]) == True\n assert candidate(groups = [[1]],nums = [1]) == True\n assert candidate(groups = [[1, 2], [3, 4]],nums = [1, 2, 5, 3, 4]) == True\n assert candidate(groups = [[1], [2], [3]],nums = [3, 2, 1]) == False\n assert candidate(groups = [[1, 1, 1, 1], [1, 1]],nums = [1, 1, 1, 1]) == False\n assert candidate(groups = [[1], [2], [3]],nums = [1, 2, 3]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4]],nums = [7, 7, 1, 2, 3, 4, 7, 7]) == False\n assert candidate(groups = [[5, 5]],nums = [5, 5, 5, 5]) == True\n assert candidate(groups = [[10, -2], [1, 2, 3, 4]],nums = [1, 2, 3, 4, 10, -2]) == False\n assert candidate(groups = [[1]],nums = [2]) == False\n assert candidate(groups = [[1, 2], [2, 3]],nums = [1, 2, 2, 3]) == True\n assert candidate(groups = [[1, 2], [3, 4]],nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4]],nums = [1, 2, 3, 4]) == False\n assert candidate(groups = [[1, 2], [3, 4], [5, 6]],nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[100, 200], [200, 300], [300, 400]],nums = [100, 200, 200, 300, 300, 400]) == True\n assert candidate(groups = [[100, 200], [300, 400], [500, 600]],nums = [100, 200, 300, 400, 500, 600, 100, 200]) == True\n assert candidate(groups = [[0, 0, 0, 0], [0]],nums = [0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(groups = [[10, 20, 30], [30, 40, 50], [50, 60, 70]],nums = [10, 20, 30, 40, 50, 60, 70]) == False\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 7, 8, 9, 7, 8, 9]) == True\n assert candidate(groups = [[9, 8, 7], [8, 7, 6], [7, 6, 5]],nums = [9, 8, 7, 8, 7, 6, 7, 6, 5]) == True\n assert candidate(groups = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],nums = [1, 2, 3, 4, 5, 6, 7]) == False\n assert candidate(groups = [[1, 1, 1], [1, 1, 1]],nums = [1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(groups = [[-1, -2, -3], [-3, -4, -5], [-5, -6, -7]],nums = [-1, -2, -3, -3, -4, -5, -5, -6, -7]) == True\n assert candidate(groups = [[1, 1, 1], [1, 1], [1]],nums = [1, 1, 1, 1, 1]) == False\n assert candidate(groups = [[0, 1], [1, 2], [2, 3], [3, 4]],nums = [0, 1, 1, 2, 2, 3, 3, 4]) == True\n assert candidate(groups = [[-1, -2, -3], [-4, -5], [-6, -7, -8, -9]],nums = [-1, -2, -3, 0, -4, -5, 1, -6, -7, -8, -9]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5]],nums = [1, 2, 3, 99, 3, 4, 5]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2, 3], [1, 2, 3]],nums = [1, 2, 3, 4, 5, 1, 2, 3, 6, 7, 8, 1, 2, 3]) == True\n assert candidate(groups = [[-1, -2, -3], [-3, -2, -1], [0, 0, 0]],nums = [-1, -2, -3, 0, 0, 0, -3, -2, -1]) == False\n assert candidate(groups = [[1, 2, 3], [1, 2, 3, 4], [4, 5]],nums = [1, 2, 3, 1, 2, 3, 4, 4, 5]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [2, 3, 4], [3, 4, 5, 6]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 2, 3, 3, 4, 4, 5]) == True\n assert candidate(groups = [[-1, -2, -3], [-4, -5, -6]],nums = [-1, -2, -3, -4, -5, -6, -1, -2, -3, -4, -5, -6]) == True\n assert candidate(groups = [[1, 2, 3], [3, 2, 1], [2, 1, 3]],nums = [1, 2, 3, 3, 2, 1, 2, 1, 3]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]],nums = [1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9]) == True\n assert candidate(groups = [[10, 20, 30], [40, 50], [60, 70, 80]],nums = [5, 10, 20, 30, 15, 40, 50, 25, 60, 70, 80]) == True\n assert candidate(groups = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 2, 3, 3, 4, 99, 4, 5]) == True\n assert candidate(groups = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7]],nums = [1, 2, 3, 3, 4, 5, 5, 6, 7]) == True\n assert candidate(groups = [[9, 8, 7], [6, 5, 4], [3, 2, 1]],nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(groups = [[1, 2, 3], [2, 3, 4], [3, 4, 5]],nums = [1, 2, 3, 2, 3, 4, 3, 4, 5]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5]],nums = [1, 0, 2, 0, 3, 0, 4, 0, 5]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2], [1]],nums = [1, 2, 3, 1, 2, 1]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]],nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4]],nums = [1, 2, 3, 4, 5, 3, 4]) == False\n assert candidate(groups = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [1, 1, 1]],nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1]) == True\n assert candidate(groups = [[1, 1], [2, 2], [1, 1], [2, 2]],nums = [1, 1, 2, 2, 1, 1, 2, 2]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2, 3], [1, 2, 3]],nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == True\n assert candidate(groups = [[-10, -20, -30], [-40, -50, -60], [-70, -80, -90]],nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == True\n assert candidate(groups = [[1, 2, 3, 4], [5, 6, 7], [8, 9]],nums = [1, 2, 3, 4, 10, 11, 5, 6, 7, 12, 8, 9]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 3, 4, 5, 2, 3, 4, 5]) == False\n assert candidate(groups = [[1, 2, 3, 4, 5], [5, 6, 7], [8, 9]],nums = [1, 2, 3, 4, 5, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[-1, -2, -3], [-3, -2, -1], [1, 2, 3]],nums = [-1, -2, -3, -3, -2, -1, 1, 2, 3]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [9, 10, 11, 12, 13]],nums = [1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == True\n assert candidate(groups = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5]],nums = [1, 2, 3, 3, 4, 5]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4]],nums = [1, 2, 3, 4, 5]) == False\n assert candidate(groups = [[-1, -2, -3], [-4, -5], [-6, -7, -8]],nums = [-1, -2, -3, 0, -4, -5, 0, -6, -7, -8]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]],nums = [1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9]) == True\n assert candidate(groups = [[10, 20, 30], [20, 30, 40], [30, 40, 50]],nums = [10, 20, 30, 20, 30, 40, 30, 40, 50]) == True\n assert candidate(groups = [[1, 2], [3, 4], [5, 6], [7, 8]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(groups = [[1, 1, 1], [1, 1], [1]],nums = [1, 1, 1, 1, 1, 1]) == True\n assert candidate(groups = [[100, 200], [200, 300], [300, 400], [400, 500]],nums = [100, 200, 200, 300, 300, 400, 400, 500]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [1, 2, 3], [4, 5, 6]],nums = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[-1, -2, -3], [-2, -3, -4], [-3, -4, -5]],nums = [-1, -2, -3, -2, -3, -4, -3, -4, -5]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 3, 4, 5]) == False\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7]],nums = [1, 2, 3, 4, 5, 6, 7]) == False\n assert candidate(groups = [[100, 200], [300, 400, 500], [600]],nums = [50, 100, 200, 150, 300, 400, 500, 200, 600]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4]],nums = [1, 2, 2, 3, 3, 4, 4]) == True\n assert candidate(groups = [[1, 2], [3, 4], [1, 2]],nums = [1, 2, 3, 4, 1, 2]) == True\n assert candidate(groups = [[1, 1, 1, 1], [1, 1], [1]],nums = [1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2, 3], [1, 2, 3]],nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2], [2, 3]],nums = [1, 2, 3, 1, 2, 2, 3]) == True\n assert candidate(groups = [[9, 8, 7], [6, 5, 4], [3, 2, 1]],nums = [9, 8, 7, 0, 6, 5, 4, 0, 3, 2, 1]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7]],nums = [1, 2, 3, 3, 4, 5, 5, 6, 7]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 9, 8, 7, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 1, 1], [1, 1], [1]],nums = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(groups = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(groups = [[10000000], [9999999], [8888888], [7777777]],nums = [10000000, 9999999, 8888888, 7777777]) == True\n assert candidate(groups = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(groups = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]],nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(groups = [[5, 5, 5, 5], [5, 5, 5], [5, 5], [5]],nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5]],nums = [1, 2, 3, 4, 5]) == True\n assert candidate(groups = [[-10, -20, -30], [-40, -50], [-60, -70, -80]],nums = [-10, -20, -30, -40, -50, -60, -70, -80]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5]],nums = [1, 2, 3, 4, 5]) == True\n assert candidate(groups = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],nums = [1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(groups = [[1, 2], [3, 4, 5, 6], [7, 8]],nums = [1, 2, 3, 4, 5, 6, 7, 8]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[10, 20, 30, 40], [50, 60, 70, 80]],nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == True\n assert candidate(groups = [[1, 2], [2, 1], [1, 2], [2, 1]],nums = [1, 2, 2, 1, 1, 2, 2, 1]) == True\n assert candidate(groups = [[-10, -20, -30], [-30, -20, -10]],nums = [-10, -20, -30, -30, -20, -10]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == True\n assert candidate(groups = [[-1, 0, 1], [-2, 0, 2]],nums = [-1, 0, 1, -2, 0, 2, -1, 0, 1]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7]],nums = [99, 1, 2, 3, 99, 3, 4, 5, 99, 5, 6, 7]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5]],nums = [1, 2, 3, 3, 4, 5]) == True\n assert candidate(groups = [[1, 2, 3], [1, 2, 3], [1, 2, 3]],nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == True\n assert candidate(groups = [[1, 2, 3], [3, 2, 1], [1, 2, 3]],nums = [1, 2, 3, 3, 2, 1, 1, 2, 3]) == True\n assert candidate(groups = [[7, 8, 9], [1, 2, 3], [4, 5, 6]],nums = [7, 8, 9, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6]],nums = [1, 2, 3, 0, 0, 4, 5, 6]) == True\n assert candidate(groups = [[-1, -2, -3], [0, 1, 2], [-3, -2, -1]],nums = [-1, -2, -3, 0, 1, 2, -3, -2, -1]) == True\n assert candidate(groups = [[1, 2, 3], [2, 3, 4]],nums = [1, 2, 3, 4]) == False\n assert candidate(groups = [[9, 8, 7, 6, 5], [4, 3, 2, 1], [0, -1, -2, -3, -4]],nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]) == True\n assert candidate(groups = [[100, 200, 300], [400, 500], [600]],nums = [100, 200, 300, 400, 500, 600]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6]],nums = [1, 2, 3, 99, 4, 5, 6]) == True\n assert candidate(groups = [[1, 1, 1, 1], [1, 1, 1], [1, 1], [1]],nums = [1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(groups = [[1, 2, 3], [3, 2, 1]],nums = [1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1]) == True\n assert candidate(groups = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],nums = [0, 1, 2, 3, 4, 0, 5, 6, 7, 8, 0, 9, 10, 11, 12]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]],nums = [1, 2, 3, 4, 5, 11, 12, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, -1], [1, -1]],nums = [1, -1, 1, -1, 1, -1]) == True\n assert candidate(groups = [[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]],nums = [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]) == True\n assert candidate(groups = [[1, 2], [2, 3], [3, 4], [4, 5]],nums = [1, 2, 3, 4, 5]) == False\n assert candidate(groups = [[1, 2, 3], [4, 5, 6]],nums = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[1], [2], [3], [4], [5], [6]],nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [0, 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9]) == True\n assert candidate(groups = [[100, 200, 300], [400, 500], [600, 700, 800, 900]],nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == True\n assert candidate(groups = [[1, 1], [1, 1], [1, 1]],nums = [1, 1, 1, 1, 1, 1]) == True\n assert candidate(groups = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],nums = [7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6]) == True\n assert candidate(groups = [[1, 2, 3, 4, 5], [6, 7, 8, 9]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(groups = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(groups = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n", "comparison": "exact"}, "public_tests": ["[[1,-1,-1],[3,-2,0]]\n[1,-1,0,1,-1,-1,3,-2,0]", "[[10,-2],[1,2,3,4]]\n[1,2,3,4,10,-2]", "[[1,2,3],[3,4]]\n[7,7,1,2,3,4,7,7]"], "hints": ["When we use a subarray, the room for the next subarrays will be the suffix after the used subarray.", "If we can match a group with multiple subarrays, we should choose the first one, as this will just leave the largest room for the next subarrays."], "metadata": {"canonical_parameter_names": ["groups", "nums"], "leetcode_dataset_entry_point": "Solution().canChoose", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:02+00:00", "tests_total": 148, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers", "greedy", "string-matching", "knuth-morris-pratt-algorithm"]}, "language": "php", "interface": {"raw_signature": "function canChoose($groups, $nums) {", "container": "Solution", "callable": "canChoose", "parameters": [{"name": "groups", "type": "Integer[][]"}, {"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1765, "task_id": "map-of-highest-peak", "difficulty": "Medium", "problem_description": "You are given an integer matrix isWater of size m x n that represents a map of land and water cells.\n\n- If isWater[i][j] == 0, cell (i, j) is a land cell.\n- If isWater[i][j] == 1, cell (i, j) is a water cell.\n\nYou must assign each cell a height in a way that follows these rules:\n\n- The height of each cell must be non-negative.\n- If the cell is a water cell, its height must be 0.\n- Any two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).\n\nFind an assignment of heights such that the maximum height in the matrix is maximized.\n\nReturn an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.\n\nExample 1:\n\nInput: isWater = [[0,1],[0,0]]\nOutput: [[1,0],[2,1]]\nExplanation: The image shows the assigned heights of each cell.\nThe blue cell is the water cell, and the green cells are the land cells.\n\nExample 2:\n\nInput: isWater = [[0,0,1],[1,0,0],[0,0,0]]\nOutput: [[1,1,0],[0,1,1],[1,2,2]]\nExplanation: A height of 2 is the maximum possible height of any assignment.\nAny height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.\n\nConstraints:\n\n- m == isWater.length\n- n == isWater[i].length\n- 1 <= m, n <= 1000\n- isWater[i][j] is 0 or 1.\n- There is at least one water cell.\n\nNote: This question is the same as 542: https://leetcode.com/problems/01-matrix/\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(isWater = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == [[2, 1, 2], [1, 0, 1], [2, 1, 2]]\n assert candidate(isWater = [[0, 1], [0, 0]]) == [[1, 0], [2, 1]]\n assert candidate(isWater = [[1, 1], [1, 1]]) == [[0, 0], [0, 0]]\n assert candidate(isWater = [[0, 0, 1], [1, 0, 0], [0, 0, 0]]) == [[1, 1, 0], [0, 1, 1], [1, 2, 2]]\n assert candidate(isWater = [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]]) == [[3, 2, 1, 0], [2, 1, 0, 1], [1, 0, 1, 2], [0, 1, 2, 3]]\n assert candidate(isWater = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 3, 2, 3, 4], [3, 2, 1, 2, 1, 2, 3], [2, 1, 0, 1, 0, 1, 2], [3, 2, 1, 2, 1, 2, 3], [4, 3, 2, 3, 2, 3, 4]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 1, 0, 1, 2, 3, 4], [3, 4, 3, 2, 1, 2, 3, 4, 3], [2, 3, 4, 3, 2, 3, 4, 3, 2], [1, 2, 3, 4, 3, 4, 3, 2, 1], [0, 1, 2, 3, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == [[3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [1, 0, 1, 0, 1], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3]]\n assert candidate(isWater = [[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, 1]]) == [[0, 1, 2, 3, 4, 4], [1, 2, 1, 2, 3, 3], [2, 1, 0, 1, 2, 2], [3, 2, 1, 2, 2, 1], [4, 3, 2, 2, 1, 0]]\n assert candidate(isWater = [[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], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 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]]) == [[0, 1, 2, 1, 0, 1, 2, 1, 0], [1, 2, 3, 2, 1, 2, 3, 2, 1], [2, 3, 4, 3, 2, 3, 4, 3, 2], [3, 4, 5, 4, 3, 4, 5, 4, 3], [4, 5, 6, 5, 4, 5, 6, 5, 4], [3, 4, 5, 4, 3, 4, 5, 4, 3], [2, 3, 4, 3, 2, 3, 4, 3, 2], [1, 2, 3, 2, 1, 2, 3, 2, 1], [0, 1, 2, 1, 0, 1, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[5, 4, 3, 2, 1, 0, 1, 2, 3, 4], [6, 5, 4, 3, 2, 1, 2, 3, 4, 5], [7, 6, 5, 4, 3, 2, 3, 4, 5, 6], [8, 7, 6, 5, 4, 3, 4, 5, 6, 7], [9, 8, 7, 6, 5, 4, 5, 6, 7, 8], [10, 9, 8, 7, 6, 5, 6, 7, 8, 9], [11, 10, 9, 8, 7, 6, 7, 8, 9, 10], [12, 11, 10, 9, 8, 7, 8, 9, 10, 11]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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]]) == [[7, 6, 5, 4, 5, 6, 7, 8, 9, 10], [6, 5, 4, 3, 4, 5, 6, 7, 8, 9], [5, 4, 3, 2, 3, 4, 5, 6, 7, 8], [4, 3, 2, 1, 2, 3, 4, 5, 6, 7], [3, 2, 1, 0, 1, 2, 3, 4, 5, 6], [4, 3, 2, 1, 2, 3, 4, 5, 6, 7], [5, 4, 3, 2, 3, 4, 5, 6, 7, 8], [6, 5, 4, 3, 4, 5, 6, 7, 8, 9], [7, 6, 5, 4, 5, 6, 7, 8, 9, 10], [8, 7, 6, 5, 6, 7, 8, 9, 10, 11]]\n assert candidate(isWater = [[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, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 8], [2, 3, 4, 5, 6, 7, 8, 9, 8, 7], [3, 4, 5, 6, 7, 8, 9, 8, 7, 6], [4, 5, 6, 7, 8, 9, 8, 7, 6, 5], [5, 6, 7, 8, 9, 8, 7, 6, 5, 4], [6, 7, 8, 9, 8, 7, 6, 5, 4, 3], [7, 8, 9, 8, 7, 6, 5, 4, 3, 2], [8, 9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [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]]) == [[8, 7, 6, 5, 4, 5, 6, 7, 8, 9], [7, 6, 5, 4, 3, 4, 5, 6, 7, 8], [6, 5, 4, 3, 2, 3, 4, 5, 6, 7], [5, 4, 3, 2, 1, 2, 3, 4, 5, 6], [4, 3, 2, 1, 0, 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], [7, 6, 5, 4, 3, 4, 5, 6, 7, 8]]\n assert candidate(isWater = [[0, 0, 0, 1, 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], [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]]) == [[3, 2, 1, 0, 1, 2, 3, 4, 5, 6], [2, 1, 0, 1, 2, 3, 4, 5, 6, 7], [1, 0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [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], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]\n assert candidate(isWater = [[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]]) == [[2, 1, 2, 1, 2], [1, 0, 1, 0, 1], [2, 1, 2, 1, 2], [1, 0, 1, 0, 1], [2, 1, 2, 1, 2]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 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]]) == [[10, 9, 8, 7, 6, 7, 8, 9], [9, 8, 7, 6, 5, 6, 7, 8], [8, 7, 6, 5, 4, 5, 6, 7], [7, 6, 5, 4, 3, 4, 5, 6], [6, 5, 4, 3, 2, 3, 4, 5], [5, 4, 3, 2, 1, 2, 3, 4], [4, 3, 2, 1, 0, 1, 2, 3], [5, 4, 3, 2, 1, 2, 3, 4]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0]]) == [[2, 1, 2, 1, 2, 3], [1, 0, 1, 0, 1, 2], [2, 1, 2, 1, 2, 3], [1, 0, 1, 0, 1, 2], [2, 1, 2, 1, 2, 3]]\n assert candidate(isWater = [[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, 1, 2, 3, 4], [1, 2, 3, 4, 3], [2, 3, 4, 3, 2], [3, 4, 3, 2, 1], [4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 3, 2, 3], [3, 2, 1, 2, 1, 2], [2, 1, 0, 1, 0, 1], [3, 2, 1, 2, 1, 2], [4, 3, 2, 3, 2, 3], [5, 4, 3, 4, 3, 4]]\n assert candidate(isWater = [[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, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]) == [[4, 3, 2, 3, 4, 3, 2, 3, 4, 5], [3, 2, 1, 2, 3, 2, 1, 2, 3, 4], [2, 1, 0, 1, 2, 1, 0, 1, 2, 3], [3, 2, 1, 2, 3, 2, 1, 2, 3, 4], [3, 2, 1, 2, 3, 2, 1, 2, 3, 4], [2, 1, 0, 1, 2, 1, 0, 1, 2, 3], [3, 2, 1, 2, 3, 2, 1, 2, 3, 4], [4, 3, 2, 3, 2, 3, 2, 3, 4, 5], [5, 4, 3, 2, 1, 2, 3, 4, 5, 6], [4, 3, 2, 1, 0, 1, 2, 3, 4, 5]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 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]]) == [[6, 5, 4, 3, 4, 5, 4, 3, 4, 5], [5, 4, 3, 2, 3, 4, 3, 2, 3, 4], [4, 3, 2, 1, 2, 3, 2, 1, 2, 3], [3, 2, 1, 0, 1, 2, 1, 0, 1, 2], [4, 3, 2, 1, 2, 3, 2, 1, 2, 3], [4, 3, 2, 1, 2, 3, 2, 1, 2, 3], [3, 2, 1, 0, 1, 2, 1, 0, 1, 2], [4, 3, 2, 1, 2, 3, 2, 1, 2, 3]]\n assert candidate(isWater = [[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]]) == [[0, 1, 2, 3, 4, 4], [1, 2, 3, 4, 4, 3], [2, 3, 4, 4, 3, 2], [3, 4, 4, 3, 2, 1], [4, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[0, 0, 0, 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, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == [[6, 5, 4, 3, 3, 4, 5, 6], [5, 4, 3, 2, 2, 3, 4, 5], [4, 3, 2, 1, 1, 2, 3, 4], [3, 2, 1, 0, 0, 1, 2, 3], [3, 2, 1, 0, 0, 1, 2, 3], [4, 3, 2, 1, 1, 2, 3, 4], [5, 4, 3, 2, 2, 3, 4, 5]]\n assert candidate(isWater = [[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, 1, 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, 1, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [8, 7, 6, 5, 4, 3, 2, 1, 0, 1], [7, 6, 5, 4, 3, 2, 1, 0, 1, 2], [6, 5, 4, 3, 2, 1, 0, 1, 2, 3], [5, 4, 3, 2, 1, 0, 1, 2, 3, 4], [4, 3, 2, 1, 0, 1, 2, 3, 4, 5], [3, 2, 1, 0, 1, 2, 3, 4, 5, 6], [2, 1, 0, 1, 2, 3, 4, 5, 6, 7], [1, 0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n assert candidate(isWater = [[1, 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, 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, 2, 3, 2, 3, 4], [1, 2, 1, 2, 1, 2, 3], [2, 1, 0, 1, 0, 1, 2], [3, 2, 1, 0, 1, 2, 3], [2, 1, 0, 1, 0, 1, 2], [3, 2, 1, 2, 1, 2, 1], [4, 3, 2, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 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, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 3, 4, 5, 6, 7], [2, 3, 4, 3, 2, 3, 4, 5, 6], [3, 4, 3, 2, 1, 2, 3, 4, 5], [4, 3, 2, 1, 0, 1, 2, 3, 4], [5, 4, 3, 2, 1, 2, 3, 4, 3], [6, 5, 4, 3, 2, 3, 4, 3, 2], [7, 6, 5, 4, 3, 4, 3, 2, 1], [8, 7, 6, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 1]]) == [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 4], [2, 3, 4, 5, 4, 3], [3, 4, 5, 4, 3, 2], [4, 5, 4, 3, 2, 1], [5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 1, 2, 3, 4, 5, 4], [1, 2, 3, 4, 5, 4, 3], [2, 3, 4, 5, 4, 3, 2], [3, 4, 5, 4, 3, 2, 1], [4, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0]]) == [[2, 1, 0, 1, 2, 2], [1, 2, 1, 2, 2, 1], [0, 1, 2, 2, 1, 0], [1, 2, 1, 2, 2, 1], [2, 1, 0, 1, 2, 2]]\n assert candidate(isWater = [[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]]) == [[6, 5, 4, 3, 4, 5], [5, 4, 3, 2, 3, 4], [4, 3, 2, 1, 2, 3], [3, 2, 1, 0, 1, 2], [4, 3, 2, 1, 2, 3], [5, 4, 3, 2, 3, 4]]\n assert candidate(isWater = [[0, 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, 0, 0, 0, 0, 0]]) == [[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(isWater = [[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, 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]]) == [[5, 4, 3, 2, 1, 0, 1, 2, 3, 4], [5, 4, 3, 2, 2, 1, 2, 3, 4, 5], [4, 3, 2, 1, 2, 2, 3, 4, 5, 4], [3, 2, 1, 0, 1, 2, 3, 4, 4, 3], [4, 3, 2, 1, 2, 3, 4, 4, 3, 2], [5, 4, 3, 2, 3, 4, 4, 3, 2, 1], [6, 5, 4, 3, 4, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 3, 4, 5], [3, 2, 1, 2, 3, 4], [2, 1, 0, 1, 2, 3], [3, 2, 1, 2, 3, 4], [4, 3, 2, 3, 4, 5]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 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]]) == [[6, 5, 4, 3, 4, 5, 6, 7, 8], [5, 4, 3, 2, 3, 4, 5, 6, 7], [4, 3, 2, 1, 2, 3, 4, 5, 6], [3, 2, 1, 0, 1, 2, 3, 4, 5], [4, 3, 2, 1, 2, 3, 4, 5, 6], [5, 4, 3, 2, 3, 4, 5, 6, 7], [6, 5, 4, 3, 4, 5, 6, 7, 8], [7, 6, 5, 4, 5, 6, 7, 8, 9], [8, 7, 6, 5, 6, 7, 8, 9, 10]]\n assert candidate(isWater = [[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, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2], [18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3], [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5], [21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6], [22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7], [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8], [24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9], [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], [26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11], [27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12], [28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13], [29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14], [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]]\n assert candidate(isWater = [[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]]) == [[2, 1, 2, 3, 4], [1, 0, 1, 2, 3], [2, 1, 2, 1, 2], [3, 2, 1, 0, 1], [4, 3, 2, 1, 2]]\n assert candidate(isWater = [[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]]) == [[0, 1, 2, 3, 4, 4, 3, 2, 1, 0], [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, 7, 6, 5, 4, 3], [3, 4, 5, 6, 7, 7, 6, 5, 4, 3], [2, 3, 4, 5, 6, 6, 5, 4, 3, 2], [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 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, 0]]) == [[2, 1, 2, 3, 3, 2, 1, 2], [1, 0, 1, 2, 2, 1, 0, 1], [2, 1, 2, 3, 3, 2, 1, 2], [3, 2, 3, 4, 4, 3, 2, 3], [2, 1, 2, 3, 3, 2, 1, 2], [1, 0, 1, 2, 2, 1, 0, 1], [2, 1, 2, 3, 3, 2, 1, 2], [3, 2, 3, 4, 4, 3, 2, 3]]\n assert candidate(isWater = [[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]]) == [[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]]\n assert candidate(isWater = [[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]]) == [[5, 4, 3, 4, 5], [4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3]]\n assert candidate(isWater = [[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]]) == [[3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4], [5, 4, 3, 4, 5]]\n assert candidate(isWater = [[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, 1, 2, 3, 3, 2, 1, 0], [1, 2, 3, 4, 4, 3, 2, 1], [2, 3, 4, 5, 5, 4, 3, 2], [3, 4, 5, 6, 6, 5, 4, 3], [3, 4, 5, 6, 6, 5, 4, 3], [2, 3, 4, 5, 5, 4, 3, 2], [1, 2, 3, 4, 4, 3, 2, 1], [0, 1, 2, 3, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 6], [2, 3, 4, 5, 6, 7, 6, 5], [3, 4, 5, 6, 7, 6, 5, 4], [4, 5, 6, 7, 6, 5, 4, 3], [5, 6, 7, 6, 5, 4, 3, 2], [6, 7, 6, 5, 4, 3, 2, 1], [7, 6, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[2, 1, 1, 1, 1, 2], [1, 0, 0, 0, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1], [2, 1, 1, 1, 1, 2]]\n assert candidate(isWater = [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]) == [[0, 1, 2, 1, 0], [1, 2, 3, 2, 1], [1, 2, 3, 2, 1], [0, 1, 2, 1, 0]]\n assert candidate(isWater = [[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, 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]]) == [[6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7], [6, 5, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8], [5, 4, 3, 4, 5, 4, 3, 4, 5, 6, 7, 8, 9], [4, 3, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 10], [3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [5, 4, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [6, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]\n assert candidate(isWater = [[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]]) == [[6, 5, 4, 3, 2, 1, 0], [7, 6, 5, 4, 3, 2, 1], [8, 7, 6, 5, 4, 3, 2], [9, 8, 7, 6, 5, 4, 3], [10, 9, 8, 7, 6, 5, 4], [11, 10, 9, 8, 7, 6, 5]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) == [[4, 3, 2, 2, 3, 4], [3, 2, 1, 1, 2, 3], [2, 1, 0, 0, 1, 2], [2, 1, 0, 0, 1, 2], [3, 2, 1, 1, 2, 3], [4, 3, 2, 2, 3, 4]]\n assert candidate(isWater = [[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]]) == [[6, 5, 4, 3, 4, 5, 6], [5, 4, 3, 2, 3, 4, 5], [4, 3, 2, 1, 2, 3, 4], [3, 2, 1, 0, 1, 2, 3], [4, 3, 2, 1, 2, 3, 4], [5, 4, 3, 2, 3, 4, 5]]\n assert candidate(isWater = [[1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1]]) == [[0, 1, 0, 1, 0, 1, 0], [1, 2, 1, 2, 1, 2, 1], [0, 1, 0, 1, 0, 1, 0], [1, 2, 1, 2, 1, 2, 1], [0, 1, 0, 1, 0, 1, 0]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 1, 0, 1], [3, 2, 3, 2, 1, 2], [2, 1, 2, 3, 2, 3], [1, 0, 1, 2, 3, 4], [2, 1, 2, 3, 4, 5]]\n assert candidate(isWater = [[0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0]]) == [[4, 3, 2, 1, 0, 1], [3, 2, 1, 0, 1, 2], [2, 1, 0, 1, 0, 1], [1, 0, 1, 2, 1, 0], [0, 1, 0, 1, 2, 1], [1, 2, 1, 0, 1, 2]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0]]) == [[6, 5, 4, 3, 3, 3, 4, 5, 6], [5, 4, 3, 2, 2, 2, 3, 4, 5], [4, 3, 2, 1, 1, 1, 2, 3, 4], [3, 2, 1, 0, 0, 0, 1, 2, 3], [3, 2, 1, 0, 0, 0, 1, 2, 3], [3, 2, 1, 0, 0, 0, 1, 2, 3], [4, 3, 2, 1, 1, 1, 2, 3, 4], [5, 4, 3, 2, 2, 2, 3, 4, 5], [6, 5, 4, 3, 3, 3, 4, 5, 6]]\n assert candidate(isWater = [[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, 1, 2, 3, 4, 4, 3, 2, 1, 0], [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, 7, 6, 5, 4, 3], [4, 5, 6, 7, 8, 8, 7, 6, 5, 4], [4, 5, 6, 7, 8, 8, 7, 6, 5, 4], [3, 4, 5, 6, 7, 7, 6, 5, 4, 3], [2, 3, 4, 5, 6, 6, 5, 4, 3, 2], [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[3, 2, 3, 2, 3, 4], [2, 1, 2, 1, 2, 3], [1, 0, 1, 0, 1, 2], [2, 1, 2, 1, 2, 3], [3, 2, 3, 2, 3, 4]]\n assert candidate(isWater = [[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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 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, 1]]) == [[0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0], [1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2], [3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3], [4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4], [5, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5], [6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7, 6], [7, 8, 9, 10, 11, 12, 13, 14, 13, 12, 11, 10, 9, 8, 7], [6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7, 6], [5, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5], [4, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5, 4], [3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3], [2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2], [1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1], [0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == [[1, 0, 1, 2, 3, 3, 4], [2, 1, 2, 3, 3, 2, 3], [3, 2, 3, 3, 2, 1, 2], [4, 3, 3, 2, 1, 0, 1], [5, 4, 4, 3, 2, 1, 2], [6, 5, 5, 4, 3, 2, 3]]\n assert candidate(isWater = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 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(isWater = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == [[3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]\n assert candidate(isWater = [[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]) == [[1, 0, 1, 2, 3], [1, 1, 2, 3, 3], [0, 1, 2, 3, 2], [1, 2, 3, 2, 1], [2, 3, 2, 1, 0]]\n assert candidate(isWater = [[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]]) == [[6, 5, 4, 3, 2, 1, 0, 1, 2, 3], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4], [8, 7, 6, 5, 4, 3, 2, 3, 4, 5], [9, 8, 7, 6, 5, 4, 3, 4, 5, 6], [10, 9, 8, 7, 6, 5, 4, 5, 6, 7], [11, 10, 9, 8, 7, 6, 5, 6, 7, 8], [12, 11, 10, 9, 8, 7, 6, 7, 8, 9], [13, 12, 11, 10, 9, 8, 7, 8, 9, 10]]\n assert candidate(isWater = [[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]]) == [[4, 3, 2, 1, 0, 1, 2, 3, 4], [3, 4, 3, 2, 1, 2, 3, 4, 3], [2, 3, 4, 3, 2, 3, 4, 3, 2], [1, 2, 3, 4, 3, 4, 3, 2, 1], [0, 1, 2, 3, 4, 3, 2, 1, 0], [1, 2, 3, 4, 3, 4, 3, 2, 1], [2, 3, 4, 3, 2, 3, 4, 3, 2], [3, 4, 3, 2, 1, 2, 3, 4, 3], [4, 3, 2, 1, 0, 1, 2, 3, 4]]\n assert candidate(isWater = [[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, 1]]) == [[0, 1, 2, 3, 4, 5, 6, 7, 8, 7], [1, 2, 3, 4, 5, 6, 7, 8, 7, 6], [2, 3, 4, 5, 6, 7, 8, 7, 6, 5], [3, 4, 5, 6, 7, 8, 7, 6, 5, 4], [4, 5, 6, 7, 8, 7, 6, 5, 4, 3], [5, 6, 7, 8, 7, 6, 5, 4, 3, 2], [6, 7, 8, 7, 6, 5, 4, 3, 2, 1], [7, 8, 7, 6, 5, 4, 3, 2, 1, 0]]\n assert candidate(isWater = [[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, 1, 2, 1, 0], [1, 2, 3, 2, 1], [2, 3, 4, 3, 2], [1, 2, 3, 2, 1], [0, 1, 2, 1, 0]]\n assert candidate(isWater = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 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, 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, 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, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 9, 8, 7, 6, 5, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 9, 10, 11], [9, 8, 7, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 9, 10], [8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8], [6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8], [6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 9, 10, 11], [11, 10, 9, 8, 7, 6, 5, 6, 7, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11, 12], [12, 11, 10, 9, 8, 7, 6, 7, 8, 9, 8, 7, 6, 7, 8, 9, 10, 11, 12, 13], [13, 12, 11, 10, 9, 8, 7, 8, 9, 10, 9, 8, 7, 8, 9, 10, 11, 12, 13, 14], [14, 13, 12, 11, 10, 9, 8, 9, 10, 11, 10, 9, 8, 9, 10, 11, 12, 13, 14, 15], [15, 14, 13, 12, 11, 10, 9, 10, 11, 12, 11, 10, 9, 10, 11, 12, 13, 14, 15, 16], [16, 15, 14, 13, 12, 11, 10, 11, 12, 13, 12, 11, 10, 11, 12, 13, 14, 15, 16, 17], [17, 16, 15, 14, 13, 12, 11, 12, 13, 14, 13, 12, 11, 12, 13, 14, 15, 16, 17, 18]]\n assert candidate(isWater = [[0, 0, 0, 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]]) == [[6, 5, 4, 3, 4, 5, 6, 7], [5, 4, 3, 2, 3, 4, 5, 6], [4, 3, 2, 1, 2, 3, 4, 5], [3, 2, 1, 0, 1, 2, 3, 4], [4, 3, 2, 1, 2, 3, 4, 5], [5, 4, 3, 2, 3, 4, 5, 6], [6, 5, 4, 3, 4, 5, 6, 7], [7, 6, 5, 4, 5, 6, 7, 8]]\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,0]]", "[[0,0,1],[1,0,0],[0,0,0]]"], "hints": ["Set each water cell to be 0. The height of each cell is limited by its closest water cell.", "Perform a multi-source BFS with all the water cells as sources."], "metadata": {"canonical_parameter_names": ["isWater"], "leetcode_dataset_entry_point": "Solution().highestPeak", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:04+00:00", "tests_total": 68, "tests_dropped": 0, "flags": ["multiple_answers", "has_images"], "topic_tags": ["array", "breadth-first-search", "matrix"]}, "language": "php", "interface": {"raw_signature": "function highestPeak($isWater) {", "container": "Solution", "callable": "highestPeak", "parameters": [{"name": "isWater", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1766, "task_id": "tree-of-coprimes", "difficulty": "Hard", "problem_description": "There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is node 0.\n\nTo represent this tree, you are given an integer array nums and a 2D array edges. Each nums[i] represents the i^th node's value, and each edges[j] = [u_j, v_j] represents an edge between nodes u_j and v_j in the tree.\n\nTwo values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.\n\nAn ancestor of a node i is any other node on the shortest path from node i to the root. A node is not considered an ancestor of itself.\n\nReturn an array ans of size n, where ans[i] is the closest ancestor to node i such that nums[i] and nums[ans[i]] are coprime, or -1 if there is no such ancestor.\n\nExample 1:\n\nInput: nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\nOutput: [-1,0,0,1]\nExplanation: In the above figure, each node's value is in parentheses.\n- Node 0 has no coprime ancestors.\n- Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).\n- Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's\n value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.\n- Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its\n closest valid ancestor.\n\nExample 2:\n\nInput: nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\nOutput: [-1,0,-1,0,0,0,-1]\n\nConstraints:\n\n- nums.length == n\n- 1 <= nums[i] <= 50\n- 1 <= n <= 10^5\n- edges.length == n - 1\n- edges[j].length == 2\n- 0 <= u_j, v_j < n\n- u_j != v_j\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 3, 2],edges = [[0, 1], [1, 2], [1, 3]]) == [-1, 0, 0, 1]\n assert candidate(nums = [5, 6, 10, 2, 3, 6, 15],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == [-1, 0, -1, 0, 0, 0, -1]\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4]\n assert candidate(nums = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4]\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 5, 1, 11],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]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]\n assert candidate(nums = [49, 42, 35, 28, 21, 14, 7, 1, 49, 42],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9]]) == [-1, -1, -1, -1, -1, -1, -1, 3, -1, -1]\n assert candidate(nums = [7, 11, 13, 5, 3, 2, 8, 9, 10, 12],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 4, 2]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],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]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 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],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]]) == [-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, 10, 15, 20, 25, 30, 35, 40, 45, 50],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47],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]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [15, 10, 6, 9, 12, 18, 21, 30, 24, 33],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [41, 37, 43, 47, 29, 31, 37, 41, 43, 47, 29, 31, 37, 41, 43, 47, 29, 31, 37, 41],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]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 1, 2, 5, 6, 6, 7, 7, 8, 8, 9]\n assert candidate(nums = [47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],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]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]\n assert candidate(nums = [47, 37, 41, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],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]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6]\n assert candidate(nums = [2, 3, 5, 2, 3, 5, 2, 3, 5, 2, 3, 5, 2, 3, 5, 2, 3, 5, 2, 3, 5],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]]) == [-1, 0, 0, 1, 0, 0, 2, 3, 3, 4, 0, 0, 5, 6, 6, 7, 3, 3, 8, 9, 9]\n assert candidate(nums = [7, 5, 6, 3, 5, 3, 7, 11, 13, 17],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [5, 8], [6, 9]]) == [-1, 0, 0, 1, 0, 0, 2, 3, 5, 6]\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4]\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [4, 11]]) == [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4]\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [5, 8], [6, 9]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [41, 43, 47, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2],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]]) == [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6]\n", "comparison": "exact"}, "public_tests": ["[2,3,3,2]\n[[0,1],[1,2],[1,3]]", "[5,6,10,2,3,6,15]\n[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]"], "hints": ["Note that for a node, it's not optimal to consider two nodes with the same value.", "Note that the values are small enough for you to iterate over them instead of iterating over the parent nodes."], "metadata": {"canonical_parameter_names": ["nums", "edges"], "leetcode_dataset_entry_point": "Solution().getCoprimes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:06+00:00", "tests_total": 31, "tests_dropped": 8, "flags": ["has_images"], "topic_tags": ["array", "math", "tree", "depth-first-search", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function getCoprimes($nums, $edges) {", "container": "Solution", "callable": "getCoprimes", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1768, "task_id": "merge-strings-alternately", "difficulty": "Easy", "problem_description": "You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.\n\nReturn the merged string.\n\nExample 1:\n\nInput: word1 = \"abc\", word2 = \"pqr\"\nOutput: \"apbqcr\"\nExplanation: The merged string will be merged as so:\nword1: a b c\nword2: p q r\nmerged: a p b q c r\n\nExample 2:\n\nInput: word1 = \"ab\", word2 = \"pqrs\"\nOutput: \"apbqrs\"\nExplanation: Notice that as word2 is longer, \"rs\" is appended to the end.\nword1: a b\nword2: p q r s\nmerged: a p b q r s\n\nExample 3:\n\nInput: word1 = \"abcd\", word2 = \"pq\"\nOutput: \"apbqcd\"\nExplanation: Notice that as word1 is longer, \"cd\" is appended to the end.\nword1: a b c d\nword2: p q\nmerged: a p b q c d\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 100\n- word1 and word2 consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"a\",word2 = \"b\") == \"ab\"\n assert candidate(word1 = \"abcd\",word2 = \"pq\") == \"apbqcd\"\n assert candidate(word1 = \"ab\",word2 = \"pqrs\") == \"apbqrs\"\n assert candidate(word1 = \"x\",word2 = \"y\") == \"xy\"\n assert candidate(word1 = \"hello\",word2 = \"world\") == \"hweolrllod\"\n assert candidate(word1 = \"a\",word2 = \"bcd\") == \"abcd\"\n assert candidate(word1 = \"abcde\",word2 = \"fgh\") == \"afbgchde\"\n assert candidate(word1 = \"abc\",word2 = \"pqr\") == \"apbqcr\"\n assert candidate(word1 = \"abcd\",word2 = \"e\") == \"aebcd\"\n assert candidate(word1 = \"a\",word2 = \"bcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(word1 = \"thisisateststring\",word2 = \"anotheronehere\") == \"tahniostihseartoensethsetrreing\"\n assert candidate(word1 = \"aabbccdd\",word2 = \"eeffgg\") == \"aeaebfbfcgcgdd\"\n assert candidate(word1 = \"complex\",word2 = \"strings\") == \"csotmrpilnegxs\"\n assert candidate(word1 = \"xyz\",word2 = \"abcde\") == \"xaybzcde\"\n assert candidate(word1 = \"abcdefgh\",word2 = \"ijkl\") == \"aibjckdlefgh\"\n assert candidate(word1 = \"abcdefghijk\",word2 = \"lmnopqrstuvwxyz\") == \"albmcndoepfqgrhsitjukvwxyz\"\n assert candidate(word1 = \"abcdefghij\",word2 = \"klmnopqrstuvwxyz\") == \"akblcmdneofpgqhrisjtuvwxyz\"\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxy\",word2 = \"z\") == \"azbcdefghijklmnopqrstuvwxy\"\n assert candidate(word1 = \"quick\",word2 = \"brownfox\") == \"qburiocwknfox\"\n assert candidate(word1 = \"onetwothreefour\",word2 = \"five\") == \"ofnievtewothreefour\"\n assert candidate(word1 = \"overlap\",word2 = \"lapping\") == \"olvaeprplianpg\"\n assert candidate(word1 = \"python\",word2 = \"java\") == \"pjyatvhaon\"\n assert candidate(word1 = \"abcdefgh\",word2 = \"ijklmnopqrstuv\") == \"aibjckdlemfngohpqrstuv\"\n assert candidate(word1 = \"different\",word2 = \"length\") == \"dliefnfgetrhent\"\n assert candidate(word1 = \"abcdefghij\",word2 = \"klmnopqrst\") == \"akblcmdneofpgqhrisjt\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"zyxwzyxwzyxw\") == \"azbycxdwazbycxdwazbycxdw\"\n assert candidate(word1 = \"longerfirstword\",word2 = \"short\") == \"lsohnogretrfirstword\"\n assert candidate(word1 = \"abcdefg\",word2 = \"hijklmnop\") == \"ahbicjdkelfmgnop\"\n assert candidate(word1 = \"abcdef\",word2 = \"ghijklmnopqrstuvwxyz\") == \"agbhcidjekflmnopqrstuvwxyz\"\n assert candidate(word1 = \"xyz\",word2 = \"abcdefg\") == \"xaybzcdefg\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"efghefghefghefgh\") == \"aebfcgdhaebfcgdhaebfcgdhefgh\"\n assert candidate(word1 = \"short\",word2 = \"longersecondword\") == \"slhoonrgtersecondword\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"gggghhhhiiii\") == \"agagbgbgchchdhdheieififi\"\n assert candidate(word1 = \"oddlength\",word2 = \"evenlengths\") == \"oedvdelnelnegntghths\"\n assert candidate(word1 = \"same\",word2 = \"size\") == \"ssaimzee\"\n assert candidate(word1 = \"abcdefg\",word2 = \"hijklmnopqrstuvwxyz\") == \"ahbicjdkelfmgnopqrstuvwxyz\"\n assert candidate(word1 = \"aabbccddeeffgghhiijj\",word2 = \"kkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"akakblblcmcmdndneoeofpfpgqgqhrhrisisjtjtuuvvwwxxyyzz\"\n assert candidate(word1 = \"hello\",word2 = \"worldwide\") == \"hweolrllodwide\"\n assert candidate(word1 = \"xyzxyzxyz\",word2 = \"abcabcabc\") == \"xaybzcxaybzcxaybzc\"\n assert candidate(word1 = \"abcdxyz\",word2 = \"efghwvu\") == \"aebfcgdhxwyvzu\"\n assert candidate(word1 = \"short\",word2 = \"averylongstring\") == \"sahvoerrtylongstring\"\n assert candidate(word1 = \"hello\",word2 = \"worldthisisaverylongstring\") == \"hweolrllodthisisaverylongstring\"\n assert candidate(word1 = \"abcdefg\",word2 = \"hijkl\") == \"ahbicjdkelfg\"\n assert candidate(word1 = \"abcdef\",word2 = \"ghijklmnop\") == \"agbhcidjekflmnop\"\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"xyzxyzxyzxyz\") == \"axbyczdxaybzcxdyazbxcydz\"\n assert candidate(word1 = \"averyveryverylongword\",word2 = \"short\") == \"asvheorrytveryverylongword\"\n assert candidate(word1 = \"longerword\",word2 = \"short\") == \"lsohnogretrword\"\n assert candidate(word1 = \"longstringwithmorecharacters\",word2 = \"shortstr\") == \"lsohnogrsttsrtirngwithmorecharacters\"\n assert candidate(word1 = \"abcdef\",word2 = \"zyxwvu\") == \"azbycxdwevfu\"\n assert candidate(word1 = \"xyz\",word2 = \"uvw\") == \"xuyvzw\"\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"zzzzyyyxxww\") == \"azazbzbzcycydydxexewfwf\"\n assert candidate(word1 = \"abcdefgh\",word2 = \"ijklmnop\") == \"aibjckdlemfngohp\"\n assert candidate(word1 = \"onetwothree\",word2 = \"four\") == \"ofnoeutrwothree\"\n assert candidate(word1 = \"aabbcc\",word2 = \"ddeeff\") == \"adadbebecfcf\"\n assert candidate(word1 = \"aabbccddeeffgghhiijj\",word2 = \"zzzzzzzzzz\") == \"azazbzbzczczdzdzezezffgghhiijj\"\n assert candidate(word1 = \"abacaxi\",word2 = \"manga\") == \"ambaancgaaxi\"\n assert candidate(word1 = \"onetwothreefour\",word2 = \"fivesix\") == \"ofnievtewsoitxhreefour\"\n assert candidate(word1 = \"one\",word2 = \"twothreefour\") == \"otnweothreefour\"\n assert candidate(word1 = \"xyz\",word2 = \"wvutsrqponmlkjihgfedcba\") == \"xwyvzutsrqponmlkjihgfedcba\"\n assert candidate(word1 = \"short\",word2 = \"averyverylongwordindeed\") == \"sahvoerrtyverylongwordindeed\"\n assert candidate(word1 = \"xy\",word2 = \"abcdefghijk\") == \"xaybcdefghijk\"\n assert candidate(word1 = \"onetwothree\",word2 = \"fourfivesix\") == \"ofnoeutrwfoitvherseiex\"\n assert candidate(word1 = \"python\",word2 = \"programming\") == \"ppyrtohgornamming\"\n assert candidate(word1 = \"verylongwordthatgoesonandone\",word2 = \"short\") == \"vsehroyrltongwordthatgoesonandone\"\n assert candidate(word1 = \"xyz\",word2 = \"abcdef\") == \"xaybzcdef\"\n assert candidate(word1 = \"merge\",word2 = \"these\") == \"mtehregsee\"\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"z\") == \"azbcdefghijklmnopqrstuvwxyz\"\n assert candidate(word1 = \"xyzlmnop\",word2 = \"qrstuvwx\") == \"xqyrzsltmunvowpx\"\n assert candidate(word1 = \"abcdefgh\",word2 = \"ijklmno\") == \"aibjckdlemfngoh\"\n assert candidate(word1 = \"short\",word2 = \"averyveryverylongword\") == \"sahvoerrtyveryverylongword\"\n assert candidate(word1 = \"averyverylongwordindeed\",word2 = \"short\") == \"asvheorrytverylongwordindeed\"\n assert candidate(word1 = \"equal\",word2 = \"equal\") == \"eeqquuaall\"\n assert candidate(word1 = \"ab\",word2 = \"cd\") == \"acbd\"\n assert candidate(word1 = \"short\",word2 = \"averylongstringthatweneedtocheck\") == \"sahvoerrtylongstringthatweneedtocheck\"\n assert candidate(word1 = \"same\",word2 = \"same\") == \"ssaammee\"\n assert candidate(word1 = \"thisisaverylongstring\",word2 = \"hello\") == \"thheilsliosaverylongstring\"\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n\"pqr\"", "\"ab\"\n\"pqrs\"", "\"abcd\"\n\"pq\""], "hints": ["Use two pointers, one pointer for each string. Alternately choose the character from each pointer, and move the pointer upwards."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().mergeAlternately", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:09+00:00", "tests_total": 92, "tests_dropped": 16, "flags": [], "topic_tags": ["two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function mergeAlternately($word1, $word2) {", "container": "Solution", "callable": "mergeAlternately", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1769, "task_id": "minimum-number-of-operations-to-move-all-balls-to-each-box", "difficulty": "Medium", "problem_description": "You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the i^th box is empty, and '1' if it contains one ball.\n\nIn one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.\n\nReturn an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the i^th box.\n\nEach answer[i] is calculated considering the initial state of the boxes.\n\nExample 1:\n\nInput: boxes = \"110\"\nOutput: [1,1,3]\nExplanation: The answer for each box is as follows:\n1) First box: you will have to move one ball from the second box to the first box in one operation.\n2) Second box: you will have to move one ball from the first box to the second box in one operation.\n3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.\n\nExample 2:\n\nInput: boxes = \"001011\"\nOutput: [11,8,5,4,3,4]\n\nConstraints:\n\n- n == boxes.length\n- 1 <= n <= 2000\n- boxes[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(boxes = \"0101010101\") == [25, 20, 17, 14, 13, 12, 13, 14, 17, 20]\n assert candidate(boxes = \"001011\") == [11, 8, 5, 4, 3, 4]\n assert candidate(boxes = \"000111000\") == [12, 9, 6, 3, 2, 3, 6, 9, 12]\n assert candidate(boxes = \"111000\") == [3, 2, 3, 6, 9, 12]\n assert candidate(boxes = \"01010101\") == [16, 12, 10, 8, 8, 8, 10, 12]\n assert candidate(boxes = \"1000000001\") == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(boxes = \"1010101010\") == [20, 17, 14, 13, 12, 13, 14, 17, 20, 25]\n assert candidate(boxes = \"1001001001001\") == [30, 27, 24, 21, 20, 19, 18, 19, 20, 21, 24, 27, 30]\n assert candidate(boxes = \"101010\") == [6, 5, 4, 5, 6, 9]\n assert candidate(boxes = \"1001001\") == [9, 8, 7, 6, 7, 8, 9]\n assert candidate(boxes = \"010101010101\") == [36, 30, 26, 22, 20, 18, 18, 18, 20, 22, 26, 30]\n assert candidate(boxes = \"11111\") == [10, 7, 6, 7, 10]\n assert candidate(boxes = \"1111\") == [6, 4, 4, 6]\n assert candidate(boxes = \"111100001111\") == [44, 38, 34, 32, 32, 32, 32, 32, 32, 34, 38, 44]\n assert candidate(boxes = \"111000111\") == [24, 20, 18, 18, 18, 18, 18, 20, 24]\n assert candidate(boxes = \"0000\") == [0, 0, 0, 0]\n assert candidate(boxes = \"1111111111\") == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(boxes = \"110\") == [1, 1, 3]\n assert candidate(boxes = \"00000\") == [0, 0, 0, 0, 0]\n assert candidate(boxes = \"1000001\") == [6, 6, 6, 6, 6, 6, 6]\n assert candidate(boxes = \"000111\") == [12, 9, 6, 3, 2, 3]\n assert candidate(boxes = \"0000011111000001111100000\") == [120, 110, 100, 90, 80, 70, 62, 56, 52, 50, 50, 50, 50, 50, 50, 50, 52, 56, 62, 70, 80, 90, 100, 110, 120]\n assert candidate(boxes = \"000000111111000000111111\") == [174, 162, 150, 138, 126, 114, 102, 92, 84, 78, 74, 72, 72, 72, 72, 72, 72, 72, 72, 74, 78, 84, 92, 102]\n assert candidate(boxes = \"0101010101010101010101010101\") == [196, 182, 170, 158, 148, 138, 130, 122, 116, 110, 106, 102, 100, 98, 98, 98, 100, 102, 106, 110, 116, 122, 130, 138, 148, 158, 170, 182]\n assert candidate(boxes = \"0101010101010101010101010101010101010101010101010101\") == [676, 650, 626, 602, 580, 558, 538, 518, 500, 482, 466, 450, 436, 422, 410, 398, 388, 378, 370, 362, 356, 350, 346, 342, 340, 338, 338, 338, 340, 342, 346, 350, 356, 362, 370, 378, 388, 398, 410, 422, 436, 450, 466, 482, 500, 518, 538, 558, 580, 602, 626, 650]\n assert candidate(boxes = \"01010101010101010101010101010101010101010101010101\") == [625, 600, 577, 554, 533, 512, 493, 474, 457, 440, 425, 410, 397, 384, 373, 362, 353, 344, 337, 330, 325, 320, 317, 314, 313, 312, 313, 314, 317, 320, 325, 330, 337, 344, 353, 362, 373, 384, 397, 410, 425, 440, 457, 474, 493, 512, 533, 554, 577, 600]\n assert candidate(boxes = \"1001001001001001001001001001001001001001001001001001\") == [459, 443, 427, 411, 397, 383, 369, 357, 345, 333, 323, 313, 303, 295, 287, 279, 273, 267, 261, 257, 253, 249, 247, 245, 243, 243, 243, 243, 245, 247, 249, 253, 257, 261, 267, 273, 279, 287, 295, 303, 313, 323, 333, 345, 357, 369, 383, 397, 411, 427, 443, 459]\n assert candidate(boxes = \"1000100010001\") == [24, 22, 20, 18, 16, 16, 16, 16, 16, 18, 20, 22, 24]\n assert candidate(boxes = \"111000111000111000111\") == [120, 110, 102, 96, 90, 84, 78, 74, 72, 72, 72, 72, 72, 74, 78, 84, 90, 96, 102, 110, 120]\n assert candidate(boxes = \"1101100110011001\") == [61, 54, 49, 44, 41, 40, 39, 38, 39, 42, 45, 48, 53, 60, 67, 74]\n assert candidate(boxes = \"111101010101010101010101010101010101010101010101\") == [578, 554, 532, 512, 494, 476, 460, 444, 430, 416, 404, 392, 382, 372, 364, 356, 350, 344, 340, 336, 334, 332, 332, 332, 334, 336, 340, 344, 350, 356, 364, 372, 382, 392, 404, 416, 430, 444, 460, 476, 494, 512, 532, 552, 574, 596, 620, 644]\n assert candidate(boxes = \"00001111110000\") == [39, 33, 27, 21, 15, 11, 9, 9, 11, 15, 21, 27, 33, 39]\n assert candidate(boxes = \"0000000000000000000000000000000000000000000000001\") == [48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(boxes = \"111000111000111\") == [63, 56, 51, 48, 45, 42, 39, 38, 39, 42, 45, 48, 51, 56, 63]\n assert candidate(boxes = \"00000000000000000000000100000000000000000000000\") == [23, 22, 21, 20, 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, 18, 19, 20, 21, 22, 23]\n assert candidate(boxes = \"0001000100010001000100010001\") == [105, 98, 91, 84, 79, 74, 69, 64, 61, 58, 55, 52, 51, 50, 49, 48, 49, 50, 51, 52, 55, 58, 61, 64, 69, 74, 79, 84]\n assert candidate(boxes = \"100000000000000000000000000000000000000000000000001\") == [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]\n assert candidate(boxes = \"0000000000000000000000000000000000000000000000000001\") == [51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(boxes = \"10101010101010101010101010101010101010101010\") == [462, 442, 422, 404, 386, 370, 354, 340, 326, 314, 302, 292, 282, 274, 266, 260, 254, 250, 246, 244, 242, 242, 242, 244, 246, 250, 254, 260, 266, 274, 282, 292, 302, 314, 326, 340, 354, 370, 386, 404, 422, 442, 462, 484]\n assert candidate(boxes = \"000010001000100010001\") == [60, 55, 50, 45, 40, 37, 34, 31, 28, 27, 26, 25, 24, 25, 26, 27, 28, 31, 34, 37, 40]\n assert candidate(boxes = \"00101010101010101010101010101\") == [210, 196, 182, 170, 158, 148, 138, 130, 122, 116, 110, 106, 102, 100, 98, 98, 98, 100, 102, 106, 110, 116, 122, 130, 138, 148, 158, 170, 182]\n assert candidate(boxes = \"011100000111000001110000011100000\") == [168, 156, 146, 138, 132, 126, 120, 114, 108, 102, 98, 96, 96, 96, 96, 96, 96, 96, 98, 102, 108, 114, 120, 126, 132, 138, 146, 156, 168, 180, 192, 204, 216]\n assert candidate(boxes = \"110001100011000\") == [33, 29, 27, 25, 23, 21, 21, 23, 25, 27, 29, 33, 39, 45, 51]\n assert candidate(boxes = \"10101010101010101010\") == [90, 82, 74, 68, 62, 58, 54, 52, 50, 50, 50, 52, 54, 58, 62, 68, 74, 82, 90, 100]\n assert candidate(boxes = \"010010001000010000010000001000000000\") == [71, 65, 61, 57, 53, 51, 49, 47, 45, 45, 45, 45, 45, 45, 47, 49, 51, 53, 55, 57, 61, 65, 69, 73, 77, 81, 85, 91, 97, 103, 109, 115, 121, 127, 133, 139]\n assert candidate(boxes = \"11100000000111100000001111\") == [147, 138, 131, 126, 121, 116, 111, 106, 101, 96, 91, 86, 83, 82, 83, 86, 89, 92, 95, 98, 101, 104, 107, 112, 119, 128]\n assert candidate(boxes = \"0010001000100010001\") == [50, 45, 40, 37, 34, 31, 28, 27, 26, 25, 24, 25, 26, 27, 28, 31, 34, 37, 40]\n assert candidate(boxes = \"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\") == [112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112]\n assert candidate(boxes = \"1010101010101010101010101\") == [156, 145, 134, 125, 116, 109, 102, 97, 92, 89, 86, 85, 84, 85, 86, 89, 92, 97, 102, 109, 116, 125, 134, 145, 156]\n assert candidate(boxes = \"111100000011110000001111\") == [138, 128, 120, 114, 110, 106, 102, 98, 94, 90, 86, 84, 84, 86, 90, 94, 98, 102, 106, 110, 114, 120, 128, 138]\n assert candidate(boxes = \"1010101010101010101010101010101010101010\") == [380, 362, 344, 328, 312, 298, 284, 272, 260, 250, 240, 232, 224, 218, 212, 208, 204, 202, 200, 200, 200, 202, 204, 208, 212, 218, 224, 232, 240, 250, 260, 272, 284, 298, 312, 328, 344, 362, 380, 400]\n assert candidate(boxes = \"101010101010101010101010101010101010101010101010101010101010\") == [870, 842, 814, 788, 762, 738, 714, 692, 670, 650, 630, 612, 594, 578, 562, 548, 534, 522, 510, 500, 490, 482, 474, 468, 462, 458, 454, 452, 450, 450, 450, 452, 454, 458, 462, 468, 474, 482, 490, 500, 510, 522, 534, 548, 562, 578, 594, 612, 630, 650, 670, 692, 714, 738, 762, 788, 814, 842, 870, 900]\n assert candidate(boxes = \"001001001001001001001001001001001001001001001001001001001\") == [551, 532, 513, 496, 479, 462, 447, 432, 417, 404, 391, 378, 367, 356, 345, 336, 327, 318, 311, 304, 297, 292, 287, 282, 279, 276, 273, 272, 271, 270, 271, 272, 273, 276, 279, 282, 287, 292, 297, 304, 311, 318, 327, 336, 345, 356, 367, 378, 391, 404, 417, 432, 447, 462, 479, 496, 513]\n assert candidate(boxes = \"1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101\") == [2552, 2495, 2440, 2385, 2332, 2281, 2230, 2181, 2134, 2087, 2042, 1999, 1956, 1915, 1876, 1837, 1800, 1765, 1730, 1697, 1666, 1635, 1606, 1579, 1552, 1527, 1504, 1481, 1460, 1441, 1422, 1405, 1390, 1375, 1362, 1351, 1340, 1331, 1324, 1317, 1312, 1309, 1306, 1305, 1306, 1307, 1310, 1315, 1320, 1327, 1336, 1345, 1356, 1369, 1382, 1397, 1414, 1431, 1450, 1471, 1492, 1515, 1540, 1565, 1592, 1621, 1650, 1681, 1714, 1747, 1782, 1819, 1856, 1895, 1936, 1977, 2020, 2065, 2110, 2157, 2206, 2255, 2306, 2359, 2412, 2467, 2524, 2581]\n assert candidate(boxes = \"10100101001010010100101001010010\") == [192, 181, 170, 161, 152, 143, 136, 129, 124, 119, 114, 111, 108, 107, 106, 105, 106, 107, 110, 113, 116, 121, 126, 133, 140, 147, 156, 165, 176, 187, 198, 211]\n assert candidate(boxes = \"1001001001001001001001001001\") == [135, 127, 119, 111, 105, 99, 93, 89, 85, 81, 79, 77, 75, 75, 75, 75, 77, 79, 81, 85, 89, 93, 99, 105, 111, 119, 127, 135]\n assert candidate(boxes = \"0001000010000100001\") == [42, 38, 34, 30, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 30]\n assert candidate(boxes = \"0000100000000100000001\") == [38, 35, 32, 29, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 18, 19, 20, 21, 22, 23, 24, 25]\n assert candidate(boxes = \"100000000000000000001\") == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(boxes = \"101001010010100101001010\") == [110, 102, 94, 88, 82, 76, 72, 68, 66, 64, 62, 62, 62, 64, 66, 68, 72, 76, 82, 88, 94, 102, 110, 120]\n assert candidate(boxes = \"1111000011110000111100001111\") == [216, 202, 190, 180, 172, 164, 156, 148, 140, 134, 130, 128, 128, 128, 128, 128, 128, 130, 134, 140, 148, 156, 164, 172, 180, 190, 202, 216]\n assert candidate(boxes = \"110100100100110\") == [44, 39, 36, 33, 32, 31, 30, 31, 32, 33, 36, 39, 42, 47, 54]\n assert candidate(boxes = \"1111111111111111111111111111111111111111111111111111\") == [1326, 1276, 1228, 1182, 1138, 1096, 1056, 1018, 982, 948, 916, 886, 858, 832, 808, 786, 766, 748, 732, 718, 706, 696, 688, 682, 678, 676, 676, 678, 682, 688, 696, 706, 718, 732, 748, 766, 786, 808, 832, 858, 886, 916, 948, 982, 1018, 1056, 1096, 1138, 1182, 1228, 1276, 1326]\n assert candidate(boxes = \"0000000000101010101010101010101010100000000\") == [286, 273, 260, 247, 234, 221, 208, 195, 182, 169, 156, 145, 134, 125, 116, 109, 102, 97, 92, 89, 86, 85, 84, 85, 86, 89, 92, 97, 102, 109, 116, 125, 134, 145, 156, 169, 182, 195, 208, 221, 234, 247, 260]\n assert candidate(boxes = \"10011001100110011001100110011\") == [217, 204, 191, 178, 167, 158, 149, 140, 133, 128, 123, 118, 115, 114, 113, 112, 113, 116, 119, 122, 127, 134, 141, 148, 157, 168, 179, 190, 203]\n assert candidate(boxes = \"11111111100000000111111110000000011111111\") == [492, 469, 448, 429, 412, 397, 384, 373, 364, 357, 350, 343, 336, 329, 322, 315, 308, 301, 296, 293, 292, 293, 296, 301, 308, 317, 326, 335, 344, 353, 362, 371, 380, 389, 400, 413, 428, 445, 464, 485, 508]\n assert candidate(boxes = \"1010101010101010\") == [56, 50, 44, 40, 36, 34, 32, 32, 32, 34, 36, 40, 44, 50, 56, 64]\n assert candidate(boxes = \"0000110000000000110000000000110000000000110000000000110000000000110000000000110000000000\") == [567, 553, 539, 525, 511, 499, 489, 479, 469, 459, 449, 439, 429, 419, 409, 399, 389, 381, 375, 369, 363, 357, 351, 345, 339, 333, 327, 321, 315, 311, 309, 307, 305, 303, 301, 299, 297, 295, 293, 291, 289, 289, 291, 293, 295, 297, 299, 301, 303, 305, 307, 309, 311, 315, 321, 327, 333, 339, 345, 351, 357, 363, 369, 375, 381, 389, 399, 409, 419, 429, 439, 449, 459, 469, 479, 489, 499, 511, 525, 539, 553, 567, 581, 595, 609, 623, 637, 651]\n assert candidate(boxes = \"00000000000111111111100000000000\") == [155, 145, 135, 125, 115, 105, 95, 85, 75, 65, 55, 45, 37, 31, 27, 25, 25, 27, 31, 37, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]\n assert candidate(boxes = \"01001010010100101001010010100101001010010100101001\") == [500, 480, 462, 444, 426, 410, 394, 380, 366, 352, 340, 328, 318, 308, 298, 290, 282, 276, 270, 264, 260, 256, 254, 252, 250, 250, 250, 252, 254, 256, 260, 264, 270, 276, 282, 290, 298, 308, 318, 328, 340, 352, 366, 380, 394, 410, 426, 444, 462, 480]\n assert candidate(boxes = \"101010101010101010101010\") == [132, 122, 112, 104, 96, 90, 84, 80, 76, 74, 72, 72, 72, 74, 76, 80, 84, 90, 96, 104, 112, 122, 132, 144]\n assert candidate(boxes = \"11110000111100001111000011110000111100001111000011110000\") == [714, 688, 664, 642, 622, 602, 582, 562, 542, 524, 508, 494, 482, 470, 458, 446, 434, 424, 416, 410, 406, 402, 398, 394, 390, 388, 388, 390, 394, 398, 402, 406, 410, 416, 424, 434, 446, 458, 470, 482, 494, 508, 524, 542, 562, 582, 602, 622, 642, 664, 688, 714, 742, 770, 798, 826]\n assert candidate(boxes = \"10000000001000000000100000000010000000001\") == [100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100]\n assert candidate(boxes = \"0000011111100000\") == [45, 39, 33, 27, 21, 15, 11, 9, 9, 11, 15, 21, 27, 33, 39, 45]\n assert candidate(boxes = \"11100000000000000000000000000000000000001\") == [43, 41, 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]\n assert candidate(boxes = \"110011001100110011001100110011001100\") == [297, 281, 267, 253, 239, 227, 217, 207, 197, 189, 183, 177, 171, 167, 165, 163, 161, 161, 163, 165, 167, 171, 177, 183, 189, 197, 207, 217, 227, 239, 253, 267, 281, 297, 315, 333]\n assert candidate(boxes = \"01010101010101010101010101010101\") == [256, 240, 226, 212, 200, 188, 178, 168, 160, 152, 146, 140, 136, 132, 130, 128, 128, 128, 130, 132, 136, 140, 146, 152, 160, 168, 178, 188, 200, 212, 226, 240]\n assert candidate(boxes = \"11111111111111111111111111111111\") == [496, 466, 438, 412, 388, 366, 346, 328, 312, 298, 286, 276, 268, 262, 258, 256, 256, 258, 262, 268, 276, 286, 298, 312, 328, 346, 366, 388, 412, 438, 466, 496]\n assert candidate(boxes = \"111111111111111111111111111111111111111111111111\") == [1128, 1082, 1038, 996, 956, 918, 882, 848, 816, 786, 758, 732, 708, 686, 666, 648, 632, 618, 606, 596, 588, 582, 578, 576, 576, 578, 582, 588, 596, 606, 618, 632, 648, 666, 686, 708, 732, 758, 786, 816, 848, 882, 918, 956, 996, 1038, 1082, 1128]\n assert candidate(boxes = \"10000001000001\") == [20, 19, 18, 17, 16, 15, 14, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(boxes = \"00000000000000000000000000000000000000000000000000000000000000000000000000000001\") == [79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(boxes = \"10000000000000000000000000000001\") == [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, 31]\n assert candidate(boxes = \"1000010000100001000010000100001\") == [105, 100, 95, 90, 85, 80, 77, 74, 71, 68, 65, 64, 63, 62, 61, 60, 61, 62, 63, 64, 65, 68, 71, 74, 77, 80, 85, 90, 95, 100, 105]\n assert candidate(boxes = \"111000111000111000111000111000111000\") == [288, 272, 258, 246, 234, 222, 210, 200, 192, 186, 180, 174, 168, 164, 162, 162, 162, 162, 162, 164, 168, 174, 180, 186, 192, 200, 210, 222, 234, 246, 258, 272, 288, 306, 324, 342]\n assert candidate(boxes = \"00000000000000000001111111111111111111\") == [532, 513, 494, 475, 456, 437, 418, 399, 380, 361, 342, 323, 304, 285, 266, 247, 228, 209, 190, 171, 154, 139, 126, 115, 106, 99, 94, 91, 90, 91, 94, 99, 106, 115, 126, 139, 154, 171]\n", "comparison": "exact"}, "public_tests": ["\"110\"", "\"001011\""], "hints": ["If you want to move a ball from box i to box j, you'll need abs(i-j) moves.", "To move all balls to some box, you can move them one by one.", "For each box i, iterate on each ball in a box j, and add abs(i-j) to answers[i]."], "metadata": {"canonical_parameter_names": ["boxes"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:11+00:00", "tests_total": 85, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minOperations($boxes) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "boxes", "type": "String"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1770, "task_id": "maximum-score-from-performing-multiplication-operations", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m.\n\nYou begin with a score of 0. You want to perform exactly m operations. On the i^th operation (0-indexed) you will:\n\n- Choose one integer x from either the start or the end of the array nums.\n- Add multipliers[i] * x to your score.\n - Note that multipliers[0] corresponds to the first operation, multipliers[1] to the second operation, and so on.\n- Remove x from nums.\n\nReturn the maximum score after performing m operations.\n\nExample 1:\n\nInput: nums = [1,2,3], multipliers = [3,2,1]\nOutput: 14\nExplanation: An optimal solution is as follows:\n- Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.\n- Choose from the end, [1,2], adding 2 * 2 = 4 to the score.\n- Choose from the end, [1], adding 1 * 1 = 1 to the score.\nThe total score is 9 + 4 + 1 = 14.\n\nExample 2:\n\nInput: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\nOutput: 102\nExplanation: An optimal solution is as follows:\n- Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.\n- Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.\n- Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.\n- Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.\n- Choose from the end, [-2,7], adding 7 * 6 = 42 to the score.\nThe total score is 50 + 15 - 9 + 4 + 42 = 102.\n\nConstraints:\n\n- n == nums.length\n- m == multipliers.length\n- 1 <= m <= 300\n- m <= n <= 10^5\n- -1000 <= nums[i], multipliers[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],multipliers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 385\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],multipliers = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 385\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],multipliers = [10, 9, 8, 7, 6]) == 330\n assert candidate(nums = [-1, -2, -3, -4, -5, -6],multipliers = [-1, -2, -3, -4, -5, -6]) == 91\n assert candidate(nums = [-3, -2, -1, 1, 2, 3],multipliers = [1, -1, 1, -1, 1, -1]) == 12\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],multipliers = [1, 2, 3, 4, 5]) == 101\n assert candidate(nums = [100, 200, 300],multipliers = [1, 2]) == 700\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],multipliers = [9, 8, 7]) == 194\n assert candidate(nums = [5, -2, 5, -3, 5, 5],multipliers = [-1, 1, -1, 1, -1, 1]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],multipliers = [1, 2, 3, 4]) == 80\n assert candidate(nums = [-5, -3, -3, -2, 7, 1],multipliers = [-10, -5, 3, 4, 6]) == 102\n assert candidate(nums = [1],multipliers = [1]) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5],multipliers = [-1, -2, -3]) == 23\n assert candidate(nums = [-1, -2, -3, -4, -5],multipliers = [1, 2, 3, 4, 5]) == -35\n assert candidate(nums = [10, 20, 30, 40, 50],multipliers = [5, 4, 3, 2, 1]) == 550\n assert candidate(nums = [10, 20, 30, 40, 50],multipliers = [1, 2, 3, 4, 5]) == 550\n assert candidate(nums = [1, 2, 3, 4, 5, 6],multipliers = [1, 2, 3]) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],multipliers = [1, 2, 3, 4]) == 71\n assert candidate(nums = [1, 2, 3],multipliers = [3, 2, 1]) == 14\n assert candidate(nums = [9, 8, 7, 6, 5],multipliers = [-1, -2, -3]) == -37\n assert candidate(nums = [-1, -2, -3, -4, -5],multipliers = [-1, -2, -3, -4, -5]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5],multipliers = [1, 2, 3]) == 23\n assert candidate(nums = [5, 7, 3, 8, 6],multipliers = [3, 2, 4]) == 60\n assert candidate(nums = [5, 3, 8, 4, 9, 2, 7, 1, 6, 0],multipliers = [10, -20, 30, -40, 50]) == 540\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],multipliers = [-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],multipliers = [10, -20, 30, -40, 50]) == 115000\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12],multipliers = [10, 9, 8, 7, 6, 5]) == 105\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 38500\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],multipliers = [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]) == 55250\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [5, 3, 8, 1, 6, 9, 2, 7, 4, 10],multipliers = [-1, 2, -3, 4, -5, 6]) == 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],multipliers = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 75\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],multipliers = [10, -9, 8, -7, 6, -5, 4, -3, 2, -1]) == 205\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],multipliers = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == -5550\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],multipliers = [-1, -2, -3, -4, -5]) == 185\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],multipliers = [-1, 1, -1, 1, -1, 1]) == 6000\n assert candidate(nums = [5, -3, 8, 2, -7, 6, 1, 4, -9, 11],multipliers = [3, -2, 7, 5, -8, 6]) == 234\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],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 21250\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],multipliers = [5, 4, 3, 2, 1]) == -350\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000],multipliers = [10, -20, 30, -40, 50]) == 115000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],multipliers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],multipliers = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == -220\n assert candidate(nums = [-100, -200, -300, 400, 500, 600, -700, 800, -900],multipliers = [10, 20, 30, 40, 50, 60, 70]) == 77000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],multipliers = [-1, -1, -1, -1, -1]) == -5\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],multipliers = [1, 2, 3, 4, 5, 6, 7]) == 52\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500],multipliers = [1, -1, 1, -1, 1, -1]) == 2400\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],multipliers = [1, -1, 1, -1, 1]) == 1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],multipliers = [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, 9, -9, 10, -10],multipliers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 800\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],multipliers = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],multipliers = [1, -1, 1, -1, 1]) == 240\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],multipliers = [5, 10, 15, 20, 25]) == 925\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],multipliers = [29, 27, 25, 23, 21]) == 3165\n assert candidate(nums = [5, 3, 8, 10, 15, 1, 4, 7],multipliers = [10, 20, 30, 40, 50]) == 1500\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],multipliers = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == -30500\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],multipliers = [-1, 2, -3, 4, -5]) == 110\n assert candidate(nums = [5, 2, 1, 4, 3],multipliers = [-1, -2, -3]) == -12\n assert candidate(nums = [500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000, 1000, 900, 800, 700],multipliers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 35400\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],multipliers = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],multipliers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == -22000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 2485\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],multipliers = [10, 20, 30, 40, 50]) == -5000\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],multipliers = [-10, 9, -8, 7, -6, 5, -4, 3, -2, 1]) == 480\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10],multipliers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 85\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],multipliers = [10, 20, 30, 40, 50]) == 2150\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],multipliers = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == -22000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],multipliers = [1, -1, 1, -1, 1, -1, 1]) == 48\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],multipliers = [-5, 10, -15, 20, -25, 30]) == 4625\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 155\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],multipliers = [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, 11, 12, 13, 14, 15],multipliers = [15, 14, 13, 12, 11]) == 855\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50],multipliers = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 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],multipliers = [20, 19, 18, 17, 16, 15, 14]) == 2051\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],multipliers = [1, 2, 3, 4, 5, 6]) == 15300\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700],multipliers = [1, -2, 3, -4, 5]) == 7500\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],multipliers = [1, 2, -3, 4, -5]) == 1030\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],multipliers = [100, -50, 25, -12, 6]) == 9630\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 821\n assert candidate(nums = [-5, -10, -15, -20, -25, -30, -35, -40, -45, -50],multipliers = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 1925\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],multipliers = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 200\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],multipliers = [1, 2, 3, 4, 5]) == 7000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],multipliers = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 700\n assert candidate(nums = [-5, 3, -1, 2, -4, 6, -7, 8, -9, 10],multipliers = [1, -1, 1, -1, 1, -1]) == 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],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 2670\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15],multipliers = [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],multipliers = [1, -1, 2, -2, 3]) == 4700\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],multipliers = [1, 2, 3, 4, 5, 6]) == 161\n assert candidate(nums = [5, 1, 4, 3, 2, 6, 7, 8, 9, 10],multipliers = [10, -10, 20, -20, 30]) == 450\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000],multipliers = [1, -1, 1, -1, 1, -1]) == 4100\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],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 26800\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],multipliers = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [5, 3, 8, -2, 6, 7, -4, 10, 15, -20],multipliers = [1, 2, 3, 4, 5, 6, 7, 8]) == 242\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 75\n assert candidate(nums = [300, -100, 200, -200, 500, -300, 400, -400, 600, -500],multipliers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 61000\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],multipliers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000\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],multipliers = [-30, -29, -28, -27, -26, -25, -24, -23, -22, -21]) == -1320\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [2, -3, 4, -5, 6]) == 211\n assert candidate(nums = [50, 25, 75, 100, -50, -25, -75, -100, 200, 150, 175, 200],multipliers = [10, -5, 2, -1, 3, -2]) == 2750\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],multipliers = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == -220\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],multipliers = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 3850\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],multipliers = [-1, -2, -3, -4, -5]) == -550\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],multipliers = [-1, 1, -1, 1, -1, 1, -1, 1]) == 50\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],multipliers = [5, -5, 4, -4, 3, -3]) == 87\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],multipliers = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == -334\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],multipliers = [100, -100, 100, -100, 100]) == 500000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],multipliers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == -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],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1081\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == -1540\n assert candidate(nums = [5, 3, 8, -2, 6, 7, -4, 10],multipliers = [1, 2, 3, 4, 5]) == 77\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20],multipliers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],multipliers = [1, 2, 3, 4, 5]) == 1850\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980],multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 54666\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],multipliers = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000],multipliers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],multipliers = [-1, -2, -3, -4, -5]) == 1150\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100],multipliers = [1, 2, 3, 4, 5]) == 600\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n[3,2,1]", "[-5,-3,-3,-2,7,1]\n[-10,-5,3,4,6]"], "hints": ["At first glance, the solution seems to be greedy, but if you try to greedily take the largest value from the beginning or the end, this will not be optimal.", "You should try all scenarios but this will be costly.", "Memoizing the pre-visited states while trying all the possible scenarios will reduce the complexity, and hence dp is a perfect choice here."], "metadata": {"canonical_parameter_names": ["nums", "multipliers"], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:13+00:00", "tests_total": 118, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function maximumScore($nums, $multipliers) {", "container": "Solution", "callable": "maximumScore", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "multipliers", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1771, "task_id": "maximize-palindrome-length-from-subsequences", "difficulty": "Hard", "problem_description": "You are given two strings, word1 and word2. You want to construct a string in the following manner:\n\n- Choose some non-empty subsequence subsequence1 from word1.\n- Choose some non-empty subsequence subsequence2 from word2.\n- Concatenate the subsequences: subsequence1 + subsequence2, to make the string.\n\nReturn the length of the longest palindrome that can be constructed in the described manner. If no palindromes can be constructed, return 0.\n\nA subsequence of a string s is a string that can be made by deleting some (possibly none) characters from s without changing the order of the remaining characters.\n\nA palindrome is a string that reads the same forward as well as backward.\n\nExample 1:\n\nInput: word1 = \"cacb\", word2 = \"cbba\"\nOutput: 5\nExplanation: Choose \"ab\" from word1 and \"cba\" from word2 to make \"abcba\", which is a palindrome.\n\nExample 2:\n\nInput: word1 = \"ab\", word2 = \"ab\"\nOutput: 3\nExplanation: Choose \"ab\" from word1 and \"a\" from word2 to make \"aba\", which is a palindrome.\n\nExample 3:\n\nInput: word1 = \"aa\", word2 = \"bb\"\nOutput: 0\nExplanation: You cannot construct a palindrome from the described method, so return 0.\n\nConstraints:\n\n- 1 <= word1.length, word2.length <= 1000\n- word1 and word2 consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"race\",word2 = \"car\") == 7\n assert candidate(word1 = \"a\",word2 = \"a\") == 2\n assert candidate(word1 = \"aabb\",word2 = \"bbcc\") == 4\n assert candidate(word1 = \"race\",word2 = \"care\") == 7\n assert candidate(word1 = \"abcde\",word2 = \"edcba\") == 10\n assert candidate(word1 = \"madam\",word2 = \"madam\") == 10\n assert candidate(word1 = \"aabb\",word2 = \"bbaa\") == 8\n assert candidate(word1 = \"xyz\",word2 = \"zyx\") == 6\n assert candidate(word1 = \"palindrome\",word2 = \"emordnilap\") == 20\n assert candidate(word1 = \"abcabc\",word2 = \"cbacba\") == 12\n assert candidate(word1 = \"aa\",word2 = \"bb\") == 0\n assert candidate(word1 = \"hello\",word2 = \"world\") == 5\n assert candidate(word1 = \"abcdxyz\",word2 = \"zyxcba\") == 12\n assert candidate(word1 = \"cacb\",word2 = \"cbba\") == 5\n assert candidate(word1 = \"mnop\",word2 = \"pqrs\") == 2\n assert candidate(word1 = \"noon\",word2 = \"noon\") == 8\n assert candidate(word1 = \"level\",word2 = \"deified\") == 5\n assert candidate(word1 = \"a\",word2 = \"b\") == 0\n assert candidate(word1 = \"noon\",word2 = \"moon\") == 7\n assert candidate(word1 = \"abcba\",word2 = \"abcba\") == 10\n assert candidate(word1 = \"abcd\",word2 = \"dcba\") == 8\n assert candidate(word1 = \"abc\",word2 = \"def\") == 0\n assert candidate(word1 = \"ab\",word2 = \"ab\") == 3\n assert candidate(word1 = \"xyzzxyzzxyzz\",word2 = \"zzzyzxzzzyzxzzzyx\") == 25\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == 52\n assert candidate(word1 = \"abacax\",word2 = \"xcabab\") == 10\n assert candidate(word1 = \"deeee\",word2 = \"eee\") == 7\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcbajihgfedcba\") == 21\n assert candidate(word1 = \"madam\",word2 = \"rotor\") == 0\n assert candidate(word1 = \"aabbccddeeff\",word2 = \"ffeeddccbbaa\") == 24\n assert candidate(word1 = \"level\",word2 = \"leve\") == 8\n assert candidate(word1 = \"palindrome\",word2 = \"emordnilapracecar\") == 20\n assert candidate(word1 = \"longestpalindrome\",word2 = \"emordnilapstgnol\") == 30\n assert candidate(word1 = \"racecar\",word2 = \"level\") == 3\n assert candidate(word1 = \"aabbaa\",word2 = \"ccddeee\") == 0\n assert candidate(word1 = \"abc\",word2 = \"cba\") == 6\n assert candidate(word1 = \"xyzzyx\",word2 = \"zyxzyz\") == 7\n assert candidate(word1 = \"abcdxyz\",word2 = \"zyxcdb\") == 10\n assert candidate(word1 = \"xyx\",word2 = \"xyx\") == 6\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcba\") == 20\n assert candidate(word1 = \"racecar\",word2 = \"racecar\") == 14\n assert candidate(word1 = \"b\",word2 = \"b\") == 2\n assert candidate(word1 = \"abcdefgh\",word2 = \"hgfedcba\") == 16\n assert candidate(word1 = \"level\",word2 = \"level\") == 10\n assert candidate(word1 = \"aabbccddeeffgg\",word2 = \"ggffeeddccbbaa\") == 28\n assert candidate(word1 = \"aabaaa\",word2 = \"aaabaa\") == 12\n assert candidate(word1 = \"abacaxaba\",word2 = \"xyzzyx\") == 6\n assert candidate(word1 = \"abcdefg\",word2 = \"gfedcba\") == 14\n assert candidate(word1 = \"uniqueletters\",word2 = \"stretteleunik\") == 20\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == 0\n assert candidate(word1 = \"abcxyz\",word2 = \"zyxcba\") == 12\n assert candidate(word1 = \"abacdfgdcaba\",word2 = \"abacdfgdcaba\") == 22\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcbaabcdabcd\") == 14\n assert candidate(word1 = \"aabbaa\",word2 = \"aaabba\") == 11\n assert candidate(word1 = \"aabbccdd\",word2 = \"ddccbbaa\") == 16\n assert candidate(word1 = \"aaaaaa\",word2 = \"bbbbbb\") == 0\n assert candidate(word1 = \"ababababab\",word2 = \"bababababa\") == 20\n assert candidate(word1 = \"step\",word2 = \"onests\") == 7\n assert candidate(word1 = \"abcd\",word2 = \"zyxw\") == 0\n assert candidate(word1 = \"ababab\",word2 = \"bababa\") == 12\n assert candidate(word1 = \"abacaba\",word2 = \"bcbcbcb\") == 9\n assert candidate(word1 = \"palindromeconstruction\",word2 = \"noitcitsnocemordnilap\") == 40\n assert candidate(word1 = \"abcd\",word2 = \"dcbaabcd\") == 8\n assert candidate(word1 = \"racecar\",word2 = \"car\") == 7\n assert candidate(word1 = \"deified\",word2 = \"deified\") == 14\n assert candidate(word1 = \"abcdefg\",word2 = \"hgfedcba\") == 15\n assert candidate(word1 = \"complexstring\",word2 = \"gnirtsxlpmoc\") == 24\n assert candidate(word1 = \"noonnoon\",word2 = \"noonnoon\") == 16\n assert candidate(word1 = \"thisisatest\",word2 = \"tsetasitisth\") == 18\n assert candidate(word1 = \"abcdxyz\",word2 = \"zyxwvut\") == 6\n assert candidate(word1 = \"mnopqr\",word2 = \"rstuvw\") == 2\n assert candidate(word1 = \"racecar\",word2 = \"carrace\") == 9\n assert candidate(word1 = \"aabbccdd\",word2 = \"aabbccdd\") == 6\n assert candidate(word1 = \"abababa\",word2 = \"bababab\") == 13\n assert candidate(word1 = \"aaaaabbbbb\",word2 = \"bbbbbbaaaa\") == 19\n assert candidate(word1 = \"xyzz\",word2 = \"zzxy\") == 6\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"cbacbacbacba\") == 24\n assert candidate(word1 = \"ab\",word2 = \"bbaa\") == 5\n assert candidate(word1 = \"qwertyuiop\",word2 = \"poiuytrewq\") == 20\n assert candidate(word1 = \"aaaaabbbbb\",word2 = \"bbbbbbaaaaa\") == 21\n assert candidate(word1 = \"zzzz\",word2 = \"zzzz\") == 8\n assert candidate(word1 = \"xyx\",word2 = \"yxy\") == 5\n assert candidate(word1 = \"repaper\",word2 = \"repaper\") == 14\n assert candidate(word1 = \"reviled\",word2 = \"devil\") == 6\n assert candidate(word1 = \"abcdef\",word2 = \"fedcbaxyz\") == 12\n assert candidate(word1 = \"mississippi\",word2 = \"ississippim\") == 18\n assert candidate(word1 = \"abcdabc\",word2 = \"cbadcbad\") == 14\n assert candidate(word1 = \"rotor\",word2 = \"rotor\") == 10\n assert candidate(word1 = \"abcdabc\",word2 = \"cbadacb\") == 12\n assert candidate(word1 = \"zyxwvutsrqponmlkjihgfedcba\",word2 = \"abcdefghijklmnopqrstuvwxyz\") == 52\n assert candidate(word1 = \"aabbccddeeffgg\",word2 = \"ggffeeddccbaa\") == 26\n assert candidate(word1 = \"xxyyzz\",word2 = \"zzxyyx\") == 10\n assert candidate(word1 = \"xyzyx\",word2 = \"xzyyx\") == 8\n assert candidate(word1 = \"aabbcc\",word2 = \"ccbbaa\") == 12\n assert candidate(word1 = \"pneumonoultramicroscopicsilicovolcanoconiosis\",word2 = \"sinoconiovacolcosilicropicoviscounmoneup\") == 49\n assert candidate(word1 = \"aaaabbbb\",word2 = \"bbbbcccc\") == 8\n assert candidate(word1 = \"pqrstu\",word2 = \"utsrqp\") == 12\n assert candidate(word1 = \"mamad\",word2 = \"adam\") == 7\n assert candidate(word1 = \"abcabcabc\",word2 = \"cbacbacba\") == 18\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"abacabadabacaba\") == 30\n assert candidate(word1 = \"refer\",word2 = \"refer\") == 10\n assert candidate(word1 = \"redder\",word2 = \"redder\") == 12\n assert candidate(word1 = \"abacdfgdcaba\",word2 = \"gfdcbba\") == 15\n assert candidate(word1 = \"abcdefghijk\",word2 = \"kjihgfedcba\") == 22\n assert candidate(word1 = \"mnopqr\",word2 = \"rqponm\") == 12\n assert candidate(word1 = \"aabbaa\",word2 = \"bbccbb\") == 6\n assert candidate(word1 = \"thisisaverylongwordtoseetifthelongestpalindrome\",word2 = \"emordnilapelongethtofeesavaloydnevasiht\") == 58\n assert candidate(word1 = \"xyzzxy\",word2 = \"zyxzyxzyx\") == 13\n assert candidate(word1 = \"overlappingword\",word2 = \"drowgnalppero\") == 20\n assert candidate(word1 = \"ab\",word2 = \"ba\") == 4\n assert candidate(word1 = \"zxcvbnmasdfghjkl\",word2 = \"lkjhgfdsamnbvcxz\") == 32\n assert candidate(word1 = \"aaaaa\",word2 = \"bbbbb\") == 0\n assert candidate(word1 = \"racecar\",word2 = \"civic\") == 5\n assert candidate(word1 = \"abcdef\",word2 = \"fedcba\") == 12\n assert candidate(word1 = \"pqr\",word2 = \"rstuv\") == 2\n assert candidate(word1 = \"xyz\",word2 = \"zyxcba\") == 6\n assert candidate(word1 = \"c\",word2 = \"c\") == 2\n assert candidate(word1 = \"abcabcabcabcabc\",word2 = \"cbacbacbacbacba\") == 30\n", "comparison": "exact"}, "public_tests": ["\"cacb\"\n\"cbba\"", "\"ab\"\n\"ab\"", "\"aa\"\n\"bb\""], "hints": ["Let's ignore the non-empty subsequence constraint. We can concatenate the two strings and find the largest palindromic subsequence with dynamic programming.", "Iterate through every pair of characters word1[i] and word2[j], and see if some palindrome begins with word1[i] and ends with word2[j]. This ensures that the subsequences are non-empty."], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().longestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:16+00:00", "tests_total": 120, "tests_dropped": 2, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function longestPalindrome($word1, $word2) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1773, "task_id": "count-items-matching-a-rule", "difficulty": "Easy", "problem_description": "You are given an array items, where each items[i] = [type_i, color_i, name_i] describes the type, color, and name of the i^th item. You are also given a rule represented by two strings, ruleKey and ruleValue.\n\nThe i^th item is said to match the rule if one of the following is true:\n\n- ruleKey == \"type\" and ruleValue == type_i.\n- ruleKey == \"color\" and ruleValue == color_i.\n- ruleKey == \"name\" and ruleValue == name_i.\n\nReturn the number of items that match the given rule.\n\nExample 1:\n\nInput: items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\"\nOutput: 1\nExplanation: There is only one item matching the given rule, which is [\"computer\",\"silver\",\"lenovo\"].\n\nExample 2:\n\nInput: items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"type\", ruleValue = \"phone\"\nOutput: 2\nExplanation: There are only two items matching the given rule, which are [\"phone\",\"blue\",\"pixel\"] and [\"phone\",\"gold\",\"iphone\"]. Note that the item [\"computer\",\"silver\",\"phone\"] does not match.\n\nConstraints:\n\n- 1 <= items.length <= 10^4\n- 1 <= type_i.length, color_i.length, name_i.length, ruleValue.length <= 10\n- ruleKey is equal to either \"type\", \"color\", or \"name\".\n- All strings consist only of lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(items = [['car', 'red', 'ferrari'], ['bike', 'blue', 'harley'], ['car', 'green', 'lambo']],ruleKey = \"color\",ruleValue = \"red\") == 1\n assert candidate(items = [['phone', 'blue', 'pixel'], ['computer', 'silver', 'phone'], ['phone', 'gold', 'iphone']],ruleKey = \"type\",ruleValue = \"phone\") == 2\n assert candidate(items = [['laptop', 'black', 'dell'], ['phone', 'black', 'samsung'], ['tablet', 'black', 'ipad']],ruleKey = \"color\",ruleValue = \"black\") == 3\n assert candidate(items = [['laptop', 'black', 'dell'], ['phone', 'white', 'samsung'], ['tablet', 'gray', 'apple']],ruleKey = \"name\",ruleValue = \"apple\") == 1\n assert candidate(items = [['laptop', 'black', 'dell'], ['tablet', 'white', 'samsung'], ['laptop', 'silver', 'macbook']],ruleKey = \"name\",ruleValue = \"dell\") == 1\n assert candidate(items = [['shoe', 'white', 'nike'], ['shirt', 'black', 'adidas'], ['shoe', 'black', 'puma']],ruleKey = \"type\",ruleValue = \"shoe\") == 2\n assert candidate(items = [['book', 'red', 'novel'], ['pen', 'blue', 'ballpoint'], ['notebook', 'red', 'blank']],ruleKey = \"name\",ruleValue = \"blank\") == 1\n assert candidate(items = [['phone', 'blue', 'pixel'], ['computer', 'silver', 'lenovo'], ['phone', 'gold', 'iphone']],ruleKey = \"color\",ruleValue = \"silver\") == 1\n assert candidate(items = [['laptop', 'black', 'dell'], ['laptop', 'gray', 'hp'], ['desktop', 'black', 'asus']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['book', 'brown', 'alice'], ['pen', 'blue', 'bic'], ['notebook', 'white', 'staples']],ruleKey = \"type\",ruleValue = \"book\") == 1\n assert candidate(items = [['car', 'red', 'ferrari'], ['bike', 'red', 'yamaha'], ['truck', 'blue', 'ford']],ruleKey = \"type\",ruleValue = \"red\") == 0\n assert candidate(items = [['book', 'red', 'novel'], ['pen', 'blue', 'ballpoint'], ['book', 'brown', 'textbook']],ruleKey = \"type\",ruleValue = \"book\") == 2\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['camera', 'black', 'canon'], ['camera', 'silver', 'nikon'], ['camera', 'black', 'sony'], ['camera', 'gold', 'fujifilm'], ['camera', 'black', 'olympus']],ruleKey = \"name\",ruleValue = \"sony\") == 1\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'blue', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'black', 'apple'], ['smartphone', 'red', 'motorola']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['toys', 'yellow', 'balloon'], ['toys', 'red', 'car'], ['toys', 'blue', 'doll'], ['toys', 'green', 'teddy'], ['toys', 'yellow', 'block']],ruleKey = \"color\",ruleValue = \"yellow\") == 2\n assert candidate(items = [['computer', 'silver', 'dell'], ['computer', 'black', 'apple'], ['computer', 'silver', 'hp'], ['computer', 'black', 'asus'], ['computer', 'silver', 'lenovo'], ['computer', 'black', 'microsoft']],ruleKey = \"color\",ruleValue = \"silver\") == 3\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'blue', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'black', 'apple'], ['laptop', 'gray', 'hp']],ruleKey = \"type\",ruleValue = \"laptop\") == 2\n assert candidate(items = [['shirt', 'blue', 'nike'], ['pants', 'blue', 'adidas'], ['shoes', 'blue', 'puma'], ['hat', 'blue', 'reebok'], ['shirt', 'blue', 'nike']],ruleKey = \"name\",ruleValue = \"nike\") == 2\n assert candidate(items = [['chair', 'brown', 'ikea'], ['table', 'white', 'ikea'], ['couch', 'gray', 'ikea'], ['desk', 'black', 'ikea'], ['lamp', 'silver', 'ikea']],ruleKey = \"brand\",ruleValue = \"ikea\") == 5\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'gold', 'fitbit'], ['laptop', 'gray', 'hp']],ruleKey = \"type\",ruleValue = \"laptop\") == 2\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'gold', 'fitbit'], ['laptop', 'gray', 'hp'], ['laptop', 'black', 'macbook']],ruleKey = \"type\",ruleValue = \"laptop\") == 3\n assert candidate(items = [['book', 'blue', 'fiction'], ['book', 'red', 'nonfiction'], ['book', 'blue', 'science'], ['book', 'green', 'history'], ['book', 'blue', 'fantasy']],ruleKey = \"name\",ruleValue = \"nonfiction\") == 1\n assert candidate(items = [['chair', 'white', 'ikea'], ['sofa', 'brown', 'ikea'], ['table', 'brown', 'ikea'], ['lamp', 'white', 'ikea'], ['shelf', 'brown', 'ikea'], ['cabinet', 'white', 'ikea']],ruleKey = \"type\",ruleValue = \"ikea\") == 0\n assert candidate(items = [['apparel', 'black', 'jacket'], ['apparel', 'white', 'shirt'], ['apparel', 'red', 'pants'], ['apparel', 'blue', 'hat']],ruleKey = \"type\",ruleValue = \"apparel\") == 4\n assert candidate(items = [['camera', 'black', 'nikon'], ['camera', 'silver', 'canon'], ['camera', 'gold', 'leica'], ['camera', 'black', 'olympus'], ['camera', 'white', 'fujifilm']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['toy', 'green', 'car'], ['toy', 'red', 'doll'], ['toy', 'blue', 'block'], ['toy', 'green', 'train'], ['toy', 'red', 'helicopter'], ['toy', 'blue', 'truck']],ruleKey = \"type\",ruleValue = \"toy\") == 6\n assert candidate(items = [['phone', 'blue', 'pixel'], ['computer', 'silver', 'lenovo'], ['phone', 'gold', 'iphone'], ['tablet', 'black', 'samsung'], ['smartwatch', 'black', 'fitbit'], ['laptop', 'blue', 'macbook']],ruleKey = \"color\",ruleValue = \"blue\") == 2\n assert candidate(items = [['smartphone', 'red', 'iphone'], ['smartphone', 'black', 'galaxy'], ['smartphone', 'white', 'nokia'], ['smartphone', 'black', 'oneplus'], ['smartphone', 'red', 'motorola'], ['smartphone', 'blue', 'huawei'], ['smartphone', 'red', 'oppo'], ['smartphone', 'green', 'realme']],ruleKey = \"name\",ruleValue = \"red\") == 0\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'gold', 'fitbit'], ['laptop', 'gray', 'hp'], ['laptop', 'black', 'macbook'], ['laptop', 'gray', 'asus']],ruleKey = \"name\",ruleValue = \"laptop\") == 0\n assert candidate(items = [['house', 'white', 'mansions'], ['house', 'blue', 'cottages'], ['apartment', 'gray', 'flats'], ['condo', 'white', 'duplex'], ['townhouse', 'blue', 'terraced'], ['house', 'white', 'bungalows'], ['apartment', 'gray', 'penthouse'], ['condo', 'blue', 'villa'], ['townhouse', 'white', 'villas'], ['house', 'gray', 'detached']],ruleKey = \"type\",ruleValue = \"house\") == 4\n assert candidate(items = [['smartphone', 'red', 'iphone'], ['smartphone', 'black', 'galaxy'], ['smartphone', 'white', 'nokia'], ['smartphone', 'black', 'oneplus'], ['smartphone', 'red', 'motorola']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['shirt', 'blue', 'tshirt'], ['jeans', 'blue', 'levis'], ['shirt', 'green', 'polo'], ['shorts', 'blue', 'nike'], ['pants', 'blue', 'adidas'], ['shirt', 'blue', 'reebok']],ruleKey = \"color\",ruleValue = \"blue\") == 5\n assert candidate(items = [['shirt', 'blue', 'nike'], ['pants', 'red', 'adidas'], ['hat', 'blue', 'reebok'], ['jacket', 'green', 'nike'], ['shoes', 'black', 'puma']],ruleKey = \"name\",ruleValue = \"nike\") == 2\n assert candidate(items = [['television', 'black', 'samsung'], ['television', 'silver', 'lg'], ['television', 'gray', 'tcl'], ['television', 'black', 'sony'], ['television', 'red', 'panasonic']],ruleKey = \"type\",ruleValue = \"television\") == 5\n assert candidate(items = [['shirt', 'blue', 'tshirt'], ['jeans', 'blue', 'levis'], ['shirt', 'green', 'polo'], ['shorts', 'blue', 'nike'], ['pants', 'blue', 'adidas']],ruleKey = \"name\",ruleValue = \"nike\") == 1\n assert candidate(items = [['phone', 'blue', 'pixel'], ['computer', 'silver', 'lenovo'], ['phone', 'gold', 'iphone'], ['tv', 'black', 'samsung'], ['monitor', 'silver', 'dell'], ['laptop', 'gray', 'hp'], ['phone', 'black', 'nokia'], ['tablet', 'gold', 'ipad']],ruleKey = \"type\",ruleValue = \"phone\") == 3\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartwatch', 'gold', 'fitbit'], ['laptop', 'gray', 'hp']],ruleKey = \"name\",ruleValue = \"dell\") == 1\n assert candidate(items = [['tv', 'black', 'samsung'], ['tv', 'white', 'lg'], ['tv', 'silver', 'sony'], ['tv', 'black', 'toshiba'], ['tv', 'white', 'vizio']],ruleKey = \"color\",ruleValue = \"white\") == 2\n assert candidate(items = [['toy', 'red', 'car'], ['toy', 'blue', 'doll'], ['toy', 'green', 'car'], ['toy', 'red', 'ball'], ['toy', 'green', 'doll'], ['toy', 'blue', 'ball']],ruleKey = \"name\",ruleValue = \"car\") == 2\n assert candidate(items = [['clothing', 'blue', 'shirt'], ['clothing', 'red', 't-shirt'], ['clothing', 'blue', 'jeans'], ['clothing', 'green', 'pants'], ['clothing', 'blue', 'jacket'], ['clothing', 'yellow', 'shorts'], ['clothing', 'blue', 'hat']],ruleKey = \"color\",ruleValue = \"blue\") == 4\n assert candidate(items = [['chair', 'brown', 'leather'], ['table', 'white', 'wood'], ['lamp', 'black', 'glass'], ['sofa', 'gray', 'cotton'], ['rug', 'blue', 'carpet'], ['cabinet', 'black', 'oak'], ['bed', 'white', 'sheets'], ['mirror', 'silver', 'frame'], ['shelf', 'black', 'metal']],ruleKey = \"color\",ruleValue = \"black\") == 3\n assert candidate(items = [['shirt', 'white', 'nike'], ['pants', 'blue', 'adidas'], ['shoes', 'black', 'puma'], ['hat', 'white', 'reebok'], ['socks', 'blue', 'nike']],ruleKey = \"color\",ruleValue = \"blue\") == 2\n assert candidate(items = [['couch', 'brown', 'sofa'], ['chair', 'black', 'office'], ['table', 'brown', 'dining'], ['lamp', 'black', 'reading'], ['cabinet', 'brown', 'kitchen']],ruleKey = \"color\",ruleValue = \"brown\") == 3\n assert candidate(items = [['keyboard', 'black', 'logitech'], ['keyboard', 'white', 'razer'], ['keyboard', 'blue', 'corsair'], ['keyboard', 'black', 'microsoft'], ['keyboard', 'black', 'filco']],ruleKey = \"type\",ruleValue = \"keyboard\") == 5\n assert candidate(items = [['shirt', 'blue', 'nike'], ['pants', 'blue', 'adidas'], ['shoes', 'black', 'reebok'], ['hat', 'red', 'nike'], ['jacket', 'blue', 'puma'], ['watch', 'silver', 'rolex'], ['belt', 'brown', 'gucci']],ruleKey = \"name\",ruleValue = \"nike\") == 2\n assert candidate(items = [['laptop', 'black', 'dell'], ['laptop', 'gray', 'hp'], ['desktop', 'black', 'asus'], ['monitor', 'black', 'dell'], ['laptop', 'silver', 'lenovo']],ruleKey = \"type\",ruleValue = \"laptop\") == 3\n assert candidate(items = [['shirt', 'blue', 'tshirt'], ['jeans', 'blue', 'levis'], ['shirt', 'green', 'polo'], ['shorts', 'blue', 'nike'], ['pants', 'blue', 'adidas']],ruleKey = \"color\",ruleValue = \"blue\") == 4\n assert candidate(items = [['camera', 'black', 'canon'], ['smartphone', 'white', 'iphone'], ['tablet', 'gold', 'ipad'], ['smartwatch', 'black', 'applewatch'], ['laptop', 'silver', 'macbook']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['furniture', 'brown', 'table'], ['furniture', 'white', 'sofa'], ['furniture', 'brown', 'chair'], ['furniture', 'black', 'cabinet'], ['furniture', 'white', 'lamp'], ['furniture', 'brown', 'dresser']],ruleKey = \"color\",ruleValue = \"brown\") == 3\n assert candidate(items = [['computer', 'black', 'macbook'], ['smartwatch', 'silver', 'apple'], ['tablet', 'white', 'samsung'], ['laptop', 'blue', 'dell'], ['desktop', 'black', 'asus'], ['computer', 'silver', 'lenovo'], ['smartwatch', 'white', 'fitbit'], ['tablet', 'black', 'xiaomi']],ruleKey = \"color\",ruleValue = \"white\") == 2\n assert candidate(items = [['camera', 'black', 'canon'], ['camera', 'silver', 'nikon'], ['lens', 'black', 'canon'], ['camera', 'white', 'sony'], ['tripod', 'gray', 'benro'], ['camera', 'black', 'fujifilm']],ruleKey = \"brand\",ruleValue = \"canon\") == 2\n assert candidate(items = [['headphones', 'black', 'sony'], ['headphones', 'black', 'apple'], ['headphones', 'black', 'sennheiser'], ['headphones', 'black', 'bose'], ['headphones', 'black', 'jaybird']],ruleKey = \"color\",ruleValue = \"black\") == 5\n assert candidate(items = [['toy', 'red', 'car'], ['toy', 'blue', 'doll'], ['toy', 'red', 'truck'], ['toy', 'yellow', 'balloon'], ['toy', 'blue', 'teddybear'], ['toy', 'red', 'firetruck']],ruleKey = \"type\",ruleValue = \"toy\") == 6\n assert candidate(items = [['camera', 'black', 'nikon'], ['phone', 'black', 'iphone'], ['tablet', 'black', 'ipad'], ['smartwatch', 'black', 'applewatch'], ['laptop', 'black', 'macbook']],ruleKey = \"color\",ruleValue = \"black\") == 5\n assert candidate(items = [['sneakers', 'white', 'nike'], ['tshirt', 'blue', 'adidas'], ['jeans', 'black', 'puma'], ['hat', 'red', 'nike'], ['pants', 'blue', 'reebok']],ruleKey = \"name\",ruleValue = \"nike\") == 2\n assert candidate(items = [['computer', 'black', 'macbook'], ['smartwatch', 'silver', 'apple'], ['tablet', 'white', 'samsung'], ['laptop', 'blue', 'dell'], ['desktop', 'black', 'asus']],ruleKey = \"type\",ruleValue = \"computer\") == 1\n assert candidate(items = [['monitor', 'black', 'asus'], ['monitor', 'white', 'dell'], ['monitor', 'blue', 'benq'], ['monitor', 'silver', 'acer'], ['monitor', 'black', 'lg']],ruleKey = \"type\",ruleValue = \"monitor\") == 5\n assert candidate(items = [['smartphone', 'black', 'samsung'], ['smartphone', 'blue', 'iphone'], ['smartphone', 'black', 'google'], ['smartphone', 'red', 'oneplus'], ['smartphone', 'black', 'zte']],ruleKey = \"color\",ruleValue = \"black\") == 3\n assert candidate(items = [['shirt', 'black', 'nike'], ['jeans', 'blue', 'levis'], ['jacket', 'brown', 'adidas'], ['shoes', 'white', 'nike'], ['hat', 'black', 'nike'], ['socks', 'blue', 'addidas'], ['gloves', 'brown', 'adidas'], ['shorts', 'white', 'levis']],ruleKey = \"color\",ruleValue = \"black\") == 2\n assert candidate(items = [['laptop', 'black', 'dell'], ['smartphone', 'black', 'samsung'], ['tablet', 'silver', 'ipad'], ['smartphone', 'blue', 'huawei'], ['laptop', 'red', 'macbook']],ruleKey = \"type\",ruleValue = \"smartphone\") == 2\n assert candidate(items = [['phone', 'blue', 'pixel'], ['computer', 'silver', 'lenovo'], ['phone', 'gold', 'iphone'], ['phone', 'black', 'samsung'], ['laptop', 'gray', 'hp'], ['tablet', 'silver', 'ipad']],ruleKey = \"type\",ruleValue = \"phone\") == 3\n assert candidate(items = [['laptop', 'black', 'dell'], ['laptop', 'gray', 'hp'], ['desktop', 'black', 'asus'], ['laptop', 'black', 'lenovo'], ['desktop', 'black', 'acer']],ruleKey = \"color\",ruleValue = \"black\") == 4\n assert candidate(items = [['shirt', 'blue', 'tshirt'], ['jeans', 'blue', 'levis'], ['shirt', 'green', 'polo'], ['shorts', 'blue', 'nike'], ['pants', 'blue', 'adidas'], ['shirt', 'blue', 'reebok'], ['shirt', 'blue', 'puma']],ruleKey = \"name\",ruleValue = \"blue\") == 0\n assert candidate(items = [['tv', 'black', 'samsung'], ['fridge', 'white', 'lg'], ['microwave', 'black', 'whirlpool'], ['stove', 'black', 'bosch']],ruleKey = \"color\",ruleValue = \"black\") == 3\n assert candidate(items = [['phone', 'blue', 'pixel'], ['phone', 'blue', 'galaxy'], ['phone', 'blue', 'nokia'], ['phone', 'blue', 'oneplus'], ['phone', 'blue', 'google'], ['phone', 'blue', 'xiaomi'], ['phone', 'blue', 'htc']],ruleKey = \"name\",ruleValue = \"google\") == 1\n assert candidate(items = [['smartwatch', 'silver', 'apple'], ['smartwatch', 'gold', 'rolex'], ['bracelet', 'silver', 'tissot'], ['pendant', 'gold', 'omega'], ['bracelet', 'silver', 'casio']],ruleKey = \"name\",ruleValue = \"silver\") == 0\n", "comparison": "exact"}, "public_tests": ["[[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]]\n\"color\"\n\"silver\"", "[[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]]\n\"type\"\n\"phone\""], "hints": ["Iterate on each item, and check if each one matches the rule according to the statement."], "metadata": {"canonical_parameter_names": ["items", "ruleKey", "ruleValue"], "leetcode_dataset_entry_point": "Solution().countMatches", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:20+00:00", "tests_total": 108, "tests_dropped": 41, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function countMatches($items, $ruleKey, $ruleValue) {", "container": "Solution", "callable": "countMatches", "parameters": [{"name": "items", "type": "String[][]"}, {"name": "ruleKey", "type": "String"}, {"name": "ruleValue", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1774, "task_id": "closest-dessert-cost", "difficulty": "Medium", "problem_description": "You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:\n\n- There must be exactly one ice cream base.\n- You can add one or more types of topping or have no toppings at all.\n- There are at most two of each type of topping.\n\nYou are given three inputs:\n\n- baseCosts, an integer array of length n, where each baseCosts[i] represents the price of the i^th ice cream base flavor.\n- toppingCosts, an integer array of length m, where each toppingCosts[i] is the price of one of the i^th topping.\n- target, an integer representing your target price for dessert.\n\nYou want to make a dessert with a total cost as close to target as possible.\n\nReturn the closest possible cost of the dessert to target. If there are multiple, return the lower one.\n\nExample 1:\n\nInput: baseCosts = [1,7], toppingCosts = [3,4], target = 10\nOutput: 10\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 7\n- Take 1 of topping 0: cost 1 x 3 = 3\n- Take 0 of topping 1: cost 0 x 4 = 0\nTotal: 7 + 3 + 0 = 10.\n\nExample 2:\n\nInput: baseCosts = [2,3], toppingCosts = [4,5,100], target = 18\nOutput: 17\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 3\n- Take 1 of topping 0: cost 1 x 4 = 4\n- Take 2 of topping 1: cost 2 x 5 = 10\n- Take 0 of topping 2: cost 0 x 100 = 0\nTotal: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.\n\nExample 3:\n\nInput: baseCosts = [3,10], toppingCosts = [2,5], target = 9\nOutput: 8\nExplanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.\n\nConstraints:\n\n- n == baseCosts.length\n- m == toppingCosts.length\n- 1 <= n, m <= 10\n- 1 <= baseCosts[i], toppingCosts[i] <= 10^4\n- 1 <= target <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(baseCosts = [10, 20],toppingCosts = [1, 2, 3],target = 15) == 15\n assert candidate(baseCosts = [5, 9],toppingCosts = [2, 3, 7],target = 15) == 15\n assert candidate(baseCosts = [1, 7],toppingCosts = [3, 4],target = 10) == 10\n assert candidate(baseCosts = [10, 20, 30],toppingCosts = [1, 2, 3, 4, 5],target = 25) == 25\n assert candidate(baseCosts = [4, 8],toppingCosts = [1, 3],target = 15) == 15\n assert candidate(baseCosts = [5],toppingCosts = [1, 2, 3],target = 8) == 8\n assert candidate(baseCosts = [4],toppingCosts = [1, 2, 3],target = 8) == 8\n assert candidate(baseCosts = [10, 20],toppingCosts = [5, 15, 25],target = 50) == 50\n assert candidate(baseCosts = [1],toppingCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(baseCosts = [5, 8],toppingCosts = [6, 1, 2],target = 20) == 20\n assert candidate(baseCosts = [10],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 20) == 20\n assert candidate(baseCosts = [2, 3],toppingCosts = [4, 5, 100],target = 18) == 17\n assert candidate(baseCosts = [3, 10],toppingCosts = [2, 5],target = 9) == 8\n assert candidate(baseCosts = [4, 8, 12, 16, 20],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 30) == 30\n assert candidate(baseCosts = [50, 75, 100, 125],toppingCosts = [10, 15, 20, 25, 30],target = 300) == 300\n assert candidate(baseCosts = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],toppingCosts = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1023) == 1023\n assert candidate(baseCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 1500) == 1500\n assert candidate(baseCosts = [1234, 5678, 9101],toppingCosts = [111, 222, 333, 444, 555, 666],target = 10000) == 10007\n assert candidate(baseCosts = [1000, 2000, 3000, 4000, 5000],toppingCosts = [50, 100, 150, 200, 250, 300, 350],target = 10000) == 7800\n assert candidate(baseCosts = [15, 25, 35, 45],toppingCosts = [2, 4, 6, 8, 10],target = 50) == 49\n assert candidate(baseCosts = [100, 200, 300, 400],toppingCosts = [10, 20, 30, 40, 50],target = 500) == 500\n assert candidate(baseCosts = [123, 456, 789],toppingCosts = [987, 654, 321, 654, 321, 987],target = 1000) == 1086\n assert candidate(baseCosts = [10, 20, 30, 40, 50],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 150) == 150\n assert candidate(baseCosts = [1000, 2000, 3000, 4000, 5000],toppingCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 7500) == 7500\n assert candidate(baseCosts = [1, 5, 10, 15],toppingCosts = [3, 6, 9, 12],target = 30) == 30\n assert candidate(baseCosts = [7, 14, 21],toppingCosts = [3, 6, 9, 12, 15, 18],target = 30) == 30\n assert candidate(baseCosts = [500, 1000, 1500],toppingCosts = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],target = 3000) == 3000\n assert candidate(baseCosts = [1000, 2000],toppingCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 5000) == 5000\n assert candidate(baseCosts = [8, 16, 24],toppingCosts = [2, 4, 6, 8, 10, 12, 14, 16],target = 35) == 34\n assert candidate(baseCosts = [3, 6, 9, 12, 15],toppingCosts = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1024) == 1024\n assert candidate(baseCosts = [300, 600, 900],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 1200) == 1200\n assert candidate(baseCosts = [1, 2, 3, 4, 5],toppingCosts = [5, 10, 15, 20, 25],target = 50) == 50\n assert candidate(baseCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 50) == 50\n assert candidate(baseCosts = [100, 200, 300],toppingCosts = [50, 75, 100, 125, 150],target = 600) == 600\n assert candidate(baseCosts = [1, 10000],toppingCosts = [5000, 3000, 2000, 1000, 500, 100],target = 9000) == 9001\n assert candidate(baseCosts = [15, 25, 35],toppingCosts = [5, 7, 11, 13, 17],target = 50) == 50\n assert candidate(baseCosts = [100, 150, 200, 250],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90],target = 750) == 750\n assert candidate(baseCosts = [999, 1999, 2999],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5000) == 3109\n assert candidate(baseCosts = [1, 1, 1, 1, 1],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 25) == 25\n assert candidate(baseCosts = [150, 250, 350],toppingCosts = [5, 15, 25, 35, 45, 55],target = 400) == 400\n assert candidate(baseCosts = [2000, 4000, 6000],toppingCosts = [100, 200, 300, 400, 500],target = 7000) == 7000\n assert candidate(baseCosts = [1, 10, 100],toppingCosts = [9, 90, 900, 9000],target = 10000) == 10000\n assert candidate(baseCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 1000) == 1000\n assert candidate(baseCosts = [15, 25, 35, 45],toppingCosts = [1, 2, 3, 4, 5, 6, 7],target = 30) == 30\n assert candidate(baseCosts = [10, 20, 30],toppingCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 45) == 45\n assert candidate(baseCosts = [1, 1, 1, 1, 1],toppingCosts = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = 100) == 101\n assert candidate(baseCosts = [1000, 2000, 3000, 4000, 5000],toppingCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 10000) == 10000\n assert candidate(baseCosts = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 100) == 100\n assert candidate(baseCosts = [500, 250],toppingCosts = [100, 200, 300, 400, 500],target = 1000) == 1000\n assert candidate(baseCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 500) == 210\n assert candidate(baseCosts = [100, 200, 300],toppingCosts = [10, 20, 30, 40, 50, 60],target = 500) == 500\n assert candidate(baseCosts = [1000, 2000, 3000],toppingCosts = [500, 100, 250, 125, 75],target = 4500) == 4500\n assert candidate(baseCosts = [123, 456, 789],toppingCosts = [11, 22, 33, 44, 55, 66, 77, 88, 99],target = 1000) == 998\n assert candidate(baseCosts = [5, 10, 15, 20, 25],toppingCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 20) == 20\n assert candidate(baseCosts = [9999],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10000) == 10000\n assert candidate(baseCosts = [123, 456, 789],toppingCosts = [987, 654, 321, 123, 456, 789, 100, 200, 300],target = 2000) == 2000\n assert candidate(baseCosts = [500, 501, 502],toppingCosts = [250, 251, 252, 253],target = 1000) == 1000\n assert candidate(baseCosts = [777, 888],toppingCosts = [55, 44, 33, 22, 11, 1, 2, 3, 4, 5],target = 2000) == 1248\n assert candidate(baseCosts = [10, 20, 30, 40, 50],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 25) == 25\n assert candidate(baseCosts = [10, 20, 30, 40, 50],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 50) == 50\n assert candidate(baseCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],toppingCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 10) == 10\n assert candidate(baseCosts = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],toppingCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 30) == 30\n assert candidate(baseCosts = [123, 456, 789],toppingCosts = [11, 22, 33, 44, 55],target = 700) == 698\n assert candidate(baseCosts = [100, 200, 300, 400],toppingCosts = [10, 20, 30, 40, 50, 60],target = 750) == 750\n assert candidate(baseCosts = [100, 200],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 500) == 310\n assert candidate(baseCosts = [1000, 1001, 1002, 1003],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10000) == 1113\n assert candidate(baseCosts = [23, 45, 67, 89, 10],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 200) == 199\n assert candidate(baseCosts = [5, 10, 15, 20],toppingCosts = [1, 3, 5, 7, 9, 11, 13],target = 40) == 40\n assert candidate(baseCosts = [100, 200, 300, 400, 500],toppingCosts = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 1000) == 1000\n assert candidate(baseCosts = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],toppingCosts = [2, 4, 6, 8, 10],target = 50) == 49\n assert candidate(baseCosts = [100, 200, 300, 400],toppingCosts = [10, 20, 30, 40, 50, 60],target = 1500) == 820\n assert candidate(baseCosts = [100, 200, 300, 400],toppingCosts = [50, 10, 15, 20, 25, 30, 35, 40, 45, 55],target = 1500) == 1050\n assert candidate(baseCosts = [1, 2, 3, 4, 5],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 100) == 101\n assert candidate(baseCosts = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],toppingCosts = [500, 1500, 2500, 3500],target = 7500) == 7500\n assert candidate(baseCosts = [2000, 3000, 4000, 5000],toppingCosts = [50, 100, 150, 200, 250],target = 8500) == 6500\n assert candidate(baseCosts = [50, 100, 150, 200, 250, 300],toppingCosts = [5, 10, 15, 20, 25, 30],target = 750) == 510\n assert candidate(baseCosts = [100, 200],toppingCosts = [50, 25, 10, 5, 1],target = 300) == 300\n assert candidate(baseCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],toppingCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 5000) == 5001\n assert candidate(baseCosts = [1000, 2000, 3000],toppingCosts = [500, 1000, 1500, 2000, 2500],target = 6000) == 6000\n assert candidate(baseCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 50) == 50\n assert candidate(baseCosts = [800, 1600, 2400],toppingCosts = [100, 200, 300, 400, 500, 600],target = 3000) == 3000\n assert candidate(baseCosts = [1000, 2000, 3000],toppingCosts = [500, 100, 250, 150, 200],target = 4500) == 4500\n assert candidate(baseCosts = [4, 8, 12, 16, 20],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 45) == 45\n assert candidate(baseCosts = [1, 2, 3, 4, 5],toppingCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 500) == 501\n assert candidate(baseCosts = [50, 60, 70, 80, 90],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 150) == 150\n assert candidate(baseCosts = [100, 200, 300],toppingCosts = [50, 75, 100, 125, 150],target = 500) == 500\n assert candidate(baseCosts = [10, 20],toppingCosts = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],target = 1000) == 1000\n assert candidate(baseCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],toppingCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 500) == 210\n assert candidate(baseCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],toppingCosts = [9999],target = 10000) == 10000\n assert candidate(baseCosts = [5, 10],toppingCosts = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = 15) == 15\n assert candidate(baseCosts = [500, 1000, 1500],toppingCosts = [5, 10, 15, 20, 25, 30, 35, 40],target = 2000) == 1860\n assert candidate(baseCosts = [999, 1000],toppingCosts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 4000) == 4000\n", "comparison": "exact"}, "public_tests": ["[1,7]\n[3,4]\n10", "[2,3]\n[4,5,100]\n18", "[3,10]\n[2,5]\n9"], "hints": ["As the constraints are not large, you can brute force and enumerate all the possibilities."], "metadata": {"canonical_parameter_names": ["baseCosts", "toppingCosts", "target"], "leetcode_dataset_entry_point": "Solution().closestCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:23+00:00", "tests_total": 99, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "knapsack-problem", "mixed-knapsack"]}, "language": "php", "interface": {"raw_signature": "function closestCost($baseCosts, $toppingCosts, $target) {", "container": "Solution", "callable": "closestCost", "parameters": [{"name": "baseCosts", "type": "Integer[]"}, {"name": "toppingCosts", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1775, "task_id": "equal-sum-arrays-with-minimum-number-of-operations", "difficulty": "Medium", "problem_description": "You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.\n\nIn one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.\n\nReturn the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1 if it is not possible to make the sum of the two arrays equal.\n\nExample 1:\n\nInput: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].\n\nExample 2:\n\nInput: nums1 = [1,1,1,1,1,1,1], nums2 = [6]\nOutput: -1\nExplanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n\nExample 3:\n\nInput: nums1 = [6,6], nums2 = [1]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [4].\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 10^5\n- 1 <= nums1[i], nums2[i] <= 6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums1 = [3, 3, 3, 3],nums2 = [2, 2, 2, 2]) == 1\n assert candidate(nums1 = [1, 1],nums2 = [6, 6]) == 2\n assert candidate(nums1 = [6, 6, 6],nums2 = [1, 1]) == 4\n assert candidate(nums1 = [1, 1, 2],nums2 = [6, 6, 6]) == 3\n assert candidate(nums1 = [1, 1],nums2 = [6, 6, 6]) == 4\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums1 = [1, 2],nums2 = [5, 6]) == 2\n assert candidate(nums1 = [6, 6, 6],nums2 = [1, 1, 1]) == 3\n assert candidate(nums1 = [3, 3, 3],nums2 = [3, 3, 3]) == 0\n assert candidate(nums1 = [2, 3, 4],nums2 = [5, 5, 5]) == 2\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1],nums2 = [6]) == -1\n assert candidate(nums1 = [6],nums2 = [1]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [1, 1, 2, 2, 2, 2]) == 3\n assert candidate(nums1 = [3, 3, 3],nums2 = [2, 2, 2]) == 1\n assert candidate(nums1 = [6, 6],nums2 = [1]) == 3\n assert candidate(nums1 = [2, 2, 2],nums2 = [5, 5, 5]) == 3\n assert candidate(nums1 = [3, 3, 3],nums2 = [2, 2, 2, 2]) == 1\n assert candidate(nums1 = [1],nums2 = [6]) == 1\n assert candidate(nums1 = [1, 1, 1],nums2 = [6, 6, 6]) == 3\n assert candidate(nums1 = [3],nums2 = [3]) == 0\n assert candidate(nums1 = [1, 3, 5],nums2 = [2, 4, 6]) == 1\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == 2\n assert candidate(nums1 = [5, 5],nums2 = [1, 1]) == 2\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1]) == 4\n assert candidate(nums1 = [3, 3, 3, 3],nums2 = [1, 6, 1, 6]) == 1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 6\n assert candidate(nums1 = [1, 3, 5, 5, 5, 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, 6, 6, 6, 6, 2]) == 5\n assert candidate(nums1 = [6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6],nums2 = [1, 2, 3, 4, 5, 6]) == 3\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]) == 0\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [1, 6, 1, 6, 1, 6],nums2 = [6, 1, 6, 1, 6, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],nums2 = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5],nums2 = [6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 0\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, 1, 1, 1, 1, 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 = [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, 6, 6, 6, 6]) == 58\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [4, 5, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 8\n assert candidate(nums1 = [1, 3, 5, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\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, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6]) == 6\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [1],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == -1\n assert candidate(nums1 = [2, 3, 4, 5, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 3, 4, 5, 6]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1],nums2 = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1]) == 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 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]) == 11\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 6\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 5\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 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(nums1 = [1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6]) == 6\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 12\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 0\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2],nums2 = [2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3]) == 1\n assert candidate(nums1 = [1, 3, 5, 1, 3, 5, 1, 3, 5],nums2 = [2, 4, 6, 2, 4, 6, 2, 4, 6]) == 2\n assert candidate(nums1 = [1, 6, 1, 6, 1, 6],nums2 = [2, 5, 2, 5, 2, 5]) == 0\n assert candidate(nums1 = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4],nums2 = [1, 2, 3, 4, 5, 6, 6, 5, 4, 3]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 7\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [6, 6, 6, 6, 1, 1, 1, 1]) == 1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [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]) == 10\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 2, 3, 4, 5, 6, 6, 6, 6]) == 3\n assert candidate(nums1 = [2, 3, 4, 5, 6],nums2 = [1, 1, 1, 1]) == 4\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = [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, 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 131\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]) == 2\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3],nums2 = [2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 6, 6, 6],nums2 = [3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1],nums2 = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 15\n assert candidate(nums1 = [1, 6, 1, 6, 1, 6, 1, 6, 1, 6],nums2 = [6, 1, 6, 1, 6, 1, 6, 1, 6, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 6]) == 2\n assert candidate(nums1 = [1, 1, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 9\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 = [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]) == 30\n assert candidate(nums1 = [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],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 14\n assert candidate(nums1 = [2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 3, 4, 5, 6]) == 3\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums1 = [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],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, 2, 2, 2, 2, 2, 2]) == 11\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 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 8\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]) == 5\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1],nums2 = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 3\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [3, 3, 3, 3, 3, 3]) == 1\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, 1, 1],nums2 = [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]) == 33\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],nums2 = [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(nums1 = [3, 3, 3, 3, 3, 3, 3],nums2 = [4, 4, 4, 4, 4, 4, 4]) == 3\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6],nums2 = [2, 3, 4, 5, 6, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 15\n assert candidate(nums1 = [4, 4, 4, 4, 4, 4, 4],nums2 = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums1 = [6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(nums1 = [4, 4, 4, 4, 4, 4],nums2 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums1 = [6, 4, 2, 6, 4, 2, 6, 4, 2],nums2 = [1, 3, 5, 1, 3, 5, 1, 3, 5]) == 2\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums1 = [1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5],nums2 = [2, 4, 6, 2, 4, 6, 2, 4, 6, 2, 4, 6]) == 3\n assert candidate(nums1 = [2, 3, 4],nums2 = [1, 5, 6, 6]) == 2\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [6, 6, 6, 6, 6]) == 2\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 6, 6, 6, 6, 6]) == 5\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 15\n assert candidate(nums1 = [1, 3, 5],nums2 = [2, 4, 6]) == 1\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],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]) == 7\n assert candidate(nums1 = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 1\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 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 20\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],nums2 = [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]) == 0\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 8\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5],nums2 = [1, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6, 6, 6, 6, 6, 6, 6]) == 7\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [4, 4, 5, 5, 6, 6]) == 4\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [6]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 8\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [4, 5, 6, 6, 6, 6, 6]) == 5\n assert candidate(nums1 = [6, 6, 6, 6, 6, 6],nums2 = [1, 1, 1, 1, 1, 1]) == 6\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6]\n[1,1,2,2,2,2]", "[1,1,1,1,1,1,1]\n[6]", "[6,6]\n[1]"], "hints": ["Let's note that we want to either decrease the sum of the array with a larger sum or increase the array's sum with the smaller sum.", "You can maintain the largest increase or decrease you can make in a binary search tree and each time get the maximum one."], "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-30T20:30:25+00:00", "tests_total": 138, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function minOperations($nums1, $nums2) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1776, "task_id": "car-fleet-ii", "difficulty": "Hard", "problem_description": "There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [position_i, speed_i] represents:\n\n- position_i is the distance between the i^th car and the beginning of the road in meters. It is guaranteed that position_i < position_{i+1}.\n- speed_i is the initial speed of the i^th car in meters per second.\n\nFor simplicity, cars can be considered as points moving along the number line. Two cars collide when they occupy the same position. Once a car collides with another car, they unite and form a single car fleet. The cars in the formed fleet will have the same position and the same speed, which is the initial speed of the slowest car in the fleet.\n\nReturn an array answer, where answer[i] is the time, in seconds, at which the i^th car collides with the next car, or -1 if the car does not collide with the next car. Answers within 10^-5 of the actual answers are accepted.\n\nExample 1:\n\nInput: cars = [[1,2],[2,1],[4,3],[7,2]]\nOutput: [1.00000,-1.00000,3.00000,-1.00000]\nExplanation: After exactly one second, the first car will collide with the second car, and form a car fleet with speed 1 m/s. After exactly 3 seconds, the third car will collide with the fourth car, and form a car fleet with speed 2 m/s.\n\nExample 2:\n\nInput: cars = [[3,4],[5,4],[6,3],[9,1]]\nOutput: [2.00000,1.00000,1.50000,-1.00000]\n\nConstraints:\n\n- 1 <= cars.length <= 10^5\n- 1 <= position_i, speed_i <= 10^6\n- position_i < position_{i+1}\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(cars=[[1, 4], [2, 3], [3, 2], [4, 1]]), [1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[1, 5], [3, 2], [5, 1]]), [0.6666666666666666, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]), [-1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[3, 4], [5, 4], [6, 3], [9, 1]]), [2.0, 1.0, 1.5, -1])\n assert answers_match(candidate(cars=[[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]), [-1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[5, 10], [10, 5], [15, 2], [20, 1]]), [1.0, 1.6666666666666667, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [3, 8], [5, 6], [7, 4], [9, 2]]), [1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]]), [-1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 2], [2, 1], [4, 3], [7, 2]]), [1.0, -1, 3.0, -1])\n assert answers_match(candidate(cars=[[10, 10], [8, 5], [6, 3], [4, 2], [2, 1]]), [-0.8888888888888888, -1.5, -2.0, -2.0, -1])\n assert answers_match(candidate(cars=[[10, 2], [20, 1], [30, 3], [40, 2]]), [10.0, -1, 10.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[5, 10], [15, 8], [20, 7], [25, 6], [30, 5]]), [5.0, 5.0, 5.0, 5.0, -1])\n assert answers_match(candidate(cars=[[10, 5], [20, 4], [30, 3], [40, 2], [50, 1]]), [10.0, 10.0, 10.0, 10.0, -1])\n assert answers_match(candidate(cars=[[10, 5], [15, 3], [20, 2], [25, 1]]), [2.5, 5.0, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]), [1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [3, 6], [5, 5], [7, 4]]), [0.5, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 20], [2, 18], [3, 16], [4, 14], [5, 12], [6, 10], [7, 8], [8, 6], [9, 4], [10, 2]]), [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -1])\n assert answers_match(candidate(cars=[[2, 9], [5, 7], [8, 6], [11, 4], [14, 2], [17, 1]]), [1.5, 1.8, 1.5, 1.5, 3.0, -1])\n assert answers_match(candidate(cars=[[10, 5], [20, 15], [30, 10], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45]]), [-1, 2.0, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[10, 90], [20, 80], [30, 70], [40, 60], [50, 50], [60, 40], [70, 30], [80, 20], [90, 10], [100, 1]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.1111111111111112, -1])\n assert answers_match(candidate(cars=[[1, 100], [10, 90], [20, 80], [30, 70], [40, 60], [50, 50], [60, 40], [70, 30], [80, 20], [90, 10]]), [0.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[50, 100], [150, 90], [250, 80], [350, 70], [450, 60], [550, 50], [650, 40], [750, 30], [850, 20], [950, 10]]), [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, -1])\n assert answers_match(candidate(cars=[[1, 25], [3, 24], [5, 23], [7, 22], [9, 21], [11, 20], [13, 19], [15, 18], [17, 17], [19, 16], [21, 15]]), [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [10, 9], [19, 8], [28, 7], [37, 6], [46, 5], [55, 4], [64, 3], [73, 2], [82, 1]]), [9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, -1])\n assert answers_match(candidate(cars=[[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11], [11, 10], [12, 9], [13, 8], [14, 7], [15, 6], [16, 5], [17, 4], [18, 3], [19, 2], [20, 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])\n assert answers_match(candidate(cars=[[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]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [12, 10], [14, 9], [16, 8], [18, 7], [20, 6], [22, 5], [24, 4], [26, 3], [28, 2], [30, 1]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]]), [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, -1])\n assert answers_match(candidate(cars=[[1, 50], [10, 45], [20, 40], [30, 35], [40, 30], [50, 25], [60, 20], [70, 15], [80, 10], [90, 5]]), [1.8, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 5], [2, 10], [3, 15], [4, 20], [5, 25], [6, 30], [7, 35], [8, 40], [9, 45], [10, 50]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 10], [4, 8], [7, 6], [10, 4], [13, 2], [16, 1]]), [1.5, 1.5, 1.5, 1.5, 3.0, -1])\n assert answers_match(candidate(cars=[[1, 8], [3, 7], [5, 6], [7, 5], [9, 4], [11, 3], [13, 2], [15, 1]]), [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 30], [4, 20], [7, 15], [10, 10], [13, 8], [16, 6], [19, 4], [22, 2], [25, 1]]), [0.3, 0.6, 0.6, 1.5, 1.5, 1.5, 1.5, 3.0, -1])\n assert answers_match(candidate(cars=[[1, 100], [10, 95], [20, 90], [30, 85], [40, 80], [50, 75], [60, 70], [70, 65], [80, 60], [90, 55]]), [1.8, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 15], [2, 25], [3, 35], [4, 45], [5, 55], [6, 65], [7, 75], [8, 85], [9, 95], [10, 105]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 5], [4, 4], [7, 3], [10, 2], [13, 1]]), [3.0, 3.0, 3.0, 3.0, -1])\n assert answers_match(candidate(cars=[[1, 100], [20, 50], [30, 30], [40, 20], [50, 10], [60, 1]]), [0.38, 0.5, 1.0, 1.0, 1.1111111111111112, -1])\n assert answers_match(candidate(cars=[[1, 15], [2, 10], [4, 5], [6, 4], [8, 3], [10, 2], [12, 1]]), [0.2, 0.4, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 3], [2, 2], [3, 1], [4, 4], [5, 5], [6, 6]]), [1.0, 1.0, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 200], [11, 180], [21, 160], [31, 140], [41, 120], [51, 100], [61, 80], [71, 60], [81, 40], [91, 20]]), [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -1])\n assert answers_match(candidate(cars=[[1, 5], [3, 4], [5, 3], [7, 2], [9, 1], [11, 10], [13, 9], [15, 8], [17, 7], [19, 6]]), [2.0, 2.0, 2.0, 2.0, -1, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[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]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 20], [4, 18], [7, 16], [10, 14], [13, 12], [16, 10], [19, 8], [22, 6], [25, 4], [28, 2], [31, 1]]), [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 3.0, -1])\n assert answers_match(candidate(cars=[[1, 100000], [2, 99000], [3, 98000], [4, 97000], [5, 96000], [6, 95000], [7, 94000], [8, 93000], [9, 92000], [10, 91000]]), [0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, -1])\n assert answers_match(candidate(cars=[[1, 100], [5, 80], [10, 60], [15, 40], [20, 20], [25, 10]]), [0.2, 0.25, 0.25, 0.25, 0.5, -1])\n assert answers_match(candidate(cars=[[1, 30], [2, 25], [3, 20], [5, 15], [8, 10], [13, 5], [20, 2], [28, 1]]), [0.2, 0.2, 0.4, 0.6, 1.0, 2.3333333333333335, 8.0, -1])\n assert answers_match(candidate(cars=[[1, 12], [3, 10], [5, 8], [7, 6], [9, 4], [11, 2]]), [1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 50], [2, 49], [3, 48], [4, 47], [5, 46], [6, 45], [7, 44], [8, 43], [9, 42], [10, 41]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[1, 5], [6, 10], [11, 5], [16, 10], [21, 5], [26, 10], [31, 5], [36, 10], [41, 5], [46, 10]]), [-1, 1.0, -1, 1.0, -1, 1.0, -1, 1.0, -1, -1])\n assert answers_match(candidate(cars=[[1, 200], [2, 190], [3, 180], [4, 170], [5, 160], [6, 150], [7, 140], [8, 130], [9, 120], [10, 110]]), [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, -1])\n assert answers_match(candidate(cars=[[1, 6], [3, 5], [5, 4], [7, 3], [9, 2], [11, 1], [13, 5], [15, 4], [17, 3], [19, 2], [21, 1]]), [2.0, 2.0, 2.0, 2.0, 2.0, -1, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 15], [5, 14], [10, 13], [15, 12], [20, 11], [25, 10], [30, 9], [35, 8], [40, 7], [45, 6], [50, 5], [55, 4], [60, 3], [65, 2], [70, 1]]), [4.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [5, 10], [10, 10], [15, 10], [20, 10], [25, 10], [30, 10], [35, 10], [40, 10], [45, 10]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 3], [5, 2], [10, 1], [15, 4], [20, 3], [25, 2], [30, 1]]), [4.0, 5.0, -1, 5.0, 5.0, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [2, 9], [5, 8], [8, 7], [13, 6], [18, 5], [24, 4], [30, 3], [36, 2], [42, 1]]), [1.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0, 6.0, 6.0, -1])\n assert answers_match(candidate(cars=[[1, 2], [2, 3], [3, 5], [4, 8], [5, 13], [6, 21], [7, 34], [8, 55], [9, 89], [10, 144]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 2], [3, 5], [5, 10], [7, 3], [9, 8], [11, 6], [13, 7], [15, 4]]), [-1, 2.0, 0.2857142857142857, -1, 1.0, 2.0, 0.6666666666666666, -1])\n assert answers_match(candidate(cars=[[3, 12], [6, 10], [9, 8], [12, 6], [15, 4], [18, 2], [21, 1]]), [1.5, 1.5, 1.5, 1.5, 1.5, 3.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [4, 9], [10, 8], [15, 7], [20, 6], [25, 5], [30, 4], [35, 3], [40, 2], [45, 1]]), [3.0, 5.125, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 20], [4, 18], [10, 16], [15, 14], [20, 12], [25, 10], [30, 8], [35, 6], [40, 4], [45, 2]]), [1.5, 2.5625, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, -1])\n assert answers_match(candidate(cars=[[1, 1], [10, 2], [20, 3], [30, 4], [40, 5], [50, 6], [60, 7], [70, 8], [80, 9], [90, 10]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 50], [5, 40], [10, 30], [16, 20], [23, 10], [31, 5], [40, 3], [50, 1]]), [0.4, 0.5, 0.6, 0.7, 1.6, 4.5, 5.0, -1])\n assert answers_match(candidate(cars=[[1, 1000], [2, 900], [3, 800], [4, 700], [5, 600], [6, 500], [7, 400], [8, 300], [9, 200], [10, 100]]), [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, -1])\n assert answers_match(candidate(cars=[[1, 20], [2, 18], [3, 16], [5, 14], [8, 12], [13, 10], [20, 8], [28, 6], [37, 4], [46, 2]]), [0.5, 0.5, 1.0, 1.5, 2.5, 3.5, 4.0, 4.5, 4.5, -1])\n assert answers_match(candidate(cars=[[1, 10], [2, 20], [3, 15], [4, 25], [5, 20], [6, 30], [7, 25], [8, 35], [9, 30], [10, 40]]), [-1, 0.2, -1, 0.2, -1, 0.2, -1, 0.2, -1, -1])\n assert answers_match(candidate(cars=[[10, 10], [20, 9], [30, 8], [40, 7], [50, 6], [60, 5], [70, 4], [80, 3], [90, 2], [100, 1]]), [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [11, 9], [21, 8], [31, 7], [41, 6], [51, 5], [61, 4], [71, 3], [81, 2], [91, 1]]), [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, -1])\n assert answers_match(candidate(cars=[[1, 10], [3, 10], [5, 10], [7, 10], [9, 10], [11, 10], [13, 10], [15, 10], [17, 10], [19, 10], [21, 10]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 30], [2, 29], [3, 28], [4, 27], [5, 26], [6, 25], [7, 24], [8, 23], [9, 22], [10, 21]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[10, 10], [25, 9], [40, 8], [55, 7], [70, 6], [85, 5], [100, 4], [115, 3], [130, 2], [145, 1]]), [15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, -1])\n assert answers_match(candidate(cars=[[1, 2], [5, 4], [9, 6], [13, 8], [17, 10], [21, 12], [25, 14], [29, 16], [33, 18], [37, 20]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 1], [100000, 100000], [200000, 99999], [300000, 99998], [400000, 99997], [500000, 99996]]), [-1, 100000.0, 100000.0, 100000.0, 100000.0, -1])\n assert answers_match(candidate(cars=[[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992], [10, 991]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[1, 50], [3, 45], [6, 40], [10, 35], [15, 30], [21, 25], [28, 20], [36, 15], [45, 10], [55, 5]]), [0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 100], [5, 90], [10, 80], [15, 70], [20, 60], [25, 50], [30, 40], [35, 30], [40, 20], [45, 10]]), [0.4, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -1])\n assert answers_match(candidate(cars=[[1, 10], [11, 9.99999], [21, 9.99998], [31, 9.99997], [41, 9.99996], [51, 9.99995], [61, 9.99994], [71, 9.99993], [81, 9.99992], [91, 9.99991]]), [999999.9999786458, 999999.9999490399, 999999.999860222, 1000000.0000023306, 999999.9999934488, 999999.9999786458, 999999.9999490399, 999999.999860222, 1000000.0000378577, -1])\n assert answers_match(candidate(cars=[[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]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.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 answers_match(candidate(cars=[[1, 15], [5, 10], [9, 7], [13, 4], [17, 2], [21, 1], [25, 3], [29, 6], [33, 9], [37, 12]]), [0.8, 1.3333333333333333, 1.3333333333333333, 2.0, 4.0, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 100], [20, 90], [30, 80], [40, 70], [50, 60], [60, 50], [70, 40], [80, 30], [90, 20], [100, 10]]), [1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1])\n assert answers_match(candidate(cars=[[10, 5], [20, 5], [30, 5], [40, 5], [50, 5], [60, 5], [70, 5], [80, 5], [90, 5], [100, 5]]), [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1])\n assert answers_match(candidate(cars=[[1, 150], [4, 130], [7, 110], [10, 90], [13, 70], [16, 50], [19, 30], [22, 10]]), [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, -1])\n assert answers_match(candidate(cars=[[1, 10], [3, 9], [6, 8], [10, 7], [15, 6], [21, 5], [28, 4], [36, 3], [45, 2], [55, 1]]), [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, -1])\n assert answers_match(candidate(cars=[[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]]), [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.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 answers_match(candidate(cars=[[1, 30], [4, 28], [7, 26], [10, 24], [13, 22], [16, 20], [19, 18], [22, 16], [25, 14], [28, 12], [31, 10], [34, 8], [37, 6], [40, 4], [43, 2]]), [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])\n assert answers_match(candidate(cars=[[1, 5], [5, 10], [9, 5], [13, 10], [17, 5], [21, 10], [25, 5], [29, 10], [33, 5], [37, 10]]), [-1, 0.8, -1, 0.8, -1, 0.8, -1, 0.8, -1, -1])\n assert answers_match(candidate(cars=[[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])\n assert answers_match(candidate(cars=[[1, 10], [2, 9.5], [3, 9], [4, 8.5], [5, 8], [6, 7.5], [7, 7], [8, 6.5], [9, 6], [10, 5.5], [11, 5]]), [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1])\n assert answers_match(candidate(cars=[[1, 15], [4, 12], [7, 9], [10, 6], [13, 3], [16, 2], [19, 1]]), [1.0, 1.0, 1.0, 1.0, 3.0, 3.0, -1])\n", "comparison": "float"}, "public_tests": ["[[1,2],[2,1],[4,3],[7,2]]", "[[3,4],[5,4],[6,3],[9,1]]"], "hints": ["We can simply ignore the merging of any car fleet, simply assume they cross each other. Now the aim is to find the first car to the right, which intersects with the current car before any other.", "Assume we have already considered all cars to the right already, now the current car is to be considered. Let’s ignore all cars with speeds higher than the current car since the current car cannot intersect with those ones. Now, all cars to the right having speed strictly less than current car are to be considered. Now, for two cars c1 and c2 with positions p1 and p2 (p1 < p2) and speed s1 and s2 (s1 > s2), if c1 and c2 intersect before the current car and c2, then c1 can never be the first car of intersection for any car to the left of current car including current car. So we can remove that car from our consideration.", "We can see that we can maintain candidate cars in this way using a stack, removing cars with speed greater than or equal to current car, and then removing cars which can never be first point of intersection. The first car after this process (if any) would be first point of intersection."], "metadata": {"canonical_parameter_names": ["cars"], "leetcode_dataset_entry_point": "Solution().getCollisionTimes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:28+00:00", "tests_total": 95, "tests_dropped": 4, "flags": ["decimal_answer"], "topic_tags": ["array", "math", "stack", "heap-priority-queue", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function getCollisionTimes($cars) {", "container": "Solution", "callable": "getCollisionTimes", "parameters": [{"name": "cars", "type": "Integer[][]"}], "return_type": "Float[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1779, "task_id": "find-nearest-point-that-has-the-same-x-or-y-coordinate", "difficulty": "Easy", "problem_description": "You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [a_i, b_i] represents that a point exists at (a_i, b_i). A point is valid if it shares the same x-coordinate or the same y-coordinate as your location.\n\nReturn the index (0-indexed) of the valid point with the smallest Manhattan distance from your current location. If there are multiple, return the valid point with the smallest index. If there are no valid points, return -1.\n\nThe Manhattan distance between two points (x_1, y_1) and (x_2, y_2) is abs(x_1 - x_2) + abs(y_1 - y_2).\n\nExample 1:\n\nInput: x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\nOutput: 2\nExplanation: Of all the points, only [3,1], [2,4] and [4,4] are valid. Of the valid points, [2,4] and [4,4] have the smallest Manhattan distance from your current location, with a distance of 1. [2,4] has the smallest index, so return 2.\n\nExample 2:\n\nInput: x = 3, y = 4, points = [[3,4]]\nOutput: 0\nExplanation: The answer is allowed to be on the same location as your current location.\n\nExample 3:\n\nInput: x = 3, y = 4, points = [[2,3]]\nOutput: -1\nExplanation: There are no valid points.\n\nConstraints:\n\n- 1 <= points.length <= 10^4\n- points[i].length == 2\n- 1 <= x, y, a_i, b_i <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(x = 3,y = 4,points = [[3, 4]]) == 0\n assert candidate(x = 5,y = 5,points = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4]]) == 3\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4]]) == -1\n assert candidate(x = 3,y = 4,points = [[2, 3]]) == -1\n assert candidate(x = 1,y = 1,points = [[1, 1], [1, 2], [1, 3], [2, 1], [3, 1]]) == 0\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == -1\n assert candidate(x = 1,y = 1,points = [[1, 1], [1, 2], [2, 1], [2, 2]]) == 0\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5]]) == -1\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 9\n assert candidate(x = 100,y = 100,points = [[50, 100], [100, 50], [150, 100], [100, 150]]) == 0\n assert candidate(x = 5,y = 5,points = [[1, 1], [5, 5], [3, 3], [4, 4]]) == 1\n assert candidate(x = 5,y = 5,points = [[5, 5], [5, 6], [6, 5], [6, 6]]) == 0\n assert candidate(x = 1,y = 10,points = [[1, 1], [1, 2], [1, 3], [1, 4]]) == 3\n assert candidate(x = 5,y = 5,points = [[1, 5], [5, 1], [5, 9], [9, 5], [5, 5]]) == 4\n assert candidate(x = 5,y = 5,points = [[5, 1], [5, 2], [5, 3], [5, 4], [1, 5], [2, 5], [3, 5], [4, 5]]) == 3\n assert candidate(x = 5,y = 5,points = [[10, 10], [5, 5], [1, 1]]) == 1\n assert candidate(x = 1,y = 1,points = [[1, 2], [1, 3], [1, 4], [2, 1], [3, 1]]) == 0\n assert candidate(x = 5,y = 5,points = [[5, 5], [6, 6], [7, 7]]) == 0\n assert candidate(x = 10,y = 10,points = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == -1\n assert candidate(x = 2,y = 3,points = [[2, 3], [1, 1], [3, 3], [4, 4]]) == 0\n assert candidate(x = 10,y = 1,points = [[1, 1], [2, 1], [3, 1], [4, 1]]) == 3\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [4, 4]]) == -1\n assert candidate(x = 3,y = 4,points = [[1, 2], [3, 1], [2, 4], [2, 3], [4, 4]]) == 2\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [10, 10]]) == 3\n assert candidate(x = 5,y = 5,points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 4\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1]]) == 0\n assert candidate(x = 1,y = 1,points = [[1, 1], [1, 1], [1, 1], [1, 1]]) == 0\n assert candidate(x = 7,y = 7,points = [[6, 7], [7, 6], [7, 8], [8, 7]]) == 0\n assert candidate(x = 3,y = 3,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, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 7\n assert candidate(x = 50,y = 50,points = [[49, 50], [51, 50], [50, 49], [50, 51], [48, 50], [52, 50], [50, 48], [50, 52]]) == 0\n assert candidate(x = 7,y = 8,points = [[7, 1], [1, 8], [7, 9], [9, 8], [7, 7], [8, 8]]) == 2\n assert candidate(x = 100,y = 100,points = [[99, 100], [100, 99], [101, 100], [100, 101], [98, 100], [100, 98]]) == 0\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 1], [4, 4], [5, 5], [1, 3], [3, 1]]) == 2\n assert candidate(x = 1,y = 2,points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 2]]) == 9\n assert candidate(x = 7,y = 7,points = [[1, 1], [1, 7], [7, 1], [7, 7], [2, 2], [6, 6], [3, 3], [5, 5], [4, 4], [8, 8]]) == 3\n assert candidate(x = 2000,y = 2000,points = [[2000, 1999], [1999, 2000], [2000, 2001], [2001, 2000], [2000, 2000], [2000, 2002], [2002, 2000]]) == 4\n assert candidate(x = 20,y = 20,points = [[20, 19], [19, 20], [21, 20], [20, 21], [20, 20], [19, 19]]) == 4\n assert candidate(x = 5,y = 5,points = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]) == 3\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1], [1, 5], [5, 1]]) == 0\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [1, 1]]) == 5\n assert candidate(x = 7,y = 7,points = [[1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [8, 7], [9, 7], [10, 7], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 8], [7, 9], [7, 10]]) == 5\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 1], [1, 2], [2, 1]]) == 9\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 10], [10, 2], [5, 5], [10, 10], [1, 10], [10, 1]]) == 4\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [10, 1], [10, 2], [10, 3], [1, 10], [2, 10], [3, 10]]) == 5\n assert candidate(x = 100,y = 100,points = [[100, 100], [100, 99], [99, 100], [100, 101], [101, 100], [99, 99], [101, 101]]) == 0\n assert candidate(x = 5000,y = 5000,points = [[5000, 4999], [4999, 5000], [5000, 5001], [5001, 5000], [4999, 4999], [5001, 5001]]) == 0\n assert candidate(x = 5000,y = 5000,points = [[4999, 5000], [5000, 4999], [5001, 5000], [5000, 5001], [5000, 5000]]) == 4\n assert candidate(x = 2000,y = 3000,points = [[2000, 2999], [2000, 3001], [1999, 3000], [2001, 3000], [2000, 3000]]) == 4\n assert candidate(x = 20,y = 20,points = [[20, 1], [1, 20], [19, 20], [20, 19], [20, 18], [20, 17], [20, 16], [20, 15], [20, 14], [20, 13], [20, 12], [20, 11], [20, 10], [20, 9], [20, 8], [20, 7], [20, 6], [20, 5], [20, 4], [20, 3], [20, 2]]) == 2\n assert candidate(x = 20,y = 20,points = [[15, 20], [20, 15], [25, 20], [20, 25], [10, 10], [30, 30]]) == 0\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 0\n assert candidate(x = 7,y = 7,points = [[7, 1], [1, 7], [7, 2], [2, 7], [7, 3], [3, 7], [7, 4], [4, 7], [7, 5], [5, 7], [7, 6], [6, 7], [7, 7]]) == 12\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5], [1, 1], [1, 2], [2, 1]]) == 4\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5], [1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == 4\n assert candidate(x = 2,y = 2,points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 1\n assert candidate(x = 1,y = 100,points = [[1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [2, 100], [3, 100], [4, 100], [5, 100], [6, 100]]) == 5\n assert candidate(x = 5,y = 5,points = [[5, 6], [6, 5], [5, 4], [4, 5], [5, 5], [5, 3], [3, 5], [5, 7], [7, 5]]) == 4\n assert candidate(x = 1000,y = 1000,points = [[1000, 1000], [999, 1000], [1000, 999], [999, 999], [998, 998], [997, 997], [996, 996], [995, 995], [994, 994], [993, 993]]) == 0\n assert candidate(x = 12,y = 15,points = [[10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19]]) == 2\n assert candidate(x = 7,y = 7,points = [[7, 8], [8, 7], [6, 7], [7, 6], [7, 9], [9, 7], [7, 7], [7, 5], [5, 7]]) == 6\n assert candidate(x = 20,y = 25,points = [[15, 25], [25, 20], [20, 15], [20, 30], [30, 20], [20, 20]]) == 0\n assert candidate(x = 10,y = 10,points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [10, 9], [8, 7], [6, 5], [4, 3], [2, 1]]) == 4\n assert candidate(x = 30,y = 40,points = [[30, 35], [25, 40], [30, 45], [35, 40], [30, 40], [25, 35]]) == 4\n assert candidate(x = 10,y = 10,points = [[5, 10], [15, 10], [10, 5], [10, 15], [10, 10]]) == 4\n assert candidate(x = 1,y = 1,points = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2]]) == -1\n assert candidate(x = 1,y = 1,points = [[2, 1], [3, 1], [4, 1], [5, 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]]) == 0\n assert candidate(x = 9,y = 9,points = [[9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9], [9, 10]]) == 8\n assert candidate(x = 3,y = 3,points = [[1, 3], [3, 1], [2, 3], [3, 2], [3, 3], [4, 3], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9]]) == 4\n assert candidate(x = 9999,y = 9999,points = [[9998, 9998], [9997, 9997], [9996, 9996], [9995, 9995], [9994, 9994], [9999, 9998], [9999, 9997], [9999, 9996], [9999, 9995], [9999, 9994], [9998, 9999], [9997, 9999], [9996, 9999], [9995, 9999], [9994, 9999]]) == 5\n assert candidate(x = 5,y = 5,points = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [1, 5], [2, 5], [3, 5], [4, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]) == 3\n assert candidate(x = 5000,y = 5000,points = [[1, 1], [10000, 10000], [5000, 1], [1, 5000], [5000, 5000], [4999, 4999], [5001, 5001]]) == 4\n assert candidate(x = 100,y = 1,points = [[50, 1], [60, 1], [70, 1], [80, 1], [90, 1], [100, 2], [100, 3], [100, 4], [100, 5], [100, 6]]) == 5\n assert candidate(x = 5000,y = 5000,points = [[4999, 5000], [5001, 5000], [5000, 4999], [5000, 5001], [4998, 5000], [5002, 5000], [5000, 4998], [5000, 5002]]) == 0\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1], [1, 5], [5, 1], [1, 6], [6, 1]]) == 0\n assert candidate(x = 50,y = 50,points = [[50, 50], [50, 49], [49, 50], [50, 48], [48, 50], [50, 47], [47, 50], [50, 46], [46, 50], [50, 45], [45, 50]]) == 0\n assert candidate(x = 2500,y = 7500,points = [[2500, 7499], [2500, 7501], [2499, 7500], [2501, 7500], [2498, 7500], [2502, 7500], [2500, 7498], [2500, 7502]]) == 0\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 1]]) == 4\n assert candidate(x = 1,y = 1,points = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 1], [2, 2], [3, 3]]) == 4\n assert candidate(x = 10,y = 10,points = [[5, 10], [10, 5], [10, 15], [15, 10], [10, 10], [11, 10], [10, 11], [9, 10], [10, 9]]) == 4\n assert candidate(x = 5,y = 5,points = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]) == 3\n assert candidate(x = 6,y = 6,points = [[5, 6], [6, 5], [7, 6], [6, 7], [6, 6], [5, 5], [7, 7], [5, 7], [7, 5]]) == 4\n assert candidate(x = 1,y = 1,points = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1], [1, 5], [5, 1], [1, 6], [6, 1]]) == 9\n assert candidate(x = 10,y = 10,points = [[10, 1], [1, 10], [10, 10], [5, 5], [10, 9], [9, 10]]) == 2\n assert candidate(x = 15,y = 20,points = [[10, 20], [15, 10], [20, 15], [15, 20], [10, 10], [20, 20]]) == 3\n assert candidate(x = 2,y = 2,points = [[2, 1], [1, 2], [3, 2], [2, 3], [1, 1], [3, 1], [1, 3], [3, 3], [2, 4], [4, 2], [4, 3], [3, 4], [4, 4]]) == 0\n assert candidate(x = 5,y = 5,points = [[5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 5], [7, 5], [8, 5], [9, 5]]) == 0\n assert candidate(x = 3,y = 3,points = [[1, 3], [2, 3], [4, 3], [5, 3], [6, 3], [7, 3], [8, 3], [9, 3], [10, 3], [3, 1], [3, 2], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10]]) == 1\n assert candidate(x = 7,y = 7,points = [[5, 7], [6, 8], [7, 9], [8, 6], [9, 5], [7, 7], [7, 8], [8, 7]]) == 5\n assert candidate(x = 100,y = 100,points = [[100, 50], [50, 100], [100, 60], [60, 100], [100, 70], [70, 100], [100, 80], [80, 100], [100, 90], [90, 100]]) == 8\n assert candidate(x = 7,y = 7,points = [[1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [8, 7], [9, 7], [10, 7]]) == 5\n assert candidate(x = 5000,y = 5000,points = [[5000, 5000], [5001, 5000], [4999, 5000], [5000, 5001], [5000, 4999]]) == 0\n assert candidate(x = 100,y = 100,points = [[99, 100], [100, 99], [100, 101], [101, 100], [98, 100], [100, 98], [99, 99], [101, 101]]) == 0\n assert candidate(x = 100,y = 100,points = [[50, 100], [100, 50], [150, 100], [100, 150], [100, 100]]) == 4\n assert candidate(x = 500,y = 500,points = [[500, 1], [1, 500], [500, 499], [499, 500], [10, 10], [490, 490], [50, 50], [1, 1], [500, 500]]) == 8\n assert candidate(x = 100,y = 100,points = [[100, 1], [1, 100], [99, 100], [100, 99], [10, 10], [90, 90], [50, 50], [1, 1], [100, 100]]) == 8\n assert candidate(x = 50,y = 50,points = [[50, 1], [50, 99], [1, 50], [99, 50], [50, 2], [2, 50], [50, 3], [3, 50], [50, 4], [4, 50]]) == 8\n assert candidate(x = 5000,y = 5000,points = [[4999, 4999], [5001, 5001], [4998, 5000], [5000, 4998], [5000, 5001], [5001, 5000], [4999, 5001], [5001, 4999]]) == 4\n assert candidate(x = 10,y = 10,points = [[1, 1], [2, 2], [3, 3], [10, 5], [5, 10], [10, 10]]) == 5\n assert candidate(x = 100,y = 100,points = [[99, 100], [100, 99], [98, 100], [100, 98], [99, 99], [101, 100], [100, 101]]) == 0\n assert candidate(x = 5000,y = 5000,points = [[1, 1], [10000, 10000], [5000, 1], [1, 5000], [5000, 5001], [5001, 5000]]) == 4\n assert candidate(x = 100,y = 100,points = [[100, 99], [99, 100], [101, 100], [100, 101], [100, 100]]) == 4\n assert candidate(x = 10,y = 10,points = [[10, 10], [9, 10], [10, 9], [11, 10], [10, 11], [9, 9], [11, 11]]) == 0\n assert candidate(x = 7,y = 7,points = [[6, 7], [8, 7], [7, 6], [7, 8], [5, 7], [7, 5], [9, 7], [7, 9], [7, 7], [6, 6], [8, 8]]) == 8\n assert candidate(x = 5000,y = 5000,points = [[5000, 5001], [5001, 5000], [4999, 5000], [5000, 4999], [5000, 5000], [1, 1], [10000, 10000]]) == 4\n assert candidate(x = 50,y = 50,points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == 4\n assert candidate(x = 3,y = 3,points = [[1, 3], [2, 3], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 3], [5, 3]]) == 4\n assert candidate(x = 10000,y = 10000,points = [[10000, 9999], [9999, 10000], [10000, 10000], [5000, 5000]]) == 2\n assert candidate(x = 25,y = 25,points = [[25, 10], [10, 25], [25, 15], [15, 25], [25, 20], [20, 25], [25, 5], [5, 25], [25, 30], [30, 25]]) == 4\n assert candidate(x = 15,y = 20,points = [[15, 1], [1, 20], [15, 3], [3, 20], [15, 4], [4, 20], [15, 5], [5, 20], [15, 6], [6, 20]]) == 9\n assert candidate(x = 20,y = 15,points = [[15, 20], [20, 15], [10, 10], [25, 25], [5, 5], [30, 30], [15, 15], [20, 20]]) == 1\n assert candidate(x = 10,y = 10,points = [[10, 1], [1, 10], [10, 10], [9, 10], [10, 9]]) == 2\n assert candidate(x = 8,y = 7,points = [[8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8], [8, 9], [8, 10]]) == 6\n", "comparison": "exact"}, "public_tests": ["3\n4\n[[1,2],[3,1],[2,4],[2,3],[4,4]]", "3\n4\n[[3,4]]", "3\n4\n[[2,3]]"], "hints": ["Iterate through each point, and keep track of the current point with the smallest Manhattan distance from your current location."], "metadata": {"canonical_parameter_names": ["x", "y", "points"], "leetcode_dataset_entry_point": "Solution().nearestValidPoint", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:30+00:00", "tests_total": 121, "tests_dropped": 9, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function nearestValidPoint($x, $y, $points) {", "container": "Solution", "callable": "nearestValidPoint", "parameters": [{"name": "x", "type": "Integer"}, {"name": "y", "type": "Integer"}, {"name": "points", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1780, "task_id": "check-if-number-is-a-sum-of-powers-of-three", "difficulty": "Medium", "problem_description": "Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.\n\nAn integer y is a power of three if there exists an integer x such that y == 3^x.\n\nExample 1:\n\nInput: n = 12\nOutput: true\nExplanation: 12 = 3^1 + 3^2\n\nExample 2:\n\nInput: n = 91\nOutput: true\nExplanation: 91 = 3^0 + 3^2 + 3^4\n\nExample 3:\n\nInput: n = 21\nOutput: false\n\nConstraints:\n\n- 1 <= n <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 59049) == True\n assert candidate(n = 3) == True\n assert candidate(n = 729) == True\n assert candidate(n = 12) == True\n assert candidate(n = 243) == True\n assert candidate(n = 21) == False\n assert candidate(n = 4782969) == True\n assert candidate(n = 19683) == True\n assert candidate(n = 1594323) == True\n assert candidate(n = 40) == True\n assert candidate(n = 59048) == False\n assert candidate(n = 1093) == True\n assert candidate(n = 10000000) == False\n assert candidate(n = 100000) == False\n assert candidate(n = 27) == True\n assert candidate(n = 6561) == True\n assert candidate(n = 3645) == False\n assert candidate(n = 2187) == True\n assert candidate(n = 177147) == True\n assert candidate(n = 91) == True\n assert candidate(n = 81) == True\n assert candidate(n = 531441) == True\n assert candidate(n = 1000000) == False\n assert candidate(n = 1000001) == False\n assert candidate(n = 9) == True\n assert candidate(n = 98415) == False\n assert candidate(n = 1) == True\n assert candidate(n = 10) == True\n assert candidate(n = 89076) == False\n assert candidate(n = 9999999) == False\n assert candidate(n = 98416) == False\n assert candidate(n = 39856) == False\n assert candidate(n = 1640261) == False\n assert candidate(n = 59050) == True\n assert candidate(n = 9876543) == False\n assert candidate(n = 32804) == False\n assert candidate(n = 819) == True\n assert candidate(n = 9841) == True\n assert candidate(n = 8) == False\n assert candidate(n = 810000) == False\n assert candidate(n = 8191) == False\n assert candidate(n = 72900) == False\n assert candidate(n = 524880) == False\n assert candidate(n = 7290) == True\n assert candidate(n = 11) == False\n assert candidate(n = 1048575) == False\n assert candidate(n = 59250) == False\n assert candidate(n = 109355) == False\n assert candidate(n = 10935) == False\n assert candidate(n = 98414) == False\n assert candidate(n = 2391484) == True\n assert candidate(n = 88572) == True\n assert candidate(n = 32805) == False\n assert candidate(n = 88573) == True\n assert candidate(n = 50000) == False\n assert candidate(n = 1049755) == False\n assert candidate(n = 590490) == True\n assert candidate(n = 4) == True\n assert candidate(n = 98411) == False\n assert candidate(n = 6560) == False\n assert candidate(n = 4100) == False\n assert candidate(n = 19684) == True\n assert candidate(n = 531442) == True\n assert candidate(n = 49308) == False\n assert candidate(n = 39858) == False\n assert candidate(n = 59047) == False\n assert candidate(n = 99018) == False\n assert candidate(n = 98409) == False\n assert candidate(n = 58324) == False\n assert candidate(n = 48619) == False\n assert candidate(n = 69192) == False\n assert candidate(n = 369059) == False\n assert candidate(n = 4052555) == False\n assert candidate(n = 1291401) == False\n assert candidate(n = 98413) == False\n assert candidate(n = 131220) == False\n assert candidate(n = 437400) == False\n assert candidate(n = 2) == False\n assert candidate(n = 4000000) == False\n assert candidate(n = 981) == True\n assert candidate(n = 97656) == False\n assert candidate(n = 3986) == False\n assert candidate(n = 19682) == False\n assert candidate(n = 797162) == False\n assert candidate(n = 656100) == False\n assert candidate(n = 45927) == False\n assert candidate(n = 79134) == False\n assert candidate(n = 1234567) == False\n assert candidate(n = 3125) == False\n assert candidate(n = 2097152) == False\n assert candidate(n = 98410) == False\n assert candidate(n = 99999) == False\n assert candidate(n = 728997) == False\n assert candidate(n = 405224) == False\n assert candidate(n = 31259) == False\n assert candidate(n = 119050) == False\n assert candidate(n = 104976) == False\n assert candidate(n = 546789) == False\n assert candidate(n = 39366) == False\n assert candidate(n = 40000) == False\n assert candidate(n = 29524) == True\n assert candidate(n = 98412) == False\n assert candidate(n = 400) == False\n assert candidate(n = 32806) == False\n assert candidate(n = 3188646) == False\n assert candidate(n = 123456) == False\n", "comparison": "exact"}, "public_tests": ["12", "91", "21"], "hints": ["Let's note that the maximum power of 3 you'll use in your soln is 3^16", "The number can not be represented as a sum of powers of 3 if it's ternary presentation has a 2 in it"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().checkPowersOfThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:33+00:00", "tests_total": 110, "tests_dropped": 4, "flags": [], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function checkPowersOfThree($n) {", "container": "Solution", "callable": "checkPowersOfThree", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1781, "task_id": "sum-of-beauty-of-all-substrings", "difficulty": "Medium", "problem_description": "The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.\n\n- For example, the beauty of \"abaacc\" is 3 - 1 = 2.\n\nGiven a string s, return the sum of beauty of all of its substrings.\n\nExample 1:\n\nInput: s = \"aabcb\"\nOutput: 5\nExplanation: The substrings with non-zero beauty are [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"], each with beauty equal to 1.\n\nExample 2:\n\nInput: s = \"aabcbaa\"\nOutput: 17\n\nConstraints:\n\n- 1 <= s.length <=500\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzzxyzzxyzz\") == 87\n assert candidate(s = \"aaabbbccc\") == 29\n assert candidate(s = \"aabcb\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"abcdedcba\") == 16\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"abcabcabc\") == 16\n assert candidate(s = \"zzzz\") == 0\n assert candidate(s = \"aabcbaa\") == 17\n assert candidate(s = \"pqrspqrspqrspqrs\") == 63\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 0\n assert candidate(s = \"xyzxyzxyz\") == 16\n assert candidate(s = \"abcdabcdabcd\") == 30\n assert candidate(s = \"abc\") == 0\n assert candidate(s = \"xyzzxyzz\") == 25\n assert candidate(s = \"abcd\") == 0\n assert candidate(s = \"aabbccddeeff\") == 40\n assert candidate(s = \"zzzzz\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 950\n assert candidate(s = \"abcdefg\") == 0\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiii\") == 1112\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 432\n assert candidate(s = \"pqrstuvwxyzabcdefghijklmno\") == 0\n assert candidate(s = \"abccbaabccbaabccbaabccba\") == 222\n assert candidate(s = \"verycomplicatedstringwithrepeatedcharactersrepeatedrepeated\") == 5556\n assert candidate(s = \"mississippimississippimississippimississippi\") == 4387\n assert candidate(s = \"abracadabra\") == 64\n assert candidate(s = \"abacabadabacabadabacabadabacabad\") == 2236\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacaba\") == 11131\n assert candidate(s = \"abcabcabcabc\") == 33\n assert candidate(s = \"xzyxzxyzxyz\") == 34\n assert candidate(s = \"abcdefabcdeabcdeabcde\") == 183\n assert candidate(s = \"aabacababa\") == 66\n assert candidate(s = \"zzzzzzzzzz\") == 0\n assert candidate(s = \"abcdefghijklmabcdefghijklm\") == 90\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 1170\n assert candidate(s = \"abababababababababababababababab\") == 240\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabc\") == 456\n assert candidate(s = \"mississippiissiippiisppiiiiiiii\") == 1732\n assert candidate(s = \"abacabadabacabadabacabadabacaba\") == 2047\n assert candidate(s = \"thisisaverylongandcomplicatedstringwithvariouscharacters\") == 2645\n assert candidate(s = \"mnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == 325\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 513\n assert candidate(s = \"kayak\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 261\n assert candidate(s = \"xyzzzzxyzzzzxyzzzzxyzzzz\") == 1254\n assert candidate(s = \"ababababababab\") == 42\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\") == 1\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdef\") == 400\n assert candidate(s = \"abcdabcdabcdabcd\") == 63\n assert candidate(s = \"level\") == 4\n assert candidate(s = \"ppppppppppppppppppppppppppppppppppqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\") == 13090\n assert candidate(s = \"xyzzyxzyxzyzyx\") == 87\n assert candidate(s = \"pqrsrstsrqpqrs\") == 102\n assert candidate(s = \"madam\") == 4\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 1053\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwerty\") == 21\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 2450\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggg\") == 630\n assert candidate(s = \"abacabadabacaba\") == 231\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\") == 702\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 44628\n assert candidate(s = \"xyzzazxzy\") == 45\n assert candidate(s = \"abababababababababababababababababababababababab\") == 552\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbcccccccccc\") == 1275\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 1350\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjaabbccddeeffgghhiijjaabbccddeeffgghhiijj\") == 2118\n assert candidate(s = \"bananaananabananananabananananananananananananana\") == 7610\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"banana\") == 8\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzz\") == 11722\n assert candidate(s = \"mnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrsmnopqrs\") == 1071\n assert candidate(s = \"aabbccddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxxyyyzzz\") == 4312\n assert candidate(s = \"aaaaabbbbccccddddeeeffffggghhh\") == 782\n assert candidate(s = \"nnnnoonnmnmlmllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\") == 33629\n assert candidate(s = \"aaaabbbbccccdddd\") == 162\n assert candidate(s = \"abacabadabacabadabacabad\") == 948\n assert candidate(s = \"deified\") == 9\n assert candidate(s = \"zzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"repaper\") == 9\n assert candidate(s = \"xyzzzzzxyzzzzzxyzzzzzxyzzzzzxyzzzzzxyzzzzzxyzzzzzxyzzzzz\") == 17541\n assert candidate(s = \"aabbaaabbbaaabbaaaabbbaaabbaaaabbbaaabbaaaabbbaaabbaaaab\") == 5129\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzz\") == 11950\n assert candidate(s = \"aabbccddeeffgghhiijjanmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 1979\n assert candidate(s = \"abababababababababababab\") == 132\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 350\n assert candidate(s = \"rotor\") == 4\n assert candidate(s = \"racecar\") == 9\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 320\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 161\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 350\n assert candidate(s = \"reviled\") == 4\n assert candidate(s = \"mnopqrnopqmonmnopq\") == 145\n assert candidate(s = \"abacabadaba\") == 85\n assert candidate(s = \"mississippi\") == 64\n assert candidate(s = \"aaaaabbbbccccddddeeeffffgggghhhhiiiiijjjjkkkkllllmmmmmnnnnnooooo\") == 4941\n assert candidate(s = \"abcabcabcabcabc\") == 56\n assert candidate(s = \"xyzzzzzxyzzzzzxyzzzzz\") == 936\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"refer\") == 4\n", "comparison": "exact"}, "public_tests": ["\"aabcb\"", "\"aabcbaa\""], "hints": ["Maintain a prefix sum for the frequencies of characters.", "You can iterate over all substring then iterate over the alphabet and find which character appears most and which appears least using the prefix sum array"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().beautySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:35+00:00", "tests_total": 103, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function beautySum($s) {", "container": "Solution", "callable": "beautySum", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1782, "task_id": "count-pairs-of-nodes", "difficulty": "Hard", "problem_description": "You are given an undirected graph defined by an integer n, the number of nodes, and a 2D integer array edges, the edges in the graph, where edges[i] = [u_i, v_i] indicates that there is an undirected edge between u_i and v_i. You are also given an integer array queries.\n\nLet incident(a, b) be defined as the number of edges that are connected to either node a or b.\n\nThe answer to the j^th query is the number of pairs of nodes (a, b) that satisfy both of the following conditions:\n\n- a < b\n- incident(a, b) > queries[j]\n\nReturn an array answers such that answers.length == queries.length and answers[j] is the answer of the j^th query.\n\nNote that there can be multiple edges between the same two nodes.\n\nExample 1:\n\nInput: n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\nOutput: [6,5]\nExplanation: The calculations for incident(a, b) are shown in the table above.\nThe answers for each of the queries are as follows:\n- answers[0] = 6. All the pairs have an incident(a, b) value greater than 2.\n- answers[1] = 5. All the pairs except (3, 4) have an incident(a, b) value greater than 3.\n\nExample 2:\n\nInput: n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\nOutput: [10,10,9,8,6]\n\nConstraints:\n\n- 2 <= n <= 2 * 10^4\n- 1 <= edges.length <= 10^5\n- 1 <= u_i, v_i <= n\n- u_i!= v_i\n- 1 <= queries.length <= 20\n- 0 <= queries[j] < edges.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2], [2, 4], [1, 3], [2, 3], [2, 1]],queries = [2, 3]) == [6, 5]\n assert candidate(n = 5,edges = [[1, 5], [1, 5], [3, 4], [2, 5], [1, 3], [5, 1], [2, 3], [2, 5]],queries = [1, 2, 3, 4, 5]) == [10, 10, 9, 8, 6]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [9, 10]],queries = [5, 10, 15]) == [45, 8, 0]\n assert candidate(n = 20,edges = [[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, 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]],queries = [3, 4, 5, 6]) == [190, 187, 183, 148]\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15]],queries = [7, 8, 9, 10, 11]) == [75, 69, 24, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]],queries = [3, 5, 7, 9]) == [41, 33, 1, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10]],queries = [5, 6, 7]) == [16, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]],queries = [1, 5, 9]) == [45, 0, 0]\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6], [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, 7]],queries = [3, 8, 13]) == [176, 15, 0]\n assert candidate(n = 100,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 1], [10, 2], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 1], [9, 2], [10, 3], [1, 4], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 1], [8, 2], [9, 3], [10, 4]],queries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [945, 945, 945, 945, 945, 945, 945, 765, 45, 45, 45]\n assert candidate(n = 20,edges = [[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], [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, 16], [2, 17], [2, 18], [2, 19], [2, 20], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [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, 20]],queries = [5, 15, 25, 35, 45]) == [190, 85, 10, 10, 0]\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [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], [1, 8], [2, 9], [3, 10], [4, 11], [5, 12], [6, 13], [7, 14], [8, 15]],queries = [10, 12, 14]) == [12, 0, 0]\n assert candidate(n = 30,edges = [[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, 1], [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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 26], [25, 27], [26, 28], [27, 29], [28, 30], [29, 1], [30, 2]],queries = [15, 20, 25, 30, 35]) == [0, 0, 0, 0, 0]\n assert candidate(n = 25,edges = [[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], [1, 25], [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, 21], [20, 22], [21, 23], [22, 24], [23, 25]],queries = [4, 9, 14]) == [300, 0, 0]\n assert candidate(n = 25,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15], [14, 16], [15, 16], [15, 17], [16, 17], [16, 18], [17, 18], [17, 19], [18, 19], [19, 20], [19, 21], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23], [22, 23], [22, 24], [22, 25], [23, 24], [23, 25], [24, 25]],queries = [6, 12, 18, 24]) == [283, 0, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10], [2, 5], [3, 7], [4, 8], [5, 9], [6, 10]],queries = [4, 5, 6, 7, 8]) == [43, 28, 4, 0, 0]\n assert candidate(n = 30,edges = [[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], [2, 30], [3, 29], [4, 28], [5, 27], [6, 26], [7, 25], [8, 24], [9, 23], [10, 22], [11, 21], [12, 20], [13, 19], [14, 18], [15, 17], [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]],queries = [20, 25, 30, 35, 40, 45]) == [29, 29, 14, 0, 0, 0]\n assert candidate(n = 30,edges = [[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], [1, 30], [2, 29], [3, 28], [4, 27], [5, 26], [6, 25], [7, 24], [8, 23], [9, 22], [10, 21], [11, 20], [12, 19], [13, 18], [14, 17], [15, 16]],queries = [0, 5, 10, 15, 20, 25, 30]) == [435, 338, 0, 0, 0, 0, 0]\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [13, 14], [13, 15], [14, 15], [14, 16], [15, 16], [15, 17], [16, 17], [16, 18], [17, 18], [17, 19], [18, 19], [19, 20], [20, 1]],queries = [5, 10, 15, 20]) == [184, 0, 0, 0]\n assert candidate(n = 50,edges = [[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, 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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 26], [25, 27], [26, 28], [27, 29], [28, 30], [29, 31], [30, 32], [31, 33], [32, 34], [33, 35], [34, 36], [35, 37], [36, 38], [37, 39], [38, 40], [39, 41], [40, 42], [41, 43], [42, 44], [43, 45], [44, 46], [45, 47], [46, 48], [47, 49], [48, 50]],queries = [10, 20, 30, 40, 50]) == [0, 0, 0, 0, 0]\n assert candidate(n = 12,edges = [[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, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12], [11, 1], [12, 2]],queries = [3, 4, 5, 6, 7]) == [66, 66, 66, 66, 42]\n assert candidate(n = 25,edges = [[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, 1], [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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 1], [25, 2], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15], [13, 16], [14, 17], [15, 18], [16, 19], [17, 20], [18, 21], [19, 22], [20, 23], [21, 24], [22, 25], [23, 1], [24, 2], [25, 3]],queries = [10, 15, 20, 25, 30]) == [300, 0, 0, 0, 0]\n assert candidate(n = 15,edges = [[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], [1, 8], [2, 9], [3, 10], [4, 11], [5, 12], [6, 13], [7, 14], [8, 15], [9, 1], [10, 2], [11, 3], [12, 4], [13, 5], [14, 6], [15, 7]],queries = [10, 15, 20, 25]) == [0, 0, 0, 0]\n assert candidate(n = 15,edges = [[1, 2], [1, 2], [1, 3], [2, 3], [2, 3], [2, 4], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6], [5, 7], [6, 7], [6, 8], [7, 8], [7, 9], [8, 9], [8, 10], [9, 10], [9, 11], [10, 11], [10, 12], [11, 12], [11, 13], [12, 13], [12, 14], [13, 14], [13, 15], [14, 15]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [105, 105, 105, 104, 102, 89, 51, 17, 0, 0]\n assert candidate(n = 20,edges = [[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]],queries = [3, 4, 5, 6, 7, 8]) == [136, 0, 0, 0, 0, 0]\n assert candidate(n = 18,edges = [[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, 1], [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, 1], [18, 2]],queries = [5, 10, 15, 20]) == [153, 0, 0, 0]\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], [8, 15], [1, 15], [2, 15], [3, 15], [4, 15]],queries = [8, 9, 10, 11]) == [6, 0, 0, 0]\n assert candidate(n = 100,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 5], [2, 6], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 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]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [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], [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]],queries = [5, 10, 15, 20, 25]) == [187, 0, 0, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [9, 10]],queries = [5, 10, 15]) == [45, 8, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],queries = [5, 6, 7]) == [8, 0, 0]\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [6, 10], [7, 8], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [11, 15], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15]],queries = [10, 20, 30, 40]) == [91, 0, 0, 0]\n assert candidate(n = 8,edges = [[1, 2], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]],queries = [1, 2, 3, 4, 5]) == [28, 28, 28, 28, 28]\n assert candidate(n = 20,edges = [[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, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [1, 12], [2, 13], [3, 14], [4, 15], [5, 16], [6, 17], [7, 18], [8, 19], [9, 20]],queries = [10, 15, 20, 25]) == [0, 0, 0, 0]\n assert candidate(n = 30,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13], [12, 14], [12, 15], [13, 14], [13, 15], [14, 15], [14, 16], [15, 16], [15, 17], [16, 17], [16, 18], [17, 18], [17, 19], [18, 19], [19, 20], [19, 21], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23], [22, 23], [22, 24], [22, 25], [23, 24], [23, 25], [24, 25], [24, 26], [24, 27], [25, 26], [25, 27], [26, 27], [26, 28], [26, 29], [27, 28], [27, 29], [28, 29], [28, 30], [29, 30]],queries = [7, 14, 21, 28]) == [360, 0, 0, 0]\n assert candidate(n = 25,edges = [[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, 1], [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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 1], [25, 2]],queries = [15, 20, 25, 30]) == [0, 0, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],queries = [5, 10, 15]) == [36, 0, 0]\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 1]],queries = [4, 8, 12, 16]) == [76, 1, 0, 0]\n assert candidate(n = 30,edges = [[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, 1], [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, 21], [20, 22], [21, 23], [22, 24], [23, 25], [24, 26], [25, 27], [26, 28], [27, 29], [28, 30]],queries = [5, 10, 15]) == [432, 0, 0]\n assert candidate(n = 15,edges = [[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], [1, 15]],queries = [2, 7, 12]) == [105, 0, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 5], [2, 6], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]],queries = [5, 6, 7]) == [19, 4, 0]\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]],queries = [5, 10, 15]) == [24, 7, 0]\n assert candidate(n = 15,edges = [[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], [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], [15, 2], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15], [13, 1], [14, 2], [15, 3]],queries = [10, 15, 20, 25, 30]) == [105, 0, 0, 0, 0]\n assert candidate(n = 20,edges = [[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, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11]],queries = [0, 5, 10, 15, 20]) == [190, 128, 0, 0, 0]\n assert candidate(n = 15,edges = [[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], [1, 15], [2, 14], [3, 13], [4, 12], [5, 11], [6, 10], [7, 9]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [105, 105, 104, 98, 50, 0, 0, 0, 0, 0]\n", "comparison": "exact"}, "public_tests": ["4\n[[1,2],[2,4],[1,3],[2,3],[2,1]]\n[2,3]", "5\n[[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]]\n[1,2,3,4,5]"], "hints": ["We want to count pairs (x,y) such that degree[x] + degree[y] - occurrences(x,y) > k", "Think about iterating on x, and counting the number of valid y to pair with x.", "You can consider at first that the (- occurrences(x,y)) isn't there, or it is 0 at first for all y. Count the valid y this way.", "Then you can iterate on the neighbors of x, let that neighbor be y, and update occurrences(x,y).", "When you update occurrences(x,y), the left-hand side decreases. Once it reaches k, then y is not valid for x anymore, so you should decrease the answer by 1."], "metadata": {"canonical_parameter_names": ["n", "edges", "queries"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:37+00:00", "tests_total": 50, "tests_dropped": 5, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "two-pointers", "binary-search", "graph", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function countPairs($n, $edges, $queries) {", "container": "Solution", "callable": "countPairs", "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": 1784, "task_id": "check-if-binary-string-has-at-most-one-segment-of-ones", "difficulty": "Easy", "problem_description": "Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false.\n\nExample 1:\n\nInput: s = \"1001\"\nOutput: false\nExplanation: The string has two segments of size 1.\n\nExample 2:\n\nInput: s = \"110\"\nOutput: true\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s[i] is either '0' or '1'.\n- s[0] is '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == True\n assert candidate(s = \"1000001\") == False\n assert candidate(s = \"111\") == True\n assert candidate(s = \"11110000\") == True\n assert candidate(s = \"100000\") == True\n assert candidate(s = \"11000\") == True\n assert candidate(s = \"111000\") == True\n assert candidate(s = \"1001001\") == False\n assert candidate(s = \"1111111111\") == True\n assert candidate(s = \"100001\") == False\n assert candidate(s = \"1000000000\") == True\n assert candidate(s = \"101\") == False\n assert candidate(s = \"10\") == True\n assert candidate(s = \"110\") == True\n assert candidate(s = \"110001\") == False\n assert candidate(s = \"1010101010\") == False\n assert candidate(s = \"1\") == True\n assert candidate(s = \"1100111\") == False\n assert candidate(s = \"101010\") == False\n assert candidate(s = \"111110000\") == True\n assert candidate(s = \"1001\") == False\n assert candidate(s = \"11001\") == False\n assert candidate(s = \"101010101010101\") == False\n assert candidate(s = \"1000000000000000000000000000000000000000000000000000001\") == False\n assert candidate(s = \"11110000001\") == False\n assert candidate(s = \"111000111000111000111000111000111000111000111000111\") == False\n assert candidate(s = \"111000111000111000\") == False\n assert candidate(s = \"1000000000000000000000000001\") == False\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\") == False\n assert candidate(s = \"1000010001000100\") == False\n assert candidate(s = \"10000000000000000000000000000000000000000000000001\") == False\n assert candidate(s = \"1111111\") == True\n assert candidate(s = \"111000111000111\") == False\n assert candidate(s = \"111111111111111111111\") == True\n assert candidate(s = \"1100110011\") == False\n assert candidate(s = \"11100000000000\") == True\n assert candidate(s = \"1010101010101010\") == False\n assert candidate(s = \"10000000000000000000\") == True\n assert candidate(s = \"111100000000\") == True\n assert candidate(s = \"11110001\") == False\n assert candidate(s = \"1111111111111110000000000001111111111111\") == False\n assert candidate(s = \"11110000111100001111\") == False\n assert candidate(s = \"101010101010\") == False\n assert candidate(s = \"111000000000000000000\") == True\n assert candidate(s = \"111111111111110000000000000\") == True\n assert candidate(s = \"100000000000100000\") == False\n assert candidate(s = \"100000000000\") == True\n assert candidate(s = \"1110001\") == False\n assert candidate(s = \"1111111111111111\") == True\n assert candidate(s = \"1001001001\") == False\n assert candidate(s = \"1000000000000000000000000000000000000001\") == False\n assert candidate(s = \"100000000000000000000000000000000000000000000000000000\") == True\n assert candidate(s = \"1111111000000\") == True\n assert candidate(s = \"111011101110111011101\") == False\n assert candidate(s = \"100000000000000000001\") == False\n assert candidate(s = \"11100000000111\") == False\n assert candidate(s = \"100000000001\") == False\n assert candidate(s = \"1001001001001001\") == False\n assert candidate(s = \"100000000000000\") == True\n assert candidate(s = \"10000000001\") == False\n assert candidate(s = \"111000111000\") == False\n assert candidate(s = \"10111000110\") == False\n assert candidate(s = \"111100001111\") == False\n assert candidate(s = \"100010001000100010001\") == False\n assert candidate(s = \"1000000000000000\") == True\n assert candidate(s = \"111110111111\") == False\n assert candidate(s = \"111111000000\") == True\n assert candidate(s = \"11011011011011011011\") == False\n assert candidate(s = \"1000000000000000000000000000000000000000000000000001\") == False\n assert candidate(s = \"11010101010101\") == False\n assert candidate(s = \"11111000001\") == False\n assert candidate(s = \"1000100010\") == False\n assert candidate(s = \"1110000000000001\") == False\n assert candidate(s = \"10000000100000001\") == False\n assert candidate(s = \"100000010000001000000\") == False\n assert candidate(s = \"10000100001\") == False\n assert candidate(s = \"1110000000\") == True\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == True\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111\") == True\n assert candidate(s = \"10101010101010101\") == False\n assert candidate(s = \"11100000000000000000000000000000000000000000000000\") == True\n assert candidate(s = \"1111000011110000\") == False\n assert candidate(s = \"10101010101010101010101010101010\") == False\n assert candidate(s = \"1111100000\") == True\n assert candidate(s = \"1111000000001111\") == False\n assert candidate(s = \"11110000100001110000\") == False\n assert candidate(s = \"1101101101\") == False\n assert candidate(s = \"1001001001001\") == False\n assert candidate(s = \"1110111100001\") == False\n assert candidate(s = \"110001000000\") == False\n assert candidate(s = \"111111111100\") == True\n assert candidate(s = \"1100000000000001\") == False\n assert candidate(s = \"10000000000000000000000000000000000000000000000000\") == True\n assert candidate(s = \"11001100110011\") == False\n assert candidate(s = \"1110000000000000000000000000000000000000000000000000\") == True\n assert candidate(s = \"11000001111\") == False\n assert candidate(s = \"11111111110000000000000000000000000000000000000000\") == True\n assert candidate(s = \"1111000011\") == False\n assert candidate(s = \"10101010101010101010\") == False\n assert candidate(s = \"10000111111110\") == False\n assert candidate(s = \"10000111110001\") == False\n assert candidate(s = \"10101010101010\") == False\n assert candidate(s = \"1000001000001000001\") == False\n assert candidate(s = \"1000000010000\") == False\n assert candidate(s = \"10000000000001\") == False\n assert candidate(s = \"11100001\") == False\n assert candidate(s = \"1000000000000001\") == False\n", "comparison": "exact"}, "public_tests": ["\"1001\"", "\"110\""], "hints": ["It's guaranteed to have at least one segment", "The string size is small so you can count all segments of ones with no that have no adjacent ones."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().checkOnesSegment", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:40+00:00", "tests_total": 113, "tests_dropped": 6, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function checkOnesSegment($s) {", "container": "Solution", "callable": "checkOnesSegment", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1785, "task_id": "minimum-elements-to-add-to-form-a-given-sum", "difficulty": "Medium", "problem_description": "You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.\n\nReturn the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.\n\nNote that abs(x) equals x if x >= 0, and -x otherwise.\n\nExample 1:\n\nInput: nums = [1,-1,1], limit = 3, goal = -4\nOutput: 2\nExplanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.\n\nExample 2:\n\nInput: nums = [1,-10,9,1], limit = 100, goal = 0\nOutput: 1\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= limit <= 10^6\n- -limit <= nums[i] <= limit\n- -10^9 <= goal <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, -1, 1],limit = 3,goal = -4) == 2\n assert candidate(nums = [1, -10, 9, 1],limit = 100,goal = 0) == 1\n assert candidate(nums = [0, 0, 0],limit = 1,goal = 3) == 3\n assert candidate(nums = [0, 0, 0, 0],limit = 5,goal = 10) == 2\n assert candidate(nums = [2, 2, 2],limit = 2,goal = 6) == 0\n assert candidate(nums = [-5, -5, -5],limit = 5,goal = 15) == 6\n assert candidate(nums = [999999, -999999, 999998, -999998, 999997, -999997],limit = 1000000,goal = -1000000) == 1\n assert candidate(nums = [1000000, -1000000, 500000, -500000],limit = 1000000,goal = 0) == 0\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 2,goal = -15) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1,goal = -10) == 20\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000],limit = 1000000,goal = 0) == 5\n assert candidate(nums = [5, -5, 5, -5, 5, -5],limit = 5,goal = 10) == 2\n assert candidate(nums = [999999, 999999, 999999],limit = 1000000,goal = -2999997) == 6\n assert candidate(nums = [999999, -999999, 999999, -999999, 999999, -999999],limit = 1000000,goal = 0) == 0\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 1,goal = -20) == 10\n assert candidate(nums = [1000000, -1000000, 1000000],limit = 1000000,goal = 3000000) == 2\n assert candidate(nums = [999999, 999998, 999997, 999996],limit = 999999,goal = 3999990) == 0\n assert candidate(nums = [1000000, -1000000, 500000],limit = 1000000,goal = 0) == 1\n assert candidate(nums = [1000, -1000, 1000, -1000],limit = 1000,goal = 1000) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],limit = 10,goal = 55) == 0\n assert candidate(nums = [5, -5, 5, -5, 5],limit = 10,goal = -15) == 2\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 1,goal = -5) == 5\n assert candidate(nums = [100, -50, 25],limit = 100,goal = 200) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1,goal = 15) == 5\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5],limit = 5,goal = -10) == 2\n assert candidate(nums = [1000000, -1000000, 500000],limit = 1000000,goal = 1000000) == 1\n assert candidate(nums = [-100, 100, -100, 100],limit = 100,goal = 0) == 0\n assert candidate(nums = [-100000, 100000, -100000, 100000, -100000],limit = 100000,goal = 50000) == 2\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],limit = 1,goal = 5) == 5\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],limit = 100000,goal = 600000) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1,goal = 10) == 0\n assert candidate(nums = [5, -5, 5, -5],limit = 5,goal = 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],limit = 1,goal = 1) == 1\n assert candidate(nums = [-5, 5, -5, 5, -5],limit = 5,goal = 0) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],limit = 10,goal = 0) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 5,goal = 10) == 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],limit = 10,goal = 0) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],limit = 1,goal = 0) == 0\n assert candidate(nums = [-999999, -999999, -999999],limit = 1000000,goal = 2999997) == 6\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 1,goal = -15) == 5\n assert candidate(nums = [-1, -1, -1, -1, -1],limit = 3,goal = 5) == 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],limit = 2,goal = 0) == 0\n assert candidate(nums = [1, -1, 1, -1, 1],limit = 1,goal = -1) == 2\n assert candidate(nums = [-5, 3, 2, -4, 1],limit = 5,goal = -10) == 2\n assert candidate(nums = [999999, -999999, 999999, -999999, 999999],limit = 1000000,goal = 4999995) == 4\n assert candidate(nums = [-1, 0, 1],limit = 1,goal = -1000000) == 1000000\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 2,goal = -30) == 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],limit = 3,goal = 20) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1,goal = 5) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 1,goal = 20) == 10\n assert candidate(nums = [-999999, -999999, -999999, -999999, -999999],limit = 1000000,goal = -5000000) == 1\n assert candidate(nums = [1, -2, 3, -4, 5],limit = 5,goal = 0) == 1\n assert candidate(nums = [999999, 999999, 999999, 999999, 999999],limit = 1000000,goal = 5000000) == 1\n assert candidate(nums = [-1000000, -1000000, -1000000, -1000000, -1000000],limit = 1000000,goal = 0) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],limit = 10,goal = 5) == 1\n assert candidate(nums = [-999999, -999998, -999997, -999996],limit = 999999,goal = -3999990) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],limit = 10,goal = -55) == 0\n assert candidate(nums = [500000, 500000, 500000, 500000, 500000],limit = 1000000,goal = 500000) == 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],limit = 1000000,goal = 10000000) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],limit = 100,goal = 500) == 5\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],limit = 2,goal = -20) == 5\n", "comparison": "exact"}, "public_tests": ["[1,-1,1]\n3\n-4", "[1,-10,9,1]\n100\n0"], "hints": ["Try thinking about the problem as if the array is empty. Then you only need to form goal using elements whose absolute value is <= limit.", "You can greedily set all of the elements except one to limit or -limit, so the number of elements you need is ceil(abs(goal)/ limit).", "You can \"normalize\" goal by offsetting it by the sum of the array. For example, if the goal is 5 and the sum is -3, then it's exactly the same as if the goal is 8 and the array is empty.", "The answer is ceil(abs(goal-sum)/limit) = (abs(goal-sum)+limit-1) / limit."], "metadata": {"canonical_parameter_names": ["nums", "limit", "goal"], "leetcode_dataset_entry_point": "Solution().minElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:42+00:00", "tests_total": 106, "tests_dropped": 45, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minElements($nums, $limit, $goal) {", "container": "Solution", "callable": "minElements", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "limit", "type": "Integer"}, {"name": "goal", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1786, "task_id": "number-of-restricted-paths-from-first-to-last-node", "difficulty": "Medium", "problem_description": "There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [u_i, v_i, weight_i] denotes that there is an edge between nodes u_i and v_i with weight equal to weight_i.\n\nA path from node start to node end is a sequence of nodes [z_0, z_1,z_2, ..., z_k] such that z_0= start and z_k = end and there is an edge between z_i and z_{i+1} where 0 <= i <= k-1.\n\nThe distance of a path is the sum of the weights on the edges of the path. Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x. A restricted path is a path that also satisfies that distanceToLastNode(z_i) > distanceToLastNode(z_{i+1}) where 0 <= i <= k-1.\n\nReturn the number of restricted paths from node 1 to node n. Since that number may be too large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\nOutput: 3\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5\n\nExample 2:\n\nInput: n = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\nOutput: 1\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7.\n\nConstraints:\n\n- 1 <= n <= 2 * 10^4\n- n - 1 <= edges.length <= 4 * 10^4\n- edges[i].length == 3\n- 1 <= u_i, v_i <= n\n- u_i!= v_i\n- 1 <= weight_i <= 10^5\n- There is at most one edge between any two nodes.\n- There is at least one path between any two nodes.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 1, 4]]) == 1\n assert candidate(n = 3,edges = [[1, 2, 5], [1, 3, 6], [2, 3, 1]]) == 2\n assert candidate(n = 7,edges = [[1, 3, 1], [4, 1, 2], [7, 3, 4], [2, 5, 3], [5, 6, 1], [6, 7, 2], [7, 5, 3], [2, 6, 4]]) == 1\n assert candidate(n = 6,edges = [[1, 2, 2], [1, 3, 4], [2, 4, 3], [3, 4, 1], [4, 5, 2], [5, 6, 1]]) == 2\n assert candidate(n = 5,edges = [[1, 2, 3], [1, 3, 3], [2, 3, 1], [1, 4, 2], [5, 2, 2], [3, 5, 1], [5, 4, 10]]) == 3\n assert candidate(n = 15,edges = [[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], [1, 15, 15]]) == 1\n assert candidate(n = 12,edges = [[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], [1, 3, 12], [2, 4, 13], [3, 5, 14], [4, 6, 15], [5, 7, 16], [6, 8, 17], [7, 9, 18], [8, 10, 19], [9, 11, 20], [10, 12, 21], [1, 4, 22], [2, 5, 23], [3, 6, 24], [4, 7, 25], [5, 8, 26], [6, 9, 27], [7, 10, 28], [8, 11, 29], [9, 12, 30]]) == 504\n assert candidate(n = 10,edges = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 6], [7, 8, 5], [8, 9, 4], [9, 10, 3]]) == 1\n assert candidate(n = 20,edges = [[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], [1, 20, 10], [2, 19, 10], [3, 18, 10], [4, 17, 10], [5, 16, 10], [6, 15, 10], [7, 14, 10], [8, 13, 10], [9, 12, 10], [10, 11, 10]]) == 1\n assert candidate(n = 10,edges = [[1, 2, 1], [1, 3, 4], [2, 4, 2], [3, 4, 1], [4, 5, 3], [5, 6, 2], [6, 7, 1], [7, 8, 2], [8, 9, 3], [9, 10, 1]]) == 2\n assert candidate(n = 8,edges = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 6], [7, 8, 7], [8, 1, 8], [2, 5, 9], [3, 6, 10], [4, 7, 11], [1, 8, 12]]) == 2\n assert candidate(n = 10,edges = [[1, 2, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 1], [6, 7, 3], [7, 8, 2], [8, 9, 1], [9, 10, 2], [1, 10, 5]]) == 1\n assert candidate(n = 50,edges = [[1, 2, 1000], [2, 3, 2000], [3, 4, 3000], [4, 5, 4000], [5, 6, 5000], [6, 7, 6000], [7, 8, 7000], [8, 9, 8000], [9, 10, 9000], [10, 11, 10000], [11, 12, 11000], [12, 13, 12000], [13, 14, 13000], [14, 15, 14000], [15, 16, 15000], [16, 17, 16000], [17, 18, 17000], [18, 19, 18000], [19, 20, 19000], [20, 21, 20000], [21, 22, 21000], [22, 23, 22000], [23, 24, 23000], [24, 25, 24000], [25, 26, 25000], [26, 27, 26000], [27, 28, 27000], [28, 29, 28000], [29, 30, 29000], [30, 31, 30000], [31, 32, 31000], [32, 33, 32000], [33, 34, 33000], [34, 35, 34000], [35, 36, 35000], [36, 37, 36000], [37, 38, 37000], [38, 39, 38000], [39, 40, 39000], [40, 41, 40000], [41, 42, 41000], [42, 43, 42000], [43, 44, 43000], [44, 45, 44000], [45, 46, 45000], [46, 47, 46000], [47, 48, 47000], [48, 49, 48000], [49, 50, 49000]]) == 1\n assert candidate(n = 15,edges = [[1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40], [8, 9, 45], [9, 10, 50], [10, 11, 55], [11, 12, 60], [12, 13, 65], [13, 14, 70], [14, 15, 75]]) == 1\n assert candidate(n = 15,edges = [[1, 2, 5], [1, 3, 3], [2, 4, 7], [3, 4, 2], [4, 5, 5], [5, 6, 4], [6, 7, 8], [7, 8, 2], [8, 9, 1], [9, 10, 2], [10, 11, 3], [11, 12, 1], [12, 13, 5], [13, 14, 4], [14, 15, 6]]) == 1\n assert candidate(n = 8,edges = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [7, 8, 7], [1, 3, 8], [2, 4, 9], [3, 5, 10], [4, 6, 11], [5, 7, 12], [6, 8, 13]]) == 21\n assert candidate(n = 10,edges = [[1, 2, 4], [1, 3, 3], [2, 4, 2], [3, 4, 1], [4, 5, 5], [5, 6, 3], [6, 7, 2], [7, 8, 1], [8, 9, 4], [9, 10, 5], [2, 5, 3], [3, 6, 4], [5, 8, 2], [6, 9, 1]]) == 4\n assert candidate(n = 15,edges = [[1, 2, 2], [1, 3, 3], [2, 4, 5], [3, 5, 4], [4, 6, 1], [5, 7, 2], [6, 8, 3], [7, 9, 4], [8, 10, 5], [9, 11, 1], [10, 12, 2], [11, 13, 3], [12, 14, 4], [13, 15, 5], [4, 7, 2], [5, 8, 1], [6, 9, 4], [7, 10, 3], [8, 11, 2], [9, 12, 1], [10, 13, 4], [11, 14, 5], [12, 15, 1]]) == 7\n assert candidate(n = 30,edges = [[1, 2, 5], [2, 3, 4], [3, 4, 1], [4, 5, 3], [5, 6, 2], [6, 7, 4], [7, 8, 3], [8, 9, 5], [9, 10, 4], [10, 11, 2], [11, 12, 1], [12, 13, 3], [13, 14, 2], [14, 15, 4], [15, 16, 1], [16, 17, 2], [17, 18, 3], [18, 19, 2], [19, 20, 1], [20, 21, 5], [21, 22, 4], [22, 23, 3], [23, 24, 2], [24, 25, 4], [25, 26, 3], [26, 27, 5], [27, 28, 1], [28, 29, 2], [29, 30, 3], [30, 1, 4]]) == 1\n assert candidate(n = 25,edges = [[1, 2, 20], [1, 3, 10], [2, 4, 5], [2, 5, 15], [3, 6, 1], [3, 7, 20], [4, 8, 25], [4, 9, 1], [5, 9, 30], [5, 10, 1], [6, 11, 10], [6, 12, 25], [7, 12, 15], [7, 13, 1], [8, 14, 20], [9, 14, 5], [10, 14, 10], [11, 15, 25], [11, 16, 1], [12, 16, 30], [12, 17, 5], [13, 17, 10], [14, 18, 15], [15, 18, 1], [16, 19, 20], [17, 19, 30], [18, 20, 10], [19, 20, 25], [20, 21, 1], [21, 22, 5], [22, 23, 10], [23, 24, 15], [24, 25, 20]]) == 2\n assert candidate(n = 30,edges = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900], [10, 11, 1000], [11, 12, 1100], [12, 13, 1200], [13, 14, 1300], [14, 15, 1400], [15, 16, 1500], [16, 17, 1600], [17, 18, 1700], [18, 19, 1800], [19, 20, 1900], [20, 21, 2000], [21, 22, 2100], [22, 23, 2200], [23, 24, 2300], [24, 25, 2400], [25, 26, 2500], [26, 27, 2600], [27, 28, 2700], [28, 29, 2800], [29, 30, 2900]]) == 1\n assert candidate(n = 8,edges = [[1, 2, 5], [1, 3, 6], [2, 4, 2], [3, 5, 4], [4, 5, 3], [4, 6, 1], [5, 7, 2], [6, 8, 3], [7, 8, 1], [2, 3, 4], [4, 7, 6], [5, 6, 2], [3, 8, 5], [2, 6, 3]]) == 8\n assert candidate(n = 20,edges = [[1, 2, 2], [1, 3, 1], [2, 4, 3], [2, 5, 4], [3, 6, 5], [3, 7, 6], [4, 8, 7], [4, 9, 8], [5, 10, 9], [5, 11, 10], [6, 12, 11], [6, 13, 12], [7, 14, 13], [7, 15, 14], [8, 16, 15], [9, 17, 16], [10, 18, 17], [11, 19, 18], [12, 20, 19], [13, 18, 20], [14, 19, 11], [15, 20, 12], [16, 17, 13], [17, 18, 14], [18, 19, 15], [19, 20, 16]]) == 2\n assert candidate(n = 15,edges = [[1, 2, 10], [2, 3, 5], [3, 4, 15], [4, 5, 20], [5, 6, 25], [6, 7, 30], [7, 8, 35], [8, 9, 40], [9, 10, 45], [10, 11, 50], [11, 12, 55], [12, 13, 60], [13, 14, 65], [14, 15, 70], [1, 3, 5], [2, 4, 5], [3, 5, 5], [4, 6, 5], [5, 7, 5], [6, 8, 5], [7, 9, 5], [8, 10, 5], [9, 11, 5], [10, 12, 5], [11, 13, 5], [12, 14, 5], [13, 15, 5]]) == 1\n assert candidate(n = 10,edges = [[1, 2, 4], [1, 3, 2], [2, 4, 1], [2, 5, 6], [3, 5, 3], [4, 6, 2], [5, 6, 1], [6, 7, 5], [6, 8, 3], [7, 9, 4], [8, 9, 2], [9, 10, 1]]) == 6\n assert candidate(n = 20,edges = [[1, 2, 2], [1, 3, 1], [2, 4, 3], [2, 5, 4], [3, 5, 2], [4, 6, 5], [4, 7, 6], [5, 6, 7], [5, 8, 8], [6, 9, 1], [7, 9, 2], [8, 10, 3], [9, 10, 4], [10, 11, 5], [11, 12, 6], [11, 13, 7], [12, 14, 8], [13, 14, 9], [14, 15, 10], [15, 16, 1], [16, 17, 2], [16, 18, 3], [17, 19, 4], [18, 19, 5], [19, 20, 6]]) == 24\n assert candidate(n = 20,edges = [[1, 2, 10], [2, 3, 9], [3, 4, 8], [4, 5, 7], [5, 6, 6], [6, 7, 5], [7, 8, 4], [8, 9, 3], [9, 10, 2], [10, 11, 1], [11, 12, 2], [12, 13, 3], [13, 14, 4], [14, 15, 5], [15, 16, 6], [16, 17, 7], [17, 18, 8], [18, 19, 9], [19, 20, 10], [1, 20, 15], [2, 19, 16], [3, 18, 17], [4, 17, 18], [5, 16, 19], [6, 15, 20]]) == 1\n assert candidate(n = 15,edges = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120], [13, 14, 130], [14, 15, 140], [1, 3, 15], [3, 5, 25], [5, 7, 35], [7, 9, 45], [9, 11, 55], [11, 13, 65], [13, 15, 75], [2, 4, 25], [4, 6, 35], [6, 8, 45], [8, 10, 55], [10, 12, 65], [12, 14, 75], [2, 5, 30], [5, 8, 40], [8, 11, 50], [11, 14, 60], [3, 6, 35], [6, 9, 45], [9, 12, 55], [12, 15, 65], [4, 7, 45], [7, 10, 55], [10, 13, 65], [4, 8, 50], [8, 12, 60], [8, 13, 65], [10, 14, 75], [10, 15, 80], [5, 9, 55], [9, 13, 70], [5, 10, 60], [10, 15, 90]]) == 174\n assert candidate(n = 12,edges = [[1, 2, 5], [1, 3, 3], [2, 4, 2], [3, 4, 1], [4, 5, 4], [5, 6, 5], [6, 7, 4], [7, 8, 3], [8, 9, 2], [9, 10, 1], [10, 11, 6], [11, 12, 7]]) == 2\n assert candidate(n = 10,edges = [[1, 2, 5], [2, 3, 10], [3, 4, 15], [4, 5, 20], [5, 6, 25], [6, 7, 30], [7, 8, 35], [8, 9, 40], [9, 10, 45], [1, 3, 2], [3, 5, 3], [5, 7, 4], [7, 9, 5], [2, 4, 7], [4, 6, 8], [6, 8, 9], [8, 10, 11], [1, 4, 6], [4, 7, 7], [7, 10, 8]]) == 3\n assert candidate(n = 20,edges = [[1, 2, 10], [1, 3, 20], [2, 4, 15], [3, 4, 5], [4, 5, 25], [5, 6, 10], [6, 7, 30], [7, 8, 15], [8, 9, 5], [9, 10, 25], [10, 11, 10], [11, 12, 30], [12, 13, 15], [13, 14, 5], [14, 15, 25], [15, 16, 10], [16, 17, 30], [17, 18, 15], [18, 19, 5], [19, 20, 25]]) == 2\n assert candidate(n = 50,edges = [[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, 20, 1], [20, 21, 1], [21, 22, 1], [22, 23, 1], [23, 24, 1], [24, 25, 1], [25, 26, 1], [26, 27, 1], [27, 28, 1], [28, 29, 1], [29, 30, 1], [30, 31, 1], [31, 32, 1], [32, 33, 1], [33, 34, 1], [34, 35, 1], [35, 36, 1], [36, 37, 1], [37, 38, 1], [38, 39, 1], [39, 40, 1], [40, 41, 1], [41, 42, 1], [42, 43, 1], [43, 44, 1], [44, 45, 1], [45, 46, 1], [46, 47, 1], [47, 48, 1], [48, 49, 1], [49, 50, 1], [1, 50, 10], [2, 49, 10], [3, 48, 10], [4, 47, 10], [5, 46, 10], [6, 45, 10], [7, 44, 10], [8, 43, 10], [9, 42, 10], [10, 41, 10], [11, 40, 10], [12, 39, 10], [13, 38, 10], [14, 37, 10], [15, 36, 10], [16, 35, 10], [17, 34, 10], [18, 33, 10], [19, 32, 10], [20, 31, 10], [21, 30, 10], [22, 29, 10], [23, 28, 10], [24, 27, 10], [25, 26, 10]]) == 1\n assert candidate(n = 15,edges = [[1, 2, 10], [1, 3, 20], [2, 4, 5], [2, 5, 7], [3, 5, 3], [4, 6, 2], [4, 7, 8], [5, 7, 1], [5, 8, 6], [6, 9, 4], [7, 9, 3], [8, 10, 1], [9, 10, 5], [10, 11, 3], [11, 12, 4], [12, 13, 1], [12, 14, 7], [13, 15, 2], [14, 15, 6]]) == 5\n assert candidate(n = 20,edges = [[1, 2, 1], [2, 3, 2], [3, 4, 1], [4, 5, 3], [5, 6, 2], [6, 7, 4], [7, 8, 1], [8, 9, 2], [9, 10, 3], [10, 11, 2], [11, 12, 1], [12, 13, 3], [13, 14, 2], [14, 15, 4], [15, 16, 1], [16, 17, 2], [17, 18, 3], [18, 19, 2], [19, 20, 1], [20, 1, 5]]) == 1\n assert candidate(n = 20,edges = [[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, 19], [1, 3, 3], [3, 5, 5], [5, 7, 7], [7, 9, 9], [9, 11, 11], [11, 13, 13], [13, 15, 15], [15, 17, 17], [17, 19, 19], [2, 4, 4], [4, 6, 6], [6, 8, 8], [8, 10, 10], [10, 12, 12], [12, 14, 14], [14, 16, 16], [16, 18, 18], [2, 5, 5], [5, 8, 8], [8, 11, 11], [11, 14, 14], [14, 17, 17], [3, 6, 6], [6, 9, 9], [9, 12, 12], [12, 15, 15], [12, 16, 16], [15, 18, 18], [4, 7, 7], [7, 10, 10], [10, 13, 13], [10, 14, 14], [13, 16, 16], [6, 11, 11], [11, 16, 16], [11, 17, 17], [7, 12, 12], [12, 17, 17], [12, 18, 18]]) == 494\n assert candidate(n = 20,edges = [[1, 2, 2], [1, 3, 3], [2, 4, 1], [2, 5, 4], [3, 6, 5], [3, 7, 7], [4, 8, 8], [4, 9, 9], [5, 9, 2], [5, 10, 3], [6, 11, 6], [6, 12, 10], [7, 12, 4], [7, 13, 5], [8, 14, 3], [9, 14, 4], [10, 14, 7], [11, 15, 1], [11, 16, 2], [12, 16, 3], [12, 17, 8], [13, 17, 9], [14, 18, 6], [15, 18, 5], [16, 19, 4], [17, 19, 3], [18, 20, 10], [19, 20, 7]]) == 6\n assert candidate(n = 20,edges = [[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, 19]]) == 1\n assert candidate(n = 10,edges = [[1, 2, 5], [1, 3, 3], [2, 4, 2], [2, 5, 6], [3, 4, 1], [3, 6, 4], [4, 7, 7], [5, 7, 8], [5, 8, 2], [6, 8, 3], [7, 9, 5], [8, 9, 6], [8, 10, 9], [9, 10, 10]]) == 2\n assert candidate(n = 50,edges = [[1, 2, 5], [2, 3, 4], [3, 4, 1], [4, 5, 3], [5, 6, 2], [6, 7, 4], [7, 8, 3], [8, 9, 5], [9, 10, 4], [10, 11, 2], [11, 12, 1], [12, 13, 3], [13, 14, 2], [14, 15, 4], [15, 16, 1], [16, 17, 2], [17, 18, 3], [18, 19, 2], [19, 20, 1], [20, 21, 5], [21, 22, 4], [22, 23, 3], [23, 24, 2], [24, 25, 4], [25, 26, 3], [26, 27, 5], [27, 28, 1], [28, 29, 2], [29, 30, 3], [30, 31, 4], [31, 32, 5], [32, 33, 4], [33, 34, 3], [34, 35, 2], [35, 36, 1], [36, 37, 2], [37, 38, 3], [38, 39, 2], [39, 40, 1], [40, 41, 5], [41, 42, 4], [42, 43, 3], [43, 44, 2], [44, 45, 4], [45, 46, 3], [46, 47, 5], [47, 48, 1], [48, 49, 2], [49, 50, 3], [50, 1, 4]]) == 1\n assert candidate(n = 15,edges = [[1, 2, 10], [1, 3, 5], [2, 4, 3], [2, 5, 4], [3, 6, 2], [3, 7, 6], [4, 8, 7], [4, 9, 8], [5, 9, 3], [5, 10, 1], [6, 11, 5], [6, 12, 3], [7, 12, 2], [7, 13, 9], [8, 14, 5], [9, 14, 6], [10, 14, 4], [11, 15, 7], [12, 15, 8], [13, 15, 3]]) == 4\n assert candidate(n = 50,edges = [[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, 20, 1], [20, 21, 1], [21, 22, 1], [22, 23, 1], [23, 24, 1], [24, 25, 1], [25, 26, 1], [26, 27, 1], [27, 28, 1], [28, 29, 1], [29, 30, 1], [30, 31, 1], [31, 32, 1], [32, 33, 1], [33, 34, 1], [34, 35, 1], [35, 36, 1], [36, 37, 1], [37, 38, 1], [38, 39, 1], [39, 40, 1], [40, 41, 1], [41, 42, 1], [42, 43, 1], [43, 44, 1], [44, 45, 1], [45, 46, 1], [46, 47, 1], [47, 48, 1], [48, 49, 1], [49, 50, 1], [1, 50, 50]]) == 2\n assert candidate(n = 15,edges = [[1, 2, 2], [2, 3, 3], [3, 4, 2], [4, 5, 1], [5, 6, 2], [6, 7, 3], [7, 8, 4], [8, 9, 2], [9, 10, 1], [10, 11, 3], [11, 12, 2], [12, 13, 1], [13, 14, 3], [14, 15, 2], [15, 1, 5]]) == 1\n assert candidate(n = 10,edges = [[1, 2, 2], [1, 3, 4], [2, 4, 3], [3, 4, 1], [4, 5, 2], [5, 6, 1], [6, 7, 5], [7, 8, 1], [8, 9, 4], [9, 10, 3], [10, 1, 7]]) == 1\n assert candidate(n = 10,edges = [[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], [1, 10, 5], [2, 8, 4], [3, 9, 3], [4, 7, 2], [5, 6, 1]]) == 1\n", "comparison": "exact"}, "public_tests": ["5\n[[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]", "7\n[[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]"], "hints": ["Run a Dijkstra from node numbered n to compute distance from the last node.", "Consider all edges [u, v] one by one and direct them such that distance of u to n > distance of v to n. If both u and v are at the same distance from n, discard this edge.", "Now this problem reduces to computing the number of paths from 1 to n in a DAG, a standard DP problem."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().countRestrictedPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:45+00:00", "tests_total": 45, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "graph", "topological-sort", "heap-priority-queue", "shortest-path", "dijkstra"]}, "language": "php", "interface": {"raw_signature": "function countRestrictedPaths($n, $edges) {", "container": "Solution", "callable": "countRestrictedPaths", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1787, "task_id": "make-the-xor-of-all-segments-equal-to-zero", "difficulty": "Hard", "problem_description": "You are given an array nums and an integer k. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].\n\nReturn the minimum number of elements to change in the array such that the XOR of all segments of size k is equal to zero.\n\nExample 1:\n\nInput: nums = [1,2,0,3,0], k = 1\nOutput: 3\nExplanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].\n\nExample 2:\n\nInput: nums = [3,4,5,2,1,7,3,4,7], k = 3\nOutput: 3\nExplanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].\n\nExample 3:\n\nInput: nums = [1,2,4,1,2,5,1,2,6], k = 3\nOutput: 3\nExplanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3].\n\nConstraints:\n\n- 1 <= k <= nums.length <= 2000\n- 0 <= nums[i] < 2^10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 0\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 5) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 5) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 4) == 4\n assert candidate(nums = [3, 4, 5, 2, 1, 7, 3, 4, 7],k = 3) == 3\n assert candidate(nums = [0, 0, 0, 0, 0],k = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 2) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 10\n assert candidate(nums = [1, 2, 4, 1, 2, 5, 1, 2, 6],k = 3) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1],k = 6) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 2) == 9\n assert candidate(nums = [1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 1) == 10\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],k = 2) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 9) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17],k = 3) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 4) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 6) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],k = 5) == 1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 10) == 0\n assert candidate(nums = [1, 2, 0, 3, 0],k = 1) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 4) == 11\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 5\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) == 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],k = 10) == 11\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 = 6) == 5\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, 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 = 4) == 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, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19],k = 8) == 30\n assert candidate(nums = [3, 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, 3, 1, 3, 1],k = 2) == 15\n assert candidate(nums = [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],k = 3) == 24\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) == 0\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240],k = 5) == 12\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 15) == 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],k = 5) == 10\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, 31, 31, 31, 31, 31, 31, 31, 31],k = 15) == 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],k = 5) == 16\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 = 5) == 14\n assert candidate(nums = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 13, 12, 11],k = 4) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 15\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],k = 8) == 26\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],k = 15) == 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, 5, 6, 5, 6],k = 3) == 22\n assert candidate(nums = [1023, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 3) == 9\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4],k = 7) == 21\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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 17) == 5\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 8\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0],k = 3) == 42\n assert candidate(nums = [511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540],k = 15) == 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, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 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 = 18) == 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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10, 9, 8, 7, 6, 5, 4],k = 5) == 24\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, 6, 7, 9],k = 13) == 69\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 = 7) == 23\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 = 10) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3],k = 5) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],k = 10) == 31\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 8\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],k = 15) == 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 = 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, 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],k = 11) == 69\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],k = 20) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 6) == 7\n assert candidate(nums = [5, 7, 9, 11, 13, 5, 7, 9, 11, 13],k = 5) == 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, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],k = 5) == 27\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 0, 8, 7, 6, 5, 4, 3, 2, 1, 0, 8, 7, 6, 5, 4, 3, 2, 1, 0, 8, 7, 6],k = 5) == 25\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],k = 10) == 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],k = 5) == 23\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 10) == 11\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 = 5) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 6\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 8) == 24\n assert candidate(nums = [8, 4, 2, 1, 0, 1, 2, 4, 8, 4, 2, 1, 0, 1, 2, 4, 8, 4, 2, 1],k = 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],k = 20) == 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],k = 7) == 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, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59],k = 5) == 26\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],k = 3) == 15\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 = 3) == 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],k = 10) == 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 = 4) == 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, 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 = [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, 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],k = 17) == 184\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 = 15) == 16\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 0, 255, 128, 64, 32, 16, 8, 4, 2, 1, 0, 255, 128, 64, 32, 16, 8, 4, 2, 1, 0],k = 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],k = 10) == 11\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 = 7) == 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],k = 10) == 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],k = 7) == 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],k = 5) == 15\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 12) == 38\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 = 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, 11, 11, 12, 12, 13, 13, 14, 14],k = 6) == 22\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],k = 15) == 15\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12],k = 10) == 11\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, 3, 2, 1, 3, 2, 1, 3, 2],k = 7) == 19\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],k = 8) == 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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 3) == 10\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, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9],k = 10) == 21\n assert candidate(nums = [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],k = 10) == 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, 310, 320, 330, 340, 350, 360, 370, 380, 390],k = 15) == 24\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 0, 255, 128, 64, 32, 16, 8, 4, 2, 1, 0, 255, 128, 64, 32, 16, 8, 4, 2, 1, 0],k = 7) == 23\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 25) == 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],k = 5) == 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, 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 = 8) == 52\n assert candidate(nums = [17, 255, 8, 19, 7, 23, 15, 42, 99, 1023, 22, 31, 56, 78, 90, 111, 132, 153, 174, 195],k = 7) == 13\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 = 10) == 21\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0],k = 6) == 5\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 = 7) == 24\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511],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, 26, 27, 28, 29, 30],k = 5) == 25\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", "comparison": "exact"}, "public_tests": ["[1,2,0,3,0]\n1", "[3,4,5,2,1,7,3,4,7]\n3", "[1,2,4,1,2,5,1,2,6]\n3"], "hints": ["Let's note that for the XOR of all segments with size K to be equal to zeros, nums[i] has to be equal to nums[i+k]", "Basically, we need to make the first K elements have XOR = 0 and then modify them."], "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-30T20:30:47+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "dynamic-programming", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function minChanges($nums, $k) {", "container": "Solution", "callable": "minChanges", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1790, "task_id": "check-if-one-string-swap-can-make-strings-equal", "difficulty": "Easy", "problem_description": "You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.\n\nReturn true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.\n\nExample 1:\n\nInput: s1 = \"bank\", s2 = \"kanb\"\nOutput: true\nExplanation: For example, swap the first character with the last character of s2 to make \"bank\".\n\nExample 2:\n\nInput: s1 = \"attack\", s2 = \"defend\"\nOutput: false\nExplanation: It is impossible to make them equal with one string swap.\n\nExample 3:\n\nInput: s1 = \"kelb\", s2 = \"kelb\"\nOutput: true\nExplanation: The two strings are already equal, so no string swap operation is required.\n\nConstraints:\n\n- 1 <= s1.length, s2.length <= 100\n- s1.length == s2.length\n- s1 and s2 consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"attack\",s2 = \"defend\") == False\n assert candidate(s1 = \"bank\",s2 = \"kanb\") == True\n assert candidate(s1 = \"abcde\",s2 = \"abced\") == True\n assert candidate(s1 = \"abcd\",s2 = \"abdc\") == True\n assert candidate(s1 = \"aaa\",s2 = \"aaa\") == True\n assert candidate(s1 = \"kelb\",s2 = \"kelb\") == True\n assert candidate(s1 = \"aabb\",s2 = \"abab\") == True\n assert candidate(s1 = \"abcd\",s2 = \"dcba\") == False\n assert candidate(s1 = \"algorithm\",s2 = \"logarithm\") == False\n assert candidate(s1 = \"almost\",s2 = \"almost\") == True\n assert candidate(s1 = \"abcdefg\",s2 = \"ghfedcb\") == False\n assert candidate(s1 = \"xyzabc\",s2 = \"yzabxc\") == False\n assert candidate(s1 = \"abcdefg\",s2 = \"fedcbag\") == False\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefx\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"ccbaab\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbbc\") == False\n assert candidate(s1 = \"abacabadabacaba\",s2 = \"babacabadabacab\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"ccbbaa\") == False\n assert candidate(s1 = \"programming\",s2 = \"programminj\") == False\n assert candidate(s1 = \"samestr\",s2 = \"strsame\") == False\n assert candidate(s1 = \"hello\",s2 = \"hlelo\") == True\n assert candidate(s1 = \"abcdefg\",s2 = \"gfedcba\") == False\n assert candidate(s1 = \"abababab\",s2 = \"babababa\") == False\n assert candidate(s1 = \"abracadabra\",s2 = \"abracadabrb\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"mississipsp\") == False\n assert candidate(s1 = \"palindrome\",s2 = \"lpadnrimoe\") == False\n assert candidate(s1 = \"aabbcc\",s2 = \"ccabba\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"mississipip\") == True\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdefg\") == True\n assert candidate(s1 = \"aabbcc\",s2 = \"bbaacc\") == False\n assert candidate(s1 = \"abcdexyz\",s2 = \"xyzabcde\") == False\n assert candidate(s1 = \"abcdxyz\",s2 = \"abczyxd\") == False\n assert candidate(s1 = \"abcdefgh\",s2 = \"hgfedcba\") == False\n assert candidate(s1 = \"abcde\",s2 = \"abcde\") == True\n assert candidate(s1 = \"ab\",s2 = \"ba\") == True\n assert candidate(s1 = \"hello\",s2 = \"olleh\") == False\n assert candidate(s1 = \"hello\",s2 = \"hallo\") == False\n assert candidate(s1 = \"abcdef\",s2 = \"abcfed\") == True\n assert candidate(s1 = \"qwertyuiop\",s2 = \"qewrtyuipo\") == False\n assert candidate(s1 = \"mississippi\",s2 = \"mississippa\") == False\n assert candidate(s1 = \"programming\",s2 = \"prorgamming\") == True\n assert candidate(s1 = \"abcdefg\",s2 = \"abdecfg\") == False\n assert candidate(s1 = \"noon\",s2 = \"nnon\") == False\n assert candidate(s1 = \"hello\",s2 = \"ohell\") == False\n assert candidate(s1 = \"hello\",s2 = \"hxllo\") == False\n assert candidate(s1 = \"aaaabbbb\",s2 = \"bbbbaaaa\") == False\n assert candidate(s1 = \"abc\",s2 = \"acb\") == True\n assert candidate(s1 = \"hello\",s2 = \"lehho\") == False\n assert candidate(s1 = \"abcdexyz\",s2 = \"abcdefyz\") == False\n assert candidate(s1 = \"python\",s2 = \"pythno\") == True\n assert candidate(s1 = \"abracadabra\",s2 = \"abracadabra\") == True\n assert candidate(s1 = \"abcdefgh\",s2 = \"bcadefgh\") == False\n assert candidate(s1 = \"abacabadabacaba\",s2 = \"abacabadabacaba\") == True\n assert candidate(s1 = \"hello\",s2 = \"bello\") == False\n assert candidate(s1 = \"hello\",s2 = \"heoll\") == True\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghjk\") == False\n assert candidate(s1 = \"unique\",s2 = \"unqieu\") == False\n assert candidate(s1 = \"abcdabcd\",s2 = \"dcbaabcd\") == False\n assert candidate(s1 = \"abacax\",s2 = \"abacxa\") == True\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghij\") == True\n assert candidate(s1 = \"algorithm\",s2 = \"algorithn\") == False\n assert candidate(s1 = \"algorithm\",s2 = \"aloritghm\") == False\n assert candidate(s1 = \"abcdefg\",s2 = \"abcdegf\") == True\n assert candidate(s1 = \"aabbcc\",s2 = \"aaccbb\") == False\n assert candidate(s1 = \"almost\",s2 = \"alosmt\") == False\n assert candidate(s1 = \"racecar\",s2 = \"racecar\") == True\n assert candidate(s1 = \"mississippi\",s2 = \"mmissisippi\") == False\n assert candidate(s1 = \"abcdefgh\",s2 = \"efghabcd\") == False\n assert candidate(s1 = \"xyzz\",s2 = \"zzxy\") == False\n assert candidate(s1 = \"palindrome\",s2 = \"palindorme\") == True\n assert candidate(s1 = \"abcdef\",s2 = \"abcdef\") == True\n assert candidate(s1 = \"ab\",s2 = \"ab\") == True\n assert candidate(s1 = \"abcdef\",s2 = \"abcdeg\") == False\n assert candidate(s1 = \"oneone\",s2 = \"noonoe\") == False\n assert candidate(s1 = \"abcxyz\",s2 = \"xyzabc\") == False\n assert candidate(s1 = \"abac\",s2 = \"caba\") == False\n assert candidate(s1 = \"xyz\",s2 = \"zyx\") == True\n assert candidate(s1 = \"abracadabra\",s2 = \"abracadbrba\") == False\n assert candidate(s1 = \"abac\",s2 = \"abca\") == True\n assert candidate(s1 = \"same\",s2 = \"same\") == True\n assert candidate(s1 = \"abcdefgh\",s2 = \"abcdefgh\") == True\n assert candidate(s1 = \"abcdef\",s2 = \"fedcba\") == False\n assert candidate(s1 = \"abcdefghij\",s2 = \"abcdefghji\") == True\n assert candidate(s1 = \"abcde\",s2 = \"edcba\") == False\n assert candidate(s1 = \"swapping\",s2 = \"swapgnip\") == False\n assert candidate(s1 = \"aabbccdd\",s2 = \"ddccbbaa\") == False\n assert candidate(s1 = \"xyzz\",s2 = \"zyzz\") == False\n assert candidate(s1 = \"algorithm\",s2 = \"algorjthm\") == False\n assert candidate(s1 = \"xyzz\",s2 = \"zyxz\") == True\n assert candidate(s1 = \"aabbcc\",s2 = \"aabbdc\") == False\n assert candidate(s1 = \"abcdefghijk\",s2 = \"abcdefghijl\") == False\n assert candidate(s1 = \"ababab\",s2 = \"bababa\") == False\n assert candidate(s1 = \"abab\",s2 = \"baba\") == False\n assert candidate(s1 = \"mambo\",s2 = \"mambp\") == False\n assert candidate(s1 = \"abcdef\",s2 = \"abcdfe\") == True\n assert candidate(s1 = \"abdc\",s2 = \"abcd\") == True\n assert candidate(s1 = \"xyzz\",s2 = \"zyzx\") == True\n assert candidate(s1 = \"aabb\",s2 = \"bbaa\") == False\n assert candidate(s1 = \"same\",s2 = \"emsa\") == False\n assert candidate(s1 = \"abcdxyz\",s2 = \"abcdzyx\") == True\n assert candidate(s1 = \"python\",s2 = \"ytonph\") == False\n assert candidate(s1 = \"xyzxyz\",s2 = \"zyxzyx\") == False\n assert candidate(s1 = \"aaaa\",s2 = \"aaaa\") == True\n", "comparison": "exact"}, "public_tests": ["\"bank\"\n\"kanb\"", "\"attack\"\n\"defend\"", "\"kelb\"\n\"kelb\""], "hints": ["The answer is false if the number of nonequal positions in the strings is not equal to 0 or 2.", "Check that these positions have the same set of characters."], "metadata": {"canonical_parameter_names": ["s1", "s2"], "leetcode_dataset_entry_point": "Solution().areAlmostEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:52+00:00", "tests_total": 108, "tests_dropped": 5, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function areAlmostEqual($s1, $s2) {", "container": "Solution", "callable": "areAlmostEqual", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1791, "task_id": "find-center-of-star-graph", "difficulty": "Easy", "problem_description": "There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.\n\nYou are given a 2D integer array edges where each edges[i] = [u_i, v_i] indicates that there is an edge between the nodes u_i and v_i. Return the center of the given star graph.\n\nExample 1:\n\nInput: edges = [[1,2],[2,3],[4,2]]\nOutput: 2\nExplanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.\n\nExample 2:\n\nInput: edges = [[1,2],[5,1],[1,3],[1,4]]\nOutput: 1\n\nConstraints:\n\n- 3 <= n <= 10^5\n- edges.length == n - 1\n- edges[i].length == 2\n- 1 <= u_i, v_i <= n\n- u_i != v_i\n- The given edges represent a valid star graph.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[3, 1], [1, 2], [1, 4], [1, 5]]) == 1\n assert candidate(edges = [[7, 3], [7, 4], [7, 2], [7, 5], [7, 6], [7, 1]]) == 7\n assert candidate(edges = [[4, 3], [5, 3], [2, 3], [1, 3]]) == 3\n assert candidate(edges = [[1, 2], [2, 3], [4, 2]]) == 2\n assert candidate(edges = [[1, 2], [5, 1], [1, 3], [1, 4]]) == 1\n assert candidate(edges = [[3, 1], [2, 1]]) == 1\n assert candidate(edges = [[3, 1], [3, 2], [3, 4], [3, 5]]) == 3\n assert candidate(edges = [[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\n assert candidate(edges = [[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, 1]]) == 2\n assert candidate(edges = [[2, 1], [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, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 58], [2, 59], [2, 60]]) == 2\n assert candidate(edges = [[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\n assert candidate(edges = [[3, 1], [3, 2], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [3, 73], [3, 74], [3, 75], [3, 76], [3, 77], [3, 78], [3, 79], [3, 80], [3, 81], [3, 82], [3, 83], [3, 84], [3, 85], [3, 86], [3, 87], [3, 88], [3, 89], [3, 90], [3, 91], [3, 92], [3, 93], [3, 94], [3, 95], [3, 96], [3, 97], [3, 98], [3, 99], [3, 100]]) == 3\n assert candidate(edges = [[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\n assert candidate(edges = [[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\n assert candidate(edges = [[2, 1], [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\n assert candidate(edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 2\n assert candidate(edges = [[30, 1], [30, 2], [30, 3], [30, 4], [30, 5], [30, 6], [30, 7], [30, 8], [30, 9], [30, 10], [30, 11], [30, 12], [30, 13], [30, 14], [30, 15], [30, 16], [30, 17], [30, 18], [30, 19], [30, 20], [30, 21], [30, 22], [30, 23], [30, 24], [30, 25], [30, 26], [30, 27], [30, 28], [30, 29]]) == 30\n assert candidate(edges = [[2, 1], [2, 4], [3, 2], [2, 6], [5, 2], [7, 2], [8, 2], [9, 2], [10, 2]]) == 2\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,3],[4,2]]", "[[1,2],[5,1],[1,3],[1,4]]"], "hints": ["The center is the only node that has more than one edge.", "The center is also connected to all other nodes.", "Any two edges must have a common node, which is the center."], "metadata": {"canonical_parameter_names": ["edges"], "leetcode_dataset_entry_point": "Solution().findCenter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:54+00:00", "tests_total": 58, "tests_dropped": 40, "flags": ["figure_reference", "has_images"], "topic_tags": ["graph"]}, "language": "php", "interface": {"raw_signature": "function findCenter($edges) {", "container": "Solution", "callable": "findCenter", "parameters": [{"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1792, "task_id": "maximum-average-pass-ratio", "difficulty": "Medium", "problem_description": "There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [pass_i, total_i]. You know beforehand that in the i^th class, there are total_i total students, but only pass_i number of students will pass the exam.\n\nYou are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.\n\nThe pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.\n\nReturn the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10^-5 of the actual answer will be accepted.\n\nExample 1:\n\nInput: classes = [[1,2],[3,5],[2,2]], extraStudents = 2\nOutput: 0.78333\nExplanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.\n\nExample 2:\n\nInput: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\nOutput: 0.53485\n\nConstraints:\n\n- 1 <= classes.length <= 10^5\n- classes[i].length == 2\n- 1 <= pass_i <= total_i <= 10^5\n- 1 <= extraStudents <= 10^5\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(classes=[[5, 10], [6, 10], [7, 10]], extraStudents=1), 0.6151515151515151)\n assert answers_match(candidate(classes=[[2, 4], [3, 9], [4, 5], [2, 10]], extraStudents=4), 0.5348484848484849)\n assert answers_match(candidate(classes=[[1, 1], [1, 1], [1, 1]], extraStudents=1), 1.0)\n assert answers_match(candidate(classes=[[1, 2], [3, 5], [2, 2]], extraStudents=2), 0.7833333333333333)\n assert answers_match(candidate(classes=[[10, 20], [20, 30], [30, 40]], extraStudents=5), 0.6722222222222222)\n assert answers_match(candidate(classes=[[5, 5], [10, 10]], extraStudents=10), 1.0)\n assert answers_match(candidate(classes=[[1, 1], [1, 2], [1, 3]], extraStudents=3), 0.7555555555555555)\n assert answers_match(candidate(classes=[[99, 100], [999, 1000], [9999, 10000]], extraStudents=1000), 0.999331746031746)\n assert answers_match(candidate(classes=[[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]], extraStudents=10), 1.0)\n assert answers_match(candidate(classes=[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]], extraStudents=10), 0.6842857142857143)\n assert answers_match(candidate(classes=[[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000]], extraStudents=45), 0.7958742756361804)\n assert answers_match(candidate(classes=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]], extraStudents=15), 0.2273449131513648)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]], extraStudents=15), 0.8571428571428571)\n assert answers_match(candidate(classes=[[1, 100], [10, 1000], [100, 10000], [1000, 100000]], extraStudents=1000), 0.3008176852167975)\n assert answers_match(candidate(classes=[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]], extraStudents=50), 0.6412325174825175)\n assert answers_match(candidate(classes=[[99, 100], [999, 1000], [9999, 10000], [99999, 100000]], extraStudents=10), 0.9974497727272728)\n assert answers_match(candidate(classes=[[5, 10], [10, 20], [15, 30], [20, 40], [25, 50]], extraStudents=25), 0.5977592214345788)\n assert answers_match(candidate(classes=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]], extraStudents=1000), 1.0)\n assert answers_match(candidate(classes=[[1000, 2000], [1500, 3000], [2000, 4000], [2500, 5000], [3000, 6000]], extraStudents=1000), 0.5350170085037467)\n assert answers_match(candidate(classes=[[1, 3], [2, 6], [3, 9], [4, 12], [5, 15]], extraStudents=10), 0.4884670884670885)\n assert answers_match(candidate(classes=[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]], extraStudents=10), 0.4164285714285715)\n assert answers_match(candidate(classes=[[1, 100], [10, 100], [50, 100]], extraStudents=50), 0.3296191939890711)\n assert answers_match(candidate(classes=[[100, 200], [150, 250], [200, 300], [250, 350]], extraStudents=50), 0.6452380952380952)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]], extraStudents=5), 0.4371428571428571)\n assert answers_match(candidate(classes=[[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]], extraStudents=50), 1.0)\n assert answers_match(candidate(classes=[[10000, 10001], [20000, 20001], [30000, 30001], [40000, 40001]], extraStudents=1000), 0.9999501925188506)\n assert answers_match(candidate(classes=[[50, 100], [75, 150], [125, 250], [200, 400], [300, 600], [450, 900]], extraStudents=300), 0.5992478200634347)\n assert answers_match(candidate(classes=[[5, 8], [5, 8], [5, 8], [5, 8], [5, 8]], extraStudents=20), 0.75)\n assert answers_match(candidate(classes=[[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]], extraStudents=100), 0.8541887125220459)\n assert answers_match(candidate(classes=[[99, 100], [98, 100], [97, 100], [96, 100], [95, 100]], extraStudents=5), 0.9704761904761904)\n assert answers_match(candidate(classes=[[99999, 100000], [50000, 100000], [25000, 50000], [10000, 20000]], extraStudents=5000), 0.6499975)\n assert answers_match(candidate(classes=[[1, 100000], [2, 100000], [3, 100000]], extraStudents=100000), 0.2500150000093752)\n assert answers_match(candidate(classes=[[100, 200], [200, 500], [300, 800], [400, 1000]], extraStudents=100), 0.4604967738352485)\n assert answers_match(candidate(classes=[[1, 2], [3, 6], [5, 10], [7, 14], [9, 18]], extraStudents=15), 0.6531926406926407)\n assert answers_match(candidate(classes=[[1, 100000], [2, 100000], [3, 100000], [4, 100000], [5, 100000]], extraStudents=100000), 0.16669166670370508)\n assert answers_match(candidate(classes=[[10000, 20000], [5000, 10000], [2500, 5000], [1000, 2000], [500, 1000], [250, 500], [100, 200], [50, 100], [25, 50], [10, 20]], extraStudents=10000), 0.7885364227868774)\n assert answers_match(candidate(classes=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], extraStudents=5), 1.0)\n assert answers_match(candidate(classes=[[50, 100], [150, 300], [250, 500], [350, 700]], extraStudents=150), 0.5803610885401075)\n assert answers_match(candidate(classes=[[1, 1], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]], extraStudents=20), 0.9074074074074074)\n assert answers_match(candidate(classes=[[9, 10], [99, 100], [999, 1000], [9999, 10000], [99999, 100000]], extraStudents=50000), 0.9999456354114968)\n assert answers_match(candidate(classes=[[99, 100], [98, 100], [97, 100], [96, 100], [95, 100], [94, 100], [93, 100], [92, 100], [91, 100], [90, 100]], extraStudents=10), 0.945917211328976)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11]], extraStudents=10), 0.3255194805194805)\n assert answers_match(candidate(classes=[[50, 100], [100, 200], [150, 300], [200, 400]], extraStudents=100), 0.567861188343116)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]], extraStudents=9), 0.341005291005291)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]], extraStudents=5), 0.7966666666666666)\n assert answers_match(candidate(classes=[[10, 11], [20, 22], [30, 33], [40, 44]], extraStudents=5), 0.9161931818181818)\n assert answers_match(candidate(classes=[[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]], extraStudents=15), 0.7535606060606062)\n assert answers_match(candidate(classes=[[1, 3], [2, 5], [3, 7], [4, 9]], extraStudents=5), 0.528968253968254)\n assert answers_match(candidate(classes=[[1, 1000], [10, 1000], [100, 1000], [1000, 1000]], extraStudents=100), 0.30143093489681594)\n assert answers_match(candidate(classes=[[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65]], extraStudents=100), 0.9114219114219114)\n assert answers_match(candidate(classes=[[1, 100], [20, 50], [30, 40], [40, 60]], extraStudents=10), 0.4822964571623233)\n assert answers_match(candidate(classes=[[1, 100000], [100000, 100000], [100000, 100000], [100000, 100000], [1, 100000]], extraStudents=100000), 0.733336)\n assert answers_match(candidate(classes=[[5, 6], [10, 12], [15, 18], [20, 24], [25, 30]], extraStudents=50), 0.8996095210091154)\n assert answers_match(candidate(classes=[[1, 2], [2, 4], [3, 8], [4, 16], [5, 32], [6, 64], [7, 128], [8, 256], [9, 512]], extraStudents=256), 0.56112903154186)\n assert answers_match(candidate(classes=[[99999, 100000], [99998, 100000], [99997, 100000]], extraStudents=3), 0.999980000299991)\n assert answers_match(candidate(classes=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]], extraStudents=100), 0.29977994676131325)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]], extraStudents=45), 0.5812816812816812)\n assert answers_match(candidate(classes=[[1, 3], [2, 5], [3, 7], [4, 9], [5, 11]], extraStudents=5), 0.5140836940836941)\n assert answers_match(candidate(classes=[[100, 200], [200, 300], [50, 150], [250, 500], [100, 250]], extraStudents=50), 0.5133333333333333)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5]], extraStudents=5), 0.5)\n assert answers_match(candidate(classes=[[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20]], extraStudents=5), 0.5488095238095239)\n assert answers_match(candidate(classes=[[1000, 10000], [2000, 20000], [3000, 30000], [4000, 40000]], extraStudents=2000), 0.1375)\n assert answers_match(candidate(classes=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]], extraStudents=200), 0.638637428727642)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]], extraStudents=50), 0.9128787878787878)\n assert answers_match(candidate(classes=[[100, 101], [200, 201], [300, 301], [400, 401], [500, 501]], extraStudents=500), 0.9974701296361822)\n assert answers_match(candidate(classes=[[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]], extraStudents=5), 0.5833333333333333)\n assert answers_match(candidate(classes=[[50, 100], [40, 80], [30, 60], [20, 40], [10, 20]], extraStudents=20), 0.554287556415216)\n assert answers_match(candidate(classes=[[1, 2], [2, 5], [3, 10], [4, 20], [5, 50], [6, 100], [7, 200], [8, 500], [9, 1000], [10, 10000]], extraStudents=5000), 0.7736090641036538)\n assert answers_match(candidate(classes=[[1, 1000], [1, 2000], [1, 3000], [1, 4000], [1, 5000]], extraStudents=1500), 0.14190236063451128)\n assert answers_match(candidate(classes=[[10, 20], [20, 40], [30, 60], [40, 80]], extraStudents=20), 0.56785944551902)\n assert answers_match(candidate(classes=[[99, 100], [199, 200], [299, 300], [399, 400], [499, 500]], extraStudents=1000), 0.998)\n assert answers_match(candidate(classes=[[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]], extraStudents=4500), 0.5002246672081883)\n assert answers_match(candidate(classes=[[10000, 100000], [20000, 100000], [30000, 100000], [40000, 100000]], extraStudents=10000), 0.27058853870831734)\n assert answers_match(candidate(classes=[[1, 100], [1, 100], [1, 100], [1, 100], [1, 100]], extraStudents=500), 0.505)\n assert answers_match(candidate(classes=[[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]], extraStudents=5), 1.0)\n assert answers_match(candidate(classes=[[1, 10], [2, 15], [3, 20], [4, 25], [5, 30]], extraStudents=15), 0.2816248934356351)\n assert answers_match(candidate(classes=[[10, 20], [15, 25], [20, 30], [25, 35]], extraStudents=10), 0.6633597883597884)\n assert answers_match(candidate(classes=[[1, 100], [10, 100], [100, 100], [1000, 1000], [10000, 10000]], extraStudents=10000), 0.9925924392888745)\n assert answers_match(candidate(classes=[[1, 100000], [100000, 100000], [50000, 100000]], extraStudents=50000), 0.6114404678259185)\n assert answers_match(candidate(classes=[[10, 20], [15, 30], [5, 15], [25, 50]], extraStudents=15), 0.55)\n assert answers_match(candidate(classes=[[10000, 100000], [20000, 100000], [30000, 100000], [40000, 100000], [50000, 100000], [60000, 100000], [70000, 100000], [80000, 100000], [90000, 100000], [100000, 100000]], extraStudents=10000), 0.5582354154833269)\n assert answers_match(candidate(classes=[[50, 100], [40, 80], [30, 60], [20, 40], [10, 20]], extraStudents=30), 0.5707749766573296)\n assert answers_match(candidate(classes=[[1, 100000], [1, 100000], [1, 100000], [1, 100000], [1, 100000]], extraStudents=100000), 0.166675)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]], extraStudents=100), 0.9415395787944808)\n assert answers_match(candidate(classes=[[10, 100], [20, 200], [30, 300], [40, 400], [50, 500]], extraStudents=50), 0.16025231286795627)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]], extraStudents=15), 0.5976190476190476)\n assert answers_match(candidate(classes=[[50, 100], [75, 150], [25, 75], [10, 50]], extraStudents=20), 0.44060351413292587)\n assert answers_match(candidate(classes=[[1, 100], [2, 100], [3, 100], [4, 100], [5, 100]], extraStudents=250), 0.3533647454875556)\n assert answers_match(candidate(classes=[[50000, 100000], [40000, 100000], [30000, 100000], [20000, 100000], [10000, 100000]], extraStudents=50000), 0.3696598823228846)\n assert answers_match(candidate(classes=[[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20]], extraStudents=100), 0.7595597403486419)\n assert answers_match(candidate(classes=[[3, 4], [4, 5], [5, 6], [6, 7], [7, 8]], extraStudents=3), 0.8464285714285715)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]], extraStudents=9), 0.8504850088183421)\n assert answers_match(candidate(classes=[[10, 12], [20, 25], [30, 35], [40, 45], [50, 55]], extraStudents=30), 0.8916472416472416)\n assert answers_match(candidate(classes=[[1, 2], [2, 4], [4, 8], [8, 16], [16, 32]], extraStudents=64), 0.7993434343434344)\n assert answers_match(candidate(classes=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]], extraStudents=100), 0.49407730392552046)\n assert answers_match(candidate(classes=[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7]], extraStudents=21), 0.5919612794612795)\n assert answers_match(candidate(classes=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]], extraStudents=500), 0.5672899020682859)\n assert answers_match(candidate(classes=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]], extraStudents=10), 0.8541887125220459)\n assert answers_match(candidate(classes=[[999, 1000], [998, 1000], [997, 1000], [996, 1000], [995, 1000]], extraStudents=10), 0.997009900990099)\n", "comparison": "float"}, "public_tests": ["[[1,2],[3,5],[2,2]]\n2", "[[2,4],[3,9],[4,5],[2,10]]\n4"], "hints": ["Pay attention to how much the pass ratio changes when you add a student to the class. If you keep adding students, what happens to the change in pass ratio? The more students you add to a class, the smaller the change in pass ratio becomes.", "Since the change in the pass ratio is always decreasing with the more students you add, then the very first student you add to each class is the one that makes the biggest change in the pass ratio.", "Because each class's pass ratio is weighted equally, it's always optimal to put the student in the class that makes the biggest change among all the other classes.", "Keep a max heap of the current class sizes and order them by the change in pass ratio. For each extra student, take the top of the heap, update the class size, and put it back in the heap."], "metadata": {"canonical_parameter_names": ["classes", "extraStudents"], "leetcode_dataset_entry_point": "Solution().maxAverageRatio", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:57+00:00", "tests_total": 101, "tests_dropped": 2, "flags": ["decimal_answer"], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maxAverageRatio($classes, $extraStudents) {", "container": "Solution", "callable": "maxAverageRatio", "parameters": [{"name": "classes", "type": "Integer[][]"}, {"name": "extraStudents", "type": "Integer"}], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1793, "task_id": "maximum-score-of-a-good-subarray", "difficulty": "Hard", "problem_description": "You are given an array of integers nums (0-indexed) and an integer k.\n\nThe score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.\n\nReturn the maximum possible score of a good subarray.\n\nExample 1:\n\nInput: nums = [1,4,3,7,4,5], k = 3\nOutput: 15\nExplanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.\n\nExample 2:\n\nInput: nums = [5,5,4,5,4,1,1,1], k = 0\nOutput: 20\nExplanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 2 * 10^4\n- 0 <= k < nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 4, 5, 4, 1, 1, 1],k = 0) == 20\n assert candidate(nums = [10, 10, 10, 10, 10],k = 2) == 50\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 25\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 4) == 10\n assert candidate(nums = [9, 7, 5, 3, 1],k = 2) == 15\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 30\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 9\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9],k = 2) == 21\n assert candidate(nums = [1, 4, 3, 7, 4, 5],k = 3) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1],k = 4) == 25\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100],k = 4) == 1500\n assert candidate(nums = [10, 20, 30, 40, 50],k = 2) == 90\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 30\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 54\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1],k = 3) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 30\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 30\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9, 10, 1, 2, 3, 4, 5],k = 9) == 18\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 7) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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, 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 = 25) == 69\n assert candidate(nums = [1, 20000, 2, 19999, 3, 19998, 4, 19997, 5, 19996, 6],k = 5) == 19998\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 = [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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 200\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 110\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50],k = 3) == 140\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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 12) == 150\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],k = 9) == 200000\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 9) == 110\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 4) == 1000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 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],k = 10) == 110\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) == 20\n assert candidate(nums = [20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000],k = 10) == 400000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 300\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 15) == 44\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5],k = 4) == 19\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9],k = 9) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 10) == 1000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 6) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1],k = 9) == 10\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 64\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5],k = 5) == 150\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) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 55\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 = 15) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 7) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == 300\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],k = 10) == 55\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 5) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 6) == 420\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],k = 11) == 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],k = 20) == 44\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12],k = 5) == 24\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) == 200\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],k = 9) == 99\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 2, 1, 2, 3, 6, 12, 25, 50, 100],k = 7) == 15\n assert candidate(nums = [5, 5, 4, 4, 4, 5, 5, 4, 4, 4, 5, 5, 4, 4, 4, 5, 5, 4, 4, 4, 5, 5, 4, 4, 4, 5, 5, 4, 4, 4],k = 12) == 120\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],k = 14) == 55\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6],k = 4) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 10) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10],k = 4) == 150\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5],k = 10) == 55\n assert candidate(nums = [10, 10, 10, 10, 10, 1, 1, 1, 1, 1],k = 5) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100],k = 9) == 100\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],k = 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],k = 20) == 169\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 12) == 128\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 100],k = 4) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5, 10, 20, 30, 40, 50, 40, 30, 20, 10, 5],k = 15) == 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],k = 10) == 1620\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 5) == 10\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10],k = 9) == 39\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 8) == 18\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 64\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990],k = 5) == 109890\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, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 20) == 38\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 5) == 910\n assert candidate(nums = [60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5],k = 5) == 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, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 20) == 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],k = 10) == 20\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],k = 15) == 100\n assert candidate(nums = [3, 3, 3, 1, 2, 3, 2, 1, 3, 3, 3, 3],k = 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],k = 10) == 110\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 5) == 21\n assert candidate(nums = [20000, 19000, 18000, 17000, 16000, 15000, 14000, 13000, 12000, 11000, 10000],k = 10) == 110000\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) == 1620\n assert candidate(nums = [1, 5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 25) == 30\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6],k = 4) == 10\n assert candidate(nums = [10000, 20000, 10000, 20000, 10000, 20000, 10000, 20000, 10000, 20000, 10000],k = 7) == 110000\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 8) == 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],k = 15) == 80\n assert candidate(nums = [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],k = 15) == 210\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 4) == 300\n", "comparison": "exact"}, "public_tests": ["[1,4,3,7,4,5]\n3", "[5,5,4,5,4,1,1,1]\n0"], "hints": ["Try thinking about the prefix before index k and the suffix after index k as two separate arrays.", "Using two pointers or binary search, we can find the maximum prefix of each array where the numbers are less than or equal to a certain value"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:30:59+00:00", "tests_total": 98, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "stack", "monotonic-stack", "cartesian-tree"]}, "language": "php", "interface": {"raw_signature": "function maximumScore($nums, $k) {", "container": "Solution", "callable": "maximumScore", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1796, "task_id": "second-largest-digit-in-a-string", "difficulty": "Easy", "problem_description": "Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.\n\nAn alphanumeric string is a string consisting of lowercase English letters and digits.\n\nExample 1:\n\nInput: s = \"dfa12321afd\"\nOutput: 2\nExplanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.\n\nExample 2:\n\nInput: s = \"abc1111\"\nOutput: -1\nExplanation: The digits that appear in s are [1]. There is no second largest digit.\n\nConstraints:\n\n- 1 <= s.length <= 500\n- s consists of only lowercase English letters and digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"9876543210\") == 8\n assert candidate(s = \"same1same1same1\") == -1\n assert candidate(s = \"abcdefghij0\") == -1\n assert candidate(s = \"abc1111\") == -1\n assert candidate(s = \"1a\") == -1\n assert candidate(s = \"1234567890\") == 8\n assert candidate(s = \"dfa12321afd\") == 2\n assert candidate(s = \"a1\") == -1\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0\") == 8\n assert candidate(s = \"11223344556677889900\") == 8\n assert candidate(s = \"unique9\") == -1\n assert candidate(s = \"a1a2a3a4a5a6a7a8a9a0\") == 8\n assert candidate(s = \"0000000000\") == -1\n assert candidate(s = \"9999999999\") == -1\n assert candidate(s = \"00000000001111111111\") == 0\n assert candidate(s = \"1001\") == 0\n assert candidate(s = \"abcdefg\") == -1\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0\") == 8\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz0\") == -1\n assert candidate(s = \"0a0b0c0d0e0f0g0h0i0j0k0l0m0n0o0p0q0r0s0t0u0v0w0x0y0z0\") == -1\n assert candidate(s = \"abcd1abcd2abcd3abcd4abcd5abcd6abcd7abcd8abcd9abcd0\") == 8\n assert candidate(s = \"9a8b7c6d5e4f3g2h1i0\") == 8\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0\") == 8\n assert candidate(s = \"abc123xyz123\") == 2\n assert candidate(s = \"9876543210abc9876543210\") == 8\n assert candidate(s = \"9223372036854775807\") == 8\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p9o8n7m6l5k4j3i2h1g0f9e8d7c6b5a4\") == 8\n assert candidate(s = \"1234567890abcdefghijklmnopqrstuvwxyz\") == 8\n assert candidate(s = \"1234567890abcdefghij0123456789\") == 8\n assert candidate(s = \"99887766554433221100\") == 8\n assert candidate(s = \"abcdefghij01234567890\") == 8\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0\") == 8\n assert candidate(s = \"abc123abc123abc123\") == 2\n assert candidate(s = \"a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == -1\n assert candidate(s = \"abc123xyz123abc123\") == 2\n assert candidate(s = \"1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz\") == 8\n assert candidate(s = \"1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == -1\n assert candidate(s = \"123abc456def789ghi123\") == 8\n assert candidate(s = \"1\") == -1\n assert candidate(s = \"a1b1c2d2e3f3g4h4i5j5k6l6m7n7o8p8q9r0\") == 8\n assert candidate(s = \"1223344556677889900\") == 8\n assert candidate(s = \"1234123412341234\") == 3\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\") == 0\n assert candidate(s = \"abc123123123abc123123\") == 2\n assert candidate(s = \"000000000000000000000\") == -1\n assert candidate(s = \"123456789098765432101234567890\") == 8\n assert candidate(s = \"a1b1c2d2e3f3g4h4i5j5\") == 4\n assert candidate(s = \"1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\") == 8\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6\") == 8\n assert candidate(s = \"1234567890123456789012345678901234567890\") == 8\n assert candidate(s = \"999888777666555444333222111000\") == 8\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0a1b2c3d4e5f6g7h8i9j0a1b2c3d4e5f6g7h8i9j0\") == 8\n assert candidate(s = \"9876543210abcdefghijklmnopqrstuvwxyz\") == 8\n assert candidate(s = \"99999999999999999999\") == -1\n assert candidate(s = \"012345678901234567890123456789\") == 8\n assert candidate(s = \"10011001100110011001100110011001100110011001\") == 0\n assert candidate(s = \"1234567890abcdefghijk\") == 8\n assert candidate(s = \"abcdefghij0123456789\") == 8\n assert candidate(s = \"5555555555\") == -1\n assert candidate(s = \"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555\") == -1\n assert candidate(s = \"987654321009876543210987654321098765432109876543210\") == 8\n assert candidate(s = \"1234567890abcdefghij1234567890\") == 8\n assert candidate(s = \"12345678901234567890\") == 8\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij012345678901234567890123456789\") == 8\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz1234567890\") == 8\n assert candidate(s = \"98765432109876543210\") == 8\n assert candidate(s = \"1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z11\") == -1\n assert candidate(s = \"111222333444555666777888999\") == 8\n assert candidate(s = \"999999999999999999999999999999999999999999999999\") == -1\n assert candidate(s = \"abcdefg1234567890\") == 8\n assert candidate(s = \"5555555555555\") == -1\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij012345678901234567890123456789\") == 8\n assert candidate(s = \"a1b2c2d3e3f4g4h5i5j6k6l7m7n8o8p9q9r0\") == 8\n assert candidate(s = \"zzzzz99999\") == -1\n assert candidate(s = \"a1b1c1d1e1f1g1h1i1j1\") == -1\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p\") == 8\n assert candidate(s = \"9876543210abcdefg\") == 8\n assert candidate(s = \"98765432100123456789\") == 8\n assert candidate(s = \"0000000000000000000000000000000000000000000000000\") == -1\n assert candidate(s = \"abc123xyz456\") == 5\n assert candidate(s = \"123456789012345678901234567890123456789012345678901234567890\") == 8\n assert candidate(s = \"1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7\") == 8\n assert candidate(s = \"zzzzzzzzzzzzzzzzz9zzzzzzzzzzzzzzzz8\") == 8\n assert candidate(s = \"aabbccddeeffgghhii123456789\") == 8\n assert candidate(s = \"0123456789\") == 8\n assert candidate(s = \"abcdefghij1234567890\") == 8\n assert candidate(s = \"abcabcabc123123123\") == 2\n assert candidate(s = \"zzz9zzz8zzz7zzz6zzz5zzz4zzz3zzz2zzz1zzz0zzz\") == 8\n assert candidate(s = \"5555555555555555\") == -1\n assert candidate(s = \"a1b\") == -1\n assert candidate(s = \"1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t\") == 8\n assert candidate(s = \"111222333444555666777888999000\") == 8\n assert candidate(s = \"zzz999zzz888zzz\") == 8\n assert candidate(s = \"0000000000000111111111111222222222222333333333\") == 2\n assert candidate(s = \"abcd1234567890abcd\") == 8\n assert candidate(s = \"123abc123abc123\") == 2\n assert candidate(s = \"123abc456def789ghi0jkl\") == 8\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0a1b2c3d4e5f6g7h8i9j0\") == 8\n assert candidate(s = \"00000000000000000000\") == -1\n assert candidate(s = \"abcdefghij012345678909876543210\") == 8\n assert candidate(s = \"123456789012345678901234567890\") == 8\n assert candidate(s = \"9999999999999999999999999999\") == -1\n assert candidate(s = \"987654321098765432109876543210\") == 8\n assert candidate(s = \"abc123xyz987\") == 8\n assert candidate(s = \"0000111122223333444455556666777788889999\") == 8\n assert candidate(s = \"555555555555555555555555555555555555\") == -1\n assert candidate(s = \"1a1b2c2d3e3f4g4h5i5j6k6l7m7n8o8p9q9r0s0t1u2v3w4x5y6z7\") == 8\n assert candidate(s = \"1122334455667788990011223344556677889900\") == 8\n assert candidate(s = \"0123456789abcdefghij0123456789\") == 8\n assert candidate(s = \"1a2b3c4d5e6f7g8h9i0j\") == 8\n assert candidate(s = \"1111111111111111111112\") == 1\n assert candidate(s = \"1234567890abcdefghijabcdefghijabcdefghijabcdefghij012345678901234567890123456789\") == 8\n assert candidate(s = \"1234567890abcdefghij\") == 8\n assert candidate(s = \"122222222222222222222\") == 1\n assert candidate(s = \"123123123123123123123123123123123\") == 2\n assert candidate(s = \"9999999999888888888877777777766666666555555554444444433333333222222221111111100000000\") == 8\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz9876543210\") == 8\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1\") == 8\n assert candidate(s = \"111122223333444455556666777788889999\") == 8\n assert candidate(s = \"abcdefghij9876543210\") == 8\n assert candidate(s = \"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\") == -1\n assert candidate(s = \"abcd1234efgh5678ijkl90mnop\") == 8\n assert candidate(s = \"123123123123123\") == 2\n assert candidate(s = \"9876543210abcdefghij0123456789\") == 8\n assert candidate(s = \"5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555\") == -1\n assert candidate(s = \"zz9zz8zz7zz6zz5zz4zz3zz2zz1zz0zz\") == 8\n assert candidate(s = \"12345678901234567890abcdefghijabcdefghijabcdefghijabcdefghij012345678901234567890123456789\") == 8\n assert candidate(s = \"0102030405060708090\") == 8\n assert candidate(s = \"abc1234567890\") == 8\n", "comparison": "exact"}, "public_tests": ["\"dfa12321afd\"", "\"abc1111\""], "hints": ["First of all, get the distinct characters since we are only interested in those", "Let's note that there might not be any digits."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().secondHighest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:04+00:00", "tests_total": 131, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function secondHighest($s) {", "container": "Solution", "callable": "secondHighest", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1798, "task_id": "maximum-number-of-consecutive-values-you-can-make", "difficulty": "Medium", "problem_description": "You are given an integer array coins of length n which represents the n coins that you own. The value of the i^th coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.\n\nReturn the maximum number of consecutive integer values that you can make with your coins starting from and including 0.\n\nNote that you may have multiple coins of the same value.\n\nExample 1:\n\nInput: coins = [1,3]\nOutput: 2\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\nYou can make 2 consecutive integer values starting from 0.\n\nExample 2:\n\nInput: coins = [1,1,1,4]\nOutput: 8\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\n- 2: take [1,1]\n- 3: take [1,1,1]\n- 4: take [4]\n- 5: take [4,1]\n- 6: take [4,1,1]\n- 7: take [4,1,1,1]\nYou can make 8 consecutive integer values starting from 0.\n\nExample 3:\n\nInput: coins = [1,4,10,3,1]\nOutput: 20\n\nConstraints:\n\n- coins.length == n\n- 1 <= n <= 4 * 10^4\n- 1 <= coins[i] <= 4 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coins = [1, 3]) == 2\n assert candidate(coins = [1, 2, 5]) == 4\n assert candidate(coins = [2, 2, 2, 2]) == 1\n assert candidate(coins = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 56\n assert candidate(coins = [1]) == 2\n assert candidate(coins = [1, 4, 10, 3, 1]) == 20\n assert candidate(coins = [40000, 40000, 40000, 40000]) == 1\n assert candidate(coins = [4, 3, 2, 1]) == 11\n assert candidate(coins = [100, 200, 300, 400, 500]) == 1\n assert candidate(coins = [1, 2, 3, 4, 5]) == 16\n assert candidate(coins = [1, 1, 1, 1, 1]) == 6\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1024\n assert candidate(coins = [1, 1, 3, 4]) == 10\n assert candidate(coins = [1, 2, 5, 10]) == 4\n assert candidate(coins = [100, 400, 200, 300]) == 1\n assert candidate(coins = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 1\n assert candidate(coins = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 21\n assert candidate(coins = [2]) == 1\n assert candidate(coins = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(coins = [10000, 20000, 30000, 40000]) == 1\n assert candidate(coins = [100, 400, 1, 1, 1]) == 4\n assert candidate(coins = [2, 2, 3, 3, 3, 4]) == 1\n assert candidate(coins = [1, 1, 3, 4, 10]) == 20\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(coins = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 84\n assert candidate(coins = [1, 1, 1, 4]) == 8\n assert candidate(coins = [2, 4, 6, 8]) == 1\n assert candidate(coins = [1, 1, 2, 2, 3, 3]) == 13\n assert candidate(coins = [40000]) == 1\n assert candidate(coins = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 1\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100]) == 4\n assert candidate(coins = [5, 7, 11, 13, 17, 19, 23, 29, 31]) == 1\n assert candidate(coins = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 31\n assert candidate(coins = [2, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144]) == 1\n assert candidate(coins = [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(coins = [1, 2, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]) == 3073\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000]) == 4\n assert candidate(coins = [1, 5, 10, 25, 50, 100, 200, 500, 1000]) == 2\n assert candidate(coins = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 1\n assert candidate(coins = [3, 6, 9, 12, 15, 18, 21, 24, 27]) == 1\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2048\n assert candidate(coins = [2, 3, 6, 12, 24, 48, 96, 192, 384, 768]) == 1\n assert candidate(coins = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 111\n assert candidate(coins = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 5, 5, 5, 5, 5]) == 41\n assert candidate(coins = [1, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576]) == 2\n assert candidate(coins = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 1\n assert candidate(coins = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 73\n assert candidate(coins = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256]) == 1023\n assert candidate(coins = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 2\n assert candidate(coins = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) == 1597\n assert candidate(coins = [1, 2, 3, 6, 11, 20, 37, 68, 129, 254]) == 532\n assert candidate(coins = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(coins = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 1\n assert candidate(coins = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(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, 33, 34, 35, 36, 37, 38, 39, 40]) == 821\n assert candidate(coins = [100, 200, 200, 300, 400, 400, 400, 500, 600, 600, 700, 800, 800, 900, 1000]) == 1\n assert candidate(coins = [2, 2, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7]) == 1\n assert candidate(coins = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 46\n assert candidate(coins = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(coins = [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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 2\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 8192\n assert candidate(coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1\n assert candidate(coins = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2\n assert candidate(coins = [10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) == 1\n assert candidate(coins = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) == 144\n assert candidate(coins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 121\n assert candidate(coins = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 1\n assert candidate(coins = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(coins = [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]) == 166\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64]) == 128\n assert candidate(coins = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 111\n assert candidate(coins = [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(coins = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 2\n assert candidate(coins = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 1\n assert candidate(coins = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 1\n assert candidate(coins = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 2\n assert candidate(coins = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]) == 28656\n assert candidate(coins = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 213\n assert candidate(coins = [1, 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(coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 1\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 32768\n assert candidate(coins = [1, 2, 3, 4, 5, 10, 20, 50, 100, 200]) == 46\n assert candidate(coins = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128]) == 511\n assert candidate(coins = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16]) == 63\n assert candidate(coins = [1, 2, 4, 8, 16, 32, 64, 128]) == 256\n assert candidate(coins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(coins = [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]) == 164\n assert candidate(coins = [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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 151\n assert candidate(coins = [4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]) == 1\n assert candidate(coins = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) == 4\n assert candidate(coins = [1, 5, 10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) == 2\n", "comparison": "exact"}, "public_tests": ["[1,3]", "[1,1,1,4]", "[1,4,10,3,1]"], "hints": ["If you can make the first x values and you have a value v, then you can make all the values ≤ v + x", "Sort the array of coins. You can always make the value 0 so you can start with x = 0.", "Process the values starting from the smallest and stop when there is a value that cannot be achieved with the current x."], "metadata": {"canonical_parameter_names": ["coins"], "leetcode_dataset_entry_point": "Solution().getMaximumConsecutive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:07+00:00", "tests_total": 98, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function getMaximumConsecutive($coins) {", "container": "Solution", "callable": "getMaximumConsecutive", "parameters": [{"name": "coins", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1800, "task_id": "maximum-ascending-subarray-sum", "difficulty": "Easy", "problem_description": "Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums.\n\nA subarray is defined as a contiguous sequence of numbers in an array.\n\nExample 1:\n\nInput: nums = [10,20,30,5,10,50]\nOutput: 65\nExplanation: [5,10,50] is the ascending subarray with the maximum sum of 65.\n\nExample 2:\n\nInput: nums = [10,20,30,40,50]\nOutput: 150\nExplanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.\n\nExample 3:\n\nInput: nums = [12,17,15,13,10,11,12]\nOutput: 33\nExplanation: [10,11,12] is the ascending subarray with the maximum sum of 33.\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, 98, 97, 96]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [10]) == 10\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [100, 1, 2, 3, 100, 2, 3, 100]) == 106\n assert candidate(nums = [100]) == 100\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50]) == 150\n assert candidate(nums = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2]) == 3\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [10, 20, 30, 5, 10, 50]) == 65\n assert candidate(nums = [12, 17, 15, 13, 10, 11, 12]) == 33\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 5]) == 14\n assert candidate(nums = [100, 100, 100]) == 100\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 175\n assert candidate(nums = [5, 10, 9, 15, 20, 25, 20, 30, 40, 50]) == 140\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 40, 41, 42, 43, 44]) == 605\n assert candidate(nums = [5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7]) == 18\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 166\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 = [50, 1, 2, 3, 4, 50, 5, 6, 7, 8, 9, 50, 10, 11, 12, 13, 14, 15, 50, 16, 17, 18, 19, 20]) == 125\n assert candidate(nums = [30, 20, 10, 21, 22, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [10, 20, 15, 25, 30, 22, 35, 40, 38, 45, 50]) == 133\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 240\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8, 6, 9, 10, 11, 10]) == 36\n assert candidate(nums = [10, 20, 10, 20, 30, 20, 30, 40, 50, 40, 60]) == 140\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 7, 8, 9, 10, 8, 9, 10, 11]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 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]) == 400\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92]) == 100\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12]) == 23\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 3, 5, 7, 4, 6, 8, 5, 7, 9]) == 21\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 100\n assert candidate(nums = [20, 30, 25, 35, 40, 35, 45, 50, 45, 55, 60, 55, 65, 70, 65, 75, 80]) == 220\n assert candidate(nums = [5, 10, 15, 20, 25, 1, 2, 3, 4, 5, 30, 35, 40, 45, 50, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 215\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 = [1, 2, 3, 2, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]) == 41\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 35, 45, 50, 45, 55, 60, 55, 65, 70, 65, 75, 80, 75, 85, 90]) == 250\n assert candidate(nums = [1, 10, 11, 2, 20, 21, 3, 30, 31, 4, 40, 41, 5, 50, 51, 6, 60, 61, 7, 70, 71]) == 148\n assert candidate(nums = [33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 747\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 3, 4, 5, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 55\n assert candidate(nums = [3, 2, 1, 10, 20, 30, 25, 35, 45, 55]) == 160\n assert candidate(nums = [10, 20, 15, 25, 30, 20, 35, 40, 50, 45, 60]) == 145\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 110\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == 30\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]) == 624\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]) == 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 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 110\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 10, 20, 15, 25, 30, 20, 35, 40]) == 95\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [10, 20, 15, 25, 30, 20, 35, 40, 30, 45, 50]) == 125\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 550\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 100\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 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, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 100\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 1, 2, 3, 4, 5, 10, 15, 20]) == 105\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]) == 50\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 165\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]) == 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]) == 210\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 156\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 100\n assert candidate(nums = [9, 10, 11, 8, 12, 13, 14, 7, 15, 16, 17, 18, 6, 19, 20, 21, 22, 23, 5, 24, 25, 26, 27, 28]) == 135\n assert candidate(nums = [5, 6, 3, 8, 9, 10, 7, 8, 9]) == 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]) == 15\n assert candidate(nums = [1, 1, 1, 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\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 = [30, 31, 32, 33, 34, 35, 15, 16, 17, 18, 19, 20, 21]) == 195\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 22\n assert candidate(nums = [5, 6, 7, 8, 9, 5, 6, 7, 10, 11, 12, 13]) == 64\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5]) == 70\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]) == 55\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(nums = [50, 40, 30, 20, 10, 20, 30, 40, 50, 60]) == 210\n assert candidate(nums = [10, 20, 10, 20, 30, 40, 30, 40, 50, 60]) == 180\n assert candidate(nums = [10, 20, 30, 25, 40, 50, 60, 55, 70, 80]) == 205\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 14]) == 39\n assert candidate(nums = [5, 1, 2, 3, 4, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [2, 3, 6, 6, 5, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 11, 12, 5, 6, 7]) == 68\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [5, 3, 7, 8, 2, 6, 9, 11, 10, 15]) == 28\n assert candidate(nums = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 1, 2, 3, 4, 5]) == 605\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 110\n assert candidate(nums = [10, 20, 30, 25, 26, 27, 28, 29, 30, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 275\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16]) == 72\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]) == 30\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]) == 120\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 8, 9, 10, 11, 12]) == 50\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 9, 11, 10]) == 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]) == 55\n assert candidate(nums = [5, 5, 5, 5, 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 = [1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 12, 11, 12]) == 50\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11]) == 51\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 15\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]) == 210\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 20, 30]) == 61\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 200\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 = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 200\n assert candidate(nums = [10, 15, 20, 25, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 100\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 150\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]) == 45\n assert candidate(nums = [100, 99, 98, 97, 96, 1, 2, 3, 4, 5]) == 100\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]) == 20\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]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 10, 11, 12, 13, 12, 13, 14, 15]) == 54\n assert candidate(nums = [3, 5, 4, 6, 7, 8, 6, 7, 8, 9, 10, 8, 9, 10, 11, 12, 10, 11, 12, 13, 14]) == 60\n", "comparison": "exact"}, "public_tests": ["[10,20,30,5,10,50]", "[10,20,30,40,50]", "[12,17,15,13,10,11,12]"], "hints": ["It is fast enough to check all possible subarrays", "The end of each ascending subarray will be the start of the next"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxAscendingSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:09+00:00", "tests_total": 128, "tests_dropped": 6, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function maxAscendingSum($nums) {", "container": "Solution", "callable": "maxAscendingSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1801, "task_id": "number-of-orders-in-the-backlog", "difficulty": "Medium", "problem_description": "You are given a 2D integer array orders, where each orders[i] = [price_i, amount_i, orderType_i] denotes that amount_iorders have been placed of type orderType_i at the price price_i. The orderType_i is:\n\n- 0 if it is a batch of buy orders, or\n- 1 if it is a batch of sell orders.\n\nNote that orders[i] represents a batch of amount_i independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.\n\nThere is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:\n\n- If the order is a buy order, you look at the sell order with the smallest price in the backlog. If that sell order's price is smaller than or equal to the current buy order's price, they will match and be executed, and that sell order will be removed from the backlog. Else, the buy order is added to the backlog.\n- Vice versa, if the order is a sell order, you look at the buy order with the largest price in the backlog. If that buy order's price is larger than or equal to the current sell order's price, they will match and be executed, and that buy order will be removed from the backlog. Else, the sell order is added to the backlog.\n\nReturn the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\nOutput: 6\nExplanation: Here is what happens with the orders:\n- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.\n- 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.\n- 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.\n- 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3^rd order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4^th order is added to the backlog.\nFinally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.\n\nExample 2:\n\nInput: orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\nOutput: 999999984\nExplanation: Here is what happens with the orders:\n- 10^9 orders of type sell with price 7 are placed. There are no buy orders, so the 10^9 orders are added to the backlog.\n- 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.\n- 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.\n- 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.\nFinally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (10^9 + 7).\n\nConstraints:\n\n- 1 <= orders.length <= 10^5\n- orders[i].length == 3\n- 1 <= price_i, amount_i <= 10^9\n- orderType_i is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(orders = [[7, 1000000000, 1], [15, 3, 0], [5, 999999995, 0], [5, 1, 1]]) == 999999984\n assert candidate(orders = [[1, 10, 0], [1, 10, 1], [1, 10, 0], [1, 10, 1]]) == 0\n assert candidate(orders = [[100, 1, 0], [200, 2, 0], [300, 3, 1], [400, 4, 1]]) == 10\n assert candidate(orders = [[1, 1, 0], [1, 1, 1], [1, 1, 0], [1, 1, 1]]) == 0\n assert candidate(orders = [[5, 5, 0], [5, 5, 1], [5, 5, 0], [5, 5, 1]]) == 0\n assert candidate(orders = [[100, 100, 0], [100, 100, 1], [101, 100, 0], [99, 100, 1]]) == 0\n assert candidate(orders = [[1, 10, 0], [2, 10, 0], [3, 10, 1], [4, 10, 1]]) == 40\n assert candidate(orders = [[5, 5, 0], [4, 4, 1], [3, 3, 0], [2, 2, 1], [1, 1, 0]]) == 3\n assert candidate(orders = [[100, 10, 0], [200, 15, 0], [100, 5, 1], [200, 20, 1]]) == 20\n assert candidate(orders = [[5, 5, 0], [5, 5, 1]]) == 0\n assert candidate(orders = [[10, 5, 0], [15, 2, 1], [25, 1, 1], [30, 4, 0]]) == 6\n assert candidate(orders = [[100, 1, 0], [99, 2, 0], [98, 3, 0], [97, 4, 1], [96, 5, 1]]) == 3\n assert candidate(orders = [[5, 10, 0], [5, 5, 1], [5, 5, 0], [5, 3, 1]]) == 7\n assert candidate(orders = [[1, 10, 0], [2, 20, 1], [3, 30, 0], [4, 40, 1]]) == 60\n assert candidate(orders = [[100, 10, 0], [99, 9, 1], [98, 8, 0], [97, 7, 1], [96, 6, 0]]) == 8\n assert candidate(orders = [[10, 10, 0], [10, 10, 0], [10, 10, 1], [10, 10, 1]]) == 0\n assert candidate(orders = [[50, 10, 0], [40, 15, 0], [30, 20, 0], [20, 25, 1], [10, 30, 1], [5, 35, 1], [3, 40, 1], [2, 45, 1], [1, 50, 1]]) == 180\n assert candidate(orders = [[10, 5, 0], [20, 5, 0], [30, 5, 0], [40, 5, 0], [10, 5, 1], [20, 5, 1], [30, 5, 1], [40, 5, 1], [5, 5, 0], [35, 5, 1]]) == 30\n assert candidate(orders = [[1, 1000000000, 0], [1, 1000000000, 0], [1, 1000000000, 1], [1, 1000000000, 1], [1, 1000000000, 0], [1, 1000000000, 1]]) == 0\n assert candidate(orders = [[1000000000, 1, 0], [1000000000, 1, 0], [1000000000, 1, 0], [1000000000, 1, 1], [1000000000, 1, 1], [1000000000, 1, 1]]) == 0\n assert candidate(orders = [[10, 5, 0], [9, 5, 0], [8, 5, 0], [7, 5, 0], [6, 5, 0], [6, 5, 1], [7, 5, 1], [8, 5, 1], [9, 5, 1], [10, 5, 1]]) == 20\n assert candidate(orders = [[1000000000, 1, 0], [999999999, 2, 0], [999999998, 3, 0], [999999997, 4, 1], [999999996, 5, 1], [999999995, 6, 1]]) == 9\n assert candidate(orders = [[1, 1000000000, 0], [1000000000, 1, 1], [2, 999999999, 0], [999999999, 2, 1], [3, 999999998, 0], [999999998, 3, 1], [4, 999999997, 0], [999999997, 4, 1]]) == 999999983\n assert candidate(orders = [[1000000000, 1, 0], [999999999, 2, 0], [999999998, 3, 0], [999999997, 4, 1], [999999996, 5, 1]]) == 3\n assert candidate(orders = [[1, 1000, 0], [2, 2000, 1], [3, 3000, 0], [4, 4000, 1], [5, 5000, 0], [6, 6000, 1], [7, 7000, 0], [8, 8000, 1], [9, 9000, 0], [10, 10000, 1]]) == 15000\n assert candidate(orders = [[1000, 1, 0], [1000, 2, 0], [1000, 3, 0], [1000, 1, 1], [1000, 2, 1], [1000, 3, 1]]) == 0\n assert candidate(orders = [[10, 100, 0], [20, 50, 1], [15, 30, 0], [25, 20, 1], [5, 10, 0], [30, 5, 1]]) == 215\n assert candidate(orders = [[100, 10, 0], [90, 5, 1], [80, 15, 0], [70, 20, 1], [60, 25, 0], [50, 30, 1]]) == 5\n assert candidate(orders = [[999999999, 50000, 0], [1, 50000, 1], [999999998, 50000, 0], [2, 50000, 1], [999999997, 50000, 0], [3, 50000, 1]]) == 0\n assert candidate(orders = [[1, 1000000000, 0], [2, 999999999, 0], [3, 999999998, 0], [4, 999999997, 0], [5, 999999996, 0], [5, 999999996, 1], [4, 999999997, 1], [3, 999999998, 1], [2, 999999999, 1], [1, 1000000000, 1]]) == 0\n assert candidate(orders = [[10, 10, 0], [20, 20, 1], [15, 15, 0], [16, 16, 1], [14, 14, 0], [17, 17, 1]]) == 92\n assert candidate(orders = [[10, 1, 0], [9, 2, 0], [8, 3, 0], [7, 4, 0], [6, 5, 1], [5, 6, 1], [4, 7, 1], [3, 8, 1], [2, 9, 1], [1, 10, 1]]) == 35\n assert candidate(orders = [[1000, 1000000, 0], [1001, 1000000, 0], [1002, 1000000, 0], [999, 1000000, 1], [998, 1000000, 1], [997, 1000000, 1]]) == 0\n assert candidate(orders = [[10, 10, 0], [20, 10, 1], [15, 10, 0], [25, 10, 1], [10, 10, 0], [20, 10, 1], [15, 10, 0], [25, 10, 1], [10, 10, 0], [20, 10, 1], [15, 10, 0], [25, 10, 1], [10, 10, 0], [20, 10, 1], [15, 10, 0], [25, 10, 1]]) == 160\n assert candidate(orders = [[1, 1000000000, 0], [2, 1000000000, 1], [3, 1000000000, 0], [4, 1000000000, 1], [5, 1000000000, 0], [6, 1000000000, 1]]) == 999999993\n assert candidate(orders = [[10, 1000, 0], [20, 1000, 0], [30, 1000, 0], [40, 1000, 1], [50, 1000, 1], [60, 1000, 1], [70, 1000, 0], [80, 1000, 1], [90, 1000, 0]]) == 5000\n assert candidate(orders = [[10, 5, 0], [20, 10, 0], [30, 15, 0], [40, 20, 0], [50, 25, 0], [10, 5, 1], [20, 10, 1], [30, 15, 1], [40, 20, 1], [50, 25, 1]]) == 60\n assert candidate(orders = [[10, 5, 0], [20, 5, 0], [30, 5, 0], [40, 5, 0], [15, 5, 1], [25, 5, 1], [35, 5, 1], [45, 5, 1]]) == 20\n assert candidate(orders = [[1, 1000000000, 0], [2, 1000000000, 0], [3, 1000000000, 0], [1, 1000000000, 1], [2, 1000000000, 1], [3, 1000000000, 1]]) == 999999993\n assert candidate(orders = [[10, 1, 0], [11, 2, 0], [12, 3, 0], [13, 4, 1], [14, 5, 1], [15, 6, 1], [16, 7, 1], [17, 8, 0], [18, 9, 0], [19, 10, 0]]) == 11\n assert candidate(orders = [[10, 1, 0], [10, 2, 0], [10, 3, 0], [10, 4, 1], [10, 5, 1], [10, 6, 1], [10, 7, 1], [10, 8, 0], [10, 9, 0], [10, 10, 0]]) == 11\n assert candidate(orders = [[5, 1, 0], [5, 2, 0], [5, 3, 0], [5, 4, 0], [5, 5, 1], [5, 4, 1], [5, 3, 1], [5, 2, 1], [5, 1, 1]]) == 5\n assert candidate(orders = [[100, 5, 0], [90, 10, 0], [80, 15, 0], [70, 20, 0], [60, 25, 0], [50, 30, 1], [40, 35, 1], [30, 40, 1], [20, 45, 1], [10, 50, 1]]) == 125\n assert candidate(orders = [[10, 1000, 0], [10, 900, 0], [10, 800, 0], [10, 700, 1], [10, 600, 1], [10, 500, 1], [10, 400, 1]]) == 500\n assert candidate(orders = [[10, 5, 0], [10, 5, 1], [10, 5, 0], [10, 5, 1], [10, 5, 0], [10, 5, 1], [10, 5, 0], [10, 5, 1]]) == 0\n assert candidate(orders = [[1, 999999999, 0], [1, 999999999, 0], [1, 999999999, 0], [1, 999999999, 0], [2, 999999999, 1], [2, 999999999, 1], [2, 999999999, 1], [2, 999999999, 1]]) == 999999943\n assert candidate(orders = [[10, 1, 0], [9, 2, 0], [8, 3, 0], [7, 4, 1], [6, 5, 1], [5, 6, 0], [4, 7, 0], [3, 8, 1], [2, 9, 1], [1, 10, 0]]) == 17\n assert candidate(orders = [[5, 100, 0], [10, 100, 1], [15, 100, 0], [20, 100, 1], [25, 100, 0], [30, 100, 1]]) == 200\n assert candidate(orders = [[10, 5, 0], [10, 5, 0], [10, 5, 0], [10, 5, 1], [10, 5, 1], [10, 5, 1], [10, 5, 0], [10, 5, 1], [10, 5, 0], [10, 5, 1]]) == 0\n assert candidate(orders = [[100, 100, 1], [90, 200, 1], [80, 300, 1], [70, 400, 0], [60, 500, 0], [50, 600, 0]]) == 2100\n assert candidate(orders = [[1000000000, 1, 0], [999999999, 1, 0], [999999998, 1, 0], [999999997, 1, 1], [999999996, 1, 1], [999999995, 1, 1]]) == 0\n assert candidate(orders = [[10, 1, 0], [20, 2, 0], [30, 3, 0], [40, 4, 0], [50, 5, 0], [10, 1, 1], [20, 2, 1], [30, 3, 1], [40, 4, 1], [50, 5, 1]]) == 12\n assert candidate(orders = [[1, 1000000000, 0], [1000000000, 1, 1], [500000000, 2, 0], [1000000000, 999999999, 1], [1, 1, 0]]) == 999999996\n assert candidate(orders = [[1, 1000000000, 0], [2, 1000000000, 1], [3, 1000000000, 0], [4, 1000000000, 1], [5, 1000000000, 0], [6, 1000000000, 1]]) == 999999993\n assert candidate(orders = [[100, 1000, 0], [999, 500, 1], [998, 750, 1], [1000, 1000, 0], [999, 250, 0]]) == 1000\n assert candidate(orders = [[100, 1, 0], [99, 2, 0], [98, 3, 0], [97, 4, 1], [96, 5, 1], [95, 6, 0], [94, 7, 1], [93, 8, 0], [92, 9, 1]]) == 5\n assert candidate(orders = [[1, 1000000000, 0], [1, 1000000000, 0], [1, 1000000000, 0], [1, 1000000000, 1], [1, 1000000000, 1], [1, 1000000000, 1]]) == 0\n assert candidate(orders = [[100, 1, 0], [99, 2, 0], [98, 3, 0], [97, 4, 1], [96, 5, 1], [95, 6, 0], [94, 7, 0], [93, 8, 1], [92, 9, 1]]) == 7\n assert candidate(orders = [[100, 100, 0], [200, 200, 0], [300, 300, 0], [400, 400, 0], [500, 500, 1], [600, 600, 1], [700, 700, 1], [800, 800, 1], [900, 900, 1], [1000, 1000, 1]]) == 5500\n assert candidate(orders = [[10, 5, 0], [20, 10, 0], [30, 15, 0], [5, 1, 1], [15, 2, 1], [25, 3, 1]]) == 24\n assert candidate(orders = [[100, 100, 0], [99, 150, 0], [98, 200, 0], [97, 250, 1], [96, 300, 1], [95, 350, 1]]) == 450\n assert candidate(orders = [[1, 1, 0], [2, 1, 0], [3, 1, 0], [4, 1, 0], [5, 1, 0], [6, 1, 0], [7, 1, 0], [8, 1, 0], [9, 1, 0], [10, 1, 0], [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]]) == 10\n assert candidate(orders = [[1000000000, 1, 0], [1, 1, 1], [500000000, 1, 0], [500000000, 1, 1], [1000000000, 1, 0], [1, 1, 1]]) == 0\n assert candidate(orders = [[100, 100, 0], [90, 200, 0], [80, 300, 0], [70, 400, 1], [60, 500, 1], [50, 600, 1]]) == 900\n assert candidate(orders = [[10, 1, 0], [20, 2, 0], [10, 1, 1], [20, 2, 1], [30, 3, 0], [25, 2, 1], [15, 1, 0], [5, 1, 1]]) == 1\n assert candidate(orders = [[100, 5, 0], [200, 10, 0], [150, 5, 1], [160, 5, 1], [200, 20, 0], [150, 10, 1]]) == 15\n assert candidate(orders = [[10, 10, 0], [20, 10, 0], [30, 10, 0], [40, 10, 0], [50, 10, 0], [10, 10, 1], [20, 10, 1], [30, 10, 1], [40, 10, 1], [50, 10, 1], [10, 10, 0], [20, 10, 0], [30, 10, 0], [40, 10, 0], [50, 10, 0], [10, 10, 1], [20, 10, 1], [30, 10, 1], [40, 10, 1], [50, 10, 1]]) == 60\n assert candidate(orders = [[100, 1, 0], [90, 2, 0], [80, 3, 0], [70, 4, 1], [60, 5, 1], [50, 6, 1], [40, 7, 1], [30, 8, 1], [20, 9, 1], [10, 10, 1]]) == 43\n assert candidate(orders = [[1, 1, 0], [2, 1, 0], [3, 1, 0], [4, 1, 0], [5, 1, 0], [5, 1, 1], [4, 1, 1], [3, 1, 1], [2, 1, 1], [1, 1, 1]]) == 0\n assert candidate(orders = [[1000000000, 1, 0], [999999999, 2, 0], [999999998, 3, 0], [999999997, 4, 1], [999999996, 5, 1], [999999995, 6, 0], [999999994, 7, 0], [999999993, 8, 1], [999999992, 9, 1]]) == 7\n assert candidate(orders = [[10, 100, 0], [20, 50, 0], [30, 200, 1], [15, 150, 1], [25, 100, 0], [35, 100, 1]]) == 400\n assert candidate(orders = [[1, 1, 0], [1, 1, 1], [1, 1, 0], [1, 1, 1], [1, 1, 0], [1, 1, 1]]) == 0\n assert candidate(orders = [[1, 1, 0], [2, 2, 0], [3, 3, 0], [4, 4, 0], [5, 5, 0], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]) == 12\n assert candidate(orders = [[100, 5, 0], [100, 5, 0], [100, 5, 1], [100, 5, 1], [100, 5, 0], [100, 5, 1]]) == 0\n assert candidate(orders = [[5, 1, 0], [6, 1, 0], [7, 1, 0], [8, 1, 0], [9, 1, 0], [10, 1, 1], [11, 1, 1], [12, 1, 1], [13, 1, 1], [14, 1, 1]]) == 10\n assert candidate(orders = [[10, 10, 0], [20, 20, 0], [30, 30, 0], [40, 40, 0], [50, 50, 0], [10, 1, 1], [20, 2, 1], [30, 3, 1], [40, 4, 1], [50, 5, 1]]) == 135\n assert candidate(orders = [[50, 10, 0], [50, 15, 0], [50, 20, 0], [50, 25, 1], [50, 30, 1], [50, 35, 1], [50, 40, 1], [50, 45, 1], [50, 50, 1]]) == 180\n assert candidate(orders = [[100, 50, 0], [100, 50, 0], [100, 50, 0], [100, 50, 1], [100, 50, 1], [100, 50, 1]]) == 0\n assert candidate(orders = [[10, 5, 0], [20, 5, 0], [30, 5, 0], [10, 5, 1], [20, 5, 1], [30, 5, 1], [15, 5, 0], [25, 5, 0], [35, 5, 0]]) == 15\n assert candidate(orders = [[10, 1, 0], [10, 1, 1], [11, 1, 0], [9, 1, 1], [12, 1, 0], [8, 1, 1], [13, 1, 0], [7, 1, 1]]) == 0\n assert candidate(orders = [[1, 1000000000, 0], [2, 1000000000, 0], [3, 1000000000, 0], [4, 1000000000, 1], [5, 1000000000, 1], [6, 1000000000, 1]]) == 999999965\n assert candidate(orders = [[10, 10, 0], [10, 10, 1], [10, 10, 0], [10, 10, 1], [10, 10, 0], [10, 10, 1], [10, 10, 0], [10, 10, 1], [10, 10, 0], [10, 10, 1]]) == 0\n assert candidate(orders = [[1, 1000000000, 0], [2, 999999999, 0], [3, 999999998, 0], [4, 999999997, 1], [5, 999999996, 1], [6, 999999995, 1], [7, 999999994, 1], [8, 999999993, 0], [9, 999999992, 0], [10, 999999991, 0]]) == 999999982\n assert candidate(orders = [[50, 10, 0], [40, 20, 0], [30, 30, 0], [20, 40, 0], [10, 50, 0], [10, 60, 1], [20, 70, 1], [30, 80, 1], [40, 90, 1], [50, 100, 1], [15, 5, 0], [25, 5, 0], [35, 5, 0], [45, 5, 0], [55, 5, 0]]) == 335\n assert candidate(orders = [[100, 10, 0], [90, 10, 0], [80, 10, 0], [70, 10, 0], [60, 10, 0], [50, 10, 1], [40, 10, 1], [30, 10, 1], [20, 10, 1], [10, 10, 1]]) == 0\n assert candidate(orders = [[10, 5, 0], [20, 5, 0], [30, 5, 0], [15, 10, 1], [25, 10, 1], [35, 10, 1], [10, 5, 0], [20, 5, 0], [30, 5, 0], [15, 10, 1], [25, 10, 1], [35, 10, 1]]) == 50\n assert candidate(orders = [[100, 100000000, 0], [90, 200000000, 0], [80, 300000000, 1], [70, 400000000, 1], [60, 500000000, 0]]) == 900000000\n assert candidate(orders = [[100, 500, 0], [90, 500, 0], [80, 500, 0], [70, 500, 1], [60, 500, 1], [50, 500, 1]]) == 0\n assert candidate(orders = [[10, 1, 0], [10, 2, 1], [10, 3, 0], [10, 4, 1], [10, 5, 0]]) == 3\n assert candidate(orders = [[1, 1000000000, 0], [2, 500000000, 1], [3, 300000000, 0], [4, 200000000, 1], [5, 400000000, 0]]) == 1000000000\n assert candidate(orders = [[100, 5, 0], [101, 3, 0], [102, 2, 0], [99, 5, 1], [98, 6, 1], [97, 7, 1]]) == 8\n assert candidate(orders = [[500, 10, 0], [500, 10, 1], [500, 5, 0], [500, 5, 1], [500, 3, 0], [500, 3, 1]]) == 0\n assert candidate(orders = [[50, 10, 0], [60, 15, 0], [70, 20, 0], [40, 5, 1], [55, 10, 1], [65, 15, 1], [50, 10, 1], [60, 15, 1], [70, 20, 1]]) == 50\n assert candidate(orders = [[10, 1, 0], [20, 1, 1], [30, 1, 0], [40, 1, 1], [50, 1, 0], [60, 1, 1], [70, 1, 0], [80, 1, 1], [90, 1, 0]]) == 1\n assert candidate(orders = [[10, 10, 0], [9, 20, 0], [8, 30, 0], [7, 40, 1], [6, 50, 1], [5, 60, 1]]) == 90\n assert candidate(orders = [[20, 5, 0], [15, 3, 0], [10, 2, 1], [5, 1, 1], [15, 4, 0], [10, 6, 1]]) == 3\n assert candidate(orders = [[100, 1, 0], [200, 1, 0], [300, 1, 0], [400, 1, 0], [500, 1, 0], [150, 1, 1], [250, 1, 1], [350, 1, 1], [450, 1, 1], [550, 1, 1]]) == 6\n assert candidate(orders = [[999999999, 1, 0], [999999998, 2, 0], [999999997, 3, 0], [999999996, 4, 1], [999999995, 5, 1]]) == 3\n assert candidate(orders = [[10, 1, 0], [10, 1, 1], [10, 1, 0], [10, 1, 1], [10, 1, 0], [10, 1, 1], [10, 1, 0], [10, 1, 1], [10, 1, 0], [10, 1, 1]]) == 0\n assert candidate(orders = [[100, 500, 0], [90, 400, 0], [80, 300, 0], [70, 200, 1], [60, 100, 1], [50, 50, 1], [40, 50, 1], [30, 100, 1], [20, 200, 1]]) == 500\n assert candidate(orders = [[100, 100000, 0], [200, 200000, 0], [150, 50000, 1], [175, 75000, 1]]) == 175000\n assert candidate(orders = [[1000000000, 1, 0], [999999999, 1, 0], [999999998, 1, 0], [999999997, 1, 0], [999999996, 1, 0], [999999995, 1, 1], [999999994, 1, 1], [999999993, 1, 1], [999999992, 1, 1], [999999991, 1, 1]]) == 0\n assert candidate(orders = [[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, 0], [10, 10, 0], [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]]) == 54\n assert candidate(orders = [[5, 10, 0], [10, 20, 0], [15, 30, 0], [20, 10, 1], [25, 20, 1], [30, 30, 1]]) == 120\n assert candidate(orders = [[100, 10, 0], [90, 5, 1], [80, 3, 0], [70, 2, 1], [60, 4, 0], [50, 1, 1]]) == 9\n assert candidate(orders = [[10, 1, 0], [20, 1, 0], [30, 1, 0], [40, 1, 0], [50, 1, 0], [10, 1, 1], [20, 1, 1], [30, 1, 1], [40, 1, 1], [50, 1, 1]]) == 4\n assert candidate(orders = [[1, 1000000000, 1], [1000000000, 1, 0], [2, 1000000000, 1], [999999999, 1, 0], [3, 1000000000, 1]]) == 999999984\n assert candidate(orders = [[1, 10, 0], [2, 10, 0], [3, 10, 0], [4, 10, 1], [5, 10, 1], [6, 10, 1], [7, 10, 1], [8, 10, 1], [9, 10, 1]]) == 90\n assert candidate(orders = [[100, 1, 0], [100, 1, 0], [100, 1, 0], [100, 1, 1], [100, 1, 1], [100, 1, 1], [100, 1, 0], [100, 1, 0], [100, 1, 0], [100, 1, 1], [100, 1, 1], [100, 1, 1], [100, 1, 0], [100, 1, 0], [100, 1, 0], [100, 1, 1], [100, 1, 1], [100, 1, 1]]) == 0\n assert candidate(orders = [[100, 10, 0], [90, 20, 0], [80, 30, 0], [70, 40, 0], [60, 50, 0], [50, 60, 1], [40, 70, 1], [30, 80, 1], [20, 90, 1], [10, 100, 1]]) == 250\n assert candidate(orders = [[1, 1000000000, 0], [2, 1000000000, 0], [3, 1000000000, 1], [4, 1000000000, 1], [5, 1000000000, 0]]) == 999999986\n assert candidate(orders = [[1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0], [6, 6, 1], [7, 7, 0], [8, 8, 1], [9, 9, 0], [10, 10, 1]]) == 15\n assert candidate(orders = [[50, 10, 0], [40, 15, 0], [30, 20, 0], [20, 25, 1], [10, 30, 1], [15, 35, 0], [25, 40, 1]]) == 65\n", "comparison": "exact"}, "public_tests": ["[[10,5,0],[15,2,1],[25,1,1],[30,4,0]]", "[[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]"], "hints": ["Store the backlog buy and sell orders in two heaps, the buy orders in a max heap by price and the sell orders in a min heap by price.", "Store the orders in batches and update the fields according to new incoming orders. Each batch should only take 1 \"slot\" in the heap."], "metadata": {"canonical_parameter_names": ["orders"], "leetcode_dataset_entry_point": "Solution().getNumberOfBacklogOrders", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:11+00:00", "tests_total": 113, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "heap-priority-queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function getNumberOfBacklogOrders($orders) {", "container": "Solution", "callable": "getNumberOfBacklogOrders", "parameters": [{"name": "orders", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1802, "task_id": "maximum-value-at-a-given-index-in-a-bounded-array", "difficulty": "Medium", "problem_description": "You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:\n\n- nums.length == n\n- nums[i] is a positive integer where 0 <= i < n.\n- abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.\n- The sum of all the elements of nums does not exceed maxSum.\n- nums[index] is maximized.\n\nReturn nums[index] of the constructed array.\n\nNote that abs(x) equals x if x >= 0, and -x otherwise.\n\nExample 1:\n\nInput: n = 4, index = 2, maxSum = 6\nOutput: 2\nExplanation: nums = [1,2,2,1] is one array that satisfies all the conditions.\nThere are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].\n\nExample 2:\n\nInput: n = 6, index = 1, maxSum = 10\nOutput: 3\n\nConstraints:\n\n- 1 <= n <= maxSum <= 10^9\n- 0 <= index < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,index = 0,maxSum = 1) == 1\n assert candidate(n = 10,index = 5,maxSum = 50) == 7\n assert candidate(n = 6,index = 1,maxSum = 10) == 3\n assert candidate(n = 1000000000,index = 500000000,maxSum = 1000000000) == 1\n assert candidate(n = 4,index = 2,maxSum = 6) == 2\n assert candidate(n = 20,index = 10,maxSum = 210) == 15\n assert candidate(n = 7,index = 3,maxSum = 20) == 4\n assert candidate(n = 100000,index = 0,maxSum = 10000000) == 4450\n assert candidate(n = 9,index = 4,maxSum = 25) == 5\n assert candidate(n = 1000,index = 500,maxSum = 500000) == 750\n assert candidate(n = 1000000000,index = 999999999,maxSum = 1000000000) == 1\n assert candidate(n = 20,index = 10,maxSum = 200) == 15\n assert candidate(n = 100,index = 50,maxSum = 5000) == 75\n assert candidate(n = 4,index = 1,maxSum = 10) == 3\n assert candidate(n = 1000,index = 500,maxSum = 100000) == 315\n assert candidate(n = 100000,index = 99999,maxSum = 10000000) == 4450\n assert candidate(n = 1000000,index = 500000,maxSum = 10000000) == 3001\n assert candidate(n = 999999999,index = 0,maxSum = 999999999) == 1\n assert candidate(n = 1000000000,index = 0,maxSum = 1000000000) == 1\n assert candidate(n = 50,index = 24,maxSum = 1225) == 37\n assert candidate(n = 100,index = 50,maxSum = 5050) == 75\n assert candidate(n = 9,index = 4,maxSum = 45) == 7\n assert candidate(n = 35,index = 17,maxSum = 3000) == 94\n assert candidate(n = 10000,index = 4999,maxSum = 1000000) == 995\n assert candidate(n = 9,index = 4,maxSum = 100) == 13\n assert candidate(n = 20,index = 0,maxSum = 50) == 8\n assert candidate(n = 50,index = 25,maxSum = 500) == 22\n assert candidate(n = 500,index = 250,maxSum = 150000) == 425\n assert candidate(n = 100,index = 50,maxSum = 10000) == 125\n assert candidate(n = 5,index = 2,maxSum = 15) == 4\n assert candidate(n = 50,index = 24,maxSum = 1275) == 38\n assert candidate(n = 200,index = 100,maxSum = 2000) == 43\n assert candidate(n = 1,index = 0,maxSum = 1000000000) == 1000000000\n assert candidate(n = 8,index = 3,maxSum = 30) == 5\n assert candidate(n = 12,index = 6,maxSum = 75) == 9\n assert candidate(n = 10,index = 0,maxSum = 36) == 7\n assert candidate(n = 50,index = 24,maxSum = 5000) == 112\n assert candidate(n = 20,index = 19,maxSum = 50) == 8\n assert candidate(n = 500000000,index = 250000000,maxSum = 1000000000) == 22361\n assert candidate(n = 2,index = 1,maxSum = 3) == 2\n assert candidate(n = 15,index = 7,maxSum = 120) == 11\n assert candidate(n = 10,index = 0,maxSum = 100) == 14\n assert candidate(n = 15,index = 7,maxSum = 500) == 37\n assert candidate(n = 50,index = 25,maxSum = 1000) == 32\n assert candidate(n = 3,index = 1,maxSum = 15) == 5\n assert candidate(n = 25,index = 12,maxSum = 1500) == 66\n assert candidate(n = 7,index = 3,maxSum = 25) == 5\n assert candidate(n = 10,index = 9,maxSum = 100) == 14\n assert candidate(n = 3,index = 1,maxSum = 1000000000) == 333333334\n assert candidate(n = 500,index = 250,maxSum = 2000) == 39\n assert candidate(n = 20,index = 19,maxSum = 200) == 19\n assert candidate(n = 500000,index = 250000,maxSum = 100000000) == 9975\n assert candidate(n = 15,index = 7,maxSum = 100) == 10\n assert candidate(n = 200,index = 100,maxSum = 20100) == 150\n assert candidate(n = 999999999,index = 499999999,maxSum = 999999999) == 1\n assert candidate(n = 200000000,index = 100000000,maxSum = 500000000) == 17321\n assert candidate(n = 1000000,index = 999999,maxSum = 2000000) == 1414\n assert candidate(n = 1000000000,index = 1,maxSum = 1000000000) == 1\n assert candidate(n = 10,index = 4,maxSum = 55) == 8\n assert candidate(n = 100,index = 50,maxSum = 1000) == 31\n assert candidate(n = 10,index = 9,maxSum = 25) == 6\n assert candidate(n = 10,index = 9,maxSum = 36) == 7\n assert candidate(n = 100000,index = 50000,maxSum = 5000000) == 2214\n assert candidate(n = 10,index = 0,maxSum = 50) == 9\n assert candidate(n = 2,index = 1,maxSum = 6) == 3\n assert candidate(n = 10,index = 0,maxSum = 25) == 6\n assert candidate(n = 150,index = 75,maxSum = 100000) == 704\n assert candidate(n = 2,index = 1,maxSum = 1000000000) == 500000000\n assert candidate(n = 5,index = 2,maxSum = 17) == 4\n assert candidate(n = 500000000,index = 250000000,maxSum = 800000000) == 17321\n assert candidate(n = 5,index = 2,maxSum = 20) == 5\n assert candidate(n = 7,index = 3,maxSum = 50) == 8\n", "comparison": "exact"}, "public_tests": ["4\n2\n6", "6\n1\n10"], "hints": ["What if the problem was instead determining if you could generate a valid array with nums[index] == target?", "To generate the array, set nums[index] to target, nums[index-i] to target-i, and nums[index+i] to target-i. Then, this will give the minimum possible sum, so check if the sum is less than or equal to maxSum.", "n is too large to actually generate the array, so you can use the formula 1 + 2 + ... + n = n * (n+1) / 2 to quickly find the sum of nums[0...index] and nums[index...n-1].", "Binary search for the target. If it is possible, then move the lower bound up. Otherwise, move the upper bound down."], "metadata": {"canonical_parameter_names": ["n", "index", "maxSum"], "leetcode_dataset_entry_point": "Solution().maxValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:14+00:00", "tests_total": 92, "tests_dropped": 20, "flags": [], "topic_tags": ["math", "binary-search", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maxValue($n, $index, $maxSum) {", "container": "Solution", "callable": "maxValue", "parameters": [{"name": "n", "type": "Integer"}, {"name": "index", "type": "Integer"}, {"name": "maxSum", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1803, "task_id": "count-pairs-with-xor-in-a-range", "difficulty": "Hard", "problem_description": "Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\n\nA nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.\n\nExample 1:\n\nInput: nums = [1,4,2,7], low = 2, high = 6\nOutput: 6\nExplanation: All nice pairs (i, j) are as follows:\n - (0, 1): nums[0] XOR nums[1] = 5\n - (0, 2): nums[0] XOR nums[2] = 3\n - (0, 3): nums[0] XOR nums[3] = 6\n - (1, 2): nums[1] XOR nums[2] = 6\n - (1, 3): nums[1] XOR nums[3] = 3\n - (2, 3): nums[2] XOR nums[3] = 5\n\nExample 2:\n\nInput: nums = [9,8,4,2,1], low = 5, high = 14\nOutput: 8\nExplanation: All nice pairs (i, j) are as follows:\n - (0, 2): nums[0] XOR nums[2] = 13\n - (0, 3): nums[0] XOR nums[3] = 11\n - (0, 4): nums[0] XOR nums[4] = 8\n - (1, 2): nums[1] XOR nums[2] = 12\n - (1, 3): nums[1] XOR nums[3] = 10\n - (1, 4): nums[1] XOR nums[4] = 9\n - (2, 3): nums[2] XOR nums[3] = 6\n - (2, 4): nums[2] XOR nums[4] = 5\n\nConstraints:\n\n- 1 <= nums.length <= 2 * 10^4\n- 1 <= nums[i] <= 2 * 10^4\n- 1 <= low <= high <= 2 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9],low = 1,high = 10) == 8\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9],low = 3,high = 7) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],low = 15,high = 25) == 1\n assert candidate(nums = [9, 8, 4, 2, 1],low = 5,high = 14) == 8\n assert candidate(nums = [1, 4, 2, 7],low = 2,high = 6) == 6\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],low = 2,high = 60) == 486\n assert candidate(nums = [8, 14, 23, 41, 56, 72],low = 10,high = 50) == 7\n assert candidate(nums = [8, 15, 3, 11, 2, 9, 13],low = 4,high = 12) == 13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],low = 3,high = 12) == 70\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],low = 1,high = 10000) == 89\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000],low = 1000,high = 12000) == 77\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],low = 2,high = 10) == 60\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],low = 5,high = 1000) == 36\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1024, 512, 256, 128],low = 1,high = 256) == 35\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],low = 2,high = 16) == 64\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993],low = 1,high = 10) == 21\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],low = 2,high = 6) == 35\n assert candidate(nums = [1023, 2047, 3071, 4095, 5119, 6143, 7167, 8191, 9215, 10239],low = 500,high = 5000) == 17\n assert candidate(nums = [2, 3, 1, 6, 7, 5, 4, 8],low = 3,high = 9) == 16\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999],low = 2000,high = 8000) == 18\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],low = 3,high = 15) == 18\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],low = 10,high = 50) == 102\n assert candidate(nums = [6, 2, 3, 8, 10, 12, 15, 18],low = 1,high = 10) == 14\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],low = 20,high = 80) == 92\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],low = 5,high = 35) == 336\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31],low = 5,high = 20) == 15\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],low = 10,high = 2000) == 51\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225],low = 50,high = 200) == 63\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],low = 1,high = 1000) == 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],low = 1,high = 20) == 86\n assert candidate(nums = [15, 3, 8, 7, 10, 12, 13, 14],low = 5,high = 15) == 18\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400],low = 50,high = 200) == 7\n assert candidate(nums = [31, 14, 7, 28, 21, 1, 2, 4, 8, 16],low = 5,high = 25) == 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],low = 5,high = 25) == 125\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],low = 5,high = 25) == 42\n assert candidate(nums = [20000, 19999, 19998, 19997, 19996, 19995, 19994, 19993, 19992, 19991],low = 100,high = 200) == 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],low = 1,high = 10) == 80\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],low = 1,high = 512) == 36\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],low = 2,high = 15) == 13\n assert candidate(nums = [1234, 2345, 3456, 4567, 5678, 6789, 7890],low = 1000,high = 5000) == 11\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024],low = 2000,high = 7000) == 3\n assert candidate(nums = [24, 48, 72, 96, 120, 144, 168, 192, 216, 240],low = 20,high = 100) == 16\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],low = 5,high = 200) == 27\n assert candidate(nums = [8191, 4095, 2047, 1023, 511],low = 1500,high = 3000) == 2\n assert candidate(nums = [123, 456, 789, 101, 112, 134, 156, 178, 190, 212],low = 50,high = 150) == 6\n assert candidate(nums = [16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],low = 1,high = 10000) == 89\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],low = 1,high = 30) == 211\n assert candidate(nums = [1024, 2048, 3072, 4096, 5120, 6144, 7168],low = 1024,high = 6144) == 18\n assert candidate(nums = [9876, 5432, 10987, 6543, 2019, 8765, 4321, 7654, 3210, 1111],low = 1000,high = 5000) == 14\n assert candidate(nums = [20000, 15000, 10000, 5000, 2500, 1250, 625],low = 1000,high = 5000) == 4\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012, 1113, 1214, 1315, 1416, 1517, 1618, 1719, 1820, 1921, 2022],low = 100,high = 500) == 41\n assert candidate(nums = [12345, 12346, 12347, 12348, 12349, 12350, 12351, 12352, 12353, 12354],low = 1,high = 5) == 18\n assert candidate(nums = [23, 5, 7, 9, 11, 13, 17, 19, 21, 23],low = 3,high = 15) == 14\n assert candidate(nums = [5000, 10000, 15000, 20000, 500, 1000, 1500, 2000],low = 100,high = 5000) == 8\n assert candidate(nums = [8, 13, 14, 30, 15, 17, 9],low = 3,high = 12) == 7\n assert candidate(nums = [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],low = 10,high = 70) == 149\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],low = 10,high = 40) == 37\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],low = 500,high = 1000) == 9\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],low = 10,high = 100) == 17\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],low = 100,high = 1000) == 90\n assert candidate(nums = [1023, 511, 255, 127, 63],low = 100,high = 500) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],low = 1,high = 5000) == 76\n assert candidate(nums = [20000, 19000, 18000, 17000, 16000, 15000, 14000, 13000, 12000, 11000, 10000, 9000, 8000, 7000, 6000],low = 500,high = 10000) == 43\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 1012, 1113, 1214, 1315, 1416, 1517],low = 100,high = 1000) == 51\n assert candidate(nums = [9876, 6543, 3210, 1234, 5678, 8765, 5432, 2109, 4321],low = 1000,high = 10000) == 23\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],low = 15,high = 55) == 21\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],low = 2,high = 18) == 28\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],low = 1,high = 15) == 24\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],low = 2,high = 10) == 63\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],low = 100,high = 500) == 20\n assert candidate(nums = [18, 17, 32, 31, 16, 15, 8, 7, 4, 3, 2, 1],low = 4,high = 12) == 14\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],low = 20,high = 100) == 15\n", "comparison": "exact"}, "public_tests": ["[1,4,2,7]\n2\n6", "[9,8,4,2,1]\n5\n14"], "hints": ["Let's note that we can count all pairs with XOR ≤ K, so the answer would be to subtract the number of pairs withs XOR < low from the number of pairs with XOR ≤ high.", "For each value, find out the number of values when you XOR it with the result is ≤ K using a trie."], "metadata": {"canonical_parameter_names": ["nums", "low", "high"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:16+00:00", "tests_total": 100, "tests_dropped": 28, "flags": [], "topic_tags": ["array", "bit-manipulation", "trie"]}, "language": "php", "interface": {"raw_signature": "function countPairs($nums, $low, $high) {", "container": "Solution", "callable": "countPairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "low", "type": "Integer"}, {"name": "high", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1805, "task_id": "number-of-different-integers-in-a-string", "difficulty": "Easy", "problem_description": "You are given a string word that consists of digits and lowercase English letters.\n\nYou will replace every non-digit character with a space. For example, \"a123bc34d8ef34\" will become \" 123 34 8 34\". Notice that you are left with some integers that are separated by at least one space: \"123\", \"34\", \"8\", and \"34\".\n\nReturn the number of different integers after performing the replacement operations on word.\n\nTwo integers are considered different if their decimal representations without any leading zeros are different.\n\nExample 1:\n\nInput: word = \"a123bc34d8ef34\"\nOutput: 3\nExplanation: The three different integers are \"123\", \"34\", and \"8\". Notice that \"34\" is only counted once.\n\nExample 2:\n\nInput: word = \"leet1234code234\"\nOutput: 2\n\nExample 3:\n\nInput: word = \"a1b01c001\"\nOutput: 1\nExplanation: The three integers \"1\", \"01\", and \"001\" all represent the same integer because\nthe leading zeros are ignored when comparing their decimal values.\n\nConstraints:\n\n- 1 <= word.length <= 1000\n- word consists of digits and lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0\") == 10\n assert candidate(word = \"a123bc34d8ef34\") == 3\n assert candidate(word = \"a1a2a3a4a5a6a7a8a9a0\") == 10\n assert candidate(word = \"100leetcode\") == 1\n assert candidate(word = \"a1a1a1\") == 1\n assert candidate(word = \"0a001b002\") == 3\n assert candidate(word = \"12345\") == 1\n assert candidate(word = \"1a2b3c4d5e6f7g8h9i0j\") == 10\n assert candidate(word = \"00000\") == 1\n assert candidate(word = \"0a001b1c1\") == 2\n assert candidate(word = \"111222333444555666777888999000\") == 1\n assert candidate(word = \"leet1234code234\") == 2\n assert candidate(word = \"1234567890\") == 1\n assert candidate(word = \"000111222333444555666777888999000\") == 1\n assert candidate(word = \"11223344556677889900\") == 1\n assert candidate(word = \"a1b1c1\") == 1\n assert candidate(word = \"1a2b3c4d5e6f7g8h9i0j1\") == 10\n assert candidate(word = \"abc\") == 0\n assert candidate(word = \"22o22o22o\") == 1\n assert candidate(word = \"a1b01c001\") == 1\n assert candidate(word = \"a001b002c003\") == 3\n assert candidate(word = \"a001001b1001c001001\") == 1\n assert candidate(word = \"1a2b3c4d5\") == 5\n assert candidate(word = \"0a0b0c0\") == 1\n assert candidate(word = \"0abc00abc000abc0000abc\") == 1\n assert candidate(word = \"1a10a100a1000a10000a1\") == 5\n assert candidate(word = \"123abc456def789ghi123jkl456mno789pqr\") == 3\n assert candidate(word = \"abc123xyz456abc123xyz456abc123xyz456\") == 2\n assert candidate(word = \"0001abc002def03ghi0004\") == 4\n assert candidate(word = \"same123same123same123same\") == 1\n assert candidate(word = \"1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == 1\n assert candidate(word = \"mixed123with456numbers789\") == 3\n assert candidate(word = \"000111000222000333000444000555000\") == 1\n assert candidate(word = \"1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t\") == 10\n assert candidate(word = \"123abc456def789ghi123jkl456mno789pqr001s002t003u\") == 6\n assert candidate(word = \"123abc321def234ghi432jkl543mno654pqrs765tuvw876xyz987\") == 9\n assert candidate(word = \"1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0a\") == 10\n assert candidate(word = \"1a11a111a1111a11111a111111\") == 6\n assert candidate(word = \"9876543210a123456789b0987654321c\") == 3\n assert candidate(word = \"aaa123bbb123ccc123ddd123eee123\") == 1\n assert candidate(word = \"a0b00c000d0000e00000f000000g0000000h00000000i00000000j000000000\") == 1\n assert candidate(word = \"z9z8z7z6z5z4z3z2z1z0z9z8z7z6z5z4z3z2z1z0\") == 10\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0a01b02c03d04e05f06g07h08i09j00\") == 10\n assert candidate(word = \"a10000b1000c100d10e1f0g00h000i0000j00000k\") == 6\n assert candidate(word = \"1a10a100a1000a10000a100000a1000000a10000000a100000000\") == 9\n assert candidate(word = \"1000000000000000000000000000000\") == 1\n assert candidate(word = \"123xyz456xyz789xyz123xyz\") == 3\n assert candidate(word = \"111111111111111111111111111111111111111111111111111111111111111111111111111111111111\") == 1\n assert candidate(word = \"100000a200000b300000c400000d500000e600000f700000g800000h900000\") == 9\n assert candidate(word = \"leading0s123trailing0s456\") == 3\n assert candidate(word = \"0001000200030004000500060007000800090000000100020003\") == 1\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6\") == 10\n assert candidate(word = \"same123same123same123\") == 1\n assert candidate(word = \"1a001b0001c00001d000001e0000001f00000001g000000001\") == 1\n assert candidate(word = \"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010\") == 1\n assert candidate(word = \"aaaa111bbbb222cccc333dddd444\") == 4\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0a1b2c3d4e5f6g7h8i9j0\") == 10\n assert candidate(word = \"a0b00c000d0000\") == 1\n assert candidate(word = \"abc0abc00abc000abc0000abc000000abc0000000abc00000000abc000000000abc0000000000\") == 1\n assert candidate(word = \"leading000trailing\") == 1\n assert candidate(word = \"many000123manymany000456many000789many\") == 3\n assert candidate(word = \"a1000b1000c1000d1000e1000f1000g1000h1000i1000j1000\") == 1\n assert candidate(word = \"abc0def00ghi000jkl0000mno00000pqr000000stu\") == 1\n assert candidate(word = \"0000123456789000000000123456789000000012345678900000001234567890\") == 1\n assert candidate(word = \"0abc00abc000abc0000abc00000\") == 1\n assert candidate(word = \"0001000000001000000001\") == 1\n assert candidate(word = \"12345abc54321abc12345\") == 2\n assert candidate(word = \"repeated000repeated000repeated\") == 1\n assert candidate(word = \"z999y999x999w998v997u996\") == 4\n assert candidate(word = \"123abc321def456ghi654jkl789mno987pqr012stu210vwx321yz456\") == 8\n assert candidate(word = \"a1b01c001d0001e00001f10g100\") == 3\n assert candidate(word = \"000000000000000001\") == 1\n assert candidate(word = \"9a8b7c6d5e4f3g2h1i0j9k8l7m6n5o4p3q2r1s0\") == 10\n assert candidate(word = \"9876543210abcdefgh0987654321\") == 2\n assert candidate(word = \"9876543210zyxwvutsrqponmlkjihgfedcba9876543210\") == 1\n assert candidate(word = \"xyz001abc002def003ghi004jkl005\") == 5\n assert candidate(word = \"000000000012345678900000000\") == 1\n assert candidate(word = \"000abc0000def1234gh5678\") == 3\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0a00b002c003d004e005f006g007h008i009j000\") == 10\n assert candidate(word = \"a1b01c001d0001e00001f000001g0000001h00000001\") == 1\n assert candidate(word = \"1a01b002c0003d00004e000005f0000006g00000007h000000008i0000000009j0\") == 10\n assert candidate(word = \"123abc456def789ghi0jklm00nopqr000stu0000vwx00000yz\") == 4\n assert candidate(word = \"abc123xyz456def789ghi10jkl11mno12pqr13stu14vwx15\") == 9\n assert candidate(word = \"000001000002000003000004000005000006000007000008000009\") == 1\n assert candidate(word = \"a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == 1\n assert candidate(word = \"abc123xyz456def789ghi001jkl234mno567pqr890stu0vwx123y0z456\") == 8\n assert candidate(word = \"abc123xyz456def456ghi789\") == 3\n assert candidate(word = \"a0b00c000d0000e00000f\") == 1\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0a000b0002c0003d0004e0005f0006g0007h0008i0009j0000\") == 10\n assert candidate(word = \"99999zzz88888xxx7777yyy6666\") == 4\n assert candidate(word = \"12345678901234567890123456789012345678901234567890123456789012345678901234567890\") == 1\n assert candidate(word = \"abc123xyz456abc123\") == 2\n assert candidate(word = \"abc123xyz456def123\") == 2\n assert candidate(word = \"a1b10c100d1000e10000f100000g1000000h10000000i100000000j1000000000\") == 10\n assert candidate(word = \"1234567890abcdefghijklmnopqrstuvwxyz0987654321\") == 2\n assert candidate(word = \"0000000000000000000000000\") == 1\n assert candidate(word = \"00000000000000000000000000000000000000000000000001\") == 1\n assert candidate(word = \"010abc0010def00010ghi\") == 1\n assert candidate(word = \"123abc123def123ghi123jkl123mno123pqrs123tuvw123xyz123\") == 1\n assert candidate(word = \"000000000000000000000000000000000000000000000000000000000000000000000000000000000000\") == 1\n assert candidate(word = \"abc123def456ghi789jkl0123\") == 3\n assert candidate(word = \"123456789a987654321b123456789c987654321d123456789e987654321f123456789g\") == 2\n assert candidate(word = \"00123456789000\") == 1\n assert candidate(word = \"0a00b000c0000d00000e000000f0000000g00000000h000000000i000000000j0\") == 1\n assert candidate(word = \"a0b00c000d0000e00000f000000g0000000h00000000i0\") == 1\n assert candidate(word = \"a1b01c001d100e0001f10\") == 3\n assert candidate(word = \"99999999999999999999999999999999999999999999999999999999999999999999999999999999999\") == 1\n assert candidate(word = \"abc001abc01abc1\") == 1\n assert candidate(word = \"a100000000b100000001c100000002d100000003e100000004f100000005\") == 6\n assert candidate(word = \"100000000000000000000000000000000000000000000000000000001\") == 1\n assert candidate(word = \"0012300abc045600def0123\") == 3\n assert candidate(word = \"00123004560078900100000000000000000000000000000000\") == 1\n assert candidate(word = \"9876543210qwertyuiopasdfghjklzxcvbnm\") == 1\n assert candidate(word = \"a0b0c00d000e0000f00000g000000h0000000i00000000j000000000\") == 1\n assert candidate(word = \"123abc456def789ghi0jkl123mno456pqr789stu0vwxyz\") == 4\n assert candidate(word = \"1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7\") == 10\n assert candidate(word = \"abc123456def654321ghi123456\") == 2\n assert candidate(word = \"abc1def2ghi3jkl4mno5pqr6stu7vwx8yz90123456789\") == 9\n assert candidate(word = \"0a123b456c789d0123\") == 4\n assert candidate(word = \"a123b456c789d012e345f678g901\") == 7\n assert candidate(word = \"00100a001b001c\") == 2\n assert candidate(word = \"abc1abc01abc001abc0001abc00001abc000001abc0000001\") == 1\n assert candidate(word = \"abc001xyz01abc100\") == 2\n assert candidate(word = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0\") == 10\n", "comparison": "exact"}, "public_tests": ["\"a123bc34d8ef34\"", "\"leet1234code234\"", "\"a1b01c001\""], "hints": ["Try to split the string so that each integer is in a different string.", "Try to remove each integer's leading zeroes and compare the strings to find how many of them are unique."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().numDifferentIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:18+00:00", "tests_total": 124, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function numDifferentIntegers($word) {", "container": "Solution", "callable": "numDifferentIntegers", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1806, "task_id": "minimum-number-of-operations-to-reinitialize-a-permutation", "difficulty": "Medium", "problem_description": "You are given an even integer n. You initially have a permutation perm of size n where perm[i] == i (0-indexed).\n\nIn one operation, you will create a new array arr, and for each i:\n\n- If i % 2 == 0, then arr[i] = perm[i / 2].\n- If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].\n\nYou will then assign arr to perm.\n\nReturn the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.\n\nExample 1:\n\nInput: n = 2\nOutput: 1\nExplanation: perm = [0,1] initially.\nAfter the 1^st operation, perm = [0,1]\nSo it takes only 1 operation.\n\nExample 2:\n\nInput: n = 4\nOutput: 2\nExplanation: perm = [0,1,2,3] initially.\nAfter the 1^st operation, perm = [0,2,1,3]\nAfter the 2^nd operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n\nExample 3:\n\nInput: n = 6\nOutput: 4\n\nConstraints:\n\n- 2 <= n <= 1000\n- n is even.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == 3\n assert candidate(n = 4) == 2\n assert candidate(n = 12) == 10\n assert candidate(n = 14) == 12\n assert candidate(n = 16) == 4\n assert candidate(n = 18) == 8\n assert candidate(n = 6) == 4\n assert candidate(n = 2) == 1\n assert candidate(n = 20) == 18\n assert candidate(n = 100) == 30\n assert candidate(n = 500) == 166\n assert candidate(n = 1000) == 36\n assert candidate(n = 10) == 6\n assert candidate(n = 896) == 356\n assert candidate(n = 992) == 495\n assert candidate(n = 988) == 138\n assert candidate(n = 50) == 21\n assert candidate(n = 300) == 132\n assert candidate(n = 384) == 191\n assert candidate(n = 600) == 299\n assert candidate(n = 64) == 6\n assert candidate(n = 72) == 35\n assert candidate(n = 192) == 95\n assert candidate(n = 888) == 443\n assert candidate(n = 128) == 7\n assert candidate(n = 22) == 6\n assert candidate(n = 46) == 12\n assert candidate(n = 256) == 8\n assert candidate(n = 768) == 348\n assert candidate(n = 32) == 5\n assert candidate(n = 48) == 23\n assert candidate(n = 800) == 184\n assert candidate(n = 200) == 99\n assert candidate(n = 400) == 18\n assert candidate(n = 512) == 9\n assert candidate(n = 750) == 318\n assert candidate(n = 998) == 332\n", "comparison": "exact"}, "public_tests": ["2", "4", "6"], "hints": ["It is safe to assume the number of operations isn't more than n", "The number is small enough to apply a brute force solution."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().reinitializePermutation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:20+00:00", "tests_total": 38, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function reinitializePermutation($n) {", "container": "Solution", "callable": "reinitializePermutation", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1807, "task_id": "evaluate-the-bracket-pairs-of-a-string", "difficulty": "Medium", "problem_description": "You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.\n\n- For example, in the string \"(name)is(age)yearsold\", there are two bracket pairs that contain the keys \"name\" and \"age\".\n\nYou know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [key_i, value_i] indicates that key key_i has a value of value_i.\n\nYou are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key key_i, you will:\n\n- Replace key_i and the bracket pair with the key's corresponding value_i.\n- If you do not know the value of the key, you will replace key_i and the bracket pair with a question mark \"?\" (without the quotation marks).\n\nEach key will appear at most once in your knowledge. There will not be any nested brackets in s.\n\nReturn the resulting string after evaluating all of the bracket pairs.\n\nExample 1:\n\nInput: s = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]\nOutput: \"bobistwoyearsold\"\nExplanation:\nThe key \"name\" has a value of \"bob\", so replace \"(name)\" with \"bob\".\nThe key \"age\" has a value of \"two\", so replace \"(age)\" with \"two\".\n\nExample 2:\n\nInput: s = \"hi(name)\", knowledge = [[\"a\",\"b\"]]\nOutput: \"hi?\"\nExplanation: As you do not know the value of the key \"name\", replace \"(name)\" with \"?\".\n\nExample 3:\n\nInput: s = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]\nOutput: \"yesyesyesaaa\"\nExplanation: The same key can appear multiple times.\nThe key \"a\" has a value of \"yes\", so replace all occurrences of \"(a)\" with \"yes\".\nNotice that the \"a\"s not in a bracket pair are not evaluated.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- 0 <= knowledge.length <= 10^5\n- knowledge[i].length == 2\n- 1 <= key_i.length, value_i.length <= 10\n- s consists of lowercase English letters and round brackets '(' and ')'.\n- Every open bracket '(' in s will have a corresponding close bracket ')'.\n- The key in each bracket pair of s will be non-empty.\n- There will not be any nested bracket pairs in s.\n- key_i and value_i consist of lowercase English letters.\n- Each key_i in knowledge is unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"(a)(a)(a)aaa\",knowledge = [['a', 'yes']]) == \"yesyesyesaaa\"\n assert candidate(s = \"hi(name)\",knowledge = [['a', 'b']]) == \"hi?\"\n assert candidate(s = \"(a)(a)(a)aaa\",knowledge = [['a', 'yes']]) == \"yesyesyesaaa\"\n assert candidate(s = \"noknowledgehere\",knowledge = []) == \"noknowledgehere\"\n assert candidate(s = \"no(brackets)here\",knowledge = []) == \"no?here\"\n assert candidate(s = \"hi(name)\",knowledge = [['a', 'b']]) == \"hi?\"\n assert candidate(s = \"(nested)but(not)really\",knowledge = [['nested', 'nested'], ['not', 'not']]) == \"nestedbutnotreally\"\n assert candidate(s = \"this(is)a(test)\",knowledge = [['is', 'was'], ['test', 'trial']]) == \"thiswasatrial\"\n assert candidate(s = \"(name)is(age)yearsold\",knowledge = [['name', 'bob'], ['age', 'two']]) == \"bobistwoyearsold\"\n assert candidate(s = \"(single)\",knowledge = [['single', 'one']]) == \"one\"\n assert candidate(s = \"(last)one\",knowledge = [['last', 'final']]) == \"finalone\"\n assert candidate(s = \"single\",knowledge = [['single', 'word']]) == \"single\"\n assert candidate(s = \"hello\",knowledge = []) == \"hello\"\n assert candidate(s = \"(unknown)key\",knowledge = [['known', 'value']]) == \"?key\"\n assert candidate(s = \"(name)is(age)yearsold\",knowledge = [['name', 'bob'], ['age', 'two']]) == \"bobistwoyearsold\"\n assert candidate(s = \"(nested)(key)(nested)\",knowledge = [['key', 'value'], ['nested', 'deep']]) == \"deepvaluedeep\"\n assert candidate(s = \"(greeting)(world)(planet)\",knowledge = [['greeting', 'hello'], ['world', 'earth'], ['planet', 'mars']]) == \"helloearthmars\"\n assert candidate(s = \"(language)programmingis(fun)\",knowledge = [['language', 'python'], ['fun', 'awesome']]) == \"pythonprogrammingisawesome\"\n assert candidate(s = \"(fruit)(vegetable)\",knowledge = [['fruit', 'apple'], ['vegetable', 'carrot']]) == \"applecarrot\"\n assert candidate(s = \"(animal)lives(in)(habitat)\",knowledge = [['animal', 'tiger'], ['habitat', 'jungle']]) == \"tigerlives?jungle\"\n assert candidate(s = \"(first)and(last)name\",knowledge = [['first', 'john'], ['last', 'doe']]) == \"johnanddoename\"\n assert candidate(s = \"(name)is(living)(in)(city)\",knowledge = [['name', 'bob'], ['in', 'at'], ['city', 'london']]) == \"bobis?atlondon\"\n assert candidate(s = \"(animal)(eats)(food)\",knowledge = [['animal', 'lion'], ['food', 'meat']]) == \"lion?meat\"\n assert candidate(s = \"(user)likes(to)(eat)(food)\",knowledge = [['user', 'alice'], ['eat', 'enjoy'], ['food', 'pizza']]) == \"alicelikes?enjoypizza\"\n assert candidate(s = \"(prefix)middle(suffix)\",knowledge = [['prefix', 'start'], ['suffix', 'end']]) == \"startmiddleend\"\n assert candidate(s = \"(flower)grows(in)(soil)\",knowledge = [['flower', 'rose'], ['soil', 'dirt']]) == \"rosegrows?dirt\"\n assert candidate(s = \"(first)nameis(last)name\",knowledge = [['first', 'john'], ['last', 'doe']]) == \"johnnameisdoename\"\n assert candidate(s = \"(drink)is(served)in(glass)\",knowledge = [['drink', 'water'], ['glass', 'big']]) == \"wateris?inbig\"\n assert candidate(s = \"(greeting)world\",knowledge = [['greeting', 'hello'], ['farewell', 'bye']]) == \"helloworld\"\n assert candidate(s = \"(name)has(a)(pet)(dog)\",knowledge = [['name', 'john'], ['pet', 'dog'], ['dog', 'buddy']]) == \"johnhas?dogbuddy\"\n assert candidate(s = \"(repeated)(key)(repeated)(key)\",knowledge = [['key', 'value']]) == \"?value?value\"\n assert candidate(s = \"(first)(second)(third)(fourth)\",knowledge = [['first', 'one'], ['second', 'two'], ['third', 'three']]) == \"onetwothree?\"\n assert candidate(s = \"(color)(animal)\",knowledge = [['color', 'blue'], ['animal', 'dog'], ['bird', 'sparrow']]) == \"bluedog\"\n assert candidate(s = \"(nested)but(notreally)nested\",knowledge = [['nested', 'deep'], ['notreally', 'shallow']]) == \"deepbutshallownested\"\n assert candidate(s = \"(first)(last)(age)\",knowledge = [['first', 'john'], ['last', 'doe'], ['age', 'thirty']]) == \"johndoethirty\"\n assert candidate(s = \"(city)(has)(many)(buildings)\",knowledge = [['city', 'newyork'], ['many', 'lots']]) == \"newyork?lots?\"\n assert candidate(s = \"(multiple)(keys)(here)\",knowledge = [['multiple', 'many'], ['keys', 'some'], ['here', 'there']]) == \"manysomethere\"\n assert candidate(s = \"(color)(is)(used)in(art)\",knowledge = [['color', 'red'], ['used', 'frequently']]) == \"red?frequentlyin?\"\n assert candidate(s = \"(prefix)example(suffix)\",knowledge = [['prefix', 'pre'], ['suffix', 'post']]) == \"preexamplepost\"\n assert candidate(s = \"(unknown)(key)(not)(present)\",knowledge = [['present', 'available']]) == \"???available\"\n assert candidate(s = \"(instrument)plays(music)\",knowledge = [['instrument', 'guitar'], ['music', 'beautiful']]) == \"guitarplaysbeautiful\"\n assert candidate(s = \"(prefix)(middle)(suffix)\",knowledge = [['prefix', 'pre'], ['middle', 'mid'], ['suffix', 'suf']]) == \"premidsuf\"\n assert candidate(s = \"(fruit)are(sweet)and(healthy)\",knowledge = [['fruit', 'apples'], ['sweet', 'very'], ['healthy', 'indeed']]) == \"applesareveryandindeed\"\n assert candidate(s = \"(repeated)repeated(repeated)\",knowledge = [['repeated', 'again']]) == \"againrepeatedagain\"\n assert candidate(s = \"(greeting)everyone(my)name(is)(unknown)\",knowledge = [['greeting', 'hi'], ['my', 'my']]) == \"hieveryonemyname??\"\n assert candidate(s = \"(bird)can(fly)high\",knowledge = [['bird', 'eagle'], ['fly', 'soar']]) == \"eaglecansoarhigh\"\n assert candidate(s = \"(a)(b)(c)(d)(e)(f)\",knowledge = [['a', 'one'], ['b', 'two'], ['c', 'three'], ['d', 'four'], ['e', 'five'], ['f', 'six']]) == \"onetwothreefourfivesix\"\n assert candidate(s = \"(color)(of)the(sky)\",knowledge = [['color', 'blue'], ['sky', 'beautiful']]) == \"blue?thebeautiful\"\n assert candidate(s = \"(a)(b)(c)(d)(e)\",knowledge = [['a', 'alpha'], ['b', 'beta'], ['c', 'gamma'], ['d', 'delta'], ['e', 'epsilon']]) == \"alphabetagammadeltaepsilon\"\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)\",knowledge = [['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']]) == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"(repeated)(repeated)(repeated)\",knowledge = [['repeated', 'rep']]) == \"repreprep\"\n assert candidate(s = \"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\",knowledge = [['a', 'one'], ['b', 'two'], ['c', 'three'], ['d', 'four'], ['e', 'five'], ['f', 'six'], ['g', 'seven'], ['h', 'eight'], ['i', 'nine'], ['j', 'ten']]) == \"onetwothreefourfivesixseveneightnineten\"\n assert candidate(s = \"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)\",knowledge = [['a', 'yes'], ['b', 'no'], ['c', 'maybe'], ['d', 'sure'], ['e', 'never'], ['f', 'always'], ['g', 'often'], ['h', 'rarely'], ['i', 'sometimes'], ['j', 'usually']]) == \"yesnomaybesureneveralwaysoftenrarelysometimesusually\"\n assert candidate(s = \"(complex)(string)(with)(multiple)(keys)\",knowledge = [['complex', 'com'], ['string', 'str'], ['with', 'wi'], ['multiple', 'mul'], ['keys', 'ke']]) == \"comstrwimulke\"\n assert candidate(s = \"(a)(b)(c)(d)(e)(f)\",knowledge = [['a', 'alpha'], ['b', 'beta'], ['c', 'gamma'], ['d', 'delta'], ['e', 'epsilon']]) == \"alphabetagammadeltaepsilon?\"\n assert candidate(s = \"(nested)brackets(are)not(allowed)\",knowledge = [['nested', 'nested'], ['brackets', 'brackets'], ['not', 'not']]) == \"nestedbrackets?not?\"\n", "comparison": "exact"}, "public_tests": ["\"(name)is(age)yearsold\"\n[[\"name\",\"bob\"],[\"age\",\"two\"]]", "\"hi(name)\"\n[[\"a\",\"b\"]]", "\"(a)(a)(a)aaa\"\n[[\"a\",\"yes\"]]"], "hints": ["Process pairs from right to left to handle repeats", "Keep track of the current enclosed string using another string"], "metadata": {"canonical_parameter_names": ["s", "knowledge"], "leetcode_dataset_entry_point": "Solution().evaluate", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:23+00:00", "tests_total": 113, "tests_dropped": 57, "flags": [], "topic_tags": ["array", "hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function evaluate($s, $knowledge) {", "container": "Solution", "callable": "evaluate", "parameters": [{"name": "s", "type": "String"}, {"name": "knowledge", "type": "String[][]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1812, "task_id": "determine-color-of-a-chessboard-square", "difficulty": "Easy", "problem_description": "You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.\n\nReturn true if the square is white, and false if the square is black.\n\nThe coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.\n\nExample 1:\n\nInput: coordinates = \"a1\"\nOutput: false\nExplanation: From the chessboard above, the square with coordinates \"a1\" is black, so return false.\n\nExample 2:\n\nInput: coordinates = \"h3\"\nOutput: true\nExplanation: From the chessboard above, the square with coordinates \"h3\" is white, so return true.\n\nExample 3:\n\nInput: coordinates = \"c7\"\nOutput: false\n\nConstraints:\n\n- coordinates.length == 2\n- 'a' <= coordinates[0] <= 'h'\n- '1' <= coordinates[1] <= '8'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(coordinates = \"d5\") == True\n assert candidate(coordinates = \"e4\") == True\n assert candidate(coordinates = \"b8\") == False\n assert candidate(coordinates = \"b2\") == False\n assert candidate(coordinates = \"a1\") == False\n assert candidate(coordinates = \"g8\") == True\n assert candidate(coordinates = \"e5\") == False\n assert candidate(coordinates = \"d4\") == False\n assert candidate(coordinates = \"g2\") == True\n assert candidate(coordinates = \"e6\") == True\n assert candidate(coordinates = \"f6\") == False\n assert candidate(coordinates = \"h3\") == True\n assert candidate(coordinates = \"f4\") == False\n assert candidate(coordinates = \"c7\") == False\n assert candidate(coordinates = \"d3\") == True\n assert candidate(coordinates = \"g7\") == False\n assert candidate(coordinates = \"a7\") == False\n assert candidate(coordinates = \"c8\") == True\n assert candidate(coordinates = \"f2\") == False\n assert candidate(coordinates = \"f1\") == True\n assert candidate(coordinates = \"g1\") == False\n assert candidate(coordinates = \"b3\") == True\n assert candidate(coordinates = \"h5\") == True\n assert candidate(coordinates = \"e1\") == False\n assert candidate(coordinates = \"a5\") == False\n assert candidate(coordinates = \"d7\") == True\n assert candidate(coordinates = \"g5\") == False\n assert candidate(coordinates = \"b6\") == False\n assert candidate(coordinates = \"f5\") == True\n assert candidate(coordinates = \"h1\") == True\n assert candidate(coordinates = \"e3\") == False\n assert candidate(coordinates = \"c3\") == False\n assert candidate(coordinates = \"g4\") == True\n assert candidate(coordinates = \"a4\") == True\n assert candidate(coordinates = \"d6\") == False\n assert candidate(coordinates = \"b1\") == True\n assert candidate(coordinates = \"g6\") == True\n assert candidate(coordinates = \"h6\") == False\n assert candidate(coordinates = \"c1\") == False\n assert candidate(coordinates = \"h7\") == True\n assert candidate(coordinates = \"b7\") == True\n assert candidate(coordinates = \"c4\") == True\n assert candidate(coordinates = \"c2\") == True\n assert candidate(coordinates = \"f3\") == True\n assert candidate(coordinates = \"h4\") == False\n assert candidate(coordinates = \"d8\") == False\n assert candidate(coordinates = \"b4\") == False\n assert candidate(coordinates = \"a8\") == True\n assert candidate(coordinates = \"a3\") == False\n assert candidate(coordinates = \"e2\") == True\n assert candidate(coordinates = \"e7\") == False\n assert candidate(coordinates = \"f7\") == True\n assert candidate(coordinates = \"d2\") == False\n assert candidate(coordinates = \"a2\") == True\n assert candidate(coordinates = \"b5\") == True\n assert candidate(coordinates = \"c5\") == False\n assert candidate(coordinates = \"h8\") == False\n assert candidate(coordinates = \"a6\") == True\n assert candidate(coordinates = \"h2\") == False\n assert candidate(coordinates = \"g3\") == False\n assert candidate(coordinates = \"d1\") == True\n assert candidate(coordinates = \"f8\") == False\n assert candidate(coordinates = \"e8\") == True\n assert candidate(coordinates = \"c6\") == True\n", "comparison": "exact"}, "public_tests": ["\"a1\"", "\"h3\"", "\"c7\""], "hints": ["Convert the coordinates to (x, y) - that is, \"a1\" is (1, 1), \"d7\" is (4, 7).", "Try add the numbers together and look for a pattern."], "metadata": {"canonical_parameter_names": ["coordinates"], "leetcode_dataset_entry_point": "Solution().squareIsWhite", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:27+00:00", "tests_total": 74, "tests_dropped": 10, "flags": ["has_images"], "topic_tags": ["math", "string"]}, "language": "php", "interface": {"raw_signature": "function squareIsWhite($coordinates) {", "container": "Solution", "callable": "squareIsWhite", "parameters": [{"name": "coordinates", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1813, "task_id": "sentence-similarity-iii", "difficulty": "Medium", "problem_description": "You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters.\n\nTwo sentences s1 and s2 are considered similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. Note that the inserted sentence must be separated from existing words by spaces.\n\nFor example,\n\n- s1 = \"Hello Jane\" and s2 = \"Hello my name is Jane\" can be made equal by inserting \"my name is\" between \"Hello\" and \"Jane\" in s1.\n- s1 = \"Frog cool\" and s2 = \"Frogs are cool\" are not similar, since although there is a sentence \"s are\" inserted into s1, it is not separated from \"Frog\" by a space.\n\nGiven two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.\n\nExample 1:\n\nInput: sentence1 = \"My name is Haley\", sentence2 = \"My Haley\"\nOutput: true\nExplanation:\nsentence2 can be turned to sentence1 by inserting \"name is\" between \"My\" and \"Haley\".\n\nExample 2:\n\nInput: sentence1 = \"of\", sentence2 = \"A lot of words\"\nOutput: false\nExplanation:\nNo single sentence can be inserted inside one of the sentences to make it equal to the other.\n\nExample 3:\n\nInput: sentence1 = \"Eating right now\", sentence2 = \"Eating\"\nOutput: true\nExplanation:\nsentence2 can be turned to sentence1 by inserting \"right now\" at the end of the sentence.\n\nConstraints:\n\n- 1 <= sentence1.length, sentence2.length <= 100\n- sentence1 and sentence2 consist of lowercase and uppercase English letters and spaces.\n- The words in sentence1 and sentence2 are separated by a single space.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Similar similar sentences\") == True\n assert candidate(sentence1 = \"Start end\",sentence2 = \"Start middle end\") == True\n assert candidate(sentence1 = \"Eating right now\",sentence2 = \"Eating\") == True\n assert candidate(sentence1 = \"A quick brown fox\",sentence2 = \"A quick brown fox jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"Quick brown fox\",sentence2 = \"Quick brown fox jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"of\",sentence2 = \"A lot of words\") == False\n assert candidate(sentence1 = \"Similarity check\",sentence2 = \"check Similarity\") == False\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Sentences Similar\") == False\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Similar very very similar sentences\") == True\n assert candidate(sentence1 = \"Python is great\",sentence2 = \"Python is very very great\") == True\n assert candidate(sentence1 = \"One two three\",sentence2 = \"One three\") == True\n assert candidate(sentence1 = \"Python is great\",sentence2 = \"is great\") == True\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Sentences that are Similar\") == False\n assert candidate(sentence1 = \"One\",sentence2 = \"One two three\") == True\n assert candidate(sentence1 = \"One\",sentence2 = \"One\") == True\n assert candidate(sentence1 = \"Test\",sentence2 = \"Test test\") == True\n assert candidate(sentence1 = \"Single\",sentence2 = \"Single word\") == True\n assert candidate(sentence1 = \"Test test test\",sentence2 = \"Test test test test\") == True\n assert candidate(sentence1 = \"Python programming\",sentence2 = \"programming\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is\") == True\n assert candidate(sentence1 = \"A B C\",sentence2 = \"A B X C\") == True\n assert candidate(sentence1 = \"One two three\",sentence2 = \"One two three four\") == True\n assert candidate(sentence1 = \"Similar sentences\",sentence2 = \"Similar very similar sentences\") == True\n assert candidate(sentence1 = \"My name is Haley\",sentence2 = \"My Haley\") == True\n assert candidate(sentence1 = \"Same Same Same\",sentence2 = \"Same\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is a dummy test\") == True\n assert candidate(sentence1 = \"Same same\",sentence2 = \"Same same same\") == True\n assert candidate(sentence1 = \"Overlap here\",sentence2 = \"Overlap word here\") == True\n assert candidate(sentence1 = \"Hello World\",sentence2 = \"World\") == True\n assert candidate(sentence1 = \"Hello World\",sentence2 = \"Hello\") == True\n assert candidate(sentence1 = \"Same same\",sentence2 = \"Same same\") == True\n assert candidate(sentence1 = \"Hello World\",sentence2 = \"Hello amazing World\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is a simple test\") == True\n assert candidate(sentence1 = \"First Second Third\",sentence2 = \"First Third\") == True\n assert candidate(sentence1 = \"Match here\",sentence2 = \"Match something here\") == True\n assert candidate(sentence1 = \"Hello World\",sentence2 = \"Hello from the World\") == True\n assert candidate(sentence1 = \"Alice in Wonderland\",sentence2 = \"Alice is in Wonderland\") == True\n assert candidate(sentence1 = \"Left Right\",sentence2 = \"Left Middle Right\") == True\n assert candidate(sentence1 = \"The quick brown fox\",sentence2 = \"The quick brown fox jumps over\") == True\n assert candidate(sentence1 = \"To be or not to be that is the question\",sentence2 = \"To be that is the question\") == True\n assert candidate(sentence1 = \"The world is a stage\",sentence2 = \"The world is a stage and all the men and women merely players\") == True\n assert candidate(sentence1 = \"One two three\",sentence2 = \"One two insert three\") == True\n assert candidate(sentence1 = \"The quick brown fox\",sentence2 = \"The quick brown fox jumps\") == True\n assert candidate(sentence1 = \"No pain no gain\",sentence2 = \"No pain no gain but sometimes the pain is not worth the gain\") == True\n assert candidate(sentence1 = \"Let us play\",sentence2 = \"Let us play a game\") == True\n assert candidate(sentence1 = \"Mary had a little lamb\",sentence2 = \"Mary lamb\") == True\n assert candidate(sentence1 = \"All roads lead to Rome\",sentence2 = \"All roads lead to Rome but not all roads are the same\") == True\n assert candidate(sentence1 = \"Unique words only\",sentence2 = \"Unique unique words only\") == True\n assert candidate(sentence1 = \"Quick brown fox jumps over the lazy dog\",sentence2 = \"Quick brown fox jumps over the lazy quick brown dog\") == True\n assert candidate(sentence1 = \"a b c d e f g h i j\",sentence2 = \"a b c X Y Z d e f g h i j\") == True\n assert candidate(sentence1 = \"OnlyOneWordHere\",sentence2 = \"Only One Word Here\") == False\n assert candidate(sentence1 = \"Actions speak louder than words\",sentence2 = \"Actions speak\") == True\n assert candidate(sentence1 = \"One two three four five\",sentence2 = \"One two four five\") == True\n assert candidate(sentence1 = \"Python programming is fun\",sentence2 = \"Python programming is very fun\") == True\n assert candidate(sentence1 = \"Actions speak louder than words\",sentence2 = \"Actions speak louder than words but intentions matter\") == True\n assert candidate(sentence1 = \"Python is fun\",sentence2 = \"Python programming is really fun\") == False\n assert candidate(sentence1 = \"OpenAI is great\",sentence2 = \"OpenAI is indeed indeed great\") == True\n assert candidate(sentence1 = \"Do or do not there is no try\",sentence2 = \"Do or do not there is no no try\") == True\n assert candidate(sentence1 = \"Quick brown fox jumps over the lazy dog\",sentence2 = \"Quick fox jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"Time flies when you are having fun\",sentence2 = \"Time flies\") == True\n assert candidate(sentence1 = \"The world is a book and those who do not travel read only one page\",sentence2 = \"The world is a book and those who do not travel read only one chapter\") == False\n assert candidate(sentence1 = \"Python programming is fun and effective\",sentence2 = \"Python programming effective\") == True\n assert candidate(sentence1 = \"Complex complex case\",sentence2 = \"Complex even more complex case\") == True\n assert candidate(sentence1 = \"Time heals all wounds\",sentence2 = \"Time heals all wounds but time is also a thief\") == True\n assert candidate(sentence1 = \"SingleWord\",sentence2 = \"SingleWord\") == True\n assert candidate(sentence1 = \"The cat sat on the mat\",sentence2 = \"The cat sat on the blue mat\") == True\n assert candidate(sentence1 = \"First and last\",sentence2 = \"First something in the middle last\") == False\n assert candidate(sentence1 = \"Once upon a time\",sentence2 = \"Once upon a time in a land far far away\") == True\n assert candidate(sentence1 = \"I think therefore I am\",sentence2 = \"I think therefore I am six\") == True\n assert candidate(sentence1 = \"Single word match\",sentence2 = \"Single word match\") == True\n assert candidate(sentence1 = \"Silence is golden\",sentence2 = \"Silence is golden in the morning\") == True\n assert candidate(sentence1 = \"A quick brown fox jumps\",sentence2 = \"A quick brown fox quick brown fox jumps\") == True\n assert candidate(sentence1 = \"Complex problem solving\",sentence2 = \"Complex problem problem solving\") == True\n assert candidate(sentence1 = \"Short\",sentence2 = \"Short and sweet\") == True\n assert candidate(sentence1 = \"a\",sentence2 = \"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\") == True\n assert candidate(sentence1 = \"Overlap at end\",sentence2 = \"Continue overlap at end\") == False\n assert candidate(sentence1 = \"Happy birthday\",sentence2 = \"Happy birthday dear\") == True\n assert candidate(sentence1 = \"First word last word\",sentence2 = \"First first word last word\") == True\n assert candidate(sentence1 = \"To be or not to be\",sentence2 = \"To be or not to be that is the question\") == True\n assert candidate(sentence1 = \"May the force be with you\",sentence2 = \"May the force\") == True\n assert candidate(sentence1 = \"Python programming is fun\",sentence2 = \"Python programming is really really fun\") == True\n assert candidate(sentence1 = \"Alibaba Cloud offers various cloud services\",sentence2 = \"Alibaba Cloud offers cloud computing and storage services\") == False\n assert candidate(sentence1 = \"The early morning sun was a beautiful sight\",sentence2 = \"The early morning sun was a beautiful golden sight\") == True\n assert candidate(sentence1 = \"This is a long sentence with multiple words in it\",sentence2 = \"This long sentence with multiple words in it\") == True\n assert candidate(sentence1 = \"Lorem ipsum dolor sit amet\",sentence2 = \"Lorem ipsum dolor sit amet consectetur adipiscing elit\") == True\n assert candidate(sentence1 = \"Hello from the other side\",sentence2 = \"Hello from this side\") == False\n assert candidate(sentence1 = \"One two three\",sentence2 = \"One two X Y Z three\") == True\n assert candidate(sentence1 = \"Beginning middle end\",sentence2 = \"Beginning middle middle middle end\") == True\n assert candidate(sentence1 = \"Unique sentence\",sentence2 = \"Unique special sentence\") == True\n assert candidate(sentence1 = \"The quick brown fox jumps over the lazy dog\",sentence2 = \"The quick brown fox jumps over the lazy\") == True\n assert candidate(sentence1 = \"Start with a sentence\",sentence2 = \"Start with a really long sentence\") == True\n assert candidate(sentence1 = \"Python is fun\",sentence2 = \"Python is an amazing and fun language\") == False\n assert candidate(sentence1 = \"All your base are belong to us\",sentence2 = \"All base are belong to us\") == True\n assert candidate(sentence1 = \"Longer sentence with multiple words\",sentence2 = \"Longer sentence with even more multiple words\") == True\n assert candidate(sentence1 = \"She sells sea shells by the sea shore\",sentence2 = \"She sells green sea shells by the sea shore\") == True\n assert candidate(sentence1 = \"Complex algorithm design and analysis\",sentence2 = \"Complex algorithm\") == True\n assert candidate(sentence1 = \"In the middle\",sentence2 = \"In the middle of nowhere\") == True\n assert candidate(sentence1 = \"First Last\",sentence2 = \"First in between Last\") == True\n assert candidate(sentence1 = \"I love to code\",sentence2 = \"I love to code code code\") == True\n assert candidate(sentence1 = \"Unique words only\",sentence2 = \"Unique words in between only\") == True\n assert candidate(sentence1 = \"The quick brown fox\",sentence2 = \"The quick brown fox jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"Single\",sentence2 = \"Single single single\") == True\n assert candidate(sentence1 = \"Life is a journey\",sentence2 = \"Life is a journey not a destination\") == True\n assert candidate(sentence1 = \"A B C D E\",sentence2 = \"A B X Y Z C D E\") == True\n assert candidate(sentence1 = \"The rain in Spain stays mainly in the plain\",sentence2 = \"The rain in Spain falls mainly in the plain\") == False\n assert candidate(sentence1 = \"A quick movement of the enemy will jeopardize six gunboats\",sentence2 = \"A quick movement of the enemy will jeopardize\") == True\n assert candidate(sentence1 = \"Short\",sentence2 = \"Very very short\") == False\n assert candidate(sentence1 = \"Do or do not there is no try\",sentence2 = \"Do or do not there is no other way\") == False\n assert candidate(sentence1 = \"Python programming is fun\",sentence2 = \"Python programming is very very fun\") == True\n assert candidate(sentence1 = \"Start coding\",sentence2 = \"Start coding today\") == True\n assert candidate(sentence1 = \"Happy new year\",sentence2 = \"Happy new new new year\") == True\n assert candidate(sentence1 = \"I love programming in Python\",sentence2 = \"I love programming in Java Python\") == True\n assert candidate(sentence1 = \"Actions speak louder than words\",sentence2 = \"Actions speak louder than words but words can inspire actions\") == True\n assert candidate(sentence1 = \"Python is great\",sentence2 = \"Programming in Python is great\") == True\n assert candidate(sentence1 = \"Data engineering and data science\",sentence2 = \"Data engineering\") == True\n assert candidate(sentence1 = \"One two three four\",sentence2 = \"One two five six seven eight three four\") == True\n assert candidate(sentence1 = \"I love coding\",sentence2 = \"I love coding in Python\") == True\n assert candidate(sentence1 = \"Prefix and suffix\",sentence2 = \"Prefix and more words suffix\") == True\n assert candidate(sentence1 = \"One two three four\",sentence2 = \"One two three four five six\") == True\n assert candidate(sentence1 = \"The quick brown fox jumps over the lazy dog\",sentence2 = \"The quick brown fox jumps over lazy dog\") == True\n assert candidate(sentence1 = \"Catch me if you can\",sentence2 = \"Catch me\") == True\n assert candidate(sentence1 = \"This is a complex example\",sentence2 = \"This is an extremely complex example\") == False\n assert candidate(sentence1 = \"Match start\",sentence2 = \"Match start middle\") == True\n assert candidate(sentence1 = \"x y z\",sentence2 = \"a b c x y z\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is only a test\") == True\n assert candidate(sentence1 = \"The quick brown fox jumps over the lazy dog\",sentence2 = \"The quick brown fox jumps high over the lazy dog\") == True\n assert candidate(sentence1 = \"Python is great\",sentence2 = \"Python is the best language great\") == True\n assert candidate(sentence1 = \"The cat in the hat sat on the mat\",sentence2 = \"The cat sat on the mat\") == True\n assert candidate(sentence1 = \"The pen is mightier than the sword\",sentence2 = \"The pen is mightier than the sword but silence is golden\") == True\n assert candidate(sentence1 = \"Machine learning is transforming industries\",sentence2 = \"Machine learning transforming industries\") == True\n assert candidate(sentence1 = \"The quick brown fox\",sentence2 = \"The quick brown lazy dog\") == False\n assert candidate(sentence1 = \"One two three\",sentence2 = \"One two two three\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is a longer test sentence\") == False\n assert candidate(sentence1 = \"Insert this sentence\",sentence2 = \"Insert some words this sentence\") == True\n assert candidate(sentence1 = \"An apple a day keeps the doctor away\",sentence2 = \"An apple a day\") == True\n assert candidate(sentence1 = \"Learning new things every day\",sentence2 = \"Learning new things every single day\") == True\n assert candidate(sentence1 = \"Match end\",sentence2 = \"Middle match end\") == False\n assert candidate(sentence1 = \"Test\",sentence2 = \"Test test test\") == True\n assert candidate(sentence1 = \"A B C D E\",sentence2 = \"A B C X Y Z D E\") == True\n assert candidate(sentence1 = \"Start with this\",sentence2 = \"Start with something in the middle this\") == True\n assert candidate(sentence1 = \"Qwen is a large language model\",sentence2 = \"Qwen is a language model\") == True\n assert candidate(sentence1 = \"The cat sat on the mat\",sentence2 = \"The cat sat on the brown mat\") == True\n assert candidate(sentence1 = \"Last word\",sentence2 = \"Last last last word\") == True\n assert candidate(sentence1 = \"Python is great for data science\",sentence2 = \"Python is great\") == True\n assert candidate(sentence1 = \"Quick brown fox jumps over the lazy dog\",sentence2 = \"Quick brown fox quickly jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"It is a truth universally acknowledged\",sentence2 = \"It is a universally acknowledged\") == True\n assert candidate(sentence1 = \"Start and finish\",sentence2 = \"Start middle and finish\") == True\n assert candidate(sentence1 = \"SingleWord\",sentence2 = \"SingleWordInserted\") == False\n assert candidate(sentence1 = \"End with a sentence\",sentence2 = \"End with a sentence and more words\") == True\n assert candidate(sentence1 = \"Overlap at start\",sentence2 = \"Overlap at start and continue\") == True\n assert candidate(sentence1 = \"We hold these truths to be self evident\",sentence2 = \"We hold these self evident\") == True\n assert candidate(sentence1 = \"Once upon a time in a land far far away\",sentence2 = \"Once upon a time\") == True\n assert candidate(sentence1 = \"Java is a high level programming language\",sentence2 = \"Java is a high level programming language that is platform independent\") == True\n assert candidate(sentence1 = \"Similar beginning and end\",sentence2 = \"Similar beginning with extra words and end\") == True\n assert candidate(sentence1 = \"Hello from the other side\",sentence2 = \"Hello from the very very other side\") == True\n assert candidate(sentence1 = \"Quick brown fox jumps over lazy dog\",sentence2 = \"Quick brown fox jumps over the lazy dog\") == True\n assert candidate(sentence1 = \"Silence is golden\",sentence2 = \"Silence\") == True\n assert candidate(sentence1 = \"Middle insertion is key\",sentence2 = \"Middle insertion of some text is key\") == True\n assert candidate(sentence1 = \"To be or not to be that is the question\",sentence2 = \"To be or not to be\") == True\n assert candidate(sentence1 = \"This is a simple test\",sentence2 = \"This is an extremely simple and detailed test\") == False\n assert candidate(sentence1 = \"It was the best of times it was the worst of times\",sentence2 = \"It was the best of times\") == True\n assert candidate(sentence1 = \"Quick brown fox jumps over the lazy dog\",sentence2 = \"Quick brown fox jumps over the lazy brown dog\") == True\n assert candidate(sentence1 = \"Learning new things is fun\",sentence2 = \"Learning fun\") == True\n assert candidate(sentence1 = \"Life is a journey not a destination\",sentence2 = \"Life is a journey of ups and downs not a destination\") == True\n assert candidate(sentence1 = \"She sells sea shells by the sea shore\",sentence2 = \"She sells sea\") == True\n assert candidate(sentence1 = \"In the beginning God created the heaven and the earth\",sentence2 = \"In the beginning God created the earth\") == True\n assert candidate(sentence1 = \"Insert sentence here\",sentence2 = \"Insert sentence in the middle sentence here\") == True\n assert candidate(sentence1 = \"End with this\",sentence2 = \"End with this and something more\") == True\n assert candidate(sentence1 = \"Python is fun\",sentence2 = \"Python is very very fun\") == True\n assert candidate(sentence1 = \"Advanced machine learning techniques\",sentence2 = \"Advanced machine learning deep learning techniques\") == True\n assert candidate(sentence1 = \"Hello from the other side\",sentence2 = \"Hello from the other side my old friend\") == True\n assert candidate(sentence1 = \"Single word\",sentence2 = \"Single single word\") == True\n assert candidate(sentence1 = \"One two three four five\",sentence2 = \"One two six seven eight nine five\") == False\n assert candidate(sentence1 = \"Same at the start\",sentence2 = \"Same at the start but different end\") == True\n assert candidate(sentence1 = \"All animals are equal\",sentence2 = \"All animals are equal but some animals are more equal than others\") == True\n assert candidate(sentence1 = \"The rain in Spain stays mainly in the plain\",sentence2 = \"The rain in Spain stays\") == True\n assert candidate(sentence1 = \"Multiple words in between\",sentence2 = \"Multiple multiple words in between\") == True\n assert candidate(sentence1 = \"Natural language processing is fascinating\",sentence2 = \"Natural language processing\") == True\n assert candidate(sentence1 = \"Hello my friend\",sentence2 = \"Hello my dear friend\") == True\n assert candidate(sentence1 = \"This is a test\",sentence2 = \"This is an amazing test\") == False\n assert candidate(sentence1 = \"Front and back\",sentence2 = \"Front middle back\") == False\n assert candidate(sentence1 = \"Complex sentences are fun\",sentence2 = \"Complex sentences with more words in between are fun\") == True\n assert candidate(sentence1 = \"Alice went to the market\",sentence2 = \"Alice went to the market to buy apples\") == True\n assert candidate(sentence1 = \"The early morning light\",sentence2 = \"The early morning light is so peaceful\") == True\n assert candidate(sentence1 = \"Same same same\",sentence2 = \"Same Same\") == False\n assert candidate(sentence1 = \"Same at the end\",sentence2 = \"Different start same at the end\") == False\n assert candidate(sentence1 = \"Beautiful day in the neighborhood\",sentence2 = \"Beautiful day in the beautiful neighborhood\") == True\n assert candidate(sentence1 = \"First second third\",sentence2 = \"First first first second third\") == True\n assert candidate(sentence1 = \"Hello from the other side\",sentence2 = \"Hello\") == True\n assert candidate(sentence1 = \"I have a dream\",sentence2 = \"I have a dream that one day this nation will rise up and live out the true meaning of its creed\") == True\n assert candidate(sentence1 = \"May the force be with you\",sentence2 = \"May the be with you\") == True\n assert candidate(sentence1 = \"OpenAI develops AI models\",sentence2 = \"OpenAI develops cutting edge AI models\") == True\n assert candidate(sentence1 = \"May the Force be with you\",sentence2 = \"May the Force be with you always\") == True\n assert candidate(sentence1 = \"Keep it simple\",sentence2 = \"Keep it simple stupid\") == True\n assert candidate(sentence1 = \"A short sentence\",sentence2 = \"A very very very short sentence\") == True\n", "comparison": "exact"}, "public_tests": ["\"My name is Haley\"\n\"My Haley\"", "\"of\"\n\"A lot of words\"", "\"Eating right now\"\n\"Eating\""], "hints": ["One way to look at it is to find one sentence as a concatenation of a prefix and suffix from the other sentence.", "Get the longest common prefix between them and the longest common suffix."], "metadata": {"canonical_parameter_names": ["sentence1", "sentence2"], "leetcode_dataset_entry_point": "Solution().areSentencesSimilar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:29+00:00", "tests_total": 197, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function areSentencesSimilar($sentence1, $sentence2) {", "container": "Solution", "callable": "areSentencesSimilar", "parameters": [{"name": "sentence1", "type": "String"}, {"name": "sentence2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1814, "task_id": "count-nice-pairs-in-an-array", "difficulty": "Medium", "problem_description": "You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:\n\n- 0 <= i < j < nums.length\n- nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])\n\nReturn the number of nice pairs of indices. Since that number can be too large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: nums = [42,11,1,97]\nOutput: 2\nExplanation: The two pairs are:\n - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.\n - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.\n\nExample 2:\n\nInput: nums = [13,10,35,24,76]\nOutput: 4\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, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 45\n assert candidate(nums = [100, 200, 300, 400]) == 0\n assert candidate(nums = [123, 321, 213, 132, 231, 312]) == 2\n assert candidate(nums = [123, 321, 213, 132]) == 1\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333]) == 3\n assert candidate(nums = [987654321, 123456789, 234567890, 345678901]) == 0\n assert candidate(nums = [123, 321, 120, 21]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500]) == 0\n assert candidate(nums = [13, 10, 35, 24, 76]) == 4\n assert candidate(nums = [1, 1, 1, 1]) == 6\n assert candidate(nums = [10, 100, 1000, 10000]) == 0\n assert candidate(nums = [0, 0, 0, 0]) == 6\n assert candidate(nums = [100, 10, 1]) == 0\n assert candidate(nums = [42, 11, 1, 97]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 10\n assert candidate(nums = [100000, 100001, 100002, 100003, 100004, 100005, 100006, 100007, 100008, 100009]) == 0\n assert candidate(nums = [1234, 2341, 3412, 4123, 5678, 6785, 7856, 8567]) == 8\n assert candidate(nums = [123, 132, 213, 231, 312, 321, 111, 222, 333, 444, 555, 666, 777, 888, 999, 101, 202, 303, 404, 505]) == 93\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]) == 0\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 123, 321]) == 4\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 0]) == 45\n assert candidate(nums = [1122, 2211, 3344, 4433, 5566, 6655, 7788, 8877]) == 12\n assert candidate(nums = [1001, 1010, 1100, 1111, 2002, 2020, 2200, 2222]) == 6\n assert candidate(nums = [564, 465, 654, 645, 546, 456]) == 2\n assert candidate(nums = [101010101, 202020202, 303030303, 404040404, 505050505, 606060606, 707070707, 808080808, 909090909]) == 36\n assert candidate(nums = [123, 456, 789, 1234, 5678, 9012, 3456, 7890, 12345, 67890]) == 7\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 36\n assert candidate(nums = [101, 101, 101, 101, 101, 101, 101, 101, 101, 101]) == 45\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555, 666666]) == 15\n assert candidate(nums = [1001, 1101, 1201, 1301, 1401, 1501, 1601, 1701, 1801, 1901]) == 0\n assert candidate(nums = [123456789, 234567890, 345678901, 456789012, 567890123, 678901234, 789012345, 890123456, 901234567, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 40\n assert candidate(nums = [121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, 303, 313, 323, 333, 343, 353, 363, 373, 383, 393, 404, 414, 424, 434, 444, 454, 464, 474, 484, 494, 505, 515, 525, 535, 545, 555, 565, 575, 585, 595, 606, 616, 626, 636, 646, 656, 666, 676, 686, 696, 707, 717, 727, 737, 747, 757, 767, 777, 787, 797, 808, 818, 828, 838, 848, 858, 868, 878, 888, 898, 909, 919, 929, 939, 949, 959, 969, 979, 989, 999]) == 3828\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555]) == 10\n assert candidate(nums = [123456789, 234567890, 345678901, 456789012, 567890123, 678901234, 789012345, 890123456, 901234567, 101234567]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 45\n assert candidate(nums = [1001, 1010, 1100, 1, 10, 100]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 45\n assert candidate(nums = [12345, 54321, 1234, 4321, 123, 321, 12, 21, 1, 0]) == 1\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 36\n assert candidate(nums = [12345, 54321, 12345, 54321, 12345, 54321, 12345, 54321]) == 12\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == 36\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]) == 0\n assert candidate(nums = [987, 789, 897, 798, 978, 879, 987, 789, 897, 798]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 36\n assert candidate(nums = [500000000, 400000000, 300000000, 200000000, 100000000, 50000000, 40000000, 30000000, 20000000, 10000000, 5000000, 4000000, 3000000, 2000000, 1000000, 500000, 400000, 300000, 200000, 100000]) == 0\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 0]) == 45\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 36\n assert candidate(nums = [1234, 4321, 1111, 2222, 3333, 4444, 5555]) == 10\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901]) == 22\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999]) == 28\n assert candidate(nums = [120, 210, 102, 201, 321, 123, 312, 213, 432, 234]) == 8\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999]) == 36\n assert candidate(nums = [123, 321, 213, 132, 312, 231]) == 2\n assert candidate(nums = [123456789, 987654321, 12345678, 87654321, 1234567, 7654321, 123456, 654321, 12345, 54321, 1234, 4321, 123, 321, 12, 21, 1, 0]) == 1\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 11011, 22022, 33033, 44044, 55055, 66066, 77077, 88088, 99099, 11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999]) == 351\n assert candidate(nums = [10001, 10101, 11001, 11111, 20002, 20202, 22002, 22222]) == 15\n assert candidate(nums = [1230, 3210, 2130, 1320, 3120, 2310]) == 0\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 1]) == 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]) == 45\n assert candidate(nums = [123, 321, 213, 312, 132, 231, 456, 654, 546, 465, 789, 987, 897, 798, 101, 11, 22, 33, 44, 55, 66, 77, 88, 99]) == 64\n assert candidate(nums = [999999999, 100000000, 111111111, 222222222, 333333333, 444444444, 555555555]) == 15\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789]) == 36\n assert candidate(nums = [1001, 1010, 1100, 100, 10, 1, 11, 111, 1111]) == 10\n assert candidate(nums = [1234, 4321, 5678, 8765, 9012, 2109, 3456, 6543]) == 6\n assert candidate(nums = [123456, 654321, 123456, 654321, 123456, 654321]) == 6\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993]) == 0\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 1000000000]) == 36\n assert candidate(nums = [12321, 13231, 21312, 31213, 41114, 51015, 60906, 70807, 80708, 90609]) == 45\n assert candidate(nums = [12345, 54321, 23451, 123456, 654321, 213456, 111111, 222222, 333333, 444444]) == 6\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 171\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 36\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 153\n assert candidate(nums = [1234, 4321, 3412, 2143, 2341, 3142, 1324, 4231, 4123, 2413, 3214, 1423]) == 1\n assert candidate(nums = [1, 21, 12, 11, 22, 202, 220, 101, 110, 111, 2002, 2200, 2020, 1001, 1100, 1010, 10001, 10101, 11001]) == 45\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 0\n assert candidate(nums = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 1000000000]) == 0\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 101, 110, 111]) == 7\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 4321, 1234, 1111, 2222, 3333]) == 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]) == 45\n assert candidate(nums = [1001, 1010, 1100, 2002, 2020, 2200, 3003, 3030, 3300]) == 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]) == 435\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 0\n assert candidate(nums = [1000001, 2000002, 3000003, 4000004, 5000005, 6000006, 7000007, 8000008, 9000009]) == 36\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 36\n assert candidate(nums = [100001, 100010, 100100, 101000, 110000, 100002, 100020, 100200, 102000, 120000]) == 0\n assert candidate(nums = [123456789, 987654321, 234567890, 890123456, 345678901, 765432109, 456789012, 654321098, 567890123, 345678901]) == 3\n assert candidate(nums = [112233, 332211, 221133, 113322, 445566, 665544, 556644]) == 3\n assert candidate(nums = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 0\n assert candidate(nums = [12, 21, 13, 31, 23, 32, 14, 41, 24, 42, 34, 43]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 0\n assert candidate(nums = [100001, 100101, 101001, 101101, 110001, 110101, 111001, 111101]) == 2\n assert candidate(nums = [999999999, 999999998, 999999997, 999999996, 999999995]) == 0\n assert candidate(nums = [900000000, 800000000, 700000000, 600000000, 500000000, 400000000, 300000000, 200000000, 100000000]) == 0\n assert candidate(nums = [123456789, 123456790, 123456788, 123456791, 123456787, 123456792, 123456786, 123456793, 123456785, 123456794]) == 0\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == 36\n assert candidate(nums = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 0\n assert candidate(nums = [123, 321, 213, 132, 312, 231, 101, 110, 10, 1]) == 5\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == 36\n assert candidate(nums = [123456789, 987654321, 234567890, 345678901, 456789012, 567890123, 678901234, 789012345, 890123456, 901234567]) == 4\n", "comparison": "exact"}, "public_tests": ["[42,11,1,97]", "[13,10,35,24,76]"], "hints": ["The condition can be rearranged to (nums[i] - rev(nums[i])) == (nums[j] - rev(nums[j])).", "Transform each nums[i] into (nums[i] - rev(nums[i])). Then, count the number of (i, j) pairs that have equal values.", "Keep a map storing the frequencies of values that you have seen so far. For each i, check if nums[i] is in the map. If it is, then add that count to the overall count. Then, increment the frequency of nums[i]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countNicePairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:32+00:00", "tests_total": 107, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting"]}, "language": "php", "interface": {"raw_signature": "function countNicePairs($nums) {", "container": "Solution", "callable": "countNicePairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1815, "task_id": "maximum-number-of-groups-getting-fresh-donuts", "difficulty": "Hard", "problem_description": "There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.\n\nWhen a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.\n\nYou can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.\n\nExample 1:\n\nInput: batchSize = 3, groups = [1,2,3,4,5,6]\nOutput: 4\nExplanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1^st, 2^nd, 4^th, and 6^th groups will be happy.\n\nExample 2:\n\nInput: batchSize = 4, groups = [1,3,2,5,2,2,1,6]\nOutput: 4\n\nConstraints:\n\n- 1 <= batchSize <= 9\n- 1 <= groups.length <= 30\n- 1 <= groups[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42, 49]) == 7\n assert candidate(batchSize = 2,groups = [2, 2, 2, 2, 2, 2]) == 6\n assert candidate(batchSize = 7,groups = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 12\n assert candidate(batchSize = 4,groups = [4, 8, 12, 16, 20]) == 5\n assert candidate(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42]) == 6\n assert candidate(batchSize = 3,groups = [1, 2, 3, 4, 5, 6]) == 4\n assert candidate(batchSize = 4,groups = [1, 3, 2, 5, 2, 2, 1, 6]) == 4\n assert candidate(batchSize = 3,groups = [3, 6, 9, 12, 15]) == 5\n assert candidate(batchSize = 5,groups = [5, 10, 15, 20, 25]) == 5\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64, 72]) == 9\n assert candidate(batchSize = 1,groups = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(batchSize = 5,groups = [1, 2, 3, 4, 5]) == 3\n assert candidate(batchSize = 5,groups = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(batchSize = 9,groups = [9, 18, 27, 36, 45, 54, 63, 72, 81]) == 9\n assert candidate(batchSize = 3,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 10\n assert candidate(batchSize = 8,groups = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 15\n assert candidate(batchSize = 5,groups = [5, 5, 5, 5, 5, 5]) == 6\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42, 49, 56]) == 8\n assert candidate(batchSize = 9,groups = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(batchSize = 9,groups = [9, 9, 9, 9, 9, 9, 9, 9, 9]) == 9\n assert candidate(batchSize = 2,groups = [1, 2, 3, 4, 5]) == 4\n assert candidate(batchSize = 6,groups = [6, 12, 18, 24, 30, 36, 42, 48, 54]) == 9\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64]) == 8\n assert candidate(batchSize = 5,groups = [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(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 11\n assert candidate(batchSize = 8,groups = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 8\n assert candidate(batchSize = 7,groups = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 11\n assert candidate(batchSize = 6,groups = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]) == 10\n assert candidate(batchSize = 5,groups = [5, 5, 5, 5, 5, 5, 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(batchSize = 4,groups = [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]) == 19\n assert candidate(batchSize = 9,groups = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 10\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147]) == 21\n assert candidate(batchSize = 8,groups = [4, 7, 9, 12, 14, 15, 18, 20, 22, 23, 25, 26, 27, 29, 31, 32]) == 8\n assert candidate(batchSize = 2,groups = [1, 1, 1, 1, 1, 1, 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(batchSize = 5,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(batchSize = 7,groups = [14, 28, 42, 56, 70, 84, 98, 112, 126, 140, 154, 168, 182]) == 13\n assert candidate(batchSize = 9,groups = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]) == 14\n assert candidate(batchSize = 6,groups = [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]) == 30\n assert candidate(batchSize = 5,groups = [8, 9, 10, 11, 12, 13, 14, 15]) == 5\n assert candidate(batchSize = 5,groups = [5, 10, 15, 20, 25, 30, 35, 40]) == 8\n assert candidate(batchSize = 9,groups = [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(batchSize = 5,groups = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 6\n assert candidate(batchSize = 6,groups = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == 15\n assert candidate(batchSize = 4,groups = [5, 8, 10, 11, 13, 16, 17, 19, 21, 22, 25, 28, 30]) == 8\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80]) == 10\n assert candidate(batchSize = 2,groups = [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]) == 21\n assert candidate(batchSize = 5,groups = [2, 3, 7, 8, 10, 12, 15, 17]) == 5\n assert candidate(batchSize = 3,groups = [9, 15, 2, 7, 8, 11, 13, 4, 1]) == 6\n assert candidate(batchSize = 4,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 13\n assert candidate(batchSize = 3,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 20\n assert candidate(batchSize = 6,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 7\n assert candidate(batchSize = 5,groups = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165]) == 9\n assert candidate(batchSize = 8,groups = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 3\n assert candidate(batchSize = 9,groups = [1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112]) == 8\n assert candidate(batchSize = 5,groups = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 6\n assert candidate(batchSize = 5,groups = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(batchSize = 7,groups = [1, 8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92]) == 2\n assert candidate(batchSize = 9,groups = [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]) == 20\n assert candidate(batchSize = 5,groups = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 6\n assert candidate(batchSize = 5,groups = [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]) == 30\n assert candidate(batchSize = 3,groups = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40]) == 5\n assert candidate(batchSize = 7,groups = [1, 1, 1, 1, 1, 1, 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(batchSize = 4,groups = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 8\n assert candidate(batchSize = 8,groups = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119]) == 10\n assert candidate(batchSize = 6,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(batchSize = 4,groups = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 6\n assert candidate(batchSize = 5,groups = [2, 4, 6, 8, 10, 12, 14, 16]) == 5\n assert candidate(batchSize = 9,groups = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 6\n assert candidate(batchSize = 9,groups = [8, 7, 6, 5, 4, 3, 2, 1, 9, 18, 27, 36, 45, 54, 63, 72, 81]) == 13\n assert candidate(batchSize = 4,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 9\n assert candidate(batchSize = 4,groups = [13, 19, 22, 29, 31, 37, 41, 43, 47, 53, 59]) == 6\n assert candidate(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 8\n assert candidate(batchSize = 3,groups = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 14\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104]) == 13\n assert candidate(batchSize = 8,groups = [15, 22, 33, 44, 55, 66, 77, 88, 99]) == 5\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96]) == 12\n assert candidate(batchSize = 6,groups = [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]) == 30\n assert candidate(batchSize = 4,groups = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]) == 10\n assert candidate(batchSize = 6,groups = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == 8\n assert candidate(batchSize = 8,groups = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120]) == 15\n assert candidate(batchSize = 5,groups = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 9\n assert candidate(batchSize = 6,groups = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72]) == 12\n assert candidate(batchSize = 9,groups = [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]) == 7\n assert candidate(batchSize = 7,groups = [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]) == 30\n assert candidate(batchSize = 9,groups = [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93]) == 7\n assert candidate(batchSize = 5,groups = [2, 3, 4, 1, 5, 6, 7, 8, 9]) == 5\n assert candidate(batchSize = 8,groups = [1, 1, 1, 1, 1, 1, 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(batchSize = 3,groups = [1, 1, 1, 1, 1, 1, 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(batchSize = 9,groups = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 8\n assert candidate(batchSize = 5,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 9\n assert candidate(batchSize = 6,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 18\n assert candidate(batchSize = 8,groups = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112]) == 9\n assert candidate(batchSize = 6,groups = [12, 24, 36, 48, 60, 72, 84, 96, 108]) == 9\n assert candidate(batchSize = 3,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39]) == 13\n assert candidate(batchSize = 7,groups = [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]) == 14\n assert candidate(batchSize = 9,groups = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91]) == 2\n assert candidate(batchSize = 8,groups = [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]) == 30\n assert candidate(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 5\n assert candidate(batchSize = 6,groups = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51]) == 7\n assert candidate(batchSize = 6,groups = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]) == 6\n assert candidate(batchSize = 3,groups = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 7\n assert candidate(batchSize = 3,groups = [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(batchSize = 4,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 10\n assert candidate(batchSize = 3,groups = [1, 1, 1, 1, 1, 1, 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(batchSize = 9,groups = [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]) == 16\n assert candidate(batchSize = 5,groups = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == 17\n assert candidate(batchSize = 6,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 7\n assert candidate(batchSize = 7,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 9\n assert candidate(batchSize = 7,groups = [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]) == 10\n assert candidate(batchSize = 3,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 20\n assert candidate(batchSize = 7,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 9\n assert candidate(batchSize = 5,groups = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 15\n assert candidate(batchSize = 3,groups = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 8\n assert candidate(batchSize = 4,groups = [9, 13, 17, 21, 25, 29, 33, 37, 41, 45]) == 3\n assert candidate(batchSize = 4,groups = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 8\n assert candidate(batchSize = 7,groups = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112]) == 16\n assert candidate(batchSize = 9,groups = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180]) == 20\n assert candidate(batchSize = 9,groups = [8, 17, 26, 35, 44, 53, 62, 71, 80, 89, 98, 107, 116, 125, 134, 143, 152]) == 2\n assert candidate(batchSize = 9,groups = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 11\n assert candidate(batchSize = 5,groups = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 20\n assert candidate(batchSize = 3,groups = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]) == 12\n assert candidate(batchSize = 5,groups = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n", "comparison": "exact"}, "public_tests": ["3\n[1,2,3,4,5,6]", "4\n[1,3,2,5,2,2,1,6]"], "hints": ["The maximum number of happy groups is the maximum number of partitions you can split the groups into such that the sum of group sizes in each partition is 0 mod batchSize. At most one partition is allowed to have a different remainder (the first group will get fresh donuts anyway).", "Suppose you have an array freq of length k where freq[i] = number of groups of size i mod batchSize. How can you utilize this in a dp solution?", "Make a DP state dp[freq][r] that represents \"the maximum number of partitions you can form given the current freq and current remainder r\". You can hash the freq array to store it more easily in the dp table.", "For each i from 0 to batchSize-1, the next DP state is dp[freq`][(r+i)%batchSize] where freq` is freq but with freq[i] decremented by 1. Take the largest of all of the next states and store it in ans. If r == 0, then return ans+1 (because you can form a new partition), otherwise return ans (continuing the current partition)."], "metadata": {"canonical_parameter_names": ["batchSize", "groups"], "leetcode_dataset_entry_point": "Solution().maxHappyGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:34+00:00", "tests_total": 125, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "memoization", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function maxHappyGroups($batchSize, $groups) {", "container": "Solution", "callable": "maxHappyGroups", "parameters": [{"name": "batchSize", "type": "Integer"}, {"name": "groups", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1816, "task_id": "truncate-sentence", "difficulty": "Easy", "problem_description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).\n\n- For example, \"Hello World\", \"HELLO\", and \"hello world hello world\" are all sentences.\n\nYou are given a sentence s and an integer k. You want to truncate s such that it contains only the first k words. Return s after truncating it.\n\nExample 1:\n\nInput: s = \"Hello how are you Contestant\", k = 4\nOutput: \"Hello how are you\"\nExplanation:\nThe words in s are [\"Hello\", \"how\", \"are\", \"you\", \"Contestant\"].\nThe first 4 words are [\"Hello\", \"how\", \"are\", \"you\"].\nHence, you should return \"Hello how are you\".\n\nExample 2:\n\nInput: s = \"What is the solution to this problem\", k = 4\nOutput: \"What is the solution\"\nExplanation:\nThe words in s are [\"What\", \"is\", \"the\", \"solution\", \"to\", \"this\", \"problem\"].\nThe first 4 words are [\"What\", \"is\", \"the\", \"solution\"].\nHence, you should return \"What is the solution\".\n\nExample 3:\n\nInput: s = \"chopper is not a tanuki\", k = 5\nOutput: \"chopper is not a tanuki\"\n\nConstraints:\n\n- 1 <= s.length <= 500\n- k is in the range [1, the number of words in s].\n- s consist of only lowercase and uppercase English letters and spaces.\n- The words in s are separated by a single space.\n- There are no leading or trailing spaces.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"I love to code\",k = 3) == \"I love to\"\n assert candidate(s = \"Python is great\",k = 2) == \"Python is\"\n assert candidate(s = \"Python programming is fun\",k = 2) == \"Python programming\"\n assert candidate(s = \"A quick brown fox jumps over the lazy dog\",k = 3) == \"A quick brown\"\n assert candidate(s = \"I love programming in Python\",k = 3) == \"I love programming\"\n assert candidate(s = \"Hello how are you Contestant\",k = 4) == \"Hello how are you\"\n assert candidate(s = \"Python is a great programming language\",k = 2) == \"Python is\"\n assert candidate(s = \"chopper is not a tanuki\",k = 5) == \"chopper is not a tanuki\"\n assert candidate(s = \"Python is fun\",k = 2) == \"Python is\"\n assert candidate(s = \"I love programming\",k = 1) == \"I\"\n assert candidate(s = \"What is the solution to this problem\",k = 4) == \"What is the solution\"\n assert candidate(s = \"I love solving problems\",k = 3) == \"I love solving\"\n assert candidate(s = \"It does not matter how slowly you go as long as you do not stop\",k = 9) == \"It does not matter how slowly you go as\"\n assert candidate(s = \"The road to success is always under construction\",k = 7) == \"The road to success is always under\"\n assert candidate(s = \"The best way to predict your future is to create it\",k = 8) == \"The best way to predict your future is\"\n assert candidate(s = \"This is a test sentence to check the functionality of the code\",k = 9) == \"This is a test sentence to check the functionality\"\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\",k = 5) == \"a b c d e\"\n assert candidate(s = \"A journey of a thousand miles begins with a single step\",k = 8) == \"A journey of a thousand miles begins with\"\n assert candidate(s = \"Keep it simple stupid\",k = 5) == \"Keep it simple stupid\"\n assert candidate(s = \"To be or not to be that is the question\",k = 10) == \"To be or not to be that is the question\"\n assert candidate(s = \"May the Force be with you young Jedi\",k = 6) == \"May the Force be with you\"\n assert candidate(s = \"Short sentence\",k = 2) == \"Short sentence\"\n assert candidate(s = \"The only way to do great work is to love what you do\",k = 7) == \"The only way to do great work\"\n assert candidate(s = \"Honesty is the best policy\",k = 4) == \"Honesty is the best\"\n assert candidate(s = \"In the middle of difficulty lies opportunity\",k = 4) == \"In the middle of\"\n assert candidate(s = \"Natural language processing has become a cornerstone of modern technology\",k = 9) == \"Natural language processing has become a cornerstone of modern\"\n assert candidate(s = \"One two three four five six seven eight nine ten\",k = 10) == \"One two three four five six seven eight nine ten\"\n assert candidate(s = \"One two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen\",k = 10) == \"One two three four five six seven eight nine ten\"\n assert candidate(s = \"What you get by achieving your goals is not as important as what you become by achieving your goals\",k = 12) == \"What you get by achieving your goals is not as important as\"\n assert candidate(s = \"Debugging is twice as hard as writing the code in the first place\",k = 7) == \"Debugging is twice as hard as writing\"\n assert candidate(s = \"Python programming is fun and challenging\",k = 10) == \"Python programming is fun and challenging\"\n assert candidate(s = \"A journey of a thousand miles begins with a single step\",k = 7) == \"A journey of a thousand miles begins\"\n assert candidate(s = \"Success is not final success is to be able to continue to try\",k = 8) == \"Success is not final success is to be\"\n assert candidate(s = \"OneWordOnly\",k = 1) == \"OneWordOnly\"\n assert candidate(s = \"Data Science and Machine Learning\",k = 3) == \"Data Science and\"\n assert candidate(s = \"Life is what happens when you are busy making other plans\",k = 7) == \"Life is what happens when you are\"\n assert candidate(s = \"The early morning sun is warm and welcoming\",k = 7) == \"The early morning sun is warm and\"\n assert candidate(s = \"To be or not to be that is the question\",k = 7) == \"To be or not to be that\"\n assert candidate(s = \"Short but tricky\",k = 2) == \"Short but\"\n assert candidate(s = \"The early bird catches the worm\",k = 5) == \"The early bird catches the\"\n assert candidate(s = \"Final complex sentence with multiple words indeed\",k = 7) == \"Final complex sentence with multiple words indeed\"\n assert candidate(s = \"The best way to predict the future is to invent it\",k = 9) == \"The best way to predict the future is to\"\n assert candidate(s = \"VeryLongWordWithoutSpacesIsAlsoAcceptedButNotTypicalInSentences\",k = 1) == \"VeryLongWordWithoutSpacesIsAlsoAcceptedButNotTypicalInSentences\"\n assert candidate(s = \"Do not judge a book by its cover\",k = 7) == \"Do not judge a book by its\"\n assert candidate(s = \"All that glitters is not gold only the good do well by gold\",k = 9) == \"All that glitters is not gold only the good\"\n assert candidate(s = \"All that glitters is not gold\",k = 5) == \"All that glitters is not\"\n assert candidate(s = \"To be or not to be that is the question\",k = 5) == \"To be or not to\"\n assert candidate(s = \"Edge case with k equal to the number of words here\",k = 9) == \"Edge case with k equal to the number of\"\n assert candidate(s = \"Multiple words with mixed CASE Words\",k = 4) == \"Multiple words with mixed\"\n assert candidate(s = \"Programming in Python is both fun and educational\",k = 6) == \"Programming in Python is both fun\"\n assert candidate(s = \"A journey of a thousand miles begins with a single step\",k = 6) == \"A journey of a thousand miles\"\n assert candidate(s = \"Success is not final success is courage to continue\",k = 7) == \"Success is not final success is courage\"\n assert candidate(s = \"In the beginning God created the heavens and the earth\",k = 6) == \"In the beginning God created the\"\n assert candidate(s = \"Programming in Python is very rewarding\",k = 5) == \"Programming in Python is very\"\n assert candidate(s = \"You can lead a horse to water but you cannot make it drink\",k = 11) == \"You can lead a horse to water but you cannot make\"\n assert candidate(s = \"Another example with different words\",k = 3) == \"Another example with\"\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\",k = 10) == \"A B C D E F G H I J\"\n assert candidate(s = \"The quick brown fox jumps over the lazy dog\",k = 9) == \"The quick brown fox jumps over the lazy dog\"\n assert candidate(s = \"MixedCASE Words In Sentences Should Be Handled\",k = 5) == \"MixedCASE Words In Sentences Should\"\n assert candidate(s = \"Well done is better than well said\",k = 5) == \"Well done is better than\"\n assert candidate(s = \"The quick brown fox jumps over the lazy dog\",k = 7) == \"The quick brown fox jumps over the\"\n assert candidate(s = \"Yet another test to ensure correctness\",k = 5) == \"Yet another test to ensure\"\n assert candidate(s = \"Edge case test with exact words count\",k = 6) == \"Edge case test with exact words\"\n assert candidate(s = \"SingleWord\",k = 1) == \"SingleWord\"\n assert candidate(s = \"Hello World from the other side of the universe\",k = 8) == \"Hello World from the other side of the\"\n assert candidate(s = \"In the middle of every difficulty lies opportunity\",k = 8) == \"In the middle of every difficulty lies opportunity\"\n assert candidate(s = \"One two three four five six seven eight nine ten\",k = 5) == \"One two three four five\"\n assert candidate(s = \"With great power comes great responsibility\",k = 5) == \"With great power comes great\"\n assert candidate(s = \"Multiple Spaces Between Words Are Not Allowed\",k = 5) == \"Multiple Spaces Between Words Are\"\n assert candidate(s = \"Multiple spaces should not be here but for testing purposes we will add them\",k = 10) == \"Multiple spaces should not be here but for testing purposes\"\n assert candidate(s = \"An apple a day keeps the doctor away\",k = 8) == \"An apple a day keeps the doctor away\"\n assert candidate(s = \"Sometimes the journey is more important than the destination\",k = 9) == \"Sometimes the journey is more important than the destination\"\n assert candidate(s = \"Sometimes you just want to have a long sentence to test the truncation functionality of the code\",k = 15) == \"Sometimes you just want to have a long sentence to test the truncation functionality of\"\n assert candidate(s = \"A quick brown fox jumps over the lazy dog\",k = 9) == \"A quick brown fox jumps over the lazy dog\"\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\",k = 26) == \"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 = \"This is a very long sentence that we need to truncate to the first few words\",k = 7) == \"This is a very long sentence that\"\n assert candidate(s = \"May the force be with you\",k = 5) == \"May the force be with\"\n assert candidate(s = \"In the heart of the night the fireflies dance\",k = 8) == \"In the heart of the night the fireflies\"\n assert candidate(s = \"ManyManyWordsInOneSentenceWithoutSpacesButAllowedByConstraintsIfWeRemoveSpacesThenThisWillBeAVeryLongListofWords\",k = 5) == \"ManyManyWordsInOneSentenceWithoutSpacesButAllowedByConstraintsIfWeRemoveSpacesThenThisWillBeAVeryLongListofWords\"\n assert candidate(s = \"To be or not to be that is the question\",k = 6) == \"To be or not to be\"\n assert candidate(s = \"Better late than never\",k = 4) == \"Better late than never\"\n assert candidate(s = \"Actions speak louder than words\",k = 4) == \"Actions speak louder than\"\n assert candidate(s = \"Keep calm and carry on\",k = 3) == \"Keep calm and\"\n assert candidate(s = \"Lorem ipsum dolor sit amet consectetur adipiscing elit\",k = 7) == \"Lorem ipsum dolor sit amet consectetur adipiscing\"\n assert candidate(s = \"This is a longer sentence to test the functionality\",k = 7) == \"This is a longer sentence to test\"\n assert candidate(s = \"Software design is all about managing complexity\",k = 7) == \"Software design is all about managing complexity\"\n assert candidate(s = \"May the Force be with you\",k = 3) == \"May the Force\"\n assert candidate(s = \"Data structures and algorithms are the building blocks of software development\",k = 8) == \"Data structures and algorithms are the building blocks\"\n assert candidate(s = \"An algorithm must be seen to be believed\",k = 5) == \"An algorithm must be seen\"\n assert candidate(s = \"This is a test for truncating the sentence at exactly the word limit\",k = 10) == \"This is a test for truncating the sentence at exactly\"\n", "comparison": "exact"}, "public_tests": ["\"Hello how are you Contestant\"\n4", "\"What is the solution to this problem\"\n4", "\"chopper is not a tanuki\"\n5"], "hints": ["It's easier to solve this problem on an array of strings so parse the string to an array of words", "After return the first k words as a sentence"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().truncateSentence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:36+00:00", "tests_total": 94, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function truncateSentence($s, $k) {", "container": "Solution", "callable": "truncateSentence", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1817, "task_id": "finding-the-users-active-minutes", "difficulty": "Medium", "problem_description": "You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [ID_i, time_i] indicates that the user with ID_i performed an action at the minute time_i.\n\nMultiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.\n\nThe user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.\n\nYou are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.\n\nReturn the array answer as described above.\n\nExample 1:\n\nInput: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\nOutput: [0,2,0,0,0]\nExplanation:\nThe user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).\nThe user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nSince both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.\n\nExample 2:\n\nInput: logs = [[1,1],[2,2],[2,3]], k = 4\nOutput: [1,1,0,0]\nExplanation:\nThe user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.\nThe user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nThere is one user with a UAM of 1 and one with a UAM of 2.\nHence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.\n\nConstraints:\n\n- 1 <= logs.length <= 10^4\n- 0 <= ID_i <= 10^9\n- 1 <= time_i <= 10^5\n- k is in the range [The maximum UAM for a user, 10^5].\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],k = 3) == [0, 0, 3]\n assert candidate(logs = [[10, 1], [11, 2], [10, 2], [11, 3], [10, 3], [11, 4]],k = 4) == [0, 0, 2, 0]\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],k = 5) == [0, 0, 0, 0, 1]\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3]],k = 3) == [0, 0, 2]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1]],k = 1) == [4]\n assert candidate(logs = [[1, 1], [2, 2], [2, 3]],k = 4) == [1, 1, 0, 0]\n assert candidate(logs = [[10, 10], [10, 10], [10, 11], [11, 12]],k = 3) == [1, 1, 0]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 5) == [5, 0, 0, 0, 0]\n assert candidate(logs = [[0, 10], [0, 10], [1, 10], [1, 11], [1, 12]],k = 3) == [1, 0, 1]\n assert candidate(logs = [[1, 1], [2, 2], [3, 3], [4, 4]],k = 4) == [4, 0, 0, 0]\n assert candidate(logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],k = 5) == [5, 0, 0, 0, 0]\n assert candidate(logs = [[0, 5], [1, 2], [0, 2], [0, 5], [1, 3]],k = 5) == [0, 2, 0, 0, 0]\n assert candidate(logs = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],k = 1) == [1]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1]],k = 1) == [5]\n assert candidate(logs = [[10, 10], [10, 10], [10, 11], [10, 12], [11, 10], [11, 11]],k = 3) == [0, 1, 1]\n assert candidate(logs = [[10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10], [90, 10], [100, 10], [110, 10], [120, 10], [130, 10], [140, 10], [150, 10]],k = 1) == [15]\n assert candidate(logs = [[100, 1], [101, 1], [102, 2], [103, 2], [104, 3], [105, 3], [106, 4], [107, 4], [108, 5], [109, 5]],k = 5) == [10, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 10) == [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10]],k = 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[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, 16], [1, 17], [2, 18], [3, 19], [4, 20]],k = 15) == [10, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(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]],k = 5) == [5, 5, 0, 0, 0]\n assert candidate(logs = [[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 = 5) == [5, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],k = 3) == [0, 0, 4]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],k = 5) == [0, 0, 0, 0, 2]\n assert candidate(logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],k = 10) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(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]],k = 3) == [0, 0, 5]\n assert candidate(logs = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1]],k = 2) == [0, 5]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [0, 4], [1, 5], [2, 6], [0, 7], [1, 8], [2, 9], [0, 10], [1, 11], [2, 12], [0, 13], [1, 14], [2, 15]],k = 5) == [0, 0, 0, 0, 3]\n assert candidate(logs = [[5, 1], [5, 1], [5, 1], [5, 1], [5, 1], [6, 2], [6, 2], [6, 2], [6, 3], [6, 4], [6, 5], [7, 3], [7, 3], [7, 3], [7, 3], [7, 3], [7, 3], [7, 3], [7, 3], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4], [8, 4]],k = 5) == [3, 0, 0, 1, 0]\n assert candidate(logs = [[1, 1], [1, 1], [1, 1], [1, 2], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]],k = 5) == [0, 0, 1, 1, 1]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19]],k = 10) == [0, 0, 0, 0, 1, 0, 0, 0, 1, 1]\n assert candidate(logs = [[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 = 15) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[100, 1], [101, 1], [102, 2], [103, 2], [104, 2], [105, 3], [106, 3], [107, 3], [108, 4], [109, 4]],k = 4) == [10, 0, 0, 0]\n assert candidate(logs = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15]],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(logs = [[0, 10], [1, 20], [0, 10], [1, 25], [2, 30], [3, 35], [4, 40], [5, 45], [6, 50], [7, 55], [8, 60], [9, 65]],k = 10) == [9, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2], [11, 3], [12, 3], [13, 3], [14, 3], [15, 3]],k = 3) == [15, 0, 0]\n assert candidate(logs = [[9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9], [9, 10], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]],k = 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 2]\n assert candidate(logs = [[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) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 2]\n assert candidate(logs = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [0, 1100], [1, 1200], [2, 1300], [3, 1400], [4, 1500], [5, 1600], [6, 1700], [7, 1800], [8, 1900], [9, 2000]],k = 10) == [0, 10, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[10, 5], [10, 5], [10, 6], [10, 7], [11, 5], [11, 6], [11, 7], [12, 5], [12, 6], [12, 7], [13, 5], [13, 6], [13, 7]],k = 3) == [0, 0, 4]\n assert candidate(logs = [[0, 10], [1, 10], [2, 10], [0, 11], [1, 11], [2, 11], [0, 12], [1, 12], [2, 12]],k = 3) == [0, 0, 3]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]],k = 1) == [10]\n assert candidate(logs = [[100, 1], [100, 2], [100, 3], [100, 4], [100, 5], [101, 1], [101, 2], [101, 3], [101, 4], [101, 5], [102, 1], [102, 2], [102, 3], [102, 4], [102, 5], [103, 1], [103, 2], [103, 3], [103, 4], [103, 5]],k = 5) == [0, 0, 0, 0, 4]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [0, 11], [1, 12], [2, 13], [3, 14], [4, 15], [5, 16], [6, 17], [7, 18], [8, 19], [9, 20]],k = 10) == [0, 10, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 5], [0, 5], [0, 5], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 1], [2, 1], [2, 2]],k = 5) == [1, 1, 0, 1, 0]\n assert candidate(logs = [[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], [0, 4], [1, 5], [2, 6], [3, 7], [4, 8]],k = 5) == [0, 0, 0, 5, 0]\n assert candidate(logs = [[99, 99], [99, 100], [99, 101], [99, 102], [99, 103], [99, 104], [99, 105]],k = 7) == [0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [110, 11], [120, 12], [130, 13], [140, 14], [150, 15]],k = 15) == [15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 2]\n assert candidate(logs = [[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]],k = 10) == [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\n assert candidate(logs = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5]],k = 5) == [0, 0, 0, 0, 3]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [0, 3], [1, 3], [2, 3], [3, 3], [4, 3]],k = 3) == [0, 0, 5]\n assert candidate(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]],k = 15) == [0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[10, 100], [11, 101], [10, 101], [11, 102], [12, 102], [13, 103], [13, 104], [14, 104], [14, 105], [15, 106], [15, 106], [15, 107]],k = 5) == [1, 5, 0, 0, 0]\n assert candidate(logs = [[0, 10], [0, 10], [0, 11], [1, 12], [1, 12], [1, 13], [2, 14], [2, 15], [2, 15], [2, 16]],k = 4) == [0, 2, 1, 0]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]],k = 2) == [0, 11]\n assert candidate(logs = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1]],k = 1) == [1]\n assert candidate(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]],k = 20) == [20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]],k = 5) == [0, 0, 0, 0, 2]\n assert candidate(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]],k = 5) == [0, 0, 0, 0, 3]\n assert candidate(logs = [[0, 1], [0, 2], [1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2], [4, 1], [4, 2], [5, 1], [5, 2]],k = 2) == [0, 6]\n assert candidate(logs = [[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]],k = 1) == [15]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [0, 11]],k = 11) == [9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [0, 3], [1, 3], [2, 3], [3, 3], [4, 3], [0, 4], [1, 4], [2, 4], [3, 4], [4, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [0, 6], [1, 6], [2, 6], [3, 6], [4, 6]],k = 6) == [0, 0, 0, 0, 0, 5]\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], [0, 3], [1, 3], [2, 3], [0, 4], [1, 4], [2, 4], [0, 5], [1, 5], [2, 5], [0, 6], [1, 6], [2, 6]],k = 6) == [0, 0, 0, 0, 0, 3]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]],k = 5) == [0, 0, 1, 1, 1]\n assert candidate(logs = [[10, 1], [10, 2], [10, 3], [20, 1], [20, 2], [30, 1], [30, 2], [30, 3], [40, 1], [40, 2], [40, 3], [50, 1], [50, 2], [50, 3], [60, 1], [60, 2]],k = 3) == [0, 2, 4]\n assert candidate(logs = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [1, 11], [2, 11], [3, 11], [4, 11], [5, 11], [1, 12], [2, 12], [3, 12], [4, 12], [5, 12]],k = 3) == [0, 0, 5]\n assert candidate(logs = [[0, 1], [0, 2], [0, 1], [0, 2], [0, 1], [0, 2], [0, 1], [0, 2], [0, 1], [0, 2], [0, 3], [0, 4]],k = 5) == [0, 0, 0, 1, 0]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 2) == [5, 0]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [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]],k = 3) == [0, 0, 7]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],k = 10) == [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\n assert candidate(logs = [[1, 1], [2, 2], [2, 2], [2, 3], [3, 3], [3, 3], [3, 3], [4, 4], [4, 4], [4, 4], [4, 4], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]],k = 4) == [4, 1, 0, 0]\n assert candidate(logs = [[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]],k = 4) == [0, 0, 0, 4]\n assert candidate(logs = [[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 = 1) == [15]\n assert candidate(logs = [[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]],k = 20) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]],k = 1) == [1]\n assert candidate(logs = [[1, 1], [1, 1], [1, 1], [2, 2], [2, 2], [3, 3], [3, 4], [3, 4], [4, 5], [4, 5], [4, 5], [5, 6], [5, 7], [5, 8], [6, 9]],k = 5) == [4, 1, 1, 0, 0]\n assert candidate(logs = [[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]],k = 1) == [5]\n assert candidate(logs = [[0, 5], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5]],k = 1) == [10]\n assert candidate(logs = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7], [3, 8], [3, 9], [3, 10], [3, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16]],k = 6) == [0, 2, 1, 1, 1, 0]\n assert candidate(logs = [[10, 10], [10, 10], [20, 20], [20, 21], [20, 22], [30, 30], [30, 30], [30, 31]],k = 3) == [1, 1, 1]\n assert candidate(logs = [[0, 1], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6]],k = 6) == [1, 0, 1, 1, 1, 1]\n assert candidate(logs = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2], [4, 1], [4, 2], [5, 1], [5, 2], [6, 1], [6, 2], [7, 1], [7, 2], [8, 1], [8, 2], [9, 1], [9, 2], [10, 1], [10, 2]],k = 2) == [0, 10]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8]],k = 8) == [0, 0, 0, 0, 1, 0, 1, 1]\n assert candidate(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], [1, 16]],k = 6) == [0, 0, 4, 1, 0, 0]\n assert candidate(logs = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [10, 11], [20, 12], [30, 13], [40, 14], [50, 15], [60, 16], [70, 17], [80, 18], [90, 19], [100, 20]],k = 10) == [0, 10, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3]],k = 3) == [0, 0, 5]\n assert candidate(logs = [[0, 1], [0, 1], [0, 1], [0, 2], [0, 2], [0, 2], [0, 3], [0, 3], [0, 3], [0, 4], [0, 4], [0, 4], [0, 5], [0, 5], [0, 5]],k = 5) == [0, 0, 0, 0, 1]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [0, 11], [1, 12], [2, 13], [3, 14], [4, 15]],k = 3) == [0, 0, 5]\n assert candidate(logs = [[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 = 15) == [15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [4, 18], [4, 19], [4, 20]],k = 7) == [1, 0, 2, 0, 0, 1, 1]\n assert candidate(logs = [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]],k = 5) == [0, 0, 1, 1, 1]\n assert candidate(logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [0, 11], [1, 12], [2, 13], [3, 14], [4, 15]],k = 5) == [0, 0, 5, 0, 0]\n assert candidate(logs = [[1, 1], [1, 1], [1, 2], [2, 1], [2, 1], [2, 2], [2, 3], [3, 1], [3, 1], [3, 2], [3, 3], [3, 4]],k = 4) == [0, 1, 1, 1]\n assert candidate(logs = [[0, 1], [0, 1], [1, 1], [1, 1], [2, 1], [2, 1], [3, 1], [3, 1], [4, 1], [4, 1]],k = 1) == [5]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]],k = 5) == [0, 0, 0, 0, 3]\n assert candidate(logs = [[10, 10], [20, 10], [10, 20], [20, 20], [10, 30], [20, 40], [30, 50]],k = 5) == [1, 0, 2, 0, 0]\n assert candidate(logs = [[1, 1], [1, 1], [1, 1], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 2], [4, 1], [4, 2], [4, 3], [4, 4]],k = 4) == [1, 1, 1, 1]\n assert candidate(logs = [[100, 1], [101, 2], [102, 3], [103, 4], [104, 5], [105, 6], [106, 7], [107, 8], [108, 9], [109, 10]],k = 10) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(logs = [[0, 1], [0, 2], [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],k = 3) == [0, 1, 3]\n assert candidate(logs = [[1, 1], [1, 1], [1, 1], [1, 2], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],k = 10) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[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]],k = 1) == [20]\n assert candidate(logs = [[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]],k = 20) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(logs = [[0, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],k = 1) == [11]\n assert candidate(logs = [[1, 1], [2, 1], [3, 1], [1, 2], [2, 2], [3, 2], [1, 3], [2, 3], [3, 3], [1, 4], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [1, 6], [2, 6], [3, 6], [1, 7], [2, 7], [3, 7]],k = 7) == [0, 0, 0, 0, 0, 0, 3]\n assert candidate(logs = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]],k = 5) == [0, 0, 0, 0, 3]\n", "comparison": "exact"}, "public_tests": ["[[0,5],[1,2],[0,2],[0,5],[1,3]]\n5", "[[1,1],[2,2],[2,3]]\n4"], "hints": ["Try to find the number of different minutes when action happened for each user.", "For each user increase the value of the answer array index which matches the UAM for this user."], "metadata": {"canonical_parameter_names": ["logs", "k"], "leetcode_dataset_entry_point": "Solution().findingUsersActiveMinutes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:39+00:00", "tests_total": 108, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "php", "interface": {"raw_signature": "function findingUsersActiveMinutes($logs, $k) {", "container": "Solution", "callable": "findingUsersActiveMinutes", "parameters": [{"name": "logs", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1818, "task_id": "minimum-absolute-sum-difference", "difficulty": "Medium", "problem_description": "You are given two positive integer arrays nums1 and nums2, both of length n.\n\nThe absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).\n\nYou can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.\n\nReturn the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 10^9 + 7.\n\n|x| is defined as:\n\n- x if x >= 0, or\n- -x if x < 0.\n\nExample 1:\n\nInput: nums1 = [1,7,5], nums2 = [2,3,5]\nOutput: 3\nExplanation: There are two possible optimal solutions:\n- Replace the second element with the first: [1,7,5] => [1,1,5], or\n- Replace the second element with the third: [1,7,5] => [1,5,5].\nBoth will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.\n\nExample 2:\n\nInput: nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\nOutput: 0\nExplanation: nums1 is equal to nums2 so no replacement is needed. This will result in an\nabsolute sum difference of 0.\n\nExample 3:\n\nInput: nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\nOutput: 20\nExplanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].\nThis yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n\nConstraints:\n\n- n == nums1.length\n- n == nums2.length\n- 1 <= n <= 10^5\n- 1 <= nums1[i], nums2[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [1, 1, 1]) == 299997\n assert candidate(nums1 = [1, 7, 5],nums2 = [2, 3, 5]) == 3\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1]) == 16\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [1, 1, 1]) == 299997\n assert candidate(nums1 = [1, 10, 4, 4, 2, 7],nums2 = [9, 3, 5, 1, 7, 4]) == 20\n assert candidate(nums1 = [2, 4, 6, 8, 10],nums2 = [2, 4, 6, 8, 10]) == 0\n assert candidate(nums1 = [1, 2, 3],nums2 = [6, 5, 4]) == 7\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 8\n assert candidate(nums1 = [100000, 1, 100000],nums2 = [1, 100000, 1]) == 199998\n assert candidate(nums1 = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000],nums2 = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == 899991\n assert candidate(nums1 = [100000, 99999, 99998, 99997],nums2 = [1, 2, 3, 4]) == 399981\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]) == 25\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1]) == 15\n assert candidate(nums1 = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 999881\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 999945\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]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 90\n assert candidate(nums1 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 945\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 5\n assert candidate(nums1 = [100000, 99999, 99998, 99997, 99996],nums2 = [1, 2, 3, 4, 5]) == 499971\n assert candidate(nums1 = [100000, 100000, 100000, 100000],nums2 = [1, 100000, 100000, 1]) == 199998\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 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]) == 41\n assert candidate(nums1 = [50000, 50000, 50000, 50000, 50000],nums2 = [1, 2, 3, 4, 5]) == 249985\n assert candidate(nums1 = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996],nums2 = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5]) == 899951\n assert candidate(nums1 = [100000, 1, 50000, 75000],nums2 = [50000, 99999, 1, 100000]) == 125000\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, 10, 20, 30, 40, 50, 60, 70, 80, 90],nums2 = [90, 80, 70, 60, 50, 40, 30, 20, 10, 1]) == 409\n assert candidate(nums1 = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996],nums2 = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5]) == 899951\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [45, 40, 35, 30, 25, 20, 15, 10, 5, 1]) == 204\n assert candidate(nums1 = [50000, 50000, 50000, 50000, 50000],nums2 = [1, 1, 1, 1, 1]) == 249995\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 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [1, 3, 6, 8, 11, 13, 16, 18, 21, 23]) == 130\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]) == 98\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999]) == 999980\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, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 499936\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5]) == 95\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]) == 36\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [90000, 90000, 90000]) == 30000\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, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 210\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]) == 500\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]) == 41\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, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\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]) == 50\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 32\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]) == 181\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]) == 82\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 25\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == 8\n assert candidate(nums1 = [1, 10, 100, 1000, 10000, 100000],nums2 = [100000, 10000, 1000, 100, 10, 1]) == 121779\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]) == 486\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]) == 410\n assert candidate(nums1 = [100, 100, 100, 100, 100],nums2 = [10, 90, 110, 10, 90]) == 210\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 999990\n assert candidate(nums1 = [100000, 100000, 100000, 100000],nums2 = [1, 1, 1, 1]) == 399996\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]) == 50\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 67\n assert candidate(nums1 = [1, 10, 100, 1000, 10000],nums2 = [2, 11, 101, 1001, 10001]) == 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]) == 405\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 5\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]) == 25\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 549990\n assert candidate(nums1 = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 999891\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]) == 20\n assert candidate(nums1 = [99999, 99998, 99997, 99996, 99995],nums2 = [1, 100, 200, 300, 400]) == 498980\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]) == 9\n assert candidate(nums1 = [50000, 40000, 30000, 20000, 10000],nums2 = [1, 2, 3, 4, 5]) == 109985\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]) == 171\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [50000, 40000, 30000, 20000, 10000]) == 210000\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]) == 99943\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [101, 201, 301, 401, 501]) == 5\n assert candidate(nums1 = [5, 25, 45, 65, 85],nums2 = [10, 30, 50, 70, 90]) == 25\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]) == 82\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 891\n assert candidate(nums1 = [100000, 100000, 100000, 100000, 100000],nums2 = [1, 1, 1, 1, 1]) == 499995\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]) == 540\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55]) == 25\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],nums2 = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 999882\n assert candidate(nums1 = [100000, 50000, 25000, 12500, 6250],nums2 = [99999, 49999, 24999, 12499, 6249]) == 5\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 55\n", "comparison": "exact"}, "public_tests": ["[1,7,5]\n[2,3,5]", "[2,4,6,8,10]\n[2,4,6,8,10]", "[1,10,4,4,2,7]\n[9,3,5,1,7,4]"], "hints": ["Go through each element and test the optimal replacements.", "There are only 2 possible replacements for each element (higher and lower) that are optimal."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minAbsoluteSumDiff", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:41+00:00", "tests_total": 87, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "binary-search", "sorting", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function minAbsoluteSumDiff($nums1, $nums2) {", "container": "Solution", "callable": "minAbsoluteSumDiff", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1819, "task_id": "number-of-different-subsequences-gcds", "difficulty": "Hard", "problem_description": "You are given an array nums that consists of positive integers.\n\nThe GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.\n\n- For example, the GCD of the sequence [4,6,16] is 2.\n\nA subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\n\n- For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].\n\nReturn the number of different GCDs among all non-empty subsequences of nums.\n\nExample 1:\n\nInput: nums = [6,10,3]\nOutput: 5\nExplanation: The figure shows all the non-empty subsequences and their GCDs.\nThe different GCDs are 6, 10, 3, 2, and 1.\n\nExample 2:\n\nInput: nums = [5,15,40,5,6]\nOutput: 7\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 2 * 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 10, 3]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10]) == 5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5, 15, 40, 5, 6]) == 7\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [7, 7, 7, 7, 7]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500]) == 5\n assert candidate(nums = [7, 14, 21, 28, 35]) == 5\n assert candidate(nums = [100000]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 11\n assert candidate(nums = [100000, 200000, 150000]) == 4\n assert candidate(nums = [7, 7, 7, 7]) == 1\n assert candidate(nums = [30, 15, 60, 90, 180]) == 5\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840, 882, 924, 966, 1008, 1050]) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 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 = [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]) == 15\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 10\n assert candidate(nums = [37, 74, 111, 148, 185, 222, 259, 296, 333, 370, 407, 444, 481, 518, 555, 592, 629, 666, 703, 740, 777, 814, 851, 888, 925, 962, 999]) == 27\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630]) == 15\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020]) == 20\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175]) == 18\n assert candidate(nums = [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 = [10, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205]) == 22\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]) == 15\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120]) == 20\n assert candidate(nums = [5, 25, 45, 65, 85, 105, 125, 145, 165, 185, 205, 225, 245, 265, 285, 305, 325, 345, 365, 385]) == 23\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 = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197]) == 21\n assert candidate(nums = [49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30]) == 34\n assert candidate(nums = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111]) == 25\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150]) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 10\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993]) == 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]) == 20\n assert candidate(nums = [12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 26\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260, 273, 286, 299, 312, 325, 338, 351, 364, 377, 390]) == 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]) == 25\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 16\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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]) == 20\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]) == 24\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515]) == 15\n assert candidate(nums = [37, 74, 111, 148, 185, 222, 259, 296, 333, 370, 407, 444, 481, 518, 555, 592, 629, 666, 703, 740]) == 20\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 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, 21, 22, 23, 24, 25]) == 25\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]) == 25\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, 286, 297, 308, 319, 330]) == 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]) == 20\n assert candidate(nums = [104729, 104728, 104727, 104726, 104725, 104724, 104723, 104722, 104721, 104720, 104719, 104718, 104717, 104716, 104715]) == 25\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 = [97, 194, 291, 388, 485, 582, 679, 776, 873, 970, 1067, 1164, 1261, 1358, 1455, 1552, 1649, 1746, 1843, 1940]) == 20\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 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]) == 16\n assert candidate(nums = [15, 21, 25, 33, 35, 39, 45, 51, 55, 57, 63, 65, 69, 75, 77, 81, 85, 87, 91, 93, 95, 99]) == 31\n assert candidate(nums = [37, 74, 111, 148, 185, 222, 259, 296, 333, 370, 407, 444, 481, 518, 555]) == 15\n assert candidate(nums = [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54]) == 18\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]) == 21\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540, 600]) == 10\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [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]) == 25\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 15\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]) == 26\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]) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == 14\n assert candidate(nums = [99995, 99996, 99997, 99998, 99999, 100000, 100001, 100002, 100003, 100004, 100005, 100006, 100007, 100008, 100009]) == 26\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 = [71, 142, 213, 284, 355, 426, 497, 568, 639, 710, 781, 852, 923, 994, 1065, 1136, 1207, 1278, 1349]) == 19\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600]) == 20\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180]) == 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]) == 20\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 15\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960, 1020, 1080, 1140, 1200]) == 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 = [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 = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 10\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345, 360, 375, 390, 405, 420, 435, 450]) == 30\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 1\n assert candidate(nums = [120, 240, 360, 480, 600, 720, 840, 960, 1080, 1200, 1320, 1440, 1560, 1680, 1800, 1920, 2040]) == 17\n assert candidate(nums = [21, 35, 49, 63, 77, 91, 105, 119, 133, 147]) == 11\n assert candidate(nums = [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]) == 33\n assert candidate(nums = [200000, 199999, 199998, 199997, 199996, 199995, 199994, 199993, 199992, 199991]) == 17\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300]) == 20\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 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]) == 20\n assert candidate(nums = [30, 42, 54, 60, 72, 84, 90, 102, 105, 108, 120, 126, 132, 144, 150, 156, 162, 168, 180, 192]) == 29\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015]) == 27\n", "comparison": "exact"}, "public_tests": ["[6,10,3]", "[5,15,40,5,6]"], "hints": ["Think of how to check if a number x is a gcd of a subsequence.", "If there is such subsequence, then all of it will be divisible by x. Moreover, if you divide each number in the subsequence by x , then the gcd of the resulting numbers will be 1.", "Adding a number to a subsequence cannot increase its gcd. So, if there is a valid subsequence for x , then the subsequence that contains all multiples of x is a valid one too.", "Iterate on all possiblex from 1 to 10^5, and check if there is a valid subsequence for x."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countDifferentSubsequenceGCDs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:44+00:00", "tests_total": 101, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "math", "counting", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function countDifferentSubsequenceGCDs($nums) {", "container": "Solution", "callable": "countDifferentSubsequenceGCDs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1822, "task_id": "sign-of-the-product-of-an-array", "difficulty": "Easy", "problem_description": "Implement a function signFunc(x) that returns:\n\n- 1 if x is positive.\n- -1 if x is negative.\n- 0 if x is equal to 0.\n\nYou are given an integer array nums. Let product be the product of all values in the array nums.\n\nReturn signFunc(product).\n\nExample 1:\n\nInput: nums = [-1,-2,-3,-4,3,2,1]\nOutput: 1\nExplanation: The product of all values in the array is 144, and signFunc(144) = 1\n\nExample 2:\n\nInput: nums = [1,5,0,2,-3]\nOutput: 0\nExplanation: The product of all values in the array is 0, and signFunc(0) = 0\n\nExample 3:\n\nInput: nums = [-1,1,-1,1,-1]\nOutput: -1\nExplanation: The product of all values in the array is -1, and signFunc(-1) = -1\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- -100 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1]) == -1\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [0, 0, 0]) == 0\n assert candidate(nums = [-99, -98, -97, -96, -95, -94, -93, -92, -91, -90]) == 1\n assert candidate(nums = [100, -100, 100]) == -1\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [100, -100, 1]) == -1\n assert candidate(nums = [-100, 0, 100]) == 0\n assert candidate(nums = [-1, -2, -3, -4, 3, 2, 1]) == 1\n assert candidate(nums = [100, -100, 100, -100]) == 1\n assert candidate(nums = [-1, -2, -3, -4]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [-1, 1, -1, 1, -1]) == -1\n assert candidate(nums = [1, 5, 0, 2, -3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [-1, -2, -3]) == -1\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1]) == 0\n assert candidate(nums = [100, -50, 25, -10, 5]) == 1\n assert candidate(nums = [100, -50, 25, -12.5, 6.25]) == 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 = [0, 1, -1, 2, -2, 3, -3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 0\n assert candidate(nums = [-1, 1, 0, -1, 1, 0, -1, 1, 0]) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 60, 70, 80, 90]) == 0\n assert candidate(nums = [1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1]) == 0\n assert candidate(nums = [-50, 50, -50, 50, -50, 50, -50, 50, -50, 50]) == -1\n assert candidate(nums = [50, 25, -10, 4, -2, 0.5, 0.2]) == 1\n assert candidate(nums = [-100, 0, 100, -100, 100, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, -6, -7, -8, -9, -10]) == -1\n assert candidate(nums = [-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]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0]) == 0\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == -1\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]) == 0\n assert candidate(nums = [0, 1, 2, 3]) == 0\n assert candidate(nums = [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\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == -1\n assert candidate(nums = [100, -50, 25, -12.5, 0.5]) == 1\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1, 0, -1, 0]) == 0\n assert candidate(nums = [100, -100, 50, -50, 25, -25]) == -1\n assert candidate(nums = [100, -100, 50, -50, 25, -25, 12, -12, 6, -6]) == -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 = [1, 0, -1, 2, 0, -2, 3, 0, -3, 4, 0, -4]) == 0\n assert candidate(nums = [100, -50, 0, 25, -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, -1]) == -1\n assert candidate(nums = [99, 98, 97, -96, -95, -94]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0]) == 0\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [99, -99, 98, -98, 97, -97, 96, -96, 95, -95]) == -1\n assert candidate(nums = [-10, 10, -10, 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\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 1\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == -1\n assert candidate(nums = [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\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == -1\n assert candidate(nums = [-10, -20, -30, -40, -50]) == -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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]) == 0\n assert candidate(nums = [100, -50, 20, -10, 5]) == 1\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, -6, -7, -8, -9, -10]) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == -1\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(nums = [-1, 0, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [100, -100, 100, -100, 100]) == 1\n assert candidate(nums = [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 = [5, -5, 5, -5, 5, -5, 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\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, 0]) == 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]) == 1\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 1\n assert candidate(nums = [-100, 100, -10, 10, -1, 1]) == -1\n", "comparison": "exact"}, "public_tests": ["[-1,-2,-3,-4,3,2,1]", "[1,5,0,2,-3]", "[-1,1,-1,1,-1]"], "hints": ["If there is a 0 in the array the answer is 0", "To avoid overflow make all the negative numbers -1 and all positive numbers 1 and calculate the prod"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().arraySign", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:49+00:00", "tests_total": 96, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "math"]}, "language": "php", "interface": {"raw_signature": "function arraySign($nums) {", "container": "Solution", "callable": "arraySign", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1823, "task_id": "find-the-winner-of-the-circular-game", "difficulty": "Medium", "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. Start at the 1^st friend.\n2. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.\n3. The last friend you counted leaves the circle and loses the game.\n4. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.\n5. Else, the last friend in the circle wins the game.\n\nGiven the number of friends, n, and an integer k, return the winner of the game.\n\nExample 1:\n\nInput: n = 5, k = 2\nOutput: 3\nExplanation: Here are the steps of the game:\n1) Start at friend 1.\n2) Count 2 friends clockwise, which are friends 1 and 2.\n3) Friend 2 leaves the circle. Next start is friend 3.\n4) Count 2 friends clockwise, which are friends 3 and 4.\n5) Friend 4 leaves the circle. Next start is friend 5.\n6) Count 2 friends clockwise, which are friends 5 and 1.\n7) Friend 1 leaves the circle. Next start is friend 3.\n8) Count 2 friends clockwise, which are friends 3 and 5.\n9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.\n\nExample 2:\n\nInput: n = 6, k = 5\nOutput: 1\nExplanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.\n\nConstraints:\n\n- 1 <= k <= n <= 500\n\nFollow up:\n\nCould you solve this problem in linear time with constant space?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,k = 1) == 3\n assert candidate(n = 3,k = 3) == 2\n assert candidate(n = 5,k = 2) == 3\n assert candidate(n = 7,k = 3) == 4\n assert candidate(n = 7,k = 1) == 7\n assert candidate(n = 6,k = 5) == 1\n assert candidate(n = 7,k = 7) == 5\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 4,k = 4) == 2\n assert candidate(n = 10,k = 4) == 5\n assert candidate(n = 10,k = 3) == 4\n assert candidate(n = 250,k = 125) == 173\n assert candidate(n = 300,k = 150) == 152\n assert candidate(n = 250,k = 150) == 76\n assert candidate(n = 200,k = 100) == 189\n assert candidate(n = 150,k = 50) == 138\n assert candidate(n = 300,k = 300) == 265\n assert candidate(n = 450,k = 450) == 87\n assert candidate(n = 123,k = 123) == 94\n assert candidate(n = 499,k = 250) == 134\n assert candidate(n = 300,k = 200) == 139\n assert candidate(n = 100,k = 13) == 70\n assert candidate(n = 500,k = 1) == 500\n assert candidate(n = 37,k = 37) == 16\n assert candidate(n = 500,k = 250) == 384\n assert candidate(n = 20,k = 19) == 11\n assert candidate(n = 200,k = 199) == 163\n assert candidate(n = 100,k = 99) == 88\n assert candidate(n = 30,k = 15) == 4\n assert candidate(n = 50,k = 7) == 1\n assert candidate(n = 30,k = 29) == 25\n assert candidate(n = 50,k = 2) == 37\n assert candidate(n = 250,k = 89) == 225\n assert candidate(n = 250,k = 3) == 41\n assert candidate(n = 50,k = 10) == 36\n assert candidate(n = 100,k = 37) == 45\n assert candidate(n = 40,k = 7) == 24\n assert candidate(n = 45,k = 23) == 36\n assert candidate(n = 45,k = 19) == 14\n assert candidate(n = 100,k = 50) == 95\n assert candidate(n = 123,k = 45) == 116\n assert candidate(n = 45,k = 13) == 36\n assert candidate(n = 500,k = 2) == 489\n assert candidate(n = 499,k = 300) == 36\n assert candidate(n = 200,k = 1) == 200\n assert candidate(n = 300,k = 299) == 145\n assert candidate(n = 400,k = 399) == 30\n assert candidate(n = 125,k = 124) == 31\n assert candidate(n = 150,k = 75) == 125\n assert candidate(n = 20,k = 7) == 3\n assert candidate(n = 350,k = 7) == 211\n assert candidate(n = 150,k = 2) == 45\n assert candidate(n = 123,k = 57) == 77\n assert candidate(n = 150,k = 41) == 79\n assert candidate(n = 200,k = 67) == 163\n assert candidate(n = 499,k = 499) == 122\n assert candidate(n = 500,k = 499) == 121\n assert candidate(n = 500,k = 500) == 69\n assert candidate(n = 400,k = 100) == 313\n assert candidate(n = 499,k = 5) == 327\n assert candidate(n = 200,k = 50) == 23\n assert candidate(n = 20,k = 5) == 7\n assert candidate(n = 250,k = 249) == 204\n assert candidate(n = 40,k = 13) == 14\n assert candidate(n = 50,k = 11) == 10\n assert candidate(n = 450,k = 3) == 286\n assert candidate(n = 450,k = 449) == 143\n assert candidate(n = 50,k = 13) == 5\n assert candidate(n = 15,k = 11) == 12\n assert candidate(n = 37,k = 13) == 14\n assert candidate(n = 15,k = 7) == 5\n assert candidate(n = 30,k = 11) == 28\n assert candidate(n = 300,k = 100) == 59\n assert candidate(n = 40,k = 19) == 6\n assert candidate(n = 120,k = 1) == 120\n assert candidate(n = 299,k = 299) == 146\n assert candidate(n = 50,k = 17) == 8\n assert candidate(n = 150,k = 1) == 150\n assert candidate(n = 250,k = 100) == 23\n assert candidate(n = 45,k = 20) == 29\n assert candidate(n = 373,k = 186) == 14\n assert candidate(n = 499,k = 2) == 487\n assert candidate(n = 50,k = 25) == 5\n", "comparison": "exact"}, "public_tests": ["5\n2", "6\n5"], "hints": ["Simulate the process.", "Maintain in a circular list the people who are still in the circle and the current person you are standing at.", "In each turn, count k people and remove the last person from the list."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().findTheWinner", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:51+00:00", "tests_total": 83, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "recursion", "queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function findTheWinner($n, $k) {", "container": "Solution", "callable": "findTheWinner", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1824, "task_id": "minimum-sideway-jumps", "difficulty": "Medium", "problem_description": "There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.\n\nYou are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.\n\n- For example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.\n\nThe frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.\n\n- For example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.\n\nReturn the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.\n\nNote: There will be no obstacles on points 0 and n.\n\nExample 1:\n\nInput: obstacles = [0,1,2,3,0]\nOutput: 2\nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).\nNote that the frog can jump over obstacles only when making side jumps (as shown at point 2).\n\nExample 2:\n\nInput: obstacles = [0,1,1,3,3,0]\nOutput: 0\nExplanation: There are no obstacles on lane 2. No side jumps are required.\n\nExample 3:\n\nInput: obstacles = [0,2,1,0,3,0]\nOutput: 2\nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps.\n\nConstraints:\n\n- obstacles.length == n + 1\n- 1 <= n <= 5 * 10^5\n- 0 <= obstacles[i] <= 3\n- obstacles[0] == obstacles[n] == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(obstacles = [0, 1, 0, 0, 2, 0, 0, 3, 0, 0]) == 1\n assert candidate(obstacles = [0, 0, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 3, 2, 1, 0, 3, 2, 1, 0]) == 4\n assert candidate(obstacles = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0]) == 1\n assert candidate(obstacles = [0, 1, 3, 2, 3, 1, 0, 0, 0, 0]) == 2\n assert candidate(obstacles = [0, 3, 0, 0, 2, 0, 0, 1, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 0, 0]) == 5\n assert candidate(obstacles = [0, 2, 1, 0, 3, 0]) == 2\n assert candidate(obstacles = [0, 1, 2, 0, 2, 1, 0, 1, 2, 0]) == 1\n assert candidate(obstacles = [0, 2, 0, 0, 0, 3, 0, 0, 1, 0]) == 2\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 0]) == 1\n assert candidate(obstacles = [0, 1, 1, 3, 3, 0]) == 0\n assert candidate(obstacles = [0, 3, 2, 1, 3, 0]) == 3\n assert candidate(obstacles = [0, 0, 1, 2, 3, 0]) == 2\n assert candidate(obstacles = [0, 3, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 2, 0, 2, 0, 2, 0]) == 1\n assert candidate(obstacles = [0, 3, 0, 3, 0, 3, 0]) == 0\n assert candidate(obstacles = [0, 1, 2, 3, 0]) == 2\n assert candidate(obstacles = [0, 1, 0, 0, 2, 0]) == 1\n assert candidate(obstacles = [0, 2, 3, 2, 1, 2, 3, 0]) == 3\n assert candidate(obstacles = [0, 3, 2, 1, 0, 0]) == 2\n assert candidate(obstacles = [0, 1, 2, 0, 3, 0]) == 2\n assert candidate(obstacles = [0, 2, 3, 1, 0, 0]) == 2\n assert candidate(obstacles = [0, 2, 2, 2, 2, 0]) == 1\n assert candidate(obstacles = [0, 3, 2, 1, 3, 2, 1, 0]) == 5\n assert candidate(obstacles = [0, 3, 0, 1, 2, 0, 0, 0, 0, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(obstacles = [0, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 16\n assert candidate(obstacles = [0, 1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 0]) == 11\n assert candidate(obstacles = [0, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 0]) == 12\n assert candidate(obstacles = [0, 3, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]) == 1\n assert candidate(obstacles = [0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0]) == 2\n assert candidate(obstacles = [0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0]) == 10\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 2, 3, 1, 0]) == 8\n assert candidate(obstacles = [0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 3, 3, 3, 3, 0, 1, 1, 1, 1, 0]) == 2\n assert candidate(obstacles = [0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0]) == 2\n assert candidate(obstacles = [0, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 20\n assert candidate(obstacles = [0, 1, 2, 0, 3, 0, 1, 2, 0, 3, 0, 1, 2, 0, 3, 0, 1, 2, 0]) == 7\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0]) == 4\n assert candidate(obstacles = [0, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 0]) == 5\n assert candidate(obstacles = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]) == 10\n assert candidate(obstacles = [0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0]) == 2\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0]) == 3\n assert candidate(obstacles = [0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]) == 1\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 10\n assert candidate(obstacles = [0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0]) == 0\n assert candidate(obstacles = [0, 3, 2, 0, 1, 0, 3, 2, 0, 1, 0, 3, 0]) == 4\n assert candidate(obstacles = [0, 1, 0, 0, 2, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 2, 0]) == 3\n assert candidate(obstacles = [0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0]) == 2\n assert candidate(obstacles = [0, 3, 3, 2, 2, 1, 1, 3, 3, 2, 2, 1, 1, 0]) == 5\n assert candidate(obstacles = [0, 1, 3, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 10\n assert candidate(obstacles = [0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0]) == 10\n assert candidate(obstacles = [0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0]) == 4\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 13\n assert candidate(obstacles = [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0]) == 1\n assert candidate(obstacles = [0, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 0]) == 0\n assert candidate(obstacles = [0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 0]) == 12\n assert candidate(obstacles = [0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0]) == 7\n assert candidate(obstacles = [0, 3, 2, 1, 0, 2, 1, 0, 3, 2, 1, 0, 2, 1, 3, 0]) == 5\n assert candidate(obstacles = [0, 1, 3, 2, 3, 1, 2, 3, 0, 1, 2, 3, 0]) == 6\n assert candidate(obstacles = [0, 2, 0, 3, 0, 2, 0, 3, 0, 2, 0, 3, 0, 2, 0, 3, 0, 2, 0, 3, 0, 2, 0, 3, 0, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0]) == 3\n assert candidate(obstacles = [0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0]) == 1\n assert candidate(obstacles = [0, 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, 0]) == 30\n assert candidate(obstacles = [0, 2, 1, 3, 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, 0]) == 26\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 0]) == 11\n assert candidate(obstacles = [0, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0]) == 1\n assert candidate(obstacles = [0, 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, 0]) == 25\n assert candidate(obstacles = [0, 2, 2, 0, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 0]) == 5\n assert candidate(obstacles = [0, 3, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0]) == 6\n assert candidate(obstacles = [0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 0]) == 7\n assert candidate(obstacles = [0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0]) == 8\n assert candidate(obstacles = [0, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 8\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0]) == 6\n assert candidate(obstacles = [0, 1, 3, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 18\n assert candidate(obstacles = [0, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 0, 3, 3, 3, 3, 3, 0]) == 1\n assert candidate(obstacles = [0, 1, 2, 0, 3, 0, 1, 2, 0, 3, 0, 1, 0]) == 4\n assert candidate(obstacles = [0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0]) == 2\n assert candidate(obstacles = [0, 3, 2, 1, 0, 2, 1, 0, 3, 1, 0, 2, 1, 0, 3, 1, 0, 2, 1, 0]) == 6\n assert candidate(obstacles = [0, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 19\n assert candidate(obstacles = [0, 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, 0]) == 31\n assert candidate(obstacles = [0, 1, 2, 3, 2, 1, 3, 2, 1, 0, 3, 2, 1, 0, 2, 1, 3, 2, 1, 0]) == 11\n assert candidate(obstacles = [0, 1, 2, 3, 2, 1, 2, 3, 2, 1, 0]) == 5\n assert candidate(obstacles = [0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 23\n assert candidate(obstacles = [0, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 0]) == 1\n assert candidate(obstacles = [0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0]) == 3\n assert candidate(obstacles = [0, 3, 2, 1, 2, 3, 1, 2, 3, 1, 0]) == 7\n assert candidate(obstacles = [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0]) == 3\n assert candidate(obstacles = [0, 3, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]) == 1\n assert candidate(obstacles = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]) == 0\n assert candidate(obstacles = [0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0]) == 3\n assert candidate(obstacles = [0, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 0]) == 12\n assert candidate(obstacles = [0, 1, 0, 3, 0, 2, 0, 1, 0, 3, 0, 2, 0, 1, 0]) == 3\n assert candidate(obstacles = [0, 1, 2, 3, 0, 2, 1, 3, 0, 1, 2, 3, 0]) == 6\n assert candidate(obstacles = [0, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 0]) == 11\n assert candidate(obstacles = [0, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 17\n assert candidate(obstacles = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(obstacles = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]) == 0\n assert candidate(obstacles = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0]) == 7\n assert candidate(obstacles = [0, 3, 0, 1, 0, 3, 0, 1, 0, 3, 0, 1, 0, 3, 0]) == 0\n assert candidate(obstacles = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0]) == 3\n assert candidate(obstacles = [0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 2, 1, 0]) == 2\n assert candidate(obstacles = [0, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 17\n assert candidate(obstacles = [0, 1, 3, 1, 2, 3, 1, 2, 3, 1, 0]) == 6\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0]) == 2\n assert candidate(obstacles = [0, 2, 3, 2, 1, 3, 2, 1, 3, 2, 0]) == 7\n assert candidate(obstacles = [0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0, 3, 0, 1, 0, 2, 0]) == 4\n assert candidate(obstacles = [0, 3, 2, 3, 1, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 9\n assert candidate(obstacles = [0, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 0]) == 9\n assert candidate(obstacles = [0, 3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]) == 2\n assert candidate(obstacles = [0, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 0]) == 1\n assert candidate(obstacles = [0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0]) == 1\n assert candidate(obstacles = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 0\n assert candidate(obstacles = [0, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0]) == 11\n assert candidate(obstacles = [0, 1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0]) == 9\n assert candidate(obstacles = [0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0]) == 0\n", "comparison": "exact"}, "public_tests": ["[0,1,2,3,0]", "[0,1,1,3,3,0]", "[0,2,1,0,3,0]"], "hints": ["At a given point, there are only 3 possible states for where the frog can be.", "Check all the ways to move from one point to the next and update the minimum side jumps for each lane."], "metadata": {"canonical_parameter_names": ["obstacles"], "leetcode_dataset_entry_point": "Solution().minSideJumps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:31:54+00:00", "tests_total": 132, "tests_dropped": 11, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minSideJumps($obstacles) {", "container": "Solution", "callable": "minSideJumps", "parameters": [{"name": "obstacles", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1827, "task_id": "minimum-operations-to-make-the-array-increasing", "difficulty": "Easy", "problem_description": "You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.\n\n- For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].\n\nReturn the minimum number of operations needed to make nums strictly increasing.\n\nAn array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.\n\nExample 1:\n\nInput: nums = [1,1,1]\nOutput: 3\nExplanation: You can do the following operations:\n1) Increment nums[2], so nums becomes [1,1,2].\n2) Increment nums[1], so nums becomes [1,2,2].\n3) Increment nums[2], so nums becomes [1,2,3].\n\nExample 2:\n\nInput: nums = [1,5,2,4,1]\nOutput: 14\n\nExample 3:\n\nInput: nums = [8]\nOutput: 0\n\nConstraints:\n\n- 1 <= nums.length <= 5000\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [10000, 1, 1, 1, 1]) == 40006\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 25\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == 109\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 25\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 16\n assert candidate(nums = [8]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 1]) == 3\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000]) == 10\n assert candidate(nums = [10000, 10000, 10000, 10000]) == 6\n assert candidate(nums = [1, 5, 2, 4, 1]) == 14\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 400\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 66\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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]) == 380\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]) == 4095\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 45045\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 380\n assert candidate(nums = [1, 100, 50, 200, 100, 300, 150, 400, 200, 500]) == 504\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\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]) == 0\n assert candidate(nums = [1, 5, 10, 15, 20, 25, 20, 25, 30, 35]) == 8\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 90\n assert candidate(nums = [5, 6, 6, 10, 8, 11, 11, 11]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [100, 200, 300, 200, 100, 200, 300, 400, 500]) == 410\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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, 1, 12, 1, 13, 1, 14, 1, 15]) == 273\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 = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981]) == 380\n assert candidate(nums = [10, 9, 10, 8, 10, 7, 10, 6, 10, 5, 10, 4, 10, 3, 10, 2, 10, 1, 10]) == 216\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]) == 870\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]) == 300\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]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 6215\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]) == 225\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 = [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]) == 1305\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, 21, 20, 22, 21, 23, 22, 24, 23, 25]) == 35\n assert candidate(nums = [10000, 1000, 100, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 189064\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21]) == 18\n assert candidate(nums = [5000, 4999, 4998, 4997, 4996, 4995, 4994, 4993, 4992, 4991, 4990, 4989, 4988, 4987, 4986, 4985, 4984, 4983, 4982, 4981, 4980, 4979, 4978, 4977, 4976, 4975, 4974, 4973, 4972, 4971, 4970]) == 930\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 180\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 11, 10, 12, 11, 13, 12, 14, 13, 15]) == 35\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]) == 375\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]) == 480\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 100\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 25\n assert candidate(nums = [5, 6, 6, 8, 8, 9, 9, 10, 10, 10, 11]) == 18\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 3, 2, 1]) == 930\n assert candidate(nums = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == 55\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 172\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 65\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4]) == 189\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 45\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 36\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 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]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 80\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]) == 486\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990]) == 110\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 24\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 5055\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 45045\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 4000, 3000, 2000, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1]) == 89209\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 280\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 260\n assert candidate(nums = [2, 3, 3, 5, 5, 5, 6, 7, 8, 8, 9, 9, 9]) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11]) == 2\n assert candidate(nums = [1, 2, 10, 11, 10, 12, 11, 13, 12, 14]) == 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, 2]) == 464\n assert candidate(nums = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 50\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7]) == 133\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 212\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 189\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 7, 8, 9, 10]) == 17\n assert candidate(nums = [100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50]) == 690\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 99\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]) == 1128\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 22935\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 4140\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 171\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 14\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 100, 100, 100]) == 7278\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 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]) == 0\n assert candidate(nums = [100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105]) == 360\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 155\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 75\n assert candidate(nums = [1, 1, 10, 10, 100, 100, 1000, 1000, 10000, 10000]) == 5\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6]) == 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]) == 280\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 100\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 45\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == 40\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]) == 496\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 100\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, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 1325\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 99\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 180\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 190\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 495\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 105\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 252\n", "comparison": "exact"}, "public_tests": ["[1,1,1]", "[1,5,2,4,1]", "[8]"], "hints": ["nums[i+1] must be at least equal to nums[i] + 1.", "Think greedily. You don't have to increase nums[i+1] beyond nums[i]+1.", "Iterate on i and set nums[i] = max(nums[i-1]+1, nums[i]) ."], "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:31:58+00:00", "tests_total": 118, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minOperations($nums) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1828, "task_id": "queries-on-number-of-points-inside-a-circle", "difficulty": "Medium", "problem_description": "You are given an array points where points[i] = [x_i, y_i] is the coordinates of the i^th point on a 2D plane. Multiple points can have the same coordinates.\n\nYou are also given an array queries where queries[j] = [x_j, y_j, r_j] describes a circle centered at (x_j, y_j) with a radius of r_j.\n\nFor each query queries[j], compute the number of points inside the j^th circle. Points on the border of the circle are considered inside.\n\nReturn an array answer, where answer[j] is the answer to the j^th query.\n\nExample 1:\n\nInput: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\nOutput: [3,2,2]\nExplanation: The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n\nExample 2:\n\nInput: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\nOutput: [2,3,2,4]\nExplanation: The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n\nConstraints:\n\n- 1 <= points.length <= 500\n- points[i].length == 2\n- 0 <= x_i, y_i <= 500\n- 1 <= queries.length <= 500\n- queries[j].length == 3\n- 0 <= x_j, y_j <= 500\n- 1 <= r_j <= 500\n- All coordinates are integers.\n\nFollow up: Could you find the answer for each query in better complexity than O(n)?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[1, 2, 2], [2, 2, 2], [4, 3, 2], [4, 3, 3]]) == [2, 3, 2, 4]\n assert candidate(points = [[1, 3], [3, 3], [5, 3], [2, 2]],queries = [[2, 3, 1], [4, 3, 1], [1, 1, 2]]) == [3, 2, 2]\n assert candidate(points = [[50, 50], [50, 150], [50, 250], [150, 50], [150, 150], [150, 250], [250, 50], [250, 150], [250, 250], [50, 100], [100, 100], [150, 100], [200, 100], [250, 100], [100, 150], [150, 150], [200, 150], [250, 150], [100, 200], [150, 200], [200, 200], [250, 200]],queries = [[100, 100, 50], [150, 150, 75], [200, 200, 100]]) == [4, 10, 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]],queries = [[5, 5, 5], [2, 2, 3], [7, 7, 2], [0, 0, 10]]) == [7, 5, 3, 8]\n assert candidate(points = [[250, 250], [260, 260], [270, 270], [280, 280], [290, 290]],queries = [[250, 250, 10], [250, 250, 20], [250, 250, 30], [250, 250, 40], [250, 250, 50]]) == [1, 2, 3, 3, 4]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[100, 100, 150], [200, 200, 150], [300, 300, 150], [400, 400, 150], [500, 500, 150]]) == [2, 3, 3, 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], [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]],queries = [[1, 1, 2], [10, 10, 5], [20, 20, 8], [15, 15, 10]]) == [2, 7, 11, 15]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[150, 150, 100], [350, 350, 150], [250, 250, 200], [450, 450, 250]]) == [2, 2, 2, 3]\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],queries = [[25, 25, 10], [15, 15, 5], [35, 35, 20]]) == [2, 0, 2]\n assert candidate(points = [[10, 10], [10, 20], [10, 30], [10, 40], [10, 50], [20, 10], [20, 20], [20, 30], [20, 40], [20, 50], [30, 10], [30, 20], [30, 30], [30, 40], [30, 50]],queries = [[15, 15, 5], [15, 25, 5], [15, 35, 5], [15, 45, 5], [15, 55, 5], [25, 15, 5], [25, 25, 5], [25, 35, 5], [25, 45, 5], [25, 55, 5], [35, 15, 5], [35, 25, 5], [35, 35, 5], [35, 45, 5], [35, 55, 5]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(points = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450], [50, 450], [450, 50]],queries = [[100, 100, 50], [200, 200, 50], [300, 300, 50], [400, 400, 50], [50, 50, 100], [450, 450, 100]]) == [0, 0, 0, 0, 1, 1]\n assert candidate(points = [[250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500], [550, 550], [600, 600], [650, 650], [700, 700], [750, 750], [800, 800], [850, 850], [900, 900], [950, 950]],queries = [[500, 500, 100], [600, 600, 150], [750, 750, 200], [850, 850, 250]]) == [3, 5, 5, 6]\n assert candidate(points = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [150, 250], [250, 350]],queries = [[200, 300, 50], [300, 400, 100], [400, 500, 150], [500, 600, 200]]) == [1, 2, 3, 2]\n assert candidate(points = [[0, 0], [500, 500], [250, 250], [100, 100], [400, 400]],queries = [[250, 250, 200], [100, 100, 100], [400, 400, 150]]) == [1, 1, 2]\n assert candidate(points = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100], [110, 120]],queries = [[50, 50, 25], [70, 70, 30], [10, 10, 15], [90, 90, 20]]) == [2, 2, 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], [14, 14], [15, 15]],queries = [[3, 3, 5], [6, 6, 10], [9, 9, 15]]) == [6, 13, 15]\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],queries = [[5, 5, 15], [15, 15, 25], [25, 25, 35], [35, 35, 45], [45, 45, 55]]) == [1, 3, 4, 5, 5]\n assert candidate(points = [[25, 25], [26, 26], [27, 27], [28, 28], [29, 29]],queries = [[10, 10, 20], [20, 20, 20], [30, 30, 20], [40, 40, 20], [50, 50, 20]]) == [0, 5, 5, 4, 0]\n assert candidate(points = [[50, 100], [100, 150], [150, 200], [200, 250], [250, 300]],queries = [[75, 125, 50], [125, 175, 50], [175, 225, 50], [225, 275, 50], [275, 325, 50]]) == [2, 2, 2, 2, 1]\n assert candidate(points = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450]],queries = [[100, 100, 50], [100, 100, 100], [100, 100, 150], [100, 100, 200], [100, 100, 250]]) == [0, 2, 2, 2, 3]\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [[15, 15, 10], [25, 25, 15], [35, 35, 20], [45, 45, 25], [55, 55, 30]]) == [2, 2, 2, 4, 4]\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],queries = [[5, 5, 5], [10, 10, 10], [15, 15, 15], [20, 20, 20], [25, 25, 25], [30, 30, 30], [35, 35, 35], [40, 40, 40], [45, 45, 45], [50, 50, 50]]) == [4, 7, 8, 7, 7, 6, 5, 4, 4, 3]\n assert candidate(points = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [[15, 15, 10], [25, 25, 15], [35, 35, 20], [45, 45, 25], [55, 55, 30], [65, 65, 35], [75, 75, 40], [85, 85, 45], [95, 95, 50], [105, 105, 55]]) == [2, 2, 2, 4, 4, 4, 6, 5, 5, 4]\n assert candidate(points = [[400, 400], [450, 450], [500, 500], [550, 550], [600, 600]],queries = [[400, 400, 100], [450, 450, 150], [500, 500, 200], [550, 550, 250], [600, 600, 300]]) == [2, 4, 5, 5, 5]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250]],queries = [[50, 50, 50], [100, 100, 50], [150, 150, 50], [200, 200, 50], [250, 250, 50]]) == [1, 1, 1, 1, 1]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [50, 50], [150, 150], [250, 250], [350, 350], [450, 450]],queries = [[250, 250, 100], [150, 150, 50], [450, 450, 150], [50, 50, 200]]) == [3, 1, 4, 3]\n assert candidate(points = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]],queries = [[10, 10, 10], [20, 20, 15], [30, 30, 20], [40, 40, 25], [50, 50, 30], [60, 60, 35], [70, 70, 40], [80, 80, 45], [90, 90, 50], [100, 100, 55]]) == [2, 2, 2, 4, 4, 4, 6, 5, 5, 4]\n assert candidate(points = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450], [100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[200, 200, 100], [100, 100, 50], [300, 300, 150], [400, 400, 200], [500, 500, 250]]) == [3, 1, 5, 5, 4]\n assert candidate(points = [[0, 0], [500, 0], [0, 500], [500, 500], [250, 250], [125, 125], [375, 125], [125, 375], [375, 375]],queries = [[250, 250, 200], [0, 0, 150], [500, 500, 150], [125, 125, 50], [375, 375, 50], [250, 0, 100], [250, 500, 100]]) == [5, 1, 1, 1, 1, 0, 0]\n assert candidate(points = [[10, 10], [10, 30], [10, 50], [10, 70], [10, 90], [30, 10], [30, 30], [30, 50], [30, 70], [30, 90], [50, 10], [50, 30], [50, 50], [50, 70], [50, 90]],queries = [[20, 20, 20], [40, 40, 20], [60, 60, 20], [20, 60, 20], [60, 20, 20]]) == [4, 4, 2, 4, 2]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500]],queries = [[250, 250, 100], [300, 300, 150], [350, 350, 200], [400, 400, 250], [450, 450, 300]]) == [3, 5, 5, 6, 6]\n assert candidate(points = [[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]],queries = [[50, 50, 40], [100, 100, 50], [150, 150, 60], [20, 20, 30], [130, 130, 70]]) == [5, 7, 5, 4, 7]\n assert candidate(points = [[100, 100], [150, 100], [200, 100], [250, 100], [300, 100], [100, 150], [150, 150], [200, 150], [250, 150], [300, 150]],queries = [[150, 100, 50], [200, 150, 75], [100, 100, 100]]) == [4, 6, 5]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [100, 200], [200, 300], [300, 400], [400, 500], [500, 100]],queries = [[150, 150, 50], [250, 250, 75], [350, 350, 100], [450, 450, 125], [550, 550, 150], [150, 250, 60], [250, 350, 85], [350, 450, 110], [450, 550, 135], [550, 150, 160]]) == [0, 3, 3, 3, 1, 0, 3, 3, 2, 1]\n assert candidate(points = [[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], [170, 170], [180, 180], [190, 190], [200, 200]],queries = [[100, 100, 50], [150, 150, 60], [200, 200, 70], [125, 125, 80]]) == [7, 9, 5, 12]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500], [50, 100], [100, 150], [150, 200], [200, 250], [250, 300], [300, 350], [350, 400], [400, 450], [450, 500], [500, 550]],queries = [[75, 75, 25], [125, 125, 50], [175, 175, 75], [225, 225, 100], [275, 275, 125], [325, 325, 150], [375, 375, 175], [425, 425, 200], [475, 475, 225], [525, 525, 250]]) == [0, 3, 3, 5, 7, 9, 9, 10, 9, 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]],queries = [[5, 5, 5], [2, 2, 3], [8, 8, 4]]) == [7, 4, 5]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [50, 50], [150, 150], [250, 250], [350, 350], [450, 450]],queries = [[100, 100, 50], [300, 300, 100], [400, 400, 150], [200, 200, 200], [50, 50, 25]]) == [1, 3, 5, 5, 1]\n assert candidate(points = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110]],queries = [[15, 25, 5], [25, 35, 10], [35, 45, 15], [45, 55, 20], [55, 65, 25], [65, 75, 30], [75, 85, 35], [85, 95, 40], [95, 105, 45], [105, 115, 50]]) == [0, 2, 2, 2, 4, 4, 4, 5, 4, 4]\n assert candidate(points = [[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]],queries = [[75, 75, 25], [50, 50, 30], [125, 125, 40], [100, 100, 50]]) == [4, 5, 6, 7]\n assert candidate(points = [[250, 250], [260, 260], [270, 270], [280, 280], [290, 290], [300, 300], [310, 310], [320, 320], [330, 330], [340, 340]],queries = [[270, 270, 20], [300, 300, 40], [320, 320, 60]]) == [3, 5, 7]\n assert candidate(points = [[25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31], [32, 32], [33, 33], [34, 34]],queries = [[25, 25, 10], [25, 25, 20], [25, 25, 30], [25, 25, 40], [25, 25, 50], [25, 25, 60], [25, 25, 70], [25, 25, 80], [25, 25, 90], [25, 25, 100]]) == [8, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500]],queries = [[25, 25, 30], [75, 75, 40], [125, 125, 50], [175, 175, 60], [225, 225, 70], [275, 275, 80], [325, 325, 90], [375, 375, 100], [425, 425, 110], [475, 475, 120]]) == [0, 2, 2, 2, 2, 2, 2, 2, 4, 3]\n assert candidate(points = [[10, 10], [10, 20], [20, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80]],queries = [[15, 15, 10], [50, 50, 30], [75, 75, 15], [45, 45, 25]]) == [4, 5, 2, 4]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500]],queries = [[250, 250, 100], [50, 50, 50], [450, 450, 150], [300, 300, 200]]) == [3, 1, 4, 5]\n assert candidate(points = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500]],queries = [[250, 250, 100], [100, 100, 50], [300, 300, 150], [400, 400, 200]]) == [3, 1, 5, 5]\n assert candidate(points = [[0, 0], [500, 500], [250, 250], [100, 400], [400, 100], [200, 300], [300, 200], [150, 350], [350, 150], [50, 450]],queries = [[250, 250, 200], [100, 100, 50], [400, 400, 150], [200, 200, 100]]) == [5, 0, 1, 3]\n assert candidate(points = [[50, 50], [100, 50], [150, 50], [200, 50], [250, 50], [300, 50], [350, 50], [400, 50], [450, 50], [500, 50]],queries = [[75, 50, 25], [125, 50, 25], [175, 50, 25], [225, 50, 25], [275, 50, 25], [325, 50, 25], [375, 50, 25], [425, 50, 25], [475, 50, 25]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(points = [[100, 100], [100, 200], [100, 300], [100, 400], [100, 500]],queries = [[100, 100, 50], [100, 200, 50], [100, 300, 50], [100, 400, 50], [100, 500, 50]]) == [1, 1, 1, 1, 1]\n assert candidate(points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[250, 250, 150], [150, 150, 50], [350, 350, 100]]) == [2, 0, 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], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19]],queries = [[5, 5, 5], [10, 10, 10], [15, 15, 15]]) == [7, 15, 15]\n", "comparison": "exact"}, "public_tests": ["[[1,3],[3,3],[5,3],[2,2]]\n[[2,3,1],[4,3,1],[1,1,2]]", "[[1,1],[2,2],[3,3],[4,4],[5,5]]\n[[1,2,2],[2,2,2],[4,3,2],[4,3,3]]"], "hints": ["For a point to be inside a circle, the euclidean distance between it and the circle's center needs to be less than or equal to the radius.", "Brute force for each circle and iterate overall points and find those inside it."], "metadata": {"canonical_parameter_names": ["points", "queries"], "leetcode_dataset_entry_point": "Solution().countPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:00+00:00", "tests_total": 51, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "math", "geometry"]}, "language": "php", "interface": {"raw_signature": "function countPoints($points, $queries) {", "container": "Solution", "callable": "countPoints", "parameters": [{"name": "points", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1829, "task_id": "maximum-xor-for-each-query", "difficulty": "Medium", "problem_description": "You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:\n\n1. Find a non-negative integer k < 2^maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the i^th query.\n2. Remove the last element from the current array nums.\n\nReturn an array answer, where answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: nums = [0,1,1,3], maximumBit = 2\nOutput: [0,3,2,3]\nExplanation: The queries are answered as follows:\n1^st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2^nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3^rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4^th query: nums = [0], k = 3 since 0 XOR 3 = 3.\n\nExample 2:\n\nInput: nums = [2,3,4,7], maximumBit = 3\nOutput: [5,2,6,5]\nExplanation: The queries are answered as follows:\n1^st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2^nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3^rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4^th query: nums = [2], k = 5 since 2 XOR 5 = 7.\n\nExample 3:\n\nInput: nums = [0,1,2,2,5,7], maximumBit = 3\nOutput: [4,3,6,4,6,7]\n\nConstraints:\n\n- nums.length == n\n- 1 <= n <= 10^5\n- 1 <= maximumBit <= 20\n- 0 <= nums[i] < 2^maximumBit\n- nums is sorted in ascending order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 4, 7],maximumBit = 3) == [5, 2, 6, 5]\n assert candidate(nums = [0, 1, 1, 3],maximumBit = 2) == [0, 3, 2, 3]\n assert candidate(nums = [1, 2, 4, 8, 16],maximumBit = 5) == [0, 16, 24, 28, 30]\n assert candidate(nums = [31, 31, 31, 31, 31],maximumBit = 5) == [0, 31, 0, 31, 0]\n assert candidate(nums = [0, 1, 2, 2, 5, 7],maximumBit = 3) == [4, 3, 6, 4, 6, 7]\n assert candidate(nums = [1, 1, 1, 1, 1],maximumBit = 1) == [0, 1, 0, 1, 0]\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, 85, 89, 93, 97, 101, 105, 109, 113, 117],maximumBit = 7) == [123, 14, 127, 18, 123, 30, 127, 34, 123, 46, 127, 50, 123, 62, 127, 66, 123, 78, 127, 82, 123, 94, 127, 98, 123, 110, 127, 114, 123, 126]\n assert candidate(nums = [1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575, 1048575],maximumBit = 20) == [1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0, 1048575, 0]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],maximumBit = 4) == [14, 7, 15, 8, 14, 11, 15, 12, 14, 15]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946],maximumBit = 14) == [5056, 14594, 9071, 13114, 14626, 16159, 15556, 16038, 16351, 16182, 16294, 16383, 16328, 16362, 16383, 16370, 16378, 16383, 16380, 16382]\n assert candidate(nums = [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],maximumBit = 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]\n assert candidate(nums = [0, 2, 6, 14, 30, 62, 126, 254, 510, 1022],maximumBit = 10) == [341, 683, 853, 939, 981, 1003, 1013, 1019, 1021, 1023]\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],maximumBit = 15) == [10922, 21845, 27306, 30037, 31402, 32085, 32426, 32597, 32682, 32725, 32746, 32757, 32762, 32765, 32766]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],maximumBit = 5) == [31, 0, 29, 6, 31, 8, 29, 14, 31, 16, 29, 22, 31, 24, 29, 30]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],maximumBit = 4) == [15, 15, 14, 12, 15, 11, 14, 8, 15, 7, 14, 4, 15, 3, 14, 0]\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50],maximumBit = 6) == [29, 47, 0, 44, 5, 35, 0, 32, 61, 39, 48, 36, 53, 59, 48, 56, 61]\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049],maximumBit = 16) == [18165, 41052, 60607, 62750, 64917, 65356, 65471, 65518, 65525, 65532]\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],maximumBit = 10) == [1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],maximumBit = 5) == [29, 14, 31, 16, 29, 22, 31, 24, 29, 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, 31],maximumBit = 5) == [31, 0, 30, 3, 31, 4, 30, 7, 31, 8, 30, 11, 31, 12, 30, 15, 31, 16, 30, 19, 31, 20, 30, 23, 31, 24, 30, 27, 31, 28, 30]\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],maximumBit = 6) == [61, 6, 63, 8, 61, 14, 63, 16, 61, 22, 63, 24, 61, 30, 63, 32, 61, 38, 63, 40, 61, 46, 63, 48, 61, 54, 63, 56, 61, 62]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],maximumBit = 20) == [0, 524288, 786432, 917504, 983040, 1015808, 1032192, 1040384, 1044480, 1046528, 1047552, 1048064, 1048320, 1048448, 1048512, 1048544, 1048560, 1048568, 1048572, 1048574]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],maximumBit = 5) == [11, 10, 8, 11, 15, 10, 12, 11, 3, 10, 0, 11, 7, 10, 4, 11, 27, 10, 24, 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],maximumBit = 3) == [7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2]\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38],maximumBit = 6) == [63, 25, 61, 31, 63, 33, 61, 39, 63, 41, 61, 47, 63, 49, 61, 55, 63, 57, 61, 63]\n assert candidate(nums = [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],maximumBit = 6) == [61, 7, 63, 9, 61, 15, 63, 17, 61, 23, 63, 25, 61, 31, 63, 33, 61, 39, 63, 41, 61, 47, 63, 49, 61, 55, 63, 57, 61, 63]\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400],maximumBit = 9) == [99, 499, 154, 478, 255, 511, 286, 474, 371, 483, 410, 510, 431, 495, 478, 506, 483, 499, 506, 510]\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576],maximumBit = 15) == [16382, 24574, 28670, 30718, 31742, 32254, 32510, 32638, 32702, 32734, 32750, 32758, 32762, 32764]\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765],maximumBit = 13) == [6403, 878, 4923, 6435, 7966, 7365, 7847, 8158, 7991, 8103, 8190, 8137, 8171, 8190, 8179, 8187, 8190, 8189, 8191, 8190]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],maximumBit = 11) == [0, 1024, 1536, 1792, 1920, 1984, 2016, 2032, 2040, 2044, 2046]\n assert candidate(nums = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015],maximumBit = 10) == [8, 1023, 7, 1022, 4, 1023, 3, 1022, 0]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],maximumBit = 4) == [15, 0, 14, 3, 15, 4, 14, 7, 15, 8, 14, 11, 15, 12, 14, 15]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],maximumBit = 7) == [63, 116, 50, 115, 79, 120, 74, 103, 79, 108, 114, 107, 127, 112, 122]\n assert candidate(nums = [12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288],maximumBit = 14) == [8187, 12283, 14331, 15355, 15867, 16123, 16251, 16315, 16347, 16363, 16371]\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],maximumBit = 6) == [1, 61, 7, 63, 9, 61, 15, 63, 17, 61, 23, 63, 25, 61, 31, 63, 33, 61, 39, 63, 41, 61, 47, 63, 49, 61, 55, 63, 57, 61]\n assert candidate(nums = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],maximumBit = 1) == [1, 0, 1, 0, 1, 0, 1, 0, 1, 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],maximumBit = 1) == [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35],maximumBit = 6) == [15, 44, 50, 43, 63, 48, 58]\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095],maximumBit = 13) == [5461, 6826, 7509, 7850, 8021, 8106, 8149, 8170, 8181, 8186, 8189, 8190]\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64],maximumBit = 7) == [63, 127, 71, 119, 95, 127, 103, 119]\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],maximumBit = 10) == [341, 682, 853, 938, 981, 1002, 1013, 1018, 1021, 1022]\n assert candidate(nums = [0, 2, 3, 5, 6, 8, 10, 12],maximumBit = 4) == [3, 15, 5, 13, 11, 14, 13, 15]\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18],maximumBit = 5) == [31, 13, 30, 14, 31, 17, 30, 18, 31, 21, 30, 22, 31, 25, 30, 26, 31, 29, 30, 30]\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127],maximumBit = 7) == [42, 85, 106, 117, 122, 125, 126]\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310],maximumBit = 10) == [990, 744, 1023, 775, 990, 868, 1023, 899, 990, 992]\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],maximumBit = 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, 1, 0, 0, 1]\n assert candidate(nums = [7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95],maximumBit = 7) == [127, 32, 119, 56, 127, 64, 119, 88, 127, 96, 119, 120]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],maximumBit = 8) == [183, 127, 193, 117, 223, 127, 233, 101, 231, 159, 241, 149, 207, 159, 217, 229, 215, 255, 225, 245]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],maximumBit = 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],maximumBit = 10) == [0, 512, 768, 896, 960, 992, 1008, 1016, 1020, 1022]\n assert candidate(nums = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287],maximumBit = 20) == [699050, 873813, 961194, 1004885, 1026730, 1037653, 1043114, 1045845, 1047210, 1047893, 1048234, 1048405, 1048490, 1048533, 1048554, 1048565, 1048570, 1048573, 1048574, 1048575]\n assert candidate(nums = [0, 1, 3, 7, 15, 31, 63],maximumBit = 6) == [21, 42, 53, 58, 61, 62, 63]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],maximumBit = 4) == [15, 0, 14, 3, 15, 4, 14, 7, 15, 8, 14, 11, 15, 12, 14, 15]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],maximumBit = 20) == [0, 524288, 786432, 917504, 983040, 1015808, 1032192, 1040384, 1044480, 1046528, 1047552, 1048064, 1048320, 1048448, 1048512, 1048544, 1048560, 1048568, 1048572, 1048574]\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],maximumBit = 6) == [14, 63, 16, 61, 22, 63, 24, 61, 30, 63, 32, 61, 38, 63, 40, 61, 46, 63, 48, 61, 54, 63, 56, 61, 62]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],maximumBit = 2) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],maximumBit = 10) == [1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],maximumBit = 7) == [113, 21, 79, 31, 89, 101, 87, 127, 97, 117]\n assert candidate(nums = [1, 3, 4, 7, 10, 12, 15, 19, 22],maximumBit = 5) == [18, 4, 23, 24, 20, 30, 25, 29, 30]\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],maximumBit = 10) == [1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0, 1023, 0]\n assert candidate(nums = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120],maximumBit = 13) == [2041, 5113, 6649, 7417, 7801, 7993, 8089, 8137, 8161, 8181]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],maximumBit = 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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],maximumBit = 5) == [11, 31, 12, 30, 15, 31, 16, 30, 19, 31, 20, 30, 23, 31, 24, 30, 27, 31, 28, 30]\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],maximumBit = 7) == [26, 126, 47, 111, 94, 122, 99, 115, 122, 126]\n assert candidate(nums = [0, 1, 3, 7, 15, 31, 63, 127],maximumBit = 7) == [42, 85, 106, 117, 122, 125, 126, 127]\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],maximumBit = 3) == [7, 4, 7, 4, 7, 4, 6, 4, 6, 4, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7]\n assert candidate(nums = [127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117],maximumBit = 7) == [11, 126, 8, 127, 7, 126, 4, 127, 3, 126, 0]\n assert candidate(nums = [5, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383],maximumBit = 14) == [5458, 10925, 13650, 15021, 15698, 16045, 16210, 16301, 16338, 16365, 16370, 16381, 16378]\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],maximumBit = 20) == [349525, 349524, 349527, 349520, 349535, 349504, 349567, 349440, 349695, 349184, 350207, 348160, 352255, 344064, 360447, 327680, 393215, 262144, 524287, 0]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],maximumBit = 10) == [0, 512, 768, 896, 960, 992, 1008, 1016, 1020, 1022]\n assert candidate(nums = [8, 10, 12, 14, 16, 18, 20, 22],maximumBit = 5) == [31, 9, 29, 15, 31, 17, 29, 23]\n assert candidate(nums = [2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575],maximumBit = 20) == [350207, 698368, 874495, 960512, 1005567, 1026048, 1038335, 1042432, 1046527, 1046528]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],maximumBit = 6) == [63, 3, 58, 12, 63, 15, 34, 8, 47, 11, 42, 52, 47, 55, 34, 48, 63, 51, 58, 60]\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],maximumBit = 8) == [255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0]\n assert candidate(nums = [0, 2, 3, 5, 8, 13, 21, 34, 55, 89],maximumBit = 7) == [39, 126, 73, 107, 126, 115, 123, 126, 125, 127]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],maximumBit = 6) == [63, 24, 61, 30, 63, 32, 61, 38, 63, 40, 61, 46, 63, 48, 61, 54, 63, 56, 61, 62]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1023],maximumBit = 10) == [1023, 0, 512, 768, 896, 960, 992, 1008, 1016, 1020, 1022]\n assert candidate(nums = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512],maximumBit = 10) == [0, 512, 768, 896, 960, 992, 1008, 1016, 1020, 1022, 1023]\n", "comparison": "exact"}, "public_tests": ["[0,1,1,3]\n2", "[2,3,4,7]\n3", "[0,1,2,2,5,7]\n3"], "hints": ["Note that the maximum possible XOR result is always 2^(maximumBit) - 1", "So the answer for a prefix is the XOR of that prefix XORed with 2^(maximumBit)-1"], "metadata": {"canonical_parameter_names": ["nums", "maximumBit"], "leetcode_dataset_entry_point": "Solution().getMaximumXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:03+00:00", "tests_total": 81, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "bit-manipulation", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function getMaximumXor($nums, $maximumBit) {", "container": "Solution", "callable": "getMaximumXor", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "maximumBit", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1832, "task_id": "check-if-the-sentence-is-pangram", "difficulty": "Easy", "problem_description": "A pangram is a sentence where every letter of the English alphabet appears at least once.\n\nGiven a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.\n\nExample 1:\n\nInput: sentence = \"thequickbrownfoxjumpsoverthelazydog\"\nOutput: true\nExplanation: sentence contains at least one of every letter of the English alphabet.\n\nExample 2:\n\nInput: sentence = \"leetcode\"\nOutput: false\n\nConstraints:\n\n- 1 <= sentence.length <= 1000\n- sentence consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentence = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(sentence = \"quickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"aaaaabbbbbccccc\") == False\n assert candidate(sentence = \"a\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogandmorelettersjusttoextendthelengthofthesentenceevenmorejustformeasurements\") == True\n assert candidate(sentence = \"hellothere\") == False\n assert candidate(sentence = \"hello\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazy\") == False\n assert candidate(sentence = \"abcdefghijjklmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzzzzz\") == True\n assert candidate(sentence = \"leetcode\") == False\n assert candidate(sentence = \"thisisaverylongsentencebutnotapangram\") == False\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzabc\") == True\n assert candidate(sentence = \"mississippi\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelaz\") == False\n assert candidate(sentence = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(sentence = \"abcdefghijlkmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogandthenomeofthezebra\") == True\n assert candidate(sentence = \"aquickmovementsoftheenemywilljeopardizethesecurityofthefort\") == False\n assert candidate(sentence = \"neverjumpoveraslydogquicklyasmyfastcat\") == False\n assert candidate(sentence = \"jumpedoverthelazybrownfoxquickly\") == False\n assert candidate(sentence = \"thisisaverylongsentencethatwantsyoumakesurethatispangram\") == False\n assert candidate(sentence = \"everygoodboydoesfine\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthefly\") == False\n assert candidate(sentence = \"thefoxjumpedoveralazydogandquicklymunchedberries\") == False\n assert candidate(sentence = \"aquickmovofjumpsbxngthevlackdwarf\") == False\n assert candidate(sentence = \"abcdefghijklnopqrstuvwxyz\") == False\n assert candidate(sentence = \"sphinxofblackquartzjudgemyvowels\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydozzzzzzzzzz\") == False\n assert candidate(sentence = \"aabbbcccdddeeefffggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == True\n assert candidate(sentence = \"thisisaverylongsentencethatshouldcontainalllettersquickly\") == False\n assert candidate(sentence = \"thebrownfoxjumpsovertheleazydog\") == False\n assert candidate(sentence = \"phinxofquizzingjudgesbringsmywonder\") == False\n assert candidate(sentence = \"packmyboxwithfivedozenliquorjugsquicklyandjudgeeachvowel\") == True\n assert candidate(sentence = \"vowelsaeiouyzqjfdxhcntrbplsmkgw\") == True\n assert candidate(sentence = \"jumpsquickonthisbrownfox\") == False\n assert candidate(sentence = \"fivexwiseguysjumpquicklyonthiszanyboat\") == False\n assert candidate(sentence = \"aquickmovewiththiszestyjuicebringsvexflation\") == False\n assert candidate(sentence = \"quickbrownfoxjumpsoverthelazydogquickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"pythonprogramminglanguage\") == False\n assert candidate(sentence = \"xylophonesarefunbutquickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogy\") == True\n assert candidate(sentence = \"qwertypoiuytrewqasdfghjklzxcvbnmasdfghjklzxcvbnmqwertyuiopcvbnm\") == True\n assert candidate(sentence = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"thesixfatfingersjumpquicklyonthisverylazydog\") == False\n assert candidate(sentence = \"jumpsfoxoverthelazydogquickb\") == False\n assert candidate(sentence = \"sixjovialfellowshavequicklyzippedanddrunkmanybeers\") == False\n assert candidate(sentence = \"abacaxypromiseyouanelephantwhoxylophones\") == False\n assert candidate(sentence = \"jumpedoverthelazydogthequickbrownfox\") == False\n assert candidate(sentence = \"sphinxofblackquartzjudgemyvexzwift\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpedoverthelazydogquickly\") == False\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxy\") == False\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzz\") == True\n assert candidate(sentence = \"foxjumpsoverthelazydogquickbrown\") == True\n assert candidate(sentence = \"thisquestionaboutpangramsissomewhatredundant\") == False\n assert candidate(sentence = \"aquickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"jumpedoverthelazydogquickbrownfox\") == False\n assert candidate(sentence = \"aquickmovingtonafleetofsixgreyhounds\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogg\") == True\n assert candidate(sentence = \"howvexinglyquickdaftzebrasjump\") == True\n assert candidate(sentence = \"quickbrownfoxjumpsoverthelazydogzzzzzzzzzz\") == True\n assert candidate(sentence = \"aquickmovementsofthejaguarzephyr\") == False\n assert candidate(sentence = \"quicklyjudginghowvexingzebraflowscanbeverytricky\") == False\n assert candidate(sentence = \"aquickbrownfoxjumpsoverthelazydogandbackagain\") == True\n assert candidate(sentence = \"abcdefghijklnopqrstuvwxyzabcdefghijklnopqrstuvwxyz\") == False\n assert candidate(sentence = \"jellyoftheplumlovesmeandthemonkeyrinsesupwithgrapejuicequickly\") == False\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(sentence = \"thebrownfoxjumpedoveralazylazydog\") == False\n assert candidate(sentence = \"packmyboxwithfivedozenliquorjugs\") == True\n assert candidate(sentence = \"foxjumpsoverthelazydogquickbrownzzzzzzzzzz\") == True\n assert candidate(sentence = \"althoughsomehumansareabsolutelyastonishing\") == False\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"jovialwaltzsexemplifiesquickbymyflyfriend\") == False\n assert candidate(sentence = \"aquickbrownfoxjumpsoverthelazydogs\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydo\") == False\n assert candidate(sentence = \"abcdefghjklmnopqrstuvwxyz\") == False\n assert candidate(sentence = \"veryfewlazydogslikejumpingoverthebigbrownfox\") == False\n assert candidate(sentence = \"therearemanysmallpacksofdifferentbooksinthelibrary\") == False\n assert candidate(sentence = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(sentence = \"jimquicklyzippedvexedfowlsbymyplushog\") == False\n assert candidate(sentence = \"quickbrownfoxjumpsoverthelazydogs\") == True\n assert candidate(sentence = \"abcdefghijkllllmnopqrstuvwxyz\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogandmore\") == True\n assert candidate(sentence = \"everygoodboydoesfinejustkickslovingmonkeysnearpianoquicksly\") == False\n assert candidate(sentence = \"pqrsghijklmnabcdefwxyzotuvcd\") == True\n assert candidate(sentence = \"pangramsarefunnywordsusedinyogamatclasses\") == False\n assert candidate(sentence = \"thequickbrownfoxjumpedoverthelazydogandthenranoff\") == False\n assert candidate(sentence = \"fourxsixtwoseveneleveneightfivenineninetwozero\") == False\n assert candidate(sentence = \"abracadabracabracadabra\") == False\n assert candidate(sentence = \"mjklqrswxzytfpuhncideaoxbgvlozmt\") == True\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydogandcat\") == True\n assert candidate(sentence = \"thisisaverylongstringsentencethatwillnotbepangram\") == False\n assert candidate(sentence = \"quovadis\") == False\n assert candidate(sentence = \"thisisaverylongsentencethatjustmightcontainallthelettersofthealphabet\") == False\n assert candidate(sentence = \"everygoodboydoesfineandzestfullyjumpoverlazysnails\") == False\n", "comparison": "exact"}, "public_tests": ["\"thequickbrownfoxjumpsoverthelazydog\"", "\"leetcode\""], "hints": ["Iterate over the string and mark each character as found (using a boolean array, bitmask, or any other similar way).", "Check if the number of found characters equals the alphabet length."], "metadata": {"canonical_parameter_names": ["sentence"], "leetcode_dataset_entry_point": "Solution().checkIfPangram", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:05+00:00", "tests_total": 98, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function checkIfPangram($sentence) {", "container": "Solution", "callable": "checkIfPangram", "parameters": [{"name": "sentence", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1833, "task_id": "maximum-ice-cream-bars", "difficulty": "Medium", "problem_description": "It is a sweltering summer day, and a boy wants to buy some ice cream bars.\n\nAt the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the i^th ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.\n\nNote: The boy can buy the ice cream bars in any order.\n\nReturn the maximum number of ice cream bars the boy can buy with coins coins.\n\nYou must solve the problem by counting sort.\n\nExample 1:\n\nInput: costs = [1,3,2,4,1], coins = 7\nOutput: 4\nExplanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.\n\nExample 2:\n\nInput: costs = [10,6,8,7,7,8], coins = 5\nOutput: 0\nExplanation: The boy cannot afford any of the ice cream bars.\n\nExample 3:\n\nInput: costs = [1,6,3,1,2,5], coins = 20\nOutput: 6\nExplanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.\n\nConstraints:\n\n- costs.length == n\n- 1 <= n <= 10^5\n- 1 <= costs[i] <= 10^5\n- 1 <= coins <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(costs = [1, 3, 2, 4, 1],coins = 7) == 4\n assert candidate(costs = [10, 6, 8, 7, 7, 8],coins = 5) == 0\n assert candidate(costs = [1],coins = 1) == 1\n assert candidate(costs = [1, 6, 3, 1, 2, 5],coins = 20) == 6\n assert candidate(costs = [100000],coins = 100000) == 1\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 10) == 4\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 55) == 10\n assert candidate(costs = [5, 5, 5, 5, 5],coins = 15) == 3\n assert candidate(costs = [10, 20, 30, 40, 50],coins = 100) == 4\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 15) == 5\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 50) == 9\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 19) == 19\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 5) == 5\n assert candidate(costs = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],coins = 15) == 6\n assert candidate(costs = [5, 4, 2, 3, 1, 6, 7, 8, 9, 10],coins = 15) == 5\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],coins = 250) == 6\n assert candidate(costs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],coins = 25) == 12\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],coins = 210) == 20\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],coins = 55) == 2\n assert candidate(costs = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],coins = 40) == 8\n assert candidate(costs = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],coins = 100) == 13\n assert candidate(costs = [100000, 99999, 99998, 99997, 99996, 99995],coins = 599985) == 6\n assert candidate(costs = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],coins = 50) == 13\n assert candidate(costs = [50, 25, 75, 100, 200, 300, 400, 500, 600, 700],coins = 2000) == 8\n assert candidate(costs = [1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 10) == 10\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],coins = 800) == 12\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 10) == 10\n assert candidate(costs = [5, 1, 4, 2, 3],coins = 10) == 4\n assert candidate(costs = [1000, 500, 200, 100, 50, 20, 10, 5, 2, 1],coins = 1000) == 9\n assert candidate(costs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],coins = 8000) == 12\n assert candidate(costs = [5, 7, 8, 6, 3, 2, 1, 4, 9, 10],coins = 20) == 5\n assert candidate(costs = [50, 20, 30, 10, 40],coins = 100) == 4\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],coins = 1000) == 10\n assert candidate(costs = [100000, 100000, 100000, 100000, 100000],coins = 500000) == 5\n assert candidate(costs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],coins = 50) == 5\n assert candidate(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],coins = 300) == 24\n assert candidate(costs = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],coins = 25) == 6\n assert candidate(costs = [99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1],coins = 5) == 5\n assert candidate(costs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],coins = 20) == 4\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 10) == 10\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 50) == 9\n assert candidate(costs = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],coins = 50) == 10\n assert candidate(costs = [9, 8, 7, 6, 5, 4, 3, 2, 1],coins = 25) == 6\n assert candidate(costs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],coins = 55) == 10\n assert candidate(costs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],coins = 1500) == 5\n assert candidate(costs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],coins = 15) == 7\n assert candidate(costs = [5, 1, 3, 1, 2, 5, 3, 1, 2, 5],coins = 15) == 7\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 10) == 10\n assert candidate(costs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],coins = 55) == 2\n assert candidate(costs = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],coins = 20) == 4\n assert candidate(costs = [1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 4],coins = 10) == 7\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],coins = 550) == 10\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 10) == 10\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],coins = 190) == 19\n assert candidate(costs = [3, 1, 2, 1, 4, 2, 2, 3, 2, 1, 2, 3, 4, 1, 2],coins = 20) == 11\n assert candidate(costs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],coins = 300) == 10\n assert candidate(costs = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31],coins = 100) == 8\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],coins = 1000) == 13\n assert candidate(costs = [100000, 1, 100000, 1, 100000, 1, 100000],coins = 100003) == 4\n assert candidate(costs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],coins = 100) == 10\n assert candidate(costs = [5, 1, 3, 2, 4, 1],coins = 10) == 4\n assert candidate(costs = [5, 3, 3, 2, 7, 8, 9],coins = 15) == 4\n assert candidate(costs = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],coins = 500000) == 9\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],coins = 100) == 13\n assert candidate(costs = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],coins = 1000000) == 10\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],coins = 5) == 5\n assert candidate(costs = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],coins = 150000) == 9\n assert candidate(costs = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],coins = 250) == 18\n assert candidate(costs = [5, 2, 3, 1, 4, 2, 3, 5, 1, 2],coins = 15) == 7\n assert candidate(costs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],coins = 2500) == 6\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],coins = 30) == 7\n assert candidate(costs = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],coins = 60) == 10\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],coins = 100) == 13\n", "comparison": "exact"}, "public_tests": ["[1,3,2,4,1]\n7", "[10,6,8,7,7,8]\n5", "[1,6,3,1,2,5]\n20"], "hints": ["It is always optimal to buy the least expensive ice cream bar first.", "Sort the prices so that the cheapest ice cream bar comes first."], "metadata": {"canonical_parameter_names": ["costs", "coins"], "leetcode_dataset_entry_point": "Solution().maxIceCream", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:07+00:00", "tests_total": 75, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy", "sorting", "counting-sort"]}, "language": "php", "interface": {"raw_signature": "function maxIceCream($costs, $coins) {", "container": "Solution", "callable": "maxIceCream", "parameters": [{"name": "costs", "type": "Integer[]"}, {"name": "coins", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1834, "task_id": "single-threaded-cpu", "difficulty": "Medium", "problem_description": "You are given n tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTime_i, processingTime_i] means that the i^th task will be available to process at enqueueTime_i and will take processingTime_ito finish processing.\n\nYou have a single-threaded CPU that can process at most one task at a time and will act in the following way:\n\n- If the CPU is idle and there are no available tasks to process, the CPU remains idle.\n- If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.\n- Once a task is started, the CPU will process the entire task without stopping.\n- The CPU can finish a task then start a new one instantly.\n\nReturn the order in which the CPU will process the tasks.\n\nExample 1:\n\nInput: tasks = [[1,2],[2,4],[3,2],[4,1]]\nOutput: [0,2,3,1]\nExplanation: The events go as follows:\n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n\nExample 2:\n\nInput: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\nOutput: [4,3,2,0,1]\nExplanation: The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n\nConstraints:\n\n- 1 <= tasks.length <= 10^5\n- tasks[i] = [enqueueTime_i, processingTime_i]\n- 1 <= enqueueTime_i, processingTime_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [[1, 3], [2, 2], [3, 1], [4, 4]]) == [0, 2, 1, 3]\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 3], [2, 5], [8, 2], [7, 4], [10, 2]]) == [0, 1, 2, 4, 3]\n assert candidate(tasks = [[1, 3], [2, 2], [3, 1], [4, 4], [5, 5]]) == [0, 2, 1, 3, 4]\n assert candidate(tasks = [[3, 1], [1, 2], [2, 4], [1, 4]]) == [1, 0, 2, 3]\n assert candidate(tasks = [[5, 2], [3, 1], [1, 4], [4, 3], [2, 5]]) == [2, 1, 0, 3, 4]\n assert candidate(tasks = [[5, 5], [8, 2], [1, 9], [3, 8]]) == [2, 1, 0, 3]\n assert candidate(tasks = [[9, 3], [3, 7], [8, 10], [4, 3], [5, 3]]) == [1, 0, 3, 4, 2]\n assert candidate(tasks = [[2, 1], [3, 1], [1, 2], [7, 3], [8, 4], [9, 5]]) == [2, 0, 1, 3, 4, 5]\n assert candidate(tasks = [[19, 13], [16, 9], [21, 10], [32, 25], [37, 4], [49, 24], [2, 15], [38, 41], [37, 34], [33, 6], [45, 4], [18, 18], [46, 39], [12, 24]]) == [6, 1, 2, 9, 4, 10, 0, 11, 5, 13, 3, 8, 12, 7]\n assert candidate(tasks = [[5, 2], [7, 2], [9, 4], [6, 3], [8, 2]]) == [0, 1, 4, 3, 2]\n assert candidate(tasks = [[7, 10], [7, 12], [7, 5], [7, 4], [7, 2]]) == [4, 3, 2, 0, 1]\n assert candidate(tasks = [[5, 2], [1, 2], [3, 1], [2, 1]]) == [1, 2, 3, 0]\n assert candidate(tasks = [[1, 2], [2, 4], [3, 2], [4, 1]]) == [0, 2, 3, 1]\n assert candidate(tasks = [[1, 3], [2, 5], [8, 2], [7, 4], [6, 1], [5, 6], [4, 3], [3, 2], [9, 5], [10, 4]]) == [0, 7, 4, 6, 2, 3, 9, 1, 8, 5]\n assert candidate(tasks = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1], [10, 10]]) == [0, 8, 7, 6, 5, 4, 3, 2, 1, 9]\n assert candidate(tasks = [[100, 1], [100, 1], [100, 1], [100, 1], [100, 1], [100, 1], [100, 1], [100, 1], [100, 1], [100, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(tasks = [[1, 2], [2, 3], [4, 5], [8, 9], [16, 17], [32, 33], [64, 65], [128, 129], [256, 257], [512, 513], [1024, 1025], [2048, 2049], [4096, 4097], [8192, 8193], [16384, 16385]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[1, 100], [101, 1], [201, 10], [301, 100], [401, 10], [501, 1], [601, 100], [701, 10], [801, 1], [901, 100]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [2, 2], [1, 3], [2, 4], [1, 5], [2, 6], [1, 7], [2, 8], [1, 9], [2, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[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]]) == [0, 10, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19]\n assert candidate(tasks = [[1, 1000000000], [2, 1000000000], [3, 1000000000], [4, 1000000000], [5, 1000000000]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 100], [200, 1], [300, 1], [400, 1], [500, 1], [600, 1], [700, 1], [800, 1], [900, 1], [1000, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 1], [7, 2], [8, 3], [9, 4], [10, 5]]) == [0, 4, 5, 3, 6, 2, 7, 1, 8, 9]\n assert candidate(tasks = [[1, 10], [10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[2, 5], [1, 3], [2, 2], [4, 1], [5, 10], [7, 1], [8, 2], [9, 3], [10, 4]]) == [1, 3, 2, 5, 6, 7, 8, 0, 4]\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]]) == [5, 6, 3, 4, 10, 2, 7, 11, 15, 1, 8, 12, 16, 0, 9, 13, 17, 14, 18, 19]\n assert candidate(tasks = [[1, 10], [10, 1], [100, 1], [1000, 1], [10000, 1], [100000, 1], [1000000, 1], [10000000, 1], [100000000, 1], [1000000000, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[10, 100], [100, 10], [200, 20], [300, 30], [400, 40], [500, 50], [600, 60], [700, 70], [800, 80], [900, 90]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5]]) == [4, 5, 3, 6, 2, 7, 1, 8, 0, 9]\n assert candidate(tasks = [[1, 3], [1, 2], [1, 1], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [1, 2], [1, 2], [2, 1], [2, 1], [2, 1], [3, 3], [3, 3], [3, 3], [4, 4], [4, 4], [4, 4], [5, 5], [5, 5], [5, 5]]) == [0, 3, 4, 5, 1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[1, 1], [1000000000, 1000000000], [2, 2], [999999999, 999999999], [3, 3], [999999998, 999999998], [4, 4], [999999997, 999999997], [5, 5], [999999996, 999999996]]) == [0, 2, 4, 6, 8, 9, 7, 5, 3, 1]\n assert candidate(tasks = [[10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [2, 1], [3, 2], [4, 1], [5, 2], [6, 1], [7, 2], [8, 1], [9, 2], [10, 1], [1, 2], [2, 1], [3, 2], [4, 1], [5, 2], [6, 1], [7, 2], [8, 1], [9, 2], [10, 1]]) == [0, 1, 3, 11, 5, 13, 7, 15, 9, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n assert candidate(tasks = [[1, 1], [10, 2], [20, 3], [30, 4], [40, 5], [50, 6], [60, 7], [70, 8], [80, 9], [90, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(tasks = [[1000000000, 1], [1000000000, 2], [1000000000, 3], [1000000000, 4], [1000000000, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [1, 2], [1, 4], [1, 8], [1, 16], [1, 32], [1, 64], [1, 128], [1, 256], [1, 512]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]\n assert candidate(tasks = [[5, 10], [10, 5], [15, 1], [20, 2], [25, 8], [30, 3], [35, 4], [40, 9], [45, 6], [50, 7]]) == [0, 2, 1, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1000000000], [2, 1000000000], [3, 1000000000], [4, 1000000000], [5, 1000000000], [6, 1000000000], [7, 1000000000], [8, 1000000000], [9, 1000000000], [10, 1000000000]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2], [10, 2]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [1000000000, 1], [999999999, 2], [2, 2], [999999998, 3], [3, 3], [999999997, 4], [4, 4], [999999996, 5], [5, 5]]) == [0, 3, 5, 7, 9, 8, 1, 2, 4, 6]\n assert candidate(tasks = [[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]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(tasks = [[1, 2], [1, 3], [2, 1], [2, 2], [3, 3], [3, 4], [4, 1], [4, 2], [5, 3], [5, 4], [6, 1], [6, 2], [7, 3], [7, 4], [8, 1], [8, 2], [9, 3], [9, 4], [10, 1], [10, 2]]) == [0, 2, 6, 3, 10, 14, 7, 18, 11, 15, 19, 1, 4, 8, 12, 16, 5, 9, 13, 17]\n assert candidate(tasks = [[1, 100], [2, 50], [3, 25], [4, 12], [5, 6], [6, 3], [7, 2], [8, 1]]) == [0, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(tasks = [[1, 20], [5, 10], [10, 5], [15, 2], [20, 1], [25, 1], [30, 1], [35, 1], [40, 1], [45, 1]]) == [0, 4, 3, 2, 5, 6, 1, 7, 8, 9]\n assert candidate(tasks = [[100, 100], [150, 100], [200, 100], [250, 100], [300, 100], [350, 100], [400, 100], [450, 100], [500, 100]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1], [11, 1], [13, 1], [15, 1], [17, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3], [4, 1]]) == [0, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[2, 1], [4, 1], [6, 1], [8, 1], [10, 1], [1, 2], [3, 2], [5, 2], [7, 2], [9, 2], [11, 2], [13, 2], [15, 2], [17, 2], [19, 2]]) == [5, 0, 1, 6, 2, 3, 7, 4, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10]]) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(tasks = [[10, 10], [15, 5], [20, 1], [25, 2], [30, 3], [35, 4], [40, 5], [45, 6], [50, 7]]) == [0, 2, 1, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[1, 100], [10, 100], [20, 100], [30, 100], [40, 100], [50, 100], [60, 100], [70, 100], [80, 100], [90, 100]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(tasks = [[1, 5], [3, 3], [5, 1], [7, 2], [9, 4], [11, 6], [13, 5], [15, 3], [17, 2], [19, 1]]) == [0, 2, 3, 1, 4, 7, 9, 8, 6, 5]\n assert candidate(tasks = [[1000000000, 1], [1000000000, 1], [1000000000, 1], [1000000000, 1], [1000000000, 1]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 10], [11, 1], [21, 1], [31, 1], [41, 1], [51, 1], [61, 1], [71, 1], [81, 1], [91, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[10, 1], [11, 2], [12, 3], [13, 4], [14, 5], [15, 6], [16, 7], [17, 8], [18, 9], [19, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1]]) == [0, 5, 6, 7, 8, 9, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 2], [10, 3], [20, 4], [30, 5], [40, 6], [50, 7], [60, 8], [70, 9], [80, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[1, 1], [1, 10], [1, 100], [1, 1000], [1, 10000], [1, 100000], [1, 1000000], [1, 10000000], [1, 100000000], [1, 1000000000]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [2, 1], [3, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(tasks = [[1, 2], [3, 1], [5, 3], [7, 4], [9, 2], [11, 1], [13, 5], [15, 3], [17, 2], [19, 1]]) == [0, 1, 2, 3, 5, 4, 7, 8, 9, 6]\n assert candidate(tasks = [[9, 5], [1, 5], [8, 5], [3, 5], [2, 5], [4, 5], [6, 5], [7, 5], [10, 5], [11, 5]]) == [1, 3, 0, 2, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [2, 1], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [10, 2], [100, 3], [1000, 4], [10000, 5], [100000, 6], [1000000, 7], [10000000, 8], [100000000, 9], [1000000000, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[10, 3], [20, 2], [30, 1], [40, 4], [50, 5], [60, 6]]) == [0, 1, 2, 3, 4, 5]\n assert candidate(tasks = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [2, 2], [4, 4], [6, 6], [8, 8], [10, 10]]) == [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]\n assert candidate(tasks = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == [0, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(tasks = [[1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [2, 10], [2, 9], [2, 8], [2, 7], [2, 6], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1]]) == [9, 19, 8, 18, 7, 17, 6, 16, 5, 15, 4, 14, 3, 13, 2, 12, 1, 11, 0, 10]\n assert candidate(tasks = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [2, 4], [3, 8], [4, 16], [5, 32], [6, 64], [7, 128], [8, 256], [9, 512], [10, 1024]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[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]]) == [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]\n assert candidate(tasks = [[1, 10], [10, 10], [20, 10], [30, 10], [40, 10], [50, 10]]) == [0, 1, 2, 3, 4, 5]\n assert candidate(tasks = [[1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1]]) == [0, 1, 3, 5, 7, 9, 2, 4, 6, 8]\n assert candidate(tasks = [[10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[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], [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]]) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]\n assert candidate(tasks = [[1, 1], [1, 1], [1, 2], [1, 2], [1, 3], [1, 3], [1, 4], [1, 4], [1, 5], [1, 5]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 1], [10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 1], [70, 1], [80, 1], [90, 1], [100, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(tasks = [[1, 10], [2, 5], [3, 15], [4, 20], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [0, 4, 5, 6, 7, 8, 9, 1, 2, 3]\n assert candidate(tasks = [[1, 2], [3, 3], [5, 2], [7, 1], [9, 2], [11, 3], [13, 1], [15, 2], [17, 3], [19, 1], [21, 2], [23, 3], [25, 1], [27, 2], [29, 3]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 1], [70, 1], [80, 1], [90, 1], [100, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 10], [5, 1], [3, 2], [2, 3], [7, 4], [6, 5], [8, 6], [9, 7], [10, 8]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(tasks = [[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]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[1, 1000000000], [2, 900000000], [3, 800000000], [4, 700000000], [5, 600000000], [6, 500000000], [7, 400000000], [8, 300000000], [9, 200000000], [10, 100000000]]) == [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(tasks = [[10, 10], [20, 5], [30, 15], [40, 1], [50, 20]]) == [0, 1, 2, 3, 4]\n assert candidate(tasks = [[1, 1], [2, 1], [1, 2], [2, 2], [1, 3], [2, 3], [1, 4], [2, 4], [1, 5], [2, 5]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(tasks = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(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]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(tasks = [[1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1]]) == [8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(tasks = [[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]]) == [0, 9, 8, 7, 6, 19, 18, 17, 16, 5, 15, 4, 14, 3, 13, 2, 12, 1, 11, 10]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,4],[3,2],[4,1]]", "[[7,10],[7,12],[7,5],[7,4],[7,2]]"], "hints": ["To simulate the problem we first need to note that if at any point in time there are no enqueued tasks we need to wait to the smallest enqueue time of a non-processed element", "We need a data structure like a min-heap to support choosing the task with the smallest processing time from all the enqueued tasks"], "metadata": {"canonical_parameter_names": ["tasks"], "leetcode_dataset_entry_point": "Solution().getOrder", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:10+00:00", "tests_total": 109, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function getOrder($tasks) {", "container": "Solution", "callable": "getOrder", "parameters": [{"name": "tasks", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1835, "task_id": "find-xor-sum-of-all-pairs-bitwise-and", "difficulty": "Hard", "problem_description": "The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.\n\n- For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.\n\nYou are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.\n\nConsider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.\n\nReturn the XOR sum of the aforementioned list.\n\nExample 1:\n\nInput: arr1 = [1,2,3], arr2 = [6,5]\nOutput: 0\nExplanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\nThe XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.\n\nExample 2:\n\nInput: arr1 = [12], arr2 = [4]\nOutput: 4\nExplanation: The list = [12 AND 4] = [4]. The XOR sum = 4.\n\nConstraints:\n\n- 1 <= arr1.length, arr2.length <= 10^5\n- 0 <= arr1[i], arr2[j] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr1 = [1, 2, 3],arr2 = [6, 5]) == 0\n assert candidate(arr1 = [1, 1, 1, 1, 1],arr2 = [1, 1, 1, 1, 1]) == 1\n assert candidate(arr1 = [1, 3, 5, 7, 9],arr2 = [2, 4, 6, 8, 10]) == 0\n assert candidate(arr1 = [1000000000],arr2 = [1000000000]) == 1000000000\n assert candidate(arr1 = [0, 0, 0],arr2 = [0, 0, 0]) == 0\n assert candidate(arr1 = [255, 128, 64],arr2 = [32, 16, 8]) == 56\n assert candidate(arr1 = [1000000000, 500000000],arr2 = [500000000, 1000000000]) == 643280640\n assert candidate(arr1 = [255, 128, 64, 32, 16],arr2 = [1, 3, 7, 15, 31]) == 5\n assert candidate(arr1 = [0, 1, 2, 3, 4],arr2 = [0, 1, 2, 3, 4]) == 4\n assert candidate(arr1 = [255, 128, 64, 32],arr2 = [1, 2, 4, 8]) == 15\n assert candidate(arr1 = [0, 1, 2, 3, 4],arr2 = [4, 3, 2, 1, 0]) == 4\n assert candidate(arr1 = [12],arr2 = [4]) == 4\n assert candidate(arr1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],arr2 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 13\n assert candidate(arr1 = [8, 16, 32, 64, 128, 256, 512],arr2 = [1024, 2048, 4096, 8192]) == 0\n assert candidate(arr1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],arr2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(arr1 = [1, 3, 5, 7, 9, 11, 13, 15],arr2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 0\n assert candidate(arr1 = [100, 200, 300, 400, 500],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 484\n assert candidate(arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(arr1 = [1023, 2047, 4095],arr2 = [8191, 16383, 32767]) == 3071\n assert candidate(arr1 = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127],arr2 = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 640\n assert candidate(arr1 = [5, 10, 15, 20, 25],arr2 = [30, 35, 40, 45, 50]) == 8\n assert candidate(arr1 = [7, 14, 21, 28, 35],arr2 = [42, 49, 56, 63, 70]) == 2\n assert candidate(arr1 = [11235813, 21345589, 34558914, 55891442],arr2 = [832040, 1346269, 2178309, 3524578]) == 279040\n assert candidate(arr1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],arr2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(arr1 = [1023, 512, 256, 128, 64],arr2 = [32, 16, 8, 4, 2, 1]) == 63\n assert candidate(arr1 = [987654321, 234567890],arr2 = [135792468, 864201357]) == 855638081\n assert candidate(arr1 = [13, 29, 42, 57, 71],arr2 = [88, 99, 101, 113, 131]) == 4\n assert candidate(arr1 = [1],arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(arr1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],arr2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 0\n assert candidate(arr1 = [1000000000, 500000000, 250000000, 125000000, 62500000],arr2 = [1, 3, 5, 7, 9]) == 0\n assert candidate(arr1 = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(arr1 = [23, 45, 67, 89, 101],arr2 = [113, 131, 149, 167]) == 64\n assert candidate(arr1 = [29, 18, 7, 2, 11],arr2 = [19, 23, 31, 37, 41]) == 1\n assert candidate(arr1 = [1000000, 2000000, 3000000],arr2 = [1000, 2000, 3000, 4000, 5000]) == 0\n assert candidate(arr1 = [1, 2, 4, 8, 16, 32],arr2 = [64, 128, 256, 512, 1024]) == 0\n assert candidate(arr1 = [1, 3, 7, 15, 31, 63, 127, 255],arr2 = [255, 127, 63, 31, 15, 7, 3, 1]) == 170\n assert candidate(arr1 = [15, 31, 63, 127, 255],arr2 = [255, 127, 63, 31, 15]) == 175\n assert candidate(arr1 = [7, 14, 21, 28, 35],arr2 = [8, 16, 24, 32, 40]) == 0\n assert candidate(arr1 = [1, 2, 4, 8, 16, 32, 64, 128],arr2 = [128, 64, 32, 16, 8, 4, 2, 1]) == 255\n assert candidate(arr1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],arr2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(arr1 = [999999999, 999999998, 999999997, 999999996, 999999995],arr2 = [999999994, 999999993, 999999992, 999999991, 999999990]) == 999999994\n assert candidate(arr1 = [314159265, 271828182, 8675309],arr2 = [161803398, 141421356, 423606797]) == 403842\n assert candidate(arr1 = [17, 34, 51, 68, 85],arr2 = [1, 2, 4, 8, 16]) == 17\n assert candidate(arr1 = [1, 0, 1, 0, 1, 0],arr2 = [1024, 2048, 4096, 8192, 16384, 32768]) == 0\n assert candidate(arr1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],arr2 = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 682\n assert candidate(arr1 = [123456789, 987654321],arr2 = [111111111, 222222222, 333333333]) == 403023108\n assert candidate(arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr2 = [1]) == 1\n assert candidate(arr1 = [255, 192, 128, 64, 32],arr2 = [16, 8, 4, 2, 1]) == 31\n assert candidate(arr1 = [134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152],arr2 = [512, 256, 128, 64, 32, 16]) == 0\n assert candidate(arr1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],arr2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(arr1 = [1, 1, 1, 1],arr2 = [2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(arr1 = [1023, 511, 255, 127, 63],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 703\n assert candidate(arr1 = [13, 14, 15],arr2 = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == 12\n assert candidate(arr1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],arr2 = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2047\n assert candidate(arr1 = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 2097151\n assert candidate(arr1 = [1000000000, 500000000, 250000000, 125000000],arr2 = [2, 3, 5, 7]) == 0\n assert candidate(arr1 = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 682\n assert candidate(arr1 = [2, 4, 6, 8, 10],arr2 = [3, 6, 9, 12, 15]) == 2\n assert candidate(arr1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],arr2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(arr1 = [1023, 2047, 4095, 8191],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1024\n assert candidate(arr1 = [0, 0, 0, 0, 0],arr2 = [1, 3, 5, 7, 9]) == 0\n assert candidate(arr1 = [29, 31, 37, 41, 43],arr2 = [47, 53, 59, 61, 67, 71]) == 0\n assert candidate(arr1 = [31, 63, 127, 255],arr2 = [255, 127, 63, 31]) == 160\n assert candidate(arr1 = [2, 4, 6, 8, 10, 12, 14, 16],arr2 = [1, 3, 5, 7, 9, 11, 13, 15]) == 0\n assert candidate(arr1 = [234, 456, 789, 1024],arr2 = [123, 234, 345, 456]) == 0\n assert candidate(arr1 = [987654321, 123456789, 456789123],arr2 = [987654321, 123456789, 456789123]) == 650094887\n assert candidate(arr1 = [123456, 654321, 987654, 321654],arr2 = [789456, 123789, 456789]) == 196608\n assert candidate(arr1 = [0, 0, 0, 0, 0],arr2 = [0, 0, 0, 0, 0]) == 0\n assert candidate(arr1 = [23, 45, 67, 89, 123],arr2 = [56, 78, 90, 101, 112]) == 25\n assert candidate(arr1 = [100, 200, 300, 400, 500],arr2 = [600, 700, 800, 900, 1000]) == 416\n assert candidate(arr1 = [7, 8, 9, 10, 11],arr2 = [12, 13, 14, 15, 16]) == 0\n assert candidate(arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(arr1 = [15, 30, 45, 60, 75, 90],arr2 = [10, 20, 30, 40, 50, 60]) == 0\n assert candidate(arr1 = [15, 27, 45, 63],arr2 = [31, 63, 95, 127]) == 0\n assert candidate(arr1 = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],arr2 = [31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17]) == 16\n assert candidate(arr1 = [1000000000, 999999999, 888888888],arr2 = [777777777, 666666666, 555555555]) == 553274368\n assert candidate(arr1 = [123456789, 987654321, 111111111],arr2 = [222222222, 333333333, 444444444]) == 1575491\n assert candidate(arr1 = [13, 21, 34, 55, 89, 144, 233, 377, 610, 987],arr2 = [1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393]) == 1\n assert candidate(arr1 = [1048576, 2097152, 4194304],arr2 = [1, 3, 5, 7]) == 0\n assert candidate(arr1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],arr2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 0\n assert candidate(arr1 = [0, 0, 0, 0],arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(arr1 = [255, 0, 127, 63, 31],arr2 = [255, 128, 64, 32, 16]) == 0\n assert candidate(arr1 = [314159265],arr2 = [271828182]) == 271679616\n assert candidate(arr1 = [1, 3, 5, 7, 9, 11, 13, 15],arr2 = [1, 2, 4, 8, 16, 32, 64, 128]) == 0\n assert candidate(arr1 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],arr2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\n assert candidate(arr1 = [1000000000, 500000000, 250000000],arr2 = [1000000000, 500000000, 250000000]) == 682696064\n assert candidate(arr1 = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],arr2 = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 682\n assert candidate(arr1 = [123456789, 987654321, 135792468],arr2 = [246813579, 864204864, 975318642]) == 85229744\n assert candidate(arr1 = [1048575, 524287, 262143, 131071, 65535],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 720895\n assert candidate(arr1 = [1000000000, 999999999, 999999998],arr2 = [999999997, 999999996, 999999995]) == 999999488\n assert candidate(arr1 = [123456789, 987654321],arr2 = [234567891, 123456789]) == 142648708\n assert candidate(arr1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],arr2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(arr1 = [1000000000, 500000000, 250000000, 125000000],arr2 = [2, 4, 8, 16]) == 0\n assert candidate(arr1 = [256, 512, 768, 1024],arr2 = [1, 2, 4, 8, 16]) == 0\n assert candidate(arr1 = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],arr2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 682\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n[6,5]", "[12]\n[4]"], "hints": ["Think about (a&b) ^ (a&c). Can you simplify this expression?", "It is equal to a&(b^c). Then, (arr1[i]&arr2[0])^(arr1[i]&arr2[1]).. = arr1[i]&(arr2[0]^arr2[1]^arr[2]...).", "Let arr2XorSum = (arr2[0]^arr2[1]^arr2[2]...), arr1XorSum = (arr1[0]^arr1[1]^arr1[2]...) so the final answer is (arr2XorSum&arr1[0]) ^ (arr2XorSum&arr1[1]) ^ (arr2XorSum&arr1[2]) ^ ... = arr2XorSum & arr1XorSum."], "metadata": {"canonical_parameter_names": ["arr1", "arr2"], "leetcode_dataset_entry_point": "Solution().getXORSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:12+00:00", "tests_total": 103, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "math", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function getXORSum($arr1, $arr2) {", "container": "Solution", "callable": "getXORSum", "parameters": [{"name": "arr1", "type": "Integer[]"}, {"name": "arr2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1837, "task_id": "sum-of-digits-in-base-k", "difficulty": "Easy", "problem_description": "Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.\n\nAfter converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.\n\nExample 1:\n\nInput: n = 34, k = 6\nOutput: 9\nExplanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.\n\nExample 2:\n\nInput: n = 10, k = 10\nOutput: 1\nExplanation: n is already in base 10. 1 + 0 = 1.\n\nConstraints:\n\n- 1 <= n <= 100\n- 2 <= k <= 10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 64,k = 2) == 1\n assert candidate(n = 7,k = 3) == 3\n assert candidate(n = 42,k = 5) == 6\n assert candidate(n = 50,k = 4) == 5\n assert candidate(n = 100,k = 3) == 4\n assert candidate(n = 10,k = 10) == 1\n assert candidate(n = 50,k = 7) == 2\n assert candidate(n = 99,k = 9) == 3\n assert candidate(n = 81,k = 9) == 1\n assert candidate(n = 34,k = 6) == 9\n assert candidate(n = 8,k = 2) == 1\n assert candidate(n = 45,k = 3) == 3\n assert candidate(n = 25,k = 2) == 3\n assert candidate(n = 81,k = 3) == 1\n assert candidate(n = 64,k = 10) == 10\n assert candidate(n = 27,k = 5) == 3\n assert candidate(n = 100,k = 2) == 3\n assert candidate(n = 1,k = 2) == 1\n assert candidate(n = 100,k = 4) == 4\n assert candidate(n = 72,k = 8) == 2\n assert candidate(n = 50,k = 5) == 2\n assert candidate(n = 17,k = 8) == 3\n assert candidate(n = 91,k = 8) == 7\n assert candidate(n = 73,k = 4) == 4\n assert candidate(n = 85,k = 7) == 7\n assert candidate(n = 63,k = 9) == 7\n assert candidate(n = 100,k = 7) == 4\n assert candidate(n = 63,k = 5) == 7\n assert candidate(n = 37,k = 5) == 5\n assert candidate(n = 95,k = 9) == 7\n assert candidate(n = 63,k = 7) == 3\n assert candidate(n = 55,k = 7) == 7\n assert candidate(n = 31,k = 5) == 3\n assert candidate(n = 32,k = 2) == 1\n assert candidate(n = 42,k = 4) == 6\n assert candidate(n = 19,k = 4) == 4\n assert candidate(n = 55,k = 6) == 5\n assert candidate(n = 100,k = 5) == 4\n assert candidate(n = 15,k = 6) == 5\n assert candidate(n = 45,k = 7) == 9\n assert candidate(n = 84,k = 4) == 3\n assert candidate(n = 31,k = 10) == 4\n assert candidate(n = 45,k = 6) == 5\n assert candidate(n = 97,k = 5) == 9\n assert candidate(n = 45,k = 10) == 9\n assert candidate(n = 50,k = 8) == 8\n assert candidate(n = 67,k = 5) == 7\n assert candidate(n = 37,k = 2) == 3\n assert candidate(n = 67,k = 7) == 7\n assert candidate(n = 29,k = 3) == 3\n assert candidate(n = 50,k = 6) == 5\n assert candidate(n = 72,k = 5) == 8\n assert candidate(n = 37,k = 6) == 2\n assert candidate(n = 85,k = 3) == 3\n assert candidate(n = 88,k = 3) == 4\n assert candidate(n = 64,k = 3) == 4\n assert candidate(n = 64,k = 4) == 1\n assert candidate(n = 95,k = 6) == 10\n assert candidate(n = 67,k = 3) == 5\n assert candidate(n = 100,k = 10) == 1\n assert candidate(n = 81,k = 5) == 5\n assert candidate(n = 55,k = 5) == 3\n assert candidate(n = 98,k = 2) == 3\n assert candidate(n = 58,k = 7) == 4\n assert candidate(n = 48,k = 4) == 3\n assert candidate(n = 31,k = 2) == 5\n assert candidate(n = 81,k = 8) == 4\n assert candidate(n = 42,k = 7) == 6\n assert candidate(n = 27,k = 9) == 3\n assert candidate(n = 77,k = 7) == 5\n assert candidate(n = 29,k = 8) == 8\n assert candidate(n = 97,k = 10) == 16\n assert candidate(n = 77,k = 4) == 5\n assert candidate(n = 13,k = 6) == 3\n assert candidate(n = 49,k = 9) == 9\n assert candidate(n = 55,k = 10) == 10\n assert candidate(n = 41,k = 4) == 5\n assert candidate(n = 98,k = 6) == 8\n assert candidate(n = 50,k = 3) == 6\n assert candidate(n = 85,k = 5) == 5\n assert candidate(n = 73,k = 8) == 3\n assert candidate(n = 100,k = 9) == 4\n assert candidate(n = 77,k = 8) == 7\n assert candidate(n = 85,k = 4) == 4\n assert candidate(n = 99,k = 3) == 3\n assert candidate(n = 29,k = 4) == 5\n assert candidate(n = 72,k = 6) == 2\n", "comparison": "exact"}, "public_tests": ["34\n6", "10\n10"], "hints": ["Convert the given number into base k."], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().sumBase", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:17+00:00", "tests_total": 87, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function sumBase($n, $k) {", "container": "Solution", "callable": "sumBase", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1838, "task_id": "frequency-of-the-most-frequent-element", "difficulty": "Medium", "problem_description": "The frequency of an element is the number of times it occurs in an array.\n\nYou are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.\n\nReturn the maximum possible frequency of an element after performing at most k operations.\n\nExample 1:\n\nInput: nums = [1,2,4], k = 5\nOutput: 3\nExplanation: Increment the first element three times and the second element two times to make nums = [4,4,4].\n4 has a frequency of 3.\n\nExample 2:\n\nInput: nums = [1,4,8,13], k = 5\nOutput: 2\nExplanation: There are multiple optimal solutions:\n- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.\n\nExample 3:\n\nInput: nums = [3,9,6], k = 2\nOutput: 1\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- 1 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 4],k = 5) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 25) == 7\n assert candidate(nums = [5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4],k = 7) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],k = 10) == 5\n assert candidate(nums = [3, 9, 6],k = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],k = 5) == 5\n assert candidate(nums = [1, 100000],k = 100000) == 2\n assert candidate(nums = [1, 2, 2, 4],k = 6) == 3\n assert candidate(nums = [1, 4, 8, 13],k = 5) == 2\n assert candidate(nums = [1, 100000],k = 99999) == 2\n assert candidate(nums = [100000, 100000, 100000],k = 100000) == 3\n assert candidate(nums = [5, 9, 11, 13, 15],k = 10) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 10) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3],k = 6) == 6\n assert candidate(nums = [1, 2, 2, 4],k = 3) == 3\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 10) == 10\n assert candidate(nums = [1, 1, 1, 1],k = 10) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],k = 15) == 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],k = 50) == 20\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 200) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 150) == 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 = 50) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 45) == 10\n assert candidate(nums = [2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5],k = 150) == 21\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9],k = 50) == 15\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 15) == 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 = 75) == 20\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6],k = 40) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 1000) == 14\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 55) == 7\n assert candidate(nums = [1, 3, 6, 10, 15],k = 25) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 6\n assert candidate(nums = [5, 7, 7, 8, 8, 10, 10, 10, 10],k = 30) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 50) == 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],k = 100) == 20\n assert candidate(nums = [5, 7, 7, 8, 8, 10, 10, 10, 12, 12, 12, 12],k = 30) == 11\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 7\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 = 100) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 150) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 50) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5],k = 10) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9],k = 30) == 9\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 = 60) == 25\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000) == 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 = 60) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 100) == 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 = 30) == 17\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 5\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],k = 100000) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 100) == 10\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 50) == 10\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],k = 100) == 7\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 200) == 14\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 50) == 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 = 100) == 20\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],k = 1500) == 17\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4],k = 50) == 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],k = 200) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 100) == 10\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, 85, 89, 93, 97, 101],k = 500) == 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 = 200) == 20\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 20) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3000) == 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 = 1000) == 20\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 100) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 100) == 10\n assert candidate(nums = [1, 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],k = 100) == 40\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 = 300) == 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],k = 100) == 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 = 100) == 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) == 17\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50],k = 100) == 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],k = 100) == 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],k = 200) == 30\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 20) == 14\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20],k = 200) == 29\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 15) == 13\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 250) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 100) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 500) == 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 = 100) == 14\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5],k = 50) == 20\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 12\n", "comparison": "exact"}, "public_tests": ["[1,2,4]\n5", "[1,4,8,13]\n5", "[3,9,6]\n2"], "hints": ["Note that you can try all values in a brute force manner and find the maximum frequency of that value.", "To find the maximum frequency of a value consider the biggest elements smaller than or equal to this value"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:19+00:00", "tests_total": 99, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "sliding-window", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxFrequency($nums, $k) {", "container": "Solution", "callable": "maxFrequency", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1839, "task_id": "longest-substring-of-all-vowels-in-order", "difficulty": "Medium", "problem_description": "A string is considered beautiful if it satisfies the following conditions:\n\n- Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.\n- The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).\n\nFor example, strings \"aeiou\" and \"aaaaaaeiiiioou\" are considered beautiful, but \"uaeio\", \"aeoiu\", and \"aaaeeeooo\" are not beautiful.\n\nGiven a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\"\nOutput: 13\nExplanation: The longest beautiful substring in word is \"aaaaeiiiiouuu\" of length 13.\n\nExample 2:\n\nInput: word = \"aeeeiiiioooauuuaeiou\"\nOutput: 5\nExplanation: The longest beautiful substring in word is \"aeiou\" of length 5.\n\nExample 3:\n\nInput: word = \"a\"\nOutput: 0\nExplanation: There is no beautiful substring, so return 0.\n\nConstraints:\n\n- 1 <= word.length <= 5 * 10^5\n- word consists of characters 'a', 'e', 'i', 'o', and 'u'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuooaauuaeiuuuuuuuuuuuuuuuuuuuuaaa\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuaauuaeiu\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuuuuuuuuuuuuuuuuuuaaaaaaeiou\") == 10\n assert candidate(word = \"aeiaaioaaaaeiioooaeiouuuaeiouuu\") == 7\n assert candidate(word = \"aeeeiiiioooauuuaeiou\") == 5\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuuuaaaaaaaaaeeeeiiiioooouuuuuu\") == 27\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuooaaeiouaaaaaaaaaaeiouuuuuuuuuuuuuuuuuuuu\") == 33\n assert candidate(word = \"aeiaaioaaaaeiioooaeiouuuaeiouuuaeiouuu\") == 7\n assert candidate(word = \"aeiaaioaaaaeiiaaaouuuooauuaeiu\") == 0\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiou\") == 5\n assert candidate(word = \"aaaaaaaaaeeeeeeeeeeiiiiiiioooooouuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\") == 68\n assert candidate(word = \"aeiaaioaaaaeiioooaeiouuu\") == 7\n assert candidate(word = \"aeiaaioaaaaeiiooouuuaeiou\") == 13\n assert candidate(word = \"a\") == 0\n assert candidate(word = \"aeiou\") == 5\n assert candidate(word = \"aeiaaioaaaaeiiaaaiiiiiouuuuuuuuuuuuuuuuuuuu\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiaaaouuuooaauuaeiaaioaaaaeiiiiouuuooaauuaeiu\") == 13\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\") == 13\n assert candidate(word = \"aeiaaioaaaaeiiooouuuooauuaeiu\") == 13\n assert candidate(word = \"uuuuuuuuuuuuuuuuuuuu\") == 0\n", "comparison": "exact"}, "public_tests": ["\"aeiaaioaaaaeiiiiouuuooaauuaeiu\"", "\"aeeeiiiioooauuuaeiou\"", "\"a\""], "hints": ["Start from each 'a' and find the longest beautiful substring starting at that index.", "Based on the current character decide if you should include the next character in the beautiful substring."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().longestBeautifulSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:22+00:00", "tests_total": 20, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function longestBeautifulSubstring($word) {", "container": "Solution", "callable": "longestBeautifulSubstring", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1840, "task_id": "maximum-building-height", "difficulty": "Hard", "problem_description": "You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.\n\nHowever, there are city restrictions on the heights of the new buildings:\n\n- The height of each building must be a non-negative integer.\n- The height of the first building must be 0.\n- The height difference between any two adjacent buildings cannot exceed 1.\n\nAdditionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [id_i, maxHeight_i] indicates that building id_i must have a height less than or equal to maxHeight_i.\n\nIt is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.\n\nReturn the maximum possible height of the tallest building.\n\nExample 1:\n\nInput: n = 5, restrictions = [[2,1],[4,1]]\nOutput: 2\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.\n\nExample 2:\n\nInput: n = 6, restrictions = []\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.\n\nExample 3:\n\nInput: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5.\n\nConstraints:\n\n- 2 <= n <= 10^9\n- 0 <= restrictions.length <= min(n - 1, 10^5)\n- 2 <= id_i <= n\n- id_i is unique.\n- 0 <= maxHeight_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,restrictions = []) == 5\n assert candidate(n = 5,restrictions = [[2, 1], [4, 1]]) == 2\n assert candidate(n = 100,restrictions = [[10, 5], [50, 25], [90, 10]]) == 37\n assert candidate(n = 1000000,restrictions = [[500000, 500000]]) == 999999\n assert candidate(n = 10,restrictions = [[5, 3], [2, 5], [7, 4], [10, 3]]) == 5\n assert candidate(n = 100000,restrictions = [[1000, 50], [2000, 100], [3000, 150], [4000, 200], [5000, 250], [6000, 300], [7000, 350], [8000, 400], [9000, 450]]) == 91450\n assert candidate(n = 20,restrictions = [[5, 3], [6, 2], [7, 1], [8, 0], [9, 1], [10, 2], [11, 3], [12, 4], [13, 5], [14, 6], [15, 7]]) == 12\n assert candidate(n = 1000,restrictions = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9]]) == 109\n assert candidate(n = 200,restrictions = [[20, 100], [40, 50], [60, 75], [80, 25], [100, 100], [120, 75], [140, 50], [160, 25], [180, 0], [200, 100]]) == 62\n assert candidate(n = 100,restrictions = [[10, 5], [30, 5], [50, 5], [70, 5], [90, 5]]) == 15\n assert candidate(n = 1000000,restrictions = [[500000, 1], [500001, 1], [500002, 1], [500003, 1], [500004, 1], [500005, 1], [500006, 1], [500007, 1], [500008, 1]]) == 499993\n assert candidate(n = 10000,restrictions = [[2000, 1000], [4000, 1500], [6000, 2000], [8000, 2500]]) == 4500\n assert candidate(n = 200,restrictions = [[5, 3], [10, 2], [15, 1], [20, 2], [25, 3], [30, 2], [35, 1], [40, 2], [45, 3], [50, 2], [55, 1], [60, 2], [65, 3], [70, 2], [75, 1], [80, 2], [85, 3], [90, 2], [95, 1], [100, 2], [105, 3], [110, 2], [115, 1], [120, 2], [125, 3], [130, 2], [135, 1], [140, 2], [145, 3], [150, 2], [155, 1], [160, 2], [165, 3], [170, 2], [175, 1], [180, 2], [185, 3], [190, 2], [195, 1]]) == 6\n assert candidate(n = 100,restrictions = [[10, 9], [20, 8], [30, 7], [40, 6], [50, 5], [60, 4], [70, 3], [80, 2], [90, 1]]) == 13\n assert candidate(n = 5000,restrictions = [[50, 1000], [100, 900], [150, 800], [200, 700], [250, 600], [300, 500], [350, 400], [400, 300], [450, 200], [500, 100]]) == 4600\n assert candidate(n = 20,restrictions = [[2, 3], [5, 4], [8, 1], [15, 5], [18, 2]]) == 6\n assert candidate(n = 100,restrictions = [[10, 5], [20, 10], [30, 3], [40, 15], [50, 5], [60, 20], [70, 7], [80, 12], [90, 10], [100, 2]]) == 16\n assert candidate(n = 20,restrictions = [[3, 2], [6, 3], [9, 2], [15, 5], [18, 4]]) == 6\n assert candidate(n = 10000,restrictions = [[1000, 5000], [2000, 10000], [3000, 15000], [4000, 20000], [5000, 25000], [6000, 30000], [7000, 35000], [8000, 40000], [9000, 45000], [10000, 50000]]) == 9999\n assert candidate(n = 999,restrictions = [[999, 1]]) == 499\n assert candidate(n = 1000000000,restrictions = [[100000000, 10000000], [200000000, 20000000], [300000000, 30000000], [400000000, 40000000]]) == 640000000\n assert candidate(n = 1000000,restrictions = [[999999, 999999]]) == 999999\n assert candidate(n = 50,restrictions = [[3, 2], [5, 3], [10, 5], [15, 7], [20, 9], [25, 11], [30, 13], [35, 15], [40, 17], [45, 19], [50, 21]]) == 22\n assert candidate(n = 20,restrictions = [[3, 3], [6, 2], [9, 5], [15, 4]]) == 9\n assert candidate(n = 1000,restrictions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]]) == 950\n assert candidate(n = 500000,restrictions = [[50000, 100000], [100000, 150000], [150000, 200000], [200000, 250000], [250000, 300000]]) == 499999\n assert candidate(n = 10000,restrictions = [[1000, 500], [2000, 1000], [3000, 1500], [4000, 2000], [5000, 2500], [6000, 3000], [7000, 3500], [8000, 4000], [9000, 4500], [10000, 5000]]) == 5250\n assert candidate(n = 1000000,restrictions = [[2, 1], [4, 1], [6, 1], [8, 1], [10, 1], [12, 1], [14, 1], [16, 1], [18, 1], [20, 1]]) == 999981\n assert candidate(n = 100000,restrictions = [[10000, 5000], [30000, 15000], [50000, 25000], [70000, 30000], [90000, 35000]]) == 45000\n assert candidate(n = 1000000,restrictions = [[2, 500000], [3, 500000], [4, 500000], [5, 500000], [6, 500000], [7, 500000], [8, 500000], [9, 500000], [10, 500000]]) == 999999\n assert candidate(n = 50000000,restrictions = [[10000000, 20000000], [20000000, 10000000], [30000000, 15000000], [40000000, 5000000], [50000000, 25000000]]) == 17500000\n assert candidate(n = 500000,restrictions = [[100000, 150000], [200000, 250000], [300000, 350000], [400000, 450000]]) == 499999\n assert candidate(n = 150,restrictions = [[15, 15], [30, 30], [45, 45], [60, 60], [75, 75], [90, 90], [105, 105], [120, 120], [135, 135], [150, 150]]) == 149\n assert candidate(n = 1000,restrictions = [[50, 50], [100, 100], [150, 150], [200, 200], [250, 250], [300, 300], [350, 350], [400, 400], [450, 450], [500, 500], [550, 550], [600, 600], [650, 650], [700, 700], [750, 750], [800, 800], [850, 850], [900, 900], [950, 950], [1000, 1000]]) == 999\n assert candidate(n = 5000,restrictions = [[1000, 500], [2000, 1000], [3000, 1500], [4000, 2000]]) == 3000\n assert candidate(n = 1000,restrictions = [[100, 900], [200, 800], [300, 700], [400, 600], [500, 500], [600, 400], [700, 300], [800, 200], [900, 100]]) == 499\n assert candidate(n = 100,restrictions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25]]) == 75\n assert candidate(n = 50,restrictions = [[5, 4], [10, 3], [15, 2], [20, 1], [25, 0], [30, 1], [35, 2], [40, 3], [45, 4], [50, 5]]) == 7\n assert candidate(n = 1000,restrictions = [[50, 100], [150, 100], [250, 100], [350, 100], [450, 100], [550, 100], [650, 100], [750, 100], [850, 100], [950, 100]]) == 150\n assert candidate(n = 1000,restrictions = [[500, 500], [250, 250], [750, 750], [100, 100], [900, 900]]) == 999\n assert candidate(n = 100000,restrictions = [[1000, 500], [5000, 2500], [10000, 5000], [25000, 10000], [50000, 15000], [75000, 10000], [90000, 5000], [95000, 1000]]) == 25000\n assert candidate(n = 100,restrictions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45]]) == 55\n assert candidate(n = 100,restrictions = [[10, 10], [20, 15], [30, 20], [40, 10], [50, 25], [60, 20], [70, 15], [80, 10], [90, 5]]) == 25\n assert candidate(n = 100,restrictions = [[3, 20], [50, 10], [90, 5]]) == 29\n assert candidate(n = 100,restrictions = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 1], [70, 1], [80, 1], [90, 1]]) == 11\n assert candidate(n = 10000,restrictions = [[500, 1000], [2500, 2000], [5000, 3000], [7500, 2000], [9500, 1000]]) == 3750\n assert candidate(n = 100,restrictions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]]) == 52\n assert candidate(n = 1000000000,restrictions = [[100000000, 99999999], [200000000, 88888888], [300000000, 77777777], [400000000, 66666666], [500000000, 55555555]]) == 555555555\n assert candidate(n = 20,restrictions = [[2, 3], [4, 2], [6, 3], [8, 2], [10, 3], [12, 2], [14, 3], [16, 2], [18, 3]]) == 5\n assert candidate(n = 200,restrictions = [[20, 1], [40, 3], [60, 5], [80, 7], [100, 9], [120, 11], [140, 13], [160, 15], [180, 17]]) == 37\n assert candidate(n = 50,restrictions = [[5, 25], [10, 15], [20, 30], [35, 20], [45, 10]]) == 27\n assert candidate(n = 1000000,restrictions = [[100000, 50000], [200000, 100000], [300000, 75000], [400000, 25000], [500000, 100000]]) == 600000\n assert candidate(n = 1000000,restrictions = [[50000, 100000], [100000, 200000], [150000, 300000], [200000, 400000], [250000, 500000], [300000, 400000], [350000, 300000], [400000, 200000], [450000, 100000]]) == 650000\n assert candidate(n = 15,restrictions = [[3, 2], [6, 3], [9, 1], [12, 4]]) == 7\n assert candidate(n = 1000000,restrictions = [[10000, 1000], [20000, 2000], [30000, 3000], [40000, 4000], [50000, 5000], [60000, 6000], [70000, 7000], [80000, 8000], [90000, 9000]]) == 919000\n assert candidate(n = 100,restrictions = [[10, 10], [20, 5], [30, 15], [40, 20], [50, 10], [60, 25], [70, 30], [80, 5], [90, 40]]) == 25\n assert candidate(n = 50,restrictions = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45]]) == 49\n assert candidate(n = 100,restrictions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]]) == 14\n assert candidate(n = 10000,restrictions = [[2, 9999], [4, 9998], [6, 9997], [8, 9996], [10, 9995], [12, 9994], [14, 9993], [16, 9992], [18, 9991], [20, 9990]]) == 9999\n assert candidate(n = 100,restrictions = [[2, 99], [4, 98], [6, 97], [8, 96], [10, 95], [12, 94], [14, 93], [16, 92], [18, 91], [20, 90], [22, 89], [24, 88], [26, 87], [28, 86], [30, 85], [32, 84], [34, 83], [36, 82], [38, 81], [40, 80], [42, 79], [44, 78], [46, 77], [48, 76], [50, 75], [52, 74], [54, 73], [56, 72], [58, 71], [60, 70], [62, 69], [64, 68], [66, 67], [68, 66], [70, 65], [72, 64], [74, 63], [76, 62], [78, 61], [80, 60], [82, 59], [84, 58], [86, 57], [88, 56], [90, 55], [92, 54], [94, 53], [96, 52], [98, 51], [100, 50]]) == 66\n assert candidate(n = 200,restrictions = [[2, 1], [50, 50], [150, 20], [100, 30], [180, 10]]) == 64\n assert candidate(n = 1000000,restrictions = [[200000, 300000], [400000, 100000], [600000, 200000], [800000, 400000], [1000000, 500000]]) == 550000\n assert candidate(n = 1000,restrictions = [[10, 900], [20, 800], [30, 700], [40, 600], [50, 500], [60, 400], [70, 300], [80, 200], [90, 100]]) == 999\n assert candidate(n = 10000,restrictions = [[100, 50], [200, 40], [300, 30], [400, 20], [500, 10], [600, 0], [700, 10], [800, 20], [900, 30]]) == 9130\n assert candidate(n = 200,restrictions = [[10, 100], [20, 90], [30, 80], [40, 70], [50, 60], [60, 50], [70, 40], [80, 30], [90, 20], [100, 10], [110, 20], [120, 30], [130, 40], [140, 50], [150, 60], [160, 70], [170, 80], [180, 90], [190, 100], [200, 110]]) == 110\n assert candidate(n = 500,restrictions = [[50, 10], [100, 20], [150, 10], [200, 20], [250, 10], [300, 20], [350, 10], [400, 20], [450, 10], [500, 20]]) == 40\n assert candidate(n = 50,restrictions = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10]]) == 12\n assert candidate(n = 5000,restrictions = [[500, 500], [1000, 400], [1500, 600], [2000, 500], [2500, 700], [3000, 400], [3500, 600], [4000, 500], [4500, 700], [5000, 400]]) == 850\n assert candidate(n = 500,restrictions = [[100, 10], [200, 200], [300, 150], [400, 100], [500, 50]]) == 180\n assert candidate(n = 300,restrictions = [[30, 2], [60, 4], [90, 6], [120, 8], [150, 10], [180, 12], [210, 14], [240, 16], [270, 18]]) == 48\n assert candidate(n = 100,restrictions = [[10, 5], [30, 10], [50, 5], [70, 10], [90, 5]]) == 17\n assert candidate(n = 100,restrictions = [[20, 15], [30, 25], [40, 35], [50, 45], [60, 55], [70, 65], [80, 75], [90, 85]]) == 95\n assert candidate(n = 1000,restrictions = [[10, 5], [20, 15], [30, 10], [40, 20], [50, 15], [60, 25], [70, 20], [80, 30], [90, 25], [100, 35]]) == 935\n assert candidate(n = 20,restrictions = [[3, 2], [6, 3], [15, 5], [18, 4]]) == 8\n assert candidate(n = 1000,restrictions = [[100, 100], [200, 900], [300, 300], [400, 700], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900]]) == 999\n assert candidate(n = 10000000,restrictions = [[1000000, 500000], [2000000, 1000000], [3000000, 1500000], [4000000, 2000000], [5000000, 2500000], [6000000, 3000000], [7000000, 3500000], [8000000, 4000000], [9000000, 4500000]]) == 5500000\n assert candidate(n = 500,restrictions = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10]]) == 460\n assert candidate(n = 2000,restrictions = [[500, 500], [1000, 500], [1500, 500]]) == 1000\n assert candidate(n = 2000,restrictions = [[500, 100], [1000, 500], [1500, 200], [2000, 1000]]) == 700\n assert candidate(n = 200,restrictions = [[2, 198], [4, 196], [6, 194], [8, 192], [10, 190], [12, 188], [14, 186], [16, 184], [18, 182], [20, 180]]) == 199\n assert candidate(n = 10000000,restrictions = [[1000000, 1000000], [3000000, 3000000], [5000000, 5000000], [7000000, 7000000], [9000000, 9000000]]) == 9999999\n assert candidate(n = 500000,restrictions = [[100000, 100000], [200000, 200000], [300000, 300000], [400000, 400000], [500000, 500000]]) == 499999\n assert candidate(n = 100000,restrictions = [[5000, 1000], [15000, 2000], [25000, 3000], [35000, 4000], [45000, 5000], [55000, 6000], [65000, 7000], [75000, 8000], [85000, 9000], [95000, 10000]]) == 15000\n assert candidate(n = 10000,restrictions = [[500, 5000], [1000, 10000], [1500, 15000], [2000, 20000], [2500, 25000], [3000, 30000]]) == 9999\n assert candidate(n = 1000000,restrictions = [[1000, 500], [2000, 1000], [3000, 750], [4000, 1500], [5000, 1250], [6000, 2000], [7000, 1750], [8000, 2500], [9000, 2250], [10000, 3000]]) == 993000\n assert candidate(n = 10000,restrictions = [[1000, 500], [2000, 750], [3000, 1000], [4000, 1250], [5000, 1500]]) == 6500\n assert candidate(n = 1000000,restrictions = [[100000, 100000], [200000, 200000], [300000, 300000], [400000, 400000], [500000, 500000], [600000, 600000], [700000, 700000], [800000, 800000], [900000, 900000]]) == 999999\n", "comparison": "exact"}, "public_tests": ["5\n[[2,1],[4,1]]", "6\n[]", "10\n[[5,3],[2,5],[7,4],[10,3]]"], "hints": ["Is it possible to find the max height if given the height range of a particular building?", "You can find the height range of a restricted building by doing 2 passes from the left and right."], "metadata": {"canonical_parameter_names": ["n", "restrictions"], "leetcode_dataset_entry_point": "Solution().maxBuilding", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:24+00:00", "tests_total": 87, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "math", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxBuilding($n, $restrictions) {", "container": "Solution", "callable": "maxBuilding", "parameters": [{"name": "n", "type": "Integer"}, {"name": "restrictions", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1844, "task_id": "replace-all-digits-with-characters", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.\n\nYou must perform an operation shift(c, x), where c is a character and x is a digit, that returns the x^th character after c.\n\n- For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.\n\nFor every odd index i, you want to replace the digit s[i] with the result of the shift(s[i-1], s[i]) operation.\n\nReturn s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.\n\nNote that shift(c, x) is not a preloaded function, but an operation to be implemented as part of the solution.\n\nExample 1:\n\nInput: s = \"a1c1e1\"\nOutput: \"abcdef\"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'\n\nExample 2:\n\nInput: s = \"a1b2c3d4e\"\nOutput: \"abbdcfdhe\"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists only of lowercase English letters and digits.\n- shift(s[i-1], s[i]) <= 'z' for all odd indices i.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"x1y2z3a4b5c6d7e8f9g0\") == \"xyy{z}aebgcidkemfogg\"\n assert candidate(s = \"x5y5z5\") == \"x}y~z\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0\") == \"ajbjcjdjejfjgjhjijjj\"\n assert candidate(s = \"a9b9c9d9\") == \"ajbkcldm\"\n assert candidate(s = \"z0y0x0w0\") == \"zzyyxxww\"\n assert candidate(s = \"a0b0c0d0\") == \"aabbccdd\"\n assert candidate(s = \"m9l8k7j6\") == \"mvltkrjp\"\n assert candidate(s = \"z0y1x2w3\") == \"zzyzxzwz\"\n assert candidate(s = \"z0y0x0w0v0\") == \"zzyyxxwwvv\"\n assert candidate(s = \"a0b0c0d0e0f0g0h0i0j0\") == \"aabbccddeeffgghhiijj\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1\") == \"ajbjcjdjejfjgjhjij\"\n assert candidate(s = \"t1s2r3q4p5o6n7m8l9k0\") == \"tusuruqupuounumulukk\"\n assert candidate(s = \"s9r8q7p6o5n4m3l2k1j0\") == \"s|rzqxpvotnrmplnkljj\"\n assert candidate(s = \"p2r4t6v8\") == \"prrvtzv~\"\n assert candidate(s = \"m0n1o2p3\") == \"mmnooqps\"\n assert candidate(s = \"q2w3e4r5\") == \"qswzeirw\"\n assert candidate(s = \"t1t2t3t4\") == \"tutvtwtx\"\n assert candidate(s = \"a1b2c3d4e\") == \"abbdcfdhe\"\n assert candidate(s = \"p1q2r3s4t\") == \"pqqsruswt\"\n assert candidate(s = \"a1c1e1\") == \"abcdef\"\n assert candidate(s = \"z0y2x3w4v\") == \"zzy{x{w{v\"\n assert candidate(s = \"q9r8s7t6u5\") == \"qzrzsztzuz\"\n assert candidate(s = \"x2y3z4\") == \"xzy|z~\"\n assert candidate(s = \"q9r8s7t6\") == \"qzrzsztz\"\n assert candidate(s = \"s0t1u2v3w4x5y6z7\") == \"sstuuwvyw{x}yz\"\n assert candidate(s = \"m9l8k7j6i5h4g3f2e1d0\") == \"mvltkrjpinhlgjfhefdd\"\n assert candidate(s = \"s9s8s7s6\") == \"s|s{szsy\"\n assert candidate(s = \"p2o3n4m5l6\") == \"prornrmrlr\"\n assert candidate(s = \"t2r3e4w5q6p7o8i9u0y1t2r3e4w\") == \"tvrueiw|qwpwowiruuyztvrueiw\"\n assert candidate(s = \"m4n3o2p1q0r9s8t7u6v5w4x3y2z1\") == \"mqnqoqpqqqr{s{t{u{v{w{x{y{z{\"\n assert candidate(s = \"z1y2x3w4v5u6t7s8r9q0p1o2n3m4l5k6j7i8h9g0f1e2d3c4b5a6\") == \"z{y{x{w{v{u{t{s{r{qqpqoqnqmqlqkqjqiqhqggfgegdgcgbgag\"\n assert candidate(s = \"n9m8l7k6j5i4h3g2f1e0d9c8b7a6z5y4x3w2v1u0t9s8r7q6p5\") == \"nwmulskqjoimhkgifgeedmckbiagzy}x{wyvwuut}s{ryqwpu\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p0o0n0m0l0k0j0i0h0g0f0e0d0c0b0a0\") == \"zyxw}v{uytwsursqqppoonnmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"z8y6x4w2v0u8t6s4r2q0p8o6n4m2l0k8j6i4h2g0f8e6d4c2b0a8\") == \"zyx|wyvvu}tzswrtqqpxounrmollksjpimhjggfnekdhcebbai\"\n assert candidate(s = \"b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9u0v1w2x3y4z5\") == \"bccedgeifkgmhoiqjskklmmonqospuqwrys{t}uuvwwyx{y}z\"\n assert candidate(s = \"m3n5o7p9q1r3s5t7u9v1w3x5y7z9a1b3c5d7e9f1g3h5i7j9\") == \"mpnsovpyqrrusxt{u~vwwzx}yzabbechdkenfggjhmipjs\"\n assert candidate(s = \"c3d2e1f0g9h8i7j6k5l4m3n2o1p0q9r8\") == \"cfdfefffgphpipjpkplpmpnpopppqzrz\"\n assert candidate(s = \"d3c2b1a0z9y8x7w6v5u4t3s2r1q0p9o8n7m6l5k4j3i2h1g0f9\") == \"dgcebcaazyxw}v{uytwsursqqpyownumslqkojmikhiggfo\"\n assert candidate(s = \"a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7\") == \"acbecgdiekfmgohqiijkkmlomqnsoupwqyr{sstuuwvyw{x}yz\"\n assert candidate(s = \"d3f5h7j9l1n3p5r7t9v1x3z5b7d9f1h3j5l7n9p1r3t5v7x9\") == \"dgfkhojslmnqpuryt}vwx{zbidmfghkjolsnwpqrutyv}x\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p9o8n7m6l5k4j3i2h1g0f9e8d7c6b5a4\") == \"zyxw}v{uytwsursqqpyownumslqkojmikhiggfoemdkcibgae\"\n assert candidate(s = \"z1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4\") == \"z{acbecgdiekfmgohqiijkkmlomqnsoupwqyr{sstuuwvyw{\"\n assert candidate(s = \"v1u2t3s4r5q6p7o8n9m0l1k2j3i4h5g6f7e8d9c0b1a2z3y4x5\") == \"vwuwtwswrwqwpwownwmmlmkmjmimhmgmfmemdmccbcacz}y}x}\"\n assert candidate(s = \"b2c4d6e8f0g2h4i6j8k0l2m4n6o8p0q2r4s6t8u0v2w4x6y8z0a2\") == \"bdcgdjemffgihliojrkklnmqntowppqsrvsyt|uuvxw{x~yzzac\"\n assert candidate(s = \"a9z8y7x6w5v4u3t2s1r0\") == \"ajzyx~w|vzuxtvstrr\"\n assert candidate(s = \"n7m6l5k4j3i2h1g0f5e4d3\") == \"numslqkojmikhiggfkeidg\"\n assert candidate(s = \"a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1\") == \"abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{\"\n assert candidate(s = \"b5c6d7e8f9g0h1i2j3k4l5m6n7o8p9q0r1s2t3u4v5w6x7y8z9\") == \"bgcidkemfogghiikjmkolqmsnuowpyqqrssutwuyv{w}xyz\"\n assert candidate(s = \"q0r2s4t6u8v0w2x4y6z8\") == \"qqrtswtzu}vvwyx|yz\"\n assert candidate(s = \"s5r4q3p2o1n0m9l8k7j6i5h4g3f2e1d0c9b8a7z6y5x4w3v2u1t0s9\") == \"sxrvqtpropnnmvltkrjpinhlgjfhefddclbjahzy~x|wzvxuvtts|\"\n assert candidate(s = \"x2y3z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8a9\") == \"xzy|z|adbfchdjelfngphhijjlknlpmrntovpxqzrrsttvuxvzw|x~yzaj\"\n assert candidate(s = \"s1t2u3v4w5x6y7z8a9b0c1d2e3f4g5h6i7j8k9l0m1n2o3p4q5r6\") == \"sttvuxvzw|x~yzajbbcddfehfjglhnipjrktllmnnporptqvrx\"\n assert candidate(s = \"t4r2q0p8o6n4m2l0k8j6i4h2g0f8e6d4c2b0a8y6x4w2v0u8t6s4\") == \"txrtqqpxounrmollksjpimhjggfnekdhcebbaiyx|wyvvu}tzsw\"\n assert candidate(s = \"a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0\") == \"acbecgdiekfmgohqiijkkmlomqnsoupwqyr{ss\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9\") == \"abbdcfdhejflgnhpirjjkllnmpnrotpvqxrzs|ttuvvxwzx|y~zahbjcl\"\n assert candidate(s = \"x2y4z6a8b0c2d4e6f8g0h2i4j6k8l0m2n4o6p8q0r2s4t6u8v0\") == \"xzy}zaibbcedhekfngghjimjpksllmonroupxqqrtswtzu}vv\"\n assert candidate(s = \"t4s3r2q1p0o9n8m7l6k5j4i3h2g1f0\") == \"txsvrtqrppoxnvmtlrkpjnilhjghff\"\n assert candidate(s = \"a2c4e6g8i0k2m4o6q8s0u2w4y6b8d0f2h4j6l8n0p2r4t6v8x0\") == \"accgekgoiikmmqouqyssuww{ybjddfhhljpltnnprrvtzv~xx\"\n assert candidate(s = \"m1n2o3p4q5r6s7t8u9v0w1x2y3z4\") == \"mnnporptqvrxszt|u~vvwxxzy|z~\"\n assert candidate(s = \"m7l6k5j4i3h2g1f0e9d8c7b6a5\") == \"mtlrkpjnilhjghffendlcjbhaf\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j8i7h6g5f4e3d2c1b0a9\") == \"abbdcfdhejflgnhpirjriphnglfjehdfcdbbaj\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0\") == \"zyxw}v{uytwsursqq\"\n assert candidate(s = \"y7x6w5v4u3t2s1r0q9p8o7n6m5l4k3j2i1h0g9f8e7d6c5b4a3z2y1x0w9v8u7t6s5r4q3p2o1n0\") == \"yx~w|vzuxtvstrrqzpxovntmrlpknjlijhhgpfneldjchbfadz|yzxxwv~u|tzsxrvqtpropnn\"\n assert candidate(s = \"z2y4x6w8v0u2t4s6r8q0p2o4n6m8l0k2j4i6h8g0f2e4d6c8b0\") == \"z|y}x~wvvuwtxsyrzqqprosntmullkmjniohpggfheidjckbb\"\n assert candidate(s = \"a2b4c6d8e0f1g3h5i7j9\") == \"acbfcidleefggjhmipjs\"\n assert candidate(s = \"b2d3f4h5j6l7n8p9r0t1v2x3z4\") == \"bddgfjhmjplsnvpyrrtuvxx{z~\"\n assert candidate(s = \"q2r3s4t5u6v7w8x9y0z1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7\") == \"qsruswtyu{v}wxyyz{acbecgdiekfmgohqiijkkmlomqnsoupw\"\n assert candidate(s = \"x9y8z7a6b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q0r9s8t7u6\") == \"xyzagbgcgdgegfggghqiqjqkqlqmqnqoqpqqqr{s{t{u{\"\n assert candidate(s = \"t2h4n6m8g0p2r4l6t8s0q2e4v6s8g0t2l4m6b8c0t2r4l6n8m0\") == \"tvhlntmuggprrvlrt|ssqseiv|s{ggtvlpmsbjcctvrvlrnvmm\"\n assert candidate(s = \"x2y3z4a5b6c7d8e9f0g1h2i3j4\") == \"xzy|z~afbhcjdlenffghhjiljn\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0k9l8m7n6\") == \"ajbjcjdjejfjgjhjijjjktltmtnt\"\n assert candidate(s = \"n5n4n3n2n1n0n9n8n7n6\") == \"nsnrnqnpnonnnwnvnunt\"\n assert candidate(s = \"d7c6b5a4z3y2x1w0v9u8t7s6r5q4p3o2n1\") == \"dkcibgaez}y{xywwvu}t{syrwqupsoqno\"\n assert candidate(s = \"q7r5s3t1u9v7w5x3y1z9a7b5c3d1e9f7g5h3i1j9k7l5m3n1o9p7\") == \"qxrwsvtuu~v}w|x{yzzahbgcfdeenfmglhkijjskrlqmpnooxpw\"\n assert candidate(s = \"x2y4z6a8b0c2d4e6f8g0h2i4j6k8l0m2n4o6p8q0r2s4t6u8v0w2y4z6\") == \"xzy}zaibbcedhekfngghjimjpksllmonroupxqqrtswtzu}vvwyy}z\"\n assert candidate(s = \"n5m4l3k2j1i0h9g8f7e6d5c4b3a2z1y0x9w8v7u6t5s4r3q2p1o0\") == \"nsmqlokmjkiihqgofmekdicgbeacz{yyxwv}u{tyswruqspqoo\"\n assert candidate(s = \"a1b1c1d1e1f1g1h1i1j1\") == \"abbccddeeffgghhiijjk\"\n assert candidate(s = \"z9y8x7w6v5u4t3s2r1q0p\") == \"zyxw}v{uytwsursqqp\"\n assert candidate(s = \"a1z2y3x4w5v6u7t8s9r0q1p2o3n4m5l6k7j8i9h0g1f2e3d4c5b6a7\") == \"abz|y|x|w|v|u|t|s|rrqrprornrmrlrkrjrirhhghfhehdhchbhah\"\n assert candidate(s = \"n9m8l7k6j5i4h3g2f1e0d9c8b7a6n9m8l7k6j5i4h3g2f1e0\") == \"nwmulskqjoimhkgifgeedmckbiagnwmulskqjoimhkgifgee\"\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0a1b2c3d4e5f6g7h8i9j0a1b2c3d4\") == \"abbdcfdhejflgnhpirjjabbdcfdhejflgnhpirjjabbdcfdh\"\n assert candidate(s = \"b5c3d7e2f4g6h1i5j3k7l2m4n6o1p5q3r7s2t4u6v1w5x3y7z2\") == \"bgcfdkegfjgmhiinjmkrlnmqntoppuqtrysutxu{vww|x{yz|\"\n assert candidate(s = \"l8k7j6i5h4g3f2e1d0c9b8a7z6y5x4w3v2u1t0s9r8q7p6o5n4m3l2\") == \"ltkrjpinhlgjfhefddclbjahzy~x|wzvxuvtts|rzqxpvotnrmpln\"\n assert candidate(s = \"z1y2x3w4v5u6t7s8r9q0p1o2n3m4\") == \"z{y{x{w{v{u{t{s{r{qqpqoqnqmq\"\n assert candidate(s = \"t2r3q4p5o6n7m8l9k0j1i2h3g4f5e6d7c8b9a0\") == \"tvruqupuounumulukkjkikhkgkfkekdkckbkaa\"\n assert candidate(s = \"t8r7e6w5q4u3i2o1p0l9k8j7h6g5f4d3c2b1a0\") == \"t|ryekw|quuxikopppluksjqhnglfjdgcebcaa\"\n assert candidate(s = \"a1c2e3g4i5k6m7o8q9s0u1w2y3\") == \"abceehgkinkqmtowqzssuvwyy|\"\n assert candidate(s = \"q9r8s7t6u5v4w3x2y1z0a9b8c7d6e5f4g3h2i1j0k9l8m7n6o5p4\") == \"qzrzsztzuzvzwzxzyzzzajbjcjdjejfjgjhjijjjktltmtntotpt\"\n assert candidate(s = \"t0u2v4w6x8y0z2a4b6c8d0e2f4g6h8i0j2k4l6m8n0o2p4q6r8s0t2u4v6w8x0y2z4\") == \"ttuwvzw}xyyz|aebhckddegfjgmhpiijlkolrmunnoqptqwrzsstvuyv|wxxy{z~\"\n assert candidate(s = \"q2r3s4t5u6v7w8x9y0z1\") == \"qsruswtyu{v}wxyyz{\"\n assert candidate(s = \"s1t2u3v4w5x6y7z8a9b0c1d2e3f4g5h6i7j8k9l0m1n2o3p4q5\") == \"sttvuxvzw|x~yzajbbcddfehfjglhnipjrktllmnnporptqv\"\n assert candidate(s = \"b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6\") == \"bccedgeifkgmhoiqjskklmmonqospuqw\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0k9l8\") == \"ajbjcjdjejfjgjhjijjjktlt\"\n assert candidate(s = \"v9w8x7y6z5a4b3c2d1e0f9g8h7\") == \"vwxyzaebecedeeefogoho\"\n assert candidate(s = \"b5c7d9e2f0g1h3i5j7k9l1m3n5o7p9q1r3s5t7u9\") == \"bgcjdmegffghhkinjqktlmmpnsovpyqrrusxt{u~\"\n assert candidate(s = \"x9y8z7a6b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q0r9\") == \"xyzagbgcgdgegfggghqiqjqkqlqmqnqoqpqqqr{\"\n assert candidate(s = \"a9z8y7x6w5v4u3t2s1r0q9p8o7n6m5l4k3j2i1h0g9f8e7d6c5b4a3\") == \"ajzyx~w|vzuxtvstrrqzpxovntmrlpknjlijhhgpfneldjchbfad\"\n assert candidate(s = \"y0x1w2v3u4t5s6r7q8p9o0n1m2l3k4j5i6h7g8f9e0d1c2b3a4\") == \"yyxywyvyuytysyryqypyoonomolokojoiohogofoeedecebeae\"\n assert candidate(s = \"n5m4l3k2j1i0h9g8f7e6d5c4b3a2\") == \"nsmqlokmjkiihqgofmekdicgbeac\"\n assert candidate(s = \"a2b4c6d8e0f2g4h6i8j0k2l4m6n8o0p2q4r6s8t0u2v4w6x8y0z2\") == \"acbfcidleefhgkhniqjjkmlpmsnvooprqurxs{ttuwvzw}xyyz|\"\n assert candidate(s = \"a2b2c2d2e2f2g2h2i2j2k2l2m2n2o2p2q2r2s2t2u2v2w2x2y2z2\") == \"acbdcedfegfhgihjikjlkmlnmonpoqprqsrtsutvuwvxwyxzy{z|\"\n assert candidate(s = \"a9b8c7d6e5f4g3h2i1j0k9l8m7n6o5p4q3r2s1t0u9v8w7x6y5z4\") == \"ajbjcjdjejfjgjhjijjjktltmtntotptqtrtstttu~v~w~x~y~z~\"\n assert candidate(s = \"t1s2r3q4p5o6n7m8l9k0j1i2h3g4f5e6d7c8b9a0z1y2x3w4v5u\") == \"tusuruqupuounumulukkjkikhkgkfkekdkckbkaaz{y{x{w{v{u\"\n assert candidate(s = \"z1y2x3w4v5u6t7s8r9q0p1o2n3\") == \"z{y{x{w{v{u{t{s{r{qqpqoqnq\"\n assert candidate(s = \"y2x3w4v5u6t7s8r9q0p1o2n3m4l5k6j7i8h9g0f1e2d3c4b5a6\") == \"y{x{w{v{u{t{s{r{qqpqoqnqmqlqkqjqiqhqggfgegdgcgbgag\"\n assert candidate(s = \"y3x5w7v9u1t3s5r7q9p1o3n5m7l9k1j3i5h7g9f1e3d5c7b9a1\") == \"y|x}w~vuvtwsxryqzpqornsmtlukljminhogpfgehdicjbkab\"\n assert candidate(s = \"s9r8q7p6o5n4m3l2k1j0i9h8g7f6e5d4c3b2a1z0y9x8w7v6u5t4s3r2q1p0\") == \"s|rzqxpvotnrmplnkljjirhpgnflejdhcfbdabzzyxw~v|uztxsvrtqrpp\"\n assert candidate(s = \"m8n7o6p5q4r3s2t1u0v9w8x7y6z5a4b3c2d1e0f9g8h7i6j5k4l3m2\") == \"munuoupuqurusutuuuvwxyzaebecedeeefogohoiojokolomo\"\n assert candidate(s = \"q2w3e4r5t6y7u8i9o0p1a2s3d4f5g6h7j8k9l0\") == \"qswzeirwtzyu}iroopqacsvdhfkgmhojrktll\"\n assert candidate(s = \"b5c6d7e8f9g0h1i2j3k4l5\") == \"bgcidkemfogghiikjmkolq\"\n assert candidate(s = \"m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2g3h4i5j6k7l8\") == \"mpnrotpvqxrzs|ttuvvxwzx|y~zahbjclddeffhgjhlinjpkrlt\"\n assert candidate(s = \"q1w2e3r4t5y6u7i8o9p0a1s2d3f4g5\") == \"qrwyehrvtyyu|iqoxppabsudgfjgl\"\n assert candidate(s = \"q2w3e4r5t6y7u8i9o0p1a2s3d4f5g6h7j8k9l0z1x2c3v4b5n6m7\") == \"qswzeirwtzyu}iroopqacsvdhfkgmhojrktllz{xzcfvzbgntmt\"\n assert candidate(s = \"n4m3l2k1j0i9h8g7f6e5d4c3b2a1z0y9x8w7v6u5t4s3r2q1p0\") == \"nrmplnkljjirhpgnflejdhcfbdabzzyxw~v|uztxsvrtqrpp\"\n", "comparison": "exact"}, "public_tests": ["\"a1c1e1\"", "\"a1b2c3d4e\""], "hints": ["We just need to replace every even positioned character with the character s[i] positions ahead of the character preceding it", "Get the position of the preceeding character in alphabet then advance it s[i] positions and get the character at that position"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().replaceDigits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:29+00:00", "tests_total": 115, "tests_dropped": 1, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function replaceDigits($s) {", "container": "Solution", "callable": "replaceDigits", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1846, "task_id": "maximum-element-after-decreasing-and-rearranging", "difficulty": "Medium", "problem_description": "You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:\n\n- The value of the first element in arr must be 1.\n- The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.\n\nThere are 2 types of operations that you can perform any number of times:\n\n- Decrease the value of any element of arr to a smaller positive integer.\n- Rearrange the elements of arr to be in any order.\n\nReturn the maximum possible value of an element in arr after performing the operations to satisfy the conditions.\n\nExample 1:\n\nInput: arr = [2,2,1,2,1]\nOutput: 2\nExplanation:\nWe can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].\nThe largest element in arr is 2.\n\nExample 2:\n\nInput: arr = [100,1,1000]\nOutput: 3\nExplanation:\nOne possible way to satisfy the conditions is by doing the following:\n1. Rearrange arr so it becomes [1,100,1000].\n2. Decrease the value of the second element to 2.\n3. Decrease the value of the third element to 3.\nNow arr = [1,2,3], which satisfies the conditions.\nThe largest element in arr is 3.\n\nExample 3:\n\nInput: arr = [1,2,3,4,5]\nOutput: 5\nExplanation: The array already satisfies the conditions, and the largest element is 5.\n\nConstraints:\n\n- 1 <= arr.length <= 10^5\n- 1 <= arr[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [3, 2, 1]) == 3\n assert candidate(arr = [5, 4, 3, 2, 1]) == 5\n assert candidate(arr = [1, 1000000000, 2, 3, 4]) == 5\n assert candidate(arr = [9, 7, 5, 3, 1]) == 5\n assert candidate(arr = [5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [1000000000, 1, 1000000000, 1, 1000000000]) == 4\n assert candidate(arr = [1, 10, 20, 30, 40]) == 5\n assert candidate(arr = [1, 1000000000, 2, 1000000000, 3]) == 5\n assert candidate(arr = [1]) == 1\n assert candidate(arr = [100, 1, 1000]) == 3\n assert candidate(arr = [1, 1, 1, 1, 1]) == 1\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(arr = [1, 10, 100, 1000, 10000]) == 5\n assert candidate(arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(arr = [1, 2, 3, 4, 5]) == 5\n assert candidate(arr = [2, 3, 4, 5, 6]) == 5\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(arr = [2, 2, 1, 2, 1]) == 2\n assert candidate(arr = [1, 3, 5, 7, 9]) == 5\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(arr = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 4\n assert candidate(arr = [999999999, 1, 999999998, 2, 999999997, 3, 999999996, 4, 999999995, 5]) == 10\n assert candidate(arr = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 4\n assert candidate(arr = [1, 3, 6, 10, 15, 21]) == 6\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\n assert candidate(arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10]) == 10\n assert candidate(arr = [100, 50, 25, 12, 6, 3, 1]) == 7\n assert candidate(arr = [1000000000, 1, 1000000000, 1, 1000000000]) == 4\n assert candidate(arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 6\n assert candidate(arr = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(arr = [1, 100, 2, 101, 3, 102, 4, 103, 5, 104]) == 10\n assert candidate(arr = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [100, 100, 100, 100, 100, 100, 100]) == 7\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(arr = [1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 8, 9]) == 9\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(arr = [50, 25, 75, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 13\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 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(arr = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5\n assert candidate(arr = [1000000000, 1000000000, 1000000000, 1000000000, 1]) == 5\n assert candidate(arr = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == 8\n assert candidate(arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 16\n assert candidate(arr = [1, 1000000000, 2, 999999999, 3, 999999998]) == 6\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(arr = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 10\n assert candidate(arr = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(arr = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 20\n assert candidate(arr = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(arr = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(arr = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 20\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(arr = [5, 3, 1, 4, 2]) == 5\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 15\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\n assert candidate(arr = [100, 50, 20, 10, 5, 2, 1, 2, 5, 10, 20, 50, 100, 150, 200, 250, 300]) == 16\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 12\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(arr = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) == 20\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 13\n assert candidate(arr = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120]) == 15\n assert candidate(arr = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(arr = [10, 1, 2, 2, 3, 4, 5]) == 6\n assert candidate(arr = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == 10\n assert candidate(arr = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 20\n assert candidate(arr = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(arr = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(arr = [10, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(arr = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 20\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 5\n assert candidate(arr = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 20\n assert candidate(arr = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(arr = [50, 40, 30, 20, 10, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 2\n assert candidate(arr = [5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(arr = [2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7]) == 8\n assert candidate(arr = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 10\n assert candidate(arr = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 3\n assert candidate(arr = [50, 40, 30, 20, 10, 1, 2, 3, 4, 5]) == 10\n assert candidate(arr = [1, 999999999, 999999998, 999999997, 999999996, 999999995]) == 6\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 10\n assert candidate(arr = [1000, 1000, 1000, 1000, 1000]) == 5\n assert candidate(arr = [1000000000, 1000000000, 1000000000, 1, 1, 1]) == 4\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(arr = [999999999, 999999998, 999999997, 999999996, 999999995, 1]) == 6\n assert candidate(arr = [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]) == 10\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]) == 10\n assert candidate(arr = [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(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(arr = [5, 4, 3, 2, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(arr = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 5\n assert candidate(arr = [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]) == 10\n assert candidate(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 20\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(arr = [5, 4, 3, 2, 1, 1, 1]) == 5\n assert candidate(arr = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 11\n assert candidate(arr = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(arr = [1, 2, 3, 4, 5, 10, 100, 1000]) == 8\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]) == 30\n assert candidate(arr = [10, 5, 15, 20, 1, 3, 8]) == 7\n assert candidate(arr = [5, 4, 3, 2, 1]) == 5\n assert candidate(arr = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900]) == 10\n assert candidate(arr = [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(arr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5]) == 15\n assert candidate(arr = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == 20\n assert candidate(arr = [1000000000, 1, 1000000000, 2, 1000000000, 3]) == 6\n assert candidate(arr = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 5\n assert candidate(arr = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 5\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(arr = [3, 3, 3, 3, 3, 2, 2, 2, 1, 1]) == 3\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2\n assert candidate(arr = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 10\n assert candidate(arr = [5, 4, 3, 2, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(arr = [1, 1000000000, 2, 999999999, 3]) == 5\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(arr = [1, 1000000000, 2, 999999999, 3, 999999998]) == 6\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == 2\n assert candidate(arr = [5, 4, 3, 2, 1, 1, 1]) == 5\n assert candidate(arr = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 15\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(arr = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5]) == 5\n assert candidate(arr = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 15\n assert candidate(arr = [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(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 2\n assert candidate(arr = [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]) == 15\n assert candidate(arr = [1, 2, 3, 100, 200, 300, 400, 500]) == 8\n", "comparison": "exact"}, "public_tests": ["[2,2,1,2,1]", "[100,1,1000]", "[1,2,3,4,5]"], "hints": ["Sort the Array.", "Decrement each element to the largest integer that satisfies the conditions."], "metadata": {"canonical_parameter_names": ["arr"], "leetcode_dataset_entry_point": "Solution().maximumElementAfterDecrementingAndRearranging", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:31+00:00", "tests_total": 135, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maximumElementAfterDecrementingAndRearranging($arr) {", "container": "Solution", "callable": "maximumElementAfterDecrementingAndRearranging", "parameters": [{"name": "arr", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1847, "task_id": "closest-room", "difficulty": "Hard", "problem_description": "There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomId_i, size_i] denotes that there is a room with room number roomId_i and size equal to size_i. Each roomId_i is guaranteed to be unique.\n\nYou are also given k queries in a 2D array queries where queries[j] = [preferred_j, minSize_j]. The answer to the j^th query is the room number id of a room such that:\n\n- The room has a size of at least minSize_j, and\n- abs(id - preferred_j) is minimized, where abs(x) is the absolute value of x.\n\nIf there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.\n\nReturn an array answer of length k where answer[j] contains the answer to the j^th query.\n\nExample 1:\n\nInput: rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\nOutput: [3,-1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.\nQuery = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.\nQuery = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.\n\nExample 2:\n\nInput: rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\nOutput: [2,1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.\nQuery = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.\nQuery = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3.\n\nConstraints:\n\n- n == rooms.length\n- 1 <= n <= 10^5\n- k == queries.length\n- 1 <= k <= 10^4\n- 1 <= roomId_i, preferred_j <= 10^7\n- 1 <= size_i, minSize_j <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8]],queries = [[15, 4], [25, 7], [35, 2]]) == [10, 30, 30]\n assert candidate(rooms = [[5, 5], [10, 5], [15, 5], [20, 5]],queries = [[7, 5], [12, 5], [17, 5], [22, 5]]) == [5, 10, 15, 20]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == [1, 2, 3, 4, 5, -1]\n assert candidate(rooms = [[10, 5], [20, 4], [30, 3]],queries = [[15, 3], [25, 4], [35, 5]]) == [10, 20, 10]\n assert candidate(rooms = [[2, 2], [1, 2], [3, 2]],queries = [[3, 1], [3, 3], [5, 2]]) == [3, -1, 3]\n assert candidate(rooms = [[10, 5], [20, 4], [30, 3]],queries = [[10, 5], [25, 3], [15, 4]]) == [10, 20, 10]\n assert candidate(rooms = [[5, 10], [10, 10], [15, 10]],queries = [[5, 10], [10, 10], [15, 10], [20, 10]]) == [5, 10, 15, 15]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300]],queries = [[150, 150], [250, 250], [350, 350]]) == [200, 300, -1]\n assert candidate(rooms = [[7, 10], [6, 9], [5, 8], [4, 7], [3, 6]],queries = [[7, 10], [6, 9], [5, 8], [4, 7], [3, 6]]) == [7, 6, 5, 4, 3]\n assert candidate(rooms = [[7, 10], [15, 7], [25, 12]],queries = [[10, 10], [15, 7], [30, 10]]) == [7, 15, 25]\n assert candidate(rooms = [[1, 4], [2, 3], [3, 5], [4, 1], [5, 2]],queries = [[2, 3], [2, 4], [2, 5]]) == [2, 1, 3]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],queries = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 7]],queries = [[10, 5], [25, 4], [40, 8]]) == [10, 30, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[5, 5], [15, 10], [25, 15], [35, 20], [45, 25], [55, 30], [65, 35], [75, 40], [85, 45], [95, 50]]) == [5, 10, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998]],queries = [[10000000, 10000000], [9999999, 9999999], [9999998, 9999998]]) == [1, 2, 3]\n assert candidate(rooms = [[1, 1000], [2, 900], [3, 800], [4, 700], [5, 600], [6, 500], [7, 400], [8, 300], [9, 200], [10, 100]],queries = [[1, 1500], [2, 1400], [3, 1300], [4, 1200], [5, 1100], [6, 1000], [7, 900], [8, 800], [9, 700], [10, 600]]) == [-1, -1, -1, -1, -1, 1, 2, 3, 4, 5]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [[10, 5], [9, 15], [8, 25], [7, 35], [6, 45], [5, 55], [4, 65], [3, 75], [2, 85], [1, 95]]) == [10, 9, 8, 7, 6, 6, 7, 8, 9, 10]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996], [6, 9999995], [7, 9999994], [8, 9999993], [9, 9999992], [10, 9999991]],queries = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996], [6, 9999995], [7, 9999994], [8, 9999993], [9, 9999992], [10, 9999991], [11, 9999990]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]\n assert candidate(rooms = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997], [5, 999996], [6, 999995], [7, 999994], [8, 999993], [9, 999992], [10, 999991]],queries = [[1, 1000000], [2, 1000000], [3, 1000000], [4, 1000000], [5, 1000000], [6, 1000000], [7, 1000000], [8, 1000000], [9, 1000000], [10, 1000000]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(rooms = [[10000, 5000], [20000, 4000], [30000, 3000], [40000, 2000], [50000, 1000]],queries = [[5000, 3000], [15000, 2000], [25000, 1000], [35000, 500], [45000, 1]]) == [10000, 10000, 20000, 30000, 40000]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]],queries = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [11, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]\n assert candidate(rooms = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]],queries = [[1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, -1]\n assert candidate(rooms = [[1, 1], [10000000, 10000000]],queries = [[5000000, 1], [5000000, 10000000], [1, 1], [10000000, 10000000], [5000000, 5000000]]) == [1, 10000000, 1, 10000000, 10000000]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]],queries = [[150, 100], [250, 200], [350, 300], [450, 400], [550, 500], [650, 600], [750, 700], [850, 800], [950, 900], [1050, 1000]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(rooms = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10]],queries = [[3, 1], [6, 2], [9, 3], [12, 4], [15, 5], [18, 6], [21, 7], [24, 8], [27, 9], [30, 10], [33, 11]]) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, -1]\n assert candidate(rooms = [[5, 10], [10, 9], [15, 8], [20, 7], [25, 6], [30, 5], [35, 4]],queries = [[8, 7], [13, 6], [18, 5], [23, 4], [28, 3], [33, 2], [38, 1]]) == [10, 15, 20, 25, 30, 35, 35]\n assert candidate(rooms = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90], [95, 100]],queries = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45], [60, 55], [70, 65], [80, 75], [90, 85], [100, 95], [110, 105]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, -1]\n assert candidate(rooms = [[10000, 10000], [20000, 20000], [30000, 30000], [40000, 40000], [50000, 50000]],queries = [[5000, 9000], [15000, 19000], [25000, 29000], [35000, 39000], [45000, 49000]]) == [10000, 20000, 30000, 40000, 50000]\n assert candidate(rooms = [[1, 1], [10000000, 10000000], [5000000, 5000000], [1000000, 1000000], [100000, 100000], [10000, 10000], [1000, 1000], [100, 100], [10, 10], [100000000, 100000000]],queries = [[1, 1], [10000000, 10000000], [5000000, 5000000], [1000000, 1000000], [100000, 100000], [10000, 10000], [1000, 1000], [100, 100], [10, 10], [100000000, 100000000]]) == [1, 10000000, 5000000, 1000000, 100000, 10000, 1000, 100, 10, 100000000]\n assert candidate(rooms = [[1000, 5000], [2000, 4000], [3000, 3000], [4000, 2000], [5000, 1000]],queries = [[1500, 3000], [2500, 2000], [3500, 1000], [4500, 500], [5500, 1]]) == [1000, 2000, 3000, 4000, 5000]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450], [550, 550]]) == [100, 200, 300, 400, 500, -1]\n assert candidate(rooms = [[100000, 1], [100001, 1], [100002, 1], [100003, 1], [100004, 1], [100005, 1], [100006, 1], [100007, 1], [100008, 1], [100009, 1]],queries = [[100000, 2], [100001, 2], [100002, 2], [100003, 2], [100004, 2], [100005, 2], [100006, 2], [100007, 2], [100008, 2], [100009, 2]]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(rooms = [[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]],queries = [[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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1]\n assert candidate(rooms = [[1, 10], [10, 20], [100, 30], [1000, 40], [10000, 50]],queries = [[5, 5], [50, 15], [500, 25], [5000, 35], [50000, 45]]) == [1, 10, 100, 1000, 10000]\n assert candidate(rooms = [[1, 1], [10, 2], [100, 3], [1000, 4], [10000, 5], [100000, 6], [1000000, 7], [10000000, 8]],queries = [[5, 1], [50, 2], [500, 3], [5000, 4], [50000, 5], [500000, 6], [5000000, 7], [50000000, 8], [50000000, 9], [50000000, 10]]) == [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, -1, -1]\n assert candidate(rooms = [[10000000, 10000000], [1, 1], [5000000, 5000000], [2, 2], [9999999, 9999999]],queries = [[10000000, 10000000], [5000000, 5000000], [2, 1], [10000000, 1], [1, 10000000]]) == [10000000, 5000000, 2, 10000000, 10000000]\n assert candidate(rooms = [[500, 1000], [1000, 900], [1500, 800], [2000, 700], [2500, 600], [3000, 500], [3500, 400], [4000, 300], [4500, 200], [5000, 100]],queries = [[100, 500], [600, 400], [1100, 300], [1600, 200], [2100, 100], [2600, 50], [3100, 1], [3600, 1], [4100, 1], [4600, 1]]) == [500, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500]\n assert candidate(rooms = [[1, 10], [10, 9], [100, 8], [1000, 7], [10000, 6]],queries = [[1, 10], [10, 9], [100, 8], [1000, 7], [10000, 6], [5, 5], [50, 5], [500, 5], [5000, 5], [50000, 5]]) == [1, 10, 100, 1000, 10000, 1, 10, 100, 1000, 10000]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996], [6, 9999995]]) == [1, 2, 3, 4, 5, 5]\n assert candidate(rooms = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14]],queries = [[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]]) == [5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1]\n assert candidate(rooms = [[1, 5], [10, 15], [20, 25], [30, 35], [40, 45], [50, 55]],queries = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65]]) == [1, 10, 20, 30, 40, 50, -1]\n assert candidate(rooms = [[100, 100], [200, 90], [300, 80], [400, 70], [500, 60], [600, 50], [700, 40], [800, 30], [900, 20], [1000, 10]],queries = [[150, 80], [250, 70], [350, 60], [450, 50], [550, 40], [650, 30], [750, 20], [850, 10], [950, 5], [1050, 1]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(rooms = [[1, 10], [20, 9], [30, 8], [40, 7], [50, 6], [60, 5], [70, 4], [80, 3], [90, 2], [100, 1]],queries = [[15, 3], [25, 4], [35, 5], [45, 6], [55, 7], [65, 8], [75, 9], [85, 10], [95, 11], [105, 12]]) == [20, 20, 30, 40, 40, 30, 20, 1, -1, -1]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]],queries = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(rooms = [[10000000, 1], [9999999, 2], [9999998, 3], [9999997, 4], [9999996, 5], [9999995, 6], [9999994, 7], [9999993, 8], [9999992, 9], [9999991, 10]],queries = [[9999995, 3], [9999994, 4], [9999993, 5], [9999992, 6], [9999991, 7], [9999990, 8], [9999989, 9], [9999988, 10]]) == [9999995, 9999994, 9999993, 9999992, 9999991, 9999991, 9999991, 9999991]\n assert candidate(rooms = [[1, 10], [10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10], [90, 10]],queries = [[5, 10], [15, 10], [25, 10], [35, 10], [45, 10], [55, 10], [65, 10], [75, 10], [85, 10], [95, 10]]) == [1, 10, 20, 30, 40, 50, 60, 70, 80, 90]\n assert candidate(rooms = [[10000, 100], [20000, 200], [30000, 300], [40000, 400], [50000, 500], [60000, 600], [70000, 700], [80000, 800], [90000, 900], [100000, 1000]],queries = [[5000, 50], [15000, 150], [25000, 250], [35000, 350], [45000, 450], [55000, 550], [65000, 650], [75000, 750], [85000, 850], [95000, 950]]) == [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]\n assert candidate(rooms = [[1, 10000000], [2, 9000000], [3, 8000000], [4, 7000000], [5, 6000000]],queries = [[1, 10000000], [2, 9000000], [3, 8000000], [4, 7000000], [5, 6000000], [10000000, 1]]) == [1, 2, 3, 4, 5, 5]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]]) == [5, 5, 5, 5, 5, 6, 7, 8, 9, 10]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [[1, 9999999], [2, 9999998], [3, 9999997], [4, 9999996], [5, 9999995]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[100, 100], [200, 90], [300, 80], [400, 70], [500, 60]],queries = [[150, 85], [250, 75], [350, 65], [450, 55], [550, 45]]) == [100, 200, 300, 400, 500]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [[100, 1], [100, 2], [100, 3], [100, 4], [100, 5], [100, 6], [100, 7], [100, 8], [100, 9], [100, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rooms = [[1, 1], [10000000, 10000000]],queries = [[5000000, 1], [5000000, 10000000], [1, 1], [10000000, 10000000], [5000000, 5000000]]) == [1, 10000000, 1, 10000000, 10000000]\n assert candidate(rooms = [[5, 1000], [15, 900], [25, 800], [35, 700], [45, 600], [55, 500], [65, 400], [75, 300], [85, 200], [95, 100]],queries = [[10, 900], [20, 800], [30, 700], [40, 600], [50, 500], [60, 400], [70, 300], [80, 200], [90, 100], [100, 90]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [[5, 15], [15, 25], [25, 35], [35, 45], [45, 55], [55, 65], [65, 75], [75, 85], [85, 95], [95, 105]]) == [20, 30, 40, 50, 60, 70, 80, 90, 100, -1]\n assert candidate(rooms = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997], [5, 999996], [6, 999995], [7, 999994], [8, 999993], [9, 999992], [10, 999991]],queries = [[500000, 999998], [1000000, 999997], [1500000, 999996], [2000000, 999995], [2500000, 999994], [3000000, 999993], [3500000, 999992], [4000000, 999991], [4500000, 999990], [5000000, 999989]]) == [3, 4, 5, 6, 7, 8, 9, 10, 10, 10]\n assert candidate(rooms = [[10, 100], [20, 90], [30, 80], [40, 70], [50, 60], [60, 50], [70, 40], [80, 30], [90, 20], [100, 10]],queries = [[15, 50], [25, 40], [35, 30], [45, 20], [55, 10], [65, 5], [75, 15], [85, 25], [95, 35], [105, 45]]) == [10, 20, 30, 40, 50, 60, 70, 80, 70, 60]\n assert candidate(rooms = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50]],queries = [[3, 3], [8, 8], [13, 13], [18, 18], [23, 23], [28, 28], [33, 33], [38, 38], [43, 43], [48, 48]]) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]\n assert candidate(rooms = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5], [1, 6]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1]\n assert candidate(rooms = [[1, 1], [10000000, 10000000]],queries = [[5000000, 1], [5000000, 5000000], [5000000, 10000000], [15000000, 1]]) == [1, 10000000, 10000000, 10000000]\n assert candidate(rooms = [[100000, 10000], [200000, 9000], [300000, 8000], [400000, 7000], [500000, 6000]],queries = [[100000, 10000], [200000, 9000], [300000, 8000], [400000, 7000], [500000, 6000], [500000, 11000]]) == [100000, 200000, 300000, 400000, 500000, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1]\n assert candidate(rooms = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, -1]\n assert candidate(rooms = [[10000000, 10000000], [1, 1], [5000000, 5000000]],queries = [[9999999, 9999999], [1, 1], [5000000, 5000000]]) == [10000000, 1, 5000000]\n assert candidate(rooms = [[5, 10], [15, 12], [25, 9], [35, 8], [45, 11], [55, 7]],queries = [[10, 8], [20, 9], [30, 10], [40, 11], [50, 12]]) == [5, 15, 15, 45, 15]\n assert candidate(rooms = [[100000, 10], [200000, 20], [300000, 30], [400000, 40], [500000, 50], [600000, 60], [700000, 70], [800000, 80], [900000, 90], [1000000, 100]],queries = [[50000, 10], [150000, 20], [250000, 30], [350000, 40], [450000, 50], [550000, 60], [650000, 70], [750000, 80], [850000, 90], [950000, 100]]) == [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000]\n assert candidate(rooms = [[1, 10000], [2, 10000], [3, 10000], [4, 10000], [5, 10000]],queries = [[1, 9000], [2, 9000], [3, 9000], [4, 9000], [5, 9000], [6, 9000], [7, 9000], [8, 9000], [9, 9000]]) == [1, 2, 3, 4, 5, 5, 5, 5, 5]\n assert candidate(rooms = [[1000000, 1000000], [999999, 999999], [999998, 999998], [999997, 999997], [999996, 999996], [999995, 999995]],queries = [[1000000, 1000000], [1000000, 999999], [1000000, 999998], [1000000, 999997], [1000000, 999996], [1000000, 999995], [1000000, 1], [1000000, 2], [1000000, 3], [1000000, 4]]) == [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]\n assert candidate(rooms = [[100, 50], [200, 60], [300, 70], [400, 80], [500, 90]],queries = [[150, 55], [250, 65], [350, 75], [450, 85], [550, 95]]) == [200, 300, 400, 500, -1]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [[5, 15], [6, 25], [7, 35], [8, 45], [9, 55], [10, 65], [11, 75], [12, 85], [13, 95], [14, 105], [15, 115]]) == [5, 6, 7, 8, 9, 10, 10, 10, 10, -1, -1]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [[1, 5], [2, 15], [3, 25], [4, 35], [5, 45], [6, 55], [7, 65], [8, 75], [9, 85], [10, 95]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [[150, 150], [250, 250], [350, 350], [450, 450], [550, 550]]) == [200, 300, 400, 500, -1]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [[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, 5, 4, 3, 2, 1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1]\n assert candidate(rooms = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9], [1000, 10]],queries = [[50, 1], [150, 2], [250, 3], [350, 4], [450, 5], [550, 6], [650, 7], [750, 8], [850, 9], [950, 10], [1050, 11]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 1]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30], [400, 40], [500, 50], [600, 60], [700, 70], [800, 80], [900, 90], [1000, 100]],queries = [[50, 10], [150, 20], [250, 30], [350, 40], [450, 50], [550, 60], [650, 70], [750, 80], [850, 90], [950, 100], [1050, 10]]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1000]\n assert candidate(rooms = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]],queries = [[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, 10, 10, 10, 10, 10]\n assert candidate(rooms = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]],queries = [[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]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]\n assert candidate(rooms = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10]],queries = [[3, 1], [8, 2], [13, 3], [18, 4], [23, 5], [28, 6], [33, 7], [38, 8], [43, 9], [48, 10], [55, 11]]) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[5, 5], [5, 6], [5, 4], [5, 7], [5, 3]]) == [5, 6, 5, 7, 5]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[10, 20], [20, 20], [30, 20], [40, 20], [50, 20], [60, 20], [70, 20], [80, 20], [90, 20], [100, 20]],queries = [[5, 10], [15, 10], [25, 10], [35, 10], [45, 10], [55, 10], [65, 10], [75, 10], [85, 10], [95, 10]]) == [10, 10, 20, 30, 40, 50, 60, 70, 80, 90]\n assert candidate(rooms = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9], [1000, 10]],queries = [[50, 5], [150, 15], [250, 25], [350, 35], [450, 45], [550, 55], [650, 65], [750, 75], [850, 85], [950, 95]]) == [500, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(rooms = [[9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],queries = [[10, 1], [9, 1], [8, 1], [7, 1], [6, 1], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1]]) == [9, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rooms = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997], [5, 999996], [6, 999995], [7, 999994], [8, 999993], [9, 999992], [10, 999991]],queries = [[1, 999991], [2, 999992], [3, 999993], [4, 999994], [5, 999995], [6, 999996], [7, 999997], [8, 999998], [9, 999999], [10, 1000000]]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],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, -1, -1, -1, -1, -1]\n assert candidate(rooms = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [1, 2, 3, 2, 1, -1, -1, -1, -1, -1]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [[1, 9999999], [2, 9999998], [3, 9999997], [4, 9999996], [5, 9999995], [6, 9999994], [7, 9999993]]) == [1, 2, 3, 4, 5, 5, 5]\n assert candidate(rooms = [[1000, 1], [2000, 2], [3000, 3], [4000, 4], [5000, 5], [6000, 6], [7000, 7], [8000, 8], [9000, 9], [10000, 10]],queries = [[500, 1], [1500, 2], [2500, 3], [3500, 4], [4500, 5], [5500, 6], [6500, 7], [7500, 8], [8500, 9], [9500, 10]]) == [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]\n assert candidate(rooms = [[10000000, 1], [9000000, 2], [8000000, 3], [7000000, 4], [6000000, 5], [5000000, 6], [4000000, 7], [3000000, 8], [2000000, 9], [1000000, 10]],queries = [[500000, 1], [1500000, 2], [2500000, 3], [3500000, 4], [4500000, 5], [5500000, 6], [6500000, 7], [7500000, 8], [8500000, 9], [9500000, 10], [10500000, 1]]) == [1000000, 1000000, 2000000, 3000000, 4000000, 5000000, 4000000, 3000000, 2000000, 1000000, 10000000]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 10]]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1]\n assert candidate(rooms = [[1, 10000], [2, 9000], [3, 8000], [4, 7000], [5, 6000], [6, 5000], [7, 4000], [8, 3000], [9, 2000], [10, 1000]],queries = [[1, 10000], [2, 9000], [3, 8000], [4, 7000], [5, 6000], [6, 5000], [7, 4000], [8, 3000], [9, 2000], [10, 1000], [11, 500]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10]\n assert candidate(rooms = [[1000, 10], [2000, 20], [3000, 30], [4000, 40], [5000, 50]],queries = [[1500, 5], [2500, 15], [3500, 25], [4500, 35], [5500, 45]]) == [1000, 2000, 3000, 4000, 5000]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],queries = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[1, 1], [3, 3], [5, 5]],queries = [[2, 2], [4, 4]]) == [3, 5]\n assert candidate(rooms = [[10, 5], [20, 5], [30, 5], [40, 5], [50, 5]],queries = [[15, 5], [25, 5], [35, 5], [45, 5], [55, 5]]) == [10, 20, 30, 40, 50]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30]],queries = [[1, 10], [2, 20], [3, 30]]) == [1, 2, 3]\n assert candidate(rooms = [[5, 10], [10, 10], [15, 10]],queries = [[7, 5], [12, 5], [17, 5]]) == [5, 10, 15]\n assert candidate(rooms = [[7, 10], [15, 20], [25, 30]],queries = [[10, 10], [20, 20], [30, 30], [40, 40]]) == [7, 15, 25, -1]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30]],queries = [[15, 10], [25, 20], [35, 30]]) == [10, 20, 30]\n assert candidate(rooms = [[5, 5], [15, 15], [25, 25], [35, 35]],queries = [[10, 5], [20, 15], [30, 25], [40, 35]]) == [5, 15, 25, 35]\n assert candidate(rooms = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5]],queries = [[1, 1], [6, 2], [11, 3], [16, 4], [21, 5], [26, 6]]) == [5, 10, 15, 20, 25, -1]\n assert candidate(rooms = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5]],queries = [[3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == [3, 3, 3, 2, 1]\n assert candidate(rooms = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[7, 7], [14, 14], [21, 21], [28, 28]],queries = [[7, 7], [14, 14], [21, 21], [28, 28], [35, 35]]) == [7, 14, 21, 28, -1]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],queries = [[3, 5], [3, 15], [3, 25], [3, 35], [3, 45]]) == [3, 3, 3, 4, 5]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8]],queries = [[15, 3], [25, 7], [10, 5]]) == [10, 30, 10]\n assert candidate(rooms = [[1, 10000000]],queries = [[1, 10000000], [1, 9999999], [1, 10000001]]) == [1, 1, -1]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30]],queries = [[15, 10], [25, 15], [35, 25]]) == [10, 20, 30]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[5000000, 5000000], [10000000, 1], [1, 10000000]]) == [1, 10000000, 1]\n assert candidate(rooms = [[7, 7], [17, 17], [27, 27], [37, 37]],queries = [[5, 7], [15, 17], [25, 27], [35, 37]]) == [7, 17, 27, 37]\n assert candidate(rooms = [[1, 10], [10, 1], [2, 9], [9, 2], [3, 8], [8, 3]],queries = [[5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == [3, 3, 8, 8, 9]\n assert candidate(rooms = [[7, 10], [5, 15], [12, 20], [3, 25]],queries = [[6, 15], [8, 10], [15, 20]]) == [5, 7, 12]\n assert candidate(rooms = [[5, 10], [6, 11], [7, 12]],queries = [[5, 10], [6, 11], [7, 12]]) == [5, 6, 7]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300]],queries = [[150, 150], [250, 250], [50, 50]]) == [200, 300, 100]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],queries = [[3, 5], [3, 10], [3, 15]]) == [3, 3, -1]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30], [400, 40], [500, 50]],queries = [[150, 15], [250, 25], [350, 35], [450, 45], [550, 55]]) == [200, 300, 400, 500, -1]\n assert candidate(rooms = [[5, 10], [15, 8], [25, 12], [35, 9]],queries = [[10, 10], [20, 8], [30, 12], [40, 9]]) == [5, 15, 25, 35]\n assert candidate(rooms = [[100, 100], [200, 100], [300, 100]],queries = [[150, 100], [250, 100], [50, 100]]) == [100, 200, 100]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[5000000, 5000000], [10000000, 10000000], [1, 1]]) == [1, 1, 1]\n assert candidate(rooms = [[7, 7], [8, 8], [9, 9]],queries = [[10, 10], [11, 11], [12, 12]]) == [-1, -1, -1]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30]],queries = [[150, 15], [250, 25], [50, 5], [350, 35]]) == [200, 300, 100, -1]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],queries = [[1, 5], [2, 15], [3, 25], [4, 35], [5, 45]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],queries = [[15, 1], [25, 2], [35, 3], [45, 4]]) == [10, 20, 30, 40]\n assert candidate(rooms = [[10, 5], [20, 5], [30, 5]],queries = [[25, 5], [15, 5], [5, 5], [35, 5]]) == [20, 10, 10, 30]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[1, 1], [10000000, 10000000], [5000000, 5000000]]) == [1, 1, 1]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998]],queries = [[2, 9999999], [1, 10000000], [3, 9999998]]) == [2, 1, 3]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],queries = [[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]\n assert candidate(rooms = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],queries = [[3, 3], [2, 2], [1, 1], [6, 6], [0, 0]]) == [3, 2, 1, -1, 1]\n assert candidate(rooms = [[1, 1]],queries = [[1, 1], [2, 1], [3, 1]]) == [1, 1, 1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6]]) == [3, 3, 3, 4, 5, -1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 7]],queries = [[15, 3], [25, 6], [35, 8]]) == [10, 30, -1]\n assert candidate(rooms = [[100000, 100000], [1, 1], [50000, 50000]],queries = [[100000, 100000], [1, 1], [50000, 50000], [25000, 50000]]) == [100000, 1, 50000, 50000]\n assert candidate(rooms = [[1, 10000000], [2, 9999999], [3, 9999998]],queries = [[1, 10000000], [2, 9999999], [3, 9999998]]) == [1, 2, 3]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],queries = [[3, 15], [3, 25], [3, 35], [3, 45], [3, 55]]) == [3, 3, 4, 5, -1]\n assert candidate(rooms = [[5, 10], [15, 10], [25, 10]],queries = [[10, 10], [20, 10], [30, 10]]) == [5, 15, 25]\n assert candidate(rooms = [[5, 5], [5, 5], [5, 5]],queries = [[5, 5], [5, 5], [5, 5]]) == [5, 5, 5]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],queries = [[3, 10], [3, 11], [3, 9]]) == [3, -1, 3]\n assert candidate(rooms = [[10000000, 1], [9999999, 2], [9999998, 3]],queries = [[10000000, 1], [9999999, 2], [9999998, 3]]) == [10000000, 9999999, 9999998]\n assert candidate(rooms = [[10, 5], [20, 7], [30, 9]],queries = [[15, 6], [25, 8], [35, 10]]) == [20, 30, -1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 7], [40, 2], [50, 6]],queries = [[15, 4], [25, 3], [35, 5], [45, 2]]) == [10, 20, 30, 40]\n assert candidate(rooms = [[5, 5], [6, 6], [7, 7]],queries = [[5, 6], [6, 7], [7, 8]]) == [6, 7, -1]\n assert candidate(rooms = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[1, 10000000], [2, 10000000], [3, 10000000]],queries = [[1, 10000000], [2, 10000000], [3, 10000000]]) == [1, 2, 3]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [5, 6, 7, 8, 9]\n assert candidate(rooms = [[7, 7], [8, 8], [9, 9]],queries = [[7, 7], [8, 8], [9, 9], [10, 10]]) == [7, 8, 9, -1]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[5000000, 1], [5000000, 10000000], [1, 1], [10000000, 1]]) == [1, 1, 1, 10000000]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[5000000, 5000000], [10000000, 10000000]]) == [1, 1]\n assert candidate(rooms = [[5, 5], [3, 3], [1, 1], [7, 7]],queries = [[4, 4], [6, 6], [2, 2], [8, 8]]) == [5, 7, 3, -1]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30]],queries = [[150, 15], [250, 25], [350, 35]]) == [200, 300, -1]\n assert candidate(rooms = [[10, 5], [20, 4], [30, 3], [40, 2], [50, 1]],queries = [[15, 4], [25, 3], [35, 2], [45, 1], [55, 1]]) == [10, 20, 30, 40, 50]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],queries = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10]]) == [1, 2, 3, 4, 5, 5]\n assert candidate(rooms = [[100, 100], [200, 90], [300, 80], [400, 70], [500, 60]],queries = [[150, 90], [250, 80], [350, 70]]) == [100, 200, 300]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 3], [1, 1], [2, 2], [4, 4], [5, 5]]) == [3, 1, 2, 4, 5]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 4], [40, 2]],queries = [[25, 3], [15, 5], [35, 4]]) == [20, 10, 30]\n assert candidate(rooms = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],queries = [[2, 1], [4, 3], [6, 5], [8, 7], [10, 9]]) == [1, 3, 5, 7, 9]\n assert candidate(rooms = [[1, 100], [100, 1], [50, 50]],queries = [[50, 1], [50, 50], [50, 100]]) == [50, 50, 1]\n assert candidate(rooms = [[5, 10], [10, 10], [15, 10], [20, 10], [25, 10]],queries = [[7, 5], [12, 8], [17, 11], [22, 14], [27, 17]]) == [5, 10, -1, -1, -1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 4], [40, 6]],queries = [[25, 3], [15, 5], [35, 4]]) == [20, 10, 30]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30], [400, 40]],queries = [[150, 5], [250, 15], [350, 25], [450, 35]]) == [100, 200, 300, 400]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 6], [40, 4]],queries = [[15, 4], [25, 5], [35, 6]]) == [10, 30, 30]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30]],queries = [[15, 5], [25, 25], [35, 15]]) == [10, 30, 30]\n assert candidate(rooms = [[1000, 1000], [2000, 1000], [3000, 1000]],queries = [[1500, 1000], [2500, 1000], [500, 1000]]) == [1000, 2000, 1000]\n assert candidate(rooms = [[1, 10], [2, 20], [3, 30]],queries = [[1, 5], [2, 15], [3, 25]]) == [1, 2, 3]\n assert candidate(rooms = [[1, 5], [2, 5], [3, 5]],queries = [[1, 6], [2, 6], [3, 6]]) == [-1, -1, -1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 4], [40, 2]],queries = [[15, 3], [25, 4], [35, 5]]) == [10, 30, 10]\n assert candidate(rooms = [[10, 5], [20, 6], [30, 7]],queries = [[15, 5], [25, 6], [35, 7]]) == [10, 20, 30]\n assert candidate(rooms = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],queries = [[5, 5], [15, 4], [25, 3], [35, 2], [45, 1], [55, 6]]) == [50, 40, 30, 30, 40, -1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8], [40, 7]],queries = [[15, 4], [25, 6], [35, 7]]) == [10, 30, 30]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],queries = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == [1, 2, 3, 3, 2]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [5, 4, 3, 4, 5]\n assert candidate(rooms = [[100, 1], [200, 2], [300, 3]],queries = [[99, 1], [199, 2], [299, 3]]) == [100, 200, 300]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30]],queries = [[15, 5], [25, 15], [35, 25]]) == [10, 20, 30]\n assert candidate(rooms = [[1, 10000000], [10000000, 1]],queries = [[5000000, 5000000], [1, 1], [10000000, 10000000]]) == [1, 1, 1]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8]],queries = [[15, 4], [25, 3], [35, 9]]) == [10, 20, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == [3, 3, 3, 4, 5]\n assert candidate(rooms = [[5, 10], [15, 20], [25, 30]],queries = [[10, 15], [20, 25], [30, 35]]) == [15, 25, -1]\n assert candidate(rooms = [[1, 5], [3, 5], [5, 5], [7, 5], [9, 5]],queries = [[2, 5], [4, 5], [6, 5], [8, 5]]) == [1, 3, 5, 7]\n assert candidate(rooms = [[100, 10], [200, 20], [300, 30]],queries = [[50, 5], [150, 15], [250, 25]]) == [100, 200, 300]\n assert candidate(rooms = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50]],queries = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45]]) == [5, 15, 25, 35, 45]\n assert candidate(rooms = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],queries = [[5, 1], [15, 2], [25, 3], [35, 4], [45, 5]]) == [10, 20, 30, 40, 50]\n assert candidate(rooms = [[5, 10], [15, 15], [25, 20], [35, 25], [45, 30]],queries = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == [5, 25, 45, -1, -1]\n assert candidate(rooms = [[1, 1], [10, 10], [100, 100]],queries = [[5, 1], [50, 10], [500, 100], [5000, 50]]) == [1, 10, 100, 100]\n assert candidate(rooms = [[10, 5], [20, 3], [30, 8]],queries = [[15, 3], [25, 6], [35, 10]]) == [10, 30, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [[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]\n assert candidate(rooms = [[10000000, 10000000]],queries = [[10000000, 10000000], [9999999, 10000000], [10000001, 10000000]]) == [10000000, 10000000, 10000000]\n assert candidate(rooms = [[10, 5], [20, 4], [30, 3], [40, 2], [50, 1]],queries = [[15, 2], [25, 3], [35, 4]]) == [10, 20, 20]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300], [400, 400]],queries = [[150, 100], [250, 200], [350, 300], [450, 400]]) == [100, 200, 300, 400]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 1], [4, 2], [5, 3], [6, 4], [7, 5]]) == [3, 4, 5, 5, 5]\n assert candidate(rooms = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [[1, 1], [5, 5], [10, 10]]) == [1, 5, 1]\n assert candidate(rooms = [[1, 5], [2, 6], [3, 7]],queries = [[1, 6], [2, 7], [3, 8]]) == [2, 3, -1]\n assert candidate(rooms = [[5, 5], [15, 15], [25, 25], [35, 35]],queries = [[10, 10], [20, 20], [30, 30], [40, 40]]) == [15, 25, 35, -1]\n assert candidate(rooms = [[7, 7], [8, 8], [9, 9]],queries = [[7, 7], [8, 8], [9, 9], [6, 6], [10, 10]]) == [7, 8, 9, 7, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(rooms = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5]],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [1, 2, 3, 2, 1]\n assert candidate(rooms = [[1, 10000000], [2, 10000000], [3, 10000000]],queries = [[1, 10000000], [2, 10000000], [3, 10000000], [4, 10000000]]) == [1, 2, 3, 3]\n assert candidate(rooms = [[10000000, 10000000]],queries = [[10000000, 10000000], [9999999, 9999999], [10000001, 10000001]]) == [10000000, 10000000, -1]\n assert candidate(rooms = [[1, 10], [2, 10], [3, 10]],queries = [[1, 5], [2, 10], [3, 15]]) == [1, 2, -1]\n assert candidate(rooms = [[100, 100], [200, 200], [300, 300], [400, 400]],queries = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450]]) == [100, 200, 300, 400, -1]\n assert candidate(rooms = [[1000, 100], [2000, 200], [3000, 300], [4000, 400]],queries = [[1500, 50], [2500, 150], [3500, 250], [4500, 350]]) == [1000, 2000, 3000, 4000]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 2], [4, 3], [5, 4]]) == [3, 4, 5]\n assert candidate(rooms = [[10, 5], [20, 4], [30, 3]],queries = [[15, 4], [25, 3], [5, 6]]) == [10, 20, -1]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[6, 1], [7, 2], [8, 3], [9, 4], [10, 5]]) == [5, 5, 5, 5, 5]\n assert candidate(rooms = [[10, 5], [20, 5], [30, 5]],queries = [[15, 5], [25, 5], [5, 5]]) == [10, 20, 10]\n assert candidate(rooms = [[1, 10000000], [2, 10000000], [3, 10000000], [4, 10000000], [5, 10000000]],queries = [[3, 10000000], [3, 10000001], [3, 9999999]]) == [3, -1, 3]\n assert candidate(rooms = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],queries = [[50, 1], [150, 2], [250, 3], [350, 4], [450, 5]]) == [100, 200, 300, 400, 500]\n assert candidate(rooms = [[10000000, 10000000]],queries = [[10000000, 10000000]]) == [10000000]\n assert candidate(rooms = [[10000000, 10000000], [1, 1]],queries = [[10000000, 10000000], [2, 1]]) == [10000000, 1]\n assert candidate(rooms = [[10, 10], [20, 20], [30, 30]],queries = [[25, 15], [15, 10], [35, 25]]) == [20, 10, 30]\n assert candidate(rooms = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [[3, 3], [3, 4], [3, 5], [3, 6], [3, 2], [3, 1]]) == [3, 4, 5, -1, 3, 3]\n assert candidate(rooms = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]],queries = [[7, 6], [12, 11], [17, 16], [22, 21], [27, 26]]) == [10, 15, 20, 25, -1]\n", "comparison": "exact"}, "public_tests": ["[[2,2],[1,2],[3,2]]\n[[3,1],[3,3],[5,2]]", "[[1,4],[2,3],[3,5],[4,1],[5,2]]\n[[2,3],[2,4],[2,5]]"], "hints": ["Is there a way to sort the queries so it's easier to search the closest room larger than the size?", "Use binary search to speed up the search time."], "metadata": {"canonical_parameter_names": ["rooms", "queries"], "leetcode_dataset_entry_point": "Solution().closestRoom", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:34+00:00", "tests_total": 213, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "sorting", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function closestRoom($rooms, $queries) {", "container": "Solution", "callable": "closestRoom", "parameters": [{"name": "rooms", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1848, "task_id": "minimum-distance-to-the-target-element", "difficulty": "Easy", "problem_description": "Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.\n\nReturn abs(i - start).\n\nIt is guaranteed that target exists in nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], target = 5, start = 3\nOutput: 1\nExplanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.\n\nExample 2:\n\nInput: nums = [1], target = 1, start = 0\nOutput: 0\nExplanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.\n\nExample 3:\n\nInput: nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\nOutput: 0\nExplanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 10^4\n- 0 <= start < nums.length\n- target is in nums.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 1, 4, 1],target = 1,start = 2) == 1\n assert candidate(nums = [1, 5, 3, 4, 5],target = 5,start = 2) == 1\n assert candidate(nums = [4, 1, 3, 5, 2],target = 2,start = 1) == 3\n assert candidate(nums = [4, 1, 3, 5, 6],target = 3,start = 1) == 1\n assert candidate(nums = [4, 1, 3, 5, 2],target = 1,start = 2) == 1\n assert candidate(nums = [5, 1, 4, 1, 2],target = 1,start = 0) == 1\n assert candidate(nums = [1],target = 1,start = 0) == 0\n assert candidate(nums = [4, 1, 3, 5, 6],target = 1,start = 2) == 1\n assert candidate(nums = [5, 1, 4, 1, 2],target = 1,start = 1) == 0\n assert candidate(nums = [5, 1, 4, 1, 2],target = 1,start = 2) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 1,start = 0) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],target = 5,start = 3) == 1\n assert candidate(nums = [7, 8, 9, 5, 6, 5, 4, 5, 3, 5],target = 5,start = 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],target = 15,start = 9) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 5,start = 9) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 500,start = 3) == 1\n assert candidate(nums = [7, 2, 5, 8, 3, 9, 1, 5],target = 5,start = 4) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],target = 18,start = 8) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 19,start = 4) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 30,start = 0) == 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],target = 2,start = 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],target = 10,start = 19) == 10\n assert candidate(nums = [1, 3, 5, 2, 4, 3, 2, 1, 3],target = 3,start = 5) == 0\n assert candidate(nums = [10, 23, 56, 78, 90, 12, 34, 56, 78, 90],target = 56,start = 5) == 2\n assert candidate(nums = [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],target = 2,start = 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],target = 15,start = 20) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 700,start = 0) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 60,start = 5) == 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],target = 20,start = 15) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 7,start = 9) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 10,start = 14) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 1,start = 9) == 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],target = 15,start = 9) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 15,start = 4) == 3\n assert candidate(nums = [5, 3, 8, 6, 2, 10, 1, 4],target = 10,start = 3) == 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 = 12,start = 10) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 15,start = 0) == 14\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 1,start = 5) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 50,start = 2) == 2\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],target = 997,start = 2) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = 35,start = 9) == 3\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 = 3,start = 15) == 0\n assert candidate(nums = [5, 2, 3, 4, 5, 1, 5],target = 5,start = 3) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 16,start = 0) == 7\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 7],target = 7,start = 5) == 4\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5],target = 1,start = 4) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 2,start = 9) == 9\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],target = 4,start = 10) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 10,start = 7) == 2\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],target = 93,start = 8) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 12,start = 3) == 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 = 13,start = 19) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],target = 15,start = 0) == 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],target = 39,start = 0) == 19\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],target = 65,start = 5) == 1\n assert candidate(nums = [1000, 500, 250, 125, 63, 31, 16, 8, 4, 2, 1],target = 16,start = 5) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 500,start = 9) == 5\n assert candidate(nums = [45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59],target = 50,start = 14) == 9\n assert candidate(nums = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3],target = 1,start = 4) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2],target = 10,start = 9) == 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],target = 10,start = 0) == 10\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 60,start = 4) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],target = 7,start = 7) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 40,start = 0) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 19,start = 9) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10,start = 0) == 9\n assert candidate(nums = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],target = 1,start = 19) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1],target = 9,start = 4) == 0\n assert candidate(nums = [5, 3, 2, 5, 3, 5, 2, 5, 3, 5],target = 3,start = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],target = 2,start = 7) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = 19,start = 12) == 3\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981],target = 985,start = 15) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = 500,start = 9) == 5\n assert candidate(nums = [3, 4, 2, 5, 1, 5, 3, 2, 5],target = 5,start = 4) == 1\n assert candidate(nums = [7, 1, 3, 4, 2, 5, 7, 6, 7, 8],target = 7,start = 5) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10,start = 5) == 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],target = 5,start = 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],target = 15,start = 10) == 4\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7],target = 2,start = 6) == 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],target = 4,start = 9) == 0\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009],target = 1009,start = 2) == 7\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = 18,start = 10) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5],target = 2,start = 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],target = 1,start = 19) == 19\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 = 7,start = 15) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 13,start = 5) == 1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],target = 23,start = 0) == 8\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],target = 15,start = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 10,start = 7) == 2\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15],target = 12,start = 3) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 30,start = 5) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 7,start = 0) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 3,start = 8) == 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 = 25,start = 15) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 10,start = 0) == 9\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],target = 3,start = 6) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 5,start = 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],target = 1,start = 19) == 19\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 18,start = 9) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = 18,start = 12) == 4\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 7,start = 3) == 1\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29],target = 20,start = 4) == 2\n assert candidate(nums = [10, 22, 33, 44, 55, 66, 77, 88, 99],target = 88,start = 0) == 7\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n5\n3", "[1]\n1\n0", "[5,3,6]\n5\n2"], "hints": ["Loop in both directions until you find the target element.", "For each index i such that nums[i] == target calculate abs(i - start)."], "metadata": {"canonical_parameter_names": ["nums", "target", "start"], "leetcode_dataset_entry_point": "Solution().getMinDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:36+00:00", "tests_total": 117, "tests_dropped": 14, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function getMinDistance($nums, $target, $start) {", "container": "Solution", "callable": "getMinDistance", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}, {"name": "start", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1849, "task_id": "splitting-a-string-into-descending-consecutive-values", "difficulty": "Medium", "problem_description": "You are given a string s that consists of only digits.\n\nCheck if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.\n\n- For example, the string s = \"0090089\" can be split into [\"0090\", \"089\"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.\n- Another example, the string s = \"001\" can be split into [\"0\", \"01\"], [\"00\", \"1\"], or [\"0\", \"0\", \"1\"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.\n\nReturn true if it is possible to split s as described above, or false otherwise.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"1234\"\nOutput: false\nExplanation: There is no valid way to split s.\n\nExample 2:\n\nInput: s = \"050043\"\nOutput: true\nExplanation: s can be split into [\"05\", \"004\", \"3\"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.\n\nExample 3:\n\nInput: s = \"9080701\"\nOutput: false\nExplanation: There is no valid way to split s.\n\nConstraints:\n\n- 1 <= s.length <= 20\n- s only consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"21\") == True\n assert candidate(s = \"9876543210\") == True\n assert candidate(s = \"050043\") == True\n assert candidate(s = \"989796959493929190\") == True\n assert candidate(s = \"1009998\") == True\n assert candidate(s = \"2120191817\") == True\n assert candidate(s = \"1201100009\") == False\n assert candidate(s = \"212120\") == False\n assert candidate(s = \"10010\") == False\n assert candidate(s = \"0000\") == False\n assert candidate(s = \"1234\") == False\n assert candidate(s = \"11110\") == False\n assert candidate(s = \"111121111\") == False\n assert candidate(s = \"1111111111\") == False\n assert candidate(s = \"989796\") == True\n assert candidate(s = \"1010\") == False\n assert candidate(s = \"9080701\") == False\n assert candidate(s = \"98765432109\") == False\n assert candidate(s = \"1001000\") == False\n assert candidate(s = \"543210\") == True\n assert candidate(s = \"1\") == False\n assert candidate(s = \"101010\") == False\n assert candidate(s = \"1000999898\") == False\n assert candidate(s = \"00000\") == False\n assert candidate(s = \"001\") == False\n assert candidate(s = \"5432109876543210\") == False\n assert candidate(s = \"100999989876543210\") == False\n assert candidate(s = \"22222222222222222221\") == True\n assert candidate(s = \"99887766554433221100\") == False\n assert candidate(s = \"11111111111111111112\") == False\n assert candidate(s = \"987876757473727170\") == False\n assert candidate(s = \"987654321987654320\") == True\n assert candidate(s = \"09080706050403020100\") == True\n assert candidate(s = \"123432109876543210\") == False\n assert candidate(s = \"98765432100987654321\") == False\n assert candidate(s = \"1098765432110987654\") == False\n assert candidate(s = \"9080706050403020100\") == True\n assert candidate(s = \"99999999999999999999\") == False\n assert candidate(s = \"11111111111111111111\") == False\n assert candidate(s = \"98765432109876543210\") == False\n assert candidate(s = \"10010010010010010010\") == False\n assert candidate(s = \"8070605040302010\") == True\n assert candidate(s = \"987654321987654321\") == False\n assert candidate(s = \"987654321000000\") == True\n assert candidate(s = \"9876543210987654321\") == False\n assert candidate(s = \"54321543215432154321\") == False\n assert candidate(s = \"12345678909876543210\") == False\n assert candidate(s = \"00000000000000000000\") == False\n assert candidate(s = \"9876556789\") == False\n assert candidate(s = \"9876543210123456789\") == False\n assert candidate(s = \"00000000000000000001\") == False\n assert candidate(s = \"12341233123212311230\") == True\n assert candidate(s = \"9879876543210\") == False\n assert candidate(s = \"000000001000000000\") == True\n", "comparison": "exact"}, "public_tests": ["\"1234\"", "\"050043\"", "\"9080701\""], "hints": ["One solution is to try all possible splits using backtrack", "Look out for trailing zeros in string"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().splitString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:38+00:00", "tests_total": 135, "tests_dropped": 81, "flags": [], "topic_tags": ["string", "backtracking", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function splitString($s) {", "container": "Solution", "callable": "splitString", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1850, "task_id": "minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "difficulty": "Medium", "problem_description": "You are given a string num, representing a large integer, and an integer k.\n\nWe call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.\n\n- For example, when num = \"5489355142\":\n - The 1^st smallest wonderful integer is \"5489355214\".\n - The 2^nd smallest wonderful integer is \"5489355241\".\n - The 3^rd smallest wonderful integer is \"5489355412\".\n - The 4^th smallest wonderful integer is \"5489355421\".\n\nReturn the minimum number of adjacent digit swaps that needs to be applied to num to reach the k^th smallest wonderful integer.\n\nThe tests are generated in such a way that k^th smallest wonderful integer exists.\n\nExample 1:\n\nInput: num = \"5489355142\", k = 4\nOutput: 2\nExplanation: The 4^th smallest wonderful number is \"5489355421\". To get this number:\n- Swap index 7 with index 8: \"5489355142\" -> \"5489355412\"\n- Swap index 8 with index 9: \"5489355412\" -> \"5489355421\"\n\nExample 2:\n\nInput: num = \"11112\", k = 4\nOutput: 4\nExplanation: The 4^th smallest wonderful number is \"21111\". To get this number:\n- Swap index 3 with index 4: \"11112\" -> \"11121\"\n- Swap index 2 with index 3: \"11121\" -> \"11211\"\n- Swap index 1 with index 2: \"11211\" -> \"12111\"\n- Swap index 0 with index 1: \"12111\" -> \"21111\"\n\nExample 3:\n\nInput: num = \"00123\", k = 1\nOutput: 1\nExplanation: The 1^st smallest wonderful number is \"00132\". To get this number:\n- Swap index 3 with index 4: \"00123\" -> \"00132\"\n\nConstraints:\n\n- 2 <= num.length <= 1000\n- 1 <= k <= 1000\n- num only consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"111222333\",k = 10) == 3\n assert candidate(num = \"1234567890\",k = 5) == 2\n assert candidate(num = \"1111111111\",k = 5) == 0\n assert candidate(num = \"9876543210\",k = 3) == 0\n assert candidate(num = \"5489355142\",k = 4) == 2\n assert candidate(num = \"321\",k = 2) == 0\n assert candidate(num = \"1000001\",k = 2) == 2\n assert candidate(num = \"343123\",k = 3) == 2\n assert candidate(num = \"00123\",k = 1) == 1\n assert candidate(num = \"12345678901234567890\",k = 10) == 5\n assert candidate(num = \"9999999999\",k = 1) == 0\n assert candidate(num = \"9876543210\",k = 5) == 0\n assert candidate(num = \"1234567890\",k = 3) == 3\n assert candidate(num = \"321\",k = 1) == 0\n assert candidate(num = \"11112\",k = 4) == 4\n assert candidate(num = \"000000000000000000000000000000000000000000000000\",k = 1) == 0\n assert candidate(num = \"12345678901234567890123456789012345678901234567890\",k = 500) == 11\n assert candidate(num = \"00000000001111111111\",k = 500) == 28\n assert candidate(num = \"12345678901234567890\",k = 1000) == 9\n assert candidate(num = \"111112222233333\",k = 500) == 9\n assert candidate(num = \"123456789012345678901234567890\",k = 50) == 3\n assert candidate(num = \"1234567890987654321012345678909876543210\",k = 100) == 39\n assert candidate(num = \"00000000000000000000000000000000000000000000000001\",k = 1) == 1\n assert candidate(num = \"01234567890123456789\",k = 500) == 8\n assert candidate(num = \"5555555555555555555555555555555555555555555555555\",k = 10) == 0\n assert candidate(num = \"3333333333\",k = 1) == 0\n assert candidate(num = \"1212121212121212121212121212\",k = 500) == 6\n assert candidate(num = \"9876543210\",k = 10) == 0\n assert candidate(num = \"5678987656789\",k = 250) == 10\n assert candidate(num = \"12345678909876543210\",k = 500) == 37\n assert candidate(num = \"55667788990011223344\",k = 500) == 11\n assert candidate(num = \"3456789012\",k = 10) == 2\n assert candidate(num = \"123123123123123123123123123123123123123123\",k = 200) == 6\n assert candidate(num = \"123321123321\",k = 50) == 3\n assert candidate(num = \"9876543210\",k = 15) == 0\n assert candidate(num = \"1000000000000000000000000000000000000000000000000001\",k = 10) == 10\n assert candidate(num = \"12345678901234567890\",k = 100) == 8\n assert candidate(num = \"3214567890\",k = 10) == 5\n assert candidate(num = \"123321123321\",k = 100) == 5\n assert candidate(num = \"987654321098765432109876543210\",k = 1000) == 37\n assert candidate(num = \"01234567890123456789\",k = 1000) == 8\n assert candidate(num = \"3333333333\",k = 500) == 0\n assert candidate(num = \"3333222211110000\",k = 100) == 0\n assert candidate(num = \"9876543210987654321098765432109876543210\",k = 50) == 42\n assert candidate(num = \"987654321987654321987654321\",k = 500) == 28\n assert candidate(num = \"33333333333333333333\",k = 1) == 0\n assert candidate(num = \"01010101010101010101\",k = 250) == 3\n assert candidate(num = \"987654321987654321\",k = 100) == 30\n assert candidate(num = \"22222222222222222223\",k = 500) == 19\n assert candidate(num = \"333333333333333333333333333333333333333333333333\",k = 10) == 0\n assert candidate(num = \"987654321098765432109876543210987654321098765432109876543210\",k = 500) == 37\n assert candidate(num = \"1010101010101010\",k = 50) == 5\n assert candidate(num = \"1221112222211122222211111222222211111111122222222222222\",k = 100) == 19\n assert candidate(num = \"99887766554433221100\",k = 500) == 0\n assert candidate(num = \"1234554321\",k = 10) == 13\n assert candidate(num = \"0000000001\",k = 1) == 1\n assert candidate(num = \"44444444444444444444\",k = 100) == 0\n assert candidate(num = \"111122223333444455556666777788889999\",k = 1000) == 15\n assert candidate(num = \"90876543210987654321\",k = 50) == 34\n assert candidate(num = \"1234321234321\",k = 50) == 6\n assert candidate(num = \"111111111111111111112\",k = 1000) == 20\n assert candidate(num = \"98765432109876543210\",k = 10) == 42\n assert candidate(num = \"1234567890\",k = 100) == 8\n assert candidate(num = \"55555555555555555555\",k = 100) == 0\n assert candidate(num = \"555444333222111000\",k = 300) == 0\n assert candidate(num = \"123123123123123123123\",k = 200) == 6\n assert candidate(num = \"0000000000000000000000000000000000000000000000000001\",k = 1) == 1\n assert candidate(num = \"33333333332222222222111111111111\",k = 500) == 0\n assert candidate(num = \"9876543210\",k = 50) == 0\n assert candidate(num = \"33333333333333333333333333333333333333333333333333\",k = 1) == 0\n assert candidate(num = \"102030405060708090\",k = 50) == 8\n assert candidate(num = \"989796959493929190898887868584838281807978777675747372717069686766656463626160595857565554535251504948474645444342414039383736353433323130292827262524232221201918171615141312111009080706050403020100\",k = 1000) == 15\n assert candidate(num = \"00000000000000000001\",k = 10) == 10\n assert candidate(num = \"23456789012345678901\",k = 500) == 10\n assert candidate(num = \"0000000000000000000000000000000000001\",k = 1) == 1\n assert candidate(num = \"13579135791357913579\",k = 500) == 7\n assert candidate(num = \"876543210123456789\",k = 500) == 8\n assert candidate(num = \"10000000001\",k = 5) == 5\n assert candidate(num = \"3333333333\",k = 100) == 0\n assert candidate(num = \"1111111111111111111111111111111111111111\",k = 100) == 0\n assert candidate(num = \"98765432101234567890\",k = 20) == 7\n assert candidate(num = \"98765432109876543210\",k = 1000) == 37\n assert candidate(num = \"1221122112211221\",k = 100) == 13\n assert candidate(num = \"222111333000444555666777888999\",k = 500) == 10\n assert candidate(num = \"123456789876543210\",k = 100) == 39\n assert candidate(num = \"11223344556677889900\",k = 50) == 12\n assert candidate(num = \"12345678900987654321\",k = 200) == 31\n assert candidate(num = \"432111111111111111111111111111\",k = 100) == 0\n assert candidate(num = \"9999999999999999999999999999999999999999999999999999\",k = 5) == 0\n assert candidate(num = \"12345678909876543210\",k = 5) == 43\n assert candidate(num = \"11223344556677889900\",k = 100) == 9\n assert candidate(num = \"11111111112222222222\",k = 100) == 11\n assert candidate(num = \"12345678901234567890\",k = 5) == 2\n assert candidate(num = \"133221100998877665544332211\",k = 1000) == 133\n assert candidate(num = \"12345678901234567890\",k = 20) == 7\n assert candidate(num = \"000000000011111111112222222222\",k = 100) == 11\n assert candidate(num = \"55555555555555555555555555555555555555555555555555555\",k = 5) == 0\n assert candidate(num = \"11223344556677889900\",k = 1000) == 11\n assert candidate(num = \"1111222233334444\",k = 1000) == 15\n assert candidate(num = \"9999999999888888888877777777776666666666\",k = 1000) == 0\n assert candidate(num = \"11223344556677889900\",k = 200) == 9\n assert candidate(num = \"99999999999999999999\",k = 1000) == 0\n assert candidate(num = \"2233445566\",k = 300) == 4\n assert candidate(num = \"99999999999999999999\",k = 100) == 0\n assert candidate(num = \"98765432109876543210987654321098765432109876543210\",k = 1000) == 37\n", "comparison": "exact"}, "public_tests": ["\"5489355142\"\n4", "\"11112\"\n4", "\"00123\"\n1"], "hints": ["Find the next permutation of the given string k times.", "Try to move each element to its correct position and calculate the number of steps."], "metadata": {"canonical_parameter_names": ["num", "k"], "leetcode_dataset_entry_point": "Solution().getMinSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:40+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function getMinSwaps($num, $k) {", "container": "Solution", "callable": "getMinSwaps", "parameters": [{"name": "num", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1851, "task_id": "minimum-interval-to-include-each-query", "difficulty": "Hard", "problem_description": "You are given a 2D integer array intervals, where intervals[i] = [left_i, right_i] describes the i^th interval starting at left_i and ending at right_i (inclusive). The size of an interval is defined as the number of integers it contains, or more formally right_i - left_i + 1.\n\nYou are also given an integer array queries. The answer to the j^th query is the size of the smallest interval i such that left_i <= queries[j] <= right_i. If no such interval exists, the answer is -1.\n\nReturn an array containing the answers to the queries.\n\nExample 1:\n\nInput: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\nOutput: [3,3,1,4]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.\n- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.\n- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.\n- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.\n\nExample 2:\n\nInput: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\nOutput: [2,-1,4,6]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.\n- Query = 19: None of the intervals contain 19. The answer is -1.\n- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.\n- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.\n\nConstraints:\n\n- 1 <= intervals.length <= 10^5\n- 1 <= queries.length <= 10^5\n- intervals[i].length == 2\n- 1 <= left_i <= right_i <= 10^7\n- 1 <= queries[j] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 1], [2, 2]],queries = [1, 2, 3]) == [1, 1, -1]\n assert candidate(intervals = [[1, 10], [10, 20], [15, 25]],queries = [5, 10, 15, 20, 25]) == [10, 10, 11, 11, 11]\n assert candidate(intervals = [[1, 1]],queries = [1]) == [1]\n assert candidate(intervals = [[5, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [-1, -1, -1, -1, 6, 6, 6, 6, 6, 6, -1]\n assert candidate(intervals = [[2, 3], [2, 5], [1, 8], [20, 25]],queries = [2, 19, 5, 22]) == [2, -1, 4, 6]\n assert candidate(intervals = [[5, 5], [10, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [-1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1]\n assert candidate(intervals = [[1, 10000000]],queries = [1, 5000000, 10000000]) == [10000000, 10000000, 10000000]\n assert candidate(intervals = [[1, 4], [2, 4], [3, 6], [4, 4]],queries = [2, 3, 4, 5]) == [3, 3, 1, 4]\n assert candidate(intervals = [[1, 3], [4, 5]],queries = [2, 3, 4, 5]) == [3, 3, 2, 2]\n assert candidate(intervals = [[10000000, 10000000]],queries = [10000000]) == [1]\n assert candidate(intervals = [[5, 5], [1, 2], [3, 4]],queries = [1, 5, 2, 3]) == [2, 1, 2, 2]\n assert candidate(intervals = [[1, 10], [2, 9], [3, 8]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 8, 6, 6, 6, 6, 6, 6, 8, 10]\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300]],queries = [1, 50, 100, 150, 200, 250, 300, 301]) == [100, 100, 100, 101, 101, 101, 101, -1]\n assert candidate(intervals = [[1000, 2000], [500, 1500], [100, 1000], [50, 500], [1, 50]],queries = [1, 50, 100, 500, 1000, 1500, 2000]) == [50, 50, 451, 451, 901, 1001, 1001]\n assert candidate(intervals = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40]],queries = [10, 15, 20, 25, 30, 35, 40, 45]) == [11, 11, 11, 11, 11, 11, 11, -1]\n assert candidate(intervals = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [1, 3, 5, 7, 9]) == [1, 1, 1, 1, 1]\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -1]\n assert candidate(intervals = [[1, 10000000], [5000000, 7500000], [2500000, 3750000], [6250000, 8750000]],queries = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000]) == [10000000, 10000000, 1250001, 10000000, 2500001, 2500001, 2500001, 2500001, 10000000, 10000000]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == [2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1]\n assert candidate(intervals = [[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]],queries = [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]\n assert candidate(intervals = [[1, 5], [6, 10], [11, 15], [16, 20]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(intervals = [[1, 10], [10, 20], [15, 25], [25, 35], [30, 40], [35, 45]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45]) == [10, 10, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(intervals = [[1000000, 10000000], [2000000, 10000000], [3000000, 10000000], [4000000, 10000000]],queries = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000]) == [9000001, 8000001, 7000001, 6000001, 6000001, 6000001, 6000001, 6000001, 6000001, 6000001]\n assert candidate(intervals = [[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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8]],queries = [1, 2, 3, 4, 5, 6, 7, 8]) == [3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],queries = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1]\n assert candidate(intervals = [[1, 500000], [500000, 1000000], [1000000, 1500000], [1500000, 2000000], [2000000, 2500000]],queries = [250000, 750000, 1250000, 1750000, 2250000]) == [500000, 500001, 500001, 500001, 500001]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1]\n assert candidate(intervals = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [10, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(intervals = [[1, 5000], [2, 4999], [3, 4998], [4, 4997], [5, 4996], [6, 4995], [7, 4994], [8, 4993], [9, 4992], [10, 4991]],queries = [2500, 3500, 4500, 5500]) == [4982, 4982, 4982, -1]\n assert candidate(intervals = [[1, 1000], [2, 1001], [3, 1002], [4, 1003], [5, 1004], [6, 1005], [7, 1006], [8, 1007], [9, 1008], [10, 1009]],queries = [1, 500, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, -1]\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],queries = [1, 19, 10, 2, 9, 18, 7, 16, 5, 15, 3, 14, 11, 13, 6, 12, 8, 17, 4]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(intervals = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70]],queries = [15, 25, 35, 45, 55, 65, 75]) == [11, 11, 11, 11, 11, 11, -1]\n assert candidate(intervals = [[1, 50000], [2, 30000], [3, 20000], [4, 10000]],queries = [1, 2, 3, 4, 5, 10000, 20000, 30000, 50000]) == [50000, 29999, 19998, 9997, 9997, 9997, 19998, 29999, 50000]\n assert candidate(intervals = [[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]) == [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]\n assert candidate(intervals = [[1, 10000000], [1000000, 2000000], [2000000, 3000000], [3000000, 4000000], [4000000, 5000000], [5000000, 6000000], [6000000, 7000000], [7000000, 8000000], [8000000, 9000000], [9000000, 10000000]],queries = [1, 5000000, 1000000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000, 4500000, 5500000, 6000000, 6500000, 7000000, 7500000, 8000000, 8500000, 9000000, 9500000, 10000000]) == [10000000, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001, 1000001]\n assert candidate(intervals = [[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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1]\n assert candidate(intervals = [[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]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]],queries = [1, 5, 9, 13, 17]) == [2, 2, 2, 2, -1]\n assert candidate(intervals = [[1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(intervals = [[1, 2000], [2, 1999], [3, 1998], [4, 1997], [5, 1996], [6, 1995], [7, 1994], [8, 1993], [9, 1992], [10, 1991]],queries = [1, 1000, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991]) == [2000, 1982, 2000, 1998, 1996, 1994, 1992, 1990, 1988, 1986, 1984, 1982]\n assert candidate(intervals = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30]],queries = [3, 7, 13, 19, 23, 27, 10, 21, 31]) == [5, 5, 5, 5, 5, 5, 5, 5, -1]\n assert candidate(intervals = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90], [95, 100]],queries = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96, 101]) == [-1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1, 6, -1]\n assert candidate(intervals = [[1, 3], [2, 5], [3, 7], [4, 9], [5, 11], [6, 13], [7, 15]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]\n assert candidate(intervals = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],queries = [50, 60, 70, 80, 90, 100]) == [82, 82, 82, 82, 82, 100]\n assert candidate(intervals = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55]],queries = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]) == [-1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(intervals = [[1, 1000000], [1, 999999], [1, 999998], [1, 999997], [1, 999996]],queries = [500000, 250000, 750000, 125000, 375000]) == [999996, 999996, 999996, 999996, 999996]\n assert candidate(intervals = [[1, 3], [1, 5], [1, 7], [1, 9], [1, 11], [1, 13], [1, 15], [1, 17], [1, 19], [1, 21]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == [3, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19, 21, 21, -1]\n assert candidate(intervals = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996]],queries = [1, 50000, 100000, 99999, 99998]) == [100000, 99992, 100000, 99998, 99996]\n assert candidate(intervals = [[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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(intervals = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [1, 2, 3, 4, 5]) == [10000000, 9999998, 9999996, 9999994, 9999992]\n assert candidate(intervals = [[5, 500], [6, 499], [7, 498], [8, 497], [9, 496]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 500]) == [488, 488, 488, 488, 488, 488, 488, 488, 488, 488, 496]\n assert candidate(intervals = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997]],queries = [1, 2, 3, 4, 5, 9999999, 10000000]) == [10000000, 9999998, 9999996, 9999994, 9999994, 9999998, 10000000]\n assert candidate(intervals = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23]],queries = [1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24]) == [3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1]\n assert candidate(intervals = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [5, 5, 5, 5, 5, -1, -1, -1, -1, -1]\n assert candidate(intervals = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, -1]\n assert candidate(intervals = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15]],queries = [1, 5, 7, 11, 13, 16]) == [3, 3, 3, 3, 3, -1]\n assert candidate(intervals = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],queries = [1, 2, 3]) == [3, 3, 3]\n assert candidate(intervals = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],queries = [5, 15, 25, 35, 45]) == [10, 10, 10, 10, 10]\n assert candidate(intervals = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],queries = [3, 4, 5, 6, 7, 8, 9, 1, 2, 10]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(intervals = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997], [5, 999996]],queries = [500000, 250000, 750000, 125000, 375000]) == [999992, 999992, 999992, 999992, 999992]\n assert candidate(intervals = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50]],queries = [3, 7, 12, 18, 23, 28, 33, 38, 43, 48]) == [-1, 6, -1, 6, -1, 6, -1, 6, -1, 6]\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]\n assert candidate(intervals = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [11, 20], [12, 19], [13, 18], [14, 17], [15, 16]],queries = [5, 15, 25, 35, 45]) == [2, 2, -1, -1, -1]\n assert candidate(intervals = [[1, 1], [10000000, 10000000], [2, 9999999], [9999998, 9999998], [3, 9999997], [9999996, 9999996]],queries = [1, 5000000, 10000000, 9999999, 9999998, 9999997, 9999996, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 9999995, 1, 9999998, 1, 9999995, 1, 1, 9999998, 9999995, 9999995, 9999995, 9999995, 9999995, 9999995, 9999995, 9999995]\n assert candidate(intervals = [[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]],queries = [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]) == [2, -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, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1]\n assert candidate(intervals = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, -1]\n assert candidate(intervals = [[1, 100000], [50000, 100000], [1, 50000], [100000, 100000]],queries = [1, 25000, 50000, 75000, 100000]) == [50000, 50000, 50000, 50001, 1]\n assert candidate(intervals = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(intervals = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995], [7, 9994]],queries = [1, 2, 3, 4, 5, 6, 7, 10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993]) == [10000, 9998, 9996, 9994, 9992, 9990, 9988, 10000, 9998, 9996, 9994, 9992, 9990, 9988, 9988]\n assert candidate(intervals = [[1, 5000], [1000, 5000], [2000, 5000], [3000, 5000], [4000, 5000]],queries = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000]) == [5000, 4001, 4001, 3001, 3001, 2001, 2001, 1001, 1001, 1001]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],queries = [1, 11, 6, 3, 8, 5, 10, 2, 7, 4, 9]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],queries = [1, 5, 9, 13, 17, 21]) == [2, 2, 2, 2, 2, -1]\n assert candidate(intervals = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992], [10, 991]],queries = [500, 600, 700, 800, 900, 1000]) == [982, 982, 982, 982, 982, 1000]\n assert candidate(intervals = [[1, 1000000], [1000000, 2000000], [2000000, 3000000], [3000000, 4000000], [4000000, 5000000], [5000000, 6000000]],queries = [500000, 1500000, 2500000, 3500000, 4500000, 5500000]) == [1000000, 1000001, 1000001, 1000001, 1000001, 1000001]\n assert candidate(intervals = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 8, 6, 4, 2, 2, 4, 6, 8, 10]\n assert candidate(intervals = [[1, 100000], [2, 99999], [50, 100], [101, 200], [201, 300]],queries = [1, 50, 101, 201, 500, 1000, 100000]) == [100000, 51, 100, 100, 99998, 99998, 100000]\n assert candidate(intervals = [[1, 1000000], [500000, 1500000], [750000, 2000000]],queries = [1, 500000, 1000000, 1500000, 2000000]) == [1000000, 1000000, 1000000, 1000001, 1250001]\n assert candidate(intervals = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]],queries = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(intervals = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -1]\n assert candidate(intervals = [[1000000, 2000000], [1500000, 2500000], [2000000, 3000000]],queries = [1000000, 1500000, 2000000, 2500000, 3000000]) == [1000001, 1000001, 1000001, 1000001, 1000001]\n assert candidate(intervals = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [1, 5000000, 10000000, 9999999, 9999998]) == [10000000, 9999992, 10000000, 9999998, 9999996]\n assert candidate(intervals = [[10, 200], [20, 190], [30, 180], [40, 170], [50, 160]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210]) == [191, 171, 151, 131, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 131, 151, 171, 191, -1]\n assert candidate(intervals = [[1, 100000], [50000, 150000], [75000, 250000]],queries = [10000, 50000, 75000, 150000, 250000]) == [100000, 100000, 100000, 100001, 175001]\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300]],queries = [25, 75, 125, 175, 225]) == [100, 100, 101, 101, 101]\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(intervals = [[100, 200], [150, 250], [200, 300], [250, 350], [300, 400], [350, 450], [400, 500], [450, 550], [500, 600]],queries = [150, 250, 350, 450, 550, 600, 100, 200, 300, 400, 500]) == [101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101]\n assert candidate(intervals = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],queries = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) == [82, 82, 82, 82, 82, 82, 82, 82, 82, 82]\n assert candidate(intervals = [[1, 500], [501, 1000], [1001, 1500], [1501, 2000]],queries = [1, 500, 501, 1000, 1001, 1500, 1501, 2000]) == [500, 500, 500, 500, 500, 500, 500, 500]\n assert candidate(intervals = [[1, 10000000], [2, 9999999], [3, 9999998], [4, 9999997], [5, 9999996]],queries = [1, 9999998, 5000000, 9999997, 10000000]) == [10000000, 9999996, 9999992, 9999994, 10000000]\n assert candidate(intervals = [[1, 100000], [50000, 150000], [100000, 200000], [250000, 300000], [1, 1000000]],queries = [50000, 150000, 250000, 500000, 999999]) == [100000, 100001, 50001, 1000000, 1000000]\n assert candidate(intervals = [[1, 3], [4, 7], [8, 10], [11, 15], [16, 20], [21, 25], [26, 30]],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]) == [3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -1]\n assert candidate(intervals = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],queries = [3, 7, 12, 17, 22, 27]) == [5, 5, 5, 5, 5, -1]\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]],queries = [1, 3, 5, 7, 9, 11]) == [1, 1, 1, 1, 1, 1]\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [1, 3, 5, 7, 9, 11]) == [1, 1, 1, 1, 1, -1]\n assert candidate(intervals = [[1, 10000000], [5000001, 10000000], [5000001, 7500000], [5000001, 6250000], [5000001, 5625000]],queries = [1, 5000000, 5625000, 6250000, 7500000, 10000000]) == [10000000, 10000000, 625000, 1250000, 2500000, 5000000]\n assert candidate(intervals = [[1, 3], [2, 6], [5, 9], [8, 12], [11, 15]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(intervals = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350]],queries = [1, 50, 100, 150, 200, 250, 300, 350]) == [100, 100, 100, 101, 101, 101, 101, 101]\n", "comparison": "exact"}, "public_tests": ["[[1,4],[2,4],[3,6],[4,4]]\n[2,3,4,5]", "[[2,3],[2,5],[1,8],[20,25]]\n[2,19,5,22]"], "hints": ["Is there a way to order the intervals and queries such that it takes less time to query?", "Is there a way to add and remove intervals by going from the smallest query to the largest query to find the minimum size?"], "metadata": {"canonical_parameter_names": ["intervals", "queries"], "leetcode_dataset_entry_point": "Solution().minInterval", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:43+00:00", "tests_total": 104, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "binary-search", "sweep-line", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function minInterval($intervals, $queries) {", "container": "Solution", "callable": "minInterval", "parameters": [{"name": "intervals", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1854, "task_id": "maximum-population-year", "difficulty": "Easy", "problem_description": "You are given a 2D integer array logs where each logs[i] = [birth_i, death_i] indicates the birth and death years of the i^th person.\n\nThe population of some year x is the number of people alive during that year. The i^th person is counted in year x's population if x is in the inclusive range [birth_i, death_i - 1]. Note that the person is not counted in the year that they die.\n\nReturn the earliest year with the maximum population.\n\nExample 1:\n\nInput: logs = [[1993,1999],[2000,2010]]\nOutput: 1993\nExplanation: The maximum population is 1, and 1993 is the earliest year with this population.\n\nExample 2:\n\nInput: logs = [[1950,1961],[1960,1971],[1970,1981]]\nOutput: 1960\nExplanation:\nThe maximum population is 2, and it had happened in years 1960 and 1970.\nThe earlier year between them is 1960.\n\nConstraints:\n\n- 1 <= logs.length <= 100\n- 1950 <= birth_i < death_i <= 2050\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(logs = [[2000, 2005], [2005, 2010], [2010, 2015]]) == 2000\n assert candidate(logs = [[1980, 1985], [1985, 1990], [1990, 1995], [1995, 2000]]) == 1980\n assert candidate(logs = [[2000, 2010], [1990, 2000], [2000, 2020]]) == 2000\n assert candidate(logs = [[1993, 1999], [2000, 2010]]) == 1993\n assert candidate(logs = [[1950, 1960], [1960, 1970], [1970, 1980], [1980, 1990]]) == 1950\n assert candidate(logs = [[1991, 1992], [1992, 1993], [1993, 1994], [1994, 1995]]) == 1991\n assert candidate(logs = [[1950, 2050]]) == 1950\n assert candidate(logs = [[1950, 1961], [1960, 1971], [1970, 1981], [1960, 1980]]) == 1960\n assert candidate(logs = [[1975, 1985], [1985, 1995], [1995, 2005], [2005, 2015]]) == 1975\n assert candidate(logs = [[1990, 1995], [1991, 1996], [1992, 1997]]) == 1992\n assert candidate(logs = [[1950, 1961], [1960, 1971], [1970, 1981]]) == 1960\n assert candidate(logs = [[2000, 2010], [2010, 2020], [2020, 2030]]) == 2000\n assert candidate(logs = [[1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005]]) == 1985\n assert candidate(logs = [[1995, 2005], [2005, 2015], [2015, 2025]]) == 1995\n assert candidate(logs = [[2000, 2010], [1990, 2000], [1980, 1990]]) == 1980\n assert candidate(logs = [[1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025], [2020, 2030]]) == 1985\n assert candidate(logs = [[1993, 1995], [1994, 1996], [1995, 1997], [1996, 1998], [1997, 1999], [1998, 2000], [1999, 2001], [2000, 2002], [2001, 2003], [2002, 2004], [2003, 2005]]) == 1994\n assert candidate(logs = [[2000, 2005], [2001, 2006], [2002, 2007], [2003, 2008], [2004, 2009], [2005, 2010]]) == 2004\n assert candidate(logs = [[1965, 1980], [1970, 1985], [1975, 1990], [1980, 1995], [1985, 2000]]) == 1975\n assert candidate(logs = [[1950, 1960], [1960, 1970], [1970, 1980], [1980, 1990], [1990, 2000], [2000, 2010], [2010, 2020], [2020, 2030]]) == 1950\n assert candidate(logs = [[1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025]]) == 1990\n assert candidate(logs = [[1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990]]) == 1960\n assert candidate(logs = [[1950, 1960], [1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005]]) == 1955\n assert candidate(logs = [[1955, 1975], [1960, 1980], [1965, 1985], [1970, 1990], [1975, 1995], [1980, 2000], [1985, 2005], [1990, 2010], [1995, 2015], [2000, 2020]]) == 1970\n assert candidate(logs = [[1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015]]) == 1985\n assert candidate(logs = [[1980, 1990], [1981, 1991], [1982, 1992], [1983, 1993], [1984, 1994], [1985, 1995], [1986, 1996], [1987, 1997], [1988, 1998], [1989, 1999]]) == 1989\n assert candidate(logs = [[1950, 2000], [1960, 1990], [1970, 1995], [1980, 2005], [1990, 2010], [2000, 2020]]) == 1980\n assert candidate(logs = [[1975, 1978], [1977, 1980], [1979, 1982], [1981, 1984], [1983, 1986], [1985, 1988], [1987, 1990], [1989, 1992], [1991, 1994], [1993, 1996]]) == 1977\n assert candidate(logs = [[1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025], [2020, 2030], [2025, 2035]]) == 1995\n assert candidate(logs = [[1990, 1991], [1991, 1992], [1992, 1993], [1993, 1994], [1994, 1995], [1995, 1996], [1996, 1997], [1997, 1998], [1998, 1999], [1999, 2000]]) == 1990\n assert candidate(logs = [[1960, 1970], [1961, 1971], [1962, 1972], [1963, 1973], [1964, 1974], [1965, 1975], [1966, 1976], [1967, 1977], [1968, 1978], [1969, 1979], [1970, 1980]]) == 1969\n assert candidate(logs = [[1950, 2050], [1960, 2040], [1970, 2030], [1980, 2020], [1990, 2010], [2000, 2005]]) == 2000\n assert candidate(logs = [[1980, 1985], [1982, 1987], [1984, 1989], [1986, 1991], [1988, 1993]]) == 1984\n assert candidate(logs = [[1950, 2050], [1951, 2049], [1952, 2048], [1953, 2047], [1954, 2046], [1955, 2045], [1956, 2044], [1957, 2043], [1958, 2042], [1959, 2041], [1960, 2040]]) == 1960\n assert candidate(logs = [[1950, 2050], [1960, 1980], [1970, 1990], [1980, 2000], [1990, 2010], [2000, 2020]]) == 1970\n assert candidate(logs = [[1990, 1995], [1991, 1996], [1992, 1997], [1993, 1998], [1994, 1999]]) == 1994\n assert candidate(logs = [[1950, 1960], [1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985]]) == 1955\n assert candidate(logs = [[1950, 1961], [1955, 1966], [1960, 1971], [1965, 1976], [1970, 1981], [1975, 1986]]) == 1960\n assert candidate(logs = [[1980, 1990], [1982, 1992], [1984, 1994], [1986, 1996], [1988, 1998], [1990, 2000]]) == 1988\n assert candidate(logs = [[1955, 1966], [1961, 1971], [1966, 1976], [1971, 1981], [1976, 1986], [1981, 1991], [1986, 1996], [1991, 2001]]) == 1961\n assert candidate(logs = [[1965, 1985], [1970, 1990], [1975, 1995], [1980, 2000], [1985, 2005], [1990, 2010], [1995, 2015], [2000, 2020], [2005, 2025], [2010, 2030]]) == 1980\n assert candidate(logs = [[1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025], [2020, 2030], [2025, 2035], [2030, 2040], [2035, 2045], [2040, 2050]]) == 1975\n assert candidate(logs = [[1950, 1965], [1960, 1975], [1970, 1985], [1980, 1995], [1990, 2005], [2000, 2015], [2010, 2025], [2020, 2035]]) == 1960\n assert candidate(logs = [[1950, 1960], [1960, 1970], [1970, 1980], [1980, 1990], [1990, 2000], [2000, 2010], [2010, 2020], [2020, 2030], [2030, 2040], [2040, 2050]]) == 1950\n assert candidate(logs = [[1950, 2050], [1955, 2045], [1960, 2040], [1965, 2035], [1970, 2030], [1975, 2025], [1980, 2020], [1985, 2015], [1990, 2010]]) == 1990\n assert candidate(logs = [[1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2015], [2005, 2020]]) == 1985\n assert candidate(logs = [[1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015]]) == 1965\n assert candidate(logs = [[1960, 1965], [1961, 1966], [1962, 1967], [1963, 1968], [1964, 1969], [1965, 1970], [1966, 1971], [1967, 1972], [1968, 1973], [1969, 1974]]) == 1964\n assert candidate(logs = [[1950, 1960], [1960, 1970], [1970, 1980], [1980, 1990], [1990, 2000], [2000, 2010]]) == 1950\n assert candidate(logs = [[1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005]]) == 1960\n assert candidate(logs = [[1993, 1999], [2000, 2010], [1995, 2000], [1985, 1995], [1990, 1998]]) == 1993\n assert candidate(logs = [[1955, 1965], [1950, 1960], [1960, 1970], [1970, 1980], [1965, 1975], [1975, 1985]]) == 1955\n assert candidate(logs = [[1955, 1965], [1965, 1975], [1975, 1985], [1985, 1995], [1995, 2005], [2005, 2015], [2015, 2025]]) == 1955\n assert candidate(logs = [[1970, 1975], [1971, 1976], [1972, 1977], [1973, 1978], [1974, 1979], [1975, 1980]]) == 1974\n assert candidate(logs = [[2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025], [2020, 2030], [2025, 2035], [2030, 2040]]) == 2005\n assert candidate(logs = [[1955, 1961], [1960, 1965], [1965, 1970], [1970, 1975], [1975, 1980], [1980, 1985], [1985, 1990]]) == 1960\n assert candidate(logs = [[1970, 1980], [1971, 1981], [1972, 1982], [1973, 1983], [1974, 1984], [1975, 1985], [1976, 1986], [1977, 1987], [1978, 1988], [1979, 1989], [1980, 1990]]) == 1979\n assert candidate(logs = [[1950, 1960], [1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980]]) == 1955\n assert candidate(logs = [[1975, 1985], [1985, 1995], [1995, 2005], [2005, 2015], [2015, 2025], [2025, 2035]]) == 1975\n assert candidate(logs = [[1990, 2000], [1992, 2002], [1994, 2004], [1996, 2006], [1998, 2008]]) == 1998\n assert candidate(logs = [[1960, 1961], [1961, 1962], [1962, 1963], [1963, 1964], [1964, 1965], [1965, 1966], [1966, 1967], [1967, 1968], [1968, 1969], [1969, 1970], [1970, 1971]]) == 1960\n assert candidate(logs = [[1950, 1955], [1951, 1956], [1952, 1957], [1953, 1958], [1954, 1959], [1955, 1960], [1956, 1961], [1957, 1962], [1958, 1963], [1959, 1964], [1960, 1965]]) == 1954\n assert candidate(logs = [[1993, 1998], [1994, 1999], [1995, 2000], [1996, 2001], [1997, 2002], [1998, 2003], [1999, 2004]]) == 1997\n assert candidate(logs = [[1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995]]) == 1965\n assert candidate(logs = [[1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2000], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025]]) == 1975\n assert candidate(logs = [[1970, 1975], [1971, 1976], [1972, 1977], [1973, 1978], [1974, 1979], [1975, 1980], [1976, 1981], [1977, 1982], [1978, 1983], [1979, 1984]]) == 1974\n assert candidate(logs = [[1950, 2000], [1960, 2010], [1970, 2020], [1980, 2030], [1990, 2040], [2000, 2050]]) == 1990\n assert candidate(logs = [[1950, 1955], [1955, 1960], [1960, 1965], [1965, 1970], [1970, 1975], [1975, 1980], [1980, 1985], [1985, 1990], [1990, 1995], [1995, 2000], [2000, 2005], [2005, 2010], [2010, 2015], [2015, 2020], [2020, 2025], [2025, 2030], [2030, 2035], [2035, 2040], [2040, 2045], [2045, 2050]]) == 1950\n assert candidate(logs = [[1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025]]) == 1995\n assert candidate(logs = [[1950, 1951], [1951, 1952], [1952, 1953], [1953, 1954], [1954, 1955], [1955, 1956], [1956, 1957], [1957, 1958], [1958, 1959], [1959, 1960], [1960, 1961], [1961, 1962], [1962, 1963], [1963, 1964], [1964, 1965]]) == 1950\n assert candidate(logs = [[1950, 1961], [1955, 1966], [1960, 1971], [1965, 1976], [1970, 1981], [1975, 1986], [1980, 1991], [1985, 1996]]) == 1960\n assert candidate(logs = [[1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020], [2015, 2025]]) == 1985\n assert candidate(logs = [[1955, 1975], [1960, 1980], [1965, 1985], [1970, 1990], [1975, 1995], [1980, 2000]]) == 1970\n assert candidate(logs = [[1990, 1995], [1992, 1997], [1994, 1999], [1996, 2001], [1998, 2003]]) == 1994\n assert candidate(logs = [[1955, 1965], [1965, 1975], [1975, 1985], [1985, 1995], [1995, 2005], [2005, 2015], [2015, 2025], [2025, 2035]]) == 1955\n assert candidate(logs = [[1975, 1980], [1978, 1985], [1980, 1985], [1982, 1990], [1985, 1995], [1988, 1995], [1990, 1998], [1992, 2000]]) == 1992\n assert candidate(logs = [[1950, 1980], [1960, 1990], [1970, 2000], [1980, 2010], [1990, 2020]]) == 1970\n assert candidate(logs = [[1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2000], [2000, 2010]]) == 1975\n assert candidate(logs = [[1960, 1970], [1961, 1971], [1962, 1972], [1963, 1973], [1964, 1974], [1965, 1975], [1966, 1976], [1967, 1977]]) == 1967\n assert candidate(logs = [[1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000], [1995, 2005]]) == 1965\n assert candidate(logs = [[1980, 1985], [1981, 1986], [1982, 1987], [1983, 1988], [1984, 1989], [1985, 1990], [1986, 1991], [1987, 1992]]) == 1984\n assert candidate(logs = [[1990, 2000], [1995, 2005], [2000, 2010], [2005, 2015], [2010, 2020]]) == 1995\n assert candidate(logs = [[1993, 1995], [1994, 1996], [1995, 1997], [1996, 1998], [1997, 1999]]) == 1994\n assert candidate(logs = [[1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000]]) == 1960\n assert candidate(logs = [[1960, 1970], [1970, 1980], [1980, 1990], [1990, 2000], [2000, 2010], [2010, 2020], [2020, 2030]]) == 1960\n assert candidate(logs = [[1990, 1995], [1990, 1995], [1990, 1995], [1995, 2000], [1995, 2000], [1995, 2000]]) == 1990\n assert candidate(logs = [[1950, 1960], [1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990], [1985, 1995], [1990, 2000]]) == 1955\n assert candidate(logs = [[1980, 1990], [1982, 1992], [1984, 1994], [1986, 1996], [1988, 1998], [1990, 2000], [1992, 2002], [1994, 2004], [1996, 2006], [1998, 2008]]) == 1988\n assert candidate(logs = [[1960, 1970], [1970, 1980], [1980, 1990], [1990, 2000], [2000, 2010], [2010, 2020]]) == 1960\n assert candidate(logs = [[1950, 1960], [1955, 1965], [1960, 1970], [1965, 1975], [1970, 1980], [1975, 1985], [1980, 1990]]) == 1955\n", "comparison": "exact"}, "public_tests": ["[[1993,1999],[2000,2010]]", "[[1950,1961],[1960,1971],[1970,1981]]"], "hints": ["For each year find the number of people whose birth_i ≤ year and death_i > year.", "Find the maximum value between all years."], "metadata": {"canonical_parameter_names": ["logs"], "leetcode_dataset_entry_point": "Solution().maximumPopulation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:48+00:00", "tests_total": 91, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "counting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maximumPopulation($logs) {", "container": "Solution", "callable": "maximumPopulation", "parameters": [{"name": "logs", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1855, "task_id": "maximum-distance-between-a-pair-of-values", "difficulty": "Medium", "problem_description": "You are given two non-increasing 0-indexed integer arrays nums1 and nums2.\n\nA pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i.\n\nReturn the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.\n\nAn array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.\n\nExample 1:\n\nInput: nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\nOutput: 2\nExplanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).\n\nExample 2:\n\nInput: nums1 = [2,2,2], nums2 = [10,10,1]\nOutput: 1\nExplanation: The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).\n\nExample 3:\n\nInput: nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\nOutput: 2\nExplanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4).\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 10^5\n- 1 <= nums1[i], nums2[j] <= 10^5\n- Both nums1 and nums2 are non-increasing.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [100],nums2 = [101]) == 0\n assert candidate(nums1 = [30, 29, 19, 5],nums2 = [25, 25, 25, 25, 25]) == 2\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [10, 9, 8, 7, 6]) == 0\n assert candidate(nums1 = [5],nums2 = [10]) == 0\n assert candidate(nums1 = [10, 9, 8, 7],nums2 = [7, 7, 7, 7]) == 0\n assert candidate(nums1 = [5],nums2 = [5]) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 3\n assert candidate(nums1 = [10],nums2 = [5]) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [100, 90],nums2 = [95, 85]) == 0\n assert candidate(nums1 = [100, 90, 80],nums2 = [100, 90, 80, 70, 60]) == 0\n assert candidate(nums1 = [99999, 99998, 99997],nums2 = [100000, 99999, 99998]) == 1\n assert candidate(nums1 = [1],nums2 = [2]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [5, 5, 5, 5, 5]) == 4\n assert candidate(nums1 = [2, 2, 2],nums2 = [10, 10, 1]) == 1\n assert candidate(nums1 = [100, 50, 25, 10],nums2 = [100, 100, 100, 100]) == 3\n assert candidate(nums1 = [55, 30, 5, 4, 2],nums2 = [100, 20, 10, 10, 5]) == 2\n assert candidate(nums1 = [1],nums2 = [1]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [15, 14, 13, 12, 11]) == 4\n assert candidate(nums1 = [100000],nums2 = [100000]) == 0\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [100, 80, 60, 40, 20]) == 2\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums1 = [30, 29, 19, 5],nums2 = [25, 25, 25, 25, 25, 20, 15, 10, 5]) == 5\n assert candidate(nums1 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],nums2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 9\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 9\n assert candidate(nums1 = [95, 85, 75, 65, 55],nums2 = [95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 0\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [100000, 100000, 100000, 100000, 100000],nums2 = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 9\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 4, 3, 2, 1]) == 9\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]) == 9\n assert candidate(nums1 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],nums2 = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 9\n assert candidate(nums1 = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],nums2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 5\n assert candidate(nums1 = [1],nums2 = [100000]) == 0\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 5\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],nums2 = [99, 89, 79, 69, 59, 49, 39, 29, 19, 9]) == 0\n assert candidate(nums1 = [50, 25, 10, 1],nums2 = [50, 40, 30, 25, 20, 15, 10, 5, 1]) == 5\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1]) == 10\n assert candidate(nums1 = [90, 80, 70, 60, 50],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 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]) == 9\n assert candidate(nums1 = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],nums2 = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 1\n assert candidate(nums1 = [10, 5, 3, 2],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 4\n assert candidate(nums1 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 4\n assert candidate(nums1 = [20, 10, 5, 2, 1],nums2 = [50, 40, 30, 20, 10, 5, 2, 1]) == 3\n assert candidate(nums1 = [50, 40, 30, 20, 10],nums2 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 5\n assert candidate(nums1 = [100],nums2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 9\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 10\n assert candidate(nums1 = [50, 30, 10],nums2 = [60, 50, 40, 30, 20, 10]) == 3\n assert candidate(nums1 = [10, 9, 8, 7, 6],nums2 = [10, 9, 8, 7, 6]) == 0\n assert candidate(nums1 = [90, 70, 50, 30, 10],nums2 = [100, 80, 60, 40, 20]) == 0\n assert candidate(nums1 = [100, 50, 25],nums2 = [150, 120, 90, 70, 50, 30, 10]) == 3\n assert candidate(nums1 = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],nums2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 9\n assert candidate(nums1 = [1000, 900, 800, 700, 600],nums2 = [1000, 950, 900, 850, 800, 750, 700, 650, 600, 550, 500]) == 4\n assert candidate(nums1 = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 1],nums2 = [100000, 99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111]) == 1\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [10, 10, 10, 10, 10, 10],nums2 = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 14\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums1 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],nums2 = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 9\n assert candidate(nums1 = [100, 50, 25, 10, 1],nums2 = [200, 150, 100, 90, 80, 70, 60, 50, 40, 30, 25, 20, 15, 10, 5]) == 10\n assert candidate(nums1 = [10, 5, 5, 5, 5],nums2 = [20, 15, 15, 10, 10, 10, 5, 5, 5, 5]) == 8\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]) == 4\n assert candidate(nums1 = [5, 4, 4, 3, 3, 3, 2, 1],nums2 = [9, 8, 7, 6, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 9\n assert candidate(nums1 = [100, 50, 30, 20, 10],nums2 = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 10\n assert candidate(nums1 = [100, 50, 25, 10, 5],nums2 = [100, 75, 50, 25, 10, 5, 2]) == 1\n assert candidate(nums1 = [10, 10, 10, 10, 10],nums2 = [20, 20, 20, 20, 20]) == 4\n assert candidate(nums1 = [100000],nums2 = [1]) == 0\n assert candidate(nums1 = [100, 90, 80, 70, 60],nums2 = [100, 95, 90, 85, 80, 75, 70, 65, 60, 55]) == 4\n", "comparison": "exact"}, "public_tests": ["[55,30,5,4,2]\n[100,20,10,10,5]", "[2,2,2]\n[10,10,1]", "[30,29,19,5]\n[25,25,25,25,25]"], "hints": ["Since both arrays are sorted in a non-increasing way, this means that for each value in the first array, we can find the farthest value larger than or equal to it using binary search.", "There is another solution using a two pointers approach. Since the first array is non-increasing, the farthest j such that nums2[j] ≥ nums1[i] is at least as far as the farthest j such that nums2[j] ≥ nums1[i-1]"], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:50+00:00", "tests_total": 75, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function maxDistance($nums1, $nums2) {", "container": "Solution", "callable": "maxDistance", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1856, "task_id": "maximum-subarray-min-product", "difficulty": "Medium", "problem_description": "The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.\n\n- For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.\n\nGiven an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 10^9 + 7.\n\nNote that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.\n\nA subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [1,2,3,2]\nOutput: 14\nExplanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).\n2 * (2+3+2) = 2 * 7 = 14.\n\nExample 2:\n\nInput: nums = [2,3,3,1,2]\nOutput: 18\nExplanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).\n3 * (3+3) = 3 * 6 = 18.\n\nExample 3:\n\nInput: nums = [3,1,5,6,4,2]\nOutput: 60\nExplanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).\n4 * (5+6+4) = 4 * 15 = 60.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 9, 6, 8, 7]) == 180\n assert candidate(nums = [2, 1]) == 4\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 240\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 180\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 240\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [10000000]) == 999300007\n assert candidate(nums = [5, 9, 6, 8, 7, 4, 3, 2, 10, 1]) == 180\n assert candidate(nums = [2, 3, 3, 1, 2]) == 18\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996]) == 696500047\n assert candidate(nums = [5, 5, 5, 5, 5]) == 125\n assert candidate(nums = [7, 1, 5, 6, 4, 2]) == 60\n assert candidate(nums = [1, 2, 3, 4, 5]) == 36\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 15\n assert candidate(nums = [1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [3, 1, 5, 6, 4, 2]) == 60\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997]) == 817200025\n assert candidate(nums = [5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1, 2]) == 4\n assert candidate(nums = [1, 2, 3, 2]) == 14\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 72\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, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 135\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991]) == 643000419\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 2400000\n assert candidate(nums = [5, 8, 6, 7, 8, 9, 9, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 642\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1728\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1728\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 360\n assert candidate(nums = [10, 20, 10, 30, 20, 10, 40, 30, 20, 10]) == 2100\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1728\n assert candidate(nums = [9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1]) == 979300008\n assert candidate(nums = [1, 3, 2, 5, 6, 2, 8, 4, 9, 1, 3]) == 84\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990]) == 342300564\n assert candidate(nums = [1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000]) == 999300007\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 756\n assert candidate(nums = [1, 1, 1, 1, 10000000, 1, 1, 1, 1, 10000000, 1, 1, 1, 1]) == 999300007\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 = [10000000, 10000000, 10000000, 10000000, 10000000]) == 996500007\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 3600\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 420\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7]) == 90\n assert candidate(nums = [7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == 238\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 420\n assert candidate(nums = [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]) == 10000\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]) == 420\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 240\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]) == 480\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]) == 420\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 480\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 999930007\n assert candidate(nums = [2, 3, 2, 4, 3, 2, 5, 4, 3, 2, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 10]) == 332\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1728\n assert candidate(nums = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000]) == 998320007\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]) == 315\n assert candidate(nums = [10, 20, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1000\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 240\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 240\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994]) == 365100133\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1728\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]) == 240\n assert candidate(nums = [8, 2, 6, 5, 4, 1, 3, 7, 9]) == 112\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 24000\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]) == 41\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]) == 82\n assert candidate(nums = [10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1]) == 999300007\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 240\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 980\n assert candidate(nums = [2, 1, 3, 4, 1, 5, 1, 6, 1, 7]) == 49\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]) == 420\n assert candidate(nums = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991]) == 643000419\n assert candidate(nums = [10000000, 1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000]) == 999300007\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]) == 3300\n assert candidate(nums = [3, 2, 5, 4, 7, 6, 8, 9, 1, 10, 2, 3, 4, 5, 6, 7, 8, 9, 1, 10, 2, 3, 4, 5, 6, 7, 8, 9, 1, 10, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 756\n assert candidate(nums = [1, 5, 4, 3, 6, 2, 8, 7, 9]) == 168\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 81\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 100\n assert candidate(nums = [5, 6, 1, 2, 8, 9, 3, 4, 7, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 240\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1728\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 180\n assert candidate(nums = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000]) == 993000007\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 144\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 148\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [10000000, 1, 10000000, 1, 10000000, 1, 10000000]) == 999300007\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 240\n assert candidate(nums = [1, 10000000, 2, 9999999, 3, 9999998, 4, 9999997, 5, 9999996]) == 999300007\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1]) == 36\n assert candidate(nums = [9999996, 9999997, 9999998, 9999999, 10000000, 9999999, 9999998, 9999997, 9999996]) == 433700087\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 30\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]) == 240\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 33\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 24000\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, 100, 1000, 10000, 100000, 1000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 999300007\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 375\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 25\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 999937007\n assert candidate(nums = [1, 10000000, 1, 10000000, 1, 10000000, 1, 10000000]) == 999300007\n", "comparison": "exact"}, "public_tests": ["[1,2,3,2]", "[2,3,3,1,2]", "[3,1,5,6,4,2]"], "hints": ["Is there a way we can sort the elements to simplify the problem?", "Can we find the maximum min-product for every value in the array?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxSumMinProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:53+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "stack", "monotonic-stack", "prefix-sum", "cartesian-tree"]}, "language": "php", "interface": {"raw_signature": "function maxSumMinProduct($nums) {", "container": "Solution", "callable": "maxSumMinProduct", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1857, "task_id": "largest-color-value-in-a-directed-graph", "difficulty": "Hard", "problem_description": "There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.\n\nYou are given a string colors where colors[i] is a lowercase English letter representing the color of the i^th node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [a_j, b_j] indicates that there is a directed edge from node a_j to node b_j.\n\nA valid path in the graph is a sequence of nodes x_1 -> x_2 -> x_3 -> ... -> x_k such that there is a directed edge from x_i to x_{i+1} for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.\n\nReturn the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.\n\nExample 1:\n\nInput: colors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]\nOutput: 3\nExplanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored \"a\" (red in the above image).\n\nExample 2:\n\nInput: colors = \"a\", edges = [[0,0]]\nOutput: -1\nExplanation: There is a cycle from 0 to 0.\n\nConstraints:\n\n- n == colors.length\n- m == edges.length\n- 1 <= n <= 10^5\n- 0 <= m <= 10^5\n- colors consists of lowercase English letters.\n- 0 <= a_j, b_j < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(colors = \"abcde\",edges = []) == 1\n assert candidate(colors = \"abcdefghijklmnopqrstuvwxyz\",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]]) == 1\n assert candidate(colors = \"zzz\",edges = [[0, 1], [1, 2], [2, 0]]) == -1\n assert candidate(colors = \"abacabadabacaba\",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]]) == 8\n assert candidate(colors = \"aaaaa\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == -1\n assert candidate(colors = \"abcdef\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 1\n assert candidate(colors = \"abcde\",edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 1\n assert candidate(colors = \"abcdef\",edges = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4], [4, 5]]) == 1\n assert candidate(colors = \"abcde\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == -1\n assert candidate(colors = \"aaaaa\",edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 5\n assert candidate(colors = \"xyzz\",edges = [[0, 1], [1, 2], [2, 3]]) == 2\n assert candidate(colors = \"abcabc\",edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]]) == -1\n assert candidate(colors = \"abcdabcdabcd\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 3\n assert candidate(colors = \"xyz\",edges = [[0, 1], [1, 2]]) == 1\n assert candidate(colors = \"aabbcc\",edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]]) == -1\n assert candidate(colors = \"abcabcabc\",edges = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]]) == -1\n assert candidate(colors = \"aabbcc\",edges = [[0, 1], [2, 3], [4, 5]]) == 2\n assert candidate(colors = \"aaabbb\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 3\n assert candidate(colors = \"zzzzz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]]) == -1\n assert candidate(colors = \"aaaa\",edges = [[0, 1], [1, 2], [2, 3], [3, 0]]) == -1\n assert candidate(colors = \"aabbcc\",edges = [[0, 1], [1, 2], [2, 0]]) == -1\n assert candidate(colors = \"a\",edges = []) == 1\n assert candidate(colors = \"abcd\",edges = [[0, 1], [0, 2], [1, 3], [2, 3]]) == 1\n assert candidate(colors = \"aabbbbcccc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 4\n assert candidate(colors = \"abcabcabc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 3\n assert candidate(colors = \"a\",edges = [[0, 0]]) == -1\n assert candidate(colors = \"abaca\",edges = [[0, 1], [0, 2], [2, 3], [3, 4]]) == 3\n assert candidate(colors = \"abcd\",edges = [[0, 1], [1, 2], [2, 3], [3, 0], [0, 2], [1, 3]]) == -1\n assert candidate(colors = \"ab\",edges = [[0, 1]]) == 1\n assert candidate(colors = \"aabbcc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(colors = \"zzzzzzzzz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0]]) == -1\n assert candidate(colors = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",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]]) == 2\n assert candidate(colors = \"abcabcabcabcabcabcabcabcabcabc\",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, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 10]]) == -1\n assert candidate(colors = \"zzzzzzzzzzz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == -1\n assert candidate(colors = \"abcbcbc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 2]]) == -1\n assert candidate(colors = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",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]]) == 2\n assert candidate(colors = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",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]]) == -1\n assert candidate(colors = \"abcdef\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]) == -1\n assert candidate(colors = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",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]]) == 2\n assert candidate(colors = \"abacabadabe\",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(colors = \"abcde\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [1, 3], [2, 4], [3, 0], [4, 1]]) == -1\n assert candidate(colors = \"aaaaaaaaaa\",edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8], [7, 9], [8, 9]]) == 5\n assert candidate(colors = \"abcdef\",edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 4], [2, 5], [3, 5], [4, 5]]) == 1\n assert candidate(colors = \"bbaaabbbaaabbbaaabbbaaa\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 8\n assert candidate(colors = \"abcdefghijklmnopqrstuvwx\",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]]) == 1\n assert candidate(colors = \"ababababa\",edges = [[0, 1], [1, 2], [2, 0], [1, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 3]]) == -1\n assert candidate(colors = \"xyzxyzxyz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 2], [1, 3], [4, 6], [5, 7]]) == -1\n assert candidate(colors = \"abcde\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [2, 0], [3, 1]]) == -1\n assert candidate(colors = \"abcdef\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 2]]) == -1\n assert candidate(colors = \"abacabadabc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 5\n assert candidate(colors = \"abcdefghijk\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 0]]) == -1\n assert candidate(colors = \"abacabadabe\",edges = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 3]]) == -1\n assert candidate(colors = \"abcabcabcabcabc\",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, 10]]) == -1\n assert candidate(colors = \"aaabbbccc\",edges = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 8], [8, 4], [1, 3], [3, 5], [5, 7]]) == -1\n assert candidate(colors = \"ababababc\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0]]) == -1\n assert candidate(colors = \"abcdefghij\",edges = [[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], [8, 0], [9, 1]]) == -1\n assert candidate(colors = \"zzzzzzzzzz\",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(colors = \"aaaabbbbccccdddd\",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]]) == 4\n assert candidate(colors = \"zzzzzzzzzz\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(colors = \"aabbccddeeff\",edges = [[0, 1], [0, 5], [1, 2], [1, 3], [2, 4], [3, 4], [5, 6], [5, 7], [6, 8], [7, 8], [8, 9]]) == 2\n assert candidate(colors = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",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]]) == -1\n assert candidate(colors = \"abacabadabe\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 5\n assert candidate(colors = \"abcde\",edges = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 3], [2, 4], [3, 4], [4, 0]]) == -1\n assert candidate(colors = \"abcabcabc\",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]]) == -1\n assert candidate(colors = \"abcabcabcabcabcabcabcabcabcabc\",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, 28]]) == -1\n assert candidate(colors = \"abcabcabcabc\",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]]) == -1\n assert candidate(colors = \"abacbacba\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 4\n assert candidate(colors = \"abacabadabe\",edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8], [7, 9], [8, 9]]) == 4\n assert candidate(colors = \"abacabadaba\",edges = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 9]]) == 5\n assert candidate(colors = \"abacabadaba\",edges = [[0, 1], [1, 0], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == -1\n assert candidate(colors = \"ababababab\",edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 9], [8, 9]]) == 5\n assert candidate(colors = \"abacabadaba\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 5\n assert candidate(colors = \"abcabcabcabcabcabcabcabcabcabc\",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]]) == 10\n assert candidate(colors = \"abcdefghij\",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(colors = \"abacabadaba\",edges = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 5\n assert candidate(colors = \"aabbaabb\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 1]]) == -1\n assert candidate(colors = \"abcdefgabcdefgabcdefgabcdefg\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0], [0, 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, 7]]) == -1\n assert candidate(colors = \"aaabbbcccdddeeefffggghhh\",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]]) == 3\n assert candidate(colors = \"abcdefghijk\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 1\n assert candidate(colors = \"aaaabbbbccccdddd\",edges = [[0, 1], [0, 4], [1, 2], [1, 5], [2, 3], [2, 6], [3, 7], [4, 5], [4, 8], [5, 6], [5, 9], [6, 7], [6, 10], [7, 11], [8, 9], [8, 12], [9, 10], [9, 13], [10, 11], [10, 14], [11, 15], [12, 13], [13, 14], [14, 15]]) == 4\n assert candidate(colors = \"abcabcabcabcabc\",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]]) == 5\n assert candidate(colors = \"abcde\",edges = [[0, 1], [0, 2], [2, 1], [1, 3], [2, 3], [3, 4], [4, 0]]) == -1\n assert candidate(colors = \"zzzzzzyyyyy\",edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 6\n assert candidate(colors = \"abacabadabacaba\",edges = [[0, 1], [0, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]) == 6\n", "comparison": "exact"}, "public_tests": ["\"abaca\"\n[[0,1],[0,2],[2,3],[3,4]]", "\"a\"\n[[0,0]]"], "hints": ["Use topological sort.", "let dp[u][c] := the maximum count of vertices with color c of any path starting from vertex u. (by JerryJin2905)"], "metadata": {"canonical_parameter_names": ["colors", "edges"], "leetcode_dataset_entry_point": "Solution().largestPathValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:32:56+00:00", "tests_total": 84, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["hash-table", "string", "dynamic-programming", "graph", "topological-sort", "memoization", "counting", "directed-acyclic-graph"]}, "language": "php", "interface": {"raw_signature": "function largestPathValue($colors, $edges) {", "container": "Solution", "callable": "largestPathValue", "parameters": [{"name": "colors", "type": "String"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1859, "task_id": "sorting-the-sentence", "difficulty": "Easy", "problem_description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.\n\nA sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.\n\n- For example, the sentence \"This is a sentence\" can be shuffled as \"sentence4 a3 is2 This1\" or \"is2 sentence4 This1 a3\".\n\nGiven a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.\n\nExample 1:\n\nInput: s = \"is2 sentence4 This1 a3\"\nOutput: \"This is a sentence\"\nExplanation: Sort the words in s to their original positions \"This1 is2 a3 sentence4\", then remove the numbers.\n\nExample 2:\n\nInput: s = \"Myself2 Me1 I4 and3\"\nOutput: \"Me Myself and I\"\nExplanation: Sort the words in s to their original positions \"Me1 Myself2 and3 I4\", then remove the numbers.\n\nConstraints:\n\n- 2 <= s.length <= 200\n- s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.\n- The number of words in s is between 1 and 9.\n- The words in s are separated by a single space.\n- s contains no leading or trailing spaces.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"eight8 seven7 six6 five5 four4 three3 two2 one1\") == \"one two three four five six seven eight\"\n assert candidate(s = \"seven7 six6 five5 four4 three3 two2 one1\") == \"one two three four five six seven\"\n assert candidate(s = \"nine9 eight8 seven7 six6 five5 four4 three3 two2 one1\") == \"one two three four five six seven eight nine\"\n assert candidate(s = \"three3 two2 one1\") == \"one two three\"\n assert candidate(s = \"is2 sentence4 This1 a3\") == \"This is a sentence\"\n assert candidate(s = \"five5 four4 three3 two2 one1\") == \"one two three four five\"\n assert candidate(s = \"A9 B8 C7 D6 E5 F4 G3 H2 I1\") == \"I H G F E D C B A\"\n assert candidate(s = \"Myself2 Me1 I4 and3\") == \"Me Myself and I\"\n assert candidate(s = \"nine9 eight8 seven7 six6 five5 four4 three3 two2 one1 zero0\") == \"one two three four five six seven eight nine zero\"\n assert candidate(s = \"six6 five5 four4 three3 two2 one1\") == \"one two three four five six\"\n assert candidate(s = \"one1\") == \"one\"\n assert candidate(s = \"two1 one2\") == \"two one\"\n assert candidate(s = \"four4 three3 two2 one1\") == \"one two three four\"\n assert candidate(s = \"quick5 brown3 fox2 jumps9 over8 lazy4 the7 dog6 a1\") == \"a fox brown lazy quick dog the over jumps\"\n assert candidate(s = \"Quick5 brown4 fox3 jumps2 over1\") == \"over jumps fox brown Quick\"\n assert candidate(s = \"big2 bigger3 biggest1\") == \"biggest big bigger\"\n assert candidate(s = \"order10 words9 in8 correct7 sequence6 is5 important4 for3 understanding2 this1\") == \"this understanding for important is sequence correct in words order1\"\n assert candidate(s = \"a1 bc2 def3 ghij4 klmno5 pqrstu6 vwxyz7 abcdefg8 hijklmno9\") == \"a bc def ghij klmno pqrstu vwxyz abcdefg hijklmno\"\n assert candidate(s = \"abc1 def2 ghi3 jkl4 mno5 pqr6 stu7 vwx8 yza9\") == \"abc def ghi jkl mno pqr stu vwx yza\"\n assert candidate(s = \"Data2 Science1\") == \"Science Data\"\n assert candidate(s = \"alpha10 beta9 gamma8 delta7 epsilon6 zeta5 eta4 theta3 iota2 kappa1\") == \"kappa iota theta eta zeta epsilon delta gamma beta alpha1\"\n assert candidate(s = \"Quick5 Brown4 Fox3 Jumps2 Over1\") == \"Over Jumps Fox Brown Quick\"\n assert candidate(s = \"Digital2 Transformation1\") == \"Transformation Digital\"\n assert candidate(s = \"zebra9 yellow8 xenon7 winter6 volcano5 umbrella4 tornado3 storm2 rainbow1\") == \"rainbow storm tornado umbrella volcano winter xenon yellow zebra\"\n assert candidate(s = \"short1 longerWord2 evenLongerWord3\") == \"short longerWord evenLongerWord\"\n assert candidate(s = \"one9 two8 three7 four6 five5 six4 seven3 eight2 nine1\") == \"nine eight seven six five four three two one\"\n assert candidate(s = \"apple8 banana7 cherry6 date5 elderberry4 fig3 grape2 huckleberry1\") == \"huckleberry grape fig elderberry date cherry banana apple\"\n assert candidate(s = \"apple9 banana8 cherry7 date6 elderberry5 fig4 grape3 honeydew2 ice1\") == \"ice honeydew grape fig elderberry date cherry banana apple\"\n assert candidate(s = \"MixedCASE1 Word2 with3 DIFFERENT4 cases5\") == \"MixedCASE Word with DIFFERENT cases\"\n assert candidate(s = \"Python1 is2 great3\") == \"Python is great\"\n assert candidate(s = \"a9 b8 c7 d6 e5 f4 g3 h2 i1\") == \"i h g f e d c b a\"\n assert candidate(s = \"single1\") == \"single\"\n assert candidate(s = \"one1 two2 three3 four4 five5 six6 seven7 eight8 nine9\") == \"one two three four five six seven eight nine\"\n assert candidate(s = \"reverse9 order8 words7 in6 a5 sentence4 for3 testing2 purposes1\") == \"purposes testing for sentence a in words order reverse\"\n assert candidate(s = \"sun8 moon7 stars6 galaxy5 universe4 planets3 asteroid2 comet1\") == \"comet asteroid planets universe galaxy stars moon sun\"\n assert candidate(s = \"two2 one1 three3 four4 five5 six6 seven7 eight8 nine9\") == \"one two three four five six seven eight nine\"\n assert candidate(s = \"complex1 testing2 cases3 with4 multiple5 digits6 and7 shuffled8 order9\") == \"complex testing cases with multiple digits and shuffled order\"\n assert candidate(s = \"Sustainability1\") == \"Sustainability\"\n assert candidate(s = \"Hard2 Work3 Makes1 Success4\") == \"Makes Hard Work Success\"\n assert candidate(s = \"A5 B4 C3 D2 E1 F6 G7 H8 I9\") == \"E D C B A F G H I\"\n assert candidate(s = \"Alphabetically9 Better8 Christmas7 Does6 Everyone5 Feel4 Good3 Happy2 Indeed1\") == \"Indeed Happy Good Feel Everyone Does Christmas Better Alphabetically\"\n assert candidate(s = \"sun9 moon8 star7 planet6 comet5 asteroid4 meteor3 satellite2 galaxy1\") == \"galaxy satellite meteor asteroid comet planet star moon sun\"\n assert candidate(s = \"The9 quick8 brown7 fox6 jumps5 over4 lazy3 dog2 one1\") == \"one dog lazy over jumps fox brown quick The\"\n assert candidate(s = \"short6 longer5 very4 much3 more2 words1\") == \"words more much very longer short\"\n assert candidate(s = \"first1 second2 third3 fourth4 fifth5 sixth6 seventh7 eighth8 ninth9\") == \"first second third fourth fifth sixth seventh eighth ninth\"\n assert candidate(s = \"Two2 Words1\") == \"Words Two\"\n assert candidate(s = \"Complicated1 Sorting2 becomes3 significantly4 more5 challenging6 when7 words8 overlap9\") == \"Complicated Sorting becomes significantly more challenging when words overlap\"\n assert candidate(s = \"Python10 Java9 C8 Cpp7 Rust6 Go5 Ruby4 Swift3 Kotlin2 TypeScript1\") == \"TypeScript Kotlin Swift Ruby Go Rust Cpp C Java Python1\"\n assert candidate(s = \"zZ9 yY8 xX7 wW6 vV5 uU4 tT3 sS2 rR1\") == \"rR sS tT uU vV wW xX yY zZ\"\n assert candidate(s = \"A9 lot8 of7 testing6 needs5 to4 be3 done2 always1\") == \"always done be to needs testing of lot A\"\n assert candidate(s = \"z9 y8 x7 w6 v5 u4 t3 s2 r1\") == \"r s t u v w x y z\"\n assert candidate(s = \"twoWords2 oneWord1\") == \"oneWord twoWords\"\n assert candidate(s = \"ab9 cd8 ef7 gh6 ij5 kl4 mn3 op2 qr1\") == \"qr op mn kl ij gh ef cd ab\"\n assert candidate(s = \"Open3 Source2 Software1\") == \"Software Source Open\"\n assert candidate(s = \"a9 quick8 brown7 fox6 jumps5 over4 lazy3 dogs2 one1\") == \"one dogs lazy over jumps fox brown quick a\"\n assert candidate(s = \"aA9 bB8 cC7 dD6 eE5 fF4 gG3 hH2 iI1\") == \"iI hH gG fF eE dD cC bB aA\"\n assert candidate(s = \"shuffle7 sentence6 original5 reconstruct4 and3 a2 is1\") == \"is a and reconstruct original sentence shuffle\"\n assert candidate(s = \"shuffle9 words8 correctly7 to6 get5 the4 right3 order2 one1\") == \"one order right the get to correctly words shuffle\"\n assert candidate(s = \"HELLO1 woRLD2\") == \"HELLO woRLD\"\n assert candidate(s = \"Short1 words2 can3 also4 be5 tricky6\") == \"Short words can also be tricky\"\n assert candidate(s = \"Python3 Java2 C1 Ruby4 Go5\") == \"C Java Python Ruby Go\"\n assert candidate(s = \"mixed8 case7 word6 CASE5 Mixed4 CASE3 mixed2 CASE1\") == \"CASE mixed CASE Mixed CASE word case mixed\"\n assert candidate(s = \"Python3 Java2 C1\") == \"C Java Python\"\n assert candidate(s = \"This8 is7 a6 sample5 sentence4 with3 various2 words1\") == \"words various with sentence sample a is This\"\n assert candidate(s = \"ninja9 samurai8 katana7 wakizashi6 tanto5 yoroi4 kusarigama3 tsurugi2 ninja1\") == \"ninja tsurugi kusarigama yoroi tanto wakizashi katana samurai ninja\"\n assert candidate(s = \"alpha9 beta8 gamma7 delta6 epsilon5 zeta4 eta3 theta2 iota1\") == \"iota theta eta zeta epsilon delta gamma beta alpha\"\n assert candidate(s = \"zebra9 yak8 xenon7 wolf6 vulture5 unicorn4 tiger3 snake2 rabbit1\") == \"rabbit snake tiger unicorn vulture wolf xenon yak zebra\"\n assert candidate(s = \"repeated1 same2 numbers3 in4 different5 words6 should7 not8 be9 valid10\") == \"repeated same numbers in different words should not be valid1\"\n assert candidate(s = \"reverse9 order8 words7 in6 this5 shuffled4 sentence3 into2 proper1\") == \"proper into sentence shuffled this in words order reverse\"\n assert candidate(s = \"Single1\") == \"Single\"\n", "comparison": "exact"}, "public_tests": ["\"is2 sentence4 This1 a3\"", "\"Myself2 Me1 I4 and3\""], "hints": ["Divide the string into the words as an array of strings", "Sort the words by removing the last character from each word and sorting according to it"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().sortSentence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:00+00:00", "tests_total": 70, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "sorting", "bubble-sort"]}, "language": "php", "interface": {"raw_signature": "function sortSentence($s) {", "container": "Solution", "callable": "sortSentence", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1860, "task_id": "incremental-memory-leak", "difficulty": "Medium", "problem_description": "You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.\n\nAt the i^th second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.\n\nReturn an array containing [crashTime, memory1_crash, memory2_crash], where crashTime is the time (in seconds) when the program crashed and memory1_crash and memory2_crash are the available bits of memory in the first and second sticks respectively.\n\nExample 1:\n\nInput: memory1 = 2, memory2 = 2\nOutput: [3,1,0]\nExplanation: The memory is allocated as follows:\n- At the 1^st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.\n- At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.\n- At the 3^rd second, the program crashes. The sticks have 1 and 0 bits available respectively.\n\nExample 2:\n\nInput: memory1 = 8, memory2 = 11\nOutput: [6,0,4]\nExplanation: The memory is allocated as follows:\n- At the 1^st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.\n- At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.\n- At the 3^rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.\n- At the 4^th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.\n- At the 5^th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.\n- At the 6^th second, the program crashes. The sticks have 0 and 4 bits available respectively.\n\nConstraints:\n\n- 0 <= memory1, memory2 <= 2^31 - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(memory1 = 0,memory2 = 0) == [1, 0, 0]\n assert candidate(memory1 = 2147483647,memory2 = 2147483647) == [92681, 88047, 41707]\n assert candidate(memory1 = 1000000000,memory2 = 1000000000) == [63245, 49116, 17494]\n assert candidate(memory1 = 15,memory2 = 10) == [7, 4, 0]\n assert candidate(memory1 = 100,memory2 = 100) == [20, 0, 10]\n assert candidate(memory1 = 10,memory2 = 10) == [6, 1, 4]\n assert candidate(memory1 = 1073741823,memory2 = 1073741823) == [65535, 65534, 32767]\n assert candidate(memory1 = 1,memory2 = 1) == [2, 0, 1]\n assert candidate(memory1 = 8,memory2 = 11) == [6, 0, 4]\n assert candidate(memory1 = 1073741824,memory2 = 1073741824) == [65536, 0, 32768]\n assert candidate(memory1 = 15,memory2 = 15) == [7, 6, 3]\n assert candidate(memory1 = 1,memory2 = 2) == [2, 1, 1]\n assert candidate(memory1 = 15,memory2 = 5) == [6, 0, 5]\n assert candidate(memory1 = 100,memory2 = 50) == [17, 3, 11]\n assert candidate(memory1 = 2,memory2 = 2) == [3, 1, 0]\n assert candidate(memory1 = 1000000000,memory2 = 500000000) == [54772, 3472, 37922]\n assert candidate(memory1 = 0,memory2 = 1000000) == [1414, 0, 1009]\n assert candidate(memory1 = 1024,memory2 = 512) == [55, 12, 39]\n assert candidate(memory1 = 123456789,memory2 = 987654321) == [47140, 11258, 33622]\n assert candidate(memory1 = 256,memory2 = 255) == [32, 15, 0]\n assert candidate(memory1 = 1000000000,memory2 = 999999999) == [63245, 17493, 49116]\n assert candidate(memory1 = 2048,memory2 = 512) == [71, 67, 8]\n assert candidate(memory1 = 5,memory2 = 1) == [3, 2, 1]\n assert candidate(memory1 = 500000000,memory2 = 499999999) == [44721, 8039, 30400]\n assert candidate(memory1 = 100000,memory2 = 100001) == [632, 460, 145]\n assert candidate(memory1 = 1073741823,memory2 = 1073741824) == [65536, 32767, 0]\n assert candidate(memory1 = 2147483647,memory2 = 1073741824) == [80264, 34153, 76602]\n assert candidate(memory1 = 1000000,memory2 = 0) == [1414, 1009, 0]\n assert candidate(memory1 = 5,memory2 = 5) == [4, 1, 3]\n assert candidate(memory1 = 0,memory2 = 100) == [14, 0, 9]\n assert candidate(memory1 = 1000000000,memory2 = 2000000000) == [77459, 17790, 72599]\n assert candidate(memory1 = 500000000,memory2 = 500000001) == [44721, 8040, 30401]\n assert candidate(memory1 = 500000,memory2 = 500000) == [1414, 151, 858]\n assert candidate(memory1 = 2000000000,memory2 = 1000000000) == [77459, 72599, 17790]\n assert candidate(memory1 = 1,memory2 = 0) == [2, 0, 0]\n assert candidate(memory1 = 1000000,memory2 = 1000000) == [2000, 0, 1000]\n assert candidate(memory1 = 2147483647,memory2 = 0) == [65536, 32767, 0]\n assert candidate(memory1 = 500000000,memory2 = 500000000) == [44721, 30400, 8040]\n assert candidate(memory1 = 1234567890,memory2 = 1234567890) == [70272, 29394, 64530]\n assert candidate(memory1 = 1024,memory2 = 1023) == [64, 31, 0]\n assert candidate(memory1 = 1023,memory2 = 1024) == [64, 31, 0]\n assert candidate(memory1 = 1048576,memory2 = 1048576) == [2048, 0, 1024]\n assert candidate(memory1 = 512,memory2 = 1024) == [55, 39, 12]\n assert candidate(memory1 = 1000000000,memory2 = 1000000001) == [63245, 17494, 49117]\n assert candidate(memory1 = 4,memory2 = 5) == [4, 2, 1]\n assert candidate(memory1 = 0,memory2 = 2147483647) == [65536, 0, 32767]\n assert candidate(memory1 = 512,memory2 = 2048) == [71, 8, 67]\n assert candidate(memory1 = 1000000,memory2 = 999999) == [2000, 999, 0]\n assert candidate(memory1 = 2147483647,memory2 = 2147483646) == [92681, 41706, 88047]\n assert candidate(memory1 = 4,memory2 = 4) == [4, 0, 2]\n assert candidate(memory1 = 4096,memory2 = 2048) == [110, 102, 47]\n assert candidate(memory1 = 1024,memory2 = 1024) == [64, 0, 32]\n assert candidate(memory1 = 2147483646,memory2 = 1) == [65536, 32766, 1]\n assert candidate(memory1 = 234567890,memory2 = 234567890) == [30631, 18665, 3350]\n assert candidate(memory1 = 2147483646,memory2 = 2147483646) == [92681, 88046, 41706]\n assert candidate(memory1 = 1,memory2 = 1000000000) == [44721, 1, 38440]\n assert candidate(memory1 = 999999999,memory2 = 1) == [44721, 38439, 1]\n assert candidate(memory1 = 500,memory2 = 500) == [44, 16, 38]\n assert candidate(memory1 = 2,memory2 = 1) == [2, 1, 1]\n assert candidate(memory1 = 128,memory2 = 256) == [27, 23, 10]\n assert candidate(memory1 = 1,memory2 = 1073741823) == [46341, 1, 20853]\n assert candidate(memory1 = 100000,memory2 = 100000) == [632, 144, 460]\n assert candidate(memory1 = 0,memory2 = 1000) == [45, 0, 10]\n assert candidate(memory1 = 2147483646,memory2 = 2147483645) == [92681, 41705, 88046]\n assert candidate(memory1 = 10,memory2 = 1) == [5, 0, 1]\n assert candidate(memory1 = 0,memory2 = 1) == [2, 0, 0]\n assert candidate(memory1 = 1000000001,memory2 = 1000000000) == [63245, 17494, 49117]\n assert candidate(memory1 = 1,memory2 = 2147483647) == [65536, 1, 32767]\n assert candidate(memory1 = 100,memory2 = 0) == [14, 9, 0]\n assert candidate(memory1 = 2147483646,memory2 = 2147483647) == [92681, 41706, 88047]\n assert candidate(memory1 = 1073741823,memory2 = 1073741825) == [65536, 0, 32768]\n assert candidate(memory1 = 10,memory2 = 15) == [7, 0, 4]\n assert candidate(memory1 = 9,memory2 = 9) == [6, 0, 3]\n assert candidate(memory1 = 1000,memory2 = 1000) == [63, 39, 8]\n assert candidate(memory1 = 2048,memory2 = 4096) == [110, 47, 102]\n assert candidate(memory1 = 1000,memory2 = 0) == [45, 10, 0]\n assert candidate(memory1 = 1,memory2 = 5) == [3, 1, 2]\n assert candidate(memory1 = 1000000000,memory2 = 1) == [44721, 38440, 1]\n", "comparison": "exact"}, "public_tests": ["2\n2", "8\n11"], "hints": ["What is the upper bound for the number of seconds?", "Simulate the process of allocating memory."], "metadata": {"canonical_parameter_names": ["memory1", "memory2"], "leetcode_dataset_entry_point": "Solution().memLeak", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:02+00:00", "tests_total": 81, "tests_dropped": 3, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function memLeak($memory1, $memory2) {", "container": "Solution", "callable": "memLeak", "parameters": [{"name": "memory1", "type": "Integer"}, {"name": "memory2", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1861, "task_id": "rotating-the-box", "difficulty": "Medium", "problem_description": "You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following:\n\n- A stone '#'\n- A stationary obstacle '*'\n- Empty '.'\n\nThe box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.\n\nIt is guaranteed that each stone in boxGrid rests on an obstacle, another stone, or the bottom of the box.\n\nReturn an n x m matrix representing the box after the rotation described above.\n\nExample 1:\n\nInput: boxGrid = [[\"#\",\".\",\"#\"]]\nOutput: [[\".\"],\n [\"#\"],\n [\"#\"]]\n\nExample 2:\n\nInput: boxGrid = [[\"#\",\".\",\"*\",\".\"],\n [\"#\",\"#\",\"*\",\".\"]]\nOutput: [[\"#\",\".\"],\n [\"#\",\"#\"],\n [\"*\",\"*\"],\n [\".\",\".\"]]\n\nExample 3:\n\nInput: boxGrid = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],\n [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],\n [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]\nOutput: [[\".\",\"#\",\"#\"],\n [\".\",\"#\",\"#\"],\n [\"#\",\"#\",\"*\"],\n [\"#\",\"*\",\".\"],\n [\"#\",\".\",\"*\"],\n [\"#\",\".\",\".\"]]\n\nConstraints:\n\n- m == boxGrid.length\n- n == boxGrid[i].length\n- 1 <= m, n <= 500\n- boxGrid[i][j] is either '#', '*', or '.'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(boxGrid = [['#', '.', '*', '.'], ['#', '#', '*', '.']]) == [['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]\n assert candidate(boxGrid = [['#', '.', '#']]) == [['.'], ['#'], ['#']]\n assert candidate(boxGrid = [['#', '#', '*', '.', '*', '.'], ['#', '#', '#', '*', '.', '.'], ['#', '#', '#', '.', '#', '.']]) == [['.', '#', '#'], ['.', '#', '#'], ['#', '#', '*'], ['#', '*', '.'], ['#', '.', '*'], ['#', '.', '.']]\n assert candidate(boxGrid = [['*', '.', '.', '.', '#', '.', '*', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '*'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '*'], ['#', '.', '.', '.', '.']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '*', '.', '.', '.', '.', '.'], ['.', '.', '#', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '#', '.', '#', '#', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '#', '*', '.'], ['.', '#', '.', '.', '#', '.'], ['.', '.', '#', '.', '.', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['.', '.', '#'], ['.', '.', '#'], ['.', '#', '*'], ['#', '#', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '#', '.'], ['*', '.', '#', '.', '.', '#'], ['#', '.', '*', '.', '#', '.'], ['.', '#', '#', '*', '.', '.']]) == [['.', '.', '*', '.'], ['#', '#', '.', '.'], ['#', '*', '.', '.'], ['*', '.', '.', '.'], ['.', '.', '#', '#'], ['.', '#', '#', '#']]\n assert candidate(boxGrid = [['.', '.', '#', '*'], ['*', '.', '.', '#'], ['.', '#', '.', '.'], ['#', '.', '.', '.']]) == [['.', '.', '*', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '#'], ['#', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '*', '.', '.'], ['.', '#', '#', '.', '.', '#'], ['#', '.', '.', '.', '#', '.'], ['#', '.', '*', '.', '.', '*'], ['.', '.', '.', '#', '#', '.']]) == [['.', '.', '.', '.', '.'], ['.', '#', '.', '.', '.'], ['.', '*', '.', '.', '#'], ['.', '.', '.', '#', '*'], ['#', '.', '#', '#', '.'], ['#', '*', '#', '#', '.']]\n assert candidate(boxGrid = [['*', '.', '.', '#'], ['.', '#', '#', '*'], ['.', '#', '.', '.'], ['.', '.', '.', '.']]) == [['.', '.', '.', '*'], ['.', '.', '#', '.'], ['.', '.', '#', '.'], ['.', '#', '*', '#']]\n assert candidate(boxGrid = [['#', '.', '*', '.', '#', '.', '*', '.'], ['.', '#', '.', '.', '.', '#', '.', '.'], ['.', '.', '#', '.', '.', '.', '#', '.']]) == [['.', '.', '.'], ['.', '.', '#'], ['.', '.', '*'], ['.', '.', '.'], ['.', '.', '.'], ['.', '.', '#'], ['#', '#', '*'], ['#', '#', '.']]\n assert candidate(boxGrid = [['#', '#', '.', '.', '*'], ['.', '#', '#', '.', '.'], ['.', '.', '*', '.', '#'], ['#', '.', '.', '#', '.']]) == [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '*', '.', '#'], ['#', '.', '#', '#'], ['#', '#', '#', '*']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '*'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '*', '.'], ['.', '.', '#', '*', '.', '.', '.'], ['#', '*', '.', '.', '.', '.', '.']]) == [['#', '.', '.', '.'], ['*', '.', '.', '.'], ['.', '#', '.', '.'], ['.', '*', '.', '.'], ['.', '.', '#', '.'], ['.', '.', '*', '.'], ['.', '.', '.', '#']]\n assert candidate(boxGrid = [['#', '#', '*', '#', '.', '.', '*', '.', '.'], ['.', '#', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '#', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '*', '.', '.'], ['.', '.', '.', '.', '#', '.', '.', '#', '.']]) == [['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '*'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '*', '.', '.', '*'], ['#', '.', '#', '.', '.'], ['#', '.', '#', '#', '.']]\n assert candidate(boxGrid = [['.', '.', '#', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '*'], ['.', '.', '#', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '#', '.', '.', '.', '.', '.'], ['.', '.', '#', '*', '#', '.', '#', '#']]\n assert candidate(boxGrid = [['#', '#', '#', '.', '.', '.', '*'], ['.', '.', '#', '#', '.', '.', '.'], ['.', '#', '.', '.', '.', '#', '.'], ['.', '.', '.', '*', '.', '.', '.'], ['#', '.', '#', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.', '.'], ['.', '*', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.', '.', '.'], ['*', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '*', '.', '.', '#'], ['.', '.', '#', '.', '.', '.', '#'], ['.', '.', '#', '.', '#', '#', '#'], ['.', '#', '#', '.', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '#', '*', '.', '*', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['*', '.', '.', '.', '*', '.', '.'], ['.', '#', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '#']]) == [['.', '.', '*', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '*'], ['.', '.', '*', '.', '.'], ['.', '#', '.', '.', '*'], ['#', '#', '.', '.', '.']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['#', '#', '#', '.'], ['.', '.', '#', '.'], ['.', '#', '.', '.']]) == [['.', '.', '.', '.'], ['.', '.', '#', '.'], ['.', '.', '#', '.'], ['#', '#', '#', '.']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '*'], ['#', '#', '#', '#', '#']]) == [['#', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.'], ['#', '*', '.', '.', '.', '.']]\n assert candidate(boxGrid = [['#', '#', '#', '#', '#', '#'], ['.', '.', '.', '.', '.', '.'], ['*', '*', '*', '*', '*', '*']]) == [['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#']]\n assert candidate(boxGrid = [['.', '.', '#', '*', '#'], ['#', '.', '#', '.', '.'], ['.', '*', '.', '#', '.']]) == [['.', '.', '.'], ['*', '.', '.'], ['.', '.', '#'], ['.', '#', '*'], ['#', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.', '.'], ['.', '.', '#', '.', '.', '.', '.'], ['.', '.', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#', '.'], ['.', '.', '.', '.', '.', '.', '*']]) == [['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['*', '#', '#', '#', '#', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '#', '.', '#', '.', '*', '.'], ['.', '.', '#', '.', '.', '.', '#', '.'], ['#', '.', '.', '.', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.'], ['*', '.', '.', '.', '.', '.', '.', '*'], ['.', '#', '.', '.', '.', '.', '.', '.']]) == [['.', '*', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '#', '.', '#'], ['.', '.', '.', '*', '.', '#'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '*'], ['#', '*', '.', '.', '#', '.']]\n assert candidate(boxGrid = [['#', '#', '#', '#', '*', '.'], ['.', '.', '*', '#', '.', '#'], ['*', '.', '#', '.', '.', '#'], ['#', '#', '#', '#', '.', '.']]) == [['.', '*', '.', '#'], ['.', '.', '.', '#'], ['#', '.', '*', '#'], ['#', '.', '.', '#'], ['#', '#', '#', '*'], ['#', '#', '#', '.']]\n assert candidate(boxGrid = [['*', '.', '.', '#', '.', '*'], ['.', '#', '.', '.', '.', '#'], ['.', '.', '#', '.', '*', '.'], ['#', '.', '.', '.', '.', '#'], ['.', '*', '.', '#', '.', '.']]) == [['.', '.', '.', '.', '*'], ['*', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '#', '.', '.'], ['.', '#', '*', '#', '#'], ['#', '#', '.', '#', '*']]\n assert candidate(boxGrid = [['.', '.', '#', '.', '*', '.', '#'], ['#', '.', '.', '.', '.', '.', '#'], ['.', '#', '#', '*', '.', '.', '.'], ['.', '.', '.', '.', '.', '*', '.']]) == [['.', '.', '.', '.'], ['.', '#', '.', '.'], ['.', '#', '.', '.'], ['.', '*', '.', '#'], ['.', '.', '.', '*'], ['*', '.', '#', '.'], ['.', '.', '#', '#']]\n assert candidate(boxGrid = [['#', '*', '#', '*', '.', '#'], ['.', '#', '.', '.', '.', '.'], ['#', '.', '.', '*', '#', '.'], ['*', '.', '.', '.', '#', '.'], ['.', '.', '#', '.', '.', '.']]) == [['.', '*', '.', '.', '#'], ['.', '.', '.', '.', '*'], ['.', '.', '#', '.', '#'], ['.', '.', '*', '.', '*'], ['.', '.', '.', '.', '.'], ['#', '#', '#', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '#', '.', '.', '.', '#'], ['.', '.', '.', '#', '.', '.', '.'], ['.', '#', '.', '.', '.', '#', '.'], ['#', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '#'], ['.', '#', '.', '#'], ['#', '#', '#', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['#', '#', '.', '#', '.', '.', '#'], ['.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.'], ['.', '#', '.', '.', '.', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '#']]) == [['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.', '.', '.', '#']]\n assert candidate(boxGrid = [['*', '*', '*', '*', '*'], ['#', '#', '#', '#', '#'], ['.', '.', '.', '.', '.'], ['*', '*', '#', '#', '.'], ['#', '#', '.', '.', '.']]) == [['.', '*', '.', '#', '*'], ['.', '*', '.', '#', '*'], ['.', '.', '.', '#', '*'], ['#', '#', '.', '#', '*'], ['#', '#', '.', '#', '*']]\n assert candidate(boxGrid = [['#', '#', '.', '.', '.', '.'], ['.', '#', '#', '.', '.', '.'], ['.', '.', '#', '#', '.', '.'], ['.', '.', '.', '#', '#', '.'], ['.', '.', '.', '.', '#', '#'], ['.', '.', '.', '.', '.', '#']]) == [['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '#', '#', '#', '#', '#'], ['#', '#', '#', '#', '#', '#']]\n assert candidate(boxGrid = [['*', '.', '.', '.', '.', '.', '#', '.', '*'], ['.', '.', '#', '.', '.', '.', '.', '#', '.'], ['.', '#', '.', '#', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#', '.', '.', '#', '.'], ['.', '.', '#', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '#', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.', '.', '.', '.', '*'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '#', '#', '#', '#'], ['.', '.', '.', '#', '#', '#', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '*'], ['.', '#', '.', '.', '.'], ['.', '.', '#', '.', '.'], ['.', '.', '.', '#', '.'], ['.', '.', '.', '.', '#']]) == [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['#', '#', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '#', '.', '.', '*', '.'], ['#', '.', '.', '#', '.', '.'], ['*', '#', '.', '.', '.', '#'], ['.', '.', '.', '#', '*', '.'], ['#', '.', '.', '.', '.', '.']]) == [['.', '.', '*', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '#', '.', '.', '#'], ['.', '*', '#', '#', '*'], ['#', '.', '#', '#', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '.', '.', '*'], ['#', '#', '.', '.', '.', '*', '.'], ['*', '.', '.', '#', '.', '.', '.'], ['.', '#', '#', '.', '.', '.', '#'], ['#', '.', '.', '.', '#', '.', '.'], ['.', '.', '#', '.', '.', '#', '.']]) == [['.', '.', '.', '*', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#', '.'], ['.', '.', '#', '.', '#', '.'], ['#', '#', '#', '.', '*', '#'], ['#', '#', '#', '#', '.', '*']]\n assert candidate(boxGrid = [['#', '#', '.', '.', '*', '.'], ['.', '#', '#', '*', '.', '#'], ['.', '.', '#', '#', '#', '.'], ['*', '.', '.', '#', '.', '.'], ['.', '#', '.', '.', '#', '*']]) == [['.', '*', '.', '.', '.'], ['.', '.', '.', '#', '.'], ['.', '.', '.', '#', '#'], ['#', '.', '#', '*', '#'], ['#', '.', '#', '.', '*'], ['*', '#', '#', '#', '.']]\n assert candidate(boxGrid = [['#', '#', '.', '.', '*', '.'], ['#', '.', '#', '.', '.', '*'], ['.', '#', '.', '#', '.', '.'], ['.', '.', '.', '.', '#', '.'], ['.', '*', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.'], ['*', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '#', '#'], ['.', '.', '#', '#', '*'], ['.', '#', '#', '*', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '#', '.', '.', '*', '.', '.', '#'], ['.', '#', '#', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#'], ['.', '.', '.', '.', '*'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '#', '.'], ['.', '#', '.', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '#']]) == [['.'], ['#'], ['#']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['*', '*', '*', '*']]) == [['*', '.'], ['*', '.'], ['*', '.'], ['*', '.']]\n assert candidate(boxGrid = [['#', '.', '#']]) == [['.'], ['#'], ['#']]\n assert candidate(boxGrid = [['*'], ['.'], ['#']]) == [['#', '.', '*']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['*', '*', '*', '*']]) == [['*', '.', '.'], ['*', '.', '.'], ['*', '.', '.'], ['*', '.', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '#'], ['.', '#', '.', '.'], ['.', '.', '#', '.'], ['#', '.', '.', '*']]) == [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['#', '.', '.', '#'], ['*', '#', '#', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]) == [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '*'], ['.', '#', '.', '*'], ['#', '.', '#', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['#', '#', '#'], ['#', '*', '*']]\n assert candidate(boxGrid = [['#', '#', '#'], ['*', '*', '*'], ['#', '#', '#']]) == [['#', '*', '#'], ['#', '*', '#'], ['#', '*', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['#', '#', '*', '.'], ['#', '#', '#', '*']]) == [['#', '#', '.', '.'], ['#', '#', '.', '.'], ['#', '*', '.', '.'], ['*', '.', '.', '.']]\n assert candidate(boxGrid = [['#', '#', '#'], ['.', '.', '.'], ['*', '*', '*']]) == [['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#']]\n assert candidate(boxGrid = [['.', '#', '#', '*']]) == [['.'], ['#'], ['#'], ['*']]\n assert candidate(boxGrid = [['#', '.', '#']]) == [['.'], ['#'], ['#']]\n assert candidate(boxGrid = [['*', '*', '*', '*']]) == [['*'], ['*'], ['*'], ['*']]\n assert candidate(boxGrid = [['#', '#', '#', '#', '#', '*', '.'], ['.', '.', '.', '.', '.', '.', '.'], ['*', '*', '*', '*', '*', '*', '*']]) == [['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '*'], ['*', '.', '.']]\n assert candidate(boxGrid = [['.', '#', '*', '#', '.', '*'], ['#', '.', '#', '.', '.', '#'], ['*', '.', '.', '#', '*', '.'], ['.', '#', '#', '*', '#', '.']]) == [['.', '*', '.', '.'], ['#', '.', '.', '#'], ['#', '.', '.', '*'], ['*', '#', '#', '.'], ['.', '*', '#', '#'], ['#', '.', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '*'], ['.', '#', '.', '.'], ['.', '.', '#', '*']]) == [['.', '.', '.'], ['.', '.', '.'], ['#', '.', '#'], ['*', '#', '*']]\n assert candidate(boxGrid = [['#', '#', '*', '.', '*', '.'], ['#', '#', '#', '*', '.', '.'], ['#', '#', '#', '.', '#', '.']]) == [['.', '#', '#'], ['.', '#', '#'], ['#', '#', '*'], ['#', '*', '.'], ['#', '.', '*'], ['#', '.', '.']]\n assert candidate(boxGrid = [['#', '#'], ['*', '.'], ['#', '.']]) == [['.', '*', '#'], ['#', '.', '#']]\n assert candidate(boxGrid = [['#', '*'], ['#', '*']]) == [['#', '#'], ['*', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '*'], ['.', '#', '.', '.'], ['.', '.', '#', '.'], ['.', '.', '.', '*']]) == [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '#'], ['*', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '#', '#'], ['.', '.', '.'], ['*', '*', '*']]) == [['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#']]\n assert candidate(boxGrid = [['#', '.', '*', '#', '.', '*'], ['#', '#', '.', '.', '#', '.'], ['.', '#', '#', '*', '.', '.'], ['*', '.', '.', '.', '.', '*']]) == [['*', '.', '.', '.'], ['.', '#', '.', '#'], ['.', '#', '.', '*'], ['.', '*', '#', '.'], ['.', '.', '#', '#'], ['*', '.', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '*'], ['.', '#', '.'], ['*', '.', '#']]) == [['*', '.', '.'], ['.', '.', '#'], ['#', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '*'], ['.', '#', '.', '#'], ['.', '.', '#', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['.', '#', '#'], ['#', '#', '*']]\n assert candidate(boxGrid = [['.', '#', '.'], ['*', '.', '#'], ['#', '#', '*']]) == [['#', '*', '.'], ['#', '.', '.'], ['*', '#', '#']]\n assert candidate(boxGrid = [['.', '#', '.', '*', '.', '#'], ['.', '.', '.', '.', '.', '.'], ['*', '.', '#', '.', '.', '*']]) == [['*', '.', '.'], ['.', '.', '.'], ['.', '.', '#'], ['.', '.', '*'], ['#', '.', '.'], ['*', '.', '#']]\n assert candidate(boxGrid = [['#', '#', '#', '#', '#'], ['.', '.', '.', '.', '.'], ['*', '*', '*', '*', '*']]) == [['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#'], ['*', '.', '#']]\n assert candidate(boxGrid = [['.', '#', '*'], ['.', '.', '#'], ['#', '.', '.']]) == [['.', '.', '.'], ['.', '.', '#'], ['#', '#', '*']]\n assert candidate(boxGrid = [['#', '#', '.', '*'], ['.', '.', '.', '.'], ['.', '*', '.', '#'], ['#', '.', '#', '*']]) == [['.', '.', '.', '.'], ['#', '*', '.', '#'], ['#', '.', '.', '#'], ['*', '#', '.', '*']]\n assert candidate(boxGrid = [['*', '.', '.', '.'], ['#', '#', '#', '.'], ['*', '*', '#', '.']]) == [['*', '.', '*'], ['*', '#', '.'], ['.', '#', '.'], ['#', '#', '.']]\n assert candidate(boxGrid = [['#', '#', '#'], ['#', '#', '#'], ['#', '#', '#']]) == [['#', '#', '#'], ['#', '#', '#'], ['#', '#', '#']]\n assert candidate(boxGrid = [['#', '#', '#'], ['*', '*', '*'], ['.', '.', '.']]) == [['.', '*', '#'], ['.', '*', '#'], ['.', '*', '#']]\n assert candidate(boxGrid = [['*', '.', '.', '#'], ['*', '.', '.', '.'], ['#', '.', '.', '*']]) == [['.', '*', '*'], ['.', '.', '.'], ['#', '.', '.'], ['*', '.', '#']]\n assert candidate(boxGrid = [['*', '*', '*', '*'], ['#', '#', '#', '#'], ['*', '*', '*', '*'], ['#', '#', '#', '#']]) == [['#', '*', '#', '*'], ['#', '*', '#', '*'], ['#', '*', '#', '*'], ['#', '*', '#', '*']]\n assert candidate(boxGrid = [['#', '*'], ['#', '.'], ['#', '.'], ['#', '.']]) == [['.', '.', '.', '#'], ['#', '#', '#', '*']]\n assert candidate(boxGrid = [['#'], ['*'], ['.']]) == [['.', '*', '#']]\n assert candidate(boxGrid = [['.', '#', '*', '.', '#'], ['.', '.', '#', '.', '.'], ['#', '.', '.', '*', '.']]) == [['.', '.', '.'], ['.', '.', '#'], ['#', '.', '*'], ['*', '.', '.'], ['.', '#', '#']]\n assert candidate(boxGrid = [['#', '*', '.'], ['.', '#', '.'], ['.', '.', '#']]) == [['.', '.', '#'], ['.', '.', '*'], ['#', '#', '.']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['#', '#', '#', '#'], ['.', '*', '.', '*'], ['#', '.', '#', '.']]) == [['.', '.', '#', '.'], ['.', '*', '#', '.'], ['#', '.', '#', '.'], ['#', '*', '#', '.']]\n assert candidate(boxGrid = [['*', '*', '.', '*'], ['*', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '.', '#']]) == [['.', '.', '*', '*'], ['.', '.', '.', '*'], ['.', '.', '.', '.'], ['#', '.', '.', '*']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['#', '#', '#', '#'], ['*', '.', '*', '.']]) == [['*', '#', '.'], ['.', '#', '.'], ['*', '#', '.'], ['.', '#', '.']]\n assert candidate(boxGrid = [['.', '#'], ['.', '*'], ['#', '.'], ['*', '.']]) == [['*', '.', '.', '.'], ['.', '#', '*', '#']]\n assert candidate(boxGrid = [['.', '.', '*', '.', '#'], ['#', '.', '#', '.', '.'], ['.', '#', '.', '*', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['#', '.', '*'], ['*', '#', '.'], ['.', '#', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['#', '#', '#', '#'], ['*', '.', '.', '*']]) == [['*', '#', '.', '.'], ['.', '#', '.', '.'], ['.', '#', '.', '.'], ['*', '#', '.', '.']]\n assert candidate(boxGrid = [['#', '.', '*', '.'], ['#', '#', '*', '.']]) == [['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]\n assert candidate(boxGrid = [['#', '*', '#'], ['*', '#', '*'], ['#', '*', '#']]) == [['#', '*', '#'], ['*', '#', '*'], ['#', '*', '#']]\n assert candidate(boxGrid = [['.', '#', '*', '#', '.', '.', '#'], ['#', '.', '.', '.', '#', '.', '.'], ['.', '*', '.', '.', '.', '#', '#'], ['.', '.', '#', '.', '.', '.', '*']]) == [['.', '.', '.', '.'], ['.', '*', '.', '#'], ['.', '.', '.', '*'], ['.', '.', '.', '.'], ['.', '.', '.', '.'], ['#', '#', '#', '#'], ['*', '#', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '*', '.'], ['#', '#', '*', '.']]) == [['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]\n assert candidate(boxGrid = [['#'], ['.'], ['*']]) == [['*', '.', '#']]\n assert candidate(boxGrid = [['*', '.', '#'], ['.', '#', '.'], ['#', '.', '*']]) == [['.', '.', '*'], ['#', '.', '.'], ['*', '#', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '#'], ['.', '.', '#', '.', '.'], ['#', '#', '#', '*', '.']]) == [['#', '.', '.'], ['#', '.', '.'], ['#', '.', '.'], ['*', '.', '#'], ['.', '#', '#']]\n assert candidate(boxGrid = [['#', '.', '.', '.', '*'], ['#', '.', '.', '.', '.'], ['#', '.', '#', '.', '.'], ['#', '#', '.', '.', '.'], ['#', '.', '.', '#', '.'], ['#', '#', '#', '.', '.']]) == [['.', '.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.', '.'], ['#', '.', '.', '.', '.', '.'], ['#', '#', '#', '#', '.', '#'], ['#', '#', '#', '#', '#', '*']]\n assert candidate(boxGrid = [['#', '.', '#'], ['.', '*', '.'], ['#', '#', '#']]) == [['#', '.', '.'], ['#', '*', '#'], ['#', '.', '#']]\n assert candidate(boxGrid = [['#', '#', '*', '.', '*', '.'], ['#', '#', '#', '*', '.', '.'], ['#', '#', '#', '.', '#', '.']]) == [['.', '#', '#'], ['.', '#', '#'], ['#', '#', '*'], ['#', '*', '.'], ['#', '.', '*'], ['#', '.', '.']]\n assert candidate(boxGrid = [['#', '#', '*', '.', '*', '.'], ['#', '#', '#', '*', '.', '.'], ['#', '#', '#', '.', '#', '.']]) == [['.', '#', '#'], ['.', '#', '#'], ['#', '#', '*'], ['#', '*', '.'], ['#', '.', '*'], ['#', '.', '.']]\n assert candidate(boxGrid = [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']]) == [['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*']]\n assert candidate(boxGrid = [['.', '.', '#'], ['.', '.', '.'], ['#', '.', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['#', '.', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '*'], ['#', '.', '#', '.'], ['.', '#', '.', '.'], ['#', '.', '.', '.']]) == [['.', '.', '.', '.'], ['.', '.', '.', '.'], ['.', '.', '#', '.'], ['#', '#', '#', '*']]\n assert candidate(boxGrid = [['.', '.', '.', '.', '.'], ['#', '#', '#', '#', '#'], ['*', '*', '*', '*', '*']]) == [['*', '#', '.'], ['*', '#', '.'], ['*', '#', '.'], ['*', '#', '.'], ['*', '#', '.']]\n assert candidate(boxGrid = [['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']]) == [['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']]\n assert candidate(boxGrid = [['#', '#', '#', '*'], ['.', '.', '.', '.'], ['*', '.', '.', '*']]) == [['*', '.', '#'], ['.', '.', '#'], ['.', '.', '#'], ['*', '.', '*']]\n assert candidate(boxGrid = [['*', '*', '*', '*'], ['#', '#', '#', '#'], ['#', '#', '#', '#'], ['*', '*', '*', '*']]) == [['*', '#', '#', '*'], ['*', '#', '#', '*'], ['*', '#', '#', '*'], ['*', '#', '#', '*']]\n assert candidate(boxGrid = [['.', '.', '#', '*', '.'], ['#', '#', '.', '.', '#'], ['.', '*', '#', '.', '.']]) == [['.', '.', '.'], ['*', '.', '.'], ['.', '#', '#'], ['.', '#', '*'], ['#', '#', '.']]\n assert candidate(boxGrid = [['#', '.', '*', '.'], ['#', '#', '*', '.']]) == [['#', '.'], ['#', '#'], ['*', '*'], ['.', '.']]\n assert candidate(boxGrid = [['*', '*', '*', '*'], ['.', '.', '.', '.'], ['#', '#', '#', '#']]) == [['#', '.', '*'], ['#', '.', '*'], ['#', '.', '*'], ['#', '.', '*']]\n assert candidate(boxGrid = [['#', '.', '.', '#'], ['.', '#', '#', '.'], ['.', '*', '.', '*']]) == [['.', '.', '.'], ['*', '.', '.'], ['.', '#', '#'], ['*', '#', '#']]\n assert candidate(boxGrid = [['#', '*', '*', '#'], ['#', '#', '#', '.'], ['*', '.', '.', '*']]) == [['*', '.', '#'], ['.', '#', '*'], ['.', '#', '*'], ['*', '#', '#']]\n assert candidate(boxGrid = [['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*']]) == [['*', '*', '*'], ['*', '*', '*'], ['*', '*', '*']]\n assert candidate(boxGrid = [['#', '*', '.'], ['.', '.', '*'], ['*', '.', '.']]) == [['*', '.', '#'], ['.', '.', '*'], ['.', '*', '.']]\n assert candidate(boxGrid = [['*', '.', '.', '#'], ['#', '#', '#', '*'], ['#', '#', '.', '#']]) == [['.', '#', '*'], ['#', '#', '.'], ['#', '#', '.'], ['#', '*', '#']]\n assert candidate(boxGrid = [['.', '.', '.', '*'], ['.', '#', '.', '.'], ['.', '#', '#', '.'], ['*', '#', '.', '*']]) == [['*', '.', '.', '.'], ['.', '.', '.', '.'], ['#', '#', '.', '.'], ['*', '#', '#', '*']]\n", "comparison": "exact"}, "public_tests": ["[[\"#\",\".\",\"#\"]]", "[[\"#\",\".\",\"*\",\".\"],[\"#\",\"#\",\"*\",\".\"]]", "[[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],[\"#\",\"#\",\"#\",\"*\",\".\",\".\"],[\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]"], "hints": ["Rotate the box using the relation rotatedBox[i][j] = box[m - 1 - j][i].", "Start iterating from the bottom of the box and for each empty cell check if there is any stone above it with no obstacles between them."], "metadata": {"canonical_parameter_names": ["boxGrid"], "leetcode_dataset_entry_point": "Solution().rotateTheBox", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:05+00:00", "tests_total": 114, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "matrix"]}, "language": "php", "interface": {"raw_signature": "function rotateTheBox($boxGrid) {", "container": "Solution", "callable": "rotateTheBox", "parameters": [{"name": "boxGrid", "type": "String[][]"}], "return_type": "String[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1862, "task_id": "sum-of-floored-pairs", "difficulty": "Hard", "problem_description": "Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 10^9 + 7.\n\nThe floor() function returns the integer part of the division.\n\nExample 1:\n\nInput: nums = [2,5,9]\nOutput: 10\nExplanation:\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\nWe calculate the floor of the division for every pair of indices in the array then sum them up.\n\nExample 2:\n\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 49\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 = [7, 7, 7, 7, 7, 7, 7]) == 49\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 100\n assert candidate(nums = [2, 5, 9]) == 10\n assert candidate(nums = [100000, 1, 100000]) == 200005\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250]) == 57\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 400\n assert candidate(nums = [10, 20, 30, 40, 50]) == 27\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 178\n assert candidate(nums = [1, 2, 3, 4, 5]) == 27\n assert candidate(nums = [100000, 100000, 100000]) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 65519\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980]) == 210\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 600\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 127\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]) == 3249\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]) == 1492\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 127\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]) == 2400\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]) == 6268\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 834\n assert candidate(nums = [15, 15, 15, 30, 30, 45, 45, 60, 60, 75, 75, 90, 90, 105, 105]) == 287\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 55\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 100\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 371\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 508\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 600\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 314\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000]) == 991\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 508\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]) == 1650\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 623578\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000]) == 123456\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == 127\n assert candidate(nums = [100000, 100000, 50000, 50000, 25000, 25000, 12500, 12500, 6250, 6250]) == 228\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 127\n assert candidate(nums = [50000, 40000, 30000, 20000, 10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1]) == 314353\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50]) == 508\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]) == 513\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 400\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2036\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 127\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 2806\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 600\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 313945\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 949\n assert candidate(nums = [50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1]) == 166591\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 6400\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225]) == 314\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]) == 2841\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 65519\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]) == 1024\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 600\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 314\n assert candidate(nums = [3, 3, 3, 5, 5, 5, 7, 7, 7, 11, 11, 11, 13, 13, 13, 17, 17, 17, 19, 19]) == 412\n assert candidate(nums = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 1]) == 500096\n", "comparison": "exact"}, "public_tests": ["[2,5,9]", "[7,7,7,7,7,7,7]"], "hints": ["Find the frequency (number of occurrences) of all elements in the array.", "For each element, iterate through its multiples and multiply frequencies to find the answer."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfFlooredPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:09+00:00", "tests_total": 60, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "math", "binary-search", "counting", "enumeration", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function sumOfFlooredPairs($nums) {", "container": "Solution", "callable": "sumOfFlooredPairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1863, "task_id": "sum-of-all-subset-xor-totals", "difficulty": "Easy", "problem_description": "The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.\n\n- For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.\n\nGiven an array nums, return the sum of all XOR totals for every subset of nums.\n\nNote: Subsets with the same elements should be counted multiple times.\n\nAn array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.\n\nExample 1:\n\nInput: nums = [1,3]\nOutput: 6\nExplanation: The 4 subsets of [1,3] are:\n- The empty subset has an XOR total of 0.\n- [1] has an XOR total of 1.\n- [3] has an XOR total of 3.\n- [1,3] has an XOR total of 1 XOR 3 = 2.\n0 + 1 + 3 + 2 = 6\n\nExample 2:\n\nInput: nums = [5,1,6]\nOutput: 28\nExplanation: The 8 subsets of [5,1,6] are:\n- The empty subset has an XOR total of 0.\n- [5] has an XOR total of 5.\n- [1] has an XOR total of 1.\n- [6] has an XOR total of 6.\n- [5,1] has an XOR total of 5 XOR 1 = 4.\n- [5,6] has an XOR total of 5 XOR 6 = 3.\n- [1,6] has an XOR total of 1 XOR 6 = 7.\n- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n\nExample 3:\n\nInput: nums = [3,4,5,6,7,8]\nOutput: 480\nExplanation: The sum of all XOR totals for every subset is 480.\n\nConstraints:\n\n- 1 <= nums.length <= 12\n- 1 <= nums[i] <= 20\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 1, 6]) == 28\n assert candidate(nums = [1, 1, 1, 1]) == 8\n assert candidate(nums = [1, 2, 4, 8, 16]) == 496\n assert candidate(nums = [10, 11, 12]) == 60\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14]) == 896\n assert candidate(nums = [2, 3, 5]) == 28\n assert candidate(nums = [11, 2, 3, 14, 7]) == 240\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [7, 8, 9, 10, 11]) == 240\n assert candidate(nums = [1, 2, 3, 4]) == 56\n assert candidate(nums = [3, 4, 5, 6, 7, 8]) == 480\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 30720\n assert candidate(nums = [2, 3, 5, 7]) == 56\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9]) == 63488\n assert candidate(nums = [1, 3]) == 6\n assert candidate(nums = [2, 2, 2, 2]) == 16\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 15360\n assert candidate(nums = [15, 16, 17, 18, 19, 20]) == 992\n assert candidate(nums = [1, 2, 3]) == 12\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2048\n assert candidate(nums = [6, 3, 5, 2, 1, 9]) == 480\n assert candidate(nums = [3, 3, 3, 5, 5, 5, 7, 7, 7, 11, 11, 11]) == 30720\n assert candidate(nums = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8]) == 63488\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 30720\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 14336\n assert candidate(nums = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8]) == 63488\n assert candidate(nums = [2, 3, 4, 5, 6]) == 112\n assert candidate(nums = [3, 5, 7, 9, 11, 13]) == 480\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 15360\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14]) == 896\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9]) == 63488\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 14336\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 15360\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7]) == 1984\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4]) == 30720\n assert candidate(nums = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 30720\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]) == 30720\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19]) == 3968\n", "comparison": "exact"}, "public_tests": ["[1,3]", "[5,1,6]", "[3,4,5,6,7,8]"], "hints": ["Is there a way to iterate through all the subsets of the array?", "Can we use recursion to efficiently iterate through all the subsets?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().subsetXORSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:11+00:00", "tests_total": 99, "tests_dropped": 61, "flags": [], "topic_tags": ["array", "math", "backtracking", "bit-manipulation", "combinatorics", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function subsetXORSum($nums) {", "container": "Solution", "callable": "subsetXORSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1864, "task_id": "minimum-number-of-swaps-to-make-the-binary-string-alternating", "difficulty": "Medium", "problem_description": "Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.\n\nThe string is called alternating if no two adjacent characters are equal. For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\n\nAny two characters may be swapped, even if they are not adjacent.\n\nExample 1:\n\nInput: s = \"111000\"\nOutput: 1\nExplanation: Swap positions 1 and 4: \"111000\" -> \"101010\"\nThe string is now alternating.\n\nExample 2:\n\nInput: s = \"010\"\nOutput: 0\nExplanation: The string is already alternating, no swaps are needed.\n\nExample 3:\n\nInput: s = \"1110\"\nOutput: -1\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == -1\n assert candidate(s = \"1100110\") == 2\n assert candidate(s = \"110011\") == -1\n assert candidate(s = \"00110011\") == 2\n assert candidate(s = \"0101010\") == 0\n assert candidate(s = \"111\") == -1\n assert candidate(s = \"11110000\") == 2\n assert candidate(s = \"1110\") == -1\n assert candidate(s = \"0000\") == -1\n assert candidate(s = \"01010\") == 0\n assert candidate(s = \"111000\") == 1\n assert candidate(s = \"10101\") == 0\n assert candidate(s = \"1100\") == 1\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"1010101\") == 0\n assert candidate(s = \"1010\") == 0\n assert candidate(s = \"0101\") == 0\n assert candidate(s = \"000111\") == 1\n assert candidate(s = \"000\") == -1\n assert candidate(s = \"01010101\") == 0\n assert candidate(s = \"10101010\") == 0\n assert candidate(s = \"110\") == 1\n assert candidate(s = \"1010101010\") == 0\n assert candidate(s = \"010101\") == 0\n assert candidate(s = \"101010\") == 0\n assert candidate(s = \"1101001\") == 2\n assert candidate(s = \"11001100\") == 2\n assert candidate(s = \"0011\") == 1\n assert candidate(s = \"0101010101\") == 0\n assert candidate(s = \"0011001\") == 2\n assert candidate(s = \"1001\") == 1\n assert candidate(s = \"101010101010101010\") == 0\n assert candidate(s = \"1110010011100100111001\") == -1\n assert candidate(s = \"010101101010101010101010101\") == 3\n assert candidate(s = \"110010110010\") == 2\n assert candidate(s = \"000110110001101100011011\") == 6\n assert candidate(s = \"00111111001111110011111100111111001111110011111100\") == -1\n assert candidate(s = \"101010101110\") == -1\n assert candidate(s = \"000000111111000000111111\") == 6\n assert candidate(s = \"0000000111111\") == 3\n assert candidate(s = \"000000000000000000111111111111111\") == -1\n assert candidate(s = \"11110000111100001111000011110000111100001111000011\") == -1\n assert candidate(s = \"010101010101010101010101010101010101010101010101011\") == 25\n assert candidate(s = \"101010101010101001010101010\") == 8\n assert candidate(s = \"1010101010101010101\") == 0\n assert candidate(s = \"010101010101010110101010101\") == 8\n assert candidate(s = \"0000000000000001111111111111\") == -1\n assert candidate(s = \"11010101010101010101010101010101\") == -1\n assert candidate(s = \"010101010101010101010101\") == 0\n assert candidate(s = \"10101010101010101010101010\") == 0\n assert candidate(s = \"000000000000111111111111\") == 6\n assert candidate(s = \"0000111110101010\") == 2\n assert candidate(s = \"1001100110011\") == 3\n assert candidate(s = \"0000000000111111111000\") == -1\n assert candidate(s = \"101010101001010101010101010\") == 5\n assert candidate(s = \"00001111000011110000\") == -1\n assert candidate(s = \"111000111000111\") == -1\n assert candidate(s = \"1011010010110100\") == 4\n assert candidate(s = \"000111000111000111\") == 3\n assert candidate(s = \"101010101010101010101010\") == 0\n assert candidate(s = \"1010010101001010100101010\") == -1\n assert candidate(s = \"111010101010\") == -1\n assert candidate(s = \"101010101010101010101\") == 0\n assert candidate(s = \"111111000000111111000000111111000000111111\") == -1\n assert candidate(s = \"010101010101010101\") == 0\n assert candidate(s = \"101010101010101010101010101\") == 0\n assert candidate(s = \"1010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"1100110011\") == -1\n assert candidate(s = \"111000111000111000111000111000\") == 5\n assert candidate(s = \"11000011000011000011\") == -1\n assert candidate(s = \"0101010101001011\") == 2\n assert candidate(s = \"111001100110011001100110011\") == -1\n assert candidate(s = \"1111111111111111111000000000000000\") == -1\n assert candidate(s = \"1010101010101010\") == 0\n assert candidate(s = \"111100001111000011110000111100001111\") == -1\n assert candidate(s = \"0000000111111100000000111111110000000011111111\") == 11\n assert candidate(s = \"111111000000111111000000\") == 6\n assert candidate(s = \"011111000000\") == -1\n assert candidate(s = \"111100001111000011110000\") == 6\n assert candidate(s = \"10101110101000\") == 1\n assert candidate(s = \"110011001100\") == 3\n assert candidate(s = \"11100101101000\") == 3\n assert candidate(s = \"0011001100110011\") == 4\n assert candidate(s = \"001100110011001100\") == -1\n assert candidate(s = \"000000111111\") == 3\n assert candidate(s = \"11111000001111100000\") == 4\n assert candidate(s = \"110010101001\") == 2\n assert candidate(s = \"111100000011\") == 3\n assert candidate(s = \"01010101011\") == 5\n assert candidate(s = \"0101010101010101010101010101010101\") == 0\n assert candidate(s = \"0000111100001111000011110000\") == -1\n assert candidate(s = \"1110001000\") == -1\n assert candidate(s = \"010101010101010101010101010\") == 0\n assert candidate(s = \"10100101010\") == 2\n assert candidate(s = \"000000000000000011111111111111\") == -1\n assert candidate(s = \"01010101010101010101010\") == 0\n assert candidate(s = \"11110000111100001111\") == -1\n assert candidate(s = \"01010101010101010101010101\") == 0\n assert candidate(s = \"01101101101101\") == -1\n assert candidate(s = \"111111111111111111000000000000000\") == -1\n assert candidate(s = \"101010101010\") == 0\n assert candidate(s = \"111111000000111111\") == -1\n assert candidate(s = \"111111111111111100000000000000\") == -1\n assert candidate(s = \"1111111111110000000000\") == -1\n assert candidate(s = \"0011001100110\") == 3\n assert candidate(s = \"01101010100\") == 4\n assert candidate(s = \"000111111000\") == 3\n assert candidate(s = \"0101010010101010\") == -1\n assert candidate(s = \"11111111111111111111\") == -1\n assert candidate(s = \"000011110000\") == -1\n assert candidate(s = \"1111111111100000000011\") == -1\n assert candidate(s = \"001001110010011\") == 4\n assert candidate(s = \"00001111111100\") == -1\n assert candidate(s = \"000111000111000\") == -1\n assert candidate(s = \"11111111000000001111111100000000\") == 8\n assert candidate(s = \"001100110011\") == 3\n assert candidate(s = \"1111111000000\") == 3\n assert candidate(s = \"10010010010010\") == -1\n assert candidate(s = \"111111111000000001111111100000000\") == 8\n assert candidate(s = \"00000000001111111111\") == 5\n assert candidate(s = \"101010101010101010101010101010101\") == 0\n assert candidate(s = \"1111111111000000000011111111110000000000\") == 10\n assert candidate(s = \"01010101010101010101010101010101010101010101010100\") == -1\n assert candidate(s = \"11001100110011001100\") == 5\n assert candidate(s = \"11111111110000000000\") == 5\n assert candidate(s = \"1111111000000011111111100000001111111110000000\") == -1\n assert candidate(s = \"01010101010101010101010101010101\") == 0\n assert candidate(s = \"0101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"1010101010101010101010101010\") == 0\n assert candidate(s = \"11110000111100\") == -1\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == -1\n assert candidate(s = \"111010101001\") == -1\n assert candidate(s = \"111000111000111000111000111\") == -1\n assert candidate(s = \"1110000011100000\") == -1\n assert candidate(s = \"111111101111111011111110\") == -1\n assert candidate(s = \"0000111111110000\") == 4\n assert candidate(s = \"111000111000\") == 2\n assert candidate(s = \"1111111100000000\") == 4\n assert candidate(s = \"1010101010110100\") == 2\n assert candidate(s = \"101110010110\") == -1\n assert candidate(s = \"0101101010101001\") == 3\n assert candidate(s = \"111100001111\") == -1\n assert candidate(s = \"000011111111\") == -1\n assert candidate(s = \"00000000000000000111111111111111\") == -1\n assert candidate(s = \"110110001101100\") == 4\n assert candidate(s = \"1100110011001100110011001100\") == 7\n assert candidate(s = \"11110000111100001111000011110000\") == 8\n assert candidate(s = \"110110110110110110110110\") == -1\n assert candidate(s = \"00110011001100\") == -1\n assert candidate(s = \"010101010101\") == 0\n assert candidate(s = \"111000100011\") == 2\n assert candidate(s = \"1111111111111111111111111111\") == -1\n assert candidate(s = \"0101010101010101\") == 0\n assert candidate(s = \"00001111\") == 2\n assert candidate(s = \"11111100000000\") == -1\n assert candidate(s = \"10100101001010010100101001010010100101001010\") == -1\n assert candidate(s = \"1111000010101010\") == 2\n assert candidate(s = \"11111111111111100000000000000000\") == -1\n assert candidate(s = \"11100111001110011100\") == -1\n assert candidate(s = \"1010101110001010\") == 1\n assert candidate(s = \"0101010101010101010101010101\") == 0\n assert candidate(s = \"11000000110000001100000011000000110000001100000011\") == -1\n assert candidate(s = \"0000000100000001000000010\") == -1\n assert candidate(s = \"111100001111000011\") == -1\n assert candidate(s = \"00000000000000000000000000000000000000000000000001\") == -1\n assert candidate(s = \"0101010101010101010\") == 0\n assert candidate(s = \"0000000000001111111111111111\") == -1\n assert candidate(s = \"000111000111000111000111000111\") == 5\n assert candidate(s = \"11111110000000\") == 3\n assert candidate(s = \"0000000000000001111111111111111\") == 8\n assert candidate(s = \"010100011101010\") == 1\n assert candidate(s = \"010101010001010101010101010\") == -1\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == -1\n assert candidate(s = \"000000111111000000111111000000111111000000\") == -1\n assert candidate(s = \"110101010101010101\") == -1\n assert candidate(s = \"100010001000\") == -1\n assert candidate(s = \"00001111000011110000111100001111\") == 8\n assert candidate(s = \"1111111111111110000000000000\") == -1\n assert candidate(s = \"101010101000\") == -1\n assert candidate(s = \"10101010010\") == 4\n assert candidate(s = \"10010010010\") == -1\n assert candidate(s = \"00110011001100110011\") == 5\n assert candidate(s = \"010110001110\") == 3\n assert candidate(s = \"011011010101010101010101010\") == 12\n assert candidate(s = \"010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"00000000000000000000\") == -1\n assert candidate(s = \"1010101010101\") == 0\n assert candidate(s = \"1111000011110000\") == 4\n assert candidate(s = \"0000000011111111\") == 4\n assert candidate(s = \"010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"1111000000001111\") == 4\n assert candidate(s = \"1111100000\") == 2\n assert candidate(s = \"11001100110011001100110011001100110011001100110011\") == -1\n assert candidate(s = \"00100100100100100100100100100100100100100100\") == -1\n assert candidate(s = \"000111000111000111000111000\") == -1\n assert candidate(s = \"01010101010101\") == 0\n assert candidate(s = \"111000010101\") == 2\n assert candidate(s = \"1001001001001\") == -1\n assert candidate(s = \"101011100010101\") == 1\n assert candidate(s = \"0100101101001011\") == 4\n assert candidate(s = \"0110110110110110110110110\") == -1\n assert candidate(s = \"11111111111111111000000000000000\") == -1\n assert candidate(s = \"1010101010101010101010\") == 0\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"00111100111100111100\") == -1\n assert candidate(s = \"100110011001\") == 3\n assert candidate(s = \"111001001001\") == 3\n assert candidate(s = \"11101110111011101110\") == -1\n assert candidate(s = \"00011100011100011100\") == -1\n assert candidate(s = \"1001100110011001\") == 4\n assert candidate(s = \"01010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"100100100100\") == -1\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"0011001100110011001100110011\") == 7\n assert candidate(s = \"01010101010101010101\") == 0\n assert candidate(s = \"110011001100110011001100110011\") == -1\n assert candidate(s = \"1100110011001\") == 3\n assert candidate(s = \"11001100110011\") == -1\n assert candidate(s = \"101010101010101010101010101010101010101010101010100\") == 25\n assert candidate(s = \"1001001001001001001001001001\") == -1\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"1101011010100010\") == 3\n assert candidate(s = \"0110011001100110011001100110011\") == 8\n assert candidate(s = \"101010010101010101010101010\") == 3\n assert candidate(s = \"1111111111110000000000000000\") == -1\n assert candidate(s = \"101010101010101010101010101010101010\") == 0\n assert candidate(s = \"000100100100\") == -1\n assert candidate(s = \"1111000000\") == -1\n assert candidate(s = \"0101010101010\") == 0\n assert candidate(s = \"111111111110000000000111111111110000000000\") == -1\n assert candidate(s = \"1111111000000011111110000000\") == 6\n assert candidate(s = \"11000011110000111100\") == 5\n assert candidate(s = \"10101010101010101010\") == 0\n assert candidate(s = \"0000000000000000000111111111111111\") == -1\n assert candidate(s = \"100110011001100110011001\") == 6\n assert candidate(s = \"11001100110011001100110011\") == -1\n assert candidate(s = \"000000111111000000111111000000\") == -1\n assert candidate(s = \"011011011011\") == -1\n assert candidate(s = \"0000000000000000000000000000\") == -1\n assert candidate(s = \"11111111111111111111111111111111111111111111111110\") == -1\n assert candidate(s = \"00001111000011110000111100001111000011110000111100\") == -1\n", "comparison": "exact"}, "public_tests": ["\"111000\"", "\"010\"", "\"1110\""], "hints": ["Think about all valid strings of length n.", "Try to count the mismatched positions with each valid string of length n."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:13+00:00", "tests_total": 243, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minSwaps($s) {", "container": "Solution", "callable": "minSwaps", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1866, "task_id": "number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "difficulty": "Hard", "problem_description": "There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.\n\n- For example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.\n\nGiven n and k, return the number of such arrangements. Since the answer may be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 3, k = 2\nOutput: 3\nExplanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.\nThe visible sticks are underlined.\n\nExample 2:\n\nInput: n = 5, k = 5\nOutput: 1\nExplanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.\nThe visible sticks are underlined.\n\nExample 3:\n\nInput: n = 20, k = 11\nOutput: 647427950\nExplanation: There are 647427950 (mod 10^9+ 7) ways to rearrange the sticks such that exactly 11 sticks are visible.\n\nConstraints:\n\n- 1 <= n <= 1000\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,k = 1) == 362880\n assert candidate(n = 1000,k = 500) == 761367694\n assert candidate(n = 7,k = 4) == 735\n assert candidate(n = 1,k = 1) == 1\n assert candidate(n = 3,k = 2) == 3\n assert candidate(n = 100,k = 50) == 768969154\n assert candidate(n = 5,k = 5) == 1\n assert candidate(n = 20,k = 11) == 647427950\n assert candidate(n = 4,k = 3) == 6\n assert candidate(n = 10,k = 3) == 1172700\n assert candidate(n = 400,k = 200) == 321592380\n assert candidate(n = 300,k = 150) == 266738846\n assert candidate(n = 500,k = 20) == 997277428\n assert candidate(n = 200,k = 100) == 515897308\n assert candidate(n = 75,k = 40) == 957213722\n assert candidate(n = 600,k = 400) == 156741878\n assert candidate(n = 90,k = 45) == 884068127\n assert candidate(n = 1000,k = 999) == 499500\n assert candidate(n = 300,k = 200) == 692591146\n assert candidate(n = 70,k = 35) == 834330443\n assert candidate(n = 25,k = 10) == 513911237\n assert candidate(n = 30,k = 15) == 439815546\n assert candidate(n = 900,k = 40) == 539248312\n assert candidate(n = 75,k = 35) == 48172892\n assert candidate(n = 400,k = 10) == 650177568\n assert candidate(n = 800,k = 200) == 252157911\n assert candidate(n = 50,k = 20) == 506372014\n assert candidate(n = 999,k = 999) == 1\n assert candidate(n = 500,k = 2) == 540925953\n assert candidate(n = 700,k = 350) == 411412946\n assert candidate(n = 999,k = 1) == 22779421\n assert candidate(n = 999,k = 499) == 23728871\n assert candidate(n = 900,k = 450) == 911433285\n assert candidate(n = 900,k = 900) == 1\n assert candidate(n = 150,k = 75) == 309130836\n assert candidate(n = 8,k = 4) == 6769\n assert candidate(n = 100,k = 10) == 451985432\n assert candidate(n = 30,k = 10) == 283914142\n assert candidate(n = 750,k = 100) == 677105109\n assert candidate(n = 25,k = 15) == 729045180\n assert candidate(n = 250,k = 249) == 31125\n assert candidate(n = 250,k = 200) == 168555168\n assert candidate(n = 1000,k = 1000) == 1\n assert candidate(n = 1000,k = 1) == 756641425\n assert candidate(n = 15,k = 7) == 409322830\n assert candidate(n = 600,k = 599) == 179700\n assert candidate(n = 800,k = 300) == 156733966\n assert candidate(n = 600,k = 300) == 326283128\n assert candidate(n = 750,k = 375) == 43563744\n assert candidate(n = 700,k = 30) == 785311933\n assert candidate(n = 800,k = 400) == 551599071\n assert candidate(n = 500,k = 50) == 982286335\n assert candidate(n = 999,k = 500) == 975713359\n assert candidate(n = 350,k = 175) == 62253251\n assert candidate(n = 400,k = 250) == 585657508\n assert candidate(n = 500,k = 250) == 112330193\n assert candidate(n = 50,k = 25) == 253549512\n", "comparison": "exact"}, "public_tests": ["3\n2", "5\n5", "20\n11"], "hints": ["Is there a way to build the solution from a base case?", "How many ways are there if we fix the position of one stick?"], "metadata": {"canonical_parameter_names": ["n", "k"], "leetcode_dataset_entry_point": "Solution().rearrangeSticks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:16+00:00", "tests_total": 57, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "dynamic-programming", "combinatorics"]}, "language": "php", "interface": {"raw_signature": "function rearrangeSticks($n, $k) {", "container": "Solution", "callable": "rearrangeSticks", "parameters": [{"name": "n", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1869, "task_id": "longer-contiguous-segments-of-ones-than-zeros", "difficulty": "Easy", "problem_description": "Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.\n\n- For example, in s = \"110100010\" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.\n\nNote that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.\n\nExample 1:\n\nInput: s = \"1101\"\nOutput: true\nExplanation:\nThe longest contiguous segment of 1s has length 2: \"1101\"\nThe longest contiguous segment of 0s has length 1: \"1101\"\nThe segment of 1s is longer, so return true.\n\nExample 2:\n\nInput: s = \"111000\"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 3: \"111000\"\nThe longest contiguous segment of 0s has length 3: \"111000\"\nThe segment of 1s is not longer, so return false.\n\nExample 3:\n\nInput: s = \"110100010\"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 2: \"110100010\"\nThe longest contiguous segment of 0s has length 3: \"110100010\"\nThe segment of 1s is not longer, so return false.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == True\n assert candidate(s = \"111000\") == False\n assert candidate(s = \"101010\") == False\n assert candidate(s = \"11100111\") == True\n assert candidate(s = \"11001100\") == False\n assert candidate(s = \"111001001\") == True\n assert candidate(s = \"1101\") == True\n assert candidate(s = \"0\") == False\n assert candidate(s = \"110100010\") == False\n assert candidate(s = \"01010101\") == False\n assert candidate(s = \"10101010\") == False\n assert candidate(s = \"1110011100010001111100000\") == False\n assert candidate(s = \"000111000\") == False\n assert candidate(s = \"001100110011\") == False\n assert candidate(s = \"0000\") == False\n assert candidate(s = \"1\") == True\n assert candidate(s = \"101010101010101010\") == False\n assert candidate(s = \"1110111011101110111\") == True\n assert candidate(s = \"000111000111000111000\") == False\n assert candidate(s = \"111111111111111111111111\") == True\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"111000111000111000\") == False\n assert candidate(s = \"001111001100110011110000111100001111100000\") == False\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111\") == True\n assert candidate(s = \"1111110000000000000000000000000000000000000000000000\") == False\n assert candidate(s = \"111100000110011000000111\") == False\n assert candidate(s = \"00000000000000000000000000000000\") == False\n assert candidate(s = \"000111000111000111000111000111000111000111000\") == False\n assert candidate(s = \"000011110000111100001111000011110000111100001111\") == False\n assert candidate(s = \"1111111111111111111\") == True\n assert candidate(s = \"1100110011001100\") == False\n assert candidate(s = \"111010101010101010101\") == True\n assert candidate(s = \"1010101010101010101\") == False\n assert candidate(s = \"111110000011111000001111100000\") == False\n assert candidate(s = \"11010101010101010101010101010101\") == True\n assert candidate(s = \"11110011000001111100110000011111001100000\") == False\n assert candidate(s = \"010101010101010101010101\") == False\n assert candidate(s = \"00000000111111110000000011111111\") == False\n assert candidate(s = \"0000000000000000000000001111111111111111111111111\") == True\n assert candidate(s = \"10101010101010101010101010\") == False\n assert candidate(s = \"111000000011111111111\") == True\n assert candidate(s = \"1010101010101010101010101010101\") == False\n assert candidate(s = \"1110000110000111\") == False\n assert candidate(s = \"00000000001111111111111111111111111111111\") == True\n assert candidate(s = \"1111111111111111111111111111111111111111111111111\") == True\n assert candidate(s = \"111111110000000\") == True\n assert candidate(s = \"000000000000000000000001\") == False\n assert candidate(s = \"00000000000000000000000000000000000000000000000011111\") == False\n assert candidate(s = \"000111000111000111\") == False\n assert candidate(s = \"111111111111111111110000000000000000111111111111\") == True\n assert candidate(s = \"10101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"10000111110000001111111110000000011111111111\") == True\n assert candidate(s = \"111111111111100000000000000011111111111111111111111111111\") == True\n assert candidate(s = \"111110000011111000001111100000111110000011111\") == False\n assert candidate(s = \"0001001001001001001001001\") == False\n assert candidate(s = \"000110001100011000110001100011\") == False\n assert candidate(s = \"0000000000\") == False\n assert candidate(s = \"111111111111111111111\") == True\n assert candidate(s = \"111110000001110000111111\") == False\n assert candidate(s = \"1010101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"111111010101010101010101010101010101010101010101010101\") == True\n assert candidate(s = \"0000000000000000\") == False\n assert candidate(s = \"000100010001000\") == False\n assert candidate(s = \"000111000111000111000111\") == False\n assert candidate(s = \"101010101010101010101010101010\") == False\n assert candidate(s = \"1001001001001001001001001001001001001001001\") == False\n assert candidate(s = \"111100001111000011110000111100001111\") == False\n assert candidate(s = \"111111000000111111000000\") == False\n assert candidate(s = \"111100001111000011110000\") == False\n assert candidate(s = \"101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"000000000000000000000\") == False\n assert candidate(s = \"111111110000000000000000000\") == False\n assert candidate(s = \"11111000001111100000\") == False\n assert candidate(s = \"11111111111111111111110000000000000000\") == True\n assert candidate(s = \"0011001100110011001100110011001100110011\") == False\n assert candidate(s = \"000000000000000011111111111\") == False\n assert candidate(s = \"00110011001100110011001100110011\") == False\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000000\") == False\n assert candidate(s = \"11110000111100001111\") == False\n assert candidate(s = \"11111000000000000000000000000000000000000000000000000\") == False\n assert candidate(s = \"110000000000000000000\") == False\n assert candidate(s = \"10101010101010101010101010101\") == False\n assert candidate(s = \"10101010101010101010101010101010101010\") == False\n assert candidate(s = \"010101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"000000011111111\") == True\n assert candidate(s = \"111111111100000000001111111111\") == False\n assert candidate(s = \"0011110000111100001111\") == False\n assert candidate(s = \"1111000001100100\") == False\n assert candidate(s = \"11111111111111111111\") == True\n assert candidate(s = \"1000000000000000000\") == False\n assert candidate(s = \"111001110011100\") == True\n assert candidate(s = \"1000111000111000111000111000111000111000\") == False\n assert candidate(s = \"1111111111111111\") == True\n assert candidate(s = \"111001110011100111001110011100\") == True\n assert candidate(s = \"101010101010101010101010101010101010101\") == False\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011\") == False\n assert candidate(s = \"00000111111111000000\") == True\n assert candidate(s = \"000000000000000000000000000000000000001\") == False\n assert candidate(s = \"110000111100001111000011110000111100001111\") == False\n assert candidate(s = \"100000011111111111100\") == True\n assert candidate(s = \"00000000001111111111\") == False\n assert candidate(s = \"010101010101010101010101010101\") == False\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000001\") == False\n assert candidate(s = \"111000111000111000111\") == False\n assert candidate(s = \"11111000011111000011\") == True\n assert candidate(s = \"0000111111110000000\") == True\n assert candidate(s = \"111111111000000001111000000111110000\") == True\n assert candidate(s = \"11111111110000000000\") == False\n assert candidate(s = \"11111111110000000000000000000000000000000\") == False\n assert candidate(s = \"01010101010101010101010101010101\") == False\n assert candidate(s = \"111111000000000000000000000000\") == False\n assert candidate(s = \"000000000000000011111111111111111111000000000000\") == True\n assert candidate(s = \"11000001110000011100000111\") == False\n assert candidate(s = \"1010101010101010101010101010\") == False\n assert candidate(s = \"111100000000011111\") == False\n assert candidate(s = \"111000111000111000111000111\") == False\n assert candidate(s = \"0000111111110000\") == True\n assert candidate(s = \"0000000000000000000000000000000000000000000000000\") == False\n assert candidate(s = \"1111111111111111111111111111111111111110\") == True\n assert candidate(s = \"11110000011110000\") == False\n assert candidate(s = \"1110000111000111\") == False\n assert candidate(s = \"11111111111111111111111111111111\") == True\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010\") == False\n assert candidate(s = \"0000000000011111111111111100000000011111111111\") == True\n assert candidate(s = \"000000001010101010101010101010101010101010101010101010\") == False\n assert candidate(s = \"0101010101010101010101010101\") == False\n assert candidate(s = \"11100100010001000100010001000100\") == False\n assert candidate(s = \"000001111110000011111100000111111\") == True\n assert candidate(s = \"11001100110011001100110011001100110011\") == False\n assert candidate(s = \"00011100010001000100010001110001\") == False\n assert candidate(s = \"11001100110011001100110011001100110011001100\") == False\n assert candidate(s = \"111000011100001110000111\") == False\n assert candidate(s = \"001111110000000011111100000000\") == False\n assert candidate(s = \"010101010101010101010101010101010101010\") == False\n assert candidate(s = \"00000000000000000000\") == False\n assert candidate(s = \"1111000011110000\") == False\n assert candidate(s = \"10101010101010101010101010101010\") == False\n assert candidate(s = \"1001001001001001001001001\") == False\n assert candidate(s = \"1010101011111010\") == True\n assert candidate(s = \"0000000111111111111111111111111111111111111111100000\") == True\n assert candidate(s = \"000111000111000111000111000\") == False\n assert candidate(s = \"1010101010101010101010101010101010101010101010\") == False\n assert candidate(s = \"0110110110110110110110110\") == True\n assert candidate(s = \"1111111111111111111111110000000000000000000000000\") == False\n assert candidate(s = \"1111111111\") == True\n assert candidate(s = \"111111111100000000\") == True\n assert candidate(s = \"1001100110011001\") == False\n assert candidate(s = \"000000000000111111000000000011111\") == False\n assert candidate(s = \"001001001001001001001\") == False\n assert candidate(s = \"1100110011001100110011\") == False\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\") == False\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"111110000000000000000000000000000000000\") == False\n assert candidate(s = \"110110110110110110110\") == True\n assert candidate(s = \"0000000000000000000000001111111111111111111111111111\") == True\n assert candidate(s = \"10101010101010101010\") == False\n assert candidate(s = \"100110011001100110011001\") == False\n assert candidate(s = \"11001100110011001100110011\") == False\n assert candidate(s = \"010101010101010101010101010101010101010101\") == False\n assert candidate(s = \"000000111111111111\") == True\n assert candidate(s = \"00011100010001000100010001000111\") == False\n", "comparison": "exact"}, "public_tests": ["\"1101\"", "\"111000\"", "\"110100010\""], "hints": ["Check every possible segment of 0s and 1s.", "Is there a way to iterate through the string to keep track of the current character and its count?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().checkZeroOnes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:21+00:00", "tests_total": 161, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function checkZeroOnes($s) {", "container": "Solution", "callable": "checkZeroOnes", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1870, "task_id": "minimum-speed-to-arrive-on-time", "difficulty": "Medium", "problem_description": "You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the i^th train ride.\n\nEach train can only depart at an integer hour, so you may need to wait in between each train ride.\n\n- For example, if the 1^st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2^nd train ride at the 2 hour mark.\n\nReturn the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.\n\nTests are generated such that the answer will not exceed 10^7 and hour will have at most two digits after the decimal point.\n\nExample 1:\n\nInput: dist = [1,3,2], hour = 6\nOutput: 1\nExplanation: At speed 1:\n- The first train ride takes 1/1 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.\n- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.\n- You will arrive at exactly the 6 hour mark.\n\nExample 2:\n\nInput: dist = [1,3,2], hour = 2.7\nOutput: 3\nExplanation: At speed 3:\n- The first train ride takes 1/3 = 0.33333 hours.\n- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.\n- You will arrive at the 2.66667 hour mark.\n\nExample 3:\n\nInput: dist = [1,3,2], hour = 1.9\nOutput: -1\nExplanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.\n\nConstraints:\n\n- n == dist.length\n- 1 <= n <= 10^5\n- 1 <= dist[i] <= 10^5\n- 1 <= hour <= 10^9\n- There will be at most two digits after the decimal point in hour.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(dist = [5, 4, 3, 2, 1],hour = 5.5) == 4\n assert candidate(dist = [5, 4, 1, 2],hour = 3.5) == 5\n assert candidate(dist = [1, 2, 3, 4, 5],hour = 9.0) == 2\n assert candidate(dist = [1, 3, 2],hour = 1.9) == -1\n assert candidate(dist = [1, 1, 100000],hour = 2.01) == 10000000\n assert candidate(dist = [5, 5, 5, 5, 5],hour = 9.0) == 5\n assert candidate(dist = [100000],hour = 2.5) == 40000\n assert candidate(dist = [100000],hour = 1.0) == 100000\n assert candidate(dist = [10, 10, 10],hour = 3.5) == 10\n assert candidate(dist = [1, 3, 2],hour = 2.7) == 3\n assert candidate(dist = [1, 2, 3, 4, 5],hour = 10.0) == 2\n assert candidate(dist = [10, 10, 10],hour = 2.5) == 20\n assert candidate(dist = [1],hour = 1.0) == 1\n assert candidate(dist = [10, 10, 10],hour = 29.99) == 2\n assert candidate(dist = [1, 3, 2],hour = 6) == 1\n assert candidate(dist = [10, 10, 10],hour = 3.0) == 10\n assert candidate(dist = [5, 5, 5, 5],hour = 10.0) == 3\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 100000.0) == 1\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],hour = 19.99) == 11\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 4.5) == -1\n assert candidate(dist = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],hour = 50.0) == 20000\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],hour = 30.0) == 50\n assert candidate(dist = [100, 200, 300, 400, 500],hour = 15.5) == 100\n assert candidate(dist = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],hour = 15.0) == 100\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 10.1) == 1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 50.0) == 12\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 9.5) == 20\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],hour = 20.0) == 10\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],hour = 9.0) == -1\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],hour = 10.5) == 20\n assert candidate(dist = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],hour = 45.0) == 13334\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],hour = 15.0) == 25\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 30.5) == 20\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],hour = 14.0) == -1\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],hour = 10.0) == 100000\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000],hour = 25.0) == 20000\n assert candidate(dist = [100000, 1, 1, 1, 1],hour = 10.1) == 14286\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 9.99) == 11\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 2.5) == -1\n assert candidate(dist = [1, 2, 3, 4, 5],hour = 2.0) == -1\n assert candidate(dist = [99999, 99999, 99999, 99999],hour = 20.0) == 20000\n assert candidate(dist = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],hour = 50.0) == 1200\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],hour = 15.0) == 5\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 49.99) == 12\n assert candidate(dist = [1000, 2000, 3000],hour = 7.0) == 1000\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 5.5) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],hour = 25.5) == 14\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],hour = 15.0) == 5\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 5.5) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 25.0) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 20.0) == 4\n assert candidate(dist = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],hour = 9.99) == 101010\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 15.0) == 5\n assert candidate(dist = [1, 10, 100, 1000, 10000],hour = 12.0) == 1250\n assert candidate(dist = [10000, 20000, 30000, 40000, 50000],hour = 12.5) == 14286\n assert candidate(dist = [10, 20, 30, 40, 50],hour = 12.5) == 15\n assert candidate(dist = [10, 20, 30, 40, 50],hour = 12.5) == 15\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 10.0) == 1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 19.0) == -1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 18.0) == 40\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 18.0) == 40\n assert candidate(dist = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],hour = 9.0) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 1.0) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 20.0) == 1\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],hour = 15.25) == 5\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],hour = 4.0) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 5.0) == -1\n assert candidate(dist = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],hour = 15.5) == 5\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],hour = 9.5) == 10\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 9.0) == -1\n assert candidate(dist = [99999, 99999, 99999, 99999, 99999],hour = 25.0) == 20000\n assert candidate(dist = [100, 200, 300, 400, 500],hour = 10.0) == 200\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],hour = 19.99) == 21\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],hour = 50.5) == 118\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],hour = 11.0) == 9\n assert candidate(dist = [100, 200, 300, 400, 500],hour = 14.0) == 125\n assert candidate(dist = [100, 200, 300, 400, 500],hour = 20.0) == 84\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 50.0) == -1\n assert candidate(dist = [1, 10000, 1, 10000, 1, 10000, 1, 10000, 1, 10000],hour = 10.5) == 10000\n assert candidate(dist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],hour = 10.0) == 19\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],hour = 25.0) == 70\n assert candidate(dist = [100000, 99999, 99998, 99997, 99996],hour = 5.0) == 100000\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],hour = 21.5) == 18\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 9.5) == 2\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 2.99) == -1\n assert candidate(dist = [5, 10, 15, 20, 25],hour = 9.0) == 10\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 9.99) == 102\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],hour = 5.0) == -1\n assert candidate(dist = [1, 100000, 1, 1, 1],hour = 10.1) == 14286\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],hour = 20.0) == 35\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],hour = 30.5) == 200\n assert candidate(dist = [99999, 99999, 99999],hour = 3.5) == 99999\n assert candidate(dist = [10000, 10000, 10000, 10000, 10000],hour = 25.0) == 2000\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],hour = 7.5) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],hour = 1.5) == -1\n", "comparison": "exact"}, "public_tests": ["[1,3,2]\n6", "[1,3,2]\n2.7", "[1,3,2]\n1.9"], "hints": ["Given the speed the trains are traveling at, can you find the total time it takes for you to arrive?", "Is there a cutoff where any speeds larger will always allow you to arrive on time?"], "metadata": {"canonical_parameter_names": ["dist", "hour"], "leetcode_dataset_entry_point": "Solution().minSpeedOnTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:23+00:00", "tests_total": 98, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function minSpeedOnTime($dist, $hour) {", "container": "Solution", "callable": "minSpeedOnTime", "parameters": [{"name": "dist", "type": "Integer[]"}, {"name": "hour", "type": "Float"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1871, "task_id": "jump-game-vii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:\n\n- i + minJump <= j <= min(i + maxJump, s.length - 1), and\n- s[j] == '0'.\n\nReturn true if you can reach index s.length - 1 in s, or false otherwise.\n\nExample 1:\n\nInput: s = \"011010\", minJump = 2, maxJump = 3\nOutput: true\nExplanation:\nIn the first step, move from index 0 to index 3.\nIn the second step, move from index 3 to index 5.\n\nExample 2:\n\nInput: s = \"01101110\", minJump = 2, maxJump = 3\nOutput: false\n\nConstraints:\n\n- 2 <= s.length <= 10^5\n- s[i] is either '0' or '1'.\n- s[0] == '0'\n- 1 <= minJump <= maxJump < s.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"0100100010001000\",minJump = 2,maxJump = 5) == True\n assert candidate(s = \"00001000\",minJump = 2,maxJump = 4) == True\n assert candidate(s = \"0010010010010010010010010010010010010010\",minJump = 2,maxJump = 4) == True\n assert candidate(s = \"011010\",minJump = 2,maxJump = 3) == True\n assert candidate(s = \"0100000\",minJump = 1,maxJump = 2) == True\n assert candidate(s = \"00001000\",minJump = 3,maxJump = 5) == True\n assert candidate(s = \"01010101\",minJump = 2,maxJump = 4) == False\n assert candidate(s = \"0101010101010101010101010101010101010101\",minJump = 5,maxJump = 10) == False\n assert candidate(s = \"0111111111111111111111111111111111111111\",minJump = 3,maxJump = 5) == False\n assert candidate(s = \"000000\",minJump = 1,maxJump = 2) == True\n assert candidate(s = \"001000\",minJump = 2,maxJump = 3) == True\n assert candidate(s = \"010101\",minJump = 1,maxJump = 2) == False\n assert candidate(s = \"00000000\",minJump = 1,maxJump = 2) == True\n assert candidate(s = \"00100\",minJump = 3,maxJump = 4) == True\n assert candidate(s = \"01101110\",minJump = 2,maxJump = 3) == False\n assert candidate(s = \"010000\",minJump = 1,maxJump = 3) == True\n assert candidate(s = \"00000000001000000000\",minJump = 4,maxJump = 7) == True\n assert candidate(s = \"0000011111000000000000000000\",minJump = 1,maxJump = 5) == False\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000000000000000000000\",minJump = 5,maxJump = 10) == True\n assert candidate(s = \"0000000000000000000000000000\",minJump = 2,maxJump = 2) == False\n assert candidate(s = \"0111111111111111111111111110\",minJump = 10,maxJump = 20) == False\n assert candidate(s = \"0100000000000000000000000000\",minJump = 2,maxJump = 3) == True\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\",minJump = 10,maxJump = 20) == True\n assert candidate(s = \"01010101010101010101010101010101010101010101010101\",minJump = 5,maxJump = 15) == False\n assert candidate(s = \"0010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\",minJump = 3,maxJump = 7) == False\n assert candidate(s = \"0000000000000000000000000001\",minJump = 1,maxJump = 1) == False\n assert candidate(s = \"000001000001000001000001000001000001000001000001\",minJump = 6,maxJump = 12) == False\n assert candidate(s = \"000111000111000111000111000111000111000111000111\",minJump = 3,maxJump = 6) == False\n assert candidate(s = \"01001001001001001001001000\",minJump = 5,maxJump = 10) == True\n assert candidate(s = \"001001001000\",minJump = 2,maxJump = 4) == True\n assert candidate(s = \"0000100100010001000100010001000100010001000100010000\",minJump = 5,maxJump = 15) == True\n assert candidate(s = \"0000000000000000000000000000000000000000000000000001000000000000000000000000\",minJump = 10,maxJump = 20) == True\n assert candidate(s = \"01001001001001001001001001001001001001001001001001\",minJump = 4,maxJump = 8) == False\n assert candidate(s = \"0000000000000000000000000000\",minJump = 5,maxJump = 5) == False\n assert candidate(s = \"010001000100010001000100010001000100010000\",minJump = 4,maxJump = 12) == True\n assert candidate(s = \"0000000000000000000000000000\",minJump = 1,maxJump = 10) == True\n assert candidate(s = \"0101010101010101010101010101\",minJump = 3,maxJump = 5) == False\n assert candidate(s = \"0100000000000000000000000000\",minJump = 10,maxJump = 10) == False\n assert candidate(s = \"0001010101010101010101010101010100\",minJump = 3,maxJump = 8) == True\n assert candidate(s = \"0000000000\",minJump = 4,maxJump = 6) == True\n assert candidate(s = \"0001000100010001000100010000\",minJump = 3,maxJump = 5) == True\n", "comparison": "exact"}, "public_tests": ["\"011010\"\n2\n3", "\"01101110\"\n2\n3"], "hints": ["Consider for each reachable index i the interval [i + a, i + b].", "Use partial sums to mark the intervals as reachable."], "metadata": {"canonical_parameter_names": ["s", "minJump", "maxJump"], "leetcode_dataset_entry_point": "Solution().canReach", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:25+00:00", "tests_total": 49, "tests_dropped": 8, "flags": [], "topic_tags": ["string", "dynamic-programming", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function canReach($s, $minJump, $maxJump) {", "container": "Solution", "callable": "canReach", "parameters": [{"name": "s", "type": "String"}, {"name": "minJump", "type": "Integer"}, {"name": "maxJump", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1872, "task_id": "stone-game-viii", "difficulty": "Hard", "problem_description": "Alice and Bob take turns playing a game, with Alice starting first.\n\nThere are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:\n\n1. Choose an integer x > 1, and remove the leftmost x stones from the row.\n2. Add the sum of the removed stones' values to the player's score.\n3. Place a new stone, whose value is equal to that sum, on the left side of the row.\n\nThe game stops when only one stone is left in the row.\n\nThe score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.\n\nGiven an integer array stones of length n where stones[i] represents the value of the i^th stone from the left, return the score difference between Alice and Bob if they both play optimally.\n\nExample 1:\n\nInput: stones = [-1,2,-3,4,-5]\nOutput: 5\nExplanation:\n- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\n value 2 on the left. stones = [2,-5].\n- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\n the left. stones = [-3].\nThe difference between their scores is 2 - (-3) = 5.\n\nExample 2:\n\nInput: stones = [7,-6,5,10,5,-2,-6]\nOutput: 13\nExplanation:\n- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\n stone of value 13 on the left. stones = [13].\nThe difference between their scores is 13 - 0 = 13.\n\nExample 3:\n\nInput: stones = [-10,-12]\nOutput: -22\nExplanation:\n- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\n score and places a stone of value -22 on the left. stones = [-22].\nThe difference between their scores is (-22) - 0 = -22.\n\nConstraints:\n\n- n == stones.length\n- 2 <= n <= 10^5\n- -10^4 <= stones[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(stones = [10, -10, 20, -20, 30, -30]) == 30\n assert candidate(stones = [100, 200, -300, 400, -500, 600, -700, 800]) == 600\n assert candidate(stones = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(stones = [-1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000]) == 0\n assert candidate(stones = [1, 2, 3, 4, 5]) == 15\n assert candidate(stones = [100, -100, 100, -100, 100]) == 100\n assert candidate(stones = [10, -10, 20, -20, 30, -30, 40, -40]) == 40\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(stones = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(stones = [-1, -2, -3, -4, -5]) == 5\n assert candidate(stones = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 50\n assert candidate(stones = [-10, -12]) == -22\n assert candidate(stones = [-5, -4, -3, -2, -1]) == 1\n assert candidate(stones = [7, -6, 5, 10, 5, -2, -6]) == 13\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(stones = [-1, 2, -3, 4, -5]) == 5\n assert candidate(stones = [100, -50, 25, -12, 6, -3, 1, -1, 3, -2, 5, -4, 7, -6, 9]) == 78\n assert candidate(stones = [-10000, 0, 10000, 0, -10000, 0, 10000, 0, -10000, 0, 10000, 0, -10000, 0, 10000, 0, -10000, 0, 10000, 0]) == 0\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -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(stones = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 1100, -1200, 1300, -1400, 1500]) == 800\n assert candidate(stones = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, -10000, -9000, -8000, -7000, -6000, -5000, -4000, -3000, -2000, -1000]) == 30000\n assert candidate(stones = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == 11055\n assert candidate(stones = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000]) == 1000\n assert candidate(stones = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 250\n assert candidate(stones = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000]) == 1000\n assert candidate(stones = [5, 10, -5, 20, -10, 25, -15, 30, -20, 35, -25, 40, -30, 45, -35, 50, -40, 55, -45, 60]) == 150\n assert candidate(stones = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 1\n assert candidate(stones = [-5, 15, -25, 35, -45, 55, -65, 75, -85, 95, -105]) == 105\n assert candidate(stones = [1, 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(stones = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 10\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(stones = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 210\n assert candidate(stones = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]) == 16\n assert candidate(stones = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 18, -19, 20]) == 10\n assert candidate(stones = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(stones = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 10\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]) == 1000\n assert candidate(stones = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, 0, -1, -3, -7, -15, -31]) == 1937\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 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(stones = [10000, -10000, 9999, -9999, 9998, -9998, 9997, -9997, 9996, -9996]) == 9996\n assert candidate(stones = [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(stones = [-10000, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1]) == -1\n assert candidate(stones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -1000, -900, -800, -700, -600]) == 3100\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(stones = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20]) == 20\n assert candidate(stones = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == 15\n assert candidate(stones = [10000, -5000, 2000, -1000, 500, -200, 100, -50, 20, -10]) == 6360\n assert candidate(stones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 28\n assert candidate(stones = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, -5, -4, -3, -2, -1]) == 9\n assert candidate(stones = [10000, -5000, 5000, -2500, 2500, -1250, 1250, -625, 625, -312, 312, -156, 156, -78, 78, -39, 39, -19, 19, -9, 9]) == 10000\n assert candidate(stones = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(stones = [5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, 5]) == 10\n assert candidate(stones = [10000, -9999, 9998, -9997, 9996, -9995, 9994, -9993, 9992, -9991, 9990]) == 9995\n assert candidate(stones = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15]) == 8\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1200\n assert candidate(stones = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40, 45, -45, 50, -50]) == 50\n assert candidate(stones = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000, 1100, -1100, 1200, -1200]) == 1200\n assert candidate(stones = [-150, -140, -130, -120, -110, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == 10\n assert candidate(stones = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10]) == 10\n assert candidate(stones = [10000, -9999, 9998, -9997, 9996, -9995, 9994, -9993, 9992, -9991]) == 9991\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 1\n assert candidate(stones = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10]) == 0\n assert candidate(stones = [100, 200, -300, 400, -500, 600, -700, 800, -900, 1000]) == 700\n assert candidate(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == 300\n assert candidate(stones = [10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000]) == 10000\n assert candidate(stones = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 1\n assert candidate(stones = [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(stones = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10000]) == 10014\n assert candidate(stones = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20]) == 20\n assert candidate(stones = [-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5]) == 5\n", "comparison": "exact"}, "public_tests": ["[-1,2,-3,4,-5]", "[7,-6,5,10,5,-2,-6]", "[-10,-12]"], "hints": ["Let's note that the only thing that matters is how many stones were removed so we can maintain dp[numberOfRemovedStones]", "dp[x] = max(sum of all elements up to y - dp[y]) for all y > x"], "metadata": {"canonical_parameter_names": ["stones"], "leetcode_dataset_entry_point": "Solution().stoneGameVIII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:28+00:00", "tests_total": 79, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "math", "dynamic-programming", "minimax-algorithm", "prefix-sum", "game-theory", "zero-sum-game"]}, "language": "php", "interface": {"raw_signature": "function stoneGameVIII($stones) {", "container": "Solution", "callable": "stoneGameVIII", "parameters": [{"name": "stones", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1876, "task_id": "substrings-of-size-three-with-distinct-characters", "difficulty": "Easy", "problem_description": "A string is good if there are no repeated characters.\n\nGiven a string s, return the number of good substrings of length three in s.\n\nNote that if there are multiple occurrences of the same substring, every occurrence should be counted.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"xyzzaz\"\nOutput: 1\nExplanation: There are 4 substrings of size 3: \"xyz\", \"yzz\", \"zza\", and \"zaz\".\nThe only good substring of length 3 is \"xyz\".\n\nExample 2:\n\nInput: s = \"aababcabc\"\nOutput: 4\nExplanation: There are 7 substrings of size 3: \"aab\", \"aba\", \"bab\", \"abc\", \"bca\", \"cab\", and \"abc\".\nThe good substrings are \"abc\", \"bca\", \"cab\", and \"abc\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 7\n assert candidate(s = \"abcabcabc\") == 7\n assert candidate(s = \"xyzzaz\") == 1\n assert candidate(s = \"aabbcc\") == 0\n assert candidate(s = \"abacab\") == 2\n assert candidate(s = \"qqqppprrr\") == 0\n assert candidate(s = \"abac\") == 1\n assert candidate(s = \"abc\") == 1\n assert candidate(s = \"xyzxyz\") == 4\n assert candidate(s = \"abcdcba\") == 4\n assert candidate(s = \"aababcabc\") == 4\n assert candidate(s = \"abacaba\") == 2\n assert candidate(s = \"abca\") == 2\n assert candidate(s = \"pqr\") == 1\n assert candidate(s = \"aaa\") == 0\n assert candidate(s = \"aaaaa\") == 0\n assert candidate(s = \"xyz\") == 1\n assert candidate(s = \"abcdefg\") == 5\n assert candidate(s = \"pqrspqrs\") == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 49\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghijkabcdefghijk\") == 42\n assert candidate(s = \"abcdabcdeabcdefabcdefg\") == 20\n assert candidate(s = \"abcdefghtijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"abcdefghijklijkijklmnopqrstuvwxyz\") == 31\n assert candidate(s = \"abcdefabcdefabcdef\") == 16\n assert candidate(s = \"abcabcabcabc\") == 10\n assert candidate(s = \"uniquecharacters\") == 13\n assert candidate(s = \"thisisateststringforcountinggoodsubstrings\") == 32\n assert candidate(s = \"mnopqrspqrspqrspqr\") == 16\n assert candidate(s = \"aaaabbbbcccc\") == 0\n assert candidate(s = \"zzzzzzzzzz\") == 0\n assert candidate(s = \"abacabadabacabad\") == 7\n assert candidate(s = \"abababababababababababababababababab\") == 0\n assert candidate(s = \"mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopq\") == 73\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabc\") == 34\n assert candidate(s = \"xyzzyxzyxzyxzyxzyxzyxzyxzyx\") == 23\n assert candidate(s = \"aaabbbcccddd\") == 0\n assert candidate(s = \"abcdbcefg\") == 7\n assert candidate(s = \"abacabadabcabcabcabc\") == 14\n assert candidate(s = \"pqrstuvwxyza\") == 10\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijkl\") == 24\n assert candidate(s = \"abcdbca\") == 5\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 28\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzxyz\") == 2\n assert candidate(s = \"xyzabxyzabxyzabxyz\") == 16\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefgabcdefgabcdefg\") == 40\n assert candidate(s = \"abcababcbacbacbabc\") == 12\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 24\n assert candidate(s = \"ababababababababab\") == 0\n assert candidate(s = \"abcabcabcabcabcabc\") == 16\n assert candidate(s = \"aabbccddeeffgghhii\") == 0\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabac\") == 19\n assert candidate(s = \"abcdeffedcbaabcdeffedcbaabcdeffedcbaabcdeffedcba\") == 32\n assert candidate(s = \"abcdefgheijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"xyzzyxzyxzyxzyxzyx\") == 14\n assert candidate(s = \"zzzzzzzzz\") == 0\n assert candidate(s = \"xyzzyzzxyzzxyzzxyzzx\") == 7\n assert candidate(s = \"abcdexyz\") == 6\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzaaa\") == 25\n assert candidate(s = \"abacabadabacaba\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzz\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 76\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefg\") == 26\n assert candidate(s = \"aabbccddeeffgghhiii\") == 0\n assert candidate(s = \"abacabadabcaba\") == 7\n assert candidate(s = \"mnopqmnopqmnopq\") == 13\n assert candidate(s = \"aabbccddeeffgg\") == 0\n assert candidate(s = \"uniquecharactersinthisstringareunique\") == 32\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(s = \"aabcaabcdaabcaabcdaabc\") == 11\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 24\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooo\") == 0\n assert candidate(s = \"abcdeabcdeabcde\") == 13\n assert candidate(s = \"ababababab\") == 0\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaa\") == 0\n assert candidate(s = \"abcdefgabcdefgabcdefg\") == 19\n assert candidate(s = \"abacdefghijklmnopqrstuvwxyz\") == 24\n assert candidate(s = \"xyzzazxyzzazxyzzaz\") == 7\n assert candidate(s = \"abababababababababababababababababababab\") == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabcabc\") == 25\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 22\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 50\n assert candidate(s = \"abacabadabcabc\") == 8\n assert candidate(s = \"abacabadaba\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabc\") == 31\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"thisisaverylongstringwithvariouscharacters\") == 37\n assert candidate(s = \"mississippi\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"repeatedrepeatedrepeatedrepeatedrepeated\") == 33\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"allcharactersareuniquehere\") == 19\n", "comparison": "exact"}, "public_tests": ["\"xyzzaz\"", "\"aababcabc\""], "hints": ["Try using a set to find out the number of distinct characters in a substring."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countGoodSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:33+00:00", "tests_total": 96, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "sliding-window", "counting"]}, "language": "php", "interface": {"raw_signature": "function countGoodSubstrings($s) {", "container": "Solution", "callable": "countGoodSubstrings", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1877, "task_id": "minimize-maximum-pair-sum-in-array", "difficulty": "Medium", "problem_description": "The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.\n\n- For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.\n\nGiven an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:\n\n- Each element of nums is in exactly one pair, and\n- The maximum pair sum is minimized.\n\nReturn the minimized maximum pair sum after optimally pairing up the elements.\n\nExample 1:\n\nInput: nums = [3,5,2,3]\nOutput: 7\nExplanation: The elements can be paired up into pairs (3,3) and (5,2).\nThe maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.\n\nExample 2:\n\nInput: nums = [3,5,4,2,4,6]\nOutput: 8\nExplanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\nThe maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 10^5\n- n is even.\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 6, 2, 5, 3, 4]) == 7\n assert candidate(nums = [10, 10, 10, 10]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1]) == 100001\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 7\n assert candidate(nums = [1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [10, 10, 10, 10, 10, 10]) == 20\n assert candidate(nums = [3, 5, 4, 2, 4, 6]) == 8\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5]) == 10\n assert candidate(nums = [3, 5, 2, 3]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 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]) == 105\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 32\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1100\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994]) == 100001\n assert candidate(nums = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 99999]) == 100001\n assert candidate(nums = [5, 8, 12, 19, 22, 28, 33, 45, 50, 55]) == 60\n assert candidate(nums = [8, 3, 5, 7, 1, 9, 2, 6, 4, 10]) == 11\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 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]) == 10\n assert candidate(nums = [7, 3, 1, 4, 9, 8, 2, 5, 6, 10]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 17\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995]) == 100000\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 200000\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\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [4, 1, 2, 3, 6, 5, 7, 8]) == 9\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995]) == 100000\n assert candidate(nums = [15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16]) == 17\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993]) == 100001\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 4, 6, 3, 7, 2, 8]) == 10\n assert candidate(nums = [34, 8, 64, 51, 32, 21]) == 72\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 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]) == 11\n assert candidate(nums = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100000]) == 100002\n assert candidate(nums = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5]) == 100001\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 11\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == 1991\n assert candidate(nums = [23, 34, 45, 56, 67, 78, 89, 90]) == 123\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [2, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 9\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 100000\n assert candidate(nums = [100, 1, 2, 99, 3, 98, 4, 97]) == 101\n assert candidate(nums = [9, 1, 4, 8, 5, 7, 6, 2]) == 11\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996]) == 100000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14, 16]) == 17\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 3\n assert candidate(nums = [8, 3, 2, 1, 6, 5, 4, 7]) == 9\n assert candidate(nums = [100000, 1, 100000, 2, 100000, 3, 100000, 4]) == 100004\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\n assert candidate(nums = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 50\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]) == 12\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12]) == 13\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 100000\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 9, 8, 11, 10]) == 12\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 100\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85]) == 100\n assert candidate(nums = [7, 10, 4, 17, 15, 9, 2, 12]) == 19\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]) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\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\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 170\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]) == 12\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 130\n assert candidate(nums = [100000, 99999, 1, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6]) == 100001\n assert candidate(nums = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == 100005\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\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000]) == 200000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 130\n assert candidate(nums = [100000, 1, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 100001\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12]) == 13\n assert candidate(nums = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 21\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995, 5]) == 100000\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994]) == 100000\n assert candidate(nums = [15, 21, 33, 44, 55, 60, 65, 70, 75, 80, 85, 90]) == 125\n assert candidate(nums = [9, 3, 2, 8, 6, 5, 7, 4, 1, 10]) == 11\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 18, 17, 16, 15, 14, 13, 12]) == 19\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1]) == 100001\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 17\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 100000\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 101\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 24\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1100\n assert candidate(nums = [9, 2, 8, 4, 5, 1, 6, 3, 7, 10]) == 11\n", "comparison": "exact"}, "public_tests": ["[3,5,2,3]", "[3,5,4,2,4,6]"], "hints": ["Would sorting help find the optimal order?", "Given a specific element, how would you minimize its specific pairwise sum?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minPairSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:35+00:00", "tests_total": 97, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "two-pointers", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minPairSum($nums) {", "container": "Solution", "callable": "minPairSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1878, "task_id": "get-biggest-three-rhombus-sums-in-a-grid", "difficulty": "Medium", "problem_description": "You are given an m x n integer matrix grid.\n\nA rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:\n\nNote that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.\n\nReturn the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.\n\nExample 1:\n\nInput: grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\nOutput: [228,216,211]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211\n\nExample 2:\n\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [20,9,8]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)\n\nExample 3:\n\nInput: grid = [[7,7,7]]\nOutput: [7]\nExplanation: All three possible rhombus sums are the same, so return [7].\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 50\n- 1 <= grid[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\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]]) == [104, 76, 72]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) == [56, 52, 48]\n assert candidate(grid = [[7, 7, 7]]) == [7]\n assert candidate(grid = [[3, 4, 5, 1, 3], [3, 3, 4, 2, 3], [20, 30, 200, 40, 10], [1, 5, 5, 4, 1], [4, 3, 2, 2, 5]]) == [228, 216, 211]\n assert candidate(grid = [[5, 3, 5, 8], [15, 25, 35, 45], [60, 70, 80, 90], [10, 20, 30, 40]]) == [225, 185, 155]\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]]) == [40, 20, 5]\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == [4, 1]\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == [20, 5]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [20, 9, 8]\n assert candidate(grid = [[5, 3, 5, 5, 5], [3, 3, 3, 3, 3], [5, 5, 5, 5, 5], [3, 3, 3, 3, 3], [5, 5, 5, 5, 5]]) == [32, 16, 14]\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]]) == [80, 40, 10]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 1], [1, 2, 3, 3, 2, 1], [1, 2, 3, 4, 3, 1], [1, 2, 3, 3, 2, 1], [1, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1]]) == [18, 17, 12]\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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]) == [40, 20, 5]\n assert candidate(grid = [[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]]) == [56, 48, 40]\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]]) == [12, 8, 6]\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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [62, 61, 60]\n assert candidate(grid = [[25, 16, 32, 8, 4], [12, 24, 18, 36, 27], [6, 12, 24, 18, 36], [3, 6, 12, 24, 18], [1, 3, 6, 12, 24]]) == [170, 120, 116]\n assert candidate(grid = [[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]]) == [160, 80, 40]\n assert candidate(grid = [[50, 40, 30, 20, 10], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65], [30, 40, 50, 60, 70]]) == [320, 220, 200]\n assert candidate(grid = [[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]]) == [176, 112, 108]\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]]) == [176, 168, 128]\n assert candidate(grid = [[1, 10, 100, 1000, 10000], [10000, 1000, 100, 10, 1], [1, 10, 100, 1000, 10000], [10000, 1000, 100, 10, 1], [1, 10, 100, 1000, 10000]]) == [12221, 10120, 10000]\n assert candidate(grid = [[10, 20, 30, 40], [40, 30, 20, 10], [10, 20, 30, 40], [40, 30, 20, 10]]) == [100, 40, 30]\n assert candidate(grid = [[10, 15, 20, 25, 30], [5, 9, 12, 18, 22], [3, 6, 8, 10, 14], [1, 2, 3, 4, 5], [7, 11, 13, 17, 19]]) == [83, 69, 55]\n assert candidate(grid = [[1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12], [13, 15, 17, 19, 21, 23], [25, 27, 29, 31, 33, 35], [37, 39, 41, 43, 45, 47], [49, 51, 53, 55, 57, 59]]) == [249, 233, 180]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 3, 1], [2, 4, 6, 4, 2], [1, 5, 9, 5, 1]]) == [28, 22, 16]\n assert candidate(grid = [[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], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]) == [176, 160, 156]\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], [9, 8, 7, 6, 5, 4, 3, 2, 1]]) == [20, 9, 8]\n assert candidate(grid = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20], [5, 9, 13, 17, 21]]) == [88, 64, 60]\n assert candidate(grid = [[1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12], [1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12], [1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12]]) == [60, 44, 38]\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], [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], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == [88, 66, 44]\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]]) == [20, 18, 12]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [32, 30, 28]\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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == [127, 118, 109]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8], [6, 7, 8, 9]]) == [28, 24, 20]\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]]) == [12, 8, 6]\n assert candidate(grid = [[5, 5, 5, 5], [5, 1, 1, 5], [5, 1, 1, 5], [5, 5, 5, 5]]) == [12, 5, 1]\n assert candidate(grid = [[5, 5, 5, 5, 5, 5], [5, 10, 10, 10, 10, 5], [5, 10, 15, 15, 10, 5], [5, 10, 15, 15, 10, 5], [5, 10, 10, 10, 10, 5], [5, 5, 5, 5, 5, 5]]) == [75, 50, 40]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]) == [24, 20, 16]\n assert candidate(grid = [[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]]) == [400, 280, 240]\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, 7, 9, 11, 13, 15], [6, 8, 10, 12, 14, 16]]) == [80, 72, 64]\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, 4, 2]\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5], [5, 6, 6, 6, 6, 6, 5], [5, 6, 7, 7, 7, 6, 5], [5, 6, 7, 8, 7, 6, 5], [5, 6, 7, 7, 7, 6, 5], [5, 6, 6, 6, 6, 6, 5], [5, 5, 5, 5, 5, 5, 5]]) == [68, 52, 50]\n assert candidate(grid = [[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]]) == [1040, 760, 720]\n assert candidate(grid = [[100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000]]) == [400000, 100000]\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], [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]]) == [80, 60, 40]\n assert candidate(grid = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [60, 70, 80, 90, 100], [55, 65, 75, 85, 95], [110, 120, 130, 140, 150]]) == [520, 400, 360]\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4], [3, 5, 7, 8, 1, 6, 4], [4, 6, 8, 3, 5, 7, 1], [9, 2, 5, 1, 8, 3, 6], [5, 7, 1, 6, 4, 9, 2], [6, 4, 9, 2, 7, 1, 5], [1, 8, 3, 7, 2, 5, 9]]) == [78, 55, 44]\n assert candidate(grid = [[8, 1, 2, 3, 4, 5], [6, 7, 8, 9, 1, 2], [3, 4, 5, 6, 7, 8], [9, 1, 2, 3, 4, 5], [5, 6, 7, 8, 9, 1], [2, 3, 4, 5, 6, 7]]) == [49, 48, 39]\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, 7, 5, 3, 1], [9, 7, 5, 3, 1, 3, 5, 7, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 7, 5, 3, 1], [9, 7, 5, 3, 1, 3, 5, 7, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == [80, 68, 67]\n assert candidate(grid = [[9, 9, 9, 9, 9, 9, 9], [9, 8, 8, 8, 8, 8, 9], [9, 8, 7, 7, 7, 8, 9], [9, 8, 7, 6, 7, 8, 9], [9, 8, 7, 7, 7, 8, 9], [9, 8, 8, 8, 8, 8, 9], [9, 9, 9, 9, 9, 9, 9]]) == [100, 62, 60]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 1], [1, 2, 3, 3, 2, 1], [1, 2, 3, 4, 3, 2], [1, 2, 3, 3, 2, 1], [1, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1]]) == [18, 17, 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], [1, 2, 3, 4, 5]]) == [28, 15, 13]\n assert candidate(grid = [[5, 2, 1, 4, 3, 6, 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]]) == [208, 200, 192]\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]]) == [320, 220, 200]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 4, 5, 6, 7, 8, 9], [3, 4, 5, 6, 7, 8, 9, 10], [4, 5, 6, 7, 8, 9, 10, 11], [5, 6, 7, 8, 9, 10, 11, 12], [6, 7, 8, 9, 10, 11, 12, 13], [7, 8, 9, 10, 11, 12, 13, 14], [8, 9, 10, 11, 12, 13, 14, 15]]) == [108, 96, 88]\n assert candidate(grid = [[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], [6, 7, 8, 9, 10, 11, 12], [7, 8, 9, 10, 11, 12, 13]]) == [84, 72, 64]\n assert candidate(grid = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == [400000, 100000]\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], [6, 7, 8, 9, 10, 1, 2, 3, 4, 5], [7, 8, 9, 10, 1, 2, 3, 4, 5, 6], [8, 9, 10, 1, 2, 3, 4, 5, 6, 7], [9, 10, 1, 2, 3, 4, 5, 6, 7, 8], [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == [90, 86, 84]\n assert candidate(grid = [[1, 10, 100, 1000, 10000], [10, 100, 1000, 10000, 1], [100, 1000, 10000, 1, 10], [1000, 10000, 1, 10, 100], [10000, 1, 10, 100, 1000]]) == [20330, 20200, 20020]\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]]) == [300, 264, 256]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 2, 2, 2, 1], [1, 2, 3, 3, 3, 3, 3, 2, 1], [1, 2, 3, 4, 4, 4, 3, 2, 1], [1, 2, 3, 4, 5, 4, 3, 2, 1], [1, 2, 3, 4, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == [32, 30, 28]\n assert candidate(grid = [[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]]) == [80, 40, 10]\n assert candidate(grid = [[5, 2, 3, 1, 4], [1, 5, 6, 2, 3], [4, 1, 7, 3, 2], [3, 8, 4, 6, 5], [9, 7, 6, 5, 4]]) == [36, 27, 24]\n assert candidate(grid = [[10, 11, 12], [13, 14, 15], [16, 17, 18]]) == [56, 18, 17]\n assert candidate(grid = [[8, 4, 2], [6, 2, 4], [1, 3, 6]]) == [17, 8, 6]\n assert candidate(grid = [[1, 2], [3, 4]]) == [4, 3, 2]\n assert candidate(grid = [[5, 9, 1, 9], [8, 7, 4, 8], [6, 6, 3, 2]]) == [27, 19, 9]\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == [20, 5]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 3, 1], [4, 2, 1, 2, 4], [1, 5, 9, 5, 1]]) == [24, 18, 14]\n assert candidate(grid = [[5, 1, 4, 3, 1], [2, 3, 5, 1, 4], [3, 4, 3, 4, 3], [4, 3, 5, 1, 3], [3, 4, 2, 4, 2]]) == [20, 18, 17]\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == [20, 16, 12]\n assert candidate(grid = [[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]]) == [120, 80, 60]\n assert candidate(grid = [[1, 2], [2, 3], [3, 4]]) == [4, 3, 2]\n assert candidate(grid = [[5, 3, 5, 3, 5], [3, 5, 3, 5, 3], [5, 3, 5, 3, 5], [3, 5, 3, 5, 3], [5, 3, 5, 3, 5]]) == [40, 20, 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, 21, 22, 23, 24]]) == [68, 64, 60]\n assert candidate(grid = [[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]]) == [40, 10]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 3, 1], [2, 4, 6, 4, 2], [3, 5, 7, 5, 3]]) == [26, 20, 16]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == [15, 14, 13]\n assert candidate(grid = [[5, 3, 2, 1], [4, 6, 7, 8], [1, 9, 10, 11], [12, 13, 14, 15]]) == [41, 30, 26]\n assert candidate(grid = [[100000, 100000], [100000, 100000]]) == [100000]\n assert candidate(grid = [[5, 3, 5, 5, 5], [3, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 3], [5, 5, 5, 3, 5]]) == [40, 20, 16]\n assert candidate(grid = [[5, 3, 5, 3], [5, 3, 5, 3], [5, 3, 5, 3], [5, 3, 5, 3]]) == [16, 5, 3]\n assert candidate(grid = [[5]]) == [5]\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]) == [36, 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, 1, 1, 1, 1]]) == [30, 19, 18]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == [12, 5, 4]\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10], [10, 10, 10]]) == [40, 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, 5, 5, 5]]) == [40, 20, 5]\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]) == [440, 400, 280]\n assert candidate(grid = [[1, 2], [3, 4], [5, 6]]) == [6, 5, 4]\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10]]) == [40, 10]\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == [20, 9, 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, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30]]) == [128, 120, 92]\n assert candidate(grid = [[5, 3, 2, 1], [9, 8, 7, 6], [5, 6, 7, 8], [1, 2, 3, 4]]) == [25, 24, 23]\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50]]) == [240, 120, 50]\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 8, 8, 8, 9], [9, 8, 7, 8, 9], [9, 8, 8, 8, 9], [9, 9, 9, 9, 9]]) == [68, 34, 32]\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]]) == [8, 4, 1]\n assert candidate(grid = [[10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50], [25, 35, 45, 55]]) == [160, 140, 120]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == [200, 90, 80]\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == [44, 40, 28]\n assert candidate(grid = [[5, 2, 10, 6], [8, 3, 9, 7], [1, 4, 8, 2], [7, 6, 5, 3]]) == [28, 23, 20]\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]]) == [40, 20, 5]\n assert candidate(grid = [[8, 1, 6], [3, 5, 7], [4, 9, 2]]) == [20, 9, 8]\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]) == [72, 36, 9]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == [10, 9, 8]\n assert candidate(grid = [[1, 2], [2, 1]]) == [2, 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]]) == [8, 4, 1]\n assert candidate(grid = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == [400000, 100000]\n assert candidate(grid = [[9, 9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9]]) == [36, 9]\n assert candidate(grid = [[1]]) == [1]\n assert candidate(grid = [[5, 3, 8, 3, 7], [3, 2, 5, 7, 8], [1, 7, 3, 3, 2], [4, 8, 4, 2, 9], [6, 2, 3, 4, 8]]) == [33, 20, 19]\n", "comparison": "exact"}, "public_tests": ["[[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]", "[[1,2,3],[4,5,6],[7,8,9]]", "[[7,7,7]]"], "hints": ["You need to maintain only the biggest 3 distinct sums", "The limits are small enough for you to iterate over all rhombus sizes then iterate over all possible borders to get the sums"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().getBiggestThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:38+00:00", "tests_total": 118, "tests_dropped": 6, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "math", "sorting", "heap-priority-queue", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function getBiggestThree($grid) {", "container": "Solution", "callable": "getBiggestThree", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1879, "task_id": "minimum-xor-sum-of-two-arrays", "difficulty": "Hard", "problem_description": "You are given two integer arrays nums1 and nums2 of length n.\n\nThe XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).\n\n- For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.\n\nRearrange the elements of nums2 such that the resulting XOR sum is minimized.\n\nReturn the XOR sum after the rearrangement.\n\nExample 1:\n\nInput: nums1 = [1,2], nums2 = [2,3]\nOutput: 2\nExplanation: Rearrange nums2 so that it becomes [3,2].\nThe XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.\n\nExample 2:\n\nInput: nums1 = [1,0,3], nums2 = [5,3,4]\nOutput: 8\nExplanation: Rearrange nums2 so that it becomes [5,4,3].\nThe XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.\n\nConstraints:\n\n- n == nums1.length\n- n == nums2.length\n- 1 <= n <= 14\n- 0 <= nums1[i], nums2[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, 4, 2],nums2 = [4, 2, 2]) == 1\n assert candidate(nums1 = [1, 2],nums2 = [2, 3]) == 2\n assert candidate(nums1 = [2, 3, 4, 5],nums2 = [5, 4, 3, 2]) == 0\n assert candidate(nums1 = [4, 6, 2],nums2 = [9, 3, 5]) == 17\n assert candidate(nums1 = [5, 10, 15],nums2 = [15, 10, 5]) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 20, 10]) == 0\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 1, 1],nums2 = [1, 1, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 0\n assert candidate(nums1 = [5, 3, 4],nums2 = [1, 0, 3]) == 8\n assert candidate(nums1 = [14, 15, 16],nums2 = [13, 14, 15]) == 29\n assert candidate(nums1 = [7, 8, 9],nums2 = [9, 8, 7]) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 2, 2, 2]) == 12\n assert candidate(nums1 = [7, 8, 9],nums2 = [10, 11, 12]) == 15\n assert candidate(nums1 = [10000000, 10000000, 10000000],nums2 = [10000000, 10000000, 10000000]) == 0\n assert candidate(nums1 = [3, 5, 7, 9],nums2 = [9, 7, 5, 3]) == 0\n assert candidate(nums1 = [0, 1, 2],nums2 = [3, 4, 5]) == 9\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [14, 28, 19],nums2 = [28, 14, 19]) == 0\n assert candidate(nums1 = [1],nums2 = [1]) == 0\n assert candidate(nums1 = [1, 0, 3],nums2 = [5, 3, 4]) == 8\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 14\n assert candidate(nums1 = [12, 14, 16, 18, 20, 22],nums2 = [21, 19, 17, 15, 13, 11]) == 34\n assert candidate(nums1 = [4, 1, 3, 2],nums2 = [7, 6, 5, 8]) == 18\n assert candidate(nums1 = [9999999, 8888888, 7777777, 6666666, 5555555],nums2 = [4444444, 3333333, 2222222, 1111111, 0]) == 28302135\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128],nums2 = [128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums1 = [7, 23, 15, 4, 8],nums2 = [17, 9, 3, 20, 12]) == 30\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8],nums2 = [8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27]) == 115\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == 36\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [15, 13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(nums1 = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 9999999, 999999, 99999, 9999, 999, 99],nums2 = [99, 999, 9999, 99999, 999999, 9999999, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 0\n assert candidate(nums1 = [7, 8, 9, 10, 11, 12],nums2 = [12, 11, 10, 9, 8, 7]) == 0\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]) == 220\n assert candidate(nums1 = [7, 13, 21, 31],nums2 = [3, 8, 15, 28]) == 34\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70],nums2 = [70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 0\n assert candidate(nums1 = [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]) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums1 = [7, 8, 9, 10, 11],nums2 = [12, 13, 14, 15, 16]) == 39\n assert candidate(nums1 = [13, 17, 19, 23, 29, 31],nums2 = [31, 29, 23, 19, 17, 13]) == 0\n assert candidate(nums1 = [101, 202, 303, 404, 505, 606, 707, 808, 909],nums2 = [909, 808, 707, 606, 505, 404, 303, 202, 101]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 24\n assert candidate(nums1 = [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]) == 42\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],nums2 = [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800],nums2 = [800, 700, 600, 500, 400, 300, 200, 100]) == 0\n assert candidate(nums1 = [5, 8, 12, 7, 3],nums2 = [10, 6, 4, 15, 9]) == 15\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000],nums2 = [140000, 130000, 120000, 110000, 100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 0\n assert candidate(nums1 = [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]) == 14\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],nums2 = [140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(nums1 = [1, 0, 0, 0],nums2 = [0, 1, 1, 1]) == 2\n assert candidate(nums1 = [21, 17, 34, 19, 28, 42],nums2 = [45, 39, 27, 51, 18, 32]) == 101\n assert candidate(nums1 = [8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],nums2 = [18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8]) == 0\n assert candidate(nums1 = [5, 6, 7, 8, 9, 10, 11, 12, 13],nums2 = [13, 12, 11, 10, 9, 8, 7, 6, 5]) == 0\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],nums2 = [8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums1 = [9, 11, 7, 13, 17, 19, 23],nums2 = [29, 25, 21, 15, 13, 11, 7]) == 30\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7],nums2 = [7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [7, 23, 45, 6, 78],nums2 = [89, 12, 34, 56, 78]) == 146\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]) == 0\n assert candidate(nums1 = [8, 16, 24, 32, 40, 48, 56, 64],nums2 = [64, 56, 48, 40, 32, 24, 16, 8]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 15\n assert candidate(nums1 = [9876543, 8765432, 7654321, 6543210, 5432109],nums2 = [4321098, 3210987, 2109876, 1098765, 987654]) == 28067535\n assert candidate(nums1 = [8, 16, 32, 64, 128, 256],nums2 = [256, 128, 64, 32, 16, 8]) == 0\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000],nums2 = [50000, 40000, 30000, 20000, 10000]) == 0\n assert candidate(nums1 = [123456, 789012, 345678, 901234, 567890, 678901, 789012, 890123, 901234, 123456, 234567, 345678, 456789, 567890],nums2 = [567890, 456789, 345678, 234567, 123456, 901234, 890123, 789012, 678901, 567890, 456789, 345678, 234567, 123456]) == 1656438\n assert candidate(nums1 = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53],nums2 = [53, 49, 45, 41, 37, 33, 29, 25, 21, 17, 13, 9, 5, 1]) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70],nums2 = [70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 40, 30, 20, 10]) == 0\n assert candidate(nums1 = [7, 8, 9, 10, 11],nums2 = [11, 10, 9, 8, 7]) == 0\n assert candidate(nums1 = [2, 3, 5, 7, 11, 13, 17, 19],nums2 = [19, 17, 13, 11, 7, 5, 3, 2]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [10, 8, 6, 4, 2]) == 15\n assert candidate(nums1 = [256, 512, 1024, 2048, 4096],nums2 = [8192, 4096, 2048, 1024, 512]) == 8448\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400],nums2 = [1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 0\n assert candidate(nums1 = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],nums2 = [98, 91, 84, 77, 70, 63, 56, 49, 42, 35, 28, 21, 14, 7]) == 0\n assert candidate(nums1 = [23, 34, 45, 56, 67],nums2 = [67, 56, 45, 34, 23]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13],nums2 = [13, 11, 9, 7, 5, 3, 1]) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700],nums2 = [700, 600, 500, 400, 300, 200, 100]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2]\n[2,3]", "[1,0,3]\n[5,3,4]"], "hints": ["Since n <= 14, we can consider every subset of nums2.", "We can represent every subset of nums2 using bitmasks."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minimumXORSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:40+00:00", "tests_total": 93, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "bitmask", "hungarian-algorithm", "bipartite-graph", "successive-shortest-path-algorithm"]}, "language": "php", "interface": {"raw_signature": "function minimumXORSum($nums1, $nums2) {", "container": "Solution", "callable": "minimumXORSum", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1880, "task_id": "check-if-word-equals-summation-of-two-words", "difficulty": "Easy", "problem_description": "The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).\n\nThe numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.\n\n- For example, if s = \"acb\", we concatenate each letter's letter value, resulting in \"021\". After converting it, we get 21.\n\nYou are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.\n\nReturn true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.\n\nExample 1:\n\nInput: firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\"\nOutput: true\nExplanation:\nThe numerical value of firstWord is \"acb\" -> \"021\" -> 21.\nThe numerical value of secondWord is \"cba\" -> \"210\" -> 210.\nThe numerical value of targetWord is \"cdb\" -> \"231\" -> 231.\nWe return true because 21 + 210 == 231.\n\nExample 2:\n\nInput: firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\"\nOutput: false\nExplanation:\nThe numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\nThe numerical value of secondWord is \"a\" -> \"0\" -> 0.\nThe numerical value of targetWord is \"aab\" -> \"001\" -> 1.\nWe return false because 0 + 0 != 1.\n\nExample 3:\n\nInput: firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\"\nOutput: true\nExplanation:\nThe numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\nThe numerical value of secondWord is \"a\" -> \"0\" -> 0.\nThe numerical value of targetWord is \"aaaa\" -> \"0000\" -> 0.\nWe return true because 0 + 0 == 0.\n\nConstraints:\n\n- 1 <= firstWord.length, secondWord.length, targetWord.length <= 8\n- firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(firstWord = \"ij\",secondWord = \"ji\",targetWord = \"ii\") == False\n assert candidate(firstWord = \"fgh\",secondWord = \"ghf\",targetWord = \"ggg\") == False\n assert candidate(firstWord = \"ij\",secondWord = \"ji\",targetWord = \"jjj\") == False\n assert candidate(firstWord = \"b\",secondWord = \"c\",targetWord = \"d\") == True\n assert candidate(firstWord = \"i\",secondWord = \"j\",targetWord = \"ji\") == False\n assert candidate(firstWord = \"ab\",secondWord = \"ba\",targetWord = \"bb\") == True\n assert candidate(firstWord = \"j\",secondWord = \"j\",targetWord = \"i\") == False\n assert candidate(firstWord = \"a\",secondWord = \"a\",targetWord = \"b\") == False\n assert candidate(firstWord = \"aaa\",secondWord = \"a\",targetWord = \"aab\") == False\n assert candidate(firstWord = \"aaa\",secondWord = \"a\",targetWord = \"aaaa\") == True\n assert candidate(firstWord = \"acb\",secondWord = \"cba\",targetWord = \"cdb\") == True\n assert candidate(firstWord = \"j\",secondWord = \"j\",targetWord = \"jj\") == False\n assert candidate(firstWord = \"acacacac\",secondWord = \"bdbdbdbd\",targetWord = \"cececece\") == False\n assert candidate(firstWord = \"ijijij\",secondWord = \"jijiji\",targetWord = \"jjjjjjjj\") == False\n assert candidate(firstWord = \"j\",secondWord = \"jj\",targetWord = \"jjj\") == False\n assert candidate(firstWord = \"ijijij\",secondWord = \"ijijij\",targetWord = \"jjjjjjjj\") == False\n assert candidate(firstWord = \"hjihj\",secondWord = \"ihjih\",targetWord = \"jjjjj\") == False\n assert candidate(firstWord = \"aabbcc\",secondWord = \"ddeeff\",targetWord = \"gggggh\") == False\n assert candidate(firstWord = \"abcdefgh\",secondWord = \"abcdefgh\",targetWord = \"hhhhhhhh\") == False\n assert candidate(firstWord = \"babababa\",secondWord = \"babababa\",targetWord = \"cacacaca\") == True\n assert candidate(firstWord = \"aaa\",secondWord = \"bbb\",targetWord = \"ccc\") == False\n assert candidate(firstWord = \"iiii\",secondWord = \"jjjj\",targetWord = \"jjjjjjjj\") == False\n assert candidate(firstWord = \"abc\",secondWord = \"def\",targetWord = \"defabc\") == False\n assert candidate(firstWord = \"a\",secondWord = \"b\",targetWord = \"c\") == False\n assert candidate(firstWord = \"abcdefgh\",secondWord = \"hgfedcba\",targetWord = \"jjjjjjjj\") == False\n assert candidate(firstWord = \"jjjjj\",secondWord = \"jjjjj\",targetWord = \"jjjjjjj\") == False\n assert candidate(firstWord = \"aaaaaaaa\",secondWord = \"bbbbbbbb\",targetWord = \"cccccccc\") == False\n assert candidate(firstWord = \"aabbccdd\",secondWord = \"dccbbaaa\",targetWord = \"dddddddd\") == False\n assert candidate(firstWord = \"iiii\",secondWord = \"jjjj\",targetWord = \"jjjjjj\") == False\n assert candidate(firstWord = \"ijijijij\",secondWord = \"hghghghg\",targetWord = \"gggggggg\") == False\n assert candidate(firstWord = \"jijij\",secondWord = \"ijiji\",targetWord = \"jjjjjjj\") == False\n assert candidate(firstWord = \"abcdefgh\",secondWord = \"hgfedcba\",targetWord = \"jjjjjjj\") == False\n assert candidate(firstWord = \"abcde\",secondWord = \"edcba\",targetWord = \"jjjjj\") == False\n assert candidate(firstWord = \"hgfedcba\",secondWord = \"abcdefgh\",targetWord = \"iiiiiiii\") == False\n assert candidate(firstWord = \"jijij\",secondWord = \"ijiji\",targetWord = \"jjjjj\") == False\n assert candidate(firstWord = \"j\",secondWord = \"ij\",targetWord = \"ji\") == True\n assert candidate(firstWord = \"jij\",secondWord = \"iji\",targetWord = \"jjjj\") == False\n", "comparison": "exact"}, "public_tests": ["\"acb\"\n\"cba\"\n\"cdb\"", "\"aaa\"\n\"a\"\n\"aab\"", "\"aaa\"\n\"a\"\n\"aaaa\""], "hints": ["Convert each character of each word to its numerical value.", "Check if the numerical values satisfies the condition."], "metadata": {"canonical_parameter_names": ["firstWord", "secondWord", "targetWord"], "leetcode_dataset_entry_point": "Solution().isSumEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:42+00:00", "tests_total": 73, "tests_dropped": 36, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function isSumEqual($firstWord, $secondWord, $targetWord) {", "container": "Solution", "callable": "isSumEqual", "parameters": [{"name": "firstWord", "type": "String"}, {"name": "secondWord", "type": "String"}, {"name": "targetWord", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1881, "task_id": "maximum-value-after-insertion", "difficulty": "Medium", "problem_description": "You are given a very large integer n, represented as a string, and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.\n\nYou want to maximize n's numerical value by inserting x anywhere in the decimal representation of n. You cannot insert x to the left of the negative sign.\n\n- For example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.\n- If n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.\n\nReturn a string representing the maximum value of n after the insertion.\n\nExample 1:\n\nInput: n = \"99\", x = 9\nOutput: \"999\"\nExplanation: The result is the same regardless of where you insert 9.\n\nExample 2:\n\nInput: n = \"-13\", x = 2\nOutput: \"-123\"\nExplanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n\nConstraints:\n\n- 1 <= n.length <= 10^5\n- 1 <= x <= 9\n- The digits in n are in the range [1, 9].\n- n is a valid representation of an integer.\n- In the case of a negative n, it will begin with '-'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = \"5486\",x = 7) == \"75486\"\n assert candidate(n = \"-11111\",x = 1) == \"-111111\"\n assert candidate(n = \"-123456789\",x = 5) == \"-1234556789\"\n assert candidate(n = \"987654321\",x = 5) == \"9876554321\"\n assert candidate(n = \"-98765\",x = 3) == \"-398765\"\n assert candidate(n = \"-1000\",x = 1) == \"-10001\"\n assert candidate(n = \"-987654321\",x = 5) == \"-5987654321\"\n assert candidate(n = \"-54321\",x = 4) == \"-454321\"\n assert candidate(n = \"123456789\",x = 5) == \"5123456789\"\n assert candidate(n = \"5\",x = 9) == \"95\"\n assert candidate(n = \"-1000\",x = 5) == \"-10005\"\n assert candidate(n = \"1000\",x = 1) == \"11000\"\n assert candidate(n = \"54321\",x = 6) == \"654321\"\n assert candidate(n = \"12345\",x = 3) == \"312345\"\n assert candidate(n = \"1000\",x = 5) == \"51000\"\n assert candidate(n = \"-973\",x = 8) == \"-8973\"\n assert candidate(n = \"-13\",x = 2) == \"-123\"\n assert candidate(n = \"54823\",x = 7) == \"754823\"\n assert candidate(n = \"1\",x = 1) == \"11\"\n assert candidate(n = \"99\",x = 9) == \"999\"\n assert candidate(n = \"-64823\",x = 7) == \"-647823\"\n assert candidate(n = \"567\",x = 8) == \"8567\"\n assert candidate(n = \"-9\",x = 1) == \"-19\"\n assert candidate(n = \"-9\",x = 9) == \"-99\"\n assert candidate(n = \"54893\",x = 7) == \"754893\"\n assert candidate(n = \"-987\",x = 7) == \"-7987\"\n assert candidate(n = \"-222222222\",x = 2) == \"-2222222222\"\n assert candidate(n = \"-1\",x = 1) == \"-11\"\n assert candidate(n = \"1000000000\",x = 9) == \"91000000000\"\n assert candidate(n = \"123123123\",x = 3) == \"3123123123\"\n assert candidate(n = \"-101010101\",x = 5) == \"-1010101015\"\n assert candidate(n = \"999999999\",x = 1) == \"9999999991\"\n assert candidate(n = \"500000000\",x = 5) == \"5500000000\"\n assert candidate(n = \"555555555\",x = 5) == \"5555555555\"\n assert candidate(n = \"-595959595\",x = 5) == \"-5595959595\"\n assert candidate(n = \"-123456789\",x = 3) == \"-1233456789\"\n assert candidate(n = \"222222222\",x = 1) == \"2222222221\"\n assert candidate(n = \"192837465\",x = 4) == \"4192837465\"\n assert candidate(n = \"-900000000\",x = 1) == \"-1900000000\"\n assert candidate(n = \"-999999999\",x = 9) == \"-9999999999\"\n assert candidate(n = \"-9876543210\",x = 1) == \"-19876543210\"\n assert candidate(n = \"9876543210\",x = 9) == \"99876543210\"\n assert candidate(n = \"-5432109876\",x = 9) == \"-54321098769\"\n assert candidate(n = \"-123456789\",x = 4) == \"-1234456789\"\n assert candidate(n = \"-199999999\",x = 9) == \"-1999999999\"\n assert candidate(n = \"-123123123\",x = 5) == \"-1231231235\"\n assert candidate(n = \"199999999\",x = 9) == \"9199999999\"\n assert candidate(n = \"123456789\",x = 9) == \"9123456789\"\n assert candidate(n = \"111111111\",x = 2) == \"2111111111\"\n assert candidate(n = \"53284769\",x = 5) == \"553284769\"\n assert candidate(n = \"9876543210\",x = 8) == \"98876543210\"\n assert candidate(n = \"9\",x = 1) == \"91\"\n assert candidate(n = \"987654321\",x = 9) == \"9987654321\"\n assert candidate(n = \"111000111\",x = 1) == \"1111000111\"\n assert candidate(n = \"-1000000000\",x = 9) == \"-10000000009\"\n assert candidate(n = \"-123456789\",x = 1) == \"-1123456789\"\n assert candidate(n = \"54321\",x = 3) == \"543321\"\n assert candidate(n = \"-9999999999\",x = 5) == \"-59999999999\"\n assert candidate(n = \"505050505\",x = 5) == \"5505050505\"\n assert candidate(n = \"121212121\",x = 3) == \"3121212121\"\n assert candidate(n = \"123454321\",x = 5) == \"5123454321\"\n assert candidate(n = \"333333333\",x = 3) == \"3333333333\"\n assert candidate(n = \"987654321\",x = 8) == \"9887654321\"\n assert candidate(n = \"11111111111111111111\",x = 2) == \"211111111111111111111\"\n assert candidate(n = \"-987654321\",x = 1) == \"-1987654321\"\n assert candidate(n = \"-500000000\",x = 5) == \"-5000000005\"\n assert candidate(n = \"-53284769\",x = 5) == \"-532584769\"\n assert candidate(n = \"101010101\",x = 5) == \"5101010101\"\n assert candidate(n = \"-9876543210\",x = 5) == \"-59876543210\"\n assert candidate(n = \"666666666\",x = 5) == \"6666666665\"\n assert candidate(n = \"111111111\",x = 1) == \"1111111111\"\n assert candidate(n = \"12345678901234567890\",x = 5) == \"512345678901234567890\"\n assert candidate(n = \"987654321\",x = 6) == \"9876654321\"\n assert candidate(n = \"-123456789\",x = 9) == \"-1234567899\"\n assert candidate(n = \"123456789\",x = 1) == \"1234567891\"\n assert candidate(n = \"-555555555\",x = 6) == \"-5555555556\"\n assert candidate(n = \"-333333333\",x = 2) == \"-2333333333\"\n assert candidate(n = \"595959595\",x = 9) == \"9595959595\"\n assert candidate(n = \"-54321\",x = 6) == \"-543216\"\n assert candidate(n = \"987654321\",x = 7) == \"9877654321\"\n assert candidate(n = \"9\",x = 9) == \"99\"\n assert candidate(n = \"-86420\",x = 1) == \"-186420\"\n assert candidate(n = \"-111111111\",x = 9) == \"-1111111119\"\n assert candidate(n = \"-54321\",x = 3) == \"-354321\"\n assert candidate(n = \"-505050505\",x = 5) == \"-5050505055\"\n assert candidate(n = \"100000000\",x = 9) == \"9100000000\"\n assert candidate(n = \"-9876543210987654321\",x = 9) == \"-98765432109876543219\"\n assert candidate(n = \"333333333\",x = 4) == \"4333333333\"\n assert candidate(n = \"-2222222222\",x = 1) == \"-12222222222\"\n assert candidate(n = \"122222222\",x = 2) == \"2122222222\"\n assert candidate(n = \"123456789\",x = 3) == \"3123456789\"\n assert candidate(n = \"-321321321\",x = 2) == \"-2321321321\"\n assert candidate(n = \"1122334455\",x = 6) == \"61122334455\"\n assert candidate(n = \"123456789\",x = 6) == \"6123456789\"\n assert candidate(n = \"1111111111\",x = 1) == \"11111111111\"\n assert candidate(n = \"-999999999\",x = 1) == \"-1999999999\"\n assert candidate(n = \"-333333333\",x = 3) == \"-3333333333\"\n assert candidate(n = \"-1122334455\",x = 3) == \"-11223334455\"\n assert candidate(n = \"-9876543210\",x = 8) == \"-89876543210\"\n assert candidate(n = \"98765432109876543210\",x = 5) == \"987655432109876543210\"\n assert candidate(n = \"-12345678901234567890\",x = 5) == \"-123455678901234567890\"\n assert candidate(n = \"1\",x = 9) == \"91\"\n assert candidate(n = \"-2000000000\",x = 1) == \"-12000000000\"\n assert candidate(n = \"11111\",x = 1) == \"111111\"\n assert candidate(n = \"100000000\",x = 1) == \"1100000000\"\n assert candidate(n = \"1234567890\",x = 5) == \"51234567890\"\n assert candidate(n = \"-999000999\",x = 9) == \"-9990009999\"\n assert candidate(n = \"1111111111\",x = 2) == \"21111111111\"\n assert candidate(n = \"-99999\",x = 1) == \"-199999\"\n assert candidate(n = \"555555555\",x = 6) == \"6555555555\"\n assert candidate(n = \"-98765432109876543210\",x = 5) == \"-598765432109876543210\"\n assert candidate(n = \"1999999999\",x = 2) == \"21999999999\"\n assert candidate(n = \"123123123\",x = 4) == \"4123123123\"\n assert candidate(n = \"86420\",x = 9) == \"986420\"\n assert candidate(n = \"-1\",x = 9) == \"-19\"\n assert candidate(n = \"-1000000000\",x = 1) == \"-10000000001\"\n assert candidate(n = \"989898989\",x = 7) == \"9898989897\"\n assert candidate(n = \"-222222222\",x = 3) == \"-2222222223\"\n assert candidate(n = \"192837465\",x = 8) == \"8192837465\"\n assert candidate(n = \"33333\",x = 3) == \"333333\"\n assert candidate(n = \"1000000000\",x = 1) == \"11000000000\"\n assert candidate(n = \"123456789\",x = 4) == \"4123456789\"\n assert candidate(n = \"-123456789\",x = 8) == \"-1234567889\"\n assert candidate(n = \"999999999\",x = 9) == \"9999999999\"\n", "comparison": "exact"}, "public_tests": ["\"99\"\n9", "\"-13\"\n2"], "hints": ["Note that if the number is negative it's the same as positive but you look for the minimum instead.", "In the case of maximum, if s[i] < x it's optimal that x is put before s[i].", "In the case of minimum, if s[i] > x it's optimal that x is put before s[i]."], "metadata": {"canonical_parameter_names": ["n", "x"], "leetcode_dataset_entry_point": "Solution().maxValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:44+00:00", "tests_total": 133, "tests_dropped": 9, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maxValue($n, $x) {", "container": "Solution", "callable": "maxValue", "parameters": [{"name": "n", "type": "String"}, {"name": "x", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1882, "task_id": "process-tasks-using-servers", "difficulty": "Medium", "problem_description": "You are given two 0-indexed integer arrays servers and tasks of lengths n and m respectively. servers[i] is the weight of the i^th server, and tasks[j] is the time needed to process the j^th task in seconds.\n\nTasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.\n\nAt second j, the j^th task is inserted into the queue (starting with the 0^th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.\n\nIf there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.\n\nA server that is assigned task j at second t will be free again at second t + tasks[j].\n\nBuild an array ans of length m, where ans[j] is the index of the server the j^th task will be assigned to.\n\nReturn the array ans.\n\nExample 1:\n\nInput: servers = [3,3,2], tasks = [1,2,3,2,1,2]\nOutput: [2,2,0,2,1,2]\nExplanation: Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.\n\nExample 2:\n\nInput: servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\nOutput: [1,4,1,4,1,3,2]\nExplanation: Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4.\n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9.\n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n\nConstraints:\n\n- servers.length == n\n- tasks.length == m\n- 1 <= n, m <= 2 * 10^5\n- 1 <= servers[i], tasks[j] <= 2 * 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(servers = [3, 3, 2],tasks = [1, 2, 3, 2, 1, 2]) == [2, 2, 0, 2, 1, 2]\n assert candidate(servers = [1, 1, 1],tasks = [10, 20, 30, 40, 50]) == [0, 1, 2, 0, 1]\n assert candidate(servers = [5, 1, 4, 3, 2],tasks = [2, 1, 2, 4, 5, 2, 1]) == [1, 4, 1, 4, 1, 3, 2]\n assert candidate(servers = [2, 2, 2, 2],tasks = [1, 1, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(servers = [2, 2, 2, 2],tasks = [1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0]\n assert candidate(servers = [1],tasks = [10]) == [0]\n assert candidate(servers = [10, 20, 30],tasks = [3, 2, 1]) == [0, 1, 2]\n assert candidate(servers = [1, 2, 3],tasks = [3, 2, 1]) == [0, 1, 2]\n assert candidate(servers = [1, 2, 3, 4, 5],tasks = [5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4]\n assert candidate(servers = [10, 20, 30],tasks = [1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0]\n assert candidate(servers = [5, 4, 3, 2, 1],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [4, 4, 3, 4, 2, 3, 1, 4, 0, 2]\n assert candidate(servers = [10, 20, 30],tasks = [1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0]\n assert candidate(servers = [2, 2, 2, 2],tasks = [1, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0, 0]\n assert candidate(servers = [1, 1, 1],tasks = [10, 10, 10, 10, 10]) == [0, 1, 2, 0, 1]\n assert candidate(servers = [1, 2, 3, 4, 5],tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(servers = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7]\n assert candidate(servers = [5, 4, 3, 2, 1],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [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]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 5, 1, 3, 0, 5, 1, 4, 2, 3, 0, 3, 0, 5, 1, 3, 0, 4, 2]\n assert candidate(servers = [10, 15, 20, 25, 30],tasks = [5, 10, 15, 20, 25, 30, 35, 40]) == [0, 1, 2, 3, 4, 0, 1, 2]\n assert candidate(servers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],tasks = [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]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [5, 15, 25, 35, 45, 55, 65]) == [0, 1, 2, 3, 4, 0, 1]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [1, 1, 1, 1, 1],tasks = [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]\n assert candidate(servers = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],tasks = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 3, 6, 0, 9, 2, 4, 8, 10, 7, 5]\n assert candidate(servers = [3, 1, 2],tasks = [2, 3, 1, 2, 1, 3, 2, 1, 2, 3, 1, 2, 3]) == [1, 2, 1, 1, 2, 1, 2, 0, 1, 2, 1, 1, 2]\n assert candidate(servers = [3, 5, 2, 7, 6],tasks = [2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 0, 2, 1, 0, 4, 2, 3, 1]\n assert candidate(servers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(servers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],tasks = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 8, 9, 8, 9, 7, 8]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],tasks = [20, 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, 18, 19]\n assert candidate(servers = [5, 4, 3, 2, 1],tasks = [2, 3, 4, 5, 1, 2, 3, 4, 5]) == [4, 3, 4, 2, 3, 3, 4, 3, 2]\n assert candidate(servers = [100, 200, 150, 50],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2]\n assert candidate(servers = [100, 100, 100, 100, 100],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [20, 10, 30, 40, 50],tasks = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [1, 0, 2, 3, 4, 1, 0, 2, 3, 4]\n assert candidate(servers = [2, 3, 1, 4, 5, 2, 3, 1, 4, 5],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [2, 7, 0, 5, 1, 6, 3, 8, 4, 9, 2, 7, 0, 5, 1, 6, 3, 8, 4, 9]\n assert candidate(servers = [15, 25, 5, 20, 10],tasks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [2, 4, 0, 3, 1, 2, 4, 0, 3, 1, 2, 4, 0, 3, 1, 2, 4, 0, 3, 1]\n assert candidate(servers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [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]\n assert candidate(servers = [2, 3, 5, 7, 11],tasks = [30, 10, 20, 40, 50, 15, 25, 35, 45, 55]) == [0, 1, 2, 3, 4, 1, 2, 1, 0, 3]\n assert candidate(servers = [7, 5, 3, 1],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [3, 3, 2, 3, 1, 2, 0, 3, 1, 2, 0, 3, 1, 2, 0]\n assert candidate(servers = [5, 3, 8, 6],tasks = [2, 6, 4, 1, 7, 3, 5]) == [1, 0, 1, 3, 3, 2, 1]\n assert candidate(servers = [3, 2, 1, 4, 5],tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [2, 1, 0, 3, 4, 2, 1, 0, 3, 4, 2, 1, 0, 3, 4]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [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]\n assert candidate(servers = [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]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [5, 3, 8, 6, 2],tasks = [2, 4, 1, 5, 7, 3, 6, 8, 9, 10]) == [4, 1, 4, 4, 0, 1, 3, 2, 4, 1]\n assert candidate(servers = [5, 1, 4, 3, 2, 6],tasks = [2, 1, 2, 4, 5, 2, 1, 3, 5, 7, 9, 11, 13, 15]) == [1, 4, 1, 4, 1, 3, 2, 4, 3, 1, 4, 2, 0, 3]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(servers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [7, 1, 1, 1, 1, 1],tasks = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]\n assert candidate(servers = [23, 45, 12, 67, 89, 34, 56, 78, 90, 10],tasks = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == [9, 2, 0, 5, 1, 6, 3, 7, 4, 8]\n assert candidate(servers = [100, 200, 300, 400, 500],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [1, 1, 1, 1, 1, 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]\n assert candidate(servers = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],tasks = [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]\n assert candidate(servers = [3, 3, 3, 3, 3],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [100, 200, 300, 400, 500],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [3, 3, 3, 3, 3],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [10, 10, 10, 10],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0]\n assert candidate(servers = [100, 200, 300, 400, 500],tasks = [500, 400, 300, 200, 100, 500, 400, 300, 200, 100]) == [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]\n assert candidate(servers = [2, 1, 3, 4],tasks = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10]) == [1, 0, 2, 3, 1, 0, 2, 3, 1, 0]\n assert candidate(servers = [7, 8, 9, 10],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 0, 1, 2, 3, 3, 2]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [5, 5, 5, 5, 5],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],tasks = [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]\n assert candidate(servers = [3, 5, 1, 4, 2],tasks = [15, 10, 5, 20, 25, 30, 5, 10, 15, 20]) == [2, 4, 0, 3, 1, 0, 4, 2, 4, 3]\n assert candidate(servers = [7, 8, 9, 10, 11],tasks = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 4]\n assert candidate(servers = [1, 10, 1, 10, 1, 10],tasks = [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]\n assert candidate(servers = [1, 1, 1, 1, 1],tasks = [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]\n assert candidate(servers = [5, 10, 15, 20, 25],tasks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(servers = [10, 20, 30, 40, 50],tasks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(servers = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7]\n assert candidate(servers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],tasks = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [3, 2, 1, 4, 5],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [2, 1, 0, 3, 4, 2, 1, 0, 3, 4, 2, 1, 0, 3, 4]\n assert candidate(servers = [5, 3, 8, 6, 2],tasks = [2, 5, 7, 4, 9, 1, 3, 6, 8, 10]) == [4, 1, 4, 0, 3, 2, 1, 0, 2, 4]\n assert candidate(servers = [7, 11, 13, 17, 19, 23, 29],tasks = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == [0, 1, 0, 2, 1, 3, 4, 0, 5, 6, 2, 1, 3, 4, 0, 5, 6, 2, 1, 3]\n assert candidate(servers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [9, 9, 8, 9, 7, 8, 6, 9, 5, 7]\n assert candidate(servers = [1, 2, 3, 4, 5],tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n assert candidate(servers = [3, 2, 1],tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [2, 1, 0, 2, 1, 0, 2, 1, 0, 2]\n assert candidate(servers = [10, 20, 15, 25, 30],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 2, 0, 1, 2, 3, 0, 4, 1, 2, 3, 0, 4, 1]\n assert candidate(servers = [5, 3, 8, 6, 2],tasks = [4, 3, 6, 2, 5, 4, 3, 7]) == [4, 1, 0, 3, 4, 1, 3, 2]\n assert candidate(servers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [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]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [100, 200, 300, 400, 500],tasks = [500, 400, 300, 200, 100, 500, 400, 300, 200, 100]) == [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]\n assert candidate(servers = [10, 5, 8, 3],tasks = [2, 8, 10, 3, 5, 7, 6, 4]) == [3, 1, 3, 2, 0, 2, 1, 0]\n assert candidate(servers = [5, 3, 7, 1, 4],tasks = [10, 5, 3, 8, 2, 1, 9, 6]) == [3, 1, 4, 0, 2, 4, 1, 4]\n assert candidate(servers = [1, 1, 1, 1, 1],tasks = [2, 3, 2, 4, 5, 2, 3, 1, 4, 5]) == [0, 1, 0, 2, 0, 1, 3, 1, 1, 0]\n assert candidate(servers = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],tasks = [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]\n assert candidate(servers = [5, 5, 5, 5, 5],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [7, 7, 7, 7, 7],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],tasks = [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]\n assert candidate(servers = [15, 10, 20, 5, 25],tasks = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == [3, 1, 0, 3, 2, 4, 1, 0, 3, 2, 4, 1, 0, 3]\n assert candidate(servers = [1, 2, 3, 4, 5],tasks = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [0, 0, 1, 0, 2, 1, 1, 0, 1, 2]\n assert candidate(servers = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1],tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [1, 3, 5, 7, 9, 1, 3, 5, 7, 9]\n assert candidate(servers = [2, 2, 2, 2],tasks = [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]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(servers = [1, 3, 2],tasks = [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, 3, 2, 1, 2, 3, 1, 3, 2, 1, 2, 3, 1]) == [0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 0, 2, 0]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 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]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [10, 1, 10, 1, 10, 1],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 1, 3, 1, 5, 3, 0, 1, 2, 5, 4, 3, 0, 1, 2]\n assert candidate(servers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2]\n assert candidate(servers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(servers = [50, 25, 75, 100, 125],tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [1, 0, 2, 3, 4, 1, 0, 2, 3, 4, 1, 0, 2, 3, 4]\n assert candidate(servers = [2, 4, 6, 8, 10],tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [0, 0, 1, 2, 0, 3, 4, 1, 2, 0]\n assert candidate(servers = [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],tasks = [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, 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, 23]\n assert candidate(servers = [1, 1, 1, 1, 1],tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 1, 3, 0, 4, 2]\n", "comparison": "exact"}, "public_tests": ["[3,3,2]\n[1,2,3,2,1,2]", "[5,1,4,3,2]\n[2,1,2,4,5,2,1]"], "hints": ["You can maintain a Heap of available Servers and a Heap of unavailable servers", "Note that the tasks will be processed in the input order so you just need to find the x-th server that will be available according to the rules"], "metadata": {"canonical_parameter_names": ["servers", "tasks"], "leetcode_dataset_entry_point": "Solution().assignTasks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:47+00:00", "tests_total": 111, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function assignTasks($servers, $tasks) {", "container": "Solution", "callable": "assignTasks", "parameters": [{"name": "servers", "type": "Integer[]"}, {"name": "tasks", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1883, "task_id": "minimum-skips-to-arrive-at-meeting-on-time", "difficulty": "Hard", "problem_description": "You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the i^th road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.\n\nAfter you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.\n\n- For example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly 2 hours, you do not need to wait.\n\nHowever, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.\n\n- For example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.\n\nReturn the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.\n\nExample 1:\n\nInput: dist = [1,3,2], speed = 4, hoursBefore = 2\nOutput: 1\nExplanation:\nWithout skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.\nYou can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.\nNote that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.\n\nExample 2:\n\nInput: dist = [7,3,5,5], speed = 2, hoursBefore = 10\nOutput: 2\nExplanation:\nWithout skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.\nYou can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.\n\nExample 3:\n\nInput: dist = [7,3,5,5], speed = 1, hoursBefore = 10\nOutput: -1\nExplanation: It is impossible to arrive at the meeting on time even if you skip all the rests.\n\nConstraints:\n\n- n == dist.length\n- 1 <= n <= 1000\n- 1 <= dist[i] <= 10^5\n- 1 <= speed <= 10^6\n- 1 <= hoursBefore <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(dist = [10, 10, 10],speed = 5,hoursBefore = 6) == 0\n assert candidate(dist = [1, 1, 1, 1, 1],speed = 1,hoursBefore = 3) == -1\n assert candidate(dist = [5, 5, 5, 5, 5],speed = 10,hoursBefore = 2) == -1\n assert candidate(dist = [1, 1, 1, 1],speed = 1,hoursBefore = 4) == 0\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 10) == 0\n assert candidate(dist = [7, 3, 5, 5],speed = 1,hoursBefore = 10) == -1\n assert candidate(dist = [1, 2, 3, 4, 5],speed = 1,hoursBefore = 20) == 0\n assert candidate(dist = [1, 1, 1, 1, 1],speed = 1,hoursBefore = 4) == -1\n assert candidate(dist = [10, 10, 10],speed = 10,hoursBefore = 3) == 0\n assert candidate(dist = [5, 5, 5, 5, 5],speed = 5,hoursBefore = 5) == 0\n assert candidate(dist = [1, 1, 1, 1],speed = 1,hoursBefore = 3) == -1\n assert candidate(dist = [7, 3, 5, 5],speed = 2,hoursBefore = 10) == 2\n assert candidate(dist = [1, 3, 2],speed = 4,hoursBefore = 2) == 1\n assert candidate(dist = [100000, 100000, 100000],speed = 100000,hoursBefore = 3) == 0\n assert candidate(dist = [10, 10, 10],speed = 5,hoursBefore = 5) == -1\n assert candidate(dist = [5, 5, 5, 5, 5],speed = 10,hoursBefore = 3) == 2\n assert candidate(dist = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],speed = 2,hoursBefore = 15) == -1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],speed = 15,hoursBefore = 15) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 1000,hoursBefore = 5) == -1\n assert candidate(dist = [7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5, 7, 3, 5, 5],speed = 2,hoursBefore = 100) == -1\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],speed = 2,hoursBefore = 10) == -1\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],speed = 10000,hoursBefore = 99) == -1\n assert candidate(dist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],speed = 5,hoursBefore = 20) == 8\n assert candidate(dist = [10, 20, 30, 40, 50],speed = 25,hoursBefore = 10) == 0\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],speed = 5,hoursBefore = 50) == -1\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],speed = 100000,hoursBefore = 9) == -1\n assert candidate(dist = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],speed = 10,hoursBefore = 40) == -1\n assert candidate(dist = [1, 2, 3, 4, 5],speed = 100,hoursBefore = 1) == 4\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 3,hoursBefore = 100) == -1\n assert candidate(dist = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],speed = 100,hoursBefore = 20) == 7\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],speed = 2,hoursBefore = 100) == -1\n assert candidate(dist = [10, 20, 30, 40, 50],speed = 5,hoursBefore = 30) == 0\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],speed = 1,hoursBefore = 50) == -1\n assert candidate(dist = [10, 21, 30, 40, 50, 60, 70, 80, 90, 100],speed = 10,hoursBefore = 55) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],speed = 2,hoursBefore = 50) == -1\n assert candidate(dist = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],speed = 100000,hoursBefore = 9) == -1\n assert candidate(dist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],speed = 5,hoursBefore = 20) == -1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 5,hoursBefore = 35) == -1\n assert candidate(dist = [10, 20, 30, 40, 50],speed = 15,hoursBefore = 15) == 0\n assert candidate(dist = [100, 200, 300, 400, 500],speed = 100,hoursBefore = 10) == -1\n assert candidate(dist = [123, 456, 789, 101, 202, 303],speed = 100,hoursBefore = 15) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 29) == -1\n assert candidate(dist = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1],speed = 4,hoursBefore = 5) == 6\n assert candidate(dist = [3, 6, 9, 12, 15, 18, 21],speed = 5,hoursBefore = 15) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = 3,hoursBefore = 12) == -1\n assert candidate(dist = [5, 10, 15, 20, 25],speed = 5,hoursBefore = 10) == -1\n assert candidate(dist = [9, 8, 7, 6, 5, 4, 3, 2, 1],speed = 3,hoursBefore = 10) == -1\n assert candidate(dist = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],speed = 100,hoursBefore = 9) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 15) == -1\n assert candidate(dist = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],speed = 2,hoursBefore = 30) == 10\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],speed = 1,hoursBefore = 105) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 20) == 0\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 19) == -1\n assert candidate(dist = [7, 3, 5, 5, 3, 7, 5, 3, 5, 5, 3, 7, 5, 3, 5, 5, 3, 7, 5, 3, 5, 5, 3, 7, 5, 3, 5, 5, 3, 7, 5, 3, 5, 5],speed = 2,hoursBefore = 50) == -1\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],speed = 10,hoursBefore = 6) == 4\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 100) == -1\n assert candidate(dist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],speed = 2,hoursBefore = 15) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],speed = 100,hoursBefore = 60) == -1\n assert candidate(dist = [7, 3, 5, 5, 7, 3, 5, 5],speed = 2,hoursBefore = 15) == -1\n assert candidate(dist = [100, 200, 300, 400],speed = 100,hoursBefore = 8) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = 5,hoursBefore = 12) == 4\n assert candidate(dist = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980],speed = 99999,hoursBefore = 10) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],speed = 3,hoursBefore = 20) == -1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 1,hoursBefore = 1000) == 0\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 25,hoursBefore = 20) == -1\n assert candidate(dist = [9, 7, 5, 3, 1],speed = 4,hoursBefore = 5) == -1\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],speed = 7,hoursBefore = 25) == -1\n assert candidate(dist = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],speed = 10,hoursBefore = 13) == -1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 25) == -1\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35],speed = 7,hoursBefore = 20) == 5\n assert candidate(dist = [10000, 20000, 30000, 40000, 50000],speed = 10000,hoursBefore = 15) == 0\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 15,hoursBefore = 30) == -1\n assert candidate(dist = [3, 8, 2, 7, 5],speed = 4,hoursBefore = 10) == 0\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 100,hoursBefore = 50) == -1\n assert candidate(dist = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],speed = 100000,hoursBefore = 5) == 5\n assert candidate(dist = [9, 8, 7, 6, 5, 4, 3, 2, 1],speed = 5,hoursBefore = 15) == 0\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],speed = 3,hoursBefore = 30) == 0\n assert candidate(dist = [1, 3, 2, 4, 5],speed = 3,hoursBefore = 5) == 3\n assert candidate(dist = [999, 1000, 1001, 1002, 1003],speed = 1,hoursBefore = 5000) == -1\n assert candidate(dist = [100000, 100000, 100000, 100000],speed = 100000,hoursBefore = 4) == 0\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000],speed = 100000,hoursBefore = 4) == -1\n assert candidate(dist = [1000, 2000, 3000, 4000],speed = 1000,hoursBefore = 10) == 0\n assert candidate(dist = [100000, 100000, 100000, 100000, 100000],speed = 100000,hoursBefore = 5) == 0\n assert candidate(dist = [100000, 90000, 80000, 70000, 60000],speed = 50000,hoursBefore = 10) == 0\n assert candidate(dist = [10, 20, 30, 40, 50],speed = 15,hoursBefore = 12) == 0\n assert candidate(dist = [100000, 100000, 100000],speed = 100000,hoursBefore = 2) == -1\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = 15,hoursBefore = 25) == -1\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],speed = 1,hoursBefore = 100) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 50,hoursBefore = 35) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 100,hoursBefore = 30) == -1\n assert candidate(dist = [5, 10, 15, 20, 25],speed = 5,hoursBefore = 15) == 0\n assert candidate(dist = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],speed = 3,hoursBefore = 25) == 0\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 100,hoursBefore = 45) == -1\n assert candidate(dist = [99999, 99998, 99997, 99996],speed = 100000,hoursBefore = 399990) == 0\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 10) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],speed = 5,hoursBefore = 25) == -1\n assert candidate(dist = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],speed = 9,hoursBefore = 8) == -1\n assert candidate(dist = [50, 100, 150, 200, 250],speed = 50,hoursBefore = 10) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = 10,hoursBefore = 5) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],speed = 3,hoursBefore = 25) == -1\n assert candidate(dist = [5, 10, 15, 20, 25],speed = 5,hoursBefore = 14) == -1\n assert candidate(dist = [100, 200, 300, 400, 500],speed = 1,hoursBefore = 1500) == 0\n assert candidate(dist = [5, 4, 3, 2, 1],speed = 1,hoursBefore = 15) == 0\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = 1,hoursBefore = 20) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = 2,hoursBefore = 15) == -1\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = 5,hoursBefore = 10) == -1\n assert candidate(dist = [5, 15, 25, 35, 45],speed = 10,hoursBefore = 12) == -1\n assert candidate(dist = [100, 200, 300, 400, 500],speed = 50,hoursBefore = 25) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 500,hoursBefore = 12) == 4\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],speed = 30,hoursBefore = 35) == -1\n assert candidate(dist = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200],speed = 50,hoursBefore = 20) == -1\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = 100,hoursBefore = 55) == 0\n assert candidate(dist = [1000, 2000, 3000, 4000, 5000],speed = 1000,hoursBefore = 20) == 0\n assert candidate(dist = [1000, 2000, 3000, 4000, 5000],speed = 1000,hoursBefore = 15) == 0\n", "comparison": "exact"}, "public_tests": ["[1,3,2]\n4\n2", "[7,3,5,5]\n2\n10", "[7,3,5,5]\n1\n10"], "hints": ["Is there something you can keep track of from one road to another?", "How would knowing the start time for each state help us solve the problem?"], "metadata": {"canonical_parameter_names": ["dist", "speed", "hoursBefore"], "leetcode_dataset_entry_point": "Solution().minSkips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:49+00:00", "tests_total": 114, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function minSkips($dist, $speed, $hoursBefore) {", "container": "Solution", "callable": "minSkips", "parameters": [{"name": "dist", "type": "Integer[]"}, {"name": "speed", "type": "Integer"}, {"name": "hoursBefore", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1884, "task_id": "egg-drop-with-2-eggs-and-n-floors", "difficulty": "Medium", "problem_description": "You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.\n\nYou know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\n\nIn each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.\n\nReturn the minimum number of moves that you need to determine with certainty what the value of f is.\n\nExample 1:\n\nInput: n = 2\nOutput: 2\nExplanation: We can drop the first egg from floor 1 and the second egg from floor 2.\nIf the first egg breaks, we know that f = 0.\nIf the second egg breaks but the first egg didn't, we know that f = 1.\nOtherwise, if both eggs survive, we know that f = 2.\n\nExample 2:\n\nInput: n = 100\nOutput: 14\nExplanation: One optimal strategy is:\n- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting from floor 1 and going up one at a time to find f within 8 more drops. Total drops is 1 + 8 = 9.\n- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9 and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more drops. Total drops is 2 + 12 = 14.\n- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45, 55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.\nRegardless of the outcome, it takes at most 14 drops to determine f.\n\nConstraints:\n\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == 4\n assert candidate(n = 1000) == 45\n assert candidate(n = 5) == 3\n assert candidate(n = 81) == 13\n assert candidate(n = 999) == 45\n assert candidate(n = 15) == 5\n assert candidate(n = 64) == 11\n assert candidate(n = 450) == 30\n assert candidate(n = 600) == 35\n assert candidate(n = 6) == 3\n assert candidate(n = 2) == 2\n assert candidate(n = 100) == 14\n assert candidate(n = 500) == 32\n assert candidate(n = 50) == 10\n assert candidate(n = 1) == 1\n assert candidate(n = 10) == 4\n assert candidate(n = 300) == 24\n assert candidate(n = 990) == 44\n assert candidate(n = 850) == 41\n assert candidate(n = 125) == 16\n assert candidate(n = 900) == 42\n assert candidate(n = 995) == 45\n assert candidate(n = 505) == 32\n assert candidate(n = 650) == 36\n assert candidate(n = 550) == 33\n assert candidate(n = 460) == 30\n assert candidate(n = 99) == 14\n assert candidate(n = 501) == 32\n assert candidate(n = 250) == 22\n assert candidate(n = 75) == 12\n assert candidate(n = 997) == 45\n assert candidate(n = 925) == 43\n assert candidate(n = 504) == 32\n assert candidate(n = 350) == 26\n assert candidate(n = 503) == 32\n assert candidate(n = 150) == 17\n assert candidate(n = 800) == 40\n assert candidate(n = 200) == 20\n assert candidate(n = 400) == 28\n assert candidate(n = 750) == 39\n assert candidate(n = 502) == 32\n assert candidate(n = 950) == 44\n assert candidate(n = 700) == 37\n assert candidate(n = 366) == 27\n assert candidate(n = 998) == 45\n assert candidate(n = 25) == 7\n", "comparison": "exact"}, "public_tests": ["2", "100"], "hints": ["Is it really optimal to always drop the egg on the middle floor for each move?", "Can we create states based on the number of unbroken eggs and floors to build our solution?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().twoEggDrop", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:51+00:00", "tests_total": 46, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function twoEggDrop($n) {", "container": "Solution", "callable": "twoEggDrop", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1886, "task_id": "determine-whether-matrix-can-be-obtained-by-rotation", "difficulty": "Easy", "problem_description": "Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.\n\nExample 1:\n\nInput: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise to make mat equal target.\n\nExample 2:\n\nInput: mat = [[0,1],[1,1]], target = [[1,0],[0,1]]\nOutput: false\nExplanation: It is impossible to make mat equal to target by rotating mat.\n\nExample 3:\n\nInput: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.\n\nConstraints:\n\n- n == mat.length == target.length\n- n == mat[i].length == target[i].length\n- 1 <= n <= 10\n- mat[i][j] and target[i][j] are either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1, 0, 0], [0, 1, 0], [0, 0, 1]],target = [[0, 0, 1], [0, 1, 0], [1, 0, 0]]) == True\n assert candidate(mat = [[0, 1], [1, 0]],target = [[1, 0], [0, 1]]) == True\n assert candidate(mat = [[1, 1], [0, 0]],target = [[0, 1], [0, 1]]) == True\n assert candidate(mat = [[1, 0], [0, 1]],target = [[0, 1], [1, 0]]) == True\n assert candidate(mat = [[1, 1, 0], [0, 1, 0], [0, 1, 1]],target = [[0, 0, 1], [0, 1, 0], [1, 1, 0]]) == False\n assert candidate(mat = [[0, 1], [1, 1]],target = [[1, 0], [0, 1]]) == False\n assert candidate(mat = [[0, 0, 0], [0, 1, 0], [1, 1, 1]],target = [[1, 1, 1], [0, 1, 0], [0, 0, 0]]) == True\n assert candidate(mat = [[1, 1, 0], [0, 0, 0], [0, 1, 1]],target = [[0, 0, 0], [0, 1, 1], [1, 1, 0]]) == False\n assert candidate(mat = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 1, 1]],target = [[0, 0, 1, 1], [0, 1, 1, 0], [1, 0, 0, 1], [1, 1, 0, 0]]) == False\n assert candidate(mat = [[1, 1], [0, 0]],target = [[0, 0], [1, 1]]) == True\n assert candidate(mat = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1]],target = [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1]]) == True\n assert candidate(mat = [[1, 1, 1, 0, 0], [1, 0, 0, 1, 1], [1, 0, 0, 1, 1], [0, 1, 1, 0, 0], [0, 0, 0, 0, 1]],target = [[0, 0, 0, 0, 1], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [1, 0, 0, 1, 1], [1, 1, 1, 0, 0]]) == False\n assert candidate(mat = [[1, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 1]],target = [[1, 1, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 0, 1]]) == False\n assert candidate(mat = [[1, 1, 1, 0, 0], [1, 0, 0, 0, 1], [1, 0, 0, 1, 0], [1, 0, 1, 0, 0], [1, 1, 0, 0, 0]],target = [[0, 0, 0, 1, 1], [0, 0, 1, 0, 1], [0, 1, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 1, 1]]) == False\n assert candidate(mat = [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]],target = [[0, 0, 1, 1], [0, 0, 1, 1], [1, 1, 0, 0], [1, 1, 0, 0]]) == True\n assert candidate(mat = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],target = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 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(mat = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],target = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1]]) == False\n assert candidate(mat = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]],target = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == True\n assert candidate(mat = [[1, 1, 0, 0], [0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0]],target = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == False\n assert candidate(mat = [[0, 1, 1, 1, 1], [1, 0, 0, 0, 0], [1, 0, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 1, 0]],target = [[0, 1, 1, 1, 0], [1, 0, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 1], [1, 1, 1, 1, 0]]) == False\n assert candidate(mat = [[0, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 0]],target = [[0, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 0]]) == True\n assert candidate(mat = [[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]]) == True\n assert candidate(mat = [[0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1]],target = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0]]) == False\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, 1, 0, 1, 0, 1]],target = [[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]]) == True\n assert candidate(mat = [[0, 1, 1, 0], [1, 1, 1, 1], [1, 0, 0, 1], [0, 1, 1, 0]],target = [[0, 1, 0, 1], [1, 1, 1, 1], [0, 0, 1, 0], [1, 1, 1, 1]]) == False\n assert candidate(mat = [[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]],target = [[0, 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, 0, 0, 0, 0, 0]]) == True\n assert candidate(mat = [[1, 0, 0, 1], [1, 0, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0]],target = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]) == False\n assert candidate(mat = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [0, 1, 1, 0, 1], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0]],target = [[0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0]]) == False\n assert candidate(mat = [[1, 1, 0, 1], [1, 0, 0, 1], [0, 0, 1, 1], [1, 0, 1, 0]],target = [[0, 1, 0, 1], [1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]) == False\n assert candidate(mat = [[1, 1, 1], [1, 0, 1], [1, 1, 1]],target = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]) == True\n assert candidate(mat = [[0, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]],target = [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]) == True\n assert candidate(mat = [[0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]],target = [[1, 1, 1, 1], [1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 0, 0]]) == True\n assert candidate(mat = [[1, 0, 0, 0], [0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0]],target = [[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 0, 1], [0, 0, 0, 1]]) == False\n assert candidate(mat = [[0, 1, 0, 0], [1, 1, 1, 0], [0, 1, 1, 1], [0, 0, 0, 1]],target = [[1, 0, 0, 0], [1, 1, 0, 1], [1, 1, 1, 0], [1, 0, 1, 0]]) == False\n assert candidate(mat = [[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]],target = [[1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1], [1, 0, 1, 0, 1]]) == True\n assert candidate(mat = [[0, 0, 1, 1], [0, 1, 0, 0], [1, 0, 0, 1], [1, 1, 0, 0]],target = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]) == False\n assert candidate(mat = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1]],target = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 0, 0], [1, 1, 1, 1]]) == False\n assert candidate(mat = [[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]],target = [[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]]) == True\n assert candidate(mat = [[1, 1, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 1, 1]],target = [[1, 0, 1, 0], [1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 1, 0]]) == False\n assert candidate(mat = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]],target = [[1, 0, 1, 0], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 1, 0]]) == False\n assert candidate(mat = [[1, 1, 1], [0, 0, 1], [0, 0, 1]],target = [[1, 1, 1], [1, 0, 0], [1, 0, 0]]) == True\n assert candidate(mat = [[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]],target = [[0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 0, 0], [1, 0, 0, 0, 0]]) == True\n assert candidate(mat = [[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]],target = [[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]]) == False\n assert candidate(mat = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],target = [[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]) == False\n assert candidate(mat = [[1, 1, 0, 0, 0], [1, 0, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 1, 0, 0, 0]],target = [[0, 0, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 1, 1]]) == False\n assert candidate(mat = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],target = [[0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0]]) == False\n assert candidate(mat = [[0, 1, 0, 0], [1, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 1]],target = [[1, 0, 0, 1], [0, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 0]]) == False\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, 0, 1]],target = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == True\n assert candidate(mat = [[1, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1]],target = [[0, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 0]]) == True\n assert candidate(mat = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],target = [[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]]) == False\n assert candidate(mat = [[1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 1]],target = [[0, 0, 0, 1, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0]]) == False\n assert candidate(mat = [[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]],target = [[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]]) == True\n assert candidate(mat = [[0, 0, 0, 1, 0], [0, 0, 1, 1, 0], [0, 1, 1, 0, 0], [1, 1, 0, 0, 0], [0, 1, 1, 0, 0]],target = [[0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 1, 1, 0, 0], [0, 0, 1, 1, 0], [0, 1, 1, 0, 0]]) == False\n assert candidate(mat = [[0, 1, 1, 0], [1, 1, 1, 1], [0, 0, 1, 0], [1, 1, 1, 1]],target = [[1, 0, 0, 0], [1, 1, 0, 1], [1, 1, 1, 1], [0, 0, 1, 1]]) == False\n assert candidate(mat = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]],target = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) == True\n assert candidate(mat = [[0, 0, 1, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 1, 0]],target = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1]]) == False\n assert candidate(mat = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],target = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]]) == False\n assert candidate(mat = [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]],target = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) == True\n assert candidate(mat = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],target = [[0, 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(mat = [[0, 1, 1, 1], [1, 1, 0, 0], [1, 0, 0, 1], [1, 1, 1, 0]],target = [[1, 1, 1, 0], [1, 0, 0, 1], [0, 0, 1, 1], [1, 1, 0, 0]]) == False\n assert candidate(mat = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0]],target = [[0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0]]) == False\n assert candidate(mat = [[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]],target = [[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]]) == False\n assert candidate(mat = [[1, 0, 1, 1], [0, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0]],target = [[0, 0, 1, 1], [1, 1, 0, 0], [1, 0, 1, 1], [0, 1, 0, 0]]) == False\n assert candidate(mat = [[1, 1, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1]],target = [[1, 0, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 0, 1]]) == False\n assert candidate(mat = [[1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]],target = [[0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == False\n assert candidate(mat = [[1, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 1, 1], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0]],target = [[0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [1, 1, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]]) == False\n assert candidate(mat = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],target = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]) == True\n assert candidate(mat = [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]],target = [[1, 0, 0, 0, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [1, 0, 0, 0, 1]]) == False\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, 0, 1]],target = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == False\n assert candidate(mat = [[0, 1, 1, 0, 0], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [0, 0, 1, 0, 0], [1, 0, 1, 0, 1]],target = [[0, 0, 1, 0, 0], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]) == False\n assert candidate(mat = [[0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 0], [1, 1, 0, 0]],target = [[0, 0, 1, 0], [0, 1, 1, 0], [1, 1, 0, 0], [0, 0, 1, 0]]) == False\n assert candidate(mat = [[0, 0, 1, 1], [0, 0, 1, 1], [1, 1, 0, 0], [1, 1, 0, 0]],target = [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]) == True\n assert candidate(mat = [[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]],target = [[0, 0, 0, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0], [1, 1, 0, 0, 0], [1, 1, 0, 0, 0]]) == True\n assert candidate(mat = [[1, 0, 1], [0, 1, 0], [1, 0, 1]],target = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == True\n assert candidate(mat = [[0, 0, 1], [0, 1, 0], [1, 0, 0]],target = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == True\n assert candidate(mat = [[1, 0, 0, 1, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [1, 0, 0, 1, 0], [1, 1, 0, 0, 1]],target = [[1, 1, 0, 1, 1], [0, 0, 1, 0, 0], [1, 0, 0, 1, 0], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]]) == False\n assert candidate(mat = [[0, 1, 1, 1], [1, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]],target = [[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 0, 1], [1, 1, 1, 0]]) == True\n assert candidate(mat = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],target = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) == True\n assert candidate(mat = [[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]],target = [[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]]) == True\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,0]]\n[[1,0],[0,1]]", "[[0,1],[1,1]]\n[[1,0],[0,1]]", "[[0,0,0],[0,1,0],[1,1,1]]\n[[1,1,1],[0,1,0],[0,0,0]]"], "hints": ["What is the maximum number of rotations you have to check?", "Is there a formula you can use to rotate a matrix 90 degrees?"], "metadata": {"canonical_parameter_names": ["mat", "target"], "leetcode_dataset_entry_point": "Solution().findRotation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:56+00:00", "tests_total": 79, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "matrix"]}, "language": "php", "interface": {"raw_signature": "function findRotation($mat, $target) {", "container": "Solution", "callable": "findRotation", "parameters": [{"name": "mat", "type": "Integer[][]"}, {"name": "target", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1887, "task_id": "reduction-operations-to-make-the-array-elements-equal", "difficulty": "Medium", "problem_description": "Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:\n\n1. Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.\n2. Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.\n3. Reduce nums[i] to nextLargest.\n\nReturn the number of operations to make all elements in nums equal.\n\nExample 1:\n\nInput: nums = [5,1,3]\nOutput: 3\nExplanation: It takes 3 operations to make all elements in nums equal:\n1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].\n2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].\n3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].\n\nExample 2:\n\nInput: nums = [1,1,1]\nOutput: 0\nExplanation: All elements in nums are already equal.\n\nExample 3:\n\nInput: nums = [1,1,2,2,3]\nOutput: 4\nExplanation: It takes 4 operations to make all elements in nums equal:\n1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].\n2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].\n3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].\n4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].\n\nConstraints:\n\n- 1 <= nums.length <= 5 * 10^4\n- 1 <= nums[i] <= 5 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 20\n assert candidate(nums = [4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 5, 2, 4, 3]) == 10\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3]) == 4\n assert candidate(nums = [3, 3, 2, 1, 2, 3, 3, 2, 1]) == 11\n assert candidate(nums = [4, 3, 2, 1, 4, 3, 2, 1]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [5, 1, 3]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums = [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]) == 18\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 60\n assert candidate(nums = [5, 3, 3, 3, 2, 2, 1, 1, 1, 1]) == 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]) == 10\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9]) == 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]) == 190\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 26\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\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5]) == 40\n assert candidate(nums = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 90\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 20\n assert candidate(nums = [4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 21\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 105\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 40\n assert candidate(nums = [4, 3, 3, 2, 2, 1, 1, 1, 1]) == 9\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991]) == 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]) == 32\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 140\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]) == 435\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]) == 50\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]) == 85\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]) == 435\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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, 7, 7, 7, 7, 7, 7, 7]) == 112\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991, 49990, 49989, 49988, 49987, 49986, 49985, 49984, 49983, 49982, 49981]) == 190\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 20\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]) == 126\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3]) == 24\n assert candidate(nums = [30000, 20000, 10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 2, 1]) == 120\n assert candidate(nums = [5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 20\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 43\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 19\n assert candidate(nums = [10, 10, 10, 10, 10, 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, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 225\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 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, 5, 5, 5, 5, 4]) == 24\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 5, 5]) == 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, 21, 22, 23, 24, 25]) == 300\n assert candidate(nums = [1, 3, 2, 5, 4, 3, 2, 1, 4, 3, 2, 1, 3, 2, 1, 2, 1, 1]) == 23\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5]) == 30\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, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]) == 174\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 190\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 20\n assert candidate(nums = [5, 4, 4, 4, 4, 3, 3, 3, 2, 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, 10, 9, 8, 7, 6]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 435\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 = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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 = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 90\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]) == 435\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\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]) == 50\n assert candidate(nums = [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]) == 71\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 105\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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]) == 45\n assert candidate(nums = [25000, 25000, 24999, 24998, 24997, 24996, 24995, 24994, 24993, 24992]) == 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]) == 190\n assert candidate(nums = [5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1]) == 40\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 26\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 28\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991]) == 45\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 18\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5]) == 41\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == 190\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]) == 56\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]) == 50\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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]) == 24\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, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 50\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, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 25\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]) == 135\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 20\n assert candidate(nums = [1, 3, 2, 3, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 125\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 = [5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2]) == 30\n assert candidate(nums = [5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 20\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]) == 0\n assert candidate(nums = [5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1]) == 36\n", "comparison": "exact"}, "public_tests": ["[5,1,3]", "[1,1,1]", "[1,1,2,2,3]"], "hints": ["Sort the array.", "Try to reduce all elements with maximum value to the next maximum value in one operation."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().reductionOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:33:58+00:00", "tests_total": 99, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "php", "interface": {"raw_signature": "function reductionOperations($nums) {", "container": "Solution", "callable": "reductionOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1888, "task_id": "minimum-number-of-flips-to-make-the-binary-string-alternating", "difficulty": "Medium", "problem_description": "You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:\n\n- Type-1: Remove the character at the start of the string s and append it to the end of the string.\n- Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.\n\nReturn the minimum number of type-2 operations you need to perform such that s becomes alternating.\n\nThe string is called alternating if no two adjacent characters are equal.\n\n- For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\n\nExample 1:\n\nInput: s = \"111000\"\nOutput: 2\nExplanation: Use the first operation two times to make s = \"100011\".\nThen, use the second operation on the third and sixth elements to make s = \"101010\".\n\nExample 2:\n\nInput: s = \"010\"\nOutput: 0\nExplanation: The string is already alternating.\n\nExample 3:\n\nInput: s = \"1110\"\nOutput: 1\nExplanation: Use the second operation on the second element to make s = \"1010\".\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 = \"100100100\") == 3\n assert candidate(s = \"1111\") == 2\n assert candidate(s = \"110011\") == 3\n assert candidate(s = \"111000111000\") == 4\n assert candidate(s = \"11110000\") == 4\n assert candidate(s = \"1110\") == 1\n assert candidate(s = \"0000\") == 2\n assert candidate(s = \"010101010\") == 0\n assert candidate(s = \"01010\") == 0\n assert candidate(s = \"111000\") == 2\n assert candidate(s = \"111111\") == 3\n assert candidate(s = \"10101\") == 0\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"00001111\") == 4\n assert candidate(s = \"000111\") == 2\n assert candidate(s = \"1001001001\") == 5\n assert candidate(s = \"11111\") == 2\n assert candidate(s = \"000000\") == 3\n assert candidate(s = \"010101\") == 0\n assert candidate(s = \"101010\") == 0\n assert candidate(s = \"00000\") == 2\n assert candidate(s = \"0001\") == 1\n assert candidate(s = \"111000111000111000\") == 6\n assert candidate(s = \"010101010101010101010101010101010101\") == 0\n assert candidate(s = \"0000000000111111111100000000001111111111\") == 20\n assert candidate(s = \"00011111000111110001111100011111\") == 12\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"00000000000000000000000000000000\") == 16\n assert candidate(s = \"0110110110110110110110110110\") == 14\n assert candidate(s = \"1010101010101010101010101\") == 0\n assert candidate(s = \"110100110100\") == 4\n assert candidate(s = \"1100110011001100\") == 8\n assert candidate(s = \"1010101010101010101\") == 0\n assert candidate(s = \"0101001101010011010100110101001101010011010100110101001\") == 12\n assert candidate(s = \"010101010101010101010101\") == 0\n assert candidate(s = \"11101001111010011110100111101001\") == 12\n assert candidate(s = \"00001111000011110000\") == 10\n assert candidate(s = \"000111000111000111\") == 6\n assert candidate(s = \"101010101010101010101010\") == 0\n assert candidate(s = \"11110101010101011111\") == 4\n assert candidate(s = \"0000000011111111000000001111\") == 14\n assert candidate(s = \"1100101010\") == 2\n assert candidate(s = \"101010101010101010101\") == 0\n assert candidate(s = \"1010101010\") == 0\n assert candidate(s = \"1010101010101010101010101010101011\") == 1\n assert candidate(s = \"010101010101010101\") == 0\n assert candidate(s = \"0000000000\") == 5\n assert candidate(s = \"101010101010101010101010101\") == 0\n assert candidate(s = \"1110011100\") == 5\n assert candidate(s = \"1100110011\") == 5\n assert candidate(s = \"111000111000111000111000111000\") == 10\n assert candidate(s = \"0000000000000000\") == 8\n assert candidate(s = \"000111000111000111000111\") == 8\n assert candidate(s = \"11100000111000001110000011100000111000001110000011100000\") == 21\n assert candidate(s = \"0101001101010011010100110101001101010011\") == 10\n assert candidate(s = \"1100110011001100110011001100110011001100\") == 20\n assert candidate(s = \"1010101010101010\") == 0\n assert candidate(s = \"010100010101\") == 1\n assert candidate(s = \"0101010101010101010101\") == 0\n assert candidate(s = \"111000111000111000111000111000111000\") == 12\n assert candidate(s = \"111101111011110111101111011110111101111011110111\") == 23\n assert candidate(s = \"01101010101010101011\") == 3\n assert candidate(s = \"01010101011\") == 0\n assert candidate(s = \"11111000001111100000\") == 8\n assert candidate(s = \"0101010101010101010101010101010101\") == 0\n assert candidate(s = \"000011110000111100001111000011110000\") == 18\n assert candidate(s = \"11001100110011001100110011001100110011001100110011001\") == 25\n assert candidate(s = \"111000011100001110000\") == 9\n assert candidate(s = \"0000111100001111000011110000\") == 14\n assert candidate(s = \"1110001110001110001110\") == 7\n assert candidate(s = \"11110000111100001111\") == 10\n assert candidate(s = \"01010101010101010101010101\") == 0\n assert candidate(s = \"10010010010010010010010010010\") == 12\n assert candidate(s = \"0101001101010011\") == 4\n assert candidate(s = \"1111111100000000111111110000\") == 14\n assert candidate(s = \"1000000000\") == 4\n assert candidate(s = \"11111111111111111111\") == 10\n assert candidate(s = \"000011110000\") == 6\n assert candidate(s = \"0011001100\") == 5\n assert candidate(s = \"1111111111111111\") == 8\n assert candidate(s = \"10101010101010101010101010101010101\") == 0\n assert candidate(s = \"00000000001111111111\") == 10\n assert candidate(s = \"101010101010101010101010101010101\") == 0\n assert candidate(s = \"00000111110000011111\") == 8\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111\") == 26\n assert candidate(s = \"1111100000111110000011111\") == 10\n assert candidate(s = \"111000111000111000111\") == 7\n assert candidate(s = \"11111111110000000000\") == 10\n assert candidate(s = \"11001100110011001100\") == 10\n assert candidate(s = \"11100011100011100011\") == 7\n assert candidate(s = \"01010101010101010101010101010101\") == 0\n assert candidate(s = \"10010010010010010010\") == 9\n assert candidate(s = \"1010101010101010101010101010\") == 0\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\") == 25\n assert candidate(s = \"1001001001001001001001\") == 11\n assert candidate(s = \"0000011111000001111100000\") == 10\n assert candidate(s = \"1111000011110000111100001111000011110000\") == 20\n assert candidate(s = \"111100001111\") == 6\n assert candidate(s = \"11110000111100001111000011110000\") == 16\n assert candidate(s = \"0000000000000000000000000111111111111111111111111\") == 23\n assert candidate(s = \"11001100110011001100110011001100110011001100110011001100110\") == 28\n assert candidate(s = \"101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"000111100011110001111\") == 9\n assert candidate(s = \"11111111111111111111111111111111\") == 16\n assert candidate(s = \"00011111000111110001111100011111000111110001111100011111\") == 21\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"00010110000101100001011000010110\") == 12\n assert candidate(s = \"0101010101010101010101010101\") == 0\n assert candidate(s = \"000111000111000111000111000111\") == 10\n assert candidate(s = \"11010101010101010110\") == 3\n assert candidate(s = \"111111111111111111111111111111111\") == 16\n assert candidate(s = \"0101010101\") == 0\n assert candidate(s = \"11111111111111111111111111111111111111111111111111\") == 25\n assert candidate(s = \"00010001000100010001000\") == 6\n assert candidate(s = \"110011001100110011001100110011001\") == 15\n assert candidate(s = \"00110011001100110011\") == 10\n assert candidate(s = \"0111011101\") == 2\n assert candidate(s = \"010101010101010101010101010101010\") == 0\n assert candidate(s = \"00000000000000000000\") == 10\n assert candidate(s = \"1111000011110000\") == 8\n assert candidate(s = \"0101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"10101010101010101010101010101010\") == 0\n assert candidate(s = \"010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"1111100000\") == 4\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111111111\") == 33\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000\") == 26\n assert candidate(s = \"010101010101010101010\") == 0\n assert candidate(s = \"1111111111111111111111111000000000000000000000000\") == 23\n assert candidate(s = \"1010101010101010101010\") == 0\n assert candidate(s = \"1111111111\") == 5\n assert candidate(s = \"1111000011110000111100001111\") == 14\n assert candidate(s = \"00000000000000000000000000000\") == 14\n assert candidate(s = \"00011100011100011100\") == 7\n assert candidate(s = \"01010101010101010101\") == 0\n assert candidate(s = \"000000000000000000000000000000000\") == 16\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010\") == 0\n assert candidate(s = \"11100000111000001110000011100000\") == 12\n assert candidate(s = \"101010101010101010101010101010101010\") == 0\n assert candidate(s = \"10101010100\") == 0\n assert candidate(s = \"11111111000000001111\") == 10\n assert candidate(s = \"01101101101101101101\") == 9\n assert candidate(s = \"10101010101010101010\") == 0\n assert candidate(s = \"00000000111111110000\") == 10\n assert candidate(s = \"11000011110000111100\") == 10\n assert candidate(s = \"11111111111111111111111111\") == 13\n assert candidate(s = \"111000111000111000111000\") == 8\n assert candidate(s = \"010101010101010101010101010101010101010101\") == 0\n assert candidate(s = \"10111011101110111011\") == 5\n assert candidate(s = \"001100110011\") == 6\n assert candidate(s = \"0000111100001111\") == 8\n", "comparison": "exact"}, "public_tests": ["\"111000\"", "\"010\"", "\"1110\""], "hints": ["Note what actually matters is how many 0s and 1s are in odd and even positions", "For every cyclic shift we need to count how many 0s and 1s are at each parity and convert the minimum between them for each parity"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:00+00:00", "tests_total": 153, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function minFlips($s) {", "container": "Solution", "callable": "minFlips", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1889, "task_id": "minimum-space-wasted-from-packaging", "difficulty": "Hard", "problem_description": "You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.\n\nThe package sizes are given as an integer array packages, where packages[i] is the size of the i^th package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the j^th supplier produces.\n\nYou want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.\n\n- For example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.\n\nReturn the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: packages = [2,3,5], boxes = [[4,8],[2,8]]\nOutput: 6\nExplanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.\nThe total waste is (4-2) + (4-3) + (8-5) = 6.\n\nExample 2:\n\nInput: packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]\nOutput: -1\nExplanation: There is no box that the package of size 5 can fit in.\n\nExample 3:\n\nInput: packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]\nOutput: 9\nExplanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.\nThe total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.\n\nConstraints:\n\n- n == packages.length\n- m == boxes.length\n- 1 <= n <= 10^5\n- 1 <= m <= 10^5\n- 1 <= packages[i] <= 10^5\n- 1 <= boxes[j].length <= 10^5\n- 1 <= boxes[j][k] <= 10^5\n- sum(boxes[j].length) <= 10^5\n- The elements in boxes[j] are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(packages = [10, 20, 30],boxes = [[10], [20], [30], [40]]) == 30\n assert candidate(packages = [100000],boxes = [[100000]]) == 0\n assert candidate(packages = [10, 20, 30],boxes = [[10, 20, 30], [15, 25, 35]]) == 0\n assert candidate(packages = [1, 100000],boxes = [[1], [100000]]) == 99999\n assert candidate(packages = [2, 3, 5],boxes = [[4, 8], [2, 8]]) == 6\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 45\n assert candidate(packages = [3, 5, 8, 10, 11, 12],boxes = [[12], [11, 9], [10, 5, 14]]) == 9\n assert candidate(packages = [1, 2, 3, 4, 5],boxes = [[5, 5, 5, 5, 5]]) == 10\n assert candidate(packages = [1, 3, 5, 7, 9],boxes = [[2, 4, 6, 8, 10]]) == 5\n assert candidate(packages = [5, 5, 5, 5],boxes = [[5, 5, 5, 5]]) == 0\n assert candidate(packages = [2, 3, 5],boxes = [[1, 4], [2, 3], [3, 4]]) == -1\n assert candidate(packages = [10000, 20000, 30000, 40000, 50000],boxes = [[20000, 30000, 50000], [10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 15, 25, 35, 45]]) == 0\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 5, 9, 13, 17], [3, 7, 11, 15, 19]]) == 10\n assert candidate(packages = [50000, 50000, 50000, 50000, 50000],boxes = [[50000, 50000], [100000], [25000, 75000]]) == 0\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 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]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],boxes = [[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], [5, 10, 15, 20, 25, 30]]) == 10\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[5, 15, 25, 35, 45, 55, 65, 75, 85, 95], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]]) == 0\n assert candidate(packages = [99999, 99998, 99997, 99996, 99995],boxes = [[100000], [99999], [99998], [99997], [99996], [99995]]) == 10\n assert candidate(packages = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],boxes = [[4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], [3, 7, 11, 15, 19, 23, 27, 31]]) == 9\n assert candidate(packages = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900],boxes = [[500, 600, 700, 800, 900, 1000], [900, 1000, 1100, 1200, 1300, 1400, 1500], [100, 200, 300, 400, 500, 600, 700, 800, 900]]) == 99\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],boxes = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29], [15, 14, 13, 12, 11, 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], [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]]) == 0\n assert candidate(packages = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],boxes = [[3, 6, 9, 12, 15, 18, 21], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]]) == 10\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30], [1, 5, 9, 13, 17, 21, 25, 29]]) == 14\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 0\n assert candidate(packages = [5, 10, 15, 20, 25],boxes = [[5, 10, 15, 20, 25], [1, 2, 3, 4, 5], [26, 27, 28, 29, 30]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]]) == 0\n assert candidate(packages = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],boxes = [[5, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60]]) == 145\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1], [2], [3, 4, 5]]) == 0\n assert candidate(packages = [100000, 90000, 80000, 70000, 60000],boxes = [[95000, 100000], [85000, 90000, 95000], [75000, 80000, 85000], [65000, 70000, 75000, 80000]]) == 80000\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 11, 12], [9, 8, 7, 6, 5, 4, 3, 2, 1], [15, 20, 25, 30, 35]]) == 45\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1], [2], [1, 2, 3, 4, 5]]) == 0\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1], [2], [3]]) == 0\n assert candidate(packages = [100000],boxes = [[99999, 99998, 99997, 99996, 99995]]) == -1\n assert candidate(packages = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[5, 10, 15], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]) == 0\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15]]) == 0\n assert candidate(packages = [25000, 50000, 75000, 100000],boxes = [[12500, 37500, 62500, 87500], [10000, 40000, 70000, 100000], [50000, 50000, 50000, 50000]]) == 60000\n assert candidate(packages = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],boxes = [[100], [200], [300], [400], [500], [600], [700], [800], [900], [1000]]) == 4500\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]]) == 0\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1], [2], [3]]) == 0\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [11, 12, 13, 14, 15], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],boxes = [[1, 3, 5, 7, 9, 11, 13, 15], [2, 4, 6, 8, 10, 12, 14], [16]]) == 7\n assert candidate(packages = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950],boxes = [[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], [50, 150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]]) == 0\n assert candidate(packages = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10], [9, 10], [8, 9, 10], [7, 8, 9, 10], [6, 7, 8, 9, 10], [5, 6, 7, 8, 9, 10]]) == 10\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[1, 2, 3, 4, 5], [101, 102, 103, 104, 105], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]]) == 0\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 0\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[15, 25, 35, 45, 55, 65, 75, 85, 95, 105], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]]) == 0\n assert candidate(packages = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],boxes = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95], [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]]) == 0\n assert candidate(packages = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],boxes = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [3, 6, 9, 12, 15, 18], [4, 8, 12, 16, 20]]) == 0\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], [50, 60, 70, 80, 90, 100, 110, 120, 130, 140]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 0\n assert candidate(packages = [1, 10, 100, 1000, 10000],boxes = [[5, 50, 500, 5000, 50000], [1, 2, 3, 4, 5], [9999, 99999]]) == 44444\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[5, 15, 25, 35, 45, 55, 65, 75, 85, 95], [10, 30, 50, 70, 90, 110], [20, 40, 60, 80, 100, 120]]) == 50\n assert candidate(packages = [1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95], [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]]) == 14\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],boxes = [[1, 3, 5, 7, 9, 11, 13, 15], [2, 4, 6, 8, 10, 12, 14], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 0\n assert candidate(packages = [50000, 50000, 50000, 50000, 50000],boxes = [[49999], [50000], [50001]]) == 0\n assert candidate(packages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],boxes = [[5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [50, 50, 50, 50, 50, 50, 50, 50, 50, 50], [100, 100, 100, 100, 100, 100, 100, 100, 100, 100], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 450\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],boxes = [[20, 40], [10, 30], [5, 15, 25, 35]]) == 90\n assert candidate(packages = [50000, 40000, 30000, 20000, 10000],boxes = [[10000, 20000, 30000, 40000, 50000], [15000, 25000, 35000, 45000, 55000], [55000]]) == 0\n assert candidate(packages = [50, 60, 70, 80, 90, 100],boxes = [[40, 90], [50, 60, 100], [80, 95, 110]]) == 60\n assert candidate(packages = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],boxes = [[100], [256, 512, 1024], [2, 4, 8, 16, 32, 64, 128]]) == 1793\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 10, 10], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 10, 10, 10, 10, 10, 10, 10, 10, 10], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]]) == 5\n assert candidate(packages = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],boxes = [[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], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]]) == 0\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 10\n assert candidate(packages = [10, 20, 30, 40, 50],boxes = [[5, 15, 25, 35, 45], [6, 16, 26, 36, 46], [7, 17, 27, 37, 47]]) == -1\n assert candidate(packages = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],boxes = [[1, 5, 9, 13, 17], [3, 7, 11, 15, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 10\n assert candidate(packages = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],boxes = [[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]]) == 0\n assert candidate(packages = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],boxes = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]]) == 0\n assert candidate(packages = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],boxes = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40], [1, 9, 17, 25, 33], [5, 10, 15, 20, 25, 30, 35]]) == 10\n assert candidate(packages = [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],boxes = [[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]]) == 25\n assert candidate(packages = [10000, 20000, 30000, 40000, 50000],boxes = [[5000, 15000, 25000, 35000, 45000, 55000], [10000, 20000, 30000, 40000, 50000]]) == 0\n assert candidate(packages = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],boxes = [[500, 600, 700, 800, 900, 1000], [900, 1000, 1100, 1200, 1300, 1400, 1500]]) == 1000\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[2, 3, 5, 7, 11], [1, 4, 9], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 9\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 20, 30], [5, 10, 15, 20, 25, 30], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]]) == 5\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[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(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [5, 10, 15, 20, 25], [3, 6, 9, 12, 15]]) == 0\n assert candidate(packages = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],boxes = [[1000, 2000], [500, 1500], [300, 700, 1100]]) == 1500\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],boxes = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == 0\n assert candidate(packages = [50000, 50000, 50000, 50000, 50000],boxes = [[50000], [50001], [50002], [50003], [50004]]) == 0\n assert candidate(packages = [1000, 2000, 3000, 4000, 5000],boxes = [[1000, 2000, 3000, 4000, 5000], [1500, 2500, 3500, 4500, 5500], [900, 1900, 2900, 3900, 4900]]) == 0\n assert candidate(packages = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],boxes = [[10, 20], [5, 15], [3, 7, 12]]) == 18\n", "comparison": "exact"}, "public_tests": ["[2,3,5]\n[[4,8],[2,8]]", "[2,3,5]\n[[1,4],[2,3],[3,4]]", "[3,5,8,10,11,12]\n[[12],[11,9],[10,5,14]]"], "hints": ["Given a fixed size box, is there a way to quickly query which packages (i.e., count and sizes) should end up in that box size?", "Do we have to order the boxes a certain way to allow us to answer the query quickly?"], "metadata": {"canonical_parameter_names": ["packages", "boxes"], "leetcode_dataset_entry_point": "Solution().minWastedSpace", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:03+00:00", "tests_total": 93, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "binary-search", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minWastedSpace($packages, $boxes) {", "container": "Solution", "callable": "minWastedSpace", "parameters": [{"name": "packages", "type": "Integer[]"}, {"name": "boxes", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1893, "task_id": "check-if-all-the-integers-in-a-range-are-covered", "difficulty": "Easy", "problem_description": "You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [start_i, end_i] represents an inclusive interval between start_i and end_i.\n\nReturn true if each integer in the inclusive range [left, right] is covered by at least one interval in ranges. Return false otherwise.\n\nAn integer x is covered by an interval ranges[i] = [start_i, end_i] if start_i <= x <= end_i.\n\nExample 1:\n\nInput: ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5\nOutput: true\nExplanation: Every integer between 2 and 5 is covered:\n- 2 is covered by the first range.\n- 3 and 4 are covered by the second range.\n- 5 is covered by the third range.\n\nExample 2:\n\nInput: ranges = [[1,10],[10,20]], left = 21, right = 21\nOutput: false\nExplanation: 21 is not covered by any range.\n\nConstraints:\n\n- 1 <= ranges.length <= 50\n- 1 <= start_i <= end_i <= 50\n- 1 <= left <= right <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(ranges = [[5, 7], [1, 3]],left = 1,right = 7) == False\n assert candidate(ranges = [[5, 10], [15, 20]],left = 10,right = 15) == False\n assert candidate(ranges = [[1, 1], [2, 2], [3, 3]],left = 1,right = 3) == True\n assert candidate(ranges = [[1, 3], [3, 5], [5, 7]],left = 3,right = 5) == True\n assert candidate(ranges = [[10, 20], [21, 30]],left = 15,right = 25) == True\n assert candidate(ranges = [[1, 3], [5, 7]],left = 2,right = 6) == False\n assert candidate(ranges = [[1, 3], [5, 7], [9, 11]],left = 4,right = 6) == False\n assert candidate(ranges = [[5, 10], [15, 20]],left = 8,right = 12) == False\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6]],left = 2,right = 5) == True\n assert candidate(ranges = [[1, 2], [4, 5]],left = 3,right = 4) == False\n assert candidate(ranges = [[1, 10], [10, 20]],left = 21,right = 21) == False\n assert candidate(ranges = [[1, 5], [6, 10]],left = 1,right = 10) == True\n assert candidate(ranges = [[1, 50]],left = 1,right = 50) == True\n assert candidate(ranges = [[5, 10], [10, 15]],left = 10,right = 10) == True\n assert candidate(ranges = [[5, 10], [11, 16], [17, 22], [23, 28]],left = 8,right = 25) == True\n assert candidate(ranges = [[3, 6], [7, 10], [11, 14], [15, 18]],left = 5,right = 17) == True\n assert candidate(ranges = [[1, 10], [15, 25], [30, 40]],left = 11,right = 14) == False\n assert candidate(ranges = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],left = 5,right = 25) == True\n assert candidate(ranges = [[5, 15], [10, 20], [25, 35]],left = 7,right = 28) == False\n assert candidate(ranges = [[1, 2], [3, 5], [6, 8], [9, 11], [12, 14]],left = 1,right = 14) == True\n assert candidate(ranges = [[2, 5], [6, 9], [10, 15], [16, 20]],left = 3,right = 19) == True\n assert candidate(ranges = [[1, 3], [6, 8], [11, 13], [16, 18]],left = 5,right = 17) == False\n assert candidate(ranges = [[2, 6], [8, 12], [14, 18], [20, 24], [26, 30]],left = 3,right = 28) == False\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],left = 1,right = 12) == True\n assert candidate(ranges = [[5, 5], [10, 10], [15, 15], [20, 20]],left = 5,right = 20) == False\n assert candidate(ranges = [[1, 50]],left = 1,right = 50) == True\n assert candidate(ranges = [[10, 20], [5, 15], [25, 35]],left = 12,right = 28) == False\n assert candidate(ranges = [[5, 7], [8, 10], [15, 20], [25, 30]],left = 7,right = 27) == False\n assert candidate(ranges = [[1, 4], [6, 9], [11, 14], [16, 19], [21, 24], [26, 29]],left = 1,right = 29) == False\n assert candidate(ranges = [[3, 6], [8, 11], [13, 16]],left = 4,right = 15) == False\n assert candidate(ranges = [[10, 15], [16, 20], [21, 25], [26, 30]],left = 12,right = 28) == True\n assert candidate(ranges = [[1, 5], [5, 10], [10, 15], [15, 20]],left = 6,right = 14) == True\n assert candidate(ranges = [[5, 8], [10, 13], [15, 18], [20, 23], [25, 28], [30, 33]],left = 3,right = 31) == False\n assert candidate(ranges = [[5, 10], [15, 25], [30, 35]],left = 25,right = 30) == False\n assert candidate(ranges = [[1, 20], [21, 40], [41, 50]],left = 1,right = 50) == True\n assert candidate(ranges = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],left = 1,right = 10) == True\n assert candidate(ranges = [[3, 7], [9, 13], [15, 19], [21, 25], [27, 31]],left = 6,right = 30) == False\n assert candidate(ranges = [[10, 15], [15, 20], [20, 25]],left = 12,right = 23) == True\n assert candidate(ranges = [[5, 5], [6, 6], [7, 7], [8, 8]],left = 5,right = 8) == True\n assert candidate(ranges = [[5, 8], [10, 15], [18, 23], [25, 30]],left = 8,right = 27) == False\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],left = 1,right = 8) == True\n assert candidate(ranges = [[1, 2], [4, 6], [8, 10], [12, 14]],left = 3,right = 13) == False\n assert candidate(ranges = [[1, 3], [4, 6], [7, 9], [10, 12]],left = 1,right = 12) == True\n assert candidate(ranges = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],left = 1,right = 5) == True\n assert candidate(ranges = [[3, 7], [10, 14], [17, 21]],left = 5,right = 19) == False\n assert candidate(ranges = [[1, 2], [4, 8], [10, 15], [16, 20], [22, 25]],left = 1,right = 25) == False\n assert candidate(ranges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],left = 2,right = 5) == True\n assert candidate(ranges = [[2, 5], [7, 10], [12, 15], [17, 20], [22, 25], [27, 30]],left = 4,right = 29) == False\n assert candidate(ranges = [[2, 4], [5, 7], [8, 10], [11, 13]],left = 2,right = 13) == True\n assert candidate(ranges = [[1, 2], [4, 5], [7, 8], [10, 11]],left = 3,right = 9) == False\n assert candidate(ranges = [[10, 20], [21, 30], [31, 40], [41, 50]],left = 15,right = 45) == True\n assert candidate(ranges = [[10, 12], [15, 17], [20, 22]],left = 10,right = 22) == False\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],left = 1,right = 10) == True\n assert candidate(ranges = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15]],left = 1,right = 15) == True\n assert candidate(ranges = [[5, 7], [7, 9], [9, 11], [11, 13]],left = 6,right = 12) == True\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30]],left = 12,right = 17) == False\n assert candidate(ranges = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30]],left = 1,right = 30) == True\n assert candidate(ranges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],left = 1,right = 6) == True\n assert candidate(ranges = [[3, 6], [8, 12], [15, 20], [22, 25], [27, 30]],left = 5,right = 28) == False\n assert candidate(ranges = [[5, 8], [10, 12], [15, 18]],left = 6,right = 17) == False\n assert candidate(ranges = [[1, 10], [12, 20], [22, 30]],left = 5,right = 25) == False\n assert candidate(ranges = [[5, 10], [12, 15], [16, 20], [22, 25]],left = 11,right = 21) == False\n assert candidate(ranges = [[1, 10], [15, 25], [30, 40]],left = 5,right = 35) == False\n assert candidate(ranges = [[1, 5], [10, 15], [20, 25], [30, 35]],left = 5,right = 30) == False\n assert candidate(ranges = [[3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13]],left = 3,right = 13) == False\n assert candidate(ranges = [[1, 10], [11, 20], [21, 30], [31, 40]],left = 5,right = 35) == True\n assert candidate(ranges = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],left = 25,right = 45) == True\n assert candidate(ranges = [[1, 5], [6, 10], [11, 15], [16, 20]],left = 3,right = 19) == True\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30], [35, 40]],left = 2,right = 38) == False\n assert candidate(ranges = [[2, 4], [6, 8], [10, 12], [14, 16], [18, 20], [22, 24]],left = 1,right = 24) == False\n assert candidate(ranges = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23]],left = 1,right = 23) == False\n assert candidate(ranges = [[2, 4], [5, 7], [8, 10], [11, 13], [14, 16]],left = 3,right = 15) == True\n assert candidate(ranges = [[2, 4], [5, 8], [9, 11], [12, 15], [16, 18], [19, 22]],left = 2,right = 22) == True\n assert candidate(ranges = [[2, 4], [6, 8], [10, 12], [14, 16], [18, 20]],left = 3,right = 19) == False\n assert candidate(ranges = [[10, 20], [20, 30], [30, 40]],left = 5,right = 45) == False\n assert candidate(ranges = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]],left = 1,right = 20) == False\n assert candidate(ranges = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],left = 25,right = 45) == True\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30]],left = 3,right = 28) == False\n assert candidate(ranges = [[3, 7], [8, 12], [13, 17], [18, 22]],left = 5,right = 20) == True\n assert candidate(ranges = [[1, 10], [20, 30], [40, 50]],left = 15,right = 35) == False\n assert candidate(ranges = [[1, 2], [4, 5], [7, 8], [10, 11]],left = 1,right = 11) == False\n assert candidate(ranges = [[2, 4], [7, 9], [12, 14], [17, 19]],left = 4,right = 19) == False\n assert candidate(ranges = [[1, 2], [2, 3], [3, 4], [4, 5]],left = 1,right = 5) == True\n assert candidate(ranges = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],left = 1,right = 25) == True\n assert candidate(ranges = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],left = 5,right = 45) == True\n assert candidate(ranges = [[1, 3], [4, 7], [8, 10], [11, 15], [16, 20]],left = 5,right = 15) == True\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],left = 1,right = 10) == True\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30], [35, 40]],left = 25,right = 35) == False\n assert candidate(ranges = [[5, 10], [11, 20], [21, 30]],left = 7,right = 29) == True\n assert candidate(ranges = [[1, 25], [26, 50]],left = 1,right = 50) == True\n assert candidate(ranges = [[3, 5], [8, 10], [13, 15], [18, 20]],left = 1,right = 20) == False\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30]],left = 1,right = 30) == False\n assert candidate(ranges = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15]],left = 2,right = 14) == True\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],left = 5,right = 10) == True\n assert candidate(ranges = [[2, 5], [6, 9], [10, 14]],left = 3,right = 13) == True\n assert candidate(ranges = [[1, 10], [15, 25], [30, 40]],left = 5,right = 20) == False\n assert candidate(ranges = [[1, 5], [6, 10], [11, 15], [16, 20]],left = 1,right = 20) == True\n assert candidate(ranges = [[1, 3], [4, 6], [7, 9]],left = 1,right = 9) == True\n assert candidate(ranges = [[2, 4], [6, 8], [10, 12], [14, 16], [18, 20]],left = 1,right = 20) == False\n assert candidate(ranges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],left = 2,right = 9) == True\n assert candidate(ranges = [[2, 5], [7, 10], [12, 15], [17, 20]],left = 3,right = 18) == False\n assert candidate(ranges = [[5, 9], [10, 14], [15, 19], [20, 24]],left = 8,right = 22) == True\n assert candidate(ranges = [[1, 4], [5, 8], [9, 12], [13, 16]],left = 3,right = 15) == True\n assert candidate(ranges = [[1, 10], [10, 20], [20, 30], [30, 40]],left = 1,right = 40) == True\n assert candidate(ranges = [[5, 10], [15, 20], [25, 30], [35, 40]],left = 10,right = 35) == False\n", "comparison": "exact"}, "public_tests": ["[[1,2],[3,4],[5,6]]\n2\n5", "[[1,10],[10,20]]\n21\n21"], "hints": ["Iterate over every integer point in the range [left, right].", "For each of these points check if it is included in one of the ranges."], "metadata": {"canonical_parameter_names": ["ranges", "left", "right"], "leetcode_dataset_entry_point": "Solution().isCovered", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:08+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function isCovered($ranges, $left, $right) {", "container": "Solution", "callable": "isCovered", "parameters": [{"name": "ranges", "type": "Integer[][]"}, {"name": "left", "type": "Integer"}, {"name": "right", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1894, "task_id": "find-the-student-that-will-replace-the-chalk", "difficulty": "Medium", "problem_description": "There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.\n\nYou are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk.\n\nReturn the index of the student that will replace the chalk pieces.\n\nExample 1:\n\nInput: chalk = [5,1,5], k = 22\nOutput: 0\nExplanation: The students go in turns as follows:\n- Student number 0 uses 5 chalk, so k = 17.\n- Student number 1 uses 1 chalk, so k = 16.\n- Student number 2 uses 5 chalk, so k = 11.\n- Student number 0 uses 5 chalk, so k = 6.\n- Student number 1 uses 1 chalk, so k = 5.\n- Student number 2 uses 5 chalk, so k = 0.\nStudent number 0 does not have enough chalk, so they will have to replace it.\n\nExample 2:\n\nInput: chalk = [3,4,1,2], k = 25\nOutput: 1\nExplanation: The students go in turns as follows:\n- Student number 0 uses 3 chalk so k = 22.\n- Student number 1 uses 4 chalk so k = 18.\n- Student number 2 uses 1 chalk so k = 17.\n- Student number 3 uses 2 chalk so k = 15.\n- Student number 0 uses 3 chalk so k = 12.\n- Student number 1 uses 4 chalk so k = 8.\n- Student number 2 uses 1 chalk so k = 7.\n- Student number 3 uses 2 chalk so k = 5.\n- Student number 0 uses 3 chalk so k = 2.\nStudent number 1 does not have enough chalk, so they will have to replace it.\n\nConstraints:\n\n- chalk.length == n\n- 1 <= n <= 10^5\n- 1 <= chalk[i] <= 10^5\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(chalk = [1, 2, 3, 4, 5],k = 15) == 0\n assert candidate(chalk = [1],k = 1000000000) == 0\n assert candidate(chalk = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 999999999) == 9\n assert candidate(chalk = [10, 10, 10],k = 100) == 1\n assert candidate(chalk = [100000],k = 1000000000) == 0\n assert candidate(chalk = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1000000000) == 0\n assert candidate(chalk = [3, 4, 1, 2],k = 25) == 1\n assert candidate(chalk = [5, 1, 5],k = 22) == 0\n assert candidate(chalk = [5, 1, 5],k = 1000000000) == 2\n assert candidate(chalk = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],k = 1000000000) == 6\n assert candidate(chalk = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 123456789) == 1\n assert candidate(chalk = [5, 8, 12, 3, 7],k = 500000000) == 1\n assert candidate(chalk = [7, 3, 2, 8, 6, 4],k = 987654321) == 4\n assert candidate(chalk = [1, 10, 100, 1000, 10000, 100000],k = 123456789) == 5\n assert candidate(chalk = [2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100000000) == 8\n assert candidate(chalk = [10, 20, 30, 40, 50],k = 123456789) == 2\n assert candidate(chalk = [100, 200, 300, 400, 500],k = 999999999) == 3\n assert candidate(chalk = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 123456789) == 9\n assert candidate(chalk = [5, 1, 5, 2, 8],k = 1000000000) == 4\n assert candidate(chalk = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000000000) == 9\n assert candidate(chalk = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 999999998) == 1\n assert candidate(chalk = [7, 14, 21, 28, 35],k = 123456789) == 4\n assert candidate(chalk = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 999999997) == 2\n assert candidate(chalk = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],k = 1000000000) == 0\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 543210) == 7\n assert candidate(chalk = [5, 1, 5, 2, 6],k = 1000000000) == 4\n assert candidate(chalk = [5, 8, 3, 7, 2],k = 500000000) == 0\n assert candidate(chalk = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 8675309) == 6\n assert candidate(chalk = [5, 3, 7, 11],k = 50) == 3\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 897654321) == 12\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 500000000) == 2\n assert candidate(chalk = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 900000000) == 5\n assert candidate(chalk = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1000000000) == 5\n assert candidate(chalk = [10, 20, 30, 40, 50],k = 999999999) == 3\n assert candidate(chalk = [100000, 100000, 100000, 100000, 100000],k = 950000000) == 0\n assert candidate(chalk = [1, 1, 1, 1, 1, 1, 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 = 999999999) == 9\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1000000000) == 8\n assert candidate(chalk = [2, 4, 6, 8, 10],k = 999999999) == 2\n assert candidate(chalk = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 987654321) == 1\n assert candidate(chalk = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 999999999) == 7\n assert candidate(chalk = [5, 8, 12, 3, 6],k = 1000000000) == 2\n assert candidate(chalk = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 800000000) == 8\n assert candidate(chalk = [99999, 99998, 99997, 99996, 99995],k = 1000000000) == 0\n assert candidate(chalk = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 987654321) == 2\n assert candidate(chalk = [1, 10, 100, 1000, 10000, 100000],k = 999999999) == 3\n assert candidate(chalk = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],k = 123456789) == 8\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 987654321) == 18\n assert candidate(chalk = [100, 200, 300, 400, 500],k = 1000000000) == 4\n assert candidate(chalk = [12345, 67890, 13579, 24680, 97531],k = 987654321) == 4\n assert candidate(chalk = [50000, 50000, 50000, 50000, 50000],k = 1000000000) == 0\n assert candidate(chalk = [3, 6, 1, 8, 4, 7],k = 999999999) == 3\n assert candidate(chalk = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100000000) == 9\n assert candidate(chalk = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 543210987) == 8\n assert candidate(chalk = [10, 15, 20, 25, 30],k = 123456789) == 4\n assert candidate(chalk = [3, 4, 1, 2, 5, 7, 8, 9, 10, 11],k = 987654321) == 5\n assert candidate(chalk = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 500000000) == 0\n assert candidate(chalk = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 456789123) == 7\n assert candidate(chalk = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 999999999) == 8\n assert candidate(chalk = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 1000000000) == 2\n assert candidate(chalk = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 1000000000) == 0\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 876543210) == 12\n assert candidate(chalk = [100000, 100000, 100000, 100000, 100000],k = 999999999) == 4\n assert candidate(chalk = [5000, 10000, 15000, 20000, 25000],k = 500000000) == 4\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 500000000) == 2\n assert candidate(chalk = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 123456789) == 11\n assert candidate(chalk = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995, 5],k = 1000000000) == 0\n", "comparison": "exact"}, "public_tests": ["[5,1,5]\n22", "[3,4,1,2]\n25"], "hints": ["Subtract the sum of chalk from k until k is less than the sum of chalk.", "Now iterate over the array. If chalk[i] is less than k, this is the answer. Otherwise, subtract chalk[i] from k and continue."], "metadata": {"canonical_parameter_names": ["chalk", "k"], "leetcode_dataset_entry_point": "Solution().chalkReplacer", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:10+00:00", "tests_total": 92, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "binary-search", "simulation", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function chalkReplacer($chalk, $k) {", "container": "Solution", "callable": "chalkReplacer", "parameters": [{"name": "chalk", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1895, "task_id": "largest-magic-square", "difficulty": "Medium", "problem_description": "A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square.\n\nGiven an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid.\n\nExample 1:\n\nInput: grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]\nOutput: 3\nExplanation: The largest magic square has a size of 3.\nEvery row sum, column sum, and diagonal sum of this magic square is equal to 12.\n- Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12\n- Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12\n- Diagonal sums: 5+4+3 = 6+4+2 = 12\n\nExample 2:\n\nInput: grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]\nOutput: 2\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 50\n- 1 <= grid[i][j] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[10, 20], [15, 25]]) == 1\n assert candidate(grid = [[7, 1, 4, 5, 6], [2, 5, 1, 6, 4], [1, 5, 4, 3, 2], [1, 2, 7, 3, 4]]) == 3\n assert candidate(grid = [[6, 3, 2, 8, 1, 9, 3, 2], [4, 7, 5, 4, 5, 3, 4, 7], [8, 4, 6, 8, 7, 2, 8, 1], [2, 9, 1, 5, 8, 7, 7, 3], [5, 4, 3, 1, 9, 4, 6, 3], [2, 8, 4, 9, 7, 8, 4, 1], [7, 8, 4, 5, 3, 9, 6, 4], [6, 3, 5, 9, 8, 7, 1, 9]]) == 1\n assert candidate(grid = [[8]]) == 1\n assert candidate(grid = [[16, 23, 17], [78, 32, 21], [17, 26, 79]]) == 1\n assert candidate(grid = [[5, 1, 3, 1], [9, 3, 3, 1], [1, 3, 3, 8]]) == 2\n assert candidate(grid = [[4, 3, 8, 4], [9, 5, 1, 9], [2, 7, 6, 2]]) == 3\n assert candidate(grid = [[16, 23, 17], [78, 32, 21], [17, 26, 78]]) == 1\n assert candidate(grid = [[1, 2], [3, 4]]) == 1\n assert candidate(grid = [[4, 9, 2], [3, 5, 7], [8, 1, 6]]) == 3\n assert candidate(grid = [[8, 1, 6, 13, 10], [3, 5, 7, 14, 11], [4, 9, 2, 15, 12], [15, 17, 24, 4, 5], [16, 23, 19, 6, 18]]) == 3\n assert candidate(grid = [[47, 36, 19, 73], [60, 22, 43, 19], [71, 23, 44, 39], [82, 24, 45, 40]]) == 1\n assert candidate(grid = [[2, 15, 13, 9], [16, 4, 6, 12], [9, 14, 7, 8], [10, 5, 11, 3]]) == 1\n assert candidate(grid = [[1, 16, 15, 4, 12], [8, 9, 10, 11, 14], [17, 2, 13, 14, 3], [12, 7, 6, 5, 18], [13, 8, 1, 12, 17]]) == 1\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 1\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\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]]) == 1\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4, 9, 2], [3, 5, 7, 8, 1, 6, 3, 5, 7], [4, 9, 2, 3, 5, 7, 4, 9, 2], [3, 5, 7, 4, 9, 2, 3, 5, 7], [8, 1, 6, 4, 9, 2, 3, 5, 7], [3, 5, 7, 8, 1, 6, 3, 5, 7], [4, 9, 2, 3, 5, 7, 8, 1, 6], [3, 5, 7, 4, 9, 2, 8, 1, 6], [4, 9, 2, 3, 5, 7, 3, 5, 7]]) == 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]]) == 1\n assert candidate(grid = [[3, 8, 4, 6], [6, 5, 7, 10], [5, 7, 8, 9], [8, 4, 5, 10]]) == 1\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 3, 8, 1, 6, 7, 2, 9, 5], [9, 5, 1, 8, 4, 2, 7, 6, 3], [7, 9, 4, 8, 5, 2, 6, 3, 1], [3, 6, 7, 2, 9, 5, 8, 1, 4], [5, 8, 1, 9, 3, 6, 4, 7, 2], [2, 4, 6, 3, 1, 8, 5, 9, 7], [8, 7, 5, 6, 4, 9, 1, 2, 3], [6, 1, 9, 7, 2, 3, 5, 8, 4]]) == 1\n assert candidate(grid = [[5, 15, 25, 35, 45], [10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65]]) == 1\n assert candidate(grid = [[3, 8, 1, 2, 7], [8, 1, 2, 7, 3], [1, 2, 7, 3, 8], [2, 7, 3, 8, 1], [7, 3, 8, 1, 2]]) == 1\n assert candidate(grid = [[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 21, 3], [11, 18, 25, 2, 9]]) == 5\n assert candidate(grid = [[37, 21, 15, 13, 31], [21, 37, 31, 15, 13], [15, 21, 37, 13, 31], [31, 13, 21, 37, 15], [13, 31, 15, 21, 37]]) == 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]]) == 5\n assert candidate(grid = [[16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1]]) == 4\n assert candidate(grid = [[20, 30, 25, 15, 10], [35, 25, 30, 20, 15], [20, 25, 30, 15, 35], [15, 30, 20, 25, 20], [10, 15, 25, 30, 20]]) == 1\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], [5, 4, 3, 2, 1, 9, 8, 7, 6], [4, 3, 2, 1, 9, 8, 7, 6, 5], [3, 2, 1, 9, 8, 7, 6, 5, 4], [2, 1, 9, 8, 7, 6, 5, 4, 3], [1, 9, 8, 7, 6, 5, 4, 3, 2]]) == 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]]) == 5\n assert candidate(grid = [[16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1]]) == 4\n assert candidate(grid = [[2, 7, 6, 9, 5], [9, 5, 1, 9, 7], [4, 3, 8, 4, 6], [1, 8, 3, 8, 2], [5, 4, 7, 5, 9]]) == 3\n assert candidate(grid = [[2, 7, 6], [9, 5, 1], [4, 3, 8], [15, 16, 17], [18, 19, 20]]) == 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]]) == 1\n assert candidate(grid = [[16, 23, 17], [78, 32, 21], [17, 23, 29]]) == 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]]) == 5\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\n assert candidate(grid = [[2, 7, 6, 1, 8], [9, 5, 1, 3, 4], [8, 1, 6, 7, 2], [4, 9, 2, 8, 5], [3, 4, 5, 9, 6]]) == 1\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == 1\n assert candidate(grid = [[3, 8, 4], [1, 6, 7], [6, 7, 2], [8, 1, 6], [7, 5, 3], [4, 9, 2]]) == 1\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4], [1, 6, 7, 8, 5, 4, 3], [6, 7, 2, 1, 3, 4, 5], [3, 5, 7, 4, 6, 8, 1], [5, 7, 4, 6, 8, 1, 3], [7, 4, 6, 8, 1, 3, 5], [4, 6, 8, 1, 3, 5, 7]]) == 1\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 7, 6, 3, 5, 9, 4, 8, 1], [4, 9, 2, 3, 5, 7, 8, 1, 6], [3, 5, 7, 4, 9, 2, 1, 6, 8], [8, 1, 6, 7, 2, 9, 4, 3, 5], [5, 4, 3, 6, 9, 2, 7, 8, 1], [6, 8, 1, 5, 3, 7, 2, 9, 4], [7, 6, 3, 1, 8, 4, 5, 2, 9]]) == 3\n assert candidate(grid = [[20, 9, 17, 12, 15, 14], [13, 18, 8, 11, 7, 10], [16, 21, 2, 14, 18, 12], [4, 19, 15, 22, 10, 6], [1, 12, 20, 17, 9, 23], [5, 24, 11, 23, 16, 4]]) == 1\n assert candidate(grid = [[3, 7, 5, 9, 11, 12], [10, 6, 14, 3, 13, 15], [4, 16, 1, 8, 17, 18], [9, 20, 12, 15, 5, 2], [13, 11, 19, 2, 6, 16], [17, 4, 22, 18, 10, 7]]) == 1\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [20, 30, 40, 50, 60], [30, 40, 50, 60, 70], [40, 50, 60, 70, 80]]) == 1\n assert candidate(grid = [[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 21, 3], [11, 18, 25, 2, 9]]) == 5\n assert candidate(grid = [[3, 5, 7, 9, 11], [6, 12, 4, 8, 2], [15, 1, 13, 3, 17], [10, 14, 5, 19, 16], [21, 25, 23, 20, 22]]) == 1\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4, 9, 2], [3, 5, 7, 8, 1, 6, 9, 2, 4], [4, 9, 2, 5, 8, 1, 6, 3, 7], [9, 2, 4, 7, 3, 5, 1, 6, 8], [1, 6, 8, 2, 4, 9, 3, 7, 5], [2, 4, 9, 6, 8, 3, 7, 5, 1], [7, 3, 5, 4, 9, 2, 8, 1, 6], [5, 8, 1, 9, 6, 4, 2, 7, 3], [6, 7, 3, 1, 2, 8, 5, 4, 9]]) == 3\n assert candidate(grid = [[2, 7, 6, 9, 5, 3], [9, 5, 1, 4, 1, 1], [4, 3, 8, 2, 4, 1], [8, 1, 6, 3, 5, 2], [3, 5, 7, 5, 3, 1], [6, 9, 2, 1, 7, 5]]) == 3\n assert candidate(grid = [[8, 1, 6, 7, 10, 12], [3, 5, 7, 8, 1, 11], [4, 9, 2, 13, 6, 7], [15, 14, 13, 12, 11, 10], [9, 8, 7, 6, 5, 4], [1, 2, 3, 4, 3, 2]]) == 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, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 6\n assert candidate(grid = [[4, 3, 8, 4], [9, 5, 1, 9], [2, 7, 6, 2], [6, 1, 8, 6], [7, 5, 3, 7]]) == 3\n assert candidate(grid = [[30, 5, 25], [5, 25, 30], [25, 30, 5], [5, 30, 25], [30, 25, 5], [25, 5, 30]]) == 1\n assert candidate(grid = [[35, 1, 6, 26, 19, 24], [3, 32, 7, 21, 23, 25], [31, 9, 2, 22, 27, 20], [8, 28, 33, 17, 10, 15], [30, 5, 34, 12, 14, 18], [4, 36, 29, 13, 16, 11]]) == 3\n assert candidate(grid = [[7, 12, 1, 14, 11, 2, 5], [13, 8, 10, 3, 4, 6, 15], [1, 14, 11, 2, 5, 7, 12], [13, 8, 10, 3, 4, 6, 15], [7, 12, 1, 14, 11, 2, 5], [13, 8, 10, 3, 4, 6, 15], [1, 14, 11, 2, 5, 7, 12]]) == 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, 100]]) == 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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 = [[25, 7, 2, 17], [14, 20, 16, 15], [13, 9, 6, 19], [18, 8, 23, 12]]) == 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]]) == 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]]) == 6\n assert candidate(grid = [[3, 10, 6, 7, 9], [1, 5, 7, 12, 8], [8, 11, 2, 5, 10], [9, 4, 3, 11, 13], [6, 7, 8, 10, 4]]) == 1\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]]) == 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]]) == 1\n assert candidate(grid = [[4, 9, 2, 16], [3, 5, 7, 12], [8, 1, 6, 10], [13, 14, 15, 11]]) == 3\n assert candidate(grid = [[3, 8, 4, 7, 2, 9], [2, 7, 3, 8, 4, 1], [1, 6, 2, 7, 3, 5], [5, 1, 6, 2, 7, 4], [4, 5, 1, 6, 2, 8], [8, 4, 5, 1, 6, 3]]) == 1\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4], [1, 6, 7, 8, 5, 3, 4], [6, 7, 2, 1, 9, 4, 3], [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, 1]]) == 1\n assert candidate(grid = [[3, 10, 4, 2, 15], [6, 8, 12, 14, 1], [9, 11, 5, 13, 7], [14, 1, 10, 6, 12], [16, 15, 9, 11, 5]]) == 1\n assert candidate(grid = [[8, 1, 6, 3, 5, 7, 4, 9, 2], [3, 5, 7, 4, 9, 2, 8, 1, 6], [4, 9, 2, 8, 1, 6, 3, 5, 7], [3, 5, 7, 4, 9, 2, 8, 1, 6], [4, 9, 2, 8, 1, 6, 3, 5, 7], [3, 5, 7, 4, 9, 2, 8, 1, 6], [4, 9, 2, 8, 1, 6, 3, 5, 7], [3, 5, 7, 4, 9, 2, 8, 1, 6], [4, 9, 2, 8, 1, 6, 3, 5, 7]]) == 3\n assert candidate(grid = [[4, 3, 8, 4], [9, 5, 1, 9], [2, 7, 6, 2], [6, 1, 8, 6]]) == 3\n assert candidate(grid = [[2, 7, 6, 9, 5, 1], [9, 5, 1, 4, 3, 8], [4, 3, 8, 2, 4, 9], [3, 8, 4, 8, 4, 3], [8, 1, 6, 6, 7, 2], [6, 7, 2, 9, 5, 1]]) == 3\n assert candidate(grid = [[3, 8, 4, 8, 4], [1, 1, 6, 7, 2], [2, 9, 6, 2, 7], [8, 2, 9, 1, 8], [4, 8, 9, 2, 8]]) == 1\n assert candidate(grid = [[47, 38, 29, 20, 11, 2], [46, 37, 30, 21, 12, 3], [45, 36, 31, 22, 13, 4], [44, 35, 32, 23, 14, 5], [43, 34, 33, 24, 15, 6], [42, 39, 40, 25, 16, 7]]) == 1\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]]) == 1\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 1, 4, 3, 5], [3, 5, 1, 4, 2], [4, 3, 5, 2, 1]]) == 1\n assert candidate(grid = [[15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15]]) == 4\n assert candidate(grid = [[2, 7, 6, 1, 8, 1], [8, 1, 6, 7, 2, 8], [6, 7, 2, 8, 1, 6], [1, 8, 1, 6, 7, 2], [8, 1, 6, 7, 2, 8], [6, 7, 2, 8, 1, 6]]) == 1\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 4\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]]) == 1\n assert candidate(grid = [[10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50], [25, 35, 45, 55], [30, 40, 50, 60]]) == 1\n", "comparison": "exact"}, "public_tests": ["[[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]", "[[5,1,3,1],[9,3,3,1],[1,3,3,8]]"], "hints": ["Check all squares in the matrix and find the largest one."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().largestMagicSquare", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:13+00:00", "tests_total": 80, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function largestMagicSquare($grid) {", "container": "Solution", "callable": "largestMagicSquare", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1896, "task_id": "minimum-cost-to-change-the-final-value-of-expression", "difficulty": "Hard", "problem_description": "You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.\n\n- For example, \"()1|1\" and \"(1)&()\" are not valid while \"1\", \"(((1))|(0))\", and \"1|(0&(1))\" are valid expressions.\n\nReturn the minimum cost to change the final value of the expression.\n\n- For example, if expression = \"1|1|(0&0)&1\", its value is 1|1|(0&0)&1 = 1|1|0&1 = 1|0&1 = 1&1 = 1. We want to apply operations so that the new expression evaluates to 0.\n\nThe cost of changing the final value of an expression is the number of operations performed on the expression. The types of operations are described as follows:\n\n- Turn a '1' into a '0'.\n- Turn a '0' into a '1'.\n- Turn a '&' into a '|'.\n- Turn a '|' into a '&'.\n\nNote: '&' does not take precedence over '|' in the order of calculation. Evaluate parentheses first, then in left-to-right order.\n\nExample 1:\n\nInput: expression = \"1&(0|1)\"\nOutput: 1\nExplanation: We can turn \"1&(0|1)\" into \"1&(0&1)\" by changing the '|' to a '&' using 1 operation.\nThe new expression evaluates to 0.\n\nExample 2:\n\nInput: expression = \"(0&0)&(0&0&0)\"\nOutput: 3\nExplanation: We can turn \"(0&0)&(0&0&0)\" into \"(0|1)|(0&0&0)\" using 3 operations.\nThe new expression evaluates to 1.\n\nExample 3:\n\nInput: expression = \"(0|(1|0&1))\"\nOutput: 1\nExplanation: We can turn \"(0|(1|0&1))\" into \"(0|(0|0&1))\" using 1 operation.\nThe new expression evaluates to 0.\n\nConstraints:\n\n- 1 <= expression.length <= 10^5\n- expression only contains '1','0','&','|','(', and ')'\n- All parentheses are properly matched.\n- There will be no empty parentheses (i.e: \"()\" is not a substring of expression).\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(expression = \"(1&(0|1&(0|1)))\") == 1\n assert candidate(expression = \"(0&1&1)|(0|1)\") == 1\n assert candidate(expression = \"(1&1)|(0&0)\") == 1\n assert candidate(expression = \"(1&((0&0)|(1|1)))\") == 1\n assert candidate(expression = \"1&(1&(1&(1&1)))\") == 1\n assert candidate(expression = \"((1|1)&(0|0))\") == 1\n assert candidate(expression = \"1&(0|1)\") == 1\n assert candidate(expression = \"((1&1)|(0&0))\") == 1\n assert candidate(expression = \"(1&1&1)|(1|1|1)\") == 2\n assert candidate(expression = \"1|1|0&1\") == 1\n assert candidate(expression = \"(0&0)|((1&1)|(0&1))\") == 1\n assert candidate(expression = \"(1&((1&1)&(1&1)))\") == 1\n assert candidate(expression = \"((1&0)|(1&1))\") == 1\n assert candidate(expression = \"(0&0&0)|(0|0|0)\") == 1\n assert candidate(expression = \"0|1&(1|0)&1\") == 1\n assert candidate(expression = \"1|1|(0&0)&1\") == 1\n assert candidate(expression = \"(((0|1)&1)|(0&0))\") == 1\n assert candidate(expression = \"(1&((0&1)|0))\") == 1\n assert candidate(expression = \"(0|(1|0&1))\") == 1\n assert candidate(expression = \"(0|((0|0)|(0|0)))\") == 1\n assert candidate(expression = \"(1&0)|(1&1)\") == 1\n assert candidate(expression = \"(0&0)&(0&0&0)\") == 3\n assert candidate(expression = \"(0|(0|(0|(0|0))))\") == 1\n assert candidate(expression = \"((1|0)&(0|1))\") == 1\n assert candidate(expression = \"(1|0|0)&(1&1)\") == 1\n assert candidate(expression = \"((1&0)|(1|0))\") == 1\n assert candidate(expression = \"(1&(1&(1&(1&1))))\") == 1\n assert candidate(expression = \"(1&1&1)|(0|0|0)\") == 1\n assert candidate(expression = \"(1|(0&(1|0)))\") == 1\n assert candidate(expression = \"(0&1)|((1|0)&(0|1))\") == 1\n assert candidate(expression = \"0|(0|(0|(0|0)))\") == 1\n assert candidate(expression = \"(1&(0|(1&0)))\") == 1\n assert candidate(expression = \"((1&(1|0))&(0|1))\") == 1\n assert candidate(expression = \"(0&(((0|1)&(1|0))|((1&0)|(0|1))))\") == 1\n assert candidate(expression = \"((0&(((1|0)|(0&1))&(1&1)))|((1|0)|(0|1)))&(1|0)\") == 1\n assert candidate(expression = \"((0&(1|0))&(0&(1|0))&(0&(1|0)))\") == 2\n assert candidate(expression = \"(0|((1&0)|(0|1)&((1|0)&(1|0))))\") == 1\n assert candidate(expression = \"((1&((1|0)|(0|1)))&((0&0)|(1&(1&(1&1)))))\") == 1\n assert candidate(expression = \"((0|1)&(1|(0|1&0))&(1|(0&(1|0))))\") == 1\n assert candidate(expression = \"((1&((0|1)&(0|1)))|((0&(1|0))&(1|0)))\") == 1\n assert candidate(expression = \"(((0|0)|(1|1))&((0|0)|(1|1))&((0|0)|(1|1))&((0|0)|(1|1)))\") == 1\n assert candidate(expression = \"(((1|0)|(0&1))&((0|1)|(0&1))&((1|0)|(0&1))&((0|1)|(0&1)))\") == 1\n assert candidate(expression = \"((0&0)&(0&0)&(1|1)&((0|0)|(1|1)))\") == 1\n assert candidate(expression = \"((1&0)|(0|1)&((1|0)&(1|0)))\") == 1\n assert candidate(expression = \"((1|0)&(1&0)|(0|1)&(1|0))\") == 1\n assert candidate(expression = \"((1|0)|(0&1)&(0|1))\") == 1\n assert candidate(expression = \"(1|(((1|0)&(0|1)))&(((0&1)|(1&1))&(1|0)))|(0|1)\") == 2\n assert candidate(expression = \"((0&(1|0)&(1|0))|(0&(0|1)&(0|1)))\") == 1\n assert candidate(expression = \"(((0|1)&(0|1))&((1&0)|(1&0))&((0|1)&(0|1))&((1&0)|(1&0)))\") == 2\n assert candidate(expression = \"(((1|1)|(0|0))&(1&(1&(1&1))))\") == 1\n assert candidate(expression = \"((1&0)|((0&1)|(1|((1&0)|(0|1)))))\") == 1\n assert candidate(expression = \"(((0&(1|0))&(1&((0&1)|(1|0))))|((1&0)|(0&((1&0)|(0&1)))))\") == 1\n assert candidate(expression = \"(((1|0)&(0|1))&((1|0)&(0|1)))|(1&(0|((1&1)|(0&0))))\") == 2\n assert candidate(expression = \"(((0|1)&(1|0))|((1&(0|1))|(0&1)))\") == 2\n assert candidate(expression = \"(0|((1&0)|(0|1)&((1|0)|(0|1)&(1|0))))\") == 1\n assert candidate(expression = \"(((0|1)|(1&0))&((0&1)|(1|0)))\") == 1\n assert candidate(expression = \"((1&0)|(1&0)|(0|1)&(0|1))\") == 1\n assert candidate(expression = \"(1|(((1|0)&(1|0))|((0&1)|(0&1))))\") == 2\n assert candidate(expression = \"(1&(0|((1&1)|(0|0))))\") == 1\n assert candidate(expression = \"(1&(((0|1)&(0|1))&((1|0)|(0|1)&(1|0))))\") == 1\n assert candidate(expression = \"((0&((0&1)|(1|0)))|((1&((0&1)|(1|0)))&(1&(0&(1|0)))))\") == 1\n assert candidate(expression = \"((1&0)|(0|1)&((1|0)|(0|1)&(1|0)))\") == 1\n assert candidate(expression = \"(1|(0&(1|0))|(0&1))\") == 1\n assert candidate(expression = \"(0|((1&1)|(0&0)))&(1&(0|((1&1)|(0&0))))\") == 1\n assert candidate(expression = \"(1|(((0&(1|0))|(1&0))&((1|0)&(0|1))))\") == 1\n assert candidate(expression = \"(((1|0)&(0|1))|((0&1)|(1|0))|((1|0)&(0|1))|((0&1)|(1|0)))\") == 2\n assert candidate(expression = \"(((1&0)|(0&1))&((0&(1|0))|(1&((0&1)|(1|0)))))\") == 1\n assert candidate(expression = \"(((1&0)|(0|1))&((1|0)|(0&1)))\") == 1\n assert candidate(expression = \"((1&0)|(1&1))&(1|0)\") == 1\n assert candidate(expression = \"(((1|1)|(0&0))&((1&1)|(0|0))|(1|0))\") == 2\n assert candidate(expression = \"((1|((0&0)|(1&1)))&(1|0))|((0|1)&(1&1))\") == 2\n assert candidate(expression = \"(((1|0)&1)|(0&(1|0)))\") == 1\n assert candidate(expression = \"((0&1)|(1&(0|1)))&((1&0)|(1|1))\") == 1\n assert candidate(expression = \"(1&((0|1)&(0|1))&(0|1))\") == 1\n assert candidate(expression = \"((0|1)|(1|0)&(0|1)&(0|1))&((0|1)|(0|1))\") == 1\n assert candidate(expression = \"(1&((0&1)|(0&(1|0))&(1|0)))\") == 1\n assert candidate(expression = \"(1|((1|0)&(0|1)))|(((0&1)|(1&1))&(1|0))\") == 2\n assert candidate(expression = \"((0&((1|0)&(0|1)))|((0&(1|0))&(1|0)))\") == 1\n assert candidate(expression = \"(((0|1)&(0|1))&((1|0)|(0|1)&(1|0)))\") == 1\n assert candidate(expression = \"(1&(((0&0)|(1|1))&(1&((0&0)|(1|1)))))|((1&(0|((1&1)|(0&0))))&(1|0))\") == 2\n assert candidate(expression = \"(((1&1)&(0|0))|(1|0)&((1&0)|(0|1))&(1|0))\") == 1\n assert candidate(expression = \"((1|(0&(1&0)))&(0|(1|0)))\") == 1\n assert candidate(expression = \"((1&(0|1))|(0&(1|0)))\") == 1\n assert candidate(expression = \"(((0|1)|(0&1))&(1|(0&0)&(1|0)))\") == 1\n assert candidate(expression = \"(1|((0|1)&(0&1))|(1&0))\") == 1\n assert candidate(expression = \"((1&0)|(1&(0|1))|(0&(1|0)))\") == 1\n assert candidate(expression = \"((0|(1&0))&(((1|0)&(0|1))|((0&1)|(1|0))))\") == 1\n assert candidate(expression = \"(1&(((0|1)|(1&0))&(0|1)))\") == 1\n assert candidate(expression = \"(((1&(0|1))&((1&0)|(0&1)))|((0&(1|0))&(1&((0&1)|(1|0)))))\") == 1\n assert candidate(expression = \"((0|1)|((1&(0|1))&(0|1)))\") == 2\n assert candidate(expression = \"((0&1)|(0&1)|(0&1)|(0&1))\") == 1\n assert candidate(expression = \"(0|(1&0)|(0|1)&(1|0))\") == 1\n assert candidate(expression = \"((1&(0|((1|0)&(1|0))))&((1&(0|((1|0)&(1|0))))&((1&(0|((1|0)&(1|0))))))\") == 1\n assert candidate(expression = \"(1|((0&0)|(1&(0|1))))\") == 2\n assert candidate(expression = \"(0|((1&((0|1)|(1|0)))&(1|0)))\") == 1\n assert candidate(expression = \"((0|((1&0)|(0|1)))&(((1|0)&(0|1))|((0&1)|(1|0))))\") == 1\n assert candidate(expression = \"(1&((0|0)|(1&0))&(0&(1|0))&(0|1))\") == 1\n assert candidate(expression = \"(((1|1)|(0|0))&(1&0))|(0|1)\") == 1\n assert candidate(expression = \"(1&(0|((0|0)&(0|0))))|((1|0)&(1&1))\") == 1\n assert candidate(expression = \"((1&(0|1))&(1|0))\") == 1\n assert candidate(expression = \"(1|((1|0)|(0|1))&(0&1))\") == 1\n assert candidate(expression = \"((1&1)|(0&(1|0)))\") == 1\n assert candidate(expression = \"(0|((1&0)|(0|1)&(1|0)))\") == 1\n assert candidate(expression = \"(1|((0&(1|0))&(1&(0|1&0))))\") == 1\n assert candidate(expression = \"((0&(1|1))|((1&0)|(0&1)))\") == 1\n assert candidate(expression = \"(1&(((1|0)|(0&1))&(1&1)))|((0|1)&(1&1))\") == 2\n assert candidate(expression = \"(((0|1)&(0|1))&((1|0)&(1|0)))\") == 1\n assert candidate(expression = \"(((0|1)&(1|0))&((1&0)|(0|1)))\") == 1\n assert candidate(expression = \"((1&((0&1)|(1|0)))&((1|0)|(0&(1|0))))|((1&(0|((1&1)|(0&0))))&(1|0))\") == 2\n assert candidate(expression = \"(((0&0)|(1&(0|1)))&((1|0)|(0&((0&1)|(1|0)))))\") == 1\n assert candidate(expression = \"(((0|1)&(1|0))|((1&0)|(0&1)))\") == 1\n assert candidate(expression = \"(1&((1|0)|(0|1))&(0&(1|0))&(0|1)&((0|0)&(1|1)))\") == 2\n assert candidate(expression = \"((1&(1&(1&0)))|((0|1)|(0&1)))\") == 1\n assert candidate(expression = \"((1|0)&(0|1)|(0&(1|0)))\") == 1\n assert candidate(expression = \"(0|((1|0)&(0|1))&(1|0))\") == 1\n assert candidate(expression = \"((1&(0|((1&0)|(0&1))))&((0&(1|0))|(1&(0|1))))\") == 1\n assert candidate(expression = \"((1&(0|1))&(1&(0|1))&(1&(0|1))&(1&(0|1)))\") == 1\n assert candidate(expression = \"(1|((0&(1|0))|(1&(0|1))))\") == 2\n assert candidate(expression = \"((1|((0&(1&0))|(0|1)))&(0&((0&(1|0))|(1&(0|1)))))\") == 1\n assert candidate(expression = \"(0&((1&0)|(1|(0&1&0))))\") == 1\n assert candidate(expression = \"(1|((0&0)&(0|0))|(0|(1&1)))\") == 2\n assert candidate(expression = \"(((1|1)&(0&0))|(1&0))\") == 1\n assert candidate(expression = \"(((0|1)&(0|1))&(1|0)&(1|0))\") == 1\n assert candidate(expression = \"((0|0)&(0|0)&(1|1)|(0|0)&(0|0))\") == 2\n assert candidate(expression = \"(0&(((1|0)|(0&1))&(1&1)))|((1|0)|(0|1))\") == 1\n assert candidate(expression = \"((0&(0|1))|(0&(0|1))|(0&(0|1))|(0&(0|1)))\") == 1\n assert candidate(expression = \"((1&0)|(0|1)&(1|0))\") == 1\n assert candidate(expression = \"((0&1)|(1&(1|0)))\") == 1\n assert candidate(expression = \"((1&(1&1))|((0|0)|(0&0)))\") == 1\n assert candidate(expression = \"((1|(0&0)&(1|0))|(0&(0|1)&(0|1))&(0&(0|1)&(0|1)))\") == 1\n assert candidate(expression = \"(((1&0)|(0&1))&((1&(0|1))|(0&1)))\") == 1\n assert candidate(expression = \"((0|((1&(0|1))|(0&(1|0))))&(1&((0&1)|(1|0))))\") == 1\n assert candidate(expression = \"(((0|0)&(0|0))&((0|0)|(0|0)))\") == 2\n assert candidate(expression = \"(1&((1&((0&0)|(1|1)))|((1|(0|1))&(0&0))))\") == 1\n assert candidate(expression = \"((0&((1|0)|(0|1)))|((1&(0|1))&(0|1)))\") == 1\n assert candidate(expression = \"(((0&(1|0))|(1&0))&((1|0)&(0|1)))\") == 1\n assert candidate(expression = \"(((1&(0|1))|(0&(1|0)))|((1&(0|1))&(0|1)))\") == 2\n assert candidate(expression = \"((0&(0&0))|((1|1)&(1|1)))\") == 1\n assert candidate(expression = \"((1&(0|1))|(0&(0|1)&(0|1)))\") == 1\n assert candidate(expression = \"(1&((0|1)|(0|1))&(0&((1|0)|(1|0))))\") == 1\n assert candidate(expression = \"(((1&(0|1))|(0&1))&(1&((0|1)|(0&(1|0)))))\") == 1\n assert candidate(expression = \"(((1|0)&(0|1))|(0&(1|0))&(1&(0|1&0)))\") == 1\n assert candidate(expression = \"((1&(0|1))|(1&0))\") == 1\n assert candidate(expression = \"(1&(((0|1)&(0|1))&((1|0)&(1|0))))\") == 1\n assert candidate(expression = \"(1&(0|1&(0|1&(1|0))))\") == 1\n assert candidate(expression = \"(((1|0)|(0&1))&((1|0)|(0&1))&((1|0)|(0&1))&((1|0)|(0&1)))\") == 1\n assert candidate(expression = \"((((0|0)|(1&1))&((0|1)&(1|0)))|((0&1)|(1|0)))\") == 2\n assert candidate(expression = \"(1|((0&0)|(1&0))&(0&(1|0))&(0|1)&((1|0)|(0|1)))\") == 1\n assert candidate(expression = \"(((0|1)&(1|0))&(0|1))\") == 1\n assert candidate(expression = \"(((1|0)|(0&1))&((1&0)|(0|1)))\") == 1\n assert candidate(expression = \"(1|(((0|1)&(1|0))|(0&(1|0))))\") == 2\n assert candidate(expression = \"(1|(((1|0)&(0|1))|(1&(0&1))))\") == 2\n assert candidate(expression = \"(((1&0)|(1|0))&((1&1)|(0|0)))\") == 1\n assert candidate(expression = \"((0|1)|((0&1)&(1|0))&(1&(0|((1&1)|(0&0)))))\") == 1\n assert candidate(expression = \"(1|(((0&0)&(0|0))|((1|1)|(1&1))))\") == 2\n assert candidate(expression = \"(0&(((1|0)|(0|1))&(0|1))&(1|0))\") == 1\n assert candidate(expression = \"((0|0)|(1&1))&(((1|0)&(0|1))|(1&1))\") == 1\n assert candidate(expression = \"((1&(0|1))|((0&1)|((1|0)&(0|1))))\") == 2\n assert candidate(expression = \"(((1&1)&(0|0))|((0|0)|(1&1)))\") == 1\n assert candidate(expression = \"(((1|0)|(1|0))&((0&1)|(0&1))&((0&1)|(0&1))&((1|0)|(1|0)))\") == 1\n assert candidate(expression = \"((1&(0|1))&((0|1)|(1&0)))\") == 1\n assert candidate(expression = \"((1&(0|1))&((0|1)&(1|0)))\") == 1\n assert candidate(expression = \"(1&((0|1)&(0|1))|(1&0)&(0&1))\") == 1\n assert candidate(expression = \"(1|((0&(1|0))|((0|1)&(1&0))))\") == 1\n assert candidate(expression = \"((1&(0|1))|((0|1)|(1&(0|1&0))))\") == 2\n assert candidate(expression = \"(((1&(0&(1|0)))|((0&(1|0))|(0&1)))&((0&1)|(1&(0&1))))\") == 2\n assert candidate(expression = \"(1&(1|(0&0)&(1|0))|(0&(0|1)&(0|1)))\") == 1\n assert candidate(expression = \"(0|((((1|0)&(0|1))|((1&0)|(0|1)))|((1&(0&0))|(0|1))))\") == 1\n assert candidate(expression = \"(((0&0)|(1|1))&((0|1)|(1|0))&((1&0)|(0|1))&((0&0)|(1|1)))\") == 1\n assert candidate(expression = \"((0&(0|1))|((1|0)&1))\") == 1\n assert candidate(expression = \"(((0|1)&(1|0))|(0&(1|0)))\") == 1\n assert candidate(expression = \"(((0&1)|(1&0))|((1&1)&(0|0)))\") == 1\n assert candidate(expression = \"((0&(1|0))|((0&1)|(1&1)))&(1|0)\") == 1\n", "comparison": "exact"}, "public_tests": ["\"1&(0|1)\"", "\"(0&0)&(0&0&0)\"", "\"(0|(1|0&1))\""], "hints": ["How many possible states are there for a given expression?", "Is there a data structure that we can use to solve the problem optimally?"], "metadata": {"canonical_parameter_names": ["expression"], "leetcode_dataset_entry_point": "Solution().minOperationsToFlip", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:15+00:00", "tests_total": 173, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "dynamic-programming", "stack"]}, "language": "php", "interface": {"raw_signature": "function minOperationsToFlip($expression) {", "container": "Solution", "callable": "minOperationsToFlip", "parameters": [{"name": "expression", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1897, "task_id": "redistribute-characters-to-make-all-strings-equal", "difficulty": "Easy", "problem_description": "You are given an array of strings words (0-indexed).\n\nIn one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].\n\nReturn true if you can make every string in words equal using any number of operations, and false otherwise.\n\nExample 1:\n\nInput: words = [\"abc\",\"aabc\",\"bc\"]\nOutput: true\nExplanation: Move the first 'a' in words[1] to the front of words[2],\nto make words[1] = \"abc\" and words[2] = \"abc\".\nAll the strings are now equal to \"abc\", so return true.\n\nExample 2:\n\nInput: words = [\"ab\",\"a\"]\nOutput: false\nExplanation: It is impossible to make all the strings equal using the operation.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 100\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl']) == False\n assert candidate(words = ['aabbcc', 'abc', 'abc', 'abc']) == False\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba']) == True\n assert candidate(words = ['abcd', 'bcad', 'acdb', 'bdac']) == True\n assert candidate(words = ['hello', 'olelh', 'loleh']) == True\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == False\n assert candidate(words = ['a', 'a', 'a', 'a']) == True\n assert candidate(words = ['test', 'sett', 'stte']) == True\n assert candidate(words = ['abc', 'def', 'ghi']) == False\n assert candidate(words = ['xyz', 'zyx', 'yzx']) == True\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy']) == False\n assert candidate(words = ['ab', 'a']) == False\n assert candidate(words = ['same', 'same', 'same']) == True\n assert candidate(words = ['abcd', 'abcd', 'abcd', 'abcd']) == True\n assert candidate(words = ['one', 'two', 'three']) == False\n assert candidate(words = ['abc', 'aabc', 'bc']) == True\n assert candidate(words = ['aabbcc', 'abc', 'abc']) == False\n assert candidate(words = ['abcd', 'abcd', 'abcd']) == True\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == True\n assert candidate(words = ['aabb', 'bbcc', 'ccdd', 'aabb', 'bbcc', 'ccdd', 'aabb', 'bbcc', 'ccdd']) == False\n assert candidate(words = ['abcdefghijklmnop', 'abcdefghijklmnop', 'abcdefghijklmnop', 'abcdefghijklmnop']) == True\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'zxy', 'yxz', 'xzy']) == True\n assert candidate(words = ['zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz', 'zzzzzzzz']) == True\n assert candidate(words = ['repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat', 'repeat']) == True\n assert candidate(words = ['abcdabcd', 'bacdbacd', 'cdabdcab', 'dcbadacb']) == True\n assert candidate(words = ['xyz', 'yzx', 'zxy', 'zyx', 'yxz', 'xzy']) == True\n assert candidate(words = ['abcdefg', 'ghfedcb', 'fedcbaa', 'bcaefgd', 'abcdefg', 'ghfedcb', 'fedcbaa', 'bcaefgd', 'abcdefg', 'ghfedcb']) == False\n assert candidate(words = ['abcde', 'bcdea', 'cdeab', 'deabc', 'eabcd', 'fghij', 'ghijf', 'hijfg', 'ijfgh', 'jfgih']) == False\n assert candidate(words = ['hello', 'bello', 'hallo', 'hellb', 'hella', 'bellh', 'hblla']) == False\n assert candidate(words = ['abcde', 'edcba', 'bcdea', 'decab', 'acdeb']) == True\n assert candidate(words = ['hello', 'lohel', 'ohell', 'llohe', 'elloh']) == True\n assert candidate(words = ['python', 'typhon', 'typhno', 'hypton', 'hptyon', 'phyton', 'ptyhno', 'thpyon', 'ptyhon', 'phytom']) == False\n assert candidate(words = ['abacabadabacaba', 'bacabacabadabacab', 'acabacabadabacaba', 'cabacabadabacabaa']) == False\n assert candidate(words = ['aabbcc', 'abcabc', 'ccbaab', 'bcaacb']) == True\n assert candidate(words = ['aabbcc', 'abcabc', 'baccab', 'cbbaca', 'acabcb', 'bcacab']) == True\n assert candidate(words = ['hello', 'world', 'owrld', 'dlrow', 'llhow']) == False\n assert candidate(words = ['abcdef', 'fedcba', 'defabc', 'cabdef', 'bacdef', 'fabcde']) == True\n assert candidate(words = ['xyx', 'yxy', 'xyx', 'xyx', 'xyx', 'xyx', 'xyx', 'xyx', 'xyx', 'xyx']) == False\n assert candidate(words = ['mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq', 'mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq', 'mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq']) == True\n assert candidate(words = ['equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal']) == True\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccaabb', 'aabbbc', 'bbccaa']) == False\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']) == False\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'aaa', 'bbb', 'ccc', 'aaa', 'bbb', 'ccc']) == True\n assert candidate(words = ['qwertyuiop', 'poiuytrewq', 'oiuytrewqp', 'iuytrewqpo', 'uytrewqpoi', 'ytrewqpoiu']) == True\n assert candidate(words = ['abcdefg', 'bcdefga', 'cdefgab', 'defgabc', 'efgabcd', 'fgabcde', 'gabcdef']) == True\n assert candidate(words = ['aabb', 'bbaa', 'abab', 'abba', 'baab', 'baba', 'aaab', 'aaba', 'abaa', 'baaa', 'bbaa', 'abab', 'abba', 'baab', 'baba', 'aaab', 'aaba', 'abaa', 'baaa', 'bbaa']) == False\n assert candidate(words = ['aabbcc', 'abcabc', 'bcaabc', 'cababc']) == True\n assert candidate(words = ['apple', 'ppale', 'pleap', 'elppa', 'lappe']) == True\n assert candidate(words = ['aabbccddeeffgghhiijjooppllnnmmbbkkqqwwaass', 'aabbccddeeffgghhiijjooppllnnmmbbkkqqwwaass', 'aabbccddeeffgghhiijjooppllnnmmbbkkqqwwaass', 'aabbccddeeffgghhiijjooppllnnmmbbkkqqwwaass']) == True\n assert candidate(words = ['aabbcc', 'bbccaa', 'ccaabb']) == True\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == True\n assert candidate(words = ['xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx', 'xy', 'yx']) == True\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee']) == False\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == True\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == True\n assert candidate(words = ['aabbcc', 'abcabc', 'ccbaab']) == True\n assert candidate(words = ['unique', 'uniqueness', 'uniquely', 'uniques']) == False\n assert candidate(words = ['aaaaab', 'aaabbb', 'aabbbb', 'abbbbb', 'bbbbbz']) == False\n assert candidate(words = ['python', 'typhon', 'nothpy', 'hnotyp', 'npytho']) == True\n assert candidate(words = ['aabbcc', 'abcabc', 'ccbaab', 'baccab']) == True\n assert candidate(words = ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']) == True\n assert candidate(words = ['abcdef', 'bcdefa', 'cdefab', 'defabc', 'efabcd', 'fabcde', 'abcdef', 'bcdefa', 'cdefab', 'defabc', 'efabcd', 'fabcde']) == True\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'xzy']) == True\n assert candidate(words = ['unique', 'characters', 'only', 'in', 'each', 'string', 'here']) == False\n assert candidate(words = ['abcdefgh', 'hgfedcba', 'abcdefg', 'gfedcba', 'abcdef', 'fedcba', 'abcde', 'edcba', 'abcd', 'dcba', 'abc', 'cba', 'ab', 'ba', 'a', 'b']) == False\n assert candidate(words = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm', 'qwertyuiop', 'asdfghjkl', 'zxcvbnm', 'qwertyuiop', 'asdfghjkl', 'zxcvbnm']) == False\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']) == False\n assert candidate(words = ['abracadabra', 'cadabraab', 'rabracada', 'abracadab', 'acadabrabr']) == False\n assert candidate(words = ['abcdef', 'bcdefa', 'cdefab', 'defabc', 'efabcd', 'fabcde']) == True\n assert candidate(words = ['qqq', 'www', 'eee', 'rrr', 'ttt', 'yyy', 'uuu', 'iii', 'ooo', 'ppp', 'lll', 'mmm', 'nnn', 'sss', 'ddd', 'fff', 'ggg', 'hhh', 'jjj', 'kkk']) == False\n assert candidate(words = ['apple', 'ppale', 'pplea', 'pelap', 'pepla']) == True\n assert candidate(words = ['racecar', 'carrace', 'ecarrac', 'rraceca', 'acecarr']) == True\n assert candidate(words = ['abcdefgh', 'hgfedcba', 'bacdefgh', 'defghabc', 'efghabcd']) == True\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc', 'abcabcabcabc', 'abcabcabcabcabc', 'abcabcabcabcabcabc', 'abcabcabcabcabcabcabc', 'abcabcabcabcabcabcabcabc', 'abcabcabcabcabcabcabcabcabc', 'abcabcabcabcabcabcabcabcabcabc']) == False\n assert candidate(words = ['mississippi', 'ppiimiss', 'pisimmpi', 'ssippiim', 'pmissipi', 'iimpsspi', 'sspiimp', 'misipip', 'sipimp', 'impispi']) == False\n assert candidate(words = ['unique', 'enquie', 'unieqe', 'inequeu', 'niuquee', 'uqneiee', 'qnueiee']) == False\n assert candidate(words = ['aabbcc', 'abcabc', 'bcaabc', 'cababc', 'bcacab']) == True\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'xzy', 'yxz']) == True\n assert candidate(words = ['abcdabcd', 'dcbaabcd', 'abcdcdab', 'dcabcdab']) == True\n assert candidate(words = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'ffffff', 'gggggg', 'hhhhh', 'iiiii', 'jjjjj']) == False\n assert candidate(words = ['hello', 'world', 'world', 'hello']) == False\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'aab', 'bbc', 'cca']) == True\n assert candidate(words = ['aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz', 'zzxyyxwwvvttsrrqpponmlkjihgfedcba', 'abcdefghijlkmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba', 'zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba', 'qrstuvwxyzzyxwvutsrqponmlkjihgfedcbaabcd']) == False\n assert candidate(words = ['zzzz', 'zzz', 'zz', 'z']) == False\n assert candidate(words = ['python', 'programming', 'challenge', 'easy']) == False\n assert candidate(words = ['qwerty', 'wertyq', 'ertyqw', 'rtyqwe', 'tyqwre', 'yqwret', 'qwertyui', 'wertyuiq', 'ertyuiqw', 'rtyuiqwe', 'tyuiqwre', 'yuiqwret']) == False\n assert candidate(words = ['hello', 'olleh', 'loleh', 'elloh', 'lhleo', 'heoll']) == True\n assert candidate(words = ['abacabadabacaba', 'bacabacabacaba', 'cabacabacabacaba', 'dacabacabacaba', 'eacabacabacaba', 'facabacabacaba', 'gacabacabacaba', 'hacabacabacaba', 'iacabacabacaba', 'jacobacabacaba', 'kacabacabacaba']) == False\n", "comparison": "exact"}, "public_tests": ["[\"abc\",\"aabc\",\"bc\"]", "[\"ab\",\"a\"]"], "hints": ["Characters are independent—only the frequency of characters matters.", "It is possible to distribute characters if all characters can be divided equally among all strings."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().makeEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:17+00:00", "tests_total": 89, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function makeEqual($words) {", "container": "Solution", "callable": "makeEqual", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1898, "task_id": "maximum-number-of-removable-characters", "difficulty": "Medium", "problem_description": "You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).\n\nYou want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence.\n\nReturn the maximum k you can choose such that p is still a subsequence of s after the removals.\n\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\nExample 1:\n\nInput: s = \"abcacb\", p = \"ab\", removable = [3,1,0]\nOutput: 2\nExplanation: After removing the characters at indices 3 and 1, \"abcacb\" becomes \"accb\".\n\"ab\" is a subsequence of \"accb\".\nIf we remove the characters at indices 3, 1, and 0, \"abcacb\" becomes \"ccb\", and \"ab\" is no longer a subsequence.\nHence, the maximum k is 2.\n\nExample 2:\n\nInput: s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6]\nOutput: 1\nExplanation: After removing the character at index 3, \"abcbddddd\" becomes \"abcddddd\".\n\"abcd\" is a subsequence of \"abcddddd\".\n\nExample 3:\n\nInput: s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4]\nOutput: 0\nExplanation: If you remove the first index in the array removable, \"abc\" is no longer a subsequence.\n\nConstraints:\n\n- 1 <= p.length <= s.length <= 10^5\n- 0 <= removable.length < s.length\n- 0 <= removable[i] < s.length\n- p is a subsequence of s.\n- s and p both consist of lowercase English letters.\n- The elements in removable are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"pqrstu\",p = \"psu\",removable = [5, 4, 3, 2, 1, 0]) == 0\n assert candidate(s = \"abcdefghij\",p = \"acegi\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(s = \"deeddeede\",p = \"dee\",removable = [5, 3, 4, 6]) == 4\n assert candidate(s = \"deeedbbcccbdaa\",p = \"ddccbb\",removable = [8, 2, 3, 0, 7]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"acegikmoqsuwy\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 13\n assert candidate(s = \"zzzzzzzzzz\",p = \"zz\",removable = [1, 3, 5, 7]) == 4\n assert candidate(s = \"aaaabbbb\",p = \"ab\",removable = [2, 3, 4, 5]) == 4\n assert candidate(s = \"abcdef\",p = \"abc\",removable = [5, 4, 3, 2, 1, 0]) == 3\n assert candidate(s = \"aabcbcb\",p = \"abc\",removable = [3, 1, 0, 4]) == 2\n assert candidate(s = \"abcdxyz\",p = \"ad\",removable = [0, 1, 2, 3, 4, 5, 6]) == 0\n assert candidate(s = \"abcacb\",p = \"ab\",removable = [3, 1, 0]) == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"acegikmoqsuwy\",removable = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 0\n assert candidate(s = \"ababababab\",p = \"aaaa\",removable = [0, 2, 4, 6, 8]) == 1\n assert candidate(s = \"mississippi\",p = \"issi\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(s = \"zpqom\",p = \"z\",removable = [0, 1, 2, 3, 4]) == 0\n assert candidate(s = \"abcab\",p = \"abc\",removable = [0, 1, 2, 3, 4]) == 0\n assert candidate(s = \"xyz\",p = \"xyz\",removable = [0, 1, 2]) == 0\n assert candidate(s = \"abcdef\",p = \"af\",removable = [1, 2, 3, 4]) == 4\n assert candidate(s = \"abcbddddd\",p = \"abcd\",removable = [3, 2, 1, 4, 5, 6]) == 1\n assert candidate(s = \"zazbzczdzezfzgzhzi\",p = \"abcdefg\",removable = [0, 2, 4, 6, 8, 10, 12, 14, 16]) == 9\n assert candidate(s = \"thisisaverylongstringthatweneedtoremovesomecharactersfrom\",p = \"thisisalong\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 0\n assert candidate(s = \"mississippi\",p = \"miss\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(s = \"abcdefghijklnmopqrstuvwxyz\",p = \"zyxwvutsrqponmlkjihgfedcba\",removable = [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\n assert candidate(s = \"abracadabra\",p = \"aca\",removable = [1, 3, 5, 7, 9, 10]) == 5\n assert candidate(s = \"leetcodeleetcodeleetcode\",p = \"leetcode\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) == 16\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",p = \"zzzz\",removable = [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\n assert candidate(s = \"abracadabra\",p = \"aa\",removable = [0, 2, 4, 6, 8, 10]) == 6\n assert candidate(s = \"abacabadabacaba\",p = \"abc\",removable = [2, 5, 8, 11, 14]) == 5\n assert candidate(s = \"abcdefghijklm\",p = \"abc\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(s = \"zzzzzzzzzz\",p = \"zz\",removable = [1, 3, 5, 7, 9]) == 5\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",p = \"abcdefghijklmnopqrstuvwxyz\",removable = [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]) == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",p = \"zzzzz\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 15\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"az\",removable = [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]) == 0\n assert candidate(s = \"abcdeffedcba\",p = \"abcdef\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 0\n assert candidate(s = \"mississippi\",p = \"issi\",removable = [2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(s = \"abcdefghijklmno\",p = \"def\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",p = \"zzzz\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 16\n assert candidate(s = \"abcdefghijklmnop\",p = \"mnop\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 12\n assert candidate(s = \"banana\",p = \"ban\",removable = [0, 2, 4]) == 0\n assert candidate(s = \"aaaabbbbccccdddd\",p = \"abcd\",removable = [3, 7, 11, 15]) == 4\n assert candidate(s = \"abracadabra\",p = \"aca\",removable = [1, 3, 5, 7, 9]) == 5\n assert candidate(s = \"banana\",p = \"ban\",removable = [0, 1, 2, 3, 4, 5]) == 0\n assert candidate(s = \"abcdefffffghijklmnopqrstuvwxyz\",p = \"acegikmoqsuwy\",removable = [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, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == 10\n assert candidate(s = \"aabbccddeeffgghhii\",p = \"abcdefghi\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == 9\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",p = \"abcdefghijklmnopqrstuvwxzy\",removable = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]) == 0\n assert candidate(s = \"abcdabcdabcd\",p = \"abc\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 8\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",p = \"qz\",removable = [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\n assert candidate(s = \"xyzzxyzzxyzz\",p = \"xyz\",removable = [0, 2, 4, 6, 8, 10]) == 4\n assert candidate(s = \"aaaaaaaaaaa\",p = \"aaaaa\",removable = [1, 3, 5, 7, 9]) == 5\n assert candidate(s = \"abababababababababab\",p = \"aabbaabb\",removable = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == 4\n assert candidate(s = \"xyzzxyzzxyzz\",p = \"xyz\",removable = [1, 3, 5, 7, 9, 11]) == 4\n assert candidate(s = \"mississippi\",p = \"issi\",removable = [3, 1, 0, 4, 5, 2, 6, 7, 8, 9, 10]) == 3\n assert candidate(s = \"abracadabra\",p = \"ac\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(s = \"bcaabcbabcabc\",p = \"abc\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",p = \"zzz\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"bdfhjlnprtvxz\",removable = [1, 5, 9, 13, 17, 21, 25]) == 0\n assert candidate(s = \"abcdeffedcba\",p = \"abcdef\",removable = [0, 2, 4, 6, 8, 10]) == 0\n assert candidate(s = \"mississippi\",p = \"miss\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"adgjmpsvy\",removable = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 0\n assert candidate(s = \"hellotherehowareyou\",p = \"heoy\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == 4\n assert candidate(s = \"aaaaabbbbbcccc\",p = \"abc\",removable = [5, 6, 7, 8, 9, 10]) == 4\n assert candidate(s = \"thisisaverylongstring\",p = \"tils\",removable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 3\n assert candidate(s = \"leetcodeleetcodeleetcodeleetcode\",p = \"leetcodelt\",removable = [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]) == 16\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"acegikmoqsuwy\",removable = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 12\n assert candidate(s = \"abcdefghijabcdefghij\",p = \"acegik\",removable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 0\n", "comparison": "exact"}, "public_tests": ["\"abcacb\"\n\"ab\"\n[3,1,0]", "\"abcbddddd\"\n\"abcd\"\n[3,2,1,4,5,6]", "\"abcab\"\n\"abc\"\n[0,1,2,3,4]"], "hints": ["First, we need to think about solving an easier problem, If we remove a set of indices from the string does P exist in S as a subsequence", "We can binary search the K and check by solving the above problem."], "metadata": {"canonical_parameter_names": ["s", "p", "removable"], "leetcode_dataset_entry_point": "Solution().maximumRemovals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:20+00:00", "tests_total": 82, "tests_dropped": 17, "flags": [], "topic_tags": ["array", "two-pointers", "string", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function maximumRemovals($s, $p, $removable) {", "container": "Solution", "callable": "maximumRemovals", "parameters": [{"name": "s", "type": "String"}, {"name": "p", "type": "String"}, {"name": "removable", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1899, "task_id": "merge-triplets-to-form-target-triplet", "difficulty": "Medium", "problem_description": "A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [a_i, b_i, c_i] describes the i^th triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.\n\nTo obtain target, you may apply the following operation on triplets any number of times (possibly zero):\n\n- Choose two indices (0-indexed) i and j (i != j) and update triplets[j] to become [max(a_i, a_j), max(b_i, b_j), max(c_i, c_j)].\n - For example, if triplets[i] = [2, 5, 3] and triplets[j] = [1, 7, 5], triplets[j] will be updated to [max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5].\n\nReturn true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.\n\nExample 1:\n\nInput: triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]\nOutput: true\nExplanation: Perform the following operations:\n- Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]\nThe target triplet [2,7,5] is now an element of triplets.\n\nExample 2:\n\nInput: triplets = [[3,4,5],[4,5,6]], target = [3,2,5]\nOutput: false\nExplanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.\n\nExample 3:\n\nInput: triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]\nOutput: true\nExplanation: Perform the following operations:\n- Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].\n- Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].\nThe target triplet [5,5,5] is now an element of triplets.\n\nConstraints:\n\n- 1 <= triplets.length <= 10^5\n- triplets[i].length == target.length == 3\n- 1 <= a_i, b_i, c_i, x, y, z <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6]],target = [1, 2, 3]) == True\n assert candidate(triplets = [[3, 4, 5], [4, 5, 6]],target = [3, 2, 5]) == False\n assert candidate(triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5]],target = [2, 7, 5]) == True\n assert candidate(triplets = [[1000, 1000, 1000]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],target = [1, 2, 3]) == False\n assert candidate(triplets = [[1, 2, 3], [3, 2, 1], [2, 3, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],target = [1, 2, 3]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],target = [1, 1, 1]) == True\n assert candidate(triplets = [[2, 5, 3], [2, 3, 4], [1, 2, 5], [5, 2, 3]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 3, 3], [3, 1, 3], [3, 3, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 4], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1000, 1, 1], [1, 1000, 1], [1, 1, 1000], [500, 500, 500]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[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]],target = [6, 6, 6]) == True\n assert candidate(triplets = [[1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 1, 3], [1, 3, 1], [3, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1]],target = [1, 2, 2]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]],target = [1, 2, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 1, 1], [10, 10, 10]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[100, 1, 1], [1, 100, 1], [1, 1, 100], [50, 50, 50], [10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40]],target = [50, 50, 50]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],target = [13, 14, 15]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [9, 10, 11]],target = [9, 10, 11]) == True\n assert candidate(triplets = [[999, 1, 1], [1, 999, 1], [1, 1, 999], [1000, 1000, 1000]],target = [999, 999, 999]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 1, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1], [1, 2, 1], [2, 1, 1]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5], [3, 2, 1], [6, 6, 6], [9, 9, 9]],target = [3, 8, 9]) == False\n assert candidate(triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5], [3, 2, 1], [6, 6, 6], [9, 9, 9]],target = [2, 7, 5]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1], [2, 2, 2]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[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]],target = [10, 10, 10]) == True\n assert candidate(triplets = [[2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]],target = [6, 7, 8]) == True\n assert candidate(triplets = [[1, 1000, 1], [2, 2, 999], [3, 3, 3], [4, 4, 4], [5, 5, 5]],target = [5, 1000, 999]) == True\n assert candidate(triplets = [[1000, 1, 1], [1, 1000, 1], [1, 1, 1000]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[999, 999, 999], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8]],target = [999, 999, 999]) == True\n assert candidate(triplets = [[1000, 1000, 1000], [999, 999, 999], [1, 1, 1]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[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, 1], [10, 1, 2]],target = [10, 10, 10]) == True\n assert candidate(triplets = [[9, 8, 7], [6, 5, 4], [3, 2, 1], [10, 11, 12]],target = [10, 11, 12]) == True\n assert candidate(triplets = [[1000, 1000, 1000], [999, 999, 999], [998, 998, 998], [1, 2, 3]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[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]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [1, 3, 2]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [3, 2, 1]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 1, 1], [2, 2, 2], [3, 3, 3]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 3, 1], [2, 1, 2], [3, 2, 3], [4, 3, 4], [5, 4, 5]],target = [5, 5, 5]) == False\n assert candidate(triplets = [[1, 2, 3], [1, 2, 2], [2, 2, 3], [2, 2, 2], [3, 2, 3], [3, 2, 2], [3, 3, 3], [6, 6, 6], [9, 9, 9]],target = [9, 9, 9]) == True\n assert candidate(triplets = [[9, 5, 1], [5, 9, 1], [1, 9, 5], [5, 1, 9], [9, 1, 5]],target = [9, 9, 9]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1000, 1, 1], [1, 1000, 1], [1, 1, 1000], [1000, 1000, 1000]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[1, 3, 2], [3, 2, 1], [2, 1, 3], [4, 4, 4]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 9, 1], [1, 1, 9], [9, 1, 1], [9, 9, 9], [5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[3, 3, 3], [3, 3, 3], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[5, 5, 5], [5, 5, 5], [5, 5, 5], [1, 2, 3], [4, 5, 6], [7, 8, 9]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[9, 9, 9], [8, 8, 8], [7, 7, 7], [6, 6, 6], [5, 5, 5], [4, 4, 4], [3, 3, 3], [2, 2, 2], [1, 1, 1]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 1, 2], [2, 2, 3], [3, 3, 4], [4, 4, 5]],target = [3, 3, 4]) == True\n assert candidate(triplets = [[1, 3, 1], [2, 1, 2], [3, 2, 1], [1, 2, 3], [2, 3, 1], [3, 1, 2]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 9, 9], [9, 1, 9], [9, 9, 1], [3, 3, 3], [2, 2, 2], [4, 4, 4]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[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]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 3, 5], [3, 5, 1], [5, 1, 3], [2, 4, 6], [4, 6, 2], [6, 2, 4]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 3], [1, 2, 3], [2, 3, 4], [2, 3, 4]],target = [2, 3, 4]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 1, 1], [10, 10, 10], [2, 2, 2], [3, 3, 3], [5, 5, 5]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],target = [1, 1, 1]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]],target = [7, 7, 7]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 4], [2, 3, 4], [3, 4, 5], [4, 5, 6]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 2], [2, 1, 1], [2, 1, 2], [1, 2, 1], [1, 2, 2], [2, 2, 1], [2, 2, 2]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [1, 5, 1], [5, 1, 5], [1, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[10, 20, 30], [10, 25, 35], [15, 25, 30], [10, 20, 35], [10, 25, 30], [15, 20, 30]],target = [15, 25, 30]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [1, 5, 6], [4, 2, 6], [4, 5, 3]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[1, 3, 5], [2, 2, 2], [3, 1, 4], [4, 4, 4], [5, 5, 5]],target = [5, 4, 5]) == False\n assert candidate(triplets = [[1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 2, 2], [2, 2, 1], [2, 1, 2], [2, 2, 2]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],target = [15, 15, 15]) == False\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [999, 999, 999]],target = [999, 999, 999]) == True\n assert candidate(triplets = [[2, 5, 3], [1, 8, 4], [1, 7, 5], [2, 7, 5], [5, 7, 5], [2, 7, 9]],target = [2, 7, 5]) == True\n assert candidate(triplets = [[1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[5, 1, 1], [1, 5, 1], [1, 1, 5], [1, 1, 1], [1, 1, 1]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 2, 2], [2, 2, 2], [2, 3, 3], [3, 3, 3]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 2, 2], [1, 2, 3], [2, 1, 3], [3, 2, 1]],target = [3, 3, 3]) == False\n assert candidate(triplets = [[500, 1, 1], [1, 500, 1], [1, 1, 500], [1, 1, 1], [1, 1, 1], [1, 1, 1]],target = [500, 500, 500]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10]],target = [6, 7, 8]) == True\n assert candidate(triplets = [[1, 100, 1], [100, 1, 1], [1, 1, 100], [100, 100, 1], [100, 1, 100], [1, 100, 100]],target = [100, 100, 100]) == True\n assert candidate(triplets = [[1, 5, 3], [1, 8, 4], [1, 7, 5], [1, 7, 9], [2, 5, 5], [1, 8, 8], [1, 7, 7]],target = [1, 8, 8]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 2, 1], [1, 1, 2], [2, 1, 1], [2, 2, 1], [2, 1, 2], [1, 2, 2], [2, 2, 2]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[3, 2, 1], [2, 1, 3], [1, 3, 2], [3, 3, 3]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],target = [10, 11, 12]) == True\n assert candidate(triplets = [[10, 10, 10], [20, 20, 20], [30, 30, 30], [40, 40, 40], [50, 50, 50]],target = [30, 30, 30]) == True\n assert candidate(triplets = [[2, 1, 1], [1, 2, 1], [1, 1, 2], [2, 2, 2]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]],target = [3, 3, 3]) == True\n assert candidate(triplets = [[100, 200, 300], [300, 400, 500], [500, 600, 700], [700, 800, 900], [900, 1000, 100], [100, 300, 500], [200, 400, 600]],target = [100, 400, 600]) == False\n assert candidate(triplets = [[1000, 1000, 1000], [1000, 1000, 1000], [1000, 1000, 1000], [1, 2, 3], [4, 5, 6], [7, 8, 9]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1]],target = [1, 1, 2]) == True\n assert candidate(triplets = [[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]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 2], [2, 2, 3], [2, 2, 2], [3, 2, 3], [3, 2, 2], [3, 3, 3], [6, 6, 6], [9, 9, 9]],target = [6, 6, 6]) == True\n assert candidate(triplets = [[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]],target = [1, 1, 1]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8]],target = [5, 6, 7]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [2, 1, 3], [3, 1, 2], [1, 3, 2], [1, 1, 1], [999, 999, 999]],target = [2, 2, 2]) == False\n assert candidate(triplets = [[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]],target = [9, 9, 9]) == True\n assert candidate(triplets = [[1, 999, 1], [999, 1, 1], [1, 1, 999], [999, 999, 1], [999, 1, 999], [1, 999, 999], [999, 999, 999]],target = [999, 999, 999]) == True\n assert candidate(triplets = [[5, 1, 1], [1, 5, 1], [1, 1, 5], [5, 5, 1], [5, 1, 5], [1, 5, 5], [5, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[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]) == True\n assert candidate(triplets = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 1, 1], [10, 10, 10], [2, 2, 2], [3, 3, 3], [5, 5, 5]],target = [10, 10, 10]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [5, 5, 5]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[1, 1, 999], [1, 999, 1], [999, 1, 1], [999, 999, 1], [999, 1, 999], [999, 999, 999]],target = [999, 999, 999]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 2], [2, 2, 3], [2, 2, 2], [3, 2, 3], [3, 2, 2], [3, 3, 3], [6, 6, 6], [9, 9, 9]],target = [3, 2, 3]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1], [2, 2, 2], [2, 2, 3]],target = [2, 2, 2]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [2, 1, 3], [1, 3, 2]],target = [1, 2, 3]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]],target = [4, 5, 6]) == True\n assert candidate(triplets = [[500, 500, 500], [1, 1, 1], [1000, 1000, 1000], [250, 250, 250], [750, 750, 750]],target = [500, 500, 500]) == True\n assert candidate(triplets = [[1, 1000, 1000], [1000, 1, 1000], [1000, 1000, 1], [250, 250, 250], [500, 500, 500], [750, 750, 750]],target = [1000, 1000, 1000]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],target = [1, 1, 1]) == True\n assert candidate(triplets = [[3, 4, 5], [5, 6, 7], [8, 9, 10], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]],target = [8, 9, 10]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]],target = [1, 1, 1]) == True\n assert candidate(triplets = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],target = [5, 6, 7]) == True\n assert candidate(triplets = [[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]],target = [5, 5, 5]) == True\n assert candidate(triplets = [[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]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]],target = [5, 6, 7]) == True\n assert candidate(triplets = [[1, 2, 3], [1, 2, 2], [2, 2, 3], [2, 2, 2], [3, 2, 3], [3, 2, 2], [3, 3, 3]],target = [3, 2, 3]) == True\n assert candidate(triplets = [[1, 1, 1], [2, 3, 4], [5, 6, 7], [1, 2, 3], [4, 5, 6], [7, 8, 9]],target = [7, 8, 9]) == True\n assert candidate(triplets = [[1, 1, 1], [1, 1, 2], [1, 2, 1], [2, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1], [2, 2, 2]],target = [2, 2, 2]) == True\n", "comparison": "exact"}, "public_tests": ["[[2,5,3],[1,8,4],[1,7,5]]\n[2,7,5]", "[[3,4,5],[4,5,6]]\n[3,2,5]", "[[2,5,3],[2,3,4],[1,2,5],[5,2,3]]\n[5,5,5]"], "hints": ["Which triplets do you actually care about?", "What property of max can you use to solve the problem?"], "metadata": {"canonical_parameter_names": ["triplets", "target"], "leetcode_dataset_entry_point": "Solution().mergeTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:23+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function mergeTriplets($triplets, $target) {", "container": "Solution", "callable": "mergeTriplets", "parameters": [{"name": "triplets", "type": "Integer[][]"}, {"name": "target", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1900, "task_id": "the-earliest-and-latest-rounds-where-players-compete", "difficulty": "Hard", "problem_description": "There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).\n\nThe tournament consists of multiple rounds (starting from round number 1). In each round, the i^th player from the front of the row competes against the i^th player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.\n\n- For example, if the row consists of players 1, 2, 4, 6, 7\n - Player 1 competes against player 7.\n - Player 2 competes against player 6.\n - Player 4 automatically advances to the next round.\n\nAfter each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).\n\nThe players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.\n\nGiven the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the latest possible round number in which these two players will compete against each other, respectively.\n\nExample 1:\n\nInput: n = 11, firstPlayer = 2, secondPlayer = 4\nOutput: [3,4]\nExplanation:\nOne possible scenario which leads to the earliest round number:\nFirst round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\nSecond round: 2, 3, 4, 5, 6, 11\nThird round: 2, 3, 4\nOne possible scenario which leads to the latest round number:\nFirst round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\nSecond round: 1, 2, 3, 4, 5, 6\nThird round: 1, 2, 4\nFourth round: 2, 4\n\nExample 2:\n\nInput: n = 5, firstPlayer = 1, secondPlayer = 5\nOutput: [1,1]\nExplanation: The players numbered 1 and 5 compete in the first round.\nThere is no way to make them compete in any other round.\n\nConstraints:\n\n- 2 <= n <= 28\n- 1 <= firstPlayer < secondPlayer <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,firstPlayer = 4,secondPlayer = 9) == [2, 4]\n assert candidate(n = 28,firstPlayer = 5,secondPlayer = 24) == [1, 1]\n assert candidate(n = 16,firstPlayer = 5,secondPlayer = 12) == [1, 1]\n assert candidate(n = 5,firstPlayer = 1,secondPlayer = 5) == [1, 1]\n assert candidate(n = 28,firstPlayer = 10,secondPlayer = 20) == [2, 5]\n assert candidate(n = 8,firstPlayer = 2,secondPlayer = 7) == [1, 1]\n assert candidate(n = 28,firstPlayer = 3,secondPlayer = 26) == [1, 1]\n assert candidate(n = 10,firstPlayer = 3,secondPlayer = 8) == [1, 1]\n assert candidate(n = 7,firstPlayer = 2,secondPlayer = 6) == [1, 1]\n assert candidate(n = 8,firstPlayer = 3,secondPlayer = 6) == [1, 1]\n assert candidate(n = 11,firstPlayer = 2,secondPlayer = 4) == [3, 4]\n assert candidate(n = 16,firstPlayer = 3,secondPlayer = 14) == [1, 1]\n assert candidate(n = 22,firstPlayer = 4,secondPlayer = 19) == [1, 1]\n assert candidate(n = 19,firstPlayer = 1,secondPlayer = 19) == [1, 1]\n assert candidate(n = 15,firstPlayer = 7,secondPlayer = 13) == [2, 4]\n assert candidate(n = 18,firstPlayer = 6,secondPlayer = 13) == [1, 1]\n assert candidate(n = 18,firstPlayer = 5,secondPlayer = 16) == [2, 5]\n assert candidate(n = 27,firstPlayer = 12,secondPlayer = 18) == [2, 5]\n assert candidate(n = 20,firstPlayer = 7,secondPlayer = 16) == [2, 5]\n assert candidate(n = 25,firstPlayer = 10,secondPlayer = 20) == [2, 5]\n assert candidate(n = 20,firstPlayer = 5,secondPlayer = 15) == [2, 5]\n assert candidate(n = 18,firstPlayer = 2,secondPlayer = 17) == [1, 1]\n assert candidate(n = 15,firstPlayer = 2,secondPlayer = 14) == [1, 1]\n assert candidate(n = 19,firstPlayer = 7,secondPlayer = 16) == [2, 5]\n assert candidate(n = 24,firstPlayer = 6,secondPlayer = 19) == [1, 1]\n assert candidate(n = 27,firstPlayer = 8,secondPlayer = 20) == [1, 1]\n assert candidate(n = 19,firstPlayer = 8,secondPlayer = 17) == [2, 5]\n assert candidate(n = 13,firstPlayer = 3,secondPlayer = 10) == [2, 4]\n assert candidate(n = 23,firstPlayer = 10,secondPlayer = 19) == [2, 5]\n assert candidate(n = 28,firstPlayer = 10,secondPlayer = 22) == [2, 5]\n assert candidate(n = 25,firstPlayer = 7,secondPlayer = 19) == [1, 1]\n assert candidate(n = 22,firstPlayer = 7,secondPlayer = 18) == [2, 5]\n assert candidate(n = 20,firstPlayer = 5,secondPlayer = 16) == [1, 1]\n assert candidate(n = 27,firstPlayer = 11,secondPlayer = 23) == [2, 5]\n assert candidate(n = 13,firstPlayer = 4,secondPlayer = 10) == [1, 1]\n assert candidate(n = 19,firstPlayer = 3,secondPlayer = 17) == [1, 1]\n assert candidate(n = 21,firstPlayer = 9,secondPlayer = 18) == [2, 5]\n assert candidate(n = 24,firstPlayer = 10,secondPlayer = 23) == [2, 5]\n assert candidate(n = 22,firstPlayer = 7,secondPlayer = 17) == [3, 5]\n assert candidate(n = 15,firstPlayer = 7,secondPlayer = 9) == [1, 1]\n assert candidate(n = 27,firstPlayer = 9,secondPlayer = 20) == [3, 5]\n assert candidate(n = 24,firstPlayer = 10,secondPlayer = 15) == [1, 1]\n assert candidate(n = 24,firstPlayer = 8,secondPlayer = 17) == [1, 1]\n assert candidate(n = 18,firstPlayer = 6,secondPlayer = 15) == [2, 5]\n assert candidate(n = 24,firstPlayer = 9,secondPlayer = 15) == [2, 5]\n assert candidate(n = 23,firstPlayer = 9,secondPlayer = 15) == [1, 1]\n assert candidate(n = 12,firstPlayer = 5,secondPlayer = 8) == [1, 1]\n assert candidate(n = 25,firstPlayer = 7,secondPlayer = 18) == [2, 5]\n assert candidate(n = 25,firstPlayer = 2,secondPlayer = 24) == [1, 1]\n assert candidate(n = 27,firstPlayer = 12,secondPlayer = 24) == [2, 5]\n assert candidate(n = 15,firstPlayer = 3,secondPlayer = 13) == [1, 1]\n assert candidate(n = 21,firstPlayer = 6,secondPlayer = 16) == [1, 1]\n assert candidate(n = 19,firstPlayer = 4,secondPlayer = 18) == [2, 4]\n assert candidate(n = 22,firstPlayer = 6,secondPlayer = 19) == [2, 5]\n assert candidate(n = 28,firstPlayer = 2,secondPlayer = 27) == [1, 1]\n assert candidate(n = 25,firstPlayer = 4,secondPlayer = 22) == [1, 1]\n assert candidate(n = 13,firstPlayer = 3,secondPlayer = 11) == [1, 1]\n assert candidate(n = 13,firstPlayer = 3,secondPlayer = 9) == [2, 4]\n assert candidate(n = 28,firstPlayer = 1,secondPlayer = 28) == [1, 1]\n assert candidate(n = 23,firstPlayer = 11,secondPlayer = 20) == [2, 5]\n assert candidate(n = 17,firstPlayer = 3,secondPlayer = 15) == [1, 1]\n assert candidate(n = 14,firstPlayer = 3,secondPlayer = 10) == [2, 4]\n assert candidate(n = 12,firstPlayer = 3,secondPlayer = 9) == [2, 4]\n assert candidate(n = 25,firstPlayer = 8,secondPlayer = 19) == [2, 5]\n assert candidate(n = 28,firstPlayer = 12,secondPlayer = 18) == [2, 5]\n assert candidate(n = 22,firstPlayer = 9,secondPlayer = 14) == [1, 1]\n assert candidate(n = 24,firstPlayer = 9,secondPlayer = 21) == [2, 5]\n assert candidate(n = 19,firstPlayer = 9,secondPlayer = 17) == [2, 5]\n assert candidate(n = 17,firstPlayer = 4,secondPlayer = 15) == [2, 4]\n assert candidate(n = 19,firstPlayer = 6,secondPlayer = 14) == [1, 1]\n assert candidate(n = 21,firstPlayer = 7,secondPlayer = 15) == [1, 1]\n assert candidate(n = 27,firstPlayer = 2,secondPlayer = 25) == [3, 3]\n assert candidate(n = 17,firstPlayer = 6,secondPlayer = 12) == [1, 1]\n assert candidate(n = 17,firstPlayer = 5,secondPlayer = 13) == [1, 1]\n assert candidate(n = 18,firstPlayer = 4,secondPlayer = 15) == [1, 1]\n assert candidate(n = 21,firstPlayer = 10,secondPlayer = 12) == [1, 1]\n assert candidate(n = 15,firstPlayer = 4,secondPlayer = 11) == [3, 4]\n assert candidate(n = 21,firstPlayer = 6,secondPlayer = 19) == [2, 5]\n assert candidate(n = 19,firstPlayer = 8,secondPlayer = 15) == [2, 5]\n assert candidate(n = 20,firstPlayer = 7,secondPlayer = 14) == [1, 1]\n assert candidate(n = 25,firstPlayer = 8,secondPlayer = 20) == [2, 5]\n assert candidate(n = 27,firstPlayer = 4,secondPlayer = 23) == [3, 5]\n assert candidate(n = 20,firstPlayer = 3,secondPlayer = 18) == [1, 1]\n assert candidate(n = 26,firstPlayer = 13,secondPlayer = 22) == [2, 5]\n assert candidate(n = 18,firstPlayer = 5,secondPlayer = 14) == [1, 1]\n assert candidate(n = 21,firstPlayer = 6,secondPlayer = 15) == [3, 5]\n assert candidate(n = 28,firstPlayer = 10,secondPlayer = 25) == [2, 5]\n", "comparison": "exact"}, "public_tests": ["11\n2\n4", "5\n1\n5"], "hints": ["Brute force using bitmasks and simulate the rounds.", "Calculate each state one time and save its solution."], "metadata": {"canonical_parameter_names": ["n", "firstPlayer", "secondPlayer"], "leetcode_dataset_entry_point": "Solution().earliestAndLatest", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:25+00:00", "tests_total": 87, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming", "memoization"]}, "language": "php", "interface": {"raw_signature": "function earliestAndLatest($n, $firstPlayer, $secondPlayer) {", "container": "Solution", "callable": "earliestAndLatest", "parameters": [{"name": "n", "type": "Integer"}, {"name": "firstPlayer", "type": "Integer"}, {"name": "secondPlayer", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1901, "task_id": "find-a-peak-element-ii", "difficulty": "Medium", "problem_description": "A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.\n\nGiven a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].\n\nYou may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.\n\nYou must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.\n\nExample 1:\n\nInput: mat = [[1,4],[3,2]]\nOutput: [0,1]\nExplanation: Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.\n\nExample 2:\n\nInput: mat = [[10,20,15],[21,30,14],[7,16,32]]\nOutput: [1,1]\nExplanation: Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.\n\nConstraints:\n\n- m == mat.length\n- n == mat[i].length\n- 1 <= m, n <= 500\n- 1 <= mat[i][j] <= 10^5\n- No two adjacent cells are equal.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1]]) == [0, 0]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]]) == [2, 2]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 24, 25, 6], [7, 8, 9, 10, 11], [12, 13, 14, 15, 18]]) == [1, 3]\n assert candidate(mat = [[10, 20, 15], [21, 30, 14], [7, 16, 32]]) == [1, 1]\n assert candidate(mat = [[1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 60]]) == [2, 3]\n assert candidate(mat = [[1, 4], [3, 2]]) == [0, 1]\n assert candidate(mat = [[5, 25, 15, 10], [100, 101, 102, 103], [99, 98, 97, 96], [50, 49, 48, 47]]) == [1, 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], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]]) == [2, 9]\n assert candidate(mat = [[1, 10, 20, 10, 1], [10, 20, 30, 20, 10], [20, 30, 40, 30, 20], [10, 20, 30, 20, 10], [1, 10, 20, 10, 1]]) == [2, 2]\n assert candidate(mat = [[1, 5, 9, 12], [10, 20, 25, 16], [8, 18, 24, 13], [7, 17, 19, 21]]) == [1, 2]\n assert candidate(mat = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [9, 21, 29, 39, 49, 59, 69, 79, 89, 101], [8, 22, 28, 38, 48, 58, 68, 78, 88, 102], [7, 23, 27, 37, 47, 57, 67, 77, 87, 103], [6, 24, 26, 36, 46, 56, 66, 76, 86, 104], [5, 25, 25, 35, 45, 55, 65, 75, 85, 105], [4, 26, 24, 34, 44, 54, 64, 74, 84, 106], [3, 27, 23, 33, 43, 53, 63, 73, 83, 107], [2, 28, 22, 32, 42, 52, 62, 72, 82, 108], [1, 29, 21, 31, 41, 51, 61, 71, 81, 109]]) == [9, 9]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [8, 7, 6, 5, 4, 3, 2, 1, 10], [9, 10, 11, 12, 13, 14, 15, 16, 17], [16, 15, 14, 13, 12, 11, 10, 9, 18], [19, 20, 21, 22, 23, 24, 25, 26, 27], [26, 25, 24, 23, 22, 21, 20, 19, 28], [29, 30, 31, 32, 33, 34, 35, 36, 37]]) == [6, 8]\n assert candidate(mat = [[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]]) == [0, 0]\n assert candidate(mat = [[30, 27, 24, 21, 18, 15], [29, 26, 23, 20, 17, 14], [28, 25, 22, 19, 16, 13], [27, 24, 21, 18, 15, 12], [26, 23, 20, 17, 14, 11], [25, 22, 19, 16, 13, 10]]) == [0, 0]\n assert candidate(mat = [[100000, 99999, 99998], [99997, 99996, 99995], [99994, 99993, 99992], [99991, 99990, 99989], [99988, 99987, 99986]]) == [0, 0]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) == [2, 4]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [15, 16, 17, 18, 19, 7], [14, 23, 24, 25, 20, 8], [13, 22, 31, 32, 21, 9], [12, 21, 30, 33, 22, 10], [11, 20, 29, 28, 27, 16]]) == [4, 3]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [25, 26, 27, 28, 29, 30, 31, 32, 10], [24, 39, 40, 41, 42, 43, 44, 33, 11], [23, 38, 51, 52, 53, 54, 45, 34, 12], [22, 37, 50, 59, 60, 55, 46, 35, 13], [21, 36, 49, 58, 61, 56, 47, 36, 14], [20, 35, 48, 57, 62, 50, 40, 30, 15], [19, 34, 47, 56, 63, 49, 39, 29, 16], [18, 33, 46, 55, 64, 48, 38, 28, 17]]) == [8, 4]\n assert candidate(mat = [[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], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]]) == [2, 19]\n assert candidate(mat = [[50, 1, 100, 200, 300, 400, 500], [600, 501, 101, 201, 301, 401, 501], [601, 602, 102, 202, 302, 402, 502], [603, 604, 103, 203, 303, 403, 503], [604, 605, 104, 204, 304, 404, 504], [605, 606, 105, 205, 305, 405, 505]]) == [5, 1]\n assert candidate(mat = [[3, 8, 4, 5, 7], [2, 9, 6, 10, 3], [5, 7, 11, 12, 8], [1, 6, 9, 13, 4]]) == [3, 3]\n assert candidate(mat = [[100, 101, 102, 103, 104], [109, 108, 107, 106, 105], [110, 111, 112, 113, 114], [119, 118, 117, 116, 115]]) == [3, 0]\n assert candidate(mat = [[5, 25, 20], [15, 30, 21], [10, 19, 22], [14, 28, 27], [9, 23, 24]]) == [3, 1]\n assert candidate(mat = [[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]]) == [0, 24]\n assert candidate(mat = [[1, 3, 5, 7, 9], [10, 8, 6, 4, 2], [3, 5, 7, 9, 11], [12, 10, 8, 6, 4], [5, 7, 9, 11, 13]]) == [0, 4]\n assert candidate(mat = [[100, 200, 300, 400], [150, 250, 350, 450], [125, 225, 325, 425], [175, 275, 375, 475]]) == [1, 3]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [18, 17, 16, 15, 14, 13, 12, 11, 10], [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]]) == [4, 8]\n assert candidate(mat = [[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]]) == [4, 0]\n assert candidate(mat = [[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]]) == [2, 4]\n assert candidate(mat = [[1, 3, 5, 7, 9, 11], [12, 14, 16, 18, 20, 19], [13, 15, 17, 19, 21, 22], [25, 24, 23, 22, 21, 20], [26, 27, 28, 29, 30, 31]]) == [2, 5]\n assert candidate(mat = [[1, 3, 5, 7, 9, 11, 13], [2, 4, 6, 8, 10, 12, 14], [3, 5, 7, 9, 11, 13, 15], [4, 6, 8, 10, 12, 14, 16], [5, 7, 9, 11, 13, 15, 17]]) == [4, 6]\n assert candidate(mat = [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9], [26, 27, 28, 29, 30]]) == [2, 2]\n assert candidate(mat = [[5, 2, 1, 6, 7, 8, 10, 4, 9, 1], [15, 14, 13, 16, 17, 18, 20, 19, 21, 2], [22, 23, 24, 25, 26, 27, 28, 29, 30, 31]]) == [2, 9]\n assert candidate(mat = [[1, 2, 3], [6, 5, 4], [7, 8, 9]]) == [2, 2]\n assert candidate(mat = [[5, 25, 9, 20, 15], [30, 35, 28, 33, 26], [29, 40, 31, 36, 27], [24, 39, 32, 37, 34], [23, 38, 21, 22, 16]]) == [2, 1]\n assert candidate(mat = [[20, 30, 25, 10, 15], [100, 120, 115, 80, 85], [75, 82, 87, 55, 60], [65, 70, 67, 78, 77]]) == [1, 1]\n assert candidate(mat = [[10, 100, 1000], [9, 99, 999], [8, 88, 888], [7, 77, 777], [6, 66, 666], [5, 55, 555], [4, 44, 444], [3, 33, 333], [2, 22, 222], [1, 11, 111]]) == [0, 2]\n assert candidate(mat = [[2, 1, 3, 4, 5, 6, 7, 8, 9], [1, 1, 1, 1, 1, 1, 1, 1, 1], [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]]) == [2, 0]\n assert candidate(mat = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == [9, 0]\n assert candidate(mat = [[5, 2, 15, 10, 20], [6, 21, 16, 14, 19], [7, 17, 25, 23, 18], [8, 18, 24, 30, 22], [9, 29, 26, 27, 31]]) == [0, 4]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [1, 0]\n assert candidate(mat = [[5, 10, 15, 20, 25], [9, 14, 19, 24, 29], [13, 18, 23, 28, 33], [17, 22, 27, 32, 37], [21, 26, 31, 36, 41]]) == [4, 4]\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, 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]]) == [0, 9]\n assert candidate(mat = [[50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [100, 101, 102, 103, 104, 105, 106, 107, 108, 109], [99, 98, 97, 96, 95, 94, 93, 92, 91, 90], [80, 81, 82, 83, 84, 85, 86, 87, 88, 89], [79, 78, 77, 76, 75, 74, 73, 72, 71, 70], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69], [59, 58, 57, 56, 55, 54, 53, 52, 51, 50], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49], [39, 38, 37, 36, 35, 34, 33, 32, 31, 30]]) == [1, 9]\n assert candidate(mat = [[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13], [17, 18, 19, 20]]) == [4, 3]\n assert candidate(mat = [[9, 8, 7, 6], [8, 7, 6, 5], [7, 6, 5, 4], [6, 5, 4, 3], [5, 4, 3, 2]]) == [0, 0]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6], [20, 19, 18, 17, 16, 15], [21, 22, 23, 24, 25, 26], [32, 31, 30, 29, 28, 27], [33, 34, 35, 36, 37, 38], [44, 43, 42, 41, 40, 39]]) == [5, 0]\n assert candidate(mat = [[10, 100, 30, 200, 40, 300], [9, 190, 25, 210, 35, 310], [18, 180, 27, 220, 45, 320], [17, 170, 26, 230, 44, 330], [16, 160, 24, 240, 43, 340], [15, 150, 23, 250, 42, 350]]) == [5, 5]\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]]) == [4, 4]\n assert candidate(mat = [[50, 49, 48, 47, 46, 45, 44, 43, 42, 41], [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]]) == [4, 9]\n assert candidate(mat = [[1, 10, 8, 11, 9], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 15]]) == [2, 2]\n assert candidate(mat = [[1, 100, 200, 300, 400, 500], [600, 501, 502, 503, 504, 505], [700, 601, 701, 702, 703, 704], [800, 701, 801, 802, 803, 804], [900, 801, 901, 902, 903, 904]]) == [4, 5]\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, 31, 32, 33, 34, 35, 36, 37, 38, 39], [49, 48, 47, 46, 45, 44, 43, 42, 41, 40]]) == [3, 0]\n assert candidate(mat = [[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]]) == [0, 0]\n assert candidate(mat = [[30, 28, 19, 27, 22], [25, 31, 26, 23, 21], [24, 29, 32, 20, 18], [17, 22, 21, 16, 15], [13, 14, 12, 11, 10]]) == [0, 0]\n assert candidate(mat = [[100, 101, 102, 103, 104, 105], [99, 106, 107, 108, 109, 110], [98, 111, 112, 113, 114, 115], [97, 116, 117, 118, 119, 120], [96, 121, 122, 123, 124, 125], [95, 126, 127, 128, 129, 130]]) == [5, 5]\n assert candidate(mat = [[5, 3, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15], [19, 18, 17, 16, 23, 22], [27, 28, 29, 30, 25, 24], [34, 33, 32, 31, 38, 37], [43, 42, 41, 40, 47, 46]]) == [5, 4]\n assert candidate(mat = [[1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1]]) == [3, 0]\n assert candidate(mat = [[1, 3, 2], [4, 6, 5], [7, 9, 8], [10, 12, 11], [13, 15, 14]]) == [4, 1]\n assert candidate(mat = [[1, 5, 7, 4, 6], [9, 8, 2, 1, 3], [12, 15, 13, 11, 10], [17, 18, 16, 20, 21]]) == [3, 4]\n assert candidate(mat = [[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, 5, 7, 9, 11, 13, 15, 17, 19, 21]]) == [0, 9]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [0, 19]\n assert candidate(mat = [[10, 20, 30, 40, 50, 60, 70], [70, 60, 50, 40, 30, 20, 10], [10, 30, 50, 70, 90, 110, 130], [130, 110, 90, 70, 50, 30, 10]]) == [0, 6]\n assert candidate(mat = [[100, 200, 300, 400], [400, 300, 200, 100], [100, 200, 300, 400], [400, 300, 200, 100]]) == [0, 3]\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, 46, 47, 48, 49, 50]]) == [4, 9]\n assert candidate(mat = [[1, 5, 9, 4], [6, 7, 3, 8], [2, 11, 13, 12], [10, 14, 15, 16]]) == [3, 3]\n assert candidate(mat = [[5, 20, 15, 25], [9, 10, 12, 8], [14, 6, 30, 7], [13, 16, 11, 18]]) == [2, 2]\n assert candidate(mat = [[10, 20, 30, 40, 50, 60], [61, 62, 63, 64, 65, 59], [70, 69, 68, 67, 66, 71], [72, 73, 74, 75, 76, 77], [78, 79, 80, 81, 82, 83]]) == [4, 5]\n assert candidate(mat = [[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]]) == [0, 0]\n assert candidate(mat = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [12, 11, 10]]) == [3, 0]\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]]) == [6, 2]\n assert candidate(mat = [[100, 200, 300, 400, 500, 600, 700, 800, 900], [901, 801, 701, 601, 501, 401, 301, 201, 101], [102, 202, 302, 402, 502, 602, 702, 802, 902], [903, 803, 703, 603, 503, 403, 303, 203, 103], [104, 204, 304, 404, 504, 604, 704, 804, 904], [905, 805, 705, 605, 505, 405, 305, 205, 105], [106, 206, 306, 406, 506, 606, 706, 806, 906], [907, 807, 707, 607, 507, 407, 307, 207, 107]]) == [0, 8]\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]]) == [0, 4]\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2]]) == [0, 8]\n assert candidate(mat = [[100, 200, 300, 400, 500], [501, 502, 503, 504, 505], [1000, 1001, 1002, 1003, 1004], [1501, 1502, 1503, 1504, 1505], [2000, 2001, 2002, 2003, 2004]]) == [4, 4]\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]]) == [4, 4]\n assert candidate(mat = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == [9, 0]\n assert candidate(mat = [[10, 11, 12, 13, 14, 15, 16], [9, 8, 7, 6, 5, 4, 3], [2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7]]) == [0, 6]\n assert candidate(mat = [[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], [35, 45, 55, 65, 75]]) == [5, 4]\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]]) == [4, 4]\n assert candidate(mat = [[1, 1000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [0, 1]\n assert candidate(mat = [[10, 20, 30, 40, 50, 60], [5, 15, 25, 35, 45, 55], [40, 50, 60, 70, 80, 90], [35, 45, 55, 65, 75, 85], [25, 35, 45, 55, 65, 75], [15, 25, 35, 45, 55, 65]]) == [2, 5]\n assert candidate(mat = [[5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]) == [4, 4]\n assert candidate(mat = [[5, 20, 3, 5, 6], [21, 22, 23, 24, 5], [1, 2, 3, 25, 26], [17, 18, 19, 28, 29], [30, 31, 32, 33, 34]]) == [4, 4]\n assert candidate(mat = [[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]]) == [0, 0]\n", "comparison": "exact"}, "public_tests": ["[[1,4],[3,2]]", "[[10,20,15],[21,30,14],[7,16,32]]"], "hints": ["Let's assume that the width of the array is bigger than the height, otherwise, we will split in another direction.", "Split the array into three parts: central column left side and right side.", "Go through the central column and two neighbor columns and look for maximum.", "If it's in the central column - this is our peak.", "If it's on the left side, run this algorithm on subarray left_side + central_column.", "If it's on the right side, run this algorithm on subarray right_side + central_column"], "metadata": {"canonical_parameter_names": ["mat"], "leetcode_dataset_entry_point": "Solution().findPeakGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:27+00:00", "tests_total": 85, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "matrix"]}, "language": "php", "interface": {"raw_signature": "function findPeakGrid($mat) {", "container": "Solution", "callable": "findPeakGrid", "parameters": [{"name": "mat", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1903, "task_id": "largest-odd-number-in-string", "difficulty": "Easy", "problem_description": "You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string \"\" if no odd integer exists.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: num = \"52\"\nOutput: \"5\"\nExplanation: The only non-empty substrings are \"5\", \"2\", and \"52\". \"5\" is the only odd number.\n\nExample 2:\n\nInput: num = \"4206\"\nOutput: \"\"\nExplanation: There are no odd numbers in \"4206\".\n\nExample 3:\n\nInput: num = \"35427\"\nOutput: \"35427\"\nExplanation: \"35427\" is already an odd number.\n\nConstraints:\n\n- 1 <= num.length <= 10^5\n- num only consists of digits and does not contain any leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"52\") == \"5\"\n assert candidate(num = \"9\") == \"9\"\n assert candidate(num = \"86420\") == \"\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"2468\") == \"\"\n assert candidate(num = \"1\") == \"1\"\n assert candidate(num = \"9876543210\") == \"987654321\"\n assert candidate(num = \"0\") == \"\"\n assert candidate(num = \"98765\") == \"98765\"\n assert candidate(num = \"2468013579\") == \"2468013579\"\n assert candidate(num = \"2222222222\") == \"\"\n assert candidate(num = \"8\") == \"\"\n assert candidate(num = \"987654321\") == \"987654321\"\n assert candidate(num = \"2\") == \"\"\n assert candidate(num = \"56789\") == \"56789\"\n assert candidate(num = \"321\") == \"321\"\n assert candidate(num = \"123\") == \"123\"\n assert candidate(num = \"1357924680\") == \"13579\"\n assert candidate(num = \"4206\") == \"\"\n assert candidate(num = \"123456789\") == \"123456789\"\n assert candidate(num = \"35427\") == \"35427\"\n assert candidate(num = \"24680\") == \"\"\n assert candidate(num = \"1234567890\") == \"123456789\"\n assert candidate(num = \"24681\") == \"24681\"\n assert candidate(num = \"11111\") == \"11111\"\n assert candidate(num = \"13579\") == \"13579\"\n assert candidate(num = \"13579135791357913577\") == \"13579135791357913577\"\n assert candidate(num = \"98765432109876543210\") == \"9876543210987654321\"\n assert candidate(num = \"10000000000000000000000000000000000000000000000002\") == \"1\"\n assert candidate(num = \"246802468024680246802468024680246802468024680\") == \"\"\n assert candidate(num = \"02468\") == \"\"\n assert candidate(num = \"9012345678\") == \"901234567\"\n assert candidate(num = \"0000000000\") == \"\"\n assert candidate(num = \"111222333444555\") == \"111222333444555\"\n assert candidate(num = \"135791357913579135791357913579135791357913579\") == \"135791357913579135791357913579135791357913579\"\n assert candidate(num = \"2468101214161820\") == \"2468101214161\"\n assert candidate(num = \"50505050505050505055\") == \"50505050505050505055\"\n assert candidate(num = \"902468013579\") == \"902468013579\"\n assert candidate(num = \"99999999999999999998\") == \"9999999999999999999\"\n assert candidate(num = \"987654321987654321987654321987654321987654321\") == \"987654321987654321987654321987654321987654321\"\n assert candidate(num = \"13579111315\") == \"13579111315\"\n assert candidate(num = \"0246802468024680246802468024680246802468024680\") == \"\"\n assert candidate(num = \"1234567890123456789012345678901234567890123456789\") == \"1234567890123456789012345678901234567890123456789\"\n assert candidate(num = \"1111111111111111111111111111111111111111111111111\") == \"1111111111111111111111111111111111111111111111111\"\n assert candidate(num = \"123456789012345678901\") == \"123456789012345678901\"\n assert candidate(num = \"246802468024680246805\") == \"246802468024680246805\"\n assert candidate(num = \"1000000000000000000000000000000000000000000000000\") == \"1\"\n assert candidate(num = \"5000000000000000000000000000000000000000000000003\") == \"5000000000000000000000000000000000000000000000003\"\n assert candidate(num = \"987654320\") == \"9876543\"\n assert candidate(num = \"111111111111111111111111111111111111111111111111\") == \"111111111111111111111111111111111111111111111111\"\n assert candidate(num = \"8642086420\") == \"\"\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"8080808080808080808080808080808080808080808080807\") == \"8080808080808080808080808080808080808080808080807\"\n assert candidate(num = \"1000000000000000000000000000000000000000000000001\") == \"1000000000000000000000000000000000000000000000001\"\n assert candidate(num = \"2468012345\") == \"2468012345\"\n assert candidate(num = \"0246802468\") == \"\"\n assert candidate(num = \"124\") == \"1\"\n assert candidate(num = \"246802468024680246802468024680\") == \"\"\n assert candidate(num = \"1000000000100000000010000000001000000000100000001\") == \"1000000000100000000010000000001000000000100000001\"\n assert candidate(num = \"1919191919191919191919191919191919191919191919\") == \"1919191919191919191919191919191919191919191919\"\n assert candidate(num = \"2000000002000000002\") == \"\"\n assert candidate(num = \"9999999998\") == \"999999999\"\n assert candidate(num = \"87654321\") == \"87654321\"\n assert candidate(num = \"10000000000000000001\") == \"10000000000000000001\"\n assert candidate(num = \"1357997531\") == \"1357997531\"\n assert candidate(num = \"987654321987654321987654321987654321987654321987654321\") == \"987654321987654321987654321987654321987654321987654321\"\n assert candidate(num = \"00000000000000000001\") == \"00000000000000000001\"\n assert candidate(num = \"987654321987654321987654321\") == \"987654321987654321987654321\"\n assert candidate(num = \"9999999999999999999999999999999999999999999999998\") == \"999999999999999999999999999999999999999999999999\"\n assert candidate(num = \"246801357924680\") == \"2468013579\"\n assert candidate(num = \"11111111111111111112\") == \"1111111111111111111\"\n assert candidate(num = \"20000000000000000000000000000000000000000000000002\") == \"\"\n assert candidate(num = \"13579111315171921\") == \"13579111315171921\"\n assert candidate(num = \"864200000\") == \"\"\n assert candidate(num = \"13579135791357913579\") == \"13579135791357913579\"\n assert candidate(num = \"2020202020202020202020202020202020202020202020\") == \"\"\n assert candidate(num = \"1001001001001001001001001001001001001001001001001\") == \"1001001001001001001001001001001001001001001001001\"\n assert candidate(num = \"24680246802468024689\") == \"24680246802468024689\"\n assert candidate(num = \"246810\") == \"24681\"\n assert candidate(num = \"999999999999999999\") == \"999999999999999999\"\n assert candidate(num = \"12345678909876543210\") == \"1234567890987654321\"\n assert candidate(num = \"99999999999999999999\") == \"99999999999999999999\"\n assert candidate(num = \"0123456789\") == \"0123456789\"\n assert candidate(num = \"1234567890123456789\") == \"1234567890123456789\"\n assert candidate(num = \"9876543210987654321098765432109876543210987654321\") == \"9876543210987654321098765432109876543210987654321\"\n assert candidate(num = \"101010101010101010101010101010101010101010101010101\") == \"101010101010101010101010101010101010101010101010101\"\n assert candidate(num = \"00000000000000000000000000000000000000000000000\") == \"\"\n assert candidate(num = \"2468024680246802468024680246802468024680246802468\") == \"\"\n assert candidate(num = \"9876543219\") == \"9876543219\"\n assert candidate(num = \"9876543210987654321098765432109876543210\") == \"987654321098765432109876543210987654321\"\n assert candidate(num = \"12345678901\") == \"12345678901\"\n assert candidate(num = \"2999999999999999999999999999999999999999999999998\") == \"299999999999999999999999999999999999999999999999\"\n assert candidate(num = \"999999999\") == \"999999999\"\n assert candidate(num = \"98765432101234567890\") == \"9876543210123456789\"\n assert candidate(num = \"11223344556677889900\") == \"112233445566778899\"\n assert candidate(num = \"543210987654321098765432109876543210987654321\") == \"543210987654321098765432109876543210987654321\"\n assert candidate(num = \"13579135791357913578\") == \"1357913579135791357\"\n assert candidate(num = \"100000000000000000001\") == \"100000000000000000001\"\n assert candidate(num = \"555555555555555555555555555555555555555555555555\") == \"555555555555555555555555555555555555555555555555\"\n assert candidate(num = \"123456789012345678902\") == \"1234567890123456789\"\n assert candidate(num = \"111222333444555666777888999\") == \"111222333444555666777888999\"\n assert candidate(num = \"864208642086420\") == \"\"\n assert candidate(num = \"024680246802468\") == \"\"\n assert candidate(num = \"9999999999\") == \"9999999999\"\n assert candidate(num = \"135791357913579135791357913579\") == \"135791357913579135791357913579\"\n assert candidate(num = \"9999999999999999999999999999999999999999999999999\") == \"9999999999999999999999999999999999999999999999999\"\n assert candidate(num = \"86420864208642086420\") == \"\"\n assert candidate(num = \"98765432109876543211\") == \"98765432109876543211\"\n assert candidate(num = \"01234567890123456789\") == \"01234567890123456789\"\n assert candidate(num = \"10000000000000000000\") == \"1\"\n assert candidate(num = \"1000000001\") == \"1000000001\"\n assert candidate(num = \"1999999999999999999999999999999999999999999999999\") == \"1999999999999999999999999999999999999999999999999\"\n assert candidate(num = \"24680246802468024680\") == \"\"\n assert candidate(num = \"222222222222222222222222222222222222222222222222\") == \"\"\n assert candidate(num = \"135790\") == \"13579\"\n assert candidate(num = \"8642097531\") == \"8642097531\"\n assert candidate(num = \"10000000000000000000000000000000000000000000000001\") == \"10000000000000000000000000000000000000000000000001\"\n assert candidate(num = \"123456789012345678901234567890\") == \"12345678901234567890123456789\"\n assert candidate(num = \"12345678901234567891\") == \"12345678901234567891\"\n assert candidate(num = \"1357913579135791357913579135791357913579135791357\") == \"1357913579135791357913579135791357913579135791357\"\n assert candidate(num = \"12345678901234567890123456789012345678901234567890\") == \"1234567890123456789012345678901234567890123456789\"\n assert candidate(num = \"246802468024680\") == \"\"\n assert candidate(num = \"987654321987654321\") == \"987654321987654321\"\n assert candidate(num = \"2222222222222222222222222222222222222222222222221\") == \"2222222222222222222222222222222222222222222222221\"\n assert candidate(num = \"9876543210987654321\") == \"9876543210987654321\"\n assert candidate(num = \"2222222222222222222222222222222222222222222222222\") == \"\"\n assert candidate(num = \"00000000000000000000\") == \"\"\n assert candidate(num = \"135791113151719\") == \"135791113151719\"\n assert candidate(num = \"987654321098765432\") == \"98765432109876543\"\n assert candidate(num = \"135791113151719111\") == \"135791113151719111\"\n assert candidate(num = \"11111111111111111111\") == \"11111111111111111111\"\n assert candidate(num = \"998877665544332211\") == \"998877665544332211\"\n assert candidate(num = \"12345678901234567890\") == \"1234567890123456789\"\n assert candidate(num = \"135791357913579\") == \"135791357913579\"\n assert candidate(num = \"09876543210987654321\") == \"09876543210987654321\"\n assert candidate(num = \"22222222221\") == \"22222222221\"\n assert candidate(num = \"10000000000000000000000000000000000000000001\") == \"10000000000000000000000000000000000000000001\"\n assert candidate(num = \"1357913579\") == \"1357913579\"\n assert candidate(num = \"22222222222222222222\") == \"\"\n assert candidate(num = \"9999999999999999999999999999999999999999998\") == \"999999999999999999999999999999999999999999\"\n", "comparison": "exact"}, "public_tests": ["\"52\"", "\"4206\"", "\"35427\""], "hints": ["In what order should you iterate through the digits?", "If an odd number exists, where must the number start from?"], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().largestOddNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:32+00:00", "tests_total": 140, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function largestOddNumber($num) {", "container": "Solution", "callable": "largestOddNumber", "parameters": [{"name": "num", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1904, "task_id": "the-number-of-full-rounds-you-have-played", "difficulty": "Medium", "problem_description": "You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.\n\n- For example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.\n\nYou are given two strings loginTime and logoutTime where:\n\n- loginTime is the time you will login to the game, and\n- logoutTime is the time you will logout from the game.\n\nIf logoutTime is earlier than loginTime, this means you have played from loginTime to midnight and from midnight to logoutTime.\n\nReturn the number of full chess rounds you have played in the tournament.\n\nNote: All the given times follow the 24-hour clock. That means the first round of the day starts at 00:00 and the last round of the day starts at 23:45.\n\nExample 1:\n\nInput: loginTime = \"09:31\", logoutTime = \"10:14\"\nOutput: 1\nExplanation: You played one full round from 09:45 to 10:00.\nYou did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.\nYou did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.\n\nExample 2:\n\nInput: loginTime = \"21:30\", logoutTime = \"03:00\"\nOutput: 22\nExplanation: You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.\n10 + 12 = 22.\n\nConstraints:\n\n- loginTime and logoutTime are in the format hh:mm.\n- 00 <= hh <= 23\n- 00 <= mm <= 59\n- loginTime and logoutTime are not equal.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(loginTime = \"11:59\",logoutTime = \"12:01\") == 0\n assert candidate(loginTime = \"14:30\",logoutTime = \"15:30\") == 4\n assert candidate(loginTime = \"00:01\",logoutTime = \"00:14\") == 0\n assert candidate(loginTime = \"14:20\",logoutTime = \"15:50\") == 5\n assert candidate(loginTime = \"00:00\",logoutTime = \"23:59\") == 95\n assert candidate(loginTime = \"18:14\",logoutTime = \"18:46\") == 2\n assert candidate(loginTime = \"14:30\",logoutTime = \"14:45\") == 1\n assert candidate(loginTime = \"23:45\",logoutTime = \"00:15\") == 2\n assert candidate(loginTime = \"22:15\",logoutTime = \"23:45\") == 6\n assert candidate(loginTime = \"15:30\",logoutTime = \"15:30\") == 0\n assert candidate(loginTime = \"14:20\",logoutTime = \"14:59\") == 1\n assert candidate(loginTime = \"05:45\",logoutTime = \"06:00\") == 1\n assert candidate(loginTime = \"09:31\",logoutTime = \"10:14\") == 1\n assert candidate(loginTime = \"00:01\",logoutTime = \"23:59\") == 94\n assert candidate(loginTime = \"07:45\",logoutTime = \"08:00\") == 1\n assert candidate(loginTime = \"11:59\",logoutTime = \"12:00\") == 0\n assert candidate(loginTime = \"23:45\",logoutTime = \"00:00\") == 1\n assert candidate(loginTime = \"05:00\",logoutTime = \"06:00\") == 4\n assert candidate(loginTime = \"01:10\",logoutTime = \"01:55\") == 2\n assert candidate(loginTime = \"01:15\",logoutTime = \"01:45\") == 2\n assert candidate(loginTime = \"07:15\",logoutTime = \"07:30\") == 1\n assert candidate(loginTime = \"01:05\",logoutTime = \"01:40\") == 1\n assert candidate(loginTime = \"21:30\",logoutTime = \"03:00\") == 22\n assert candidate(loginTime = \"13:00\",logoutTime = \"13:01\") == 0\n assert candidate(loginTime = \"12:00\",logoutTime = \"12:15\") == 1\n assert candidate(loginTime = \"05:30\",logoutTime = \"06:00\") == 2\n assert candidate(loginTime = \"08:45\",logoutTime = \"09:00\") == 1\n assert candidate(loginTime = \"01:00\",logoutTime = \"02:30\") == 6\n assert candidate(loginTime = \"18:15\",logoutTime = \"18:44\") == 1\n assert candidate(loginTime = \"10:15\",logoutTime = \"11:14\") == 3\n assert candidate(loginTime = \"19:10\",logoutTime = \"20:50\") == 6\n assert candidate(loginTime = \"07:00\",logoutTime = \"07:01\") == 0\n assert candidate(loginTime = \"12:16\",logoutTime = \"12:44\") == 0\n assert candidate(loginTime = \"20:44\",logoutTime = \"21:00\") == 1\n assert candidate(loginTime = \"12:30\",logoutTime = \"14:45\") == 9\n assert candidate(loginTime = \"11:15\",logoutTime = \"11:16\") == 0\n assert candidate(loginTime = \"14:30\",logoutTime = \"14:30\") == 0\n assert candidate(loginTime = \"18:45\",logoutTime = \"19:45\") == 4\n assert candidate(loginTime = \"18:00\",logoutTime = \"07:00\") == 52\n assert candidate(loginTime = \"07:15\",logoutTime = \"07:15\") == 0\n assert candidate(loginTime = \"08:15\",logoutTime = \"08:30\") == 1\n assert candidate(loginTime = \"02:10\",logoutTime = \"05:50\") == 14\n assert candidate(loginTime = \"08:25\",logoutTime = \"09:50\") == 5\n assert candidate(loginTime = \"01:00\",logoutTime = \"01:14\") == 0\n assert candidate(loginTime = \"12:30\",logoutTime = \"13:15\") == 3\n assert candidate(loginTime = \"03:45\",logoutTime = \"05:10\") == 5\n assert candidate(loginTime = \"06:30\",logoutTime = \"06:30\") == 0\n assert candidate(loginTime = \"17:45\",logoutTime = \"18:00\") == 1\n assert candidate(loginTime = \"20:00\",logoutTime = \"20:14\") == 0\n assert candidate(loginTime = \"23:59\",logoutTime = \"00:01\") == 0\n assert candidate(loginTime = \"07:07\",logoutTime = \"07:32\") == 1\n assert candidate(loginTime = \"06:59\",logoutTime = \"07:01\") == 0\n assert candidate(loginTime = \"14:23\",logoutTime = \"14:24\") == 0\n assert candidate(loginTime = \"12:10\",logoutTime = \"12:20\") == 0\n assert candidate(loginTime = \"05:00\",logoutTime = \"05:00\") == 0\n assert candidate(loginTime = \"02:30\",logoutTime = \"02:31\") == 0\n assert candidate(loginTime = \"20:00\",logoutTime = \"04:00\") == 32\n assert candidate(loginTime = \"21:15\",logoutTime = \"21:45\") == 2\n assert candidate(loginTime = \"00:45\",logoutTime = \"01:00\") == 1\n assert candidate(loginTime = \"21:10\",logoutTime = \"21:14\") == 0\n assert candidate(loginTime = \"12:45\",logoutTime = \"13:45\") == 4\n assert candidate(loginTime = \"00:10\",logoutTime = \"01:05\") == 3\n assert candidate(loginTime = \"14:00\",logoutTime = \"14:14\") == 0\n assert candidate(loginTime = \"17:10\",logoutTime = \"18:55\") == 6\n assert candidate(loginTime = \"06:30\",logoutTime = \"07:30\") == 4\n assert candidate(loginTime = \"00:44\",logoutTime = \"00:59\") == 0\n assert candidate(loginTime = \"16:00\",logoutTime = \"16:01\") == 0\n assert candidate(loginTime = \"09:00\",logoutTime = \"21:15\") == 49\n assert candidate(loginTime = \"15:10\",logoutTime = \"15:15\") == 0\n assert candidate(loginTime = \"14:00\",logoutTime = \"18:30\") == 18\n assert candidate(loginTime = \"20:00\",logoutTime = \"21:00\") == 4\n assert candidate(loginTime = \"11:10\",logoutTime = \"11:10\") == 0\n assert candidate(loginTime = \"11:45\",logoutTime = \"12:44\") == 3\n assert candidate(loginTime = \"07:45\",logoutTime = \"08:15\") == 2\n assert candidate(loginTime = \"10:00\",logoutTime = \"10:14\") == 0\n assert candidate(loginTime = \"07:05\",logoutTime = \"08:10\") == 3\n assert candidate(loginTime = \"08:45\",logoutTime = \"09:15\") == 2\n assert candidate(loginTime = \"16:45\",logoutTime = \"17:45\") == 4\n assert candidate(loginTime = \"07:01\",logoutTime = \"07:14\") == 0\n assert candidate(loginTime = \"11:46\",logoutTime = \"12:44\") == 2\n assert candidate(loginTime = \"09:00\",logoutTime = \"16:45\") == 31\n assert candidate(loginTime = \"13:30\",logoutTime = \"14:00\") == 2\n assert candidate(loginTime = \"20:00\",logoutTime = \"20:15\") == 1\n assert candidate(loginTime = \"00:00\",logoutTime = \"04:00\") == 16\n assert candidate(loginTime = \"00:00\",logoutTime = \"00:15\") == 1\n assert candidate(loginTime = \"07:07\",logoutTime = \"07:47\") == 2\n assert candidate(loginTime = \"13:46\",logoutTime = \"13:47\") == 0\n assert candidate(loginTime = \"13:15\",logoutTime = \"14:15\") == 4\n assert candidate(loginTime = \"14:16\",logoutTime = \"15:14\") == 2\n assert candidate(loginTime = \"21:00\",logoutTime = \"21:59\") == 3\n assert candidate(loginTime = \"07:00\",logoutTime = \"07:14\") == 0\n assert candidate(loginTime = \"01:01\",logoutTime = \"24:00\") == 91\n assert candidate(loginTime = \"17:15\",logoutTime = \"17:45\") == 2\n assert candidate(loginTime = \"12:00\",logoutTime = \"12:00\") == 0\n assert candidate(loginTime = \"03:45\",logoutTime = \"04:15\") == 2\n assert candidate(loginTime = \"04:45\",logoutTime = \"05:00\") == 1\n assert candidate(loginTime = \"00:00\",logoutTime = \"23:45\") == 95\n assert candidate(loginTime = \"02:20\",logoutTime = \"02:25\") == 0\n assert candidate(loginTime = \"09:45\",logoutTime = \"10:45\") == 4\n assert candidate(loginTime = \"22:00\",logoutTime = \"01:30\") == 14\n assert candidate(loginTime = \"07:07\",logoutTime = \"07:45\") == 2\n assert candidate(loginTime = \"22:45\",logoutTime = \"23:59\") == 4\n assert candidate(loginTime = \"05:00\",logoutTime = \"24:00\") == 76\n assert candidate(loginTime = \"02:30\",logoutTime = \"03:30\") == 4\n assert candidate(loginTime = \"13:23\",logoutTime = \"14:22\") == 3\n assert candidate(loginTime = \"16:20\",logoutTime = \"18:55\") == 9\n assert candidate(loginTime = \"00:00\",logoutTime = \"00:14\") == 0\n assert candidate(loginTime = \"08:20\",logoutTime = \"09:20\") == 3\n assert candidate(loginTime = \"12:05\",logoutTime = \"12:20\") == 0\n assert candidate(loginTime = \"03:33\",logoutTime = \"04:48\") == 4\n assert candidate(loginTime = \"23:00\",logoutTime = \"23:15\") == 1\n assert candidate(loginTime = \"13:46\",logoutTime = \"14:14\") == 0\n assert candidate(loginTime = \"15:00\",logoutTime = \"15:15\") == 1\n assert candidate(loginTime = \"13:15\",logoutTime = \"13:30\") == 1\n assert candidate(loginTime = \"15:00\",logoutTime = \"16:00\") == 4\n assert candidate(loginTime = \"03:00\",logoutTime = \"03:01\") == 0\n assert candidate(loginTime = \"09:00\",logoutTime = \"09:00\") == 0\n assert candidate(loginTime = \"00:00\",logoutTime = \"24:00\") == 96\n assert candidate(loginTime = \"19:40\",logoutTime = \"20:05\") == 1\n assert candidate(loginTime = \"16:00\",logoutTime = \"17:00\") == 4\n assert candidate(loginTime = \"12:46\",logoutTime = \"13:14\") == 0\n assert candidate(loginTime = \"03:45\",logoutTime = \"03:45\") == 0\n assert candidate(loginTime = \"00:15\",logoutTime = \"00:30\") == 1\n assert candidate(loginTime = \"08:30\",logoutTime = \"09:00\") == 2\n assert candidate(loginTime = \"23:15\",logoutTime = \"00:14\") == 3\n assert candidate(loginTime = \"05:55\",logoutTime = \"06:05\") == 0\n assert candidate(loginTime = \"00:15\",logoutTime = \"23:59\") == 94\n assert candidate(loginTime = \"10:00\",logoutTime = \"10:00\") == 0\n assert candidate(loginTime = \"01:59\",logoutTime = \"02:01\") == 0\n assert candidate(loginTime = \"06:59\",logoutTime = \"07:00\") == 0\n assert candidate(loginTime = \"23:40\",logoutTime = \"00:10\") == 1\n assert candidate(loginTime = \"09:00\",logoutTime = \"09:59\") == 3\n assert candidate(loginTime = \"06:30\",logoutTime = \"07:00\") == 2\n assert candidate(loginTime = \"01:45\",logoutTime = \"02:44\") == 3\n assert candidate(loginTime = \"18:00\",logoutTime = \"18:00\") == 0\n assert candidate(loginTime = \"01:14\",logoutTime = \"01:46\") == 2\n assert candidate(loginTime = \"23:55\",logoutTime = \"00:05\") == 0\n assert candidate(loginTime = \"09:00\",logoutTime = \"18:45\") == 39\n assert candidate(loginTime = \"01:46\",logoutTime = \"02:14\") == 0\n assert candidate(loginTime = \"09:10\",logoutTime = \"09:20\") == 0\n assert candidate(loginTime = \"09:00\",logoutTime = \"09:14\") == 0\n assert candidate(loginTime = \"18:25\",logoutTime = \"19:50\") == 5\n assert candidate(loginTime = \"23:00\",logoutTime = \"23:45\") == 3\n assert candidate(loginTime = \"07:05\",logoutTime = \"08:05\") == 3\n assert candidate(loginTime = \"23:30\",logoutTime = \"00:30\") == 4\n assert candidate(loginTime = \"10:00\",logoutTime = \"24:00\") == 56\n assert candidate(loginTime = \"06:30\",logoutTime = \"09:15\") == 11\n assert candidate(loginTime = \"06:45\",logoutTime = \"07:00\") == 1\n assert candidate(loginTime = \"00:30\",logoutTime = \"00:45\") == 1\n assert candidate(loginTime = \"21:00\",logoutTime = \"22:15\") == 5\n assert candidate(loginTime = \"14:45\",logoutTime = \"15:00\") == 1\n assert candidate(loginTime = \"00:05\",logoutTime = \"00:30\") == 1\n assert candidate(loginTime = \"11:59\",logoutTime = \"12:14\") == 0\n assert candidate(loginTime = \"18:45\",logoutTime = \"19:10\") == 1\n assert candidate(loginTime = \"13:30\",logoutTime = \"16:45\") == 13\n assert candidate(loginTime = \"09:44\",logoutTime = \"09:45\") == 0\n assert candidate(loginTime = \"08:29\",logoutTime = \"08:40\") == 0\n assert candidate(loginTime = \"14:30\",logoutTime = \"16:30\") == 8\n assert candidate(loginTime = \"01:05\",logoutTime = \"02:30\") == 5\n assert candidate(loginTime = \"00:00\",logoutTime = \"01:00\") == 4\n assert candidate(loginTime = \"05:15\",logoutTime = \"05:15\") == 0\n assert candidate(loginTime = \"13:20\",logoutTime = \"13:59\") == 1\n assert candidate(loginTime = \"09:59\",logoutTime = \"10:00\") == 0\n assert candidate(loginTime = \"10:10\",logoutTime = \"11:09\") == 3\n assert candidate(loginTime = \"01:10\",logoutTime = \"01:40\") == 1\n assert candidate(loginTime = \"13:00\",logoutTime = \"13:14\") == 0\n assert candidate(loginTime = \"23:01\",logoutTime = \"23:14\") == 0\n assert candidate(loginTime = \"19:15\",logoutTime = \"20:00\") == 3\n", "comparison": "exact"}, "public_tests": ["\"09:31\"\n\"10:14\"", "\"21:30\"\n\"03:00\""], "hints": ["Consider the day as 48 hours instead of 24.", "For each round check if you were playing."], "metadata": {"canonical_parameter_names": ["loginTime", "logoutTime"], "leetcode_dataset_entry_point": "Solution().numberOfRounds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:34+00:00", "tests_total": 168, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string"]}, "language": "php", "interface": {"raw_signature": "function numberOfRounds($loginTime, $logoutTime) {", "container": "Solution", "callable": "numberOfRounds", "parameters": [{"name": "loginTime", "type": "String"}, {"name": "logoutTime", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1905, "task_id": "count-sub-islands", "difficulty": "Medium", "problem_description": "You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the grid are considered water cells.\n\nAn island in grid2 is considered a sub-island if there is an island in grid1 that contains all the cells that make up this island in grid2.\n\nReturn the number of islands in grid2 that are considered sub-islands.\n\nExample 1:\n\nInput: grid1 = [[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]], grid2 = [[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]]\nOutput: 3\nExplanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\nThe 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.\n\nExample 2:\n\nInput: grid1 = [[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]], grid2 = [[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]]\nOutput: 2\nExplanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\nThe 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands.\n\nConstraints:\n\n- m == grid1.length == grid2.length\n- n == grid1[i].length == grid2[i].length\n- 1 <= m, n <= 500\n- grid1[i][j] and grid2[i][j] are either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid1 = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 0, 0]],grid2 = [[1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 0], [0, 0, 0, 0, 1]]) == 2\n assert candidate(grid1 = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],grid2 = [[0, 0, 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(grid1 = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]],grid2 = [[1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0]]) == 2\n assert candidate(grid1 = [[1, 1, 1], [0, 0, 0], [0, 0, 0]],grid2 = [[1, 1, 1], [0, 0, 0], [0, 0, 0]]) == 1\n assert candidate(grid1 = [[1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]],grid2 = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]]) == 2\n assert candidate(grid1 = [[0, 0, 0], [0, 0, 0]],grid2 = [[0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid1 = [[1, 1, 0, 1, 1], [1, 0, 0, 0, 0], [0, 0, 0, 0, 1], [1, 1, 0, 1, 1]],grid2 = [[1, 1, 0, 0, 0], [1, 0, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 0, 1, 1]]) == 2\n assert candidate(grid1 = [[1, 1, 1, 0, 0], [0, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 1, 0, 1, 1]],grid2 = [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1], [0, 1, 0, 0, 0], [1, 0, 1, 1, 0], [0, 1, 0, 1, 0]]) == 3\n assert candidate(grid1 = [[1, 0, 1], [0, 1, 0], [1, 0, 1]],grid2 = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid1 = [[1, 1, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 1]],grid2 = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 1, 0, 1]]) == 0\n assert candidate(grid1 = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],grid2 = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 1\n assert candidate(grid1 = [[1, 1, 1], [1, 0, 1], [1, 1, 1]],grid2 = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid1 = [[1, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1]],grid2 = [[1, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 1], [1, 0, 1, 0, 1]]) == 4\n assert candidate(grid1 = [[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 1, 1]],grid2 = [[1, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 1]]) == 2\n assert candidate(grid1 = [[1, 1, 1, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 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]],grid2 = [[1, 1, 1, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 1, 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], [1, 1, 1, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],grid2 = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 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(grid1 = [[1, 1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]],grid2 = [[1, 1, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],grid2 = [[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, 0], [0, 1, 0, 0, 0, 1, 0]]) == 5\n assert candidate(grid1 = [[1, 1, 0, 0, 1, 1, 1, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]],grid2 = [[1, 1, 0, 0, 1, 1, 1, 1], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid1 = [[0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0]],grid2 = [[1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 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(grid1 = [[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]],grid2 = [[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(grid1 = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]],grid2 = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 13\n assert candidate(grid1 = [[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, 1, 1, 0, 0, 1, 1, 0, 0]],grid2 = [[1, 1, 0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 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]]) == 23\n assert candidate(grid1 = [[1, 1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0], [0, 1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1, 1], [1, 1, 0, 1, 1, 0, 1]],grid2 = [[1, 1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 1, 1, 1], [1, 1, 0, 1, 0, 0, 1]]) == 5\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],grid2 = [[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, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 19\n assert candidate(grid1 = [[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]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 14\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]],grid2 = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 3\n assert candidate(grid1 = [[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]],grid2 = [[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(grid1 = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid1 = [[1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1]],grid2 = [[1, 0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0, 1]]) == 5\n assert candidate(grid1 = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [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, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 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(grid1 = [[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]],grid2 = [[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]]) == 1\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 1, 0], [1, 1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1]],grid2 = [[1, 0, 1, 0, 1, 1, 0], [1, 1, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1]]) == 6\n assert candidate(grid1 = [[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]],grid2 = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1]]) == 3\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1]],grid2 = [[0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1]]) == 2\n assert candidate(grid1 = [[1, 1, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [1, 0, 0, 1, 0], [0, 0, 1, 0, 0]],grid2 = [[1, 1, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 1, 0], [1, 1, 0, 1, 0], [0, 0, 0, 0, 0]]) == 2\n assert candidate(grid1 = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],grid2 = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 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(grid1 = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]],grid2 = [[1, 0, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 0, 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, 0, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 27\n assert candidate(grid1 = [[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, 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]],grid2 = [[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, 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]]) == 19\n assert candidate(grid1 = [[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], [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, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]],grid2 = [[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], [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, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) == 7\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]],grid2 = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0, 1], [1, 0, 0, 1, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 1\n assert candidate(grid1 = [[1, 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, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]],grid2 = [[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, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1]]) == 3\n assert candidate(grid1 = [[1, 1, 0, 0, 0, 0, 1], [1, 1, 0, 1, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1]],grid2 = [[1, 1, 0, 0, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0], [0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 1]]) == 6\n assert candidate(grid1 = [[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], [0, 0, 0, 0, 0, 0, 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]],grid2 = [[1, 1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 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], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == 4\n assert candidate(grid1 = [[1, 1, 0, 0, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 0, 0, 1, 0, 1, 0, 1]],grid2 = [[0, 1, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 0, 0, 1, 0, 1, 0, 1]]) == 8\n assert candidate(grid1 = [[1, 1, 1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1, 1]],grid2 = [[1, 1, 1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 1], [0, 0, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 1, 1]]) == 6\n assert candidate(grid1 = [[1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1, 1, 1, 0, 1, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 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]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1, 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, 0]]) == 0\n assert candidate(grid1 = [[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]],grid2 = [[0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0]]) == 11\n assert candidate(grid1 = [[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]],grid2 = [[1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1]]) == 7\n assert candidate(grid1 = [[1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1, 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, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],grid2 = [[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1, 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, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid1 = [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 1, 0, 1, 1, 0, 1, 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, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1, 0]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 0, 1, 1, 0, 1, 1], [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, 0, 0, 0, 0, 0, 0, 0, 0]]) == 17\n assert candidate(grid1 = [[1, 1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 0, 1], [0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1, 1], [1, 0, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1]],grid2 = [[1, 1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 0, 1], [0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1, 1], [1, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1]]) == 3\n assert candidate(grid1 = [[1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1], [1, 1, 0, 1, 1, 0]],grid2 = [[1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1], [1, 1, 0, 1, 1, 0]]) == 6\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1], [1, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1]],grid2 = [[0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 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, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0]]) == 9\n assert candidate(grid1 = [[1, 1, 0, 0, 0, 1, 1], [1, 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, 1], [1, 1, 0, 0, 0, 1, 1]],grid2 = [[1, 1, 0, 0, 0, 1, 1], [1, 0, 1, 1, 1, 0, 1], [0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0], [1, 0, 1, 1, 1, 0, 1], [1, 1, 0, 0, 0, 1, 1]]) == 4\n assert candidate(grid1 = [[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]],grid2 = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 14\n assert candidate(grid1 = [[1, 0, 0, 1, 0, 1, 1, 0, 0, 1], [0, 1, 0, 1, 0, 1, 1, 0, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]],grid2 = [[0, 0, 0, 1, 0, 1, 1, 0, 0, 1], [0, 1, 0, 1, 0, 1, 1, 0, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]]) == 33\n assert candidate(grid1 = [[1, 1, 0, 0, 1], [1, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 1, 0, 1], [1, 1, 0, 0, 1]],grid2 = [[1, 1, 0, 0, 1], [1, 0, 0, 0, 0], [0, 0, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 0, 0, 1]]) == 4\n assert candidate(grid1 = [[1, 1, 0, 1, 1, 0, 1, 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]],grid2 = [[1, 1, 0, 1, 1, 0, 1, 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]]) == 46\n assert candidate(grid1 = [[1, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1]],grid2 = [[1, 1, 0, 0, 0, 0, 1], [0, 0, 0, 1, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 0, 0, 1]]) == 10\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 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, 0, 1], [1, 0, 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, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],grid2 = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 1\n assert candidate(grid1 = [[1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 0, 0, 1, 1], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 5\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],grid2 = [[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, 0, 0, 1, 0], [0, 1, 0, 1, 0, 0, 0, 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]]) == 0\n assert candidate(grid1 = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]],grid2 = [[0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 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]]) == 1\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]],grid2 = [[0, 0, 1, 0, 1, 0, 1, 0, 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, 0, 0], [1, 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, 0]]) == 26\n assert candidate(grid1 = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]],grid2 = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 13\n assert candidate(grid1 = [[1, 0, 0, 1, 1, 0, 1], [0, 0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1]],grid2 = [[1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 0, 0, 0], [1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1]]) == 5\n", "comparison": "exact"}, "public_tests": ["[[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]]\n[[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]]", "[[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]]\n[[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]]"], "hints": ["Let's use floodfill to iterate over the islands of the second grid", "Let's note that if all the cells in an island in the second grid if they are represented by land in the first grid then they are connected hence making that island a sub-island"], "metadata": {"canonical_parameter_names": ["grid1", "grid2"], "leetcode_dataset_entry_point": "Solution().countSubIslands", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:37+00:00", "tests_total": 67, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "depth-first-search", "breadth-first-search", "union-find", "matrix"]}, "language": "php", "interface": {"raw_signature": "function countSubIslands($grid1, $grid2) {", "container": "Solution", "callable": "countSubIslands", "parameters": [{"name": "grid1", "type": "Integer[][]"}, {"name": "grid2", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1906, "task_id": "minimum-absolute-difference-queries", "difficulty": "Medium", "problem_description": "The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.\n\n- For example, the minimum absolute difference of the array [5,2,3,7,2] is |2 - 3| = 1. Note that it is not 0 because a[i] and a[j] must be different.\n\nYou are given an integer array nums and the array queries where queries[i] = [l_i, r_i]. For each query i, compute the minimum absolute difference of the subarray nums[l_i...r_i] containing the elements of nums between the 0-based indices l_i and r_i (inclusive).\n\nReturn an array ans where ans[i] is the answer to the i^th query.\n\nA subarray is a contiguous sequence of elements in an array.\n\nThe value of |x| is defined as:\n\n- x if x >= 0.\n- -x if x < 0.\n\nExample 1:\n\nInput: nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]]\nOutput: [2,1,4,1]\nExplanation: The queries are processed as follows:\n- queries[0] = [0,1]: The subarray is [1,3] and the minimum absolute difference is |1-3| = 2.\n- queries[1] = [1,2]: The subarray is [3,4] and the minimum absolute difference is |3-4| = 1.\n- queries[2] = [2,3]: The subarray is [4,8] and the minimum absolute difference is |4-8| = 4.\n- queries[3] = [0,3]: The subarray is [1,3,4,8] and the minimum absolute difference is |3-4| = 1.\n\nExample 2:\n\nInput: nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]]\nOutput: [-1,1,1,3]\nExplanation: The queries are processed as follows:\n- queries[0] = [2,3]: The subarray is [2,2] and the minimum absolute difference is -1 because all the\n elements are the same.\n- queries[1] = [0,2]: The subarray is [4,5,2] and the minimum absolute difference is |4-5| = 1.\n- queries[2] = [0,5]: The subarray is [4,5,2,2,7,10] and the minimum absolute difference is |4-5| = 1.\n- queries[3] = [3,5]: The subarray is [2,7,10] and the minimum absolute difference is |7-10| = 3.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= 100\n- 1 <= queries.length <= 2 * 10^4\n- 0 <= l_i < r_i < nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [[0, 4], [1, 3]]) == [-1, -1]\n assert candidate(nums = [5, 5, 5, 5],queries = [[0, 3], [1, 2], [2, 3], [0, 1]]) == [-1, -1, -1, -1]\n assert candidate(nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [5, 5, 5, 5],queries = [[0, 3], [1, 2]]) == [-1, -1]\n assert candidate(nums = [4, 5, 2, 2, 7, 10],queries = [[2, 3], [0, 2], [0, 5], [3, 5]]) == [-1, 1, 1, 3]\n assert candidate(nums = [1, 3, 4, 8],queries = [[0, 1], [1, 2], [2, 3], [0, 3]]) == [2, 1, 4, 1]\n assert candidate(nums = [100, 1, 2, 3, 4, 100],queries = [[0, 5], [1, 4], [2, 3], [0, 1]]) == [1, 1, 1, 99]\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3],queries = [[0, 6], [1, 5], [2, 4]]) == [1, 1, 1]\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 5]\n assert candidate(nums = [9, 10, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 10], [2, 9], [5, 8], [1, 4], [3, 6]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [99, 99, 99, 99, 99]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 19], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [8, 8, 8, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8],queries = [[0, 13], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8]]) == [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 = [[0, 19], [0, 9], [10, 19], [5, 15], [1, 18]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [1, 1, 1, 1, 3, 1, 1]\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [0, 19], [9, 10]]) == [99, 99, 99, 99, 99, 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, 26, 27, 28, 29, 30],queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [5, 1, 4, 8, 2, 3, 7, 6],queries = [[0, 2], [1, 6], [3, 7], [0, 7], [2, 5]]) == [1, 1, 1, 1, 1]\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]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [[0, 9], [0, 4], [5, 9], [2, 8], [1, 7]]) == [2, 2, 2, 2, 2]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 3], [5, 8], [0, 4]]) == [-1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 10, 12, 11, 14, 13, 15],queries = [[0, 14], [0, 4], [5, 14], [2, 12], [1, 10]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [50, 20, 30, 10, 40],queries = [[0, 4], [1, 3], [2, 4], [0, 3], [1, 4], [0, 2], [3, 4], [0, 1]]) == [10, 10, 10, 10, 10, 10, 30, 30]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 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, 1, 1, 1, 1, 1],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],queries = [[0, 14], [1, 3], [5, 7], [9, 11], [0, 4], [6, 8]]) == [1, 1, 1, 1, 1, 1]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [0, 19], [9, 10]]) == [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],queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [42, 21, 17, 36, 21, 21, 17, 42, 36, 21],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4]]) == [4, 4, 4, 4, -1, 4]\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [10, 1, 2, 10, 1, 2, 10, 1, 2, 10],queries = [[0, 9], [0, 2], [3, 5], [6, 8], [1, 7]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 3, 2, 4, 3, 2, 1, 3, 2, 4],queries = [[0, 3], [1, 5], [2, 8], [3, 9], [0, 9]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],queries = [[0, 5], [5, 9], [0, 9], [2, 7], [1, 8]]) == [1, 1, 1, 1, 1]\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]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 95]\n assert candidate(nums = [50, 40, 30, 20, 10, 20, 30, 40, 50, 60],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [10, 10, 10, 10, 10]\n assert candidate(nums = [3, 1, 5, 1, 3, 2, 5, 3, 2, 1],queries = [[0, 4], [4, 8], [0, 9], [1, 5], [5, 9]]) == [2, 1, 1, 1, 1]\n assert candidate(nums = [2, 5, 1, 4, 3, 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]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],queries = [[0, 9], [0, 4], [5, 9], [2, 8], [1, 7]]) == [10, 10, 10, 10, 10]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],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, 2, 2]\n assert candidate(nums = [5, 5, 1, 1, 9, 9, 5, 5, 1, 1, 9, 9],queries = [[0, 11], [0, 3], [2, 5], [4, 7], [6, 9], [8, 11]]) == [4, 4, 8, 4, 4, 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],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14]]) == [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 = [[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(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], [0, 19], [9, 10]]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [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(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [20, 30, 10, 40, 50, 10, 20, 30, 40, 50],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [10, 10, 10, 10, 40]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 2], [2, 4], [4, 6], [6, 8], [1, 3], [3, 5], [5, 7], [7, 9]]) == [1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2],queries = [[0, 8], [1, 5], [2, 6], [3, 7], [4, 8], [0, 3], [5, 8], [0, 4]]) == [1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],queries = [[0, 9], [0, 4], [5, 9], [2, 8], [1, 7]]) == [1, 1, 1, 1, 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],queries = [[0, 9], [10, 19], [0, 19], [5, 14], [1, 18]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [5, 2, 5, 2, 5, 2, 5, 2, 5, 2],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [3, 3, 3, 3, 3]\n assert candidate(nums = [50, 40, 30, 20, 10, 20, 30, 40, 50],queries = [[0, 4], [4, 8], [0, 8], [1, 7], [2, 6]]) == [10, 10, 10, 10, 10]\n assert candidate(nums = [1, 5, 3, 9, 7, 11, 13, 15, 17, 19],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 3], [5, 8], [0, 4], [1, 3], [2, 4], [1, 5], [3, 7], [0, 6]]) == [2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],queries = [[0, 10], [0, 5], [5, 10], [2, 8], [1, 9]]) == [5, 5, 5, 5, 5]\n assert candidate(nums = [7, 10, 4, 3, 20, 15],queries = [[0, 5], [1, 2], [2, 4], [3, 5], [0, 4], [1, 3], [2, 5], [0, 3]]) == [1, 6, 1, 5, 1, 1, 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],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [4, 1, 3, 2, 5, 6, 7, 8, 9, 10],queries = [[0, 9], [1, 4], [2, 6], [0, 5], [3, 8], [4, 9], [0, 2], [7, 9]]) == [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 = [[0, 19], [1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18]]) == [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 = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [10, 10, 10, 10, 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],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, 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],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [2, 4, 2, 4, 2, 4, 2, 4, 2, 4],queries = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(nums = [5, 6, 6, 5, 5, 6, 5, 6, 6, 5],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 3], [5, 8], [0, 4], [1, 3], [2, 4]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 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],queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15]]) == [2, 2, 2, 2, 2]\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 3], [5, 8], [0, 4], [1, 3], [2, 4], [1, 5], [3, 7], [0, 6], [4, 8], [0, 7], [2, 9]]) == [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],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [-1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 95]\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]]) == [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],queries = [[0, 14], [0, 4], [5, 14], [2, 12], [1, 10]]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 4], [5, 9]]) == [10, 10, 10, 10, 10, 10, 10]\n", "comparison": "exact"}, "public_tests": ["[1,3,4,8]\n[[0,1],[1,2],[2,3],[0,3]]", "[4,5,2,2,7,10]\n[[2,3],[0,2],[0,5],[3,5]]"], "hints": ["How does the maximum value being 100 help us?", "How can we tell if a number exists in a given range?"], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().minDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:39+00:00", "tests_total": 90, "tests_dropped": 16, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minDifference($nums, $queries) {", "container": "Solution", "callable": "minDifference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1909, "task_id": "remove-one-element-to-make-the-array-strictly-increasing", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.\n\nThe array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).\n\nExample 1:\n\nInput: nums = [1,2,10,5,7]\nOutput: true\nExplanation: By removing 10 at index 2 from nums, it becomes [1,2,5,7].\n[1,2,5,7] is strictly increasing, so return true.\n\nExample 2:\n\nInput: nums = [2,3,1,2]\nOutput: false\nExplanation:\n[3,1,2] is the result of removing the element at index 0.\n[2,1,2] is the result of removing the element at index 1.\n[2,3,2] is the result of removing the element at index 2.\n[2,3,1] is the result of removing the element at index 3.\nNo resulting array is strictly increasing, so return false.\n\nExample 3:\n\nInput: nums = [1,1,1]\nOutput: false\nExplanation: The result of removing any element is [1,1].\n[1,1] is not strictly increasing, so return false.\n\nConstraints:\n\n- 2 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 2, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3]) == True\n assert candidate(nums = [1, 1, 1]) == False\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 3]) == True\n assert candidate(nums = [3, 5, 4, 6, 7]) == True\n assert candidate(nums = [1, 2, 10, 5, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [5, 2, 3, 4]) == True\n assert candidate(nums = [100, 20, 30]) == True\n assert candidate(nums = [3, 2, 1]) == False\n assert candidate(nums = [5, 7, 1, 8]) == True\n assert candidate(nums = [1, 2, 3, 3, 4]) == True\n assert candidate(nums = [5, 4, 3, 2, 1]) == False\n assert candidate(nums = [1, 2, 2, 3, 4]) == True\n assert candidate(nums = [1, 2, 3]) == True\n assert candidate(nums = [2, 3, 1, 2]) == False\n assert candidate(nums = [100, 200, 150, 300]) == True\n assert candidate(nums = [100, 200, 150, 300, 400]) == True\n assert candidate(nums = [1, 3, 2, 4]) == 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, 19]) == True\n assert candidate(nums = [1, 2, 3, 5, 4, 3, 2, 6, 7, 8]) == False\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 8, 9]) == 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, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 3]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 5, 15, 16, 17]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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, 21, 22, 23, 21]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 12]) == 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, 22]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 5, 18, 19]) == True\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 8, 7, 9]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 10, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 7, 8, 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, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 1000, 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, 5, 11, 12, 13]) == True\n assert candidate(nums = [1, 5, 2, 3, 4, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 10, 9, 11]) == True\n assert candidate(nums = [1, 3, 2, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 5, 4, 3, 6, 7, 8]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 10, 8, 9, 11, 12]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 14]) == True\n assert candidate(nums = [1, 2, 3, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == False\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, 20, 27]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 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, 21, 22, 20, 23]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 11]) == True\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 10, 9, 11, 12]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == False\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 55]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 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, 26, 27, 28, 29, 30, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 12, 13]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == True\n assert candidate(nums = [1, 3, 5, 4, 7, 9, 8, 10, 12, 14, 15]) == 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]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 12]) == 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, 18]) == True\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5]) == False\n assert candidate(nums = [3, 4, 5, 6, 7, 8, 9, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 25]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 18, 21, 23, 25, 27, 29]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8]) == True\n assert candidate(nums = [6, 7, 8, 9, 10, 5, 11, 12]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 6, 7]) == True\n assert candidate(nums = [8, 9, 10, 2, 11, 12]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 10]) == False\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 2, 17, 19, 21]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 5, 19, 20]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 5, 16, 17, 18]) == 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, 5, 21, 22]) == 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, 24]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 3]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 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, 19, 21]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 11, 12]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 12, 14]) == True\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [1, 2, 3, 10, 4, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 13, 15, 16, 17, 18, 19]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 7, 9, 10, 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, 23]) == True\n assert candidate(nums = [100, 200, 150, 250, 300]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 100, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 100, 4, 5, 6]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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, 25]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 15]) == True\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 10, 12, 14]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7]) == True\n assert candidate(nums = [1, 3, 5, 7, 6, 8, 9]) == True\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 9, 8, 10, 11]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 10, 5, 6]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 10, 9, 11, 12]) == True\n assert candidate(nums = [1, 3, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 10, 11]) == False\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 9, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 8]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5]) == False\n assert candidate(nums = [3, 5, 6, 7, 8, 9, 10, 5, 11, 12]) == True\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 3, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 8, 9]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 3]) == True\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 3, 14]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 6]) == False\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 6, 7]) == True\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 11]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 5]) == True\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 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, 17]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 11]) == True\n assert candidate(nums = [10, 20, 30, 25, 40, 50]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5, 20, 21]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 16]) == 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, 20, 22]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 10]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 8, 9, 11, 12, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 10, 13, 14]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 10, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 6, 7, 8]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 7, 8, 9, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 11, 12, 13, 14, 15]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 10]) == True\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5, 6, 7, 8]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 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, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 10, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 4, 7]) == 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, 20]) == True\n", "comparison": "exact"}, "public_tests": ["[1,2,10,5,7]", "[2,3,1,2]", "[1,1,1]"], "hints": ["For each index i in nums remove this index.", "If the array becomes sorted return true, otherwise revert to the original array and try different index."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().canBeIncreasing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:44+00:00", "tests_total": 179, "tests_dropped": 1, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function canBeIncreasing($nums) {", "container": "Solution", "callable": "canBeIncreasing", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1910, "task_id": "remove-all-occurrences-of-a-substring", "difficulty": "Medium", "problem_description": "Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:\n\n- Find the leftmost occurrence of the substring part and remove it from s.\n\nReturn s after removing all occurrences of part.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"daabcbaabcbc\", part = \"abc\"\nOutput: \"dab\"\nExplanation: The following operations are done:\n- s = \"daabcbaabcbc\", remove \"abc\" starting at index 2, so s = \"dabaabcbc\".\n- s = \"dabaabcbc\", remove \"abc\" starting at index 4, so s = \"dababc\".\n- s = \"dababc\", remove \"abc\" starting at index 3, so s = \"dab\".\nNow s has no occurrences of \"abc\".\n\nExample 2:\n\nInput: s = \"axxxxyyyyb\", part = \"xy\"\nOutput: \"ab\"\nExplanation: The following operations are done:\n- s = \"axxxxyyyyb\", remove \"xy\" starting at index 4 so s = \"axxxyyyb\".\n- s = \"axxxyyyb\", remove \"xy\" starting at index 3 so s = \"axxyyb\".\n- s = \"axxyyb\", remove \"xy\" starting at index 2 so s = \"axyb\".\n- s = \"axyb\", remove \"xy\" starting at index 1 so s = \"ab\".\nNow s has no occurrences of \"xy\".\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- 1 <= part.length <= 1000\n- s and part consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcd\",part = \"efg\") == \"abcd\"\n assert candidate(s = \"zzzz\",part = \"zz\") == \"\"\n assert candidate(s = \"abcdabcdabcd\",part = \"abcd\") == \"\"\n assert candidate(s = \"abcdefg\",part = \"xyz\") == \"abcdefg\"\n assert candidate(s = \"abcde\",part = \"f\") == \"abcde\"\n assert candidate(s = \"daabcbaabcbc\",part = \"abc\") == \"dab\"\n assert candidate(s = \"abcabcabc\",part = \"bca\") == \"abc\"\n assert candidate(s = \"axxxxyyyyb\",part = \"xy\") == \"ab\"\n assert candidate(s = \"hello\",part = \"ll\") == \"heo\"\n assert candidate(s = \"abcabcabc\",part = \"abc\") == \"\"\n assert candidate(s = \"aaaa\",part = \"aa\") == \"\"\n assert candidate(s = \"mississippi\",part = \"issi\") == \"mssippi\"\n assert candidate(s = \"abababab\",part = \"aba\") == \"bb\"\n assert candidate(s = \"aaaaaaa\",part = \"aa\") == \"a\"\n assert candidate(s = \"zzzzzzz\",part = \"zzz\") == \"z\"\n assert candidate(s = \"banana\",part = \"na\") == \"ba\"\n assert candidate(s = \"abcabcabc\",part = \"cab\") == \"abc\"\n assert candidate(s = \"aabababa\",part = \"aba\") == \"ba\"\n assert candidate(s = \"abababababababababab\",part = \"abab\") == \"\"\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiop\",part = \"erty\") == \"qwuiopqwuiopqwuiop\"\n assert candidate(s = \"hellohellohellohellohello\",part = \"hello\") == \"\"\n assert candidate(s = \"abcdefghij\",part = \"xyz\") == \"abcdefghij\"\n assert candidate(s = \"abcdabcdabcdabcd\",part = \"dabc\") == \"abcd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",part = \"xyz\") == \"abcdefghijklmnopqrstuvw\"\n assert candidate(s = \"aabbccddeeff\",part = \"bbcc\") == \"aaddeeff\"\n assert candidate(s = \"exampleexampleexampleexample\",part = \"exampleexample\") == \"\"\n assert candidate(s = \"aaaaaaabbbbbbbcccccc\",part = \"abc\") == \"aaaaaaabbbbbbbcccccc\"\n assert candidate(s = \"aaaaabbbbbcccc\",part = \"ab\") == \"cccc\"\n assert candidate(s = \"thisisaverylongstringthatwillbeusedtocheckthefunctionality\",part = \"is\") == \"thaverylongstringthatwillbeusedtocheckthefunctionality\"\n assert candidate(s = \"yyyyyyyyyyyyyyyyyyyy\",part = \"yyyy\") == \"\"\n assert candidate(s = \"lkjhgfedcba\",part = \"fe\") == \"lkjhgdcba\"\n assert candidate(s = \"hellohellohello\",part = \"lohe\") == \"hellllo\"\n assert candidate(s = \"abcdeabcdeabcdeabcde\",part = \"abc\") == \"dededede\"\n assert candidate(s = \"hellohellohellohello\",part = \"elloh\") == \"hello\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",part = \"abc\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"aaaaaaaaaabcdeeeeee\",part = \"aaa\") == \"abcdeeeeee\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",part = \"qwerty\") == \"uiopasdfghjklzxcvbnmuiop\"\n assert candidate(s = \"zzzzzzzzzz\",part = \"zz\") == \"\"\n assert candidate(s = \"stackoverflow\",part = \"flow\") == \"stackover\"\n assert candidate(s = \"aaaaaaabaaaaa\",part = \"aaaa\") == \"aaaba\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",part = \"ghij\") == \"abcdefabcdefabcdef\"\n assert candidate(s = \"acabacabacabacabacab\",part = \"acab\") == \"\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",part = \"abcdefghij\") == \"\"\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbcccccc\",part = \"abccba\") == \"aaaaaaaaaabbbbbbbbbbcccccc\"\n assert candidate(s = \"abcdefghij\",part = \"jihgfedcba\") == \"abcdefghij\"\n assert candidate(s = \"qwertyuiopqwertyuiop\",part = \"rty\") == \"qweuiopqweuiop\"\n assert candidate(s = \"ababababab\",part = \"aba\") == \"bbab\"\n assert candidate(s = \"aabbccddeeffgg\",part = \"bbcc\") == \"aaddeeffgg\"\n assert candidate(s = \"racecaracecaracecar\",part = \"aceca\") == \"rrrr\"\n assert candidate(s = \"xylophoneisfunxylophoneisfunxylophoneisfun\",part = \"xylophoneis\") == \"funfunfun\"\n assert candidate(s = \"abacabadabacaba\",part = \"abaca\") == \"badba\"\n assert candidate(s = \"supercalifragilisticexpialidocious\",part = \"cious\") == \"supercalifragilisticexpialido\"\n assert candidate(s = \"abababababababababab\",part = \"bab\") == \"aaaaa\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",part = \"abcabc\") == \"\"\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\",part = \"defabc\") == \"abcdef\"\n assert candidate(s = \"abracadabra\",part = \"abra\") == \"cad\"\n assert candidate(s = \"aaabaaaabaaa\",part = \"aab\") == \"aaaaaa\"\n assert candidate(s = \"longstringwithsomerepeatedpatternpattern\",part = \"pattern\") == \"longstringwithsomerepeated\"\n assert candidate(s = \"programmingprogrammingprogramming\",part = \"gram\") == \"promingpromingproming\"\n assert candidate(s = \"abcabcabcabcabcabcabcabc\",part = \"abcabc\") == \"\"\n assert candidate(s = \"aaaaabaaaaabaaaaab\",part = \"ba\") == \"aaaaaaaaaaaaab\"\n assert candidate(s = \"hellohellohellohellohellohello\",part = \"ll\") == \"heoheoheoheoheoheo\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",part = \"qwerty\") == \"uiopasdfghjklzxcvbnmuiopasdfghjklzxcvbnm\"\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyz\",part = \"xyzxyz\") == \"\"\n assert candidate(s = \"bananaapplebanana\",part = \"an\") == \"baappleba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",part = \"mnop\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"xyxyxyxyxy\",part = \"xyx\") == \"yyxy\"\n assert candidate(s = \"hellohellohellohello\",part = \"llohe\") == \"hello\"\n assert candidate(s = \"aaaaabbbbbcccccd\",part = \"abc\") == \"aaaaabbbbbcccccd\"\n assert candidate(s = \"abcdabcdabcd\",part = \"cdab\") == \"abcd\"\n assert candidate(s = \"xyzxyzxyzxyz\",part = \"xyz\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",part = \"nopqr\") == \"abcdefghijklmstuvwxyz\"\n assert candidate(s = \"xyzyxzyxzyxzyxzyxzyx\",part = \"zyx\") == \"xy\"\n assert candidate(s = \"zzzzzzzzzz\",part = \"zzz\") == \"z\"\n assert candidate(s = \"abcdefgabcdefgabcdefg\",part = \"efgabc\") == \"abcdddefg\"\n assert candidate(s = \"ababababab\",part = \"abab\") == \"ab\"\n assert candidate(s = \"xxxxxxxxxxxxxxxxxxxx\",part = \"xxx\") == \"xx\"\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\",part = \"micro\") == \"pneumonoultrascopicsilicovolcanoconiosis\"\n assert candidate(s = \"abcdefgabcdefg\",part = \"def\") == \"abcgabcg\"\n assert candidate(s = \"aabbccddeeaabbccddeeaabbccddeeaabbccdd\",part = \"abcd\") == \"aabbccddeeaabbccddeeaabbccddeeaabbccdd\"\n assert candidate(s = \"abacabadabacabadabacaba\",part = \"abad\") == \"abacabacabacaba\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",part = \"erty\") == \"qwuiopasdfghjklzxcvbnmqwuiop\"\n assert candidate(s = \"abcdabcdeabcdabcdeabcd\",part = \"bcde\") == \"abcdaabcdaabcd\"\n assert candidate(s = \"abcdabcdabcdabcd\",part = \"abcd\") == \"\"\n assert candidate(s = \"ababababababababababababababababababababababababababababababababab\",part = \"abab\") == \"ab\"\n assert candidate(s = \"abcdabcdabcdabcd\",part = \"abcdabcd\") == \"\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",part = \"zyx\") == \"wvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwerty\",part = \"erty\") == \"qwuiopasdfghjklzxcvbnmqw\"\n assert candidate(s = \"noonnoonnoonnoon\",part = \"noon\") == \"\"\n assert candidate(s = \"oneonetwoonethreeonefouronefiveonesixone\",part = \"oneone\") == \"twoonethreeonefouronefiveonesixone\"\n assert candidate(s = \"12345678901234567890\",part = \"345\") == \"12678901267890\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",part = \"def\") == \"abcghijklmnopqrstuvwxyz\"\n assert candidate(s = \"thisisaverylongstringwithrepeatedpatterns\",part = \"pattern\") == \"thisisaverylongstringwithrepeateds\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",part = \"mnop\") == \"qwertyuiopasdfghjklzxcvbnm\"\n assert candidate(s = \"abcdefghijabcdefghij\",part = \"cdefg\") == \"abhijabhij\"\n assert candidate(s = \"aaaaaaaaaaaabbbbbaaaaaaaaaaabbbbbaaaaaaaaaaabbbbbaaaaaaaaaaabbbbb\",part = \"aaaabbbb\") == \"aaaaaaaabaaaaaaabaaaaaaabaaaaaaab\"\n assert candidate(s = \"abcdefghabcdefghabcdefgh\",part = \"efgh\") == \"abcdabcdabcd\"\n assert candidate(s = \"thisisaverylongstringwithrepeatedpattern\",part = \"pattern\") == \"thisisaverylongstringwithrepeated\"\n assert candidate(s = \"abababababababab\",part = \"abab\") == \"\"\n assert candidate(s = \"abcdeabcdeabcdeabcde\",part = \"abcde\") == \"\"\n assert candidate(s = \"abababababababababab\",part = \"ababa\") == \"bbbab\"\n assert candidate(s = \"abcdeabcdeabcde\",part = \"bcde\") == \"aaa\"\n assert candidate(s = \"abcdefghij\",part = \"gh\") == \"abcdefij\"\n assert candidate(s = \"aabbccddeeff\",part = \"abc\") == \"aabbccddeeff\"\n assert candidate(s = \"xyxxyxyxyx\",part = \"xyx\") == \"y\"\n assert candidate(s = \"aaaaaa\",part = \"aa\") == \"\"\n assert candidate(s = \"abcdefabcdef\",part = \"defabc\") == \"abcdef\"\n assert candidate(s = \"zzzzzzzz\",part = \"zz\") == \"\"\n assert candidate(s = \"bananaanananasanananananana\",part = \"ana\") == \"bnnasnnna\"\n assert candidate(s = \"abcabcabcabcabcabc\",part = \"abcabc\") == \"\"\n assert candidate(s = \"aaaaaa\",part = \"a\") == \"\"\n assert candidate(s = \"abcdefghij\",part = \"efg\") == \"abcdhij\"\n assert candidate(s = \"onetwothreefourfivesixseveneightnineseven\",part = \"seven\") == \"onetwothreefourfivesixeightnine\"\n assert candidate(s = \"abcabcabcabcabcabc\",part = \"ab\") == \"cccccc\"\n assert candidate(s = \"mississippi\",part = \"iss\") == \"mippi\"\n assert candidate(s = \"aaaabbbbcccc\",part = \"bbcc\") == \"aaaa\"\n assert candidate(s = \"abracadabraabracadabra\",part = \"bracad\") == \"aabraaabra\"\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",part = \"abcdabcd\") == \"\"\n assert candidate(s = \"abababababababab\",part = \"aba\") == \"bbbb\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",part = \"zzzz\") == \"zz\"\n assert candidate(s = \"xyzxyzxyzxyzxyzxyz\",part = \"xyzxyz\") == \"\"\n assert candidate(s = \"aaaaaaaaaa\",part = \"aaa\") == \"a\"\n assert candidate(s = \"repeatedrepeatedrepeatedrepeated\",part = \"repeated\") == \"\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzz\",part = \"zzzz\") == \"zz\"\n assert candidate(s = \"repeatedsubstringrepeatedsubstring\",part = \"ted\") == \"repeasubstringrepeasubstring\"\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghijk\",part = \"efg\") == \"abcdhijkabcdhijkabcdhijk\"\n assert candidate(s = \"mnopqrsmnopqrsmnopqrs\",part = \"mnopqrs\") == \"\"\n assert candidate(s = \"ananasanananas\",part = \"ana\") == \"nasns\"\n assert candidate(s = \"zzzzz\",part = \"zz\") == \"z\"\n assert candidate(s = \"thisisaverylongstringwithrepeatedparts\",part = \"thisis\") == \"averylongstringwithrepeatedparts\"\n", "comparison": "exact"}, "public_tests": ["\"daabcbaabcbc\"\n\"abc\"", "\"axxxxyyyyb\"\n\"xy\""], "hints": ["Note that a new occurrence of pattern can appear if you remove an old one, For example, s = \"ababcc\" and pattern = \"abc\".", "You can maintain a stack of characters and if the last character of the pattern size in the stack match the pattern remove them"], "metadata": {"canonical_parameter_names": ["s", "part"], "leetcode_dataset_entry_point": "Solution().removeOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:46+00:00", "tests_total": 130, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "stack", "simulation"]}, "language": "php", "interface": {"raw_signature": "function removeOccurrences($s, $part) {", "container": "Solution", "callable": "removeOccurrences", "parameters": [{"name": "s", "type": "String"}, {"name": "part", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1911, "task_id": "maximum-alternating-subsequence-sum", "difficulty": "Medium", "problem_description": "The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.\n\n- For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.\n\nGiven an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence).\n\nA 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. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.\n\nExample 1:\n\nInput: nums = [4,2,5,3]\nOutput: 7\nExplanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.\n\nExample 2:\n\nInput: nums = [5,6,7,8]\nOutput: 8\nExplanation: It is optimal to choose the subsequence [8] with alternating sum 8.\n\nExample 3:\n\nInput: nums = [6,2,1,2,4,5]\nOutput: 10\nExplanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.\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 = [100000, 99999, 99998, 99997, 99996]) == 100000\n assert candidate(nums = [4, 2, 5, 3]) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [6, 2, 1, 2, 4, 5]) == 10\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 = [100]) == 100\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 50\n assert candidate(nums = [1, 100000, 1, 100000, 1]) == 199999\n assert candidate(nums = [5, 6, 7, 8]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [100000, 1, 100000, 1, 100000]) == 299998\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5]) == 54\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 17\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 100000\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == 499996\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 991\n assert candidate(nums = [100, 50, 100, 50, 100, 50, 100]) == 250\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 24\n assert candidate(nums = [100, 10, 200, 20, 300, 30, 400, 40, 500, 50]) == 1400\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 499976\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]) == 106\n assert candidate(nums = [100000, 50000, 100000, 50000, 100000, 50000, 100000, 50000, 100000, 50000]) == 300000\n assert candidate(nums = [5, 3, 8, 1, 4, 7, 2, 6, 9]) == 23\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1000\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70]) == 110\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9]) == 65\n assert candidate(nums = [120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 120\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 499996\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 9\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 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]) == 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]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 100000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 19\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 11\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 15\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 7\n assert candidate(nums = [5, 3, 8, 12, 4, 9, 2, 7, 6, 10]) == 28\n assert candidate(nums = [10, 15, 10, 5, 20, 25, 30, 35, 40, 45]) == 55\n assert candidate(nums = [100000, 99999, 100000, 99998, 100000, 99997, 100000, 99996, 100000, 99995]) == 100010\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9]) == 15\n assert candidate(nums = [5, 3, 8, 6, 7, 2, 9, 4, 1, 10]) == 27\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, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 140\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 11\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50]) == 100\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 29\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 28\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 17\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 17\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 = [9, 7, 8, 5, 6, 3, 4, 1, 2, 10]) == 21\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 20\n assert candidate(nums = [5, 3, 8, 6, 11, 9, 14, 12, 17, 15, 20, 18, 23, 21, 25]) == 39\n assert candidate(nums = [5, 3, 6, 7, 2, 9, 4, 10, 1, 11]) == 32\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 11\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 13\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 20\n assert candidate(nums = [75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == 75\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 21\n assert candidate(nums = [5, 1, 4, 2, 7, 3, 6, 8]) == 18\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10]) == 46\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 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, 5]) == 13\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4]) == 399984\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 120\n assert candidate(nums = [10, 5, 15, 10, 20, 15, 25, 20, 30, 25]) == 50\n assert candidate(nums = [5, 1, 4, 2, 3]) == 9\n assert candidate(nums = [5, 1, 4, 2, 3, 1, 2, 1, 3, 2, 1]) == 12\n assert candidate(nums = [5, 3, 8, 12, 7, 10, 1, 15, 9, 20]) == 42\n assert candidate(nums = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == 499990\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, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 110\n assert candidate(nums = [100, 200, 150, 300, 250, 350, 400, 300, 450, 500]) == 700\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 5, 4, 6, 3, 7, 2, 8, 1, 9]) == 45\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, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 476\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 10000, 1000, 100, 10]) == 100000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 75\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 150\n", "comparison": "exact"}, "public_tests": ["[4,2,5,3]", "[5,6,7,8]", "[6,2,1,2,4,5]"], "hints": ["Is only tracking a single sum enough to solve the problem?", "How does tracking an odd sum and an even sum reduce the number of states?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxAlternatingSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:49+00:00", "tests_total": 96, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function maxAlternatingSum($nums) {", "container": "Solution", "callable": "maxAlternatingSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1913, "task_id": "maximum-product-difference-between-two-pairs", "difficulty": "Easy", "problem_description": "The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).\n\n- For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.\n\nGiven an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.\n\nReturn the maximum such product difference.\n\nExample 1:\n\nInput: nums = [5,6,2,7,4]\nOutput: 34\nExplanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).\nThe product difference is (6 * 7) - (2 * 4) = 34.\n\nExample 2:\n\nInput: nums = [4,2,5,9,7,4,8]\nOutput: 64\nExplanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).\nThe product difference is (9 * 8) - (2 * 4) = 64.\n\nConstraints:\n\n- 4 <= nums.length <= 10^4\n- 1 <= nums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 6, 2, 7, 4]) == 34\n assert candidate(nums = [9, 5, 8, 6, 7, 3, 2, 1, 4]) == 70\n assert candidate(nums = [1, 2, 3, 4]) == 10\n assert candidate(nums = [4, 2, 5, 9, 7, 4, 8]) == 64\n assert candidate(nums = [10000, 1, 10000, 1]) == 99999999\n assert candidate(nums = [9, 5, 8, 6, 7, 3, 4, 2, 1]) == 70\n assert candidate(nums = [9, 5, 8, 3, 7]) == 57\n assert candidate(nums = [10000, 1, 10000, 1, 10000, 1]) == 99999999\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 88000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 2080000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 896\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 880000\n assert candidate(nums = [2345, 1234, 5678, 6789, 3456, 4567, 7890, 8901]) == 67335160\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 11766\n assert candidate(nums = [5000, 5000, 5000, 5000, 1, 1, 1, 1]) == 24999999\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 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10000, 10000, 10000, 10000, 10000]) == 99999999\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 832\n assert candidate(nums = [10000, 10000, 10000, 10000, 9999, 9999, 9999, 9999]) == 19999\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 1, 9999]) == 49990000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 780\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 80\n assert candidate(nums = [10000, 1, 9999, 2, 9998, 3, 9997, 4, 9996, 5]) == 99989998\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996]) == 99989998\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 3258\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10000, 10000, 10000, 10000, 10000]) == 99999975\n assert candidate(nums = [10000, 9999, 1, 2]) == 99989998\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 159928\n assert candidate(nums = [8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 100, 200, 300, 400, 500, 600, 700, 800]) == 55980000\n assert candidate(nums = [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19]) == 357\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 10, 20, 30, 40, 50]) == 899800\n assert candidate(nums = [5000, 5000, 5000, 5000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 24999999\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009]) == 16072\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 99\n assert candidate(nums = [10000, 10000, 10000, 10000, 1, 1, 1, 1]) == 99999999\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 2015\n assert candidate(nums = [3333, 6666, 4444, 7777, 2222, 8888, 1111, 9999]) == 86402470\n assert candidate(nums = [5000, 5000, 4999, 4999, 4998, 4998, 4997, 4997, 4996, 4996]) == 39984\n assert candidate(nums = [8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 500, 100, 50, 10, 5, 1, 2, 3, 4, 6, 7, 8]) == 55999998\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86]) == 2418\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996, 6, 9995, 7, 9994, 8, 9993, 9, 9992, 10, 9991]) == 99989998\n assert candidate(nums = [2, 3, 6, 7, 8, 10, 5, 4, 1, 9]) == 88\n assert candidate(nums = [10000, 10000, 10000, 1, 1, 1, 9999, 9999, 9999, 2]) == 99999999\n assert candidate(nums = [9999, 9998, 9997, 9996, 2, 3, 4, 5]) == 99969996\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == 1672\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 378\n assert candidate(nums = [3, 9, 10, 2, 18, 15, 11, 1, 17, 7]) == 304\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996, 6, 9995, 7, 9994, 8]) == 99989998\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4]) == 899998\n assert candidate(nums = [1, 1, 1, 1, 10000, 10000, 10000, 10000, 9999, 9999, 9999, 9999]) == 99999999\n assert candidate(nums = [10000, 9999, 9998, 9997, 1, 2, 3, 4, 5, 6]) == 99989998\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997]) == 99989998\n assert candidate(nums = [5000, 5001, 4999, 4998, 5002, 5003]) == 40004\n assert candidate(nums = [1, 10, 100, 1000, 10000, 1, 10, 100, 1000, 10000]) == 99999999\n assert candidate(nums = [5000, 5001, 5002, 5003, 5004, 1, 2, 3, 4, 5]) == 25035010\n assert candidate(nums = [10000, 9999, 9998, 9997, 1, 2, 3, 4]) == 99989998\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 10000, 10000]) == 99999991\n assert candidate(nums = [1, 10000, 1, 10000, 1, 10000, 1, 10000]) == 99999999\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 8800\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 2080000\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]) == 8627\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 208\n assert candidate(nums = [1500, 1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 2080000\n assert candidate(nums = [1, 10000, 2, 9999, 3, 9998, 4, 9997, 5, 9996]) == 99989998\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 880000\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97]) == 9898\n assert candidate(nums = [1, 2, 3, 4, 5, 10000, 9999, 9998, 9997, 9996]) == 99989998\n assert candidate(nums = [1, 1, 1, 1, 10000, 10000, 10000, 10000, 10000, 10000]) == 99999999\n assert candidate(nums = [2500, 2501, 2502, 2503, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 6262504\n assert candidate(nums = [5000, 4000, 3000, 2000, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 19999997\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 378\n assert candidate(nums = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 360\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10000, 9999]) == 99989999\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5]) == 899998\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985]) == 279790\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]) == 8\n assert candidate(nums = [9999, 1, 9998, 2, 9997, 3, 9996, 4, 9995, 5, 9994, 6, 9993, 7, 9992, 8, 9991, 9, 9990, 10]) == 99970000\n assert candidate(nums = [5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010, 5011, 5012, 5013, 5014, 5015]) == 140210\n assert candidate(nums = [10000, 1, 9999, 2, 9998, 3, 9997, 4, 9996, 5]) == 99989998\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 99989998\n assert candidate(nums = [10000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 189998\n assert candidate(nums = [5000, 5000, 5000, 5000, 5000, 1, 2, 3, 4, 5]) == 24999998\n assert candidate(nums = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 1, 2, 3, 4, 5]) == 99970000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 8800\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10000]) == 49975\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 1810\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]) == 2485\n assert candidate(nums = [9999, 9998, 9997, 9996, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 99970000\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 89\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 661\n assert candidate(nums = [5000, 5001, 5002, 5003, 1, 2, 3, 4]) == 25025004\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 20800\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 5200\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10000]) == 89998\n", "comparison": "exact"}, "public_tests": ["[5,6,2,7,4]", "[4,2,5,9,7,4,8]"], "hints": ["If you only had to find the maximum product of 2 numbers in an array, which 2 numbers should you choose?", "We only need to worry about 4 numbers in the array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxProductDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:51+00:00", "tests_total": 98, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "sorting", "quicksort"]}, "language": "php", "interface": {"raw_signature": "function maxProductDifference($nums) {", "container": "Solution", "callable": "maxProductDifference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1914, "task_id": "cyclically-rotating-a-grid", "difficulty": "Medium", "problem_description": "You are given an m x n integer matrix grid, where m and n are both even integers, and an integer k.\n\nThe matrix is composed of several layers, which is shown in the below image, where each color is its own layer:\n\nA cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the counter-clockwise direction. An example rotation is shown below:\n\nReturn the matrix after applying k cyclic rotations to it.\n\nExample 1:\n\nInput: grid = [[40,10],[30,20]], k = 1\nOutput: [[10,20],[40,30]]\nExplanation: The figures above represent the grid at every state.\n\nExample 2:\n\nInput: grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\nOutput: [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\nExplanation: The figures above represent the grid at every state.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 50\n- Both m and n are even integers.\n- 1 <= grid[i][j] <=5000\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8]],k = 1) == [[2, 4], [1, 6], [3, 8], [5, 7]]\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]],k = 4) == [[5, 6, 7, 8, 16, 24, 32, 40], [4, 14, 15, 23, 31, 39, 47, 48], [3, 13, 30, 38, 46, 45, 55, 56], [2, 12, 22, 28, 29, 44, 54, 64], [1, 11, 21, 36, 37, 43, 53, 63], [9, 10, 20, 19, 27, 35, 52, 62], [17, 18, 26, 34, 42, 50, 51, 61], [25, 33, 41, 49, 57, 58, 59, 60]]\n assert candidate(grid = [[100, 200, 300, 400], [500, 600, 700, 800], [900, 1000, 1100, 1200], [1300, 1400, 1500, 1600]],k = 10) == [[900, 500, 100, 200], [1300, 1100, 1000, 300], [1400, 700, 600, 400], [1500, 1600, 1200, 800]]\n assert candidate(grid = [[100, 101, 102], [99, 103, 104], [98, 105, 106]],k = 4) == [[106, 105, 98], [104, 103, 99], [102, 101, 100]]\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8]],k = 5) == [[7, 5], [8, 3], [6, 1], [4, 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, 24], [25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36]],k = 3) == [[4, 5, 6, 12, 18, 24], [3, 11, 17, 23, 29, 30], [2, 10, 21, 15, 28, 36], [1, 9, 22, 16, 27, 35], [7, 8, 14, 20, 26, 34], [13, 19, 25, 31, 32, 33]]\n assert candidate(grid = [[5000, 5000, 5000, 5000], [5000, 1, 2, 5000], [5000, 4, 3, 5000], [5000, 5000, 5000, 5000]],k = 1000000000) == [[5000, 5000, 5000, 5000], [5000, 1, 2, 5000], [5000, 4, 3, 5000], [5000, 5000, 5000, 5000]]\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 1000000000) == [[8, 12, 16, 15], [4, 6, 7, 14], [3, 10, 11, 13], [2, 1, 5, 9]]\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 2) == [[3, 4, 8, 12], [2, 11, 10, 16], [1, 7, 6, 15], [5, 9, 13, 14]]\n assert candidate(grid = [[40, 10], [30, 20]],k = 1) == [[10, 20], [40, 30]]\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]],k = 7) == [[150, 140, 130, 90], [160, 100, 60, 50], [120, 110, 70, 10], [80, 40, 30, 20]]\n assert candidate(grid = [[100, 101, 102, 103, 104, 105, 106, 107], [108, 11, 12, 13, 14, 15, 16, 109], [110, 17, 18, 19, 20, 21, 22, 111], [112, 23, 24, 25, 26, 27, 28, 113], [114, 29, 30, 31, 32, 33, 34, 115], [116, 35, 36, 37, 38, 39, 40, 117], [118, 41, 42, 43, 44, 45, 46, 119], [120, 121, 122, 123, 124, 125, 126, 127]],k = 10) == [[113, 115, 117, 119, 127, 126, 125, 124], [111, 46, 45, 44, 43, 42, 41, 123], [109, 40, 30, 24, 18, 19, 35, 122], [107, 34, 36, 32, 31, 20, 29, 121], [106, 28, 37, 26, 25, 21, 23, 120], [105, 22, 38, 39, 33, 27, 17, 118], [104, 16, 15, 14, 13, 12, 11, 116], [103, 102, 101, 100, 108, 110, 112, 114]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2]],k = 50) == [[1, 1, 1, 1, 1, 1, 1, 2], [1, 7, 6, 5, 4, 3, 2, 3], [2, 7, 5, 6, 6, 6, 2, 4], [3, 7, 4, 5, 4, 6, 2, 5], [4, 7, 3, 5, 4, 5, 2, 6], [5, 7, 3, 3, 3, 4, 2, 7], [6, 7, 6, 5, 4, 3, 2, 8], [7, 2, 2, 2, 2, 2, 2, 2]]\n assert candidate(grid = [[6, 7, 8, 9], [5, 2, 3, 10], [4, 1, 12, 11], [13, 14, 15, 16]],k = 3) == [[9, 10, 11, 16], [8, 1, 2, 15], [7, 12, 3, 14], [6, 5, 4, 13]]\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]],k = 500000000) == [[1, 2, 3, 4], [5, 22, 18, 8], [9, 26, 14, 12], [13, 27, 10, 16], [17, 23, 6, 20], [21, 19, 7, 24], [25, 15, 11, 28], [29, 30, 31, 32]]\n assert candidate(grid = [[5000, 5000, 5000, 5000, 5000, 5000], [5000, 1, 2, 3, 4, 5000], [5000, 6, 7, 8, 9, 5000], [5000, 10, 11, 12, 13, 5000], [5000, 14, 15, 16, 17, 5000], [5000, 5000, 5000, 5000, 5000, 5000]],k = 1000000000) == [[5000, 5000, 5000, 5000, 5000, 5000], [5000, 9, 13, 17, 16, 5000], [5000, 4, 7, 8, 15, 5000], [5000, 3, 11, 12, 14, 5000], [5000, 2, 1, 6, 10, 5000], [5000, 5000, 5000, 5000, 5000, 5000]]\n assert candidate(grid = [[100, 101, 102, 103, 104], [99, 49, 50, 51, 105], [98, 48, 1, 2, 106], [97, 47, 46, 3, 107], [96, 95, 94, 93, 108]],k = 7) == [[107, 108, 93, 94, 95], [106, 48, 49, 50, 96], [105, 47, 1, 51, 97], [104, 46, 3, 2, 98], [103, 102, 101, 100, 99]]\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]],k = 25) == [[25, 17, 9, 1, 2, 3, 4, 5], [33, 15, 23, 31, 39, 47, 55, 6], [41, 14, 20, 21, 22, 30, 54, 7], [49, 13, 19, 29, 37, 38, 53, 8], [57, 12, 27, 28, 36, 46, 52, 16], [58, 11, 35, 43, 44, 45, 51, 24], [59, 10, 18, 26, 34, 42, 50, 32], [60, 61, 62, 63, 64, 56, 48, 40]]\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]],k = 13) == [[16, 11, 6, 1, 2], [21, 18, 17, 12, 3], [22, 19, 13, 7, 4], [23, 14, 9, 8, 5], [24, 25, 20, 15, 10]]\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, 1], [1, 2, 3, 4, 4, 3, 2, 1], [1, 2, 3, 3, 3, 3, 2, 1], [1, 2, 2, 2, 2, 2, 2, 1]],k = 5) == [[1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 3, 2, 2, 1], [1, 2, 4, 3, 4, 4, 3, 1], [1, 2, 3, 4, 5, 3, 3, 2], [1, 2, 3, 4, 4, 3, 3, 2], [1, 2, 3, 3, 3, 3, 3, 2], [1, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 2, 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, 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]],k = 10) == [[32, 40, 48, 56, 64, 63, 62, 61], [24, 55, 54, 53, 52, 51, 50, 60], [16, 47, 35, 27, 19, 20, 42, 59], [8, 39, 43, 37, 36, 21, 34, 58], [7, 31, 44, 29, 28, 22, 26, 57], [6, 23, 45, 46, 38, 30, 18, 49], [5, 15, 14, 13, 12, 11, 10, 41], [4, 3, 2, 1, 9, 17, 25, 33]]\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]],k = 100) == [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]]\n assert candidate(grid = [[2, 3, 4, 5, 6, 7, 8], [1, 14, 13, 12, 11, 10, 9], [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 = 25) == [[3, 4, 5, 6, 7, 8, 9], [2, 40, 39, 38, 37, 30, 21], [1, 41, 18, 19, 26, 23, 28], [15, 34, 17, 25, 33, 16, 35], [22, 27, 24, 31, 32, 14, 42], [29, 20, 10, 11, 12, 13, 49], [36, 43, 44, 45, 46, 47, 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]],k = 100) == [[5, 6, 12, 18, 24, 30], [4, 17, 23, 29, 35, 36], [3, 11, 34, 33, 41, 42], [2, 10, 28, 27, 40, 48], [1, 9, 22, 21, 39, 47], [7, 8, 16, 15, 38, 46], [13, 14, 20, 26, 32, 45], [19, 25, 31, 37, 43, 44]]\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]],k = 5) == [[6, 12, 18, 24, 30, 36], [5, 23, 29, 28, 27, 35], [4, 17, 16, 22, 26, 34], [3, 11, 15, 21, 20, 33], [2, 10, 9, 8, 14, 32], [1, 7, 13, 19, 25, 31]]\n assert candidate(grid = [[9, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2], [1, 2, 3, 4, 5, 6, 7, 2]],k = 100) == [[6, 5, 4, 3, 2, 1, 1, 1], [7, 2, 3, 4, 5, 6, 7, 1], [2, 2, 6, 6, 6, 5, 7, 1], [2, 2, 6, 4, 5, 4, 7, 1], [2, 2, 5, 4, 5, 3, 7, 1], [2, 2, 4, 3, 3, 3, 7, 9], [2, 2, 3, 4, 5, 6, 7, 2], [2, 2, 8, 7, 6, 5, 4, 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], [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 = 1000000000) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 65, 64, 63, 62, 52, 42, 32, 22, 20], [21, 66, 23, 24, 25, 26, 27, 28, 12, 30], [31, 67, 33, 34, 35, 36, 37, 38, 13, 40], [41, 68, 43, 44, 45, 46, 47, 48, 14, 50], [51, 69, 53, 54, 55, 56, 57, 58, 15, 60], [61, 59, 49, 39, 29, 19, 18, 17, 16, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80]]\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]],k = 20) == [[58, 57, 49, 41, 33, 25, 17, 9], [59, 10, 11, 12, 13, 14, 15, 1], [60, 18, 44, 43, 35, 27, 23, 2], [61, 26, 45, 28, 29, 19, 31, 3], [62, 34, 46, 36, 37, 20, 39, 4], [63, 42, 38, 30, 22, 21, 47, 5], [64, 50, 51, 52, 53, 54, 55, 6], [56, 48, 40, 32, 24, 16, 8, 7]]\n assert candidate(grid = [[9, 10, 11, 12, 13, 14], [8, 17, 18, 19, 20, 15], [7, 16, 25, 26, 21, 16], [6, 15, 24, 23, 22, 17], [5, 14, 13, 12, 11, 18], [4, 3, 2, 1, 0, 19]],k = 23) == [[12, 13, 14, 15, 16, 17], [11, 16, 17, 18, 19, 18], [10, 15, 24, 25, 20, 19], [9, 14, 23, 26, 21, 0], [8, 13, 12, 11, 22, 1], [7, 6, 5, 4, 3, 2]]\n assert candidate(grid = [[5000, 1, 2, 3, 4, 5, 6, 5000], [5000, 5000, 1, 2, 3, 4, 5000, 5000], [5000, 5000, 5000, 1, 2, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 1, 2, 5000, 5000, 5000], [5000, 5000, 1, 2, 3, 4, 5000, 5000], [5000, 1, 2, 3, 4, 5, 6, 5000], [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]],k = 1000000000) == [[5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 1, 2, 3, 4, 5000, 5000], [5000, 5000, 5000, 5000, 4, 3, 5000, 1], [5000, 5000, 5000, 5000, 5000, 2, 5000, 2], [5000, 5000, 2, 1, 2, 1, 5000, 3], [5000, 5000, 1, 5000, 5000, 5000, 5000, 4], [5000, 1, 2, 3, 4, 5, 6, 5], [5000, 5000, 5000, 5000, 5000, 5000, 5000, 6]]\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]],k = 4) == [[1, 1, 2, 3, 4, 5], [1, 3, 4, 5, 5, 6], [1, 2, 3, 3, 5, 6], [1, 2, 4, 4, 5, 6], [1, 2, 2, 3, 4, 6], [2, 3, 4, 5, 6, 6]]\n assert candidate(grid = [[5, 5, 5, 5, 5, 5], [5, 1, 2, 3, 4, 5], [5, 6, 7, 8, 9, 5], [5, 10, 11, 12, 13, 5], [5, 14, 15, 16, 17, 5], [5, 5, 5, 5, 5, 5]],k = 15) == [[5, 5, 5, 5, 5, 5], [5, 4, 9, 13, 17, 5], [5, 3, 11, 7, 16, 5], [5, 2, 12, 8, 15, 5], [5, 1, 6, 10, 14, 5], [5, 5, 5, 5, 5, 5]]\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]],k = 50) == [[49, 41, 33, 25, 17, 9, 1, 2], [57, 55, 54, 53, 52, 51, 50, 3], [58, 47, 21, 22, 30, 38, 42, 4], [59, 39, 20, 37, 36, 46, 34, 5], [60, 31, 19, 29, 28, 45, 26, 6], [61, 23, 27, 35, 43, 44, 18, 7], [62, 15, 14, 13, 12, 11, 10, 8], [63, 64, 56, 48, 40, 32, 24, 16]]\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]],k = 15) == [[63, 62, 61, 60, 59, 58, 57, 49], [64, 50, 42, 34, 26, 18, 10, 41], [56, 51, 22, 30, 38, 46, 11, 33], [48, 52, 21, 36, 28, 45, 12, 25], [40, 53, 20, 37, 29, 44, 13, 17], [32, 54, 19, 27, 35, 43, 14, 9], [24, 55, 47, 39, 31, 23, 15, 1], [16, 8, 7, 6, 5, 4, 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, 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]],k = 5) == [[6, 7, 8, 16, 24, 32, 40, 48], [5, 15, 23, 31, 39, 47, 55, 56], [4, 14, 38, 46, 45, 44, 54, 64], [3, 13, 30, 29, 37, 43, 53, 63], [2, 12, 22, 28, 36, 35, 52, 62], [1, 11, 21, 20, 19, 27, 51, 61], [9, 10, 18, 26, 34, 42, 50, 60], [17, 25, 33, 41, 49, 57, 58, 59]]\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]],k = 15) == [[31, 25, 19, 13, 7, 1], [32, 11, 17, 23, 29, 2], [33, 10, 21, 15, 28, 3], [34, 9, 22, 16, 27, 4], [35, 8, 14, 20, 26, 5], [36, 30, 24, 18, 12, 6]]\n assert candidate(grid = [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]],k = 3) == [[4, 5, 6, 7], [3, 16, 13, 8], [2, 15, 14, 9], [1, 12, 11, 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, 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]],k = 1000000000) == [[44, 43, 37, 31, 25, 19], [45, 8, 9, 10, 11, 13], [46, 14, 15, 16, 17, 7], [47, 20, 21, 22, 23, 1], [48, 26, 27, 28, 29, 2], [42, 32, 33, 34, 35, 3], [36, 38, 39, 40, 41, 4], [30, 24, 18, 12, 6, 5]]\n assert candidate(grid = [[6, 7, 8, 9, 10], [5, 4, 3, 2, 11], [14, 13, 12, 1, 15], [19, 18, 17, 16, 20], [24, 23, 22, 21, 25]],k = 3) == [[9, 10, 11, 15, 20], [8, 1, 16, 17, 25], [7, 2, 12, 18, 21], [6, 3, 4, 13, 22], [5, 14, 19, 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, 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 = 15) == [[46, 45, 44, 43, 36, 29, 22], [47, 16, 9, 10, 11, 12, 15], [48, 23, 24, 17, 18, 13, 8], [49, 30, 31, 25, 19, 20, 1], [42, 37, 32, 33, 26, 27, 2], [35, 38, 39, 40, 41, 34, 3], [28, 21, 14, 7, 6, 5, 4]]\n assert candidate(grid = [[4, 3, 2, 1, 0], [9, 8, 7, 6, 5], [14, 13, 12, 11, 10], [19, 18, 17, 16, 15], [24, 23, 22, 21, 20]],k = 3) == [[1, 0, 5, 10, 15], [2, 11, 16, 17, 20], [3, 6, 12, 18, 21], [4, 7, 8, 13, 22], [9, 14, 19, 24, 23]]\n assert candidate(grid = [[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]],k = 7) == [[180, 240, 300, 360, 350, 340], [120, 280, 270, 260, 200, 330], [60, 290, 210, 150, 140, 320], [50, 230, 220, 160, 80, 310], [40, 170, 110, 100, 90, 250], [30, 20, 10, 70, 130, 190]]\n assert candidate(grid = [[100, 101, 102, 103, 104, 105, 106, 107, 108, 109], [110, 1, 2, 3, 4, 5, 6, 7, 8, 111], [112, 9, 12, 13, 14, 15, 16, 17, 9, 113], [114, 8, 11, 18, 19, 20, 21, 10, 12, 115], [116, 7, 10, 19, 22, 23, 18, 11, 13, 117], [118, 6, 9, 20, 25, 24, 17, 12, 14, 119], [120, 5, 8, 21, 26, 27, 22, 13, 15, 121], [122, 4, 7, 28, 29, 30, 25, 14, 16, 123], [124, 3, 6, 31, 32, 33, 34, 26, 17, 125], [126, 2, 5, 35, 36, 37, 38, 39, 40, 127]],k = 15) == [[121, 123, 125, 127, 40, 39, 38, 37, 36, 35], [119, 26, 34, 33, 32, 31, 6, 3, 4, 5], [117, 17, 7, 8, 9, 10, 11, 12, 5, 2], [115, 16, 28, 21, 18, 17, 22, 13, 6, 126], [113, 15, 29, 20, 25, 22, 27, 14, 7, 124], [111, 14, 30, 19, 24, 23, 26, 15, 8, 122], [109, 13, 25, 18, 19, 20, 21, 16, 9, 120], [108, 12, 14, 13, 12, 11, 10, 17, 1, 118], [107, 9, 8, 7, 6, 5, 4, 3, 2, 116], [106, 105, 104, 103, 102, 101, 100, 110, 112, 114]]\n assert candidate(grid = [[100, 200, 300, 400], [201, 5, 6, 501], [202, 7, 8, 502], [303, 403, 503, 600]],k = 3) == [[400, 501, 502, 600], [300, 7, 5, 503], [200, 8, 6, 403], [100, 201, 202, 303]]\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]],k = 15) == [[31, 25, 19, 13, 7, 1], [32, 11, 17, 23, 29, 2], [33, 10, 21, 15, 28, 3], [34, 9, 22, 16, 27, 4], [35, 8, 14, 20, 26, 5], [36, 30, 24, 18, 12, 6]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [21, 22, 23, 24, 25, 7], [20, 35, 36, 37, 26, 8], [19, 34, 39, 38, 27, 9], [18, 33, 32, 31, 28, 10], [17, 16, 15, 14, 13, 11]],k = 3) == [[4, 5, 6, 7, 8, 9], [3, 25, 26, 27, 28, 10], [2, 24, 39, 36, 31, 11], [1, 23, 38, 37, 32, 13], [21, 22, 35, 34, 33, 14], [20, 19, 18, 17, 16, 15]]\n assert candidate(grid = [[5000, 1, 2, 5000, 3, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000]],k = 1000000000) == [[5000, 1, 2, 5000, 3, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000], [5000, 5000, 5000, 5000, 5000, 5000]]\n assert candidate(grid = [[100, 101, 102, 103], [104, 105, 106, 107], [108, 109, 110, 111], [112, 113, 114, 115]],k = 7) == [[114, 113, 112, 108], [115, 109, 105, 104], [111, 110, 106, 100], [107, 103, 102, 101]]\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]],k = 20) == [[58, 57, 49, 41, 33, 25, 17, 9], [59, 10, 11, 12, 13, 14, 15, 1], [60, 18, 44, 43, 35, 27, 23, 2], [61, 26, 45, 28, 29, 19, 31, 3], [62, 34, 46, 36, 37, 20, 39, 4], [63, 42, 38, 30, 22, 21, 47, 5], [64, 50, 51, 52, 53, 54, 55, 6], [56, 48, 40, 32, 24, 16, 8, 7]]\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]],k = 50) == [[3, 4, 5, 10, 15], [2, 9, 14, 19, 20], [1, 8, 13, 18, 25], [6, 7, 12, 17, 24], [11, 16, 21, 22, 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, 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]],k = 7) == [[8, 16, 24, 32, 40, 48, 56, 64], [7, 31, 39, 47, 55, 54, 53, 63], [6, 23, 45, 44, 43, 35, 52, 62], [5, 15, 46, 36, 28, 27, 51, 61], [4, 14, 38, 37, 29, 19, 50, 60], [3, 13, 30, 22, 21, 20, 42, 59], [2, 12, 11, 10, 18, 26, 34, 58], [1, 9, 17, 25, 33, 41, 49, 57]]\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, 100]],k = 1000000000) == [[81, 71, 61, 51, 41, 31, 21, 11, 1, 2], [91, 83, 82, 72, 62, 52, 42, 32, 22, 3], [92, 84, 23, 24, 25, 26, 27, 28, 12, 4], [93, 85, 33, 47, 57, 67, 66, 38, 13, 5], [94, 86, 43, 37, 45, 46, 65, 48, 14, 6], [95, 87, 53, 36, 55, 56, 64, 58, 15, 7], [96, 88, 63, 35, 34, 44, 54, 68, 16, 8], [97, 89, 73, 74, 75, 76, 77, 78, 17, 9], [98, 79, 69, 59, 49, 39, 29, 19, 18, 10], [99, 100, 90, 80, 70, 60, 50, 40, 30, 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, 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 = 50) == [[60, 70, 80, 90, 100, 99, 98, 97, 96, 95], [50, 72, 62, 52, 42, 32, 22, 12, 13, 94], [40, 82, 78, 77, 76, 75, 74, 73, 14, 93], [30, 83, 68, 36, 37, 47, 57, 63, 15, 92], [20, 84, 58, 35, 56, 55, 67, 53, 16, 91], [10, 85, 48, 34, 46, 45, 66, 43, 17, 81], [9, 86, 38, 44, 54, 64, 65, 33, 18, 71], [8, 87, 28, 27, 26, 25, 24, 23, 19, 61], [7, 88, 89, 79, 69, 59, 49, 39, 29, 51], [6, 5, 4, 3, 2, 1, 11, 21, 31, 41]]\n", "comparison": "exact"}, "public_tests": ["[[40,10],[30,20]]\n1", "[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]\n2"], "hints": ["First, you need to consider each layer separately as an array.", "Just cycle this array and then re-assign it."], "metadata": {"canonical_parameter_names": ["grid", "k"], "leetcode_dataset_entry_point": "Solution().rotateGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:53+00:00", "tests_total": 57, "tests_dropped": 4, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function rotateGrid($grid, $k) {", "container": "Solution", "callable": "rotateGrid", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1915, "task_id": "number-of-wonderful-substrings", "difficulty": "Medium", "problem_description": "A wonderful string is a string where at most one letter appears an odd number of times.\n\n- For example, \"ccjjc\" and \"abab\" are wonderful, but \"ab\" is not.\n\nGiven a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: word = \"aba\"\nOutput: 4\nExplanation: The four wonderful substrings are underlined below:\n- \"aba\" -> \"a\"\n- \"aba\" -> \"b\"\n- \"aba\" -> \"a\"\n- \"aba\" -> \"aba\"\n\nExample 2:\n\nInput: word = \"aabb\"\nOutput: 9\nExplanation: The nine wonderful substrings are underlined below:\n- \"aabb\" -> \"a\"\n- \"aabb\" -> \"aa\"\n- \"aabb\" -> \"aab\"\n- \"aabb\" -> \"aabb\"\n- \"aabb\" -> \"a\"\n- \"aabb\" -> \"abb\"\n- \"aabb\" -> \"b\"\n- \"aabb\" -> \"bb\"\n- \"aabb\" -> \"b\"\n\nExample 3:\n\nInput: word = \"he\"\nOutput: 2\nExplanation: The two wonderful substrings are underlined below:\n- \"he\" -> \"h\"\n- \"he\" -> \"e\"\n\nConstraints:\n\n- 1 <= word.length <= 10^5\n- word consists of lowercase English letters from 'a' to 'j'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aaaaaaaaaa\") == 55\n assert candidate(word = \"aabbccddeeffgghhiijj\") == 165\n assert candidate(word = \"aba\") == 4\n assert candidate(word = \"aaaabbbbcccc\") == 66\n assert candidate(word = \"babcbabcbab\") == 32\n assert candidate(word = \"abcdefghija\") == 11\n assert candidate(word = \"abcdcba\") == 10\n assert candidate(word = \"aaa\") == 6\n assert candidate(word = \"aabb\") == 9\n assert candidate(word = \"aabbccddeeffgg\") == 84\n assert candidate(word = \"abcdefghij\") == 10\n assert candidate(word = \"jihgfedcba\") == 10\n assert candidate(word = \"aabbccddeeff\") == 63\n assert candidate(word = \"abcabc\") == 9\n assert candidate(word = \"abacaba\") == 12\n assert candidate(word = \"jij\") == 4\n assert candidate(word = \"abcdefghijabcdefghij\") == 23\n assert candidate(word = \"abcde\") == 5\n assert candidate(word = \"ijji\") == 8\n assert candidate(word = \"jjjjj\") == 15\n assert candidate(word = \"jijijijiji\") == 40\n assert candidate(word = \"aabbaa\") == 19\n assert candidate(word = \"abcabcabc\") == 21\n assert candidate(word = \"he\") == 2\n assert candidate(word = \"a\") == 1\n assert candidate(word = \"abcdefghijabcdefghijabcdefghij\") == 63\n assert candidate(word = \"jijjjijijj\") == 41\n assert candidate(word = \"aaaaaaa\") == 28\n assert candidate(word = \"aaaaa\") == 15\n assert candidate(word = \"abacabadabacaba\") == 32\n assert candidate(word = \"aaaaaaaabbbbbbbbaaaaaaaabbbbbbbb\") == 464\n assert candidate(word = \"jihgfedcbajihgfedcbajihgfedcbajihgfedcbajihgfedcba\") == 176\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 1038\n assert candidate(word = \"jijijiijijijiijijijiijijijiijijijiijijijiijijiij\") == 879\n assert candidate(word = \"abcdefghijabcde\") == 15\n assert candidate(word = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\") == 903\n assert candidate(word = \"acacacacacacacacacac\") == 155\n assert candidate(word = \"jijijiijjjjijiijijijiijjjjijiijijijiijjjjijiijijijiijjjjijiijijijiijjjjijiijijijiijjjjijiijijijiijjjjijiijijijiijjjjj\") == 5171\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 106\n assert candidate(word = \"aabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccdd\") == 4720\n assert candidate(word = \"aabbaaabbbaaabbaaa\") == 126\n assert candidate(word = \"jjiijjiijjjiiijjiiijjjijjjiiijjiiijjjijjjjj\") == 721\n assert candidate(word = \"aabbaabbaabbaabb\") == 120\n assert candidate(word = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\") == 990\n assert candidate(word = \"aabbaabbaabbaabbccddeeffgghhiijj\") == 420\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabc\") == 225\n assert candidate(word = \"abcdeedcba\") == 23\n assert candidate(word = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjj\") == 640\n assert candidate(word = \"abcdabcdaabbccddeeffgghhiijj\") == 222\n assert candidate(word = \"ababababababababababababababababababababab\") == 672\n assert candidate(word = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\") == 2485\n assert candidate(word = \"jijijiijjjijiiiiij\") == 132\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 176\n assert candidate(word = \"ababababababababababababab\") == 260\n assert candidate(word = \"aabbaaabbbaaabbaaabbba\") == 187\n assert candidate(word = \"acccabbbdcbaaaccbbaaccbbcdac\") == 161\n assert candidate(word = \"aabbaaabbbaaaabbbaaa\") == 159\n assert candidate(word = \"abcabcabcabcabc\") == 57\n assert candidate(word = \"jjjjjjjjjj\") == 55\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 670\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 452\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee\") == 1025\n assert candidate(word = \"abcdefghijabcdeijfgh\") == 23\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 820\n assert candidate(word = \"aaaaaaaaaabbbbbbbbbbbbccccccccccdddddddddd\") == 738\n assert candidate(word = \"aabbccddeeaabbccddeeaabbccddeedcba\") == 403\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 715\n assert candidate(word = \"babababababababababa\") == 155\n assert candidate(word = \"aabbccddeeffgghhiijjijjiihhggeeffddccbbaa\") == 501\n assert candidate(word = \"aabbccddeeffgghhiijjabcdefghijabcdefghijabcdefghijabcdefghij\") == 363\n assert candidate(word = \"abcabccbaabccbaabcabccbaabccba\") == 225\n assert candidate(word = \"abcdefghijjihgfedcba\") == 48\n assert candidate(word = \"abacabadabacabadabacabad\") == 90\n assert candidate(word = \"abababababababababababababababab\") == 392\n assert candidate(word = \"abacabadabacabadabacabadabacabad\") == 154\n", "comparison": "exact"}, "public_tests": ["\"aba\"", "\"aabb\"", "\"he\""], "hints": ["For each prefix of the string, check which characters are of even frequency and which are not and represent it by a bitmask.", "Find the other prefixes whose masks differs from the current prefix mask by at most one bit."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().wonderfulSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:55+00:00", "tests_total": 77, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "string", "bit-manipulation", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function wonderfulSubstrings($word) {", "container": "Solution", "callable": "wonderfulSubstrings", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1916, "task_id": "count-ways-to-build-rooms-in-an-ant-colony", "difficulty": "Hard", "problem_description": "You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and these two rooms must be connected directly. Room 0 is already built, so prevRoom[0] = -1. The expansion plan is given such that once all the rooms are built, every room will be reachable from room 0.\n\nYou can only build one room at a time, and you can travel freely between rooms you have already built only if they are connected. You can choose to build any room as long as its previous room is already built.\n\nReturn the number of different orders you can build all the rooms in. Since the answer may be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: prevRoom = [-1,0,1]\nOutput: 1\nExplanation: There is only one way to build the additional rooms: 0 → 1 → 2\n\nExample 2:\n\nInput: prevRoom = [-1,0,0,1,2]\nOutput: 6\nExplanation:\nThe 6 ways are:\n0 → 1 → 3 → 2 → 4\n0 → 2 → 4 → 1 → 3\n0 → 1 → 2 → 3 → 4\n0 → 1 → 2 → 4 → 3\n0 → 2 → 1 → 3 → 4\n0 → 2 → 1 → 4 → 3\n\nConstraints:\n\n- n == prevRoom.length\n- 2 <= n <= 10^5\n- prevRoom[0] == -1\n- 0 <= prevRoom[i] < n for all 1 <= i < n\n- Every room is reachable from room 0 once all the rooms are built.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9]) == 258365767\n assert candidate(prevRoom = [-1, 0, 1, 1, 2, 2]) == 8\n assert candidate(prevRoom = [-1, 0, 0, 1, 2]) == 6\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2]) == 80\n assert candidate(prevRoom = [-1, 0, 1]) == 1\n assert candidate(prevRoom = [-1, 0, 0, 0]) == 6\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 2, 2]) == 120\n assert candidate(prevRoom = [-1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 896\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 4]) == 1\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4]) == 3360\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]) == 1\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 2, 2]) == 560\n assert candidate(prevRoom = [-1, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12]) == 645120\n assert candidate(prevRoom = [-1, 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]) == 203434154\n assert candidate(prevRoom = [-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]) == 37717233\n assert candidate(prevRoom = [-1, 0, 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]) == 118354482\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14]) == 2\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 977384288\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 1\n assert candidate(prevRoom = [-1, 0, 1, 2, 1, 4, 2, 6, 5, 7, 5, 9, 8, 10, 9, 11, 12, 13, 14, 10]) == 245044800\n assert candidate(prevRoom = [-1, 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, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14]) == 645247453\n assert candidate(prevRoom = [-1, 0, 0, 2, 2, 1, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 466985999\n assert candidate(prevRoom = [-1, 0, 1, 2, 0, 2, 3, 4, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 11, 12]) == 777509735\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 960269310\n assert candidate(prevRoom = [-1, 0, 0, 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]) == 270200339\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 815328371\n assert candidate(prevRoom = [-1, 0, 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, 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]) == 558903913\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 1, 3, 4, 3, 5, 6, 7, 5, 8, 9, 10, 11, 12, 11, 13, 14, 15, 16, 17, 18]) == 574577861\n assert candidate(prevRoom = [-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]) == 1\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == 594293086\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 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, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 65279563\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 258365767\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6]) == 916824814\n assert candidate(prevRoom = [-1, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5]) == 499858301\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 144195955\n assert candidate(prevRoom = [-1, 0, 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, 14, 15, 15, 16, 16, 17, 17]) == 977718734\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 927211300\n assert candidate(prevRoom = [-1, 0, 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]) == 214454105\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 881663664\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7]) == 182996126\n assert candidate(prevRoom = [-1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 904828424\n assert candidate(prevRoom = [-1, 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]) == 19170323\n assert candidate(prevRoom = [-1, 0, 0, 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, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 232266423\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 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]) == 281601700\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 134837072\n assert candidate(prevRoom = [-1, 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, 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]) == 151296514\n assert candidate(prevRoom = [-1, 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]) == 580542770\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 374254273\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 506880\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 4036032\n assert candidate(prevRoom = [-1, 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]) == 457389881\n assert candidate(prevRoom = [-1, 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]) == 862785756\n assert candidate(prevRoom = [-1, 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, 20, 20]) == 259495482\n assert candidate(prevRoom = [-1, 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, 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]) == 104533170\n assert candidate(prevRoom = [-1, 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]) == 944857254\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 185834123\n assert candidate(prevRoom = [-1, 0, 1, 2, 3, 0, 5, 6, 7, 8, 4, 11, 12, 13, 14, 10, 16, 17, 18, 19]) == 462\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 686400\n assert candidate(prevRoom = [-1, 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12]) == 846964197\n assert candidate(prevRoom = [-1, 0, 0, 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]) == 839553459\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 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]) == 864359005\n assert candidate(prevRoom = [-1, 0, 1, 0, 2, 3, 2, 4, 5, 6, 5, 7, 8, 9, 10, 11, 10, 11, 12, 13, 14, 15, 14, 15, 16, 17, 18, 19, 20]) == 696057029\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5]) == 495153778\n assert candidate(prevRoom = [-1, 0, 1, 2, 1, 4, 5, 6, 4, 8, 9, 5, 10, 11, 6, 12, 13, 7, 14, 15, 8, 16, 17, 9, 18, 19]) == 298444100\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]) == 980653881\n assert candidate(prevRoom = [-1, 0, 1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 185998261\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 820019200\n assert candidate(prevRoom = [-1, 0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24]) == 316920121\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 645414306\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 1, 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]) == 989258543\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 414301485\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7]) == 452706138\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 37717233\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 185998261\n assert candidate(prevRoom = [-1, 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, 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]) == 764478009\n assert candidate(prevRoom = [-1, 0, 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]) == 874133999\n assert candidate(prevRoom = [-1, 0, 1, 1, 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, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 838387635\n assert candidate(prevRoom = [-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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 544962428\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 268444119\n assert candidate(prevRoom = [-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(prevRoom = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24]) == 435629637\n assert candidate(prevRoom = [-1, 0, 1, 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, 11, 11, 11, 11]) == 59583424\n assert candidate(prevRoom = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29]) == 468972288\n assert candidate(prevRoom = [-1, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 930392109\n assert candidate(prevRoom = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 466985999\n assert candidate(prevRoom = [-1, 0, 0, 0, 1, 1, 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, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17]) == 715654985\n assert candidate(prevRoom = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4]) == 199114634\n assert candidate(prevRoom = [-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]) == 1\n", "comparison": "exact"}, "public_tests": ["[-1,0,1]", "[-1,0,0,1,2]"], "hints": ["Use dynamic programming.", "Let dp[i] be the number of ways to solve the problem for the subtree of node i.", "Imagine you are trying to fill an array with the order of traversal, dp[i] equals the multiplications of the number of ways to distribute the subtrees of the children of i on the array using combinatorics, multiplied bu their dp values."], "metadata": {"canonical_parameter_names": ["prevRoom"], "leetcode_dataset_entry_point": "Solution().waysToBuildRooms", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:34:58+00:00", "tests_total": 89, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "dynamic-programming", "tree", "depth-first-search", "graph", "topological-sort", "combinatorics", "dp-on-trees", "fermats-little-theorem"]}, "language": "php", "interface": {"raw_signature": "function waysToBuildRooms($prevRoom) {", "container": "Solution", "callable": "waysToBuildRooms", "parameters": [{"name": "prevRoom", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1920, "task_id": "build-array-from-permutation", "difficulty": "Easy", "problem_description": "Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.\n\nA zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).\n\nExample 1:\n\nInput: nums = [0,2,1,5,3,4]\nOutput: [0,1,2,4,5,3]\nExplanation: The array ans is built as follows:\nans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]\n = [0,1,2,4,5,3]\n\nExample 2:\n\nInput: nums = [5,0,1,2,3,4]\nOutput: [4,5,0,1,2,3]\nExplanation: The array ans is built as follows:\nans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]\n = [4,5,0,1,2,3]\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 0 <= nums[i] < nums.length\n- The elements in nums are distinct.\n\nFollow-up: Can you solve it without using an extra space (i.e., O(1) memory)?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 0, 2, 1, 3]) == [3, 4, 2, 0, 1]\n assert candidate(nums = [3, 2, 1, 0]) == [0, 1, 2, 3]\n assert candidate(nums = [5, 0, 1, 2, 3, 4]) == [4, 5, 0, 1, 2, 3]\n assert candidate(nums = [1, 0, 3, 2]) == [0, 1, 2, 3]\n assert candidate(nums = [0, 1, 2, 3]) == [0, 1, 2, 3]\n assert candidate(nums = [0, 2, 1, 5, 3, 4]) == [0, 1, 2, 4, 5, 3]\n assert candidate(nums = [1, 0, 2, 3]) == [0, 1, 2, 3]\n assert candidate(nums = [4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4]\n assert candidate(nums = [1, 0]) == [0, 1]\n assert candidate(nums = [1, 5, 4, 3, 2, 0, 8, 7, 6, 9]) == [5, 0, 2, 3, 4, 1, 6, 7, 8, 9]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [15, 2, 12, 11, 9, 4, 8, 13, 10, 7, 5, 6, 3, 14, 1, 0]) == [0, 12, 3, 6, 7, 9, 10, 14, 5, 13, 4, 8, 11, 1, 2, 15]\n assert candidate(nums = [15, 10, 5, 0, 14, 9, 4, 13, 8, 3, 12, 7, 2, 11, 6, 1]) == [1, 12, 9, 15, 6, 3, 14, 11, 8, 0, 2, 13, 5, 7, 4, 10]\n assert candidate(nums = [1, 3, 0, 2, 6, 5, 4, 7, 9, 8]) == [3, 2, 1, 0, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [8, 0, 4, 1, 3, 7, 6, 2, 5, 9]) == [5, 8, 3, 0, 1, 2, 6, 4, 7, 9]\n assert candidate(nums = [21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]\n assert candidate(nums = [1, 2, 3, 0, 4, 5, 6]) == [2, 3, 0, 1, 4, 5, 6]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(nums = [6, 2, 0, 4, 5, 1, 3]) == [3, 0, 6, 5, 1, 2, 4]\n assert candidate(nums = [9, 3, 2, 8, 4, 5, 7, 0, 6, 1]) == [1, 8, 2, 6, 4, 5, 0, 9, 7, 3]\n assert candidate(nums = [7, 5, 9, 8, 6, 0, 1, 2, 4, 3]) == [2, 0, 3, 4, 1, 7, 5, 9, 6, 8]\n assert candidate(nums = [13, 9, 1, 15, 0, 14, 6, 10, 5, 2, 12, 4, 11, 7, 3, 8]) == [7, 2, 9, 8, 13, 3, 6, 12, 14, 1, 11, 0, 4, 10, 15, 5]\n assert candidate(nums = [7, 5, 2, 4, 6, 0, 3, 1]) == [1, 0, 2, 6, 3, 7, 4, 5]\n assert candidate(nums = [1, 3, 0, 2]) == [3, 2, 1, 0]\n assert candidate(nums = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [6, 2, 0, 5, 1, 4, 3]) == [3, 0, 6, 4, 2, 1, 5]\n assert candidate(nums = [2, 0, 1, 4, 3, 6, 5, 8, 7, 9, 10, 11]) == [1, 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [24, 25, 28, 0, 7, 12, 17, 29, 15, 9, 23, 21, 20, 22, 5, 27, 10, 13, 16, 3, 18, 8, 19, 11, 1, 6, 26, 4, 14, 2]) == [1, 6, 14, 24, 29, 20, 13, 2, 27, 9, 11, 8, 18, 19, 12, 4, 23, 22, 10, 0, 16, 15, 3, 21, 25, 17, 26, 7, 5, 28]\n assert candidate(nums = [2, 1, 0, 4, 3, 5, 9, 8, 6, 7]) == [0, 1, 2, 3, 4, 5, 7, 6, 9, 8]\n assert candidate(nums = [4, 5, 6, 7, 0, 1, 2, 3, 8, 9]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 0, 3, 2, 5, 4]) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [0, 3, 1, 4, 2, 5, 7, 6]) == [0, 4, 3, 2, 1, 5, 6, 7]\n assert candidate(nums = [10, 7, 8, 9, 1, 5, 6, 0, 3, 4, 2]) == [2, 0, 3, 4, 7, 5, 6, 10, 9, 1, 8]\n assert candidate(nums = [5, 8, 6, 3, 1, 0, 9, 2, 4, 7]) == [0, 4, 9, 3, 8, 5, 7, 6, 1, 2]\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 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(nums = [75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [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]\n assert candidate(nums = [0, 5, 2, 1, 6, 4, 3]) == [0, 4, 2, 5, 3, 6, 1]\n assert candidate(nums = [3, 0, 1, 4, 2]) == [4, 3, 0, 2, 1]\n assert candidate(nums = [6, 1, 0, 2, 3, 5, 4]) == [4, 1, 6, 0, 2, 5, 3]\n assert candidate(nums = [6, 0, 3, 1, 8, 9, 7, 4, 2, 5]) == [7, 6, 1, 0, 2, 5, 4, 8, 3, 9]\n assert candidate(nums = [2, 0, 1]) == [1, 2, 0]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = [2, 4, 3, 0, 1, 5, 6, 7, 8, 9]) == [3, 1, 0, 2, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [10, 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 = [8, 2, 3, 0, 4, 1, 7, 5, 9, 6]) == [9, 3, 0, 8, 4, 2, 5, 1, 6, 7]\n assert candidate(nums = [4, 8, 3, 1, 7, 10, 5, 6, 9, 0, 2, 11]) == [7, 9, 1, 8, 6, 2, 10, 5, 0, 4, 3, 11]\n assert candidate(nums = [9, 4, 3, 7, 8, 0, 2, 1, 5, 6]) == [6, 8, 7, 1, 5, 9, 3, 4, 0, 2]\n assert candidate(nums = [4, 3, 0, 1, 2]) == [2, 1, 4, 3, 0]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [0, 5, 1, 4, 6, 2, 3, 7, 8, 9]) == [0, 2, 5, 6, 3, 1, 4, 7, 8, 9]\n assert candidate(nums = [7, 5, 6, 3, 2, 1, 4, 0]) == [0, 1, 4, 3, 6, 5, 2, 7]\n assert candidate(nums = [1, 3, 0, 2, 7, 5, 8, 4, 9, 6]) == [3, 2, 1, 0, 4, 5, 9, 7, 6, 8]\n assert candidate(nums = [6, 1, 3, 5, 7, 0, 2, 4, 9, 8]) == [2, 1, 5, 0, 4, 6, 3, 7, 8, 9]\n assert candidate(nums = [34, 5, 11, 14, 2, 8, 1, 25, 16, 18, 20, 4, 0, 13, 31, 33, 10, 17, 3, 32, 23, 26, 15, 19, 6, 29, 7, 28, 24, 30, 9, 22, 12, 27, 5, 21]) == [5, 8, 4, 31, 11, 16, 5, 29, 10, 3, 23, 2, 34, 13, 22, 27, 20, 17, 14, 12, 19, 7, 33, 32, 1, 30, 25, 24, 6, 9, 18, 15, 0, 28, 8, 26]\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [6, 0, 1, 2, 3, 4, 5, 7, 8, 9]) == [5, 6, 0, 1, 2, 3, 4, 7, 8, 9]\n assert candidate(nums = [0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [59, 48, 54, 28, 74, 33, 85, 64, 80, 68, 47, 22, 25, 63, 98, 70, 19, 34, 6, 5, 82, 44, 73, 14, 72, 31, 32, 86, 3, 18, 92, 56, 53, 50, 49, 97, 90, 9, 93, 69, 37, 10, 84, 95, 35, 38, 52, 11, 62, 16, 88, 60, 42, 51, 15, 41, 77, 45, 67, 78, 46, 13, 20, 65, 87, 21, 7, 58, 36, 83, 17, 23, 29, 39, 91, 75, 61, 12, 99, 27, 94, 26, 40, 55, 1, 89, 79, 24, 57, 8, 30, 0, 43, 81, 96, 71, 66, 4, 76, 2, 59]) == [78, 62, 15, 3, 91, 50, 89, 87, 94, 36, 11, 73, 31, 65, 76, 17, 5, 49, 85, 33, 40, 35, 39, 98, 29, 56, 53, 79, 28, 6, 43, 77, 51, 88, 16, 4, 30, 68, 81, 83, 9, 47, 1, 71, 97, 93, 42, 22, 20, 19, 57, 46, 84, 60, 70, 10, 12, 38, 58, 99, 52, 63, 82, 21, 24, 44, 64, 67, 90, 55, 34, 14, 18, 69, 0, 75, 13, 25, 2, 86, 96, 32, 37, 41, 48, 8, 27, 72, 45, 80, 92, 59, 95, 26, 66, 23, 7, 74, 61, 54, 78]\n assert candidate(nums = [4, 0, 3, 1, 2]) == [2, 4, 1, 0, 3]\n assert candidate(nums = [5, 8, 4, 2, 0, 6, 7, 9, 1, 3]) == [6, 1, 0, 4, 5, 7, 9, 3, 8, 2]\n assert candidate(nums = [9, 7, 2, 3, 8, 6, 5, 0, 1, 4]) == [4, 0, 2, 3, 1, 5, 6, 9, 7, 8]\n assert candidate(nums = [10, 0, 2, 4, 1, 5, 6, 8, 3, 9, 7]) == [7, 10, 2, 1, 0, 5, 6, 3, 4, 9, 8]\n assert candidate(nums = [5, 1, 4, 8, 2, 9, 6, 0, 3, 7]) == [9, 1, 2, 3, 4, 7, 6, 5, 8, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == [0, 5, 9, 4, 1, 6, 8, 3, 2, 7]\n assert candidate(nums = [8, 11, 1, 0, 14, 9, 4, 13, 8, 3, 12, 7, 6, 10, 2, 5]) == [8, 7, 11, 8, 2, 3, 14, 10, 8, 0, 6, 13, 4, 12, 1, 9]\n assert candidate(nums = [8, 5, 2, 1, 6, 9, 7, 3, 0, 4]) == [0, 9, 2, 5, 7, 4, 3, 1, 8, 6]\n assert candidate(nums = [64, 5, 37, 49, 46, 17, 27, 47, 53, 39, 19, 35, 50, 1, 28, 58, 44, 0, 13, 20, 4, 30, 59, 10, 56, 63, 3, 31, 18, 48, 36, 24, 55, 26, 57, 34, 14, 6, 2, 40, 33, 16, 60, 25, 54, 52, 21, 62, 43, 61, 29, 38, 45, 41, 32, 51, 23, 11, 12, 42, 8, 7, 22, 15, 9, 5, 65, 37, 49, 46, 17, 27, 47, 53, 39, 19, 35, 50, 1, 28, 58, 44, 0, 13, 20, 4, 30, 59, 10, 56, 63, 3, 31, 18, 48, 36, 24, 55, 26, 57, 34, 14, 6, 2, 40, 33, 16, 60, 25, 54, 52, 21, 62, 43, 61, 29, 38, 45, 41, 32, 51, 23, 11, 12, 42, 8, 7, 22, 15, 9, 5]) == [9, 17, 6, 61, 21, 0, 31, 62, 41, 40, 20, 34, 29, 5, 18, 12, 54, 64, 1, 4, 46, 36, 42, 19, 23, 15, 49, 24, 13, 43, 14, 56, 51, 3, 11, 57, 28, 27, 37, 33, 26, 44, 8, 63, 32, 45, 30, 22, 25, 7, 48, 2, 52, 16, 55, 38, 10, 35, 50, 60, 53, 47, 59, 58, 39, 17, 5, 6, 61, 21, 0, 31, 62, 41, 40, 20, 34, 29, 5, 18, 12, 54, 64, 1, 4, 46, 36, 42, 19, 23, 15, 49, 24, 13, 43, 14, 56, 51, 3, 11, 57, 28, 27, 37, 33, 26, 44, 8, 63, 32, 45, 30, 22, 25, 7, 48, 2, 52, 16, 55, 38, 10, 35, 50, 60, 53, 47, 59, 58, 39, 17]\n assert candidate(nums = [1, 3, 5, 7, 9, 0, 2, 4, 6, 8]) == [3, 7, 0, 4, 8, 1, 5, 9, 2, 6]\n assert candidate(nums = [0, 5, 9, 1, 7, 2, 8, 4, 6, 3]) == [0, 2, 3, 5, 4, 9, 6, 7, 8, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 10, 9, 8, 7, 6]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [29, 22, 15, 8, 1, 28, 21, 14, 7, 0, 27, 20, 13, 6, 2, 26, 19, 12, 5, 3, 25, 18, 11, 4, 24, 17, 10, 16, 9, 23]) == [23, 11, 26, 7, 22, 9, 18, 2, 14, 29, 16, 25, 6, 21, 15, 10, 3, 13, 28, 8, 17, 5, 20, 1, 24, 12, 27, 19, 0, 4]\n assert candidate(nums = [0, 1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [7, 0, 5, 3, 6, 2, 4, 1]) == [1, 7, 2, 3, 4, 5, 6, 0]\n assert candidate(nums = [0, 10, 6, 7, 4, 3, 9, 1, 8, 2, 5]) == [0, 5, 9, 1, 4, 7, 2, 10, 8, 6, 3]\n assert candidate(nums = [4, 5, 0, 1, 2, 3]) == [2, 3, 4, 5, 0, 1]\n assert candidate(nums = [7, 9, 6, 3, 5, 8, 4, 0, 2, 1]) == [0, 1, 4, 3, 8, 2, 5, 7, 6, 9]\n assert candidate(nums = [7, 8, 9, 0, 3, 2, 5, 4, 6, 1]) == [4, 6, 1, 7, 0, 9, 2, 3, 5, 8]\n assert candidate(nums = [2, 7, 4, 5, 1, 9, 3, 6, 8, 0]) == [4, 6, 1, 9, 7, 0, 5, 3, 8, 2]\n assert candidate(nums = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [2, 5, 8, 3, 9, 6, 1, 7, 4, 0]) == [8, 6, 4, 3, 0, 1, 5, 7, 9, 2]\n", "comparison": "exact"}, "public_tests": ["[0,2,1,5,3,4]", "[5,0,1,2,3,4]"], "hints": ["Just apply what's said in the statement.", "Notice that you can't apply it on the same array directly since some elements will change after application"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().buildArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:02+00:00", "tests_total": 81, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function buildArray($nums) {", "container": "Solution", "callable": "buildArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1921, "task_id": "eliminate-maximum-number-of-monsters", "difficulty": "Medium", "problem_description": "You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the i^th monster from the city.\n\nThe monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the i^th monster in kilometers per minute.\n\nYou have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge. The weapon is fully charged at the very start.\n\nYou lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.\n\nReturn the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.\n\nExample 1:\n\nInput: dist = [1,3,4], speed = [1,1,1]\nOutput: 3\nExplanation:\nIn the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.\nAfter a minute, the distances of the monsters are [X,X,2]. You eliminate the third monster.\nAll 3 monsters can be eliminated.\n\nExample 2:\n\nInput: dist = [1,1,2,3], speed = [1,1,1,1]\nOutput: 1\nExplanation:\nIn the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,0,1,2], so you lose.\nYou can only eliminate 1 monster.\n\nExample 3:\n\nInput: dist = [3,2,4], speed = [5,3,2]\nOutput: 1\nExplanation:\nIn the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,0,2], so you lose.\nYou can only eliminate 1 monster.\n\nConstraints:\n\n- n == dist.length == speed.length\n- 1 <= n <= 10^5\n- 1 <= dist[i], speed[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(dist = [6, 7, 8],speed = [2, 2, 2]) == 3\n assert candidate(dist = [1, 2, 3],speed = [3, 2, 1]) == 1\n assert candidate(dist = [100, 200, 300],speed = [1, 1, 1]) == 3\n assert candidate(dist = [7, 14, 21],speed = [1, 2, 3]) == 3\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [3, 5, 7, 9],speed = [1, 2, 3, 4]) == 3\n assert candidate(dist = [1, 1, 2, 3],speed = [1, 1, 1, 1]) == 1\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [50, 40, 30, 20, 10]) == 5\n assert candidate(dist = [6, 4, 5],speed = [1, 2, 1]) == 3\n assert candidate(dist = [1, 2, 3, 4, 5],speed = [1, 2, 3, 4, 5]) == 1\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(dist = [1, 3, 4],speed = [1, 1, 1]) == 3\n assert candidate(dist = [10, 20, 30],speed = [1, 2, 3]) == 3\n assert candidate(dist = [5, 10, 15, 20],speed = [5, 4, 3, 2]) == 4\n assert candidate(dist = [3, 2, 4],speed = [5, 3, 2]) == 1\n assert candidate(dist = [1, 2, 3, 4, 5],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [10, 5, 6, 12, 3],speed = [2, 1, 1, 1, 1]) == 5\n assert candidate(dist = [5, 5, 5],speed = [1, 1, 1]) == 3\n assert candidate(dist = [2, 4, 6],speed = [2, 2, 2]) == 3\n assert candidate(dist = [1],speed = [1]) == 1\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [10, 20, 30, 40, 50]) == 5\n assert candidate(dist = [5, 5, 5, 5],speed = [1, 1, 1, 1]) == 4\n assert candidate(dist = [6, 7, 12, 13, 14],speed = [3, 3, 4, 4, 5]) == 3\n assert candidate(dist = [6, 3, 4, 1],speed = [2, 1, 2, 1]) == 3\n assert candidate(dist = [10, 20, 30],speed = [5, 10, 15]) == 2\n assert candidate(dist = [10, 15, 20],speed = [2, 3, 4]) == 3\n assert candidate(dist = [10, 20, 30],speed = [5, 5, 5]) == 3\n assert candidate(dist = [100, 200, 300],speed = [10, 20, 30]) == 3\n assert candidate(dist = [10, 20, 30, 40],speed = [10, 10, 10, 10]) == 4\n assert candidate(dist = [1, 2, 3, 4, 5],speed = [5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [10, 10, 10, 10, 10],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [500, 1000, 1500, 2000, 2500],speed = [50, 100, 150, 200, 250]) == 5\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],speed = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [1000, 900, 800, 700, 600],speed = [100, 200, 300, 400, 500]) == 5\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [9, 8, 7, 6, 5, 4, 3, 2, 1],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(dist = [2, 3, 4, 5, 6],speed = [2, 2, 2, 2, 2]) == 2\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [2, 3, 4, 5, 6]) == 5\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(dist = [10, 25, 40, 55, 70, 85],speed = [5, 5, 5, 5, 5, 5]) == 6\n assert candidate(dist = [10, 15, 20, 25],speed = [5, 4, 3, 2]) == 4\n assert candidate(dist = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [99, 98, 97, 96, 95],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [1000, 1500, 2000, 2500, 3000],speed = [100, 200, 300, 400, 500]) == 5\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [50, 40, 30, 20, 10]) == 5\n assert candidate(dist = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(dist = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [10, 20, 30, 40, 50]) == 5\n assert candidate(dist = [15, 15, 20, 25, 30],speed = [1, 2, 1, 2, 1]) == 5\n assert candidate(dist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],speed = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],speed = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(dist = [5, 15, 25, 35, 45],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(dist = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [5, 5, 5, 5, 5]) == 5\n assert candidate(dist = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(dist = [2, 4, 6, 8, 10],speed = [1, 2, 3, 4, 5]) == 2\n assert candidate(dist = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],speed = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(dist = [5, 10, 15, 20, 25, 30],speed = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [25, 25, 25, 25, 25],speed = [5, 5, 5, 5, 5]) == 5\n assert candidate(dist = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [2, 4, 6, 8, 10],speed = [1, 2, 3, 4, 5]) == 2\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(dist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [5, 15, 25, 35, 45],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(dist = [5, 10, 15, 20, 25, 30],speed = [1, 2, 3, 4, 5, 6]) == 5\n assert candidate(dist = [99, 198, 297, 396, 495, 594, 693, 792, 891, 990],speed = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99]) == 10\n assert candidate(dist = [3, 5, 7, 9, 11],speed = [1, 2, 3, 4, 5]) == 3\n assert candidate(dist = [10000, 20000, 30000, 40000, 50000],speed = [100, 200, 300, 400, 500]) == 5\n assert candidate(dist = [3, 6, 9, 12, 15],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [1, 2, 3, 4, 5],speed = [5, 4, 3, 2, 1]) == 1\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [2, 4, 5, 6, 8]) == 5\n assert candidate(dist = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [1000, 2000, 3000],speed = [10, 20, 30]) == 3\n assert candidate(dist = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(dist = [10, 25, 30, 45, 50, 65, 70, 85, 90, 105],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [2, 3, 4, 5, 6],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 15\n assert candidate(dist = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],speed = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 10\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [10, 20, 30, 40, 50]) == 1\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [2, 2, 2, 2, 1]) == 5\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 1\n assert candidate(dist = [9, 9, 9, 9, 9],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [100, 150, 200, 250, 300],speed = [25, 50, 75, 100, 125]) == 3\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [10, 11, 12, 13, 14],speed = [1, 1, 1, 1, 1]) == 5\n assert candidate(dist = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(dist = [15, 10, 20, 30, 40],speed = [2, 5, 3, 4, 1]) == 5\n assert candidate(dist = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(dist = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(dist = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [50, 100, 150, 200, 250]) == 2\n assert candidate(dist = [3, 6, 9, 12, 15, 18],speed = [1, 2, 3, 4, 5, 6]) == 3\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(dist = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],speed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(dist = [10, 20, 30, 40, 50],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [9, 18, 27, 36, 45],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [15, 25, 35, 45, 55],speed = [5, 5, 5, 5, 5]) == 5\n assert candidate(dist = [100, 200, 300, 400, 500],speed = [50, 50, 50, 50, 50]) == 5\n assert candidate(dist = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],speed = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(dist = [2, 4, 6, 8, 10],speed = [2, 2, 2, 2, 2]) == 5\n assert candidate(dist = [7, 14, 21, 28, 35],speed = [1, 2, 3, 4, 5]) == 5\n assert candidate(dist = [100, 150, 200, 250, 300],speed = [5, 10, 15, 20, 25]) == 5\n assert candidate(dist = [100, 150, 200, 250, 300, 350, 400, 450, 500],speed = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 9\n", "comparison": "exact"}, "public_tests": ["[1,3,4]\n[1,1,1]", "[1,1,2,3]\n[1,1,1,1]", "[3,2,4]\n[5,3,2]"], "hints": ["Find the amount of time it takes each monster to arrive.", "Find the order in which the monsters will arrive."], "metadata": {"canonical_parameter_names": ["dist", "speed"], "leetcode_dataset_entry_point": "Solution().eliminateMaximum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:05+00:00", "tests_total": 127, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function eliminateMaximum($dist, $speed) {", "container": "Solution", "callable": "eliminateMaximum", "parameters": [{"name": "dist", "type": "Integer[]"}, {"name": "speed", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1923, "task_id": "longest-common-subpath", "difficulty": "Hard", "problem_description": "There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities.\n\nThere are m friends numbered from 0 to m - 1 who are traveling through the country. Each one of them will take a path consisting of some cities. Each path is represented by an integer array that contains the visited cities in order. The path may contain a city more than once, but the same city will not be listed consecutively.\n\nGiven an integer n and a 2D integer array paths where paths[i] is an integer array representing the path of the i^th friend, return the length of the longest common subpath that is shared by every friend's path, or 0 if there is no common subpath at all.\n\nA subpath of a path is a contiguous sequence of cities within that path.\n\nExample 1:\n\nInput: n = 5, paths = [[0,1,2,3,4],\n [2,3,4],\n [4,0,1,2,3]]\nOutput: 2\nExplanation: The longest common subpath is [2,3].\n\nExample 2:\n\nInput: n = 3, paths = [[0],[1],[2]]\nOutput: 0\nExplanation: There is no common subpath shared by the three paths.\n\nExample 3:\n\nInput: n = 5, paths = [[0,1,2,3,4],\n [4,3,2,1,0]]\nOutput: 1\nExplanation: The possible longest common subpaths are [0], [1], [2], [3], and [4]. All have a length of 1.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- m == paths.length\n- 2 <= m <= 10^5\n- sum(paths[i].length) <= 10^5\n- 0 <= paths[i][j] < n\n- The same city is not listed multiple times consecutively in paths[i].\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,paths = [[0], [0], [0]]) == 1\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0]]) == 1\n assert candidate(n = 3,paths = [[0], [1], [2]]) == 0\n assert candidate(n = 10,paths = [[0, 1, 2], [1, 2, 3], [2, 3, 4]]) == 1\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 0, 1, 2, 3, 4], [3, 4, 5, 6, 7, 8, 9, 0, 1, 2]]) == 5\n assert candidate(n = 7,paths = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) == 0\n assert candidate(n = 6,paths = [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 0], [2, 3, 4, 5, 0, 1]]) == 4\n assert candidate(n = 10,paths = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]]) == 0\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [2, 3, 4], [4, 0, 1, 2, 3]]) == 2\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3], [6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5]]) == 9\n assert candidate(n = 9,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 0], [2, 3, 4, 5, 6, 7, 8, 0, 1], [3, 4, 5, 6, 7, 8, 0, 1, 2]]) == 6\n assert candidate(n = 100,paths = [[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], [90, 91, 92, 93, 94, 95, 96, 97, 98, 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], [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, 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\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3]]) == 16\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 10\n assert candidate(n = 7,paths = [[0, 1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 0], [2, 3, 4, 5, 6, 0, 1], [3, 4, 5, 6, 0, 1, 2], [4, 5, 6, 0, 1, 2, 3], [5, 6, 0, 1, 2, 3, 4], [6, 0, 1, 2, 3, 4, 5], [0, 6, 5, 4, 3, 2, 1]]) == 1\n assert candidate(n = 8,paths = [[0, 1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1, 0], [2, 1, 0, 7, 6, 5, 4, 3], [3, 2, 1, 0, 7, 6, 5, 4]]) == 1\n assert candidate(n = 100,paths = [[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], [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, 2, 3, 4, 5, 6, 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], [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, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]]) == 50\n assert candidate(n = 8,paths = [[0, 1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7, 0], [2, 3, 4, 5, 6, 7, 0, 1], [3, 4, 5, 6, 7, 0, 1, 2], [4, 5, 6, 7, 0, 1, 2, 3], [5, 6, 7, 0, 1, 2, 3, 4], [6, 7, 0, 1, 2, 3, 4, 5], [7, 0, 1, 2, 3, 4, 5, 6]]) == 1\n assert candidate(n = 25,paths = [[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], [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 10\n assert candidate(n = 100,paths = [[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], [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, 2, 3, 4, 5, 6, 7, 8, 9], [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]) == 70\n assert candidate(n = 7,paths = [[0, 1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 0], [2, 3, 4, 5, 6, 0, 1], [3, 4, 5, 6, 0, 1, 2], [4, 5, 6, 0, 1, 2, 3], [5, 6, 0, 1, 2, 3, 4], [6, 0, 1, 2, 3, 4, 5]]) == 1\n assert candidate(n = 15,paths = [[0, 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, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1]]) == 13\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4], [10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 5\n assert candidate(n = 10,paths = [[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]]) == 10\n assert candidate(n = 50,paths = [[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], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], [49, 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]]) == 25\n assert candidate(n = 25,paths = [[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], [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], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 15\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]) == 10\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4]]) == 5\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4]]) == 10\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0], [2, 3, 4, 0, 1], [3, 4, 0, 1, 2], [4, 0, 1, 2, 3], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 0, 1, 2, 3, 4], [6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [7, 8, 9, 0, 1, 2, 3, 4, 5, 6], [8, 9, 0, 1, 2, 3, 4, 5, 6, 7], [9, 0, 1, 2, 3, 4, 5, 6, 7, 8]]) == 1\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1]]) == 18\n assert candidate(n = 25,paths = [[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], [20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 10\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 3, 4, 5, 6, 7, 8, 9, 0, 1], [3, 4, 5, 6, 7, 8, 9, 0, 1, 2], [4, 5, 6, 7, 8, 9, 0, 1, 2, 3], [5, 6, 7, 8, 9, 0, 1, 2, 3, 4], [6, 7, 8, 9, 0, 1, 2, 3, 4, 5], [7, 8, 9, 0, 1, 2, 3, 4, 5, 6], [8, 9, 0, 1, 2, 3, 4, 5, 6, 7], [9, 0, 1, 2, 3, 4, 5, 6, 7, 8]]) == 1\n assert candidate(n = 25,paths = [[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], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]) == 10\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [1, 2, 3, 0, 4], [2, 3, 0, 1, 4], [3, 0, 1, 2, 4], [0, 1, 2, 3, 4]]) == 1\n assert candidate(n = 50,paths = [[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], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 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]]) == 20\n assert candidate(n = 15,paths = [[0, 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, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4]]) == 10\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [1, 2, 3, 4, 0], [2, 3, 4, 0, 1], [3, 4, 0, 1, 2], [4, 0, 1, 2, 3]]) == 1\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 0, 2, 4, 6, 8], [0, 3, 6, 9, 0, 3, 6, 9, 0, 3]]) == 1\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [2, 3, 4, 5, 6, 7, 8, 9, 0, 1], [8, 9, 0, 1, 2, 3, 4, 5, 6, 7]]) == 1\n assert candidate(n = 30,paths = [[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], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]) == 10\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3]]) == 11\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2]]) == 5\n assert candidate(n = 50,paths = [[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], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]) == 30\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2]]) == 17\n assert candidate(n = 7,paths = [[0, 1, 2, 3, 4, 5, 6], [3, 4, 5, 6, 0, 1, 2], [6, 0, 1, 2, 3, 4, 5], [4, 5, 6, 0, 1, 2, 3], [2, 3, 4, 5, 6, 0, 1]]) == 2\n assert candidate(n = 12,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2]]) == 9\n assert candidate(n = 7,paths = [[0, 1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 0, 1], [4, 5, 6, 0, 1, 2, 3], [6, 0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 0]]) == 2\n assert candidate(n = 12,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1], [4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3], [6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5], [8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7]]) == 4\n assert candidate(n = 20,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8], [15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]) == 9\n assert candidate(n = 10,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], [2, 3, 4, 5, 6, 7, 8, 9, 0, 1], [3, 4, 5, 6, 7, 8, 9, 0, 1, 2]]) == 7\n assert candidate(n = 100,paths = [[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], [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, 2, 3, 4, 5, 6, 7, 8, 9]]) == 90\n assert candidate(n = 15,paths = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [5, 4, 3, 2, 1, 0, 14, 13, 12, 11, 10, 9, 8, 7, 6]]) == 1\n assert candidate(n = 7,paths = [[0, 1, 2, 3, 4, 5, 6], [6, 0, 1, 2, 3, 4, 5], [5, 6, 0, 1, 2, 3, 4], [4, 5, 6, 0, 1, 2, 3]]) == 4\n assert candidate(n = 5,paths = [[0, 1, 2, 3, 4], [1, 2, 3, 4], [2, 3, 4], [3, 4], [4]]) == 1\n", "comparison": "exact"}, "public_tests": ["5\n[[0,1,2,3,4],[2,3,4],[4,0,1,2,3]]", "3\n[[0],[1],[2]]", "5\n[[0,1,2,3,4],[4,3,2,1,0]]"], "hints": ["If there is a common path with length x, there is for sure a common path of length y where y < x.", "We can use binary search over the answer with the range [0, min(path[i].length)].", "Using binary search, we want to verify if we have a common path of length m. We can achieve this using hashing."], "metadata": {"canonical_parameter_names": ["n", "paths"], "leetcode_dataset_entry_point": "Solution().longestCommonSubpath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:10+00:00", "tests_total": 55, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "rolling-hash", "suffix-array", "hash-function", "suffix-automaton", "suffix-tree"]}, "language": "php", "interface": {"raw_signature": "function longestCommonSubpath($n, $paths) {", "container": "Solution", "callable": "longestCommonSubpath", "parameters": [{"name": "n", "type": "Integer"}, {"name": "paths", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1925, "task_id": "count-square-sum-triples", "difficulty": "Easy", "problem_description": "A square triple (a,b,c) is a triple where a, b, and c are integers and a^2 + b^2 = c^2.\n\nGiven an integer n, return the number of square triples such that 1 <= a, b, c <= n.\n\nExample 1:\n\nInput: n = 5\nOutput: 2\nExplanation: The square triples are (3,4,5) and (4,3,5).\n\nExample 2:\n\nInput: n = 10\nOutput: 4\nExplanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).\n\nConstraints:\n\n- 1 <= n <= 250\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 250) == 330\n assert candidate(n = 5) == 2\n assert candidate(n = 15) == 8\n assert candidate(n = 200) == 254\n assert candidate(n = 20) == 12\n assert candidate(n = 100) == 104\n assert candidate(n = 50) == 40\n assert candidate(n = 1) == 0\n assert candidate(n = 10) == 4\n assert candidate(n = 25) == 16\n assert candidate(n = 150) == 178\n assert candidate(n = 80) == 78\n assert candidate(n = 230) == 302\n assert candidate(n = 125) == 142\n assert candidate(n = 75) == 74\n assert candidate(n = 240) == 314\n assert candidate(n = 199) == 250\n assert candidate(n = 120) == 132\n assert candidate(n = 225) == 296\n assert candidate(n = 249) == 324\n assert candidate(n = 190) == 236\n assert candidate(n = 175) == 214\n assert candidate(n = 180) == 218\n", "comparison": "exact"}, "public_tests": ["5", "10"], "hints": ["Iterate over all possible pairs (a,b) and check that the square root of a * a + b * b is an integers less than or equal n", "You can check that the square root of an integer is an integer using binary seach or a builtin function like sqrt"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().countTriples", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:14+00:00", "tests_total": 23, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countTriples($n) {", "container": "Solution", "callable": "countTriples", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1927, "task_id": "sum-game", "difficulty": "Medium", "problem_description": "Alice and Bob take turns playing a game, with Alice starting first.\n\nYou are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if there is still at least one '?' in num:\n\n1. Choose an index i where num[i] == '?'.\n2. Replace num[i] with any digit between '0' and '9'.\n\nThe game ends when there are no more '?' characters in num.\n\nFor Bob to win, the sum of the digits in the first half of num must be equal to the sum of the digits in the second half. For Alice to win, the sums must not be equal.\n\n- For example, if the game ended with num = \"243801\", then Bob wins because 2+4+3 = 8+0+1. If the game ended with num = \"243803\", then Alice wins because 2+4+3 != 8+0+3.\n\nAssuming Alice and Bob play optimally, return true if Alice will win and false if Bob will win.\n\nExample 1:\n\nInput: num = \"5023\"\nOutput: false\nExplanation: There are no moves to be made.\nThe sum of the first half is equal to the sum of the second half: 5 + 0 = 2 + 3.\n\nExample 2:\n\nInput: num = \"25??\"\nOutput: true\nExplanation: Alice can replace one of the '?'s with '9' and it will be impossible for Bob to make the sums equal.\n\nExample 3:\n\nInput: num = \"?3295???\"\nOutput: false\nExplanation: It can be proven that Bob will always win. One possible outcome is:\n- Alice replaces the first '?' with '9'. num = \"93295???\".\n- Bob replaces one of the '?' in the right half with '9'. num = \"932959??\".\n- Alice replaces one of the '?' in the right half with '2'. num = \"9329592?\".\n- Bob replaces the last '?' in the right half with '7'. num = \"93295927\".\nBob wins because 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7.\n\nConstraints:\n\n- 2 <= num.length <= 10^5\n- num.length is even.\n- num consists of only digits and '?'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"1???2???\") == True\n assert candidate(num = \"9?8?7?6?\") == True\n assert candidate(num = \"????2222\") == True\n assert candidate(num = \"98765432\") == True\n assert candidate(num = \"???45678\") == True\n assert candidate(num = \"9999????\") == True\n assert candidate(num = \"12??34??\") == True\n assert candidate(num = \"?3295???\") == False\n assert candidate(num = \"0000????\") == True\n assert candidate(num = \"12345678\") == True\n assert candidate(num = \"12345678??\") == True\n assert candidate(num = \"00112233\") == True\n assert candidate(num = \"????567890\") == True\n assert candidate(num = \"5023\") == False\n assert candidate(num = \"????1234\") == True\n assert candidate(num = \"????????\") == False\n assert candidate(num = \"00?0?0?0\") == True\n assert candidate(num = \"00000000\") == False\n assert candidate(num = \"1234567890\") == True\n assert candidate(num = \"99?9?9?9\") == True\n assert candidate(num = \"25??\") == True\n assert candidate(num = \"1234????\") == True\n assert candidate(num = \"11112222\") == True\n assert candidate(num = \"????5000500050005000\") == True\n assert candidate(num = \"8888888888????????????????\") == True\n assert candidate(num = \"1234567890????\") == True\n assert candidate(num = \"00000000001234567890\") == True\n assert candidate(num = \"1234????5678\") == True\n assert candidate(num = \"1111111111111111????\") == True\n assert candidate(num = \"12345678901234567890????????????????????\") == False\n assert candidate(num = \"98765432109876543210\") == False\n assert candidate(num = \"1010101010??????????????????????\") == True\n assert candidate(num = \"9999999999999999999999999999????????????????????????????????????????????????????????????????????????????????????????????????????????\") == True\n assert candidate(num = \"12345678????????????????12345678\") == False\n assert candidate(num = \"1111111111111111????????????????\") == True\n assert candidate(num = \"2468013579????????????????\") == False\n assert candidate(num = \"99999999998765432100\") == True\n assert candidate(num = \"5555555555555555????\") == True\n assert candidate(num = \"50005000500050005000????\") == True\n assert candidate(num = \"1111111111????????????????\") == True\n assert candidate(num = \"1111????2222\") == True\n assert candidate(num = \"????????5432109876\") == True\n assert candidate(num = \"2222222222????????????????\") == True\n assert candidate(num = \"1234567890123456789012345678901234567890????\") == True\n assert candidate(num = \"1234567890????????\") == True\n assert candidate(num = \"555555555555555555550000000000000000????????\") == True\n assert candidate(num = \"00009999????\") == True\n assert candidate(num = \"2468024680??????????????????????\") == True\n assert candidate(num = \"98765432109876543210????????????\") == True\n assert candidate(num = \"1111222233334444????\") == True\n assert candidate(num = \"243801????????????????243801\") == False\n assert candidate(num = \"12345678901234567890????????????????????????????????????????????????????\") == False\n assert candidate(num = \"222222222222222222222222222222222222222222222222????????????????????????????????????????????\") == True\n assert candidate(num = \"1234567890123456????\") == True\n assert candidate(num = \"12345678901234567890????????????????????????????????????????????????????????????????????????????????????????????????????????\") == False\n assert candidate(num = \"????????????\") == False\n assert candidate(num = \"502350235023????\") == True\n assert candidate(num = \"1234567890????????1234567890????????\") == False\n assert candidate(num = \"11111111????1111\") == True\n assert candidate(num = \"1111111111111111\") == False\n assert candidate(num = \"????????????????\") == False\n assert candidate(num = \"25??1234????????????????\") == True\n assert candidate(num = \"1234123412341234????\") == True\n assert candidate(num = \"0000000000000000000011111111111111111111\") == True\n assert candidate(num = \"5432109876????????\") == True\n assert candidate(num = \"????567890????567890\") == False\n assert candidate(num = \"1111111122222222????\") == True\n assert candidate(num = \"4444444444????????????????\") == True\n assert candidate(num = \"1234567890123456789012345678901234????\") == True\n assert candidate(num = \"999999999999????????????\") == True\n assert candidate(num = \"9876543210??????????????????????\") == False\n assert candidate(num = \"6666666666????????????????\") == True\n assert candidate(num = \"55555555555555555555555555555555\") == False\n assert candidate(num = \"9876543210????????????????\") == False\n assert candidate(num = \"0987654321????\") == True\n assert candidate(num = \"00000000000000001111111111111111????????????????\") == True\n assert candidate(num = \"0123456789????????\") == True\n assert candidate(num = \"0987654321098765\") == True\n assert candidate(num = \"1234567890????????????????\") == False\n assert candidate(num = \"????????1234567890\") == True\n assert candidate(num = \"9999999999999999999999999999????\") == True\n assert candidate(num = \"????0000????0000\") == False\n assert candidate(num = \"0000000000000000????????????????\") == True\n assert candidate(num = \"55555555555555555555555555555555????????????????\") == True\n assert candidate(num = \"0?????????????????????????????????\") == True\n assert candidate(num = \"9876987698769876????\") == True\n assert candidate(num = \"0000000000????????\") == True\n assert candidate(num = \"11111111111111111111????????????????\") == True\n assert candidate(num = \"1234567890????1234\") == True\n assert candidate(num = \"9999999999999999????\") == True\n assert candidate(num = \"1234567890??????????????????????\") == False\n assert candidate(num = \"9999????????\") == True\n assert candidate(num = \"1234567890????????1234567890????\") == False\n assert candidate(num = \"1010101010????????????????\") == True\n assert candidate(num = \"1234567890123456\") == True\n assert candidate(num = \"1234567890????????????????0123456789\") == False\n assert candidate(num = \"5555555555??????????????????????\") == True\n assert candidate(num = \"55555555????\") == True\n assert candidate(num = \"000000000000000000000000????????????????\") == True\n assert candidate(num = \"000099990000????????\") == False\n assert candidate(num = \"????????11111111\") == True\n assert candidate(num = \"1111111111????????????????????1111111111\") == False\n assert candidate(num = \"1234567890123456????????????????\") == True\n assert candidate(num = \"5023????5023????\") == False\n assert candidate(num = \"1234567890????????????????1234567890\") == False\n assert candidate(num = \"13579135791357913579????????????????????\") == True\n assert candidate(num = \"99999999999999991234\") == True\n assert candidate(num = \"????9876543210????\") == True\n assert candidate(num = \"99999999999999999999999999999999\") == False\n assert candidate(num = \"9999999999999999????????????????\") == True\n assert candidate(num = \"99999999999999999999\") == False\n assert candidate(num = \"9????9????\") == False\n assert candidate(num = \"99999999990000000000\") == True\n assert candidate(num = \"1122334455????????????????\") == True\n assert candidate(num = \"1111111122222222\") == True\n assert candidate(num = \"?????????????????????????????????1\") == True\n assert candidate(num = \"5555555544444444????\") == True\n assert candidate(num = \"1234567890123456789012345678901234567890????????????????????????????\") == True\n assert candidate(num = \"????1234567890??\") == True\n assert candidate(num = \"0000000000000000????\") == True\n assert candidate(num = \"00000000000000000000000000000000000000000000????????????????\") == True\n assert candidate(num = \"99999999????\") == True\n assert candidate(num = \"1020304050????????????????\") == True\n assert candidate(num = \"24680246802468024680????????????????????\") == True\n assert candidate(num = \"5000500050005000????\") == True\n assert candidate(num = \"0000000000000000000000000000????????????????????????????????\") == True\n assert candidate(num = \"9012345678????????????????8765432109\") == False\n assert candidate(num = \"????????9999999999\") == True\n assert candidate(num = \"98765432109876543210????????????????????\") == False\n assert candidate(num = \"9876543210????????????\") == False\n assert candidate(num = \"7777777777????????????????\") == True\n assert candidate(num = \"9753186420????????????????\") == False\n assert candidate(num = \"2222111144443333????\") == True\n assert candidate(num = \"5023????????????????????\") == True\n assert candidate(num = \"0000000000????????????????\") == True\n assert candidate(num = \"3333333333????????????????\") == True\n assert candidate(num = \"9876543210????????\") == True\n assert candidate(num = \"0000000000000000000000000000????\") == True\n assert candidate(num = \"12345678901234567890????????????\") == True\n assert candidate(num = \"123456789012345678901234567890\") == True\n assert candidate(num = \"5555555555????????????????\") == True\n assert candidate(num = \"9999????9999\") == False\n assert candidate(num = \"????2345????????????????5432????\") == False\n assert candidate(num = \"11223344556677889900????????????\") == False\n assert candidate(num = \"0000000099999999\") == True\n assert candidate(num = \"55555555555555555555555555555555????????????????????????????????????\") == True\n assert candidate(num = \"22222222222222222222222222222222????????????????????????????????????2222222222\") == True\n assert candidate(num = \"99999999????9999\") == True\n assert candidate(num = \"11111111111111111111\") == False\n assert candidate(num = \"20202020202020202020202020????????\") == True\n assert candidate(num = \"0101010101????????????????\") == True\n assert candidate(num = \"12345678901234567890\") == False\n assert candidate(num = \"9876543210????\") == True\n assert candidate(num = \"5555555555????????\") == True\n assert candidate(num = \"33333333333333333333333333333333333333333333333333????????????????????????????????????????????????????????????????????????????????333333333333\") == True\n assert candidate(num = \"11111111111111112222222222222222\") == True\n assert candidate(num = \"1?????????????????????????????????\") == True\n assert candidate(num = \"1234567890????????????????0987654321\") == False\n assert candidate(num = \"0000000000000000\") == False\n assert candidate(num = \"9999999999????????????????\") == True\n assert candidate(num = \"50505050????\") == True\n", "comparison": "exact"}, "public_tests": ["\"5023\"", "\"25??\"", "\"?3295???\""], "hints": ["Bob can always make the total sum of both sides equal in mod 9.", "Why does the difference between the number of question marks on the left and right side matter?"], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().sumGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:19+00:00", "tests_total": 168, "tests_dropped": 7, "flags": [], "topic_tags": ["math", "string", "greedy", "game-theory"]}, "language": "php", "interface": {"raw_signature": "function sumGame($num) {", "container": "Solution", "callable": "sumGame", "parameters": [{"name": "num", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1928, "task_id": "minimum-cost-to-reach-destination-in-time", "difficulty": "Hard", "problem_description": "There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array edges where edges[i] = [x_i, y_i, time_i] denotes a road between cities x_i and y_i that takes time_i minutes to travel. There may be multiple roads of differing travel times connecting the same two cities, but no road connects a city to itself.\n\nEach time you pass through a city, you must pay a passing fee. This is represented as a 0-indexed integer array passingFees of length n where passingFees[j] is the amount of dollars you must pay when you pass through city j.\n\nIn the beginning, you are at city 0 and want to reach city n - 1 in maxTime minutes or less. The cost of your journey is the summation of passing fees for each city that you passed through at some moment of your journey (including the source and destination cities).\n\nGiven maxTime, edges, and passingFees, return the minimum cost to complete your journey, or -1 if you cannot complete it within maxTime minutes.\n\nExample 1:\n\nInput: maxTime = 30, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: 11\nExplanation: The path to take is 0 -> 1 -> 2 -> 5, which takes 30 minutes and has $11 worth of passing fees.\n\nExample 2:\n\nInput: maxTime = 29, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: 48\nExplanation: The path to take is 0 -> 3 -> 4 -> 5, which takes 26 minutes and has $48 worth of passing fees.\nYou cannot take path 0 -> 1 -> 2 -> 5 since it would take too long.\n\nExample 3:\n\nInput: maxTime = 25, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: -1\nExplanation: There is no way to reach city 5 from city 0 within 25 minutes.\n\nConstraints:\n\n- 1 <= maxTime <= 1000\n- n == passingFees.length\n- 2 <= n <= 1000\n- n - 1 <= edges.length <= 1000\n- 0 <= x_i, y_i <= n - 1\n- 1 <= time_i <= 1000\n- 1 <= passingFees[j] <= 1000\n- The graph may contain multiple edges between two nodes.\n- The graph does not contain self loops.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(maxTime = 50,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1]],passingFees = [1, 2, 3, 4, 5, 6]) == 21\n assert candidate(maxTime = 5,edges = [[0, 1, 5], [0, 2, 5], [1, 3, 5], [2, 3, 5], [3, 4, 5]],passingFees = [10, 10, 10, 10, 10]) == -1\n assert candidate(maxTime = 10,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [0, 3, 15]],passingFees = [10, 1, 1, 10]) == -1\n assert candidate(maxTime = 20,edges = [[0, 1, 10], [1, 0, 10], [0, 2, 5], [2, 0, 5], [1, 3, 10], [3, 1, 10], [2, 3, 10], [3, 2, 10]],passingFees = [1, 2, 3, 4]) == 7\n assert candidate(maxTime = 15,edges = [[0, 1, 10], [1, 2, 10], [0, 2, 1]],passingFees = [3, 1, 2]) == 5\n assert candidate(maxTime = 10,edges = [[0, 1, 5], [1, 2, 5], [0, 2, 10]],passingFees = [3, 2, 1]) == 4\n assert candidate(maxTime = 5,edges = [[0, 1, 5], [1, 2, 5], [0, 2, 10]],passingFees = [1, 2, 3]) == -1\n assert candidate(maxTime = 29,edges = [[0, 1, 10], [1, 2, 10], [2, 5, 10], [0, 3, 1], [3, 4, 10], [4, 5, 15]],passingFees = [5, 1, 2, 20, 20, 3]) == 48\n assert candidate(maxTime = 50,edges = [[0, 1, 1], [0, 2, 1], [1, 2, 1], [1, 3, 1], [2, 3, 1]],passingFees = [1, 1, 1, 1]) == 3\n assert candidate(maxTime = 50,edges = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1]],passingFees = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(maxTime = 5,edges = [[0, 1, 5], [1, 2, 5], [0, 2, 10]],passingFees = [3, 2, 1]) == -1\n assert candidate(maxTime = 30,edges = [[0, 1, 10], [1, 2, 10], [2, 5, 10], [0, 3, 1], [3, 4, 10], [4, 5, 15]],passingFees = [5, 1, 2, 20, 20, 3]) == 11\n assert candidate(maxTime = 25,edges = [[0, 1, 10], [1, 2, 10], [2, 5, 10], [0, 3, 1], [3, 4, 10], [4, 5, 15]],passingFees = [5, 1, 2, 20, 20, 3]) == -1\n assert candidate(maxTime = 5,edges = [[0, 1, 6], [1, 2, 5], [0, 2, 10]],passingFees = [1, 2, 3]) == -1\n assert candidate(maxTime = 10,edges = [[0, 1, 3], [1, 2, 3], [0, 2, 5]],passingFees = [1, 2, 3]) == 4\n assert candidate(maxTime = 50,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [0, 3, 15]],passingFees = [10, 20, 30, 40]) == 50\n assert candidate(maxTime = 20,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [0, 2, 5], [1, 3, 6]],passingFees = [1, 2, 3, 4]) == 7\n assert candidate(maxTime = 10,edges = [[0, 1, 5], [1, 2, 5], [0, 2, 10]],passingFees = [1, 2, 3]) == 4\n assert candidate(maxTime = 1,edges = [[0, 1, 1]],passingFees = [1, 1]) == 2\n assert candidate(maxTime = 45,edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [0, 2, 25], [1, 3, 30], [2, 4, 10], [3, 5, 15], [0, 3, 35], [1, 4, 40], [2, 5, 20], [0, 4, 50], [1, 5, 55]],passingFees = [5, 4, 3, 2, 1, 6]) == 14\n assert candidate(maxTime = 150,edges = [[0, 1, 20], [1, 2, 30], [0, 2, 40], [2, 3, 10], [3, 4, 50], [0, 3, 10], [1, 4, 30], [4, 5, 20], [5, 6, 40], [6, 7, 30], [7, 5, 15], [6, 8, 10], [8, 9, 50], [9, 0, 20], [9, 1, 10], [1, 3, 25]],passingFees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 55\n assert candidate(maxTime = 500,edges = [[0, 1, 5], [0, 2, 10], [1, 2, 15], [1, 3, 20], [2, 3, 25], [2, 4, 30], [3, 4, 35], [3, 5, 40], [4, 5, 45], [4, 6, 50], [5, 6, 55], [5, 7, 60], [6, 7, 65], [6, 8, 70], [7, 8, 75], [7, 9, 80], [8, 9, 85], [0, 3, 30], [0, 4, 40], [0, 5, 50], [1, 4, 45], [1, 5, 55], [1, 6, 65], [2, 5, 50], [2, 6, 60], [2, 7, 70], [3, 6, 65], [3, 7, 75], [3, 8, 80], [4, 7, 70], [4, 8, 80], [4, 9, 85], [5, 8, 80], [5, 9, 85], [6, 9, 85]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 160\n assert candidate(maxTime = 50,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], [0, 10, 10], [1, 9, 15], [2, 8, 20], [3, 7, 25], [4, 6, 30]],passingFees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 60\n assert candidate(maxTime = 100,edges = [[0, 1, 20], [1, 2, 30], [2, 3, 10], [3, 4, 50], [0, 2, 40], [1, 3, 10], [2, 4, 20]],passingFees = [10, 5, 15, 20, 25]) == 50\n assert candidate(maxTime = 300,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, 0, 10], [0, 9, 9], [1, 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]],passingFees = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(maxTime = 15,edges = [[0, 1, 4], [1, 2, 3], [0, 2, 6], [2, 3, 5], [3, 4, 7], [0, 3, 8], [1, 3, 2]],passingFees = [2, 3, 4, 1, 5]) == 8\n assert candidate(maxTime = 100,edges = [[0, 1, 50], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 10], [0, 5, 90], [1, 3, 25], [2, 4, 15]],passingFees = [10, 20, 30, 40, 50, 60]) == 70\n assert candidate(maxTime = 25,edges = [[0, 1, 2], [1, 2, 2], [2, 3, 2], [3, 4, 2], [4, 5, 2], [0, 5, 10], [1, 3, 5], [2, 4, 5], [0, 3, 7], [0, 4, 8], [1, 4, 4], [2, 5, 3]],passingFees = [1, 2, 3, 4, 5, 6]) == 7\n assert candidate(maxTime = 600,edges = [[0, 1, 15], [0, 5, 15], [1, 2, 25], [1, 6, 25], [2, 3, 35], [2, 7, 35], [3, 4, 45], [3, 8, 45], [4, 9, 55], [5, 6, 5], [6, 7, 5], [7, 8, 5], [8, 9, 5], [0, 6, 25], [1, 7, 35], [2, 8, 45], [3, 9, 55], [0, 7, 35], [1, 8, 45], [2, 9, 55], [0, 8, 45], [1, 9, 55], [0, 9, 55], [5, 10, 5], [10, 6, 5], [6, 10, 5], [7, 10, 5], [10, 8, 5], [8, 10, 5], [9, 10, 5]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 180\n assert candidate(maxTime = 60,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [0, 3, 15], [0, 2, 10], [1, 3, 10], [3, 4, 10], [2, 4, 10], [0, 4, 20]],passingFees = [3, 2, 1, 2, 3]) == 6\n assert candidate(maxTime = 10,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [0, 3, 5], [0, 2, 1], [1, 3, 1]],passingFees = [1, 2, 3, 4]) == 5\n assert candidate(maxTime = 5,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5]],passingFees = [1, 1, 1, 1, 1]) == -1\n assert candidate(maxTime = 220,edges = [[0, 1, 50], [1, 2, 40], [2, 3, 30], [3, 4, 20], [4, 0, 10], [0, 2, 60], [1, 3, 50], [2, 4, 40], [0, 4, 50], [3, 2, 40]],passingFees = [1, 1, 1, 1, 1]) == 2\n assert candidate(maxTime = 300,edges = [[0, 1, 50], [1, 2, 50], [2, 3, 50], [3, 4, 50], [0, 2, 60], [1, 3, 60], [2, 4, 60], [0, 3, 70], [1, 4, 70], [0, 4, 80]],passingFees = [10, 20, 30, 40, 50]) == 60\n assert candidate(maxTime = 100,edges = [[0, 1, 10], [0, 2, 30], [1, 3, 20], [2, 3, 10], [3, 4, 40], [1, 2, 5]],passingFees = [10, 15, 20, 25, 30]) == 80\n assert candidate(maxTime = 100,edges = [[0, 1, 20], [1, 2, 20], [2, 3, 20], [3, 4, 20], [4, 5, 20], [0, 3, 50], [3, 5, 50]],passingFees = [5, 10, 15, 20, 25, 30]) == 55\n assert candidate(maxTime = 200,edges = [[0, 1, 50], [1, 2, 40], [2, 3, 30], [3, 4, 20], [4, 0, 10], [0, 2, 60], [1, 3, 50], [2, 4, 40]],passingFees = [100, 200, 150, 50, 300]) == 400\n assert candidate(maxTime = 250,edges = [[0, 1, 5], [1, 2, 15], [2, 3, 25], [3, 4, 35], [4, 5, 45], [0, 5, 55], [1, 3, 25], [2, 4, 35], [0, 4, 45], [1, 4, 15]],passingFees = [5, 5, 5, 5, 5, 5]) == 10\n assert candidate(maxTime = 600,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [0, 4, 40], [4, 5, 50], [1, 5, 60], [2, 6, 70], [3, 6, 80], [4, 7, 90], [5, 8, 100], [6, 8, 110], [0, 7, 120], [0, 3, 130], [1, 6, 140], [2, 7, 150], [3, 8, 160], [4, 6, 170], [5, 7, 180], [6, 7, 190]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 140\n assert candidate(maxTime = 150,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]],passingFees = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(maxTime = 100,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], [9, 0, 10], [0, 5, 5], [1, 6, 5], [2, 7, 5], [3, 8, 5], [4, 9, 5]],passingFees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 55\n assert candidate(maxTime = 100,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [2, 3, 25], [1, 4, 40], [3, 4, 15], [4, 5, 5], [5, 6, 30], [6, 1, 25], [2, 6, 10]],passingFees = [10, 15, 20, 25, 30, 35, 40]) == 65\n assert candidate(maxTime = 30,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]],passingFees = [5, 1, 2, 20, 20, 3, 5, 1, 2, 3]) == -1\n assert candidate(maxTime = 120,edges = [[0, 1, 20], [0, 2, 30], [0, 3, 10], [1, 2, 15], [1, 3, 20], [1, 4, 10], [2, 3, 25], [2, 4, 5], [3, 4, 15], [2, 5, 10], [3, 5, 20], [4, 5, 5], [0, 5, 20]],passingFees = [15, 25, 35, 45, 55, 65]) == 80\n assert candidate(maxTime = 200,edges = [[0, 1, 30], [0, 2, 20], [1, 2, 10], [1, 3, 40], [2, 4, 20], [3, 4, 10], [3, 5, 50], [4, 5, 30], [2, 5, 25], [5, 6, 10], [6, 7, 20], [6, 8, 15], [7, 8, 5], [8, 9, 10], [9, 0, 10]],passingFees = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(maxTime = 20,edges = [[0, 1, 5], [1, 2, 10], [0, 3, 15], [3, 4, 20], [2, 4, 25], [4, 5, 30]],passingFees = [5, 10, 15, 20, 25, 30]) == -1\n assert candidate(maxTime = 50,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 15], [3, 4, 10], [4, 5, 10], [0, 3, 25], [1, 4, 20]],passingFees = [10, 20, 30, 40, 50, 60]) == 140\n assert candidate(maxTime = 60,edges = [[0, 1, 10], [0, 2, 15], [0, 3, 20], [1, 2, 5], [1, 3, 10], [2, 3, 25], [1, 4, 10], [2, 4, 5], [3, 4, 15], [2, 5, 10], [3, 5, 20], [4, 5, 5]],passingFees = [10, 20, 30, 40, 50, 60]) == 100\n assert candidate(maxTime = 50,edges = [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 0, 5], [0, 2, 10], [1, 3, 10], [2, 4, 10]],passingFees = [1, 2, 3, 4, 5]) == 6\n assert candidate(maxTime = 80,edges = [[0, 1, 10], [1, 2, 20], [0, 2, 30], [2, 3, 40], [0, 3, 50], [3, 4, 60], [0, 4, 70]],passingFees = [5, 5, 5, 5, 5]) == 10\n assert candidate(maxTime = 50,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 2, 4], [1, 3, 3], [2, 4, 2], [3, 5, 1]],passingFees = [1, 2, 3, 4, 5, 6]) == 13\n assert candidate(maxTime = 120,edges = [[0, 1, 15], [1, 2, 25], [2, 3, 35], [3, 4, 45], [0, 3, 65], [1, 4, 75], [2, 4, 85], [0, 4, 95], [3, 1, 105], [4, 2, 115]],passingFees = [50, 20, 30, 40, 60]) == 110\n assert candidate(maxTime = 20,edges = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [0, 5, 10]],passingFees = [5, 10, 15, 20, 25, 30]) == 35\n assert candidate(maxTime = 500,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [0, 4, 40], [4, 5, 50], [1, 5, 60], [2, 6, 70], [3, 6, 80], [4, 7, 90], [5, 8, 100], [6, 8, 110], [0, 7, 120]],passingFees = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 18\n assert candidate(maxTime = 200,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [0, 3, 30], [1, 3, 30], [2, 4, 30], [3, 4, 30], [0, 4, 50]],passingFees = [1, 2, 3, 4, 5]) == 6\n assert candidate(maxTime = 550,edges = [[0, 1, 20], [0, 5, 20], [1, 2, 30], [1, 6, 30], [2, 3, 40], [2, 7, 40], [3, 4, 50], [3, 8, 50], [4, 9, 60], [5, 6, 10], [6, 7, 10], [7, 8, 10], [8, 9, 10], [0, 6, 40], [1, 7, 50], [2, 8, 60], [3, 9, 70], [0, 7, 50], [1, 8, 60], [2, 9, 70], [0, 8, 60], [1, 9, 70], [0, 9, 70]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 110\n assert candidate(maxTime = 400,edges = [[0, 1, 30], [1, 2, 30], [2, 3, 30], [3, 4, 30], [0, 2, 50], [1, 3, 50], [2, 4, 50], [0, 3, 70], [1, 4, 70], [0, 4, 90], [0, 5, 40], [5, 4, 10], [4, 6, 60], [6, 5, 10], [5, 3, 20]],passingFees = [5, 15, 25, 35, 45, 55, 65]) == 115\n assert candidate(maxTime = 350,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [2, 3, 20], [3, 4, 40], [0, 3, 30], [1, 2, 20], [0, 4, 50], [1, 4, 30], [2, 4, 40]],passingFees = [10, 20, 30, 40, 50]) == 60\n assert candidate(maxTime = 350,edges = [[0, 1, 50], [1, 2, 100], [2, 3, 150], [3, 4, 200], [4, 5, 250], [5, 6, 300], [6, 7, 350], [7, 8, 400], [8, 9, 450], [0, 9, 500]],passingFees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == -1\n assert candidate(maxTime = 30,edges = [[0, 1, 5], [0, 2, 10], [1, 2, 3], [1, 3, 15], [2, 3, 20], [3, 4, 25]],passingFees = [1, 2, 3, 4, 5]) == -1\n assert candidate(maxTime = 180,edges = [[0, 1, 20], [0, 2, 30], [1, 3, 40], [2, 3, 20], [3, 4, 50], [0, 3, 30], [1, 2, 30], [0, 4, 60], [1, 4, 40]],passingFees = [10, 10, 10, 10, 10]) == 20\n assert candidate(maxTime = 150,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, 0, 5], [0, 3, 10], [1, 4, 10], [2, 5, 10], [3, 6, 10], [4, 7, 10], [5, 8, 10], [6, 9, 10], [7, 0, 10], [8, 1, 10], [9, 2, 10]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 110\n assert candidate(maxTime = 100,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [0, 5, 50], [0, 2, 40], [1, 3, 30], [2, 4, 20], [3, 5, 10], [0, 4, 60], [1, 5, 50]],passingFees = [5, 1, 2, 3, 4, 5]) == 10\n assert candidate(maxTime = 100,edges = [[0, 1, 10], [0, 2, 15], [1, 2, 10], [1, 3, 20], [2, 4, 15], [3, 4, 20], [4, 5, 30], [3, 5, 40]],passingFees = [5, 1, 2, 3, 4, 5]) == 14\n assert candidate(maxTime = 35,edges = [[0, 1, 5], [1, 2, 3], [0, 2, 9], [1, 3, 7], [2, 4, 4], [0, 3, 6], [1, 4, 8], [3, 4, 2], [0, 4, 12]],passingFees = [1, 2, 3, 4, 5]) == 6\n assert candidate(maxTime = 25,edges = [[0, 1, 10], [1, 2, 15], [0, 2, 20], [2, 3, 5], [3, 4, 10], [4, 5, 15], [5, 6, 20], [6, 7, 25], [7, 8, 30], [8, 9, 10], [0, 9, 35]],passingFees = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(maxTime = 300,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [0, 3, 60], [1, 4, 70], [2, 5, 80], [0, 2, 90], [3, 5, 100]],passingFees = [10, 20, 30, 40, 50, 60]) == 100\n assert candidate(maxTime = 30,edges = [[0, 1, 5], [1, 2, 7], [2, 3, 6], [0, 3, 10], [1, 3, 2], [2, 4, 5], [3, 4, 3], [0, 4, 8]],passingFees = [10, 20, 15, 25, 30]) == 40\n assert candidate(maxTime = 400,edges = [[0, 1, 100], [1, 2, 100], [2, 3, 100], [3, 4, 100], [4, 5, 100], [0, 5, 100], [0, 2, 100], [1, 3, 100], [2, 4, 100], [3, 5, 100]],passingFees = [5, 5, 5, 5, 5, 5]) == 10\n assert candidate(maxTime = 200,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], [9, 0, 10], [0, 2, 20], [1, 3, 20], [2, 4, 20], [3, 5, 20], [4, 6, 20], [5, 7, 20], [6, 8, 20], [7, 9, 20], [8, 1, 20], [9, 2, 20], [0, 3, 30], [1, 4, 30], [2, 5, 30], [3, 6, 30], [4, 7, 30], [5, 8, 30], [6, 9, 30], [7, 0, 30], [8, 1, 30], [9, 2, 30], [0, 4, 40], [1, 5, 40], [2, 6, 40], [3, 7, 40], [4, 8, 40], [5, 9, 40], [6, 0, 40], [7, 1, 40], [8, 2, 40], [9, 3, 40]],passingFees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 55\n assert candidate(maxTime = 100,edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [0, 2, 5], [1, 3, 5], [0, 3, 2], [2, 4, 20], [3, 4, 10]],passingFees = [10, 5, 3, 20, 1]) == 14\n assert candidate(maxTime = 30,edges = [[0, 1, 10], [1, 2, 10], [2, 5, 10], [0, 3, 1], [3, 4, 10], [4, 5, 15], [1, 3, 1], [2, 4, 5]],passingFees = [5, 1, 2, 20, 20, 3]) == 11\n assert candidate(maxTime = 50,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], [0, 9, 40]],passingFees = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 19\n assert candidate(maxTime = 200,edges = [[0, 1, 15], [0, 2, 20], [1, 3, 25], [2, 3, 15], [3, 4, 30], [0, 3, 15], [1, 2, 10]],passingFees = [10, 20, 30, 40, 50]) == 100\n assert candidate(maxTime = 180,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [0, 4, 50], [0, 2, 60], [1, 3, 70], [2, 4, 80], [3, 1, 90], [4, 0, 100]],passingFees = [50, 40, 30, 20, 10]) == 60\n assert candidate(maxTime = 300,edges = [[0, 1, 10], [1, 2, 20], [0, 3, 30], [3, 4, 40], [4, 5, 50], [0, 2, 60], [2, 3, 70], [1, 4, 80], [2, 5, 90]],passingFees = [5, 10, 15, 20, 25, 30]) == 50\n assert candidate(maxTime = 150,edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [0, 5, 50], [1, 3, 20], [2, 4, 25]],passingFees = [1, 1, 1, 1, 1, 1]) == 2\n assert candidate(maxTime = 220,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 20], [2, 3, 15], [3, 4, 25], [0, 3, 25], [1, 2, 15], [0, 4, 40], [1, 4, 25], [2, 4, 35]],passingFees = [5, 15, 25, 35, 45]) == 50\n assert candidate(maxTime = 15,edges = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 4], [2, 3, 5], [0, 3, 1]],passingFees = [10, 20, 30, 40]) == 50\n assert candidate(maxTime = 40,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 15], [3, 4, 5], [4, 5, 5], [5, 6, 5], [0, 2, 25], [1, 3, 15], [2, 4, 25], [3, 5, 15], [0, 4, 40], [1, 5, 25]],passingFees = [3, 2, 1, 4, 2, 5, 3]) == 13\n assert candidate(maxTime = 200,edges = [[0, 1, 100], [1, 2, 100], [2, 3, 100], [3, 4, 100], [4, 5, 100], [0, 3, 1], [3, 4, 1], [4, 5, 1], [0, 2, 1], [2, 4, 1]],passingFees = [5, 1, 2, 20, 20, 3]) == 30\n assert candidate(maxTime = 40,edges = [[0, 1, 3], [0, 2, 4], [1, 2, 2], [1, 3, 5], [2, 3, 6], [2, 4, 1], [3, 4, 7], [0, 4, 8], [1, 4, 3]],passingFees = [1, 2, 3, 4, 5]) == 6\n assert candidate(maxTime = 60,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]],passingFees = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(maxTime = 150,edges = [[0, 1, 10], [1, 2, 20], [0, 2, 30], [2, 3, 10], [3, 0, 20], [1, 3, 10], [0, 3, 50], [1, 0, 20], [2, 1, 30], [3, 2, 40]],passingFees = [5, 15, 25, 35]) == 40\n assert candidate(maxTime = 60,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], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10], [0, 14, 60]],passingFees = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 18\n assert candidate(maxTime = 250,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], [0, 9, 100]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 110\n assert candidate(maxTime = 500,edges = [[0, 1, 25], [1, 2, 25], [2, 3, 25], [3, 4, 25], [4, 5, 25], [5, 6, 25], [6, 7, 25], [7, 8, 25], [8, 9, 25], [9, 10, 25], [0, 9, 200], [9, 1, 200], [1, 10, 200], [10, 0, 200], [0, 10, 100], [1, 9, 100], [9, 2, 100], [2, 0, 100], [0, 8, 150], [8, 3, 150], [3, 1, 150], [1, 6, 150], [6, 4, 150], [4, 2, 150], [2, 7, 150], [7, 5, 150], [5, 8, 150]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 120\n assert candidate(maxTime = 400,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [2, 4, 40], [3, 5, 50], [4, 6, 60], [1, 2, 70], [3, 4, 80], [2, 5, 90], [4, 5, 100]],passingFees = [5, 10, 15, 20, 25, 30, 35]) == 80\n assert candidate(maxTime = 100,edges = [[0, 1, 20], [1, 2, 20], [2, 3, 20], [3, 4, 20], [4, 5, 20], [5, 6, 20], [6, 7, 20], [7, 8, 20], [8, 9, 20], [9, 10, 20], [10, 11, 20], [11, 12, 20], [12, 13, 20], [13, 14, 20], [14, 15, 20], [15, 16, 20], [16, 17, 20], [17, 18, 20], [18, 19, 20], [0, 19, 90]],passingFees = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 21\n assert candidate(maxTime = 80,edges = [[0, 1, 20], [0, 2, 30], [1, 3, 10], [2, 3, 10], [3, 4, 20], [0, 3, 10]],passingFees = [5, 5, 5, 5, 5]) == 15\n assert candidate(maxTime = 70,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, 0, 5]],passingFees = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 20\n assert candidate(maxTime = 60,edges = [[0, 1, 20], [1, 2, 20], [2, 3, 20], [3, 4, 20], [0, 2, 10], [1, 3, 10], [2, 4, 10], [0, 3, 30], [1, 4, 30]],passingFees = [5, 15, 25, 35, 45]) == 65\n assert candidate(maxTime = 120,edges = [[0, 1, 10], [0, 2, 20], [1, 2, 30], [1, 3, 20], [2, 3, 10], [3, 4, 10], [0, 3, 20], [1, 2, 30]],passingFees = [5, 5, 5, 5, 5]) == 15\n assert candidate(maxTime = 800,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [0, 4, 40], [4, 5, 50], [1, 5, 60], [2, 6, 70], [3, 6, 80], [4, 7, 90], [5, 8, 100], [6, 8, 110], [0, 7, 120], [0, 3, 130], [1, 6, 140], [2, 7, 150], [3, 8, 160], [4, 6, 170], [5, 7, 180], [6, 7, 190], [1, 3, 200], [2, 4, 210], [3, 5, 220], [4, 8, 230], [5, 6, 240], [0, 8, 250], [1, 7, 260], [2, 8, 270], [3, 7, 280], [4, 7, 290], [0, 6, 300], [1, 8, 310], [2, 5, 320], [3, 4, 330]],passingFees = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 100\n assert candidate(maxTime = 20,edges = [[0, 1, 5], [1, 2, 3], [2, 3, 7], [0, 3, 12], [3, 4, 10], [2, 4, 2], [0, 4, 8]],passingFees = [4, 1, 2, 3, 5]) == 9\n assert candidate(maxTime = 200,edges = [[0, 1, 50], [1, 2, 50], [2, 3, 50], [3, 4, 50], [4, 5, 50], [0, 3, 60], [2, 4, 70]],passingFees = [10, 20, 30, 40, 50, 60]) == 160\n assert candidate(maxTime = 300,edges = [[0, 1, 50], [0, 2, 100], [1, 3, 200], [2, 3, 150], [3, 4, 250], [0, 3, 200], [1, 2, 100], [0, 4, 300], [1, 4, 150]],passingFees = [10, 20, 30, 40, 50]) == 60\n", "comparison": "exact"}, "public_tests": ["30\n[[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]]\n[5,1,2,20,20,3]", "29\n[[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]]\n[5,1,2,20,20,3]", "25\n[[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]]\n[5,1,2,20,20,3]"], "hints": ["Consider a new graph where each node is one of the old nodes at a specific time. For example, node 0 at time 5.", "You need to find the shortest path in the new graph."], "metadata": {"canonical_parameter_names": ["maxTime", "edges", "passingFees"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:21+00:00", "tests_total": 98, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "graph", "dijkstra"]}, "language": "php", "interface": {"raw_signature": "function minCost($maxTime, $edges, $passingFees) {", "container": "Solution", "callable": "minCost", "parameters": [{"name": "maxTime", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "passingFees", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1929, "task_id": "concatenation-of-array", "difficulty": "Easy", "problem_description": "Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).\n\nSpecifically, ans is the concatenation of two nums arrays.\n\nReturn the array ans.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: [1,2,1,1,2,1]\nExplanation: The array ans is formed as follows:\n- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]\n- ans = [1,2,1,1,2,1]\n\nExample 2:\n\nInput: nums = [1,3,2,1]\nOutput: [1,3,2,1,1,3,2,1]\nExplanation: The array ans is formed as follows:\n- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]\n- ans = [1,3,2,1,1,3,2,1]\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 1000\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\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]\n assert candidate(nums = [5, 6, 7]) == [5, 6, 7, 5, 6, 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, 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]\n assert candidate(nums = [1, 2, 1]) == [1, 2, 1, 1, 2, 1]\n assert candidate(nums = [1000, 999, 998, 997, 996]) == [1000, 999, 998, 997, 996, 1000, 999, 998, 997, 996]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [999, 1000]) == [999, 1000, 999, 1000]\n assert candidate(nums = [1, 3, 2, 1]) == [1, 3, 2, 1, 1, 3, 2, 1]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [10, 20, 30, 40, 50, 10, 20, 30, 40, 50]\n assert candidate(nums = [999, 1000, 999, 1000]) == [999, 1000, 999, 1000, 999, 1000, 999, 1000]\n assert candidate(nums = [5, 6, 7, 8, 9]) == [5, 6, 7, 8, 9, 5, 6, 7, 8, 9]\n assert candidate(nums = [5]) == [5, 5]\n assert candidate(nums = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10]) == [10, 10]\n assert candidate(nums = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 992, 8, 991, 9, 990, 10]) == [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 992, 8, 991, 9, 990, 10, 999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 992, 8, 991, 9, 990, 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]) == [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980]) == [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]\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, 1, 2, 3, 4, 5, 6, 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, 2, 3, 2, 1, 2, 3, 2, 1]) == [1, 2, 3, 2, 1, 2, 3, 2, 1, 1, 2, 3, 2, 1, 2, 3, 2, 1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510]) == [500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510]\n assert candidate(nums = [1000, 1, 999, 2, 998, 3, 997, 4, 996, 5]) == [1000, 1, 999, 2, 998, 3, 997, 4, 996, 5, 1000, 1, 999, 2, 998, 3, 997, 4, 996, 5]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]\n assert candidate(nums = [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]\n assert candidate(nums = [500, 250, 125, 62, 31, 15, 7, 3, 1]) == [500, 250, 125, 62, 31, 15, 7, 3, 1, 500, 250, 125, 62, 31, 15, 7, 3, 1]\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630]) == [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630]\n assert candidate(nums = [1000, 1, 200, 2, 300, 3, 400, 4]) == [1000, 1, 200, 2, 300, 3, 400, 4, 1000, 1, 200, 2, 300, 3, 400, 4]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145]\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]\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, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\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]\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209]) == [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209]\n assert candidate(nums = [999, 1000, 998, 999, 1000, 998, 999]) == [999, 1000, 998, 999, 1000, 998, 999, 999, 1000, 998, 999, 1000, 998, 999]\n assert candidate(nums = [500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1]) == [500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1, 500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1]\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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666]) == [333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666, 333, 666]\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]) == [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, 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(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]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]\n assert candidate(nums = [999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == [999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 998, 997, 996, 995, 994, 993, 992, 991, 990, 999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 998, 997, 996, 995, 994, 993, 992, 991, 990]\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981]) == [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981]\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, 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, 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]\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, 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, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 1]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 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]) == [1, 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 = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) == [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991]) == [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991, 1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991]\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, 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, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]\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, 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]\n assert candidate(nums = [999, 1000, 999, 1000, 999, 1000, 999, 1000]) == [999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000]\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]) == [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, 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]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000]) == [1000, 1, 1000, 1, 1000, 1, 1000, 1000, 1, 1000, 1, 1000, 1, 1000]\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505]) == [123, 456, 789, 101, 202, 303, 404, 505, 123, 456, 789, 101, 202, 303, 404, 505]\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990]\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]\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, 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 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990]\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]\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]) == [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 1000, 999, 998, 997, 996, 995, 994, 993, 992, 991]\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840]) == [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840, 42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840]\n", "comparison": "exact"}, "public_tests": ["[1,2,1]", "[1,3,2,1]"], "hints": ["Build an array of size 2 * n and assign nums[i] to ans[i] and ans[i + n]"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().getConcatenation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:23+00:00", "tests_total": 71, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function getConcatenation($nums) {", "container": "Solution", "callable": "getConcatenation", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1930, "task_id": "unique-length-3-palindromic-subsequences", "difficulty": "Medium", "problem_description": "Given a string s, return the number of unique palindromes of length three that are a subsequence of s.\n\nNote that even if there are multiple ways to obtain the same subsequence, it is still only counted once.\n\nA palindrome is a string that reads the same forwards and backwards.\n\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\n- For example, \"ace\" is a subsequence of \"abcde\".\n\nExample 1:\n\nInput: s = \"aabca\"\nOutput: 3\nExplanation: The 3 palindromic subsequences of length 3 are:\n- \"aba\" (subsequence of \"aabca\")\n- \"aaa\" (subsequence of \"aabca\")\n- \"aca\" (subsequence of \"aabca\")\n\nExample 2:\n\nInput: s = \"adc\"\nOutput: 0\nExplanation: There are no palindromic subsequences of length 3 in \"adc\".\n\nExample 3:\n\nInput: s = \"bbcbaba\"\nOutput: 4\nExplanation: The 4 palindromic subsequences of length 3 are:\n- \"bbb\" (subsequence of \"bbcbaba\")\n- \"bcb\" (subsequence of \"bbcbaba\")\n- \"bab\" (subsequence of \"bbcbaba\")\n- \"aba\" (subsequence of \"bbcbaba\")\n\nConstraints:\n\n- 3 <= s.length <= 10^5\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == 3\n assert candidate(s = \"madam\") == 3\n assert candidate(s = \"abcdedcba\") == 10\n assert candidate(s = \"aaaaa\") == 1\n assert candidate(s = \"adc\") == 0\n assert candidate(s = \"abcabcabc\") == 9\n assert candidate(s = \"abracadabra\") == 13\n assert candidate(s = \"aaa\") == 1\n assert candidate(s = \"racecar\") == 6\n assert candidate(s = \"abba\") == 1\n assert candidate(s = \"noon\") == 1\n assert candidate(s = \"abccba\") == 3\n assert candidate(s = \"aaaa\") == 1\n assert candidate(s = \"aabbcc\") == 0\n assert candidate(s = \"mississippi\") == 5\n assert candidate(s = \"aabca\") == 3\n assert candidate(s = \"bbcbaba\") == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(s = \"xyzzyx\") == 3\n assert candidate(s = \"level\") == 3\n assert candidate(s = \"abcdefg\") == 0\n assert candidate(s = \"aabacbaabacba\") == 8\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"noonmoonnoonmoonnoonmoonnoonmoonnoonmoonnoonmoonnoon\") == 9\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzyyxwwvvuuttssrrqqppoonnmmllkkjjiihhggeeffddccbbaa\") == 352\n assert candidate(s = \"zzzzzzzyyyyxxxwwvvuttsrrqqppoonnmmllkkjjiihhggffeeddccba\") == 3\n assert candidate(s = \"zzzazzaaz\") == 4\n assert candidate(s = \"abacabadabacaba\") == 11\n assert candidate(s = \"ababababababababababababababababababababab\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 9\n assert candidate(s = \"ababcab\") == 6\n assert candidate(s = \"abacabadabacabadabacabadabacabad\") == 16\n assert candidate(s = \"racecarcarcarecarracecarcarcarecarracecarcarcarecarracecar\") == 16\n assert candidate(s = \"abacdfgdcaba\") == 16\n assert candidate(s = \"aabbbaaabbbaaa\") == 4\n assert candidate(s = \"aaabaaaabaaaaabaaaabaaaaaabaaaa\") == 4\n assert candidate(s = \"aaaabaaaabaaaab\") == 4\n assert candidate(s = \"abcbabcbabcbabcbabcbabcbabcba\") == 9\n assert candidate(s = \"bababababababababababababababababababababa\") == 4\n assert candidate(s = \"abcbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac\") == 9\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 325\n assert candidate(s = \"xyzyxyzyxyzyx\") == 9\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 650\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaedcba\") == 20\n assert candidate(s = \"abbaabbbaabbaabbbaabbaabbbaabbaabbbaabbaabbba\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 9\n assert candidate(s = \"abcdefghihgfedcbaabcdefghihgfedcba\") == 80\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == 26\n assert candidate(s = \"aaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaab\") == 4\n assert candidate(s = \"abcbacbacbacbacbacbacbacbacbacbacbacbacb\") == 9\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"babababababababababababababababababababababababababababababa\") == 4\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba\") == 4\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzzzz\") == 26\n assert candidate(s = \"mamamadadadmmadammaddada\") == 9\n assert candidate(s = \"aabbccddeeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"ababababababababababababababababababababababababababab\") == 4\n assert candidate(s = \"aaaaaaaaaaaabbbbbbbbbbbbccccccccccdddddddddd\") == 4\n assert candidate(s = \"racecarcarcarecarracecarcarcarecarracecar\") == 16\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 9\n assert candidate(s = \"abacbacbacbacba\") == 9\n assert candidate(s = \"ababababababababababababababababababababababababababababababab\") == 4\n assert candidate(s = \"mississippississippiississippiississippiississippiississippi\") == 9\n assert candidate(s = \"abcabcabcabcabc\") == 9\n assert candidate(s = \"noonmoonnoonmoon\") == 8\n assert candidate(s = \"noonmoonnoonmoonnoonmoonnoonmoonnoonmoonnoonmoonnoonnoonmoon\") == 9\n assert candidate(s = \"aaaaabbbbbccccc\") == 3\n assert candidate(s = \"mississippississippiississippiississippiississippi\") == 9\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabad\") == 16\n assert candidate(s = \"zzzzzyyyxxwwvvuttsrrqqppoonnmmllkkjjiihhggffeeddccba\") == 2\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 9\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba\") == 4\n", "comparison": "exact"}, "public_tests": ["\"aabca\"", "\"adc\"", "\"bbcbaba\""], "hints": ["What is the maximum number of length-3 palindromic strings?", "How can we keep track of the characters that appeared to the left of a given position?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countPalindromicSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:25+00:00", "tests_total": 75, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "bit-manipulation", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function countPalindromicSubsequence($s) {", "container": "Solution", "callable": "countPalindromicSubsequence", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1931, "task_id": "painting-a-grid-with-three-different-colors", "difficulty": "Hard", "problem_description": "You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted.\n\nReturn the number of ways to color the grid with no two adjacent cells having the same color. Since the answer can be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: m = 1, n = 1\nOutput: 3\nExplanation: The three possible colorings are shown in the image above.\n\nExample 2:\n\nInput: m = 1, n = 2\nOutput: 6\nExplanation: The six possible colorings are shown in the image above.\n\nExample 3:\n\nInput: m = 5, n = 5\nOutput: 580986\n\nConstraints:\n\n- 1 <= m <= 5\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 2,n = 4) == 162\n assert candidate(m = 4,n = 3) == 1122\n assert candidate(m = 5,n = 1) == 48\n assert candidate(m = 1,n = 2) == 6\n assert candidate(m = 5,n = 5) == 580986\n assert candidate(m = 3,n = 4) == 1122\n assert candidate(m = 1,n = 1) == 3\n assert candidate(m = 4,n = 2) == 162\n assert candidate(m = 3,n = 3) == 246\n assert candidate(m = 2,n = 3) == 54\n assert candidate(m = 5,n = 800) == 253729951\n assert candidate(m = 4,n = 4) == 7812\n assert candidate(m = 2,n = 800) == 351341125\n assert candidate(m = 5,n = 500) == 859596253\n assert candidate(m = 5,n = 250) == 385854418\n assert candidate(m = 1,n = 1000) == 32634808\n assert candidate(m = 4,n = 350) == 47085356\n assert candidate(m = 3,n = 10) == 10107954\n assert candidate(m = 4,n = 500) == 614795573\n assert candidate(m = 1,n = 5) == 48\n assert candidate(m = 1,n = 500) == 85724507\n assert candidate(m = 3,n = 50) == 151149117\n assert candidate(m = 4,n = 600) == 643128638\n assert candidate(m = 4,n = 750) == 346928514\n assert candidate(m = 3,n = 500) == 350959293\n assert candidate(m = 2,n = 100) == 772083415\n assert candidate(m = 5,n = 2) == 486\n assert candidate(m = 2,n = 900) == 360544652\n assert candidate(m = 2,n = 2) == 18\n assert candidate(m = 4,n = 1000) == 281273229\n assert candidate(m = 4,n = 998) == 16509421\n assert candidate(m = 3,n = 7) == 106494\n assert candidate(m = 3,n = 1000) == 650420578\n assert candidate(m = 5,n = 50) == 597561939\n assert candidate(m = 4,n = 100) == 80216004\n assert candidate(m = 4,n = 10) == 896895828\n assert candidate(m = 4,n = 999) == 772309689\n assert candidate(m = 4,n = 6) == 379602\n assert candidate(m = 2,n = 999) == 37925462\n assert candidate(m = 5,n = 100) == 714933866\n assert candidate(m = 2,n = 600) == 138487123\n assert candidate(m = 3,n = 1) == 12\n assert candidate(m = 5,n = 10) == 796884854\n assert candidate(m = 3,n = 800) == 314710698\n assert candidate(m = 4,n = 5) == 54450\n assert candidate(m = 5,n = 200) == 55054779\n assert candidate(m = 3,n = 750) == 493513580\n assert candidate(m = 5,n = 997) == 582030758\n assert candidate(m = 3,n = 900) == 999754739\n assert candidate(m = 3,n = 700) == 360760626\n assert candidate(m = 5,n = 300) == 194398079\n assert candidate(m = 4,n = 9) == 128643282\n assert candidate(m = 2,n = 1000) == 113776386\n assert candidate(m = 4,n = 700) == 795691966\n assert candidate(m = 4,n = 250) == 727847864\n assert candidate(m = 5,n = 3) == 5118\n assert candidate(m = 4,n = 800) == 197304781\n assert candidate(m = 3,n = 300) == 748221310\n assert candidate(m = 5,n = 1000) == 408208448\n assert candidate(m = 3,n = 20) == 690883140\n assert candidate(m = 2,n = 5) == 486\n", "comparison": "exact"}, "public_tests": ["1\n1", "1\n2", "5\n5"], "hints": ["Represent each colored column by a bitmask based on each cell color.", "Use bitmasks DP with state (currentCell, prevColumn)."], "metadata": {"canonical_parameter_names": ["m", "n"], "leetcode_dataset_entry_point": "Solution().colorTheGrid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:28+00:00", "tests_total": 61, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["dynamic-programming", "graph-coloring"]}, "language": "php", "interface": {"raw_signature": "function colorTheGrid($m, $n) {", "container": "Solution", "callable": "colorTheGrid", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1935, "task_id": "maximum-number-of-words-you-can-type", "difficulty": "Easy", "problem_description": "There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.\n\nGiven a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all distinct letter keys that are broken, return the number of words in text you can fully type using this keyboard.\n\nExample 1:\n\nInput: text = \"hello world\", brokenLetters = \"ad\"\nOutput: 1\nExplanation: We cannot type \"world\" because the 'd' key is broken.\n\nExample 2:\n\nInput: text = \"leet code\", brokenLetters = \"lt\"\nOutput: 1\nExplanation: We cannot type \"leet\" because the 'l' and 't' keys are broken.\n\nExample 3:\n\nInput: text = \"leet code\", brokenLetters = \"e\"\nOutput: 0\nExplanation: We cannot type either word because the 'e' key is broken.\n\nConstraints:\n\n- 1 <= text.length <= 10^4\n- 0 <= brokenLetters.length <= 26\n- text consists of words separated by a single space without any leading or trailing spaces.\n- Each word only consists of lowercase English letters.\n- brokenLetters consists of distinct lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(text = \"jumped over the lazy dog\",brokenLetters = \"zg\") == 3\n assert candidate(text = \"nopqrstuvwxyz\",brokenLetters = \"xyz\") == 0\n assert candidate(text = \"xyzzzz\",brokenLetters = \"x\") == 0\n assert candidate(text = \"leet code\",brokenLetters = \"lt\") == 1\n assert candidate(text = \"programming is fun\",brokenLetters = \"fn\") == 1\n assert candidate(text = \"this is a test\",brokenLetters = \"xyz\") == 4\n assert candidate(text = \"mississippi\",brokenLetters = \"sip\") == 0\n assert candidate(text = \"python java cplusplus\",brokenLetters = \"ypx\") == 1\n assert candidate(text = \"same same same\",brokenLetters = \"aem\") == 0\n assert candidate(text = \"a b c d e\",brokenLetters = \"\") == 5\n assert candidate(text = \"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\",brokenLetters = \"xyz\") == 23\n assert candidate(text = \"abcdefghijk\",brokenLetters = \"abcde\") == 0\n assert candidate(text = \"leet code\",brokenLetters = \"e\") == 0\n assert candidate(text = \"single\",brokenLetters = \"s\") == 0\n assert candidate(text = \"unique words\",brokenLetters = \"\") == 2\n assert candidate(text = \"single\",brokenLetters = \"\") == 1\n assert candidate(text = \"abc def ghi\",brokenLetters = \"xyz\") == 3\n assert candidate(text = \"python programming\",brokenLetters = \"p\") == 0\n assert candidate(text = \"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\",brokenLetters = \"\") == 26\n assert candidate(text = \"a quick brown fox\",brokenLetters = \"\") == 4\n assert candidate(text = \"abcd efgh ijkl mnop qrst uvwx yz\",brokenLetters = \"aeiou\") == 2\n assert candidate(text = \"python programming\",brokenLetters = \"th\") == 1\n assert candidate(text = \"abcdefghij\",brokenLetters = \"\") == 1\n assert candidate(text = \"hello hello hello\",brokenLetters = \"lo\") == 0\n assert candidate(text = \"hello world\",brokenLetters = \"ad\") == 1\n assert candidate(text = \"every good boy does fine\",brokenLetters = \"f\") == 4\n assert candidate(text = \"hello world abcdefghijklmnopqrstuvwxyz\",brokenLetters = \"\") == 3\n assert candidate(text = \"a b c d e f g\",brokenLetters = \"xyz\") == 7\n assert candidate(text = \"extreme example with all letters\",brokenLetters = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(text = \"this is a simple test\",brokenLetters = \"sti\") == 1\n assert candidate(text = \"singleword\",brokenLetters = \"w\") == 0\n assert candidate(text = \"abcdefghij klmnopqrstuvwxyz\",brokenLetters = \"xyz\") == 1\n assert candidate(text = \"university of california berkeley\",brokenLetters = \"bcdfg\") == 1\n assert candidate(text = \"congratulations on your success\",brokenLetters = \"cns\") == 1\n assert candidate(text = \"every good boy does fine\",brokenLetters = \"bd\") == 2\n assert candidate(text = \"hello world from the other side\",brokenLetters = \"dfr\") == 2\n assert candidate(text = \"complexity arises from multiple factors\",brokenLetters = \"ae\") == 1\n assert candidate(text = \"all the letters of the alphabet\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"keyboard malfunctioning example\",brokenLetters = \"kmb\") == 0\n assert candidate(text = \"short long longer longestword\",brokenLetters = \"nlg\") == 1\n assert candidate(text = \"repeated letters letters letters\",brokenLetters = \"r\") == 0\n assert candidate(text = \"quick brown fox jumps over the lazy dog\",brokenLetters = \"xyz\") == 6\n assert candidate(text = \"data structures and algorithms\",brokenLetters = \"dts\") == 0\n assert candidate(text = \"abcdef ghijklm nopqrst uvwxyz\",brokenLetters = \"mnop\") == 2\n assert candidate(text = \"multiple broken letters test\",brokenLetters = \"mlpt\") == 1\n assert candidate(text = \"abcdefghij klmnopqrstuvwxyz\",brokenLetters = \"jkl\") == 0\n assert candidate(text = \"mississippi river\",brokenLetters = \"is\") == 0\n assert candidate(text = \"no broken letters here\",brokenLetters = \"qwxz\") == 4\n assert candidate(text = \"programming is fun\",brokenLetters = \"funs\") == 0\n assert candidate(text = \"all unique characters\",brokenLetters = \"\") == 3\n assert candidate(text = \"quick brown fox jumps over the lazy dog\",brokenLetters = \"\") == 8\n assert candidate(text = \"hello world hello universe\",brokenLetters = \"d\") == 3\n assert candidate(text = \"supercalifragilisticexpialidocious\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"special symbols are not included !@#$%^&*()\",brokenLetters = \"\") == 6\n assert candidate(text = \"brokenkeyboard faultydevice\",brokenLetters = \"bdf\") == 0\n assert candidate(text = \"sequential typing test\",brokenLetters = \"qseq\") == 1\n assert candidate(text = \"unique letters in words\",brokenLetters = \"aeiouy\") == 0\n assert candidate(text = \"python code implementation\",brokenLetters = \"py\") == 1\n assert candidate(text = \"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\",brokenLetters = \"qz\") == 24\n assert candidate(text = \"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\",brokenLetters = \"abcdefghijkl\") == 14\n assert candidate(text = \"complex words like supercalifragilisticexpialidocious\",brokenLetters = \"xyz\") == 2\n assert candidate(text = \"this is a simple test case\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"one two three four five six seven eight nine ten\",brokenLetters = \"on\") == 4\n assert candidate(text = \"lets write some code\",brokenLetters = \"wrs\") == 1\n assert candidate(text = \"multiple broken letters scenario\",brokenLetters = \"aeiouy\") == 0\n assert candidate(text = \"complex problem solving required\",brokenLetters = \"abc\") == 2\n assert candidate(text = \"this is a simple test\",brokenLetters = \"s\") == 1\n assert candidate(text = \"all characters must be checked\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"quick brown fox jumps over lazy dog\",brokenLetters = \"qz\") == 5\n assert candidate(text = \"various broken keys test\",brokenLetters = \"var\") == 2\n assert candidate(text = \"quick brown fox jumps over the lazy dog\",brokenLetters = \"qz\") == 6\n assert candidate(text = \"a quick brown fox jumps over the lazy dog\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"beautiful scenery on the mountain top\",brokenLetters = \"mnt\") == 0\n assert candidate(text = \"vowels are often omitted\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"mississippi river flows smoothly\",brokenLetters = \"m\") == 2\n assert candidate(text = \"hello world from another dimension\",brokenLetters = \"ad\") == 2\n assert candidate(text = \"singlewordwithoutspaces\",brokenLetters = \"s\") == 0\n assert candidate(text = \"abcdefghijklmnopqrstuvwxyz\",brokenLetters = \"xyz\") == 0\n assert candidate(text = \"fuzzy wuzzy was a bear\",brokenLetters = \"f\") == 4\n assert candidate(text = \"algorithms and data structures\",brokenLetters = \"da\") == 1\n assert candidate(text = \"make america great again\",brokenLetters = \"mag\") == 0\n assert candidate(text = \"hello hello hello world\",brokenLetters = \"d\") == 3\n assert candidate(text = \"a aa aaa aaaa aaaaa\",brokenLetters = \"a\") == 0\n assert candidate(text = \"mississippi river\",brokenLetters = \"m\") == 1\n assert candidate(text = \"many many words with many repeated letters\",brokenLetters = \"mny\") == 4\n assert candidate(text = \"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz\",brokenLetters = \"\") == 2\n assert candidate(text = \"alibaba cloud is amazing\",brokenLetters = \"aim\") == 1\n assert candidate(text = \"boundary conditions and edge cases\",brokenLetters = \"bace\") == 0\n assert candidate(text = \"the quick brown fox jumps over the lazy dog\",brokenLetters = \"\") == 9\n assert candidate(text = \"algorithm data structures\",brokenLetters = \"abcde\") == 0\n assert candidate(text = \"xylophone xylophone xylophone\",brokenLetters = \"xy\") == 0\n assert candidate(text = \"complex problem solving\",brokenLetters = \"cps\") == 0\n assert candidate(text = \"longer words with various letters\",brokenLetters = \"wv\") == 2\n assert candidate(text = \"every good boy does fine\",brokenLetters = \"boyd\") == 1\n assert candidate(text = \"the quick brown fox jumps over the lazy dog\",brokenLetters = \"qxyz\") == 6\n assert candidate(text = \"programming in python is fun\",brokenLetters = \"pqf\") == 2\n assert candidate(text = \"this is a test case with many words\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"repeated letters in words\",brokenLetters = \"r\") == 1\n assert candidate(text = \"mississippi river\",brokenLetters = \"r\") == 1\n assert candidate(text = \"edge cases require attention\",brokenLetters = \"ecr\") == 0\n assert candidate(text = \"short words\",brokenLetters = \"aef\") == 2\n assert candidate(text = \"all characters are broken here\",brokenLetters = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(text = \"this is a simple test\",brokenLetters = \"st\") == 1\n assert candidate(text = \"multiple words with repeated letters\",brokenLetters = \"w\") == 3\n assert candidate(text = \"python is a versatile programming language\",brokenLetters = \"p\") == 4\n assert candidate(text = \"this is a simple test case\",brokenLetters = \"\") == 6\n assert candidate(text = \"short words\",brokenLetters = \"ow\") == 0\n assert candidate(text = \"distinct distinct letters letters\",brokenLetters = \"distnl\") == 0\n assert candidate(text = \"the quick brown fox jumps over the lazy dog\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"let us escape from this困境\",brokenLetters = \"et\") == 2\n assert candidate(text = \"broken keyboards are annoying sometimes\",brokenLetters = \"bks\") == 2\n assert candidate(text = \"various combinations\",brokenLetters = \"vbc\") == 0\n assert candidate(text = \"every good boy does fine and gets chocolate\",brokenLetters = \"xyz\") == 6\n assert candidate(text = \"hello world from mars\",brokenLetters = \"mr\") == 1\n assert candidate(text = \"various punctuations are missing\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"quick brown fox jumps over the lazy dog\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"unique words in this sentence\",brokenLetters = \"uie\") == 1\n assert candidate(text = \"multiple words with repeated letters\",brokenLetters = \"r\") == 2\n assert candidate(text = \"one two three four five\",brokenLetters = \"one\") == 0\n assert candidate(text = \"computer science\",brokenLetters = \"xyz\") == 2\n assert candidate(text = \"this is a simple test case\",brokenLetters = \"s\") == 1\n assert candidate(text = \"multiple spaces between words are not allowed\",brokenLetters = \"\") == 7\n assert candidate(text = \"special characters !@#$%^&*()\",brokenLetters = \"s\") == 1\n assert candidate(text = \"banana apple orange\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"abcdefghijklmnopqrstuvwxyz\",brokenLetters = \"nopqrstuvwxyz\") == 0\n assert candidate(text = \"abcdef ghijklm nopqrstuvwxyz\",brokenLetters = \"aeiou\") == 0\n assert candidate(text = \"spaceship traveling fast\",brokenLetters = \"spfc\") == 1\n assert candidate(text = \"unique characters only\",brokenLetters = \"uqnc\") == 0\n assert candidate(text = \"every good boy does fine\",brokenLetters = \"egbf\") == 0\n assert candidate(text = \"repeated repeated words words\",brokenLetters = \"dpw\") == 0\n assert candidate(text = \"abcdefghijklmnopqrstuvwxy z\",brokenLetters = \"z\") == 1\n assert candidate(text = \"complex problems require careful thought\",brokenLetters = \"th\") == 4\n assert candidate(text = \"all words can be typed\",brokenLetters = \"\") == 5\n assert candidate(text = \"abcdefg hijklm nopqrstuvwxyz\",brokenLetters = \"xyz\") == 2\n", "comparison": "exact"}, "public_tests": ["\"hello world\"\n\"ad\"", "\"leet code\"\n\"lt\"", "\"leet code\"\n\"e\""], "hints": ["Check each word separately if it can be typed.", "A word can be typed if all its letters are not broken."], "metadata": {"canonical_parameter_names": ["text", "brokenLetters"], "leetcode_dataset_entry_point": "Solution().canBeTypedWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:32+00:00", "tests_total": 135, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function canBeTypedWords($text, $brokenLetters) {", "container": "Solution", "callable": "canBeTypedWords", "parameters": [{"name": "text", "type": "String"}, {"name": "brokenLetters", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1936, "task_id": "add-minimum-number-of-rungs", "difficulty": "Medium", "problem_description": "You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder. You are currently on the floor at height 0, and you want to reach the last rung.\n\nYou are also given an integer dist. You can only climb to the next highest rung if the distance between where you are currently at (the floor or on a rung) and the next rung is at most dist. You are able to insert rungs at any positive integer height if a rung is not already there.\n\nReturn the minimum number of rungs that must be added to the ladder in order for you to climb to the last rung.\n\nExample 1:\n\nInput: rungs = [1,3,5,10], dist = 2\nOutput: 2\nExplanation:\nYou currently cannot reach the last rung.\nAdd rungs at heights 7 and 8 to climb this ladder.\nThe ladder will now have rungs at [1,3,5,7,8,10].\n\nExample 2:\n\nInput: rungs = [3,6,8,10], dist = 3\nOutput: 0\nExplanation:\nThis ladder can be climbed without adding additional rungs.\n\nExample 3:\n\nInput: rungs = [3,4,6,7], dist = 2\nOutput: 1\nExplanation:\nYou currently cannot reach the first rung from the ground.\nAdd a rung at height 1 to climb this ladder.\nThe ladder will now have rungs at [1,3,4,6,7].\n\nConstraints:\n\n- 1 <= rungs.length <= 10^5\n- 1 <= rungs[i] <= 10^9\n- 1 <= dist <= 10^9\n- rungs is strictly increasing.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rungs = [1, 3, 5, 10],dist = 2) == 2\n assert candidate(rungs = [1, 2, 3, 4, 5],dist = 1) == 0\n assert candidate(rungs = [3, 6, 8, 10],dist = 3) == 0\n assert candidate(rungs = [10],dist = 10) == 0\n assert candidate(rungs = [1000000000],dist = 1) == 999999999\n assert candidate(rungs = [1, 1000000000],dist = 1) == 999999998\n assert candidate(rungs = [1, 5, 11, 20],dist = 4) == 3\n assert candidate(rungs = [3, 4, 6, 7],dist = 2) == 1\n assert candidate(rungs = [5],dist = 10) == 0\n assert candidate(rungs = [1, 5, 10, 16, 23, 31, 40, 50, 61, 73, 86, 100],dist = 14) == 0\n assert candidate(rungs = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 1) == 89\n assert candidate(rungs = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],dist = 10) == 0\n assert candidate(rungs = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],dist = 2) == 502\n assert candidate(rungs = [2, 8, 16, 32, 64, 128],dist = 15) == 7\n assert candidate(rungs = [100, 200, 300, 400, 500],dist = 150) == 0\n assert candidate(rungs = [2, 5, 10, 20, 35, 55, 80, 110, 145, 185, 230],dist = 5) == 36\n assert candidate(rungs = [1, 8, 15, 22, 29],dist = 5) == 4\n assert candidate(rungs = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],dist = 10) == 0\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],dist = 15) == 0\n assert candidate(rungs = [5, 10, 20, 40, 80, 160],dist = 10) == 11\n assert candidate(rungs = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],dist = 3) == 24\n assert candidate(rungs = [1, 7, 15, 30, 60],dist = 10) == 3\n assert candidate(rungs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],dist = 1) == 502\n assert candidate(rungs = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],dist = 20) == 47\n assert candidate(rungs = [10, 25, 45, 70, 100, 130, 160, 190, 220, 250],dist = 30) == 0\n assert candidate(rungs = [1, 6, 15, 30, 50],dist = 10) == 2\n assert candidate(rungs = [1, 1000000000],dist = 100000000) == 9\n assert candidate(rungs = [100, 200, 300, 400, 500],dist = 99) == 5\n assert candidate(rungs = [1, 8, 15, 22, 30],dist = 5) == 4\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 9) == 10\n assert candidate(rungs = [10, 15, 25, 40, 50],dist = 10) == 1\n assert candidate(rungs = [2, 5, 11, 21, 35, 50],dist = 5) == 6\n assert candidate(rungs = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59],dist = 6) == 0\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 1) == 90\n assert candidate(rungs = [1, 1000000000],dist = 100000000) == 9\n assert candidate(rungs = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105],dist = 14) == 0\n assert candidate(rungs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],dist = 1) == 0\n assert candidate(rungs = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],dist = 50) == 0\n assert candidate(rungs = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100],dist = 10) == 0\n assert candidate(rungs = [10, 30, 50, 70, 90, 110, 130, 150, 170, 190],dist = 20) == 0\n assert candidate(rungs = [10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105],dist = 10) == 4\n assert candidate(rungs = [5, 10, 20, 40, 80, 160],dist = 25) == 4\n assert candidate(rungs = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],dist = 1) == 10\n assert candidate(rungs = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120],dist = 4) == 21\n assert candidate(rungs = [1, 4, 10, 20, 30],dist = 5) == 3\n assert candidate(rungs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],dist = 10) == 98\n assert candidate(rungs = [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000],dist = 100000) == 6\n assert candidate(rungs = [3, 15, 25, 30, 45, 60, 85, 100],dist = 12) == 5\n assert candidate(rungs = [1, 3, 6, 10, 15, 21, 28],dist = 3) == 5\n assert candidate(rungs = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],dist = 100) == 8\n assert candidate(rungs = [2, 6, 10, 14, 18, 22, 26],dist = 4) == 0\n assert candidate(rungs = [100, 200, 300, 400, 500],dist = 90) == 5\n assert candidate(rungs = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],dist = 100000) == 9995\n assert candidate(rungs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576],dist = 1024) == 1013\n assert candidate(rungs = [5, 11, 19, 29, 41, 55, 71, 89, 109, 131],dist = 6) == 15\n assert candidate(rungs = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 9) == 9\n assert candidate(rungs = [2, 8, 14, 20, 26, 32, 38, 44, 50],dist = 6) == 0\n assert candidate(rungs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],dist = 3) == 0\n assert candidate(rungs = [1, 2, 4, 7, 13, 21],dist = 3) == 3\n assert candidate(rungs = [1000000000],dist = 500000000) == 1\n assert candidate(rungs = [1, 5, 15, 30, 50, 70, 100, 150, 200, 300],dist = 25) == 6\n assert candidate(rungs = [2, 8, 14, 22, 30, 40, 50],dist = 6) == 4\n assert candidate(rungs = [1, 1000000000],dist = 1) == 999999998\n assert candidate(rungs = [1, 100, 200, 300],dist = 50) == 3\n assert candidate(rungs = [3, 15, 35, 65, 100, 145, 195, 250, 310, 375],dist = 10) == 31\n assert candidate(rungs = [10, 25, 45, 60, 75, 90],dist = 15) == 1\n assert candidate(rungs = [10, 25, 45, 70, 100],dist = 15) == 3\n assert candidate(rungs = [1, 1000000000],dist = 500000000) == 1\n assert candidate(rungs = [5, 12, 24, 40, 60, 85, 100],dist = 10) == 6\n assert candidate(rungs = [1, 1000000000],dist = 1000000) == 999\n assert candidate(rungs = [2, 5, 9, 14, 20, 27, 35, 44, 54, 65],dist = 4) == 10\n assert candidate(rungs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],dist = 2) == 0\n assert candidate(rungs = [1, 9, 15, 25, 30],dist = 5) == 3\n assert candidate(rungs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],dist = 9) == 0\n assert candidate(rungs = [2, 8, 18, 32, 50, 72, 98],dist = 15) == 3\n assert candidate(rungs = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120],dist = 500) == 8\n assert candidate(rungs = [5, 10, 20, 40, 80, 160],dist = 10) == 11\n assert candidate(rungs = [1, 6, 11, 16, 21, 26],dist = 5) == 0\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 10) == 0\n assert candidate(rungs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],dist = 2) == 0\n assert candidate(rungs = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],dist = 5) == 5\n assert candidate(rungs = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],dist = 1000000) == 996\n assert candidate(rungs = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],dist = 3) == 0\n assert candidate(rungs = [1000000000],dist = 100000000) == 9\n assert candidate(rungs = [1, 1000000000],dist = 500000000) == 1\n assert candidate(rungs = [10, 1000000000],dist = 500000000) == 1\n assert candidate(rungs = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 9) == 9\n assert candidate(rungs = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106],dist = 5) == 13\n assert candidate(rungs = [2, 3, 6, 8, 15, 22, 30, 35, 40, 50],dist = 5) == 4\n assert candidate(rungs = [3, 9, 12, 21, 23, 29, 30],dist = 6) == 1\n assert candidate(rungs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],dist = 2) == 0\n assert candidate(rungs = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],dist = 3) == 12\n assert candidate(rungs = [1, 10, 15, 20, 25, 30],dist = 5) == 1\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],dist = 15) == 0\n assert candidate(rungs = [5, 12, 22, 35, 50, 68, 89, 113, 141, 173, 209],dist = 7) == 23\n assert candidate(rungs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],dist = 1) == 0\n assert candidate(rungs = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],dist = 1) == 10\n assert candidate(rungs = [1, 2, 4, 8, 16, 32, 64],dist = 15) == 3\n assert candidate(rungs = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89],dist = 2) == 38\n assert candidate(rungs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],dist = 9) == 10\n assert candidate(rungs = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],dist = 1000000) == 996\n assert candidate(rungs = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],dist = 100) == 8\n", "comparison": "exact"}, "public_tests": ["[1,3,5,10]\n2", "[3,6,8,10]\n3", "[3,4,6,7]\n2"], "hints": ["Go as far as you can on the available rungs before adding new rungs.", "If you have to add a new rung, add it as high up as possible.", "Try using division to decrease the number of computations."], "metadata": {"canonical_parameter_names": ["rungs", "dist"], "leetcode_dataset_entry_point": "Solution().addRungs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:34+00:00", "tests_total": 102, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function addRungs($rungs, $dist) {", "container": "Solution", "callable": "addRungs", "parameters": [{"name": "rungs", "type": "Integer[]"}, {"name": "dist", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1937, "task_id": "maximum-number-of-points-with-cost", "difficulty": "Medium", "problem_description": "You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.\n\nTo gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.\n\nHowever, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c_1) and (r + 1, c_2) will subtract abs(c_1 - c_2) from your score.\n\nReturn the maximum number of points you can achieve.\n\nabs(x) is defined as:\n\n- x for x >= 0.\n- -x for x < 0.\n\nExample 1:\n\nInput: points = [[1,2,3],[1,5,1],[3,1,1]]\nOutput: 9\nExplanation:\nThe blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).\nYou add 3 + 5 + 3 = 11 to your score.\nHowever, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.\nYour final score is 11 - 2 = 9.\n\nExample 2:\n\nInput: points = [[1,5],[2,3],[4,2]]\nOutput: 11\nExplanation:\nThe blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).\nYou add 5 + 3 + 4 = 12 to your score.\nHowever, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.\nYour final score is 12 - 1 = 11.\n\nConstraints:\n\n- m == points.length\n- n == points[r].length\n- 1 <= m, n <= 10^5\n- 1 <= m * n <= 10^5\n- 0 <= points[r][c] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [[5, 10], [10, 5]]) == 19\n assert candidate(points = [[5, 2], [1, 2]]) == 6\n assert candidate(points = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9]]) == 15\n assert candidate(points = [[1, 2, 3], [1, 5, 1], [3, 1, 1]]) == 9\n assert candidate(points = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == 6\n assert candidate(points = [[1, 5], [2, 3], [4, 2]]) == 11\n assert candidate(points = [[1]]) == 1\n assert candidate(points = [[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]]) == 15\n assert candidate(points = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == 25\n assert candidate(points = [[5, 3, 8, 6, 7, 2], [9, 4, 1, 5, 3, 8], [2, 6, 4, 9, 1, 5], [7, 3, 5, 2, 8, 6]]) == 28\n assert candidate(points = [[1, 3, 2], [4, 6, 5], [7, 9, 8], [10, 12, 11], [13, 15, 14]]) == 45\n assert candidate(points = [[1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1]]) == 15\n assert candidate(points = [[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, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 121\n assert candidate(points = [[9, 5, 3, 1, 7], [2, 8, 6, 4, 0], [5, 1, 9, 3, 6], [4, 7, 2, 8, 5], [3, 6, 4, 1, 9]]) == 39\n assert candidate(points = [[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]]) == 21\n assert candidate(points = [[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 28\n assert candidate(points = [[5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5]]) == 20\n assert candidate(points = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 0\n assert candidate(points = [[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]]) == 40\n assert candidate(points = [[5, 10, 15, 20, 25], [25, 20, 15, 10, 5], [5, 5, 5, 5, 5], [10, 15, 20, 25, 30], [30, 25, 20, 15, 10]]) == 103\n assert candidate(points = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 12\n assert candidate(points = [[10, 20, 30, 40, 50, 60, 70], [70, 60, 50, 40, 30, 20, 10], [10, 70, 20, 60, 30, 50, 40]]) == 203\n assert candidate(points = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 40\n assert candidate(points = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(points = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1]]) == 106\n assert candidate(points = [[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, 9, 7, 5, 3, 1]]) == 21\n assert candidate(points = [[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]]) == 51\n assert candidate(points = [[5, 3, 1, 4], [3, 1, 4, 5], [1, 4, 5, 3], [4, 5, 3, 1]]) == 17\n assert candidate(points = [[5, 3, 8, 6], [2, 4, 7, 1], [3, 6, 9, 2], [8, 5, 2, 4]]) == 30\n assert candidate(points = [[9, 1, 5, 3, 7], [3, 9, 1, 5, 3], [7, 3, 9, 1, 5], [5, 7, 3, 9, 1], [1, 5, 7, 3, 9]]) == 41\n assert candidate(points = [[5, 2, 3, 1, 4], [1, 3, 2, 5, 4], [3, 4, 5, 2, 1], [4, 1, 2, 3, 5], [2, 5, 4, 1, 3]]) == 18\n assert candidate(points = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]]) == 15\n assert candidate(points = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 180\n assert candidate(points = [[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]]) == 45\n assert candidate(points = [[0, 0, 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(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]]) == 5\n assert candidate(points = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [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]]) == 50\n assert candidate(points = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 6, 2, 5, 3, 4]]) == 13\n assert candidate(points = [[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]]) == 27\n assert candidate(points = [[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]]) == 250\n assert candidate(points = [[100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000]]) == 300000\n assert candidate(points = [[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], [1, 9, 1, 9, 1, 9, 1, 9, 1]]) == 27\n assert candidate(points = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 100], [100, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 100, 0], [0, 0, 0, 0, 0, 0, 0, 100, 0, 0], [0, 0, 0, 0, 0, 0, 100, 0, 0, 0]]) == 481\n assert candidate(points = [[100, 200, 300, 400, 500], [90, 80, 70, 60, 50], [10, 20, 30, 40, 50], [5, 15, 25, 35, 45]]) == 677\n assert candidate(points = [[1, 10, 2, 9, 3, 8, 4, 7, 5, 6], [10, 1, 9, 2, 8, 3, 7, 4, 6, 5], [5, 6, 4, 7, 3, 8, 2, 9, 1, 10]]) == 24\n assert candidate(points = [[10, 10, 10, 10, 10], [1, 1, 1, 1, 1], [9, 9, 9, 9, 9], [2, 2, 2, 2, 2]]) == 22\n assert candidate(points = [[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]]) == 30\n assert candidate(points = [[1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2], [2, 1]]) == 12\n assert candidate(points = [[10, 6, 3, 9, 7], [1, 4, 5, 8, 2], [9, 7, 4, 3, 6], [2, 8, 1, 5, 9]]) == 31\n assert candidate(points = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 110\n assert candidate(points = [[100, 100, 100], [100, 100, 100], [100, 100, 100], [100, 100, 100], [100, 100, 100]]) == 500\n assert candidate(points = [[5, 3, 8, 6, 2, 9], [1, 7, 4, 8, 5, 3], [6, 2, 9, 4, 8, 1], [3, 6, 5, 7, 2, 8]]) == 29\n assert candidate(points = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 50, 10, 50, 10], [50, 10, 50, 10, 50], [10, 20, 30, 40, 50]]) == 242\n assert candidate(points = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 4\n assert candidate(points = [[1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13]]) == 22\n assert candidate(points = [[1, 1, 1, 1, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == 7\n assert candidate(points = [[100000, 90000, 80000, 70000, 60000], [50000, 40000, 30000, 20000, 10000], [90000, 80000, 70000, 60000, 50000], [40000, 30000, 20000, 10000, 9000]]) == 280000\n assert candidate(points = [[90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [99, 98, 97, 96, 95, 94, 93, 92, 91, 90], [90, 92, 94, 96, 98, 100, 98, 96, 94, 92]]) == 289\n assert candidate(points = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 20, 30, 40, 50, 60, 70, 80, 90], [90, 80, 70, 60, 50, 40, 30, 20, 10]]) == 182\n assert candidate(points = [[1000, 500, 250, 125], [125, 250, 500, 1000], [1000, 500, 250, 125], [125, 250, 500, 1000]]) == 3991\n assert candidate(points = [[5, 3, 1, 4, 2], [8, 6, 7, 5, 3], [0, 9, 8, 7, 6], [2, 3, 4, 5, 1]]) == 24\n assert candidate(points = [[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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 42\n assert candidate(points = [[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]]) == 150\n assert candidate(points = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 45\n assert candidate(points = [[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], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 112\n assert candidate(points = [[0, 0, 0, 0, 0, 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(points = [[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]]) == 41\n assert candidate(points = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 30, 50, 70, 90], [90, 70, 50, 30, 10]]) == 268\n assert candidate(points = [[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]]) == 10\n assert candidate(points = [[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\n assert candidate(points = [[5, 3, 8, 2, 1], [1, 4, 2, 3, 8], [8, 1, 4, 2, 3], [3, 8, 1, 4, 2]]) == 25\n assert candidate(points = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [1, 2, 3, 4, 5], [9, 8, 7, 6, 5]]) == 106\n assert candidate(points = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == 300000\n assert candidate(points = [[100, 200], [150, 250], [200, 150], [250, 100], [300, 50]]) == 1199\n assert candidate(points = [[100, 90, 80, 70, 60, 50, 40, 30, 20, 10], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 201\n assert candidate(points = [[5, 3, 1], [1, 5, 3], [3, 1, 5], [5, 3, 1], [1, 5, 3]]) == 20\n assert candidate(points = [[10, 3, 5, 1, 2], [4, 6, 7, 3, 8], [2, 9, 1, 4, 6], [5, 3, 7, 9, 1], [8, 2, 6, 4, 5]]) == 36\n assert candidate(points = [[10, 1, 3, 5, 20], [5, 10, 15, 20, 25], [25, 20, 15, 10, 5]]) == 66\n assert candidate(points = [[1, 3, 1, 5, 1, 3, 1], [3, 1, 3, 1, 3, 1, 3], [1, 5, 1, 5, 1, 5, 1], [5, 1, 5, 1, 5, 1, 5]]) == 15\n assert candidate(points = [[100, 200, 300], [300, 200, 100], [200, 300, 200], [100, 100, 100]]) == 997\n assert candidate(points = [[100, 90, 80, 70, 60], [60, 70, 80, 90, 100], [100, 100, 100, 100, 100], [1, 2, 3, 4, 5]]) == 301\n assert candidate(points = [[7, 6, 8, 5, 9, 10], [10, 9, 8, 7, 6, 5], [5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6]]) == 31\n assert candidate(points = [[10, 15, 20, 25, 30], [5, 10, 15, 20, 25], [30, 25, 20, 15, 10], [1, 2, 3, 4, 5]]) == 82\n assert candidate(points = [[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], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 32\n assert candidate(points = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 11\n assert candidate(points = [[10, 20, 30], [30, 20, 10], [20, 30, 10], [10, 20, 30], [30, 10, 20]]) == 144\n assert candidate(points = [[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]]) == 45\n assert candidate(points = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == 0\n assert candidate(points = [[10, 15, 20, 25], [25, 20, 15, 10], [10, 20, 30, 40], [40, 30, 20, 10]]) == 121\n assert candidate(points = [[7, 8, 9, 10, 11], [11, 10, 9, 8, 7], [7, 9, 11, 10, 8], [8, 10, 7, 9, 11]]) == 38\n assert candidate(points = [[5, 1, 3, 2, 4], [2, 6, 1, 4, 5], [3, 3, 5, 1, 2], [1, 2, 4, 6, 3]]) == 19\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[1,5,1],[3,1,1]]", "[[1,5],[2,3],[4,2]]"], "hints": ["Try using dynamic programming.", "dp[i][j] is the maximum number of points you can have if points[i][j] is the most recent cell you picked."], "metadata": {"canonical_parameter_names": ["points"], "leetcode_dataset_entry_point": "Solution().maxPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:37+00:00", "tests_total": 91, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "php", "interface": {"raw_signature": "function maxPoints($points) {", "container": "Solution", "callable": "maxPoints", "parameters": [{"name": "points", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1938, "task_id": "maximum-genetic-difference-query", "difficulty": "Hard", "problem_description": "There is a rooted tree consisting of n nodes numbered 0 to n - 1. Each node's number denotes its unique genetic value (i.e. the genetic value of node x is x). The genetic difference between two genetic values is defined as the bitwise-XOR of their values. You are given the integer array parents, where parents[i] is the parent for node i. If node x is the root of the tree, then parents[x] == -1.\n\nYou are also given the array queries where queries[i] = [node_i, val_i]. For each query i, find the maximum genetic difference between val_i and p_i, where p_i is the genetic value of any node that is on the path between node_i and the root (including node_i and the root). More formally, you want to maximize val_i XOR p_i.\n\nReturn an array ans where ans[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: parents = [-1,0,1,1], queries = [[0,2],[3,2],[2,5]]\nOutput: [2,3,7]\nExplanation: The queries are processed as follows:\n- [0,2]: The node with the maximum genetic difference is 0, with a difference of 2 XOR 0 = 2.\n- [3,2]: The node with the maximum genetic difference is 1, with a difference of 2 XOR 1 = 3.\n- [2,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.\n\nExample 2:\n\nInput: parents = [3,7,-1,2,0,7,0,2], queries = [[4,6],[1,15],[0,5]]\nOutput: [6,14,7]\nExplanation: The queries are processed as follows:\n- [4,6]: The node with the maximum genetic difference is 0, with a difference of 6 XOR 0 = 6.\n- [1,15]: The node with the maximum genetic difference is 1, with a difference of 15 XOR 1 = 14.\n- [0,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.\n\nConstraints:\n\n- 2 <= parents.length <= 10^5\n- 0 <= parents[i] <= parents.length - 1 for every node i that is not the root.\n- parents[root] == -1\n- 1 <= queries.length <= 3 * 10^4\n- 0 <= node_i <= parents.length - 1\n- 0 <= val_i <= 2 * 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(parents = [-1, 0, 0, 1, 1],queries = [[0, 3], [2, 1], [3, 4], [4, 5]]) == [3, 3, 7, 5]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3],queries = [[4, 5], [7, 10], [2, 15]]) == [5, 13, 15]\n assert candidate(parents = [3, 7, -1, 2, 0, 7, 0, 2],queries = [[4, 6], [1, 15], [0, 5]]) == [6, 14, 7]\n assert candidate(parents = [0, 0, 0, 1, 1, 2, 2, 3, 3],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70]]) == [10, 21, 30, 43, 54, 62, 70]\n assert candidate(parents = [-1, 0, 0, 1, 1],queries = [[2, 3], [4, 4], [3, 5]]) == [3, 5, 6]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7],queries = [[8, 1], [7, 2], [6, 3], [5, 4], [4, 5], [3, 6], [2, 7], [1, 8], [0, 9]]) == [9, 7, 7, 7, 7, 7, 7, 9, 9]\n assert candidate(parents = [-1, 0, 1, 1, 3, 3],queries = [[0, 10], [5, 15], [3, 20]]) == [10, 15, 23]\n assert candidate(parents = [-1, 0, 0, 1, 1],queries = [[0, 3], [1, 2], [2, 1], [3, 4], [4, 5]]) == [3, 3, 3, 7, 5]\n assert candidate(parents = [-1, 0, 1, 1],queries = [[0, 2], [3, 2], [2, 5]]) == [2, 3, 7]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6],queries = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [1, 3, 3, 7, 7, 7, 7]\n assert candidate(parents = [-1, 0, 0, 1],queries = [[0, 3], [2, 5], [3, 4]]) == [3, 7, 7]\n assert candidate(parents = [-1, 0, 1, 2, 3],queries = [[4, 1], [1, 2], [2, 3], [3, 4]]) == [5, 3, 3, 7]\n assert candidate(parents = [3, 3, -1, 0, 0],queries = [[4, 100000], [3, 100001], [2, 100002], [1, 100003], [0, 100004]]) == [0, 0, 100000, 0, 0]\n assert candidate(parents = [-1, 0, 0, 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],queries = [[0, 25], [1, 50], [2, 75], [3, 100], [4, 125], [5, 150], [6, 175], [7, 200], [8, 225], [9, 250], [10, 275], [11, 300], [12, 325], [13, 350], [14, 375], [15, 400], [16, 425], [17, 450], [18, 475], [19, 500], [20, 525], [21, 550], [22, 575], [23, 600], [24, 625], [25, 650], [26, 675], [27, 700]]) == [25, 51, 75, 103, 125, 151, 175, 207, 233, 251, 281, 301, 329, 351, 377, 415, 441, 467, 477, 502, 537, 563, 575, 603, 633, 659, 697, 703]\n assert candidate(parents = [-1, 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, 20, 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], [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]]) == [1, 3, 3, 7, 5, 6, 7, 15, 10, 14, 15, 14, 15, 14, 15, 31, 22, 26, 27, 29, 28, 28, 29, 29, 28, 31, 30, 30, 31, 30, 31, 63, 46, 50, 51, 53, 52, 52, 53]\n assert candidate(parents = [-1, 0, 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],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110], [11, 120], [12, 130], [13, 140], [14, 150], [15, 160], [16, 170], [17, 180], [18, 190], [19, 200], [20, 210], [21, 220], [22, 230], [23, 240], [24, 250], [25, 260], [26, 270], [27, 280], [28, 290], [29, 300]]) == [10, 21, 30, 43, 54, 61, 71, 87, 90, 109, 110, 123, 142, 141, 152, 175, 186, 181, 191, 219, 212, 221, 240, 247, 253, 285, 276, 282, 318, 305]\n assert candidate(parents = [-1, 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],queries = [[0, 100000], [1, 50000], [2, 25000], [3, 12500], [4, 6250], [5, 3125], [6, 1562], [7, 781], [8, 390], [9, 195], [10, 97], [11, 48], [12, 24], [13, 12], [14, 6], [15, 3], [16, 1], [17, 0], [18, 0], [19, 0], [0, 100000]]) == [100000, 50001, 25002, 12503, 6254, 3127, 1564, 782, 398, 202, 107, 59, 29, 14, 8, 12, 17, 17, 18, 19, 100000]\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24],queries = [[0, 10101], [1, 10102], [2, 10103], [3, 10104], [4, 10105], [5, 10106], [6, 10107], [7, 10108], [8, 10109], [9, 10110], [10, 10111], [11, 10112], [12, 10113], [13, 10114], [14, 10115], [15, 10116], [16, 10117], [17, 10118], [18, 10119], [19, 10120], [20, 10121], [21, 10122], [22, 10123], [23, 10124], [24, 10125], [25, 10126], [26, 10127], [27, 10128], [28, 10129], [29, 10130], [30, 10131], [31, 10132], [32, 10133], [33, 10134], [34, 10135], [35, 10136], [36, 10137], [37, 10138], [38, 10139], [39, 10140]]) == [10101, 10103, 10103, 10107, 10109, 10111, 10109, 10111, 10110, 10111, 10111, 10123, 10125, 10127, 10125, 10123, 10133, 10135, 10133, 10139, 10141, 10143, 10141, 10139, 10133, 10135, 10133, 10141, 10140, 10140, 10141, 10139, 10165, 10167, 10165, 10171, 10173, 10175, 10173, 10171]\n assert candidate(parents = [-1, 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, 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],queries = [[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, 20], [19, 21], [18, 22], [17, 23], [16, 24], [15, 25], [14, 26], [13, 27], [12, 28], [11, 29], [10, 30], [9, 31], [8, 32], [7, 33], [6, 34], [5, 35], [4, 36], [3, 37], [2, 38], [1, 39], [0, 40]]) == [38, 36, 38, 32, 38, 36, 38, 40, 22, 20, 22, 16, 22, 20, 22, 27, 26, 24, 25, 29, 28, 30, 31, 31, 30, 28, 29, 30, 31, 31, 31, 40, 38, 36, 38, 37, 38, 38, 39, 40]\n assert candidate(parents = [-1, 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],queries = [[0, 1], [1, 3], [2, 7], [3, 15], [4, 31], [5, 63], [6, 127], [7, 255], [8, 511], [9, 1023], [10, 2047], [11, 4095], [12, 8191], [13, 16383], [14, 32767], [15, 65535]]) == [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535]\n assert candidate(parents = [-1, 0, 0, 1, 1, 3, 3, 4, 4, 5, 5],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100]]) == [100, 201, 302, 403, 501, 605, 703, 807, 908, 1005, 1103]\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29],queries = [[0, 5000], [1, 5001], [2, 5002], [3, 5003], [4, 5004], [5, 5005], [6, 5006], [7, 5007], [8, 5008], [9, 5009], [10, 5010], [11, 5011], [12, 5012], [13, 5013], [14, 5014], [15, 5015], [16, 5016], [17, 5017], [18, 5018], [19, 5019], [20, 5020], [21, 5021], [22, 5022], [23, 5023], [24, 5024], [25, 5025], [26, 5026], [27, 5027], [28, 5028], [29, 5029], [30, 5030], [31, 5031], [32, 5032], [33, 5033], [34, 5034], [35, 5035], [36, 5036], [37, 5037], [38, 5038], [39, 5039]]) == [5000, 5001, 5002, 5003, 5005, 5007, 5006, 5007, 5016, 5016, 5016, 5016, 5016, 5016, 5016, 5016, 5023, 5018, 5019, 5023, 5021, 5021, 5023, 5023, 5048, 5048, 5048, 5048, 5048, 5048, 5048, 5048, 5039, 5049, 5050, 5050, 5053, 5055, 5052, 5052]\n assert candidate(parents = [-1, 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, 20, 20],queries = [[0, 1000], [1, 2000], [2, 3000], [3, 4000], [4, 5000], [5, 6000], [6, 7000], [7, 8000], [8, 9000], [9, 10000], [10, 11000], [11, 12000], [12, 13000], [13, 14000], [14, 15000], [15, 16000], [16, 17000], [17, 18000], [18, 19000], [19, 20000], [20, 21000], [21, 22000], [22, 23000], [23, 24000], [24, 25000], [25, 26000], [26, 27000], [27, 28000], [28, 29000], [29, 30000], [30, 31000], [31, 32000]]) == [1000, 2001, 3002, 4003, 5004, 6005, 7006, 8007, 9003, 10009, 11004, 12011, 13005, 14013, 15006, 16015, 17016, 18008, 19003, 20019, 21020, 22010, 23004, 24023, 25008, 26012, 27005, 28027, 29012, 30014, 31006, 32031]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4],queries = [[0, 123], [1, 456], [2, 789], [3, 101], [4, 202], [5, 303], [6, 404], [7, 505], [8, 606], [9, 707], [10, 808], [11, 909]]) == [123, 457, 791, 102, 206, 303, 406, 510, 606, 714, 812, 909]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600], [16, 1700], [17, 1800]]) == [100, 201, 302, 403, 501, 605, 702, 807, 908, 1003, 1101, 1211, 1304, 1405, 1502, 1615, 1716, 1817]\n assert candidate(parents = [-1, 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],queries = [[0, 500], [1, 1000], [2, 1500], [3, 2000], [4, 2500], [5, 3000], [6, 3500], [7, 4000], [8, 4500], [9, 5000], [10, 5500], [11, 6000], [12, 6500], [13, 7000], [14, 7500], [15, 8000], [16, 8500], [17, 9000], [18, 9500], [19, 10000], [20, 10500], [21, 11000], [22, 11500], [23, 12000], [24, 12500], [25, 13000], [26, 13500], [27, 14000], [28, 14500], [29, 15000]]) == [500, 1001, 1502, 2003, 2501, 3005, 3502, 4007, 4508, 5004, 5501, 6011, 6504, 7006, 7502, 8015, 8503, 9017, 9503, 10009, 10512, 11004, 11514, 12023, 12511, 13009, 13502, 14013, 14520, 15006]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600], [16, 1700], [17, 1800], [18, 1900]]) == [100, 201, 302, 403, 503, 605, 703, 807, 908, 1007, 1103, 1211, 1311, 1407, 1503, 1615, 1716, 1817, 1918]\n assert candidate(parents = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],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, 3, 3, 7, 5, 7, 7, 15, 11, 11, 11, 15, 13, 15, 15, 31, 20, 23, 21, 22]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600], [16, 1700], [17, 1800], [18, 1900], [19, 2000], [20, 2100], [21, 2200]]) == [100, 201, 302, 403, 501, 605, 702, 807, 908, 1003, 1101, 1211, 1304, 1405, 1502, 1615, 1716, 1817, 1918, 2008, 2109, 2203]\n assert candidate(parents = [-1, 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],queries = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110], [11, 120], [12, 130], [13, 140], [14, 150], [15, 160], [16, 170], [17, 180], [18, 190], [19, 200], [20, 210], [21, 220], [22, 230], [23, 240], [24, 250], [25, 260], [26, 270], [27, 280], [28, 290], [29, 300]]) == [10, 21, 30, 43, 54, 62, 70, 87, 91, 109, 111, 125, 142, 142, 152, 175, 186, 188, 191, 219, 219, 221, 240, 251, 255, 285, 276, 286, 318, 305]\n assert candidate(parents = [-1, 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, 10, 10, 10, 10, 11, 11, 11, 11],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600], [16, 1700], [17, 1800], [18, 1900], [19, 2000], [20, 2100], [21, 2200], [22, 2300], [23, 2400], [24, 2500], [25, 2600], [26, 2700], [27, 2800], [28, 2900], [29, 3000], [30, 3100], [31, 3200], [32, 3300], [33, 3400], [34, 3500], [35, 3600], [36, 3700], [37, 3800], [38, 3900], [39, 4000]]) == [100, 201, 302, 403, 500, 605, 701, 807, 908, 1002, 1102, 1211, 1304, 1403, 1503, 1615, 1716, 1817, 1918, 2004, 2100, 2205, 2301, 2423, 2524, 2609, 2710, 2806, 2901, 3007, 3101, 3231, 3301, 3433, 3501, 3635, 3708, 3837, 3902, 4009]\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600]]) == [100, 201, 302, 403, 502, 605, 703, 807, 908, 1004, 1102, 1211, 1304, 1406, 1503, 1615]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],queries = [[0, 101], [1, 102], [2, 103], [3, 104], [4, 105], [5, 106], [6, 107], [7, 108], [8, 109], [9, 110], [10, 111], [11, 112], [12, 113], [13, 114], [14, 115], [15, 116], [16, 117], [17, 118], [18, 119], [19, 120]]) == [101, 103, 103, 107, 109, 111, 109, 111, 111, 111, 111, 123, 125, 127, 125, 123, 125, 126, 126, 124]\n assert candidate(parents = [-1, 0, 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, 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],queries = [[0, 1000], [1, 2000], [2, 3000], [3, 4000], [4, 5000], [5, 6000], [6, 7000], [7, 8000], [8, 9000], [9, 10000], [10, 11000], [11, 12000], [12, 13000], [13, 14000], [14, 15000], [15, 16000], [16, 17000], [17, 18000], [18, 19000], [19, 20000], [20, 21000], [21, 22000], [22, 23000], [23, 24000], [24, 25000], [25, 26000], [26, 27000], [27, 28000], [28, 29000], [29, 30000], [30, 31000], [31, 32000], [32, 33000], [33, 34000], [34, 35000], [35, 36000], [36, 37000], [37, 38000], [38, 39000], [39, 40000], [40, 41000], [41, 42000], [42, 43000], [43, 44000], [44, 45000], [45, 46000], [46, 47000], [47, 48000], [48, 49000], [49, 50000], [50, 51000], [51, 52000], [52, 53000], [53, 54000], [54, 55000], [55, 56000], [56, 57000], [57, 58000], [58, 59000], [59, 60000]]) == [1000, 2001, 3002, 4003, 5004, 6005, 7006, 8007, 9002, 10009, 11003, 12011, 13003, 14013, 15004, 16015, 17016, 18005, 19005, 20019, 21020, 22006, 23007, 24023, 25008, 26008, 27002, 28027, 29012, 30009, 31002, 32031, 33003, 34033, 35003, 36011, 37036, 38012, 39038, 40039, 41004, 42041, 43004, 44014, 45028, 46014, 47030, 48047, 49004, 50017, 51005, 52016, 53052, 54005, 55022, 56055, 57018, 58025, 59006, 60019]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [[0, 1024], [1, 512], [2, 256], [3, 128], [4, 64], [5, 32], [6, 16], [7, 8], [8, 4], [9, 2], [10, 1], [11, 513], [12, 257], [13, 129], [14, 65], [15, 33]]) == [1024, 513, 258, 131, 68, 37, 22, 15, 12, 11, 11, 523, 269, 141, 79, 47]\n assert candidate(parents = [-1, 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, 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],queries = [[0, 3000], [1, 4000], [2, 5000], [3, 6000], [4, 7000], [5, 8000], [6, 9000], [7, 10000], [8, 11000], [9, 12000], [10, 13000], [11, 14000], [12, 15000], [13, 16000], [14, 17000], [15, 18000], [16, 19000], [17, 20000], [18, 21000], [19, 22000], [20, 23000], [21, 24000], [22, 25000], [23, 26000], [24, 27000], [25, 28000], [26, 29000], [27, 30000], [28, 31000], [29, 32000], [30, 33000], [31, 34000], [32, 35000], [33, 36000], [34, 37000], [35, 38000], [36, 39000], [37, 40000], [38, 41000], [39, 42000], [40, 43000], [41, 44000], [42, 45000], [43, 46000], [44, 47000], [45, 48000], [46, 49000], [47, 50000], [48, 51000], [49, 52000], [50, 53000], [51, 54000], [52, 55000], [53, 56000], [54, 57000], [55, 58000], [56, 59000], [57, 60000], [58, 61000], [59, 62000], [60, 63000], [61, 64000], [62, 65000], [63, 66000], [64, 67000], [65, 68000], [66, 69000], [67, 70000], [68, 71000], [69, 72000], [70, 73000], [71, 74000], [72, 75000], [73, 76000], [74, 77000], [75, 78000], [76, 79000], [77, 80000], [78, 81000], [79, 82000], [80, 83000], [81, 84000], [82, 85000], [83, 86000], [84, 87000], [85, 88000], [86, 89000], [87, 90000], [88, 91000], [89, 92000], [90, 93000], [91, 94000], [92, 95000], [93, 96000], [94, 97000], [95, 98000], [96, 99000], [97, 100000], [98, 101000], [99, 102000]]) == [3000, 4001, 5002, 6003, 7004, 8005, 9006, 10007, 11003, 12009, 13004, 14011, 15005, 16013, 17006, 18015, 19007, 20017, 21018, 22009, 23004, 24021, 25022, 26011, 27005, 28025, 29010, 30013, 31006, 32029, 33014, 34015, 35007, 36016, 37034, 38008, 39036, 40037, 41018, 42039, 43004, 44020, 45026, 46010, 47028, 48045, 49022, 50047, 51005, 52024, 53050, 54012, 55020, 56053, 57010, 58023, 59006, 60028, 61042, 62014, 63012, 64061, 65014, 66031, 67064, 68065, 69066, 70007, 71033, 72034, 73070, 74071, 75003, 76017, 77036, 78075, 79060, 80077, 81018, 82039, 83048, 84081, 85082, 86009, 87025, 88042, 89086, 90055, 91004, 92021, 93028, 94059, 95044, 96093, 97022, 98047, 99032, 100033, 101098, 102011]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9],queries = [[0, 100], [1, 200], [2, 300], [3, 400], [4, 500], [5, 600], [6, 700], [7, 800], [8, 900], [9, 1000], [10, 1100], [11, 1200], [12, 1300], [13, 1400], [14, 1500], [15, 1600], [16, 1700], [17, 1800], [18, 1900], [19, 2000]]) == [100, 201, 302, 403, 501, 605, 702, 807, 908, 1004, 1101, 1211, 1304, 1406, 1502, 1615, 1716, 1817, 1918, 2009]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49],queries = [[0, 2000], [1, 3000], [2, 4000], [3, 5000], [4, 6000], [5, 7000], [6, 8000], [7, 9000], [8, 10000], [9, 11000], [10, 12000], [11, 13000], [12, 14000], [13, 15000], [14, 16000], [15, 17000], [16, 18000], [17, 19000], [18, 20000], [19, 21000], [20, 22000], [21, 23000], [22, 24000], [23, 25000], [24, 26000], [25, 27000], [26, 28000], [27, 29000], [28, 30000], [29, 31000], [30, 32000], [31, 33000], [32, 34000], [33, 35000], [34, 36000], [35, 37000], [36, 38000], [37, 39000], [38, 40000], [39, 41000], [40, 42000], [41, 43000], [42, 44000], [43, 45000], [44, 46000], [45, 47000], [46, 48000], [47, 49000], [48, 50000], [49, 51000]]) == [2000, 3001, 4002, 5003, 6004, 7005, 8006, 9007, 10008, 11007, 12010, 13007, 14012, 15007, 16014, 17007, 18015, 19007, 20018, 21019, 22015, 23007, 24022, 25023, 26015, 27007, 28026, 29023, 30015, 31007, 32030, 33023, 34032, 35007, 36031, 37035, 38015, 39037, 40038, 41023, 42040, 43007, 44031, 45039, 46015, 47039, 48046, 49023, 50047, 51007]\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30],queries = [[0, 50], [1, 100], [2, 150], [3, 200], [4, 250], [5, 300], [6, 350], [7, 400], [8, 450], [9, 500], [10, 550], [11, 600], [12, 650], [13, 700], [14, 750], [15, 800], [16, 850], [17, 900], [18, 950], [19, 1000], [20, 1050], [21, 1100], [22, 1150], [23, 1200], [24, 1250], [25, 1300], [26, 1350], [27, 1400], [28, 1450], [29, 1500], [30, 1550], [31, 1600], [32, 1650], [33, 1700], [34, 1750], [35, 1800], [36, 1850], [37, 1900], [38, 1950], [39, 2000], [40, 2050], [41, 2100], [42, 2150], [43, 2200], [44, 2250], [45, 2300], [46, 2350], [47, 2400], [48, 2450], [49, 2500]]) == [50, 101, 150, 203, 254, 302, 350, 407, 458, 509, 556, 605, 655, 702, 750, 815, 853, 917, 958, 1019, 1054, 1113, 1151, 1211, 1274, 1304, 1372, 1406, 1462, 1502, 1552, 1631, 1661, 1716, 1780, 1835, 1851, 1918, 1976, 2039, 2090, 2109, 2162, 2227, 2278, 2301, 2360, 2423, 2466, 2549]\n assert candidate(parents = [-1, 0, 0, 0, 0, 0, 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],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], [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]]) == [1, 3, 3, 7, 5, 6, 7, 15, 9, 11, 11, 14, 15, 14, 15, 31, 18, 18, 19, 23, 22, 22, 23, 28, 29, 30, 30, 28, 29, 30, 31, 63, 39, 36, 37, 37, 37, 39, 39, 47, 46, 43, 43, 45, 45, 47, 47, 57, 56, 59, 58]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],queries = [[0, 1000], [1, 2000], [2, 3000], [3, 4000], [4, 5000], [5, 6000], [6, 7000], [7, 8000], [8, 9000], [9, 10000], [10, 11000], [11, 12000], [12, 13000], [13, 14000], [14, 15000]]) == [1000, 2001, 3002, 4003, 5004, 6005, 7006, 8007, 9007, 10009, 11007, 12011, 13007, 14013, 15007]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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],queries = [[0, 3000], [1, 4000], [2, 5000], [3, 6000], [4, 7000], [5, 8000], [6, 9000], [7, 10000], [8, 11000], [9, 12000], [10, 13000], [11, 14000], [12, 15000], [13, 16000], [14, 17000], [15, 18000], [16, 19000], [17, 20000], [18, 21000], [19, 22000], [20, 23000], [21, 24000], [22, 25000], [23, 26000], [24, 27000], [25, 28000], [26, 29000], [27, 30000], [28, 31000], [29, 32000], [30, 33000], [31, 34000], [32, 35000], [33, 36000], [34, 37000], [35, 38000], [36, 39000], [37, 40000], [38, 41000], [39, 42000], [40, 43000], [41, 44000], [42, 45000], [43, 46000], [44, 47000], [45, 48000], [46, 49000], [47, 50000], [48, 51000], [49, 52000], [50, 53000], [51, 54000], [52, 55000], [53, 56000], [54, 57000], [55, 58000], [56, 59000], [57, 60000], [58, 61000], [59, 62000], [60, 63000], [61, 64000], [62, 65000], [63, 66000], [64, 67000], [65, 68000], [66, 69000], [67, 70000], [68, 71000], [69, 72000], [70, 73000], [71, 74000], [72, 75000], [73, 76000], [74, 77000], [75, 78000], [76, 79000], [77, 80000], [78, 81000], [79, 82000], [80, 83000], [81, 84000], [82, 85000], [83, 86000], [84, 87000], [85, 88000], [86, 89000], [87, 90000], [88, 91000], [89, 92000], [90, 93000], [91, 94000], [92, 95000], [93, 96000], [94, 97000], [95, 98000], [96, 99000], [97, 100000], [98, 101000], [99, 102000]]) == [3000, 4001, 5002, 6003, 7004, 8005, 9006, 10007, 11007, 12009, 13007, 14011, 15007, 16013, 17007, 18015, 19007, 20017, 21018, 22015, 23007, 24021, 25022, 26015, 27007, 28025, 29023, 30015, 31007, 32029, 33023, 34015, 35007, 36031, 37034, 38015, 39036, 40037, 41023, 42039, 43007, 44031, 45039, 46015, 47039, 48045, 49023, 50047, 51007, 52031, 53050, 54015, 55039, 56053, 57023, 58047, 59007, 60031, 61055, 62015, 63039, 64061, 65023, 66047, 67064, 68065, 69066, 70015, 71039, 72063, 73070, 74071, 75007, 76031, 77055, 78075, 79071, 80077, 81023, 82047, 83071, 84081, 85082, 86015, 87039, 88063, 89086, 90079, 91007, 92031, 93055, 94079, 95071, 96093, 97023, 98047, 99071, 100095, 101098, 102015]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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],queries = [[0, 100000], [1, 100001], [2, 100002], [3, 100003], [4, 100004], [5, 100005], [6, 100006], [7, 100007], [8, 100008], [9, 100009], [10, 100010], [11, 100011], [12, 100012], [13, 100013], [14, 100014], [15, 100015], [16, 100016], [17, 100017], [18, 100018], [19, 100019], [20, 100020], [21, 100021], [22, 100022], [23, 100023], [24, 100024], [25, 100025], [26, 100026], [27, 100027], [28, 100028], [29, 100029], [30, 100030], [31, 100031], [32, 100032], [33, 100033], [34, 100034], [35, 100035], [36, 100036], [37, 100037], [38, 100038], [39, 100039], [40, 100040], [41, 100041], [42, 100042], [43, 100043], [44, 100044], [45, 100045], [46, 100046], [47, 100047], [48, 100048], [49, 100049], [50, 100050], [51, 100051], [52, 100052], [53, 100053], [54, 100054], [55, 100055], [56, 100056], [57, 100057], [58, 100058], [59, 100059], [60, 100060], [61, 100061], [62, 100062], [63, 100063], [64, 100064], [65, 100065], [66, 100066], [67, 100067], [68, 100068], [69, 100069], [70, 100070], [71, 100071], [72, 100072], [73, 100073], [74, 100074], [75, 100075], [76, 100076], [77, 100077], [78, 100078], [79, 100079], [80, 100080], [81, 100081], [82, 100082], [83, 100083], [84, 100084], [85, 100085], [86, 100086], [87, 100087], [88, 100088], [89, 100089], [90, 100090], [91, 100091], [92, 100092], [93, 100093], [94, 100094], [95, 100095], [96, 100096], [97, 100097], [98, 100098], [99, 100099]]) == [100000, 100001, 100003, 100003, 100007, 100007, 100007, 100007, 100015, 100015, 100015, 100015, 100015, 100015, 100015, 100015, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100031, 100064, 100065, 100067, 100067, 100071, 100071, 100071, 100071, 100079, 100079, 100079, 100079, 100079, 100079, 100079, 100079, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100095, 100192, 100193, 100195, 100195]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],queries = [[0, 100000], [1, 50000], [2, 25000], [3, 12500], [4, 6250], [5, 3125], [6, 1562], [7, 781], [8, 390], [9, 195], [10, 97], [11, 48], [12, 24], [13, 12], [14, 6], [15, 3], [16, 1], [17, 513], [18, 257], [19, 129], [20, 65], [21, 32], [22, 16], [23, 8], [24, 4], [25, 2], [26, 1], [27, 513], [28, 257], [29, 129], [30, 65]]) == [100000, 50001, 25002, 12503, 6254, 3127, 1567, 783, 398, 203, 107, 59, 31, 15, 15, 15, 17, 529, 275, 147, 85, 53, 31, 31, 28, 27, 27, 539, 285, 157, 95]\n assert candidate(parents = [-1, 0, 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, 14],queries = [[0, 2000], [1, 2001], [2, 2002], [3, 2003], [4, 2004], [5, 2005], [6, 2006], [7, 2007], [8, 2008], [9, 2009], [10, 2010], [11, 2011], [12, 2012], [13, 2013], [14, 2014], [15, 2015], [16, 2016], [17, 2017], [18, 2018], [19, 2019], [20, 2020], [21, 2021], [22, 2022], [23, 2023], [24, 2024], [25, 2025], [26, 2026], [27, 2027], [28, 2028], [29, 2029]]) == [2000, 2001, 2002, 2003, 2006, 2007, 2007, 2007, 2012, 2013, 2015, 2014, 2015, 2014, 2015, 2015, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032, 2032]\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],queries = [[0, 101], [1, 202], [2, 303], [3, 404], [4, 505], [5, 606], [6, 707], [7, 808], [8, 909], [9, 1010], [10, 1111], [11, 1212], [12, 1313], [13, 1414], [14, 1515], [15, 1616], [16, 1717], [17, 1818]]) == [101, 203, 303, 407, 509, 606, 709, 815, 911, 1019, 1117, 1214, 1325, 1419, 1516, 1631, 1725, 1822]\n assert candidate(parents = [-1, 0, 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],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], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30]]) == [1, 3, 3, 7, 5, 7, 7, 15, 11, 10, 11, 15, 14, 15, 15, 31, 20, 23, 22, 21, 21, 23, 23, 31, 30, 26, 27, 30, 31, 30]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4],queries = [[0, 15], [1, 30], [2, 45], [3, 60], [4, 75], [5, 90], [6, 105], [7, 120], [8, 135], [9, 150]]) == [15, 31, 47, 63, 79, 95, 111, 127, 143, 159]\n assert candidate(parents = [-1, 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, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14],queries = [[0, 65535], [1, 65534], [2, 65533], [3, 65532], [4, 65531], [5, 65530], [6, 65529], [7, 65528], [8, 65527], [9, 65526], [10, 65525], [11, 65524], [12, 65523], [13, 65522], [14, 65521], [15, 65520], [16, 65519], [17, 65518], [18, 65517], [19, 65516], [20, 65515], [21, 65514], [22, 65513], [23, 65512], [24, 65511], [25, 65510], [26, 65509], [27, 65508], [28, 65507], [29, 65506], [30, 65505], [31, 65504], [32, 65503], [33, 65502], [34, 65501], [35, 65500], [36, 65499], [37, 65498], [38, 65497], [39, 65496], [40, 65495], [41, 65494], [42, 65493], [43, 65492], [44, 65491], [45, 65490], [46, 65489], [47, 65488], [48, 65487], [49, 65486]]) == [65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535]\n assert candidate(parents = [-1, 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],queries = [[0, 65536], [1, 32768], [2, 16384], [3, 8192], [4, 4096], [5, 2048], [6, 1024], [7, 512], [8, 256], [9, 128], [10, 64], [11, 32], [12, 16], [13, 8], [14, 4], [15, 2], [14, 1], [13, 3], [12, 7], [11, 15], [10, 31], [9, 63], [8, 127], [7, 255], [6, 511], [5, 1023], [4, 2047], [3, 4095], [2, 8191], [1, 16383], [0, 32767]]) == [65536, 32769, 16386, 8195, 4100, 2053, 1030, 519, 264, 137, 74, 43, 28, 14, 10, 13, 15, 14, 11, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]\n assert candidate(parents = [-1, 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],queries = [[15, 65535], [14, 32767], [13, 16383], [12, 8191], [11, 4095], [10, 2047], [9, 1023], [8, 511], [7, 255], [6, 127], [5, 63], [4, 31], [3, 15], [2, 7], [1, 3], [0, 1]]) == [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]\n", "comparison": "exact"}, "public_tests": ["[-1,0,1,1]\n[[0,2],[3,2],[2,5]]", "[3,7,-1,2,0,7,0,2]\n[[4,6],[1,15],[0,5]]"], "hints": ["How can we use a trie to store all the XOR values in the path from a node to the root?", "How can we dynamically add the XOR values with a DFS search?"], "metadata": {"canonical_parameter_names": ["parents", "queries"], "leetcode_dataset_entry_point": "Solution().maxGeneticDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:40+00:00", "tests_total": 59, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "bit-manipulation", "depth-first-search", "trie"]}, "language": "php", "interface": {"raw_signature": "function maxGeneticDifference($parents, $queries) {", "container": "Solution", "callable": "maxGeneticDifference", "parameters": [{"name": "parents", "type": "Integer[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1941, "task_id": "check-if-all-characters-have-equal-number-of-occurrences", "difficulty": "Easy", "problem_description": "Given a string s, return true if s is a good string, or false otherwise.\n\nA string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).\n\nExample 1:\n\nInput: s = \"abacbc\"\nOutput: true\nExplanation: The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.\n\nExample 2:\n\nInput: s = \"aaabb\"\nOutput: false\nExplanation: The characters that appear in s are 'a' and 'b'.\n'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbccc\") == False\n assert candidate(s = \"abacbc\") == True\n assert candidate(s = \"abcabcabc\") == True\n assert candidate(s = \"qqqq\") == True\n assert candidate(s = \"aabbcc\") == True\n assert candidate(s = \"zzzzzzzzzz\") == True\n assert candidate(s = \"aabbc\") == False\n assert candidate(s = \"a\") == True\n assert candidate(s = \"abc\") == True\n assert candidate(s = \"aabb\") == True\n assert candidate(s = \"aabbccddeeff\") == True\n assert candidate(s = \"abcdabcd\") == True\n assert candidate(s = \"zzz\") == True\n assert candidate(s = \"xyz\") == True\n assert candidate(s = \"aaabb\") == False\n assert candidate(s = \"hello\") == False\n assert candidate(s = \"thisisnotagoodstring\") == False\n assert candidate(s = \"aaaabbbbccccdddd\") == True\n assert candidate(s = \"almostgoodbutoneextrab\") == False\n assert candidate(s = \"mnopqrstuvwxyzz\") == False\n assert candidate(s = \"uniquecharactersabcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(s = \"qwertyuioplkjhgfdsazxcvbnm\") == True\n assert candidate(s = \"kjhgfdsazxcvbnmlpoiuytrewq\") == True\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == True\n assert candidate(s = \"llllkkkkjjjjiiiihhhhggggffffeeeeeeee\") == False\n assert candidate(s = \"repeatedcharsrepeatedcharsrepeatedchars\") == False\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz\") == False\n assert candidate(s = \"samefrequencyforallcharacters\") == False\n assert candidate(s = \"lmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmnolmno\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == False\n assert candidate(s = \"mnopqrsmnopqrsmnopqrsmnopqrsmnopqrs\") == True\n assert candidate(s = \"abcdefabcdefabcdef\") == True\n assert candidate(s = \"abacadaeafagahaibiciidieifigihiiijijikikililimimioinioipoipiqiririsititiuiujujukukululumiumiujujukvkvkwlwlxmxmylynzozp\") == False\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza\") == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzqqqq\") == False\n assert candidate(s = \"abracadabra\") == False\n assert candidate(s = \"mnopqrstuvwxymnopqrstuvwxymnopqrstuvwxymnopqrstuvwxyn\") == False\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == True\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop\") == True\n assert candidate(s = \"abcdefabcdef\") == True\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == True\n assert candidate(s = \"almostgoodbutoneextraa\") == False\n assert candidate(s = \"abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop\") == True\n assert candidate(s = \"jjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzzaaaaaa\") == False\n assert candidate(s = \"zzzzzyyyyxxxwwvvuuttssrrqqlloommnnppekkaaiioouuyy\") == False\n assert candidate(s = \"racecar\") == False\n assert candidate(s = \"almostgoodbutoneextrac\") == False\n assert candidate(s = \"xyzxyzxyz\") == True\n assert candidate(s = \"qwerqwerqwer\") == True\n assert candidate(s = \"abababababababab\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\") == True\n assert candidate(s = \"ppppppqqqqqrrrrrssssstttttuuuuuvvvvvwwwwwooooo\") == False\n assert candidate(s = \"ababababc\") == False\n assert candidate(s = \"mmnnnmmmnnnmmmnnnmmmnnnmmmnnnmmmnnnmmmnnnmm\") == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == False\n assert candidate(s = \"pqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrspqrs\") == True\n assert candidate(s = \"mmnnooppqqrrssttuuvvwwxxyyzzqqwweerrttyyuuiihhggffeeddccba\") == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy\") == True\n assert candidate(s = \"ppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz\") == True\n assert candidate(s = \"mnopmnopmnopmnopmnopmnopmnopmnop\") == True\n assert candidate(s = \"xyzzzzzyzx\") == False\n assert candidate(s = \"abacabadabacabad\") == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzy\") == True\n assert candidate(s = \"abcdefghijklmnop\") == True\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzz\") == False\n assert candidate(s = \"zzzyyyxxxwwwwvvvvuuuuuuuuutttttttsssssssrrrrrrqqqqpppooooonnnnmmmmllllkkkkjjjjiiiihhhhhgggggfffffeeeeeeeee\") == False\n assert candidate(s = \"mnopqrmpqrno\") == True\n assert candidate(s = \"qqwweerrttyyuuuiooppppllkkiijjhgffeeddccba\") == False\n assert candidate(s = \"qrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == False\n assert candidate(s = \"mississippi\") == False\n assert candidate(s = \"xyzzxyzzxyzzxyzz\") == False\n assert candidate(s = \"oneonetwoonetwothree\") == False\n assert candidate(s = \"zxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnmzxcvbnm\") == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(s = \"xyzxyzxyzxyz\") == True\n assert candidate(s = \"zzzzyyyyxxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == False\n assert candidate(s = \"qqqqwweerrrrtttyyyy\") == False\n assert candidate(s = \"abcdabcdabcdabcd\") == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == False\n assert candidate(s = \"almostgoodbutoneextrad\") == False\n assert candidate(s = \"almostgoodbutoneextrae\") == False\n assert candidate(s = \"programming\") == False\n assert candidate(s = \"equalfrequenciesequalfrequencies\") == False\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabc\") == False\n assert candidate(s = \"almostgoodbutoneextraf\") == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghij\") == False\n", "comparison": "exact"}, "public_tests": ["\"abacbc\"", "\"aaabb\""], "hints": ["Build a dictionary containing the frequency of each character appearing in s", "Check if all values in the dictionary are the same."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().areOccurrencesEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:44+00:00", "tests_total": 91, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function areOccurrencesEqual($s) {", "container": "Solution", "callable": "areOccurrencesEqual", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1942, "task_id": "the-number-of-the-smallest-unoccupied-chair", "difficulty": "Medium", "problem_description": "There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with the smallest number.\n\n- For example, if chairs 0, 1, and 5 are occupied when a friend comes, they will sit on chair number 2.\n\nWhen a friend leaves the party, their chair becomes unoccupied at the moment they leave. If another friend arrives at that same moment, they can sit in that chair.\n\nYou are given a 0-indexed 2D integer array times where times[i] = [arrival_i, leaving_i], indicating the arrival and leaving times of the i^th friend respectively, and an integer targetFriend. All arrival times are distinct.\n\nReturn the chair number that the friend numbered targetFriend will sit on.\n\nExample 1:\n\nInput: times = [[1,4],[2,3],[4,6]], targetFriend = 1\nOutput: 1\nExplanation:\n- Friend 0 arrives at time 1 and sits on chair 0.\n- Friend 1 arrives at time 2 and sits on chair 1.\n- Friend 1 leaves at time 3 and chair 1 becomes empty.\n- Friend 0 leaves at time 4 and chair 0 becomes empty.\n- Friend 2 arrives at time 4 and sits on chair 0.\nSince friend 1 sat on chair 1, we return 1.\n\nExample 2:\n\nInput: times = [[3,10],[1,5],[2,6]], targetFriend = 0\nOutput: 2\nExplanation:\n- Friend 1 arrives at time 1 and sits on chair 0.\n- Friend 2 arrives at time 2 and sits on chair 1.\n- Friend 0 arrives at time 3 and sits on chair 2.\n- Friend 1 leaves at time 5 and chair 0 becomes empty.\n- Friend 2 leaves at time 6 and chair 1 becomes empty.\n- Friend 0 leaves at time 10 and chair 2 becomes empty.\nSince friend 0 sat on chair 2, we return 2.\n\nConstraints:\n\n- n == times.length\n- 2 <= n <= 10^4\n- times[i].length == 2\n- 1 <= arrival_i < leaving_i <= 10^5\n- 0 <= targetFriend <= n - 1\n- Each arrival_i time is distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(times = [[5, 10], [1, 3], [2, 6], [7, 8]],targetFriend = 1) == 0\n assert candidate(times = [[5, 10], [1, 2], [3, 8]],targetFriend = 2) == 0\n assert candidate(times = [[2, 7], [7, 9], [1, 5]],targetFriend = 2) == 0\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5]],targetFriend = 3) == 0\n assert candidate(times = [[8, 12], [1, 6], [3, 5], [9, 10]],targetFriend = 2) == 1\n assert candidate(times = [[2, 5], [3, 7], [4, 9], [5, 10]],targetFriend = 2) == 2\n assert candidate(times = [[5, 15], [1, 20], [10, 25]],targetFriend = 2) == 2\n assert candidate(times = [[10, 20], [20, 30], [15, 25], [5, 15]],targetFriend = 2) == 0\n assert candidate(times = [[2, 5], [3, 9], [4, 7], [5, 8]],targetFriend = 2) == 2\n assert candidate(times = [[5, 10], [1, 3], [4, 8], [6, 9]],targetFriend = 3) == 2\n assert candidate(times = [[10, 20], [5, 10], [15, 25]],targetFriend = 1) == 0\n assert candidate(times = [[1, 4], [2, 3], [4, 6]],targetFriend = 1) == 1\n assert candidate(times = [[5, 10], [1, 3], [4, 6], [6, 7]],targetFriend = 1) == 0\n assert candidate(times = [[1, 3], [2, 5], [3, 6], [4, 7]],targetFriend = 2) == 0\n assert candidate(times = [[2, 5], [1, 3], [6, 7], [4, 8]],targetFriend = 1) == 0\n assert candidate(times = [[3, 10], [1, 5], [2, 6]],targetFriend = 0) == 2\n assert candidate(times = [[1, 2], [2, 5], [4, 7], [7, 9]],targetFriend = 0) == 0\n assert candidate(times = [[3, 4], [1, 5], [2, 6], [5, 7], [4, 8], [6, 9]],targetFriend = 3) == 0\n assert candidate(times = [[5, 8], [12, 15], [10, 14], [20, 25], [1, 4], [16, 18], [6, 9], [19, 22], [3, 7], [11, 13]],targetFriend = 8) == 1\n assert candidate(times = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22], [23, 24], [25, 26]],targetFriend = 6) == 0\n assert candidate(times = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100], [11, 110], [12, 120]],targetFriend = 11) == 10\n assert candidate(times = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92]],targetFriend = 8) == 8\n assert candidate(times = [[1, 10], [2, 5], [3, 7], [8, 12], [6, 9], [11, 13]],targetFriend = 5) == 0\n assert candidate(times = [[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]],targetFriend = 7) == 7\n assert candidate(times = [[10, 20], [5, 15], [1, 10], [16, 30], [21, 40]],targetFriend = 3) == 1\n assert candidate(times = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14]],targetFriend = 2) == 2\n assert candidate(times = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]],targetFriend = 6) == 2\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],targetFriend = 8) == 0\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],targetFriend = 5) == 0\n assert candidate(times = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22], [23, 24], [25, 26], [27, 28]],targetFriend = 7) == 0\n assert candidate(times = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],targetFriend = 0) == 0\n assert candidate(times = [[5, 10], [1, 6], [7, 12], [15, 20], [2, 8]],targetFriend = 4) == 1\n assert candidate(times = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],targetFriend = 3) == 3\n assert candidate(times = [[3, 20], [1, 5], [7, 15], [10, 18], [2, 8], [13, 17]],targetFriend = 3) == 1\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],targetFriend = 4) == 0\n assert candidate(times = [[1, 2], [3, 4], [5, 6], [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]],targetFriend = 22) == 0\n assert candidate(times = [[1, 5], [2, 3], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11]],targetFriend = 5) == 1\n assert candidate(times = [[10, 20], [1, 6], [3, 11], [7, 14], [15, 25]],targetFriend = 4) == 0\n assert candidate(times = [[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]],targetFriend = 15) == 15\n assert candidate(times = [[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]],targetFriend = 10) == 10\n assert candidate(times = [[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]],targetFriend = 6) == 0\n assert candidate(times = [[1, 50], [2, 49], [3, 48], [4, 47], [5, 46], [6, 45], [7, 44], [8, 43], [9, 42], [10, 41]],targetFriend = 9) == 9\n assert candidate(times = [[1, 10], [2, 5], [3, 4], [6, 9], [7, 11]],targetFriend = 4) == 2\n assert candidate(times = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]],targetFriend = 9) == 0\n assert candidate(times = [[1, 10], [2, 12], [3, 14], [4, 16], [5, 18], [6, 20]],targetFriend = 2) == 2\n assert candidate(times = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992], [10, 991]],targetFriend = 9) == 9\n assert candidate(times = [[3, 8], [1, 5], [2, 6], [7, 10], [4, 9], [6, 12], [8, 15]],targetFriend = 2) == 1\n assert candidate(times = [[1, 2], [3, 4], [5, 6], [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]],targetFriend = 19) == 0\n assert candidate(times = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90]],targetFriend = 4) == 0\n assert candidate(times = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12], [11, 13], [12, 14]],targetFriend = 10) == 0\n assert candidate(times = [[10, 20], [5, 15], [1, 8], [21, 25], [11, 18]],targetFriend = 2) == 0\n assert candidate(times = [[2, 4], [6, 8], [10, 12], [1, 3], [5, 7], [9, 11]],targetFriend = 0) == 1\n assert candidate(times = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],targetFriend = 5) == 0\n assert candidate(times = [[1, 10], [2, 5], [6, 12], [3, 9], [7, 15]],targetFriend = 2) == 1\n assert candidate(times = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95]],targetFriend = 5) == 5\n assert candidate(times = [[1, 5], [2, 3], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15]],targetFriend = 7) == 2\n assert candidate(times = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]],targetFriend = 5) == 2\n assert candidate(times = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40]],targetFriend = 5) == 0\n assert candidate(times = [[1, 30], [2, 25], [3, 20], [4, 15], [5, 10], [6, 28], [7, 24], [8, 22], [9, 29], [10, 18], [11, 21], [12, 27], [13, 23], [14, 26], [15, 19], [16, 17]],targetFriend = 4) == 4\n assert candidate(times = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995], [7, 9994], [8, 9993], [9, 9992], [10, 9991]],targetFriend = 9) == 9\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],targetFriend = 0) == 0\n assert candidate(times = [[10, 20], [30, 40], [20, 30], [5, 15], [45, 55], [50, 60]],targetFriend = 4) == 0\n assert candidate(times = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],targetFriend = 9) == 9\n assert candidate(times = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]],targetFriend = 9) == 1\n assert candidate(times = [[1, 500], [2, 499], [3, 498], [4, 497], [5, 496], [6, 495], [7, 494], [8, 493], [9, 492], [10, 491], [11, 490], [12, 489], [13, 488], [14, 487], [15, 486]],targetFriend = 13) == 13\n assert candidate(times = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80]],targetFriend = 3) == 0\n assert candidate(times = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110]],targetFriend = 4) == 0\n assert candidate(times = [[10, 30], [20, 40], [30, 50], [40, 60], [50, 70], [60, 80], [70, 90], [80, 100], [90, 110], [100, 120], [110, 130], [120, 140], [130, 150], [140, 160], [150, 170], [160, 180], [170, 190], [180, 200], [190, 210], [200, 220]],targetFriend = 9) == 1\n assert candidate(times = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50]],targetFriend = 0) == 0\n assert candidate(times = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40]],targetFriend = 3) == 0\n assert candidate(times = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55]],targetFriend = 8) == 0\n assert candidate(times = [[1, 100], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100]],targetFriend = 5) == 5\n assert candidate(times = [[1, 30], [2, 29], [3, 28], [4, 27], [5, 26], [6, 25], [7, 24], [8, 23], [9, 22], [10, 21]],targetFriend = 5) == 5\n assert candidate(times = [[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11]],targetFriend = 6) == 6\n assert candidate(times = [[1, 10000], [2, 9999], [3, 9998], [4, 9997], [5, 9996], [6, 9995], [7, 9994]],targetFriend = 6) == 6\n assert candidate(times = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]],targetFriend = 9) == 0\n assert candidate(times = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]],targetFriend = 5) == 0\n assert candidate(times = [[1, 10], [11, 20], [2, 19], [12, 18], [3, 17]],targetFriend = 3) == 3\n assert candidate(times = [[1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12]],targetFriend = 4) == 4\n assert candidate(times = [[3, 8], [5, 10], [1, 4], [7, 12], [9, 15]],targetFriend = 3) == 2\n assert candidate(times = [[1, 10], [2, 12], [3, 14], [4, 16], [5, 18], [6, 20], [7, 22], [8, 24], [9, 26], [10, 28]],targetFriend = 9) == 0\n assert candidate(times = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90]],targetFriend = 5) == 0\n assert candidate(times = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],targetFriend = 5) == 0\n assert candidate(times = [[2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19], [20, 21]],targetFriend = 9) == 0\n assert candidate(times = [[1, 5], [1, 4], [1, 3], [1, 2], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7]],targetFriend = 8) == 0\n assert candidate(times = [[10, 25], [20, 30], [5, 15], [15, 20], [1, 10], [25, 35], [30, 40], [5, 10], [15, 20]],targetFriend = 5) == 0\n assert candidate(times = [[1, 10], [2, 5], [3, 6], [7, 12], [8, 9], [4, 11]],targetFriend = 2) == 2\n assert candidate(times = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],targetFriend = 8) == 0\n assert candidate(times = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]],targetFriend = 7) == 3\n assert candidate(times = [[5, 10], [1, 6], [11, 16], [21, 26], [10, 15], [6, 11], [16, 21], [26, 31], [2, 7], [7, 12]],targetFriend = 8) == 1\n assert candidate(times = [[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11], [21, 40], [22, 39], [23, 38], [24, 37], [25, 36], [26, 35], [27, 34], [28, 33], [29, 32], [30, 31]],targetFriend = 15) == 5\n assert candidate(times = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60]],targetFriend = 5) == 0\n assert candidate(times = [[5, 10], [10, 20], [15, 25], [20, 30], [25, 35], [30, 40]],targetFriend = 3) == 0\n assert candidate(times = [[5, 10], [1, 2], [3, 4], [6, 7], [8, 9], [10, 11]],targetFriend = 1) == 0\n assert candidate(times = [[10, 20], [5, 15], [1, 11], [25, 35], [30, 40]],targetFriend = 4) == 1\n", "comparison": "exact"}, "public_tests": ["[[1,4],[2,3],[4,6]]\n1", "[[3,10],[1,5],[2,6]]\n0"], "hints": ["Sort times by arrival time.", "for each arrival_i find the smallest unoccupied chair and mark it as occupied until leaving_i."], "metadata": {"canonical_parameter_names": ["times", "targetFriend"], "leetcode_dataset_entry_point": "Solution().smallestChair", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:47+00:00", "tests_total": 101, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function smallestChair($times, $targetFriend) {", "container": "Solution", "callable": "smallestChair", "parameters": [{"name": "times", "type": "Integer[][]"}, {"name": "targetFriend", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1943, "task_id": "describe-the-painting", "difficulty": "Medium", "problem_description": "There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer array segments, where segments[i] = [start_i, end_i, color_i] represents the half-closed segment [start_i, end_i) with color_i as the color.\n\nThe colors in the overlapping segments of the painting were mixed when it was painted. When two or more colors mix, they form a new color that can be represented as a set of mixed colors.\n\n- For example, if colors 2, 4, and 6 are mixed, then the resulting mixed color is {2,4,6}.\n\nFor the sake of simplicity, you should only output the sum of the elements in the set rather than the full set.\n\nYou want to describe the painting with the minimum number of non-overlapping half-closed segments of these mixed colors. These segments can be represented by the 2D array painting where painting[j] = [left_j, right_j, mix_j] describes a half-closed segment [left_j, right_j) with the mixed color sum of mix_j.\n\n- For example, the painting created with segments = [[1,4,5],[1,7,7]] can be described by painting = [[1,4,12],[4,7,7]] because:\n - [1,4) is colored {5,7} (with a sum of 12) from both the first and second segments.\n - [4,7) is colored {7} from only the second segment.\n\nReturn the 2D array painting describing the finished painting (excluding any parts that are not painted). You may return the segments in any order.\n\nA half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.\n\nExample 1:\n\nInput: segments = [[1,4,5],[4,7,7],[1,7,9]]\nOutput: [[1,4,14],[4,7,16]]\nExplanation: The painting can be described as follows:\n- [1,4) is colored {5,9} (with a sum of 14) from the first and third segments.\n- [4,7) is colored {7,9} (with a sum of 16) from the second and third segments.\n\nExample 2:\n\nInput: segments = [[1,7,9],[6,8,15],[8,10,7]]\nOutput: [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\nExplanation: The painting can be described as follows:\n- [1,6) is colored 9 from the first segment.\n- [6,7) is colored {9,15} (with a sum of 24) from the first and second segments.\n- [7,8) is colored 15 from the second segment.\n- [8,10) is colored 7 from the third segment.\n\nExample 3:\n\nInput: segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]\nOutput: [[1,4,12],[4,7,12]]\nExplanation: The painting can be described as follows:\n- [1,4) is colored {5,7} (with a sum of 12) from the first and second segments.\n- [4,7) is colored {1,11} (with a sum of 12) from the third and fourth segments.\nNote that returning a single segment [1,7) is incorrect because the mixed color sets are different.\n\nConstraints:\n\n- 1 <= segments.length <= 2 * 10^4\n- segments[i].length == 3\n- 1 <= start_i < end_i <= 10^5\n- 1 <= color_i <= 10^9\n- Each color_i is distinct.\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(segments=[[10, 20, 5], [15, 25, 3], [12, 18, 8]]), [[10, 12, 5], [12, 15, 13], [15, 18, 16], [18, 20, 8], [20, 25, 3]])\n assert answers_match(candidate(segments=[[1, 10, 100], [5, 15, 200], [12, 20, 300]]), [[1, 5, 100], [5, 10, 300], [10, 12, 200], [12, 15, 500], [15, 20, 300]])\n assert answers_match(candidate(segments=[[2, 5, 10], [3, 8, 20], [5, 6, 30]]), [[2, 3, 10], [3, 5, 30], [5, 6, 50], [6, 8, 20]])\n assert answers_match(candidate(segments=[[2, 5, 10], [3, 8, 20], [6, 10, 30]]), [[2, 3, 10], [3, 5, 30], [5, 6, 20], [6, 8, 50], [8, 10, 30]])\n assert answers_match(candidate(segments=[[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]]), [[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]])\n assert answers_match(candidate(segments=[[1, 4, 5], [1, 4, 7], [4, 7, 1], [4, 7, 11]]), [[1, 4, 12], [4, 7, 12]])\n assert answers_match(candidate(segments=[[5, 10, 1], [10, 15, 2], [15, 20, 3], [20, 25, 4]]), [[5, 10, 1], [10, 15, 2], [15, 20, 3], [20, 25, 4]])\n assert answers_match(candidate(segments=[[10, 20, 100], [15, 25, 200], [20, 30, 300]]), [[10, 15, 100], [15, 20, 300], [20, 25, 500], [25, 30, 300]])\n assert answers_match(candidate(segments=[[10, 20, 100], [20, 30, 200], [15, 25, 150]]), [[10, 15, 100], [15, 20, 250], [20, 25, 350], [25, 30, 200]])\n assert answers_match(candidate(segments=[[1, 3, 1], [3, 5, 2], [5, 7, 3], [7, 9, 4]]), [[1, 3, 1], [3, 5, 2], [5, 7, 3], [7, 9, 4]])\n assert answers_match(candidate(segments=[[1, 4, 5], [4, 7, 7], [1, 7, 9]]), [[1, 4, 14], [4, 7, 16]])\n assert answers_match(candidate(segments=[[1, 100000, 1000000000]]), [[1, 100000, 1000000000]])\n assert answers_match(candidate(segments=[[1, 7, 9], [6, 8, 15], [8, 10, 7]]), [[1, 6, 9], [6, 7, 24], [7, 8, 15], [8, 10, 7]])\n assert answers_match(candidate(segments=[[10, 15, 5], [12, 20, 15], [18, 25, 25]]), [[10, 12, 5], [12, 15, 20], [15, 18, 15], [18, 20, 40], [20, 25, 25]])\n assert answers_match(candidate(segments=[[1, 10, 5], [2, 9, 10], [3, 8, 15], [4, 7, 20]]), [[1, 2, 5], [2, 3, 15], [3, 4, 30], [4, 7, 50], [7, 8, 30], [8, 9, 15], [9, 10, 5]])\n assert answers_match(candidate(segments=[[1, 3, 1], [2, 5, 2], [3, 7, 3], [4, 8, 4], [5, 9, 5], [6, 10, 6]]), [[1, 2, 1], [2, 3, 3], [3, 4, 5], [4, 5, 9], [5, 6, 12], [6, 7, 18], [7, 8, 15], [8, 9, 11], [9, 10, 6]])\n assert answers_match(candidate(segments=[[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5]]), [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5]])\n assert answers_match(candidate(segments=[[10, 20, 500], [15, 25, 700], [20, 30, 900], [5, 25, 300], [25, 35, 800]]), [[5, 10, 300], [10, 15, 800], [15, 20, 1500], [20, 25, 1900], [25, 30, 1700], [30, 35, 800]])\n assert answers_match(candidate(segments=[[1000, 2000, 5000000], [1500, 2500, 10000000], [2000, 3000, 15000000], [1750, 2250, 12000000], [2250, 2750, 22000000], [2750, 3250, 25000000]]), [[1000, 1500, 5000000], [1500, 1750, 15000000], [1750, 2000, 27000000], [2000, 2250, 37000000], [2250, 2500, 47000000], [2500, 2750, 37000000], [2750, 3000, 40000000], [3000, 3250, 25000000]])\n assert answers_match(candidate(segments=[[1, 100, 1000000000], [50, 150, 1000000000], [100, 200, 1000000000], [150, 250, 1000000000], [200, 300, 1000000000]]), [[1, 50, 1000000000], [50, 100, 2000000000], [100, 150, 2000000000], [150, 200, 2000000000], [200, 250, 2000000000], [250, 300, 1000000000]])\n assert answers_match(candidate(segments=[[1, 4, 5], [2, 6, 7], [3, 7, 9], [4, 8, 11], [5, 9, 13], [6, 10, 15]]), [[1, 2, 5], [2, 3, 12], [3, 4, 21], [4, 5, 27], [5, 6, 40], [6, 7, 48], [7, 8, 39], [8, 9, 28], [9, 10, 15]])\n assert answers_match(candidate(segments=[[10000, 10005, 1], [10001, 10006, 2], [10002, 10007, 3], [10003, 10008, 4], [10004, 10009, 5]]), [[10000, 10001, 1], [10001, 10002, 3], [10002, 10003, 6], [10003, 10004, 10], [10004, 10005, 15], [10005, 10006, 14], [10006, 10007, 12], [10007, 10008, 9], [10008, 10009, 5]])\n assert answers_match(candidate(segments=[[5, 10, 10], [10, 15, 20], [15, 20, 30], [20, 25, 40], [25, 30, 50], [30, 35, 60], [35, 40, 70], [40, 45, 80], [45, 50, 90], [50, 55, 100]]), [[5, 10, 10], [10, 15, 20], [15, 20, 30], [20, 25, 40], [25, 30, 50], [30, 35, 60], [35, 40, 70], [40, 45, 80], [45, 50, 90], [50, 55, 100]])\n assert answers_match(candidate(segments=[[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000]]), [[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000]])\n assert answers_match(candidate(segments=[[1, 100000, 1], [50000, 100000, 2], [1, 50000, 3], [25000, 75000, 4]]), [[1, 25000, 4], [25000, 50000, 8], [50000, 75000, 7], [75000, 100000, 3]])\n assert answers_match(candidate(segments=[[1, 5, 10], [2, 4, 20], [3, 6, 30], [4, 8, 40], [5, 9, 50], [6, 10, 60], [7, 11, 70], [8, 12, 80], [9, 13, 90]]), [[1, 2, 10], [2, 3, 30], [3, 4, 60], [4, 5, 80], [5, 6, 120], [6, 7, 150], [7, 8, 220], [8, 9, 260], [9, 10, 300], [10, 11, 240], [11, 12, 170], [12, 13, 90]])\n assert answers_match(candidate(segments=[[1, 3, 1000000000], [3, 5, 1000000000], [5, 7, 1000000000], [7, 9, 1000000000], [9, 11, 1000000000], [11, 13, 1000000000], [13, 15, 1000000000], [15, 17, 1000000000], [17, 19, 1000000000], [19, 21, 1000000000]]), [[1, 3, 1000000000], [3, 5, 1000000000], [5, 7, 1000000000], [7, 9, 1000000000], [9, 11, 1000000000], [11, 13, 1000000000], [13, 15, 1000000000], [15, 17, 1000000000], [17, 19, 1000000000], [19, 21, 1000000000]])\n assert answers_match(candidate(segments=[[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]]), [[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]])\n assert answers_match(candidate(segments=[[1, 2, 1], [1, 2, 2], [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 2, 8], [1, 2, 9], [1, 2, 10]]), [[1, 2, 55]])\n assert answers_match(candidate(segments=[[5, 15, 100], [10, 20, 200], [15, 25, 300], [20, 30, 400], [25, 35, 500]]), [[5, 10, 100], [10, 15, 300], [15, 20, 500], [20, 25, 700], [25, 30, 900], [30, 35, 500]])\n assert answers_match(candidate(segments=[[1, 100000, 1000000], [50000, 100000, 900000], [1, 50000, 800000]]), [[1, 50000, 1800000], [50000, 100000, 1900000]])\n assert answers_match(candidate(segments=[[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000], [6, 7, 1000000000], [7, 8, 1000000000], [8, 9, 1000000000], [9, 10, 1000000000], [10, 11, 1000000000]]), [[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000], [6, 7, 1000000000], [7, 8, 1000000000], [8, 9, 1000000000], [9, 10, 1000000000], [10, 11, 1000000000]])\n assert answers_match(candidate(segments=[[1, 5, 1], [2, 4, 2], [3, 5, 3], [4, 6, 4], [5, 7, 5], [6, 8, 6]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 8], [5, 6, 9], [6, 7, 11], [7, 8, 6]])\n assert answers_match(candidate(segments=[[100, 200, 500], [150, 250, 1000], [200, 300, 1500], [175, 225, 1200], [225, 275, 2200], [275, 325, 2500]]), [[100, 150, 500], [150, 175, 1500], [175, 200, 2700], [200, 225, 3700], [225, 250, 4700], [250, 275, 3700], [275, 300, 4000], [300, 325, 2500]])\n assert answers_match(candidate(segments=[[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]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 6, 15], [6, 7, 21], [7, 8, 28], [8, 9, 36], [9, 10, 45], [10, 11, 55], [11, 12, 45], [12, 13, 36], [13, 14, 28], [14, 15, 21], [15, 16, 15], [16, 17, 10], [17, 18, 6], [18, 19, 3], [19, 20, 1]])\n assert answers_match(candidate(segments=[[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, 19], [20, 21, 20]]), [[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, 19], [20, 21, 20]])\n assert answers_match(candidate(segments=[[1, 5, 1], [2, 6, 2], [3, 7, 3], [4, 8, 4], [5, 9, 5], [6, 10, 6], [7, 11, 7], [8, 12, 8], [9, 13, 9], [10, 14, 10]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 6, 14], [6, 7, 18], [7, 8, 22], [8, 9, 26], [9, 10, 30], [10, 11, 34], [11, 12, 27], [12, 13, 19], [13, 14, 10]])\n assert answers_match(candidate(segments=[[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5], [1, 5, 6], [1, 5, 7], [1, 5, 8], [1, 5, 9], [1, 5, 10]]), [[1, 5, 55]])\n assert answers_match(candidate(segments=[[1, 5, 100], [2, 6, 200], [3, 7, 300], [4, 8, 400], [5, 9, 500], [6, 10, 600], [7, 11, 700], [8, 12, 800], [9, 13, 900], [10, 14, 1000]]), [[1, 2, 100], [2, 3, 300], [3, 4, 600], [4, 5, 1000], [5, 6, 1400], [6, 7, 1800], [7, 8, 2200], [8, 9, 2600], [9, 10, 3000], [10, 11, 3400], [11, 12, 2700], [12, 13, 1900], [13, 14, 1000]])\n assert answers_match(candidate(segments=[[1, 5, 1], [2, 4, 2], [3, 6, 3], [4, 8, 4], [5, 9, 5], [6, 10, 6]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 8], [5, 6, 12], [6, 8, 15], [8, 9, 11], [9, 10, 6]])\n assert answers_match(candidate(segments=[[1, 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]]), [[1, 2, 5], [2, 3, 11], [3, 4, 18], [4, 5, 26], [5, 6, 30], [6, 7, 34], [7, 8, 38], [8, 9, 42], [9, 10, 46], [10, 11, 50], [11, 12, 39], [12, 13, 27], [13, 14, 14]])\n assert answers_match(candidate(segments=[[1, 10, 5], [5, 15, 7], [10, 20, 9], [1, 20, 3]]), [[1, 5, 8], [5, 10, 15], [10, 15, 19], [15, 20, 12]])\n assert answers_match(candidate(segments=[[1, 10, 10], [2, 8, 20], [5, 15, 30], [10, 20, 40], [15, 25, 50]]), [[1, 2, 10], [2, 5, 30], [5, 8, 60], [8, 10, 40], [10, 15, 70], [15, 20, 90], [20, 25, 50]])\n assert answers_match(candidate(segments=[[1, 3, 10], [2, 4, 20], [3, 5, 30], [4, 6, 40], [5, 7, 50], [6, 8, 60], [7, 9, 70], [8, 10, 80], [9, 11, 90], [10, 12, 100]]), [[1, 2, 10], [2, 3, 30], [3, 4, 50], [4, 5, 70], [5, 6, 90], [6, 7, 110], [7, 8, 130], [8, 9, 150], [9, 10, 170], [10, 11, 190], [11, 12, 100]])\n assert answers_match(candidate(segments=[[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]]), [[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]])\n assert answers_match(candidate(segments=[[1, 10, 1000000000], [2, 9, 900000000], [3, 8, 800000000], [4, 7, 700000000], [5, 6, 600000000]]), [[1, 2, 1000000000], [2, 3, 1900000000], [3, 4, 2700000000], [4, 5, 3400000000], [5, 6, 4000000000], [6, 7, 3400000000], [7, 8, 2700000000], [8, 9, 1900000000], [9, 10, 1000000000]])\n assert answers_match(candidate(segments=[[1, 10, 5], [2, 8, 10], [3, 7, 15], [4, 6, 20]]), [[1, 2, 5], [2, 3, 15], [3, 4, 30], [4, 6, 50], [6, 7, 30], [7, 8, 15], [8, 10, 5]])\n assert answers_match(candidate(segments=[[2, 6, 7], [3, 8, 3], [5, 9, 5], [1, 4, 10], [6, 11, 2]]), [[1, 2, 10], [2, 3, 17], [3, 4, 20], [4, 5, 10], [5, 6, 15], [6, 8, 10], [8, 9, 7], [9, 11, 2]])\n assert answers_match(candidate(segments=[[5, 10, 1], [10, 15, 2], [15, 20, 3], [20, 25, 4], [25, 30, 5], [30, 35, 6], [35, 40, 7], [40, 45, 8], [45, 50, 9], [50, 55, 10]]), [[5, 10, 1], [10, 15, 2], [15, 20, 3], [20, 25, 4], [25, 30, 5], [30, 35, 6], [35, 40, 7], [40, 45, 8], [45, 50, 9], [50, 55, 10]])\n assert answers_match(candidate(segments=[[100, 200, 1], [150, 250, 2], [200, 300, 3], [250, 350, 4], [300, 400, 5], [350, 450, 6], [400, 500, 7], [450, 550, 8], [500, 600, 9], [550, 650, 10]]), [[100, 150, 1], [150, 200, 3], [200, 250, 5], [250, 300, 7], [300, 350, 9], [350, 400, 11], [400, 450, 13], [450, 500, 15], [500, 550, 17], [550, 600, 19], [600, 650, 10]])\n assert answers_match(candidate(segments=[[1, 100, 1], [50, 150, 2], [100, 200, 3], [150, 250, 4], [200, 300, 5]]), [[1, 50, 1], [50, 100, 3], [100, 150, 5], [150, 200, 7], [200, 250, 9], [250, 300, 5]])\n assert answers_match(candidate(segments=[[10, 20, 100], [15, 25, 200], [20, 30, 300], [12, 18, 150], [17, 23, 250]]), [[10, 12, 100], [12, 15, 250], [15, 17, 450], [17, 18, 700], [18, 20, 550], [20, 23, 750], [23, 25, 500], [25, 30, 300]])\n assert answers_match(candidate(segments=[[1, 3, 1000000000], [2, 4, 500000000], [3, 5, 300000000], [4, 6, 200000000], [5, 7, 100000000]]), [[1, 2, 1000000000], [2, 3, 1500000000], [3, 4, 800000000], [4, 5, 500000000], [5, 6, 300000000], [6, 7, 100000000]])\n assert answers_match(candidate(segments=[[10, 20, 5], [15, 25, 6], [20, 30, 7], [10, 30, 3], [25, 35, 8]]), [[10, 15, 8], [15, 20, 14], [20, 25, 16], [25, 30, 18], [30, 35, 8]])\n assert answers_match(candidate(segments=[[1, 50000, 1], [2, 50001, 2], [3, 50002, 3], [4, 50003, 4], [5, 50004, 5]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 50000, 15], [50000, 50001, 14], [50001, 50002, 12], [50002, 50003, 9], [50003, 50004, 5]])\n assert answers_match(candidate(segments=[[1, 10, 5], [2, 9, 15], [3, 8, 25], [4, 7, 35], [5, 6, 45]]), [[1, 2, 5], [2, 3, 20], [3, 4, 45], [4, 5, 80], [5, 6, 125], [6, 7, 80], [7, 8, 45], [8, 9, 20], [9, 10, 5]])\n assert answers_match(candidate(segments=[[1, 10, 5], [5, 15, 10], [10, 20, 15]]), [[1, 5, 5], [5, 10, 15], [10, 15, 25], [15, 20, 15]])\n assert answers_match(candidate(segments=[[1, 100, 1], [50, 150, 2], [100, 200, 3], [150, 250, 4], [200, 300, 5], [250, 350, 6], [300, 400, 7], [350, 450, 8], [400, 500, 9], [450, 550, 10]]), [[1, 50, 1], [50, 100, 3], [100, 150, 5], [150, 200, 7], [200, 250, 9], [250, 300, 11], [300, 350, 13], [350, 400, 15], [400, 450, 17], [450, 500, 19], [500, 550, 10]])\n assert answers_match(candidate(segments=[[10, 20, 100], [15, 25, 50], [5, 15, 200]]), [[5, 10, 200], [10, 15, 300], [15, 20, 150], [20, 25, 50]])\n assert answers_match(candidate(segments=[[1, 10, 100], [5, 15, 200], [10, 20, 300], [15, 25, 400]]), [[1, 5, 100], [5, 10, 300], [10, 15, 500], [15, 20, 700], [20, 25, 400]])\n assert answers_match(candidate(segments=[[1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000], [1, 2, 1000000000]]), [[1, 2, 10000000000]])\n assert answers_match(candidate(segments=[[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000], [6, 7, 1000000000], [7, 8, 1000000000], [8, 9, 1000000000], [9, 10, 1000000000]]), [[1, 2, 1000000000], [2, 3, 1000000000], [3, 4, 1000000000], [4, 5, 1000000000], [5, 6, 1000000000], [6, 7, 1000000000], [7, 8, 1000000000], [8, 9, 1000000000], [9, 10, 1000000000]])\n assert answers_match(candidate(segments=[[1, 100, 1], [1, 100, 2], [1, 100, 3], [1, 100, 4], [1, 100, 5], [1, 100, 6], [1, 100, 7], [1, 100, 8], [1, 100, 9], [1, 100, 10]]), [[1, 100, 55]])\n assert answers_match(candidate(segments=[[1, 10, 1], [2, 9, 2], [3, 8, 3], [4, 7, 4], [5, 6, 5]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 6, 15], [6, 7, 10], [7, 8, 6], [8, 9, 3], [9, 10, 1]])\n assert answers_match(candidate(segments=[[10, 20, 5], [5, 15, 10], [20, 30, 15], [15, 25, 20], [25, 35, 25], [30, 40, 30]]), [[5, 10, 10], [10, 15, 15], [15, 20, 25], [20, 25, 35], [25, 30, 40], [30, 35, 55], [35, 40, 30]])\n assert answers_match(candidate(segments=[[1, 3, 10], [3, 5, 20], [5, 7, 30], [7, 9, 40], [9, 11, 50], [11, 13, 60], [13, 15, 70]]), [[1, 3, 10], [3, 5, 20], [5, 7, 30], [7, 9, 40], [9, 11, 50], [11, 13, 60], [13, 15, 70]])\n assert answers_match(candidate(segments=[[1, 10, 1], [1, 10, 2], [1, 10, 3], [1, 10, 4], [1, 10, 5], [1, 10, 6], [1, 10, 7], [1, 10, 8], [1, 10, 9], [1, 10, 10]]), [[1, 10, 55]])\n assert answers_match(candidate(segments=[[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]]), [[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]])\n assert answers_match(candidate(segments=[[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9]]), [[1, 2, 45], [2, 3, 44], [3, 4, 42], [4, 5, 39], [5, 6, 35], [6, 7, 30], [7, 8, 24], [8, 9, 17], [9, 10, 9]])\n assert answers_match(candidate(segments=[[5, 10, 10], [10, 15, 10], [15, 20, 10], [20, 25, 10], [25, 30, 10], [30, 35, 10], [35, 40, 10], [40, 45, 10], [45, 50, 10], [50, 55, 10]]), [[5, 10, 10], [10, 15, 10], [15, 20, 10], [20, 25, 10], [25, 30, 10], [30, 35, 10], [35, 40, 10], [40, 45, 10], [45, 50, 10], [50, 55, 10]])\n assert answers_match(candidate(segments=[[1, 1000, 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, 20, 1], [20, 1000, 1]]), [[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], [11, 12, 2], [12, 13, 2], [13, 14, 2], [14, 15, 2], [15, 16, 2], [16, 17, 2], [17, 18, 2], [18, 19, 2], [19, 20, 2], [20, 1000, 2]])\n assert answers_match(candidate(segments=[[1, 100, 1], [2, 99, 2], [3, 98, 3], [4, 97, 4], [5, 96, 5], [6, 95, 6], [7, 94, 7], [8, 93, 8], [9, 92, 9], [10, 91, 10]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 6, 15], [6, 7, 21], [7, 8, 28], [8, 9, 36], [9, 10, 45], [10, 91, 55], [91, 92, 45], [92, 93, 36], [93, 94, 28], [94, 95, 21], [95, 96, 15], [96, 97, 10], [97, 98, 6], [98, 99, 3], [99, 100, 1]])\n assert answers_match(candidate(segments=[[1, 10, 10], [2, 8, 20], [5, 15, 30], [10, 20, 40]]), [[1, 2, 10], [2, 5, 30], [5, 8, 60], [8, 10, 40], [10, 15, 70], [15, 20, 40]])\n assert answers_match(candidate(segments=[[10, 20, 100], [20, 30, 200], [30, 40, 300], [40, 50, 400], [50, 60, 500], [60, 70, 600], [70, 80, 700], [80, 90, 800], [90, 100, 900], [100, 110, 1000]]), [[10, 20, 100], [20, 30, 200], [30, 40, 300], [40, 50, 400], [50, 60, 500], [60, 70, 600], [70, 80, 700], [80, 90, 800], [90, 100, 900], [100, 110, 1000]])\n assert answers_match(candidate(segments=[[1, 3, 1000000000], [2, 4, 1000000000], [3, 5, 1000000000], [4, 6, 1000000000], [5, 7, 1000000000]]), [[1, 2, 1000000000], [2, 3, 2000000000], [3, 4, 2000000000], [4, 5, 2000000000], [5, 6, 2000000000], [6, 7, 1000000000]])\n assert answers_match(candidate(segments=[[10, 20, 5], [15, 25, 7], [20, 30, 9], [25, 35, 11], [30, 40, 13], [35, 45, 15], [40, 50, 17], [45, 55, 19], [50, 60, 21], [55, 65, 23]]), [[10, 15, 5], [15, 20, 12], [20, 25, 16], [25, 30, 20], [30, 35, 24], [35, 40, 28], [40, 45, 32], [45, 50, 36], [50, 55, 40], [55, 60, 44], [60, 65, 23]])\n assert answers_match(candidate(segments=[[1, 10000, 1], [2, 9999, 2], [3, 9998, 3], [4, 9997, 4], [5, 9996, 5]]), [[1, 2, 1], [2, 3, 3], [3, 4, 6], [4, 5, 10], [5, 9996, 15], [9996, 9997, 10], [9997, 9998, 6], [9998, 9999, 3], [9999, 10000, 1]])\n assert answers_match(candidate(segments=[[1, 5, 10], [2, 6, 20], [3, 7, 30], [4, 8, 40], [5, 9, 50]]), [[1, 2, 10], [2, 3, 30], [3, 4, 60], [4, 5, 100], [5, 6, 140], [6, 7, 120], [7, 8, 90], [8, 9, 50]])\n assert answers_match(candidate(segments=[[10, 20, 1], [15, 25, 2], [20, 30, 3], [25, 35, 4], [30, 40, 5], [35, 45, 6], [40, 50, 7], [45, 55, 8], [50, 60, 9], [55, 65, 10]]), [[10, 15, 1], [15, 20, 3], [20, 25, 5], [25, 30, 7], [30, 35, 9], [35, 40, 11], [40, 45, 13], [45, 50, 15], [50, 55, 17], [55, 60, 19], [60, 65, 10]])\n assert answers_match(candidate(segments=[[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, 10, 1]]), [[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, 10, 1]])\n assert answers_match(candidate(segments=[[1, 5, 1], [2, 4, 2], [3, 6, 3], [1, 3, 4], [2, 5, 5], [3, 4, 6], [4, 5, 7], [5, 6, 8]]), [[1, 2, 5], [2, 3, 12], [3, 4, 17], [4, 5, 16], [5, 6, 11]])\n assert answers_match(candidate(segments=[[1, 10, 1], [10, 20, 2], [20, 30, 3], [30, 40, 4], [40, 50, 5], [50, 60, 6], [60, 70, 7], [70, 80, 8], [80, 90, 9], [90, 100, 10]]), [[1, 10, 1], [10, 20, 2], [20, 30, 3], [30, 40, 4], [40, 50, 5], [50, 60, 6], [60, 70, 7], [70, 80, 8], [80, 90, 9], [90, 100, 10]])\n assert answers_match(candidate(segments=[[1, 10, 10], [2, 9, 20], [3, 8, 30], [4, 7, 40], [5, 6, 50], [1, 10, 1], [2, 9, 2], [3, 8, 3], [4, 7, 4], [5, 6, 5]]), [[1, 2, 11], [2, 3, 33], [3, 4, 66], [4, 5, 110], [5, 6, 165], [6, 7, 110], [7, 8, 66], [8, 9, 33], [9, 10, 11]])\n assert answers_match(candidate(segments=[[1, 5, 1], [1, 5, 2], [1, 5, 3], [1, 5, 4], [1, 5, 5], [1, 5, 6], [1, 5, 7], [1, 5, 8], [1, 5, 9], [1, 5, 10]]), [[1, 5, 55]])\n assert answers_match(candidate(segments=[[1, 100000, 1], [1, 100000, 2], [1, 100000, 3], [1, 100000, 4], [1, 100000, 5]]), [[1, 100000, 15]])\n assert answers_match(candidate(segments=[[10, 20, 1], [20, 30, 2], [30, 40, 3], [40, 50, 4], [50, 60, 5], [60, 70, 6], [70, 80, 7], [80, 90, 8], [90, 100, 9], [100, 110, 10]]), [[10, 20, 1], [20, 30, 2], [30, 40, 3], [40, 50, 4], [50, 60, 5], [60, 70, 6], [70, 80, 7], [80, 90, 8], [90, 100, 9], [100, 110, 10]])\n assert answers_match(candidate(segments=[[1, 100, 100], [20, 50, 200], [30, 40, 300], [40, 60, 400], [50, 70, 500], [60, 80, 600], [70, 90, 700], [80, 100, 800]]), [[1, 20, 100], [20, 30, 300], [30, 40, 600], [40, 50, 700], [50, 60, 1000], [60, 70, 1200], [70, 80, 1400], [80, 90, 1600], [90, 100, 900]])\n assert answers_match(candidate(segments=[[1, 2, 1], [1, 3, 2], [1, 4, 3], [1, 5, 4], [1, 6, 5], [1, 7, 6], [1, 8, 7], [1, 9, 8], [1, 10, 9], [1, 11, 10]]), [[1, 2, 55], [2, 3, 54], [3, 4, 52], [4, 5, 49], [5, 6, 45], [6, 7, 40], [7, 8, 34], [8, 9, 27], [9, 10, 19], [10, 11, 10]])\n", "comparison": "unordered"}, "public_tests": ["[[1,4,5],[4,7,7],[1,7,9]]", "[[1,7,9],[6,8,15],[8,10,7]]", "[[1,4,5],[1,4,7],[4,7,1],[4,7,11]]"], "hints": ["Can we sort the segments in a way to help solve the problem?", "How can we dynamically keep track of the sum of the current segment(s)?"], "metadata": {"canonical_parameter_names": ["segments"], "leetcode_dataset_entry_point": "Solution().splitPainting", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:49+00:00", "tests_total": 98, "tests_dropped": 10, "flags": ["any_order", "has_images"], "topic_tags": ["array", "hash-table", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function splitPainting($segments) {", "container": "Solution", "callable": "splitPainting", "parameters": [{"name": "segments", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1944, "task_id": "number-of-visible-people-in-a-queue", "difficulty": "Hard", "problem_description": "There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the i^th person.\n\nA person can see another person to their right in the queue if everybody in between is shorter than both of them. More formally, the i^th person can see the j^th person if i < j and min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1]).\n\nReturn an array answer of length n where answer[i] is the number of people the i^th person can see to their right in the queue.\n\nExample 1:\n\nInput: heights = [10,6,8,5,11,9]\nOutput: [3,1,2,1,1,0]\nExplanation:\nPerson 0 can see person 1, 2, and 4.\nPerson 1 can see person 2.\nPerson 2 can see person 3 and 4.\nPerson 3 can see person 4.\nPerson 4 can see person 5.\nPerson 5 can see no one since nobody is to the right of them.\n\nExample 2:\n\nInput: heights = [5,1,2,3,10]\nOutput: [4,1,1,1,0]\n\nConstraints:\n\n- n == heights.length\n- 1 <= n <= 10^5\n- 1 <= heights[i] <= 10^5\n- All the values of heights are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(heights = [1]) == [0]\n assert candidate(heights = [1, 2, 3, 6, 5, 4, 10, 9, 8, 7]) == [1, 1, 1, 2, 2, 1, 1, 1, 1, 0]\n assert candidate(heights = [5, 1, 2, 3, 10]) == [4, 1, 1, 1, 0]\n assert candidate(heights = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [5, 4, 3, 2, 1]) == [1, 1, 1, 1, 0]\n assert candidate(heights = [10, 6, 8, 5, 11, 9]) == [3, 1, 2, 1, 1, 0]\n assert candidate(heights = [3, 1, 2]) == [2, 1, 0]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5]) == [1, 1, 1, 1, 0]\n assert candidate(heights = [3, 1, 4, 2, 5]) == [2, 1, 2, 1, 0]\n assert candidate(heights = [100000]) == [0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [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, 0]\n assert candidate(heights = [1, 9, 2, 8, 3, 7, 4, 6, 5, 14, 13, 12, 11, 10]) == [1, 3, 1, 3, 1, 3, 1, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [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, 0]\n assert candidate(heights = [5, 9, 2, 8, 7, 6, 3, 4, 1, 10]) == [1, 3, 1, 2, 2, 3, 1, 2, 1, 0]\n assert candidate(heights = [10, 20, 15, 25, 30, 5, 35, 40, 45, 50]) == [1, 2, 1, 1, 2, 1, 1, 1, 1, 0]\n assert candidate(heights = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 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, 0]\n assert candidate(heights = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [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, 99975, 99974, 99973, 99972, 99971, 99970]) == [1, 1, 1, 1, 1, 1, 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(heights = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 12, 14, 16, 18, 20, 11, 13, 15, 17, 19]) == [1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [1, 5, 2, 6, 3, 7, 4, 8, 9, 10]) == [1, 2, 1, 2, 1, 2, 1, 1, 1, 0]\n assert candidate(heights = [5, 1, 3, 2, 4, 6, 7, 8, 9, 10]) == [4, 1, 2, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5]) == [2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [5, 1, 3, 2, 6, 4, 8, 7, 10, 9]) == [3, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [50, 10, 51, 11, 52, 12, 53, 13, 54, 14]) == [2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [2, 1, 5, 4, 3, 8, 7, 6, 10, 9, 14, 13, 12, 18, 17, 16, 20, 19, 22, 21]) == [2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [5, 3, 8, 6, 11, 9, 14, 12, 17, 15, 20, 18, 23, 21, 26, 24, 29, 27, 32, 30, 35, 33, 38, 36, 39]) == [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10]) == [1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 0]\n assert candidate(heights = [15, 10, 5, 14, 9, 4, 13, 8, 3, 12, 7, 2, 11, 6, 1]) == [2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, 0]\n assert candidate(heights = [1, 5, 2, 6, 3, 7, 4, 8, 9, 10]) == [1, 2, 1, 2, 1, 2, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 11, 12, 13, 14, 15]) == [3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0]\n assert candidate(heights = [5, 4, 3, 2, 1, 10]) == [2, 2, 2, 2, 1, 0]\n assert candidate(heights = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 99999]) == [30, 1, 1, 1, 1, 1, 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(heights = [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, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 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(heights = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]) == [1, 1, 1, 1, 5, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 10, 3, 9, 5, 8, 7, 2, 6, 4]) == [1, 2, 1, 2, 1, 1, 2, 1, 1, 0]\n assert candidate(heights = [10, 5, 6, 7, 1, 2, 3, 4, 8, 9]) == [5, 1, 1, 5, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 5, 4, 6, 7, 8, 9, 10]) == [1, 1, 1, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 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, 0]\n assert candidate(heights = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23]) == [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [5, 8, 4, 9, 7, 6, 10, 3, 2, 1, 11, 14, 12, 13, 16, 15, 18, 17, 20, 19]) == [1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 1, 3, 1, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 20, 2, 19, 3, 18, 4, 17, 5, 16, 6, 15, 7, 14, 8, 13, 9, 12, 10, 11]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 15, 11, 14, 12, 13, 20, 16, 19, 17, 18]) == [3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 3, 1, 3, 1, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [5, 3, 8, 6, 7, 2, 4, 1, 10, 9]) == [2, 1, 3, 1, 3, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 20, 15, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [10, 1, 20, 3, 40, 5, 60, 7, 80, 9, 100]) == [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9]) == [4, 1, 2, 1, 1, 1, 2, 1, 1, 0]\n assert candidate(heights = [100, 50, 75, 25, 60, 35, 80, 10, 90, 40]) == [4, 1, 3, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [50, 20, 40, 10, 30, 60, 70, 80, 90, 100]) == [3, 1, 3, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 15, 4, 3, 2, 1, 16, 17, 18, 19]) == [2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 0]\n assert candidate(heights = [5, 9, 1, 4, 6, 8, 2, 3, 7, 10]) == [1, 5, 1, 1, 1, 4, 1, 1, 1, 0]\n assert candidate(heights = [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, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 105, 95, 85, 75, 65, 55, 45, 35, 25, 15]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [77, 73, 69, 65, 61, 57, 53, 49, 45, 41, 37, 33, 29, 25, 21, 17, 13, 9, 5, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15, 20, 19, 18, 17, 16]) == [1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == [2, 2, 2, 2, 2, 2, 2, 2, 1, 0]\n assert candidate(heights = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [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, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [100000, 99999, 99998, 99997, 99996, 99995]) == [1, 1, 1, 1, 1, 0]\n assert candidate(heights = [50, 40, 30, 20, 10, 5, 15, 25, 35, 45]) == [2, 3, 3, 3, 2, 1, 1, 1, 1, 0]\n assert candidate(heights = [1, 3, 2, 6, 5, 4, 10, 9, 8, 7, 14, 13, 12, 11, 20, 19, 18, 17, 16, 15]) == [1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [5, 3, 8, 6, 7, 2, 4, 9, 1, 10]) == [2, 1, 3, 1, 3, 1, 1, 2, 1, 0]\n assert candidate(heights = [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 18]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 0]\n assert candidate(heights = [1, 5, 3, 7, 2, 8, 4, 9, 6, 10]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 0]\n assert candidate(heights = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15]) == [1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(heights = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == [2, 2, 2, 2, 1, 1, 1, 1, 1, 0]\n", "comparison": "exact"}, "public_tests": ["[10,6,8,5,11,9]", "[5,1,2,3,10]"], "hints": ["How to solve this problem in quadratic complexity ?", "For every subarray start at index i, keep finding new maximum values until a value larger than arr[i] is found.", "Since the limits are high, you need a linear solution.", "Use a stack to keep the values of the array sorted as you iterate the array from the end to the start.", "Keep popping from the stack the elements in sorted order until a value larger than arr[i] is found, these are the ones that person i can see."], "metadata": {"canonical_parameter_names": ["heights"], "leetcode_dataset_entry_point": "Solution().canSeePersonsCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:52+00:00", "tests_total": 123, "tests_dropped": 26, "flags": ["has_images"], "topic_tags": ["array", "stack", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function canSeePersonsCount($heights) {", "container": "Solution", "callable": "canSeePersonsCount", "parameters": [{"name": "heights", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1945, "task_id": "sum-of-digits-of-string-after-convert", "difficulty": "Easy", "problem_description": "You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps:\n\n1. Convert s into an integer by replacing each letter with its position in the alphabet (i.e. replace 'a' with 1, 'b' with 2, ..., 'z' with 26).\n2. Transform the integer by replacing it with the sum of its digits.\n3. Repeat the transform operation (step 2) k times in total.\n\nFor example, if s = \"zbax\" and k = 2, then the resulting integer would be 8 by the following operations:\n\n1. Convert: \"zbax\" ➝ \"(26)(2)(1)(24)\" ➝ \"262124\" ➝ 262124\n2. Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17\n3. Transform #2: 17 ➝ 1 + 7 ➝ 8\n\nReturn the resulting integer after performing the operations described above.\n\nExample 1:\n\nInput: s = \"iiii\", k = 1\nOutput: 36\nExplanation:\nThe operations are as follows:\n- Convert: \"iiii\" ➝ \"(9)(9)(9)(9)\" ➝ \"9999\" ➝ 9999\n- Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36\nThus the resulting integer is 36.\n\nExample 2:\n\nInput: s = \"leetcode\", k = 2\nOutput: 6\nExplanation:\nThe operations are as follows:\n- Convert: \"leetcode\" ➝ \"(12)(5)(5)(20)(3)(15)(4)(5)\" ➝ \"12552031545\" ➝ 12552031545\n- Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33\n- Transform #2: 33 ➝ 3 + 3 ➝ 6\nThus the resulting integer is 6.\n\nExample 3:\n\nInput: s = \"zbax\", k = 2\nOutput: 8\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 1 <= k <= 10\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzz\",k = 1) == 32\n assert candidate(s = \"zzz\",k = 10) == 6\n assert candidate(s = \"programming\",k = 1) == 68\n assert candidate(s = \"abz\",k = 5) == 2\n assert candidate(s = \"a\",k = 1) == 1\n assert candidate(s = \"aaa\",k = 3) == 3\n assert candidate(s = \"challenge\",k = 2) == 4\n assert candidate(s = \"iiii\",k = 1) == 36\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == 135\n assert candidate(s = \"hello\",k = 1) == 25\n assert candidate(s = \"python\",k = 2) == 8\n assert candidate(s = \"abc\",k = 3) == 6\n assert candidate(s = \"zbax\",k = 2) == 8\n assert candidate(s = \"abcxyz\",k = 3) == 9\n assert candidate(s = \"leetcode\",k = 2) == 6\n assert candidate(s = \"a\",k = 10) == 1\n assert candidate(s = \"zzzz\",k = 3) == 5\n assert candidate(s = \"zzzzzzzzzz\",k = 1) == 80\n assert candidate(s = \"algorithms\",k = 4) == 5\n assert candidate(s = \"repeatthisoverandover\",k = 7) == 8\n assert candidate(s = \"zzzzzzzzzz\",k = 6) == 8\n assert candidate(s = \"interview\",k = 5) == 8\n assert candidate(s = \"artificialintelligence\",k = 7) == 5\n assert candidate(s = \"zzyxwvutsrqponmlkjihgfedcba\",k = 4) == 8\n assert candidate(s = \"singleletterx\",k = 10) == 8\n assert candidate(s = \"thisisaverylongstringwhichshouldbeconverted\",k = 4) == 2\n assert candidate(s = \"zzzzzzzzzz\",k = 3) == 8\n assert candidate(s = \"hippopotamus\",k = 10) == 7\n assert candidate(s = \"qwen\",k = 5) == 5\n assert candidate(s = \"datastructure\",k = 4) == 9\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 3) == 8\n assert candidate(s = \"repeatedlettersqqqq\",k = 6) == 7\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 2) == 9\n assert candidate(s = \"programming\",k = 3) == 5\n assert candidate(s = \"unbelievable\",k = 9) == 2\n assert candidate(s = \"mississippi\",k = 7) == 4\n assert candidate(s = \"zebra\",k = 6) == 7\n assert candidate(s = \"zzzzzzzzzz\",k = 10) == 8\n assert candidate(s = \"xyzxyz\",k = 3) == 6\n assert candidate(s = \"supercalifragilisticexpialidocious\",k = 5) == 1\n assert candidate(s = \"onetwothreefourfivesixseveneightnine\",k = 5) == 8\n assert candidate(s = \"generateadditionalinputs\",k = 8) == 2\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 4) == 8\n assert candidate(s = \"multifarious\",k = 7) == 2\n assert candidate(s = \"consecutivesimilar\",k = 8) == 1\n assert candidate(s = \"neuralnetwork\",k = 8) == 6\n assert candidate(s = \"developerslovepython\",k = 9) == 3\n assert candidate(s = \"algorithm\",k = 1) == 49\n assert candidate(s = \"wearethebestprogrammers\",k = 7) == 4\n assert candidate(s = \"xylophone\",k = 3) == 8\n assert candidate(s = \"alibabacloud\",k = 7) == 2\n assert candidate(s = \"aaaaaaaaaa\",k = 10) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 5) == 9\n assert candidate(s = \"elephant\",k = 8) == 9\n assert candidate(s = \"supercalifragilisticexpialidocious\",k = 4) == 1\n assert candidate(s = \"abcdefghij\",k = 5) == 1\n assert candidate(s = \"repeatedletters\",k = 4) == 2\n assert candidate(s = \"datastructures\",k = 5) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 3) == 9\n assert candidate(s = \"facetious\",k = 8) == 9\n assert candidate(s = \"numericalsum\",k = 7) == 5\n assert candidate(s = \"expertise\",k = 2) == 13\n assert candidate(s = \"codingcontest\",k = 6) == 4\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 4) == 9\n assert candidate(s = \"alibabacloud\",k = 2) == 11\n assert candidate(s = \"manytimesk\",k = 10) == 4\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 6) == 8\n assert candidate(s = \"giraffe\",k = 9) == 7\n assert candidate(s = \"qwen\",k = 10) == 5\n assert candidate(s = \"mississippi\",k = 8) == 4\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 10) == 9\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 10) == 8\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == 4\n assert candidate(s = \"solution\",k = 7) == 8\n assert candidate(s = \"abacaxabacax\",k = 5) == 1\n assert candidate(s = \"algorithms\",k = 5) == 5\n assert candidate(s = \"zzzzzzzzzz\",k = 5) == 8\n assert candidate(s = \"transform\",k = 8) == 7\n assert candidate(s = \"congratulations\",k = 5) == 9\n assert candidate(s = \"xylophone\",k = 4) == 8\n assert candidate(s = \"quickbrownfoxjumpsoverthelazydog\",k = 2) == 8\n assert candidate(s = \"qwen\",k = 4) == 5\n assert candidate(s = \"leetcodeisfun\",k = 9) == 3\n assert candidate(s = \"programmingisfun\",k = 3) == 2\n assert candidate(s = \"machinelearning\",k = 6) == 7\n assert candidate(s = \"abcdefg\",k = 10) == 1\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",k = 6) == 5\n assert candidate(s = \"thisisaverylongandcomplexstring\",k = 6) == 1\n assert candidate(s = \"xylophone\",k = 5) == 8\n assert candidate(s = \"thisisanexampletocheckthecomplexity\",k = 4) == 1\n assert candidate(s = \"datastructure\",k = 5) == 9\n assert candidate(s = \"abacaxi\",k = 3) == 5\n assert candidate(s = \"abcdabcdabcd\",k = 4) == 3\n", "comparison": "exact"}, "public_tests": ["\"iiii\"\n1", "\"leetcode\"\n2", "\"zbax\"\n2"], "hints": ["First, let's note that after the first transform the value will be at most 100 * 10 which is not much", "After The first transform, we can just do the rest of the transforms by brute force"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().getLucky", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:54+00:00", "tests_total": 93, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function getLucky($s, $k) {", "container": "Solution", "callable": "getLucky", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1946, "task_id": "largest-number-after-mutating-substring", "difficulty": "Medium", "problem_description": "You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].\n\nYou may choose to mutate a single substring of num. To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.e. replace num[i] with change[num[i]]).\n\nReturn a string representing the largest possible integer after mutating (or choosing not to) a single substring of num.\n\nA substring is a contiguous sequence of characters within the string.\n\nExample 1:\n\nInput: num = \"132\", change = [9,8,5,0,3,6,4,2,6,8]\nOutput: \"832\"\nExplanation: Replace the substring \"1\":\n- 1 maps to change[1] = 8.\nThus, \"132\" becomes \"832\".\n\"832\" is the largest number that can be created, so return it.\n\nExample 2:\n\nInput: num = \"021\", change = [9,4,3,5,7,2,1,9,0,6]\nOutput: \"934\"\nExplanation: Replace the substring \"021\":\n- 0 maps to change[0] = 9.\n- 2 maps to change[2] = 3.\n- 1 maps to change[1] = 4.\nThus, \"021\" becomes \"934\".\n\"934\" is the largest number that can be created, so return it.\n\nExample 3:\n\nInput: num = \"5\", change = [1,4,7,5,3,2,5,6,9,4]\nOutput: \"5\"\nExplanation: \"5\" is already the largest number that can be created, so return it.\n\nConstraints:\n\n- 1 <= num.length <= 10^5\n- num consists of only digits 0-9.\n- change.length == 10\n- 0 <= change[d] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"132\",change = [9, 8, 5, 0, 3, 6, 4, 2, 6, 8]) == \"832\"\n assert candidate(num = \"1111\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999\"\n assert candidate(num = \"5\",change = [1, 4, 7, 5, 3, 2, 5, 6, 9, 4]) == \"5\"\n assert candidate(num = \"9876543210\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"9876543210\"\n assert candidate(num = \"3333\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"3333\"\n assert candidate(num = \"021\",change = [9, 4, 3, 5, 7, 2, 1, 9, 0, 6]) == \"934\"\n assert candidate(num = \"1234567890\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8765567890\"\n assert candidate(num = \"1001001001\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"8642086420\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9753197531\"\n assert candidate(num = \"1999999999\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"9999999999\"\n assert candidate(num = \"9999999999\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"9999999999\"\n assert candidate(num = \"1231231231\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"1231231231\"\n assert candidate(num = \"1001\",change = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == \"1111\"\n assert candidate(num = \"9000000009\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9111111119\"\n assert candidate(num = \"9876543210\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"9876543210\"\n assert candidate(num = \"0001112223\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"13579\",change = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == \"26579\"\n assert candidate(num = \"1357924680\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"1122334455\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"1122334455\"\n assert candidate(num = \"5432109876\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"5567899876\"\n assert candidate(num = \"999888777666555444333222111000\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 9]) == \"999888777666555444333222111000\"\n assert candidate(num = \"11111111111111111111\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"99999999999999999999\"\n assert candidate(num = \"100100100\",change = [9, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"199100100\"\n assert candidate(num = \"100100\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"899899\"\n assert candidate(num = \"99999\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 9]) == \"99999\"\n assert candidate(num = \"2468013579\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"7568013579\"\n assert candidate(num = \"1000000001\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"9000000009\"\n assert candidate(num = \"9876543210\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9876556789\"\n assert candidate(num = \"9009\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9999\"\n assert candidate(num = \"0123456789\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"0123456789\"\n assert candidate(num = \"13579246801357924680\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"13579246801357924680\"\n assert candidate(num = \"10987654321\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"99999999999\"\n assert candidate(num = \"1234567890\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"1234567890\"\n assert candidate(num = \"9087654321\",change = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"9187654321\"\n assert candidate(num = \"1919191919\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8919191919\"\n assert candidate(num = \"5555555555\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"6666666666\"\n assert candidate(num = \"4444444444\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"4444444444\"\n assert candidate(num = \"1111\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"1111\"\n assert candidate(num = \"9876543210\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"9090909090\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 9]) == \"9090909090\"\n assert candidate(num = \"12345678901234567890\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"12345678901234567890\"\n assert candidate(num = \"1234567890\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"1234567891\"\n assert candidate(num = \"98765432109876543210\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"98765567899876543210\"\n assert candidate(num = \"9898989898\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"9898989898\"\n assert candidate(num = \"5432109876\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"5432109876\"\n assert candidate(num = \"9999999999\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9999999999\"\n assert candidate(num = \"0000000000\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9999999999\"\n assert candidate(num = \"2222\",change = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == \"3333\"\n assert candidate(num = \"1123344556677889900\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"1123344556677889900\"\n assert candidate(num = \"8765432109\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8765567899\"\n assert candidate(num = \"2468013579\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"2468013579\"\n assert candidate(num = \"1000100010\",change = [9, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"1999100010\"\n assert candidate(num = \"9999999999\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"123456789012345678901234567890\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"987656789012345678901234567890\"\n assert candidate(num = \"3214567890\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"6785567890\"\n assert candidate(num = \"11223344556677889900\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"99887766556677889900\"\n assert candidate(num = \"543210\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"543210\"\n assert candidate(num = \"1234554321\",change = [0, 1, 2, 3, 4, 6, 5, 6, 7, 8]) == \"1234664321\"\n assert candidate(num = \"9080706050\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9191817161\"\n assert candidate(num = \"99999999999999999999\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"99999999999999999999\"\n assert candidate(num = \"5678943210\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"5678943210\"\n assert candidate(num = \"11223344556677889900\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"11223344556677889900\"\n assert candidate(num = \"9090909090\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9190909090\"\n assert candidate(num = \"2222222222\",change = [0, 1, 9, 3, 4, 5, 6, 7, 8, 9]) == \"9999999999\"\n assert candidate(num = \"0000000000\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"1111111111\"\n assert candidate(num = \"239847362876\",change = [8, 9, 5, 7, 6, 5, 4, 3, 2, 1]) == \"579847362876\"\n assert candidate(num = \"00000000000000000000\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"99999999999999999999\"\n assert candidate(num = \"123123123\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"987987987\"\n assert candidate(num = \"2468024680\",change = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == \"4868024680\"\n assert candidate(num = \"0000000000\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"1111111111\"\n assert candidate(num = \"2345678901\",change = [0, 1, 2, 9, 4, 5, 6, 7, 8, 3]) == \"2945678901\"\n assert candidate(num = \"999999\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 9]) == \"999999\"\n assert candidate(num = \"3333\",change = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == \"3333\"\n assert candidate(num = \"00112233445566778899\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"99999999999999999999\"\n assert candidate(num = \"8888888888\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"8888888888\"\n assert candidate(num = \"1234567890\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"2345678990\"\n assert candidate(num = \"1212121212\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"1212121212\"\n assert candidate(num = \"2727272727\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"2727272727\"\n assert candidate(num = \"111222333\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"222333444\"\n assert candidate(num = \"111000111\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"111000111\"\n assert candidate(num = \"1919191919\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"9919191919\"\n assert candidate(num = \"86420\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"86579\"\n assert candidate(num = \"4444444444\",change = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == \"4444444444\"\n assert candidate(num = \"0000000000\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"0000000000\"\n assert candidate(num = \"1357924680\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"1357924680\"\n assert candidate(num = \"109876543210987654321\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"219876543210987654321\"\n assert candidate(num = \"09876543210\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"09876543210\"\n assert candidate(num = \"0000000000\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"01234567890123456789\",change = [9, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"91234567890123456789\"\n assert candidate(num = \"3456789\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"6556789\"\n assert candidate(num = \"2222222222\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"2222222222\"\n assert candidate(num = \"12345678901234567890\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"98765678901234567890\"\n assert candidate(num = \"0123456789\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9876556789\"\n assert candidate(num = \"1234567890\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"9876567890\"\n assert candidate(num = \"888888\",change = [1, 2, 3, 4, 5, 6, 7, 8, 8, 9]) == \"888888\"\n assert candidate(num = \"56789\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"56789\"\n assert candidate(num = \"99999\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"99999\"\n assert candidate(num = \"5643210987\",change = [0, 1, 2, 3, 4, 9, 6, 7, 8, 9]) == \"9643210987\"\n assert candidate(num = \"54321098765432109876\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"55678998765432109876\"\n assert candidate(num = \"9234567890\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9345678990\"\n assert candidate(num = \"98765432109876543210\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"98765432109876543210\"\n assert candidate(num = \"1234567890\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"12345678901234567890\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"87655678901234567890\"\n assert candidate(num = \"1111111111\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == \"1111111111\"\n assert candidate(num = \"1999\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"2999\"\n assert candidate(num = \"2736419850\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"7736419850\"\n assert candidate(num = \"505050\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"505050\"\n assert candidate(num = \"1010101010\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"000000\",change = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == \"000000\"\n assert candidate(num = \"1212121212\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8787878787\"\n assert candidate(num = \"1122334455\",change = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == \"6677889955\"\n assert candidate(num = \"5555555555\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"9876543210\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"9987654321\"\n assert candidate(num = \"1122334455\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8877665555\"\n assert candidate(num = \"1111111111\",change = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == \"9999999999\"\n assert candidate(num = \"532532532\",change = [8, 9, 0, 7, 6, 5, 4, 3, 2, 1]) == \"572532532\"\n assert candidate(num = \"9321876543\",change = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9]) == \"9567876543\"\n assert candidate(num = \"0000\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"9999\"\n assert candidate(num = \"5678912345\",change = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == \"5678998765\"\n assert candidate(num = \"543210\",change = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == \"654321\"\n assert candidate(num = \"1234567890\",change = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == \"1234567890\"\n assert candidate(num = \"5555555555\",change = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == \"5555555555\"\n assert candidate(num = \"5555\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"5555\"\n assert candidate(num = \"8888888888\",change = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == \"8888888888\"\n", "comparison": "exact"}, "public_tests": ["\"132\"\n[9,8,5,0,3,6,4,2,6,8]", "\"021\"\n[9,4,3,5,7,2,1,9,0,6]", "\"5\"\n[1,4,7,5,3,2,5,6,9,4]"], "hints": ["Should you change a digit if the new digit is smaller than the original?", "If changing the first digit and the last digit both make the number bigger, but you can only change one of them; which one should you change?", "Changing numbers closer to the front is always better"], "metadata": {"canonical_parameter_names": ["num", "change"], "leetcode_dataset_entry_point": "Solution().maximumNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:56+00:00", "tests_total": 125, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumNumber($num, $change) {", "container": "Solution", "callable": "maximumNumber", "parameters": [{"name": "num", "type": "String"}, {"name": "change", "type": "Integer[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1947, "task_id": "maximum-compatibility-score-sum", "difficulty": "Medium", "problem_description": "There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).\n\nThe survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the i^th student (0-indexed). The answers of the mentors are represented by a 2D integer array mentors where mentors[j] is an integer array that contains the answers of the j^th mentor (0-indexed).\n\nEach student will be assigned to one mentor, and each mentor will have one student assigned to them. The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor.\n\n- For example, if the student's answers were [1, 0, 1] and the mentor's answers were [0, 0, 1], then their compatibility score is 2 because only the second and the third answers are the same.\n\nYou are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.\n\nGiven students and mentors, return the maximum compatibility score sum that can be achieved.\n\nExample 1:\n\nInput: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]\nOutput: 8\nExplanation: We assign students to mentors in the following way:\n- student 0 to mentor 2 with a compatibility score of 3.\n- student 1 to mentor 0 with a compatibility score of 2.\n- student 2 to mentor 1 with a compatibility score of 3.\nThe compatibility score sum is 3 + 2 + 3 = 8.\n\nExample 2:\n\nInput: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]\nOutput: 0\nExplanation: The compatibility score of any student-mentor pair is 0.\n\nConstraints:\n\n- m == students.length == mentors.length\n- n == students[i].length == mentors[j].length\n- 1 <= m, n <= 8\n- students[i][k] is either 0 or 1.\n- mentors[j][k] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(students = [[1, 1, 0, 0], [0, 0, 1, 1]],mentors = [[1, 0, 1, 0], [0, 1, 0, 1]]) == 4\n assert candidate(students = [[1, 1], [0, 0]],mentors = [[0, 0], [1, 1]]) == 4\n assert candidate(students = [[1, 0], [0, 1]],mentors = [[1, 0], [0, 1]]) == 4\n assert candidate(students = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0]],mentors = [[1, 1, 1, 1], [0, 0, 0, 0], [0, 1, 0, 1]]) == 8\n assert candidate(students = [[1, 0, 1, 0], [0, 1, 0, 1]],mentors = [[0, 0, 1, 1], [1, 1, 0, 0]]) == 4\n assert candidate(students = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 1, 1]],mentors = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1]]) == 10\n assert candidate(students = [[1, 1, 0, 0], [0, 0, 1, 1]],mentors = [[0, 0, 1, 1], [1, 1, 0, 0]]) == 8\n assert candidate(students = [[1, 1, 1], [0, 0, 0]],mentors = [[1, 1, 1], [0, 0, 0]]) == 6\n assert candidate(students = [[0, 0], [0, 0], [0, 0]],mentors = [[1, 1], [1, 1], [1, 1]]) == 0\n assert candidate(students = [[1, 1, 1, 1], [0, 0, 0, 0]],mentors = [[1, 1, 1, 1], [0, 0, 0, 0]]) == 8\n assert candidate(students = [[0, 0, 0], [1, 1, 1], [0, 1, 0]],mentors = [[1, 1, 1], [0, 0, 0], [1, 0, 1]]) == 6\n assert candidate(students = [[1, 0, 1], [0, 1, 0]],mentors = [[0, 1, 0], [1, 0, 1]]) == 6\n assert candidate(students = [[1, 1, 0], [1, 0, 1], [0, 0, 1]],mentors = [[1, 0, 0], [0, 0, 1], [1, 1, 0]]) == 8\n assert candidate(students = [[1, 0], [0, 1]],mentors = [[0, 1], [1, 0]]) == 4\n assert candidate(students = [[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[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]]) == 32\n assert candidate(students = [[1, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1]],mentors = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 1, 1]]) == 40\n assert candidate(students = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 1, 0, 1, 0], [0, 0, 1, 0, 0]],mentors = [[0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 0, 1, 0, 0], [1, 1, 0, 1, 0]]) == 20\n assert candidate(students = [[1, 0, 1, 1, 0], [0, 1, 0, 0, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]],mentors = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == 16\n assert candidate(students = [[1, 0, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]],mentors = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1, 0, 0]]) == 64\n assert candidate(students = [[1, 1, 1], [0, 0, 0], [1, 0, 1], [0, 1, 0]],mentors = [[1, 0, 1], [0, 1, 0], [0, 0, 0], [1, 1, 1]]) == 12\n assert candidate(students = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],mentors = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == 20\n assert candidate(students = [[1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],mentors = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0]]) == 28\n assert candidate(students = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 1]],mentors = [[1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 1, 1]]) == 49\n assert candidate(students = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]],mentors = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 20\n assert candidate(students = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1]],mentors = [[1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]) == 20\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1]],mentors = [[1, 0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0]]) == 22\n assert candidate(students = [[1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]]) == 24\n assert candidate(students = [[0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0]],mentors = [[1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1]]) == 32\n assert candidate(students = [[0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]],mentors = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 20\n assert candidate(students = [[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]],mentors = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]]) == 8\n assert candidate(students = [[1, 0, 1, 1, 0], [0, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0]],mentors = [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 0, 1, 1, 0], [1, 1, 0, 0, 1]]) == 20\n assert candidate(students = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]]) == 64\n assert candidate(students = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],mentors = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 20\n assert candidate(students = [[1, 0, 0, 1, 0], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [0, 1, 1, 0, 0]],mentors = [[0, 1, 1, 0, 0], [1, 0, 0, 1, 0], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0]]) == 20\n assert candidate(students = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 1]],mentors = [[0, 1, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1], [1, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 1]]) == 24\n assert candidate(students = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],mentors = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]) == 28\n assert candidate(students = [[1, 0, 1, 1, 0], [0, 1, 0, 0, 1], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1]],mentors = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == 12\n assert candidate(students = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1, 1, 0]],mentors = [[0, 1, 1, 0, 0, 1, 1, 0], [1, 0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 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], [0, 0, 0, 0, 0, 0, 0, 0]]) == 64\n assert candidate(students = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]],mentors = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]]) == 24\n assert candidate(students = [[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [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]],mentors = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [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]]) == 64\n assert candidate(students = [[1, 0, 0, 1, 0, 0, 1, 0], [0, 1, 1, 0, 1, 1, 0, 1]],mentors = [[0, 1, 1, 0, 1, 1, 0, 1], [1, 0, 0, 1, 0, 0, 1, 0]]) == 16\n assert candidate(students = [[0, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1]],mentors = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1]]) == 24\n assert candidate(students = [[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]) == 64\n assert candidate(students = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1]],mentors = [[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1]]) == 12\n assert candidate(students = [[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]],mentors = [[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], [0, 1, 0, 1, 0, 1, 0, 1]]) == 64\n assert candidate(students = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [1, 1, 0, 0, 0, 1], [0, 0, 1, 1, 1, 0], [1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1]],mentors = [[0, 0, 1, 1, 1, 1], [1, 1, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1]]) == 28\n assert candidate(students = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]],mentors = [[0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]]) == 24\n assert candidate(students = [[1, 0, 1, 1, 0, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0, 1], [1, 1, 1, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0]],mentors = [[0, 0, 1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 1]]) == 28\n assert candidate(students = [[1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0]]) == 32\n assert candidate(students = [[1, 0, 1, 1, 0], [0, 1, 0, 1, 0], [1, 1, 1, 0, 1]],mentors = [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 1, 0, 0]]) == 11\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 1, 0, 1, 0], [0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0]]) == 60\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1]],mentors = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 28\n assert candidate(students = [[1, 1, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1]],mentors = [[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]]) == 30\n assert candidate(students = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]],mentors = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == 20\n assert candidate(students = [[1, 1, 0, 0, 1, 0, 1], [0, 0, 1, 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], [0, 0, 0, 0, 0, 0, 0]],mentors = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1]]) == 42\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1]],mentors = [[0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 48\n assert candidate(students = [[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]],mentors = [[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]]) == 36\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1]],mentors = [[0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]) == 48\n assert candidate(students = [[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]],mentors = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 32\n assert candidate(students = [[0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]],mentors = [[1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]]) == 30\n assert candidate(students = [[1, 0, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]],mentors = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == 21\n assert candidate(students = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1]],mentors = [[1, 1, 0, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == 15\n assert candidate(students = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]],mentors = [[1, 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(students = [[1, 1, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]],mentors = [[0, 1, 1, 0], [1, 0, 0, 1], [1, 1, 0, 1], [0, 0, 1, 0]]) == 15\n assert candidate(students = [[0, 1, 1, 1, 1, 0], [1, 0, 0, 0, 1, 1], [1, 1, 0, 1, 0, 0], [0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0]],mentors = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0]]) == 28\n assert candidate(students = [[1, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1]],mentors = [[0, 1, 1, 0, 0, 1, 0], [1, 0, 0, 1, 1, 0, 1], [0, 0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 0]]) == 28\n assert candidate(students = [[1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 0, 0, 1, 0], [0, 1, 1, 0, 1, 1, 0, 1]],mentors = [[0, 1, 1, 0, 1, 1, 0, 1], [1, 0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]]) == 48\n assert candidate(students = [[1, 1, 1, 0, 0], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1]],mentors = [[0, 1, 0, 1, 1], [1, 0, 0, 1, 0], [1, 1, 1, 0, 0]]) == 10\n", "comparison": "exact"}, "public_tests": ["[[1,1,0],[1,0,1],[0,0,1]]\n[[1,0,0],[0,0,1],[1,1,0]]", "[[0,0],[0,0],[0,0]]\n[[1,1],[1,1],[1,1]]"], "hints": ["Calculate the compatibility score for each student-mentor pair.", "Try every permutation of students with the original mentors array."], "metadata": {"canonical_parameter_names": ["students", "mentors"], "leetcode_dataset_entry_point": "Solution().maxCompatibilitySum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:35:58+00:00", "tests_total": 68, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "bit-manipulation", "bitmask", "hungarian-algorithm", "bipartite-graph", "successive-shortest-path-algorithm", "matching-graph", "perfect-matching", "minimum-cost-flow", "flow-network"]}, "language": "php", "interface": {"raw_signature": "function maxCompatibilitySum($students, $mentors) {", "container": "Solution", "callable": "maxCompatibilitySum", "parameters": [{"name": "students", "type": "Integer[][]"}, {"name": "mentors", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1948, "task_id": "delete-duplicate-folders-in-system", "difficulty": "Hard", "problem_description": "Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the i^th folder in the file system.\n\n- For example, [\"one\", \"two\", \"three\"] represents the path \"/one/two/three\".\n\nTwo folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.\n\n- For example, folders \"/a\" and \"/b\" in the file structure below are identical. They (as well as their subfolders) should all be marked:\n - /a\n - /a/x\n - /a/x/y\n - /a/z\n - /b\n - /b/x\n - /b/x/y\n - /b/z\n- However, if the file structure also included the path \"/b/w\", then the folders \"/a\" and \"/b\" would not be identical. Note that \"/a/x\" and \"/b/x\" would still be considered identical even with the added folder.\n\nOnce all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.\n\nReturn the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.\n\nExample 1:\n\nInput: paths = [[\"a\"],[\"c\"],[\"d\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"d\",\"a\"]]\nOutput: [[\"d\"],[\"d\",\"a\"]]\nExplanation: The file structure is as shown.\nFolders \"/a\" and \"/c\" (and their subfolders) are marked for deletion because they both contain an empty\nfolder named \"b\".\n\nExample 2:\n\nInput: paths = [[\"a\"],[\"c\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"a\",\"b\",\"x\"],[\"a\",\"b\",\"x\",\"y\"],[\"w\"],[\"w\",\"y\"]]\nOutput: [[\"c\"],[\"c\",\"b\"],[\"a\"],[\"a\",\"b\"]]\nExplanation: The file structure is as shown.\nFolders \"/a/b/x\" and \"/w\" (and their subfolders) are marked for deletion because they both contain an empty folder named \"y\".\nNote that folders \"/a\" and \"/c\" are identical after the deletion, but they are not deleted because they were not marked beforehand.\n\nExample 3:\n\nInput: paths = [[\"a\",\"b\"],[\"c\",\"d\"],[\"c\"],[\"a\"]]\nOutput: [[\"c\"],[\"c\",\"d\"],[\"a\"],[\"a\",\"b\"]]\nExplanation: All folders are unique in the file system.\nNote that the returned array can be in a different order as the order does not matter.\n\nConstraints:\n\n- 1 <= paths.length <= 2 * 10^4\n- 1 <= paths[i].length <= 500\n- 1 <= paths[i][j].length <= 10\n- 1 <= sum(paths[i][j].length) <= 2 * 10^5\n- path[i][j] consists of lowercase English letters.\n- No two paths lead to the same folder.\n- For any folder not at the root level, its parent folder will also be in the input.\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(paths=[['project'], ['project', 'src'], ['project', 'src', 'main'], ['project', 'src', 'test'], ['project', 'docs'], ['project', 'docs', 'api'], ['project', 'docs', 'user']]), [['project', 'docs', 'api'], ['project', 'docs', 'user'], ['project', 'docs'], ['project', 'src', 'main'], ['project', 'src', 'test'], ['project', 'src'], ['project']])\n assert answers_match(candidate(paths=[['x'], ['x', 'y'], ['x', 'z'], ['y'], ['y', 'x'], ['z'], ['z', 'x']]), [['x', 'y'], ['x', 'z'], ['x']])\n assert answers_match(candidate(paths=[['a', 'b'], ['c', 'd'], ['c'], ['a']]), [['a', 'b'], ['a'], ['c', 'd'], ['c']])\n assert answers_match(candidate(paths=[['home'], ['home', 'user'], ['home', 'user', 'documents'], ['home', 'guest'], ['home', 'guest', 'documents']]), [['home']])\n assert answers_match(candidate(paths=[['a'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd', 'e'], ['f'], ['f', 'g'], ['f', 'g', 'h'], ['f', 'g', 'h', 'i'], ['f', 'g', 'h', 'i', 'j']]), [['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c'], ['a', 'b'], ['a'], ['f', 'g', 'h', 'i', 'j'], ['f', 'g', 'h', 'i'], ['f', 'g', 'h'], ['f', 'g'], ['f']])\n assert answers_match(candidate(paths=[['root'], ['root', 'a'], ['root', 'b'], ['root', 'a', 'x'], ['root', 'b', 'x'], ['root', 'a', 'x', 'y'], ['root', 'b', 'x', 'y']]), [['root']])\n assert answers_match(candidate(paths=[['folder1'], ['folder1', 'sub1'], ['folder1', 'sub2'], ['folder2'], ['folder2', 'sub1'], ['folder2', 'sub2']]), [])\n assert answers_match(candidate(paths=[['a'], ['c'], ['a', 'b'], ['c', 'b'], ['a', 'b', 'x'], ['a', 'b', 'x', 'y'], ['w'], ['w', 'y']]), [['a', 'b'], ['a'], ['c', 'b'], ['c']])\n assert answers_match(candidate(paths=[['x'], ['x', 'y'], ['x', 'y', 'z'], ['x', 'y', 'z', 'w'], ['u'], ['u', 'v'], ['u', 'v', 'w']]), [['u'], ['x', 'y'], ['x']])\n assert answers_match(candidate(paths=[['m'], ['m', 'n'], ['n'], ['n', 'm'], ['m', 'n', 'o'], ['n', 'm', 'o']]), [['m'], ['n']])\n assert answers_match(candidate(paths=[['root'], ['root', 'folder1'], ['root', 'folder2'], ['root', 'folder1', 'subfolder1'], ['root', 'folder2', 'subfolder1']]), [['root']])\n assert answers_match(candidate(paths=[['m'], ['m', 'n'], ['p'], ['p', 'n']]), [])\n assert answers_match(candidate(paths=[['a'], ['c'], ['d'], ['a', 'b'], ['c', 'b'], ['d', 'a']]), [['d', 'a'], ['d']])\n assert answers_match(candidate(paths=[['x'], ['x', 'y'], ['x', 'y', 'z'], ['y'], ['y', 'z']]), [['x']])\n assert answers_match(candidate(paths=[['one'], ['one', 'two'], ['one', 'two', 'three'], ['two'], ['two', 'three']]), [['one']])\n assert answers_match(candidate(paths=[['p'], ['p', 'q'], ['p', 'q', 'r'], ['p', 'q', 'r', 's'], ['p', 'q', 'r', 't'], ['q'], ['q', 'r'], ['q', 'r', 's'], ['q', 'r', 't'], ['r'], ['r', 's'], ['r', 't'], ['s'], ['t'], ['u'], ['u', 'v'], ['u', 'v', 'w'], ['u', 'v', 'w', 'x'], ['u', 'v', 'w', 'y'], ['v'], ['v', 'w'], ['v', 'w', 'x'], ['v', 'w', 'y'], ['w'], ['w', 'x'], ['w', 'y'], ['x'], ['y']]), [['p'], ['s'], ['t'], ['u'], ['x'], ['y']])\n assert answers_match(candidate(paths=[['level1', 'level2', 'level3', 'level4'], ['level1', 'level2', 'level5', 'level4'], ['level1', 'level6', 'level3', 'level4'], ['level1', 'level6', 'level5', 'level4'], ['level1', 'level7', 'level8'], ['level1', 'level9', 'level10', 'level11'], ['level1', 'level9', 'level10', 'level12']]), [['level1', 'level7', 'level8'], ['level1', 'level7'], ['level1', 'level9', 'level10', 'level11'], ['level1', 'level9', 'level10', 'level12'], ['level1', 'level9', 'level10'], ['level1', 'level9'], ['level1']])\n assert answers_match(candidate(paths=[['home', 'user', 'docs'], ['home', 'user', 'photos'], ['home', 'guest', 'docs'], ['home', 'guest', 'photos'], ['home', 'user', 'docs', 'file1'], ['home', 'guest', 'docs', 'file1'], ['home', 'user', 'photos', 'image1'], ['home', 'guest', 'photos', 'image1'], ['home', 'user', 'docs', 'file2'], ['home', 'guest', 'docs', 'file2']]), [['home']])\n assert answers_match(candidate(paths=[['projects', 'proj1'], ['projects', 'proj2'], ['projects', 'proj1', 'src'], ['projects', 'proj2', 'src'], ['projects', 'proj1', 'src', 'main'], ['projects', 'proj2', 'src', 'main'], ['projects', 'proj1', 'src', 'test'], ['projects', 'proj2', 'src', 'test'], ['projects', 'proj1', 'src', 'main', 'file1'], ['projects', 'proj2', 'src', 'main', 'file1'], ['projects', 'proj1', 'src', 'test', 'test1'], ['projects', 'proj2', 'src', 'test', 'test1']]), [['projects']])\n assert answers_match(candidate(paths=[['alpha'], ['alpha', 'beta'], ['alpha', 'beta', 'gamma'], ['alpha', 'beta', 'delta'], ['alpha', 'epsilon'], ['alpha', 'epsilon', 'gamma'], ['alpha', 'epsilon', 'delta'], ['beta'], ['beta', 'gamma'], ['beta', 'delta'], ['epsilon'], ['epsilon', 'gamma'], ['epsilon', 'delta'], ['gamma'], ['delta'], ['charlie'], ['charlie', 'foxtrot'], ['charlie', 'foxtrot', 'gamma'], ['charlie', 'foxtrot', 'delta'], ['charlie', 'tango'], ['charlie', 'tango', 'gamma'], ['charlie', 'tango', 'delta']]), [['alpha'], ['charlie'], ['delta'], ['gamma']])\n assert answers_match(candidate(paths=[['project'], ['project', 'src'], ['project', 'docs'], ['project', 'src', 'main'], ['project', 'src', 'test'], ['project', 'docs', 'api'], ['project', 'docs', 'userguide'], ['project', 'src', 'main', 'java'], ['project', 'src', 'test', 'java'], ['project', 'docs', 'api', 'java'], ['project', 'docs', 'userguide', 'java'], ['project', 'src', 'main', 'java', 'utils'], ['project', 'src', 'test', 'java', 'utils'], ['project', 'docs', 'api', 'java', 'utils'], ['project', 'docs', 'userguide', 'java', 'utils']]), [['project', 'docs'], ['project', 'src'], ['project']])\n assert answers_match(candidate(paths=[['data', 'archive'], ['data', 'archive', '2021'], ['data', 'archive', '2022'], ['data', 'archive', '2023'], ['data', 'backup'], ['data', 'backup', '2021'], ['data', 'backup', '2022'], ['data', 'backup', '2023'], ['data', 'logs'], ['data', 'logs', 'server1'], ['data', 'logs', 'server2'], ['data', 'logs', 'server3'], ['data', 'temp'], ['data', 'temp', 'server1'], ['data', 'temp', 'server2'], ['data', 'temp', 'server3']]), [['data']])\n assert answers_match(candidate(paths=[['root', 'a'], ['root', 'b'], ['root', 'a', 'c'], ['root', 'b', 'c'], ['root', 'a', 'd'], ['root', 'b', 'd'], ['root', 'a', 'c', 'e'], ['root', 'b', 'c', 'e']]), [['root']])\n assert answers_match(candidate(paths=[['home'], ['home', 'user1'], ['home', 'user2'], ['home', 'user1', 'files'], ['home', 'user2', 'files'], ['home', 'user1', 'files', 'docs'], ['home', 'user2', 'files', 'docs'], ['home', 'user1', 'files', 'docs', 'report1'], ['home', 'user2', 'files', 'docs', 'report1'], ['home', 'user1', 'files', 'docs', 'report2'], ['home', 'user2', 'files', 'docs', 'report2']]), [['home']])\n assert answers_match(candidate(paths=[['x'], ['y'], ['z'], ['x', 'a'], ['y', 'a'], ['z', 'a'], ['x', 'a', 'b'], ['y', 'a', 'b'], ['z', 'a', 'b'], ['x', 'a', 'b', 'c'], ['y', 'a', 'b', 'c'], ['z', 'a', 'b', 'c'], ['x', 'd'], ['y', 'e'], ['z', 'f']]), [['x', 'd'], ['x'], ['y', 'e'], ['y'], ['z', 'f'], ['z']])\n assert answers_match(candidate(paths=[['root', 'a', 'b', 'c', 'd'], ['root', 'x', 'y', 'z', 'w'], ['root', 'a', 'b', 'c', 'd', 'e'], ['root', 'x', 'y', 'z', 'w', 'v'], ['root', 'a', 'b', 'f'], ['root', 'x', 'y', 'f'], ['root', 'a', 'g'], ['root', 'x', 'g'], ['root', 'a', 'h'], ['root', 'x', 'h'], ['root', 'a', 'i', 'j'], ['root', 'x', 'i', 'j'], ['root', 'a', 'i', 'k'], ['root', 'x', 'i', 'k']]), [['root', 'a', 'b', 'c', 'd', 'e'], ['root', 'a', 'b', 'c', 'd'], ['root', 'a', 'b', 'c'], ['root', 'a', 'b', 'f'], ['root', 'a', 'b'], ['root', 'a', 'g'], ['root', 'a', 'h'], ['root', 'a'], ['root', 'x', 'g'], ['root', 'x', 'h'], ['root', 'x', 'y', 'f'], ['root', 'x', 'y', 'z', 'w', 'v'], ['root', 'x', 'y', 'z', 'w'], ['root', 'x', 'y', 'z'], ['root', 'x', 'y'], ['root', 'x'], ['root']])\n assert answers_match(candidate(paths=[['root'], ['root', 'folder1'], ['root', 'folder2'], ['root', 'folder1', 'sub1'], ['root', 'folder2', 'sub1'], ['root', 'folder1', 'sub1', 'subsub1'], ['root', 'folder2', 'sub1', 'subsub1']]), [['root']])\n assert answers_match(candidate(paths=[['base'], ['base', 'folder1'], ['base', 'folder1', 'subfolder1'], ['base', 'folder1', 'subfolder2'], ['base', 'folder2'], ['base', 'folder2', 'subfolder1'], ['base', 'folder2', 'subfolder2'], ['base', 'folder3'], ['base', 'folder3', 'subfolder1'], ['base', 'folder3', 'subfolder2'], ['base', 'folder1', 'subfolder1', 'deep1'], ['base', 'folder2', 'subfolder1', 'deep1'], ['base', 'folder3', 'subfolder1', 'deep1']]), [['base']])\n assert answers_match(candidate(paths=[['system'], ['system', 'app1'], ['system', 'app1', 'data'], ['system', 'app2'], ['system', 'app2', 'data'], ['system', 'app3'], ['system', 'app3', 'data'], ['system', 'app3', 'logs'], ['system', 'app4'], ['system', 'app4', 'data'], ['system', 'app4', 'logs'], ['system', 'app4', 'temp'], ['system', 'app5'], ['system', 'app5', 'data'], ['system', 'app5', 'logs'], ['system', 'app5', 'temp'], ['system', 'app6'], ['system', 'app6', 'data'], ['system', 'app6', 'logs'], ['system', 'app6', 'temp'], ['system', 'app6', 'config'], ['system', 'app7'], ['system', 'app7', 'data'], ['system', 'app7', 'logs'], ['system', 'app7', 'temp'], ['system', 'app7', 'config'], ['system', 'app8'], ['system', 'app8', 'data'], ['system', 'app8', 'logs'], ['system', 'app8', 'temp'], ['system', 'app8', 'config'], ['system', 'app8', 'bin']]), [['system', 'app3', 'data'], ['system', 'app3', 'logs'], ['system', 'app3'], ['system', 'app8', 'bin'], ['system', 'app8', 'config'], ['system', 'app8', 'data'], ['system', 'app8', 'logs'], ['system', 'app8', 'temp'], ['system', 'app8'], ['system']])\n assert answers_match(candidate(paths=[['root', 'x'], ['root', 'y'], ['root', 'x', 'z'], ['root', 'y', 'z'], ['root', 'x', 'a'], ['root', 'y', 'a'], ['root', 'x', 'a', 'b'], ['root', 'y', 'a', 'b']]), [['root']])\n assert answers_match(candidate(paths=[['root', 'level1', 'level2', 'level3'], ['root', 'level1', 'level2', 'level4'], ['root', 'level5', 'level6'], ['root', 'level1', 'level2', 'level3', 'level7'], ['root', 'level5', 'level6', 'level7'], ['root', 'level1', 'level2', 'level3', 'level7', 'level8'], ['root', 'level5', 'level6', 'level7', 'level8']]), [['root', 'level1', 'level2', 'level4'], ['root', 'level1', 'level2'], ['root', 'level1'], ['root', 'level5'], ['root']])\n assert answers_match(candidate(paths=[['data'], ['data', 'backup'], ['data', 'backup', '2021'], ['data', 'backup', '2022'], ['data', 'backup', '2021', 'month1'], ['data', 'backup', '2022', 'month1'], ['data', 'backup', '2021', 'month2'], ['data', 'backup', '2022', 'month2'], ['data', 'backup', '2021', 'month1', 'day1'], ['data', 'backup', '2022', 'month1', 'day1'], ['data', 'backup', '2021', 'month1', 'day2'], ['data', 'backup', '2022', 'month1', 'day2'], ['data', 'backup', '2021', 'month2', 'day1'], ['data', 'backup', '2022', 'month2', 'day1'], ['data', 'backup', '2021', 'month2', 'day2'], ['data', 'backup', '2022', 'month2', 'day2'], ['data', 'backup', '2021', 'month1', 'day1', 'file1'], ['data', 'backup', '2022', 'month1', 'day1', 'file1'], ['data', 'backup', '2021', 'month1', 'day2', 'file1'], ['data', 'backup', '2022', 'month1', 'day2', 'file1'], ['data', 'backup', '2021', 'month2', 'day1', 'file1'], ['data', 'backup', '2022', 'month2', 'day1', 'file1'], ['data', 'backup', '2021', 'month2', 'day2', 'file1'], ['data', 'backup', '2022', 'month2', 'day2', 'file1']]), [['data', 'backup'], ['data']])\n assert answers_match(candidate(paths=[['root', 'dir1', 'subdir1'], ['root', 'dir1', 'subdir2'], ['root', 'dir2', 'subdir1'], ['root', 'dir2', 'subdir3'], ['root', 'dir3', 'subdir2'], ['root', 'dir3', 'subdir4']]), [['root', 'dir1', 'subdir1'], ['root', 'dir1', 'subdir2'], ['root', 'dir1'], ['root', 'dir2', 'subdir1'], ['root', 'dir2', 'subdir3'], ['root', 'dir2'], ['root', 'dir3', 'subdir2'], ['root', 'dir3', 'subdir4'], ['root', 'dir3'], ['root']])\n assert answers_match(candidate(paths=[['x'], ['x', 'y'], ['x', 'y', 'z'], ['x', 'y', 'w'], ['y'], ['y', 'z'], ['y', 'w'], ['a'], ['a', 'b'], ['a', 'b', 'c'], ['b'], ['b', 'c'], ['b', 'd'], ['c'], ['c', 'd'], ['d']]), [['a', 'b', 'c'], ['a', 'b'], ['a'], ['b', 'c'], ['b', 'd'], ['b'], ['c', 'd'], ['c'], ['d'], ['x']])\n assert answers_match(candidate(paths=[['base', 'level1', 'level2', 'level3'], ['other', 'level1', 'level2', 'level3'], ['base', 'level1', 'level2', 'level3', 'level4'], ['other', 'level1', 'level2', 'level3', 'level4'], ['base', 'level1', 'level2', 'level3', 'level4', 'level5'], ['other', 'level1', 'level2', 'level3', 'level4', 'level5'], ['base', 'level1', 'level2', 'other'], ['other', 'level1', 'level2', 'other']]), [])\n assert answers_match(candidate(paths=[['home', 'user1', 'documents'], ['home', 'user2', 'documents'], ['home', 'user1', 'documents', 'file1'], ['home', 'user2', 'documents', 'file1'], ['home', 'user1', 'pictures'], ['home', 'user2', 'pictures'], ['home', 'user1', 'pictures', 'photo1'], ['home', 'user2', 'pictures', 'photo1']]), [['home']])\n assert answers_match(candidate(paths=[['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h'], ['a', 'b', 'c', 'd', 'f'], ['f', 'g', 'h', 'i'], ['a', 'b', 'c', 'd', 'j'], ['j', 'k'], ['f', 'g', 'h', 'i', 'k']]), [['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'f'], ['a', 'b', 'c', 'd', 'j'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c'], ['a', 'b'], ['a'], ['f', 'g', 'h'], ['f', 'g'], ['f']])\n assert answers_match(candidate(paths=[['root', 'a', 'b', 'c'], ['root', 'x', 'y', 'z'], ['root', 'a', 'b', 'd'], ['root', 'x', 'y', 'd'], ['root', 'a', 'b', 'c', 'e'], ['root', 'x', 'y', 'z', 'e'], ['root', 'a', 'b', 'c', 'f'], ['root', 'x', 'y', 'z', 'f'], ['root', 'a', 'g'], ['root', 'x', 'g'], ['root', 'a', 'h'], ['root', 'x', 'h']]), [['root', 'a', 'b', 'd'], ['root', 'a', 'b'], ['root', 'a', 'g'], ['root', 'a', 'h'], ['root', 'a'], ['root', 'x', 'g'], ['root', 'x', 'h'], ['root', 'x', 'y', 'd'], ['root', 'x', 'y'], ['root', 'x'], ['root']])\n assert answers_match(candidate(paths=[['library', 'books', 'genre1'], ['library', 'books', 'genre2'], ['library', 'books', 'genre3'], ['library', 'books', 'genre1', 'author1'], ['library', 'books', 'genre3', 'author1'], ['library', 'books', 'genre2', 'author2'], ['library', 'books', 'genre3', 'author2'], ['library', 'books', 'genre1', 'author1', 'book1'], ['library', 'books', 'genre3', 'author1', 'book1']]), [['library', 'books', 'genre1'], ['library', 'books', 'genre2', 'author2'], ['library', 'books', 'genre2'], ['library', 'books', 'genre3', 'author2'], ['library', 'books', 'genre3'], ['library', 'books'], ['library']])\n assert answers_match(candidate(paths=[['a'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd', 'e'], ['b'], ['b', 'c'], ['b', 'c', 'd'], ['b', 'c', 'd', 'e'], ['c'], ['c', 'd'], ['c', 'd', 'e'], ['d'], ['d', 'e'], ['e']]), [['a'], ['e']])\n assert answers_match(candidate(paths=[['folder1'], ['folder1', 'folder2'], ['folder1', 'folder2', 'folder3'], ['folder1', 'folder2', 'folder3', 'folder4'], ['folder1', 'folder2', 'folder3', 'folder5'], ['folder1', 'folder2', 'folder6'], ['folder1', 'folder2', 'folder6', 'folder7'], ['folder1', 'folder2', 'folder6', 'folder8'], ['folder1', 'folder9'], ['folder1', 'folder9', 'folder10'], ['folder1', 'folder9', 'folder10', 'folder11'], ['folder1', 'folder9', 'folder10', 'folder12'], ['folder1', 'folder9', 'folder13'], ['folder1', 'folder9', 'folder13', 'folder14'], ['folder1', 'folder9', 'folder13', 'folder15']]), [['folder1', 'folder2', 'folder3', 'folder4'], ['folder1', 'folder2', 'folder3', 'folder5'], ['folder1', 'folder2', 'folder3'], ['folder1', 'folder2', 'folder6', 'folder7'], ['folder1', 'folder2', 'folder6', 'folder8'], ['folder1', 'folder2', 'folder6'], ['folder1', 'folder2'], ['folder1', 'folder9', 'folder10', 'folder11'], ['folder1', 'folder9', 'folder10', 'folder12'], ['folder1', 'folder9', 'folder10'], ['folder1', 'folder9', 'folder13', 'folder14'], ['folder1', 'folder9', 'folder13', 'folder15'], ['folder1', 'folder9', 'folder13'], ['folder1', 'folder9'], ['folder1']])\n assert answers_match(candidate(paths=[['projects', 'projectA'], ['projects', 'projectB'], ['projects', 'projectA', 'src'], ['projects', 'projectB', 'src'], ['projects', 'projectA', 'src', 'module1'], ['projects', 'projectB', 'src', 'module1'], ['projects', 'projectA', 'src', 'module2'], ['projects', 'projectB', 'src', 'module2'], ['projects', 'projectA', 'src', 'module1', 'file1'], ['projects', 'projectB', 'src', 'module1', 'file1'], ['projects', 'projectA', 'src', 'module2', 'file2'], ['projects', 'projectB', 'src', 'module2', 'file3'], ['projects', 'projectA', 'src', 'module1', 'file4'], ['projects', 'projectB', 'src', 'module1', 'file5']]), [['projects', 'projectA', 'src', 'module1', 'file1'], ['projects', 'projectA', 'src', 'module1', 'file4'], ['projects', 'projectA', 'src', 'module1'], ['projects', 'projectA', 'src', 'module2', 'file2'], ['projects', 'projectA', 'src', 'module2'], ['projects', 'projectA', 'src'], ['projects', 'projectA'], ['projects', 'projectB', 'src', 'module1', 'file1'], ['projects', 'projectB', 'src', 'module1', 'file5'], ['projects', 'projectB', 'src', 'module1'], ['projects', 'projectB', 'src', 'module2', 'file3'], ['projects', 'projectB', 'src', 'module2'], ['projects', 'projectB', 'src'], ['projects', 'projectB'], ['projects']])\n assert answers_match(candidate(paths=[['dir1'], ['dir2'], ['dir3'], ['dir1', 'sub1'], ['dir2', 'sub2'], ['dir3', 'sub1'], ['dir1', 'sub1', 'subsub1'], ['dir2', 'sub2', 'subsub2'], ['dir3', 'sub1', 'subsub1'], ['dir1', 'sub1', 'subsub1', 'deeper1'], ['dir3', 'sub1', 'subsub1', 'deeper1']]), [['dir2', 'sub2', 'subsub2'], ['dir2', 'sub2'], ['dir2']])\n assert answers_match(candidate(paths=[['a'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'b', 'd'], ['b'], ['b', 'c'], ['b', 'd'], ['c'], ['c', 'a'], ['c', 'a', 'b'], ['d'], ['d', 'a'], ['d', 'a', 'b']]), [['a']])\n assert answers_match(candidate(paths=[['folderA'], ['folderB'], ['folderA', 'subA'], ['folderB', 'subA'], ['folderA', 'subA', 'subsubA'], ['folderB', 'subA', 'subsubA'], ['folderC'], ['folderC', 'subB'], ['folderD'], ['folderD', 'subB', 'subsubB'], ['folderE'], ['folderE', 'subB', 'subsubB', 'deepB']]), [['folderC', 'subB'], ['folderC'], ['folderD', 'subB', 'subsubB'], ['folderD', 'subB'], ['folderD'], ['folderE', 'subB', 'subsubB', 'deepB'], ['folderE', 'subB', 'subsubB'], ['folderE', 'subB'], ['folderE']])\n assert answers_match(candidate(paths=[['main'], ['main', 'projects'], ['main', 'projects', 'project1'], ['main', 'projects', 'project2'], ['main', 'projects', 'project1', 'code'], ['main', 'projects', 'project2', 'code'], ['main', 'docs'], ['main', 'docs', 'project1'], ['main', 'docs', 'project2'], ['main', 'docs', 'project1', 'notes'], ['main', 'docs', 'project2', 'notes']]), [['main', 'docs'], ['main', 'projects'], ['main']])\n assert answers_match(candidate(paths=[['folder1', 'subfolder1', 'deepsub1'], ['folder2', 'subfolder2', 'deepsub2'], ['folder1', 'subfolder1', 'deepsub3'], ['folder2', 'subfolder2', 'deepsub3'], ['folder1', 'subfolder2'], ['folder2', 'subfolder2'], ['folder3', 'subfolder3']]), [['folder1', 'subfolder1', 'deepsub1'], ['folder1', 'subfolder1', 'deepsub3'], ['folder1', 'subfolder1'], ['folder1', 'subfolder2'], ['folder1'], ['folder2', 'subfolder2', 'deepsub2'], ['folder2', 'subfolder2', 'deepsub3'], ['folder2', 'subfolder2'], ['folder2'], ['folder3', 'subfolder3'], ['folder3']])\n assert answers_match(candidate(paths=[['root', 'a', 'x'], ['root', 'b', 'x'], ['root', 'a', 'y'], ['root', 'b', 'y'], ['root', 'a', 'x', 'z'], ['root', 'b', 'x', 'z'], ['root', 'a', 'w'], ['root', 'b', 'w']]), [['root']])\n assert answers_match(candidate(paths=[['a', 'b', 'c'], ['a', 'd', 'e'], ['a', 'd', 'e', 'f'], ['g', 'h', 'i'], ['g', 'j', 'k'], ['g', 'j', 'l'], ['a', 'b', 'c', 'm'], ['g', 'h', 'i', 'm'], ['n', 'o', 'p'], ['n', 'o', 'q'], ['n', 'r', 's'], ['n', 'r', 's', 't']]), [['a', 'b'], ['a', 'd', 'e', 'f'], ['a', 'd', 'e'], ['a', 'd'], ['a'], ['g', 'h'], ['g', 'j', 'k'], ['g', 'j', 'l'], ['g', 'j'], ['g'], ['n', 'o', 'p'], ['n', 'o', 'q'], ['n', 'o'], ['n', 'r', 's', 't'], ['n', 'r', 's'], ['n', 'r'], ['n']])\n assert answers_match(candidate(paths=[['x'], ['x', 'y'], ['x', 'y', 'z'], ['x', 'y', 'z', 'w'], ['y'], ['y', 'z'], ['y', 'z', 'w'], ['z'], ['z', 'w'], ['w']]), [['w'], ['x']])\n assert answers_match(candidate(paths=[['main', 'branch1'], ['main', 'branch2'], ['main', 'branch1', 'sub1'], ['main', 'branch2', 'sub1'], ['main', 'branch1', 'sub2'], ['main', 'branch2', 'sub2'], ['main', 'branch1', 'sub1', 'subsub1'], ['main', 'branch2', 'sub1', 'subsub1'], ['main', 'branch1', 'sub1', 'subsub2'], ['main', 'branch2', 'sub1', 'subsub2']]), [['main']])\n assert answers_match(candidate(paths=[['x'], ['y'], ['z'], ['x', 'a'], ['y', 'a'], ['z', 'a'], ['x', 'a', 'b'], ['y', 'a', 'b'], ['x', 'a', 'b', 'c'], ['y', 'a', 'b', 'c'], ['w'], ['w', 'd'], ['w', 'd', 'e'], ['w', 'd', 'e', 'f'], ['v'], ['v', 'd'], ['v', 'd', 'e'], ['v', 'd', 'e', 'f']]), [['z', 'a'], ['z']])\n assert answers_match(candidate(paths=[['level1'], ['level1', 'level2'], ['level1', 'level2', 'level3'], ['level1', 'level2', 'level3', 'level4'], ['level1', 'level2', 'level3', 'level4', 'level5'], ['levelA'], ['levelA', 'level2'], ['levelA', 'level2', 'level3'], ['levelA', 'level2', 'level3', 'level4'], ['levelA', 'level2', 'level3', 'level4', 'level5']]), [])\n assert answers_match(candidate(paths=[['root'], ['root', 'dir1'], ['root', 'dir1', 'subdir1'], ['root', 'dir2'], ['root', 'dir2', 'subdir1'], ['root', 'dir2', 'subdir2'], ['root', 'dir3'], ['root', 'dir3', 'subdir2'], ['root', 'dir4'], ['root', 'dir4', 'subdir1'], ['root', 'dir4', 'subdir2']]), [['root', 'dir1', 'subdir1'], ['root', 'dir1'], ['root', 'dir3', 'subdir2'], ['root', 'dir3'], ['root']])\n assert answers_match(candidate(paths=[['home', 'user1', 'docs'], ['home', 'user2', 'docs'], ['home', 'user1', 'music'], ['home', 'user2', 'music'], ['home', 'user1', 'docs', 'report'], ['home', 'user2', 'docs', 'report'], ['home', 'user1', 'music', 'song1'], ['home', 'user2', 'music', 'song2'], ['home', 'user1', 'docs', 'report', 'summary'], ['home', 'user2', 'docs', 'report', 'summary'], ['home', 'user1', 'docs', 'report', 'summary', 'details'], ['home', 'user2', 'docs', 'report', 'summary', 'details']]), [['home', 'user1', 'music', 'song1'], ['home', 'user1', 'music'], ['home', 'user1'], ['home', 'user2', 'music', 'song2'], ['home', 'user2', 'music'], ['home', 'user2'], ['home']])\n assert answers_match(candidate(paths=[['projects', 'proj1', 'src'], ['projects', 'proj2', 'src'], ['projects', 'proj3'], ['projects', 'proj1', 'src', 'main'], ['projects', 'proj2', 'src', 'main'], ['projects', 'proj1', 'docs'], ['projects', 'proj2', 'docs'], ['projects', 'proj3', 'docs']]), [['projects', 'proj3', 'docs'], ['projects', 'proj3'], ['projects']])\n assert answers_match(candidate(paths=[['alpha'], ['beta'], ['gamma'], ['alpha', 'delta'], ['beta', 'delta'], ['gamma', 'epsilon'], ['alpha', 'delta', 'zeta'], ['beta', 'delta', 'zeta'], ['alpha', 'delta', 'zeta', 'eta'], ['beta', 'delta', 'zeta', 'eta'], ['alpha', 'theta'], ['beta', 'theta'], ['gamma', 'theta']]), [['gamma', 'epsilon'], ['gamma', 'theta'], ['gamma']])\n assert answers_match(candidate(paths=[['project'], ['project', 'module1'], ['project', 'module1', 'file1'], ['project', 'module2'], ['project', 'module2', 'file1'], ['project', 'module3'], ['project', 'module3', 'file2'], ['project', 'module4'], ['project', 'module4', 'file3'], ['project', 'module5'], ['project', 'module5', 'file3'], ['project', 'module6'], ['project', 'module6', 'file4'], ['project', 'module7'], ['project', 'module7', 'file4'], ['project', 'module8'], ['project', 'module8', 'file5'], ['project', 'module8', 'file6']]), [['project', 'module3', 'file2'], ['project', 'module3'], ['project', 'module8', 'file5'], ['project', 'module8', 'file6'], ['project', 'module8'], ['project']])\n assert answers_match(candidate(paths=[['app', 'module1', 'service1'], ['app', 'module2', 'service2'], ['app', 'module3', 'service1'], ['app', 'module4', 'service4'], ['app', 'module1', 'service1', 'endpoint1'], ['app', 'module3', 'service1', 'endpoint1'], ['app', 'module5'], ['app', 'module5', 'endpoint2']]), [['app', 'module2', 'service2'], ['app', 'module2'], ['app', 'module4', 'service4'], ['app', 'module4'], ['app', 'module5', 'endpoint2'], ['app', 'module5'], ['app']])\n assert answers_match(candidate(paths=[['root', 'dir1', 'subdir1'], ['root', 'dir2', 'subdir1'], ['root', 'dir1', 'subdir2'], ['root', 'dir2', 'subdir2'], ['root', 'dir1', 'subdir1', 'subsubdir1'], ['root', 'dir2', 'subdir1', 'subsubdir1'], ['root', 'dir1', 'subdir3'], ['root', 'dir2', 'subdir3']]), [['root']])\n assert answers_match(candidate(paths=[['root'], ['root', 'child1'], ['root', 'child2'], ['root', 'child1', 'sub1'], ['root', 'child2', 'sub1'], ['root', 'child1', 'sub1', 'subsub1'], ['root', 'child2', 'sub1', 'subsub1'], ['root', 'child1', 'sub2'], ['root', 'child2', 'sub2'], ['root', 'child1', 'sub2', 'subsub2'], ['root', 'child2', 'sub2', 'subsub2'], ['root', 'child3'], ['root', 'child3', 'sub1'], ['root', 'child3', 'sub1', 'subsub1'], ['root', 'child3', 'sub2'], ['root', 'child3', 'sub2', 'subsub2']]), [['root']])\n assert answers_match(candidate(paths=[['home'], ['home', 'user1'], ['home', 'user1', 'documents'], ['home', 'user1', 'pictures'], ['home', 'user2'], ['home', 'user2', 'documents'], ['home', 'user2', 'pictures'], ['home', 'user3'], ['home', 'user3', 'documents'], ['home', 'user3', 'pictures'], ['home', 'user3', 'videos'], ['home', 'user4'], ['home', 'user4', 'documents'], ['home', 'user4', 'pictures'], ['home', 'user4', 'videos'], ['home', 'user5'], ['home', 'user5', 'documents'], ['home', 'user5', 'pictures'], ['home', 'user5', 'videos'], ['home', 'user6'], ['home', 'user6', 'documents'], ['home', 'user6', 'pictures'], ['home', 'user6', 'videos'], ['home', 'user6', 'music']]), [['home', 'user6', 'documents'], ['home', 'user6', 'music'], ['home', 'user6', 'pictures'], ['home', 'user6', 'videos'], ['home', 'user6'], ['home']])\n assert answers_match(candidate(paths=[['documents', 'work', 'reports'], ['documents', 'work', 'reports', 'monthly'], ['documents', 'work', 'reports', 'monthly', 'jan'], ['documents', 'work', 'reports', 'monthly', 'feb'], ['documents', 'work', 'reports', 'monthly', 'mar'], ['documents', 'home', 'reports'], ['documents', 'home', 'reports', 'monthly'], ['documents', 'home', 'reports', 'monthly', 'jan'], ['documents', 'home', 'reports', 'monthly', 'feb'], ['documents', 'home', 'reports', 'monthly', 'mar'], ['documents', 'finance', 'reports'], ['documents', 'finance', 'reports', 'monthly'], ['documents', 'finance', 'reports', 'monthly', 'jan'], ['documents', 'finance', 'reports', 'monthly', 'feb'], ['documents', 'finance', 'reports', 'monthly', 'mar']]), [['documents']])\n assert answers_match(candidate(paths=[['root', 'folder1', 'sub1'], ['root', 'folder2', 'sub1'], ['root', 'folder1', 'sub2'], ['root', 'folder2', 'sub2'], ['root', 'folder3', 'sub1'], ['root', 'folder4', 'sub1'], ['root', 'folder3', 'sub3'], ['root', 'folder4', 'sub3']]), [['root']])\n assert answers_match(candidate(paths=[['home', 'user1', 'docs', 'work'], ['home', 'user2', 'docs', 'work'], ['home', 'user1', 'docs', 'projects'], ['home', 'user2', 'docs', 'projects'], ['home', 'user1', 'downloads', 'movies'], ['home', 'user2', 'downloads', 'movies'], ['home', 'user1', 'downloads', 'music'], ['home', 'user2', 'downloads', 'music'], ['home', 'user1', 'pictures', 'vacation'], ['home', 'user2', 'pictures', 'vacation'], ['home', 'user1', 'pictures', 'wedding'], ['home', 'user2', 'pictures', 'wedding']]), [['home']])\n assert answers_match(candidate(paths=[['library'], ['library', 'section1'], ['library', 'section1', 'shelf1'], ['library', 'section1', 'shelf2'], ['library', 'section1', 'shelf3'], ['library', 'section2'], ['library', 'section2', 'shelf1'], ['library', 'section2', 'shelf2'], ['library', 'section2', 'shelf4'], ['library', 'section3'], ['library', 'section3', 'shelf3'], ['library', 'section3', 'shelf4'], ['library', 'section4'], ['library', 'section4', 'shelf5'], ['library', 'section4', 'shelf6'], ['library', 'section5'], ['library', 'section5', 'shelf5'], ['library', 'section5', 'shelf6'], ['library', 'section6'], ['library', 'section6', 'shelf7'], ['library', 'section6', 'shelf8'], ['library', 'section7'], ['library', 'section7', 'shelf9'], ['library', 'section7', 'shelf10']]), [['library', 'section1', 'shelf1'], ['library', 'section1', 'shelf2'], ['library', 'section1', 'shelf3'], ['library', 'section1'], ['library', 'section2', 'shelf1'], ['library', 'section2', 'shelf2'], ['library', 'section2', 'shelf4'], ['library', 'section2'], ['library', 'section3', 'shelf3'], ['library', 'section3', 'shelf4'], ['library', 'section3'], ['library', 'section6', 'shelf7'], ['library', 'section6', 'shelf8'], ['library', 'section6'], ['library', 'section7', 'shelf10'], ['library', 'section7', 'shelf9'], ['library', 'section7'], ['library']])\n assert answers_match(candidate(paths=[['home'], ['home', 'user1'], ['home', 'user2'], ['home', 'user1', 'documents'], ['home', 'user2', 'documents'], ['home', 'user1', 'pictures'], ['home', 'user2', 'pictures'], ['home', 'user1', 'documents', 'work'], ['home', 'user2', 'documents', 'work'], ['home', 'user1', 'documents', 'personal'], ['home', 'user2', 'documents', 'personal'], ['home', 'user1', 'pictures', 'vacation'], ['home', 'user2', 'pictures', 'vacation'], ['home', 'user1', 'pictures', 'travel'], ['home', 'user2', 'pictures', 'travel'], ['home', 'user1', 'pictures', 'travel', '2022'], ['home', 'user2', 'pictures', 'travel', '2022']]), [['home']])\n assert answers_match(candidate(paths=[['root'], ['root', 'dir1'], ['root', 'dir2'], ['root', 'dir1', 'dir3'], ['root', 'dir2', 'dir4'], ['root', 'dir2', 'dir3'], ['root', 'dir1', 'dir3', 'dir5'], ['root', 'dir2', 'dir3', 'dir5']]), [['root', 'dir1'], ['root', 'dir2', 'dir4'], ['root', 'dir2'], ['root']])\n", "comparison": "unordered"}, "public_tests": ["[[\"a\"],[\"c\"],[\"d\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"d\",\"a\"]]", "[[\"a\"],[\"c\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"a\",\"b\",\"x\"],[\"a\",\"b\",\"x\",\"y\"],[\"w\"],[\"w\",\"y\"]]", "[[\"a\",\"b\"],[\"c\",\"d\"],[\"c\"],[\"a\"]]"], "hints": ["Can we use a trie to build the folder structure?", "Can we utilize hashing to hash the folder structures?"], "metadata": {"canonical_parameter_names": ["paths"], "leetcode_dataset_entry_point": "Solution().deleteDuplicateFolder", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:01+00:00", "tests_total": 76, "tests_dropped": 8, "flags": ["any_order", "has_images"], "topic_tags": ["array", "hash-table", "string", "depth-first-search", "trie", "sorting", "hash-function"]}, "language": "php", "interface": {"raw_signature": "function deleteDuplicateFolder($paths) {", "container": "Solution", "callable": "deleteDuplicateFolder", "parameters": [{"name": "paths", "type": "String[][]"}], "return_type": "String[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1952, "task_id": "three-divisors", "difficulty": "Easy", "problem_description": "Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.\n\nAn integer m is a divisor of n if there exists an integer k such that n = k * m.\n\nExample 1:\n\nInput: n = 2\nOutput: false\nExplantion: 2 has only two divisors: 1 and 2.\n\nExample 2:\n\nInput: n = 4\nOutput: true\nExplantion: 4 has three divisors: 1, 2, and 4.\n\nConstraints:\n\n- 1 <= n <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 625) == False\n assert candidate(n = 3) == False\n assert candidate(n = 576) == False\n assert candidate(n = 729) == False\n assert candidate(n = 144) == False\n assert candidate(n = 49) == True\n assert candidate(n = 900) == False\n assert candidate(n = 324) == False\n assert candidate(n = 100) == False\n assert candidate(n = 841) == True\n assert candidate(n = 5) == False\n assert candidate(n = 289) == True\n assert candidate(n = 4) == True\n assert candidate(n = 64) == False\n assert candidate(n = 16) == False\n assert candidate(n = 10000) == False\n assert candidate(n = 484) == False\n assert candidate(n = 2) == False\n assert candidate(n = 225) == False\n assert candidate(n = 784) == False\n assert candidate(n = 1024) == False\n assert candidate(n = 101) == False\n assert candidate(n = 169) == True\n assert candidate(n = 256) == False\n assert candidate(n = 36) == False\n assert candidate(n = 529) == True\n assert candidate(n = 20) == False\n assert candidate(n = 676) == False\n assert candidate(n = 81) == False\n assert candidate(n = 15) == False\n assert candidate(n = 961) == True\n assert candidate(n = 400) == False\n assert candidate(n = 9) == True\n assert candidate(n = 196) == False\n assert candidate(n = 121) == True\n assert candidate(n = 361) == True\n assert candidate(n = 441) == False\n assert candidate(n = 7) == False\n assert candidate(n = 10) == False\n assert candidate(n = 25) == True\n assert candidate(n = 1089) == False\n assert candidate(n = 7225) == False\n assert candidate(n = 5929) == False\n assert candidate(n = 4761) == False\n assert candidate(n = 27) == False\n assert candidate(n = 6241) == True\n assert candidate(n = 8821) == False\n assert candidate(n = 2809) == True\n assert candidate(n = 1) == False\n assert candidate(n = 9604) == False\n assert candidate(n = 2601) == False\n assert candidate(n = 5329) == True\n assert candidate(n = 3025) == False\n assert candidate(n = 1009) == False\n assert candidate(n = 1681) == True\n assert candidate(n = 1225) == False\n assert candidate(n = 7921) == True\n assert candidate(n = 2401) == False\n assert candidate(n = 2025) == False\n assert candidate(n = 5625) == False\n assert candidate(n = 4489) == True\n assert candidate(n = 2209) == True\n assert candidate(n = 4225) == False\n assert candidate(n = 3969) == False\n assert candidate(n = 343) == False\n assert candidate(n = 6561) == False\n assert candidate(n = 5041) == True\n assert candidate(n = 8361) == False\n assert candidate(n = 1849) == True\n assert candidate(n = 3481) == True\n assert candidate(n = 6889) == True\n assert candidate(n = 1369) == True\n assert candidate(n = 7569) == False\n assert candidate(n = 3721) == True\n assert candidate(n = 3249) == False\n assert candidate(n = 9409) == True\n assert candidate(n = 9216) == False\n assert candidate(n = 1521) == False\n", "comparison": "exact"}, "public_tests": ["2", "4"], "hints": ["You can count the number of divisors and just check that they are 3", "Beware of the case of n equal 1 as some solutions might fail in it"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().isThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:06+00:00", "tests_total": 144, "tests_dropped": 66, "flags": [], "topic_tags": ["math", "enumeration", "number-theory", "prime-factorization", "sieve-theory"]}, "language": "php", "interface": {"raw_signature": "function isThree($n) {", "container": "Solution", "callable": "isThree", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1953, "task_id": "maximum-number-of-weeks-for-which-you-can-work", "difficulty": "Medium", "problem_description": "There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the i^th project has.\n\nYou can work on the projects following these two rules:\n\n- Every week, you will finish exactly one milestone of one project. You must work every week.\n- You cannot work on two milestones from the same project for two consecutive weeks.\n\nOnce all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will stop working. Note that you may not be able to finish every project's milestones due to these constraints.\n\nReturn the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.\n\nExample 1:\n\nInput: milestones = [1,2,3]\nOutput: 6\nExplanation: One possible scenario is:\n- During the 1^st week, you will work on a milestone of project 0.\n- During the 2^nd week, you will work on a milestone of project 2.\n- During the 3^rd week, you will work on a milestone of project 1.\n- During the 4^th week, you will work on a milestone of project 2.\n- During the 5^th week, you will work on a milestone of project 1.\n- During the 6^th week, you will work on a milestone of project 2.\nThe total number of weeks is 6.\n\nExample 2:\n\nInput: milestones = [5,2,1]\nOutput: 7\nExplanation: One possible scenario is:\n- During the 1^st week, you will work on a milestone of project 0.\n- During the 2^nd week, you will work on a milestone of project 1.\n- During the 3^rd week, you will work on a milestone of project 0.\n- During the 4^th week, you will work on a milestone of project 1.\n- During the 5^th week, you will work on a milestone of project 0.\n- During the 6^th week, you will work on a milestone of project 2.\n- During the 7^th week, you will work on a milestone of project 0.\nThe total number of weeks is 7.\nNote that you cannot work on the last milestone of project 0 on 8^th week because it would violate the rules.\nThus, one milestone in project 0 will remain unfinished.\n\nConstraints:\n\n- n == milestones.length\n- 1 <= n <= 10^5\n- 1 <= milestones[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(milestones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(milestones = [3, 3, 3]) == 9\n assert candidate(milestones = [1, 1, 1, 1, 1]) == 5\n assert candidate(milestones = [10, 5, 1]) == 13\n assert candidate(milestones = [1000000000, 1, 1]) == 5\n assert candidate(milestones = [1, 2, 3]) == 6\n assert candidate(milestones = [5, 2, 1]) == 7\n assert candidate(milestones = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(milestones = [1, 1, 1000000000]) == 5\n assert candidate(milestones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(milestones = [1]) == 1\n assert candidate(milestones = [1, 1000000000]) == 3\n assert candidate(milestones = [5, 5, 5, 5, 5, 5]) == 30\n assert candidate(milestones = [10, 1, 1]) == 5\n assert candidate(milestones = [1, 1000000000, 1]) == 5\n assert candidate(milestones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 1200\n assert candidate(milestones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(milestones = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 200\n assert candidate(milestones = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(milestones = [1000000000, 1000000000, 1000000000]) == 3000000000\n assert candidate(milestones = [5, 5, 5, 5, 5, 5, 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(milestones = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(milestones = [1000000000, 500000000, 100000000, 50000000, 10000000, 5000000, 1000000, 500000, 100000, 50000, 10000, 5000, 1000, 500, 100, 50, 10, 5, 1]) == 1333333333\n assert candidate(milestones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(milestones = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 10000\n assert candidate(milestones = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(milestones = [1000000000, 999999999, 1, 2, 3, 4, 5]) == 2000000014\n assert candidate(milestones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 120\n assert candidate(milestones = [100, 200, 300, 400]) == 1000\n assert candidate(milestones = [1000000000, 999999999, 888888888]) == 2888888887\n assert candidate(milestones = [1, 2, 3, 4, 5]) == 15\n assert candidate(milestones = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) == 1596\n assert candidate(milestones = [500000000, 500000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000000009\n assert candidate(milestones = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 1000\n assert candidate(milestones = [10, 10, 10, 10, 10, 10, 10, 10, 10, 100]) == 181\n assert candidate(milestones = [10, 10, 10, 10, 10]) == 50\n assert candidate(milestones = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 550\n assert candidate(milestones = [999999999, 1, 1, 1]) == 7\n assert candidate(milestones = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == 550000\n assert candidate(milestones = [1000000000, 1000000000, 1000000000, 1]) == 3000000001\n assert candidate(milestones = [10, 20, 30, 40, 50]) == 150\n assert candidate(milestones = [5, 5, 5, 5, 5, 5]) == 30\n assert candidate(milestones = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1]) == 5000000001\n assert candidate(milestones = [10, 20, 30, 40, 50]) == 150\n assert candidate(milestones = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(milestones = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(milestones = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1]) == 10000000001\n assert candidate(milestones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 64\n assert candidate(milestones = [100, 99, 98, 97, 96, 95]) == 585\n assert candidate(milestones = [999999999, 999999999, 1]) == 1999999999\n assert candidate(milestones = [1000000000, 500000000, 250000000, 125000000]) == 1750000001\n assert candidate(milestones = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 32767\n assert candidate(milestones = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 90\n assert candidate(milestones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 5500\n assert candidate(milestones = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 5500\n assert candidate(milestones = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990]) == 9999999945\n assert candidate(milestones = [100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 39\n assert candidate(milestones = [1000000000, 1000000000, 1000000000, 1000000000, 1]) == 4000000001\n assert candidate(milestones = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 101\n assert candidate(milestones = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 40\n assert candidate(milestones = [2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1]) == 35\n assert candidate(milestones = [500000000, 500000000, 1]) == 1000000001\n assert candidate(milestones = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 80\n assert candidate(milestones = [999999999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 39\n assert candidate(milestones = [100, 150, 200, 250]) == 700\n assert candidate(milestones = [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]) == 50\n assert candidate(milestones = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 77\n assert candidate(milestones = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 110\n assert candidate(milestones = [500, 400, 300, 200, 100, 50, 25, 12, 6, 3, 1]) == 1597\n assert candidate(milestones = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000]) == 4000000003\n assert candidate(milestones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(milestones = [500000000, 500000000, 500000000, 500000000]) == 2000000000\n assert candidate(milestones = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(milestones = [1, 2, 4, 8, 16, 32, 64]) == 127\n assert candidate(milestones = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711]) == 46365\n assert candidate(milestones = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120]) == 680\n assert candidate(milestones = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]) == 376\n assert candidate(milestones = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 30\n assert candidate(milestones = [333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333]) == 3333333330\n assert candidate(milestones = [100, 1, 100, 1, 100, 1]) == 303\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[5,2,1]"], "hints": ["Work on the project with the largest number of milestones as long as it is possible.", "Does the project with the largest number of milestones affect the number of weeks?"], "metadata": {"canonical_parameter_names": ["milestones"], "leetcode_dataset_entry_point": "Solution().numberOfWeeks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:09+00:00", "tests_total": 80, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function numberOfWeeks($milestones) {", "container": "Solution", "callable": "numberOfWeeks", "parameters": [{"name": "milestones", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1954, "task_id": "minimum-garden-perimeter-to-collect-enough-apples", "difficulty": "Medium", "problem_description": "In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.\n\nYou will buy an axis-aligned square plot of land that is centered at (0, 0).\n\nGiven an integer neededApples, return the minimum perimeter of a plot such that at least neededApples apples are inside or on the perimeter of that plot.\n\nThe value of |x| is defined as:\n\n- x if x >= 0\n- -x if x < 0\n\nExample 1:\n\nInput: neededApples = 1\nOutput: 8\nExplanation: A square plot of side length 1 does not contain any apples.\nHowever, a square plot of side length 2 has 12 apples inside (as depicted in the image above).\nThe perimeter is 2 * 4 = 8.\n\nExample 2:\n\nInput: neededApples = 13\nOutput: 16\n\nExample 3:\n\nInput: neededApples = 1000000000\nOutput: 5040\n\nConstraints:\n\n- 1 <= neededApples <= 10^15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(neededApples = 10000000000) == 10856\n assert candidate(neededApples = 10) == 8\n assert candidate(neededApples = 50) == 16\n assert candidate(neededApples = 1000000) == 504\n assert candidate(neededApples = 13) == 16\n assert candidate(neededApples = 1000000000) == 5040\n assert candidate(neededApples = 1000000000000000) == 503968\n assert candidate(neededApples = 1000) == 48\n assert candidate(neededApples = 987654321) == 5016\n assert candidate(neededApples = 1000000000000) == 50400\n assert candidate(neededApples = 999999999999999) == 503968\n assert candidate(neededApples = 100) == 24\n assert candidate(neededApples = 100000000) == 2336\n assert candidate(neededApples = 123456789) == 2512\n assert candidate(neededApples = 1) == 8\n assert candidate(neededApples = 2000000000) == 6352\n assert candidate(neededApples = 50000000000) == 18568\n assert candidate(neededApples = 123456789012345) == 250944\n assert candidate(neededApples = 1000000001) == 5040\n assert candidate(neededApples = 10000) == 112\n assert candidate(neededApples = 5000000000) == 8616\n assert candidate(neededApples = 50000) == 184\n assert candidate(neededApples = 120) == 24\n assert candidate(neededApples = 5) == 8\n assert candidate(neededApples = 6) == 8\n assert candidate(neededApples = 20) == 16\n assert candidate(neededApples = 2000000000000) == 63496\n assert candidate(neededApples = 100000000000) == 23392\n assert candidate(neededApples = 2147483647) == 6504\n assert candidate(neededApples = 100000) == 232\n assert candidate(neededApples = 123456789123) == 25096\n assert candidate(neededApples = 987654321987) == 50192\n assert candidate(neededApples = 2500000000) == 6840\n assert candidate(neededApples = 468) == 40\n assert candidate(neededApples = 500000000000) == 40000\n assert candidate(neededApples = 20736) == 136\n assert candidate(neededApples = 256) == 32\n assert candidate(neededApples = 500000000000000) == 400000\n assert candidate(neededApples = 111111111111111) == 242280\n assert candidate(neededApples = 8000000000) == 10080\n assert candidate(neededApples = 12) == 8\n assert candidate(neededApples = 122500) == 248\n assert candidate(neededApples = 25200) == 144\n assert candidate(neededApples = 598593750000) == 42472\n assert candidate(neededApples = 9261000) == 1056\n assert candidate(neededApples = 754321098) == 4584\n assert candidate(neededApples = 876543210987654) == 482312\n assert candidate(neededApples = 100000000000000) == 233920\n assert candidate(neededApples = 400000000000000) == 371328\n assert candidate(neededApples = 987654321098765) == 501888\n assert candidate(neededApples = 5000) == 88\n assert candidate(neededApples = 10000000000000) == 108576\n assert candidate(neededApples = 3500) == 80\n assert candidate(neededApples = 1024) == 48\n assert candidate(neededApples = 18) == 16\n assert candidate(neededApples = 30000000000000) == 156592\n assert candidate(neededApples = 2) == 8\n assert candidate(neededApples = 500) == 40\n assert candidate(neededApples = 4) == 8\n assert candidate(neededApples = 3) == 8\n assert candidate(neededApples = 4608) == 80\n", "comparison": "exact"}, "public_tests": ["1", "13", "1000000000"], "hints": ["Find a formula for the number of apples inside a square with a side length L.", "Iterate over the possible lengths of the square until enough apples are collected."], "metadata": {"canonical_parameter_names": ["neededApples"], "leetcode_dataset_entry_point": "Solution().minimumPerimeter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:11+00:00", "tests_total": 68, "tests_dropped": 7, "flags": ["figure_reference", "has_images"], "topic_tags": ["math", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function minimumPerimeter($neededApples) {", "container": "Solution", "callable": "minimumPerimeter", "parameters": [{"name": "neededApples", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1955, "task_id": "count-number-of-special-subsequences", "difficulty": "Hard", "problem_description": "A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s.\n\n- For example, [0,1,2] and [0,0,1,1,1,2] are special.\n- In contrast, [2,1,0], [1], and [0,1,2,0] are not special.\n\nGiven an array nums (consisting of only integers 0, 1, and 2), return the number of different subsequences that are special. Since the answer may be very large, return it modulo 10^9 + 7.\n\nA subsequence of an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences are different if the set of indices chosen are different.\n\nExample 1:\n\nInput: nums = [0,1,2,2]\nOutput: 3\nExplanation: The special subsequences are bolded [0,1,2,2], [0,1,2,2], and [0,1,2,2].\n\nExample 2:\n\nInput: nums = [2,2,0,0]\nOutput: 0\nExplanation: There are no special subsequences in [2,2,0,0].\n\nExample 3:\n\nInput: nums = [0,1,2,0,1,2]\nOutput: 7\nExplanation: The special subsequences are bolded:\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 2]) == 9\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 2]) == 21\n assert candidate(nums = [2, 2, 0, 0]) == 0\n assert candidate(nums = [0, 1, 2, 2]) == 3\n assert candidate(nums = [0, 1, 2, 2, 2]) == 7\n assert candidate(nums = [1, 2, 2, 0, 0, 1]) == 0\n assert candidate(nums = [0, 1, 2, 1, 2, 0, 1, 2]) == 19\n assert candidate(nums = [0, 1, 0, 1, 2]) == 5\n assert candidate(nums = [0, 1, 1, 1, 2, 2, 2]) == 49\n assert candidate(nums = [2, 1, 0, 1, 0, 2, 0]) == 1\n assert candidate(nums = [0, 1, 2, 0, 1, 0, 1, 2]) == 19\n assert candidate(nums = [2, 0, 1, 2, 0, 1, 2]) == 7\n assert candidate(nums = [2, 0, 1, 0, 1, 2]) == 5\n assert candidate(nums = [2, 0, 1, 0, 1, 2, 0, 1, 2]) == 27\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 2]) == 63\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 2, 0, 1, 2, 0]) == 7\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 2, 2]) == 51\n assert candidate(nums = [0, 1, 2, 0, 1, 2]) == 7\n assert candidate(nums = [0, 1, 2]) == 1\n assert candidate(nums = [0, 0, 1, 2, 1, 2]) == 15\n assert candidate(nums = [0, 0, 1, 1, 2, 2]) == 27\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 2, 2, 2]) == 119\n assert candidate(nums = [0, 0, 0, 1, 2, 2]) == 21\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2]) == 343\n assert candidate(nums = [0, 1, 0, 1, 2, 0, 1, 2]) == 27\n assert candidate(nums = [0, 1, 1, 2, 2, 2]) == 21\n assert candidate(nums = [1, 2, 0]) == 0\n assert candidate(nums = [2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2]) == 735\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, 1, 1, 1, 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]) == 375309442\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2]) == 21567\n assert candidate(nums = [0, 0, 0, 0, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2]) == 9975\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, 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]) == 554508028\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 25039\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 133432831\n assert candidate(nums = [0, 1, 0, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 207\n assert candidate(nums = [2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0]) == 351\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 14415\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]) == 2048383\n assert candidate(nums = [0, 1, 0, 2, 0, 1, 0, 2, 1, 2]) == 55\n assert candidate(nums = [0, 1, 1, 0, 2, 2, 1, 1, 0, 2, 0, 1, 2]) == 135\n assert candidate(nums = [0, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 6399\n assert candidate(nums = [2, 1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2]) == 735\n assert candidate(nums = [0, 1, 2, 2, 0, 1, 2, 2, 0, 1, 2, 2, 0, 1, 2, 2, 0, 1, 2, 2]) == 3519\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 14175\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 2, 0, 1, 2, 0, 1, 2]) == 2335\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 2]) == 3999\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 0, 1, 2, 2]) == 3279\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2]) == 1575\n assert candidate(nums = [2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0]) == 0\n assert candidate(nums = [0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2]) == 71\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2, 2]) == 1647\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 2]) == 423\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]) == 26775\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 29295\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 2, 2]) == 135\n assert candidate(nums = [2, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 0, 1, 2]) == 4047\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2]) == 31\n assert candidate(nums = [2, 2, 2, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 1023\n assert candidate(nums = [2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 70599160\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 2, 2, 0, 0, 1, 1, 2]) == 495\n assert candidate(nums = [0, 1, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2]) == 63\n assert candidate(nums = [0, 1, 1, 2, 0, 1, 2, 2, 1, 2, 0, 1, 2, 2, 1, 0, 1, 2, 2]) == 2847\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2]) == 675\n assert candidate(nums = [0, 1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 1, 2]) == 127\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]) == 1575\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 2, 2, 2, 2]) == 255\n assert candidate(nums = [2, 0, 0, 0, 1, 1, 1, 2, 2, 2]) == 343\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 250047\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2]) == 8575\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 2, 2]) == 651\n assert candidate(nums = [2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 18943\n assert candidate(nums = [0, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2]) == 4609\n assert candidate(nums = [0, 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]) == 534776319\n assert candidate(nums = [0, 1, 2, 0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 303\n assert candidate(nums = [0, 1, 1, 2, 2, 2, 2, 2, 0, 1, 2, 0, 1, 2, 2]) == 855\n assert candidate(nums = [2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 2815\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]) == 3375\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 4287\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 20223\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 2815\n assert candidate(nums = [2, 2, 0, 0, 0, 1, 1, 1, 2, 2]) == 147\n assert candidate(nums = [2, 0, 0, 1, 1, 1, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2]) == 1647\n assert candidate(nums = [0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 831\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 29791\n assert candidate(nums = [2, 2, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 451143\n assert candidate(nums = [2, 2, 2, 0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 335\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 1, 2, 0, 1, 2]) == 1855\n assert candidate(nums = [0, 1, 1, 1, 2, 2, 2, 2, 0, 1, 2]) == 227\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 1, 2]) == 1447\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2, 2, 2]) == 16095\n assert candidate(nums = [0, 1, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 7039\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 351\n assert candidate(nums = [0, 1, 2, 0, 0, 1, 1, 1, 2, 2, 0, 1, 2]) == 479\n assert candidate(nums = [2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 2943\n assert candidate(nums = [2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]) == 735\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 2, 2]) == 975\n assert candidate(nums = [2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 2, 2]) == 2239\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2]) == 6727\n assert candidate(nums = [0, 0, 0, 1, 2, 2, 2, 1, 1, 1, 0, 0, 0]) == 49\n assert candidate(nums = [0, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 783\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 704511\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 2]) == 527\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2, 2, 2]) == 28639\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2]) == 735\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2]) == 2943\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 2]) == 315\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 1323\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]) == 3375\n assert candidate(nums = [0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 1, 1, 1, 2, 2, 2]) == 3087\n assert candidate(nums = [0, 1, 2, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2]) == 167\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 351\n assert candidate(nums = [2, 1, 0, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2]) == 7423\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2]) == 4335\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 0, 1, 2]) == 3151\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 18943\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 274431\n assert candidate(nums = [0, 0, 1, 1, 2, 0, 1, 2, 0, 1, 2]) == 151\n assert candidate(nums = [0, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2]) == 3591\n assert candidate(nums = [2, 2, 2, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(nums = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 111\n assert candidate(nums = [0, 0, 0, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2]) == 3367\n", "comparison": "exact"}, "public_tests": ["[0,1,2,2]", "[2,2,0,0]", "[0,1,2,0,1,2]"], "hints": ["Can we first solve a simpler problem? Counting the number of subsequences with 1s followed by 0s.", "How can we keep track of the partially matched subsequences to help us find the answer?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countSpecialSubsequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:14+00:00", "tests_total": 128, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countSpecialSubsequences($nums) {", "container": "Solution", "callable": "countSpecialSubsequences", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1957, "task_id": "delete-characters-to-make-fancy-string", "difficulty": "Easy", "problem_description": "A fancy string is a string where no three consecutive characters are equal.\n\nGiven a string s, delete the minimum possible number of characters from s to make it fancy.\n\nReturn the final string after the deletion. It can be shown that the answer will always be unique.\n\nExample 1:\n\nInput: s = \"leeetcode\"\nOutput: \"leetcode\"\nExplanation:\nRemove an 'e' from the first group of 'e's to create \"leetcode\".\nNo three consecutive characters are equal, so return \"leetcode\".\n\nExample 2:\n\nInput: s = \"aaabaaaa\"\nOutput: \"aabaa\"\nExplanation:\nRemove an 'a' from the first group of 'a's to create \"aabaaaa\".\nRemove two 'a's from the second group of 'a's to create \"aabaa\".\nNo three consecutive characters are equal, so return \"aabaa\".\n\nExample 3:\n\nInput: s = \"aab\"\nOutput: \"aab\"\nExplanation: No three consecutive characters are equal, so return \"aab\".\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 = \"zzzzzzzzz\") == \"zz\"\n assert candidate(s = \"aaabbbccc\") == \"aabbcc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aabbaa\") == \"aabbaa\"\n assert candidate(s = \"leeetcode\") == \"leetcode\"\n assert candidate(s = \"aaaaa\") == \"aa\"\n assert candidate(s = \"ccccccaaa\") == \"ccaa\"\n assert candidate(s = \"aabbccddd\") == \"aabbccdd\"\n assert candidate(s = \"cccaaa\") == \"ccaa\"\n assert candidate(s = \"aaa\") == \"aa\"\n assert candidate(s = \"aababab\") == \"aababab\"\n assert candidate(s = \"aaaabbbcccaa\") == \"aabbccaa\"\n assert candidate(s = \"aaaabbbbcccc\") == \"aabbcc\"\n assert candidate(s = \"zzzzzzzzzz\") == \"zz\"\n assert candidate(s = \"ababababc\") == \"ababababc\"\n assert candidate(s = \"abacadaeafag\") == \"abacadaeafag\"\n assert candidate(s = \"abc\") == \"abc\"\n assert candidate(s = \"aabbaaabbbaaa\") == \"aabbaabbaa\"\n assert candidate(s = \"aab\") == \"aab\"\n assert candidate(s = \"aabbcc\") == \"aabbcc\"\n assert candidate(s = \"mississippi\") == \"mississippi\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"xyzzzxxzzzz\") == \"xyzzxxzz\"\n assert candidate(s = \"aaabaaaa\") == \"aabaa\"\n assert candidate(s = \"abcdefg\") == \"abcdefg\"\n assert candidate(s = \"aabbccddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwwwxxxxyyyzzz\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"abcabcabcabc\") == \"abcabcabcabc\"\n assert candidate(s = \"pppaaabbbcccddddeeeffffggghhhhiiiijjjjjkkkkklllllmmmmmnnnnnooooooopppppqqqqqrrrrrssssstttttuuuuuuvvvvvvvvvvwwwwwwxxxxxyyyyzzzzz\") == \"ppaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"xyzzzzzzzzzyx\") == \"xyzzyx\"\n assert candidate(s = \"mnonononojmnonononojmnonononoj\") == \"mnonononojmnonononojmnonononoj\"\n assert candidate(s = \"pppqqqrssstttuuuvvvwwwxxyyyzzz\") == \"ppqqrssttuuvvwwxxyyzz\"\n assert candidate(s = \"aabbccddeeefff\") == \"aabbccddeeff\"\n assert candidate(s = \"abcdefghijjjjjklmnopqrstuvwxyz\") == \"abcdefghijjklmnopqrstuvwxyz\"\n assert candidate(s = \"nnneennneennneennn\") == \"nneenneenneenn\"\n", "comparison": "exact"}, "public_tests": ["\"leeetcode\"", "\"aaabaaaa\"", "\"aab\""], "hints": ["What's the optimal way to delete characters if three or more consecutive characters are equal?", "If three or more consecutive characters are equal, keep two of them and delete the rest."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().makeFancyString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:19+00:00", "tests_total": 34, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function makeFancyString($s) {", "container": "Solution", "callable": "makeFancyString", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1959, "task_id": "minimum-total-space-wasted-with-k-resizing-operations", "difficulty": "Medium", "problem_description": "You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maximum number of times you can resize the array (to any size).\n\nThe size of the array at time t, size_t, must be at least nums[t] because there needs to be enough space in the array to hold all the elements. The space wasted at time t is defined as size_t - nums[t], and the total space wasted is the sum of the space wasted across every time t where 0 <= t < nums.length.\n\nReturn the minimum total space wasted if you can resize the array at most k times.\n\nNote: The array can have any size at the start and does not count towards the number of resizing operations.\n\nExample 1:\n\nInput: nums = [10,20], k = 0\nOutput: 10\nExplanation: size = [20,20].\nWe can set the initial size to be 20.\nThe total wasted space is (20 - 10) + (20 - 20) = 10.\n\nExample 2:\n\nInput: nums = [10,20,30], k = 1\nOutput: 10\nExplanation: size = [20,20,30].\nWe can set the initial size to be 20 and resize to 30 at time 2.\nThe total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.\n\nExample 3:\n\nInput: nums = [10,20,15,30,20], k = 2\nOutput: 15\nExplanation: size = [10,20,20,30,30].\nWe can set the initial size to 10, resize to 20 at time 1, and resize to 30 at time 3.\nThe total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15.\n\nConstraints:\n\n- 1 <= nums.length <= 200\n- 1 <= nums[i] <= 10^6\n- 0 <= k <= nums.length - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10, 10],k = 2) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 3) == 10\n assert candidate(nums = [10, 20, 30],k = 1) == 10\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],k = 0) == 45\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7],k = 3) == 3\n assert candidate(nums = [100, 200, 150, 300, 200, 350],k = 2) == 250\n assert candidate(nums = [10, 20, 15, 30, 20],k = 2) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 0) == 90\n assert candidate(nums = [1, 2, 3, 4, 5],k = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],k = 0) == 1000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 0) == 450\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500],k = 4) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 10\n assert candidate(nums = [5, 8, 6, 10],k = 1) == 5\n assert candidate(nums = [1, 3, 5, 7, 9],k = 4) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 9) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],k = 0) == 0\n assert candidate(nums = [1000000, 1000000, 1000000],k = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 40\n assert candidate(nums = [10, 20],k = 0) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 5\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 0\n assert candidate(nums = [20, 10, 30, 25, 40],k = 2) == 15\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 0) == 0\n assert candidate(nums = [20, 10, 30, 25, 15],k = 2) == 15\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 2) == 4\n assert candidate(nums = [300, 200, 100, 400, 300, 200, 500, 400, 300, 600, 500, 400, 700, 600, 500, 800, 700, 600, 900, 800, 700, 1000, 900, 800, 1100, 1000, 900, 1200, 1100, 1000, 1300, 1200, 1100, 1400, 1300, 1200, 1500, 1400, 1300, 1600, 1500, 1400, 1700, 1600, 1500, 1800, 1700, 1600, 1900, 1800, 1700, 2000, 1900, 1800, 2100, 2000, 1900, 2200, 2100, 2000, 2300, 2200, 2100, 2400, 2300, 2200],k = 30) == 4800\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 = 14) == 15\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 10) == 33\n assert candidate(nums = [3, 5, 4, 7, 8, 6, 9],k = 2) == 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],k = 10) == 18\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 120\n assert candidate(nums = [20, 15, 10, 5, 15, 20, 25, 30, 35, 40, 45, 50],k = 2) == 65\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 4) == 50\n assert candidate(nums = [300, 200, 100, 50, 25, 125, 62, 31, 15, 7, 3, 1],k = 5) == 186\n assert candidate(nums = [100, 200, 150, 300, 250, 350, 400],k = 2) == 250\n assert candidate(nums = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 50\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == 0\n assert candidate(nums = [10, 20, 30, 25, 40, 35, 50, 45, 60, 55],k = 4) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 0) == 190\n assert candidate(nums = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000],k = 9) == 5000\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, 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, 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, 500, 500, 500, 500, 500, 500, 500, 500],k = 0) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 3) == 30\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 4) == 90\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 5) == 24\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100],k = 9) == 495\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994],k = 3) == 3\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 0) == 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],k = 9) == 29\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 50\n assert candidate(nums = [20, 10, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110, 105],k = 3) == 215\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(nums = [100, 200, 150, 100, 300, 250, 200, 350, 400, 300],k = 3) == 450\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) == 1985\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 = 0) == 1900\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == 90\n assert candidate(nums = [1000000, 500000, 750000, 250000, 100000],k = 2) == 400000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 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 = 19) == 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 = 0) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 4) == 150\n assert candidate(nums = [10, 5, 15, 10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35, 45],k = 6) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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) == 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],k = 5) == 140629\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],k = 6) == 12\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 = 5) == 73729\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350],k = 2) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 0) == 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 = 5) == 120\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500],k = 2) == 450\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 = 5) == 80\n assert candidate(nums = [10, 20, 30, 20, 10, 40, 30, 20, 50, 40, 30, 20, 60, 50, 40, 30],k = 5) == 130\n assert candidate(nums = [200, 150, 100, 50, 150, 200, 250, 300, 350, 400],k = 3) == 350\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],k = 0) == 0\n assert candidate(nums = [500000, 400000, 300000, 200000, 100000, 100000, 200000, 300000, 400000, 500000, 100000, 200000, 300000, 400000, 500000, 100000, 200000, 300000, 400000, 500000],k = 7) == 1400000\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 5) == 81\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205],k = 7) == 160\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1],k = 10) == 3788\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],k = 5) == 0\n assert candidate(nums = [20, 10, 30, 5, 40, 25, 60, 35, 70, 45, 80, 55, 90, 65, 100, 75, 110, 85, 120, 95, 130, 105, 140, 115, 150, 125, 160, 135, 170, 145, 180, 155],k = 8) == 515\n assert candidate(nums = [10, 20, 10, 30, 10, 20, 30, 40, 50],k = 3) == 50\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],k = 100) == 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, 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],k = 25) == 48\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 10\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],k = 0) == 0\n assert candidate(nums = [100, 200, 150, 300, 250, 400],k = 2) == 200\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 9) == 45\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, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9],k = 25) == 119\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 = 15) == 140\n assert candidate(nums = [100, 200, 150, 100, 250, 200, 150, 300],k = 2) == 400\n assert candidate(nums = [200, 100, 200, 100, 200, 100, 200, 100, 200, 100],k = 4) == 300\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],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) == 90\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == 1200\n assert candidate(nums = [500, 400, 300, 200, 100, 50, 25, 10, 5, 2, 1, 1, 2, 5, 10, 25, 50, 100, 200, 300, 400, 500],k = 10) == 264\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) == 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) == 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],k = 10) == 90\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 7) == 16\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],k = 10) == 100\n assert candidate(nums = [10, 20, 15, 30, 20, 25, 35, 40, 45, 50],k = 4) == 30\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000],k = 5) == 9\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 0) == 450\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 6\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],k = 5) == 0\n assert candidate(nums = [20, 15, 10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85],k = 5) == 100\n assert candidate(nums = [1000, 2000, 1500, 3000, 2500, 4000, 3500, 5000, 4500, 6000],k = 5) == 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],k = 0) == 0\n assert candidate(nums = [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],k = 10) == 0\n", "comparison": "exact"}, "public_tests": ["[10,20]\n0", "[10,20,30]\n1", "[10,20,15,30,20]\n2"], "hints": ["Given a range, how can you find the minimum waste if you can't perform any resize operations?", "Can we build our solution using dynamic programming using the current index and the number of resizing operations performed as the states?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minSpaceWastedKResizing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:23+00:00", "tests_total": 120, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minSpaceWastedKResizing($nums, $k) {", "container": "Solution", "callable": "minSpaceWastedKResizing", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1960, "task_id": "maximum-product-of-the-length-of-two-palindromic-substrings", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string s and are tasked with finding two non-intersecting palindromic substrings of odd length such that the product of their lengths is maximized.\n\nMore formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.length and both the substrings s[i...j] and s[k...l] are palindromes and have odd lengths. s[i...j] denotes a substring from index i to index j inclusive.\n\nReturn the maximum possible product of the lengths of the two non-intersecting palindromic substrings.\n\nA palindrome is a string that is the same forward and backward. A substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"ababbb\"\nOutput: 9\nExplanation: Substrings \"aba\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.\n\nExample 2:\n\nInput: s = \"zaaaxbbby\"\nOutput: 9\nExplanation: Substrings \"aaa\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.\n\nConstraints:\n\n- 2 <= s.length <= 10^5\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"mnoonmmon\") == 1\n assert candidate(s = \"mamadmim\") == 9\n assert candidate(s = \"abcdcba\") == 5\n assert candidate(s = \"abcdedcba\") == 7\n assert candidate(s = \"mamad\") == 3\n assert candidate(s = \"aaaaa\") == 3\n assert candidate(s = \"abcdefghi\") == 1\n assert candidate(s = \"abacdfgdcaba\") == 9\n assert candidate(s = \"zaaaxbbby\") == 9\n assert candidate(s = \"noonnoon\") == 1\n assert candidate(s = \"abcde\") == 1\n assert candidate(s = \"racecar\") == 5\n assert candidate(s = \"abcdeedcba\") == 1\n assert candidate(s = \"banana\") == 5\n assert candidate(s = \"ababbb\") == 9\n assert candidate(s = \"abc\") == 1\n assert candidate(s = \"abcbabcbabcba\") == 35\n assert candidate(s = \"abcdefgh\") == 1\n assert candidate(s = \"abcd\") == 1\n assert candidate(s = \"mississippi\") == 7\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 1\n assert candidate(s = \"mnoonmnonoomnm\") == 15\n assert candidate(s = \"abcdefg\") == 1\n assert candidate(s = \"aabbccddeeeffgg\") == 3\n assert candidate(s = \"abccbaabccbaabccbaabccba\") == 1\n assert candidate(s = \"aaaaaabbaaaaa\") == 25\n assert candidate(s = \"nunrunrunrun\") == 3\n assert candidate(s = \"abaaacbaaaaba\") == 9\n assert candidate(s = \"racecarlevelnoonracecar\") == 49\n assert candidate(s = \"deeeeefedeeeed\") == 15\n assert candidate(s = \"rotorrotor\") == 25\n assert candidate(s = \"abracadabra\") == 3\n assert candidate(s = \"abcabcabcabc\") == 1\n assert candidate(s = \"abcbaacbabcba\") == 25\n assert candidate(s = \"abcbacbacbacb\") == 5\n assert candidate(s = \"tattarrattat\") == 9\n assert candidate(s = \"repaperrelevelrepeepr\") == 35\n assert candidate(s = \"babadabababa\") == 25\n assert candidate(s = \"madaminnadammadam\") == 25\n assert candidate(s = \"abccbaabcdcba\") == 7\n assert candidate(s = \"aabaaaabaaaabaa\") == 25\n assert candidate(s = \"abcdeffedcbaffedcba\") == 1\n assert candidate(s = \"abccbaabccba\") == 1\n assert candidate(s = \"xyzabcbaedcbaxyz\") == 5\n assert candidate(s = \"levellevellevellevel\") == 75\n assert candidate(s = \"noonnoonnoonnoon\") == 1\n assert candidate(s = \"mississippimississippi\") == 49\n assert candidate(s = \"xyzxyzxyzxyz\") == 1\n assert candidate(s = \"abacdfgdcabaxyzzyzyzyzyzx\") == 27\n assert candidate(s = \"aabbbaabbbaabbbaaa\") == 49\n assert candidate(s = \"abacadaeafagahagaha\") == 21\n assert candidate(s = \"noonracecarnoon\") == 13\n assert candidate(s = \"aabbbaaabbbaaabbbaaabbbaaabbba\") == 221\n assert candidate(s = \"ababababababababa\") == 63\n assert candidate(s = \"abacabaabacabaabacaba\") == 49\n assert candidate(s = \"repel\") == 3\n assert candidate(s = \"levelnoonlevel\") == 25\n assert candidate(s = \"rotorlevelmadamracecar\") == 35\n assert candidate(s = \"noonnoonnoonnoonnoonnoon\") == 1\n assert candidate(s = \"kayak\") == 3\n assert candidate(s = \"mnopqrstuvuvwxyzyx\") == 15\n assert candidate(s = \"madamlevelmadam\") == 25\n assert candidate(s = \"babcbabcbabcba\") == 35\n assert candidate(s = \"abacadaeafagaha\") == 9\n assert candidate(s = \"leveloneleveleleveldoneleveldot\") == 55\n assert candidate(s = \"xyzzzzyzyzyzx\") == 21\n assert candidate(s = \"madaminnadam\") == 15\n assert candidate(s = \"abababababababab\") == 63\n assert candidate(s = \"racecarabcdeedcbacar\") == 21\n assert candidate(s = \"noon\") == 1\n assert candidate(s = \"abcbacbacb\") == 5\n assert candidate(s = \"ababababababababab\") == 81\n assert candidate(s = \"deeee\") == 3\n assert candidate(s = \"leveloneleveltwo\") == 25\n assert candidate(s = \"abcabcabcabcabcabc\") == 1\n assert candidate(s = \"xyzbcbzxyxzyzyzyz\") == 35\n assert candidate(s = \"abcdefggfedcba\") == 1\n assert candidate(s = \"aaaaabbbbbbaaaa\") == 25\n assert candidate(s = \"abcdeffedcba\") == 1\n assert candidate(s = \"ababcbaababcbaababcba\") == 25\n assert candidate(s = \"babcbabcbabcbabcbabcbabcbabcbabcbabcbabcba\") == 399\n assert candidate(s = \"ababaababaababa\") == 27\n assert candidate(s = \"abcbabcbaabcbabcba\") == 81\n assert candidate(s = \"mmabccbaakak\") == 3\n assert candidate(s = \"abcdefedcba\") == 9\n assert candidate(s = \"palindromeemordnilap\") == 1\n assert candidate(s = \"level\") == 3\n assert candidate(s = \"racecarlevelracecar\") == 49\n assert candidate(s = \"levellevellevel\") == 25\n assert candidate(s = \"aaaaabaaaaabaaaaabaaaaab\") == 143\n assert candidate(s = \"xyxzyxzyxzyx\") == 3\n assert candidate(s = \"nunabannun\") == 15\n assert candidate(s = \"deeeeefeeeed\") == 15\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzz\") == 143\n assert candidate(s = \"abababababababababab\") == 99\n assert candidate(s = \"madamimadamracecar\") == 77\n assert candidate(s = \"abbbbabbbaaaaaaaabbba\") == 49\n assert candidate(s = \"radar\") == 3\n assert candidate(s = \"abababa\") == 9\n assert candidate(s = \"abacabadabacaba\") == 49\n assert candidate(s = \"abacabadabacabada\") == 63\n assert candidate(s = \"bananaananab\") == 25\n assert candidate(s = \"aabbccddeeefffggg\") == 9\n assert candidate(s = \"redivider\") == 7\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 99\n assert candidate(s = \"abcabccbaabcabccba\") == 1\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 1\n assert candidate(s = \"deedlevel\") == 5\n assert candidate(s = \"abcbabcba\") == 15\n assert candidate(s = \"deifiedrotatordeified\") == 49\n assert candidate(s = \"noonnoonnoonnoonnoon\") == 1\n assert candidate(s = \"abcbadefgfe\") == 25\n assert candidate(s = \"anana\") == 3\n assert candidate(s = \"ababaabababababa\") == 55\n assert candidate(s = \"abracadabraabracadabra\") == 9\n assert candidate(s = \"detartrated\") == 9\n assert candidate(s = \"manamzzamanaplanacanalpanamazzamanaplanacanalpanamazzzzzz\") == 529\n assert candidate(s = \"xyxyxyxyxyxyxyxyx\") == 63\n assert candidate(s = \"madamimadam\") == 25\n assert candidate(s = \"levelonelevelonelevel\") == 25\n assert candidate(s = \"madamracecaramadam\") == 35\n assert candidate(s = \"aaabbaaabbaaa\") == 21\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"xylophonepiponolyx\") == 9\n assert candidate(s = \"racecarandracecar\") == 49\n assert candidate(s = \"aabaaaabaaba\") == 25\n assert candidate(s = \"racecarannakayak\") == 35\n assert candidate(s = \"kayakkayakkayakkayak\") == 75\n assert candidate(s = \"aaaaabbbbbaaaaa\") == 27\n assert candidate(s = \"mammadmooommom\") == 15\n assert candidate(s = \"aaaaabbbbbaaaaaabbbbaaaaa\") == 75\n assert candidate(s = \"racecarracecar\") == 49\n assert candidate(s = \"noonnoonnoon\") == 1\n assert candidate(s = \"repaper\") == 5\n assert candidate(s = \"racecarlevelrotorkayak\") == 35\n assert candidate(s = \"rotorrotorrotor\") == 25\n assert candidate(s = \"aaaaabaaabaaaabaaaaabaaaa\") == 99\n assert candidate(s = \"ababaababab\") == 25\n assert candidate(s = \"noonhighnoon\") == 1\n assert candidate(s = \"tacocattacocattaco\") == 49\n assert candidate(s = \"rotorrotorrotorrotor\") == 75\n assert candidate(s = \"bananaananananab\") == 45\n assert candidate(s = \"zzzyzyzyzyzyzyzyzyzyzyzyz\") == 121\n assert candidate(s = \"deeddeeddeed\") == 1\n assert candidate(s = \"aaaaaabbbbbaaaa\") == 35\n assert candidate(s = \"rotorresistor\") == 15\n assert candidate(s = \"xylophonelevel\") == 5\n assert candidate(s = \"aaabaaaabaaaaabaaaaaaab\") == 77\n assert candidate(s = \"aabbccddeeefffgggzzzzzzzzzzzzzzzzzzzz\") == 99\n assert candidate(s = \"abcdedcbaabcdedcbaabcdedcba\") == 81\n assert candidate(s = \"civic\") == 3\n assert candidate(s = \"rotor\") == 3\n assert candidate(s = \"qwertyuioplkjhgfdsazxcvbnmnbvcxzasdfghjklpoiuytrewq\") == 49\n assert candidate(s = \"abbaabbbaabba\") == 11\n assert candidate(s = \"abcdefghihgfedcba\") == 15\n assert candidate(s = \"tacocattaco\") == 7\n assert candidate(s = \"repaperrepaperrepaper\") == 49\n assert candidate(s = \"aabaaaabaa\") == 25\n assert candidate(s = \"reviled\") == 1\n assert candidate(s = \"amoreroma\") == 7\n assert candidate(s = \"aabbccddeeefffggghhhiiiijjjjkkkkllllmmmnnnooopppqqqqrrrrssssttttuuuuvvvvwwwwwxxxxxyyyyyzzzzzzyyyyyxxxwwvvuuttrrqqppoonnmlkkjjiihhggffeeddccbbaa\") == 25\n assert candidate(s = \"xyzyzyzyzyzyzyzyz\") == 63\n assert candidate(s = \"xyxzyzyzyzyzyzyx\") == 35\n assert candidate(s = \"zzzzzzyyyyyxxxwwvvuuttrrqqppoonnmlkkjjiihhggffeeddccbbaa\") == 25\n assert candidate(s = \"rotorabcdrotor\") == 25\n assert candidate(s = \"aabbccddeeeffgghhiii\") == 9\n assert candidate(s = \"abcdedcbabcdedcbabcdedcb\") == 135\n assert candidate(s = \"aabbccddeeefffggghhhiiiijjjjkkkkllllmmmnnnooopppqqqqrrrrssssttttuuuuvvvvwwwwwxxxxxyyyyyzzzzz\") == 25\n assert candidate(s = \"abcabcabcabcabc\") == 1\n assert candidate(s = \"deed\") == 1\n assert candidate(s = \"aaaaabbbbbbaaaaa\") == 25\n assert candidate(s = \"levelwasracecar\") == 35\n assert candidate(s = \"racecarabcdeedcba\") == 9\n", "comparison": "exact"}, "public_tests": ["\"ababbb\"", "\"zaaaxbbby\""], "hints": ["You can use Manacher's algorithm to get the maximum palindromic substring centered at each index", "After using Manacher's for each center use a line sweep from the center to the left and from the center to the right to find for each index the farthest center to it with distance ≤ palin[center]", "After that, find the maximum palindrome size for each prefix in the string and for each suffix and the answer would be max(prefix[i] * suffix[i + 1])"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maxProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:25+00:00", "tests_total": 173, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "rolling-hash", "hash-function", "manacher", "palindromic-tree"]}, "language": "php", "interface": {"raw_signature": "function maxProduct($s) {", "container": "Solution", "callable": "maxProduct", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1961, "task_id": "check-if-string-is-a-prefix-of-array", "difficulty": "Easy", "problem_description": "Given a string s and an array of strings words, determine whether s is a prefix string of words.\n\nA string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive k no larger than words.length.\n\nReturn true if s is a prefix string of words, or false otherwise.\n\nExample 1:\n\nInput: s = \"iloveleetcode\", words = [\"i\",\"love\",\"leetcode\",\"apples\"]\nOutput: true\nExplanation:\ns can be made by concatenating \"i\", \"love\", and \"leetcode\" together.\n\nExample 2:\n\nInput: s = \"iloveleetcode\", words = [\"apples\",\"i\",\"love\",\"leetcode\"]\nOutput: false\nExplanation:\nIt is impossible to make s using a prefix of arr.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 20\n- 1 <= s.length <= 1000\n- words[i] and s consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaa\",words = ['aa', 'aa']) == True\n assert candidate(s = \"hello\",words = ['he', 'll', 'o']) == True\n assert candidate(s = \"abc\",words = ['a']) == False\n assert candidate(s = \"abc\",words = ['a', 'bc']) == True\n assert candidate(s = \"a\",words = ['a', 'b', 'c']) == True\n assert candidate(s = \"abcd\",words = ['a', 'bcd']) == True\n assert candidate(s = \"cat\",words = ['ca', 't']) == True\n assert candidate(s = \"abcd\",words = ['abc', 'd']) == True\n assert candidate(s = \"hello\",words = ['he', 'l', 'lo']) == True\n assert candidate(s = \"abc\",words = ['ab', 'c']) == True\n assert candidate(s = \"iloveleetcode\",words = ['apples', 'i', 'love', 'leetcode']) == False\n assert candidate(s = \"hello\",words = ['he', 'llo']) == True\n assert candidate(s = \"abcd\",words = ['a', 'b', 'c', 'd']) == True\n assert candidate(s = \"abcd\",words = ['ab', 'cd']) == True\n assert candidate(s = \"abcd\",words = ['abcd']) == True\n assert candidate(s = \"iloveleetcode\",words = ['i', 'love', 'leetcode', 'apples']) == True\n assert candidate(s = \"xyz\",words = ['x', 'y', 'z']) == True\n assert candidate(s = \"abc\",words = ['a', 'b', 'c']) == True\n assert candidate(s = \"abcd\",words = ['abc']) == False\n assert candidate(s = \"complexprefixstring\",words = ['complex', 'prefix', 'string', 'extra']) == True\n assert candidate(s = \"aquickbrownfox\",words = ['a', 'quick', 'brown', 'fox', 'jumps']) == True\n assert candidate(s = \"onetwothree\",words = ['one', 'two', 'three', 'four', 'five']) == True\n assert candidate(s = \"algorithm\",words = ['algo', 'r', 'ith', 'm']) == True\n assert candidate(s = \"python\",words = ['py', 'th', 'on', 'n']) == True\n assert candidate(s = \"complexprefix\",words = ['com', 'ple', 'xpre', 'fix']) == True\n assert candidate(s = \"concatenate\",words = ['con', 'cat', 'en', 'ate']) == True\n assert candidate(s = \"algorithms\",words = ['algo', 'rithm', 's', 'data']) == True\n assert candidate(s = \"abracadabra\",words = ['abra', 'ca', 'da', 'bra', 'bra']) == True\n assert candidate(s = \"substring\",words = ['sub', 'str', 'ing', 'example']) == True\n assert candidate(s = \"onetwothreefour\",words = ['one', 'two', 'three', 'four', 'five']) == True\n assert candidate(s = \"xyz\",words = ['x', 'y', 'z', 'w']) == True\n assert candidate(s = \"prefixstring\",words = ['pre', 'fix', 'string']) == True\n assert candidate(s = \"programming\",words = ['pro', 'gram', 'ming']) == True\n assert candidate(s = \"concatenate\",words = ['con', 'cat', 'e', 'nate']) == True\n assert candidate(s = \"thisisatest\",words = ['this', 'is', 'a', 'test', 'case']) == True\n assert candidate(s = \"substring\",words = ['sub', 'string', 'abc']) == True\n assert candidate(s = \"mississippi\",words = ['mis', 'si', 'ssippi', 'p']) == True\n assert candidate(s = \"prefixprefix\",words = ['pre', 'fix', 'pre', 'fix', 'pre', 'fix']) == True\n assert candidate(s = \"abcdef\",words = ['a', 'b', 'c', 'def', 'ghi']) == True\n assert candidate(s = \"thisisatest\",words = ['this', 'is', 'a', 'test', 'case']) == True\n assert candidate(s = \"abcdefg\",words = ['a', 'b', 'c', 'd', 'e', 'f', 'g']) == True\n assert candidate(s = \"aaabbbccc\",words = ['aaa', 'bbb', 'ccc', 'ddd']) == True\n assert candidate(s = \"hello\",words = ['h', 'he', 'hel', 'hell', 'hello']) == False\n assert candidate(s = \"abcdabc\",words = ['ab', 'c', 'd', 'abc', 'def']) == True\n assert candidate(s = \"complexstring\",words = ['com', 'plex', 'string', 'other']) == True\n assert candidate(s = \"abcdefghijk\",words = ['abcd', 'ef', 'gh', 'ijk']) == True\n assert candidate(s = \"uniqueprefix\",words = ['unique', 'prefix', 'not']) == True\n assert candidate(s = \"prefix\",words = ['pre', 'fix', 'e', 'f', 'g']) == True\n assert candidate(s = \"oneonetwo\",words = ['one', 'one', 'two', 'three']) == True\n assert candidate(s = \"xyzzy\",words = ['xy', 'zz', 'y', 'z']) == True\n assert candidate(s = \"partialmatch\",words = ['partial', 'non', 'matching', 'words']) == False\n assert candidate(s = \"prefixmatching\",words = ['pre', 'fix', 'mat', 'ching']) == True\n assert candidate(s = \"overlapexample\",words = ['over', 'lap', 'ex', 'ample']) == True\n assert candidate(s = \"boundary\",words = ['bound', 'ary', 'extra']) == True\n assert candidate(s = \"partialmatch\",words = ['par', 'tial', 'match', 'nomatch']) == True\n assert candidate(s = \"abcdabcd\",words = ['abcd', 'abcd', 'abcd']) == True\n assert candidate(s = \"oneonetwo\",words = ['one', 'one', 'two', 'three']) == True\n assert candidate(s = \"abcdefghij\",words = ['abc', 'def', 'ghi', 'j']) == True\n assert candidate(s = \"mississippi\",words = ['mis', 'si', 'ss', 'ippi']) == True\n assert candidate(s = \"matchmaking\",words = ['mat', 'ch', 'mak', 'ing']) == True\n assert candidate(s = \"abcdefg\",words = ['a', 'bc', 'de', 'fg', 'xyz']) == True\n assert candidate(s = \"prefix\",words = ['pre', 'fix', 'ed', 'abc']) == True\n assert candidate(s = \"prefix\",words = ['pre', 'fix', 'post']) == True\n assert candidate(s = \"mnopqr\",words = ['mn', 'op', 'qr', 'st']) == True\n assert candidate(s = \"programminglanguage\",words = ['pro', 'gram', 'ming', 'lan', 'guage']) == True\n assert candidate(s = \"hellohello\",words = ['hello', 'hello', 'world']) == True\n assert candidate(s = \"prefixstring\",words = ['pre', 'fix', 'str', 'ing']) == True\n assert candidate(s = \"hellothere\",words = ['he', 'll', 'o', 'there']) == True\n assert candidate(s = \"concatenation\",words = ['con', 'cat', 'en', 'ation']) == True\n assert candidate(s = \"hellohello\",words = ['hello', 'hello', 'hello']) == True\n assert candidate(s = \"hello\",words = ['h', 'e', 'l', 'l', 'o', 'world']) == True\n assert candidate(s = \"quickbrownfox\",words = ['quick', 'brown', 'fox', 'jump']) == True\n assert candidate(s = \"abcdefghi\",words = ['abc', 'def', 'ghi', 'jkl']) == True\n assert candidate(s = \"one\",words = ['on', 'e', 'extra']) == True\n assert candidate(s = \"notprefix\",words = ['prefix', 'not']) == False\n assert candidate(s = \"abcdefgh\",words = ['a', 'bc', 'def', 'gh']) == True\n assert candidate(s = \"prefixstring\",words = ['prefix', 'string', 'extra']) == True\n assert candidate(s = \"prefix\",words = ['pre', 'fi', 'x']) == True\n assert candidate(s = \"longword\",words = ['lo', 'ng', 'wor', 'd']) == True\n assert candidate(s = \"xxyyyzzz\",words = ['xx', 'yyy', 'zzz', 'a']) == True\n assert candidate(s = \"concatenation\",words = ['con', 'cat', 'en', 'ation']) == True\n assert candidate(s = \"unique\",words = ['un', 'iq', 'ue']) == True\n assert candidate(s = \"abcdefghij\",words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == True\n assert candidate(s = \"algorithm\",words = ['algo', 'r', 'ith', 'm']) == True\n assert candidate(s = \"variouslengths\",words = ['vari', 'ous', 'length', 's']) == True\n assert candidate(s = \"two\",words = ['tw', 'o', 'tw', 'o']) == True\n assert candidate(s = \"abcdabcd\",words = ['abc', 'd', 'abcd']) == True\n assert candidate(s = \"wordplay\",words = ['word', 'play', 'game', 'time']) == True\n assert candidate(s = \"programming\",words = ['pro', 'gram', 'ming', 'lang']) == True\n assert candidate(s = \"concatenation\",words = ['con', 'cat', 'enation', 'ation']) == True\n assert candidate(s = \"supercalifragilisticexpialidocious\",words = ['super', 'cali', 'fragilistic', 'expiali', 'docious']) == True\n assert candidate(s = \"abcdefghij\",words = ['a', 'bc', 'de', 'fghi', 'j']) == True\n assert candidate(s = \"algorithm\",words = ['algo', 'rith', 'm']) == True\n assert candidate(s = \"testcase\",words = ['tes', 't', 'ca', 'se']) == True\n assert candidate(s = \"concatenation\",words = ['con', 'cat', 'e', 'na', 'tion']) == True\n assert candidate(s = \"abcdefghij\",words = ['abc', 'def', 'ghi', 'j']) == True\n assert candidate(s = \"xyz\",words = ['x', 'y', 'z', 'a', 'b', 'c']) == True\n assert candidate(s = \"prefixtest\",words = ['pre', 'fix', 'test', 'suffix']) == True\n assert candidate(s = \"repeated\",words = ['rep', 'e', 'ated']) == True\n assert candidate(s = \"matchingprefix\",words = ['matching', 'prefix', 'matching', 'prefix']) == True\n assert candidate(s = \"abcdexyz\",words = ['abc', 'de', 'xyz', 'mnop']) == True\n assert candidate(s = \"aabbccdd\",words = ['aa', 'bb', 'cc', 'd', 'd']) == True\n assert candidate(s = \"abcdef\",words = ['a', 'b', 'c', 'def']) == True\n assert candidate(s = \"programmingisfun\",words = ['pro', 'gram', 'ming', 'is', 'fun']) == True\n assert candidate(s = \"short\",words = ['shor', 't']) == True\n assert candidate(s = \"mississippi\",words = ['mis', 'si', 's', 'ip', 'pi']) == False\n assert candidate(s = \"repeatedword\",words = ['repeated', 'word', 'repeated']) == True\n assert candidate(s = \"rapiddevelopment\",words = ['rap', 'id', 'devel', 'op', 'ment']) == True\n assert candidate(s = \"onetwothree\",words = ['one', 'two', 'three', 'four']) == True\n assert candidate(s = \"interviewquestion\",words = ['inter', 'view', 'quest', 'ion']) == True\n assert candidate(s = \"abcdabcd\",words = ['abcd', 'abcd']) == True\n assert candidate(s = \"longstring\",words = ['long', 'string', 'extrastuff']) == True\n assert candidate(s = \"xyz\",words = ['xy', 'z', 'a', 'b']) == True\n assert candidate(s = \"thisisatest\",words = ['this', 'is', 'a', 'test']) == True\n assert candidate(s = \"abcdefg\",words = ['abc', 'def', 'g', 'h']) == True\n assert candidate(s = \"hellothere\",words = ['he', 'll', 'ot', 'her', 'e']) == True\n assert candidate(s = \"buildingblocks\",words = ['building', 'block', 's']) == True\n assert candidate(s = \"abcdefghij\",words = ['abc', 'de', 'f', 'gh', 'ij']) == True\n assert candidate(s = \"prefixmatch\",words = ['prefix', 'ma', 'tch']) == True\n assert candidate(s = \"python\",words = ['py', 'th', 'on', 'o']) == True\n assert candidate(s = \"python\",words = ['py', 't', 'h', 'o', 'n', 'extra']) == True\n assert candidate(s = \"aabbcc\",words = ['aa', 'bb', 'cc', 'dd']) == True\n assert candidate(s = \"abacax\",words = ['aba', 'c', 'ax', 'a']) == True\n assert candidate(s = \"aabbcc\",words = ['aa', 'bb', 'cc', 'dd']) == True\n", "comparison": "exact"}, "public_tests": ["\"iloveleetcode\"\n[\"i\",\"love\",\"leetcode\",\"apples\"]", "\"iloveleetcode\"\n[\"apples\",\"i\",\"love\",\"leetcode\"]"], "hints": ["There are only words.length prefix strings.", "Create all of them and see if s is one of them."], "metadata": {"canonical_parameter_names": ["s", "words"], "leetcode_dataset_entry_point": "Solution().isPrefixString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:27+00:00", "tests_total": 125, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function isPrefixString($s, $words) {", "container": "Solution", "callable": "isPrefixString", "parameters": [{"name": "s", "type": "String"}, {"name": "words", "type": "String[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1962, "task_id": "remove-stones-to-minimize-the-total", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the i^th pile, and an integer k. You should apply the following operation exactly k times:\n\n- Choose any piles[i] and remove floor(piles[i] / 2) stones from it.\n\nNotice that you can apply the operation on the same pile more than once.\n\nReturn the minimum possible total number of stones remaining after applying the k operations.\n\nfloor(x) is the largest integer that is smaller than or equal to x (i.e., rounds x down).\n\nExample 1:\n\nInput: piles = [5,4,9], k = 2\nOutput: 12\nExplanation: Steps of a possible scenario are:\n- Apply the operation on pile 2. The resulting piles are [5,4,5].\n- Apply the operation on pile 0. The resulting piles are [3,4,5].\nThe total number of stones in [3,4,5] is 12.\n\nExample 2:\n\nInput: piles = [4,3,6,7], k = 3\nOutput: 12\nExplanation: Steps of a possible scenario are:\n- Apply the operation on pile 2. The resulting piles are [4,3,3,7].\n- Apply the operation on pile 3. The resulting piles are [4,3,3,4].\n- Apply the operation on pile 0. The resulting piles are [2,3,3,4].\nThe total number of stones in [2,3,3,4] is 12.\n\nConstraints:\n\n- 1 <= piles.length <= 10^5\n- 1 <= piles[i] <= 10^4\n- 1 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(piles = [1, 2, 3, 4, 5],k = 10) == 5\n assert candidate(piles = [10, 10, 10, 10],k = 4) == 20\n assert candidate(piles = [5, 4, 9],k = 2) == 12\n assert candidate(piles = [10, 10, 10],k = 1) == 25\n assert candidate(piles = [100, 200, 300],k = 10) == 57\n assert candidate(piles = [4, 3, 6, 7],k = 3) == 12\n assert candidate(piles = [100, 200, 300],k = 1) == 450\n assert candidate(piles = [10000, 10000, 10000],k = 10000) == 3\n assert candidate(piles = [100, 200, 300],k = 2) == 350\n assert candidate(piles = [100, 100, 100],k = 10) == 33\n assert candidate(piles = [1],k = 1) == 1\n assert candidate(piles = [10000, 10000, 10000],k = 10000) == 3\n assert candidate(piles = [10, 10, 10],k = 5) == 11\n assert candidate(piles = [1, 2, 3, 4, 5],k = 5) == 8\n assert candidate(piles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 15\n assert candidate(piles = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111, 1],k = 100) == 25\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000],k = 25000) == 5\n assert candidate(piles = [1000, 500, 250, 125],k = 10) == 252\n assert candidate(piles = [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(piles = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],k = 100) == 10\n assert candidate(piles = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 50) == 1441\n assert candidate(piles = [9999, 9998, 9997, 9996, 9995],k = 100) == 5\n assert candidate(piles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 10\n assert candidate(piles = [1000, 999, 998, 997, 996, 995],k = 15) == 1123\n assert candidate(piles = [10000, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19],k = 50) == 149\n assert candidate(piles = [9999],k = 10000) == 1\n assert candidate(piles = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],k = 1000) == 10\n assert candidate(piles = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100) == 10\n assert candidate(piles = [1, 10, 100, 1000, 10000],k = 100) == 5\n assert candidate(piles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 10\n assert candidate(piles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 117\n assert candidate(piles = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991],k = 1000) == 10\n assert candidate(piles = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],k = 1000) == 20\n assert candidate(piles = [1, 1, 1, 1, 1, 1, 1, 1, 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) == 32\n assert candidate(piles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 10\n assert candidate(piles = [1, 100, 1000, 10000, 10000, 1000, 100, 1],k = 50000) == 8\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],k = 100) == 50\n assert candidate(piles = [50, 25, 75, 200, 150],k = 5) == 201\n assert candidate(piles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 20\n assert candidate(piles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 20\n assert candidate(piles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 20\n assert candidate(piles = [10000, 1000, 100, 10, 1],k = 15000) == 5\n assert candidate(piles = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1000) == 20\n assert candidate(piles = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 200) == 10\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000],k = 1000) == 5\n assert candidate(piles = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],k = 1000) == 10\n assert candidate(piles = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512],k = 100) == 20\n assert candidate(piles = [1000, 500, 250, 125, 63, 32, 16, 8, 4, 2, 1],k = 30) == 63\n assert candidate(piles = [999, 1000, 1001, 1002, 1003],k = 10) == 1253\n assert candidate(piles = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500],k = 2500) == 20\n assert candidate(piles = [10000, 5000, 2500, 1250, 625],k = 20) == 785\n assert candidate(piles = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 30) == 63\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000],k = 100000) == 5\n assert candidate(piles = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 1000) == 20\n assert candidate(piles = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 50) == 20\n assert candidate(piles = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],k = 50) == 1441\n assert candidate(piles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 100) == 15\n assert candidate(piles = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 500) == 20\n assert candidate(piles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 20\n assert candidate(piles = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],k = 20) == 253\n assert candidate(piles = [9999, 9999, 9999, 9999],k = 100000) == 4\n assert candidate(piles = [1, 10, 100, 1000, 10000],k = 10) == 315\n assert candidate(piles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 20\n assert candidate(piles = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 1000) == 10\n assert candidate(piles = [500, 300, 200, 100],k = 5) == 400\n assert candidate(piles = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 30) == 31\n assert candidate(piles = [9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111],k = 10000) == 9\n assert candidate(piles = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 100) == 11\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],k = 5000) == 31\n assert candidate(piles = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990],k = 50) == 3130\n assert candidate(piles = [5000, 4000, 3000, 2000, 1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],k = 100) == 16\n assert candidate(piles = [10, 15, 20, 25, 30, 35, 40, 45, 50],k = 100) == 9\n assert candidate(piles = [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999],k = 10000) == 20\n assert candidate(piles = [9999, 1, 2, 3, 4, 5],k = 10) == 25\n assert candidate(piles = [1000, 1000, 1000, 1000, 1000],k = 50) == 5\n assert candidate(piles = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],k = 100) == 10\n assert candidate(piles = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990],k = 5000) == 10\n assert candidate(piles = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],k = 50000) == 10\n assert candidate(piles = [1, 1, 1, 1, 1, 1, 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) == 30\n assert candidate(piles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 100) == 20\n", "comparison": "exact"}, "public_tests": ["[5,4,9]\n2", "[4,3,6,7]\n3"], "hints": ["Choose the pile with the maximum number of stones each time.", "Use a data structure that helps you find the mentioned pile each time efficiently.", "One such data structure is a Priority Queue."], "metadata": {"canonical_parameter_names": ["piles", "k"], "leetcode_dataset_entry_point": "Solution().minStoneSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:30+00:00", "tests_total": 83, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function minStoneSum($piles, $k) {", "container": "Solution", "callable": "minStoneSum", "parameters": [{"name": "piles", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1963, "task_id": "minimum-number-of-swaps-to-make-the-string-balanced", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.\n\nA string is called balanced if and only if:\n\n- It is the empty string, or\n- It can be written as AB, where both A and B are balanced strings, or\n- It can be written as [C], where C is a balanced string.\n\nYou may swap the brackets at any two indices any number of times.\n\nReturn the minimum number of swaps to make s balanced.\n\nExample 1:\n\nInput: s = \"][][\"\nOutput: 1\nExplanation: You can make the string balanced by swapping index 0 with index 3.\nThe resulting string is \"[[]]\".\n\nExample 2:\n\nInput: s = \"]]][[[\"\nOutput: 2\nExplanation: You can do the following to make the string balanced:\n- Swap index 0 with index 4. s = \"[]][][\".\n- Swap index 1 with index 5. s = \"[[][]]\".\nThe resulting string is \"[[][]]\".\n\nExample 3:\n\nInput: s = \"[]\"\nOutput: 0\nExplanation: The string is already balanced.\n\nConstraints:\n\n- n == s.length\n- 2 <= n <= 10^6\n- n is even.\n- s[i] is either '[' or ']'.\n- The number of opening brackets '[' equals n / 2, and the number of closing brackets ']' equals n / 2.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"[]][[]\") == 1\n assert candidate(s = \"[[[[]]]]\") == 0\n assert candidate(s = \"]][[[]]]\") == 0\n assert candidate(s = \"][][\") == 1\n assert candidate(s = \"]]][[][[\") == 2\n assert candidate(s = \"]]]][[[[\") == 2\n assert candidate(s = \"][[]][\") == 1\n assert candidate(s = \"[][][][]\") == 0\n assert candidate(s = \"[[[]]]\") == 0\n assert candidate(s = \"[[[]]][[]]\") == 0\n assert candidate(s = \"]][[][][\") == 1\n assert candidate(s = \"]]][[[\") == 2\n assert candidate(s = \"[][]\") == 0\n assert candidate(s = \"[]\") == 0\n assert candidate(s = \"]][[\") == 1\n assert candidate(s = \"]]][[[[[[]]]]]\") == 1\n assert candidate(s = \"]][[[]\") == 1\n assert candidate(s = \"[[]][]\") == 0\n assert candidate(s = \"][[][]\") == 1\n assert candidate(s = \"[[[][]]]\") == 0\n assert candidate(s = \"]]]]][[[[[[[]]]]]]\") == 1\n assert candidate(s = \"]]]]][[[[[][][]]]]]][[[[[][][]]]]]\") == 0\n assert candidate(s = \"[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]\") == 1\n assert candidate(s = \"][]]]][[[[[]][[]]]\") == 1\n assert candidate(s = \"]][[[[[[[[[[]]]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]][[[[[[[]]]]]]\") == 1\n assert candidate(s = \"]][[[]]]]][[[[[]]]\") == 1\n assert candidate(s = \"]]][[][[[[[]]]]]]]\") == 0\n assert candidate(s = \"]]][[[][]]][[[[[[[]]]]]][][][[]][[\") == 2\n assert candidate(s = \"]][[[]]][][[[[[[[[]]]]]][][[\") == 2\n assert candidate(s = \"]]][[[[[[[]]]]]]][[[[[]]]]]][[[[]]]]]]]]\") == 0\n assert candidate(s = \"]]]]][[[[[[]]][]]]\") == 1\n assert candidate(s = \"]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[\") == 1\n assert candidate(s = \"]][[[]]][][[[]]]\") == 0\n assert candidate(s = \"[[][]]]][[[][][[]][][[]][[]]\") == 1\n assert candidate(s = \"[[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]][[]]\") == 0\n assert candidate(s = \"]]][[[[[[[]]]]]]][[[[[]]]]]][[[[[]]]]]\") == 0\n assert candidate(s = \"]]][[[[]][]][][[][]][][[[]][]][][[[]]]\") == 1\n assert candidate(s = \"[][][][][][][][][][][][][][][][][][][][][][][][]\") == 0\n assert candidate(s = \"[[[[[[[[]]]]]]]][[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]\") == 0\n assert candidate(s = \"]]]]]][[[[[[\") == 3\n assert candidate(s = \"]]]]][[[[[]]]]\") == 1\n assert candidate(s = \"]]][[[[[[[]]]]][[[[[[]]]]]]][[[[\") == 3\n assert candidate(s = \"]]]]][[[[[]]]][[\") == 2\n assert candidate(s = \"]]][[[[[[[[[[[][][]][[]][]]]]]]][[[[[[[[[][][]][[]][]]]]]]][[[[[[[[[][][]][[]][]]]]]]][[[[[[[[[][]]]]]]]]]\") == 3\n assert candidate(s = \"]][[[[[[[]]]]]]][[[[[]]]]]\") == 0\n assert candidate(s = \"]]][[[]][[[[]]]][]]]]][][[[[]]]]\") == 0\n assert candidate(s = \"]]][[[[]]][][[[]]]\") == 1\n assert candidate(s = \"]][[[[[][]]]]]][[[[[][]]]]]][[[[[][]]]]][[\") == 1\n assert candidate(s = \"]]][[[[[[[]]]]]]\") == 1\n assert candidate(s = \"]][[[][]]][[\") == 1\n assert candidate(s = \"]][[[[[[[[[[]]]]]]]]][[[[[[[[[[[]]]]]]]]]][[[[[[[[[[[]]]]]]]]]]]\") == 1\n assert candidate(s = \"]][[[]]][][[\") == 1\n assert candidate(s = \"]]][[[]]][[[]]]]][[[[[]]]]\") == 1\n assert candidate(s = \"]]]]][[[[[[]]]]][[[[]]]]\") == 1\n assert candidate(s = \"]]][[[[[[[[[[[][][]][[]][]]]][][[[[[[[[][][]][[]][]]]][][[[[[[[[][][]][[]][]]]][][[[[[[[[][]]]]]]]]]\") == 6\n assert candidate(s = \"]]][[[]]]][[[[\") == 2\n assert candidate(s = \"]]]][][][[[[\") == 2\n assert candidate(s = \"]]][[[[[[[][]]]]]]\") == 1\n assert candidate(s = \"]][[[]][[[]][]]]\") == 0\n assert candidate(s = \"]]][[[[]][]]\") == 1\n", "comparison": "exact"}, "public_tests": ["\"][][\"", "\"]]][[[\"", "\"[]\""], "hints": ["Iterate over the string and keep track of the number of opening and closing brackets on each step.", "If the number of closing brackets is ever larger, you need to make a swap.", "Swap it with the opening bracket closest to the end of s."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:33+00:00", "tests_total": 91, "tests_dropped": 31, "flags": [], "topic_tags": ["two-pointers", "string", "stack", "greedy", "bracket-sequences"]}, "language": "php", "interface": {"raw_signature": "function minSwaps($s) {", "container": "Solution", "callable": "minSwaps", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1964, "task_id": "find-the-longest-valid-obstacle-course-at-each-position", "difficulty": "Hard", "problem_description": "You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the i^th obstacle.\n\nFor every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such that:\n\n- You choose any number of obstacles between 0 and i inclusive.\n- You must include the i^th obstacle in the course.\n- You must put the chosen obstacles in the same order as they appear in obstacles.\n- Every obstacle (except the first) is taller than or the same height as the obstacle immediately before it.\n\nReturn an array ans of length n, where ans[i] is the length of the longest obstacle course for index i as described above.\n\nExample 1:\n\nInput: obstacles = [1,2,3,2]\nOutput: [1,2,3,3]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [1], [1] has length 1.\n- i = 1: [1,2], [1,2] has length 2.\n- i = 2: [1,2,3], [1,2,3] has length 3.\n- i = 3: [1,2,3,2], [1,2,2] has length 3.\n\nExample 2:\n\nInput: obstacles = [2,2,1]\nOutput: [1,2,1]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [2], [2] has length 1.\n- i = 1: [2,2], [2,2] has length 2.\n- i = 2: [2,2,1], [1] has length 1.\n\nExample 3:\n\nInput: obstacles = [3,1,5,6,4,2]\nOutput: [1,1,2,3,2,2]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [3], [3] has length 1.\n- i = 1: [3,1], [1] has length 1.\n- i = 2: [3,1,5], [3,5] has length 2. [1,5] is also valid.\n- i = 3: [3,1,5,6], [3,5,6] has length 3. [1,5,6] is also valid.\n- i = 4: [3,1,5,6,4], [3,4] has length 2. [1,4] is also valid.\n- i = 5: [3,1,5,6,4,2], [1,2] has length 2.\n\nConstraints:\n\n- n == obstacles.length\n- 1 <= n <= 10^5\n- 1 <= obstacles[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(obstacles = [1]) == [1]\n assert candidate(obstacles = [3, 1, 5, 6, 4, 2]) == [1, 1, 2, 3, 2, 2]\n assert candidate(obstacles = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1]\n assert candidate(obstacles = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [5, 5, 5, 5, 5]) == [1, 2, 3, 4, 5]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [1, 1, 1, 1, 1]) == [1, 2, 3, 4, 5]\n assert candidate(obstacles = [10, 9, 2, 5, 3, 7, 101, 18]) == [1, 1, 1, 2, 2, 3, 4, 4]\n assert candidate(obstacles = [10, 9, 8, 7, 6]) == [1, 1, 1, 1, 1]\n assert candidate(obstacles = [2, 2, 1]) == [1, 2, 1]\n assert candidate(obstacles = [1, 3, 5, 6, 8, 7, 9, 4, 10, 2]) == [1, 2, 3, 4, 5, 5, 6, 3, 7, 2]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(obstacles = [1, 3, 5, 7, 9]) == [1, 2, 3, 4, 5]\n assert candidate(obstacles = [1, 2, 3, 2]) == [1, 2, 3, 3]\n assert candidate(obstacles = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(obstacles = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(obstacles = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12]\n assert candidate(obstacles = [5, 1, 5, 2, 5, 3, 5, 4, 5]) == [1, 1, 2, 2, 3, 3, 4, 4, 5]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6]\n assert candidate(obstacles = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]\n assert candidate(obstacles = [10, 10, 10, 1, 1, 1, 10, 10, 10, 1, 1, 1, 10, 10, 10]) == [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 7, 8, 9]\n assert candidate(obstacles = [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, 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]\n assert candidate(obstacles = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7]\n assert candidate(obstacles = [5, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 5]) == [1, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 4]\n assert candidate(obstacles = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 2, 4, 5, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == [1, 2, 3, 3, 2, 4, 5, 5, 3, 6, 7, 7, 4, 8, 9]\n assert candidate(obstacles = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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]\n assert candidate(obstacles = [1, 2, 1, 2, 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, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14]\n assert candidate(obstacles = [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]) == [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(obstacles = [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]\n assert candidate(obstacles = [3, 2, 1, 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, 21, 20, 22, 21, 23, 22, 24, 23, 25, 24, 26, 25, 27, 26, 28, 27, 29, 28, 30, 29, 31, 30, 32, 31, 33, 32, 34, 33, 35, 34, 36, 35, 37, 36, 38, 37, 39, 38, 40, 39]) == [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, 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]\n assert candidate(obstacles = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3]\n assert candidate(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6]\n assert candidate(obstacles = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7]\n assert candidate(obstacles = [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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [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, 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(obstacles = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 10, 7, 8, 5, 6, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 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(obstacles = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 4, 5, 6, 7]\n assert candidate(obstacles = [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, 1, 1, 1, 1, 1, 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(obstacles = [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]) == [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(obstacles = [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]) == [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(obstacles = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 19, 18, 17, 16, 15, 14, 13, 12]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8]\n assert candidate(obstacles = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == [1, 2, 3, 4, 5, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7]\n assert candidate(obstacles = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]\n assert candidate(obstacles = [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, 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]) == [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16]\n assert candidate(obstacles = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1, 5, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 3, 2, 4, 5, 5, 4, 4, 3, 6, 7, 7, 6, 5, 5, 4]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7, 4, 5, 6, 7, 8]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 4, 5, 6, 7, 7, 6, 5, 3]\n assert candidate(obstacles = [100000, 99999, 99998, 100000, 100000, 99999, 99998, 99997, 99996, 99995]) == [1, 1, 1, 2, 3, 2, 2, 1, 1, 1]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(obstacles = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(obstacles = [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(obstacles = [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, 2, 3, 4, 5, 6]\n assert candidate(obstacles = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]\n assert candidate(obstacles = [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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 11, 11, 10, 9, 8, 7, 6, 5, 4, 3]\n assert candidate(obstacles = [15, 14, 13, 12, 11, 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]\n assert candidate(obstacles = [3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == [1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 2, 3, 4, 5]\n assert candidate(obstacles = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 3, 4, 5, 6, 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]\n assert candidate(obstacles = [1, 2, 2, 3, 3, 2, 1, 4, 4, 3, 3, 5, 5, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7]) == [1, 2, 3, 4, 5, 4, 2, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]\n assert candidate(obstacles = [2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2]) == [1, 2, 3, 4, 2, 3, 4, 5, 6, 7, 8, 9, 6, 7, 8, 9]\n assert candidate(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]\n assert candidate(obstacles = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 10, 7, 8, 5, 6, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 10, 10, 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, 13, 12, 11, 10, 8, 6, 5, 4, 2]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [10000000, 5000000, 7500000, 6000000, 8000000, 9000000, 4000000, 3000000, 2000000, 1000000]) == [1, 1, 2, 2, 3, 4, 1, 1, 1, 1]\n assert candidate(obstacles = [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, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(obstacles = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(obstacles = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5, 10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6]\n assert candidate(obstacles = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]\n assert candidate(obstacles = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 11, 11, 10, 9, 8, 7, 6, 5, 4, 3]\n assert candidate(obstacles = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 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]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [1, 2, 3, 4, 5, 2, 3, 4, 5, 6]\n assert candidate(obstacles = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(obstacles = [1, 3, 5, 2, 4, 6, 3, 5, 7, 8, 4, 6, 9]) == [1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 4, 5, 7]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == [1, 2, 3, 4, 5, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7]\n assert candidate(obstacles = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 11, 10, 9, 8, 7, 6, 5, 3]\n assert candidate(obstacles = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]\n assert candidate(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(obstacles = [1, 2, 3, 2, 1, 3, 4, 5, 4, 3, 2, 4, 5, 6, 5, 4, 3, 4, 5]) == [1, 2, 3, 3, 2, 4, 5, 6, 6, 5, 4, 7, 8, 9, 9, 8, 6, 9, 10]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(obstacles = [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, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 6, 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(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 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(obstacles = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 4, 5, 6, 7, 7, 6, 5, 3, 6, 7, 8, 9]\n assert candidate(obstacles = [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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n assert candidate(obstacles = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(obstacles = [3, 1, 2, 3, 4, 2, 1, 4, 3, 2, 5, 6, 4, 5, 7, 8, 9]) == [1, 1, 2, 3, 4, 3, 2, 5, 4, 4, 6, 7, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 10, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 10, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 10]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 2, 8, 3, 7, 4, 7, 5, 7, 6, 7, 9, 3, 10, 4, 8, 5, 8, 6, 8, 7, 8, 11]\n assert candidate(obstacles = [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]\n assert candidate(obstacles = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, 12, 13, 14, 15, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 2, 3, 4, 5]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(obstacles = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 21]\n assert candidate(obstacles = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 7, 8, 9]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(obstacles = [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]) == [1, 2, 3, 4, 5, 6, 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(obstacles = [5, 3, 4, 1, 2, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == [1, 1, 2, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7]\n assert candidate(obstacles = [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, 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, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]\n assert candidate(obstacles = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(obstacles = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == [1, 2, 3, 4, 2, 3, 4, 5, 6, 7, 5, 6, 7, 8, 9, 10, 8, 9, 10, 8, 9, 10]\n assert candidate(obstacles = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]\n assert candidate(obstacles = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(obstacles = [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(obstacles = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == [1, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9]\n assert candidate(obstacles = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(obstacles = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(obstacles = [1, 2, 3, 4, 5, 4, 5, 3, 4, 5, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1]) == [1, 2, 3, 4, 5, 5, 6, 4, 6, 7, 3, 5, 7, 8, 2, 4, 6, 8, 9, 3]\n assert candidate(obstacles = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(obstacles = [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]) == [1, 1, 1, 1, 1, 1, 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(obstacles = [3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5]) == [1, 1, 1, 2, 3, 3, 2, 4, 5, 6, 6, 5, 3, 6, 7, 8, 9]\n", "comparison": "exact"}, "public_tests": ["[1,2,3,2]", "[2,2,1]", "[3,1,5,6,4,2]"], "hints": ["Can you keep track of the minimum height for each obstacle course length?", "You can use binary search to find the longest previous obstacle course length that satisfies the conditions."], "metadata": {"canonical_parameter_names": ["obstacles"], "leetcode_dataset_entry_point": "Solution().longestObstacleCourseAtEachPosition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:35+00:00", "tests_total": 128, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "binary-indexed-tree", "longest-increasing-subsequence"]}, "language": "php", "interface": {"raw_signature": "function longestObstacleCourseAtEachPosition($obstacles) {", "container": "Solution", "callable": "longestObstacleCourseAtEachPosition", "parameters": [{"name": "obstacles", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1967, "task_id": "number-of-strings-that-appear-as-substrings-in-word", "difficulty": "Easy", "problem_description": "Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: patterns = [\"a\",\"abc\",\"bc\",\"d\"], word = \"abc\"\nOutput: 3\nExplanation:\n- \"a\" appears as a substring in \"abc\".\n- \"abc\" appears as a substring in \"abc\".\n- \"bc\" appears as a substring in \"abc\".\n- \"d\" does not appear as a substring in \"abc\".\n3 of the strings in patterns appear as a substring in word.\n\nExample 2:\n\nInput: patterns = [\"a\",\"b\",\"c\"], word = \"aaaaabbbbb\"\nOutput: 2\nExplanation:\n- \"a\" appears as a substring in \"aaaaabbbbb\".\n- \"b\" appears as a substring in \"aaaaabbbbb\".\n- \"c\" does not appear as a substring in \"aaaaabbbbb\".\n2 of the strings in patterns appear as a substring in word.\n\nExample 3:\n\nInput: patterns = [\"a\",\"a\",\"a\"], word = \"ab\"\nOutput: 3\nExplanation: Each of the patterns appears as a substring in word \"ab\".\n\nConstraints:\n\n- 1 <= patterns.length <= 100\n- 1 <= patterns[i].length <= 100\n- 1 <= word.length <= 100\n- patterns[i] and word consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(patterns = ['a', 'b', 'c'],word = \"aaaaabbbbb\") == 2\n assert candidate(patterns = ['aa', 'bb', 'cc'],word = \"abcabc\") == 0\n assert candidate(patterns = ['a', 'abc', 'bc', 'd'],word = \"abc\") == 3\n assert candidate(patterns = ['aaa'],word = \"aaaaa\") == 1\n assert candidate(patterns = ['abc'],word = \"abc\") == 1\n assert candidate(patterns = ['xyz', 'xy', 'yz'],word = \"xyz\") == 3\n assert candidate(patterns = ['hello', 'world'],word = \"helloworld\") == 2\n assert candidate(patterns = ['a', 'a', 'a'],word = \"ab\") == 3\n assert candidate(patterns = ['z'],word = \"abcz\") == 1\n assert candidate(patterns = ['a', 'b', 'c', 'd', 'e'],word = \"edcba\") == 5\n assert candidate(patterns = ['hello', 'world', 'foo', 'bar'],word = \"helloworldfoo\") == 3\n assert candidate(patterns = ['repeated', 'repeat', 'eat'],word = \"repeatedrepeat\") == 3\n assert candidate(patterns = ['this', 'is', 'a', 'test'],word = \"thisisatest\") == 4\n assert candidate(patterns = ['abc', 'cab', 'bac'],word = \"abacabcabc\") == 3\n assert candidate(patterns = ['aabb', 'bbcc', 'ccdd', 'ddaa'],word = \"aabbccdd\") == 3\n assert candidate(patterns = ['a', 'ab', 'abc', 'abcd'],word = \"abcd\") == 4\n assert candidate(patterns = ['a', 'aa', 'aaa', 'aaaa'],word = \"aaaaaaaa\") == 4\n assert candidate(patterns = ['overlapping', 'lapping', 'lappingo', 'verlapping'],word = \"overlappinglappingoverlappingoverlapping\") == 4\n assert candidate(patterns = ['hello', 'world', 'python', 'programming'],word = \"helloworldpythonprogramming\") == 4\n assert candidate(patterns = ['xyz', 'zyx', 'zxy'],word = \"xyzzyxzyxzxyzyx\") == 3\n assert candidate(patterns = ['xy', 'yx', 'xyz', 'zyx'],word = \"xyzzyx\") == 4\n assert candidate(patterns = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'],word = \"loremipsumdolorsitamet\") == 5\n assert candidate(patterns = ['abcd', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop', 'nopq', 'opqr', 'pqrs', 'qrst', 'rstu', 'stuv', 'tuvw', 'uvwx', 'vwxy', 'wxyz'],word = \"abcdefghijklmnopqrstuvwxyz\") == 23\n assert candidate(patterns = ['mnop', 'nopq', 'opqr', 'pqrs', 'qrst'],word = \"mnopqrstu\") == 5\n assert candidate(patterns = ['quick', 'brown', 'fox'],word = \"thequickbrownfox\") == 3\n assert candidate(patterns = ['abcd', 'abcde', 'abcdef'],word = \"abcdefgabcdefg\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'yxz', 'xzy', 'zyx'],word = \"zyxzyxzyxzyx\") == 4\n assert candidate(patterns = ['ab', 'ba', 'aba', 'bab'],word = \"abababab\") == 4\n assert candidate(patterns = ['aaaa', 'bbbb', 'cccc'],word = \"aaaabbbbccccaaaabbbbcccc\") == 3\n assert candidate(patterns = ['aba', 'bba', 'aaa', 'bbb'],word = \"abababababa\") == 1\n assert candidate(patterns = ['repeated', 'pattern', 'substring', 'string'],word = \"repeatedpatternsubstringstring\") == 4\n assert candidate(patterns = ['ab', 'bc', 'cd', 'de', 'ef', 'fg'],word = \"abcdefg\") == 6\n assert candidate(patterns = ['repeated', 'substring', 'example'],word = \"repeatedsubstringexample\") == 3\n assert candidate(patterns = ['overlap', 'lap', 'ap', 'p'],word = \"overlaplapap\") == 4\n assert candidate(patterns = ['hello', 'world', 'python', 'programming'],word = \"programmingworldpython\") == 3\n assert candidate(patterns = ['longer', 'substrings', 'to', 'check'],word = \"thisisalongersubstringtocheck\") == 3\n assert candidate(patterns = ['unique', 'un', 'iq'],word = \"uniqueiq\") == 3\n assert candidate(patterns = ['substring', 'string', 'sub'],word = \"thisisjustasubstringexample\") == 3\n assert candidate(patterns = ['hello', 'world', 'hello', 'world'],word = \"helloworldhello\") == 4\n assert candidate(patterns = ['aaa', 'aa', 'a'],word = \"aaaaaaaaaaaa\") == 3\n assert candidate(patterns = ['z', 'zz', 'zzz'],word = \"zzzzzzzzz\") == 3\n assert candidate(patterns = ['ab', 'bc', 'cd', 'de', 'ef'],word = \"abcdef\") == 5\n assert candidate(patterns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],word = \"abcdefghij\") == 10\n assert candidate(patterns = ['a', 'b', 'c', 'd', 'e', 'f'],word = \"abcdef\") == 6\n assert candidate(patterns = ['a', 'ab', 'abc', 'abcd', 'abcde'],word = \"abcde\") == 5\n assert candidate(patterns = ['one', 'two', 'three'],word = \"onetwothreeonetwothree\") == 3\n assert candidate(patterns = ['aaa', 'aab', 'aba', 'baa', 'aabaa', 'aaaba', 'aaba', 'baaa'],word = \"aaaabaaaa\") == 8\n assert candidate(patterns = ['hello', 'world', 'helloworld'],word = \"helloworld\") == 3\n assert candidate(patterns = ['quick', 'brown', 'fox'],word = \"thequickbrownfoxjumps\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'yzz', 'zzz'],word = \"xyzzyzyzzz\") == 3\n assert candidate(patterns = ['aaa', 'bbb', 'ccc', 'abc', 'bca', 'cab'],word = \"abcabcabc\") == 3\n assert candidate(patterns = ['abcd', 'dcba', 'abcdabcd'],word = \"abcdabcdabcdabcd\") == 2\n assert candidate(patterns = ['a', 'ab', 'abc', 'abcd', 'abcde'],word = \"abcdefghijklmnopqrstuvwxyz\") == 5\n assert candidate(patterns = ['abc', 'def', 'ghi', 'jkl'],word = \"abcdefghijkl\") == 4\n assert candidate(patterns = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'],word = \"abcdeabcdeabcdeabcde\") == 0\n assert candidate(patterns = ['ab', 'bc', 'cd', 'de'],word = \"abcdefg\") == 4\n assert candidate(patterns = ['pattern', 'matching', 'substrings'],word = \"matchingpatternsubstring\") == 2\n assert candidate(patterns = ['ab', 'ba', 'abab', 'baba'],word = \"abababababababab\") == 4\n assert candidate(patterns = ['same', 'sub', 'string', 'test', 'case'],word = \"substringtestcase\") == 4\n assert candidate(patterns = ['aaaa', 'bbbb', 'cccc', 'ddd'],word = \"aaaabbbbccccddd\") == 4\n assert candidate(patterns = ['apple', 'banana', 'cherry'],word = \"cherrybananaapple\") == 3\n assert candidate(patterns = ['cat', 'dog', 'bird', 'fish'],word = \"fishdogcatbird\") == 4\n assert candidate(patterns = ['python', 'java', 'cpp'],word = \"pythonjavacpp\") == 3\n assert candidate(patterns = ['aaa', 'bbb', 'ccc', 'ddd'],word = \"aaabbbcccddd\") == 4\n assert candidate(patterns = ['test', 'sett', 'best'],word = \"bestsett\") == 2\n assert candidate(patterns = ['abc', 'bca', 'cab', 'abcabc'],word = \"abcabcabcabc\") == 4\n assert candidate(patterns = ['aaa', 'aa', 'a'],word = \"aaaaaaaaaa\") == 3\n assert candidate(patterns = ['quick', 'brown', 'fox', 'jump', 'over', 'lazy', 'dog'],word = \"thequickbrownfoxjumpsoverthelazydog\") == 7\n assert candidate(patterns = ['abc', 'cab', 'bca'],word = \"abcabcabcabc\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'xy', 'yx', 'xzy', 'yzx'],word = \"zyxwvutsrqponmlkjihgfedcba\") == 2\n assert candidate(patterns = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'],word = \"abcdefabcdefabcdef\") == 0\n assert candidate(patterns = ['abc', 'def', 'ghi'],word = \"defabc\") == 2\n assert candidate(patterns = ['quick', 'brown', 'fox'],word = \"thequickbrownfoxjumpsoverthelazydog\") == 3\n assert candidate(patterns = ['aaa', 'aa', 'a'],word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 3\n assert candidate(patterns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],word = \"abcdefghijabcdefghij\") == 10\n assert candidate(patterns = ['test', 'string', 'finding', 'substring'],word = \"teststringfindingsubstring\") == 4\n assert candidate(patterns = ['aa', 'aaa', 'aaaa'],word = \"aaaa\") == 3\n assert candidate(patterns = ['short', 'shot', 'dot'],word = \"shortshot\") == 2\n assert candidate(patterns = ['foo', 'bar', 'foobar', 'barfoo'],word = \"foobarbarfoobarfoo\") == 4\n assert candidate(patterns = ['aba', 'bab', 'aba'],word = \"ababababa\") == 3\n assert candidate(patterns = ['hello', 'world', 'python'],word = \"pythonworldhello\") == 3\n assert candidate(patterns = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'],word = \"abcacbcbacbacbcbac\") == 5\n assert candidate(patterns = ['banana', 'ana', 'nan', 'ban'],word = \"banananana\") == 4\n assert candidate(patterns = ['abc', 'abcd', 'abcde'],word = \"abcdefgh\") == 3\n assert candidate(patterns = ['abcd', 'dcba', 'abcd'],word = \"abcdcbaabcd\") == 3\n assert candidate(patterns = ['aaaa', 'bbbb', 'cccc', 'dddd'],word = \"abcdeabcdeabcde\") == 0\n assert candidate(patterns = ['longpattern', 'long', 'pattern'],word = \"longpatternlongpattern\") == 3\n assert candidate(patterns = ['ab', 'bc', 'cd', 'de', 'ef', 'fg', 'gh', 'hi', 'ij'],word = \"abcdefghij\") == 9\n assert candidate(patterns = ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz'],word = \"abcdefghijklmnopqrstuvwxyz\") == 24\n assert candidate(patterns = ['zzz', 'zzzz', 'zzzzz'],word = \"zzzzzzzzzz\") == 3\n assert candidate(patterns = ['ab', 'bc', 'cd', 'de'],word = \"abcde\") == 4\n assert candidate(patterns = ['abc', 'bcd', 'cde', 'def'],word = \"abcdefg\") == 4\n assert candidate(patterns = ['abc', 'abcd', 'abcde', 'abcdef'],word = \"abcdefg\") == 4\n assert candidate(patterns = ['test', 'tset', 'sett', 'settset'],word = \"testsettsettset\") == 4\n assert candidate(patterns = ['small', 'medium', 'large', 'extra', 'huge'],word = \"smallmediumlargeextrahuge\") == 5\n assert candidate(patterns = ['pattern', 'tern', 'ternary', 'ternarysearch'],word = \"binarysearchternarysearch\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'yzx'],word = \"xyzzyxzyxzyx\") == 2\n assert candidate(patterns = ['abcd', 'efgh', 'ijkl'],word = \"efghijklabcd\") == 3\n assert candidate(patterns = ['abc', 'cab', 'bac', 'bca', 'acb', 'cba'],word = \"abcabcabc\") == 3\n assert candidate(patterns = ['abc', 'abcabc', 'abcabcabc'],word = \"abcabcabcabc\") == 3\n assert candidate(patterns = ['aaa', 'bbb', 'ccc'],word = \"abacabadabc\") == 0\n assert candidate(patterns = ['one', 'two', 'three', 'onetwothree'],word = \"onetwothreeonetwothree\") == 4\n assert candidate(patterns = ['search', 'sear', 'arch'],word = \"searchingthesearchinthesearch\") == 3\n assert candidate(patterns = ['overlap', 'lap', 'lapping'],word = \"lapping\") == 2\n assert candidate(patterns = ['abc', 'def', 'ghi', 'jkl'],word = \"abcdefghijklmnopqrstuvwxyz\") == 4\n assert candidate(patterns = ['abc', 'def', 'ghi', 'jkl'],word = \"abcdefghijk\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'wxy', 'uvw'],word = \"xyzzyxwxyuvw\") == 4\n assert candidate(patterns = ['abc', 'def', 'ghi', 'jkl'],word = \"abcdefghij\") == 3\n assert candidate(patterns = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yz'],word = \"abcdefghijklmnopqrstuvwxyz\") == 7\n assert candidate(patterns = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],word = \"abcdefghijklmnopqrstuvwxyz\") == 9\n assert candidate(patterns = ['zz', 'zzz', 'zzzz'],word = \"zzzzzzzzzz\") == 3\n assert candidate(patterns = ['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'],word = \"zyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(patterns = ['example', 'ample', 'mple', 'ple', 'le', 'e'],word = \"exampleexampleexample\") == 6\n assert candidate(patterns = ['ab', 'ba', 'ac', 'ca', 'bc', 'cb'],word = \"abcbaacbba\") == 5\n assert candidate(patterns = ['abc', 'def', 'ghi'],word = \"abcdefghi\") == 3\n assert candidate(patterns = ['xyz', 'zyx', 'yzx'],word = \"xyzzyxzyx\") == 2\n assert candidate(patterns = ['zzz', 'zz', 'z'],word = \"zzzzzzzzzz\") == 3\n assert candidate(patterns = ['pattern', 'tern', 'ternary', 'ary'],word = \"patternarypatternary\") == 4\n assert candidate(patterns = ['xyz', 'abc', 'def', 'ghi', 'jkl'],word = \"zyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(patterns = ['a', 'ab', 'abc', 'abcd'],word = \"abcdabcdabcd\") == 4\n", "comparison": "exact"}, "public_tests": ["[\"a\",\"abc\",\"bc\",\"d\"]\n\"abc\"", "[\"a\",\"b\",\"c\"]\n\"aaaaabbbbb\"", "[\"a\",\"a\",\"a\"]\n\"ab\""], "hints": ["Deal with each of the patterns individually.", "Use the built-in function in the language you are using to find if the pattern exists as a substring in word."], "metadata": {"canonical_parameter_names": ["patterns", "word"], "leetcode_dataset_entry_point": "Solution().numOfStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:40+00:00", "tests_total": 122, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function numOfStrings($patterns, $word) {", "container": "Solution", "callable": "numOfStrings", "parameters": [{"name": "patterns", "type": "String[]"}, {"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1968, "task_id": "array-with-elements-not-equal-to-average-of-neighbors", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged array is not equal to the average of its neighbors.\n\nMore formally, the rearranged array should have the property such that for every i in the range 1 <= i < nums.length - 1, (nums[i-1] + nums[i+1]) / 2 is not equal to nums[i].\n\nReturn any rearrangement of nums that meets the requirements.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: [1,2,4,5,3]\nExplanation:\nWhen i=1, nums[i] = 2, and the average of its neighbors is (1+4) / 2 = 2.5.\nWhen i=2, nums[i] = 4, and the average of its neighbors is (2+5) / 2 = 3.5.\nWhen i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3.5.\n\nExample 2:\n\nInput: nums = [6,2,0,9,7]\nOutput: [9,7,6,2,0]\nExplanation:\nWhen i=1, nums[i] = 7, and the average of its neighbors is (9+6) / 2 = 7.5.\nWhen i=2, nums[i] = 6, and the average of its neighbors is (7+2) / 2 = 4.5.\nWhen i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3.\nNote that the original array [6,2,0,9,7] also satisfies the conditions.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 100000, 50000, 25000, 75000]) == [0, 75000, 25000, 100000, 50000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == [10, 40, 20, 50, 30, 60]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13]) == [1, 9, 3, 11, 5, 13, 7]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7]) == [1, 5, 2, 6, 3, 7, 4]\n assert candidate(nums = [3, 1, 2, 5, 4]) == [1, 4, 2, 5, 3]\n assert candidate(nums = [10, 5, 1, 6, 2]) == [1, 6, 2, 10, 5]\n assert candidate(nums = [5, 1, 3, 2, 4]) == [1, 4, 2, 5, 3]\n assert candidate(nums = [5, 10, 15, 20, 25, 30]) == [5, 20, 10, 25, 15, 30]\n assert candidate(nums = [6, 2, 0, 9, 7]) == [0, 7, 2, 9, 6]\n assert candidate(nums = [0, 100, 50, 25, 75]) == [0, 75, 25, 100, 50]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [10, 40, 20, 50, 30]\n assert candidate(nums = [5, 3, 1, 2, 4]) == [1, 4, 2, 5, 3]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [1, 4, 2, 5, 3]\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == [1, 7, 3, 9, 5, 11]\n assert candidate(nums = [10, 0, 5, 3, 8]) == [0, 8, 3, 10, 5]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == [100, 106, 101, 107, 102, 108, 103, 109, 104, 110, 105]\n assert candidate(nums = [31, 41, 59, 26, 53, 58, 97, 93, 23, 84, 62, 64, 33, 83, 27, 95, 0, 88, 49, 51]) == [0, 58, 23, 59, 26, 62, 27, 64, 31, 83, 33, 84, 41, 88, 49, 93, 51, 95, 53, 97]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]) == [7, 77, 14, 84, 21, 91, 28, 98, 35, 105, 42, 112, 49, 119, 56, 126, 63, 133, 70, 140]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [100, 600, 200, 700, 300, 800, 400, 900, 500, 1000]\n assert candidate(nums = [85, 90, 80, 95, 75, 100, 70, 105, 65, 110]) == [65, 90, 70, 95, 75, 100, 80, 105, 85, 110]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [1, 32, 2, 64, 4, 128, 8, 256, 16, 512]\n assert candidate(nums = [100000, 50000, 25000, 12500, 62500, 31250, 93750, 46875, 15625, 78125]) == [12500, 50000, 15625, 62500, 25000, 78125, 31250, 93750, 46875, 100000]\n assert candidate(nums = [123, 456, 789, 234, 567, 890, 345, 678, 901, 12, 34, 56]) == [12, 456, 34, 567, 56, 678, 123, 789, 234, 890, 345, 901]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\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, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986]) == [9986, 9994, 9987, 9995, 9988, 9996, 9989, 9997, 9990, 9998, 9991, 9999, 9992, 10000, 9993]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [5, 3, 8, 6, 11, 9, 14, 12, 17, 15, 20, 18, 23, 21, 26, 24, 29, 27, 32, 30]) == [3, 18, 5, 20, 6, 21, 8, 23, 9, 24, 11, 26, 12, 27, 14, 29, 15, 30, 17, 32]\n assert candidate(nums = [100000, 0, 50000, 25000, 75000, 12500, 87500, 31250, 68750]) == [0, 68750, 12500, 75000, 25000, 87500, 31250, 100000, 50000]\n assert candidate(nums = [50, 25, 75, 37, 62, 88, 43, 91, 56, 12]) == [12, 56, 25, 62, 37, 75, 43, 88, 50, 91]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == [1, 5, 1, 5, 2, 5, 2, 6, 3, 6, 3, 7, 3, 8, 3, 9, 4, 9, 4, 9]\n assert candidate(nums = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50]) == [5, 30, 10, 35, 15, 40, 20, 45, 25, 50]\n assert candidate(nums = [5, 15, 10, 20, 25, 12, 30, 18, 28]) == [5, 20, 10, 25, 12, 28, 15, 30, 18]\n assert candidate(nums = [8, 6, 4, 2, 0, 1, 3, 5, 7, 9]) == [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]\n assert candidate(nums = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994, 7, 99993]) == [1, 99994, 2, 99995, 3, 99996, 4, 99997, 5, 99998, 6, 99999, 7, 100000, 99993]\n assert candidate(nums = [8, 1, 6, 3, 9, 4, 5, 2, 7]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [42, 84, 21, 168, 105, 252, 175, 336, 245, 420, 315, 462, 368]) == [21, 252, 42, 315, 84, 336, 105, 368, 168, 420, 175, 462, 245]\n assert candidate(nums = [8192, 16384, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == [1, 256, 2, 512, 4, 1024, 8, 2048, 16, 4096, 32, 8192, 64, 16384, 128]\n assert candidate(nums = [1, 4, 2, 5, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n assert candidate(nums = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 0]) == [0, 55555, 11111, 66666, 22222, 77777, 33333, 88888, 44444, 99999]\n assert candidate(nums = [34, 7, 23, 32, 5, 62, 32, 2, 78, 1, 45, 67, 89, 12, 34, 56, 78, 90]) == [1, 34, 2, 45, 5, 56, 7, 62, 12, 67, 23, 78, 32, 78, 32, 89, 34, 90]\n assert candidate(nums = [101, 203, 305, 407, 509, 611, 713, 815, 917, 1019]) == [101, 611, 203, 713, 305, 815, 407, 917, 509, 1019]\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150]) == [15, 90, 30, 105, 45, 120, 60, 135, 75, 150]\n assert candidate(nums = [10, 5, 8, 2, 6, 4, 9, 1, 7, 3]) == [1, 6, 2, 7, 3, 8, 4, 9, 5, 10]\n assert candidate(nums = [1, 5, 3, 9, 7, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == [1, 5, 1, 5, 2, 5, 3, 6, 3, 9, 4, 9]\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125]) == [15, 75, 25, 85, 35, 95, 45, 105, 55, 115, 65, 125]\n assert candidate(nums = [99999, 0, 50000, 25000, 75000, 1, 99998]) == [0, 75000, 1, 99998, 25000, 99999, 50000]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [5, 30, 10, 35, 15, 40, 20, 45, 25, 50]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13]) == [1, 8, 2, 9, 3, 10, 4, 11, 5, 12, 6, 13, 7]\n assert candidate(nums = [85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]) == [85, 93, 86, 94, 87, 95, 88, 96, 89, 97, 90, 98, 91, 99, 92, 100]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40]) == [5, 25, 10, 30, 15, 35, 20, 40]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == [99990, 99995, 99991, 99996, 99992, 99997, 99993, 99998, 99994, 99999]\n assert candidate(nums = [42, 84, 21, 105, 52, 7, 14, 35, 28, 70]) == [7, 42, 14, 52, 21, 70, 28, 84, 35, 105]\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == [1, 13, 2, 21, 3, 34, 5, 55, 8, 89]\n assert candidate(nums = [1000, 2000, 500, 3000, 1500, 4000, 2500, 5000, 3500]) == [500, 3000, 1000, 3500, 1500, 4000, 2000, 5000, 2500]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [5, 55, 15, 65, 25, 75, 35, 85, 45, 95]\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600]) == [100, 350, 150, 400, 200, 450, 250, 500, 300, 600]\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == [7, 17, 8, 18, 9, 19, 10, 20, 11, 21, 12, 22, 13, 23, 14, 24, 15, 25, 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]) == [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == [1, 256, 2, 512, 4, 1024, 8, 2048, 16, 4096, 32, 8192, 64, 16384, 128]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10]) == [1, 6, 2, 7, 3, 8, 4, 9, 5, 10]\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == [90, 95, 91, 96, 92, 97, 93, 98, 94, 99]\n assert candidate(nums = [10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009]) == [10000, 10005, 10001, 10006, 10002, 10007, 10003, 10008, 10004, 10009]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [2, 14, 4, 16, 6, 18, 8, 20, 10, 22, 12]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == [2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30, 16]\n assert candidate(nums = [50000, 25000, 75000, 12500, 87500, 31250, 68750, 15625, 93750]) == [12500, 68750, 15625, 75000, 25000, 87500, 31250, 93750, 50000]\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]) == [180, 191, 181, 192, 182, 193, 183, 194, 184, 195, 185, 196, 186, 197, 187, 198, 188, 199, 189, 200, 190]\n assert candidate(nums = [8, 6, 4, 2, 0, 1, 3, 5, 7, 9, 11, 13]) == [0, 6, 1, 7, 2, 8, 3, 9, 4, 11, 5, 13]\n assert candidate(nums = [50, 40, 30, 20, 10, 60, 70, 80, 90, 100, 110, 120]) == [10, 70, 20, 80, 30, 90, 40, 100, 50, 110, 60, 120]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 8]\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 6, 2, 7, 3, 8, 4, 9, 5, 10]\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100]) == [10, 60, 20, 70, 30, 80, 40, 90, 50, 100]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]\n assert candidate(nums = [23, 45, 12, 67, 89, 34, 56, 78, 90, 11, 32, 54]) == [11, 54, 12, 56, 23, 67, 32, 78, 34, 89, 45, 90]\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]) == [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 5, 1, 5, 2, 5, 3, 6, 3, 9, 4]\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]) == [100, 111, 101, 112, 102, 113, 103, 114, 104, 115, 105, 116, 106, 117, 107, 118, 108, 119, 109, 120, 110]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == [10, 70, 20, 80, 30, 90, 40, 100, 50, 110, 60, 120]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [10, 90, 20, 100, 30, 110, 40, 120, 50, 130, 60, 140, 70, 150, 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]) == [1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19, 10, 20]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == [7, 63, 14, 70, 21, 77, 28, 84, 35, 91, 42, 98, 49, 105, 56]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == [85, 93, 86, 94, 87, 95, 88, 96, 89, 97, 90, 98, 91, 99, 92, 100]\n assert candidate(nums = [1, 2, 3, 6, 5, 4, 7, 8, 9]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300]) == [100, 800, 200, 900, 300, 1000, 400, 1100, 500, 1200, 600, 1300, 700]\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == [85, 93, 86, 94, 87, 95, 88, 96, 89, 97, 90, 98, 91, 99, 92]\n assert candidate(nums = [8, 1, 6, 3, 5, 7, 2, 4, 9]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5]) == [1, 100, 2, 200, 3, 300, 4, 400, 5, 500]\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995]) == [1, 99996, 2, 99997, 3, 99998, 4, 99999, 99995]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == [1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 8]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119]) == [7, 70, 14, 77, 21, 84, 28, 91, 35, 98, 42, 105, 49, 112, 56, 119, 63]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [10, 60, 20, 70, 30, 80, 40, 90, 50, 100]\n assert candidate(nums = [8, 1, 4, 9, 3, 7, 6, 2, 5, 10]) == [1, 6, 2, 7, 3, 8, 4, 9, 5, 10]\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6]) == [1, 6, 2, 7, 3, 8, 4, 9, 5]\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505, 606, 707]) == [101, 456, 123, 505, 202, 606, 303, 707, 404, 789]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]\n assert candidate(nums = [15, 10, 5, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == [5, 45, 10, 50, 15, 55, 20, 60, 25, 65, 30, 70, 35, 75, 40]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [5, 35, 10, 40, 15, 45, 20, 50, 25, 55, 30]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [100, 600, 200, 700, 300, 800, 400, 900, 500, 1000]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == [1000, 6000, 2000, 7000, 3000, 8000, 4000, 9000, 5000, 10000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [10, 90, 20, 100, 30, 110, 40, 120, 50, 130, 60, 140, 70, 150, 80]\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350]) == [100, 300, 150, 350, 200, 400, 250]\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7]) == [7, 17, 8, 18, 9, 19, 10, 20, 11, 21, 12, 22, 13, 23, 14, 24, 15, 25, 16]\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]) == [12, 72, 24, 84, 36, 96, 48, 108, 60, 120]\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[6,2,0,9,7]"], "hints": ["A number can be the average of its neighbors if one neighbor is smaller than the number and the other is greater than the number.", "We can put numbers smaller than the median on odd indices and the rest on even indices."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().rearrangeArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:43+00:00", "tests_total": 115, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function rearrangeArray($nums) {", "container": "Solution", "callable": "rearrangeArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1970, "task_id": "last-day-where-you-can-still-cross", "difficulty": "Hard", "problem_description": "There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively.\n\nInitially on day 0, the entire matrix is land. However, each day a new cell becomes flooded with water. You are given a 1-based 2D array cells, where cells[i] = [r_i, c_i] represents that on the i^th day, the cell on the r_i^th row and c_i^th column (1-based coordinates) will be covered with water (i.e., changed to 1).\n\nYou want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells. You can start from any cell in the top row and end at any cell in the bottom row. You can only travel in the four cardinal directions (left, right, up, and down).\n\nReturn the last day where it is possible to walk from the top to the bottom by only walking on land cells.\n\nExample 1:\n\nInput: row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]]\nOutput: 2\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 2.\n\nExample 2:\n\nInput: row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]]\nOutput: 1\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 1.\n\nExample 3:\n\nInput: row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]\nOutput: 3\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 3.\n\nConstraints:\n\n- 2 <= row, col <= 2 * 10^4\n- 4 <= row * col <= 2 * 10^4\n- cells.length == row * col\n- 1 <= r_i <= row\n- 1 <= c_i <= col\n- All the values of cells are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(row = 3,col = 3,cells = [[1, 2], [2, 1], [3, 3], [2, 2], [1, 1], [1, 3], [2, 3], [3, 2], [3, 1]]) == 3\n assert candidate(row = 3,col = 4,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4]]) == 3\n assert candidate(row = 4,col = 4,cells = [[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]]) == 3\n assert candidate(row = 2,col = 2,cells = [[1, 1], [2, 1], [1, 2], [2, 2]]) == 2\n assert candidate(row = 2,col = 2,cells = [[1, 1], [1, 2], [2, 1], [2, 2]]) == 1\n assert candidate(row = 5,col = 5,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [4, 1], [3, 1], [2, 1], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [4, 2], [4, 3], [4, 4]]) == 4\n assert candidate(row = 7,col = 7,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7]]) == 6\n assert candidate(row = 5,col = 4,cells = [[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]]) == 15\n assert candidate(row = 6,col = 6,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [6, 5], [6, 4], [6, 3], [6, 2], [6, 1], [5, 1], [4, 1], [3, 1], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 2], [3, 3], [3, 4], [3, 5], [4, 2], [4, 3], [4, 4], [4, 5], [5, 2], [5, 3], [5, 4], [5, 5]]) == 5\n assert candidate(row = 5,col = 5,cells = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4]]) == 4\n assert candidate(row = 4,col = 6,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 6], [3, 6], [4, 6], [4, 5], [4, 4], [4, 3], [4, 2], [4, 1], [3, 1], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 2], [3, 3], [3, 4], [3, 5]]) == 5\n assert candidate(row = 4,col = 6,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 1], [4, 6], [4, 2], [4, 3], [4, 4], [4, 5]]) == 5\n assert candidate(row = 10,col = 5,cells = [[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], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5]]) == 4\n assert candidate(row = 8,col = 8,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 1], [2, 8], [3, 1], [3, 8], [4, 1], [4, 8], [5, 1], [5, 8], [6, 1], [6, 8], [7, 1], [7, 8], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 2], [3, 7], [3, 3], [3, 6], [3, 4], [3, 5], [4, 2], [4, 7], [4, 3], [4, 6], [4, 4], [4, 5], [5, 2], [5, 7], [5, 3], [5, 6], [5, 4], [5, 5], [6, 2], [6, 7], [6, 3], [6, 6], [6, 4], [6, 5], [7, 2], [7, 7], [7, 3], [7, 6], [7, 4], [7, 5]]) == 7\n assert candidate(row = 7,col = 7,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 7], [3, 1], [3, 7], [4, 1], [4, 7], [5, 1], [5, 7], [6, 1], [6, 7], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 2], [3, 6], [3, 3], [3, 5], [3, 4], [4, 2], [4, 6], [4, 3], [4, 5], [4, 4], [5, 2], [5, 6], [5, 3], [5, 5], [5, 4], [6, 2], [6, 6], [6, 3], [6, 5], [6, 4]]) == 6\n assert candidate(row = 5,col = 5,cells = [[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], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == 20\n assert candidate(row = 10,col = 10,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [2, 10], [3, 1], [3, 10], [4, 1], [4, 10], [5, 1], [5, 10], [6, 1], [6, 10], [7, 1], [7, 10], [8, 1], [8, 10], [9, 1], [9, 10], [10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [6, 8], [6, 9], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [7, 8], [7, 9], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8], [8, 9], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9]]) == 9\n assert candidate(row = 6,col = 5,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [6, 4], [6, 3], [6, 2], [6, 1], [5, 1], [5, 2], [5, 3], [5, 4], [4, 4], [4, 3], [4, 2], [4, 1], [3, 1], [3, 2], [3, 3], [3, 4], [2, 4], [2, 3], [2, 2], [2, 1]]) == 4\n assert candidate(row = 6,col = 5,cells = [[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], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5]]) == 4\n assert candidate(row = 5,col = 4,cells = [[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], [5, 1], [5, 2], [5, 3], [5, 4]]) == 3\n assert candidate(row = 8,col = 8,cells = [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5], [4, 4], [4, 5], [5, 4], [5, 5], [6, 4], [6, 5], [7, 4], [7, 5], [8, 4], [8, 5], [1, 1], [1, 2], [1, 3], [1, 6], [1, 7], [1, 8], [2, 1], [2, 2], [2, 3], [2, 6], [2, 7], [2, 8], [3, 1], [3, 2], [3, 3], [3, 6], [3, 7], [3, 8], [4, 1], [4, 2], [4, 3], [4, 6], [4, 7], [4, 8], [5, 1], [5, 2], [5, 3], [5, 6], [5, 7], [5, 8], [6, 1], [6, 2], [6, 3], [6, 6], [6, 7], [6, 8], [7, 1], [7, 2], [7, 3], [7, 6], [7, 7], [7, 8], [8, 1], [8, 2], [8, 3], [8, 6], [8, 7], [8, 8]]) == 21\n assert candidate(row = 5,col = 10,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [2, 10], [3, 1], [3, 10], [4, 1], [4, 10], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 2], [3, 9], [3, 3], [3, 8], [3, 4], [3, 7], [3, 5], [3, 6], [4, 2], [4, 9], [4, 3], [4, 8], [4, 4], [4, 7], [4, 5], [4, 6]]) == 9\n assert candidate(row = 5,col = 5,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 5], [3, 1], [3, 5], [4, 1], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [2, 2], [2, 3], [2, 4], [3, 2], [3, 4], [4, 2], [4, 3], [4, 4], [3, 3]]) == 4\n assert candidate(row = 7,col = 7,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 7], [3, 1], [3, 7], [4, 1], [4, 7], [5, 1], [5, 7], [6, 1], [6, 7], [7, 1], [7, 7], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6]]) == 6\n assert candidate(row = 5,col = 5,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 5], [3, 1], [3, 5], [4, 1], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [4, 2], [4, 3], [4, 4]]) == 4\n assert candidate(row = 7,col = 7,cells = [[1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [6, 4], [7, 4], [1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [7, 6], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [7, 7]]) == 42\n assert candidate(row = 8,col = 8,cells = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8], [7, 8], [6, 8], [5, 8], [4, 8], [3, 8], [2, 8], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [7, 2], [6, 2], [5, 2], [4, 2], [3, 2], [2, 2], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [7, 4], [6, 4], [5, 4], [4, 4], [3, 4], [2, 4], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [7, 6], [6, 6], [5, 6], [4, 6], [3, 6], [2, 6], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [7, 7]]) == 14\n assert candidate(row = 5,col = 5,cells = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == 20\n assert candidate(row = 7,col = 7,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 7], [3, 1], [3, 7], [4, 1], [4, 7], [5, 1], [5, 7], [6, 1], [6, 7], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]]) == 6\n assert candidate(row = 8,col = 8,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 1], [2, 8], [3, 1], [3, 8], [4, 1], [4, 8], [5, 1], [5, 8], [6, 1], [6, 8], [7, 1], [7, 8], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7]]) == 7\n assert candidate(row = 6,col = 6,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 6], [3, 1], [3, 6], [4, 1], [4, 6], [5, 1], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [2, 2], [2, 3], [2, 4], [2, 5], [3, 2], [3, 3], [3, 4], [3, 5], [4, 2], [4, 3], [4, 4], [4, 5], [5, 2], [5, 3], [5, 4], [5, 5]]) == 5\n assert candidate(row = 8,col = 8,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 1], [2, 8], [3, 1], [3, 8], [4, 1], [4, 8], [5, 1], [5, 8], [6, 1], [6, 8], [7, 1], [7, 8], [8, 1], [8, 8], [8, 7], [8, 6], [8, 5], [8, 4], [8, 3], [8, 2], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7]]) == 7\n assert candidate(row = 10,col = 10,cells = [[1, 5], [1, 6], [2, 5], [2, 6], [3, 5], [3, 6], [4, 5], [4, 6], [5, 5], [5, 6], [6, 5], [6, 6], [7, 5], [7, 6], [8, 5], [8, 6], [9, 5], [9, 6], [10, 5], [10, 6], [1, 1], [1, 2], [1, 3], [1, 4], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [2, 2], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [3, 1], [3, 2], [3, 3], [3, 4], [3, 7], [3, 8], [3, 9], [3, 10], [4, 1], [4, 2], [4, 3], [4, 4], [4, 7], [4, 8], [4, 9], [4, 10], [5, 1], [5, 2], [5, 3], [5, 4], [5, 7], [5, 8], [5, 9], [5, 10], [6, 1], [6, 2], [6, 3], [6, 4], [6, 7], [6, 8], [6, 9], [6, 10], [7, 1], [7, 2], [7, 3], [7, 4], [7, 7], [7, 8], [7, 9], [7, 10], [8, 1], [8, 2], [8, 3], [8, 4], [8, 7], [8, 8], [8, 9], [8, 10], [9, 1], [9, 2], [9, 3], [9, 4], [9, 7], [9, 8], [9, 9], [9, 10], [10, 1], [10, 2], [10, 3], [10, 4], [10, 7], [10, 8], [10, 9], [10, 10]]) == 27\n assert candidate(row = 5,col = 4,cells = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [5, 3], [5, 2], [5, 1], [4, 1], [3, 1], [2, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 2], [4, 3]]) == 3\n assert candidate(row = 4,col = 5,cells = [[1, 2], [1, 3], [1, 4], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [4, 2], [4, 3], [4, 4], [1, 1], [2, 1], [3, 1], [4, 1], [1, 5], [2, 5], [3, 5], [4, 5]]) == 16\n", "comparison": "exact"}, "public_tests": ["2\n2\n[[1,1],[2,1],[1,2],[2,2]]", "2\n2\n[[1,1],[1,2],[2,1],[2,2]]", "3\n3\n[[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]"], "hints": ["What graph algorithm allows us to find whether a path exists?", "Can we use binary search to help us solve the problem?"], "metadata": {"canonical_parameter_names": ["row", "col", "cells"], "leetcode_dataset_entry_point": "Solution().latestDayToCross", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:46+00:00", "tests_total": 54, "tests_dropped": 19, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "depth-first-search", "breadth-first-search", "union-find", "matrix"]}, "language": "php", "interface": {"raw_signature": "function latestDayToCross($row, $col, $cells) {", "container": "Solution", "callable": "latestDayToCross", "parameters": [{"name": "row", "type": "Integer"}, {"name": "col", "type": "Integer"}, {"name": "cells", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1974, "task_id": "minimum-time-to-type-word-using-special-typewriter", "difficulty": "Easy", "problem_description": "There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.\n\nEach second, you may perform one of the following operations:\n\n- Move the pointer one character counterclockwise or clockwise.\n- Type the character the pointer is currently on.\n\nGiven a string word, return the minimum number of seconds to type out the characters in word.\n\nExample 1:\n\nInput: word = \"abc\"\nOutput: 5\nExplanation:\nThe characters are printed as follows:\n- Type the character 'a' in 1 second since the pointer is initially on 'a'.\n- Move the pointer clockwise to 'b' in 1 second.\n- Type the character 'b' in 1 second.\n- Move the pointer clockwise to 'c' in 1 second.\n- Type the character 'c' in 1 second.\n\nExample 2:\n\nInput: word = \"bza\"\nOutput: 7\nExplanation:\nThe characters are printed as follows:\n- Move the pointer clockwise to 'b' in 1 second.\n- Type the character 'b' in 1 second.\n- Move the pointer counterclockwise to 'z' in 2 seconds.\n- Type the character 'z' in 1 second.\n- Move the pointer clockwise to 'a' in 1 second.\n- Type the character 'a' in 1 second.\n\nExample 3:\n\nInput: word = \"zjpc\"\nOutput: 34\nExplanation:\nThe characters are printed as follows:\n- Move the pointer counterclockwise to 'z' in 1 second.\n- Type the character 'z' in 1 second.\n- Move the pointer clockwise to 'j' in 10 seconds.\n- Type the character 'j' in 1 second.\n- Move the pointer clockwise to 'p' in 6 seconds.\n- Type the character 'p' in 1 second.\n- Move the pointer counterclockwise to 'c' in 13 seconds.\n- Type the character 'c' in 1 second.\n\nConstraints:\n\n- 1 <= word.length <= 100\n- word consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aaabbbccc\") == 11\n assert candidate(word = \"zyxwvut\") == 14\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 29\n assert candidate(word = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 178\n assert candidate(word = \"qpwoeirutyalskdjfhgzmxncbv\") == 191\n assert candidate(word = \"zjpc\") == 34\n assert candidate(word = \"abcdz\") == 12\n assert candidate(word = \"pqrstuvwxyzabcdefghijklmno\") == 62\n assert candidate(word = \"aaa\") == 3\n assert candidate(word = \"mnopqrstuvwxyzabcdefghijkl\") == 63\n assert candidate(word = \"z\") == 2\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaa\") == 26\n assert candidate(word = \"qpwoeirutyalskdjfhgzmxncbva\") == 197\n assert candidate(word = \"za\") == 4\n assert candidate(word = \"zzz\") == 4\n assert candidate(word = \"qpwoeirutyalskdjfhgzmxcvbn\") == 193\n assert candidate(word = \"mnonmonmomnonmon\") == 47\n assert candidate(word = \"a\") == 1\n assert candidate(word = \"bza\") == 7\n assert candidate(word = \"abc\") == 5\n assert candidate(word = \"az\") == 3\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\") == 52\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 51\n assert candidate(word = \"abacabadabacaba\") == 37\n assert candidate(word = \"mnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewq\") == 348\n assert candidate(word = \"adgjmpsvxzbehiklnortuwfyqc\") == 110\n assert candidate(word = \"bbaaccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 79\n assert candidate(word = \"aazzbbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 81\n assert candidate(word = \"mamamamamamamamamamamamamam\") == 351\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 47\n assert candidate(word = \"abcdezyxwvut\") == 27\n assert candidate(word = \"zaqwsxcderfvgytujnhytgfrdxcvbnmzaqwsxcderfv\") == 328\n assert candidate(word = \"mnopqrstuvmnopqrstuvmnopqrstuv\") == 87\n assert candidate(word = \"qwertyuioplkjhgfdsazxcvbnmnbvcxzlkjhgfdsapoiuytrewq\") == 323\n assert candidate(word = \"mamamamamamamamamamamamamamamamamamamamamamamamamamama\") == 702\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzz\") == 70\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 346\n assert candidate(word = \"lkjhgfdsapoiuytrewqzxcvbnm\") == 174\n assert candidate(word = \"mjmlkdjfhakjdhfkahdfkldshfklsjdhfkjd\") == 217\n assert candidate(word = \"aaaabbbbccccddddeeeeffffgggghhhhiiii\") == 44\n assert candidate(word = \"lkjhgfdsapoiuytrewqmasdfghjkl\") == 178\n assert candidate(word = \"qponmlkjihgfedcba\") == 43\n assert candidate(word = \"jklmnopqrstuvwxyzaaaazzzzz\") == 53\n assert candidate(word = \"wvutsrqponmlkjihgfedcba\") == 49\n assert candidate(word = \"wertyuioplkjhgfdsamnbvcxzabcd\") == 164\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 33\n assert candidate(word = \"abcdpqrsuvxyzefghijkmnotwxyz\") == 79\n assert candidate(word = \"qwertypasdfghjklzxcvbnmqwertypasdfghjklzxcvbnm\") == 312\n assert candidate(word = \"bdfhjlnprtvxz\") == 38\n assert candidate(word = \"qzcvmlkjhgfdsapoiuytrwer\") == 157\n assert candidate(word = \"mnopqrstuvwxynmlkjihgfedcbazyxw\") == 83\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyza\") == 53\n assert candidate(word = \"zyzzzzzzzzzzzzzzzzzzzzzzzzz\") == 30\n assert candidate(word = \"qwerasdfzxcv\") == 99\n assert candidate(word = \"abcdefghijklnmopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 104\n assert candidate(word = \"abcdpqrsuvxyzefghijkmnotw\") == 73\n assert candidate(word = \"dcbazyxwvutsrqponmlkjihgfedcba\") == 62\n assert candidate(word = \"acdfghjklmnpqrstvwxyz\") == 46\n assert candidate(word = \"mnopqrstuzyxwvutsrqponmlkjihgfedcba\") == 85\n assert candidate(word = \"zxcvbnmlkjhgfdsapoiuytrewqzxcvbnmlkjhgfdsapoiuytrewq\") == 320\n assert candidate(word = \"lkjhgfdsapoiuytrewqzxcvbnmzxcvbnmlkjhgfdsapoiuytrewq\") == 342\n assert candidate(word = \"fedcbazyxwvutsrqponmlkjihg\") == 56\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbb\") == 40\n assert candidate(word = \"mnopqrlkjihgfedcbazyxwvut\") == 66\n assert candidate(word = \"qpwoeirutyalskdjfhgzxcvbnm\") == 172\n assert candidate(word = \"mlkjihgfedcba\") == 37\n assert candidate(word = \"yzab\") == 9\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 102\n assert candidate(word = \"qzmlkihgfedcba\") == 58\n assert candidate(word = \"bcadefghijklmnopqrstuvwxyz\") == 55\n assert candidate(word = \"aaaaaaaaaaaabbbbbbbbccccccccdddddd\") == 37\n assert candidate(word = \"llllllllllllllllllllllllllllllllllllllllllllllllllllllll\") == 67\n assert candidate(word = \"nlbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkbnlkb\") == 392\n assert candidate(word = \"lkjhgfdsazxcvbnmmnbvcxzlkjhgfdsa\") == 176\n assert candidate(word = \"mnopqrsvxyz\") == 36\n assert candidate(word = \"poiuytrewqlkjhgfdsamnbvcxzpoiuytrewqlkjhgfdsamnbvcxz\") == 341\n assert candidate(word = \"qwertypoiuytrewertyuiop\") == 178\n assert candidate(word = \"aaaaabbbbbcccccdddddeeeee\") == 29\n assert candidate(word = \"uqwertyuioplkjhgfdsamnbvcxz\") == 170\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == 104\n assert candidate(word = \"qrstuvzxcvbnmlkjhgfedcba\") == 88\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 35\n assert candidate(word = \"qwerasdfzxcvqwerasdfzxcvqwerasdfzxcv\") == 287\n assert candidate(word = \"lkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkmlkm\") == 136\n assert candidate(word = \"zazazazazazazazazazazazazazazaz\") == 62\n assert candidate(word = \"aazzzzyyyyxxxwwvvuuttrrssqqppoonnmmlkkjjiihhggffeeddaa\") == 82\n assert candidate(word = \"jqpnfjwmsvkmrekjijgqpxvukz\") == 175\n assert candidate(word = \"lkjhgfdsapoiuytrewqasdfghjklmnbvcxz\") == 212\n assert candidate(word = \"ejpmytlrzwhgodicuvnkxfsab\") == 190\n assert candidate(word = \"qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvbnm\") == 310\n assert candidate(word = \"qrstuvwxyzaeiou\") == 55\n assert candidate(word = \"aeiouyaeiouyaeiouyaeiouy\") == 126\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbaa\") == 53\n assert candidate(word = \"poiuytrewqasdfghjklzxcvbnmpoiuytrewqasdfghjklzxcvbnmpoiuytrewq\") == 414\n assert candidate(word = \"abcdefghjklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 101\n assert candidate(word = \"qazwsxedcrfvtgbyhnujmikolpqwazxsedcrfvtgbyhnujmikolpqwaz\") == 361\n assert candidate(word = \"mzaixmsdcvnbmqwerty\") == 169\n assert candidate(word = \"zabcdefghijklmnopqrstuvwxyz\") == 54\n assert candidate(word = \"poiuytrewqlkjhgfdsamnbvcxz\") == 171\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == 111\n assert candidate(word = \"aaaaaaaaaaaaaaaaaaaaaaaaaaab\") == 29\n assert candidate(word = \"pppppppppppppppppppppppppppp\") == 39\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 103\n assert candidate(word = \"abcdefghijkmnopqrstuvwxyz\") == 50\n assert candidate(word = \"azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 58\n assert candidate(word = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 97\n assert candidate(word = \"zaazaaazzaa\") == 17\n assert candidate(word = \"zzzaaazzzaaazzzaaazzzaaazzzaaazzz\") == 44\n assert candidate(word = \"zyxcbaqwertyuiopasdfghjklmnbvcxz\") == 181\n assert candidate(word = \"asdfghjklqwertyuiopzxcvbnm\") == 158\n assert candidate(word = \"pqrstuvwxyzyxwvutsrqponmlkjihgfedcba\") == 82\n assert candidate(word = \"zabcdefghijklmnopqrstuvwxyza\") == 56\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzza\") == 54\n assert candidate(word = \"tgbnhyujmkiolpvcxz\") == 125\n assert candidate(word = \"qwertyuiopasdfghjklzxcvbnm\") == 176\n assert candidate(word = \"qazwsxedcrfvtgbyhnujmikolp\") == 177\n assert candidate(word = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == 118\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 77\n assert candidate(word = \"mnbvcxzlkjhgfdsapoiuytrewqasdfghjklpoiuytrewq\") == 295\n assert candidate(word = \"lkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkj\") == 135\n assert candidate(word = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 103\n assert candidate(word = \"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc\") == 64\n assert candidate(word = \"mnopqrstuvwx\") == 35\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcbaqwertyuiop\") == 129\n assert candidate(word = \"abacabadabacabadabacaba\") == 59\n assert candidate(word = \"fedcbazyxwvutsrqponmlkjihgfedcba\") == 68\n assert candidate(word = \"zaqwsxcderfvgytuhjnmkiolp\") == 156\n", "comparison": "exact"}, "public_tests": ["\"abc\"", "\"bza\"", "\"zjpc\""], "hints": ["There are only two possible directions you can go when you move to the next letter.", "When moving to the next letter, you will always go in the direction that takes the least amount of time."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().minTimeToType", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:53+00:00", "tests_total": 129, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minTimeToType($word) {", "container": "Solution", "callable": "minTimeToType", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1975, "task_id": "maximum-matrix-sum", "difficulty": "Medium", "problem_description": "You are given an n x n integer matrix. You can do the following operation any number of times:\n\n- Choose any two adjacent elements of matrix and multiply each of them by -1.\n\nTwo elements are considered adjacent if and only if they share a border.\n\nYour goal is to maximize the summation of the matrix's elements. Return the maximum sum of the matrix's elements using the operation mentioned above.\n\nExample 1:\n\nInput: matrix = [[1,-1],[-1,1]]\nOutput: 4\nExplanation: We can follow the following steps to reach sum equals 4:\n- Multiply the 2 elements in the first row by -1.\n- Multiply the 2 elements in the first column by -1.\n\nExample 2:\n\nInput: matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]\nOutput: 16\nExplanation: We can follow the following step to reach sum equals 16:\n- Multiply the 2 last elements in the second row by -1.\n\nConstraints:\n\n- n == matrix.length == matrix[i].length\n- 2 <= n <= 250\n- -10^5 <= matrix[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[-1, -2], [3, 4]]) == 10\n assert candidate(matrix = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == 43\n assert candidate(matrix = [[1, 2], [3, -4]]) == 8\n assert candidate(matrix = [[1, 2, 3], [-1, -2, -3], [1, 2, 3]]) == 16\n assert candidate(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(matrix = [[1, 2], [3, 4]]) == 10\n assert candidate(matrix = [[100000, -100000], [-100000, 100000]]) == 400000\n assert candidate(matrix = [[1, 0, -1], [0, 1, 0], [-1, 0, 1]]) == 5\n assert candidate(matrix = [[1, -2], [-3, 4]]) == 10\n assert candidate(matrix = [[1, -1], [-1, 1]]) == 4\n assert candidate(matrix = [[-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]]) == 160\n assert candidate(matrix = [[-1, 2, -3, 4], [5, -6, 7, -8], [-9, 10, -11, 12], [13, -14, 15, -16]]) == 136\n assert candidate(matrix = [[-20, 15, 30], [5, -25, 40], [-10, 25, -35]]) == 205\n assert candidate(matrix = [[0, -100000, 100000, 0], [100000, 0, 0, -100000], [0, 100000, 0, -100000], [-100000, 0, 100000, 0]]) == 800000\n assert candidate(matrix = [[-1, -2, -3, -4], [5, 6, 7, 8], [-9, -10, -11, -12], [13, 14, 15, 16]]) == 136\n assert candidate(matrix = [[100000, 0, 0], [0, 0, 0], [0, 0, -100000]]) == 200000\n assert candidate(matrix = [[1, -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(matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(matrix = [[-1, 0, 1], [0, -2, 0], [1, 0, -1]]) == 6\n assert candidate(matrix = [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]) == 7\n assert candidate(matrix = [[10, 20, 30], [-40, -50, -60], [70, 80, 90]]) == 430\n assert candidate(matrix = [[-1, 2, -3, 4], [-5, 6, -7, 8], [9, -10, 11, -12], [13, -14, 15, -16]]) == 136\n assert candidate(matrix = [[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]]) == 47\n assert candidate(matrix = [[0, 0, 0], [0, -1, 0], [0, 0, 0]]) == 1\n assert candidate(matrix = [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]) == 7\n assert candidate(matrix = [[1, -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(matrix = [[1000, -1000, 1000, -1000], [1000, -1000, 1000, -1000], [-1000, 1000, -1000, 1000], [-1000, 1000, -1000, 1000]]) == 16000\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]]) == 325\n assert candidate(matrix = [[-1, -1, 1, 1], [1, 1, -1, -1], [-1, -1, 1, 1], [1, 1, -1, -1]]) == 16\n assert candidate(matrix = [[-1, 1, -1, 1], [-1, 1, -1, 1], [-1, 1, -1, 1], [-1, 1, -1, 1]]) == 16\n assert candidate(matrix = [[-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]]) == 73\n assert candidate(matrix = [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12], [-13, -14, -15, -16]]) == 136\n assert candidate(matrix = [[-10000, 20000, -30000], [40000, -50000, 60000], [-70000, 80000, -90000]]) == 430000\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], [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]]) == 5050\n assert candidate(matrix = [[100000, 0, -100000, 0], [0, 100000, 0, -100000], [-100000, 0, 100000, 0], [0, -100000, 0, 100000]]) == 800000\n assert candidate(matrix = [[-1, 2, 3], [4, -5, 6], [-7, 8, -9]]) == 45\n assert candidate(matrix = [[-100000, 100000, -100000], [100000, -100000, 100000], [-100000, 100000, -100000]]) == 700000\n assert candidate(matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == 136\n assert candidate(matrix = [[-99999, 99999], [100000, -100000]]) == 399998\n assert candidate(matrix = [[-1, 2, -3, 4], [-5, 6, -7, 8], [-9, 10, -11, 12], [-13, 14, -15, 16]]) == 136\n assert candidate(matrix = [[-10, -20, -30, -40], [-50, -60, -70, -80], [-90, -100, -110, -120], [-130, -140, -150, -160]]) == 1360\n assert candidate(matrix = [[-100000, -100000], [-100000, -100000]]) == 400000\n assert candidate(matrix = [[-5, 3, -2], [-1, 4, -6], [7, -8, 9]]) == 43\n assert candidate(matrix = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]) == 43\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]]) == 325\n assert candidate(matrix = [[-50000, 50000, -60000], [60000, -70000, 70000], [-80000, 80000, -90000]]) == 510000\n assert candidate(matrix = [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12], [-13, -14, -15, -16]]) == 136\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]]) == 323\n assert candidate(matrix = [[-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]]) == 205\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]]) == 325\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]]) == 325\n assert candidate(matrix = [[-99999, 99998, -99997, 99996], [99995, -99994, 99993, -99992], [-99991, 99990, -99989, 99988], [99987, -99986, 99985, -99984]]) == 1599864\n assert candidate(matrix = [[-10, -20, -30], [-40, -50, -60], [-70, -80, -90]]) == 430\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == 0\n assert candidate(matrix = [[-10, -20, -30], [-40, -50, -60], [-70, -80, -90]]) == 430\n assert candidate(matrix = [[-1, 0, 1, 0, -1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [-1, 0, 1, 0, -1]]) == 13\n assert candidate(matrix = [[-99999, 100000, 99999], [-100000, -99999, 100000], [99999, -100000, -99999]]) == 699997\n assert candidate(matrix = [[1, -1, 1, -1], [1, -1, 1, -1], [-1, 1, -1, 1], [-1, 1, -1, 1]]) == 16\n assert candidate(matrix = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]) == 450\n assert candidate(matrix = [[-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]]) == 223\n assert candidate(matrix = [[-1, -1, -1], [1, 1, 1], [-1, -1, -1]]) == 9\n assert candidate(matrix = [[-1, 0, 1], [-2, 0, 2], [-3, 0, 3]]) == 12\n assert candidate(matrix = [[-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1], [-1, 1, -1, 1, -1, 1]]) == 36\n assert candidate(matrix = [[-10000, 10000, -10000, 10000, -10000], [10000, -10000, 10000, -10000, 10000], [-10000, 10000, -10000, 10000, -10000], [10000, -10000, 10000, -10000, 10000], [-10000, 10000, -10000, 10000, -10000]]) == 230000\n assert candidate(matrix = [[1, 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(matrix = [[1, -1, 1, -1], [-1, 1, -1, 1], [1, -1, 1, -1], [-1, 1, -1, 1]]) == 16\n assert candidate(matrix = [[-100000, 100000, -100000, 100000], [100000, -100000, 100000, -100000], [-100000, 100000, -100000, 100000], [100000, -100000, 100000, -100000]]) == 1600000\n assert candidate(matrix = [[100, -100, 200], [-300, 400, -500], [600, -700, 800]]) == 3700\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]]) == 325\n assert candidate(matrix = [[-2, 3, -4], [-1, -2, -3], [4, 5, -6]]) == 30\n assert candidate(matrix = [[0, 1, -1], [1, 0, -1], [-1, 1, 0]]) == 6\n assert candidate(matrix = [[100000, -100000, 100000], [-100000, 100000, -100000], [100000, -100000, 100000]]) == 900000\n assert candidate(matrix = [[-5, -4, 3], [2, 1, 0], [-1, 6, -7]]) == 29\n assert candidate(matrix = [[100000, 0, -100000], [-100000, 0, 100000], [0, 100000, 0]]) == 500000\n assert candidate(matrix = [[1, -1, 2, -2], [3, -3, 4, -4], [5, -5, 6, -6], [7, -7, 8, -8]]) == 72\n assert candidate(matrix = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(matrix = [[-1, 2, -3, 4], [-5, 6, -7, 8], [-9, 10, -11, 12], [13, -14, 15, -16]]) == 136\n assert candidate(matrix = [[100, -200, 300, -400], [500, -600, 700, -800], [900, -1000, 1100, -1200], [-1300, 1400, -1500, 1600]]) == 13600\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]]) == 323\n assert candidate(matrix = [[100000, 100000], [100000, 100000]]) == 400000\n assert candidate(matrix = [[-1, 2, -3, 4], [-5, 6, -7, 8], [9, -10, 11, -12], [-13, 14, -15, 16]]) == 136\n", "comparison": "exact"}, "public_tests": ["[[1,-1],[-1,1]]", "[[1,2,3],[-1,-2,-3],[1,2,3]]"], "hints": ["Try to use the operation so that each row has only one negative number.", "If you have only one negative element you cannot convert it to positive."], "metadata": {"canonical_parameter_names": ["matrix"], "leetcode_dataset_entry_point": "Solution().maxMatrixSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:55+00:00", "tests_total": 85, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "greedy", "matrix"]}, "language": "php", "interface": {"raw_signature": "function maxMatrixSum($matrix) {", "container": "Solution", "callable": "maxMatrixSum", "parameters": [{"name": "matrix", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1976, "task_id": "number-of-ways-to-arrive-at-destination", "difficulty": "Medium", "problem_description": "You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.\n\nYou are given an integer n and a 2D integer array roads where roads[i] = [u_i, v_i, time_i] means that there is a road between intersections u_i and v_i that takes time_i minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.\n\nReturn the number of ways you can arrive at your destination in the shortest amount of time. Since the answer may be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]\nOutput: 4\nExplanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.\nThe four ways to get there in 7 minutes are:\n- 0 ➝ 6\n- 0 ➝ 4 ➝ 6\n- 0 ➝ 1 ➝ 2 ➝ 5 ➝ 6\n- 0 ➝ 1 ➝ 3 ➝ 5 ➝ 6\n\nExample 2:\n\nInput: n = 2, roads = [[1,0,10]]\nOutput: 1\nExplanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.\n\nConstraints:\n\n- 1 <= n <= 200\n- n - 1 <= roads.length <= n * (n - 1) / 2\n- roads[i].length == 3\n- 0 <= u_i, v_i <= n - 1\n- 1 <= time_i <= 10^9\n- u_i!= v_i\n- There is at most one road connecting any two intersections.\n- You can reach any intersection from any other intersection.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,roads = [[0, 1, 1], [0, 2, 4], [0, 3, 3], [0, 4, 10], [1, 2, 2], [1, 3, 4], [1, 4, 6], [2, 3, 3], [2, 4, 5], [3, 4, 1]]) == 1\n assert candidate(n = 4,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 3], [1, 3, 4], [2, 3, 5]]) == 1\n assert candidate(n = 3,roads = [[0, 1, 1], [1, 2, 1], [0, 2, 2]]) == 2\n assert candidate(n = 5,roads = [[0, 1, 2], [0, 4, 8], [1, 2, 6], [1, 4, 2], [2, 3, 3], [3, 4, 2]]) == 1\n assert candidate(n = 5,roads = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 3], [2, 3, 3], [2, 4, 1], [3, 4, 1]]) == 2\n assert candidate(n = 6,roads = [[0, 1, 5], [1, 2, 3], [0, 2, 4], [2, 3, 1], [2, 4, 2], [3, 5, 1], [4, 5, 2]]) == 1\n assert candidate(n = 4,roads = [[0, 1, 1], [0, 2, 1], [1, 2, 1], [1, 3, 1], [2, 3, 1]]) == 2\n assert candidate(n = 7,roads = [[0, 6, 7], [0, 1, 2], [1, 2, 3], [1, 3, 3], [6, 3, 3], [3, 5, 1], [6, 5, 1], [2, 5, 1], [0, 4, 5], [4, 6, 2]]) == 4\n assert candidate(n = 5,roads = [[0, 1, 2], [0, 2, 4], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1]]) == 1\n assert candidate(n = 5,roads = [[0, 1, 1], [0, 2, 1], [1, 2, 1], [1, 3, 1], [2, 4, 1], [3, 4, 1]]) == 1\n assert candidate(n = 4,roads = [[0, 1, 2], [0, 2, 4], [1, 2, 1], [1, 3, 1], [2, 3, 2]]) == 1\n assert candidate(n = 3,roads = [[0, 1, 2], [1, 2, 2], [0, 2, 3]]) == 1\n assert candidate(n = 6,roads = [[0, 1, 4], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 2]]) == 1\n assert candidate(n = 2,roads = [[1, 0, 10]]) == 1\n assert candidate(n = 4,roads = [[0, 1, 1], [0, 2, 5], [1, 2, 1], [2, 3, 1]]) == 1\n assert candidate(n = 8,roads = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 4], [2, 3, 1], [2, 4, 2], [3, 5, 3], [3, 6, 2], [4, 5, 4], [4, 6, 1], [5, 7, 2], [6, 7, 1]]) == 2\n assert candidate(n = 8,roads = [[0, 1, 4], [1, 2, 5], [2, 3, 1], [3, 4, 2], [4, 5, 3], [5, 6, 4], [6, 7, 5], [0, 7, 20], [0, 2, 10], [1, 6, 15], [2, 5, 8], [3, 4, 7]]) == 1\n assert candidate(n = 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, 9, 9], [9, 10, 10], [10, 11, 11], [11, 12, 12], [12, 13, 13], [13, 14, 14], [0, 14, 70], [1, 13, 69], [2, 12, 68], [3, 11, 67], [4, 10, 66], [5, 9, 65], [6, 8, 64]]) == 1\n assert candidate(n = 15,roads = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 1], [7, 8, 2], [8, 9, 1], [9, 10, 2], [10, 11, 3], [11, 12, 1], [12, 13, 2], [13, 14, 1]]) == 1\n assert candidate(n = 8,roads = [[0, 1, 3], [0, 2, 5], [1, 2, 2], [1, 3, 4], [1, 4, 1], [2, 5, 3], [3, 4, 2], [4, 5, 6], [4, 6, 4], [4, 7, 2], [5, 7, 5], [6, 7, 1]]) == 1\n assert candidate(n = 8,roads = [[0, 1, 1], [0, 2, 1], [1, 3, 2], [1, 4, 2], [2, 5, 3], [2, 6, 3], [3, 7, 4], [4, 7, 4], [5, 6, 1], [5, 7, 2], [6, 7, 2]]) == 2\n assert candidate(n = 20,roads = [[0, 1, 2], [0, 2, 10], [0, 3, 5], [1, 4, 1], [1, 5, 3], [1, 6, 4], [2, 5, 2], [2, 7, 6], [3, 6, 5], [3, 8, 7], [4, 9, 1], [4, 10, 2], [5, 9, 4], [5, 10, 3], [5, 11, 1], [6, 11, 3], [7, 11, 2], [7, 12, 10], [8, 12, 5], [8, 13, 3], [9, 13, 4], [9, 14, 6], [10, 14, 5], [11, 14, 3], [11, 15, 2], [11, 16, 1], [12, 16, 2], [12, 17, 10], [13, 17, 5], [14, 17, 3], [14, 18, 2], [14, 19, 1], [15, 18, 2], [16, 19, 3], [17, 19, 1]]) == 2\n assert candidate(n = 6,roads = [[0, 1, 10], [0, 2, 10], [1, 3, 5], [1, 4, 2], [2, 3, 3], [2, 4, 4], [3, 5, 8], [4, 5, 1]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 6], [2, 4, 4], [2, 5, 1], [3, 6, 3], [3, 7, 2], [4, 7, 5], [4, 8, 3], [5, 8, 2], [5, 9, 4], [6, 9, 1], [7, 9, 3]]) == 1\n assert candidate(n = 12,roads = [[0, 1, 6], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 4, 2], [2, 5, 1], [3, 6, 3], [3, 7, 2], [4, 7, 1], [4, 8, 4], [5, 8, 3], [5, 9, 2], [6, 10, 1], [7, 10, 2], [7, 11, 3], [8, 11, 1], [9, 11, 2]]) == 2\n assert candidate(n = 20,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 1], [1, 3, 2], [1, 4, 3], [2, 3, 1], [2, 4, 2], [2, 5, 3], [3, 4, 1], [3, 5, 2], [3, 6, 3], [4, 5, 1], [4, 6, 2], [4, 7, 3], [5, 6, 1], [5, 7, 2], [5, 8, 3], [6, 7, 1], [6, 8, 2], [6, 9, 3], [7, 8, 1], [7, 9, 2], [7, 10, 3], [8, 9, 1], [8, 10, 2], [8, 11, 3], [9, 10, 1], [9, 11, 2], [9, 12, 3], [10, 11, 1], [10, 12, 2], [10, 13, 3], [11, 12, 1], [11, 13, 2], [11, 14, 3], [12, 13, 1], [12, 14, 2], [12, 15, 3], [13, 14, 1], [13, 15, 2], [13, 16, 3], [14, 15, 1], [14, 16, 2], [14, 17, 3], [15, 16, 1], [15, 17, 2], [15, 18, 3], [16, 17, 1], [16, 18, 2], [16, 19, 3], [17, 18, 1], [17, 19, 2], [18, 19, 1]]) == 55403\n assert candidate(n = 15,roads = [[0, 1, 5], [0, 2, 5], [1, 3, 4], [1, 4, 4], [2, 5, 5], [2, 6, 5], [3, 7, 3], [3, 8, 3], [4, 9, 4], [4, 10, 4], [5, 11, 5], [5, 12, 5], [6, 13, 6], [6, 14, 6], [7, 11, 2], [8, 12, 2], [9, 13, 3], [10, 14, 3], [11, 14, 1], [12, 13, 1]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 2], [0, 2, 4], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 4], [7, 8, 5], [8, 9, 6], [0, 3, 5], [1, 4, 3], [2, 5, 6], [3, 6, 7], [4, 7, 8], [5, 8, 9], [6, 9, 10]]) == 2\n assert candidate(n = 15,roads = [[0, 1, 5], [0, 2, 10], [1, 2, 3], [1, 3, 8], [2, 3, 6], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 4], [7, 8, 5], [8, 9, 6], [9, 10, 7], [10, 11, 8], [11, 12, 9], [12, 13, 10], [13, 14, 11], [0, 5, 7], [1, 6, 4], [2, 7, 5], [3, 8, 6], [4, 9, 7], [5, 10, 8], [6, 11, 9], [7, 12, 10], [8, 13, 11], [9, 14, 12]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 2], [1, 3, 3], [2, 4, 4], [3, 4, 3], [3, 5, 5], [4, 6, 6], [5, 7, 7], [6, 8, 8], [7, 8, 9], [8, 9, 10], [0, 3, 4], [1, 4, 5], [2, 5, 6], [3, 6, 7], [4, 7, 8], [5, 8, 9], [6, 9, 10]]) == 2\n assert candidate(n = 9,roads = [[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 1], [1, 5, 2], [2, 5, 3], [2, 6, 2], [3, 6, 1], [3, 7, 2], [4, 8, 1], [5, 8, 2], [6, 8, 3], [7, 8, 4]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 5], [0, 2, 3], [1, 2, 2], [1, 3, 10], [2, 3, 6], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 4], [7, 8, 5], [8, 9, 6], [0, 9, 15], [1, 8, 8], [2, 7, 7], [3, 6, 5]]) == 1\n assert candidate(n = 8,roads = [[0, 1, 1], [0, 2, 1], [1, 3, 2], [2, 3, 2], [1, 4, 1], [2, 5, 1], [3, 6, 3], [4, 6, 3], [5, 7, 4], [6, 7, 4], [1, 5, 2], [2, 4, 2], [0, 3, 3], [0, 4, 3], [1, 2, 3], [3, 5, 4], [4, 5, 4]]) == 1\n assert candidate(n = 20,roads = [[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], [0, 19, 100], [1, 18, 99], [2, 17, 98], [3, 16, 97], [4, 15, 96], [5, 14, 95], [6, 13, 94], [7, 12, 93], [8, 11, 92], [9, 10, 91]]) == 1\n assert candidate(n = 12,roads = [[0, 1, 5], [0, 2, 3], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 1], [7, 8, 2], [8, 9, 1], [9, 10, 2], [10, 11, 3], [11, 4, 1]]) == 2\n assert candidate(n = 10,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], [0, 9, 45], [1, 8, 35], [2, 7, 25], [3, 6, 15], [4, 5, 5]]) == 5\n assert candidate(n = 10,roads = [[0, 1, 4], [0, 2, 3], [1, 3, 2], [1, 4, 1], [2, 3, 5], [2, 4, 2], [3, 5, 1], [4, 5, 3], [5, 6, 2], [5, 7, 1], [6, 8, 2], [7, 8, 1], [8, 9, 3]]) == 1\n assert candidate(n = 10,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], [0, 9, 18]]) == 1\n assert candidate(n = 15,roads = [[0, 1, 5], [0, 2, 4], [1, 2, 3], [1, 3, 2], [2, 3, 1], [2, 4, 6], [3, 4, 5], [3, 5, 7], [3, 6, 2], [4, 5, 4], [4, 6, 3], [4, 7, 10], [5, 6, 6], [5, 7, 8], [5, 8, 4], [6, 7, 7], [6, 8, 9], [7, 8, 11], [7, 9, 6], [8, 9, 3], [9, 10, 2], [9, 11, 5], [9, 12, 7], [10, 11, 3], [10, 12, 6], [11, 12, 4], [11, 13, 8], [11, 14, 2], [12, 13, 5], [12, 14, 9], [13, 14, 1]]) == 4\n assert candidate(n = 8,roads = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10], [0, 7, 70], [1, 6, 60], [2, 5, 50], [3, 4, 40]]) == 1\n assert candidate(n = 15,roads = [[0, 1, 2], [0, 2, 3], [1, 2, 4], [1, 3, 5], [2, 3, 6], [2, 4, 7], [3, 4, 8], [3, 5, 9], [4, 5, 10], [5, 6, 11], [6, 7, 12], [7, 8, 13], [8, 9, 14], [9, 10, 15], [10, 11, 16], [11, 12, 17], [12, 13, 18], [13, 14, 19], [0, 14, 20], [1, 13, 21], [2, 12, 22], [3, 11, 23], [4, 10, 24], [5, 9, 25], [6, 8, 26], [7, 9, 27], [8, 11, 28], [9, 12, 29], [10, 13, 30], [11, 14, 31]]) == 1\n assert candidate(n = 12,roads = [[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, 2], [4, 7, 3], [4, 8, 4], [5, 8, 5], [5, 9, 6], [6, 9, 7], [6, 10, 8], [7, 10, 9], [7, 11, 10], [8, 11, 11], [9, 11, 12]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 1], [7, 8, 2], [8, 9, 1]]) == 1\n assert candidate(n = 9,roads = [[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, 5, 10], [4, 6, 11], [5, 7, 12], [5, 8, 13], [6, 7, 14], [6, 8, 15], [7, 8, 16]]) == 1\n assert candidate(n = 15,roads = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [1, 4, 1], [1, 5, 2], [2, 5, 3], [2, 6, 1], [3, 6, 2], [3, 7, 3], [4, 8, 1], [5, 8, 2], [5, 9, 3], [6, 9, 1], [6, 10, 2], [7, 10, 3], [8, 11, 1], [9, 11, 2], [9, 12, 3], [10, 12, 1], [10, 13, 2], [11, 14, 1], [12, 14, 2], [13, 14, 3]]) == 1\n assert candidate(n = 15,roads = [[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], [0, 14, 900], [1, 13, 800], [2, 12, 700], [3, 11, 600], [4, 10, 500], [5, 9, 400], [6, 8, 300], [7, 9, 200], [8, 10, 100]]) == 1\n assert candidate(n = 12,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 3], [1, 3, 4], [2, 3, 5], [2, 4, 6], [3, 4, 7], [3, 5, 8], [4, 5, 9], [4, 6, 10], [5, 6, 11], [5, 7, 12], [6, 7, 13], [6, 8, 14], [7, 8, 15], [7, 9, 16], [8, 9, 17], [8, 10, 18], [9, 10, 19], [9, 11, 20], [10, 11, 21], [0, 7, 22], [1, 8, 23], [2, 9, 24], [3, 10, 25], [4, 11, 26], [5, 0, 27], [6, 1, 28], [7, 2, 29], [8, 3, 30], [9, 4, 31], [10, 5, 32], [11, 6, 33]]) == 1\n assert candidate(n = 20,roads = [[0, 1, 5], [1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1], [5, 6, 1], [6, 7, 2], [7, 8, 3], [8, 9, 4], [9, 10, 5], [10, 11, 6], [11, 12, 7], [12, 13, 8], [13, 14, 9], [14, 15, 10], [15, 16, 11], [16, 17, 12], [17, 18, 13], [18, 19, 14], [0, 19, 95], [1, 18, 90], [2, 17, 85], [3, 16, 80], [4, 15, 75], [5, 14, 70], [6, 13, 65], [7, 12, 60], [8, 11, 55], [9, 10, 50]]) == 1\n assert candidate(n = 20,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 3], [1, 3, 4], [2, 3, 5], [2, 4, 6], [3, 4, 7], [3, 5, 8], [4, 5, 9], [4, 6, 10], [5, 6, 11], [5, 7, 12], [6, 7, 13], [6, 8, 14], [7, 8, 15], [7, 9, 16], [8, 9, 17], [8, 10, 18], [9, 10, 19], [9, 11, 20], [10, 11, 21], [10, 12, 22], [11, 12, 23], [11, 13, 24], [12, 13, 25], [12, 14, 26], [13, 14, 27], [13, 15, 28], [14, 15, 29], [14, 16, 30], [15, 16, 31], [15, 17, 32], [16, 17, 33], [16, 18, 34], [17, 18, 35], [17, 19, 36], [18, 19, 37]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 2], [0, 2, 5], [1, 2, 1], [1, 3, 3], [2, 4, 2], [3, 4, 2], [3, 5, 1], [4, 5, 1], [4, 6, 4], [5, 6, 3], [5, 7, 5], [6, 7, 2], [6, 8, 6], [7, 8, 1], [7, 9, 3], [8, 9, 2]]) == 10\n assert candidate(n = 8,roads = [[0, 1, 3], [0, 2, 5], [1, 2, 2], [1, 3, 4], [2, 3, 1], [2, 4, 6], [3, 4, 3], [3, 5, 7], [4, 5, 2], [4, 6, 8], [5, 6, 1], [5, 7, 5], [6, 7, 4]]) == 4\n assert candidate(n = 12,roads = [[0, 1, 2], [0, 3, 1], [1, 2, 3], [1, 3, 2], [2, 4, 1], [2, 5, 2], [3, 4, 4], [3, 5, 3], [4, 6, 1], [4, 7, 2], [5, 6, 2], [5, 7, 3], [6, 8, 1], [6, 9, 2], [7, 8, 3], [7, 9, 4], [8, 10, 1], [8, 11, 2], [9, 10, 3], [9, 11, 4]]) == 2\n assert candidate(n = 18,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 3], [1, 3, 4], [2, 3, 5], [2, 4, 6], [3, 4, 7], [3, 5, 8], [4, 5, 9], [4, 6, 10], [5, 6, 11], [5, 7, 12], [6, 7, 13], [6, 8, 14], [7, 8, 15], [7, 9, 16], [8, 9, 17], [8, 10, 18], [9, 10, 19], [9, 11, 20], [10, 11, 21], [10, 12, 22], [11, 12, 23], [11, 13, 24], [12, 13, 25], [12, 14, 26], [13, 14, 27], [13, 15, 28], [14, 15, 29], [14, 16, 30], [15, 16, 31], [15, 17, 32], [16, 17, 33], [0, 13, 34], [1, 14, 35], [2, 15, 36], [3, 16, 37], [4, 17, 38], [5, 0, 39], [6, 1, 40], [7, 2, 41], [8, 3, 42], [9, 4, 43], [10, 5, 44], [11, 6, 45], [12, 7, 46], [13, 8, 47], [14, 9, 48], [15, 10, 49], [16, 11, 50], [17, 12, 51]]) == 1\n assert candidate(n = 10,roads = [[0, 1, 1], [0, 2, 4], [1, 3, 2], [1, 4, 5], [2, 3, 1], [2, 5, 6], [3, 4, 3], [3, 6, 7], [4, 5, 2], [4, 7, 8], [5, 6, 3], [5, 8, 4], [6, 7, 1], [6, 9, 5], [7, 8, 2], [8, 9, 3]]) == 3\n assert candidate(n = 12,roads = [[0, 1, 2], [0, 2, 5], [0, 3, 10], [1, 4, 1], [1, 5, 3], [1, 6, 4], [2, 5, 2], [2, 7, 6], [3, 6, 5], [3, 8, 7], [4, 9, 1], [4, 10, 2], [5, 9, 4], [5, 10, 3], [5, 11, 1], [6, 11, 3], [7, 11, 2], [8, 11, 5], [9, 11, 2], [10, 11, 4]]) == 2\n assert candidate(n = 10,roads = [[0, 1, 1], [0, 3, 5], [1, 2, 2], [1, 3, 4], [2, 3, 1], [3, 4, 1], [4, 5, 2], [5, 6, 1], [6, 7, 2], [7, 8, 1], [8, 9, 2], [0, 2, 3], [2, 4, 2], [4, 6, 1], [6, 8, 2], [1, 5, 3], [5, 7, 1], [7, 9, 2]]) == 1\n assert candidate(n = 15,roads = [[0, 1, 10], [0, 2, 15], [1, 2, 5], [1, 3, 6], [1, 4, 8], [2, 3, 3], [2, 4, 7], [3, 4, 1], [3, 5, 2], [3, 6, 4], [4, 5, 9], [4, 6, 6], [5, 7, 5], [5, 8, 1], [6, 8, 3], [6, 9, 7], [7, 10, 4], [8, 10, 2], [8, 11, 6], [9, 11, 5], [10, 12, 3], [10, 13, 8], [11, 13, 1], [11, 14, 9], [12, 14, 2], [13, 14, 7]]) == 1\n assert candidate(n = 18,roads = [[0, 1, 10], [0, 2, 5], [1, 2, 1], [1, 3, 2], [2, 3, 3], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 1], [7, 8, 2], [8, 9, 1], [9, 10, 2], [10, 11, 3], [11, 12, 1], [12, 13, 2], [13, 14, 1], [14, 15, 2], [15, 16, 3], [16, 17, 1]]) == 2\n assert candidate(n = 15,roads = [[0, 1, 10], [0, 2, 15], [0, 3, 5], [1, 2, 7], [1, 4, 4], [1, 5, 3], [2, 5, 2], [2, 6, 10], [3, 5, 6], [3, 7, 2], [4, 6, 5], [4, 8, 3], [5, 9, 1], [5, 10, 2], [6, 10, 4], [6, 11, 8], [7, 11, 2], [7, 12, 10], [8, 12, 5], [8, 13, 3], [9, 13, 4], [9, 14, 6], [10, 14, 5], [11, 14, 3]]) == 1\n assert candidate(n = 12,roads = [[0, 1, 5], [0, 2, 3], [0, 3, 4], [1, 2, 2], [1, 3, 10], [2, 3, 6], [3, 4, 1], [4, 5, 2], [5, 6, 3], [6, 7, 4], [7, 8, 5], [8, 9, 6], [9, 10, 7], [10, 11, 8], [0, 11, 60], [1, 10, 59], [2, 9, 58], [3, 8, 57], [4, 7, 56], [5, 6, 55]]) == 1\n assert candidate(n = 8,roads = [[0, 1, 1], [0, 2, 2], [1, 2, 3], [1, 3, 4], [2, 3, 5], [2, 4, 6], [3, 4, 7], [3, 5, 8], [4, 5, 9], [4, 6, 10], [5, 6, 11], [5, 7, 12], [6, 7, 13], [0, 5, 14], [1, 6, 15], [2, 7, 16], [0, 3, 17], [1, 4, 18], [2, 5, 19], [3, 6, 20], [4, 7, 21]]) == 1\n assert candidate(n = 18,roads = [[0, 1, 2], [0, 2, 10], [0, 3, 5], [1, 4, 1], [1, 5, 3], [1, 6, 4], [2, 5, 2], [2, 7, 6], [3, 6, 5], [3, 8, 7], [4, 9, 1], [4, 10, 2], [5, 9, 4], [5, 10, 3], [5, 11, 1], [6, 11, 3], [7, 11, 2], [7, 12, 10], [8, 12, 5], [8, 13, 3], [9, 13, 4], [9, 14, 6], [10, 14, 5], [11, 14, 3], [11, 15, 2], [11, 16, 1], [12, 16, 2], [12, 17, 10], [13, 17, 5], [14, 17, 3]]) == 1\n assert candidate(n = 7,roads = [[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 5], [2, 4, 4], [3, 4, 2], [3, 5, 6], [4, 5, 3], [4, 6, 7], [5, 6, 1]]) == 2\n assert candidate(n = 8,roads = [[0, 1, 4], [0, 2, 1], [1, 2, 2], [1, 3, 5], [2, 3, 1], [2, 4, 2], [3, 4, 3], [3, 5, 1], [4, 5, 2], [4, 6, 1], [5, 6, 2], [5, 7, 3], [6, 7, 1]]) == 1\n", "comparison": "exact"}, "public_tests": ["7\n[[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]", "2\n[[1,0,10]]"], "hints": ["First use any shortest path algorithm to get edges where dist[u] + weight = dist[v], here dist[x] is the shortest distance between node 0 and x", "Using those edges only the graph turns into a dag now we just need to know the number of ways to get from node 0 to node n - 1 on a dag using dp"], "metadata": {"canonical_parameter_names": ["n", "roads"], "leetcode_dataset_entry_point": "Solution().countPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:36:58+00:00", "tests_total": 64, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["dynamic-programming", "graph", "topological-sort", "shortest-path", "dijkstra"]}, "language": "php", "interface": {"raw_signature": "function countPaths($n, $roads) {", "container": "Solution", "callable": "countPaths", "parameters": [{"name": "n", "type": "Integer"}, {"name": "roads", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1977, "task_id": "number-of-ways-to-separate-numbers", "difficulty": "Hard", "problem_description": "You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros.\n\nReturn the number of possible lists of integers that you could have written down to get the string num. Since the answer may be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: num = \"327\"\nOutput: 2\nExplanation: You could have written down the numbers:\n3, 27\n327\n\nExample 2:\n\nInput: num = \"094\"\nOutput: 0\nExplanation: No numbers can have leading zeros and all numbers must be positive.\n\nExample 3:\n\nInput: num = \"0\"\nOutput: 0\nExplanation: No numbers can have leading zeros and all numbers must be positive.\n\nConstraints:\n\n- 1 <= num.length <= 3500\n- num consists of digits '0' through '9'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"327\") == 2\n assert candidate(num = \"11110000111100001111\") == 30\n assert candidate(num = \"3333333333\") == 42\n assert candidate(num = \"123456789012345678901234567890\") == 1451\n assert candidate(num = \"0\") == 0\n assert candidate(num = \"10101\") == 2\n assert candidate(num = \"987654321\") == 8\n assert candidate(num = \"123\") == 3\n assert candidate(num = \"094\") == 0\n assert candidate(num = \"1111111111111111111111111111111\") == 6842\n assert candidate(num = \"9876543210987654321098765432109876543210\") == 1307\n assert candidate(num = \"101010\") == 3\n assert candidate(num = \"5555555\") == 15\n assert candidate(num = \"9999999999999999999999999999999\") == 6842\n assert candidate(num = \"100100100100100100100\") == 15\n assert candidate(num = \"24680\") == 6\n assert candidate(num = \"12345678901234567890\") == 287\n assert candidate(num = \"1234567890\") == 41\n assert candidate(num = \"11111\") == 7\n assert candidate(num = \"13579\") == 7\n assert candidate(num = \"12345\") == 7\n assert candidate(num = \"1001\") == 1\n assert candidate(num = \"999\") == 3\n assert candidate(num = \"111\") == 3\n assert candidate(num = \"1000000000000000000000000000000\") == 1\n assert candidate(num = \"112113114115116117118119120121\") == 1464\n assert candidate(num = \"11223344556677889900112233445566\") == 4050\n assert candidate(num = \"112233445566778899001122334455\") == 2836\n assert candidate(num = \"3330333033303330333033303330333\") == 481\n assert candidate(num = \"98765432109876543210\") == 67\n assert candidate(num = \"9999999999999999999999999999998\") == 5604\n assert candidate(num = \"123456789101112131415161718192021\") == 3405\n assert candidate(num = \"012345678901234567890123456789\") == 0\n assert candidate(num = \"987654321109876543211098765432110987654321\") == 1638\n assert candidate(num = \"1234567890123456789012345678901\") == 1716\n assert candidate(num = \"1000000000000000000000000000001\") == 1\n assert candidate(num = \"111222333444555666777888999000111222333444555\") == 41226\n assert candidate(num = \"1234567890123456789012345678901234567890\") == 6307\n assert candidate(num = \"1010101010101010101010101010101\") == 176\n assert candidate(num = \"212121212121212121212121212121\") == 1186\n assert candidate(num = \"11110001111000111100011110001111000111100011110001111000\") == 2300\n assert candidate(num = \"123456789876543211234567898765\") == 2137\n assert candidate(num = \"5555555555555555555555555555555555555555555555555\") == 173525\n assert candidate(num = \"123123123123123123123123123123\") == 1474\n assert candidate(num = \"111111111111111111111111111111111111111111111111\") == 147273\n assert candidate(num = \"321321321321321321321321321321\") == 809\n assert candidate(num = \"12312312312312312312312312312312\") == 2069\n assert candidate(num = \"1231231231231231231231231231230\") == 1641\n assert candidate(num = \"123456789876543211234567898765432112345678987654321\") == 41516\n assert candidate(num = \"123123123123123123123123123123123\") == 2438\n assert candidate(num = \"987654321109876543210987654321\") == 310\n assert candidate(num = \"121212121212121212121212121212\") == 1888\n assert candidate(num = \"1234567898765432109876543210987654321098765432109876543210\") == 81400\n assert candidate(num = \"00000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(num = \"1122334455667788990011223344556677889900\") == 14863\n assert candidate(num = \"1001001001001001001001001001001\") == 42\n assert candidate(num = \"202020202020202020202020202020\") == 176\n assert candidate(num = \"987654321987654321987654321987\") == 423\n assert candidate(num = \"123123123123123123123123123123123123123123123123123123123\") == 78648\n assert candidate(num = \"11112222333344445555666677778888\") == 8349\n assert candidate(num = \"98979695949392919089888786858483\") == 454\n assert candidate(num = \"999000999000999000999000999000999000999000999000999000\") == 1027\n assert candidate(num = \"10203040506070809010\") == 41\n assert candidate(num = \"111222333444555666777888999000\") == 5513\n assert candidate(num = \"2222222222222222222222222222222\") == 6842\n assert candidate(num = \"1234123412341234123412341234123412341234\") == 7113\n assert candidate(num = \"999111999111999111999111999111\") == 987\n assert candidate(num = \"2333233323332333233323332333233323332333233323332333\") == 43205\n assert candidate(num = \"100100100100100100100100100100100100100100100100100\") == 297\n assert candidate(num = \"999999999999999999999999999999999999999999999999\") == 147273\n assert candidate(num = \"1234567891011121314151617181920\") == 2406\n assert candidate(num = \"987654321098765432109876543210\") == 326\n assert candidate(num = \"1231231231231231231231231231231\") == 1751\n assert candidate(num = \"101010101010101010101010101010101010101010101010101\") == 1958\n assert candidate(num = \"999990000099999000009999900000\") == 107\n assert candidate(num = \"999000999000999000999000999000\") == 98\n assert candidate(num = \"99999999988888888877777777666666665555555544444444333333332222222211111111\") == 299850\n assert candidate(num = \"11223344556677889900\") == 616\n assert candidate(num = \"1234567898765432109876543210987654321\") == 5367\n assert candidate(num = \"0123456789012345678901234567890\") == 0\n assert candidate(num = \"10101010101010101010101010101010\") == 231\n assert candidate(num = \"1111111111111111111122222222222222222\") == 21637\n assert candidate(num = \"1010101010101010101010101010102\") == 176\n assert candidate(num = \"22222222222222222222222222222222222222222222222\") == 124754\n assert candidate(num = \"1231231231231231231231231231231231231231231231231231231230\") == 85398\n assert candidate(num = \"12343211234567898765432109876543210\") == 2572\n assert candidate(num = \"123412341234123412341234123412\") == 1471\n assert candidate(num = \"12345432101234543210\") == 199\n assert candidate(num = \"0000000000000000000000000000001\") == 0\n assert candidate(num = \"123456789876543212345678987654321\") == 3452\n assert candidate(num = \"100100100100100100100100100100\") == 42\n assert candidate(num = \"00000000000000000000\") == 0\n assert candidate(num = \"10000000000000000000000000000000000000000000000\") == 1\n assert candidate(num = \"555555555555555555555555555555\") == 5604\n assert candidate(num = \"9999999999999999999999999999999999999999999999\") == 105558\n assert candidate(num = \"303030303030303030303030303030\") == 176\n assert candidate(num = \"1112131415161718192021222324252627282930\") == 12048\n assert candidate(num = \"1212121212121212121212121212121\") == 2059\n assert candidate(num = \"123412341234123412341234123412341234123412341234123412341\") == 69419\n assert candidate(num = \"1213141516171819202122232425262728293031323334353637383940\") == 97025\n assert candidate(num = \"0000000000000000000000000000000\") == 0\n assert candidate(num = \"1010101010101010101010101010101010101010101010\") == 1255\n assert candidate(num = \"1221221221221221221221221221221221221221221221221221\") == 46460\n assert candidate(num = \"123456789101112131415\") == 387\n assert candidate(num = \"1001001001001001001001001001000\") == 42\n", "comparison": "exact"}, "public_tests": ["\"327\"", "\"094\"", "\"0\""], "hints": ["If we know the current number has d digits, how many digits can the previous number have?", "Is there a quick way of calculating the number of possibilities for the previous number if we know that it must have less than or equal to d digits? Try to do some pre-processing."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().numberOfCombinations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:00+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function numberOfCombinations($num) {", "container": "Solution", "callable": "numberOfCombinations", "parameters": [{"name": "num", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1979, "task_id": "find-greatest-common-divisor-of-array", "difficulty": "Easy", "problem_description": "Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.\n\nThe greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n\nExample 1:\n\nInput: nums = [2,5,6,9,10]\nOutput: 2\nExplanation:\nThe smallest number in nums is 2.\nThe largest number in nums is 10.\nThe greatest common divisor of 2 and 10 is 2.\n\nExample 2:\n\nInput: nums = [7,5,6,8,3]\nOutput: 1\nExplanation:\nThe smallest number in nums is 3.\nThe largest number in nums is 8.\nThe greatest common divisor of 3 and 8 is 1.\n\nExample 3:\n\nInput: nums = [3,3]\nOutput: 3\nExplanation:\nThe smallest number in nums is 3.\nThe largest number in nums is 3.\nThe greatest common divisor of 3 and 3 is 3.\n\nConstraints:\n\n- 2 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [42, 56, 14]) == 14\n assert candidate(nums = [1, 1000]) == 1\n assert candidate(nums = [17, 23, 37, 41]) == 1\n assert candidate(nums = [3, 3]) == 3\n assert candidate(nums = [7, 5, 6, 8, 3]) == 1\n assert candidate(nums = [1000, 1000]) == 1000\n assert candidate(nums = [48, 18, 30]) == 6\n assert candidate(nums = [10, 20, 30, 40, 50]) == 10\n assert candidate(nums = [100, 200, 300, 400, 500]) == 100\n assert candidate(nums = [17, 23, 19, 29, 31]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1000, 1]) == 1\n assert candidate(nums = [48, 18]) == 6\n assert candidate(nums = [2, 5, 6, 9, 10]) == 2\n assert candidate(nums = [48, 180, 120, 240]) == 48\n assert candidate(nums = [54, 24, 36]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [56, 98, 140, 224, 336]) == 56\n assert candidate(nums = [81, 27, 9, 3, 1]) == 1\n assert candidate(nums = [22, 44, 66, 88, 110, 132, 154]) == 22\n assert candidate(nums = [27, 54, 81, 108, 135, 162, 189]) == 27\n assert candidate(nums = [999, 1000]) == 1\n assert candidate(nums = [84, 60, 48, 36, 24]) == 12\n assert candidate(nums = [81, 27, 54, 162, 81]) == 27\n assert candidate(nums = [29, 29, 29, 29, 29, 29]) == 29\n assert candidate(nums = [83, 166, 332, 664, 996]) == 83\n assert candidate(nums = [999, 333, 666, 111, 222]) == 111\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136]) == 17\n assert candidate(nums = [1000, 1, 500, 250, 750, 200]) == 1\n assert candidate(nums = [60, 48, 36, 24, 12, 6, 3, 1]) == 1\n assert candidate(nums = [441, 49, 147, 343, 735]) == 49\n assert candidate(nums = [1, 1000, 2, 999, 3, 998]) == 1\n assert candidate(nums = [1000, 10, 50, 250, 500]) == 10\n assert candidate(nums = [44, 55, 66, 77, 88, 99]) == 11\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150]) == 15\n assert candidate(nums = [999, 998, 997, 996, 995]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500]) == 100\n assert candidate(nums = [31, 62, 93, 124, 155]) == 31\n assert candidate(nums = [77, 143, 209, 286, 187]) == 11\n assert candidate(nums = [42, 42, 42, 42, 42]) == 42\n assert candidate(nums = [98, 49, 147, 245, 343, 441, 539]) == 49\n assert candidate(nums = [17, 23, 29, 31, 37]) == 1\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13]) == 13\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == 13\n assert candidate(nums = [999, 888, 777, 666, 555]) == 111\n assert candidate(nums = [1000, 750, 500, 250]) == 250\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260]) == 13\n assert candidate(nums = [54, 24, 36, 48, 60]) == 12\n assert candidate(nums = [1000, 1000, 1000, 1000]) == 1000\n assert candidate(nums = [999, 333, 111, 37, 1]) == 1\n assert candidate(nums = [231, 105, 77, 49, 33, 11, 7]) == 7\n assert candidate(nums = [77, 49, 14, 21, 28]) == 7\n assert candidate(nums = [997, 991, 983, 977, 971, 967, 953, 941, 929, 919, 907, 887, 883]) == 1\n assert candidate(nums = [50, 75, 100, 125, 150, 175, 200]) == 50\n assert candidate(nums = [210, 231, 273, 308, 357, 399]) == 21\n assert candidate(nums = [17, 34, 51, 68, 85]) == 17\n assert candidate(nums = [1, 1000]) == 1\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170]) == 17\n assert candidate(nums = [100, 150, 200, 250, 300]) == 100\n assert candidate(nums = [650, 520, 390, 780, 260]) == 260\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == 100\n assert candidate(nums = [17, 19, 23, 29, 31]) == 1\n assert candidate(nums = [123, 456, 789, 987, 654]) == 3\n assert candidate(nums = [33, 66, 99, 132, 165, 198, 231, 264]) == 33\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [13, 26, 39, 52, 65]) == 13\n assert candidate(nums = [12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 12\n assert candidate(nums = [17, 34, 51, 68, 85, 102]) == 17\n assert candidate(nums = [1, 1000, 2, 500, 4]) == 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]) == 29\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996]) == 1\n assert candidate(nums = [77, 49, 14, 28, 35, 56]) == 7\n assert candidate(nums = [500, 500, 500, 500, 500, 500]) == 500\n assert candidate(nums = [24, 36, 48, 60, 72, 84, 96]) == 24\n assert candidate(nums = [1000, 750, 500, 250, 125, 62, 31]) == 1\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111]) == 111\n assert candidate(nums = [41, 82, 123, 164, 205, 246, 287, 328]) == 41\n assert candidate(nums = [1, 1000, 500, 250, 125, 62, 31, 15]) == 1\n assert candidate(nums = [84, 112, 168, 224, 280]) == 28\n assert candidate(nums = [56, 98, 140, 182, 224]) == 56\n assert candidate(nums = [77, 154, 231, 308, 385, 462, 539, 616]) == 77\n assert candidate(nums = [60, 120, 180, 240, 300, 360]) == 60\n assert candidate(nums = [840, 756, 630, 504, 420]) == 420\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108]) == 12\n assert candidate(nums = [49, 63, 28, 91, 35]) == 7\n assert candidate(nums = [1000, 500, 250, 125, 62]) == 2\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [27, 81, 54, 162, 243]) == 27\n assert candidate(nums = [101, 202, 303, 404, 505]) == 101\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203]) == 29\n assert candidate(nums = [24, 36, 48, 60, 72, 84]) == 12\n assert candidate(nums = [840, 756, 672, 588, 504, 420, 336, 252, 168, 84]) == 84\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == 101\n assert candidate(nums = [997, 991, 983, 977, 971]) == 1\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137]) == 1\n assert candidate(nums = [987, 654, 321, 123, 456, 789]) == 3\n assert candidate(nums = [101, 103, 107, 109, 113]) == 1\n assert candidate(nums = [23, 47, 17, 53, 31, 19, 89, 73]) == 1\n", "comparison": "exact"}, "public_tests": ["[2,5,6,9,10]", "[7,5,6,8,3]", "[3,3]"], "hints": ["Find the minimum and maximum in one iteration. Let them be mn and mx.", "Try all the numbers in the range [1, mn] and check the largest number which divides both of them."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findGCD", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:02+00:00", "tests_total": 117, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "math", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function findGCD($nums) {", "container": "Solution", "callable": "findGCD", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1980, "task_id": "find-unique-binary-string", "difficulty": "Medium", "problem_description": "Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.\n\nExample 1:\n\nInput: nums = [\"01\",\"10\"]\nOutput: \"11\"\nExplanation: \"11\" does not appear in nums. \"00\" would also be correct.\n\nExample 2:\n\nInput: nums = [\"00\",\"01\"]\nOutput: \"11\"\nExplanation: \"11\" does not appear in nums. \"10\" would also be correct.\n\nExample 3:\n\nInput: nums = [\"111\",\"011\",\"001\"]\nOutput: \"101\"\nExplanation: \"101\" does not appear in nums. \"000\", \"010\", \"100\", and \"110\" would also be correct.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 16\n- nums[i].length == n\n- nums[i] is either '0' or '1'.\n- All the strings of nums are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = ['01', '10']) == \"00\"\n assert candidate(nums = ['00', '01']) == \"11\"\n assert candidate(nums = ['111', '011', '001']) == \"000\"\n assert candidate(nums = ['1101', '1011', '0111', '0011']) == \"0000\"\n assert candidate(nums = ['1100', '0011', '1010', '0101']) == \"0000\"\n assert candidate(nums = ['101010', '010101', '001100', '110011', '111100', '000011']) == \"000000\"\n assert candidate(nums = ['1100', '1011', '0011', '1110']) == \"0000\"\n assert candidate(nums = ['1101', '0010', '1001', '0110']) == \"0000\"\n assert candidate(nums = ['1100', '0101', '1010', '0011']) == \"0000\"\n assert candidate(nums = ['11111111', '00000000', '10101010', '01010101', '11001100', '00110011', '10011001', '01100110']) == \"10000000\"\n assert candidate(nums = ['1100', '1010', '0110', '0001']) == \"0000\"\n assert candidate(nums = ['1010', '0101', '1111', '0000']) == \"1000\"\n assert candidate(nums = ['1010', '0101', '1100', '0011']) == \"0000\"\n", "comparison": "exact"}, "public_tests": ["[\"01\",\"10\"]", "[\"00\",\"01\"]", "[\"111\",\"011\",\"001\"]"], "hints": ["We can convert the given strings into base 10 integers.", "Can we use recursion to generate all possible strings?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findDifferentBinaryString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:04+00:00", "tests_total": 54, "tests_dropped": 41, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "string", "backtracking"]}, "language": "php", "interface": {"raw_signature": "function findDifferentBinaryString($nums) {", "container": "Solution", "callable": "findDifferentBinaryString", "parameters": [{"name": "nums", "type": "String[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1981, "task_id": "minimize-the-difference-between-target-and-chosen-elements", "difficulty": "Medium", "problem_description": "You are given an m x n integer matrix mat and an integer target.\n\nChoose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.\n\nReturn the minimum absolute difference.\n\nThe absolute difference between two numbers a and b is the absolute value of a - b.\n\nExample 1:\n\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13\nOutput: 0\nExplanation: One possible choice is to:\n- Choose 1 from the first row.\n- Choose 5 from the second row.\n- Choose 7 from the third row.\nThe sum of the chosen elements is 13, which equals the target, so the absolute difference is 0.\n\nExample 2:\n\nInput: mat = [[1],[2],[3]], target = 100\nOutput: 94\nExplanation: The best possible choice is to:\n- Choose 1 from the first row.\n- Choose 2 from the second row.\n- Choose 3 from the third row.\nThe sum of the chosen elements is 6, and the absolute difference is 94.\n\nExample 3:\n\nInput: mat = [[1,2,9,8,7]], target = 6\nOutput: 1\nExplanation: The best choice is to choose 7 from the first row.\nThe absolute difference is 1.\n\nConstraints:\n\n- m == mat.length\n- n == mat[i].length\n- 1 <= m, n <= 70\n- 1 <= mat[i][j] <= 70\n- 1 <= target <= 800\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mat = [[1], [2], [3]],target = 100) == 94\n assert candidate(mat = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],target = 15) == 0\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],target = 13) == 0\n assert candidate(mat = [[7, 8, 9], [1, 2, 3], [4, 5, 6]],target = 20) == 2\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19]],target = 25) == 1\n assert candidate(mat = [[10, 20, 30], [5, 15, 25], [1, 10, 20]],target = 50) == 4\n assert candidate(mat = [[7, 8, 9], [10, 11, 12], [13, 14, 15]],target = 36) == 0\n assert candidate(mat = [[70, 70, 70], [70, 70, 70], [70, 70, 70]],target = 150) == 60\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15]],target = 20) == 0\n assert candidate(mat = [[70, 70, 70], [70, 70, 70], [70, 70, 70]],target = 100) == 110\n assert candidate(mat = [[1, 2, 9, 8, 7]],target = 6) == 1\n assert candidate(mat = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],target = 5) == 2\n assert candidate(mat = [[1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]],target = 21) == 0\n assert candidate(mat = [[70, 70, 70, 70, 70], [70, 70, 70, 70, 70], [70, 70, 70, 70, 70]],target = 800) == 590\n assert candidate(mat = [[2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [5, 10, 15, 20, 25], [7, 14, 21, 28, 35]],target = 100) == 15\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 1, 1, 1, 1]],target = 25) == 5\n assert candidate(mat = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [7, 17, 27, 37, 47]],target = 150) == 3\n assert candidate(mat = [[5, 15, 25], [5, 15, 25], [5, 15, 25], [5, 15, 25], [5, 15, 25]],target = 50) == 5\n assert candidate(mat = [[70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1], [70, 1]],target = 200) == 14\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]],target = 75) == 12\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]],target = 105) == 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, 21]],target = 50) == 8\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]],target = 100) == 30\n assert candidate(mat = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 2, 3, 4, 5]],target = 85) == 1\n assert candidate(mat = [[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]],target = 420) == 165\n assert candidate(mat = [[10, 20, 30, 40, 50, 60, 70], [70, 60, 50, 40, 30, 20, 10], [1, 2, 3, 4, 5, 6, 7]],target = 200) == 53\n assert candidate(mat = [[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]],target = 50) == 35\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19], [20, 22, 24, 26, 28]],target = 50) == 0\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]],target = 50) == 1\n assert candidate(mat = [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60]],target = 120) == 0\n assert candidate(mat = [[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]],target = 50) == 16\n assert candidate(mat = [[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]],target = 400) == 50\n assert candidate(mat = [[1, 70], [2, 69], [3, 68], [4, 67], [5, 66], [6, 65], [7, 64], [8, 63], [9, 62], [10, 61]],target = 400) == 1\n assert candidate(mat = [[5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [1, 6, 11, 16, 21, 26, 31, 36, 41, 46], [2, 7, 12, 17, 22, 27, 32, 37, 42, 47], [3, 8, 13, 18, 23, 28, 33, 38, 43, 48]],target = 150) == 1\n assert candidate(mat = [[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]],target = 28) == 0\n assert candidate(mat = [[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]],target = 260) == 22\n assert candidate(mat = [[70, 69, 68], [67, 66, 65], [64, 63, 62], [61, 60, 59], [58, 57, 56]],target = 250) == 60\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]],target = 100) == 30\n assert candidate(mat = [[50, 49, 48, 47, 46, 45, 44], [43, 42, 41, 40, 39, 38, 37], [36, 35, 34, 33, 32, 31, 30]],target = 130) == 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]],target = 10) == 6\n assert candidate(mat = [[3, 10, 7], [8, 6, 4], [15, 12, 9], [18, 16, 13]],target = 50) == 1\n assert candidate(mat = [[7, 8, 9], [1, 2, 3], [4, 5, 6], [10, 11, 12]],target = 25) == 0\n assert candidate(mat = [[7, 21, 42, 58], [9, 23, 46, 62], [11, 25, 49, 65], [13, 27, 51, 67], [15, 29, 53, 69]],target = 200) == 0\n assert candidate(mat = [[70, 60, 50, 40, 30], [20, 30, 40, 50, 60], [10, 20, 30, 40, 50]],target = 200) == 20\n assert candidate(mat = [[7, 17, 27, 37, 47], [8, 18, 28, 38, 48], [9, 19, 29, 39, 49], [10, 20, 30, 40, 50], [11, 21, 31, 41, 51]],target = 150) == 5\n assert candidate(mat = [[70, 69, 68, 67], [66, 65, 64, 63], [62, 61, 60, 59], [58, 57, 56, 55]],target = 260) == 4\n assert candidate(mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],target = 80) == 30\n assert candidate(mat = [[7, 8, 9], [4, 5, 6], [1, 2, 3], [7, 8, 9], [4, 5, 6], [1, 2, 3]],target = 30) == 0\n assert candidate(mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],target = 50) == 5\n assert candidate(mat = [[70, 60, 50, 40, 30], [10, 20, 30, 40, 50], [60, 50, 40, 30, 20], [1, 2, 3, 4, 5]],target = 180) == 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]],target = 60) == 0\n assert candidate(mat = [[1, 3, 5, 7, 9, 11, 13], [2, 4, 6, 8, 10, 12, 14], [15, 17, 19, 21, 23, 25, 27]],target = 50) == 0\n assert candidate(mat = [[10, 20, 30], [11, 21, 31], [12, 22, 32], [13, 23, 33], [14, 24, 34]],target = 120) == 0\n assert candidate(mat = [[5, 5, 5, 5, 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 = 10) == 10\n assert candidate(mat = [[1, 3, 5, 7], [2, 4, 6, 8], [9, 11, 13, 15], [17, 19, 21, 23]],target = 30) == 1\n assert candidate(mat = [[1, 70], [1, 70], [1, 70], [1, 70], [1, 70], [1, 70], [1, 70]],target = 300) == 17\n assert candidate(mat = [[10, 20, 30], [15, 25, 35], [20, 30, 40], [25, 35, 45]],target = 120) == 0\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15]],target = 100) == 66\n assert candidate(mat = [[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]],target = 20) == 10\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]],target = 150) == 45\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, 1, 1, 1]],target = 1) == 5\n assert candidate(mat = [[5, 10, 15], [10, 20, 30], [15, 25, 35], [20, 30, 40], [25, 35, 45]],target = 100) == 0\n assert candidate(mat = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41]],target = 120) == 4\n assert candidate(mat = [[70, 70, 70], [70, 70, 70], [70, 70, 70], [70, 70, 70], [70, 70, 70], [70, 70, 70], [70, 70, 70]],target = 800) == 310\n assert candidate(mat = [[5, 15, 25], [10, 20, 30], [15, 25, 35], [20, 30, 40]],target = 100) == 0\n assert candidate(mat = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]],target = 50) == 0\n assert candidate(mat = [[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]],target = 100) == 85\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19]],target = 50) == 12\n assert candidate(mat = [[5, 15, 25, 35], [10, 20, 30, 40], [15, 25, 35, 45], [20, 30, 40, 50], [25, 35, 45, 55]],target = 200) == 5\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19]],target = 30) == 0\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]],target = 10) == 3\n assert candidate(mat = [[70, 60, 50, 40, 30, 20, 10], [65, 55, 45, 35, 25, 15, 5], [1, 2, 3, 4, 5, 6, 7]],target = 200) == 58\n assert candidate(mat = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20]],target = 40) == 0\n assert candidate(mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]],target = 30) == 4\n assert candidate(mat = [[1, 5, 9, 14], [3, 7, 10, 17], [4, 8, 12, 19], [6, 11, 15, 20]],target = 45) == 0\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]],target = 50) == 8\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]],target = 55) == 22\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]],target = 15) == 0\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]],target = 150) == 0\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]],target = 30) == 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, 41, 42]],target = 200) == 53\n assert candidate(mat = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]],target = 49) == 0\n assert candidate(mat = [[7, 8, 9], [1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6], [7, 8, 9]],target = 50) == 5\n assert candidate(mat = [[7, 8, 9], [1, 2, 3], [4, 5, 6], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21]],target = 80) == 0\n assert candidate(mat = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]],target = 25) == 15\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]],target = 100) == 16\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, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1]],target = 7) == 0\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[4,5,6],[7,8,9]]\n13", "[[1],[2],[3]]\n100", "[[1,2,9,8,7]]\n6"], "hints": ["The sum of chosen elements will not be too large. Consider using a hash set to record all possible sums while iterating each row.", "Instead of keeping track of all possible sums, since in each row, we are adding positive numbers, only keep those that can be a candidate, not exceeding the target by too much."], "metadata": {"canonical_parameter_names": ["mat", "target"], "leetcode_dataset_entry_point": "Solution().minimizeTheDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:07+00:00", "tests_total": 104, "tests_dropped": 17, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "php", "interface": {"raw_signature": "function minimizeTheDifference($mat, $target) {", "container": "Solution", "callable": "minimizeTheDifference", "parameters": [{"name": "mat", "type": "Integer[][]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1982, "task_id": "find-array-given-subset-sums", "difficulty": "Hard", "problem_description": "You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2^n subset sums of the unknown array (in no particular order).\n\nReturn the array ans of length n representing the unknown array. If multiple answers exist, return any of them.\n\nAn array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0.\n\nNote: Test cases are generated such that there will always be at least one correct answer.\n\nExample 1:\n\nInput: n = 3, sums = [-3,-2,-1,0,0,1,2,3]\nOutput: [1,2,-3]\nExplanation: [1,2,-3] is able to achieve the given subset sums:\n- []: sum is 0\n- [1]: sum is 1\n- [2]: sum is 2\n- [1,2]: sum is 3\n- [-3]: sum is -3\n- [1,-3]: sum is -2\n- [2,-3]: sum is -1\n- [1,2,-3]: sum is 0\nNote that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.\n\nExample 2:\n\nInput: n = 2, sums = [0,0,0,0]\nOutput: [0,0]\nExplanation: The only correct answer is [0,0].\n\nExample 3:\n\nInput: n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8]\nOutput: [0,-1,4,5]\nExplanation: [0,-1,4,5] is able to achieve the given subset sums.\n\nConstraints:\n\n- 1 <= n <= 15\n- sums.length == 2^n\n- -10^4 <= sums[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3,sums = [-3, -2, -1, 0, 0, 1, 2, 3]) == [-1, -2, 3]\n assert candidate(n = 2,sums = [0, 0, 0, 0]) == [0, 0]\n assert candidate(n = 1,sums = [0, 5]) == [5]\n assert candidate(n = 3,sums = [3, 1, 2, 0, 4, 5, 6, 8]) == [1, 2, 4]\n assert candidate(n = 4,sums = [0, 0, 5, 5, 4, -1, 4, 9, 9, -1, 4, 3, 4, 8, 3, 8]) == [0, -1, 4, 5]\n assert candidate(n = 1,sums = [0, -1]) == [-1]\n assert candidate(n = 4,sums = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == [0, 1, 2, 4]\n assert candidate(n = 4,sums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 2, 4, 8]\n assert candidate(n = 3,sums = [0, 2, 2, 4, 6, 6, 8, 10]) == [2, 2, 6]\n assert candidate(n = 3,sums = [1, 2, 3, 4, 5, 6, 7, 8]) == [1, 2, 4]\n assert candidate(n = 4,sums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == [1, -2, 4, -8]\n assert candidate(n = 4,sums = [0, -1, -2, -3, -4, 1, 2, 3, 4, -5, 5, -6, 6, -7, 7, 8]) == [-1, -2, -4, 8]\n assert candidate(n = 3,sums = [10, 20, 30, 40, 50, 60, 70, 80]) == [10, 20, 40]\n assert candidate(n = 4,sums = [-1, -2, -3, -4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1, 2, -4, 8]\n assert candidate(n = 4,sums = [-9, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]) == [-2, -3, -4, 8]\n assert candidate(n = 5,sums = [1, 2, 3, 4, 5, 6, 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, 2, 4, 8, 16]\n assert candidate(n = 6,sums = [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]) == [1, 2, 4, 8, 16, 32]\n assert candidate(n = 4,sums = [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [-1, -2, 4, 8]\n assert candidate(n = 4,sums = [-10, -7, -9, -8, -5, -6, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == [1, -2, 4, -8]\n assert candidate(n = 3,sums = [-4, -2, -1, 0, 0, 1, 2, 4]) == [2, 3, -4]\n assert candidate(n = 4,sums = [-6, -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2]) == [-1, -1, 2, -4]\n assert candidate(n = 5,sums = [-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [-1, -2, -4, -8, 15]\n assert candidate(n = 1,sums = [0, 2]) == [2]\n assert candidate(n = 6,sums = [-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, 1, 2, 3, 4, 5, 6, 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]) == [-1, -2, -4, -8, -16, 31]\n assert candidate(n = 3,sums = [-5, -3, -2, -1, 0, 0, 1, 2]) == [-2, -3, 4]\n assert candidate(n = 3,sums = [-1, -1, -1, -1, -1, 0, 0, 0]) == [0, 0, 0]\n assert candidate(n = 1,sums = [0, 1]) == [1]\n assert candidate(n = 4,sums = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == [0, 0, 1, 2]\n assert candidate(n = 1,sums = [0, 3]) == [3]\n assert candidate(n = 2,sums = [-1, 0, 1, 2]) == [-1, 2]\n assert candidate(n = 4,sums = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == [1, -2, 4, -8]\n assert candidate(n = 1,sums = [0, -5]) == [-5]\n assert candidate(n = 4,sums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [0, 0, 0, 0]\n assert candidate(n = 2,sums = [-2, -1, 0, 1]) == [1, -2]\n assert candidate(n = 3,sums = [-3, -1, 0, 1, 2, 3, 4, 6]) == [2, -3, 4]\n assert candidate(n = 3,sums = [-1, -2, -3, 0, 1, 2, 3, 4]) == [-1, -2, 4]\n assert candidate(n = 1,sums = [0, 0]) == [0]\n assert candidate(n = 3,sums = [-3, -2, -1, -1, 0, 0, 1, 2]) == [-1, -2, 2]\n assert candidate(n = 3,sums = [1, 2, 3, 4, 5, 6, 7, 8]) == [1, 2, 4]\n", "comparison": "exact"}, "public_tests": ["3\n[-3,-2,-1,0,0,1,2,3]", "2\n[0,0,0,0]", "4\n[0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8]"], "hints": ["What information do the two largest elements tell us?", "Can we use recursion to check all possible states?"], "metadata": {"canonical_parameter_names": ["n", "sums"], "leetcode_dataset_entry_point": "Solution().recoverArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:09+00:00", "tests_total": 89, "tests_dropped": 50, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function recoverArray($n, $sums) {", "container": "Solution", "callable": "recoverArray", "parameters": [{"name": "n", "type": "Integer"}, {"name": "sums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1984, "task_id": "minimum-difference-between-highest-and-lowest-of-k-scores", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums, where nums[i] represents the score of the i^th student. You are also given an integer k.\n\nPick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.\n\nReturn the minimum possible difference.\n\nExample 1:\n\nInput: nums = [90], k = 1\nOutput: 0\nExplanation: There is one way to pick score(s) of one student:\n- [90]. The difference between the highest and lowest score is 90 - 90 = 0.\nThe minimum possible difference is 0.\n\nExample 2:\n\nInput: nums = [9,4,1,7], k = 2\nOutput: 2\nExplanation: There are six ways to pick score(s) of two students:\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.\n- [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.\n- [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.\n- [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.\nThe minimum possible difference is 2.\n\nConstraints:\n\n- 1 <= k <= nums.length <= 1000\n- 0 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 9, 1, 32, 13],k = 3) == 8\n assert candidate(nums = [1, 5, 6, 14, 15],k = 3) == 5\n assert candidate(nums = [9, 4, 1, 7],k = 2) == 2\n assert candidate(nums = [8, 10, 2],k = 2) == 2\n assert candidate(nums = [1, 5, 9, 14, 18],k = 3) == 8\n assert candidate(nums = [4, 9, 1, 17, 6, 11, 22],k = 5) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [8, 10, 5, 7, 9, 3],k = 4) == 3\n assert candidate(nums = [4, 9, 1, 32, 13],k = 2) == 3\n assert candidate(nums = [90],k = 1) == 0\n assert candidate(nums = [8, 10, 12, 14, 16],k = 3) == 4\n assert candidate(nums = [4, 2, 1, 3],k = 2) == 1\n assert candidate(nums = [8, 8, 8, 8, 8],k = 5) == 0\n assert candidate(nums = [1, 5, 6, 14, 15],k = 2) == 1\n assert candidate(nums = [100000, 0, 1, 2, 99999],k = 2) == 1\n assert candidate(nums = [8, 10, 15, 17, 20, 23],k = 4) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 3\n assert candidate(nums = [1, 3, 6, 19, 20],k = 3) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 10) == 900\n assert candidate(nums = [5, 8, 12, 19, 23, 27, 31, 35, 39, 41, 45, 49, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99],k = 5) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 40\n assert candidate(nums = [28, 90, 3, 23, 90, 18, 39, 72, 45, 67],k = 5) == 27\n assert candidate(nums = [88, 22, 55, 77, 33, 44, 66, 11, 99, 0, 6, 3, 5, 7, 9, 1, 2, 4, 8, 10, 12, 14, 16, 18, 20, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 90, 92, 94, 96, 98],k = 10) == 9\n assert candidate(nums = [50, 40, 30, 20, 10, 90, 80, 70, 60, 100],k = 5) == 40\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 8) == 700\n assert candidate(nums = [1, 3, 6, 19, 20, 25, 28, 30, 31, 32, 33],k = 6) == 8\n assert candidate(nums = [500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50],k = 7) == 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],k = 3) == 0\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 5) == 4\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020],k = 11) == 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, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400],k = 13) == 120\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980],k = 15) == 14\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],k = 3) == 2000\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 = 15) == 140\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 = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 0, 99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 0],k = 15) == 77777\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 10000, 20000, 30000, 40000, 50000],k = 10) == 40000\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120],k = 6) == 5\n assert candidate(nums = [123, 456, 789, 101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717],k = 8) == 505\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 = 30) == 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 = 5) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 90000, 9000, 900, 90],k = 3) == 89\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 4) == 3\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 = 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],k = 10) == 9\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],k = 10) == 72\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 4) == 3\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, 3, 9, 3, 2, 8, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0],k = 20) == 1\n assert candidate(nums = [5, 15, 30, 10, 20, 25, 40, 50],k = 5) == 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],k = 11) == 1000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 40\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 6) == 50\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 = 1) == 0\n assert candidate(nums = [1, 3, 6, 19, 20, 25, 30, 35, 40, 45, 50],k = 6) == 21\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 3) == 20000\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, 85, 89, 93, 97, 101, 105, 109],k = 10) == 36\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 = 2) == 0\n assert candidate(nums = [80, 60, 40, 20, 0, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480],k = 7) == 120\n assert candidate(nums = [23, 45, 12, 67, 89, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90],k = 8) == 23\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == 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],k = 10) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7) == 60\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 3) == 200\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7) == 60\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],k = 3) == 2\n assert candidate(nums = [45, 33, 21, 10, 1, 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],k = 25) == 41\n assert candidate(nums = [300, 200, 100, 50, 25, 10, 5, 3, 2, 1, 0, 1, 3, 5, 10, 25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 15) == 99\n assert candidate(nums = [99999, 100000, 0, 1, 2, 99998, 3, 4, 5, 6],k = 4) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 210, 311, 412, 513, 614, 715, 816, 917, 1018],k = 8) == 77\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) == 90\n assert candidate(nums = [8, 18, 28, 38, 48, 58, 68, 78, 88, 98, 108, 118, 128, 138, 148, 158],k = 3) == 20\n assert candidate(nums = [34, 7, 23, 32, 5, 62],k = 4) == 27\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 7) == 60\n assert candidate(nums = [5, 8, 12, 18, 23, 30, 37, 45, 53, 62],k = 6) == 25\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 = 26) == 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],k = 15) == 14\n assert candidate(nums = [89, 75, 91, 85, 92, 88, 76, 90, 86, 84],k = 4) == 3\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991],k = 10) == 9\n assert candidate(nums = [5, 8, 12, 18, 22, 27, 30, 35, 40, 45, 50],k = 5) == 17\n assert candidate(nums = [987, 654, 321, 654, 321, 987, 654, 321, 987, 654, 321, 987, 654, 321, 987],k = 6) == 333\n assert candidate(nums = [345, 678, 901, 234, 567, 890, 123, 456, 789],k = 4) == 223\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 = 9) == 16\n assert candidate(nums = [5, 23, 9, 56, 12, 89, 76, 45, 34, 67, 88, 90],k = 5) == 23\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 0\n", "comparison": "exact"}, "public_tests": ["[90]\n1", "[9,4,1,7]\n2"], "hints": ["For the difference between the highest and lowest element to be minimized, the k chosen scores need to be as close to each other as possible.", "What if the array was sorted?", "After sorting the scores, any contiguous k scores are as close to each other as possible.", "Apply a sliding window solution to iterate over each contiguous k scores, and find the minimum of the differences of all windows."], "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-30T20:37:14+00:00", "tests_total": 95, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "sliding-window", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumDifference($nums, $k) {", "container": "Solution", "callable": "minimumDifference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1985, "task_id": "find-the-kth-largest-integer-in-the-array", "difficulty": "Medium", "problem_description": "You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.\n\nReturn the string that represents the k^th largest integer in nums.\n\nNote: Duplicate numbers should be counted distinctly. For example, if nums is [\"1\",\"2\",\"2\"], \"2\" is the first largest integer, \"2\" is the second-largest integer, and \"1\" is the third-largest integer.\n\nExample 1:\n\nInput: nums = [\"3\",\"6\",\"7\",\"10\"], k = 4\nOutput: \"3\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"3\",\"6\",\"7\",\"10\"].\nThe 4^th largest integer in nums is \"3\".\n\nExample 2:\n\nInput: nums = [\"2\",\"21\",\"12\",\"1\"], k = 3\nOutput: \"2\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"1\",\"2\",\"12\",\"21\"].\nThe 3^rd largest integer in nums is \"2\".\n\nExample 3:\n\nInput: nums = [\"0\",\"0\"], k = 2\nOutput: \"0\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"0\",\"0\"].\nThe 2^nd largest integer in nums is \"0\".\n\nConstraints:\n\n- 1 <= k <= nums.length <= 10^4\n- 1 <= nums[i].length <= 100\n- nums[i] consists of only digits.\n- nums[i] will not have any leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = ['100', '200', '300', '400', '500'],k = 2) == \"400\"\n assert candidate(nums = ['2', '21', '12', '1'],k = 3) == \"2\"\n assert candidate(nums = ['9', '8', '7', '6', '5', '4', '3', '2', '1'],k = 5) == \"5\"\n assert candidate(nums = ['100', '200', '300', '400'],k = 2) == \"300\"\n assert candidate(nums = ['9', '11', '8', '9', '10'],k = 5) == \"8\"\n assert candidate(nums = ['9', '11', '2', '22'],k = 2) == \"11\"\n assert candidate(nums = ['10', '20', '30', '40', '50'],k = 5) == \"10\"\n assert candidate(nums = ['10', '10', '10', '10'],k = 3) == \"10\"\n assert candidate(nums = ['0', '0'],k = 2) == \"0\"\n assert candidate(nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],k = 10) == \"1\"\n assert candidate(nums = ['100', '200', '300', '400'],k = 1) == \"400\"\n assert candidate(nums = ['10', '2', '11', '3', '7'],k = 1) == \"11\"\n assert candidate(nums = ['5', '3', '8', '6', '7'],k = 1) == \"8\"\n assert candidate(nums = ['1', '2', '2', '3', '3', '3'],k = 4) == \"2\"\n assert candidate(nums = ['10', '100', '1000', '10000'],k = 3) == \"100\"\n assert candidate(nums = ['3', '6', '7', '10'],k = 4) == \"3\"\n assert candidate(nums = ['100', '200', '300', '400', '500', '600', '700', '800', '900'],k = 9) == \"100\"\n assert candidate(nums = ['500', '50', '5000', '50000', '5'],k = 4) == \"50\"\n assert candidate(nums = ['987654321', '987654320', '987654319', '987654318', '987654317'],k = 5) == \"987654317\"\n assert candidate(nums = ['123456789', '987654321', '135792468', '246813579', '864209753'],k = 3) == \"246813579\"\n assert candidate(nums = ['1', '11', '111', '1111', '11111'],k = 3) == \"111\"\n assert candidate(nums = ['111', '222', '333', '444', '555', '666', '777', '888', '999', '000'],k = 7) == \"333\"\n assert candidate(nums = ['500', '50', '5', '5000'],k = 3) == \"50\"\n assert candidate(nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15'],k = 10) == \"6\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000', '1000000'],k = 5) == \"100\"\n assert candidate(nums = ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19'],k = 7) == \"7\"\n assert candidate(nums = ['123', '456', '789', '101112', '131415', '161718', '192021', '222324', '252627', '282930'],k = 5) == \"161718\"\n assert candidate(nums = ['1000000', '999999', '100000', '99999', '10000', '9999', '1000', '999', '100', '99', '10', '9'],k = 8) == \"999\"\n assert candidate(nums = ['999', '1000', '1001', '1002', '1003'],k = 2) == \"1002\"\n assert candidate(nums = ['987654321', '987654320', '987654319', '987654318', '987654317'],k = 4) == \"987654318\"\n assert candidate(nums = ['9876543210', '9876543211', '9876543212', '9876543213', '9876543214'],k = 5) == \"9876543210\"\n assert candidate(nums = ['123', '456', '789', '123', '456', '789', '123', '456', '789'],k = 5) == \"456\"\n assert candidate(nums = ['10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000'],k = 3) == \"10000000\"\n assert candidate(nums = ['1000000000', '1000000001', '1000000002', '1000000003', '1000000004'],k = 2) == \"1000000003\"\n assert candidate(nums = ['100000000000000000000000000000000000000000000000000000000000000', '99999999999999999999999999999999999999999999999999999999999999'],k = 1) == \"100000000000000000000000000000000000000000000000000000000000000\"\n assert candidate(nums = ['0', '00', '000', '0000', '00000'],k = 3) == \"000\"\n assert candidate(nums = ['5000', '4000', '3000', '2000', '1000', '500', '400', '300', '200', '100'],k = 5) == \"1000\"\n assert candidate(nums = ['987654321', '87654321', '7654321', '654321', '54321', '4321', '321', '21', '1'],k = 3) == \"7654321\"\n assert candidate(nums = ['1', '1', '2', '2', '3', '3', '4', '4', '5', '5'],k = 8) == \"2\"\n assert candidate(nums = ['111111111', '222222222', '333333333', '444444444', '555555555', '666666666', '777777777', '888888888', '999999999'],k = 9) == \"111111111\"\n assert candidate(nums = ['1', '11', '111', '1111', '11111', '111111'],k = 6) == \"1\"\n assert candidate(nums = ['12345', '12345', '12345', '12345', '12345', '12345', '12345', '12345', '12345', '12345'],k = 8) == \"12345\"\n assert candidate(nums = ['99', '98', '97', '96', '95', '94', '93', '92', '91', '90'],k = 5) == \"95\"\n assert candidate(nums = ['10', '2', '3', '4', '5', '6', '7', '8', '9'],k = 1) == \"10\"\n assert candidate(nums = ['9876543210', '987654321', '98765432', '9876543', '987654', '98765', '9876', '987', '98', '9'],k = 5) == \"987654\"\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', '3', '5', '7', '9', '11', '13', '15', '17', '19'],k = 1) == \"19\"\n assert candidate(nums = ['11111111111111111111', '22222222222222222222', '33333333333333333333', '44444444444444444444', '55555555555555555555'],k = 2) == \"44444444444444444444\"\n assert candidate(nums = ['100', '1000', '10000', '100000', '1000000'],k = 4) == \"1000\"\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) == \"2\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000'],k = 7) == \"1000\"\n assert candidate(nums = ['1000', '999', '100', '99', '10', '9', '1'],k = 7) == \"1\"\n assert candidate(nums = ['9', '8', '7', '6', '5', '4', '3', '2', '1'],k = 9) == \"1\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000'],k = 3) == \"10000000\"\n assert candidate(nums = ['999999999999999999', '888888888888888888', '777777777777777777', '666666666666666666', '555555555555555555'],k = 3) == \"777777777777777777\"\n assert candidate(nums = ['123', '123', '123', '123', '123', '123', '123', '123', '123', '123'],k = 10) == \"123\"\n assert candidate(nums = ['123456789', '987654321', '123456789', '987654321', '123456789', '987654321', '123456789', '987654321', '123456789', '987654321'],k = 5) == \"987654321\"\n assert candidate(nums = ['1000', '999', '888', '777', '666', '555', '444', '333', '222', '111'],k = 10) == \"111\"\n assert candidate(nums = ['123456789', '987654321', '111111111', '999999999', '222222222'],k = 3) == \"222222222\"\n assert candidate(nums = ['111', '222', '333', '444', '555', '666', '777', '888', '999', '1111'],k = 6) == \"555\"\n assert candidate(nums = ['10000', '9999', '9998', '9997', '9996', '9995', '9994', '9993', '9992', '9991'],k = 6) == \"9995\"\n assert candidate(nums = ['1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000'],k = 1) == \"1000\"\n assert candidate(nums = ['9', '99', '999', '9999', '99999', '999999', '9999999', '99999999', '999999999'],k = 8) == \"99\"\n assert candidate(nums = ['1000000000', '999999999', '100000000', '99999999', '10000000', '9999999', '1000000', '999999', '100000', '99999'],k = 10) == \"99999\"\n assert candidate(nums = ['123456789', '987654321', '135792468', '246813579'],k = 4) == \"123456789\"\n assert candidate(nums = ['1000000000', '1000000001', '1000000002', '1000000003', '1000000004', '1000000005'],k = 2) == \"1000000004\"\n assert candidate(nums = ['100', '200', '300', '400', '500', '600', '700', '800', '900', '1000'],k = 10) == \"100\"\n assert candidate(nums = ['123456789012345678901234567890', '987654321098765432109876543210', '111111111111111111111111111111', '999999999999999999999999999999', '222222222222222222222222222222'],k = 3) == \"222222222222222222222222222222\"\n assert candidate(nums = ['11111', '22222', '33333', '44444', '55555', '66666', '77777', '88888', '99999', '100000'],k = 9) == \"22222\"\n assert candidate(nums = ['500', '500', '500', '500', '500', '500', '500', '500', '500', '500'],k = 5) == \"500\"\n assert candidate(nums = ['9', '19', '29', '39', '49', '59', '69', '79', '89', '99'],k = 1) == \"99\"\n assert candidate(nums = ['9', '8', '7', '6', '5', '4', '3', '2', '1'],k = 1) == \"9\"\n assert candidate(nums = ['9', '99', '999', '9999', '99999'],k = 3) == \"999\"\n assert candidate(nums = ['1111111111', '2222222222', '3333333333', '4444444444', '5555555555'],k = 1) == \"5555555555\"\n assert candidate(nums = ['9999999999', '8888888888', '7777777777', '6666666666', '5555555555', '4444444444', '3333333333', '2222222222', '1111111111', '0'],k = 10) == \"0\"\n assert candidate(nums = ['111', '222', '333', '444', '555', '666', '777', '888', '999', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'],k = 15) == \"444\"\n assert candidate(nums = ['9999999999', '8888888888', '7777777777', '6666666666', '5555555555'],k = 3) == \"7777777777\"\n assert candidate(nums = ['1000', '1000', '1000', '1000', '1000', '1000'],k = 3) == \"1000\"\n assert candidate(nums = ['1111111111', '2222222222', '3333333333', '4444444444', '5555555555', '6666666666', '7777777777', '8888888888', '9999999999', '10000000000'],k = 2) == \"9999999999\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000'],k = 5) == \"10\"\n assert candidate(nums = ['9', '29', '39', '49', '59', '69', '79', '89', '99', '109'],k = 8) == \"39\"\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 = ['123456789', '987654321', '111111111', '222222222', '333333333'],k = 4) == \"123456789\"\n assert candidate(nums = ['123', '456', '789', '101112', '131415'],k = 1) == \"131415\"\n assert candidate(nums = ['123', '456', '789', '101112', '131415', '161718', '192021', '222324', '252627', '282930'],k = 4) == \"192021\"\n assert candidate(nums = ['5', '10', '15', '20', '25', '30', '35', '40'],k = 7) == \"10\"\n assert candidate(nums = ['1000000000', '999999999', '1000000000', '999999999', '1000000000', '999999999', '1000000000', '999999999', '1000000000', '999999999'],k = 8) == \"999999999\"\n assert candidate(nums = ['999999999999999999', '1000000000000000000', '999999999999999998'],k = 1) == \"1000000000000000000\"\n assert candidate(nums = ['100', '1000', '10', '1'],k = 2) == \"100\"\n assert candidate(nums = ['100', '200', '300', '400', '500', '600', '700', '800', '900'],k = 7) == \"300\"\n assert candidate(nums = ['1234567890', '1234567891', '1234567892', '1234567893', '1234567894', '1234567895', '1234567896', '1234567897', '1234567898', '1234567899'],k = 9) == \"1234567891\"\n assert candidate(nums = ['987654321', '98765432', '9876543', '987654', '98765', '9876', '987', '98', '9'],k = 8) == \"98\"\n assert candidate(nums = ['99999', '88888', '77777', '66666', '55555', '44444', '33333', '22222', '11111'],k = 9) == \"11111\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000'],k = 3) == \"100\"\n assert candidate(nums = ['10000', '10001', '10002', '10003', '10004', '10005', '10006', '10007', '10008', '10009'],k = 8) == \"10002\"\n assert candidate(nums = ['123456789', '987654321', '111111111', '222222222', '333333333'],k = 2) == \"333333333\"\n assert candidate(nums = ['999999999999999999', '999999999999999998', '1000000000000000000'],k = 2) == \"999999999999999999\"\n assert candidate(nums = ['111', '222', '333', '444', '555', '666', '777', '888', '999', '111', '222', '333', '444', '555', '666', '777', '888', '999', '111', '222'],k = 15) == \"222\"\n assert candidate(nums = ['999999999999999999', '1000000000000000000', '999999999999999998'],k = 2) == \"999999999999999999\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000'],k = 10) == \"1\"\n assert candidate(nums = ['100', '200', '300', '400', '500', '600', '700', '800', '900', '1000'],k = 7) == \"400\"\n assert candidate(nums = ['999', '998', '997', '996', '995', '994', '993', '992', '991', '990'],k = 10) == \"990\"\n assert candidate(nums = ['1', '11', '111', '1111', '11111', '111111', '1111111', '11111111', '111111111', '1111111111'],k = 3) == \"11111111\"\n assert candidate(nums = ['9876543210', '102030405060708090', '123456789', '987654321', '1000000000', '999999999', '1111111111', '2222222222', '3333333333', '4444444444'],k = 3) == \"4444444444\"\n assert candidate(nums = ['9', '99', '999', '9999', '99999', '999999', '9999999', '99999999', '999999999', '9999999999'],k = 5) == \"999999\"\n assert candidate(nums = ['123', '456', '789', '101112', '131415', '161718', '192021', '222324', '252627', '282930'],k = 6) == \"131415\"\n assert candidate(nums = ['123', '456', '789', '101112', '131415', '161718'],k = 3) == \"101112\"\n assert candidate(nums = ['1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000', '1000'],k = 5) == \"1000\"\n assert candidate(nums = ['1000000', '999999', '888888', '777777', '666666'],k = 2) == \"999999\"\n assert candidate(nums = ['999', '998', '997', '996', '995', '994', '993', '992', '991', '990'],k = 5) == \"995\"\n assert candidate(nums = ['1', '10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000'],k = 5) == \"100000\"\n assert candidate(nums = ['12345678901234567890', '12345678901234567891', '12345678901234567892'],k = 2) == \"12345678901234567891\"\n assert candidate(nums = ['999', '888', '777', '666', '555', '444', '333', '222', '111', '0'],k = 1) == \"999\"\n", "comparison": "exact"}, "public_tests": ["[\"3\",\"6\",\"7\",\"10\"]\n4", "[\"2\",\"21\",\"12\",\"1\"]\n3", "[\"0\",\"0\"]\n2"], "hints": ["If two numbers have different lengths, which one will be larger?", "The longer number is the larger number.", "If two numbers have the same length, which one will be larger?", "Compare the two numbers starting from the most significant digit. Once you have found the first digit that differs, the one with the larger digit is the larger number."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().kthLargestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:16+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "divide-and-conquer", "sorting", "heap-priority-queue", "quickselect"]}, "language": "php", "interface": {"raw_signature": "function kthLargestNumber($nums, $k) {", "container": "Solution", "callable": "kthLargestNumber", "parameters": [{"name": "nums", "type": "String[]"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1986, "task_id": "minimum-number-of-work-sessions-to-finish-the-tasks", "difficulty": "Medium", "problem_description": "There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the i^th task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break.\n\nYou should finish the given tasks in a way that satisfies the following conditions:\n\n- If you start a task in a work session, you must complete it in the same work session.\n- You can start a new task immediately after finishing the previous one.\n- You may complete the tasks in any order.\n\nGiven tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.\n\nThe tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].\n\nExample 1:\n\nInput: tasks = [1,2,3], sessionTime = 3\nOutput: 2\nExplanation: You can finish the tasks in two work sessions.\n- First work session: finish the first and the second tasks in 1 + 2 = 3 hours.\n- Second work session: finish the third task in 3 hours.\n\nExample 2:\n\nInput: tasks = [3,1,3,1,1], sessionTime = 8\nOutput: 2\nExplanation: You can finish the tasks in two work sessions.\n- First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.\n- Second work session: finish the last task in 1 hour.\n\nExample 3:\n\nInput: tasks = [1,2,3,4,5], sessionTime = 15\nOutput: 1\nExplanation: You can finish all the tasks in one work session.\n\nConstraints:\n\n- n == tasks.length\n- 1 <= n <= 14\n- 1 <= tasks[i] <= 10\n- max(tasks[i]) <= sessionTime <= 15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [1, 3, 2, 4],sessionTime = 5) == 2\n assert candidate(tasks = [5, 7, 4, 2, 6],sessionTime = 10) == 3\n assert candidate(tasks = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],sessionTime = 12) == 5\n assert candidate(tasks = [1, 2, 3],sessionTime = 3) == 2\n assert candidate(tasks = [5, 5, 5, 5],sessionTime = 5) == 4\n assert candidate(tasks = [9, 9, 9, 9],sessionTime = 9) == 4\n assert candidate(tasks = [2, 3, 3, 4, 6],sessionTime = 6) == 3\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 2) == 7\n assert candidate(tasks = [7, 7, 7, 7],sessionTime = 14) == 2\n assert candidate(tasks = [10, 10, 10, 10],sessionTime = 10) == 4\n assert candidate(tasks = [10, 10, 10],sessionTime = 10) == 3\n assert candidate(tasks = [2, 3, 4, 5, 1],sessionTime = 6) == 3\n assert candidate(tasks = [1, 2, 3, 4, 5],sessionTime = 15) == 1\n assert candidate(tasks = [7, 2, 7, 2, 7],sessionTime = 12) == 3\n assert candidate(tasks = [8, 8, 8, 8, 8, 8, 8, 8],sessionTime = 15) == 8\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],sessionTime = 10) == 14\n assert candidate(tasks = [1, 2, 3, 4],sessionTime = 10) == 1\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 15) == 5\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 14) == 1\n assert candidate(tasks = [3, 1, 3, 1, 1],sessionTime = 8) == 2\n assert candidate(tasks = [7, 2, 4, 3, 5],sessionTime = 12) == 2\n assert candidate(tasks = [1, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7],sessionTime = 10) == 6\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1],sessionTime = 10) == 6\n assert candidate(tasks = [7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7],sessionTime = 13) == 5\n assert candidate(tasks = [2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5],sessionTime = 12) == 5\n assert candidate(tasks = [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6],sessionTime = 12) == 5\n assert candidate(tasks = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1],sessionTime = 11) == 7\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],sessionTime = 15) == 14\n assert candidate(tasks = [10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 15) == 4\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],sessionTime = 14) == 7\n assert candidate(tasks = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2],sessionTime = 8) == 5\n assert candidate(tasks = [3, 6, 7, 9, 10, 1, 2, 4, 5, 8, 2, 3, 4, 6],sessionTime = 10) == 7\n assert candidate(tasks = [7, 8, 7, 8, 7, 8, 7, 8],sessionTime = 15) == 4\n assert candidate(tasks = [7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7],sessionTime = 12) == 5\n assert candidate(tasks = [2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9],sessionTime = 14) == 6\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6],sessionTime = 10) == 6\n assert candidate(tasks = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5],sessionTime = 10) == 4\n assert candidate(tasks = [8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 15) == 4\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 15) == 5\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7],sessionTime = 15) == 6\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1],sessionTime = 7) == 5\n assert candidate(tasks = [10, 10, 10, 10, 1, 2, 3, 4],sessionTime = 15) == 4\n assert candidate(tasks = [9, 1, 4, 8, 3, 2, 5, 6, 7, 10, 1, 2, 3, 4],sessionTime = 10) == 7\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 14) == 4\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 5) == 14\n assert candidate(tasks = [10, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 10, 1, 2],sessionTime = 10) == 8\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 10) == 4\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],sessionTime = 30) == 5\n assert candidate(tasks = [7, 3, 4, 5, 6, 2, 8, 9, 10, 1, 2, 3, 4, 5],sessionTime = 10) == 7\n assert candidate(tasks = [10, 10, 10, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4],sessionTime = 14) == 4\n assert candidate(tasks = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5],sessionTime = 10) == 5\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],sessionTime = 14) == 4\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],sessionTime = 9) == 5\n assert candidate(tasks = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],sessionTime = 12) == 6\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],sessionTime = 9) == 5\n assert candidate(tasks = [2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7],sessionTime = 12) == 6\n assert candidate(tasks = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],sessionTime = 10) == 5\n assert candidate(tasks = [1, 2, 3, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2],sessionTime = 8) == 5\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],sessionTime = 10) == 14\n assert candidate(tasks = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5],sessionTime = 9) == 5\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 10) == 7\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4],sessionTime = 20) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4],sessionTime = 10) == 4\n assert candidate(tasks = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],sessionTime = 16) == 7\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1],sessionTime = 10) == 14\n assert candidate(tasks = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],sessionTime = 13) == 5\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 10) == 7\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],sessionTime = 6) == 4\n assert candidate(tasks = [10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 10) == 5\n assert candidate(tasks = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],sessionTime = 4) == 7\n assert candidate(tasks = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],sessionTime = 6) == 6\n assert candidate(tasks = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],sessionTime = 10) == 6\n assert candidate(tasks = [9, 6, 3, 2, 1, 9, 6, 3, 2, 1, 9, 6, 3, 2],sessionTime = 10) == 7\n assert candidate(tasks = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],sessionTime = 13) == 3\n assert candidate(tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2],sessionTime = 10) == 5\n assert candidate(tasks = [10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],sessionTime = 15) == 6\n assert candidate(tasks = [10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 10) == 5\n assert candidate(tasks = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4],sessionTime = 8) == 4\n assert candidate(tasks = [1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7],sessionTime = 12) == 6\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],sessionTime = 4) == 6\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1],sessionTime = 9) == 4\n assert candidate(tasks = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8],sessionTime = 15) == 5\n assert candidate(tasks = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],sessionTime = 12) == 7\n assert candidate(tasks = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5],sessionTime = 6) == 7\n assert candidate(tasks = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],sessionTime = 8) == 4\n assert candidate(tasks = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1],sessionTime = 8) == 14\n assert candidate(tasks = [3, 2, 3, 2, 3, 2, 3, 2],sessionTime = 5) == 4\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],sessionTime = 10) == 6\n assert candidate(tasks = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8],sessionTime = 14) == 5\n assert candidate(tasks = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2],sessionTime = 5) == 6\n assert candidate(tasks = [2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5],sessionTime = 10) == 5\n assert candidate(tasks = [7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2],sessionTime = 15) == 5\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],sessionTime = 8) == 7\n assert candidate(tasks = [1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7],sessionTime = 14) == 5\n assert candidate(tasks = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8],sessionTime = 12) == 6\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1],sessionTime = 20) == 4\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],sessionTime = 20) == 7\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n3", "[3,1,3,1,1]\n8", "[1,2,3,4,5]\n15"], "hints": ["Try all possible ways of assignment.", "If we can store the assignments in form of a state then we can reuse that state and solve the problem in a faster way."], "metadata": {"canonical_parameter_names": ["tasks", "sessionTime"], "leetcode_dataset_entry_point": "Solution().minSessions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:19+00:00", "tests_total": 123, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function minSessions($tasks, $sessionTime) {", "container": "Solution", "callable": "minSessions", "parameters": [{"name": "tasks", "type": "Integer[]"}, {"name": "sessionTime", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1987, "task_id": "number-of-unique-good-subsequences", "difficulty": "Hard", "problem_description": "You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of \"0\").\n\nFind the number of unique good subsequences of binary.\n\n- For example, if binary = \"001\", then all the good subsequences are [\"0\", \"0\", \"1\"], so the unique good subsequences are \"0\" and \"1\". Note that subsequences \"00\", \"01\", and \"001\" are not good because they have leading zeros.\n\nReturn the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 10^9 + 7.\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: binary = \"001\"\nOutput: 2\nExplanation: The good subsequences of binary are [\"0\", \"0\", \"1\"].\nThe unique good subsequences are \"0\" and \"1\".\n\nExample 2:\n\nInput: binary = \"11\"\nOutput: 2\nExplanation: The good subsequences of binary are [\"1\", \"1\", \"11\"].\nThe unique good subsequences are \"1\" and \"11\".\n\nExample 3:\n\nInput: binary = \"101\"\nOutput: 5\nExplanation: The good subsequences of binary are [\"1\", \"0\", \"1\", \"10\", \"11\", \"101\"].\nThe unique good subsequences are \"0\", \"1\", \"10\", \"11\", and \"101\".\n\nConstraints:\n\n- 1 <= binary.length <= 10^5\n- binary consists of only '0's and '1's.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(binary = \"101\") == 5\n assert candidate(binary = \"1111\") == 4\n assert candidate(binary = \"1\") == 1\n assert candidate(binary = \"010101\") == 13\n assert candidate(binary = \"111000111\") == 43\n assert candidate(binary = \"10000100001\") == 64\n assert candidate(binary = \"1001001\") == 26\n assert candidate(binary = \"1010101010\") == 144\n assert candidate(binary = \"00000\") == 1\n assert candidate(binary = \"000000\") == 1\n assert candidate(binary = \"0000000000\") == 1\n assert candidate(binary = \"000\") == 1\n assert candidate(binary = \"001\") == 2\n assert candidate(binary = \"11\") == 2\n assert candidate(binary = \"0101010101\") == 89\n assert candidate(binary = \"1100110011\") == 99\n assert candidate(binary = \"0101010\") == 21\n assert candidate(binary = \"0\") == 1\n assert candidate(binary = \"111111\") == 6\n assert candidate(binary = \"100101010\") == 76\n assert candidate(binary = \"1000000000000000000000000000000000000000000000000000000000000001\") == 127\n assert candidate(binary = \"1101\") == 8\n assert candidate(binary = \"1001010\") == 29\n assert candidate(binary = \"01010101\") == 34\n assert candidate(binary = \"11010\") == 13\n assert candidate(binary = \"11111\") == 5\n assert candidate(binary = \"1111111111\") == 10\n assert candidate(binary = \"00000000000000000000000000000000000000000001\") == 2\n assert candidate(binary = \"11011011011011011011\") == 7953\n assert candidate(binary = \"10000000000000000001\") == 39\n assert candidate(binary = \"010101010101010101010101\") == 75025\n assert candidate(binary = \"11111111111111111111111111111111111111111110\") == 87\n assert candidate(binary = \"100000000000000000000000\") == 25\n assert candidate(binary = \"101010101010101010101010101010101010101010101010101\") == 316290802\n assert candidate(binary = \"10101010101010101010\") == 17711\n assert candidate(binary = \"010101010101010101010101010101010101010101010101010\") == 951279875\n assert candidate(binary = \"0000000011111111\") == 9\n assert candidate(binary = \"11110000111100001111000011110000\") == 121393\n assert candidate(binary = \"110110110110\") == 265\n assert candidate(binary = \"11111000001111100000\") == 836\n assert candidate(binary = \"1010101010101\") == 610\n assert candidate(binary = \"111000111000\") == 142\n assert candidate(binary = \"1001001001001001001001001001001001\") == 3650401\n assert candidate(binary = \"0101010101010101010101010101\") == 514229\n assert candidate(binary = \"010101010101\") == 233\n assert candidate(binary = \"1010101010101010101010101010101010101010\") == 267914296\n assert candidate(binary = \"0101010101010101\") == 1597\n assert candidate(binary = \"1111111111111111111111111111111111111111\") == 40\n assert candidate(binary = \"11001100110011001100\") == 8119\n assert candidate(binary = \"000000000001\") == 2\n assert candidate(binary = \"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110\") == 199\n assert candidate(binary = \"01010101010101010101010101010101010101010101010\") == 807526948\n assert candidate(binary = \"10101010101010101010101\") == 75025\n assert candidate(binary = \"1001001001\") == 97\n assert candidate(binary = \"11001010010111\") == 545\n assert candidate(binary = \"000111111111111111111111111111111111111111111111111\") == 49\n assert candidate(binary = \"111111111111111111111111\") == 24\n assert candidate(binary = \"11111111111111111111111111111111111111111111\") == 44\n assert candidate(binary = \"1001001001001001001001001001001001001001001001001001001001\") == 379190178\n assert candidate(binary = \"000000000000000000000000000000000000000000000000001\") == 2\n assert candidate(binary = \"0101010101010101010101010101010101010101\") == 165580141\n assert candidate(binary = \"110110110110110110\") == 3691\n assert candidate(binary = \"1111000011110000\") == 377\n assert candidate(binary = \"000000000000\") == 1\n assert candidate(binary = \"1111100000011111\") == 191\n assert candidate(binary = \"1111111111111111111111111111\") == 28\n assert candidate(binary = \"111000111000111000111000111000111000111000111000111000111\") == 619446900\n assert candidate(binary = \"110101010101\") == 377\n assert candidate(binary = \"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\") == 2\n assert candidate(binary = \"1001001001001001\") == 1351\n assert candidate(binary = \"1100110011001100\") == 1393\n assert candidate(binary = \"00000000000000000000000000000000\") == 1\n assert candidate(binary = \"01010101010101010101010101010101010101010101\") == 134903163\n assert candidate(binary = \"1010101010101010101010101010101010101010101010101011\") == 681301736\n assert candidate(binary = \"10111001001010011001\") == 8492\n assert candidate(binary = \"11111111111111111110\") == 39\n assert candidate(binary = \"111000111000111000111000111000111000111000111000\") == 239244622\n assert candidate(binary = \"101010101010\") == 377\n assert candidate(binary = \"000000000011111111110000000000\") == 111\n assert candidate(binary = \"00000000000000000000\") == 1\n assert candidate(binary = \"1111100000111110000011111\") == 4341\n assert candidate(binary = \"100100100100100100100100100100100100100100100100100\") == 694626305\n assert candidate(binary = \"000111000111000\") == 142\n assert candidate(binary = \"001100110011\") == 99\n assert candidate(binary = \"11000110001100011000\") == 4401\n assert candidate(binary = \"1000000000000000001\") == 37\n assert candidate(binary = \"111100001111000011110000111100001111000011110000111\") == 133957148\n assert candidate(binary = \"10010101010101010101\") == 15127\n assert candidate(binary = \"01010101010101010101\") == 10946\n assert candidate(binary = \"0001111111000\") == 29\n", "comparison": "exact"}, "public_tests": ["\"001\"", "\"11\"", "\"101\""], "hints": ["The number of unique good subsequences is equal to the number of unique decimal values there are for all possible subsequences.", "Find the answer at each index based on the previous indexes' answers."], "metadata": {"canonical_parameter_names": ["binary"], "leetcode_dataset_entry_point": "Solution().numberOfUniqueGoodSubsequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:21+00:00", "tests_total": 90, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function numberOfUniqueGoodSubsequences($binary) {", "container": "Solution", "callable": "numberOfUniqueGoodSubsequences", "parameters": [{"name": "binary", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1991, "task_id": "find-the-middle-index-in-array", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).\n\nA middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].\n\nIf middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.\n\nReturn the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.\n\nExample 1:\n\nInput: nums = [2,3,-1,8,4]\nOutput: 3\nExplanation: The sum of the numbers before index 3 is: 2 + 3 + -1 = 4\nThe sum of the numbers after index 3 is: 4 = 4\n\nExample 2:\n\nInput: nums = [1,-1,4]\nOutput: 2\nExplanation: The sum of the numbers before index 2 is: 1 + -1 = 0\nThe sum of the numbers after index 2 is: 0\n\nExample 3:\n\nInput: nums = [2,5]\nOutput: -1\nExplanation: There is no valid middleIndex.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- -1000 <= nums[i] <= 1000\n\nNote: This question is the same as 724: https://leetcode.com/problems/find-pivot-index/\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, -1, 4]) == 2\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 100]) == -1\n assert candidate(nums = [0, 1]) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5]) == -1\n assert candidate(nums = [2, 5]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [1, 0]) == 0\n assert candidate(nums = [2, 3, -1, 8, 4]) == 3\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [-1, -1, -1, -1]) == -1\n assert candidate(nums = [1, 7, 3, 6, 5, 6]) == 3\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [1000, -1000, 1000, -1000]) == -1\n assert candidate(nums = [1, 1]) == -1\n assert candidate(nums = [1, 2, 3]) == -1\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000]) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6]) == -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 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1000, -500, 250, 250, -1000, 500, 500, 0, 0, 0]) == 0\n assert candidate(nums = [100, 0, -100, 0, 100, 0, -100]) == 3\n assert candidate(nums = [100, -50, 25, 25, -100, 50, 50]) == 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]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1, 0]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == -1\n assert candidate(nums = [7, 1, 5, 2, -4, 3, 0, 1, -2, 3]) == -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, -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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1]) == 0\n assert candidate(nums = [5, -10, 10, 5, 0]) == -1\n assert candidate(nums = [-5, 5, -5, 5, -5, 5]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 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, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == -1\n assert candidate(nums = [3, -2, 1, 6, -4, 2, 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]) == -1\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40]) == 6\n assert candidate(nums = [100, 200, -300, 400, -500, 600, -700, 800]) == -1\n assert candidate(nums = [7, 1, 5, 2, -4, 3, 0]) == -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, 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 = [10, -10, 10, -10, 10, -10, 10, -10, 10, -10]) == -1\n assert candidate(nums = [10, -10, 20, -20, 30, -30]) == -1\n assert candidate(nums = [1000, -1000, 0, 1000, -1000]) == 2\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == -1\n assert candidate(nums = [-1000, 500, -250, 125, -62, 31, -15, 7, -3, 1]) == -1\n assert candidate(nums = [5, -5, 5, -5, 5, -5, 5]) == 0\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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums = [-1, -2, -3, -4, -5, 15]) == -1\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, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]) == 9\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums = [1, -2, 3, 4, -3, 2]) == -1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, -210]) == -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\n assert candidate(nums = [10, -10, 0, 5, -5, 5, -5]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000, 1000, -1000]) == -1\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40]) == -1\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1]) == 0\n assert candidate(nums = [999, 1, 999, 1, 999, 1, 999, 1, 999, 1]) == -1\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250, 125, -125]) == -1\n assert candidate(nums = [0, 1, 2, 3, 4, 3, 2, 1, 0]) == 4\n assert candidate(nums = [1, -1, 0, 1, -1]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 7\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]) == -1\n assert candidate(nums = [10, 20, 30, 10, 10, 30]) == -1\n assert candidate(nums = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1, 0]) == -1\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [1000, -1000, 1000, -1000, 1000, -1000]) == -1\n assert candidate(nums = [100, -100, 50, -50, 25, -25, 12, -12, 6, -6, 3, -3, 1, -1]) == -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]) == -1\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == -1\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6]) == -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, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 9\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250]) == -1\n assert candidate(nums = [1000, -1000, 500, -500, 0, 0]) == 4\n assert candidate(nums = [7, 1, 5, 2, -4, 3, 0, 0, 0, 0]) == -1\n assert candidate(nums = [1000, -500, 250, -125, 62, -31, 15, -7, 3, -1, 1]) == -1\n assert candidate(nums = [-10, 10, -20, 20, -30, 30]) == -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]) == 20\n", "comparison": "exact"}, "public_tests": ["[2,3,-1,8,4]", "[1,-1,4]", "[2,5]"], "hints": ["Could we go from left to right and check to see if an index is a middle index?", "Do we need to sum every number to the left and right of an index each time?", "Use a prefix sum array where prefix[i] = nums[0] + nums[1] + ... + nums[i]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findMiddleIndex", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:25+00:00", "tests_total": 94, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function findMiddleIndex($nums) {", "container": "Solution", "callable": "findMiddleIndex", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1992, "task_id": "find-all-groups-of-farmland", "difficulty": "Medium", "problem_description": "You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.\n\nTo keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.\n\nland can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r_1, c_1) and a bottom right corner at (r_2, c_2) is represented by the 4-length array [r_1, c_1, r_2, c_2].\n\nReturn a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.\n\nExample 1:\n\nInput: land = [[1,0,0],[0,1,1],[0,1,1]]\nOutput: [[0,0,0,0],[1,1,2,2]]\nExplanation:\nThe first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].\nThe second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].\n\nExample 2:\n\nInput: land = [[1,1],[1,1]]\nOutput: [[0,0,1,1]]\nExplanation:\nThe first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].\n\nExample 3:\n\nInput: land = [[0]]\nOutput: []\nExplanation:\nThere are no groups of farmland.\n\nConstraints:\n\n- m == land.length\n- n == land[i].length\n- 1 <= m, n <= 300\n- land consists of only 0's and 1's.\n- Groups of farmland are rectangular in shape.\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(land=[[0]]), [])\n assert answers_match(candidate(land=[[1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]]), [[0, 0, 0, 1], [1, 2, 1, 3], [2, 0, 2, 1], [3, 2, 3, 3]])\n assert answers_match(candidate(land=[[1, 0, 1], [0, 0, 0], [1, 1, 1]]), [[0, 0, 0, 0], [0, 2, 0, 2], [2, 0, 2, 2]])\n assert answers_match(candidate(land=[[1, 0, 1], [0, 0, 0], [1, 1, 0]]), [[0, 0, 0, 0], [0, 2, 0, 2], [2, 0, 2, 1]])\n assert answers_match(candidate(land=[[0, 0, 0], [0, 0, 0], [0, 0, 0]]), [])\n assert answers_match(candidate(land=[[1, 1, 1], [1, 0, 1], [1, 1, 1]]), [[0, 0, 2, 2]])\n assert answers_match(candidate(land=[[1, 0, 1], [0, 1, 0], [1, 0, 1]]), [[0, 0, 0, 0], [0, 2, 0, 2], [1, 1, 1, 1], [2, 0, 2, 0], [2, 2, 2, 2]])\n assert answers_match(candidate(land=[[1, 1], [1, 1]]), [[0, 0, 1, 1]])\n assert answers_match(candidate(land=[[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]), [[0, 0, 1, 1], [2, 2, 3, 3]])\n assert answers_match(candidate(land=[[1, 0, 0, 0], [0, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 0]]), [[0, 0, 0, 0], [1, 1, 2, 3]])\n assert answers_match(candidate(land=[[1, 0, 0], [0, 1, 1], [0, 1, 1]]), [[0, 0, 0, 0], [1, 1, 2, 2]])\n assert answers_match(candidate(land=[[0, 1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1]]), [[0, 1, 1, 2], [0, 5, 1, 6], [3, 0, 4, 2], [3, 4, 4, 6], [6, 0, 7, 1], [6, 6, 7, 7]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1]]), [[0, 0, 1, 1], [2, 2, 3, 4], [4, 5, 5, 5]])\n assert answers_match(candidate(land=[[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, 0, 0, 0], [0, 2, 0, 2], [0, 4, 0, 4], [0, 6, 0, 6], [1, 1, 1, 1], [1, 3, 1, 3], [1, 5, 1, 5], [1, 7, 1, 7], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [2, 6, 2, 6], [3, 1, 3, 1], [3, 3, 3, 3], [3, 5, 3, 5], [3, 7, 3, 7], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4], [4, 6, 4, 6]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1]]), [[0, 0, 1, 3]])\n assert answers_match(candidate(land=[[1, 1, 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, 1, 1]]), [[0, 0, 1, 5], [3, 0, 4, 5]])\n assert answers_match(candidate(land=[[1, 0, 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, 2, 0, 2], [0, 4, 0, 4], [1, 1, 1, 1], [1, 3, 1, 3], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [3, 1, 3, 1], [3, 3, 3, 3], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4]])\n assert answers_match(candidate(land=[[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]]), [[1, 1, 3, 3]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1]]), [[0, 0, 0, 2], [0, 6, 0, 8], [2, 0, 2, 2], [2, 4, 2, 6], [3, 7, 4, 8], [4, 0, 4, 4]])\n assert answers_match(candidate(land=[[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]]), [[0, 0, 5, 5], [2, 2, 3, 3]])\n assert answers_match(candidate(land=[[1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1], [1, 1, 0, 1, 1, 0, 1, 1, 0, 1]]), [[0, 0, 1, 1], [0, 3, 1, 4], [0, 6, 1, 7], [0, 9, 1, 9], [3, 0, 4, 1], [3, 3, 4, 4], [3, 6, 4, 7], [3, 9, 4, 9], [6, 0, 7, 1], [6, 3, 7, 4], [6, 6, 7, 7], [6, 9, 7, 9]])\n assert answers_match(candidate(land=[[1, 0, 1, 0, 1, 0, 1, 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], [1, 0, 1, 0, 1, 0, 1, 0]]), [[0, 0, 0, 0], [0, 2, 0, 2], [0, 4, 0, 4], [0, 6, 0, 6], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [2, 6, 2, 6], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4], [4, 6, 4, 6]])\n assert answers_match(candidate(land=[[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 1, 1], [1, 0, 0, 0]]), [[0, 0, 3, 0], [2, 2, 2, 3]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 0, 1], [1, 1, 0, 0, 1, 1], [0, 1, 0, 0, 1, 0], [1, 1, 0, 0, 1, 1], [0, 1, 0, 0, 1, 0]]), [[0, 0, 1, 1], [0, 5, 1, 5], [1, 4, 4, 4], [3, 0, 3, 1]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0, 1, 1]]), [[0, 0, 0, 0], [0, 4, 3, 7], [0, 6, 1, 7], [1, 1, 1, 2], [2, 9, 3, 9], [3, 1, 3, 1], [5, 2, 5, 4], [5, 8, 5, 9]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1]]), [[0, 0, 2, 2], [0, 6, 2, 8], [4, 0, 6, 2], [4, 6, 6, 8]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1]]), [[0, 0, 0, 2], [1, 3, 2, 4], [2, 1, 2, 1], [3, 2, 3, 2], [3, 5, 3, 5]])\n assert answers_match(candidate(land=[[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], [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, 2, 7], [4, 0, 6, 7]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 1, 0], [0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1]]), [[0, 0, 0, 0], [0, 4, 0, 4], [1, 1, 2, 2], [1, 5, 4, 5], [3, 3, 4, 5]])\n assert answers_match(candidate(land=[[1, 0, 0, 1, 0], [1, 1, 0, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 0, 1], [0, 1, 1, 0, 1]]), [[0, 0, 1, 1], [0, 3, 1, 3], [3, 0, 3, 2], [3, 4, 4, 4]])\n assert answers_match(candidate(land=[[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]]), [[0, 0, 0, 0], [0, 2, 0, 2], [0, 4, 0, 4], [0, 6, 0, 6], [1, 1, 1, 1], [1, 3, 1, 3], [1, 5, 1, 5], [1, 7, 1, 7], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [2, 6, 2, 6], [3, 1, 3, 1], [3, 3, 3, 3], [3, 5, 3, 5], [3, 7, 3, 7], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4], [4, 6, 4, 6], [5, 1, 5, 1], [5, 3, 5, 3], [5, 5, 5, 5], [5, 7, 5, 7]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1]]), [[0, 0, 1, 3], [2, 4, 3, 5]])\n assert answers_match(candidate(land=[[0, 1, 1, 0, 0, 0], [1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [0, 0, 1, 1, 0, 0]]), [[0, 1, 1, 1], [1, 0, 2, 0], [1, 4, 2, 4], [2, 3, 2, 4], [3, 1, 3, 2], [3, 5, 3, 5]])\n assert answers_match(candidate(land=[[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]]), [[1, 1, 3, 3]])\n assert answers_match(candidate(land=[[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 1]]), [[1, 1, 2, 2], [4, 0, 4, 3], [6, 0, 7, 0], [6, 3, 7, 3]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]), [[0, 0, 1, 1], [1, 4, 2, 5], [3, 2, 3, 3]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1, 0, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0]]), [[0, 0, 1, 3], [0, 9, 3, 9], [1, 6, 3, 7], [2, 4, 3, 7], [4, 2, 4, 3]])\n assert answers_match(candidate(land=[[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 0, 1, 1], [0, 0, 1, 0, 0]]), [[0, 0, 0, 0], [0, 2, 1, 3], [0, 4, 0, 4], [1, 1, 2, 1], [2, 0, 2, 1], [3, 2, 3, 2]])\n assert answers_match(candidate(land=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]), [[1, 1, 3, 4], [1, 8, 4, 9], [3, 6, 4, 9], [3, 11, 4, 12]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1]]), [[0, 0, 1, 3], [2, 4, 4, 6], [4, 2, 4, 6]])\n assert answers_match(candidate(land=[[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, 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, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1]]), [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 7, 7]])\n assert answers_match(candidate(land=[[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, 1, 1, 1, 1, 0, 0], [0, 0, 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, 1, 1, 1, 1]]), [[1, 1, 3, 5], [5, 3, 7, 7]])\n assert answers_match(candidate(land=[[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1]]), [[0, 0, 1, 1], [0, 3, 1, 4], [3, 0, 4, 1], [3, 3, 4, 4]])\n assert answers_match(candidate(land=[[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 0, 0, 0]]), [[1, 1, 2, 2], [1, 4, 2, 5], [3, 6, 4, 7], [5, 3, 5, 4]])\n assert answers_match(candidate(land=[[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]]), [[1, 1, 4, 4]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 0], [1, 0, 0, 0, 1]]), [[0, 0, 1, 1], [0, 4, 1, 4], [2, 2, 3, 3], [4, 0, 4, 0], [4, 4, 4, 4]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 1, 0, 0, 1], [1, 1, 1, 0, 0, 1, 0]]), [[0, 0, 0, 3], [1, 4, 2, 5], [2, 0, 2, 2], [3, 3, 3, 3], [3, 6, 3, 6], [4, 0, 4, 2], [4, 5, 4, 5]])\n assert answers_match(candidate(land=[[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 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, 2, 0, 2], [0, 4, 0, 4], [0, 6, 0, 6], [1, 1, 1, 1], [1, 3, 1, 3], [1, 5, 1, 5], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [2, 6, 2, 6], [3, 1, 3, 1], [3, 3, 3, 3], [3, 5, 3, 5], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4], [4, 6, 4, 6]])\n assert answers_match(candidate(land=[[0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 0], [0, 0, 0, 1, 1]]), [[1, 1, 2, 2], [4, 0, 4, 3]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0, 1, 1]]), [[0, 0, 1, 2], [0, 6, 1, 7], [2, 4, 3, 5], [4, 0, 4, 1], [4, 6, 4, 7]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0]]), [[0, 0, 1, 2], [2, 3, 3, 5], [4, 0, 5, 0], [4, 2, 5, 2]])\n assert answers_match(candidate(land=[[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]]), [[0, 0, 1, 1], [0, 5, 1, 6], [2, 2, 3, 4], [4, 0, 5, 1], [4, 5, 5, 6]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 1], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0], [1, 0, 0, 1, 1], [0, 0, 0, 1, 1]]), [[0, 0, 0, 0], [0, 4, 0, 4], [1, 1, 1, 3], [3, 0, 3, 0], [3, 3, 4, 4]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1]]), [[0, 0, 4, 0]])\n assert answers_match(candidate(land=[[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1]]), [[0, 0, 0, 0], [0, 3, 0, 3], [1, 1, 2, 2], [1, 4, 2, 4], [3, 0, 3, 0], [3, 3, 3, 3], [4, 1, 4, 2], [4, 4, 4, 4]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 0, 0, 0]]), [[0, 0, 1, 3], [2, 4, 3, 7], [5, 0, 5, 3]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]]), [[0, 0, 1, 2], [1, 4, 2, 5], [3, 0, 4, 1]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 0], [1, 1, 0, 1, 1], [0, 0, 0, 1, 1], [1, 1, 0, 0, 0], [1, 1, 0, 0, 0]]), [[0, 0, 1, 1], [1, 3, 2, 4], [3, 0, 4, 1]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1], [1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0]]), [[0, 0, 1, 1], [1, 4, 2, 5], [3, 0, 3, 3]])\n assert answers_match(candidate(land=[[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, 0, 0, 0], [0, 2, 0, 2], [0, 4, 0, 4], [1, 1, 1, 1], [1, 3, 1, 3], [1, 5, 1, 5], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [3, 1, 3, 1], [3, 3, 3, 3], [3, 5, 3, 5], [4, 0, 4, 0], [4, 2, 4, 2], [4, 4, 4, 4]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0]]), [[0, 0, 0, 0], [0, 4, 0, 5], [1, 1, 2, 3], [3, 0, 3, 0], [3, 4, 3, 5], [4, 1, 4, 3]])\n assert answers_match(candidate(land=[[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0]]), [[0, 0, 2, 2], [0, 6, 0, 8], [1, 4, 1, 4], [2, 6, 2, 8], [3, 3, 5, 5], [4, 1, 4, 7]])\n assert answers_match(candidate(land=[[0, 1, 1, 0, 0, 1], [0, 0, 1, 0, 1, 0], [1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 1]]), [[0, 1, 0, 2], [0, 5, 0, 5], [1, 4, 2, 5], [2, 0, 2, 2], [4, 0, 4, 1], [4, 3, 4, 5]])\n assert answers_match(candidate(land=[[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]), [[1, 1, 2, 2]])\n assert answers_match(candidate(land=[[1, 1, 1, 1, 0, 0], [1, 0, 0, 1, 1, 0], [1, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 1]]), [[0, 0, 2, 0]])\n assert answers_match(candidate(land=[[0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1]]), [[0, 1, 4, 1], [0, 3, 4, 3], [0, 5, 4, 5], [1, 0, 1, 5], [3, 0, 3, 5]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1]]), [[0, 0, 0, 0], [0, 4, 0, 5], [2, 0, 2, 1], [2, 4, 2, 5], [4, 0, 4, 1], [4, 4, 4, 5]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 0, 1], [0, 1, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1]]), [[0, 0, 0, 0], [0, 5, 0, 5], [1, 1, 2, 2], [1, 4, 2, 4], [3, 3, 3, 3], [3, 5, 3, 5]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0]]), [[0, 0, 1, 1], [0, 6, 1, 7], [2, 2, 3, 3], [4, 0, 4, 1], [4, 4, 4, 5]])\n assert answers_match(candidate(land=[[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, 2, 0, 2], [0, 4, 0, 4], [1, 1, 1, 1], [1, 3, 1, 3], [2, 0, 2, 0], [2, 2, 2, 2], [2, 4, 2, 4], [3, 1, 3, 1], [3, 3, 3, 3]])\n assert answers_match(candidate(land=[[1, 1, 0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]]), [[0, 0, 0, 1], [0, 4, 0, 5], [0, 8, 0, 9], [1, 6, 1, 7], [2, 0, 2, 1], [2, 4, 2, 5], [2, 8, 2, 9], [3, 6, 3, 7], [4, 0, 4, 1], [4, 4, 4, 5], [4, 8, 4, 9]])\n assert answers_match(candidate(land=[[1, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1]]), [[0, 0, 0, 0], [0, 5, 0, 5], [1, 2, 2, 3], [4, 0, 4, 0], [4, 5, 4, 5]])\n assert answers_match(candidate(land=[[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, 3, 0, 3], [0, 5, 0, 5], [0, 7, 0, 7], [0, 9, 0, 9], [1, 0, 1, 0], [1, 2, 1, 2], [1, 4, 1, 4], [1, 6, 1, 6], [1, 8, 1, 8], [2, 1, 2, 1], [2, 3, 2, 3], [2, 5, 2, 5], [2, 7, 2, 7], [2, 9, 2, 9], [3, 0, 3, 0], [3, 2, 3, 2], [3, 4, 3, 4], [3, 6, 3, 6], [3, 8, 3, 8]])\n assert answers_match(candidate(land=[[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, 2, 5]])\n", "comparison": "unordered"}, "public_tests": ["[[1,0,0],[0,1,1],[0,1,1]]", "[[1,1],[1,1]]", "[[0]]"], "hints": ["Since every group of farmland is rectangular, the top left corner of each group will have the smallest x-coordinate and y-coordinate of any farmland in the group.", "Similarly, the bottom right corner of each group will have the largest x-coordinate and y-coordinate of any farmland in the group.", "Use DFS to traverse through different groups of farmlands and keep track of the smallest and largest x-coordinate and y-coordinates you have seen in each group."], "metadata": {"canonical_parameter_names": ["land"], "leetcode_dataset_entry_point": "Solution().findFarmland", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:28+00:00", "tests_total": 74, "tests_dropped": 0, "flags": ["any_order", "has_images"], "topic_tags": ["array", "depth-first-search", "breadth-first-search", "matrix"]}, "language": "php", "interface": {"raw_signature": "function findFarmland($land) {", "container": "Solution", "callable": "findFarmland", "parameters": [{"name": "land", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1994, "task_id": "the-number-of-good-subsets", "difficulty": "Hard", "problem_description": "You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.\n\n- For example, if nums = [1, 2, 3, 4]:\n - [2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.\n - [1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.\n\nReturn the number of different good subsets in nums modulo 10^9 + 7.\n\nA subset of nums is any array that can be obtained by deleting some (possibly none or 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 = [1,2,3,4]\nOutput: 6\nExplanation: The good subsets are:\n- [1,2]: product is 2, which is the product of distinct prime 2.\n- [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [1,3]: product is 3, which is the product of distinct prime 3.\n- [2]: product is 2, which is the product of distinct prime 2.\n- [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [3]: product is 3, which is the product of distinct prime 3.\n\nExample 2:\n\nInput: nums = [4,2,3,15]\nOutput: 5\nExplanation: The good subsets are:\n- [2]: product is 2, which is the product of distinct prime 2.\n- [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.\n- [3]: product is 3, which is the product of distinct prime 3.\n- [15]: product is 15, which is the product of distinct primes 3 and 5.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 30\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 2, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29]) == 59048.0\n assert candidate(nums = [1, 1, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 8184.0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10.0\n assert candidate(nums = [1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 142.0\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 703.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]) == 20.0\n assert candidate(nums = [30, 26, 28, 12, 14, 22, 2, 4, 18, 20, 16, 8, 10, 24, 6, 5, 15, 3, 25, 7, 9, 11, 13, 17, 19, 21, 23, 27, 29]) == 3327.0\n assert candidate(nums = [1, 2, 3, 4]) == 6.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]) == 6654.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]) == 20.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 = [7, 11, 13, 17, 19, 23, 29]) == 127.0\n assert candidate(nums = [4, 2, 3, 15]) == 5.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 = [30, 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]) == 3326.0\n assert candidate(nums = [30, 28, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == 6.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1023.0\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 30]) == 72.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 = [10, 20, 30, 1, 2, 3, 5, 7]) == 42.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30]) == 14.0\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 5, 5, 5, 7, 7, 7, 11, 11, 11, 13, 13, 13, 17, 17, 17, 19, 19, 19, 23, 23, 23, 29, 29, 29]) == 1048575.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 6, 10, 14, 15, 21, 22, 26, 30, 4, 9, 16, 25, 28, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3406848.0\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 25, 26, 27, 30]) == 14.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 = [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 = [6, 10, 14, 15, 21, 22, 26, 30, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 1, 1]) == 13308.0\n assert candidate(nums = [2, 3, 2, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29, 30, 30, 30]) == 65609.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]) == 43.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]) == 6654.0\n assert candidate(nums = [4, 6, 10, 14, 15, 21, 22, 26, 27, 30]) == 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, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 72693241.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, 29, 29]) == 27.0\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 11, 11, 11, 11]) == 3124.0\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 14.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, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 255.0\n assert candidate(nums = [1, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30]) == 4604.0\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 11, 11, 11, 11]) == 4998.0\n assert candidate(nums = [6, 15, 10, 14, 21, 22, 26, 22, 21, 14, 10, 15, 6, 30, 30, 30, 30, 30, 30, 30]) == 40.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 6, 10, 14, 15, 21, 22, 26, 30, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3406848.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]) == 2303.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18]) == 2111.0\n assert candidate(nums = [4, 9, 16, 25, 28, 10, 14, 21, 22, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 16.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 = [2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29, 30, 30, 30, 30, 30]) == 69983.0\n assert candidate(nums = [4, 8, 9, 12, 18, 20, 24, 25, 27, 28, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7]) == 9984.0\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 30, 30]) == 16.0\n assert candidate(nums = [1, 6, 10, 15, 21, 22, 26, 30]) == 24.0\n assert candidate(nums = [1, 6, 8, 9, 10, 12, 14, 15, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 28.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]) == 6654.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 3327.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, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 1548287.0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 1047552.0\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30, 15, 6, 10, 21, 22]) == 5246.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, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 72693241.0\n assert candidate(nums = [1, 1, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 8184.0\n assert candidate(nums = [1, 2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29, 30, 30]) == 126844.0\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 6, 10, 14, 15, 21, 22, 26, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 8958.0\n assert candidate(nums = [1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 28.0\n assert candidate(nums = [30, 28, 15, 10, 6, 3, 2, 1]) == 18.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 = [15, 10, 21, 30, 22, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 32.0\n assert candidate(nums = [30, 28, 26, 22, 21, 14, 10, 15, 6, 4, 8, 9, 12, 18, 20, 24, 25, 27, 1, 1]) == 56.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]) == 1054.0\n assert candidate(nums = [10, 15, 21, 22, 26, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 25.0\n assert candidate(nums = [8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]) == 13.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30, 30, 30, 30, 30]) == 18.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.0\n assert candidate(nums = [4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 30, 30, 1, 1, 1, 1, 1, 1]) == 1024.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, 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]) == 691088.0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 14.0\n assert candidate(nums = [30, 15, 6, 10, 21, 22, 26, 27, 28, 3, 5, 7, 11, 13, 17, 19, 23, 29, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2292736.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30, 2, 3, 5, 7, 11, 13, 17, 19, 23]) == 40823.0\n assert candidate(nums = [1, 2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29]) == 118096.0\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30]) == 2302.0\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3406848.0\n assert candidate(nums = [6, 15, 10, 14, 21, 22, 26, 22, 21, 14, 10, 15, 6, 30, 2, 3, 5, 7, 11, 13]) == 359.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 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1047552.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 30, 30, 30]) == 1407.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 = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 6, 10, 14, 15, 21, 22, 26, 30, 1]) == 13308.0\n assert candidate(nums = [6, 10, 14, 15, 21, 22, 26, 30, 30, 30]) == 16.0\n assert candidate(nums = [1, 1, 1, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 16368.0\n assert candidate(nums = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 1, 2, 3, 5, 7, 11, 13, 17, 19]) == 510.0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29]) == 1048575.0\n assert candidate(nums = [8, 9, 12, 18, 20, 24, 25, 27, 28, 30]) == 1.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]) == 13308.0\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 24166.0\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]", "[4,2,3,15]"], "hints": ["Consider only the numbers which have a good prime factorization.", "Use brute force to find all possible good subsets and then calculate its frequency in nums."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberOfGoodSubsets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:30+00:00", "tests_total": 108, "tests_dropped": 17, "flags": [], "topic_tags": ["array", "hash-table", "math", "dynamic-programming", "bit-manipulation", "counting", "number-theory", "bitmask", "sieve-theory"]}, "language": "php", "interface": {"raw_signature": "function numberOfGoodSubsets($nums) {", "container": "Solution", "callable": "numberOfGoodSubsets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1995, "task_id": "count-special-quadruplets", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:\n\n- nums[a] + nums[b] + nums[c] == nums[d], and\n- a < b < c < d\n\nExample 1:\n\nInput: nums = [1,2,3,6]\nOutput: 1\nExplanation: The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.\n\nExample 2:\n\nInput: nums = [3,3,6,4,5]\nOutput: 0\nExplanation: There are no such quadruplets in [3,3,6,4,5].\n\nExample 3:\n\nInput: nums = [1,1,1,3,5]\nOutput: 4\nExplanation: The 4 quadruplets that satisfy the requirement are:\n- (0, 1, 2, 3): 1 + 1 + 1 == 3\n- (0, 1, 3, 4): 1 + 1 + 3 == 5\n- (0, 2, 3, 4): 1 + 1 + 3 == 5\n- (1, 2, 3, 4): 1 + 1 + 3 == 5\n\nConstraints:\n\n- 4 <= nums.length <= 50\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 6]) == 1\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1]) == 0\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 11\n assert candidate(nums = [3, 3, 6, 4, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [1, 1, 1, 3, 5]) == 4\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36]) == 3\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66]) == 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]) == 147\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 11\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10]) == 40\n assert candidate(nums = [4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13, 20, 19, 18, 17]) == 143\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 19]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 12]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]) == 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]) == 0\n assert candidate(nums = [1, 2, 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]) == 817\n assert candidate(nums = [50, 25, 25, 75, 50, 50, 100, 50, 75, 100]) == 7\n assert candidate(nums = [5, 5, 5, 5, 15, 15, 15, 15, 25, 25, 25, 25, 35, 35, 35, 35]) == 304\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 174\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 60]) == 123\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 9, 12, 15, 18, 21, 24]) == 34\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]) == 927\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 15, 5, 5, 5, 5, 5, 5, 5]) == 35\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]) == 358\n assert candidate(nums = [5, 5, 5, 5, 5, 15, 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, 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 = [5, 1, 4, 3, 6, 2, 7, 8, 9, 10]) == 10\n assert candidate(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 53\n assert candidate(nums = [2, 2, 2, 6, 6, 6, 18, 18, 18]) == 6\n assert candidate(nums = [1, 1, 1, 1, 4, 1, 1, 1, 1, 5]) == 0\n assert candidate(nums = [3, 3, 6, 4, 5, 5, 5, 15, 15, 15, 15, 30, 30, 30, 30]) == 16\n assert candidate(nums = [1, 2, 3, 4, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33]) == 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, 80]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 30]) == 21\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == 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]) == 244\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]) == 0\n assert candidate(nums = [5, 5, 5, 15, 15, 15, 30]) == 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]) == 244\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11]) == 39\n assert candidate(nums = [7, 1, 2, 4, 5, 3, 8, 6, 9, 10]) == 10\n assert candidate(nums = [3, 3, 3, 9, 3, 3, 3, 3, 3, 3, 9, 3]) == 85\n assert candidate(nums = [5, 5, 5, 15, 15, 25, 25]) == 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]) == 147\n assert candidate(nums = [2, 2, 2, 6, 2, 2, 2, 6, 2, 2, 2, 6, 2, 2, 2]) == 105\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, 15]) == 420\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 147\n assert candidate(nums = [5, 5, 5, 15, 10, 15, 20]) == 5\n assert candidate(nums = [8, 2, 2, 4, 6, 10, 2, 6, 2, 12, 8, 4]) == 22\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 20]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 53\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36]) == 0\n assert candidate(nums = [1, 2, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54]) == 119\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 83\n assert candidate(nums = [8, 8, 8, 8, 32, 8, 8, 8, 8, 8, 8, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 5, 1, 8, 3, 9, 4, 6]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 586\n assert candidate(nums = [5, 5, 5, 5, 5, 15, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 1, 2, 3, 3, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 13, 13, 14, 15]) == 218\n assert candidate(nums = [5, 1, 4, 2, 8, 10, 7]) == 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]) == 2972\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]) == 21\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 147\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 0\n assert candidate(nums = [5, 1, 5, 5, 5, 5, 5, 10]) == 0\n assert candidate(nums = [30, 20, 10, 60, 50, 40, 100, 90, 80, 70]) == 10\n assert candidate(nums = [1, 2, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39]) == 43\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 21]) == 76\n assert candidate(nums = [2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 166\n assert candidate(nums = [5, 15, 10, 10, 10, 10, 25, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 120\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28]) == 61\n assert candidate(nums = [9, 5, 3, 7, 2, 8, 10, 6, 4, 12, 1, 11]) == 9\n assert candidate(nums = [7, 3, 6, 2, 4, 8, 10, 15, 1, 9]) == 5\n assert candidate(nums = [3, 3, 3, 6, 9, 12, 15, 18, 21, 24, 27]) == 38\n", "comparison": "exact"}, "public_tests": ["[1,2,3,6]", "[3,3,6,4,5]", "[1,1,1,3,5]"], "hints": ["N is very small, how can we use that?", "Can we check every possible quadruplet?"], "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:37:32+00:00", "tests_total": 107, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "hash-table", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countQuadruplets($nums) {", "container": "Solution", "callable": "countQuadruplets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1996, "task_id": "the-number-of-weak-characters-in-the-game", "difficulty": "Medium", "problem_description": "You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attack_i, defense_i] represents the properties of the i^th character in the game.\n\nA character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attack_j > attack_i and defense_j > defense_i.\n\nReturn the number of weak characters.\n\nExample 1:\n\nInput: properties = [[5,5],[6,3],[3,6]]\nOutput: 0\nExplanation: No character has strictly greater attack and defense than the other.\n\nExample 2:\n\nInput: properties = [[2,2],[3,3]]\nOutput: 1\nExplanation: The first character is weak because the second character has a strictly greater attack and defense.\n\nExample 3:\n\nInput: properties = [[1,5],[10,4],[4,3]]\nOutput: 1\nExplanation: The third character is weak because the second character has a strictly greater attack and defense.\n\nConstraints:\n\n- 2 <= properties.length <= 10^5\n- properties[i].length == 2\n- 1 <= attack_i, defense_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(properties = [[5, 5], [6, 3], [3, 6], [2, 2], [1, 1]]) == 2\n assert candidate(properties = [[2, 2], [3, 3]]) == 1\n assert candidate(properties = [[5, 1], [5, 10], [4, 10], [4, 4], [3, 14], [3, 6], [2, 10], [1, 14], [1, 4]]) == 4\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 4\n assert candidate(properties = [[5, 5], [6, 3], [3, 6]]) == 0\n assert candidate(properties = [[10, 1], [5, 1], [7, 10], [4, 1], [5, 9], [6, 9], [7, 2], [1, 10]]) == 4\n assert candidate(properties = [[1, 5], [10, 4], [4, 3], [5, 6], [7, 8], [8, 7], [9, 9], [2, 2]]) == 6\n assert candidate(properties = [[1, 10], [10, 1], [4, 4], [4, 5]]) == 0\n assert candidate(properties = [[1, 5], [10, 4], [4, 3], [3, 15], [1, 20]]) == 2\n assert candidate(properties = [[1, 5], [10, 4], [4, 3]]) == 1\n assert candidate(properties = [[5, 5], [6, 3], [3, 6], [2, 2], [1, 1], [6, 7]]) == 4\n assert candidate(properties = [[1, 5], [1, 5], [1, 5], [10, 4], [4, 3]]) == 1\n assert candidate(properties = [[10, 1], [5, 1], [7, 10], [4, 11], [12, 1], [8, 4], [9, 7]]) == 2\n assert candidate(properties = [[6, 9], [7, 5], [7, 9], [7, 10], [10, 4], [10, 7], [8, 4]]) == 3\n assert candidate(properties = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 4\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 3\n assert candidate(properties = [[100000, 100000], [1, 1], [2, 2], [3, 3], [4, 4]]) == 4\n assert candidate(properties = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995], [7, 99994], [8, 99993], [9, 99992], [10, 99991], [11, 99990], [12, 99989], [13, 99988], [14, 99987], [15, 99986], [16, 99985], [17, 99984], [18, 99983], [19, 99982], [20, 99981]]) == 0\n assert candidate(properties = [[1, 1], [1, 2], [2, 1], [2, 2], [1, 3], [2, 3], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [1, 4], [2, 4], [3, 4], [4, 4], [1, 5], [2, 5], [3, 5], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 16\n assert candidate(properties = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995], [7, 99994], [8, 99993], [9, 99992], [10, 99991]]) == 0\n assert candidate(properties = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [9, 5], [8, 5], [7, 5], [6, 5], [5, 5]]) == 0\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 2]]) == 8\n assert candidate(properties = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [1, 11]]) == 9\n assert candidate(properties = [[100000, 100000], [1, 1], [2, 2], [99999, 99999], [50000, 50000], [10000, 10000]]) == 5\n assert candidate(properties = [[100000, 100000], [99999, 99999], [99998, 99998], [99997, 99997], [99996, 99996], [99995, 99995], [99994, 99994], [99993, 99993], [99992, 99992], [99991, 99991]]) == 9\n assert candidate(properties = [[100000, 1], [1, 100000], [50000, 50000], [25000, 75000], [75000, 25000]]) == 0\n assert candidate(properties = [[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]]) == 20\n assert candidate(properties = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [10, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 10]]) == 17\n assert candidate(properties = [[5, 9], [5, 7], [5, 5], [5, 3], [5, 1], [10, 10], [10, 9], [10, 8], [10, 7], [10, 6], [10, 5], [10, 4], [10, 3], [10, 2], [10, 1]]) == 5\n assert candidate(properties = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 17\n assert candidate(properties = [[1, 10], [10, 1], [2, 9], [9, 2], [3, 8], [8, 3], [4, 7], [7, 4], [5, 6], [6, 5]]) == 0\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [2, 10], [3, 9], [4, 8], [5, 7], [6, 6], [7, 5], [8, 4], [9, 3], [10, 2], [1, 10]]) == 16\n assert candidate(properties = [[1, 1], [1, 10], [1, 100], [1, 1000], [1, 10000], [1, 100000], [10, 1], [10, 10], [10, 100], [10, 1000], [10, 10000], [10, 100000]]) == 5\n assert candidate(properties = [[10, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 10]]) == 8\n assert candidate(properties = [[100000, 100000], [99999, 99999], [99998, 99998], [99997, 99997], [99996, 99996]]) == 4\n assert candidate(properties = [[10, 10], [10, 9], [10, 8], [10, 7], [10, 6], [10, 5], [10, 4], [10, 3], [10, 2], [10, 1], [9, 10], [8, 10], [7, 10], [6, 10], [5, 10], [4, 10], [3, 10], [2, 10], [1, 10]]) == 0\n assert candidate(properties = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [10, 10]]) == 9\n assert candidate(properties = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91], [1, 90], [2, 89], [3, 88], [4, 87], [5, 86], [6, 85], [7, 84], [8, 83], [9, 82], [10, 81], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 18\n assert candidate(properties = [[50, 50], [51, 49], [52, 48], [53, 47], [54, 46], [55, 45], [56, 44], [57, 43], [58, 42], [59, 41], [60, 40]]) == 0\n assert candidate(properties = [[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]]) == 9\n assert candidate(properties = [[100000, 1], [99999, 2], [99998, 3], [99997, 4], [99996, 5], [99995, 6], [99994, 7], [99993, 8], [99992, 9], [99991, 10]]) == 0\n assert candidate(properties = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 8\n assert candidate(properties = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 13\n assert candidate(properties = [[10, 5], [9, 6], [8, 7], [7, 8], [6, 9], [5, 10], [4, 11], [3, 12], [2, 13], [1, 14], [10, 15], [9, 16], [8, 17], [7, 18], [6, 19], [5, 20], [4, 21], [3, 22], [2, 23], [1, 24]]) == 9\n assert candidate(properties = [[100000, 1], [1, 100000], [50000, 50000], [90000, 20000], [20000, 90000]]) == 0\n assert candidate(properties = [[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]]) == 8\n assert candidate(properties = [[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]]) == 12\n assert candidate(properties = [[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], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]]) == 9\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 9\n assert candidate(properties = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]]) == 8\n assert candidate(properties = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 9\n assert candidate(properties = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 14\n assert candidate(properties = [[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]]) == 8\n assert candidate(properties = [[1, 5], [2, 10], [3, 15], [4, 20], [5, 25], [6, 30], [7, 35], [8, 40], [9, 45], [10, 50], [5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45]]) == 17\n assert candidate(properties = [[1, 10], [1, 20], [1, 30], [1, 40], [1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [1, 100]]) == 0\n assert candidate(properties = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 0\n assert candidate(properties = [[5, 9], [7, 7], [4, 3], [1, 10], [6, 6], [8, 2], [3, 5]]) == 3\n assert candidate(properties = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [15, 6], [25, 11], [35, 16], [45, 21], [55, 26], [10, 7], [20, 12], [30, 17], [40, 22], [50, 27]]) == 13\n assert candidate(properties = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 1], [8, 2], [9, 3], [10, 4]]) == 8\n assert candidate(properties = [[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]]) == 14\n assert candidate(properties = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995]]) == 0\n assert candidate(properties = [[20, 39], [19, 37], [18, 35], [17, 33], [16, 31], [15, 29], [14, 27], [13, 25], [12, 23], [11, 21], [10, 19], [9, 17], [8, 15], [7, 13], [6, 11], [5, 9], [4, 7], [3, 5], [2, 3], [1, 1]]) == 19\n assert candidate(properties = [[1, 100000], [100000, 1], [50000, 50000], [75000, 25000], [25000, 75000], [1, 1], [100000, 100000]]) == 4\n assert candidate(properties = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 0\n assert candidate(properties = [[1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1]]) == 0\n assert candidate(properties = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 9\n assert candidate(properties = [[100, 1], [100, 2], [100, 3], [100, 4], [100, 5], [100, 6], [100, 7], [100, 8], [100, 9], [100, 10], [99, 11], [98, 12], [97, 13], [96, 14], [95, 15], [94, 16], [93, 17], [92, 18], [91, 19], [90, 20]]) == 0\n assert candidate(properties = [[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, 1]]) == 17\n assert candidate(properties = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 0\n assert candidate(properties = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14]]) == 9\n assert candidate(properties = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [1, 11]]) == 0\n assert candidate(properties = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91], [1, 90], [2, 89], [3, 88], [4, 87], [5, 86], [6, 85], [7, 84], [8, 83], [9, 82], [10, 81]]) == 9\n assert candidate(properties = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 4\n assert candidate(properties = [[5, 5], [5, 6], [6, 5], [6, 6], [1, 1], [1, 2], [2, 1], [2, 2], [7, 7], [8, 8]]) == 9\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [10, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 1]]) == 18\n assert candidate(properties = [[10, 10], [10, 9], [10, 8], [10, 7], [10, 6], [9, 10], [8, 10], [7, 10], [6, 10], [5, 10]]) == 0\n assert candidate(properties = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 0\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10]]) == 8\n assert candidate(properties = [[1, 5], [1, 5], [1, 5], [10, 4], [4, 3], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 8\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [1, 10]]) == 8\n assert candidate(properties = [[1, 50000], [50000, 1], [2, 49999], [49999, 2], [3, 49998], [49998, 3], [4, 49997], [49997, 4], [5, 49996], [49996, 5], [6, 49995], [49995, 6], [7, 49994], [49994, 7], [8, 49993], [49993, 8], [9, 49992], [49992, 9], [10, 49991], [49991, 10]]) == 0\n assert candidate(properties = [[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]]) == 0\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]]) == 11\n assert candidate(properties = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1], [10, 9], [11, 8], [12, 7], [13, 6], [14, 5], [15, 4]]) == 8\n assert candidate(properties = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19], [11, 21], [12, 23], [13, 25], [14, 27], [15, 29], [16, 31], [17, 33], [18, 35], [19, 37], [20, 39]]) == 19\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [4, 5], [3, 5], [2, 5], [1, 5], [5, 4], [5, 3], [5, 2], [5, 1]]) == 4\n assert candidate(properties = [[50, 50], [40, 40], [30, 30], [20, 20], [10, 10], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]]) == 9\n assert candidate(properties = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 8\n assert candidate(properties = [[5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [10, 10], [10, 10], [10, 10], [10, 10], [10, 10]]) == 5\n assert candidate(properties = [[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]]) == 0\n assert candidate(properties = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]]) == 0\n assert candidate(properties = [[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], [10, 10]]) == 17\n assert candidate(properties = [[9, 8], [8, 9], [7, 10], [6, 11], [5, 12], [4, 13], [3, 14], [2, 15], [1, 16], [10, 7], [11, 6], [12, 5], [13, 4], [14, 3], [15, 2], [16, 1]]) == 0\n assert candidate(properties = [[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]]) == 16\n assert candidate(properties = [[1, 50], [50, 1], [2, 49], [49, 2], [3, 48], [48, 3], [4, 47], [47, 4], [5, 46], [46, 5], [6, 45], [45, 6], [7, 44], [44, 7], [8, 43], [43, 8], [9, 42], [42, 9], [10, 41], [41, 10]]) == 0\n assert candidate(properties = [[9, 7], [9, 8], [9, 9], [10, 7], [10, 8], [10, 9], [11, 7], [11, 8], [11, 9]]) == 4\n assert candidate(properties = [[1, 100000], [100000, 1], [50000, 50000], [75000, 25000], [25000, 75000]]) == 0\n assert candidate(properties = [[5, 10], [10, 5], [15, 15], [20, 10], [25, 15], [30, 20], [35, 25], [40, 30], [45, 35], [50, 40]]) == 9\n assert candidate(properties = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 9\n", "comparison": "exact"}, "public_tests": ["[[5,5],[6,3],[3,6]]", "[[2,2],[3,3]]", "[[1,5],[10,4],[4,3]]"], "hints": ["Sort the array on the basis of the attack values and group characters with the same attack together. How can you use these groups?", "Characters in one group will always have a lesser attack value than the characters of the next group. Hence, we will only need to check if there is a higher defense value present in the next groups."], "metadata": {"canonical_parameter_names": ["properties"], "leetcode_dataset_entry_point": "Solution().numberOfWeakCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:35+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "stack", "greedy", "sorting", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function numberOfWeakCharacters($properties) {", "container": "Solution", "callable": "numberOfWeakCharacters", "parameters": [{"name": "properties", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1997, "task_id": "first-day-where-you-have-been-in-all-the-rooms", "difficulty": "Medium", "problem_description": "There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.\n\nInitially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by the following rules and a given 0-indexed array nextVisit of length n:\n\n- Assuming that on a day, you visit room i,\n- if you have been in room i an odd number of times (including the current visit), on the next day you will visit a room with a lower or equal room number specified by nextVisit[i] where 0 <= nextVisit[i] <= i;\n- if you have been in room i an even number of times (including the current visit), on the next day you will visit room (i + 1) mod n.\n\nReturn the label of the first day where you have been in all the rooms. It can be shown that such a day exists. Since the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: nextVisit = [0,0]\nOutput: 2\nExplanation:\n- On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.\n On the next day you will visit room nextVisit[0] = 0\n- On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.\n On the next day you will visit room (0 + 1) mod 2 = 1\n- On day 2, you visit room 1. This is the first day where you have been in all the rooms.\n\nExample 2:\n\nInput: nextVisit = [0,0,2]\nOutput: 6\nExplanation:\nYour room visiting order for each day is: [0,0,1,0,0,1,2,...].\nDay 6 is the first day where you have been in all the rooms.\n\nExample 3:\n\nInput: nextVisit = [0,1,2,0]\nOutput: 6\nExplanation:\nYour room visiting order for each day is: [0,0,1,1,2,2,3,...].\nDay 6 is the first day where you have been in all the rooms.\n\nConstraints:\n\n- n == nextVisit.length\n- 2 <= n <= 10^5\n- 0 <= nextVisit[i] <= i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nextVisit = [0, 0, 2]) == 6\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5]) == 10\n assert candidate(nextVisit = [0, 1, 1, 1, 1]) == 16\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1022\n assert candidate(nextVisit = [0, 1, 0, 1, 0, 1]) == 42\n assert candidate(nextVisit = [0, 1, 2, 3, 2, 1, 0, 1, 2, 3]) == 230\n assert candidate(nextVisit = [0, 1, 0, 2]) == 10\n assert candidate(nextVisit = [0, 1, 2, 0]) == 6\n assert candidate(nextVisit = [0, 1, 1, 1, 1, 1]) == 32\n assert candidate(nextVisit = [0, 1, 1, 0, 1, 1, 0]) == 72\n assert candidate(nextVisit = [0, 1, 0, 2, 1]) == 18\n assert candidate(nextVisit = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 682\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 0]) == 10\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 18\n assert candidate(nextVisit = [0, 1, 1, 0, 1, 2]) == 36\n assert candidate(nextVisit = [0, 1, 1, 0]) == 8\n assert candidate(nextVisit = [0, 0]) == 2\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == 328\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0]) == 670\n assert candidate(nextVisit = [0, 1, 0, 3, 2, 5, 4, 7, 6, 9]) == 58\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1022\n assert candidate(nextVisit = [0, 0, 2, 1, 4, 3, 5, 6, 7, 8, 9]) == 98\n assert candidate(nextVisit = [0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0]) == 599186\n assert candidate(nextVisit = [0, 1, 1, 2, 2, 2, 3, 3, 3, 3]) == 358\n assert candidate(nextVisit = [0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18]) == 56\n assert candidate(nextVisit = [0, 1, 0, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 633246732\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 38\n assert candidate(nextVisit = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 110\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 2044\n assert candidate(nextVisit = [0, 1, 0, 3, 2, 1, 4, 5, 2, 3, 6, 7, 8, 9]) == 3802\n assert candidate(nextVisit = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 524288\n assert candidate(nextVisit = [0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0]) == 13851577\n assert candidate(nextVisit = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 461127067\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1048574\n assert candidate(nextVisit = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 44739242\n assert candidate(nextVisit = [0, 1, 0, 2, 1, 0, 3, 2, 1, 0]) == 556\n assert candidate(nextVisit = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 786430\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1048574\n assert candidate(nextVisit = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 699050\n assert candidate(nextVisit = [0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9]) == 198234\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10258\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 41964584\n assert candidate(nextVisit = [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]) == 308\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 63550\n assert candidate(nextVisit = [0, 1, 1, 3, 2, 2, 5]) == 34\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 38954\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0]) == 18\n assert candidate(nextVisit = [0, 1, 0, 2, 3, 2, 5, 4]) == 82\n assert candidate(nextVisit = [0, 1, 2, 3, 2, 3, 4, 3, 4, 5]) == 154\n assert candidate(nextVisit = [0, 1, 0, 3, 0, 1, 0, 5, 0, 1, 0, 3, 0, 1, 0, 7, 0, 1, 0, 3, 0, 1]) == 1543578\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 3, 2, 3, 4, 5]) == 106\n assert candidate(nextVisit = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]) == 57521884\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10258\n assert candidate(nextVisit = [0, 1, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16, 0, 18, 0, 20]) == 5114\n assert candidate(nextVisit = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0]) == 438\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3]) == 123366\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20126903\n assert candidate(nextVisit = [0, 0, 0, 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, 10]) == 943314207\n assert candidate(nextVisit = [0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3]) == 229862\n assert candidate(nextVisit = [0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 89816588\n assert candidate(nextVisit = [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]) == 855298880\n assert candidate(nextVisit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 40\n assert candidate(nextVisit = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 512\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 640520038\n assert candidate(nextVisit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 147483632\n assert candidate(nextVisit = [0, 1, 2, 0, 3, 2, 5, 6, 7, 8, 9, 10, 0]) == 220\n assert candidate(nextVisit = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) == 590\n assert candidate(nextVisit = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 512\n assert candidate(nextVisit = [0, 1, 0, 1, 2, 3, 4, 5, 6, 7]) == 334\n", "comparison": "exact"}, "public_tests": ["[0,0]", "[0,0,2]", "[0,1,2,0]"], "hints": ["The only way to get to room i+1 is when you are visiting room i and room i has been visited an even number of times.", "After visiting room i an odd number of times, you are required to visit room nextVisit[i] where nextVisit[i] <= i. It takes a fixed amount of days for you to come back from room nextVisit[i] to room i. Then, you have visited room i even number of times.nextVisit[i]", "Can you use Dynamic Programming to avoid recomputing the number of days it takes to visit room i from room nextVisit[i]?"], "metadata": {"canonical_parameter_names": ["nextVisit"], "leetcode_dataset_entry_point": "Solution().firstDayBeenInAllRooms", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:38+00:00", "tests_total": 110, "tests_dropped": 41, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function firstDayBeenInAllRooms($nextVisit) {", "container": "Solution", "callable": "firstDayBeenInAllRooms", "parameters": [{"name": "nextVisit", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 1998, "task_id": "gcd-sort-of-an-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums, and you can perform the following operation any number of times on nums:\n\n- Swap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], nums[j]) is the greatest common divisor of nums[i] and nums[j].\n\nReturn true if it is possible to sort nums in non-decreasing order using the above swap method, or false otherwise.\n\nExample 1:\n\nInput: nums = [7,21,3]\nOutput: true\nExplanation: We can sort [7,21,3] by performing the following operations:\n- Swap 7 and 21 because gcd(7,21) = 7. nums = [21,7,3]\n- Swap 21 and 3 because gcd(21,3) = 3. nums = [3,7,21]\n\nExample 2:\n\nInput: nums = [5,2,6,2]\nOutput: false\nExplanation: It is impossible to sort the array because 5 cannot be swapped with any other element.\n\nExample 3:\n\nInput: nums = [10,5,9,3,15]\nOutput: true\nWe can sort [10,5,9,3,15] by performing the following operations:\n- Swap 10 and 15 because gcd(10,15) = 5. nums = [15,5,9,3,10]\n- Swap 15 and 3 because gcd(15,3) = 3. nums = [3,5,9,15,10]\n- Swap 10 and 15 because gcd(10,15) = 5. nums = [3,5,9,10,15]\n\nConstraints:\n\n- 1 <= nums.length <= 3 * 10^4\n- 2 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [12, 15, 18, 20, 25]) == True\n assert candidate(nums = [7, 21, 3]) == True\n assert candidate(nums = [8, 4, 12, 6]) == True\n assert candidate(nums = [2, 3, 5, 7, 11]) == True\n assert candidate(nums = [2, 4, 6, 8, 10]) == True\n assert candidate(nums = [18, 9, 27, 3, 6]) == True\n assert candidate(nums = [3, 9, 6, 18, 27]) == True\n assert candidate(nums = [37, 49, 111, 143, 169]) == True\n assert candidate(nums = [100, 200, 400, 800, 1600]) == True\n assert candidate(nums = [22, 44, 11, 66, 33]) == True\n assert candidate(nums = [100, 200, 300, 400, 500]) == True\n assert candidate(nums = [83, 97, 101, 103, 107]) == True\n assert candidate(nums = [100000, 99998, 99999, 99997, 99996]) == False\n assert candidate(nums = [10, 5, 9, 3, 15]) == True\n assert candidate(nums = [105, 70, 30, 210, 42]) == True\n assert candidate(nums = [30, 42, 70, 105, 35]) == True\n assert candidate(nums = [5, 2, 6, 2]) == False\n assert candidate(nums = [56, 72, 88, 104, 120, 136, 152]) == True\n assert candidate(nums = [121, 132, 143, 154, 165, 176, 187, 198, 209]) == True\n assert candidate(nums = [48, 64, 80, 96, 112]) == True\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119]) == True\n assert candidate(nums = [210, 315, 420, 525, 630, 735]) == True\n assert candidate(nums = [105, 45, 63, 21, 315]) == True\n assert candidate(nums = [100, 50, 25, 125, 200, 150]) == True\n assert candidate(nums = [91, 182, 273, 364, 455]) == True\n assert candidate(nums = [121, 132, 143, 154, 165, 176]) == True\n assert candidate(nums = [16, 32, 48, 64, 80, 96, 112, 128, 144]) == True\n assert candidate(nums = [70, 35, 28, 56, 14, 18]) == True\n assert candidate(nums = [14, 21, 28, 35, 42, 49, 56, 63, 70]) == True\n assert candidate(nums = [32, 48, 64, 80, 96, 112]) == True\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310]) == True\n assert candidate(nums = [30, 25, 20, 15, 10, 5]) == True\n assert candidate(nums = [30, 45, 60, 75, 90, 105]) == True\n assert candidate(nums = [44, 55, 66, 77, 88, 99, 110, 121]) == True\n assert candidate(nums = [15, 20, 25, 30, 35]) == True\n assert candidate(nums = [33, 66, 99, 132, 165]) == True\n assert candidate(nums = [49, 14, 7, 98, 28]) == True\n assert candidate(nums = [6, 8, 10, 12, 14, 16, 18, 20]) == True\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189]) == True\n assert candidate(nums = [49, 42, 28, 35, 70]) == True\n assert candidate(nums = [123, 246, 369, 492, 615, 738, 861, 984]) == True\n assert candidate(nums = [84, 126, 168, 210, 252, 294, 336, 378, 420]) == True\n assert candidate(nums = [84, 28, 42, 70, 56]) == True\n assert candidate(nums = [101, 202, 303, 404, 505, 606]) == True\n assert candidate(nums = [56, 14, 28, 7, 98, 49]) == True\n assert candidate(nums = [45, 30, 60, 90, 120, 150]) == True\n assert candidate(nums = [100, 50, 75, 25, 150]) == True\n assert candidate(nums = [15, 25, 35, 45, 55, 65]) == True\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184]) == True\n assert candidate(nums = [121, 221, 143, 169, 13]) == True\n assert candidate(nums = [100, 200, 300, 400, 500]) == True\n assert candidate(nums = [462, 882, 924, 1092, 1260]) == True\n assert candidate(nums = [360, 720, 1080, 1440, 1800, 2160]) == True\n assert candidate(nums = [1000, 500, 250, 125, 625]) == True\n assert candidate(nums = [48, 120, 180, 240, 300]) == True\n assert candidate(nums = [16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240]) == True\n assert candidate(nums = [210, 70, 35, 14, 105]) == True\n assert candidate(nums = [1024, 2048, 512, 256, 128]) == True\n assert candidate(nums = [56, 112, 168, 224, 280]) == True\n assert candidate(nums = [100, 25, 50, 20, 40]) == True\n assert candidate(nums = [24, 36, 48, 12, 60]) == True\n assert candidate(nums = [99, 33, 66, 22, 11, 132]) == True\n assert candidate(nums = [21, 42, 63, 84, 105]) == True\n assert candidate(nums = [13, 26, 39, 52, 65, 78]) == True\n assert candidate(nums = [30, 45, 60, 75, 90]) == True\n assert candidate(nums = [77, 154, 231, 308, 385]) == True\n assert candidate(nums = [91, 130, 169, 182, 273, 338]) == True\n assert candidate(nums = [22, 15, 45, 33, 10, 55]) == True\n assert candidate(nums = [18, 27, 36, 45, 54, 63, 72, 81, 90]) == True\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == True\n assert candidate(nums = [171, 342, 513, 684, 855]) == True\n assert candidate(nums = [33, 55, 66, 88, 110, 121, 132, 143]) == True\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]) == True\n assert candidate(nums = [45, 90, 135, 180, 225]) == True\n assert candidate(nums = [20, 40, 60, 80, 100, 120, 140, 160, 180]) == True\n assert candidate(nums = [100, 50, 25, 20, 125]) == True\n assert candidate(nums = [18, 24, 30, 36, 42]) == True\n assert candidate(nums = [1000, 250, 500, 200, 750, 125, 375, 625, 875, 1250]) == True\n assert candidate(nums = [102, 136, 170, 204, 238, 272, 306, 340, 374]) == True\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190]) == True\n assert candidate(nums = [27, 54, 81, 108, 135, 162, 189, 216]) == True\n assert candidate(nums = [119, 238, 357, 476, 595]) == True\n assert candidate(nums = [81, 27, 54, 162, 324, 486]) == True\n assert candidate(nums = [84, 12, 14, 21, 63]) == True\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105]) == True\n assert candidate(nums = [18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108]) == True\n assert candidate(nums = [49, 63, 77, 91, 105, 119, 133, 147, 161, 175, 189, 203, 217]) == True\n assert candidate(nums = [72, 108, 144, 180, 216, 252, 288, 324, 360, 396]) == True\n assert candidate(nums = [225, 150, 100, 50, 25, 75]) == True\n assert candidate(nums = [121, 110, 99, 88, 77, 66, 55, 44, 33, 22, 11]) == True\n assert candidate(nums = [22, 44, 66, 88, 110, 132, 154, 176, 198]) == True\n assert candidate(nums = [1000, 500, 250, 125, 2000]) == True\n assert candidate(nums = [135, 90, 45, 60, 30]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54]) == True\n assert candidate(nums = [17, 34, 51, 68, 85]) == True\n assert candidate(nums = [105, 15, 35, 21, 63]) == True\n assert candidate(nums = [81, 135, 207, 279, 351, 423]) == True\n assert candidate(nums = [36, 48, 60, 72, 84, 96]) == True\n assert candidate(nums = [180, 120, 90, 60, 45, 30, 20, 15, 10, 5]) == True\n assert candidate(nums = [28, 14, 42, 70, 98]) == True\n assert candidate(nums = [17, 19, 23, 29, 31, 37]) == True\n assert candidate(nums = [81, 27, 54, 108, 162]) == True\n assert candidate(nums = [121, 11, 22, 33, 44, 55]) == True\n assert candidate(nums = [165, 330, 495, 660, 825]) == True\n assert candidate(nums = [49, 98, 147, 196, 245]) == True\n assert candidate(nums = [121, 44, 88, 22, 176]) == True\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85]) == True\n assert candidate(nums = [100, 101, 102, 103, 104, 105]) == True\n assert candidate(nums = [17, 19, 23, 29, 31]) == True\n assert candidate(nums = [315, 105, 35, 7, 14, 21, 42, 63, 84]) == True\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == True\n assert candidate(nums = [13, 26, 39, 52, 65]) == True\n assert candidate(nums = [15, 25, 35, 45, 55]) == True\n assert candidate(nums = [7, 49, 343, 2401, 16807]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == True\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152]) == True\n assert candidate(nums = [14, 21, 35, 49, 70]) == True\n assert candidate(nums = [33, 66, 99, 132, 165, 198]) == True\n assert candidate(nums = [18, 24, 30, 36, 42, 48]) == True\n assert candidate(nums = [22, 44, 66, 88, 110]) == True\n assert candidate(nums = [84, 56, 28, 14, 7, 49, 35]) == True\n assert candidate(nums = [48, 64, 80, 96, 112, 128]) == True\n assert candidate(nums = [1024, 2048, 4096, 8192, 16384, 32768]) == True\n assert candidate(nums = [56, 63, 70, 77, 84, 91]) == True\n assert candidate(nums = [99, 33, 66, 132, 264]) == True\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250]) == True\n assert candidate(nums = [77, 91, 143, 1001, 1001, 143]) == True\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700]) == True\n assert candidate(nums = [77, 55, 99, 110, 132]) == True\n assert candidate(nums = [30, 45, 60, 15, 90]) == True\n assert candidate(nums = [72, 24, 16, 8, 40]) == True\n assert candidate(nums = [42, 21, 7, 14, 28]) == True\n assert candidate(nums = [77, 143, 169, 187, 209, 221, 247, 299, 323, 341]) == True\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50]) == True\n assert candidate(nums = [121, 143, 169, 187, 209]) == True\n assert candidate(nums = [14, 21, 28, 35, 42, 49, 56, 63]) == True\n assert candidate(nums = [14, 21, 28, 35, 42, 49]) == True\n assert candidate(nums = [49, 147, 245, 343, 441, 539]) == True\n assert candidate(nums = [22, 15, 10, 18, 30]) == True\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149]) == True\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81]) == True\n assert candidate(nums = [16, 32, 64, 128, 256, 512, 1024]) == True\n assert candidate(nums = [102, 204, 306, 408, 510]) == True\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000]) == True\n assert candidate(nums = [60, 120, 180, 240, 300, 360]) == True\n assert candidate(nums = [42, 28, 70, 14, 35]) == True\n assert candidate(nums = [22, 33, 44, 55, 66]) == True\n assert candidate(nums = [77, 49, 35, 21, 14, 7]) == True\n assert candidate(nums = [23, 46, 69, 92, 115]) == True\n assert candidate(nums = [101, 202, 303, 404, 505]) == True\n assert candidate(nums = [102, 68, 34, 17, 51, 85]) == True\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117]) == True\n assert candidate(nums = [100, 105, 140, 210, 70]) == True\n assert candidate(nums = [11, 22, 33, 44, 55, 66]) == True\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153]) == True\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384]) == True\n assert candidate(nums = [1000, 500, 250, 125, 2000, 10000, 2500]) == True\n assert candidate(nums = [30, 45, 60, 75, 90, 105, 120]) == True\n assert candidate(nums = [12, 18, 24, 30, 36, 42]) == True\n assert candidate(nums = [25, 45, 65, 85, 105]) == True\n assert candidate(nums = [100, 200, 150, 300, 250]) == True\n assert candidate(nums = [14, 28, 42, 56, 70]) == True\n assert candidate(nums = [81, 135, 225, 315, 405, 525, 675]) == True\n assert candidate(nums = [121, 132, 220, 110, 55]) == True\n", "comparison": "exact"}, "public_tests": ["[7,21,3]", "[5,2,6,2]", "[10,5,9,3,15]"], "hints": ["Can we build a graph with all the prime numbers and the original array?", "We can use union-find to determine which indices are connected (i.e., which indices can be swapped)."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().gcdSort", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:40+00:00", "tests_total": 168, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "math", "union-find", "sorting", "number-theory", "prime-factorization", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function gcdSort($nums) {", "container": "Solution", "callable": "gcdSort", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2000, "task_id": "reverse-prefix-of-word", "difficulty": "Easy", "problem_description": "Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.\n\n- For example, if word = \"abcdefd\" and ch = \"d\", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be \"dcbaefd\".\n\nReturn the resulting string.\n\nExample 1:\n\nInput: word = \"abcdefd\", ch = \"d\"\nOutput: \"dcbaefd\"\nExplanation: The first occurrence of \"d\" is at index 3.\nReverse the part of word from 0 to 3 (inclusive), the resulting string is \"dcbaefd\".\n\nExample 2:\n\nInput: word = \"xyxzxe\", ch = \"z\"\nOutput: \"zxyxxe\"\nExplanation: The first and only occurrence of \"z\" is at index 3.\nReverse the part of word from 0 to 3 (inclusive), the resulting string is \"zxyxxe\".\n\nExample 3:\n\nInput: word = \"abcd\", ch = \"z\"\nOutput: \"abcd\"\nExplanation: \"z\" does not exist in word.\nYou should not do any reverse operation, the resulting string is \"abcd\".\n\nConstraints:\n\n- 1 <= word.length <= 250\n- word consists of lowercase English letters.\n- ch is a lowercase English letter.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"abcdef\",ch = \"f\") == \"fedcba\"\n assert candidate(word = \"madam\",ch = \"d\") == \"damam\"\n assert candidate(word = \"abcdefd\",ch = \"d\") == \"dcbaefd\"\n assert candidate(word = \"abcd\",ch = \"z\") == \"abcd\"\n assert candidate(word = \"a\",ch = \"a\") == \"a\"\n assert candidate(word = \"python\",ch = \"y\") == \"ypthon\"\n assert candidate(word = \"operation\",ch = \"p\") == \"poeration\"\n assert candidate(word = \"xyxzxe\",ch = \"z\") == \"zxyxxe\"\n assert candidate(word = \"segment\",ch = \"t\") == \"tnemges\"\n assert candidate(word = \"hello\",ch = \"l\") == \"lehlo\"\n assert candidate(word = \"racecar\",ch = \"e\") == \"ecarcar\"\n assert candidate(word = \"abcdef\",ch = \"g\") == \"abcdef\"\n assert candidate(word = \"example\",ch = \"m\") == \"maxeple\"\n assert candidate(word = \"reverse\",ch = \"r\") == \"reverse\"\n assert candidate(word = \"abcdef\",ch = \"a\") == \"abcdef\"\n assert candidate(word = \"supercalifragilisticexpialidocious\",ch = \"x\") == \"xecitsiligarfilacrepuspialidocious\"\n assert candidate(word = \"abracadabra\",ch = \"r\") == \"rbaacadabra\"\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\",ch = \"a\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(word = \"unbelievable\",ch = \"e\") == \"ebnulievable\"\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",ch = \"m\") == \"mlkjihgfedcbanopqrstuvwxyz\"\n assert candidate(word = \"supercalifragilisticexpialidocious\",ch = \"c\") == \"crepusalifragilisticexpialidocious\"\n assert candidate(word = \"interview\",ch = \"w\") == \"weivretni\"\n assert candidate(word = \"unpredictable\",ch = \"d\") == \"derpnuictable\"\n assert candidate(word = \"beautifulization\",ch = \"z\") == \"zilufituaebation\"\n assert candidate(word = \"characterization\",ch = \"c\") == \"characterization\"\n assert candidate(word = \"communication\",ch = \"m\") == \"mocmunication\"\n assert candidate(word = \"reversethispart\",ch = \"e\") == \"erversethispart\"\n assert candidate(word = \"reinforce\",ch = \"e\") == \"erinforce\"\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\",ch = \"q\") == \"qrstuvwxyzponmlkjihgfedcba\"\n assert candidate(word = \"unbelievable\",ch = \"l\") == \"lebnuievable\"\n assert candidate(word = \"nothingtoreverse\",ch = \"x\") == \"nothingtoreverse\"\n assert candidate(word = \"characterization\",ch = \"a\") == \"ahcracterization\"\n assert candidate(word = \"quickbrownfox\",ch = \"o\") == \"orbkciuqwnfox\"\n assert candidate(word = \"banana\",ch = \"n\") == \"nabana\"\n assert candidate(word = \"qwertyuiop\",ch = \"p\") == \"poiuytrewq\"\n assert candidate(word = \"qwertyuiop\",ch = \"q\") == \"qwertyuiop\"\n assert candidate(word = \"boundary\",ch = \"d\") == \"dnuobary\"\n assert candidate(word = \"continuous\",ch = \"s\") == \"suounitnoc\"\n assert candidate(word = \"interoperability\",ch = \"i\") == \"interoperability\"\n assert candidate(word = \"aaaaaa\",ch = \"a\") == \"aaaaaa\"\n assert candidate(word = \"quizzically\",ch = \"q\") == \"quizzically\"\n assert candidate(word = \"congratulations\",ch = \"g\") == \"gnocratulations\"\n assert candidate(word = \"aabbccddeeff\",ch = \"f\") == \"feeddccbbaaf\"\n assert candidate(word = \"zyxwvutsrqponmlkjihgfedcba\",ch = \"m\") == \"mnopqrstuvwxyzlkjihgfedcba\"\n assert candidate(word = \"concatenation\",ch = \"c\") == \"concatenation\"\n assert candidate(word = \"implementation\",ch = \"i\") == \"implementation\"\n assert candidate(word = \"establishment\",ch = \"b\") == \"batselishment\"\n assert candidate(word = \"abcdefghijkllllllllllllllllllllllllllllllllllllllllllllllll\",ch = \"l\") == \"lkjihgfedcballlllllllllllllllllllllllllllllllllllllllllllll\"\n assert candidate(word = \"abcdefg\",ch = \"g\") == \"gfedcba\"\n assert candidate(word = \"development\",ch = \"p\") == \"polevedment\"\n assert candidate(word = \"unfortunately\",ch = \"r\") == \"rofnutunately\"\n assert candidate(word = \"challenges\",ch = \"e\") == \"ellahcnges\"\n assert candidate(word = \"thisisaverylongwordthatneedstoreversed\",ch = \"n\") == \"nolyrevasisihtgwordthatneedstoreversed\"\n assert candidate(word = \"interview\",ch = \"e\") == \"etnirview\"\n assert candidate(word = \"abcdeffedcba\",ch = \"f\") == \"fedcbafedcba\"\n assert candidate(word = \"classification\",ch = \"l\") == \"lcassification\"\n assert candidate(word = \"thisisateststring\",ch = \"t\") == \"thisisateststring\"\n assert candidate(word = \"mississippi\",ch = \"i\") == \"imssissippi\"\n assert candidate(word = \"unbelievable\",ch = \"b\") == \"bnuelievable\"\n assert candidate(word = \"mississippi\",ch = \"s\") == \"simsissippi\"\n assert candidate(word = \"congratulations\",ch = \"l\") == \"lutargnocations\"\n assert candidate(word = \"synchronous\",ch = \"c\") == \"cnyshronous\"\n assert candidate(word = \"algorithm\",ch = \"l\") == \"lagorithm\"\n assert candidate(word = \"abracadabra\",ch = \"c\") == \"carbaadabra\"\n assert candidate(word = \"zzzzzzzzzzzzzzzz\",ch = \"z\") == \"zzzzzzzzzzzzzzzz\"\n assert candidate(word = \"development\",ch = \"l\") == \"levedopment\"\n assert candidate(word = \"identification\",ch = \"i\") == \"identification\"\n assert candidate(word = \"beautiful\",ch = \"t\") == \"tuaebiful\"\n assert candidate(word = \"asdfghjklzxcvbnm\",ch = \"m\") == \"mnbvcxzlkjhgfdsa\"\n assert candidate(word = \"representation\",ch = \"r\") == \"representation\"\n assert candidate(word = \"congratulations\",ch = \"t\") == \"targnoculations\"\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",ch = \"q\") == \"qppoonnmmllkkjjiihhggffeeddccbbaaqrrssttuuvvwwxxyyzz\"\n assert candidate(word = \"sequence\",ch = \"q\") == \"qesuence\"\n assert candidate(word = \"environment\",ch = \"v\") == \"vneironment\"\n assert candidate(word = \"algorithm\",ch = \"g\") == \"glaorithm\"\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",ch = \"z\") == \"zyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaaz\"\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\",ch = \"z\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(word = \"abcdefghij\",ch = \"e\") == \"edcbafghij\"\n assert candidate(word = \"solution\",ch = \"u\") == \"ulostion\"\n assert candidate(word = \"environment\",ch = \"n\") == \"nevironment\"\n assert candidate(word = \"environmentally\",ch = \"v\") == \"vneironmentally\"\n assert candidate(word = \"algorithm\",ch = \"o\") == \"oglarithm\"\n assert candidate(word = \"single\",ch = \"l\") == \"lgnise\"\n assert candidate(word = \"supercalifragilisticexpialidocious\",ch = \"f\") == \"filacrepusragilisticexpialidocious\"\n assert candidate(word = \"abcdefg\",ch = \"z\") == \"abcdefg\"\n assert candidate(word = \"double\",ch = \"x\") == \"double\"\n assert candidate(word = \"algorithms\",ch = \"a\") == \"algorithms\"\n assert candidate(word = \"algorithm\",ch = \"r\") == \"roglaithm\"\n assert candidate(word = \"characterization\",ch = \"h\") == \"hcaracterization\"\n assert candidate(word = \"xyzzyx\",ch = \"z\") == \"zyxzyx\"\n assert candidate(word = \"subsequence\",ch = \"q\") == \"qesbusuence\"\n assert candidate(word = \"reversal\",ch = \"a\") == \"asreverl\"\n assert candidate(word = \"a\",ch = \"b\") == \"a\"\n assert candidate(word = \"visualization\",ch = \"i\") == \"ivsualization\"\n assert candidate(word = \"incomprehensible\",ch = \"h\") == \"herpmocniensible\"\n assert candidate(word = \"hellothere\",ch = \"e\") == \"ehllothere\"\n assert candidate(word = \"reverseprefix\",ch = \"r\") == \"reverseprefix\"\n assert candidate(word = \"pneumonoultramicroscopicsilicovolcanoconiosis\",ch = \"o\") == \"omuenpnoultramicroscopicsilicovolcanoconiosis\"\n assert candidate(word = \"uniquecharacters\",ch = \"u\") == \"uniquecharacters\"\n assert candidate(word = \"alphabetization\",ch = \"b\") == \"bahplaetization\"\n assert candidate(word = \"standardization\",ch = \"i\") == \"idradnatszation\"\n assert candidate(word = \"automation\",ch = \"o\") == \"otuamation\"\n assert candidate(word = \"mnopqr\",ch = \"r\") == \"rqponm\"\n assert candidate(word = \"pronunciation\",ch = \"u\") == \"unorpnciation\"\n assert candidate(word = \"abacaxa\",ch = \"a\") == \"abacaxa\"\n assert candidate(word = \"reversal\",ch = \"r\") == \"reversal\"\n assert candidate(word = \"congratulations\",ch = \"u\") == \"utargnoclations\"\n assert candidate(word = \"performance\",ch = \"f\") == \"frepormance\"\n assert candidate(word = \"nevertheless\",ch = \"n\") == \"nevertheless\"\n assert candidate(word = \"multifaceted\",ch = \"f\") == \"fitlumaceted\"\n assert candidate(word = \"reversal\",ch = \"v\") == \"verersal\"\n assert candidate(word = \"thisisaverylongwordthatshouldtestthelimitsofthefunction\",ch = \"t\") == \"thisisaverylongwordthatshouldtestthelimitsofthefunction\"\n assert candidate(word = \"sophistication\",ch = \"s\") == \"sophistication\"\n assert candidate(word = \"xylophone\",ch = \"o\") == \"olyxphone\"\n assert candidate(word = \"visualization\",ch = \"z\") == \"zilausivation\"\n assert candidate(word = \"pneumonoultramicroscopicsilicovolcanoconiosis\",ch = \"u\") == \"uenpmonoultramicroscopicsilicovolcanoconiosis\"\n assert candidate(word = \"xyzxyzxyz\",ch = \"x\") == \"xyzxyzxyz\"\n assert candidate(word = \"challenge\",ch = \"e\") == \"ellahcnge\"\n assert candidate(word = \"perseverance\",ch = \"v\") == \"vesreperance\"\n assert candidate(word = \"abcdefghijk\",ch = \"i\") == \"ihgfedcbajk\"\n assert candidate(word = \"mississippi\",ch = \"p\") == \"pississimpi\"\n assert candidate(word = \"programming\",ch = \"g\") == \"gorpramming\"\n assert candidate(word = \"responsibilities\",ch = \"s\") == \"serponsibilities\"\n assert candidate(word = \"synchronization\",ch = \"n\") == \"nyschronization\"\n assert candidate(word = \"floccinaucinihilipilification\",ch = \"f\") == \"floccinaucinihilipilification\"\n assert candidate(word = \"operationalization\",ch = \"o\") == \"operationalization\"\n assert candidate(word = \"specializations\",ch = \"a\") == \"aicepslizations\"\n assert candidate(word = \"optimization\",ch = \"t\") == \"tpoimization\"\n assert candidate(word = \"abcdefghijk\",ch = \"h\") == \"hgfedcbaijk\"\n assert candidate(word = \"xylophone\",ch = \"p\") == \"polyxhone\"\n assert candidate(word = \"hellohellohello\",ch = \"l\") == \"lehlohellohello\"\n assert candidate(word = \"concatenation\",ch = \"n\") == \"noccatenation\"\n", "comparison": "exact"}, "public_tests": ["\"abcdefd\"\n\"d\"", "\"xyxzxe\"\n\"z\"", "\"abcd\"\n\"z\""], "hints": ["Find the first index where ch appears.", "Find a way to reverse a substring of word."], "metadata": {"canonical_parameter_names": ["word", "ch"], "leetcode_dataset_entry_point": "Solution().reversePrefix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:44+00:00", "tests_total": 133, "tests_dropped": 1, "flags": [], "topic_tags": ["two-pointers", "string", "stack"]}, "language": "php", "interface": {"raw_signature": "function reversePrefix($word, $ch) {", "container": "Solution", "callable": "reversePrefix", "parameters": [{"name": "word", "type": "String"}, {"name": "ch", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2001, "task_id": "number-of-pairs-of-interchangeable-rectangles", "difficulty": "Medium", "problem_description": "You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [width_i, height_i] denotes the width and height of the i^th rectangle.\n\nTwo rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles are interchangeable if width_i/height_i == width_j/height_j (using decimal division, not integer division).\n\nReturn the number of pairs of interchangeable rectangles in rectangles.\n\nExample 1:\n\nInput: rectangles = [[4,8],[3,6],[10,20],[15,30]]\nOutput: 6\nExplanation: The following are the interchangeable pairs of rectangles by index (0-indexed):\n- Rectangle 0 with rectangle 1: 4/8 == 3/6.\n- Rectangle 0 with rectangle 2: 4/8 == 10/20.\n- Rectangle 0 with rectangle 3: 4/8 == 15/30.\n- Rectangle 1 with rectangle 2: 3/6 == 10/20.\n- Rectangle 1 with rectangle 3: 3/6 == 15/30.\n- Rectangle 2 with rectangle 3: 10/20 == 15/30.\n\nExample 2:\n\nInput: rectangles = [[4,5],[7,8]]\nOutput: 0\nExplanation: There are no interchangeable pairs of rectangles.\n\nConstraints:\n\n- n == rectangles.length\n- 1 <= n <= 10^5\n- rectangles[i].length == 2\n- 1 <= width_i, height_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 10\n assert candidate(rectangles = [[5, 10], [10, 20], [20, 40], [40, 80]]) == 6\n assert candidate(rectangles = [[2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(rectangles = [[4, 5], [7, 8]]) == 0\n assert candidate(rectangles = [[5, 10], [10, 20], [15, 30], [20, 40], [25, 50]]) == 10\n assert candidate(rectangles = [[5, 10], [10, 20], [15, 30], [20, 40]]) == 6\n assert candidate(rectangles = [[4, 8], [3, 6], [10, 20], [15, 30]]) == 6\n assert candidate(rectangles = [[1, 2], [2, 4], [3, 6], [4, 8]]) == 6\n assert candidate(rectangles = [[2, 3], [3, 4], [4, 6], [6, 9]]) == 3\n assert candidate(rectangles = [[2, 3], [3, 2], [6, 9], [9, 6]]) == 2\n assert candidate(rectangles = [[10, 5], [5, 10], [20, 10], [10, 20], [30, 15]]) == 4\n assert candidate(rectangles = [[1, 2], [2, 4], [4, 8], [8, 16]]) == 6\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 45\n assert candidate(rectangles = [[2, 4], [4, 8], [8, 16], [16, 32], [32, 64], [64, 128]]) == 15\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]]) == 66\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11]]) == 55\n assert candidate(rectangles = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]]) == 45\n assert candidate(rectangles = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15]]) == 10\n assert candidate(rectangles = [[5, 10], [10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90], [50, 100]]) == 45\n assert candidate(rectangles = [[7, 10], [14, 20], [21, 30], [28, 40], [35, 50], [42, 60], [49, 70], [56, 80], [63, 90], [70, 100], [77, 110], [84, 120]]) == 66\n assert candidate(rectangles = [[10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90]]) == 28\n assert candidate(rectangles = [[100, 200], [150, 300], [200, 400], [250, 500], [300, 600], [350, 700], [400, 800], [450, 900], [500, 1000]]) == 36\n assert candidate(rectangles = [[2, 5], [4, 10], [6, 15], [8, 20], [10, 25], [12, 30], [14, 35], [16, 40], [18, 45], [20, 50]]) == 45\n assert candidate(rectangles = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20], [11, 22], [12, 24]]) == 66\n assert candidate(rectangles = [[100, 200], [200, 400], [300, 600], [400, 800], [500, 1000], [600, 1200], [700, 1400], [800, 1600], [900, 1800], [1000, 2000]]) == 45\n assert candidate(rectangles = [[3, 9], [6, 18], [9, 27], [12, 36], [15, 45], [18, 54], [21, 63], [24, 72], [27, 81], [30, 90]]) == 45\n assert candidate(rectangles = [[1000, 2000], [1500, 3000], [2000, 4000], [2500, 5000], [3000, 6000], [3500, 7000], [4000, 8000], [4500, 9000], [5000, 10000]]) == 36\n assert candidate(rectangles = [[1, 1], [1, 2], [2, 1], [1, 3], [3, 1], [2, 3], [3, 2], [1, 4], [4, 1], [2, 4], [4, 2], [3, 4], [4, 3]]) == 2\n assert candidate(rectangles = [[10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90], [50, 100]]) == 36\n assert candidate(rectangles = [[10, 5], [5, 10], [2, 1], [1, 2], [4, 2], [2, 4], [8, 4], [4, 8], [16, 8], [8, 16]]) == 20\n assert candidate(rectangles = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15], [6, 18], [7, 21], [8, 24], [9, 27], [10, 30], [11, 33], [12, 36], [13, 39]]) == 78\n assert candidate(rectangles = [[3, 4], [6, 8], [9, 12], [12, 16], [15, 20], [18, 24], [21, 28], [24, 32]]) == 28\n assert candidate(rectangles = [[5, 15], [10, 30], [15, 45], [20, 60], [25, 75]]) == 10\n assert candidate(rectangles = [[3, 9], [9, 27], [27, 81], [81, 243], [243, 729]]) == 10\n assert candidate(rectangles = [[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]]) == 105\n assert candidate(rectangles = [[10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90], [50, 100], [55, 110]]) == 45\n assert candidate(rectangles = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == 0\n assert candidate(rectangles = [[1, 2], [2, 1], [1, 3], [3, 1], [2, 3], [3, 2], [1, 4], [4, 1], [2, 4], [4, 2]]) == 2\n assert candidate(rectangles = [[5, 15], [10, 30], [15, 45], [20, 60], [25, 75], [30, 90], [35, 105], [40, 120]]) == 28\n assert candidate(rectangles = [[1, 100000], [2, 50000], [3, 33333], [4, 25000], [5, 20000], [6, 16667], [7, 14286], [8, 12500], [9, 11111], [10, 10000]]) == 0\n assert candidate(rectangles = [[2, 3], [4, 6], [6, 9], [8, 12], [10, 15], [12, 18], [14, 21], [16, 24], [18, 27], [20, 30]]) == 45\n assert candidate(rectangles = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15], [6, 18], [7, 21], [8, 24], [9, 27], [10, 30]]) == 45\n assert candidate(rectangles = [[2, 4], [4, 8], [8, 16], [16, 32], [32, 64], [64, 128], [128, 256], [256, 512], [512, 1024], [1024, 2048]]) == 45\n assert candidate(rectangles = [[5, 4], [10, 8], [15, 12], [20, 16], [25, 20], [30, 24], [35, 28], [40, 32], [45, 36], [50, 40]]) == 45\n assert candidate(rectangles = [[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]]) == 105\n assert candidate(rectangles = [[11, 22], [22, 44], [33, 66], [44, 88], [55, 110], [66, 132], [77, 154], [88, 176]]) == 28\n assert candidate(rectangles = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]]) == 45\n assert candidate(rectangles = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8], [45, 9], [50, 10]]) == 45\n assert candidate(rectangles = [[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]]) == 105\n assert candidate(rectangles = [[1, 4], [2, 8], [3, 12], [4, 16], [5, 20], [6, 24], [7, 28], [8, 32], [9, 36], [10, 40]]) == 45\n assert candidate(rectangles = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 0\n assert candidate(rectangles = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]]) == 45\n assert candidate(rectangles = [[3, 4], [6, 8], [9, 12], [12, 16], [15, 20], [18, 24], [21, 28], [24, 32], [27, 36], [30, 40]]) == 45\n assert candidate(rectangles = [[3, 5], [6, 10], [9, 15], [12, 20], [15, 25], [18, 30]]) == 15\n assert candidate(rectangles = [[8, 12], [16, 24], [24, 36], [32, 48], [40, 60], [48, 72], [56, 84], [64, 96]]) == 28\n assert candidate(rectangles = [[100, 200], [200, 400], [300, 600], [400, 800], [500, 1000], [600, 1200]]) == 15\n assert candidate(rectangles = [[2, 1], [4, 2], [6, 3], [8, 4], [10, 5], [12, 6], [14, 7], [16, 8], [18, 9], [20, 10]]) == 45\n assert candidate(rectangles = [[100, 200], [200, 400], [300, 600], [400, 800], [500, 1000]]) == 10\n assert candidate(rectangles = [[3, 7], [6, 14], [9, 21], [12, 28], [15, 35], [18, 42], [21, 49], [24, 56], [27, 63], [30, 70]]) == 45\n assert candidate(rectangles = [[3, 9], [1, 3], [2, 6], [4, 12], [5, 15], [6, 18], [7, 21], [8, 24]]) == 28\n assert candidate(rectangles = [[7, 14], [14, 28], [28, 56], [56, 112], [112, 224], [224, 448]]) == 15\n assert candidate(rectangles = [[3, 5], [6, 10], [9, 15], [12, 20], [15, 25], [18, 30], [21, 35], [24, 40], [27, 45], [30, 50]]) == 45\n assert candidate(rectangles = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15], [6, 18], [7, 21]]) == 21\n assert candidate(rectangles = [[7, 14], [14, 28], [21, 42], [28, 56], [35, 70], [42, 84]]) == 15\n assert candidate(rectangles = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 0\n assert candidate(rectangles = [[1, 1], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 0\n assert candidate(rectangles = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11]]) == 0\n assert candidate(rectangles = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == 45\n assert candidate(rectangles = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9], [1000, 10]]) == 45\n assert candidate(rectangles = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20]]) == 45\n assert candidate(rectangles = [[100000, 1], [1, 100000], [50000, 2], [2, 50000], [1, 1], [1, 2], [2, 1]]) == 0\n assert candidate(rectangles = [[1, 5], [2, 10], [3, 15], [4, 20], [5, 25], [6, 30], [7, 35], [8, 40], [9, 45], [10, 50], [11, 55], [12, 60]]) == 66\n assert candidate(rectangles = [[7, 14], [14, 28], [21, 42], [28, 56], [35, 70], [42, 84], [49, 98]]) == 21\n assert candidate(rectangles = [[3, 1], [6, 2], [9, 3], [12, 4], [15, 5], [18, 6], [21, 7], [24, 8], [27, 9], [30, 10]]) == 45\n assert candidate(rectangles = [[3, 4], [6, 8], [9, 12], [12, 16], [15, 20], [18, 24], [21, 28]]) == 21\n assert candidate(rectangles = [[1, 2], [2, 4], [4, 8], [8, 16], [16, 32], [32, 64], [64, 128], [128, 256], [256, 512], [512, 1024]]) == 45\n assert candidate(rectangles = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15], [6, 18], [7, 21], [8, 24], [9, 27], [10, 30], [11, 33], [12, 36]]) == 66\n assert candidate(rectangles = [[5, 10], [10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80], [45, 90], [50, 100], [55, 110], [60, 120]]) == 66\n assert candidate(rectangles = [[7, 14], [14, 28], [21, 42], [28, 56], [35, 70], [42, 84], [49, 98], [56, 112]]) == 28\n assert candidate(rectangles = [[1, 2], [1, 3], [2, 4], [2, 6], [3, 6], [3, 9], [4, 8], [4, 12], [5, 10], [5, 15]]) == 20\n assert candidate(rectangles = [[5, 10], [15, 30], [25, 50], [35, 70], [45, 90], [55, 110], [65, 130], [75, 150], [85, 170], [95, 190]]) == 45\n assert candidate(rectangles = [[5, 7], [10, 14], [15, 21], [20, 28], [25, 35], [30, 42], [35, 49], [40, 56]]) == 28\n", "comparison": "exact"}, "public_tests": ["[[4,8],[3,6],[10,20],[15,30]]", "[[4,5],[7,8]]"], "hints": ["Store the rectangle height and width ratio in a hashmap.", "Traverse the ratios, and for each ratio, use the frequency of the ratio to add to the total pair count."], "metadata": {"canonical_parameter_names": ["rectangles"], "leetcode_dataset_entry_point": "Solution().interchangeableRectangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:47+00:00", "tests_total": 84, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function interchangeableRectangles($rectangles) {", "container": "Solution", "callable": "interchangeableRectangles", "parameters": [{"name": "rectangles", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2002, "task_id": "maximum-product-of-the-length-of-two-palindromic-subsequences", "difficulty": "Medium", "problem_description": "Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.\n\nReturn the maximum possible product of the lengths of the two palindromic subsequences.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is palindromic if it reads the same forward and backward.\n\nExample 1:\n\nInput: s = \"leetcodecom\"\nOutput: 9\nExplanation: An optimal solution is to choose \"ete\" for the 1^st subsequence and \"cdc\" for the 2^nd subsequence.\nThe product of their lengths is: 3 * 3 = 9.\n\nExample 2:\n\nInput: s = \"bb\"\nOutput: 1\nExplanation: An optimal solution is to choose \"b\" (the first character) for the 1^st subsequence and \"b\" (the second character) for the 2^nd subsequence.\nThe product of their lengths is: 1 * 1 = 1.\n\nExample 3:\n\nInput: s = \"accbcaxxcxx\"\nOutput: 25\nExplanation: An optimal solution is to choose \"accca\" for the 1^st subsequence and \"xxcxx\" for the 2^nd subsequence.\nThe product of their lengths is: 5 * 5 = 25.\n\nConstraints:\n\n- 2 <= s.length <= 12\n- s consists of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzyx\") == 6\n assert candidate(s = \"aabbcc\") == 4\n assert candidate(s = \"aaaa\") == 4\n assert candidate(s = \"accbcaxxcxx\") == 25\n assert candidate(s = \"madam\") == 6\n assert candidate(s = \"noon\") == 4\n assert candidate(s = \"racecar\") == 12\n assert candidate(s = \"deified\") == 12\n assert candidate(s = \"noonhighnoon\") == 35\n assert candidate(s = \"abcdcba\") == 12\n assert candidate(s = \"abacaba\") == 12\n assert candidate(s = \"level\") == 6\n assert candidate(s = \"abcdedcba\") == 20\n assert candidate(s = \"abcde\") == 1\n assert candidate(s = \"rotor\") == 6\n assert candidate(s = \"leetcodecom\") == 9\n assert candidate(s = \"bb\") == 1\n assert candidate(s = \"refer\") == 6\n assert candidate(s = \"aaabbbccc\") == 9\n assert candidate(s = \"xxyyzzxxyyzz\") == 36\n assert candidate(s = \"noonnoonnoon\") == 36\n assert candidate(s = \"repaper\") == 12\n assert candidate(s = \"abbaabbaabba\") == 36\n assert candidate(s = \"xyzzyxzyxz\") == 25\n assert candidate(s = \"aababababab\") == 30\n assert candidate(s = \"xyzyzyzyzyzy\") == 30\n assert candidate(s = \"aabbbbaa\") == 16\n assert candidate(s = \"abababa\") == 12\n assert candidate(s = \"babadab\") == 9\n assert candidate(s = \"referrefer\") == 25\n assert candidate(s = \"rotorrotor\") == 25\n assert candidate(s = \"abracadabra\") == 25\n assert candidate(s = \"abacdfgdcaba\") == 35\n assert candidate(s = \"mammam\") == 9\n assert candidate(s = \"abccbaabcba\") == 30\n assert candidate(s = \"redderredder\") == 36\n assert candidate(s = \"redivider\") == 20\n assert candidate(s = \"racecarabc\") == 15\n assert candidate(s = \"noonnoon\") == 16\n assert candidate(s = \"abcdzdcba\") == 20\n assert candidate(s = \"levelup\") == 6\n assert candidate(s = \"rotorositor\") == 25\n assert candidate(s = \"zzzzzzzzzzzz\") == 36\n assert candidate(s = \"xyzyxzyzyx\") == 25\n assert candidate(s = \"deeee\") == 4\n assert candidate(s = \"abcbaabcba\") == 25\n assert candidate(s = \"deeeevee\") == 12\n assert candidate(s = \"aaabaaa\") == 12\n assert candidate(s = \"aabbccddeeff\") == 4\n assert candidate(s = \"levellevel\") == 25\n assert candidate(s = \"madamimadam\") == 30\n assert candidate(s = \"mississippi\") == 24\n assert candidate(s = \"xyzzazxy\") == 15\n assert candidate(s = \"xyxxyxyxyxyx\") == 35\n assert candidate(s = \"programming\") == 12\n assert candidate(s = \"zyxzyxzyxzyx\") == 36\n assert candidate(s = \"zzzzzyzzzz\") == 25\n assert candidate(s = \"aabbaabbaa\") == 25\n assert candidate(s = \"xyzabcdcba\") == 12\n assert candidate(s = \"optimization\") == 15\n assert candidate(s = \"abccbaabc\") == 15\n", "comparison": "exact"}, "public_tests": ["\"leetcodecom\"", "\"bb\"", "\"accbcaxxcxx\""], "hints": ["Could you generate all possible pairs of disjoint subsequences?", "Could you find the maximum length palindrome in each subsequence for a pair of disjoint subsequences?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().maxProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:49+00:00", "tests_total": 81, "tests_dropped": 20, "flags": ["has_images"], "topic_tags": ["string", "dynamic-programming", "backtracking", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function maxProduct($s) {", "container": "Solution", "callable": "maxProduct", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2003, "task_id": "smallest-missing-genetic-value-in-each-subtree", "difficulty": "Hard", "problem_description": "There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1.\n\nThere are 10^5 genetic values, each represented by an integer in the inclusive range [1, 10^5]. You are given a 0-indexed integer array nums, where nums[i] is a distinct genetic value for node i.\n\nReturn an array ans of length n where ans[i] is the smallest genetic value that is missing from the subtree rooted at node i.\n\nThe subtree rooted at a node x contains node x and all of its descendant nodes.\n\nExample 1:\n\nInput: parents = [-1,0,0,2], nums = [1,2,3,4]\nOutput: [5,1,1,1]\nExplanation: The answer for each subtree is calculated as follows:\n- 0: The subtree contains nodes [0,1,2,3] with values [1,2,3,4]. 5 is the smallest missing value.\n- 1: The subtree contains only node 1 with value 2. 1 is the smallest missing value.\n- 2: The subtree contains nodes [2,3] with values [3,4]. 1 is the smallest missing value.\n- 3: The subtree contains only node 3 with value 4. 1 is the smallest missing value.\n\nExample 2:\n\nInput: parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3]\nOutput: [7,1,1,4,2,1]\nExplanation: The answer for each subtree is calculated as follows:\n- 0: The subtree contains nodes [0,1,2,3,4,5] with values [5,4,6,2,1,3]. 7 is the smallest missing value.\n- 1: The subtree contains nodes [1,2] with values [4,6]. 1 is the smallest missing value.\n- 2: The subtree contains only node 2 with value 6. 1 is the smallest missing value.\n- 3: The subtree contains nodes [3,4,5] with values [2,1,3]. 4 is the smallest missing value.\n- 4: The subtree contains only node 4 with value 1. 2 is the smallest missing value.\n- 5: The subtree contains only node 5 with value 3. 1 is the smallest missing value.\n\nExample 3:\n\nInput: parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8]\nOutput: [1,1,1,1,1,1,1]\nExplanation: The value 1 is missing from all the subtrees.\n\nConstraints:\n\n- n == parents.length == nums.length\n- 2 <= n <= 10^5\n- 0 <= parents[i] <= n - 1 for i != 0\n- parents[0] == -1\n- parents represents a valid tree.\n- 1 <= nums[i] <= 10^5\n- Each nums[i] is distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(parents = [-1, 0, 0, 2],nums = [1, 2, 3, 4]) == [5, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 0, 3, 3],nums = [5, 4, 6, 2, 1, 3]) == [7, 1, 1, 4, 2, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2],nums = [1, 2, 3, 4, 5, 6, 7]) == [8, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 2, 3, 0, 2, 4, 1],nums = [2, 3, 4, 5, 6, 7, 8]) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 2, 2, 3, 3],nums = [7, 1, 3, 2, 6, 5, 4]) == [8, 2, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],nums = [5, 1, 12, 13, 1, 2, 6, 7, 8, 9, 3, 4, 10, 11, 14, 15]) == [16, 5, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7],nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3],nums = [10, 1, 2, 9, 8, 7, 6, 5, 4]) == [3, 2, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],nums = [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, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 0, 6, 7, 8],nums = [100, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [10, 6, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [11, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4],nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == [12, 4, 1, 1, 2, 1, 1, 1, 1, 2, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [11, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums = [5, 1, 3, 7, 9, 2, 6, 4, 8, 10, 11]) == [12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],nums = [2, 1, 14, 13, 8, 15, 6, 9, 4, 10, 5, 11, 3, 12, 7, 16]) == [17, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3],nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 3, 1, 3, 1, 1, 1, 1, 2]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [23, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],nums = [20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [21, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4],nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 101]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums = [10, 20, 30, 40, 1, 11, 21, 31, 41, 2, 12, 22, 32, 42, 3, 13, 23, 33, 4, 14, 24, 29]) == [5, 5, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [21, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],nums = [1, 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]\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums = [40, 30, 20, 10, 35, 31, 25, 21, 34, 32, 24, 22, 33, 26, 23, 27, 36, 28, 29, 37, 38, 39]) == [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(parents = [-1, 0, 0, 0, 3, 3, 4, 4],nums = [1, 2, 3, 4, 5, 6, 7, 8]) == [9, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums = [10, 9, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 17, 18, 19, 20]) == [11, 10, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],nums = [3, 1, 2, 5, 7, 8, 10, 12, 13, 9, 4, 6, 11, 14, 15, 16, 17, 18, 19, 20, 21]) == [22, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13]) == [14, 4, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [21, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == [12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],nums = [13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [14, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 22]) == [23, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3],nums = [8, 9, 10, 1, 2, 3, 4, 5, 6]) == [7, 3, 1, 2, 1, 1, 1, 1, 1]\n", "comparison": "exact"}, "public_tests": ["[-1,0,0,2]\n[1,2,3,4]", "[-1,0,1,0,3,3]\n[5,4,6,2,1,3]", "[-1,2,3,0,2,4,1]\n[2,3,4,5,6,7,8]"], "hints": ["If the subtree doesn't contain 1, then the missing value will always be 1.", "What data structure allows us to dynamically update the values that are currently not present?"], "metadata": {"canonical_parameter_names": ["parents", "nums"], "leetcode_dataset_entry_point": "Solution().smallestMissingValueSubtree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:52+00:00", "tests_total": 38, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "tree", "depth-first-search", "union-find"]}, "language": "php", "interface": {"raw_signature": "function smallestMissingValueSubtree($parents, $nums) {", "container": "Solution", "callable": "smallestMissingValueSubtree", "parameters": [{"name": "parents", "type": "Integer[]"}, {"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2006, "task_id": "count-number-of-pairs-with-absolute-difference-k", "difficulty": "Easy", "problem_description": "Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.\n\nThe value of |x| is defined as:\n\n- x if x >= 0.\n- -x if x < 0.\n\nExample 1:\n\nInput: nums = [1,2,2,1], k = 1\nOutput: 4\nExplanation: The pairs with an absolute difference of 1 are:\n- [1,2,2,1]\n- [1,2,2,1]\n- [1,2,2,1]\n- [1,2,2,1]\n\nExample 2:\n\nInput: nums = [1,3], k = 3\nOutput: 0\nExplanation: There are no pairs with an absolute difference of 3.\n\nExample 3:\n\nInput: nums = [3,2,1,5,4], k = 2\nOutput: 3\nExplanation: The pairs with an absolute difference of 2 are:\n- [3,2,1,5,4]\n- [3,2,1,5,4]\n- [3,2,1,5,4]\n\nConstraints:\n\n- 1 <= nums.length <= 200\n- 1 <= nums[i] <= 100\n- 1 <= k <= 99\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 1, 100, 1, 100],k = 99) == 6\n assert candidate(nums = [5, 4, 3, 2, 1],k = 4) == 1\n assert candidate(nums = [3, 2, 1, 5, 4],k = 2) == 3\n assert candidate(nums = [5, 1, 4, 1],k = 2) == 0\n assert candidate(nums = [1, 3],k = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],k = 20) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 4\n assert candidate(nums = [1, 2, 2, 1],k = 1) == 4\n assert candidate(nums = [100, 1, 100, 1],k = 99) == 4\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 4) == 32\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82],k = 9) == 9\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93],k = 99) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86],k = 1) == 14\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],k = 4) == 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) == 20\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 3, 6, 9, 12, 15],k = 3) == 22\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],k = 1) == 40\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57],k = 4) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50],k = 30) == 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 = 1) == 36\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43],k = 1) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 4\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 8) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50],k = 10) == 16\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 5, 15, 25, 35, 45],k = 10) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 4) == 13\n assert candidate(nums = [55, 45, 35, 25, 15, 5, 5, 15, 25, 35, 45],k = 10) == 18\n assert candidate(nums = [99, 100, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94],k = 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],k = 2) == 19\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],k = 2) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 9\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 9) == 1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 1) == 9\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],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 = 3) == 17\n assert candidate(nums = [99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9],k = 97) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1) == 14\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],k = 9) == 26\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30],k = 10) == 11\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 1) == 9\n assert candidate(nums = [50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55],k = 1) == 125\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 2) == 14\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 = 20) == 32\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85],k = 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],k = 5) == 15\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 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],k = 2) == 19\n assert candidate(nums = [10, 10, 10, 10, 11, 11, 12, 12, 13],k = 1) == 14\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33],k = 3) == 10\n assert candidate(nums = [10, 20, 30, 20, 10, 30, 20, 10, 30],k = 10) == 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 = 2) == 32\n assert candidate(nums = [90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40],k = 5) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 2) == 14\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85],k = 3) == 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],k = 1) == 19\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49],k = 2) == 24\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 1) == 16\n assert candidate(nums = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 9],k = 10) == 10\n assert candidate(nums = [10, 12, 15, 7, 5, 3, 10, 15],k = 5) == 7\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 = 9) == 11\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 9\n assert candidate(nums = [10, 10, 20, 20, 30, 30],k = 10) == 8\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 = 4) == 19\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 10) == 9\n assert candidate(nums = [100, 1, 100, 2, 100, 3, 100, 4, 100, 5],k = 99) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 5\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, 85, 89, 93, 97],k = 4) == 24\n assert candidate(nums = [8, 18, 28, 38, 48, 58, 68, 78, 88, 98],k = 10) == 9\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 = 1) == 36\n assert candidate(nums = [50, 60, 70, 80, 90, 50, 60, 70, 80, 90, 50, 60],k = 20) == 16\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50],k = 1) == 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],k = 1) == 29\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 1) == 32\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 2) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == 13\n assert candidate(nums = [50, 50, 50, 51, 51, 52, 52, 52, 53, 53],k = 1) == 18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 4) == 13\n assert candidate(nums = [5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15],k = 5) == 50\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 3) == 8\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 6\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91],k = 9) == 10\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],k = 1) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],k = 7) == 13\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100],k = 9) == 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, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 60\n", "comparison": "exact"}, "public_tests": ["[1,2,2,1]\n1", "[1,3]\n3", "[3,2,1,5,4]\n2"], "hints": ["Can we check every possible pair?", "Can we use a nested for loop to solve this problem?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countKDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:56+00:00", "tests_total": 106, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function countKDifference($nums, $k) {", "container": "Solution", "callable": "countKDifference", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2007, "task_id": "find-original-array-from-doubled-array", "difficulty": "Medium", "problem_description": "An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.\n\nGiven an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.\n\nExample 1:\n\nInput: changed = [1,3,4,2,6,8]\nOutput: [1,3,4]\nExplanation: One possible original array could be [1,3,4]:\n- Twice the value of 1 is 1 * 2 = 2.\n- Twice the value of 3 is 3 * 2 = 6.\n- Twice the value of 4 is 4 * 2 = 8.\nOther original arrays could be [4,3,1] or [3,1,4].\n\nExample 2:\n\nInput: changed = [6,3,0,1]\nOutput: []\nExplanation: changed is not a doubled array.\n\nExample 3:\n\nInput: changed = [1]\nOutput: []\nExplanation: changed is not a doubled array.\n\nConstraints:\n\n- 1 <= changed.length <= 10^5\n- 0 <= changed[i] <= 10^5\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(changed=[2, 1, 4, 2, 8, 4]), [1, 2, 4])\n assert answers_match(candidate(changed=[2, 4, 2, 4]), [2, 2])\n assert answers_match(candidate(changed=[1, 2, 3, 6, 9, 18]), [1, 3, 9])\n assert answers_match(candidate(changed=[8, 4, 2, 1, 16, 8, 4, 2]), [1, 2, 4, 8])\n assert answers_match(candidate(changed=[5, 3, 10, 0, 6, 9, 18, 15]), [])\n assert answers_match(candidate(changed=[0, 0, 0, 0]), [0, 0])\n assert answers_match(candidate(changed=[100, 200, 300, 400, 500, 1000]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 6, 8, 12, 16]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 6, 12, 24, 48, 96]), [1, 3, 12, 48])\n assert answers_match(candidate(changed=[5, 3, 10, 15, 2, 6]), [])\n assert answers_match(candidate(changed=[1, 3, 4, 2, 6, 8]), [1, 3, 4])\n assert answers_match(candidate(changed=[1, 2]), [1])\n assert answers_match(candidate(changed=[1]), [])\n assert answers_match(candidate(changed=[2, 1, 2, 4, 4, 8]), [1, 2, 4])\n assert answers_match(candidate(changed=[6, 3, 0, 1]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 50]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 6, 4, 8]), [1, 3, 4])\n assert answers_match(candidate(changed=[2, 4, 2, 4, 8, 8]), [])\n assert answers_match(candidate(changed=[2, 1]), [1])\n assert answers_match(candidate(changed=[5, 3, 10, 15, 20, 6]), [])\n assert answers_match(candidate(changed=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 60, 120, 180, 240, 300]), [])\n assert answers_match(candidate(changed=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]), [])\n assert answers_match(candidate(changed=[3, 6, 6, 12, 12, 12, 24, 24, 24, 24, 24, 24, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), [])\n assert answers_match(candidate(changed=[2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024]), [2, 2, 8, 8, 32, 32, 128, 128, 512, 512])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 6, 8, 9, 12, 12, 16, 18, 24, 24, 32, 36, 48, 48, 64, 72, 96, 96, 128, 144, 192, 192]), [])\n assert answers_match(candidate(changed=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]), [])\n assert answers_match(candidate(changed=[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]), [])\n assert answers_match(candidate(changed=[19, 38, 57, 76, 95, 114, 133, 152, 171, 190, 380, 570, 760, 950, 1140, 1330, 1520, 1710, 1900]), [])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 3, 3, 6, 6, 9, 9, 12, 12, 18, 18, 24, 24, 36, 36, 48, 48, 54, 54, 72, 72, 96, 96, 108, 108, 144, 144, 192, 192]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40]), [])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 3, 3, 6, 6, 9, 9, 18, 18]), [1, 1, 3, 3, 9, 9])\n assert answers_match(candidate(changed=[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]), [])\n assert answers_match(candidate(changed=[0, 0, 0, 0, 0, 0]), [0, 0, 0])\n assert answers_match(candidate(changed=[2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 6, 8, 9, 12, 12, 16, 18, 24, 24, 32, 36, 48, 48, 64, 72, 96, 96, 128, 144, 192, 192, 256, 288, 384, 384]), [])\n assert answers_match(candidate(changed=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(candidate(changed=[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]), [])\n assert answers_match(candidate(changed=[11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 222, 333, 444, 555, 666, 777, 888, 999, 1100, 2200, 3300, 4400, 5500, 6600, 7700, 8800, 9900]), [])\n assert answers_match(candidate(changed=[7, 14, 7, 14, 28, 28, 56, 56, 112, 112, 224, 224]), [7, 7, 28, 28, 112, 112])\n assert answers_match(candidate(changed=[1, 2, 3, 6, 9, 18, 27, 54, 81, 162, 243, 486, 729, 1458, 2187, 4374, 6561, 13122, 19683, 39366]), [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683])\n assert answers_match(candidate(changed=[3, 6, 12, 15, 30, 60, 75, 150, 225, 450, 900]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 64, 64, 64, 64, 64, 128, 128, 128, 128, 128, 256, 256, 256, 256, 256, 512, 512, 512, 512, 512, 1024, 1024, 1024, 1024, 1024, 2048, 2048, 2048, 2048, 2048]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400]), [])\n assert answers_match(candidate(changed=[15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 300, 450, 600, 750, 900]), [])\n assert answers_match(candidate(changed=[1023, 2046, 3069, 4092, 5115, 6138, 7161, 8184, 9207, 10230, 2046, 4092, 6138, 8184, 10230, 12276, 14322, 16368, 18414, 20460, 3069, 6138, 9207, 12276, 15345, 18414, 21483, 24540, 27597, 30654]), [])\n assert answers_match(candidate(changed=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]), [])\n assert answers_match(candidate(changed=[7, 14, 14, 21, 28, 28, 35, 42, 42, 56, 56, 70, 70, 84, 84, 105, 105, 140, 140, 168, 168, 210, 210, 280, 280]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400]), [5, 10, 15, 20, 20, 25, 30, 35, 40, 40, 45, 50, 60, 80, 100, 120, 140, 160, 180, 200])\n assert answers_match(candidate(changed=[23, 46, 69, 92, 115, 138, 161, 184, 207, 230, 460, 690, 920, 1150, 1380, 1610, 1840, 2070, 2300]), [])\n assert answers_match(candidate(changed=[0, 0, 0, 0, 0, 0, 0]), [])\n assert answers_match(candidate(changed=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60]), [])\n assert answers_match(candidate(changed=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]), [])\n assert answers_match(candidate(changed=[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, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40]), [])\n assert answers_match(candidate(changed=[13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 260, 520, 780, 1040, 1300]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32]), [])\n assert answers_match(candidate(changed=[1, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256]), [])\n assert answers_match(candidate(changed=[5, 10, 10, 20, 20, 40, 40, 80, 80, 160, 160, 320, 320]), [])\n assert answers_match(candidate(changed=[3, 6, 9, 18, 27, 54, 81, 162, 243, 486]), [3, 9, 27, 81, 243])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40]), [])\n assert answers_match(candidate(changed=[17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 340, 510, 680, 850, 1020, 1190, 1360, 1530, 1700]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]), [])\n assert answers_match(candidate(changed=[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000]), [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000])\n assert answers_match(candidate(changed=[5, 10, 10, 15, 20, 20, 25, 30, 30, 40, 40, 50, 50, 60, 60, 75, 75, 100, 100, 120, 120, 150, 150, 200, 200]), [])\n assert answers_match(candidate(changed=[3, 6, 9, 12, 18, 24, 36, 48, 54, 72, 96, 108, 144, 192, 216, 288, 384, 432, 576, 768, 864, 1152, 1536, 1728, 2304, 3072, 3456, 4608, 6144, 6912, 9216, 12288, 13824, 18432, 24576, 27648, 36864, 49152, 55296, 73728, 98304]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024]), [])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 3, 3, 4, 4, 6, 6, 8, 8, 12, 12, 16, 16, 24, 24, 32, 32, 48, 48, 64, 64, 96, 96, 128, 128]), [1, 1, 3, 3, 4, 4, 12, 12, 16, 16, 48, 48, 64, 64])\n assert answers_match(candidate(changed=[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]), [])\n assert answers_match(candidate(changed=[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]), [])\n assert answers_match(candidate(changed=[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]), [1, 1, 1, 4, 4, 4, 16, 16, 16, 64, 64, 64, 256, 256, 256])\n assert answers_match(candidate(changed=[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]), [2, 8, 32, 128, 512])\n assert answers_match(candidate(changed=[2, 4, 4, 8, 8, 16, 16, 32, 32, 64]), [2, 4, 8, 16, 32])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200]), [])\n assert answers_match(candidate(changed=[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 140, 280, 420, 560, 700]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 3, 6, 6, 12, 12, 24, 24, 48, 48]), [])\n assert answers_match(candidate(changed=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512]), [1, 4, 16, 64, 256])\n assert answers_match(candidate(changed=[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]), [])\n assert answers_match(candidate(changed=[2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64]), [])\n assert answers_match(candidate(changed=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]), [])\n assert answers_match(candidate(changed=[10, 20, 30, 40, 50, 60, 20, 40, 60, 80, 100, 120, 40, 80, 120, 160, 200, 240, 80, 160, 240, 320, 400, 480, 160, 320, 480, 640, 800, 960]), [])\n assert answers_match(candidate(changed=[3, 3, 6, 6, 9, 9, 18, 18, 27, 27]), [])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024]), [1, 2, 4, 8, 16, 32, 64, 128, 256, 512])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64]), [])\n assert answers_match(candidate(changed=[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]), [2, 8, 32, 128, 512, 2048, 8192, 32768])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 60, 120, 180, 240, 300]), [])\n assert answers_match(candidate(changed=[9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 180, 360, 540, 720, 900]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]), [])\n assert answers_match(candidate(changed=[9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 18, 36, 54, 72, 90, 108, 126, 144, 162, 180]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]), [])\n assert answers_match(candidate(changed=[10, 20, 30, 40, 50, 60, 20, 40, 60, 80, 100, 120]), [10, 20, 30, 40, 50, 60])\n assert answers_match(candidate(changed=[1, 2, 2, 4, 4, 8, 8, 16, 16, 32]), [1, 2, 4, 8, 16])\n assert answers_match(candidate(changed=[11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 22, 44, 66, 88, 110, 132, 154, 176, 198, 220, 33, 66, 99, 132, 165, 198, 231, 264, 297, 330]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150]), [])\n assert answers_match(candidate(changed=[1, 1, 2, 3, 3, 6, 6, 12, 12, 24, 24, 48, 48, 96, 96, 192, 192, 384, 384, 768, 768, 1536, 1536, 3072, 3072, 6144, 6144, 12288, 12288, 24576, 24576]), [])\n assert answers_match(candidate(changed=[29, 58, 87, 116, 145, 174, 203, 232, 261, 290, 580, 870, 1160, 1450, 1740, 2030, 2320, 2610, 2900]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 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, 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, 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, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272, 288, 304, 320, 336, 352, 368, 384, 400, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800, 64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024, 1088, 1152, 1216, 1280, 1344, 1408, 1472, 1536, 1600, 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920, 2048, 2176, 2304, 2432, 2560, 2688, 2816, 2944, 3072, 3200, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]), [])\n assert answers_match(candidate(changed=[5, 10, 10, 20, 20, 40, 40, 80, 80, 160, 160, 320, 320, 640, 640, 1280, 1280, 2560, 2560, 5120]), [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560])\n assert answers_match(candidate(changed=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 240, 280, 320, 360, 400]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512]), [1, 1, 4, 4, 16, 16, 64, 64, 256, 256])\n assert answers_match(candidate(changed=[1, 2, 3, 6, 9, 12, 18, 27, 36, 54, 81, 108, 162, 243, 324, 486, 729, 972, 1458, 2187]), [])\n assert answers_match(candidate(changed=[100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1]), [])\n assert answers_match(candidate(changed=[5, 10, 15, 20, 25, 50, 75, 100, 125, 250, 375, 500, 625, 1250]), [])\n assert answers_match(candidate(changed=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20])\n assert answers_match(candidate(changed=[100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200]), [100, 400, 1600, 6400, 25600])\n assert answers_match(candidate(changed=[1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024]), [])\n assert answers_match(candidate(changed=[1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 24, 30, 40, 60, 120]), [])\n assert answers_match(candidate(changed=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [0, 0, 0, 0, 0])\n", "comparison": "unordered"}, "public_tests": ["[1,3,4,2,6,8]", "[6,3,0,1]", "[1]"], "hints": ["If changed is a doubled array, you should be able to delete elements and their doubled values until the array is empty.", "Which element is guaranteed to not be a doubled value? It is the smallest element.", "After removing the smallest element and its double from changed, is there another number that is guaranteed to not be a doubled value?"], "metadata": {"canonical_parameter_names": ["changed"], "leetcode_dataset_entry_point": "Solution().findOriginalArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:37:59+00:00", "tests_total": 124, "tests_dropped": 11, "flags": ["any_order"], "topic_tags": ["array", "hash-table", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function findOriginalArray($changed) {", "container": "Solution", "callable": "findOriginalArray", "parameters": [{"name": "changed", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2008, "task_id": "maximum-earnings-from-taxi", "difficulty": "Medium", "problem_description": "There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to point n to make money by picking up passengers. You cannot change the direction of the taxi.\n\nThe passengers are represented by a 0-indexed 2D integer array rides, where rides[i] = [start_i, end_i, tip_i] denotes the i^th passenger requesting a ride from point start_i to point end_i who is willing to give a tip_i dollar tip.\n\nFor each passenger i you pick up, you earn end_i - start_i + tip_i dollars. You may only drive at most one passenger at a time.\n\nGiven n and rides, return the maximum number of dollars you can earn by picking up the passengers optimally.\n\nNote: You may drop off a passenger and pick up a different passenger at the same point.\n\nExample 1:\n\nInput: n = 5, rides = [[2,5,4],[1,5,1]]\nOutput: 7\nExplanation: We can pick up passenger 0 to earn 5 - 2 + 4 = 7 dollars.\n\nExample 2:\n\nInput: n = 20, rides = [[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]]\nOutput: 20\nExplanation: We will pick up the following passengers:\n- Drive passenger 1 from point 3 to point 10 for a profit of 10 - 3 + 2 = 9 dollars.\n- Drive passenger 2 from point 10 to point 12 for a profit of 12 - 10 + 3 = 5 dollars.\n- Drive passenger 5 from point 13 to point 18 for a profit of 18 - 13 + 1 = 6 dollars.\nWe earn 9 + 5 + 6 = 20 dollars in total.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 1 <= rides.length <= 3 * 10^4\n- rides[i].length == 3\n- 1 <= start_i < end_i <= n\n- 1 <= tip_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 100,rides = [[1, 10, 50], [20, 30, 25], [50, 60, 100], [70, 80, 75], [90, 100, 200]]) == 499\n assert candidate(n = 10,rides = [[1, 3, 2], [2, 5, 3], [4, 6, 1]]) == 7\n assert candidate(n = 30,rides = [[1, 10, 10], [10, 20, 10], [20, 30, 10]]) == 59\n assert candidate(n = 15,rides = [[1, 2, 5], [2, 3, 10], [3, 4, 20], [4, 5, 30]]) == 69\n assert candidate(n = 5,rides = [[2, 5, 4], [1, 5, 1]]) == 7\n assert candidate(n = 15,rides = [[1, 4, 1], [2, 6, 2], [3, 7, 3], [4, 8, 4], [5, 9, 5]]) == 13\n assert candidate(n = 10,rides = [[1, 3, 2], [2, 5, 3], [4, 8, 2], [6, 10, 3]]) == 13\n assert candidate(n = 100,rides = [[1, 10, 50], [2, 20, 60], [3, 30, 70], [4, 40, 80], [5, 50, 90]]) == 135\n assert candidate(n = 30,rides = [[1, 15, 10], [16, 30, 5]]) == 43\n assert candidate(n = 15,rides = [[1, 4, 3], [3, 7, 4], [7, 10, 5]]) == 16\n assert candidate(n = 15,rides = [[1, 4, 5], [2, 6, 3], [3, 8, 7], [5, 9, 4]]) == 16\n assert candidate(n = 20,rides = [[1, 6, 1], [3, 10, 2], [10, 12, 3], [11, 12, 2], [12, 15, 2], [13, 18, 1]]) == 20\n assert candidate(n = 10,rides = [[1, 3, 5], [2, 5, 2], [5, 8, 3]]) == 13\n assert candidate(n = 10,rides = [[1, 3, 2], [2, 5, 3], [5, 7, 2], [6, 9, 1]]) == 10\n assert candidate(n = 100000,rides = [[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]]) == 20\n assert candidate(n = 1000,rides = [[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, 1000, 999]]) == 2043\n assert candidate(n = 30000,rides = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [29998, 29999, 1], [29999, 30000, 100]]) == 112\n assert candidate(n = 10000,rides = [[1, 500, 100], [501, 1000, 200], [1001, 1500, 300], [1501, 2000, 400], [2001, 2500, 500], [2501, 3000, 600], [3001, 3500, 700], [3501, 4000, 800], [4001, 4500, 900], [4501, 5000, 1000], [5001, 10000, 4500]]) == 19989\n assert candidate(n = 75000,rides = [[1, 25000, 10000], [25000, 50000, 10000], [50000, 75000, 10000]]) == 104999\n assert candidate(n = 5000,rides = [[1, 2500, 2500], [2501, 5000, 2500], [1, 5000, 5000]]) == 9999\n assert candidate(n = 100,rides = [[1, 5, 10], [5, 10, 10], [10, 15, 10], [15, 20, 10], [20, 25, 10], [25, 30, 10], [30, 35, 10], [35, 40, 10], [40, 45, 10], [45, 50, 10], [50, 55, 10], [55, 60, 10], [60, 65, 10], [65, 70, 10], [70, 75, 10], [75, 80, 10], [80, 85, 10], [85, 90, 10], [90, 95, 10], [95, 100, 10]]) == 299\n assert candidate(n = 1000,rides = [[1, 500, 1000], [501, 1000, 500], [1, 250, 200], [251, 500, 150], [501, 750, 125], [751, 1000, 100]]) == 2498\n assert candidate(n = 50000,rides = [[1, 5, 5], [2, 6, 7], [3, 7, 8], [4, 8, 9], [5, 9, 10], [6, 10, 12], [7, 11, 14], [8, 12, 16], [9, 13, 18], [10, 14, 20]]) == 51\n assert candidate(n = 30000,rides = [[1, 10000, 5000], [10001, 20000, 5000], [20001, 30000, 5000], [1, 20000, 10000], [10001, 30000, 10000], [1, 30000, 15000]]) == 44999\n assert candidate(n = 30000,rides = [[1, 10000, 5000], [10001, 20000, 10000], [20001, 30000, 15000], [1, 5000, 2500], [5001, 10000, 5000], [10001, 15000, 7500], [15001, 20000, 10000], [20001, 25000, 12500], [25001, 30000, 15000], [1, 2000, 1000], [2001, 4000, 2000], [4001, 6000, 3000], [6001, 8000, 4000], [8001, 10000, 5000], [10001, 12000, 6000], [12001, 14000, 7000], [14001, 16000, 8000], [16001, 18000, 9000], [18001, 20000, 10000], [20001, 22000, 11000], [22001, 24000, 12000], [24001, 26000, 13000], [26001, 28000, 14000], [28001, 30000, 15000]]) == 149985\n assert candidate(n = 30000,rides = [[1, 30000, 15000], [2, 29999, 14999], [3, 29998, 14998], [4, 29997, 14997], [5, 29996, 14996], [6, 29995, 14995], [7, 29994, 14994], [8, 29993, 14993], [9, 29992, 14992], [10, 29991, 14991]]) == 44999\n assert candidate(n = 50000,rides = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5]]) == 20\n assert candidate(n = 80000,rides = [[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, 80000, 79999]]) == 160043\n assert candidate(n = 100000,rides = [[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]]) == 135\n assert candidate(n = 50000,rides = [[1, 1000, 500], [1001, 2000, 1000], [2001, 3000, 1500], [3001, 4000, 2000], [4001, 5000, 2500], [5001, 10000, 3000], [10001, 15000, 3500], [15001, 20000, 4000], [20001, 25000, 4500], [25001, 30000, 5000], [30001, 35000, 5500], [35001, 40000, 6000], [40001, 45000, 6500], [45001, 50000, 7000]]) == 102486\n assert candidate(n = 10000,rides = [[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, 19], [20, 21, 20], [21, 22, 21], [22, 23, 22], [23, 24, 23], [24, 25, 24], [25, 26, 25], [26, 27, 26], [27, 28, 27], [28, 29, 28], [29, 30, 29], [30, 31, 30], [31, 32, 31], [32, 33, 32], [33, 34, 33], [34, 35, 34], [35, 36, 35], [36, 37, 36], [37, 38, 37], [38, 39, 38], [39, 40, 39], [40, 41, 40]]) == 860\n assert candidate(n = 200,rides = [[1, 100, 50], [2, 199, 49], [3, 198, 48], [4, 197, 47], [5, 196, 46], [6, 195, 45], [7, 194, 44], [8, 193, 43], [9, 192, 42], [10, 191, 41]]) == 246\n assert candidate(n = 100,rides = [[10, 20, 10], [20, 30, 20], [30, 40, 30], [40, 50, 40], [50, 60, 50], [60, 70, 60], [70, 80, 70], [80, 90, 80], [90, 100, 90], [1, 10, 5], [2, 20, 15], [3, 30, 25], [4, 40, 35], [5, 50, 45], [6, 60, 55], [7, 70, 65], [8, 80, 75], [9, 90, 85], [10, 100, 95]]) == 554\n assert candidate(n = 10000,rides = [[1, 10000, 10000], [2, 9999, 9999], [3, 9998, 9998], [4, 9997, 9997], [5, 9996, 9996]]) == 19999\n assert candidate(n = 10000,rides = [[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, 20, 1]]) == 38\n assert candidate(n = 50,rides = [[1, 3, 2], [3, 5, 3], [5, 7, 2], [7, 9, 1], [9, 11, 5], [11, 13, 4], [13, 15, 6], [15, 17, 2], [17, 19, 3], [19, 21, 7], [21, 23, 4], [23, 25, 5], [25, 27, 2], [27, 29, 3], [29, 31, 1], [31, 33, 5], [33, 35, 4], [35, 37, 6], [37, 39, 2], [39, 41, 3], [41, 43, 7], [43, 45, 4], [45, 47, 5], [47, 49, 2], [49, 50, 3]]) == 140\n assert candidate(n = 100,rides = [[1, 10, 50], [11, 20, 50], [21, 30, 50], [31, 40, 50], [41, 50, 50], [51, 60, 50], [61, 70, 50], [71, 80, 50], [81, 90, 50], [91, 100, 50]]) == 590\n assert candidate(n = 30000,rides = [[1, 10, 50], [11, 20, 100], [21, 30, 150], [31, 40, 200], [41, 50, 250], [51, 60, 300], [61, 70, 350], [71, 80, 400], [81, 90, 450], [91, 100, 500], [101, 30000, 29900]]) == 62639\n assert candidate(n = 20000,rides = [[1, 5, 10], [2, 6, 15], [3, 7, 20], [4, 8, 25], [5, 9, 30], [6, 10, 35], [7, 11, 40], [8, 12, 45], [9, 13, 50], [10, 20000, 19950]]) == 39998\n assert candidate(n = 1000,rides = [[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]]) == 54\n assert candidate(n = 100000,rides = [[1, 100000, 100000]]) == 199999\n assert candidate(n = 30000,rides = [[1, 30000, 10000], [10000, 20000, 15000], [20000, 30000, 20000], [5000, 15000, 10000]]) == 55000\n assert candidate(n = 50000,rides = [[1, 25000, 25000], [25000, 50000, 25000], [5000, 10000, 5000], [15000, 20000, 5000], [30000, 35000, 5000]]) == 99999\n assert candidate(n = 50,rides = [[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, 19], [20, 21, 20], [21, 22, 21], [22, 23, 22], [23, 24, 23], [24, 25, 24], [25, 26, 25], [26, 27, 26], [27, 28, 27], [28, 29, 28], [29, 30, 29], [30, 31, 30], [31, 32, 31], [32, 33, 32], [33, 34, 33], [34, 35, 34], [35, 36, 35], [36, 37, 36], [37, 38, 37], [38, 39, 38], [39, 40, 39], [40, 41, 40], [41, 42, 41], [42, 43, 42], [43, 44, 43], [44, 45, 44], [45, 46, 45], [46, 47, 46], [47, 48, 47], [48, 49, 48], [49, 50, 49]]) == 1274\n assert candidate(n = 50,rides = [[1, 10, 5], [1, 10, 3], [1, 10, 1], [10, 20, 5], [10, 20, 3], [10, 20, 1], [20, 30, 5], [20, 30, 3], [20, 30, 1]]) == 44\n assert candidate(n = 70000,rides = [[1, 10000, 10000], [10001, 20000, 10000], [20001, 30000, 10000], [30001, 40000, 10000], [40001, 50000, 10000], [50001, 60000, 10000], [60001, 70000, 10000]]) == 139993\n assert candidate(n = 100000,rides = [[1, 50000, 50000], [50000, 100000, 50000], [25000, 75000, 30000]]) == 199999\n assert candidate(n = 50000,rides = [[1, 10, 100], [10, 20, 100], [20, 30, 100], [30, 40, 100], [40, 50, 100], [50, 60, 100], [60, 70, 100], [70, 80, 100], [80, 90, 100], [90, 100, 100]]) == 1099\n assert candidate(n = 10000,rides = [[1, 5000, 1000], [5001, 10000, 2000], [2001, 4000, 1500], [4001, 6000, 1200], [6001, 8000, 1800], [8001, 10000, 1600], [3001, 4500, 800], [4501, 6500, 1300], [6501, 8500, 1700], [8501, 9500, 1400]]) == 14096\n assert candidate(n = 50000,rides = [[1, 10, 10], [10, 20, 20], [20, 30, 30], [30, 40, 40], [40, 50, 50], [50, 60, 60], [60, 70, 70], [70, 80, 80], [80, 90, 90], [90, 100, 100], [100, 50000, 49900]]) == 100449\n assert candidate(n = 90000,rides = [[1, 10, 1], [11, 20, 2], [21, 30, 3], [31, 40, 4], [41, 50, 5], [51, 60, 6], [61, 70, 7], [71, 80, 8], [81, 90, 9], [91, 100, 10], [101, 110, 11], [111, 120, 12], [121, 130, 13], [131, 140, 14], [141, 150, 15], [151, 160, 16], [161, 170, 17], [171, 180, 18], [181, 190, 19], [191, 200, 20]]) == 390\n assert candidate(n = 90000,rides = [[1, 30000, 30000], [30001, 60000, 30000], [60001, 90000, 30000], [1, 60000, 60000], [30001, 90000, 60000], [1, 90000, 90000]]) == 179999\n assert candidate(n = 5000,rides = [[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], [11, 13, 1], [12, 14, 1], [13, 15, 1], [14, 16, 1], [15, 17, 1], [16, 18, 1], [17, 19, 1], [18, 20, 1], [19, 21, 1], [20, 22, 1], [21, 23, 1], [22, 24, 1], [23, 25, 1], [24, 26, 1], [25, 27, 1], [26, 28, 1], [27, 29, 1], [28, 30, 1], [29, 31, 1], [30, 32, 1], [31, 33, 1], [32, 34, 1], [33, 35, 1], [34, 36, 1], [35, 37, 1], [36, 38, 1], [37, 39, 1], [38, 40, 1]]) == 57\n assert candidate(n = 10000,rides = [[1, 5, 50], [2, 6, 40], [3, 7, 30], [4, 8, 20], [5, 9, 10], [6, 10, 5]]) == 68\n assert candidate(n = 1000,rides = [[1, 10, 5], [2, 15, 10], [5, 100, 50], [10, 50, 25], [15, 90, 45], [20, 80, 35], [25, 70, 30], [30, 60, 25], [35, 55, 20], [40, 45, 15]]) == 145\n assert candidate(n = 50000,rides = [[1, 10000, 10000], [10001, 20000, 20000], [20001, 30000, 30000], [30001, 40000, 40000], [40001, 50000, 50000]]) == 199995\n assert candidate(n = 100,rides = [[1, 10, 5], [11, 20, 10], [21, 30, 15], [31, 40, 20], [41, 50, 25], [51, 60, 30], [61, 70, 35], [71, 80, 40], [81, 90, 45], [91, 100, 50]]) == 365\n assert candidate(n = 100000,rides = [[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, 20, 1], [20, 21, 1], [21, 22, 1], [22, 23, 1], [23, 24, 1], [24, 25, 1], [25, 26, 1], [26, 27, 1], [27, 28, 1], [28, 29, 1], [29, 30, 1], [30, 31, 1], [31, 32, 1], [32, 33, 1], [33, 34, 1], [34, 35, 1], [35, 36, 1], [36, 37, 1], [37, 38, 1], [38, 39, 1], [39, 40, 1], [40, 41, 1], [41, 42, 1], [42, 43, 1], [43, 44, 1], [44, 45, 1], [45, 46, 1], [46, 47, 1], [47, 48, 1], [48, 49, 1], [49, 50, 1], [50, 51, 1], [51, 52, 1], [52, 53, 1], [53, 54, 1], [54, 55, 1], [55, 56, 1], [56, 57, 1], [57, 58, 1], [58, 59, 1], [59, 60, 1], [60, 61, 1], [61, 62, 1], [62, 63, 1], [63, 64, 1], [64, 65, 1], [65, 66, 1], [66, 67, 1], [67, 68, 1], [68, 69, 1], [69, 70, 1], [70, 71, 1], [71, 72, 1], [72, 73, 1], [73, 74, 1], [74, 75, 1], [75, 76, 1], [76, 77, 1], [77, 78, 1], [78, 79, 1], [79, 80, 1], [80, 81, 1], [81, 82, 1], [82, 83, 1], [83, 84, 1], [84, 85, 1], [85, 86, 1], [86, 87, 1], [87, 88, 1], [88, 89, 1], [89, 90, 1], [90, 91, 1], [91, 92, 1], [92, 93, 1], [93, 94, 1], [94, 95, 1], [95, 96, 1], [96, 97, 1], [97, 98, 1], [98, 99, 1], [99, 100, 1], [100, 101, 1], [101, 102, 1], [102, 103, 1], [103, 104, 1], [104, 105, 1], [105, 106, 1], [106, 107, 1], [107, 108, 1], [108, 109, 1], [109, 110, 1], [110, 111, 1], [111, 112, 1], [112, 113, 1], [113, 114, 1], [114, 115, 1], [115, 116, 1], [116, 117, 1], [117, 118, 1], [118, 119, 1], [119, 120, 1], [120, 121, 1], [121, 122, 1], [122, 123, 1], [123, 124, 1], [124, 125, 1], [125, 126, 1], [126, 127, 1], [127, 128, 1], [128, 129, 1], [129, 130, 1], [130, 131, 1], [131, 132, 1], [132, 133, 1], [133, 134, 1], [134, 135, 1], [135, 136, 1], [136, 137, 1], [137, 138, 1], [138, 139, 1], [139, 140, 1], [140, 141, 1], [141, 142, 1], [142, 143, 1], [143, 144, 1], [144, 145, 1], [145, 146, 1], [146, 147, 1], [147, 148, 1], [148, 149, 1], [149, 150, 1], [150, 151, 1], [151, 152, 1], [152, 153, 1], [153, 154, 1], [154, 155, 1], [155, 156, 1], [156, 157, 1], [157, 158, 1], [158, 159, 1], [159, 160, 1], [160, 161, 1], [161, 162, 1], [162, 163, 1], [163, 164, 1], [164, 165, 1], [165, 166, 1], [166, 167, 1], [167, 168, 1], [168, 169, 1], [169, 170, 1], [170, 171, 1], [171, 172, 1], [172, 173, 1], [173, 174, 1], [174, 175, 1], [175, 176, 1], [176, 177, 1], [177, 178, 1], [178, 179, 1], [179, 180, 1], [180, 181, 1], [181, 182, 1], [182, 183, 1], [183, 184, 1], [184, 185, 1], [185, 186, 1], [186, 187, 1], [187, 188, 1], [188, 189, 1], [189, 190, 1], [190, 191, 1], [191, 192, 1], [192, 193, 1], [193, 194, 1], [194, 195, 1], [195, 196, 1], [196, 197, 1], [197, 198, 1], [198, 199, 1], [199, 200, 1]]) == 398\n assert candidate(n = 100000,rides = [[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, 100000, 99999]]) == 200007\n assert candidate(n = 100000,rides = [[1, 100000, 100000], [50000, 100000, 50000], [25000, 75000, 25000], [1, 50000, 10000], [50001, 100000, 10000]]) == 199999\n assert candidate(n = 20,rides = [[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, 20, 1]]) == 38\n assert candidate(n = 100000,rides = [[1, 100000, 1], [1, 100000, 2], [1, 100000, 3], [1, 100000, 4], [1, 100000, 5], [1, 100000, 6], [1, 100000, 7], [1, 100000, 8], [1, 100000, 9], [1, 100000, 10]]) == 100009\n assert candidate(n = 15,rides = [[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]]) == 119\n assert candidate(n = 60000,rides = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [59999, 60000, 100000]]) == 100028\n assert candidate(n = 80000,rides = [[1, 20000, 1000], [20000, 40000, 1000], [40000, 60000, 1000], [60000, 80000, 1000]]) == 83999\n assert candidate(n = 10000,rides = [[1, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 10, 10], [7, 11, 10], [8, 12, 10], [9, 13, 10], [10, 14, 10]]) == 42\n assert candidate(n = 10000,rides = [[1, 10, 5], [2, 11, 5], [3, 12, 5], [4, 13, 5], [5, 14, 5], [6, 15, 5], [7, 16, 5], [8, 17, 5], [9, 18, 5], [10, 19, 5], [11, 20, 5], [12, 21, 5], [13, 22, 5], [14, 23, 5], [15, 24, 5], [16, 25, 5], [17, 26, 5], [18, 27, 5], [19, 28, 5], [20, 29, 5], [21, 30, 5], [22, 31, 5], [23, 32, 5], [24, 33, 5], [25, 34, 5], [26, 35, 5], [27, 36, 5], [28, 37, 5], [29, 38, 5], [30, 39, 5], [31, 40, 5], [32, 41, 5], [33, 42, 5], [34, 43, 5], [35, 44, 5], [36, 45, 5], [37, 46, 5], [38, 47, 5], [39, 48, 5], [40, 49, 5], [41, 50, 5], [42, 51, 5], [43, 52, 5], [44, 53, 5], [45, 54, 5], [46, 55, 5], [47, 56, 5], [48, 57, 5], [49, 58, 5], [50, 59, 5], [51, 60, 5], [52, 61, 5], [53, 62, 5], [54, 63, 5], [55, 64, 5], [56, 65, 5], [57, 66, 5], [58, 67, 5], [59, 68, 5], [60, 69, 5], [61, 70, 5], [62, 71, 5], [63, 72, 5], [64, 73, 5], [65, 74, 5], [66, 75, 5], [67, 76, 5], [68, 77, 5], [69, 78, 5], [70, 79, 5], [71, 80, 5], [72, 81, 5], [73, 82, 5], [74, 83, 5], [75, 84, 5], [76, 85, 5], [77, 86, 5], [78, 87, 5], [79, 88, 5], [80, 89, 5], [81, 90, 5], [82, 91, 5], [83, 92, 5], [84, 93, 5], [85, 94, 5], [86, 95, 5], [87, 96, 5], [88, 97, 5], [89, 98, 5], [90, 99, 5], [91, 100, 5]]) == 154\n", "comparison": "exact"}, "public_tests": ["5\n[[2,5,4],[1,5,1]]", "20\n[[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]]"], "hints": ["Can we sort the array to help us solve the problem?", "We can use dynamic programming to keep track of the maximum at each position."], "metadata": {"canonical_parameter_names": ["n", "rides"], "leetcode_dataset_entry_point": "Solution().maxTaxiEarnings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:02+00:00", "tests_total": 71, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "dynamic-programming", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxTaxiEarnings($n, $rides) {", "container": "Solution", "callable": "maxTaxiEarnings", "parameters": [{"name": "n", "type": "Integer"}, {"name": "rides", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2009, "task_id": "minimum-number-of-operations-to-make-array-continuous", "difficulty": "Hard", "problem_description": "You are given an integer array nums. In one operation, you can replace any element in nums with any integer.\n\nnums is considered continuous if both of the following conditions are fulfilled:\n\n- All elements in nums are unique.\n- The difference between the maximum element and the minimum element in nums equals nums.length - 1.\n\nFor example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.\n\nReturn the minimum number of operations to make nums continuous.\n\nExample 1:\n\nInput: nums = [4,2,5,3]\nOutput: 0\nExplanation: nums is already continuous.\n\nExample 2:\n\nInput: nums = [1,2,3,5,6]\nOutput: 1\nExplanation: One possible solution is to change the last element to 4.\nThe resulting array is [1,2,3,5,4], which is continuous.\n\nExample 3:\n\nInput: nums = [1,10,100,1000]\nOutput: 3\nExplanation: One possible solution is to:\n- Change the second element to 2.\n- Change the third element to 3.\n- Change the fourth element to 4.\nThe resulting array is [1,2,3,4], which is continuous.\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, 10, 10, 10]) == 3\n assert candidate(nums = [4, 2, 5, 3]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 2, 3, 4, 5]) == 2\n assert candidate(nums = [5, 6, 7, 8, 9, 1]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1000000000, 1, 2, 3, 4]) == 1\n assert candidate(nums = [1000000000]) == 0\n assert candidate(nums = [100, 101, 102, 1]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 5\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [2, 3, 5, 8, 9, 10]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [1, 10, 100, 1000]) == 3\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [10, 5, 1, 2, 7]) == 2\n assert candidate(nums = [1, 2, 2, 3, 4]) == 1\n assert candidate(nums = [1, 2, 3, 5, 6]) == 1\n assert candidate(nums = [10, 5, 7, 11, 6]) == 2\n assert candidate(nums = [5, 3, 1, 2, 4]) == 0\n assert candidate(nums = [10, 5, 3, 11, 6]) == 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 = [5, 3, 1, 4, 2]) == 0\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 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, 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 = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 4\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 6\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 10]) == 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]) == 16\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 14\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 9\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998]) == 3\n assert candidate(nums = [1, 1000000000]) == 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, 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 = [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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 7\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 19\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]) == 24\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164, 175, 186, 197, 208, 219]) == 18\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 4, 5, 5, 6]) == 4\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]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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]) == 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]) == 10\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [5, 6, 15, 16, 25, 26, 35, 36, 45, 46, 55, 56, 65, 66, 75, 76, 85, 86, 95, 96]) == 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, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [3, 7, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == 12\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, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995]) == 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, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 0\n assert candidate(nums = [2, 1, 3, 4, 7, 6, 5, 8, 9, 10]) == 0\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 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]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 4\n assert candidate(nums = [1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 33, 35, 36, 37, 38, 40]) == 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, 15, 15]) == 15\n assert candidate(nums = [1, 3, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 7\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 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]) == 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]) == 12\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 15, 16]) == 4\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]) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20]) == 3\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 = [1, 2, 3, 4, 5, 6, 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, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, 118, 127, 136, 145, 154, 163, 172, 181, 190, 199, 208, 217, 226]) == 23\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]) == 0\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]) == 18\n assert candidate(nums = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 10\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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]) == 0\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]) == 13\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10]) == 12\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5]) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == 5\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 8\n assert candidate(nums = [1000000, 1000001, 1000002, 1000004, 1000005, 1000007, 1000008, 1000010, 1000011, 1000013]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 5\n assert candidate(nums = [1, 3, 5, 7, 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, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 9\n assert candidate(nums = [5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 14\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]) == 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]) == 16\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, 100, 101, 200, 201, 300, 301, 400, 401, 500, 501, 600, 601, 700, 701, 800, 801, 900, 901, 1000]) == 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]) == 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]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60]) == 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, 210, 220, 230, 240, 250]) == 22\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]) == 20\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 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]) == 0\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995]) == 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, 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]) == 45\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 8\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 5\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 200, 201, 202, 203, 204]) == 5\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 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]) == 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]) == 18\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 7\n assert candidate(nums = [1, 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]) == 30\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 5\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 14\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 9\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209]) == 10\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]) == 0\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 10\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]) == 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]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 13\n", "comparison": "exact"}, "public_tests": ["[4,2,5,3]", "[1,2,3,5,6]", "[1,10,100,1000]"], "hints": ["Sort the array.", "For every index do a binary search to get the possible right end of the window and calculate the possible answer."], "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:38:04+00:00", "tests_total": 136, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function minOperations($nums) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2011, "task_id": "final-value-of-variable-after-performing-operations", "difficulty": "Easy", "problem_description": "There is a programming language with only four operations and one variable X:\n\n- ++X and X++ increments the value of the variable X by 1.\n- --X and X-- decrements the value of the variable X by 1.\n\nInitially, the value of X is 0.\n\nGiven an array of strings operations containing a list of operations, return the final value of X after performing all the operations.\n\nExample 1:\n\nInput: operations = [\"--X\",\"X++\",\"X++\"]\nOutput: 1\nExplanation: The operations are performed as follows:\nInitially, X = 0.\n--X: X is decremented by 1, X = 0 - 1 = -1.\nX++: X is incremented by 1, X = -1 + 1 = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.\n\nExample 2:\n\nInput: operations = [\"++X\",\"++X\",\"X++\"]\nOutput: 3\nExplanation: The operations are performed as follows:\nInitially, X = 0.\n++X: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\nX++: X is incremented by 1, X = 2 + 1 = 3.\n\nExample 3:\n\nInput: operations = [\"X++\",\"++X\",\"--X\",\"X--\"]\nOutput: 0\nExplanation: The operations are performed as follows:\nInitially, X = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\n--X: X is decremented by 1, X = 2 - 1 = 1.\nX--: X is decremented by 1, X = 1 - 1 = 0.\n\nConstraints:\n\n- 1 <= operations.length <= 100\n- operations[i] will be either \"++X\", \"X++\", \"--X\", or \"X--\".\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(operations = ['X++', '++X', '--X', 'X--']) == 0\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++']) == 5\n assert candidate(operations = ['--X', '--X', 'X--', 'X--']) == -4\n assert candidate(operations = ['++X', '++X', '++X', '++X']) == 4\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++']) == 4\n assert candidate(operations = ['--X', 'X++', 'X++']) == 1\n assert candidate(operations = ['--X', '--X', '--X', '--X']) == -4\n assert candidate(operations = ['--X', '--X', '--X', '--X', '--X']) == -5\n assert candidate(operations = ['--X', '--X', 'X++', '++X']) == 0\n assert candidate(operations = ['++X', '++X', 'X++']) == 3\n assert candidate(operations = ['--X', '--X', 'X++', '++X', '--X']) == -1\n assert candidate(operations = ['++X', 'X--', '--X', 'X++']) == 0\n assert candidate(operations = ['X++', 'X--', '++X', '--X']) == 0\n assert candidate(operations = ['++X', '++X', '++X', '++X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == -12\n assert candidate(operations = ['X++', 'X++', 'X++', '--X', '--X', '--X', '--X', '--X', 'X++', 'X++', 'X++']) == 1\n assert candidate(operations = ['--X', '--X', 'X++', 'X++', 'X--', 'X--', 'X++', '++X', '--X', 'X++', '--X', '++X', 'X--', '--X', 'X++', 'X++']) == 0\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == 0\n assert candidate(operations = ['++X', '++X', '++X', '++X', 'X--', 'X--', 'X--', 'X--', 'X--', 'X--', 'X--', 'X--', 'X--', 'X--']) == -6\n assert candidate(operations = ['--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++']) == 0\n assert candidate(operations = ['X--', '--X', 'X--', '--X', 'X--', '--X', 'X--', '--X', 'X--', '--X', 'X--', '--X', 'X--', '--X', 'X--', '--X']) == -16\n assert candidate(operations = ['++X', '--X', '++X', '--X', '++X', '--X']) == 0\n assert candidate(operations = ['++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--']) == 0\n assert candidate(operations = ['X--', '--X', 'X++', '++X', '--X', 'X--', '--X', '++X', 'X++']) == -1\n assert candidate(operations = ['++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++']) == 0\n assert candidate(operations = ['X++', 'X++', '--X', 'X++', 'X++', '--X', '--X', 'X++', '--X', 'X++', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X']) == 1\n assert candidate(operations = ['--X', '--X', 'X--', 'X++', '++X', '++X', 'X--', '--X', '++X', '--X']) == -2\n assert candidate(operations = ['++X', 'X--', '--X', 'X++', 'X--', '++X', 'X--', '--X', 'X++', '++X']) == 0\n assert candidate(operations = ['++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++']) == 2\n assert candidate(operations = ['++X', 'X--', '--X', 'X++', '++X', '--X', 'X++']) == 1\n assert candidate(operations = ['--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']) == -5\n assert candidate(operations = ['++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X']) == 0\n assert candidate(operations = ['++X', '++X', '--X', '--X', '++X', '++X', '--X', '--X', '++X', '++X', '--X', '--X', '++X', '++X', '--X', '--X', '++X', '++X']) == 2\n assert candidate(operations = ['--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == -12\n assert candidate(operations = ['X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X']) == 0\n assert candidate(operations = ['++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X', '--X']) == 0\n assert candidate(operations = ['X++', '--X', '++X', 'X--', '++X', 'X++', '--X', '--X', '++X', 'X++']) == 2\n assert candidate(operations = ['++X', '++X', '++X', '++X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == -4\n assert candidate(operations = ['X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X']) == 0\n assert candidate(operations = ['--X', 'X++', '++X', '--X', 'X++', '--X', 'X--', 'X++', '--X', '++X']) == 0\n assert candidate(operations = ['++X', '++X', '++X', '--X', '--X', '--X', '++X', 'X++', '--X']) == 1\n assert candidate(operations = ['++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', '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--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X']) == -1\n assert candidate(operations = ['--X', '--X', 'X++', 'X--', 'X--', 'X--', 'X--', 'X--', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 0\n assert candidate(operations = ['++X', '--X', 'X++', '++X', '--X', 'X--', '++X', 'X++']) == 2\n assert candidate(operations = ['--X', 'X--', '--X', 'X--', '--X', 'X--', '++X', 'X++', '++X', 'X++', '++X', 'X++', '++X', 'X++']) == 2\n assert candidate(operations = ['X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X']) == 0\n assert candidate(operations = ['--X', '++X', '--X', '++X', '--X', '++X', '--X', '++X']) == 0\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X--', 'X--', 'X--', 'X--', 'X++', 'X++', 'X--', 'X--']) == 0\n assert candidate(operations = ['X--', '--X', '++X', 'X++', 'X--', '--X', '++X', 'X++', 'X--', '--X', '++X', 'X++', 'X--', '--X', '++X', 'X++', 'X--', '--X', '++X', 'X++']) == 0\n assert candidate(operations = ['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', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == -4\n assert candidate(operations = ['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++', '--X', 'X++', '--X', 'X--', 'X++', '--X']) == -5\n assert candidate(operations = ['X++', 'X++', '--X', '--X', '++X', 'X--', '++X', '--X', '++X', '--X']) == 0\n assert candidate(operations = ['X++', 'X++', '++X', '--X', 'X--', 'X--', '--X', '++X', 'X--', '--X']) == -2\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 12\n assert candidate(operations = ['--X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', '--X', 'X++', '--X', '++X', 'X--', '--X', 'X++']) == -2\n assert candidate(operations = ['--X', '--X', '--X', '--X', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 4\n assert candidate(operations = ['--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X']) == -1\n assert candidate(operations = ['X--', '--X', '++X', 'X++', 'X--', '--X', '++X', 'X++']) == 0\n assert candidate(operations = ['X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', '++X', 'X++', '--X', '--X', '++X', 'X++']) == 2\n assert candidate(operations = ['--X', '--X', '--X', '--X', '--X', '--X', '++X', '++X', '++X', '++X', '++X', '++X', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 8\n assert candidate(operations = ['--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', '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(operations = ['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++', '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++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 57\n assert candidate(operations = ['X++', '--X', '++X', 'X--', '++X', '--X', 'X++', '++X', '--X', 'X--']) == 0\n assert candidate(operations = ['--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++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 37\n assert candidate(operations = ['X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++']) == 2\n assert candidate(operations = ['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++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X']) == 0\n assert candidate(operations = ['X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X']) == 0\n assert candidate(operations = ['--X', '--X', '--X', 'X++', 'X++', 'X++', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', 'X--', 'X--', '++X', '++X']) == 0\n assert candidate(operations = ['X++', 'X--', '++X', '--X', 'X++', 'X--', '++X', '--X', 'X++', 'X--', '++X', '--X', 'X++', 'X--', '++X', '--X', 'X++', 'X--', '++X', '--X']) == 0\n assert candidate(operations = ['X++', 'X--', '++X', '--X', 'X--', '++X', 'X--', '++X', 'X--', '++X', 'X--', '++X']) == 0\n assert candidate(operations = ['X++', '--X', '++X', '--X', 'X++', '--X', 'X--']) == -1\n assert candidate(operations = ['--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++']) == 0\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++']) == 2\n assert candidate(operations = ['X--', 'X--', '--X', '--X', 'X++', 'X++', '++X']) == -1\n assert candidate(operations = ['X++', 'X++', 'X++', '--X', '--X', '--X', 'X++', 'X++', '--X', '--X', 'X++', 'X++', 'X++', '--X', '--X']) == 1\n assert candidate(operations = ['++X', '++X', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++']) == 2\n assert candidate(operations = ['--X', '--X', '--X', '--X', '--X', '++X', '++X', '++X', '++X', '++X', 'X++', 'X++', 'X++']) == 3\n assert candidate(operations = ['++X', 'X++', '--X', 'X--', '++X', '--X', 'X++', '++X']) == 2\n assert candidate(operations = ['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++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X', 'X--', '--X', 'X++', '++X']) == 2\n assert candidate(operations = ['X++', '++X', 'X++', '++X', '--X', '--X', 'X--', '--X', 'X++', '++X', '--X', 'X--', '++X', 'X++']) == 2\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == -4\n assert candidate(operations = ['X++', 'X++', '--X', '--X', 'X++', 'X++', 'X++', '--X', '--X', '--X']) == 0\n assert candidate(operations = ['X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', 'X++', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X', '--X']) == 0\n assert candidate(operations = ['X--', '--X', 'X++', '++X', 'X--', 'X--', '--X', '++X', 'X--', 'X--', 'X++', '++X']) == -2\n assert candidate(operations = ['X++', 'X++', '--X', '--X', 'X++', 'X--', 'X++', '--X', 'X++', 'X--', '++X', '--X']) == 0\n assert candidate(operations = ['++X', 'X--', '++X', 'X--', '++X', 'X--', '++X', 'X--', '++X', 'X--', '++X', 'X--']) == 0\n assert candidate(operations = ['X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X', 'X++', '--X']) == 0\n assert candidate(operations = ['--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++', '--X', 'X--', '++X', 'X++']) == 0\n assert candidate(operations = ['++X', '++X', '++X', '--X', 'X--', '--X', 'X--', '--X', '++X', '--X']) == -2\n", "comparison": "exact"}, "public_tests": ["[\"--X\",\"X++\",\"X++\"]", "[\"++X\",\"++X\",\"X++\"]", "[\"X++\",\"++X\",\"--X\",\"X--\"]"], "hints": ["There are only two operations to keep track of.", "Use a variable to store the value after each operation."], "metadata": {"canonical_parameter_names": ["operations"], "leetcode_dataset_entry_point": "Solution().finalValueAfterOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:07+00:00", "tests_total": 88, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function finalValueAfterOperations($operations) {", "container": "Solution", "callable": "finalValueAfterOperations", "parameters": [{"name": "operations", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2012, "task_id": "sum-of-beauty-in-the-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals:\n\n- 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1.\n- 1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not satisfied.\n- 0, if none of the previous conditions holds.\n\nReturn the sum of beauty of all nums[i] where 1 <= i <= nums.length - 2.\n\nExample 1:\n\nInput: nums = [1,2,3]\nOutput: 2\nExplanation: For each index i in the range 1 <= i <= 1:\n- The beauty of nums[1] equals 2.\n\nExample 2:\n\nInput: nums = [2,4,6,4]\nOutput: 1\nExplanation: For each index i in the range 1 <= i <= 2:\n- The beauty of nums[1] equals 1.\n- The beauty of nums[2] equals 0.\n\nExample 3:\n\nInput: nums = [3,2,1]\nOutput: 0\nExplanation: For each index i in the range 1 <= i <= 1:\n- The beauty of nums[1] equals 0.\n\nConstraints:\n\n- 3 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 100, 8, 6, 90, 101]) == 1\n assert candidate(nums = [9, 7, 5, 3, 1]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [5, 3, 4, 2, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 0\n assert candidate(nums = [2, 4, 6, 4]) == 1\n assert candidate(nums = [1, 100, 101, 102, 99]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [5, 1, 4, 3, 6, 7]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 14\n assert candidate(nums = [3, 2, 1]) == 0\n assert candidate(nums = [1, 5, 2, 5, 3, 5, 4, 5]) == 0\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 0\n assert candidate(nums = [1, 3, 2, 3, 5, 2, 6, 2]) == 1\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 0\n assert candidate(nums = [1, 2, 3]) == 2\n assert candidate(nums = [1, 3, 2, 5, 4, 6]) == 0\n assert candidate(nums = [1, 6, 4, 3, 5, 7, 8]) == 3\n assert candidate(nums = [1, 5, 2, 4, 3, 6]) == 0\n assert candidate(nums = [1, 5, 3, 7, 9, 11, 13, 2, 14]) == 3\n assert candidate(nums = [10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35, 45, 40, 50, 45]) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9, 8, 9, 10]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 94, 93, 92, 91]) == 16\n assert candidate(nums = [5, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15]) == 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]) == 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 = [10, 20, 30, 25, 24, 35, 40, 39, 45, 50]) == 6\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3]) == 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]) == 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 = [3, 1, 4, 2, 5, 8, 7, 10, 9, 12, 11]) == 2\n assert candidate(nums = [1, 5, 3, 4, 2, 8, 6, 7, 9, 11, 10]) == 3\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 24\n assert candidate(nums = [5, 3, 4, 2, 6, 1, 7, 9, 8, 10]) == 2\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8]) == 0\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 2, 45]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 9, 8, 10]) == 4\n assert candidate(nums = [10, 20, 11, 30, 12, 40, 13, 50, 14, 60, 15]) == 0\n assert candidate(nums = [1, 2, 3, 100, 2, 3, 4, 5, 6, 7]) == 6\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 0\n assert candidate(nums = [1, 10, 3, 5, 8, 12, 7, 6, 9, 11, 15, 14, 13, 16, 18, 17, 20, 19, 21, 22]) == 8\n assert candidate(nums = [90, 100, 110, 120, 115, 130, 140, 150, 145, 160, 170, 180, 175, 190, 200]) == 14\n assert candidate(nums = [1, 3, 5, 4, 6, 7, 2, 8, 9, 10]) == 6\n assert candidate(nums = [1, 2, 3, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 22\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]) == 46\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009]) == 16\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 0\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 8, 7, 10, 9, 12, 11]) == 2\n assert candidate(nums = [1, 20, 3, 40, 5, 60, 7, 80, 9, 100]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [1, 2, 3, 100, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 0\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15]) == 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, 41, 43, 45, 47, 49]) == 46\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 8\n assert candidate(nums = [1, 2, 3, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 3\n assert candidate(nums = [5, 1, 4, 3, 6, 8, 2, 9, 7, 10]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24]) == 0\n assert candidate(nums = [1, 20, 3, 15, 4, 10, 5, 25, 6]) == 0\n assert candidate(nums = [1, 3, 5, 2, 4, 6, 8, 7, 9, 11]) == 6\n assert candidate(nums = [5, 1, 4, 3, 6, 2, 8, 7, 10, 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, 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]) == 28\n assert candidate(nums = [5, 1, 3, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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]) == 0\n assert candidate(nums = [10, 20, 30, 25, 40, 35, 50, 45, 60, 55]) == 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]) == 56\n assert candidate(nums = [10, 20, 30, 25, 40, 35, 50, 45, 60]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 25\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12]) == 4\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 45, 50, 39, 41]) == 6\n assert candidate(nums = [1, 100, 50, 200, 150, 250, 200, 300, 250, 350, 300, 400, 350, 450, 400, 500, 450, 550, 500, 600]) == 0\n assert candidate(nums = [10, 20, 30, 15, 25, 35, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 14\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]) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 0\n assert candidate(nums = [30, 20, 10, 25, 15, 5, 35, 25, 15, 40, 30, 20, 50, 40, 30]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 26\n assert candidate(nums = [5, 3, 4, 2, 1, 6, 7, 8]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 20]) == 17\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 22\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 14\n assert candidate(nums = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 99999]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11]) == 8\n assert candidate(nums = [1, 2, 5, 3, 6, 4, 7, 8, 10, 9]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10]) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 0\n assert candidate(nums = [5, 8, 3, 9, 4, 10, 6, 11, 7, 12]) == 0\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 1\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991]) == 0\n assert candidate(nums = [20, 10, 30, 5, 25, 15, 35, 40, 50, 60]) == 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]) == 36\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 25\n assert candidate(nums = [1, 2, 3, 100, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 1, 101, 2, 102, 3, 103, 4, 104]) == 0\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 9, 10, 11, 12, 13, 14, 15]) == 12\n assert candidate(nums = [3, 1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) == 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]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15]) == 4\n assert candidate(nums = [1, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 22\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 0\n assert candidate(nums = [10, 11, 9, 12, 8, 13, 7, 14, 6, 15, 5, 16, 4, 17, 3, 18, 2, 19, 1, 20]) == 0\n assert candidate(nums = [5, 1, 4, 3, 6, 8, 2, 9, 7]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50]) == 11\n assert candidate(nums = [50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110, 100, 120, 110, 130, 120, 140, 130]) == 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, 22, 23, 24, 25, 26]) == 8\n assert candidate(nums = [1, 5, 3, 4, 6, 2, 7, 8, 9, 10]) == 7\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4]) == 16\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 0\n assert candidate(nums = [10, 20, 30, 29, 28, 27, 26, 25, 24, 23]) == 2\n assert candidate(nums = [1, 2, 3, 100, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 16\n assert candidate(nums = [1, 3, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20, 23, 22, 25, 24]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10]) == 21\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, 3, 2, 4, 6, 5, 7, 9, 8, 10, 11, 12, 13, 14, 15]) == 14\n assert candidate(nums = [1, 3, 5, 7, 9, 8, 11, 10, 13, 15]) == 8\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 2, 45, 50]) == 4\n assert candidate(nums = [1, 2, 100, 3, 4, 101, 5, 6, 102, 7, 8]) == 4\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20]) == 0\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 36, 45, 50, 55]) == 8\n assert candidate(nums = [5, 1, 4, 3, 6, 2, 7, 8, 10, 9]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[2,4,6,4]", "[3,2,1]"], "hints": ["Use suffix/prefix arrays.", "prefix[i] records the maximum value in range (0, i - 1) inclusive.", "suffix[i] records the minimum value in range (i + 1, n - 1) inclusive."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sumOfBeauties", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:09+00:00", "tests_total": 136, "tests_dropped": 4, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function sumOfBeauties($nums) {", "container": "Solution", "callable": "sumOfBeauties", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2014, "task_id": "longest-subsequence-repeated-k-times", "difficulty": "Hard", "problem_description": "You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nA subsequence seq is repeated k times in the string s if seq * k is a subsequence of s, where seq * k represents a string constructed by concatenating seq k times.\n\n- For example, \"bba\" is repeated 2 times in the string \"bababcba\", because the string \"bbabba\", constructed by concatenating \"bba\" 2 times, is a subsequence of the string \"bababcba\".\n\nReturn the longest subsequence repeated k times in string s. If multiple such subsequences are found, return the lexicographically largest one. If there is no such subsequence, return an empty string.\n\nExample 1:\n\nInput: s = \"letsleetcode\", k = 2\nOutput: \"let\"\nExplanation: There are two longest subsequences repeated 2 times: \"let\" and \"ete\".\n\"let\" is the lexicographically largest one.\n\nExample 2:\n\nInput: s = \"bb\", k = 2\nOutput: \"b\"\nExplanation: The longest subsequence repeated 2 times is \"b\".\n\nExample 3:\n\nInput: s = \"ab\", k = 2\nOutput: \"\"\nExplanation: There is no subsequence repeated 2 times. Empty string is returned.\n\nConstraints:\n\n- n == s.length\n- 2 <= k <= 2000\n- 2 <= n < min(2001, k * 8)\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc\",k = 3) == \"\"\n assert candidate(s = \"zzzzzzzzz\",k = 4) == \"zz\"\n assert candidate(s = \"zzzzzzzzzz\",k = 5) == \"zz\"\n assert candidate(s = \"abcabcabcabc\",k = 4) == \"abc\"\n assert candidate(s = \"abcdabcabc\",k = 3) == \"abc\"\n assert candidate(s = \"abababababab\",k = 3) == \"abab\"\n assert candidate(s = \"aabbbccccc\",k = 3) == \"c\"\n assert candidate(s = \"letsleetcode\",k = 2) == \"let\"\n assert candidate(s = \"ab\",k = 2) == \"\"\n assert candidate(s = \"zzzzzzzzzzzzzz\",k = 5) == \"zz\"\n assert candidate(s = \"aaaabbbbcccc\",k = 2) == \"cc\"\n assert candidate(s = \"aaaabbbb\",k = 2) == \"bb\"\n assert candidate(s = \"aabbccddeeff\",k = 2) == \"f\"\n assert candidate(s = \"abcabcabc\",k = 3) == \"abc\"\n assert candidate(s = \"abcdabcdabcd\",k = 3) == \"abcd\"\n assert candidate(s = \"bb\",k = 2) == \"b\"\n assert candidate(s = \"abcdeabcdeabcde\",k = 3) == \"abcde\"\n assert candidate(s = \"aabbcc\",k = 2) == \"c\"\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",k = 16) == \"qq\"\n assert candidate(s = \"mnopmnopmnop\",k = 6) == \"\"\n assert candidate(s = \"abcabcabcabc\",k = 3) == \"cab\"\n assert candidate(s = \"abcdefabcdefabcdefabcdef\",k = 4) == \"abcdef\"\n assert candidate(s = \"aabbaaccdd\",k = 3) == \"a\"\n assert candidate(s = \"abcdefgabcdefgabcdefg\",k = 3) == \"abcdefg\"\n assert candidate(s = \"kkkkkkkkkkkkkkkk\",k = 16) == \"k\"\n assert candidate(s = \"abcdefghijklaaaaaaabbbbbbbbbccccccccc\",k = 5) == \"cc\"\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\",k = 8) == \"yxyx\"\n assert candidate(s = \"abababababababababababababab\",k = 7) == \"abab\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 5) == \"zzzz\"\n assert candidate(s = \"aabaaaabbbaaa\",k = 4) == \"aa\"\n assert candidate(s = \"ababababababababababababababababab\",k = 10) == \"ba\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabc\",k = 5) == \"cabcab\"\n assert candidate(s = \"mississippi\",k = 2) == \"ssi\"\n assert candidate(s = \"ppppqqrrrrrssstttt\",k = 3) == \"t\"\n assert candidate(s = \"abcabcabcabcabcabcabc\",k = 3) == \"cabcab\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzz\",k = 10) == \"z\"\n assert candidate(s = \"abcabcabcabcabcabc\",k = 3) == \"abcabc\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 20) == \"zzz\"\n assert candidate(s = \"abababababababab\",k = 8) == \"ab\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 5) == \"abcabc\"\n assert candidate(s = \"aaabbbcccddd\",k = 3) == \"d\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",k = 10) == \"abc\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabca\",k = 5) == \"bcabca\"\n assert candidate(s = \"zzzzzzzzzzzz\",k = 5) == \"zz\"\n assert candidate(s = \"aaaabbbbccccdddddd\",k = 4) == \"d\"\n assert candidate(s = \"aabbccddeeffgg\",k = 2) == \"g\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 20) == \"z\"\n assert candidate(s = \"ababababababab\",k = 4) == \"ba\"\n assert candidate(s = \"ababababababababab\",k = 5) == \"ba\"\n assert candidate(s = \"aaaaaaaaaa\",k = 2) == \"aaaaa\"\n assert candidate(s = \"qwertyqwertyqwerty\",k = 3) == \"qwerty\"\n assert candidate(s = \"ababababababababababababababababab\",k = 16) == \"ba\"\n assert candidate(s = \"aabbccddeeefff\",k = 2) == \"f\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == \"zzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 25) == \"z\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiii\",k = 4) == \"\"\n assert candidate(s = \"abcdabcdbacdb\",k = 2) == \"cdab\"\n assert candidate(s = \"xyxyxyxyxyxy\",k = 4) == \"yx\"\n assert candidate(s = \"abcabcabcabcabcabcabcabc\",k = 4) == \"abcabc\"\n assert candidate(s = \"aabaaabaaabaaabaaab\",k = 5) == \"aab\"\n assert candidate(s = \"abcabcabcabcabc\",k = 5) == \"abc\"\n assert candidate(s = \"mmmmmmnnnnnnnnnnoooooo\",k = 5) == \"nn\"\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcd\",k = 8) == \"abcd\"\n assert candidate(s = \"zzzzzzzzzzzzz\",k = 5) == \"zz\"\n assert candidate(s = \"aaabbbcccdddeeefff\",k = 4) == \"\"\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\",k = 10) == \"zxy\"\n assert candidate(s = \"zzzzyyyxxxwww\",k = 4) == \"z\"\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 4) == \"zxy\"\n", "comparison": "exact"}, "public_tests": ["\"letsleetcode\"\n2", "\"bb\"\n2", "\"ab\"\n2"], "hints": ["The length of the longest subsequence does not exceed n/k. Do you know why?", "Find the characters that could be included in the potential answer. A character occurring more than or equal to k times can be used in the answer up to (count of the character / k) times.", "Try all possible candidates in reverse lexicographic order, and check the string for the subsequence condition."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().longestSubsequenceRepeatedK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:11+00:00", "tests_total": 89, "tests_dropped": 21, "flags": ["has_images"], "topic_tags": ["hash-table", "two-pointers", "string", "backtracking", "counting", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function longestSubsequenceRepeatedK($s, $k) {", "container": "Solution", "callable": "longestSubsequenceRepeatedK", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2016, "task_id": "maximum-difference-between-increasing-elements", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j].\n\nReturn the maximum difference. If no such i and j exists, return -1.\n\nExample 1:\n\nInput: nums = [7,1,5,4]\nOutput: 4\nExplanation:\nThe maximum difference occurs with i = 1 and j = 2, nums[j] - nums[i] = 5 - 1 = 4.\nNote that with i = 1 and j = 0, the difference nums[j] - nums[i] = 7 - 1 = 6, but i > j, so it is not valid.\n\nExample 2:\n\nInput: nums = [9,4,3,2]\nOutput: -1\nExplanation:\nThere is no i and j such that i < j and nums[i] < nums[j].\n\nExample 3:\n\nInput: nums = [1,5,2,10]\nOutput: 9\nExplanation:\nThe maximum difference occurs with i = 0 and j = 3, nums[j] - nums[i] = 10 - 1 = 9.\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 1000\n- 1 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 4, 3, 2]) == -1\n assert candidate(nums = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 2, 999999999]) == 999999998\n assert candidate(nums = [1, 100, 1, 100, 1]) == 99\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 999999999, 2, 999999998]) == 999999998\n assert candidate(nums = [10, 20, 20, 10, 30]) == 20\n assert candidate(nums = [1, 5, 2, 10]) == 9\n assert candidate(nums = [1, 1, 1, 1]) == -1\n assert candidate(nums = [1, 3, 2, 4, 3, 5]) == 4\n assert candidate(nums = [10, 1, 10, 1, 10]) == 9\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [7, 1, 5, 4]) == 4\n assert candidate(nums = [1, 3, 6, 7, 9, 14, 10]) == 13\n assert candidate(nums = [1, 2, 1, 2, 1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 11]) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 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]) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1000000000, 999999999, 1, 1000000000, 2, 999999998, 3, 1000000000, 4, 999999997]) == 999999999\n assert candidate(nums = [100, 100, 100, 100, 101, 100, 100, 100]) == 1\n assert candidate(nums = [2, 3, 10, 6, 4, 8, 1, 5, 7, 9]) == 8\n assert candidate(nums = [10, 1, 2, 8, 1, 5, 6, 3, 9]) == 8\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 18\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == 999999999\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 38\n assert candidate(nums = [3, 2, 1, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 2, 3, 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, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 29\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 1\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, 3, 2, 3, 100, 1, 2, 3, 4]) == 99\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 9\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\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == 3\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\n assert candidate(nums = [2, 1, 5, 3, 4, 8, 7, 6, 9, 10, 1]) == 9\n assert candidate(nums = [8, 11, 9, 8, 10, 12]) == 4\n assert candidate(nums = [10, 9, 10, 8, 9, 7, 8, 6, 7, 5, 6, 4, 5, 3, 4, 2, 3, 1, 2]) == 1\n assert candidate(nums = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 9\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 150]) == 50\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 9\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == 14\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 11, 12, 13]) == 12\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, 1]) == -1\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 10\n assert candidate(nums = [999999999, 1, 2, 3, 4, 5, 6, 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]) == 99\n assert candidate(nums = [3, 3, 3, 1, 2, 2, 2, 5, 5, 5]) == 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]) == 19\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12]) == 11\n assert candidate(nums = [1, 2, 3, 100, 1, 2, 3, 101, 1, 2, 3, 102, 1, 2, 3, 103, 1, 2, 3, 104]) == 103\n assert candidate(nums = [3, 3, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 5\n assert candidate(nums = [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, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 3]) == 2\n assert candidate(nums = [5, 1, 4, 3, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 20\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, 1, 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\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 18\n assert candidate(nums = [5, 2, 6, 1, 9, 4, 3, 7, 8]) == 8\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 10, 40, 35, 45, 50]) == 45\n assert candidate(nums = [1, 5, 3, 7, 9, 2, 6, 8, 4, 10]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1]) == 90\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]) == 10\n assert candidate(nums = [5, 3, 6, 7, 2, 5, 4, 8, 9, 1]) == 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]) == 20\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19\n assert candidate(nums = [5, 4, 3, 2, 1, 10]) == 9\n assert candidate(nums = [3, 3, 3, 1, 1, 1, 2, 2, 2, 5, 5, 5, 4, 4, 4]) == 4\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 9\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == 10\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 9\n assert candidate(nums = [5, 11, 2, 14, 1, 3, 10, 6, 12, 4, 15, 8]) == 14\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == -1\n assert candidate(nums = [100, 1, 101, 2, 102, 3, 103, 4, 104, 5, 105, 6, 106, 7, 107, 8, 108, 9, 109, 10]) == 108\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 = [5, 1, 9, 2, 8, 3, 7, 4, 6, 10, 1, 9, 2, 8, 3, 7, 4, 6, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 10]) == 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]) == 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\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]) == 14\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\n assert candidate(nums = [50, 20, 30, 10, 40, 60, 25, 35, 55, 45, 70, 65, 80, 75, 90, 85, 100, 95]) == 90\n assert candidate(nums = [2, 3, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 11\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 10\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996]) == 999999999\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == 9\n assert candidate(nums = [1, 2, 3, 4, 100, 5, 6, 7, 8, 9, 10]) == 99\n assert candidate(nums = [5, 2, 3, 1, 4, 7, 6, 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\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 9\n assert candidate(nums = [100, 100, 100, 100, 101, 100, 100, 100, 100, 100]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 10\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18]) == 99\n assert candidate(nums = [50, 25, 75, 100, 200, 150, 175, 225, 275, 300, 250, 325, 350]) == 325\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40]) == 40\n assert candidate(nums = [10, 5, 1, 7, 3, 6, 4]) == 6\n assert candidate(nums = [100, 1, 101, 2, 102, 3, 103, 4, 104, 5]) == 103\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9]) == 4\n", "comparison": "exact"}, "public_tests": ["[7,1,5,4]", "[9,4,3,2]", "[1,5,2,10]"], "hints": ["Could you keep track of the minimum element visited while traversing?", "We have a potential candidate for the answer if the prefix min is less than nums[i]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:16+00:00", "tests_total": 118, "tests_dropped": 5, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function maximumDifference($nums) {", "container": "Solution", "callable": "maximumDifference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2017, "task_id": "grid-game", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.\n\nBoth robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).\n\nAt the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.\n\nThe first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.\n\nExample 1:\n\nInput: grid = [[2,5,4],[1,5,1]]\nOutput: 4\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 0 + 4 + 0 = 4 points.\n\nExample 2:\n\nInput: grid = [[3,3,1],[8,5,2]]\nOutput: 4\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 3 + 1 + 0 = 4 points.\n\nExample 3:\n\nInput: grid = [[1,3,1,15],[1,3,3,1]]\nOutput: 7\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points.\n\nConstraints:\n\n- grid.length == 2\n- n == grid[r].length\n- 1 <= n <= 5 * 10^4\n- 1 <= grid[r][c] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]) == 9\n assert candidate(grid = [[1, 3, 1, 15], [1, 3, 3, 1]]) == 7\n assert candidate(grid = [[2, 5, 4], [1, 5, 1]]) == 4\n assert candidate(grid = [[10, 10, 10], [1, 1, 1]]) == 2\n assert candidate(grid = [[3, 3, 1], [8, 5, 2]]) == 4\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]]) == 9\n assert candidate(grid = [[100, 200, 300, 400, 500], [500, 400, 300, 200, 100]]) == 900\n assert candidate(grid = [[100000, 100000, 100000, 100000, 100000], [1, 1, 1, 1, 1]]) == 4\n assert candidate(grid = [[1, 10, 3, 40, 5, 60, 7, 80, 9, 100], [100, 9, 80, 7, 60, 5, 40, 3, 20, 1]]) == 256\n assert candidate(grid = [[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 = [[100000, 100000, 100000], [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], [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]]) == 19\n assert candidate(grid = [[100000, 90000, 80000, 70000, 60000, 50000], [50000, 60000, 70000, 80000, 90000, 100000]]) == 180000\n assert candidate(grid = [[23456, 12345, 67890, 45678, 34567], [76543, 89012, 12345, 67890, 54321]]) == 148135\n assert candidate(grid = [[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]]) == 84\n assert candidate(grid = [[100000, 1, 100000, 1, 100000, 1], [1, 100000, 1, 100000, 1, 100000]]) == 100002\n assert candidate(grid = [[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 = [[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]]) == 155\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]]) == 15\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 7\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]]) == 75\n assert candidate(grid = [[5, 10, 15, 20, 25, 30, 35], [35, 30, 25, 20, 15, 10, 5]]) == 90\n assert candidate(grid = [[7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [16, 15, 14, 13, 12, 11, 10, 9, 8, 7]]) == 70\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10]]) == 90\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]) == 25\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 8\n assert candidate(grid = [[5, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 5]]) == 3\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 27\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]) == 35\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 10\n assert candidate(grid = [[100000, 99999, 99998, 99997, 99996], [1, 2, 3, 4, 5]]) == 10\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]]) == 9\n assert candidate(grid = [[99999, 99998, 99997, 99996, 99995], [1, 2, 3, 4, 5]]) == 10\n assert candidate(grid = [[1, 1, 100000], [100000, 1, 1]]) == 100000\n assert candidate(grid = [[100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1], [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]]) == 200003\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]]) == 13\n assert candidate(grid = [[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]]) == 4000\n assert candidate(grid = [[100000, 99999, 99998, 99997, 99996], [1, 2, 3, 4, 5]]) == 10\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 6\n assert candidate(grid = [[10, 20, 30, 40, 50, 60], [60, 50, 40, 30, 20, 10]]) == 150\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]]) == 13\n assert candidate(grid = [[1, 100, 1], [100, 1, 100]]) == 100\n assert candidate(grid = [[1, 100000, 1, 100000, 1], [100000, 1, 100000, 1, 100000]]) == 100001\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 10\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 40\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10]]) == 90\n assert candidate(grid = [[5, 4, 3, 2, 1], [1, 2, 3, 4, 5]]) == 3\n assert candidate(grid = [[100, 200, 300, 400, 500], [500, 400, 300, 200, 100]]) == 900\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], [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]]) == 234\n assert candidate(grid = [[1, 99999, 99999, 99999, 99999], [99999, 99999, 99999, 99999, 99999]]) == 199998\n assert candidate(grid = [[5, 10, 15, 20, 25, 30], [30, 25, 20, 15, 10, 5]]) == 75\n assert candidate(grid = [[100000, 100000, 100000, 100000], [1, 1, 1, 1]]) == 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]]) == 40\n assert candidate(grid = [[100000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999]]) == 18\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 5, 5, 5, 5]]) == 10\n assert candidate(grid = [[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 = [[1, 1, 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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]]) == 23\n assert candidate(grid = [[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]]) == 84\n assert candidate(grid = [[1, 5, 2, 7, 3, 8, 4, 9], [9, 4, 8, 3, 7, 2, 5, 1]]) == 24\n assert candidate(grid = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2]]) == 3\n assert candidate(grid = [[100000, 100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000, 100000]]) == 200000\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 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, 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, 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]]) == 950\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], [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]]) == 234\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100000], [100000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 100004\n assert candidate(grid = [[5000, 5000, 5000, 5000, 5000], [1, 1, 1, 1, 1]]) == 4\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]]) == 155\n assert candidate(grid = [[100000, 100000, 100000, 100000, 100000], [1, 2, 3, 4, 5]]) == 10\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]]) == 30\n assert candidate(grid = [[1, 10, 100, 1000, 10000], [10000, 1000, 100, 10, 1]]) == 11000\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]]) == 15\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]]) == 9\n assert candidate(grid = [[5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]]) == 200\n", "comparison": "exact"}, "public_tests": ["[[2,5,4],[1,5,1]]", "[[3,3,1],[8,5,2]]", "[[1,3,1,15],[1,3,3,1]]"], "hints": ["There are n choices for when the first robot moves to the second row.", "Can we use prefix sums to help solve this problem?"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().gridGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:19+00:00", "tests_total": 75, "tests_dropped": 2, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function gridGame($grid) {", "container": "Solution", "callable": "gridGame", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2018, "task_id": "check-if-word-can-be-placed-in-crossword", "difficulty": "Medium", "problem_description": "You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.\n\nA word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:\n\n- It does not occupy a cell containing the character '#'.\n- The cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.\n- There must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.\n- There must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.\n\nGiven a string word, return true if word can be placed in board, or false otherwise.\n\nExample 1:\n\nInput: board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \"c\", \" \"]], word = \"abc\"\nOutput: true\nExplanation: The word \"abc\" can be placed as shown above (top to bottom).\n\nExample 2:\n\nInput: board = [[\" \", \"#\", \"a\"], [\" \", \"#\", \"c\"], [\" \", \"#\", \"a\"]], word = \"ac\"\nOutput: false\nExplanation: It is impossible to place the word because there will always be a space/letter above or below it.\n\nExample 3:\n\nInput: board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \" \", \"c\"]], word = \"ca\"\nOutput: true\nExplanation: The word \"ca\" can be placed as shown above (right to left).\n\nConstraints:\n\n- m == board.length\n- n == board[i].length\n- 1 <= m * n <= 2 * 10^5\n- board[i][j] will be ' ', '#', or a lowercase English letter.\n- 1 <= word.length <= max(m, n)\n- word will contain only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(board = [['#', ' ', '#'], [' ', ' ', '#'], ['#', ' ', 'c']],word = \"ca\") == True\n assert candidate(board = [['a'], ['b'], ['c'], ['d'], ['e']],word = \"abcde\") == True\n assert candidate(board = [['#', ' ', '#'], [' ', ' ', '#'], ['#', ' ', 'c']],word = \"ca\") == True\n assert candidate(board = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']],word = \"ihg\") == True\n assert candidate(board = [['a', ' ', 'a'], [' ', ' ', ' '], ['a', ' ', 'a']],word = \"aba\") == True\n assert candidate(board = [['#', ' ', '#'], ['a', 'b', 'c'], ['#', ' ', '#']],word = \"cba\") == True\n assert candidate(board = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']],word = \"def\") == True\n assert candidate(board = [['a', 'b', 'c'], ['#', '#', '#'], ['g', 'h', 'i']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' '], ['#', 'a', '#'], [' ', ' ', ' ']],word = \"a\") == True\n assert candidate(board = [['#', '#', '#'], ['#', ' ', '#'], ['#', ' ', '#']],word = \"a\") == True\n assert candidate(board = [['#', ' ', '#'], [' ', ' ', '#'], ['#', 'c', ' ']],word = \"abc\") == True\n assert candidate(board = [[' ', '#', 'a'], [' ', '#', 'c'], [' ', '#', 'a']],word = \"ac\") == False\n assert candidate(board = [[' ', '#', 'a'], [' ', '#', 'c'], [' ', '#', 'a']],word = \"ac\") == False\n assert candidate(board = [[' ', ' ', ' ', '#'], [' ', ' ', ' ', '#'], [' ', ' ', ' ', '#']],word = \"test\") == False\n assert candidate(board = [['#', '#', '#'], [' ', ' ', ' '], ['#', '#', '#']],word = \"ab\") == False\n assert candidate(board = [['#', ' ', '#'], [' ', ' ', '#'], ['#', 'c', ' ']],word = \"abc\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#']],word = \"test\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ']],word = \"abcd\") == True\n assert candidate(board = [['#', '#', 'a', '#', '#'], ['#', '#', 'b', '#', '#'], ['#', '#', 'c', '#', '#'], ['#', '#', 'd', '#', '#'], ['#', '#', '#', '#', '#']],word = \"abcd\") == True\n assert candidate(board = [[' ', ' ', '#', '#', '#', ' '], [' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ', ' '], [' ', ' ', '#', '#', '#', ' ']],word = \"test\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['a', 'b', 'c', 'd', 'e'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"abcde\") == True\n assert candidate(board = [['#', ' ', ' ', ' ', '#'], [' ', 'a', ' ', 'b', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"find\") == False\n assert candidate(board = [[' ', '#', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', ' ', ' ', '#']],word = \"abcde\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', ' ', ' ', '#'], ['#', '#', '#', '#']],word = \"a\") == False\n assert candidate(board = [['a', 'b', 'c'], ['#', '#', '#'], [' ', ' ', ' '], [' ', ' ', ' '], ['#', 'a', 'b']],word = \"abc\") == True\n assert candidate(board = [[' ', '#', ' ', ' ', '#', ' '], ['#', ' ', '#', ' ', '#', '#'], [' ', '#', ' ', '#', ' ', ' '], ['#', '#', ' ', '#', ' ', '#']],word = \"hello\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' ']],word = \"ghijkl\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', 'a', ' ', ' '], ['#', ' ', 'b', ' '], ['#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], ['#', 'a', ' ', ' '], ['#', ' ', 'b', ' '], ['#', ' ', ' ', 'c']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"hello\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"abc\") == False\n assert candidate(board = [['#', ' ', '#', ' '], [' ', ' ', ' ', ' '], [' ', ' ', '#', ' '], [' ', ' ', ' ', ' ']],word = \"ab\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', 'a', ' ', ' '], [' ', ' ', 'b', ' '], ['#', ' ', ' ', 'c']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', ' ', ' ', 'a'], ['#', '#', 'b', 'c']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], ['a', 'b', 'c', 'd', 'e'], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"abcde\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', '#', '#', ' '], [' ', ' ', ' ', ' ']],word = \"ab\") == True\n assert candidate(board = [[' ', '#', ' ', '#', ' '], ['#', 'a', '#', ' ', '#'], ['#', '#', '#', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', ' ']],word = \"abc\") == False\n assert candidate(board = [['#', '#', '#'], ['#', ' ', '#'], ['#', ' ', '#'], ['#', '#', '#']],word = \"ab\") == True\n assert candidate(board = [['#', '#', '#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', '#', '#', '#', ' ', '#'], ['#', ' ', '#', 'a', '#', ' ', '#'], ['#', ' ', '#', 'b', '#', ' ', '#'], ['#', ' ', '#', 'c', '#', ' ', '#'], ['#', '#', '#', '#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [['#', 'a', '#'], ['#', '#', '#'], ['#', 'a', '#']],word = \"aa\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], ['#', 'a', '#', 'c', '#'], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"ac\") == True\n assert candidate(board = [[' ', ' ', ' ', ' '], ['#', 'a', 'b', '#'], [' ', ' ', ' ', ' '], ['#', 'd', 'c', '#']],word = \"abcd\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', 'a', ' ', 'b', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"ab\") == False\n assert candidate(board = [['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', '#', ' ', '#', '#', ' ', '#'], ['#', ' ', 'a', ' ', ' ', ' ', '#'], ['#', '#', ' ', 'b', '#', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#']],word = \"abc\") == True\n assert candidate(board = [[' ', '#', ' ', '#', ' '], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], [' ', '#', ' ', '#', ' ']],word = \"test\") == False\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['e', 'd', 'c', 'b', 'a'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"abcde\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], ['#', 'a', 'b', 'c', '#'], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"cba\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', 'a', ' ', ' ', '#'], ['#', ' ', ' ', 'b', '#'], ['#', ' ', 'c', ' ', '#'], ['#', '#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', '#', ' ', ' '], ['#', ' ', 'a', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', 'c', ' ', '#'], [' ', ' ', '#', ' ', ' ']],word = \"play\") == False\n assert candidate(board = [[' ', '#', '#', '#', ' '], ['#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', '#', '#', '#', ' ']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' ']],word = \"mnopqr\") == True\n assert candidate(board = [['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' ']],word = \"abcdef\") == True\n assert candidate(board = [['#', '#', '#', '#'], ['#', ' ', ' ', '#'], ['#', ' ', ' ', '#'], ['#', '#', '#', '#']],word = \"word\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' '], ['#', 'a', ' ', ' ', 'b', '#'], ['#', ' ', ' ', ' ', ' ', '#'], ['#', 'c', ' ', ' ', 'd', '#'], ['#', ' ', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#', '#']],word = \"abcd\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' ']],word = \"abc\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', 'a', ' ', ' '], [' ', ' ', 'b', ' '], [' ', ' ', ' ', 'c']],word = \"abc\") == False\n assert candidate(board = [['#', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ']],word = \"world\") == True\n assert candidate(board = [['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#']],word = \"abcdef\") == False\n assert candidate(board = [['#', ' ', '#', ' ', '#', ' ', '#'], ['#', 'a', '#', 'b', '#', 'c', '#'], ['#', ' ', '#', ' ', '#', ' ', '#'], ['#', 'd', '#', 'e', '#', 'f', '#'], ['#', ' ', '#', ' ', '#', ' ', '#']],word = \"abcdef\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', 'a', '#', '#'], ['#', '#', 'b', '#', '#'], ['#', '#', 'c', '#', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"abc\") == False\n assert candidate(board = [[' ', '#', ' ', ' ', ' '], [' ', ' ', ' ', '#', ' '], [' ', '#', ' ', ' ', ' '], [' ', ' ', ' ', '#', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"abcde\") == True\n assert candidate(board = [[' ', ' ', '#', ' ', ' '], ['#', 'a', '#', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"abc\") == False\n assert candidate(board = [['a', 'b', ' ', 'd', 'e'], ['#', '#', 'c', '#', '#'], ['e', 'd', ' ', 'b', 'a'], ['#', '#', 'c', '#', '#'], ['a', 'b', ' ', 'd', 'e']],word = \"abcde\") == True\n assert candidate(board = [[' ', '#', '#', '#', ' '], ['#', 'a', '#', 'b', '#'], ['#', '#', '#', '#', '#'], ['#', 'c', '#', 'd', '#'], [' ', '#', '#', '#', ' ']],word = \"abcd\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', 'a', '#', ' '], ['#', 'b', '#', ' '], ['#', 'c', '#', ' ']],word = \"abc\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', ' ', ' ', ' ']],word = \"abcdef\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"abcd\") == False\n assert candidate(board = [['#', ' ', ' ', ' ', '#'], ['#', '#', ' ', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', '#', ' ', '#', '#'], ['#', ' ', ' ', ' ', '#']],word = \"game\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', '#', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', 'k', ' ', ' ', 'l', ' '], ['#', ' ', ' ', ' ', ' ', ' ', 'm'], ['#', '#', '#', '#', '#', '#', '#']],word = \"klm\") == True\n assert candidate(board = [['#', ' ', '#'], [' ', 'a', ' '], ['#', ' ', '#'], [' ', 'b', ' '], ['#', ' ', '#']],word = \"aba\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#']],word = \"a\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' '], ['#', 'a', '#', 'b', '#', 'c'], [' ', ' ', ' ', ' ', ' ', ' '], ['#', 'd', '#', 'e', '#', 'f'], [' ', ' ', ' ', ' ', ' ', ' ']],word = \"abcdef\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"world\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', 'j'], ['#', ' ', '#', ' ', '#', ' ', 'i'], ['#', ' ', ' ', ' ', ' ', ' ', 'h'], ['#', ' ', '#', ' ', '#', ' ', 'g'], ['#', ' ', ' ', ' ', ' ', ' ', 'f'], ['#', '#', '#', '#', '#', '#', '#']],word = \"ghij\") == False\n assert candidate(board = [['#', ' ', '#'], [' ', ' ', ' '], [' ', ' ', '#'], [' ', '#', ' ']],word = \"abc\") == True\n assert candidate(board = [['#', ' ', ' ', ' ', '#'], [' ', ' ', '#', ' ', ' '], [' ', 'a', '#', 'b', ' '], ['#', ' ', '#', ' ', '#']],word = \"abcd\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', 'a', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#']],word = \"aaa\") == True\n assert candidate(board = [['#', ' ', ' ', ' ', ' ', ' ', '#'], [' ', 'g', ' ', 'h', ' ', 'i', ' '], ['#', ' ', '#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#', '#', '#']],word = \"ghji\") == True\n assert candidate(board = [['#', '#', '#', '#'], ['#', ' ', ' ', ' '], ['#', ' ', '#', ' '], ['#', ' ', ' ', ' '], ['#', '#', '#', '#']],word = \"code\") == False\n assert candidate(board = [['#', 'a', 'b', 'c'], ['#', 'd', 'e', 'f'], ['#', 'g', 'h', 'i'], ['#', 'j', 'k', 'l']],word = \"mnop\") == False\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"abcd\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', ' '], ['#', ' ', 'a', ' ', ' '], ['#', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', ' ']],word = \"abc\") == False\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', 'a', '#', 'b', '#'], ['#', '#', '#', '#', '#'], ['#', 'c', '#', 'd', '#'], ['#', '#', '#', '#', '#']],word = \"abcd\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', '#', ' ', '#'], ['#', ' ', ' ', ' ', ' ', ' ', ' '], ['#', ' ', 'n', ' ', ' ', 'o', ' '], ['#', ' ', ' ', ' ', ' ', ' ', 'p'], ['#', '#', '#', '#', '#', '#', '#']],word = \"pon\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"abc\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', 'a', 'b', 'c', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"abc\") == True\n assert candidate(board = [[' ', ' ', ' ', '#'], [' ', ' ', ' ', '#'], [' ', ' ', ' ', '#'], [' ', ' ', ' ', '#'], ['a', 'b', 'c', 'd']],word = \"abcd\") == True\n assert candidate(board = [[' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#'], [' ', ' ', '#', ' ', ' ']],word = \"abacaba\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#', ' ', '#'], [' ', 'a', ' ', 'b', ' ', 'c', ' '], ['#', ' ', '#', ' ', '#', ' ', '#'], [' ', 'd', ' ', 'e', ' ', 'f', ' ']],word = \"abcdef\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', 'a', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', 'c', '#', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"race\") == False\n assert candidate(board = [['#', ' ', ' ', '#'], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', ' ', ' ', '#']],word = \"word\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#', ' ', '#'], ['#', 'g', '#', 'h', '#', 'i', '#'], ['#', ' ', '#', ' ', '#', ' ', '#'], ['#', 'j', '#', 'k', '#', 'l', '#'], ['#', ' ', '#', ' ', '#', ' ', '#']],word = \"ghijkl\") == False\n assert candidate(board = [['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#']],word = \"word\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', '#', ' ', ' '], [' ', ' ', ' ', ' ']],word = \"a\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#']],word = \"abcde\") == True\n assert candidate(board = [[' ', ' ', ' ', '#'], ['#', 'b', 'c', '#'], ['#', ' ', ' ', '#'], ['#', 'd', ' ', 'e']],word = \"bcde\") == True\n assert candidate(board = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#']],word = \"hello\") == False\n assert candidate(board = [['a', 'b', 'c', 'd', 'e'], ['#', '#', '#', '#', '#'], ['e', 'd', 'c', 'b', 'a'], ['#', '#', '#', '#', '#'], ['a', 'b', 'c', 'd', 'e']],word = \"abcde\") == True\n assert candidate(board = [['#', '#', '#'], ['a', ' ', 'a'], ['#', ' ', '#'], ['b', ' ', 'b'], ['#', '#', '#']],word = \"aba\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', '#', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"java\") == False\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', 'a', ' ', 'a', ' '], ['#', ' ', '#', ' ', '#'], [' ', 'b', ' ', 'b', ' '], ['#', ' ', '#', ' ', '#']],word = \"abba\") == False\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', 'a', 'b', 'c', ' '], ['#', ' ', '#', ' ', '#']],word = \"abc\") == False\n assert candidate(board = [['#', '#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', ' ', '#'], ['#', ' ', 'a', 'b', ' ', '#'], ['#', ' ', ' ', ' ', ' ', '#'], ['#', '#', '#', '#', '#', '#']],word = \"ab\") == False\n assert candidate(board = [[' ', ' ', '#', ' ', ' '], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], [' ', ' ', '#', ' ', ' ']],word = \"hello\") == True\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], ['#', ' ', 'a', ' ', '#'], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"a\") == True\n assert candidate(board = [['a', ' ', ' ', '#'], [' ', 'b', ' ', '#'], [' ', ' ', 'c', ' '], ['#', '#', '#', '#']],word = \"abc\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', ' ', ' ', '#'], [' ', ' ', ' ', ' ', ' '], ['#', ' ', '#', ' ', '#']],word = \"car\") == True\n assert candidate(board = [['#', '#', '#'], ['#', '#', '#'], ['#', '#', '#']],word = \"a\") == False\n assert candidate(board = [['a', 'b', 'c'], ['d', '#', 'e'], ['f', 'g', 'h'], ['i', 'j', 'k']],word = \"def\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], [' ', '#', 'a', '#', ' '], [' ', '#', ' ', '#', ' '], [' ', '#', 'b', '#', ' '], [' ', ' ', ' ', ' ', ' ']],word = \"ba\") == False\n assert candidate(board = [['#', ' ', '#'], ['a', ' ', 'b'], ['#', ' ', '#'], ['c', ' ', 'd'], ['#', ' ', '#']],word = \"abcd\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', '#', '#', ' '], [' ', '#', '#', ' '], [' ', ' ', ' ', ' ']],word = \"abcd\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#', ' ', '#'], ['#', ' ', '#', ' ', '#', ' ', '#']],word = \"abc\") == False\n assert candidate(board = [[' ', '#', ' ', '#', ' '], ['#', 'a', '#', 'c', '#'], [' ', '#', ' ', '#', ' '], ['#', ' ', '#', 'a', '#']],word = \"ca\") == False\n assert candidate(board = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], ['#', 'a', 'b', 'c'], [' ', ' ', ' ', ' ']],word = \"abc\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', '#'], ['#', ' ', '#', ' ', '#'], [' ', ' ', ' ', ' ', '#'], ['#', ' ', '#', ' ', '#']],word = \"abcde\") == True\n assert candidate(board = [['#', ' ', '#', ' ', '#'], [' ', 'c', 'b', 'a', ' '], ['#', ' ', '#', ' ', '#']],word = \"abc\") == False\n assert candidate(board = [[' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' '], ['#', '#', '#', '#', '#'], [' ', ' ', ' ', ' ', ' ']],word = \"cross\") == True\n", "comparison": "exact"}, "public_tests": ["[[\"#\",\" \",\"#\"],[\" \",\" \",\"#\"],[\"#\",\"c\",\" \"]]\n\"abc\"", "[[\" \",\"#\",\"a\"],[\" \",\"#\", \"c\"],[\" \",\"#\",\"a\"]]\n\"ac\"", "[[\"#\",\" \",\"#\"],[\" \",\" \",\"#\"],[\"#\",\" \",\"c\"]]\n\"ca\""], "hints": ["Check all possible placements for the word.", "There is a limited number of places where a word can start."], "metadata": {"canonical_parameter_names": ["board", "word"], "leetcode_dataset_entry_point": "Solution().placeWordInCrossword", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:22+00:00", "tests_total": 134, "tests_dropped": 13, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function placeWordInCrossword($board, $word) {", "container": "Solution", "callable": "placeWordInCrossword", "parameters": [{"name": "board", "type": "String[][]"}, {"name": "word", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2019, "task_id": "the-score-of-students-solving-math-expression", "difficulty": "Hard", "problem_description": "You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The students were instructed to get the answer of the expression by following this order of operations:\n\n1. Compute multiplication, reading from left to right; Then,\n2. Compute addition, reading from left to right.\n\nYou are given an integer array answers of length n, which are the submitted answers of the students in no particular order. You are asked to grade the answers, by following these rules:\n\n- If an answer equals the correct answer of the expression, this student will be rewarded 5 points;\n- Otherwise, if the answer could be interpreted as if the student applied the operators in the wrong order but had correct arithmetic, this student will be rewarded 2 points;\n- Otherwise, this student will be rewarded 0 points.\n\nReturn the sum of the points of the students.\n\nExample 1:\n\nInput: s = \"7+3*1*2\", answers = [20,13,42]\nOutput: 7\nExplanation: As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,13,42]\nA student might have applied the operators in this wrong order: ((7+3)*1)*2 = 20. Therefore one student is rewarded 2 points: [20,13,42]\nThe points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.\n\nExample 2:\n\nInput: s = \"3+5*2\", answers = [13,0,10,13,13,16,16]\nOutput: 19\nExplanation: The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [13,0,10,13,13,16,16]\nA student might have applied the operators in this wrong order: ((3+5)*2 = 16. Therefore two students are rewarded 2 points: [13,0,10,13,13,16,16]\nThe points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.\n\nExample 3:\n\nInput: s = \"6+0*1\", answers = [12,9,6,4,8,6]\nOutput: 10\nExplanation: The correct answer of the expression is 6.\nIf a student had incorrectly done (6+0)*1, the answer would also be 6.\nBy the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.\nThe points for the students are: [0,0,5,0,0,5]. The sum of the points is 10.\n\nConstraints:\n\n- 3 <= s.length <= 31\n- s represents a valid expression that contains only digits 0-9, '+', and '*' only.\n- All the integer operands in the expression are in the inclusive range [0, 9].\n- 1 <= The count of all operators ('+' and '*') in the math expression <= 15\n- Test data are generated such that the correct answer of the expression is in the range of [0, 1000].\n- Test data are generated such that value never exceeds 10^9 in intermediate steps of multiplication.\n- n == answers.length\n- 1 <= n <= 10^4\n- 0 <= answers[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"3+5*2\",answers = [13, 0, 10, 13, 13, 16, 16]) == 19\n assert candidate(s = \"1+2*3+4*5\",answers = [14, 23, 13, 47, 23, 53]) == 2\n assert candidate(s = \"7+3*1*2\",answers = [20, 13, 42]) == 7\n assert candidate(s = \"5*4+3+2\",answers = [27, 20, 17, 25, 20, 30]) == 5\n assert candidate(s = \"5*3+2*2\",answers = [19, 17, 15, 13, 21]) == 5\n assert candidate(s = \"9*7+3*8\",answers = [78, 108, 70, 63, 136, 54, 110, 39, 103, 97]) == 0\n assert candidate(s = \"1+2*3+4\",answers = [11, 13, 15, 9]) == 9\n assert candidate(s = \"6+0*1\",answers = [12, 9, 6, 4, 8, 6]) == 10\n assert candidate(s = \"1+2*3+4\",answers = [23, 18, 21, 9, 10, 17, 14, 22, 20, 15]) == 4\n assert candidate(s = \"9+8*7+6*5+4*3+2*1\",answers = [268, 280, 292, 304, 316, 328, 340, 352, 364, 376]) == 0\n assert candidate(s = \"5+6*2+7*3+8*1\",answers = [63, 104, 80, 77, 63, 120]) == 2\n assert candidate(s = \"1*5+2*7+3*6+4\",answers = [56, 50, 47, 53, 58, 45, 51, 46, 49, 52]) == 2\n assert candidate(s = \"2*9+5*6*7+8\",answers = [226, 488, 628, 624, 226, 508]) == 0\n assert candidate(s = \"4*6+3*2+5*1+7*8+9*0\",answers = [74, 76, 78, 80, 82, 84, 86, 88, 90, 92]) == 2\n assert candidate(s = \"7+6*5+4*3+2*1\",answers = [181, 175, 169, 163, 157, 151, 145, 139, 133, 127]) == 4\n assert candidate(s = \"1*2*3*4*5+6\",answers = [126, 12, 36, 24, 126, 126]) == 15\n assert candidate(s = \"9*8+7*6+5*4\",answers = [203, 230, 247, 274, 263, 290, 307, 334, 343, 370]) == 0\n assert candidate(s = \"1+2*3+4*5+6\",answers = [71, 51, 83, 47, 79, 53, 77, 67, 89, 57, 59, 73, 41, 87, 85, 61, 65, 75]) == 20\n assert candidate(s = \"9+8*2*4+1\",answers = [153, 73, 161, 177, 145, 153]) == 4\n assert candidate(s = \"8*7+9*6+4\",answers = [158, 202, 156, 134, 164, 148, 162, 174]) == 0\n assert candidate(s = \"9+7*8+5*4\",answers = [155, 143, 139, 147, 135, 149, 153, 151, 157]) == 0\n assert candidate(s = \"7*3+1*2*4+6*5\",answers = [62, 122, 86, 74, 62, 86]) == 2\n assert candidate(s = \"1+2+3+4+5+6+7+8+9\",answers = [45, 44, 46, 43, 47, 42, 48, 41, 49]) == 5\n assert candidate(s = \"5*5*5+4*4*4+3*3*3+2*2*2+1*1*1\",answers = [657, 681, 679, 678, 680, 677, 676, 675, 674, 673, 672, 671, 670, 669, 668, 667, 666, 665, 664, 663]) == 14\n assert candidate(s = \"1*2*3+4*5+6*7+8*9\",answers = [204, 205, 203, 206, 202, 207, 201]) == 2\n assert candidate(s = \"8*9+7*6+5*4+3*2\",answers = [167, 173, 179, 185, 191, 197, 203, 209, 215, 221]) == 0\n assert candidate(s = \"3+8*5*2+7+6*4\",answers = [173, 185, 197, 209, 221, 233, 245, 257, 269, 281]) == 0\n assert candidate(s = \"5*6+7*2+8*1+9\",answers = [104, 100, 111, 110, 115, 120, 108, 116, 106, 118]) == 0\n assert candidate(s = \"2*3+4*5+6\",answers = [30, 46, 28, 52, 34, 38, 40, 42, 44, 50]) == 4\n assert candidate(s = \"3*4+2*5+1*6+8\",answers = [58, 54, 59, 65, 62, 68, 63, 66, 57, 60]) == 2\n assert candidate(s = \"5+9*3+8*2\",answers = [89, 71, 106, 58, 95, 125, 86, 92, 91]) == 2\n assert candidate(s = \"8*7+6*5+4*3+2*1\",answers = [134, 135, 133, 136, 132, 137, 131]) == 0\n assert candidate(s = \"1*2*3*4*5+6+7+8+9\",answers = [120, 150, 315, 369, 225, 252, 360, 270, 288]) == 7\n assert candidate(s = \"6+3*5*2+9*1\",answers = [48, 39, 69, 102, 57, 78]) == 0\n assert candidate(s = \"4*3+2*8+1*7+6\",answers = [63, 59, 66, 71, 60, 69, 64, 73, 68, 61]) == 0\n assert candidate(s = \"2*9+8*7+6*5+4*3\",answers = [192, 172, 162, 152, 187, 202, 207, 182, 197, 177, 167, 157, 184, 169, 159, 179, 199, 174, 189]) == 4\n assert candidate(s = \"1*2+3*4+5*6+7*8+9\",answers = [159, 173, 187, 201, 215, 229, 243, 257, 271, 285]) == 4\n assert candidate(s = \"6+5*4+3*2+1\",answers = [55, 51, 47, 43, 39, 35, 31, 27, 23, 19]) == 4\n assert candidate(s = \"9+1*8+2*3+7*4\",answers = [77, 81, 90, 83, 94, 100, 88, 97, 91, 105]) == 2\n assert candidate(s = \"9*8+7*6+5*4+3*2+1*0\",answers = [168, 172, 176, 180, 184, 188, 192, 196, 200, 204]) == 2\n assert candidate(s = \"2+3*4+5*6+7\",answers = [157, 172, 187, 202, 217, 232, 247, 262, 277, 292]) == 6\n assert candidate(s = \"9*0+8*1+7*2\",answers = [23, 15, 16, 8, 3, 17, 24, 22, 18, 9]) == 5\n assert candidate(s = \"1*2+3*4+5*6+7*8+9*0\",answers = [120, 93, 115, 132, 108, 114, 102, 130, 128, 124, 123, 125, 126, 127, 129, 121, 122, 131, 133, 134]) == 2\n assert candidate(s = \"1+1*1+1*1+1*1+1*1+1*1+1*1+1*1\",answers = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == 25\n assert candidate(s = \"9*8+7*6+5*4+3*2+1\",answers = [383, 410, 437, 464, 491, 518, 545, 572, 599, 626]) == 4\n assert candidate(s = \"3*3+2*2+1*1\",answers = [15, 12, 13, 14, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 7\n assert candidate(s = \"7*1+6*2+5*3\",answers = [47, 37, 41, 43, 49, 53, 55, 57, 61, 63]) == 2\n assert candidate(s = \"4*1*3+5*2\",answers = [22, 14, 16, 17, 18, 19, 20, 21, 23]) == 5\n assert candidate(s = \"9+8*7+6*5+4*3+2*1\",answers = [383, 357, 347, 358, 356, 365, 359, 348, 350, 351, 349, 352, 353, 354, 355, 346, 345, 364, 366, 367]) == 2\n assert candidate(s = \"8*2+3*9+4*1+5\",answers = [69, 76, 108, 98, 63, 110, 95, 80, 73, 83]) == 0\n assert candidate(s = \"8+9*2+3*4*5+6\",answers = [222, 185, 223, 197, 196, 231, 229, 226, 220, 225, 221, 228, 227, 219, 218, 217, 230, 232, 233, 234]) == 2\n assert candidate(s = \"9*9+8*8+7*7+6*6\",answers = [320, 311, 314, 317, 323, 332, 335, 338, 341, 347, 344, 350, 353, 356, 359, 365, 368, 371, 374, 380, 383, 386, 389, 395, 392, 398]) == 0\n assert candidate(s = \"8*9+7*6+5*4+3*2+1\",answers = [163, 177, 181, 185, 189, 193, 197, 201, 205, 209]) == 4\n assert candidate(s = \"9*2+1*6+4*5+8*3\",answers = [124, 122, 121, 126, 125, 123, 127, 120, 128, 119]) == 2\n assert candidate(s = \"2+3*4+5*6\",answers = [106, 110, 74, 86, 62, 140, 106, 128]) == 0\n assert candidate(s = \"9*3+8*2+7*1\",answers = [55, 63, 95, 100, 111, 120, 123, 115, 116, 119, 102, 87, 90, 83, 93]) == 0\n assert candidate(s = \"1*9+8*2+3*7+5\",answers = [85, 100, 80, 88, 93, 95, 91, 107, 105, 98]) == 0\n assert candidate(s = \"1*2+3*4+5*6\",answers = [101, 39, 45, 81, 29, 143, 51, 17, 135, 65]) == 0\n assert candidate(s = \"6*4+3*2+1*5+7\",answers = [45, 43, 47, 52, 46, 44, 48, 50, 49, 51]) == 2\n assert candidate(s = \"2*3+4*5+6*7+8*9+0\",answers = [234, 248, 262, 276, 290, 304, 318, 332, 346, 360]) == 0\n assert candidate(s = \"2+3*4+5*6+7\",answers = [107, 110, 113, 104, 116, 109, 115, 108, 111, 112]) == 2\n assert candidate(s = \"8*7+4*2+1\",answers = [65, 100, 57, 60, 93, 120, 81, 65, 96, 104]) == 10\n assert candidate(s = \"2*3+5*6+7\",answers = [41, 101, 38, 47, 110, 83, 37, 53, 61, 56]) == 2\n assert candidate(s = \"9*8+7*6+5*4+3*2+1\",answers = [234, 197, 207, 198, 209, 205, 214, 218, 216, 215, 213, 212, 210, 211, 208, 206, 204, 203, 202, 201]) == 2\n assert candidate(s = \"5*5+4*4+3*3+2*2\",answers = [105, 85, 135, 90, 110, 100, 120, 115, 130, 95, 101, 125, 80, 91, 87, 83, 89]) == 6\n assert candidate(s = \"1*3+2*4+5*6+7*8\",answers = [109, 113, 137, 141, 145, 149, 153, 161, 165, 169]) == 2\n assert candidate(s = \"3*6+2*7+8*9\",answers = [134, 132, 136, 130, 128, 138, 140, 126, 142]) == 2\n assert candidate(s = \"1*2+3*4+5*6+7*8\",answers = [497, 524, 551, 578, 605, 632, 659, 686, 713, 740]) == 2\n assert candidate(s = \"1+2+3+4+5+6+7+8+9+0\",answers = [45, 46, 44, 43, 47, 48, 42]) == 5\n assert candidate(s = \"4*2+1*3+5*6+7\",answers = [51, 49, 67, 51, 67, 69]) == 0\n assert candidate(s = \"9*1+8*2+7*3+6\",answers = [92, 110, 113, 92, 113, 110]) == 0\n assert candidate(s = \"8+7*6+5*4+3*2+1*0\",answers = [177, 185, 184, 186, 183, 182, 181, 180, 179, 178, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167]) == 2\n assert candidate(s = \"1*2+3*4+5*6+7*8+9*0\",answers = [88, 92, 96, 100, 104, 108, 112, 116, 120, 124]) == 7\n assert candidate(s = \"8*3+2*7+9*5+4*1\",answers = [124, 116, 127, 119, 118, 120, 121, 117, 126, 122]) == 2\n assert candidate(s = \"9*8+7*6+5*4+3*2+1*0\",answers = [162, 178, 194, 210, 226, 242, 258, 274, 290, 306]) == 4\n assert candidate(s = \"3*5+2*4+6\",answers = [33, 50, 38, 46, 40, 64, 54, 28, 58, 42]) == 0\n assert candidate(s = \"9+8*7+6*5+4*3+2*1+0\",answers = [389, 388, 390, 391, 387, 392, 386]) == 2\n assert candidate(s = \"1+2*3+4*5+6*7+8*9\",answers = [528, 526, 527, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545]) == 10\n assert candidate(s = \"2*3+4*5+6*7\",answers = [65, 51, 47, 45, 41, 37, 35, 31, 29, 27]) == 0\n assert candidate(s = \"5*3*6+2*8+1\",answers = [91, 100, 110, 120, 95, 93, 99, 105, 94, 101, 97, 96, 102, 98, 103, 92, 90, 104, 106, 91]) == 0\n assert candidate(s = \"3+5*6+7*2+8\",answers = [109, 119, 80, 103, 109, 119]) == 2\n assert candidate(s = \"8*3+4*2+5\",answers = [37, 70, 100, 61, 51, 41, 37]) == 12\n assert candidate(s = \"6*3+4*2+1+5*3\",answers = [44, 53, 49, 41, 57, 61, 56, 67, 65, 46]) == 2\n assert candidate(s = \"3*3*3*3*3+2+1\",answers = [244, 242, 243, 245, 246, 247]) == 5\n assert candidate(s = \"8*6+5*3+2*1\",answers = [56, 51, 106, 103, 83, 96, 90, 113, 78, 111, 54, 122]) == 0\n assert candidate(s = \"7*6+5*4+3*2+1*0\",answers = [62, 57, 67, 72, 69, 75, 77, 74, 71, 52, 64, 76, 78, 73, 53, 65, 70, 66, 68, 61, 56, 60, 59, 58, 55, 54, 51, 50, 49]) == 7\n assert candidate(s = \"8*3+7*2+9*4\",answers = [118, 154, 106, 94, 210, 142, 126, 130, 182, 166]) == 0\n assert candidate(s = \"5*3+2*8+9*7\",answers = [108, 131, 128, 136, 119, 131, 142, 123, 127, 131]) == 0\n assert candidate(s = \"3*8+2*6+5*9+1*7\",answers = [140, 138, 137, 142, 141, 139, 143, 136, 144, 145]) == 2\n assert candidate(s = \"1+2*3+4*5+6*7+8*9\",answers = [277, 278, 276, 275, 279, 280, 274]) == 2\n assert candidate(s = \"4*4+3*3+2*2+1*1\",answers = [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]) == 7\n assert candidate(s = \"9*3+8*2+7*6+5\",answers = [139, 167, 145, 151, 146, 158, 147, 148, 152, 150]) == 2\n assert candidate(s = \"7*2+3*9+1*6+5*8\",answers = [155, 148, 149, 151, 147, 152, 150, 146, 154, 153]) == 0\n assert candidate(s = \"1+2*3+4*5+6\",answers = [78, 54, 72, 86, 94, 104, 118, 126, 138, 158]) == 0\n assert candidate(s = \"3*6+2*5+4*7\",answers = [54, 59, 66, 74, 81, 83, 88, 60, 71, 78]) == 0\n assert candidate(s = \"8*7+5*6+2\",answers = [65, 106, 122, 158, 162, 232, 250, 188, 210, 202]) == 0\n assert candidate(s = \"7*6+5*3+2*4+1\",answers = [74, 78, 83, 79, 87, 81, 85, 76, 82, 86]) == 0\n assert candidate(s = \"5+4*3+2*1+0\",answers = [19, 25, 17, 15, 23, 27, 30]) == 7\n assert candidate(s = \"2+5*3*2+4\",answers = [40, 42, 38, 50, 36, 74, 68, 54, 82, 80]) == 7\n assert candidate(s = \"5*9+4*8+3*7\",answers = [102, 105, 116, 121, 135, 132, 93, 113, 143, 150]) == 0\n assert candidate(s = \"4+3*2*1+5\",answers = [21, 19, 17, 15, 13, 11, 9, 7, 5, 3]) == 7\n assert candidate(s = \"3*3+2*2+1*1\",answers = [14, 16, 12, 18, 15, 13, 17, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 19]) == 7\n assert candidate(s = \"6+7*8+9*2\",answers = [169, 137, 154, 131, 166, 152, 145, 158, 170]) == 0\n assert candidate(s = \"1*2*3*4*5\",answers = [120, 20, 60, 30, 10, 240, 15, 40, 6]) == 5\n assert candidate(s = \"5+9*8+7*6+4*3+2*1\",answers = [279, 283, 287, 291, 295, 299, 303, 307, 311, 315]) == 2\n", "comparison": "exact"}, "public_tests": ["\"7+3*1*2\"\n[20,13,42]", "\"3+5*2\"\n[13,0,10,13,13,16,16]", "\"6+0*1\"\n[12,9,6,4,8,6]"], "hints": ["The number of operators in the equation is less. Could you find the right answer then generate all possible answers using different orders of operations?", "Divide the equation into blocks separated by the operators, and use memoization on the results of blocks for optimization.", "Use set and the max limit of the answer for further optimization."], "metadata": {"canonical_parameter_names": ["s", "answers"], "leetcode_dataset_entry_point": "Solution().scoreOfStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:24+00:00", "tests_total": 109, "tests_dropped": 4, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "math", "string", "dynamic-programming", "stack", "memoization"]}, "language": "php", "interface": {"raw_signature": "function scoreOfStudents($s, $answers) {", "container": "Solution", "callable": "scoreOfStudents", "parameters": [{"name": "s", "type": "String"}, {"name": "answers", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2022, "task_id": "convert-1d-array-into-2d-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original.\n\nThe elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.\n\nReturn an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.\n\nExample 1:\n\nInput: original = [1,2,3,4], m = 2, n = 2\nOutput: [[1,2],[3,4]]\nExplanation: The constructed 2D array should contain 2 rows and 2 columns.\nThe first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.\nThe second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.\n\nExample 2:\n\nInput: original = [1,2,3], m = 1, n = 3\nOutput: [[1,2,3]]\nExplanation: The constructed 2D array should contain 1 row and 3 columns.\nPut all three elements in original into the first row of the constructed 2D array.\n\nExample 3:\n\nInput: original = [1,2], m = 1, n = 1\nOutput: []\nExplanation: There are 2 elements in original.\nIt is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.\n\nConstraints:\n\n- 1 <= original.length <= 5 * 10^4\n- 1 <= original[i] <= 10^5\n- 1 <= m, n <= 4 * 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(original = [5, 6, 7, 8, 9, 10, 11, 12],m = 4,n = 2) == [[5, 6], [7, 8], [9, 10], [11, 12]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9],m = 3,n = 3) == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n assert candidate(original = [9, 10, 11, 12, 13, 14],m = 2,n = 3) == [[9, 10, 11], [12, 13, 14]]\n assert candidate(original = [1, 2],m = 1,n = 1) == []\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8],m = 4,n = 2) == [[1, 2], [3, 4], [5, 6], [7, 8]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],m = 3,n = 4) == [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]\n assert candidate(original = [3, 3, 3, 3, 3, 3],m = 2,n = 3) == [[3, 3, 3], [3, 3, 3]]\n assert candidate(original = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 3,n = 3) == [[9, 8, 7], [6, 5, 4], [3, 2, 1]]\n assert candidate(original = [1, 2, 3, 4, 5, 6],m = 2,n = 3) == [[1, 2, 3], [4, 5, 6]]\n assert candidate(original = [10, 20, 30, 40, 50],m = 5,n = 1) == [[10], [20], [30], [40], [50]]\n assert candidate(original = [5, 6, 7, 8, 9, 10],m = 2,n = 3) == [[5, 6, 7], [8, 9, 10]]\n assert candidate(original = [42, 43, 44, 45, 46, 47, 48, 49, 50],m = 3,n = 3) == [[42, 43, 44], [45, 46, 47], [48, 49, 50]]\n assert candidate(original = [1, 2, 3, 4],m = 2,n = 2) == [[1, 2], [3, 4]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 2,n = 5) == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]\n assert candidate(original = [25, 26, 27],m = 3,n = 1) == [[25], [26], [27]]\n assert candidate(original = [1, 2, 3],m = 1,n = 3) == [[1, 2, 3]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],m = 4,n = 4) == [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]\n assert candidate(original = [5, 6, 7, 8, 9],m = 1,n = 5) == [[5, 6, 7, 8, 9]]\n assert candidate(original = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24],m = 5,n = 2) == [[15, 16], [17, 18], [19, 20], [21, 22], [23, 24]]\n assert candidate(original = [1],m = 1,n = 1) == [[1]]\n assert candidate(original = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41],m = 3,n = 4) == [[30, 31, 32, 33], [34, 35, 36, 37], [38, 39, 40, 41]]\n assert candidate(original = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],m = 4,n = 3) == [[10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21]]\n assert candidate(original = [5, 6, 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],m = 6,n = 6) == []\n assert candidate(original = [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 = 7,n = 5) == []\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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 = 5,n = 6) == [[1, 2, 3, 4, 5, 6], [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(original = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],m = 5,n = 2) == [[1000, 2000], [3000, 4000], [5000, 6000], [7000, 8000], [9000, 10000]]\n assert candidate(original = [1, 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 = 5,n = 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]]\n assert candidate(original = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],m = 3,n = 4) == [[100, 200, 300, 400], [500, 600, 700, 800], [900, 1000, 1100, 1200]]\n assert candidate(original = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],m = 10,n = 5) == [[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 assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 5,n = 4) == [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]]\n assert candidate(original = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49],m = 5,n = 5) == [[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]]\n assert candidate(original = [12345],m = 1,n = 1) == [[12345]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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],m = 5,n = 8) == [[1, 2, 3, 4, 5, 6, 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(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 3,n = 5) == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]\n assert candidate(original = [99, 88, 77, 66, 55, 44, 33, 22, 11],m = 3,n = 3) == [[99, 88, 77], [66, 55, 44], [33, 22, 11]]\n assert candidate(original = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 4,n = 4) == [[5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]]\n assert candidate(original = [42],m = 1,n = 1) == [[42]]\n assert candidate(original = [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],m = 5,n = 5) == []\n assert candidate(original = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160],m = 5,n = 4) == [[8, 16, 24, 32], [40, 48, 56, 64], [72, 80, 88, 96], [104, 112, 120, 128], [136, 144, 152, 160]]\n assert candidate(original = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],m = 10,n = 5) == [[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 assert candidate(original = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 3,n = 3) == [[9, 8, 7], [6, 5, 4], [3, 2, 1]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 10,n = 1) == [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],m = 6,n = 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]]\n assert candidate(original = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240],m = 6,n = 4) == [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160], [170, 180, 190, 200], [210, 220, 230, 240]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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],m = 6,n = 10) == [[1, 2, 3, 4, 5, 6, 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]]\n assert candidate(original = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 3,n = 5) == [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1]]\n assert candidate(original = [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],m = 5,n = 5) == [[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(original = [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 = 10,n = 10) == []\n assert candidate(original = [1, 1, 1, 1, 1, 1, 1, 1, 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 = 6,n = 5) == []\n assert candidate(original = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],m = 2,n = 5) == [[1000, 2000, 3000, 4000, 5000], [6000, 7000, 8000, 9000, 10000]]\n assert candidate(original = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],m = 3,n = 4) == [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]]\n assert candidate(original = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],m = 10,n = 10) == []\n assert candidate(original = [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],m = 5,n = 6) == [[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]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],m = 7,n = 7) == []\n assert candidate(original = [5, 15, 25, 35, 45, 55, 65, 75],m = 2,n = 4) == [[5, 15, 25, 35], [45, 55, 65, 75]]\n assert candidate(original = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],m = 5,n = 3) == [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60], [65, 70, 75]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],m = 10,n = 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]]\n assert candidate(original = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 10,n = 10) == []\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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],m = 6,n = 10) == [[1, 2, 3, 4, 5, 6, 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]]\n assert candidate(original = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80],m = 4,n = 4) == [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [65, 70, 75, 80]]\n assert candidate(original = [1, 2, 3, 4, 5],m = 1,n = 5) == [[1, 2, 3, 4, 5]]\n assert candidate(original = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42],m = 7,n = 3) == [[42, 42, 42], [42, 42, 42], [42, 42, 42], [42, 42, 42], [42, 42, 42], [42, 42, 42], [42, 42, 42]]\n assert candidate(original = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90],m = 6,n = 3) == [[5, 10, 15], [20, 25, 30], [35, 40, 45], [50, 55, 60], [65, 70, 75], [80, 85, 90]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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],m = 8,n = 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]]\n assert candidate(original = [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],m = 6,n = 10) == [[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]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 4,n = 5) == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]\n assert candidate(original = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],m = 4,n = 4) == [[1, 3, 5, 7], [9, 11, 13, 15], [17, 19, 21, 23], [25, 27, 29, 31]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 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 = 5,n = 6) == [[1, 2, 3, 4, 5, 6], [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(original = [1, 2, 3, 4, 5, 6, 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 = 10,n = 10) == [[1, 2, 3, 4, 5, 6, 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]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27],m = 3,n = 9) == [[1, 2, 3, 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(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],m = 4,n = 4) == [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]\n assert candidate(original = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],m = 4,n = 5) == [[3, 6, 9, 12, 15], [18, 21, 24, 27, 30], [33, 36, 39, 42, 45], [48, 51, 54, 57, 60]]\n assert candidate(original = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],m = 2,n = 5) == [[5, 10, 15, 20, 25], [30, 35, 40, 45, 50]]\n assert candidate(original = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80],m = 4,n = 5) == [[99, 98, 97, 96, 95], [94, 93, 92, 91, 90], [89, 88, 87, 86, 85], [84, 83, 82, 81, 80]]\n assert candidate(original = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400],m = 4,n = 6) == [[100, 200, 300, 400, 500, 600], [700, 800, 900, 1000, 1100, 1200], [1300, 1400, 1500, 1600, 1700, 1800], [1900, 2000, 2100, 2200, 2300, 2400]]\n assert candidate(original = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160],m = 4,n = 4) == [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]\n assert candidate(original = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],m = 2,n = 5) == [[1000, 2000, 3000, 4000, 5000], [6000, 7000, 8000, 9000, 10000]]\n assert candidate(original = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020, 2121, 2222, 2323, 2424, 2525],m = 5,n = 5) == [[101, 202, 303, 404, 505], [606, 707, 808, 909, 1010], [1111, 1212, 1313, 1414, 1515], [1616, 1717, 1818, 1919, 2020], [2121, 2222, 2323, 2424, 2525]]\n assert candidate(original = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986],m = 3,n = 5) == [[100000, 99999, 99998, 99997, 99996], [99995, 99994, 99993, 99992, 99991], [99990, 99989, 99988, 99987, 99986]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],m = 5,n = 10) == [[1, 2, 3, 4, 5, 6, 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(original = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],m = 5,n = 3) == [[10, 20, 30], [40, 50, 60], [70, 80, 90], [100, 110, 120], [130, 140, 150]]\n assert candidate(original = [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],m = 9,n = 4) == [[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]]\n assert candidate(original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],m = 2,n = 13) == [[1, 2, 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(original = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],m = 5,n = 3) == [[100, 200, 300], [400, 500, 600], [700, 800, 900], [1000, 1100, 1200], [1300, 1400, 1500]]\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n2\n2", "[1,2,3]\n1\n3", "[1,2]\n1\n1"], "hints": ["When is it possible to convert original into a 2D array and when is it impossible?", "It is possible if and only if m * n == original.length", "If it is possible to convert original to a 2D array, keep an index i such that original[i] is the next element to add to the 2D array."], "metadata": {"canonical_parameter_names": ["original", "m", "n"], "leetcode_dataset_entry_point": "Solution().construct2DArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:29+00:00", "tests_total": 85, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function construct2DArray($original, $m, $n) {", "container": "Solution", "callable": "construct2DArray", "parameters": [{"name": "original", "type": "Integer[]"}, {"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2023, "task_id": "number-of-pairs-of-strings-with-concatenation-equal-to-target", "difficulty": "Medium", "problem_description": "Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.\n\nExample 1:\n\nInput: nums = [\"777\",\"7\",\"77\",\"77\"], target = \"7777\"\nOutput: 4\nExplanation: Valid pairs are:\n- (0, 1): \"777\" + \"7\"\n- (1, 0): \"7\" + \"777\"\n- (2, 3): \"77\" + \"77\"\n- (3, 2): \"77\" + \"77\"\n\nExample 2:\n\nInput: nums = [\"123\",\"4\",\"12\",\"34\"], target = \"1234\"\nOutput: 2\nExplanation: Valid pairs are:\n- (0, 1): \"123\" + \"4\"\n- (2, 3): \"12\" + \"34\"\n\nExample 3:\n\nInput: nums = [\"1\",\"1\",\"1\"], target = \"11\"\nOutput: 6\nExplanation: Valid pairs are:\n- (0, 1): \"1\" + \"1\"\n- (1, 0): \"1\" + \"1\"\n- (0, 2): \"1\" + \"1\"\n- (2, 0): \"1\" + \"1\"\n- (1, 2): \"1\" + \"1\"\n- (2, 1): \"1\" + \"1\"\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i].length <= 100\n- 2 <= target.length <= 100\n- nums[i] and target consist of digits.\n- nums[i] and target do not have leading zeros.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = ['777', '7', '77', '77'],target = \"7777\") == 4\n assert candidate(nums = ['10', '11', '1'],target = \"101\") == 1\n assert candidate(nums = ['1234', '56', '78', '9'],target = \"123456\") == 1\n assert candidate(nums = ['99', '9', '999'],target = \"9999\") == 2\n assert candidate(nums = ['50', '2', '5', '0'],target = \"5025\") == 0\n assert candidate(nums = ['10', '100', '1'],target = \"10100\") == 1\n assert candidate(nums = ['123', '4', '12', '34'],target = \"1234\") == 2\n assert candidate(nums = ['50', '5', '500'],target = \"505\") == 1\n assert candidate(nums = ['1', '1', '1'],target = \"11\") == 6\n assert candidate(nums = ['123', '234', '345', '456', '567', '678', '789', '890'],target = \"123234\") == 1\n assert candidate(nums = ['66', '666', '6666', '66666'],target = \"66666666\") == 2\n assert candidate(nums = ['33', '3', '333', '3333', '33'],target = \"333333\") == 4\n assert candidate(nums = ['555', '55', '5', '5555'],target = \"555555\") == 2\n assert candidate(nums = ['1', '1', '2', '2', '3', '3'],target = \"11\") == 2\n assert candidate(nums = ['78', '87', '7', '8'],target = \"7887\") == 1\n assert candidate(nums = ['7777', '777', '77', '7'],target = \"7777777\") == 2\n assert candidate(nums = ['0', '00', '000', '0000'],target = \"0000\") == 2\n assert candidate(nums = ['001', '010', '100', '1'],target = \"1001\") == 2\n assert candidate(nums = ['15', '51', '1515', '151', '515'],target = \"151515\") == 3\n assert candidate(nums = ['10', '01', '100', '001', '1000', '0001'],target = \"1001\") == 1\n assert candidate(nums = ['789', '897', '978', '78', '89', '97'],target = \"789897\") == 1\n assert candidate(nums = ['10', '20', '30', '40', '50'],target = \"1020\") == 1\n assert candidate(nums = ['1234', '5678', '4321', '8765'],target = \"12345678\") == 1\n assert candidate(nums = ['111', '222', '333', '444', '555', '666', '777', '888', '999'],target = \"111222\") == 1\n assert candidate(nums = ['5', '55', '555', '5555', '55555'],target = \"555555\") == 4\n assert candidate(nums = ['9', '99', '999', '9999'],target = \"999999\") == 2\n assert candidate(nums = ['18', '81', '181', '818', '1818'],target = \"181818\") == 3\n assert candidate(nums = ['20', '02', '2', '2002'],target = \"200202\") == 1\n assert candidate(nums = ['5', '55', '555', '5555'],target = \"55555\") == 4\n assert candidate(nums = ['9', '99', '999', '9999', '99999'],target = \"999999\") == 4\n assert candidate(nums = ['90', '09', '9', '0'],target = \"9009\") == 1\n assert candidate(nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9'],target = \"12\") == 1\n assert candidate(nums = ['111', '222', '333', '111', '222'],target = \"111222\") == 4\n assert candidate(nums = ['222', '2222', '2', '22', '22222'],target = \"22222222\") == 2\n assert candidate(nums = ['1234', '5678', '12', '34', '56', '78'],target = \"12345678\") == 1\n assert candidate(nums = ['111', '222', '333', '444'],target = \"111222\") == 1\n assert candidate(nums = ['98765', '4321', '9876', '54321'],target = \"987654321\") == 2\n assert candidate(nums = ['90', '909', '09', '9'],target = \"90909\") == 2\n assert candidate(nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '09'],target = \"09\") == 1\n assert candidate(nums = ['100000', '10000', '1000', '100', '10', '1'],target = \"10000010000\") == 1\n assert candidate(nums = ['0', '0', '0', '0'],target = \"00\") == 12\n assert candidate(nums = ['8', '88', '888', '8888'],target = \"88888\") == 4\n assert candidate(nums = ['123', '456', '789', '0', '1', '2'],target = \"123456\") == 1\n assert candidate(nums = ['111111', '11111', '1111', '111', '11'],target = \"111111111\") == 4\n assert candidate(nums = ['100', '200', '300', '400', '500'],target = \"100200\") == 1\n assert candidate(nums = ['123', '234', '345', '456', '567'],target = \"123234\") == 1\n assert candidate(nums = ['1234', '4321', '2341', '3412', '5678', '8765', '6785', '7856'],target = \"12344321\") == 1\n assert candidate(nums = ['123', '345', '567', '789'],target = \"123345\") == 1\n assert candidate(nums = ['10', '20', '30', '40', '50'],target = \"2030\") == 1\n assert candidate(nums = ['0000', '000', '00', '0'],target = \"00000000\") == 0\n assert candidate(nums = ['0001', '10', '01', '1'],target = \"00011\") == 1\n assert candidate(nums = ['123', '456', '789', '0'],target = \"123456\") == 1\n assert candidate(nums = ['16', '61', '161', '6', '1661'],target = \"166161\") == 1\n assert candidate(nums = ['21', '12', '22', '11', '2112'],target = \"211221\") == 1\n assert candidate(nums = ['42', '424', '2', '4'],target = \"4242\") == 1\n assert candidate(nums = ['777', '77', '7', '7777'],target = \"777777\") == 2\n assert candidate(nums = ['11', '11', '11', '11', '11'],target = \"1111\") == 20\n assert candidate(nums = ['19', '91', '191', '9', '1991'],target = \"199191\") == 1\n assert candidate(nums = ['987654321', '123456789', '1234', '4321'],target = \"987654321123456789\") == 1\n assert candidate(nums = ['111111', '1111', '111', '11', '1'],target = \"111111111111\") == 0\n assert candidate(nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],target = \"12\") == 1\n assert candidate(nums = ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'],target = \"11\") == 90\n assert candidate(nums = ['101', '101', '101', '101'],target = \"101101\") == 12\n assert candidate(nums = ['8888', '888', '88', '8', '88', '888', '8888'],target = \"88888888\") == 2\n assert candidate(nums = ['22', '2', '222', '2222'],target = \"222222\") == 2\n assert candidate(nums = ['123456', '654321', '1234', '4321', '5678', '8765'],target = \"123456654321\") == 1\n assert candidate(nums = ['12', '21', '11', '22'],target = \"1221\") == 1\n assert candidate(nums = ['55', '555', '5555', '55555'],target = \"5555555\") == 4\n assert candidate(nums = ['14', '41', '144', '4'],target = \"1441\") == 1\n assert candidate(nums = ['8', '88', '888', '8888', '88888', '888888'],target = \"8888888\") == 6\n assert candidate(nums = ['12', '23', '34', '45', '56'],target = \"2345\") == 1\n assert candidate(nums = ['12345', '54321', '123', '321', '12', '21'],target = \"1234554321\") == 1\n assert candidate(nums = ['55', '5', '555', '5555'],target = \"55555\") == 4\n assert candidate(nums = ['987', '654', '321', '654'],target = \"987654\") == 2\n assert candidate(nums = ['111', '11', '1', '1111', '11111'],target = \"1111111\") == 4\n assert candidate(nums = ['1234', '4321', '2341', '3412'],target = \"12344321\") == 1\n assert candidate(nums = ['101', '01', '10', '1'],target = \"1010\") == 0\n assert candidate(nums = ['8', '88', '888', '8888', '88888'],target = \"888888888\") == 2\n assert candidate(nums = ['6', '66', '666', '6666'],target = \"666666\") == 2\n assert candidate(nums = ['10', '01', '0', '1'],target = \"1001\") == 1\n assert candidate(nums = ['10', '20', '30', '40', '50', '60', '70', '80', '90'],target = \"1020\") == 1\n assert candidate(nums = ['111', '11', '1', '1111'],target = \"111111\") == 2\n assert candidate(nums = ['1', '2', '3', '4', '5'],target = \"12\") == 1\n assert candidate(nums = ['111', '222', '112', '121', '211'],target = \"111222\") == 1\n assert candidate(nums = ['12345', '23456', '34567', '45678', '56789'],target = \"1234523456\") == 1\n assert candidate(nums = ['12', '12', '12', '12'],target = \"1212\") == 12\n assert candidate(nums = ['555', '55', '5', '5555', '55555'],target = \"5555555\") == 4\n assert candidate(nums = ['23', '32', '232', '2', '3223'],target = \"233223\") == 1\n assert candidate(nums = ['11', '22', '33', '44', '55', '66', '77', '88', '99'],target = \"1122\") == 1\n assert candidate(nums = ['123', '321', '213', '132', '231', '312'],target = \"123213\") == 1\n assert candidate(nums = ['12', '21', '121', '212'],target = \"1212\") == 0\n assert candidate(nums = ['555', '555', '555', '555', '555'],target = \"555555\") == 20\n assert candidate(nums = ['89', '98', '8998', '9889'],target = \"899889\") == 2\n assert candidate(nums = ['22', '222', '2', '2222'],target = \"222222\") == 2\n assert candidate(nums = ['23', '32', '123', '456', '654', '321'],target = \"23456\") == 1\n assert candidate(nums = ['9876', '8765', '7654', '6543', '5432', '4321', '3210', '2109'],target = \"98768765\") == 1\n assert candidate(nums = ['1010', '0101', '10', '01', '101', '010'],target = \"10100101\") == 1\n assert candidate(nums = ['90', '80', '70', '60'],target = \"7080\") == 1\n assert candidate(nums = ['101', '010', '10', '01'],target = \"101010\") == 1\n assert candidate(nums = ['9', '99', '999', '9999'],target = \"99999999\") == 0\n assert candidate(nums = ['5050', '50', '5', '500', '5000'],target = \"505050\") == 2\n assert candidate(nums = ['12', '21', '121', '112'],target = \"12112\") == 2\n assert candidate(nums = ['13', '31', '1', '3'],target = \"1331\") == 1\n assert candidate(nums = ['2', '22', '222', '2222', '22222'],target = \"222222\") == 4\n assert candidate(nums = ['2020', '20', '2', '0202'],target = \"202020\") == 2\n assert candidate(nums = ['12', '23', '34', '45', '56', '67', '78', '89'],target = \"1223\") == 1\n assert candidate(nums = ['999', '99', '9', '9999'],target = \"9999999\") == 2\n assert candidate(nums = ['00', '0', '000', '0000'],target = \"000000\") == 2\n assert candidate(nums = ['17', '71', '1717', '717', '177'],target = \"171717\") == 2\n assert candidate(nums = ['987', '876', '765', '654', '543'],target = \"987876\") == 1\n assert candidate(nums = ['12', '23', '34', '45', '56', '67', '78', '89', '90'],target = \"1223\") == 1\n assert candidate(nums = ['12', '12', '12', '12', '12', '12', '12', '12', '12', '12'],target = \"1212\") == 90\n assert candidate(nums = ['00', '000', '0000', '00000'],target = \"00000000\") == 2\n assert candidate(nums = ['1010', '10', '1', '101', '10101'],target = \"10101010\") == 0\n assert candidate(nums = ['12', '23', '34', '45', '56'],target = \"1223\") == 1\n assert candidate(nums = ['55', '5', '555', '5555'],target = \"5555\") == 2\n assert candidate(nums = ['1234', '456', '12', '3456'],target = \"123456\") == 1\n assert candidate(nums = ['45', '54', '4', '5'],target = \"4554\") == 1\n assert candidate(nums = ['10', '01', '100', '1'],target = \"101\") == 2\n assert candidate(nums = ['100', '10', '1', '1000'],target = \"1001000\") == 1\n assert candidate(nums = ['1111', '111', '11', '1'],target = \"11111111\") == 0\n assert candidate(nums = ['11', '111', '1111', '11111'],target = \"111111111\") == 2\n assert candidate(nums = ['9876', '8769', '7698', '6987', '987', '876', '769', '698'],target = \"98768769\") == 1\n assert candidate(nums = ['12345', '67890', '123', '4567890'],target = \"1234567890\") == 2\n assert candidate(nums = ['9', '9', '9', '9', '9', '9', '9', '9', '9', '9'],target = \"99\") == 90\n assert candidate(nums = ['123', '456', '789', '1234'],target = \"123456\") == 1\n assert candidate(nums = ['1234', '5678', '91011', '121314'],target = \"12345678\") == 1\n", "comparison": "exact"}, "public_tests": ["[\"777\",\"7\",\"77\",\"77\"]\n\"7777\"", "[\"123\",\"4\",\"12\",\"34\"]\n\"1234\"", "[\"1\",\"1\",\"1\"]\n\"11\""], "hints": ["Try to concatenate every two different strings from the list.", "Count the number of pairs with concatenation equals to target."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().numOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:31+00:00", "tests_total": 127, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function numOfPairs($nums, $target) {", "container": "Solution", "callable": "numOfPairs", "parameters": [{"name": "nums", "type": "String[]"}, {"name": "target", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2024, "task_id": "maximize-the-confusion-of-an-exam", "difficulty": "Medium", "problem_description": "A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).\n\nYou are given a string answerKey, where answerKey[i] is the original answer to the i^th question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:\n\n- Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').\n\nReturn the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.\n\nExample 1:\n\nInput: answerKey = \"TTFF\", k = 2\nOutput: 4\nExplanation: We can replace both the 'F's with 'T's to make answerKey = \"TTTT\".\nThere are four consecutive 'T's.\n\nExample 2:\n\nInput: answerKey = \"TFFT\", k = 1\nOutput: 3\nExplanation: We can replace the first 'T' with an 'F' to make answerKey = \"FFFT\".\nAlternatively, we can replace the second 'T' with an 'F' to make answerKey = \"TFFF\".\nIn both cases, there are three consecutive 'F's.\n\nExample 3:\n\nInput: answerKey = \"TTFTTFTT\", k = 1\nOutput: 5\nExplanation: We can replace the first 'F' to make answerKey = \"TTTTTFTT\"\nAlternatively, we can replace the second 'F' to make answerKey = \"TTFTTTTT\".\nIn both cases, there are five consecutive 'T's.\n\nConstraints:\n\n- n == answerKey.length\n- 1 <= n <= 5 * 10^4\n- answerKey[i] is either 'T' or 'F'\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(answerKey = \"TTTTFFFF\",k = 2) == 6\n assert candidate(answerKey = \"FFFFFF\",k = 3) == 6\n assert candidate(answerKey = \"TFFTFFTFFTFT\",k = 3) == 10\n assert candidate(answerKey = \"TFTFTFTF\",k = 2) == 5\n assert candidate(answerKey = \"FFTFFT\",k = 2) == 6\n assert candidate(answerKey = \"FFTTFFTTFF\",k = 5) == 10\n assert candidate(answerKey = \"FFTFFTFF\",k = 2) == 8\n assert candidate(answerKey = \"TFTFTFTFTF\",k = 4) == 9\n assert candidate(answerKey = \"T\",k = 1) == 1\n assert candidate(answerKey = \"FFTFFTFF\",k = 3) == 8\n assert candidate(answerKey = \"TTFF\",k = 2) == 4\n assert candidate(answerKey = \"TFTFTFTF\",k = 4) == 8\n assert candidate(answerKey = \"FTFTFTFT\",k = 2) == 5\n assert candidate(answerKey = \"TTFTTFTT\",k = 1) == 5\n assert candidate(answerKey = \"FFFFFFFF\",k = 5) == 8\n assert candidate(answerKey = \"FFFFFFT\",k = 2) == 7\n assert candidate(answerKey = \"FTFTFTFTFTFT\",k = 5) == 11\n assert candidate(answerKey = \"TTTTFFT\",k = 1) == 5\n assert candidate(answerKey = \"TTTTTTFTTTTT\",k = 2) == 12\n assert candidate(answerKey = \"TFFTFFTT\",k = 3) == 7\n assert candidate(answerKey = \"TTTTFFTFFT\",k = 3) == 8\n assert candidate(answerKey = \"FTFFTFFT\",k = 3) == 8\n assert candidate(answerKey = \"TTTTTTTT\",k = 3) == 8\n assert candidate(answerKey = \"TFFT\",k = 1) == 3\n assert candidate(answerKey = \"FFFFFFF\",k = 3) == 7\n assert candidate(answerKey = \"FFFFF\",k = 3) == 5\n assert candidate(answerKey = \"TFFFFF\",k = 2) == 6\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\",k = 20) == 38\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFT\",k = 4) == 9\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFF\",k = 10) == 16\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFT\",k = 8) == 16\n assert candidate(answerKey = \"TTTTTTTFFFFFFFFFFFFFFTTTTTTTTTTTTTTTTTTTTTT\",k = 15) == 43\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTT\",k = 5) == 16\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 25) == 51\n assert candidate(answerKey = \"TFFTFTFTFTFTFTFTFTFT\",k = 10) == 20\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTTTTTTTTT\",k = 15) == 24\n assert candidate(answerKey = \"TTFTFTFFTFTF\",k = 4) == 10\n assert candidate(answerKey = \"TFFFFFFFFFTTTTTTTTTT\",k = 6) == 16\n assert candidate(answerKey = \"TTFTFTFTFT\",k = 4) == 10\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFT\",k = 8) == 17\n assert candidate(answerKey = \"TFFTFFTFFTFFTFFTFFTFFTFFTFFT\",k = 21) == 28\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTFTF\",k = 10) == 20\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\",k = 20) == 32\n assert candidate(answerKey = \"FFFFFFFFTTTTTTTT\",k = 5) == 13\n assert candidate(answerKey = \"TFFTFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFFTFT\",k = 7) == 23\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFF\",k = 20) == 28\n assert candidate(answerKey = \"FFFFFFFFFTTTTTTTTT\",k = 5) == 14\n assert candidate(answerKey = \"FTTFTTFTTFFTFTTFFT\",k = 11) == 18\n assert candidate(answerKey = \"FFFFFFFFTTTTTTFFFFFFFFTTTTTTTTT\",k = 9) == 25\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTF\",k = 10) == 16\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTT\",k = 10) == 16\n assert candidate(answerKey = \"FFFFFFFFTTTTTTTTTTFT\",k = 2) == 13\n assert candidate(answerKey = \"TTTFFFFTTTFFTFTFFF\",k = 3) == 9\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 20) == 41\n assert candidate(answerKey = \"FTTTFTTFTTFTTFTTFT\",k = 7) == 18\n assert candidate(answerKey = \"TFTFTFTFTF\",k = 5) == 10\n assert candidate(answerKey = \"FFFTTTFFFFTTTTFF\",k = 5) == 12\n assert candidate(answerKey = \"TTFFFFFFFFTTTTTTTTTTTTFFFFFFF\",k = 8) == 22\n assert candidate(answerKey = \"TTTFFFTTTFFFTTTFFF\",k = 5) == 11\n assert candidate(answerKey = \"FFFFFFFFFTTTTTTTTTTTTTT\",k = 10) == 23\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFT\",k = 2) == 5\n assert candidate(answerKey = \"TTFTFTFTFTFTFTFT\",k = 5) == 12\n assert candidate(answerKey = \"FFTTFFTTFFTTFFTTFF\",k = 10) == 18\n assert candidate(answerKey = \"TTTTFFFFFFFFFFFFTTTTTTTTTTTT\",k = 15) == 28\n assert candidate(answerKey = \"TTFTFTFTFTFTFTFTFTFTFT\",k = 12) == 22\n assert candidate(answerKey = \"TTTTTTTTTTFFFFFFFFFFFFFFFFF\",k = 11) == 27\n assert candidate(answerKey = \"TTTTTTTTTFFFFFFF\",k = 5) == 14\n assert candidate(answerKey = \"FTFFTFFTFFTFFTFFTFF\",k = 10) == 19\n assert candidate(answerKey = \"TTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 7) == 16\n assert candidate(answerKey = \"FFFFFFFFFTTTTT\",k = 5) == 14\n assert candidate(answerKey = \"TFFTFTFTFFTTFTFT\",k = 3) == 9\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTF\",k = 6) == 13\n assert candidate(answerKey = \"TTTFTFTFTFTFTFTF\",k = 6) == 15\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTT\",k = 15) == 17\n assert candidate(answerKey = \"FFTFTFTFTFFTFTFTFT\",k = 6) == 15\n assert candidate(answerKey = \"FFFFFFFFTTTTTFFFFF\",k = 4) == 12\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFTTTTTTTTTTTTTTTT\",k = 8) == 38\n assert candidate(answerKey = \"FFFFFFFFTTTTTTTTTT\",k = 12) == 18\n assert candidate(answerKey = \"TTTTTTFFTFFTFFFF\",k = 4) == 12\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTF\",k = 9) == 18\n assert candidate(answerKey = \"TTTTTTTTTTFFTTFFTT\",k = 5) == 18\n assert candidate(answerKey = \"TTTFFFFTTTFFFFTTTFFFFTTT\",k = 6) == 18\n assert candidate(answerKey = \"TTFFTTFFTFFTFFTT\",k = 7) == 15\n assert candidate(answerKey = \"FFTTFFFTTF\",k = 2) == 7\n assert candidate(answerKey = \"FFFFFFFFFTTTTTTT\",k = 6) == 15\n assert candidate(answerKey = \"TTFTTTFTFTFTFTFFTFTF\",k = 4) == 12\n assert candidate(answerKey = \"TTTTTTTTTTFFFFFFFFFF\",k = 8) == 18\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\",k = 20) == 36\n assert candidate(answerKey = \"TTTFFFFTTTTFTTTFFTTT\",k = 7) == 20\n assert candidate(answerKey = \"TFFTFTFTFTFTFTFTFT\",k = 8) == 17\n assert candidate(answerKey = \"TTFFFTFTFTFTFFFT\",k = 6) == 15\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFT\",k = 5) == 11\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 20) == 38\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\",k = 25) == 32\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 15) == 31\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTF\",k = 20) == 41\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFT\",k = 9) == 18\n assert candidate(answerKey = \"TTTTTFFTTTTFFTT\",k = 4) == 15\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 15) == 28\n assert candidate(answerKey = \"FFTFTFFTFTFFTFTFFTFT\",k = 5) == 14\n assert candidate(answerKey = \"TTFFFFFFFFFFFFFFFFFT\",k = 3) == 20\n assert candidate(answerKey = \"TFFTFFTFFTFFTFFTFF\",k = 10) == 18\n assert candidate(answerKey = \"FFFFFFFFTTTTTTTTFFFFFFFFTTTTTTTT\",k = 8) == 24\n assert candidate(answerKey = \"TTTTTTFTTTTTFTTTTTFTTTTT\",k = 7) == 24\n assert candidate(answerKey = \"TFFFFFFFTTTTTTTTTT\",k = 10) == 18\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTFTF\",k = 15) == 20\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\",k = 25) == 30\n assert candidate(answerKey = \"FTTFTTFTTFFTFTTFFTFFTFTTFTT\",k = 22) == 27\n assert candidate(answerKey = \"TTFFFFFFFFFFFFFFFFFF\",k = 10) == 20\n assert candidate(answerKey = \"FFFFFFFFFTTTTTTT\",k = 7) == 16\n assert candidate(answerKey = \"TFTFTFTFTFTFTFTFTFTFTFTFTFTF\",k = 18) == 28\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 10) == 21\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTTTTTTT\",k = 15) == 22\n assert candidate(answerKey = \"FFTTFFTFFTFFTFFT\",k = 4) == 12\n assert candidate(answerKey = \"TTTTTFFFFF\",k = 2) == 7\n assert candidate(answerKey = \"TTTFFFTTTFFFTTTFFFTTTFFFTTTFFTFTFFTT\",k = 15) == 32\n assert candidate(answerKey = \"TFFTFFTTFFTTFFTTFFTT\",k = 9) == 19\n assert candidate(answerKey = \"FTFTFTTTTTFTFTFT\",k = 6) == 16\n assert candidate(answerKey = \"TTTTTTTTTTTTTTTTTTTTTTTTTTTT\",k = 20) == 28\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFF\",k = 15) == 17\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFT\",k = 8) == 17\n assert candidate(answerKey = \"TFFTFFTFFTFFTFFTFFTFFTFFTFFT\",k = 12) == 28\n assert candidate(answerKey = \"TTTTFFTTFFTTFF\",k = 4) == 12\n assert candidate(answerKey = \"FTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 12) == 25\n assert candidate(answerKey = \"TFFFFFFFTTTTTTTT\",k = 7) == 16\n assert candidate(answerKey = \"TFFTFFTFFTFFTFFTFFTFFT\",k = 7) == 21\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFFFFFFF\",k = 20) == 29\n assert candidate(answerKey = \"TTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFT\",k = 24) == 32\n assert candidate(answerKey = \"TTFTTTTTTTTTTTTTTTTT\",k = 1) == 20\n assert candidate(answerKey = \"TTFFTFTFFTFFTFTFFTFFTFFTTFFTFTFFTFFTFFTFFTFTFFTFF\",k = 6) == 19\n assert candidate(answerKey = \"TTFTFTFTFTFTFTFTFTFTFTFT\",k = 12) == 24\n assert candidate(answerKey = \"TTTTTTTTTFFFFFFF\",k = 6) == 15\n assert candidate(answerKey = \"FFFFFFFFFFFFFFFFFFFFFFFF\",k = 15) == 24\n", "comparison": "exact"}, "public_tests": ["\"TTFF\"\n2", "\"TFFT\"\n1", "\"TTFTTFTT\"\n1"], "hints": ["Can we use the maximum length at the previous position to help us find the answer for the current position?", "Can we use binary search to find the maximum consecutive same answer at every position?"], "metadata": {"canonical_parameter_names": ["answerKey", "k"], "leetcode_dataset_entry_point": "Solution().maxConsecutiveAnswers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:34+00:00", "tests_total": 141, "tests_dropped": 8, "flags": [], "topic_tags": ["string", "binary-search", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxConsecutiveAnswers($answerKey, $k) {", "container": "Solution", "callable": "maxConsecutiveAnswers", "parameters": [{"name": "answerKey", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2025, "task_id": "maximum-number-of-ways-to-partition-an-array", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:\n\n- 1 <= pivot < n\n- nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]\n\nYou are also given an integer k. You can choose to change the value of one element of nums to k, or to leave the array unchanged.\n\nReturn the maximum possible number of ways to partition nums to satisfy both conditions after changing at most one element.\n\nExample 1:\n\nInput: nums = [2,-1,2], k = 3\nOutput: 1\nExplanation: One optimal approach is to change nums[0] to k. The array becomes [3,-1,2].\nThere is one way to partition the array:\n- For pivot = 2, we have the partition [3,-1 | 2]: 3 + -1 == 2.\n\nExample 2:\n\nInput: nums = [0,0,0], k = 1\nOutput: 2\nExplanation: The optimal approach is to leave the array unchanged.\nThere are two ways to partition the array:\n- For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0.\n- For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.\n\nExample 3:\n\nInput: nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33\nOutput: 4\nExplanation: One optimal approach is to change nums[2] to k. The array becomes [22,4,-33,-20,-15,15,-16,7,19,-10,0,-13,-14].\nThere are four ways to partition the array.\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 10^5\n- -10^5 <= k, nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 0\n assert candidate(nums = [0, 0, 0],k = 1) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [100000, -100000, 100000, -100000],k = 0) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5],k = -3) == 0\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, -6, -7, -8, -9, -10],k = -5) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0],k = 1) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 55) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5],k = -15) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, -1, 2],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],k = 9) == 0\n assert candidate(nums = [-1, 1, -1, 1, -1],k = 0) == 3\n assert candidate(nums = [22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14],k = -33) == 4\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],k = 15000) == 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 = [100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000],k = 0) == 4\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 = 50) == 9\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 60) == 0\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],k = 1) == 14\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1],k = 0) == 3\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],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 = 0) == 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 = 2) == 1\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 = [22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14, 22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14],k = -33) == 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 = 5) == 1\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40],k = 0) == 3\n assert candidate(nums = [-100000, -99999, -99998, -99997, -99996],k = 50000) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 105) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 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],k = 15) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 525) == 1\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9],k = 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],k = 210) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = -5) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1],k = 2) == 4\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) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1],k = 0) == 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],k = 1) == 1\n assert candidate(nums = [10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000],k = 0) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 0) == 7\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400],k = 50) == 3\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 420) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 780) == 0\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100],k = 0) == 1\n assert candidate(nums = [100000, -100000, 100000, -100000, 100000, -100000],k = 0) == 2\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000],k = 10500) == 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],k = 0) == 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 = 15) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 1) == 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],k = 2100) == 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 = 110) == 0\n assert candidate(nums = [-100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000],k = 0) == 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],k = 1910) == 1\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40],k = 0) == 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],k = 15) == 1\n assert candidate(nums = [100000, -100000, 100000, -100000, 100000],k = 0) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 65) == 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 = 100) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 1275) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 10) == 0\n assert candidate(nums = [0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5],k = 0) == 5\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],k = 5) == 10\n assert candidate(nums = [-100000, 0, 100000, 0, -100000, 0, 100000, 0, -100000],k = 50000) == 0\n assert candidate(nums = [10000, -10000, 20000, -20000, 30000, -30000, 40000, -40000, 50000],k = -10000) == 3\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1],k = 0) == 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 = 10) == 1\n assert candidate(nums = [10000, -5000, 20000, -10000, 15000, -5000, 20000, -10000, 15000],k = 10000) == 2\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40],k = 0) == 3\n assert candidate(nums = [22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14, 30, -30],k = -33) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 120) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 500) == 1\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 0) == 4\n assert candidate(nums = [5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5, 5, -5],k = 10) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 100) == 1\n assert candidate(nums = [22, 4, -25, -20, -15, 15, -16, 7, 19, -10, 0, -13, -14],k = 100) == 0\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],k = 5) == 1\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],k = 0) == 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],k = 50) == 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 = [-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000],k = 5000) == 3\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 = 5) == 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) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 120) == 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) == 0\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90],k = 0) == 2\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) == 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],k = 10) == 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 = 0) == 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],k = 2) == 1\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = -55) == 0\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 55000) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 225) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = -50) == 1\n assert candidate(nums = [-100000, -90000, -80000, -70000, -60000, -50000, -40000, -30000, -20000, -10000],k = -55000) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1) == 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],k = 0) == 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],k = 210) == 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 = 10) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 275) == 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) == 1\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],k = 50000) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 55) == 0\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 = 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],k = 100) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900],k = 4500) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 550) == 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 = 190) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 100) == 0\n", "comparison": "exact"}, "public_tests": ["[2,-1,2]\n3", "[0,0,0]\n1", "[22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14]\n-33"], "hints": ["A pivot point splits the array into equal prefix and suffix. If no change is made to the array, the goal is to find the number of pivot p such that prefix[p-1] == suffix[p].", "Consider how prefix and suffix will change when we change a number nums[i] to k.", "When sweeping through each element, can you find the total number of pivots where the difference of prefix and suffix happens to equal to the changes of k-nums[i]."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().waysToPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:36+00:00", "tests_total": 117, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "counting", "enumeration", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function waysToPartition($nums, $k) {", "container": "Solution", "callable": "waysToPartition", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2027, "task_id": "minimum-moves-to-convert-string", "difficulty": "Easy", "problem_description": "You are given a string s consisting of n characters which are either 'X' or 'O'.\n\nA move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.\n\nReturn the minimum number of moves required so that all the characters of s are converted to 'O'.\n\nExample 1:\n\nInput: s = \"XXX\"\nOutput: 1\nExplanation: XXX -> OOO\nWe select all the 3 characters and convert them in one move.\n\nExample 2:\n\nInput: s = \"XXOX\"\nOutput: 2\nExplanation: XXOX -> OOOX -> OOOO\nWe select the first 3 characters in the first move, and convert them to 'O'.\nThen we select the last 3 characters and convert them so that the final string contains all 'O's.\n\nExample 3:\n\nInput: s = \"OOOO\"\nOutput: 0\nExplanation: There are no 'X's in s to convert.\n\nConstraints:\n\n- 3 <= s.length <= 1000\n- s[i] is either 'X' or 'O'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"XXXXXXXXXX\") == 4\n assert candidate(s = \"OOXOOX\") == 2\n assert candidate(s = \"OOXOOXOOXO\") == 3\n assert candidate(s = \"OOXXOOXXOO\") == 2\n assert candidate(s = \"XXOX\") == 2\n assert candidate(s = \"OXOXOXOXOX\") == 3\n assert candidate(s = \"XOOOXXOOOX\") == 3\n assert candidate(s = \"XXX\") == 1\n assert candidate(s = \"OOOO\") == 0\n assert candidate(s = \"XOOXOX\") == 2\n assert candidate(s = \"OXOXOX\") == 2\n assert candidate(s = \"OOOXXOOOXXOOO\") == 2\n assert candidate(s = \"XOXOXOXOXO\") == 3\n assert candidate(s = \"XXXXXX\") == 2\n assert candidate(s = \"XOOXOOXOOX\") == 4\n assert candidate(s = \"XXXXXXXXX\") == 3\n assert candidate(s = \"XOXOXO\") == 2\n assert candidate(s = \"OOXXOOX\") == 2\n assert candidate(s = \"OOXOXO\") == 1\n assert candidate(s = \"XOOOOXOOXOXXXX\") == 4\n assert candidate(s = \"XOOXOXOOXOXOXO\") == 4\n assert candidate(s = \"OOXOXOXXOXXOOXOX\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXOXOXO\") == 8\n assert candidate(s = \"XOXOOXOXOOXOXOXOXOOXOXOXOOXOXOXOOXO\") == 9\n assert candidate(s = \"XOOXOXOOXOOXOOXOOXOOXOOXOOXOOX\") == 10\n assert candidate(s = \"XOXOXXOOXOXOXXXOXO\") == 5\n assert candidate(s = \"XOOXOXOOXOXOOXOXOOX\") == 5\n assert candidate(s = \"OOXOOXOOXOOXOO\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXO\") == 7\n assert candidate(s = \"OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX\") == 12\n assert candidate(s = \"OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX\") == 9\n assert candidate(s = \"XOOOXOOOXOOOXOOOXOOO\") == 5\n assert candidate(s = \"XOOXOXOXOXOXOXOX\") == 5\n assert candidate(s = \"OOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"OOOOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"XXOOOOXXOOOOXXOOOOXXOOOOXXOOOOXXOOOOXXOOOOXX\") == 8\n assert candidate(s = \"OOXXOOXXOOXXXX\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO\") == 9\n assert candidate(s = \"XOOXXOOXXOOXXOOXX\") == 5\n assert candidate(s = \"XOXOXOXOXOOOXOXO\") == 4\n assert candidate(s = \"XXXOXOXOXOXO\") == 3\n assert candidate(s = \"XXOOXOXOXOXOXX\") == 4\n assert candidate(s = \"OXXOXOXOXOXO\") == 3\n assert candidate(s = \"XXXXXXXXXXXXXXXXXXX\") == 7\n assert candidate(s = \"OOXOXOXOXOOO\") == 2\n assert candidate(s = \"OXOXOXOXOXOX\") == 3\n assert candidate(s = \"XXOOXOXOXOXOXXOXOXXOXOXXOXOXXOXOXX\") == 10\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX\") == 14\n assert candidate(s = \"XOXOXOXOXOXO\") == 3\n assert candidate(s = \"XOOOXXXXOOOXXXXOOO\") == 5\n assert candidate(s = \"XXOXOXOXOXOXOXOXOXOXOXOXOX\") == 7\n assert candidate(s = \"XXOOXXOOXXOOXXOOXXOOX\") == 6\n assert candidate(s = \"XXXXXXXXXXXXXXXX\") == 6\n assert candidate(s = \"XXXOXOXOXOXOXOXO\") == 4\n assert candidate(s = \"XOXXXXXXXXXOXOXOXOXOXOXOXO\") == 8\n assert candidate(s = \"XOXOXXXXXXXXXOXXXXXXXXXOXXXXXXXXXOXXXXXXXXXO\") == 13\n assert candidate(s = \"OOXOXOXOXOXOXOXO\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO\") == 12\n assert candidate(s = \"OXOXOXOXOXOXOXOXOXOXOX\") == 6\n assert candidate(s = \"OOXXOOXXOOXXOOXXOOXXOO\") == 5\n assert candidate(s = \"OXOXOXOXOXOXOXOXOXOXOXOX\") == 6\n assert candidate(s = \"XXXXXXXXXOOOOOOOOOXXXXXXXXX\") == 6\n assert candidate(s = \"XXOOXXOOXXOOXXOOXX\") == 5\n assert candidate(s = \"XOOXOOXOOXOOXOOX\") == 6\n assert candidate(s = \"OOXOXOXOXOXOXOXOXOXOXOXOXOXOXOOO\") == 7\n assert candidate(s = \"OOXOOXOOXOOXOOXO\") == 5\n assert candidate(s = \"XXXXXXXXXXXXX\") == 5\n assert candidate(s = \"XXOOXOXOXOXOXO\") == 4\n assert candidate(s = \"XXXOOOOXOXOOXOXO\") == 3\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXO\") == 6\n assert candidate(s = \"XXOOXXOOXXOOXX\") == 4\n assert candidate(s = \"XOOXOOXOOXOXOX\") == 5\n assert candidate(s = \"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"XXOOXOXOXOXOXOXOXO\") == 5\n assert candidate(s = \"XOOXOOXOOXOOXOOXOOX\") == 7\n assert candidate(s = \"OOOXXXOOOXXXOOO\") == 2\n assert candidate(s = \"XXXOXOXOXXXO\") == 3\n assert candidate(s = \"XOXOXXOOXOXO\") == 3\n assert candidate(s = \"OXXXXOOOXXXXOOOXXX\") == 5\n assert candidate(s = \"OOOXOXOXOXOXOXOOOO\") == 3\n assert candidate(s = \"XOOXOOXOOXOOXOOXOOXOOX\") == 8\n assert candidate(s = \"OOXOOXOOXOOXOOXOOXOO\") == 6\n assert candidate(s = \"OOXOOXOOXOOXOOX\") == 5\n assert candidate(s = \"XXXXXXXXXXXXXXXXXXXXXXXX\") == 8\n assert candidate(s = \"OOXOXOXOXOXOXOOO\") == 3\n assert candidate(s = \"XOXXOXXOXXOXXOXX\") == 6\n assert candidate(s = \"XXOOXOXOXOXOXOXOXOXX\") == 6\n assert candidate(s = \"XOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXO\") == 13\n assert candidate(s = \"XOXOXOXOXOXOXO\") == 4\n assert candidate(s = \"OXOXOXOXOXOXOX\") == 4\n assert candidate(s = \"XXOXOXOXOXOXOXOXOXOX\") == 6\n assert candidate(s = \"XXXXOXXXXOXXXXO\") == 5\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXOXOXOXOXO\") == 7\n assert candidate(s = \"XOOXOXOOXOXOOXOXOOXOXOOX\") == 6\n assert candidate(s = \"OOOOXXOOXXOOXX\") == 3\n assert candidate(s = \"XXOOXXOOXXOOXXOOXXOOXXOOXXOOX\") == 8\n assert candidate(s = \"XXXXOOXXXXOOXXXXOO\") == 6\n assert candidate(s = \"XXOXXOXXOXXOXX\") == 5\n assert candidate(s = \"OOOOOOOOOOOOO\") == 0\n assert candidate(s = \"OOXXXXXXOOXXXXXXOOXXXXXX\") == 6\n assert candidate(s = \"XOXOXXXOXOXOXXX\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXO\") == 5\n assert candidate(s = \"XOXOXOOXOXOX\") == 4\n assert candidate(s = \"XXOOXXOOXXOOXXOOXXOO\") == 5\n assert candidate(s = \"XXXXXXXXXXXXXXXXXX\") == 6\n assert candidate(s = \"XXXXXXXXXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO\") == 13\n assert candidate(s = \"XXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX\") == 9\n assert candidate(s = \"XXOXOXOXOXOXOXOX\") == 5\n assert candidate(s = \"XOOXOOXOOXOOXOOXOOXOOXOOX\") == 9\n assert candidate(s = \"XOOOXOOOXOOOXOOO\") == 4\n assert candidate(s = \"OOXXOOXXOOXXOO\") == 3\n assert candidate(s = \"XOXOXOXOXOXOX\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXOXOXO\") == 5\n assert candidate(s = \"XXOXOXOXOXOX\") == 4\n assert candidate(s = \"OOXOXOXOXO\") == 2\n assert candidate(s = \"XOOOXXOOOOXXOOOXXOOO\") == 4\n assert candidate(s = \"OOXOOXOOXOOXOOXOOXOOXOOX\") == 8\n assert candidate(s = \"XXOXOXOXOXOXOX\") == 4\n assert candidate(s = \"OXOXOXOXOXOXOXOXOX\") == 5\n assert candidate(s = \"OXOOXOOXOOXOOXOOXOOXOOX\") == 8\n assert candidate(s = \"OOXOOXOOXOOXOOXOOXOOXOOXOOXOO\") == 9\n assert candidate(s = \"OXXOXOXXOXOXXOXO\") == 5\n assert candidate(s = \"XXXXXXXXOXOXO\") == 4\n assert candidate(s = \"XXXXXXXXOOOXXXXX\") == 5\n assert candidate(s = \"OOXXOOXXOOXXOOXXOOXXOOXXOO\") == 6\n assert candidate(s = \"OOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOO\") == 12\n assert candidate(s = \"XOOXOXXOXOXXOX\") == 5\n assert candidate(s = \"OOOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOO\") == 9\n assert candidate(s = \"OXOXOXOXOXOXOXOXOXO\") == 5\n assert candidate(s = \"OXOXOXOXOXOXO\") == 3\n assert candidate(s = \"XXXXOXXXXOXXXXOXXXXOXXXXOXXXXOXXXXO\") == 11\n assert candidate(s = \"XOXOXXXXXXXXOXXXXXXXXX\") == 7\n assert candidate(s = \"XOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOX\") == 12\n assert candidate(s = \"XOOOXXOOOXXOOOXXOOO\") == 4\n assert candidate(s = \"OOOXOXOXOXOXOXOXOXOXOXOOOO\") == 5\n assert candidate(s = \"XOXXOXOXXOXOXXOXOXXOXXO\") == 7\n assert candidate(s = \"OOXOXOXOXOXOXOXOXOXOXOXOXO\") == 6\n assert candidate(s = \"OOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"XXOXXOXXOXXO\") == 4\n assert candidate(s = \"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"OXOXOXOXOXOXOXOX\") == 4\n assert candidate(s = \"XXXXXXXXXXXXXXXXXOOOOOOOOOOOO\") == 6\n assert candidate(s = \"OOOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"XXXXXXXXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX\") == 11\n assert candidate(s = \"XXXOOXOXOOXOXX\") == 4\n assert candidate(s = \"XOXOXOXOXOXOXOXO\") == 4\n assert candidate(s = \"XOOOOXOOOOXOOOOXOOOO\") == 4\n assert candidate(s = \"XOOXXOOXXOOXXOOX\") == 5\n assert candidate(s = \"OOOXOXOXOXOXOOOO\") == 3\n assert candidate(s = \"OOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOXOOX\") == 12\n assert candidate(s = \"XOOOOXOOOXOOO\") == 3\n assert candidate(s = \"XXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXX\") == 11\n assert candidate(s = \"OOXOXOXOXOXOXOXOXO\") == 4\n assert candidate(s = \"XOXOXOOXOXOXOO\") == 4\n assert candidate(s = \"XOOOOXOOOOXOOOOXOOOOXOOOO\") == 5\n assert candidate(s = \"XOOXOXOXOXOX\") == 4\n assert candidate(s = \"OOXOOOXOOOXOOOXOOOXOOOXOOOXOOOXOOOXOOOXOOO\") == 10\n assert candidate(s = \"XXOOXXOOXXOO\") == 3\n assert candidate(s = \"XXXXXXXXOOOOXXXXXXXX\") == 6\n assert candidate(s = \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\") == 14\n assert candidate(s = \"XXXXXXXXXXXXXXXXX\") == 6\n assert candidate(s = \"XOXOOXOXOOXOXOXO\") == 4\n assert candidate(s = \"OXOOXOOOXOXOOXOO\") == 4\n assert candidate(s = \"XXOXOXXOXOXOXXOX\") == 5\n assert candidate(s = \"OOOOOOOOOOOOOOOOOOOOOOOOOOOO\") == 0\n assert candidate(s = \"XXXXXXXXXXXXXX\") == 5\n", "comparison": "exact"}, "public_tests": ["\"XXX\"", "\"XXOX\"", "\"OOOO\""], "hints": ["Find the smallest substring you need to consider at a time.", "Try delaying a move as long as possible."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:39+00:00", "tests_total": 166, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumMoves($s) {", "container": "Solution", "callable": "minimumMoves", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2028, "task_id": "find-missing-observations", "difficulty": "Medium", "problem_description": "You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.\n\nYou are given an integer array rolls of length m where rolls[i] is the value of the i^th observation. You are also given the two integers mean and n.\n\nReturn an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.\n\nThe average value of a set of k numbers is the sum of the numbers divided by k.\n\nNote that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.\n\nExample 1:\n\nInput: rolls = [3,2,4,3], mean = 4, n = 2\nOutput: [6,6]\nExplanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.\n\nExample 2:\n\nInput: rolls = [1,5,6], mean = 3, n = 4\nOutput: [2,3,2,2]\nExplanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.\n\nExample 3:\n\nInput: rolls = [1,2,3,4], mean = 6, n = 4\nOutput: []\nExplanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.\n\nConstraints:\n\n- m == rolls.length\n- 1 <= n, m <= 10^5\n- 1 <= rolls[i], mean <= 6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rolls = [1, 2],mean = 3,n = 2) == [5, 4]\n assert candidate(rolls = [1, 3, 5],mean = 2,n = 2) == []\n assert candidate(rolls = [5, 5, 5, 5],mean = 5,n = 4) == [5, 5, 5, 5]\n assert candidate(rolls = [5, 6, 6, 6],mean = 5,n = 3) == [4, 4, 4]\n assert candidate(rolls = [6, 6, 6, 6],mean = 6,n = 3) == [6, 6, 6]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 3,n = 6) == [3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 2, 3, 4],mean = 6,n = 4) == []\n assert candidate(rolls = [1, 5, 6],mean = 3,n = 4) == [3, 2, 2, 2]\n assert candidate(rolls = [5, 5, 5, 5],mean = 5,n = 5) == [5, 5, 5, 5, 5]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1],mean = 2,n = 6) == [3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [3, 2, 4, 3],mean = 4,n = 2) == [6, 6]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 5,n = 6) == [4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 1, 1, 1],mean = 2,n = 4) == [3, 3, 3, 3]\n assert candidate(rolls = [3],mean = 4,n = 1) == [5]\n assert candidate(rolls = [6],mean = 6,n = 1) == [6]\n assert candidate(rolls = [1, 1, 1],mean = 2,n = 3) == [3, 3, 3]\n assert candidate(rolls = [6, 6, 6],mean = 5,n = 3) == [4, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],mean = 3,n = 10) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6],mean = 3,n = 6) == [3, 3, 3, 2, 2, 2]\n assert candidate(rolls = [1],mean = 6,n = 5) == []\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 6,n = 15) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 4,n = 3) == [6, 6, 6]\n assert candidate(rolls = [1, 1, 1, 1],mean = 2,n = 10) == [3, 3, 3, 3, 2, 2, 2, 2, 2, 2]\n assert candidate(rolls = [1, 1, 1, 1, 1],mean = 5,n = 5) == []\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],mean = 3,n = 5) == [5, 5, 5, 5, 5]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 4,n = 20) == []\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 3,n = 3) == [3, 3, 3]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 12) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 6, 3, 4, 2, 5],mean = 3,n = 5) == [3, 3, 2, 2, 2]\n assert candidate(rolls = [2, 4, 6, 1, 3, 5],mean = 4,n = 3) == [5, 5, 5]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1],mean = 4,n = 12) == [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 6, 1, 6, 1, 6],mean = 4,n = 3) == [5, 5, 5]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 6,n = 10) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [1, 2, 3, 4, 5],mean = 4,n = 5) == [5, 5, 5, 5, 5]\n assert candidate(rolls = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],mean = 4,n = 20) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3],mean = 5,n = 5) == []\n assert candidate(rolls = [5, 1, 5, 1, 5, 1],mean = 4,n = 2) == []\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1],mean = 4,n = 18) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],mean = 3,n = 15) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 15) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 1, 1, 1, 1],mean = 2,n = 10) == [3, 3, 3, 3, 3, 2, 2, 2, 2, 2]\n assert candidate(rolls = [6, 5, 4, 3, 2, 1],mean = 3,n = 7) == [3, 3, 3, 3, 2, 2, 2]\n assert candidate(rolls = [1, 2, 3],mean = 2,n = 9) == [2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(rolls = [4, 4, 4, 4, 4, 4, 4, 4],mean = 4,n = 1) == [4]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2],mean = 2,n = 12) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 20) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [2, 3, 4, 5, 6],mean = 4,n = 6) == [4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6],mean = 4,n = 3) == [5, 5, 5]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 6,n = 12) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [6, 4, 6, 4, 6, 4],mean = 5,n = 5) == [5, 5, 5, 5, 5]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 3,n = 10) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rolls = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],mean = 5,n = 12) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rolls = [6, 5, 4, 3, 2, 1],mean = 4,n = 10) == [5, 5, 5, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [5, 1, 5, 1, 5, 1],mean = 3,n = 6) == [3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [4, 4, 4, 4, 4, 4],mean = 5,n = 1) == []\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 5,n = 10) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 6,n = 6) == [6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],mean = 3,n = 20) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 1,n = 10) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 6,n = 6) == [6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [1, 1, 2, 2, 3, 3],mean = 3,n = 3) == [5, 5, 5]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2, 2, 2],mean = 3,n = 6) == [5, 5, 5, 4, 4, 4]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 10) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 6,n = 18) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [1, 6, 1, 6, 1, 6],mean = 4,n = 6) == [5, 5, 5, 4, 4, 4]\n assert candidate(rolls = [1, 6, 1, 6, 1, 6],mean = 4,n = 3) == [5, 5, 5]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2],mean = 3,n = 4) == [5, 5, 5, 4]\n assert candidate(rolls = [1, 2, 3, 4, 5],mean = 2,n = 1) == []\n assert candidate(rolls = [2, 4, 6, 5, 4, 3, 2],mean = 4,n = 5) == [5, 5, 4, 4, 4]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 5,n = 5) == [4, 4, 4, 4, 3]\n assert candidate(rolls = [6, 6, 6, 6],mean = 4,n = 8) == [3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 5,n = 20) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],mean = 3,n = 10) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [6, 5, 4, 3, 2, 1],mean = 4,n = 5) == [5, 5, 5, 4, 4]\n assert candidate(rolls = [1, 2, 3, 4, 5],mean = 3,n = 5) == [3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],mean = 4,n = 5) == [6, 6, 6, 5, 5]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],mean = 4,n = 12) == [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 4,n = 5) == []\n assert candidate(rolls = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],mean = 4,n = 10) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 3,n = 10) == [2, 2, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(rolls = [4, 5, 6, 1, 2, 3],mean = 4,n = 6) == [5, 5, 5, 4, 4, 4]\n assert candidate(rolls = [1, 2, 2, 3, 3, 4, 5, 6],mean = 3,n = 10) == [3, 3, 3, 3, 3, 3, 3, 3, 2, 2]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 5) == [4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],mean = 4,n = 5) == [5, 5, 5, 4, 4]\n assert candidate(rolls = [5, 5, 5, 5, 5],mean = 5,n = 5) == [5, 5, 5, 5, 5]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 18) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [5, 5, 5, 5, 5, 5],mean = 4,n = 6) == [3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],mean = 5,n = 10) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rolls = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],mean = 4,n = 10) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1],mean = 2,n = 9) == [3, 3, 3, 3, 3, 3, 3, 2, 2]\n assert candidate(rolls = [4, 4, 4, 4, 4, 4],mean = 4,n = 3) == [4, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],mean = 4,n = 5) == [6, 6, 6, 6, 6]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 3,n = 20) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rolls = [6],mean = 1,n = 5) == []\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 4,n = 3) == [6, 6, 6]\n assert candidate(rolls = [6, 6, 6, 6, 6],mean = 6,n = 1) == [6]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],mean = 4,n = 12) == [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 4,n = 10) == [5, 5, 5, 5, 5, 5, 4, 4, 4, 4]\n assert candidate(rolls = [6, 6, 6, 6],mean = 5,n = 2) == [3, 3]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6],mean = 5,n = 3) == [3, 3, 3]\n assert candidate(rolls = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],mean = 5,n = 20) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rolls = [3, 3, 3, 3, 3],mean = 5,n = 5) == []\n assert candidate(rolls = [6, 5, 4, 3, 2, 1],mean = 4,n = 6) == [5, 5, 5, 4, 4, 4]\n assert candidate(rolls = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],mean = 6,n = 10) == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(rolls = [1, 2, 3, 4, 5, 6],mean = 4,n = 5) == [5, 5, 5, 4, 4]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3],mean = 4,n = 5) == [6, 5, 5, 5, 5]\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],mean = 2,n = 20) == [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],mean = 5,n = 10) == []\n assert candidate(rolls = [1, 2, 3, 4, 5],mean = 3,n = 7) == [3, 3, 3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 1, 2, 2, 3, 3],mean = 3,n = 6) == [4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],mean = 3,n = 10) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(rolls = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],mean = 3,n = 5) == [3, 3, 3, 3, 3]\n assert candidate(rolls = [1, 2, 3],mean = 4,n = 3) == [6, 6, 6]\n", "comparison": "exact"}, "public_tests": ["[3,2,4,3]\n4\n2", "[1,5,6]\n3\n4", "[1,2,3,4]\n6\n4"], "hints": ["What should the sum of the n rolls be?", "Could you generate an array of size n such that each element is between 1 and 6?"], "metadata": {"canonical_parameter_names": ["rolls", "mean", "n"], "leetcode_dataset_entry_point": "Solution().missingRolls", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:41+00:00", "tests_total": 116, "tests_dropped": 3, "flags": ["multiple_answers"], "topic_tags": ["array", "math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function missingRolls($rolls, $mean, $n) {", "container": "Solution", "callable": "missingRolls", "parameters": [{"name": "rolls", "type": "Integer[]"}, {"name": "mean", "type": "Integer"}, {"name": "n", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2029, "task_id": "stone-game-ix", "difficulty": "Medium", "problem_description": "Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the i^th stone.\n\nAlice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).\n\nAssuming both players play optimally, return true if Alice wins and false if Bob wins.\n\nExample 1:\n\nInput: stones = [2,1]\nOutput: true\nExplanation: The game will be played as follows:\n- Turn 1: Alice can remove either stone.\n- Turn 2: Bob removes the remaining stone.\nThe sum of the removed stones is 1 + 2 = 3 and is divisible by 3. Therefore, Bob loses and Alice wins the game.\n\nExample 2:\n\nInput: stones = [2]\nOutput: false\nExplanation: Alice will remove the only stone, and the sum of the values on the removed stones is 2.\nSince all the stones are removed and the sum of values is not divisible by 3, Bob wins the game.\n\nExample 3:\n\nInput: stones = [5,1,2,4,3]\nOutput: false\nExplanation: Bob will always win. One possible way for Bob to win is shown below:\n- Turn 1: Alice can remove the second stone with value 1. Sum of removed stones = 1.\n- Turn 2: Bob removes the fifth stone with value 3. Sum of removed stones = 1 + 3 = 4.\n- Turn 3: Alices removes the fourth stone with value 4. Sum of removed stones = 1 + 3 + 4 = 8.\n- Turn 4: Bob removes the third stone with value 2. Sum of removed stones = 1 + 3 + 4 + 2 = 10.\n- Turn 5: Alice removes the first stone with value 5. Sum of removed stones = 1 + 3 + 4 + 2 + 5 = 15.\nAlice loses the game because the sum of the removed stones (15) is divisible by 3. Bob wins the game.\n\nConstraints:\n\n- 1 <= stones.length <= 10^5\n- 1 <= stones[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stones = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == True\n assert candidate(stones = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == False\n assert candidate(stones = [3, 6, 9, 12, 15]) == False\n assert candidate(stones = [2, 1]) == True\n assert candidate(stones = [1, 2, 3, 6, 9, 12, 15]) == False\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(stones = [3, 3, 3]) == False\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 1]) == False\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(stones = [1, 5, 9, 13, 17, 21]) == True\n assert candidate(stones = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(stones = [5, 1, 2, 4, 3]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == False\n assert candidate(stones = [3, 6, 9, 12, 15, 18, 21]) == False\n assert candidate(stones = [1, 5, 7, 11, 13, 17, 19]) == True\n assert candidate(stones = [10, 20, 30, 40, 50]) == False\n assert candidate(stones = [3, 6, 9]) == False\n assert candidate(stones = [1, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73]) == True\n assert candidate(stones = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == True\n assert candidate(stones = [2]) == False\n assert candidate(stones = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(stones = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == False\n assert candidate(stones = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == False\n assert candidate(stones = [1, 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(stones = [1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2]) == True\n assert candidate(stones = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == False\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3]) == True\n assert candidate(stones = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == False\n assert candidate(stones = [1, 2, 4, 5, 7, 8, 10, 11]) == True\n assert candidate(stones = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == True\n assert candidate(stones = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == False\n assert candidate(stones = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == False\n assert candidate(stones = [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, 77, 80, 83, 86]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 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(stones = [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]) == True\n assert candidate(stones = [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, 77, 80]) == False\n assert candidate(stones = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1]) == True\n assert candidate(stones = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28]) == False\n assert candidate(stones = [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]) == False\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == False\n assert candidate(stones = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29]) == False\n assert candidate(stones = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == False\n assert candidate(stones = [5, 1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 4, 3]) == True\n assert candidate(stones = [1, 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 8, 8, 9, 10, 10, 10, 11, 12, 12, 12, 13, 14, 15, 16, 16, 17, 18, 18, 19, 19, 20]) == False\n assert candidate(stones = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == False\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == False\n assert candidate(stones = [3, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51]) == False\n assert candidate(stones = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(stones = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17]) == True\n assert candidate(stones = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4]) == True\n assert candidate(stones = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == True\n assert candidate(stones = [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]) == False\n assert candidate(stones = [1, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1]) == True\n assert candidate(stones = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == False\n assert candidate(stones = [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]) == False\n assert candidate(stones = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 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(stones = [3, 6, 9, 12, 15, 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22]) == False\n assert candidate(stones = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == True\n assert candidate(stones = [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]) == False\n assert candidate(stones = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == False\n assert candidate(stones = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 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(stones = [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == True\n assert candidate(stones = [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(stones = [3, 6, 9, 2, 5, 8, 11, 14, 17, 20]) == True\n assert candidate(stones = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == False\n assert candidate(stones = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == False\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == False\n assert candidate(stones = [1, 2, 1, 2, 1, 2, 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(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(stones = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29]) == True\n assert candidate(stones = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(stones = [1, 2, 2, 1, 2, 1, 2, 2, 1]) == True\n assert candidate(stones = [1, 2, 2, 2, 3, 3, 3, 3, 4, 5, 6, 6, 6, 6, 7, 8, 9]) == False\n assert candidate(stones = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == False\n assert candidate(stones = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]) == False\n assert candidate(stones = [1001, 1004, 1007, 1010, 1013, 1016, 1019, 1022, 1025, 1028, 1031, 1034, 1037, 1040, 1043, 1046, 1049, 1052, 1055, 1058]) == False\n assert candidate(stones = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == True\n assert candidate(stones = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == False\n assert candidate(stones = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == True\n assert candidate(stones = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]) == False\n assert candidate(stones = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == True\n assert candidate(stones = [1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6]) == True\n assert candidate(stones = [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]) == False\n assert candidate(stones = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180]) == False\n assert candidate(stones = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == True\n assert candidate(stones = [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, 3, 3]) == True\n assert candidate(stones = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1]) == True\n assert candidate(stones = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7]) == True\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == False\n assert candidate(stones = [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, 77, 80, 83, 86, 89]) == False\n assert candidate(stones = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == False\n assert candidate(stones = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58]) == False\n assert candidate(stones = [1, 2, 2, 1, 2, 2, 1, 2]) == True\n assert candidate(stones = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == False\n assert candidate(stones = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(stones = [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(stones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == False\n assert candidate(stones = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == True\n assert candidate(stones = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11]) == True\n assert candidate(stones = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == True\n", "comparison": "exact"}, "public_tests": ["[2,1]", "[2]", "[5,1,2,4,3]"], "hints": ["There are limited outcomes given the current sum and the stones remaining.", "Can we greedily simulate starting with taking a stone with remainder 1 or 2 divided by 3?"], "metadata": {"canonical_parameter_names": ["stones"], "leetcode_dataset_entry_point": "Solution().stoneGameIX", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:44+00:00", "tests_total": 108, "tests_dropped": 4, "flags": ["figure_reference"], "topic_tags": ["array", "math", "greedy", "minimax-algorithm", "counting", "game-theory", "nim-game", "zero-sum-game"]}, "language": "php", "interface": {"raw_signature": "function stoneGameIX($stones) {", "container": "Solution", "callable": "stoneGameIX", "parameters": [{"name": "stones", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2030, "task_id": "smallest-k-length-subsequence-with-occurrences-of-a-letter", "difficulty": "Hard", "problem_description": "You are given a string s, an integer k, a letter letter, and an integer repetition.\n\nReturn the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases are generated so that the letter appears in s at least repetition times.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nA string a is lexicographically smaller than a string b 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\nExample 1:\n\nInput: s = \"leet\", k = 3, letter = \"e\", repetition = 1\nOutput: \"eet\"\nExplanation: There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:\n- \"lee\" (from \"leet\")\n- \"let\" (from \"leet\")\n- \"let\" (from \"leet\")\n- \"eet\" (from \"leet\")\nThe lexicographically smallest subsequence among them is \"eet\".\n\nExample 2:\n\nInput: s = \"leetcode\", k = 4, letter = \"e\", repetition = 2\nOutput: \"ecde\"\nExplanation: \"ecde\" is the lexicographically smallest subsequence of length 4 that has the letter \"e\" appear at least 2 times.\n\nExample 3:\n\nInput: s = \"bb\", k = 2, letter = \"b\", repetition = 2\nOutput: \"bb\"\nExplanation: \"bb\" is the only subsequence of length 2 that has the letter \"b\" appear at least 2 times.\n\nConstraints:\n\n- 1 <= repetition <= k <= s.length <= 5 * 10^4\n- s consists of lowercase English letters.\n- letter is a lowercase English letter, and appears in s at least repetition times.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"bb\",k = 2,letter = \"b\",repetition = 2) == \"bb\"\n assert candidate(s = \"leetcode\",k = 4,letter = \"e\",repetition = 2) == \"ecde\"\n assert candidate(s = \"leet\",k = 3,letter = \"e\",repetition = 1) == \"eet\"\n assert candidate(s = \"aabbc\",k = 3,letter = \"a\",repetition = 1) == \"aab\"\n assert candidate(s = \"abacabad\",k = 4,letter = \"a\",repetition = 2) == \"aaaa\"\n assert candidate(s = \"zzzzz\",k = 3,letter = \"z\",repetition = 3) == \"zzz\"\n assert candidate(s = \"abcdedcba\",k = 5,letter = \"d\",repetition = 1) == \"abcda\"\n assert candidate(s = \"zzzzzaaaaa\",k = 5,letter = \"a\",repetition = 3) == \"aaaaa\"\n assert candidate(s = \"apple\",k = 3,letter = \"p\",repetition = 1) == \"ape\"\n assert candidate(s = \"abacabadabacaba\",k = 7,letter = \"a\",repetition = 3) == \"aaaaaaa\"\n assert candidate(s = \"azbzczdz\",k = 4,letter = \"z\",repetition = 2) == \"abzz\"\n assert candidate(s = \"abcdedcba\",k = 5,letter = \"c\",repetition = 1) == \"abcba\"\n assert candidate(s = \"xyzxyzxyz\",k = 5,letter = \"z\",repetition = 2) == \"xxyzz\"\n assert candidate(s = \"abcdedcba\",k = 5,letter = \"c\",repetition = 2) == \"abcca\"\n assert candidate(s = \"zzzz\",k = 2,letter = \"z\",repetition = 2) == \"zz\"\n assert candidate(s = \"abcabcabc\",k = 6,letter = \"a\",repetition = 2) == \"aababc\"\n assert candidate(s = \"abcdabcdabcd\",k = 9,letter = \"b\",repetition = 3) == \"ababcabcd\"\n assert candidate(s = \"elephant\",k = 4,letter = \"e\",repetition = 1) == \"eant\"\n assert candidate(s = \"zazbzazbzazb\",k = 8,letter = \"z\",repetition = 4) == \"abzazbzz\"\n assert candidate(s = \"babcbabcbabc\",k = 5,letter = \"b\",repetition = 3) == \"aabbb\"\n assert candidate(s = \"abcdedcbaabcdedcbaabcdedcba\",k = 15,letter = \"c\",repetition = 3) == \"aaabcaabcdedcba\"\n assert candidate(s = \"aaaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\",k = 20,letter = \"c\",repetition = 4) == \"aaaaaaaaaaaabbbbcccc\"\n assert candidate(s = \"aaaaaabbbbbbcccccc\",k = 12,letter = \"b\",repetition = 4) == \"aaaaaabbbbbb\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 26,letter = \"z\",repetition = 1) == \"aabcdefghijklmnopqrstuvwxz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 13,letter = \"m\",repetition = 1) == \"abcdefghijklm\"\n assert candidate(s = \"mississippi\",k = 5,letter = \"i\",repetition = 2) == \"iiipi\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\",k = 26,letter = \"a\",repetition = 2) == \"ayxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"ababababababababababababababababababababababab\",k = 10,letter = \"a\",repetition = 3) == \"aaaaaaaaaa\"\n assert candidate(s = \"xyzyxyzyxyzyxyzyzyzyxyzyzyzyzyzyxyzyxyzyzyzyzyzy\",k = 15,letter = \"x\",repetition = 3) == \"xxxxxxxyyyyzyzy\"\n assert candidate(s = \"aabbccddeeff\",k = 8,letter = \"c\",repetition = 3) == \"aabbccd\"\n assert candidate(s = \"zzzzzaaaaabbbb\",k = 10,letter = \"a\",repetition = 4) == \"zaaaaabbbb\"\n assert candidate(s = \"mississippi\",k = 4,letter = \"i\",repetition = 2) == \"iiii\"\n assert candidate(s = \"mississippi\",k = 6,letter = \"i\",repetition = 2) == \"iiippi\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 50,letter = \"z\",repetition = 10) == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 20,letter = \"a\",repetition = 2) == \"aabbccddeeffgghhiijj\"\n assert candidate(s = \"banana\",k = 4,letter = \"a\",repetition = 2) == \"aana\"\n assert candidate(s = \"abcdabcdabcd\",k = 8,letter = \"b\",repetition = 3) == \"abababcd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 10,letter = \"m\",repetition = 2) == \"abcdefghm\"\n assert candidate(s = \"abracadabra\",k = 7,letter = \"a\",repetition = 3) == \"aaaabra\"\n assert candidate(s = \"zyxzyxzyx\",k = 5,letter = \"x\",repetition = 2) == \"xxzyx\"\n assert candidate(s = \"abracadabraabracadabra\",k = 12,letter = \"a\",repetition = 4) == \"aaaaaaaaabra\"\n assert candidate(s = \"racecar\",k = 5,letter = \"e\",repetition = 1) == \"acear\"\n assert candidate(s = \"abcdabcabcabc\",k = 9,letter = \"c\",repetition = 3) == \"aabcabcac\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwerty\",k = 12,letter = \"r\",repetition = 2) == \"erabnmqwerty\"\n assert candidate(s = \"xyzyzyzyzyx\",k = 7,letter = \"y\",repetition = 3) == \"xyyyyyx\"\n", "comparison": "exact"}, "public_tests": ["\"leet\"\n3\n\"e\"\n1", "\"leetcode\"\n4\n\"e\"\n2", "\"bb\"\n2\n\"b\"\n2"], "hints": ["Use stack. For every character to be appended, decide how many character(s) from the stack needs to get popped based on the stack length and the count of the required character.", "Pop the extra characters out from the stack and return the characters in the stack (reversed)."], "metadata": {"canonical_parameter_names": ["s", "k", "letter", "repetition"], "leetcode_dataset_entry_point": "Solution().smallestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:46+00:00", "tests_total": 45, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["string", "stack", "greedy", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function smallestSubsequence($s, $k, $letter, $repetition) {", "container": "Solution", "callable": "smallestSubsequence", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}, {"name": "letter", "type": "String"}, {"name": "repetition", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2032, "task_id": "two-out-of-three", "difficulty": "Easy", "problem_description": "Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.\n\nExample 1:\n\nInput: nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]\nOutput: [3,2]\nExplanation: The values that are present in at least two arrays are:\n- 3, in all three arrays.\n- 2, in nums1 and nums2.\n\nExample 2:\n\nInput: nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]\nOutput: [2,3,1]\nExplanation: The values that are present in at least two arrays are:\n- 2, in nums2 and nums3.\n- 3, in nums1 and nums2.\n- 1, in nums1 and nums3.\n\nExample 3:\n\nInput: nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]\nOutput: []\nExplanation: No value is present in at least two arrays.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length, nums3.length <= 100\n- 1 <= nums1[i], nums2[j], nums3[k] <= 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(nums1=[5, 6, 7], nums2=[5, 6, 8], nums3=[7, 6, 9]), [5, 6, 7])\n assert answers_match(candidate(nums1=[100], nums2=[100], nums3=[100]), [100])\n assert answers_match(candidate(nums1=[5, 5, 5], nums2=[5, 5, 5], nums3=[5, 5, 5]), [5])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[40, 50, 60], nums3=[10, 50, 90]), [10, 50])\n assert answers_match(candidate(nums1=[1, 2, 3], nums2=[4, 5, 6], nums3=[7, 8, 9]), [])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[20, 30, 40], nums3=[30, 40, 50]), [20, 30, 40])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[5, 4, 3, 2, 1], nums3=[1, 3, 5, 7, 9]), [1, 2, 3, 4, 5])\n assert answers_match(candidate(nums1=[1, 2], nums2=[2, 3], nums3=[3, 4]), [2, 3])\n assert answers_match(candidate(nums1=[1, 2, 2], nums2=[4, 3, 3], nums3=[5]), [])\n assert answers_match(candidate(nums1=[1, 1, 3, 2], nums2=[2, 3], nums3=[3]), [2, 3])\n assert answers_match(candidate(nums1=[3, 1], nums2=[2, 3], nums3=[1, 2]), [1, 2, 3])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[5, 6, 7, 8, 9], nums3=[3, 4, 5, 10, 11]), [3, 4, 5])\n assert answers_match(candidate(nums1=[10], nums2=[10, 20], nums3=[10, 30]), [10])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[5, 6, 7, 8, 9, 10, 11, 12, 13, 14], nums3=[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]), [5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[11, 12, 13, 14, 15, 16, 17, 18, 19, 20], nums3=[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]), [])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[15, 25, 35, 45, 55], nums3=[20, 30, 40, 50, 60]), [20, 30, 40, 50])\n assert answers_match(candidate(nums1=[1, 2, 3, 1, 2, 3], nums2=[3, 4, 5, 3, 4, 5], nums3=[5, 6, 7, 5, 6, 7]), [3, 5])\n assert answers_match(candidate(nums1=[99, 98, 97, 96, 95], nums2=[94, 93, 92, 91, 90], nums3=[95, 94, 93, 92, 91]), [91, 92, 93, 94, 95])\n assert answers_match(candidate(nums1=[6, 7, 8, 9, 10], nums2=[1, 2, 3, 4, 5], nums3=[5, 6, 7]), [5, 6, 7])\n assert answers_match(candidate(nums1=[50, 50, 50, 50], nums2=[50, 50, 50, 50], nums3=[50, 50, 50, 50]), [50])\n assert answers_match(candidate(nums1=[5, 10, 15, 20], nums2=[10, 20, 30, 40], nums3=[15, 20, 25, 30]), [10, 15, 20, 30])\n assert answers_match(candidate(nums1=[50, 51, 52, 53, 54, 55], nums2=[55, 56, 57, 58, 59], nums3=[59, 60, 61, 62, 63]), [55, 59])\n assert answers_match(candidate(nums1=[7, 7, 7, 7, 7], nums2=[7, 7, 7, 7, 8], nums3=[7, 7, 7, 7, 9]), [7])\n assert answers_match(candidate(nums1=[15, 25, 35, 45, 55], nums2=[55, 65, 75, 85, 95], nums3=[15, 25, 35, 45, 55]), [15, 25, 35, 45, 55])\n assert answers_match(candidate(nums1=[1, 1, 1, 1, 1], nums2=[2, 2, 2, 2, 2], nums3=[1, 2, 3, 4, 5]), [1, 2])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[5, 15, 25, 35, 45], nums3=[10, 25, 40, 55]), [10, 25, 40])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[5, 15, 25, 35, 45], nums3=[10, 20, 30, 40, 50]), [10, 20, 30, 40, 50])\n assert answers_match(candidate(nums1=[60, 61, 62, 63], nums2=[63, 64, 65, 66], nums3=[66, 67, 68, 69]), [63, 66])\n assert answers_match(candidate(nums1=[1, 1, 2, 2], nums2=[2, 2, 3, 3], nums3=[3, 3, 1, 1]), [1, 2, 3])\n assert answers_match(candidate(nums1=[50, 51, 52, 53, 54], nums2=[55, 56, 57, 58, 59], nums3=[50, 51, 52, 53, 54]), [50, 51, 52, 53, 54])\n assert answers_match(candidate(nums1=[1, 1, 1, 2, 2, 3], nums2=[2, 2, 2, 3, 3, 3], nums3=[3, 3, 3, 4, 4, 4]), [2, 3])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[50, 60, 70, 80, 90], nums3=[90, 10, 20, 30, 100]), [10, 20, 30, 50, 90])\n assert answers_match(candidate(nums1=[10, 20, 30, 40], nums2=[40, 50, 60], nums3=[10, 50, 70]), [10, 40, 50])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6], nums2=[2, 3, 4, 5, 6, 7], nums3=[3, 4, 5, 6, 7, 8]), [2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(nums1=[99, 98, 97], nums2=[96, 95, 94], nums3=[93, 92, 91]), [])\n assert answers_match(candidate(nums1=[7, 14, 21, 28], nums2=[14, 28, 42, 56], nums3=[21, 42, 63, 84]), [14, 21, 28, 42])\n assert answers_match(candidate(nums1=[99, 100], nums2=[1, 2], nums3=[3, 4]), [])\n assert answers_match(candidate(nums1=[1, 1, 1, 1], nums2=[1, 1, 1, 1], nums3=[2, 2, 2, 2]), [1])\n assert answers_match(candidate(nums1=[90, 91, 92], nums2=[91, 92, 93], nums3=[92, 93, 94]), [91, 92, 93])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[20, 30, 40], nums3=[30, 40, 50]), [20, 30, 40])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[4, 5, 6, 7, 8], nums3=[5, 8, 9, 10, 11]), [4, 5, 8])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[5, 4, 3, 2, 1], nums3=[1, 3, 5, 7, 9]), [1, 2, 3, 4, 5])\n assert answers_match(candidate(nums1=[20, 30, 40, 50], nums2=[50, 60, 70, 80], nums3=[80, 90, 100, 20]), [20, 50, 80])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[30, 40, 50], nums3=[50, 60, 70]), [30, 50])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[11, 12, 13, 14, 15, 16, 17, 18, 19, 20], nums3=[21, 22, 23, 24, 25, 1, 2, 3]), [1, 2, 3])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[11, 12, 13, 14, 15, 16, 17, 18, 19, 20], nums3=[5, 10, 15, 20]), [5, 10, 15, 20])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[1, 4, 7, 10]), [1, 4, 7, 10])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[30, 40, 50], nums3=[50, 60, 70, 10]), [10, 30, 50])\n assert answers_match(candidate(nums1=[99, 98, 97, 96, 95], nums2=[94, 95, 96, 97, 98], nums3=[93, 94, 95, 96, 97]), [94, 95, 96, 97, 98])\n assert answers_match(candidate(nums1=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50], nums2=[5, 15, 25, 35, 45, 55, 65, 75, 85, 95], nums3=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50])\n assert answers_match(candidate(nums1=[4, 5, 6], nums2=[7, 8, 9], nums3=[4, 7, 10]), [4, 7])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[4, 5, 6, 7, 8], nums3=[7, 8, 9, 10, 1]), [1, 4, 5, 7, 8])\n assert answers_match(candidate(nums1=[10, 20, 30, 40], nums2=[30, 40, 50, 60], nums3=[50, 60, 70, 80]), [30, 40, 50, 60])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[60, 70, 80, 90, 10], nums3=[11, 22, 33, 44, 50]), [10, 50])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[1, 3, 5, 7, 9]), [1, 3, 5, 7, 9])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9, 11], nums2=[2, 4, 6, 8, 10, 12], nums3=[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 answers_match(candidate(nums1=[10, 20, 30, 40], nums2=[20, 30, 40, 50], nums3=[30, 40, 50, 60]), [20, 30, 40, 50])\n assert answers_match(candidate(nums1=[10], nums2=[20, 30, 40, 50, 10], nums3=[10, 60, 70, 80, 90]), [10])\n assert answers_match(candidate(nums1=[9, 8, 7, 6, 5, 4, 3, 2, 1], nums2=[1, 3, 5, 7, 9], nums3=[2, 4, 6, 8, 10]), [1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[5, 6, 7, 8, 9], nums3=[9, 1, 2, 3]), [1, 2, 3, 5, 9])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[1, 2, 3, 4, 5]), [1, 2, 3, 4, 5])\n assert answers_match(candidate(nums1=[1, 2, 3], nums2=[4, 5, 6], nums3=[7, 8, 9]), [])\n assert answers_match(candidate(nums1=[60, 61, 62, 63, 64], nums2=[65, 66, 67, 68, 69], nums3=[60, 61, 62, 63, 64, 65]), [60, 61, 62, 63, 64, 65])\n assert answers_match(candidate(nums1=[1, 1, 1, 1], nums2=[1, 2, 3, 4], nums3=[1, 5, 6, 7]), [1])\n assert answers_match(candidate(nums1=[90, 91, 92, 93], nums2=[91, 92, 93, 94], nums3=[92, 93, 94, 95]), [91, 92, 93, 94])\n assert answers_match(candidate(nums1=[10, 20, 30], nums2=[30, 40, 50], nums3=[50, 60, 10]), [10, 30, 50])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[1, 5, 9, 10, 11]), [1, 5, 9, 10])\n assert answers_match(candidate(nums1=[1, 2], nums2=[1, 3], nums3=[1, 4]), [1])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[10, 20, 60, 70, 80], nums3=[30, 40, 50, 60, 90]), [10, 20, 30, 40, 50, 60])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[3, 6, 9, 12]), [3, 6, 9])\n assert answers_match(candidate(nums1=[1, 1, 1, 1], nums2=[1, 2, 2, 2], nums3=[1, 2, 3, 3]), [1, 2])\n assert answers_match(candidate(nums1=[99, 98, 97], nums2=[97, 96, 95], nums3=[95, 94, 93]), [95, 97])\n assert answers_match(candidate(nums1=[50, 51, 52, 53, 54], nums2=[50, 55, 56, 57, 58], nums3=[50, 51, 59, 60, 61]), [50, 51])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[5, 6, 7, 8, 9], nums3=[9, 10, 1, 11, 12]), [1, 5, 9])\n assert answers_match(candidate(nums1=[1, 4, 7, 9], nums2=[2, 4, 7, 10], nums3=[3, 4, 8, 9]), [4, 7, 9])\n assert answers_match(candidate(nums1=[7, 8, 9], nums2=[10, 11, 12], nums3=[13, 14, 15]), [])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5], nums2=[3, 4, 5, 6, 7], nums3=[5, 6, 7, 8, 9]), [3, 4, 5, 6, 7])\n assert answers_match(candidate(nums1=[1, 2, 3], nums2=[4, 5, 6], nums3=[1, 2, 3, 4, 5]), [1, 2, 3, 4, 5])\n assert answers_match(candidate(nums1=[10, 20, 30, 40, 50], nums2=[20, 30, 40, 50, 60], nums3=[30, 40, 50, 60, 70]), [20, 30, 40, 50, 60])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[5, 10, 15, 20, 25]), [5, 10])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9], nums2=[2, 4, 6, 8, 10], nums3=[3, 4, 5, 6, 7]), [3, 4, 5, 6, 7])\n assert answers_match(candidate(nums1=[2, 4, 6, 8, 10], nums2=[1, 3, 5, 7, 9], nums3=[2, 4, 6, 8, 10]), [2, 4, 6, 8, 10])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[2, 3, 4, 5, 6, 7, 8, 9, 10, 1], nums3=[3, 4, 5, 6, 7, 8, 9, 10, 1, 2]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n assert answers_match(candidate(nums1=[5, 10, 15, 20, 25], nums2=[25, 30, 35, 40, 45], nums3=[45, 50, 55, 60, 65]), [25, 45])\n assert answers_match(candidate(nums1=[1, 2, 3], nums2=[1, 2, 4, 5], nums3=[2, 3, 4, 6]), [1, 2, 3, 4])\n assert answers_match(candidate(nums1=[5, 10, 15, 20, 25], nums2=[10, 15, 20, 25, 30], nums3=[15, 20, 25, 30, 35]), [10, 15, 20, 25, 30])\n assert answers_match(candidate(nums1=[33, 44, 55, 66], nums2=[22, 33, 44, 55], nums3=[11, 22, 33, 44]), [22, 33, 44, 55])\n assert answers_match(candidate(nums1=[20, 30, 40, 50], nums2=[20, 30, 40], nums3=[20, 30]), [20, 30, 40])\n assert answers_match(candidate(nums1=[5, 15, 25, 35], nums2=[5, 15, 45, 55], nums3=[5, 25, 45, 65]), [5, 15, 25, 45])\n assert answers_match(candidate(nums1=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums2=[11, 12, 13, 14, 15, 16, 17, 18, 19, 20], nums3=[1, 11, 3, 13, 5, 15, 7, 17, 9, 19]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(candidate(nums1=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], nums2=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], nums3=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n assert answers_match(candidate(nums1=[1, 1, 2, 2, 3, 3], nums2=[1, 2, 3, 4, 5, 6], nums3=[3, 4, 5, 6, 7, 8]), [1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(nums1=[1, 1, 2, 2, 3, 3, 4, 4, 5, 5], nums2=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nums3=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]), [1, 2, 3, 4, 5, 7, 9])\n assert answers_match(candidate(nums1=[90, 91, 92], nums2=[92, 93, 94], nums3=[94, 95, 96, 97, 90]), [90, 92, 94])\n assert answers_match(candidate(nums1=[1, 1, 2, 2, 3], nums2=[3, 3, 4, 4, 5], nums3=[5, 5, 6, 6, 7]), [3, 5])\n assert answers_match(candidate(nums1=[1, 1, 1, 1, 1], nums2=[1, 1, 1, 1, 2], nums3=[2, 2, 2, 2, 2]), [1, 2])\n", "comparison": "unordered"}, "public_tests": ["[1,1,3,2]\n[2,3]\n[3]", "[3,1]\n[2,3]\n[1,2]", "[1,2,2]\n[4,3,3]\n[5]"], "hints": ["What data structure can we use to help us quickly find whether an element belongs in an array?", "Can we count the frequencies of the elements in each array?"], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "nums3"], "leetcode_dataset_entry_point": "Solution().twoOutOfThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:50+00:00", "tests_total": 100, "tests_dropped": 4, "flags": ["any_order"], "topic_tags": ["array", "hash-table", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function twoOutOfThree($nums1, $nums2, $nums3) {", "container": "Solution", "callable": "twoOutOfThree", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "nums3", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2033, "task_id": "minimum-operations-to-make-a-uni-value-grid", "difficulty": "Medium", "problem_description": "You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.\n\nA uni-value grid is a grid where all the elements of it are equal.\n\nReturn the minimum number of operations to make the grid uni-value. If it is not possible, return -1.\n\nExample 1:\n\nInput: grid = [[2,4],[6,8]], x = 2\nOutput: 4\nExplanation: We can make every element equal to 4 by doing the following:\n- Add x to 2 once.\n- Subtract x from 6 once.\n- Subtract x from 8 twice.\nA total of 4 operations were used.\n\nExample 2:\n\nInput: grid = [[1,5],[2,3]], x = 1\nOutput: 5\nExplanation: We can make every element equal to 3.\n\nExample 3:\n\nInput: grid = [[1,2],[3,4]], x = 2\nOutput: -1\nExplanation: It is impossible to make every element equal.\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- 1 <= x, grid[i][j] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 5], [2, 3]],x = 1) == 5\n assert candidate(grid = [[10, 10], [10, 10]],x = 5) == 0\n assert candidate(grid = [[10, 10], [10, 10]],x = 3) == 0\n assert candidate(grid = [[10, 12], [14, 16]],x = 2) == 4\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],x = 1) == 0\n assert candidate(grid = [[2, 4], [6, 8]],x = 2) == 4\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],x = 1) == 20\n assert candidate(grid = [[1, 2], [3, 4]],x = 2) == -1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],x = 5) == 0\n assert candidate(grid = [[1, 1, 1], [1, 1, 1]],x = 3) == 0\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],x = 2) == -1\n assert candidate(grid = [[1, 1], [2, 2]],x = 3) == -1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],x = 1) == 0\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9]],x = 1) == 20\n assert candidate(grid = [[1, 3, 5, 7], [9, 11, 13, 15], [17, 19, 21, 23]],x = 2) == 36\n assert candidate(grid = [[7, 14, 21, 28, 35], [42, 49, 56, 63, 70], [77, 84, 91, 98, 105], [112, 119, 126, 133, 140]],x = 7) == 100\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900]],x = 100) == 20\n assert candidate(grid = [[5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],x = 1) == 36\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]],x = 1) == 81\n assert candidate(grid = [[1, 2], [3, 4], [5, 6]],x = 1) == 9\n assert candidate(grid = [[1, 5, 9], [13, 17, 21], [25, 29, 33]],x = 4) == 20\n assert candidate(grid = [[7, 14, 21], [14, 28, 42], [21, 42, 63]],x = 7) == 17\n assert candidate(grid = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],x = 1) == 8\n assert candidate(grid = [[2, 4, 6, 8], [10, 12, 14, 16], [18, 20, 22, 24]],x = 2) == 36\n assert candidate(grid = [[1, 2], [3, 4], [5, 7]],x = 2) == -1\n assert candidate(grid = [[7, 7, 7], [7, 8, 7], [7, 7, 7]],x = 1) == 1\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],x = 1) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],x = 2) == -1\n assert candidate(grid = [[7, 11, 15], [19, 23, 27], [31, 35, 39]],x = 2) == 40\n assert candidate(grid = [[1, 1, 1], [2, 2, 2], [3, 3, 3]],x = 1) == 6\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],x = 15) == -1\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 5, 7, 9, 11]],x = 2) == -1\n assert candidate(grid = [[3, 6, 9, 12], [15, 18, 21, 24], [27, 30, 33, 36], [39, 42, 45, 48]],x = 3) == 64\n assert candidate(grid = [[100, 200], [300, 400]],x = 100) == 4\n assert candidate(grid = [[1001, 1002, 1003, 1004], [1005, 1006, 1007, 1008], [1009, 1010, 1011, 1012]],x = 1) == 36\n assert candidate(grid = [[3, 6, 9, 12], [6, 12, 18, 24], [9, 18, 27, 36], [12, 24, 36, 48]],x = 3) == 54\n assert candidate(grid = [[1, 3, 5], [7, 9, 11], [13, 15, 17]],x = 2) == 20\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 2, 1]],x = 1) == 1\n assert candidate(grid = [[5000, 5000, 5000], [5000, 5000, 5000], [5000, 5000, 5000]],x = 1000) == 0\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],x = 3) == -1\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45]],x = 5) == 20\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18]],x = 2) == 20\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],x = 7) == -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]],x = 1) == 100\n assert candidate(grid = [[10, 20, 30, 40, 50], [60, 70, 80, 90, 100]],x = 10) == 25\n assert candidate(grid = [[10, 20, 30], [20, 30, 40], [30, 40, 50]],x = 10) == 8\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18]],x = 5) == -1\n assert candidate(grid = [[4, 8, 12, 16], [8, 16, 24, 32], [12, 24, 36, 48], [16, 32, 48, 64]],x = 4) == 54\n assert candidate(grid = [[4, 8, 12], [16, 20, 24], [28, 32, 36]],x = 4) == 20\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 2]],x = 1) == 1\n assert candidate(grid = [[101, 202, 303], [404, 505, 606], [707, 808, 909]],x = 101) == 20\n assert candidate(grid = [[7, 14, 21, 28], [35, 42, 49, 56], [63, 70, 77, 84]],x = 7) == 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]],x = 5) == -1\n assert candidate(grid = [[1, 3, 5, 7, 9], [11, 13, 15, 17, 19], [21, 23, 25, 27, 29]],x = 2) == 56\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],x = 4) == -1\n assert candidate(grid = [[1, 5, 9], [2, 6, 10], [3, 7, 11]],x = 2) == -1\n assert candidate(grid = [[1, 3, 5, 7, 9], [11, 13, 15, 17, 19], [21, 23, 25, 27, 29], [31, 33, 35, 37, 39]],x = 2) == 100\n assert candidate(grid = [[101, 102, 103], [104, 105, 106], [107, 108, 109]],x = 1) == 20\n assert candidate(grid = [[1, 4, 7, 10], [13, 16, 19, 22], [25, 28, 31, 34]],x = 3) == 36\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5]],x = 1) == 8\n assert candidate(grid = [[1, 5, 9], [2, 6, 10], [3, 7, 11]],x = 3) == -1\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 10]],x = 5) == 1\n assert candidate(grid = [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60]],x = 5) == 36\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],x = 10) == -1\n assert candidate(grid = [[5, 9, 13], [17, 21, 25], [29, 33, 37]],x = 4) == 20\n assert candidate(grid = [[3, 6, 9], [12, 15, 18], [21, 24, 27]],x = 3) == 20\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],x = 10) == 20\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]],x = 5) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1]],x = 1) == 1\n assert candidate(grid = [[3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 4]],x = 1) == 1\n assert candidate(grid = [[3, 9, 15], [12, 15, 18], [21, 24, 27]],x = 3) == 17\n assert candidate(grid = [[5, 15, 25, 35], [45, 55, 65, 75], [85, 95, 105, 115], [125, 135, 145, 155]],x = 10) == 64\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18]],x = 3) == -1\n assert candidate(grid = [[100, 102, 104], [106, 108, 110], [112, 114, 116]],x = 2) == 20\n assert candidate(grid = [[3, 9, 15], [21, 27, 33], [39, 45, 51]],x = 6) == 20\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 2, 1]],x = 1) == 1\n assert candidate(grid = [[5, 15, 25], [35, 45, 55], [65, 75, 85]],x = 10) == 20\n assert candidate(grid = [[1, 1, 1, 2], [1, 1, 2, 2], [1, 2, 2, 3]],x = 1) == 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]],x = 1) == 0\n assert candidate(grid = [[123, 456, 789], [1011, 1213, 1415], [1617, 1819, 2021]],x = 3) == -1\n assert candidate(grid = [[1, 3, 5, 7], [9, 11, 13, 15], [17, 19, 21, 23], [25, 27, 29, 31]],x = 2) == 64\n assert candidate(grid = [[5, 10, 15, 20], [10, 20, 30, 40], [15, 30, 45, 60]],x = 5) == 30\n assert candidate(grid = [[2, 4, 6, 8, 10], [12, 14, 16, 18, 20], [22, 24, 26, 28, 30]],x = 2) == 56\n assert candidate(grid = [[1, 5, 9, 13, 17], [21, 25, 29, 33, 37], [41, 45, 49, 53, 57]],x = 4) == 56\n assert candidate(grid = [[2, 4, 6, 8], [10, 12, 14, 16], [18, 20, 22, 24], [26, 28, 30, 32]],x = 2) == 64\n assert candidate(grid = [[7, 14, 21], [28, 35, 42], [49, 56, 63]],x = 7) == 20\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]],x = 10) == 36\n assert candidate(grid = [[5, 15, 25, 35], [45, 55, 65, 75], [85, 95, 105, 115]],x = 10) == 36\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],x = 1) == 36\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],x = 1) == 56\n assert candidate(grid = [[3, 6, 9, 12], [15, 18, 21, 24], [27, 30, 33, 36]],x = 3) == 36\n assert candidate(grid = [[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]],x = 3) == -1\n assert candidate(grid = [[4, 8, 12, 16], [20, 24, 28, 32], [36, 40, 44, 48]],x = 4) == 36\n assert candidate(grid = [[2, 4, 6], [8, 10, 12], [14, 16, 18]],x = 1) == 40\n assert candidate(grid = [[11, 22, 33], [44, 55, 66], [77, 88, 99]],x = 11) == 20\n", "comparison": "exact"}, "public_tests": ["[[2,4],[6,8]]\n2", "[[1,5],[2,3]]\n1", "[[1,2],[3,4]]\n2"], "hints": ["Is it possible to make two integers a and b equal if they have different remainders dividing by x?", "If it is possible, which number should you select to minimize the number of operations?", "What if the elements are sorted?"], "metadata": {"canonical_parameter_names": ["grid", "x"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:53+00:00", "tests_total": 95, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "sorting", "matrix"]}, "language": "php", "interface": {"raw_signature": "function minOperations($grid, $x) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "x", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2035, "task_id": "partition-array-into-two-arrays-to-minimize-sum-difference", "difficulty": "Hard", "problem_description": "You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.\n\nReturn the minimum possible absolute difference.\n\nExample 1:\n\nInput: nums = [3,9,7,3]\nOutput: 2\nExplanation: One optimal partition is: [3,9] and [7,3].\nThe absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.\n\nExample 2:\n\nInput: nums = [-36,36]\nOutput: 72\nExplanation: One optimal partition is: [-36] and [36].\nThe absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.\n\nExample 3:\n\nInput: nums = [2,-1,0,4,-2,-9]\nOutput: 0\nExplanation: One optimal partition is: [2,4,-9] and [-1,0,-2].\nThe absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0.\n\nConstraints:\n\n- 1 <= n <= 15\n- nums.length == 2 * n\n- -10^7 <= nums[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 9, 7, 3]) == 2\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]) == 0\n assert candidate(nums = [10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000]) == 0\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 = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000]) == 5000000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 30]) == 0\n assert candidate(nums = [10000000, -10000000, 5000000, -5000000, 2500000, -2500000, 1250000, -1250000]) == 0\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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, -1, 0, 4, -2, -9]) == 0\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 = [1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40]) == 0\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000, 10000000, -10000000]) == 0\n assert candidate(nums = [10000000, -10000000, 10000000, -10000000, 10000000, -10000000]) == 20000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == 0\n assert candidate(nums = [-36, 36]) == 72\n assert candidate(nums = [-1, -2, -3, -4, -5, -6]) == 1\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 = [-1000, 1000, -1500, 1500, -2000, 2000, -2500, 2500, -3000, 3000, -3500, 3500, -4000, 4000, -4500, 4500]) == 0\n assert candidate(nums = [987654, -987654, 876543, -876543, 765432, -765432, 654321, -654321, 543210, -543210, 432109, -432109, 321098, -321098, 210987, -210987]) == 0\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 = [1000000, -1000000, 500000, -500000, 250000, -250000, 125000, -125000, 62500, -62500, 31250, -31250, 15625, -15625, 7812, -7812]) == 0\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75]) == 0\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800]) == 0\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 0\n assert candidate(nums = [1234567, -7654321, 8901234, -4321098, 5678901, -1234567, 8765432, -2345678, 9876543, -3456789, 4567890, -5678901, 6789012, -6789012, 7890123, -7890123]) == 7307\n assert candidate(nums = [1000000, -1000000, 2000000, -2000000, 3000000, -3000000, 4000000, -4000000, 5000000, -5000000, 6000000, -6000000, 7000000, -7000000, 8000000, -8000000]) == 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\n assert candidate(nums = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, -10000000, -10000000, -10000000, -10000000, -10000000, -10000000]) == 0\n assert candidate(nums = [0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1]) == 0\n assert candidate(nums = [-9, 9, -8, 8, -7, 7, -6, 6, -5, 5, -4, 4, -3, 3, -2, 2]) == 0\n assert candidate(nums = [-1000, 1000, -2000, 2000, -3000, 3000, -4000, 4000, -5000, 5000, -6000, 6000, -7000, 7000, -8000, 8000]) == 0\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 = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [12345, -12345, 67890, -67890, 11111, -11111, 22222, -22222, 33333, -33333, 44444, -44444, 55555, -55555, 66666, -66666]) == 0\n assert candidate(nums = [123, 456, 789, -123, -456, -789, 321, 654, 987, -321, -654, -987, 234, 567, 890, -234, -567, -890]) == 4\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 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 0\n assert candidate(nums = [-10000, 10000, -20000, 20000, -30000, 30000, -40000, 40000, -50000, 50000, -60000, 60000, -70000, 70000, -80000, 80000]) == 0\n assert candidate(nums = [5, 2, 9, 11, 15, 18, 3, 7, 14, 6, 10, 4, 8, 13, 1, 12]) == 0\n assert candidate(nums = [100000, -100000, 200000, -200000, 300000, -300000, 400000, -400000, 500000, -500000, 600000, -600000, 700000, -700000, 800000, -800000]) == 0\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8]) == 0\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]) == 0\n assert candidate(nums = [-100, -200, -300, -400, -500, 500, 400, 300, 200, 100, 0, 100, 200, 300, 400, 500]) == 100\n assert candidate(nums = [9999999, -9999999, 4999999, -4999999, 2499999, -2499999, 1249999, -1249999, 624999, -624999, 312499, -312499, 156249, -156249, 78124, -78124]) == 0\n assert candidate(nums = [1000, -500, 2000, -1500, 3000, -2500, 4000, -3500, 5000, -4500, 6000, -5500, 7000, -6500, 8000, -7500]) == 0\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 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 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, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15]) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80]) == 0\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 1100, -1200, 1300, -1400, 1500, -1600]) == 0\n assert candidate(nums = [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, -11, -12, -13, -14, -15, -16]) == 0\n assert candidate(nums = [1000000, -1000000, 500000, -500000, 250000, -250000, 750000, -750000, 375000, -375000, 187500, -187500, 937500, -937500, 468750, -468750]) == 0\n assert candidate(nums = [-7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 0\n assert candidate(nums = [100, 200, 300, 400, -500, 600, -700, 800, -900, 1000, -1100, 1200, -1300, 1400, -1500, 1600]) == 0\n assert candidate(nums = [-5, 5, -10, 10, -15, 15, -20, 20, -25, 25, -30, 30, -35, 35, -40, 40]) == 0\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500, -600, 600, -700, 700, -800, 800]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == 0\n assert candidate(nums = [-5, 5, -5, 5, -5, 5, -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, 120, 130, 140, 150, 160]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 0\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50, -60, 60, -70, 70, -80, 80]) == 0\n assert candidate(nums = [23, 45, 67, 89, 12, 34, 56, 78, 90, 11, 33, 55, 77, 99, 22, 44]) == 3\n assert candidate(nums = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000, 0, -1000000, -2000000, -3000000, -4000000, -5000000]) == 0\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 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [10000000, -9999999, 9999998, -9999997, 9999996, -9999995, 9999994, -9999993, 9999992, -9999991, 9999990, -9999989, 9999988, -9999987, 9999986, -9999985]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100000]) == 99999\n assert candidate(nums = [9999999, -9999999, 8888888, -8888888, 7777777, -7777777, 6666666, -6666666, 5555555, -5555555, 4444444, -4444444, 3333333, -3333333, 2222222, -2222222]) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]) == 0\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8]) == 0\n assert candidate(nums = [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, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == 0\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == 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 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [5, 3, 8, 1, 9, 2, 6, 4, 7, 0, 11, 13, 15, 17, 19, 21]) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 0\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16]) == 0\n", "comparison": "exact"}, "public_tests": ["[3,9,7,3]", "[-36,36]", "[2,-1,0,4,-2,-9]"], "hints": ["The target sum for the two partitions is sum(nums) / 2.", "Could you reduce the time complexity if you arbitrarily divide nums into two halves (two arrays)? Meet-in-the-Middle?", "For both halves, pre-calculate a 2D array where the kth index will store all possible sum values if only k elements from this half are added.", "For each sum of k elements in the first half, find the best sum of n-k elements in the second half such that the two sums add up to a value closest to the target sum from hint 1. These two subsets will form one array of the partition."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:38:55+00:00", "tests_total": 88, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "binary-search", "dynamic-programming", "bit-manipulation", "meet-in-the-middle", "sorting", "ordered-set", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function minimumDifference($nums) {", "container": "Solution", "callable": "minimumDifference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2037, "task_id": "minimum-number-of-moves-to-seat-everyone", "difficulty": "Easy", "problem_description": "There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the i^th seat. You are also given the array students of length n, where students[j] is the position of the j^th student.\n\nYou may perform the following move any number of times:\n\n- Increase or decrease the position of the i^th student by 1 (i.e., moving the i^th student from position x to x + 1 or x - 1)\n\nReturn the minimum number of moves required to move each student to a seat such that no two students are in the same seat.\n\nNote that there may be multiple seats or students in the same position at the beginning.\n\nExample 1:\n\nInput: seats = [3,1,5], students = [2,7,4]\nOutput: 4\nExplanation: The students are moved as follows:\n- The first student is moved from position 2 to position 1 using 1 move.\n- The second student is moved from position 7 to position 5 using 2 moves.\n- The third student is moved from position 4 to position 3 using 1 move.\nIn total, 1 + 2 + 1 = 4 moves were used.\n\nExample 2:\n\nInput: seats = [4,1,5,9], students = [1,3,2,6]\nOutput: 7\nExplanation: The students are moved as follows:\n- The first student is not moved.\n- The second student is moved from position 3 to position 4 using 1 move.\n- The third student is moved from position 2 to position 5 using 3 moves.\n- The fourth student is moved from position 6 to position 9 using 3 moves.\nIn total, 0 + 1 + 3 + 3 = 7 moves were used.\n\nExample 3:\n\nInput: seats = [2,2,6,6], students = [1,3,2,6]\nOutput: 4\nExplanation: Note that there are two seats at position 2 and two seats at position 6.\nThe students are moved as follows:\n- The first student is moved from position 1 to position 2 using 1 move.\n- The second student is moved from position 3 to position 6 using 3 moves.\n- The third student is not moved.\n- The fourth student is not moved.\nIn total, 1 + 3 + 0 + 0 = 4 moves were used.\n\nConstraints:\n\n- n == seats.length == students.length\n- 1 <= n <= 100\n- 1 <= seats[i], students[j] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(seats = [5, 5, 5, 5],students = [5, 5, 5, 5]) == 0\n assert candidate(seats = [10, 20, 30],students = [5, 15, 25]) == 15\n assert candidate(seats = [4, 1, 5, 9],students = [1, 3, 2, 6]) == 7\n assert candidate(seats = [1, 1, 1, 1],students = [1, 1, 1, 1]) == 0\n assert candidate(seats = [3, 1, 5],students = [2, 7, 4]) == 4\n assert candidate(seats = [1, 1, 1],students = [1, 1, 1]) == 0\n assert candidate(seats = [50, 50, 50],students = [49, 50, 51]) == 2\n assert candidate(seats = [10, 20, 30],students = [15, 25, 35]) == 15\n assert candidate(seats = [10, 20, 30],students = [1, 2, 3]) == 54\n assert candidate(seats = [100, 1, 50],students = [50, 100, 1]) == 0\n assert candidate(seats = [10, 20, 30, 40, 50],students = [5, 15, 25, 35, 45]) == 25\n assert candidate(seats = [100, 1, 50, 50],students = [50, 1, 100, 50]) == 0\n assert candidate(seats = [100, 1, 2, 3, 4],students = [1, 2, 3, 4, 100]) == 0\n assert candidate(seats = [100, 90, 80, 70],students = [70, 80, 90, 100]) == 0\n assert candidate(seats = [50, 50, 50],students = [50, 50, 50]) == 0\n assert candidate(seats = [10, 1, 100],students = [5, 10, 99]) == 5\n assert candidate(seats = [1, 2, 3, 4, 5],students = [5, 4, 3, 2, 1]) == 0\n assert candidate(seats = [2, 2, 6, 6],students = [1, 3, 2, 6]) == 4\n assert candidate(seats = [1, 3, 5, 7, 9],students = [2, 4, 6, 8, 10]) == 5\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 495\n assert candidate(seats = [5, 5, 5, 5, 5, 5],students = [1, 2, 3, 4, 5, 6]) == 11\n assert candidate(seats = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 495\n assert candidate(seats = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],students = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]) == 95\n assert candidate(seats = [20, 30, 40, 50, 60, 70, 80],students = [15, 25, 35, 45, 55, 65, 75]) == 35\n assert candidate(seats = [50, 50, 50, 50, 50, 50],students = [45, 45, 45, 55, 55, 55]) == 30\n assert candidate(seats = [3, 3, 8, 8, 10, 10, 13, 13],students = [2, 3, 6, 8, 9, 10, 12, 15]) == 7\n assert candidate(seats = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],students = [95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 0\n assert candidate(seats = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],students = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28]) == 20\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],students = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],students = [10, 1, 9, 2, 8, 3, 7, 4, 6, 5]) == 0\n assert candidate(seats = [1, 100, 1, 100, 1, 100],students = [50, 50, 50, 50, 50, 50]) == 297\n assert candidate(seats = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],students = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 300\n assert candidate(seats = [90, 80, 70, 60, 50, 40, 30],students = [10, 20, 30, 40, 50, 60, 70]) == 140\n assert candidate(seats = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],students = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 495\n assert candidate(seats = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],students = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 250\n assert candidate(seats = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],students = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 30\n assert candidate(seats = [99, 100, 1, 2, 3, 4],students = [5, 6, 7, 8, 9, 1]) == 191\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 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],students = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(seats = [30, 10, 20, 40, 50, 60],students = [5, 15, 25, 35, 45, 55]) == 30\n assert candidate(seats = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 980\n assert candidate(seats = [1, 5, 9, 13, 17, 21, 25, 29],students = [2, 6, 10, 14, 18, 22, 26, 30]) == 8\n assert candidate(seats = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],students = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 9\n assert candidate(seats = [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],students = [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]) == 0\n assert candidate(seats = [5, 5, 5, 5, 5],students = [1, 2, 3, 4, 5]) == 10\n assert candidate(seats = [2, 2, 2, 3, 3, 3, 5, 5, 5, 6, 6, 6],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 32\n assert candidate(seats = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],students = [41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 0\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [95, 85, 75, 65, 55, 45, 35, 25, 15, 5]) == 50\n assert candidate(seats = [8, 12, 20, 25, 30, 35],students = [5, 10, 15, 22, 31, 36]) == 15\n assert candidate(seats = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],students = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 90\n assert candidate(seats = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96],students = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) == 450\n assert candidate(seats = [5, 3, 8, 9, 2, 10],students = [4, 6, 7, 1, 11, 15]) == 11\n assert candidate(seats = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],students = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29]) == 10\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],students = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 45\n assert candidate(seats = [50, 50, 50, 50, 50],students = [49, 50, 51, 52, 53]) == 7\n assert candidate(seats = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 130\n assert candidate(seats = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],students = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]) == 40\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 0\n assert candidate(seats = [2, 3, 5, 6, 8, 11, 13],students = [1, 4, 7, 9, 10, 12, 15]) == 12\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],students = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(seats = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],students = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 540\n assert candidate(seats = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],students = [1, 7, 13, 19, 24, 29, 34, 38, 44, 49]) == 17\n assert candidate(seats = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],students = [6, 5, 5, 4, 4, 3, 3, 2, 2, 1]) == 0\n assert candidate(seats = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],students = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(seats = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(seats = [1, 3, 6, 8, 10, 15],students = [2, 4, 5, 7, 9, 16]) == 6\n assert candidate(seats = [50, 40, 30, 20, 10, 100, 90, 80, 70, 60],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 495\n assert candidate(seats = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],students = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 10\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]) == 90\n assert candidate(seats = [3, 8, 15, 22, 29],students = [1, 6, 13, 21, 28]) == 8\n assert candidate(seats = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],students = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == 20\n assert candidate(seats = [1, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 42\n assert candidate(seats = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],students = [3, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57]) == 35\n assert candidate(seats = [1, 4, 6, 9, 12, 15],students = [3, 5, 7, 10, 13, 16]) == 7\n assert candidate(seats = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],students = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 210\n assert candidate(seats = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],students = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(seats = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],students = [45, 46, 47, 48, 49, 51, 52, 53, 54, 55]) == 30\n assert candidate(seats = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 100\n assert candidate(seats = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 31\n assert candidate(seats = [2, 3, 5, 7, 11, 13, 17, 19],students = [1, 4, 6, 8, 10, 12, 14, 16]) == 12\n assert candidate(seats = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],students = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 15\n assert candidate(seats = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],students = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(seats = [1, 3, 6, 8, 10, 15],students = [2, 4, 7, 9, 11, 16]) == 6\n assert candidate(seats = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 17\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99]) == 10\n assert candidate(seats = [95, 96, 97, 98, 99, 100],students = [1, 2, 3, 4, 5, 6]) == 564\n assert candidate(seats = [5, 15, 25, 35, 45, 55],students = [1, 7, 17, 27, 37, 47]) == 44\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 540\n assert candidate(seats = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],students = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 890\n assert candidate(seats = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],students = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 0\n assert candidate(seats = [5, 6, 8, 10, 15, 17, 20, 25, 30, 35],students = [4, 5, 7, 10, 12, 16, 18, 22, 28, 34]) == 15\n assert candidate(seats = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],students = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 50\n assert candidate(seats = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10],students = [1, 3, 3, 5, 5, 7, 7, 9, 9, 11]) == 10\n assert candidate(seats = [20, 20, 20, 20, 20],students = [19, 20, 21, 22, 23]) == 7\n assert candidate(seats = [95, 55, 10, 30, 70],students = [5, 90, 60, 40, 80]) == 35\n assert candidate(seats = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],students = [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24]) == 800\n assert candidate(seats = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6],students = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == 3\n", "comparison": "exact"}, "public_tests": ["[3,1,5]\n[2,7,4]", "[4,1,5,9]\n[1,3,2,6]", "[2,2,6,6]\n[1,3,2,6]"], "hints": ["Can we sort the arrays to help solve the problem?", "Can we greedily match each student to a seat?", "The smallest positioned student will go to the smallest positioned chair, and then the next smallest positioned student will go to the next smallest positioned chair, and so on."], "metadata": {"canonical_parameter_names": ["seats", "students"], "leetcode_dataset_entry_point": "Solution().minMovesToSeat", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:00+00:00", "tests_total": 101, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "greedy", "sorting", "counting-sort"]}, "language": "php", "interface": {"raw_signature": "function minMovesToSeat($seats, $students) {", "container": "Solution", "callable": "minMovesToSeat", "parameters": [{"name": "seats", "type": "Integer[]"}, {"name": "students", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2038, "task_id": "remove-colored-pieces-if-both-neighbors-are-the-same-color", "difficulty": "Medium", "problem_description": "There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the i^th piece.\n\nAlice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.\n\n- Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.\n- Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.\n- Alice and Bob cannot remove pieces from the edge of the line.\n- If a player cannot make a move on their turn, that player loses and the other player wins.\n\nAssuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.\n\nExample 1:\n\nInput: colors = \"AAABABB\"\nOutput: true\nExplanation:\nAAABABB -> AABABB\nAlice moves first.\nShe removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.\n\nNow it's Bob's turn.\nBob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.\nThus, Alice wins, so return true.\n\nExample 2:\n\nInput: colors = \"AA\"\nOutput: false\nExplanation:\nAlice has her turn first.\nThere are only two 'A's and both are on the edge of the line, so she cannot move on her turn.\nThus, Bob wins, so return false.\n\nExample 3:\n\nInput: colors = \"ABBBBBBBAAA\"\nOutput: false\nExplanation:\nABBBBBBBAAA -> ABBBBBBBAA\nAlice moves first.\nHer only option is to remove the second to last 'A' from the right.\n\nABBBBBBBAA -> ABBBBBBAA\nNext is Bob's turn.\nHe has many options for which 'B' piece to remove. He can pick any.\n\nOn Alice's second turn, she has no more pieces that she can remove.\nThus, Bob wins, so return false.\n\nConstraints:\n\n- 1 <= colors.length <= 10^5\n- colors consists of only the letters 'A' and 'B'\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(colors = \"AABBAABB\") == False\n assert candidate(colors = \"AAAAAAAAA\") == True\n assert candidate(colors = \"AAABAAAAABBBB\") == True\n assert candidate(colors = \"ABABABABAB\") == False\n assert candidate(colors = \"AABBBBAAA\") == False\n assert candidate(colors = \"BBBBB\") == False\n assert candidate(colors = \"BBBAAAABB\") == True\n assert candidate(colors = \"AAAAAAAA\") == True\n assert candidate(colors = \"AAAAA\") == True\n assert candidate(colors = \"AAABBBAAABBBA\") == False\n assert candidate(colors = \"AAABABB\") == True\n assert candidate(colors = \"AABBBBAA\") == False\n assert candidate(colors = \"AAAABBBB\") == False\n assert candidate(colors = \"BBBBBBBBB\") == False\n assert candidate(colors = \"ABBBBBBBAAA\") == False\n assert candidate(colors = \"ABABABABABA\") == False\n assert candidate(colors = \"ABABABAB\") == False\n assert candidate(colors = \"AAAAABBAAA\") == True\n assert candidate(colors = \"AABAABBBBAAA\") == False\n assert candidate(colors = \"ABABAB\") == False\n assert candidate(colors = \"BBBAAABB\") == False\n assert candidate(colors = \"ABAAABAA\") == True\n assert candidate(colors = \"AA\") == False\n assert candidate(colors = \"BBBBAAAABBB\") == False\n assert candidate(colors = \"AAAABBBAA\") == True\n assert candidate(colors = \"AABBBAAABBB\") == False\n assert candidate(colors = \"ABABABABABABAB\") == False\n assert candidate(colors = \"AAABBBAAABBBAABBBAAABBBAABBB\") == False\n assert candidate(colors = \"AABBABBABBABBABBABBA\") == False\n assert candidate(colors = \"ABAABAABAABAABAABA\") == False\n assert candidate(colors = \"BBBBBBBBBBAAAABBB\") == False\n assert candidate(colors = \"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"AAABAAAABBAAABBBBAAAABBB\") == True\n assert candidate(colors = \"AABAABAABAABAABAA\") == False\n assert candidate(colors = \"AABBBAAABBBAABBAAABBBAABB\") == False\n assert candidate(colors = \"BBBBBBBBBBABBBBBBBBB\") == False\n assert candidate(colors = \"ABABABABABABABABABABAB\") == False\n assert candidate(colors = \"ABABABABABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"AAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"AABBBAAABBBAAABBB\") == False\n assert candidate(colors = \"AABBAABBBAABBBAABBBAABBA\") == False\n assert candidate(colors = \"ABABABABABABABABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"AAABAAAAAAAAABBBBBBB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBB\") == True\n assert candidate(colors = \"ABABABABABABABABA\") == False\n assert candidate(colors = \"BBBBBBBBBBAAAAAAAAAAB\") == False\n assert candidate(colors = \"BBBAAAABBBAAAABBBAAAABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"BBABBABBABBABBABB\") == False\n assert candidate(colors = \"BAAAAAAAAAABBBBBBBBBB\") == False\n assert candidate(colors = \"AAABAAABBBAAABBBBAA\") == False\n assert candidate(colors = \"AABBBAAAABBBAAB\") == False\n assert candidate(colors = \"AABBAAAABBAAAABB\") == True\n assert candidate(colors = \"BBBAABBBAAABBBAABBB\") == False\n assert candidate(colors = \"AAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBB\") == True\n assert candidate(colors = \"AAAAAAAAAABBBBBBBBBBB\") == False\n assert candidate(colors = \"AAAABBBBBBAAAABBBBBB\") == False\n assert candidate(colors = \"AAAAAABAAAAAABAAAAAAB\") == True\n assert candidate(colors = \"BBBAAAAAAAAABBBBBB\") == True\n assert candidate(colors = \"BBABABABABABABABABAB\") == False\n assert candidate(colors = \"AAABBBAAABBBAAABBBAAABBBAAABBBAAABBB\") == False\n assert candidate(colors = \"AAAAAAAAAAAAAAAAAAAAAAAAA\") == True\n assert candidate(colors = \"AAAAAAAABBBBBBBBBB\") == False\n assert candidate(colors = \"ABBBAAAAABBAAAAAAA\") == True\n assert candidate(colors = \"BBBAAAABBAAAABBAAAABBAAAABBAAAABB\") == True\n assert candidate(colors = \"AAAABAAAABBAAAABBAAAABBAAAABBAAAAB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAABBBBBBBBBBBB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAA\") == True\n assert candidate(colors = \"AABBBAAAAABBBBAAA\") == True\n assert candidate(colors = \"AAAAAAAAAABBBBBBBBBB\") == False\n assert candidate(colors = \"AAABBBAAAABBBAAABBBAAABBBAA\") == True\n assert candidate(colors = \"AAABAAAABAAABAAAABAA\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAAA\") == True\n assert candidate(colors = \"AAAAAAAAABBBBBBBBAABBBBBBBBA\") == False\n assert candidate(colors = \"BBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"ABABABAAAABBBABAABAB\") == True\n assert candidate(colors = \"ABBBAAAABBAAAABBBA\") == True\n assert candidate(colors = \"AAABBBAABBBAAABBBA\") == False\n assert candidate(colors = \"AAABBBAABBBAABBBAAB\") == False\n assert candidate(colors = \"AAABBBAAAABBBAAABBBAA\") == True\n assert candidate(colors = \"ABABABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"BBBAAAABBBAAAABAA\") == True\n assert candidate(colors = \"AAABBBAAAABBBAAAABBBAAA\") == True\n assert candidate(colors = \"BBBBBAABAAAAAAABBB\") == True\n assert candidate(colors = \"AAABBAAAABBAAAABBAAAABBBAAAABB\") == True\n assert candidate(colors = \"BBBBBAAAAAAAAABBBBB\") == True\n assert candidate(colors = \"AAAAAAAAABBBBBBBBBBBB\") == False\n assert candidate(colors = \"BABAABABABABABABAB\") == False\n assert candidate(colors = \"AAABBBBAABBBBAA\") == False\n assert candidate(colors = \"BBAAABBBAAABBBAAABB\") == True\n assert candidate(colors = \"AAABAAABAAABAAABA\") == True\n assert candidate(colors = \"AAABBBAAABBBAAABBBAAABBBAAABBB\") == False\n assert candidate(colors = \"BBBBBBBBBB\") == False\n assert candidate(colors = \"BBAAAABBBAAABBBAAABB\") == True\n assert candidate(colors = \"AAAAAAAAAABBBBBBBB\") == True\n assert candidate(colors = \"BBBBBAAAABBBBBBBAAAAA\") == False\n assert candidate(colors = \"BBBBBAAAABBBBBAAAABBBBBAAAABBBBB\") == False\n assert candidate(colors = \"AAAAABBBBBAAAAABBBBBAAAAA\") == True\n assert candidate(colors = \"ABBBAAAABBAAAABBBAABA\") == True\n assert candidate(colors = \"AAAABBBBAAAABBBBAAAABBBB\") == False\n assert candidate(colors = \"BBBBAAAABBBBBBBBAAA\") == False\n assert candidate(colors = \"ABABABABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBB\") == True\n assert candidate(colors = \"BBBBBBAAAABBBBBBBBAAA\") == False\n assert candidate(colors = \"AABAAAAAAABBBBBBBBA\") == False\n assert candidate(colors = \"BBBAABBBAAAABBBAAABBB\") == False\n assert candidate(colors = \"ABABABABAAAAAAAABBBBBBBB\") == False\n assert candidate(colors = \"BBAAAABBBAAAABBAAA\") == True\n assert candidate(colors = \"BBAABBAAAABBAAAABBBB\") == True\n assert candidate(colors = \"AAABBBAABBAAABBBAAAAAAABBBB\") == True\n assert candidate(colors = \"AAAAABBAAAABBAAAAB\") == True\n assert candidate(colors = \"ABBBAAAABBBBAAA\") == False\n assert candidate(colors = \"BBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"BBBBBBAAAAAAAAAA\") == True\n assert candidate(colors = \"BBAAAABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"ABBBAAAABBBAAAABB\") == True\n assert candidate(colors = \"BBBBBAABBBBAABBBBAABBBBA\") == False\n assert candidate(colors = \"BBBBBBBBBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"BBBBBBBAAAAAAAAAAAABB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"ABABABABABABABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"BBBBAAAABBBBBAAAABBBBBAAAABB\") == False\n assert candidate(colors = \"AABAAABAABAAABAAA\") == True\n assert candidate(colors = \"ABABABABABABABABAB\") == False\n assert candidate(colors = \"BBBAAAABBAAAABBAAAABBB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAABBBBBBBBBBB\") == True\n assert candidate(colors = \"AABBBAAABBAAAABBAAAAB\") == True\n assert candidate(colors = \"AAABAAABAAABAAABAAABAAAB\") == True\n assert candidate(colors = \"ABABABABABABABABABABABABABAB\") == False\n assert candidate(colors = \"AAAAAABBBBBBAAA\") == True\n assert candidate(colors = \"BBBAAAABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"ABABABABABABABABABABA\") == False\n assert candidate(colors = \"AAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"AAAABBAABBABBAABBBAAA\") == True\n assert candidate(colors = \"ABAAAABBBBAABBBBAA\") == False\n assert candidate(colors = \"AAABAAAABBBBAAAABBBBAAAABBBBAAAABBB\") == True\n assert candidate(colors = \"AAAAAAAAAAAAABBBBBBBBBBBBB\") == False\n assert candidate(colors = \"AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"BABAABBAABBBBAAAABBBB\") == False\n assert candidate(colors = \"AABBAABBAABBAAA\") == True\n assert candidate(colors = \"AAAAAAAAABBBBBBBB\") == True\n assert candidate(colors = \"BBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAA\") == True\n assert candidate(colors = \"BBAABBAAAABBBBAAAAABBBAAABBBAAABBBB\") == True\n assert candidate(colors = \"AAAAAAAAABBAAAAAAAAA\") == True\n assert candidate(colors = \"AAAABBBAAAABBB\") == True\n assert candidate(colors = \"AABBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"AAAAAAAABBBBBBBBBBAAA\") == False\n assert candidate(colors = \"AAAABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"AAAAAAAAABBBBBBB\") == True\n assert candidate(colors = \"BBAAAABBAAAABBAAAABBAAAABBB\") == True\n assert candidate(colors = \"AABBBAAAABBBAAA\") == True\n assert candidate(colors = \"BBBBBBBBAAAABBBBBBB\") == False\n assert candidate(colors = \"BBBBBAAAABBBBBAAAABBBBBAAAABBBBBAAAABBBBBAAAABBBBB\") == False\n assert candidate(colors = \"BBABABABBABABABBABABABBB\") == False\n assert candidate(colors = \"BBAABBAAAABBAAAABBAAAABBB\") == True\n assert candidate(colors = \"BBBAAAABBAAAABBB\") == True\n assert candidate(colors = \"BBBBBBBBBBBBBBBBBB\") == False\n assert candidate(colors = \"AAAABBBBAAAA\") == True\n assert candidate(colors = \"BBBBAABBBAABBBAAB\") == False\n assert candidate(colors = \"AAAAAAAAAA\") == True\n assert candidate(colors = \"BBBBBBAAAABBBBBBAAAABBBBBB\") == False\n assert candidate(colors = \"BAAABAAABAAABBB\") == True\n assert candidate(colors = \"AAABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"AAAAAABBBBAAAABBBBAAAAA\") == True\n assert candidate(colors = \"BBBAAAAAAAABBBBBB\") == True\n assert candidate(colors = \"AAABBBAABBBAAABBBAABBB\") == False\n assert candidate(colors = \"BABABABABABABABAB\") == False\n assert candidate(colors = \"AABAAAAABBAAABAAAAABB\") == True\n assert candidate(colors = \"BBBBBAAAABBBBBAAAABBBBBAAAABBBBBAAAABBBBB\") == False\n assert candidate(colors = \"BBBAAABBBAAABBBAAA\") == False\n assert candidate(colors = \"AAABAAAAAAAABBBBBBB\") == True\n assert candidate(colors = \"BBBBBBBBAAAAAAAAAA\") == True\n assert candidate(colors = \"ABABABABABABABABABAB\") == False\n assert candidate(colors = \"ABBBBAAAAAABBBBBAAA\") == False\n assert candidate(colors = \"AAABAAABBBABBAAA\") == True\n assert candidate(colors = \"AABBBAAAAAAAAABBBBB\") == True\n assert candidate(colors = \"BBAAAABBBAAAABBBAAAABBBAAA\") == True\n assert candidate(colors = \"BBBBBBBAAAAAAAAAA\") == True\n assert candidate(colors = \"AABBBAAAABBBAAAABBB\") == True\n assert candidate(colors = \"AAAAAAAAAABBBBBBBBAAAAAAAAAABBBBBBBB\") == True\n assert candidate(colors = \"AABAAABAAABAAABAAABAAABAAABAAABAAAB\") == True\n assert candidate(colors = \"BBBBBAAAABBBBBAAAAABBBBBAAABBBAAAB\") == False\n", "comparison": "exact"}, "public_tests": ["\"AAABABB\"", "\"AA\"", "\"ABBBBBBBAAA\""], "hints": ["Does the number of moves a player can make depend on what the other player does? No", "How many moves can Alice make if colors == \"AAAAAA\"", "If a group of n consecutive pieces has the same color, the player can take n - 2 of those pieces if n is greater than or equal to 3"], "metadata": {"canonical_parameter_names": ["colors"], "leetcode_dataset_entry_point": "Solution().winnerOfGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:02+00:00", "tests_total": 182, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string", "greedy", "game-theory"]}, "language": "php", "interface": {"raw_signature": "function winnerOfGame($colors) {", "container": "Solution", "callable": "winnerOfGame", "parameters": [{"name": "colors", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2039, "task_id": "the-time-when-the-network-becomes-idle", "difficulty": "Medium", "problem_description": "There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [u_i, v_i] indicates there is a message channel between servers u_i and v_i, and they can pass any number of messages to each other directly in one second. You are also given a 0-indexed integer array patience of length n.\n\nAll servers are connected, i.e., a message can be passed from one server to any other server(s) directly or indirectly through the message channels.\n\nThe server labeled 0 is the master server. The rest are data servers. Each data server needs to send its message to the master server for processing and wait for a reply. Messages move between servers optimally, so every message takes the least amount of time to arrive at the master server. The master server will process all newly arrived messages instantly and send a reply to the originating server via the reversed path the message had gone through.\n\nAt the beginning of second 0, each data server sends its message to be processed. Starting from second 1, at the beginning of every second, each data server will check if it has received a reply to the message it sent (including any newly arrived replies) from the master server:\n\n- If it has not, it will resend the message periodically. The data server i will resend the message every patience[i] second(s), i.e., the data server i will resend the message if patience[i] second(s) have elapsed since the last time the message was sent from this server.\n- Otherwise, no more resending will occur from this server.\n\nThe network becomes idle when there are no messages passing between servers or arriving at servers.\n\nReturn the earliest second starting from which the network becomes idle.\n\nExample 1:\n\nInput: edges = [[0,1],[1,2]], patience = [0,2,1]\nOutput: 8\nExplanation:\nAt (the beginning of) second 0,\n- Data server 1 sends its message (denoted 1A) to the master server.\n- Data server 2 sends its message (denoted 2A) to the master server.\n\nAt second 1,\n- Message 1A arrives at the master server. Master server processes message 1A instantly and sends a reply 1A back.\n- Server 1 has not received any reply. 1 second (1 < patience[1] = 2) elapsed since this server has sent the message, therefore it does not resend the message.\n- Server 2 has not received any reply. 1 second (1 == patience[2] = 1) elapsed since this server has sent the message, therefore it resends the message (denoted 2B).\n\nAt second 2,\n- The reply 1A arrives at server 1. No more resending will occur from server 1.\n- Message 2A arrives at the master server. Master server processes message 2A instantly and sends a reply 2A back.\n- Server 2 resends the message (denoted 2C).\n...\nAt second 4,\n- The reply 2A arrives at server 2. No more resending will occur from server 2.\n...\nAt second 7, reply 2D arrives at server 2.\n\nStarting from the beginning of the second 8, there are no messages passing between servers or arriving at servers.\nThis is the time when the network becomes idle.\n\nExample 2:\n\nInput: edges = [[0,1],[0,2],[1,2]], patience = [0,10,10]\nOutput: 3\nExplanation: Data servers 1 and 2 receive a reply back at the beginning of second 2.\nFrom the beginning of the second 3, the network becomes idle.\n\nConstraints:\n\n- n == patience.length\n- 2 <= n <= 10^5\n- patience[0] == 0\n- 1 <= patience[i] <= 10^5 for 1 <= i < n\n- 1 <= edges.length <= min(10^5, n * (n - 1) / 2)\n- edges[i].length == 2\n- 0 <= u_i, v_i < n\n- u_i != v_i\n- There are no duplicate edges.\n- Each server can directly or indirectly reach another server.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [[0, 1], [1, 2]],patience = [0, 2, 1]) == 8\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]],patience = [0, 5, 5, 5]) == 3\n assert candidate(edges = [[0, 1], [1, 3], [3, 4], [2, 4]],patience = [0, 1, 2, 3, 4]) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 0]],patience = [0, 2, 1]) == 4\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4]],patience = [0, 1, 2, 3, 4]) == 13\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],patience = [0, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],patience = [0, 5, 4, 3, 2, 1, 6, 7, 8, 9]) == 28\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4]],patience = [0, 5, 2, 3, 1]) == 16\n assert candidate(edges = [[0, 1], [0, 2], [1, 2]],patience = [0, 10, 10]) == 3\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],patience = [0, 1, 2, 3, 4, 5, 6]) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],patience = [0, 1, 1, 5, 2, 3, 6]) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],patience = [0, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]],patience = [0, 4, 3, 2, 1, 5]) == 4\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, 0], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11], [12, 14]],patience = [0, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == 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]],patience = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(edges = [[0, 1], [1, 2], [2, 0], [0, 3], [3, 4], [4, 5], [5, 0], [0, 6], [6, 7], [7, 8], [8, 9], [9, 0]],patience = [0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 5\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, 0], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10]],patience = [0, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 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]],patience = [0, 5, 7, 3, 2, 1, 6, 4, 8, 9, 11]) == 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], [10, 11], [11, 12], [12, 13], [13, 14], [14, 0]],patience = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 23\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]],patience = [0, 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(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]],patience = [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]) == 9\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]],patience = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 58\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],patience = [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 7\n assert candidate(edges = [[0, 1], [1, 2], [0, 3], [3, 4], [2, 4], [4, 5], [5, 6]],patience = [0, 2, 1, 3, 4, 5, 6]) == 15\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0]],patience = [0, 100, 90, 80, 70, 60, 50, 40, 30]) == 9\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],patience = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\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]],patience = [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]) == 16\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, 0], [0, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 0]],patience = [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 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]],patience = [0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]) == 12\n assert candidate(edges = [[0, 1], [0, 3], [1, 2], [1, 4], [2, 5], [2, 7], [3, 6], [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]],patience = [0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == 9\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],patience = [0, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 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]],patience = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 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, 0]],patience = [0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12]) == 27\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]],patience = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 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], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19], [10, 20], [19, 21], [20, 22], [11, 23], [12, 24], [13, 25], [14, 26], [15, 27], [16, 28], [17, 29], [29, 30], [28, 31], [27, 32], [26, 33], [25, 34], [24, 35], [23, 36]],patience = [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]) == 13\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 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, 22], [8, 23], [8, 24], [8, 25]],patience = [0, 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]) == 7\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]],patience = [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]) == 29\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 5], [2, 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]],patience = [0, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 12\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9]],patience = [0, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 3\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]],patience = [0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11]) == 12\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]],patience = [0, 7, 7, 7, 7, 2, 2, 2, 2, 2, 2, 2, 2]) == 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], [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]],patience = [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]) == 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]],patience = [0, 15, 10, 20, 5, 12, 8, 6, 4, 7, 3]) == 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], [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]],patience = [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]) == 31\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 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], [7, 18], [7, 19], [8, 20], [8, 21], [9, 22], [9, 23], [10, 24], [10, 25], [11, 26], [11, 27], [12, 28], [12, 29], [13, 30], [13, 31], [14, 32], [14, 33], [15, 34], [15, 35]],patience = [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]) == 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]],patience = [0, 5, 5, 3, 3, 1, 1, 4, 4, 2, 2]) == 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]],patience = [0, 3, 2, 1, 6, 5, 4, 7, 8, 9, 12, 11, 10, 15, 14, 13, 18, 17, 16, 19, 20, 21, 24, 23, 22, 27, 26, 25, 28, 29, 30, 31, 32, 33, 34, 35]) == 9\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]],patience = [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]) == 119\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 5], [5, 6], [6, 0], [0, 7], [7, 8], [8, 9], [9, 0]],patience = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],patience = [0, 2, 5, 3, 4, 7, 8, 6, 1, 9, 10]) == 12\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]],patience = [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]) == 116\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,2]]\n[0,2,1]", "[[0,1],[0,2],[1,2]]\n[0,10,10]"], "hints": ["What method can you use to find the shortest time taken for a message from a data server to reach the master server? How can you use this value and the server's patience value to determine the time at which the server sends its last message?", "What is the time when the last message sent from a server gets back to the server?", "For each data server, by the time the server receives the first returned messages, how many messages has the server sent?"], "metadata": {"canonical_parameter_names": ["edges", "patience"], "leetcode_dataset_entry_point": "Solution().networkBecomesIdle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:05+00:00", "tests_total": 51, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "breadth-first-search", "graph"]}, "language": "php", "interface": {"raw_signature": "function networkBecomesIdle($edges, $patience) {", "container": "Solution", "callable": "networkBecomesIdle", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "patience", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2040, "task_id": "kth-smallest-product-of-two-sorted-arrays", "difficulty": "Hard", "problem_description": "Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the k^th (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nums1.length and 0 <= j < nums2.length.\n\nExample 1:\n\nInput: nums1 = [2,5], nums2 = [3,4], k = 2\nOutput: 8\nExplanation: The 2 smallest products are:\n- nums1[0] * nums2[0] = 2 * 3 = 6\n- nums1[0] * nums2[1] = 2 * 4 = 8\nThe 2^nd smallest product is 8.\n\nExample 2:\n\nInput: nums1 = [-4,-2,0,3], nums2 = [2,4], k = 6\nOutput: 0\nExplanation: The 6 smallest products are:\n- nums1[0] * nums2[1] = (-4) * 4 = -16\n- nums1[0] * nums2[0] = (-4) * 2 = -8\n- nums1[1] * nums2[1] = (-2) * 4 = -8\n- nums1[1] * nums2[0] = (-2) * 2 = -4\n- nums1[2] * nums2[0] = 0 * 2 = 0\n- nums1[2] * nums2[1] = 0 * 4 = 0\nThe 6^th smallest product is 0.\n\nExample 3:\n\nInput: nums1 = [-2,-1,0,1,2], nums2 = [-3,-1,2,4,5], k = 3\nOutput: -6\nExplanation: The 3 smallest products are:\n- nums1[0] * nums2[4] = (-2) * 5 = -10\n- nums1[0] * nums2[3] = (-2) * 4 = -8\n- nums1[4] * nums2[0] = 2 * (-3) = -6\nThe 3^rd smallest product is -6.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 5 * 10^4\n- -10^5 <= nums1[i], nums2[j] <= 10^5\n- 1 <= k <= nums1.length * nums2.length\n- nums1 and nums2 are sorted.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [-100000, 100000],nums2 = [-100000, 100000],k = 1) == -10000000000\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-1, 0, 1],k = 4) == 0\n assert candidate(nums1 = [-100000, -50000, 0, 50000, 100000],nums2 = [-100000, -50000, 0, 50000, 100000],k = 12) == 0\n assert candidate(nums1 = [-10, -9, -8, -7, -6],nums2 = [-5, -4, -3, -2, -1],k = 1) == 6\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],k = 25) == 90\n assert candidate(nums1 = [2, 5],nums2 = [3, 4],k = 2) == 8\n assert candidate(nums1 = [-4, -2, 0, 3],nums2 = [2, 4],k = 6) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5],k = 10) == 5\n assert candidate(nums1 = [-100000, 100000],nums2 = [-100000, 100000],k = 2) == -10000000000\n assert candidate(nums1 = [-5, -3, -1, 1, 3, 5],nums2 = [-5, -3, -1, 1, 3, 5],k = 18) == -1\n assert candidate(nums1 = [-2, -1, 0, 1, 2],nums2 = [-3, -1, 2, 4, 5],k = 3) == -6\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5],k = 25) == 25\n assert candidate(nums1 = [-10, -5, -1],nums2 = [1, 5, 10],k = 5) == -10\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6],k = 5) == 10\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0],k = 5) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],k = 12) == 0\n assert candidate(nums1 = [-5, -4, -3, -2, -1],nums2 = [-5, -4, -3, -2, -1],k = 12) == 6\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-10000, 0, 10000],k = 7) == 0\n assert candidate(nums1 = [-25, -15, -5, 5, 15, 25],nums2 = [-25, -15, -5, 0, 5, 15, 25],k = 30) == 75\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 25) == 1\n assert candidate(nums1 = [-50000, -25000, 0, 25000, 50000],nums2 = [-10000, -5000, 0, 5000, 10000],k = 7) == -125000000\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [-1, -1, -1, -1, -1],k = 25) == -1\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 = 50) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],k = 20) == 50\n assert candidate(nums1 = [-9, -3, 0, 1, 5],nums2 = [-6, -2, 1, 4, 7],k = 9) == -3\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-100, -50, 0, 50, 100],k = 10) == 0\n assert candidate(nums1 = [-1, -2, -3, -4, -5, 1, 2, 3, 4, 5],nums2 = [-1, -2, -3, -4, -5, 1, 2, 3, 4, 5],k = 49) == -2\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],k = 24) == 72\n assert candidate(nums1 = [-100, -50, 0, 50, 100],nums2 = [-200, -100, 0, 100, 200],k = 10) == 0\n assert candidate(nums1 = [-10, -5, -1, 0, 1, 5, 10],nums2 = [-20, -15, -10, -5, 0, 5, 10, 15, 20],k = 20) == -15\n assert candidate(nums1 = [-50, -25, 0, 25, 50],nums2 = [-50, -25, 0, 25, 50],k = 12) == 0\n assert candidate(nums1 = [100000],nums2 = [-100000, 0, 100000],k = 2) == 0\n assert candidate(nums1 = [-100000, 100000],nums2 = [-1, 1],k = 1) == -100000\n assert candidate(nums1 = [-1000, -900, -800],nums2 = [800, 900, 1000],k = 8) == -720000\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [-9, -7, -5, -3, -1],k = 15) == -15\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 15) == 0\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 13) == 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, 10],k = 45) == 20\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 2, 3, 4, 5],k = 20) == 1500\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000],nums2 = [-10000, -20000, -30000, -40000, -50000],k = 12) == -900000000\n assert candidate(nums1 = [-2, -1, 0, 1, 2],nums2 = [-2, -1, 0, 1, 2, 3, 4, 5],k = 15) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [2, 4, 6, 8, 10, 12],k = 36) == 132\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [-5, -10, -15, -20, -25],k = 10) == -600\n assert candidate(nums1 = [-1000, -500, -100, 0, 100, 500, 1000],nums2 = [-1000, -500, -100, 0, 100, 500, 1000],k = 48) == 1000000\n assert candidate(nums1 = [-2, 0, 2],nums2 = [-2, 0, 2],k = 3) == 0\n assert candidate(nums1 = [-1, -1, 0, 1, 1],nums2 = [-1, -1, 0, 1, 1],k = 12) == 0\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],k = 100) == 380\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-1, 0, 1],k = 3) == 0\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000],nums2 = [-1, -2, -3, -4, -5],k = 15) == -90000\n assert candidate(nums1 = [-10000, -5000, -1000, -500, -100, -50, -10, -5, -1, 0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000],nums2 = [-10000, -5000, -1000, -500, -100, -50, -10, -5, -1, 0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000],k = 361) == 100000000\n assert candidate(nums1 = [-1, 1],nums2 = [-100000, 100000],k = 1) == -100000\n assert candidate(nums1 = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 324) == 40\n assert candidate(nums1 = [-1, -1, -1, -1, -1],nums2 = [-1, -1, -1, -1, -1],k = 1) == 1\n assert candidate(nums1 = [-3, -2, -1, 0, 1, 2, 3],nums2 = [-3, -2, -1, 0, 1, 2, 3],k = 21) == 0\n assert candidate(nums1 = [-1, -1, -1, -1, -1],nums2 = [-1, -1, -1, -1, -1],k = 20) == 1\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-100000, -10000, -1000, -100, -10, -1, 0, 1, 10, 100, 1000, 10000, 100000],k = 13) == 0\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-1, 0, 1],k = 5) == 0\n assert candidate(nums1 = [-5, -3, -1, 1, 3, 5],nums2 = [-5, -3, -1, 1, 3, 5],k = 15) == -3\n assert candidate(nums1 = [-9, -7, -5, -3, -1],nums2 = [-9, -7, -5, -3, -1],k = 24) == 63\n assert candidate(nums1 = [-1, -1, -1, -1],nums2 = [-1, -1, -1, -1],k = 10) == 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],k = 50) == 240\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-1, 0, 1],k = 4) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],k = 10) == 0\n assert candidate(nums1 = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 100) == -15\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-2, -1, 0, 1, 2],k = 8) == -5\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 10) == 0\n assert candidate(nums1 = [-1, -1, -1, -1],nums2 = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],k = 5) == 1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],k = 12) == 20\n assert candidate(nums1 = [-1000, -900, -800, -700, -600],nums2 = [-1000, -900, -800, -700, -600],k = 20) == 800000\n assert candidate(nums1 = [-100, -50, 0, 50, 100],nums2 = [-100, -50, 0, 50, 100],k = 12) == 0\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 12) == 0\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-100000, -50000, -10000, -5000, -1000, -500, -100, -50, -10, -5, -1, 0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000],k = 50) == 5\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 25) == 100\n assert candidate(nums1 = [-1, 0, 1],nums2 = [-100, 0, 100],k = 4) == 0\n assert candidate(nums1 = [-5, -3, -1, 0, 1, 3, 5],nums2 = [-6, -4, -2, 0, 2, 4, 6],k = 15) == -4\n assert candidate(nums1 = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 441) == 100\n assert candidate(nums1 = [-5, -3, -1, 1, 3, 5],nums2 = [-6, -4, -2, 0, 2, 4, 6],k = 15) == -4\n assert candidate(nums1 = [-9, -7, -5, -3, -1],nums2 = [1, 3, 5, 7, 9],k = 10) == -27\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [-5, -4, -3, -2, -1],k = 25) == -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],k = 50) == 24\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],k = 45) == -36\n assert candidate(nums1 = [-3, -2, -1, 0, 1, 2, 3],nums2 = [-3, -2, -1, 0, 1, 2, 3],k = 20) == 0\n assert candidate(nums1 = [-1, -1, -1, -1, 1, 1, 1, 1],nums2 = [-1, -1, -1, -1, 1, 1, 1, 1],k = 32) == -1\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [-9, -7, -5, -3, -1],k = 25) == -1\n assert candidate(nums1 = [-50000, -40000, -30000, 0, 30000, 40000, 50000],nums2 = [-50000, 0, 50000],k = 20) == 2500000000\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [-5, -4, -3, -2, -1],k = 15) == -6\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-10, -5, 0, 5, 10],k = 20) == 50\n assert candidate(nums1 = [-1, 1, -1, 1, -1],nums2 = [-1, 1, -1, 1, -1],k = 10) == -1\n assert candidate(nums1 = [-9, -6, -3, 0, 3, 6, 9],nums2 = [-9, -6, -3, 0, 3, 6, 9],k = 49) == 81\n assert candidate(nums1 = [-10, -5, 0, 5, 10],nums2 = [-20, -15, -10, -5, 0, 5, 10, 15, 20],k = 30) == 25\n assert candidate(nums1 = [-100, -50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100],nums2 = [-100, -50, -25, -10, -5, -1, 0, 1, 5, 10, 25, 50, 100],k = 100) == 5\n assert candidate(nums1 = [-5, -4, -3, -2, -1],nums2 = [1, 2, 3, 4, 5],k = 25) == -1\n", "comparison": "exact"}, "public_tests": ["[2,5]\n[3,4]\n2", "[-4,-2,0,3]\n[2,4]\n6", "[-2,-1,0,1,2]\n[-3,-1,2,4,5]\n3"], "hints": ["Can we split this problem into four cases depending on the sign of the numbers?", "Can we binary search the value?"], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k"], "leetcode_dataset_entry_point": "Solution().kthSmallestProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:07+00:00", "tests_total": 108, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function kthSmallestProduct($nums1, $nums2, $k) {", "container": "Solution", "callable": "kthSmallestProduct", "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": 2042, "task_id": "check-if-numbers-are-ascending-in-a-sentence", "difficulty": "Easy", "problem_description": "A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lowercase English letters.\n\n- For example, \"a puppy has 2 eyes 4 legs\" is a sentence with seven tokens: \"2\" and \"4\" are numbers and the other tokens such as \"puppy\" are words.\n\nGiven a string s representing a sentence, you need to check if all the numbers in s are strictly increasing from left to right (i.e., other than the last number, each number is strictly smaller than the number on its right in s).\n\nReturn true if so, or false otherwise.\n\nExample 1:\n\nInput: s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"\nOutput: true\nExplanation: The numbers in s are: 1, 3, 4, 6, 12.\nThey are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.\n\nExample 2:\n\nInput: s = \"hello world 5 x 5\"\nOutput: false\nExplanation: The numbers in s are: 5, 5. They are not strictly increasing.\n\nExample 3:\n\nInput: s = \"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\"\nOutput: false\nExplanation: The numbers in s are: 7, 51, 50, 60. They are not strictly increasing.\n\nConstraints:\n\n- 3 <= s.length <= 200\n- s consists of lowercase English letters, spaces, and digits from 0 to 9, inclusive.\n- The number of tokens in s is between 2 and 100, inclusive.\n- The tokens in s are separated by a single space.\n- There are at least two numbers in s.\n- Each number in s is a positive number less than 100, with no leading zeros.\n- s contains no leading or trailing spaces.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"start 99 end 100\") == True\n assert candidate(s = \"1 apple 2 banana 3 cherry 4 date\") == True\n assert candidate(s = \"100 99 98 97 96\") == False\n assert candidate(s = \"5 15 25 35 45 55\") == True\n assert candidate(s = \"there are 10 cars 20 bikes and 30 trucks\") == True\n assert candidate(s = \"the times 10 20 30 40 50 are correct\") == True\n assert candidate(s = \"5 6 7 8 9 10 11\") == True\n assert candidate(s = \"the quick brown fox jumps over 1 lazy 2 dogs\") == True\n assert candidate(s = \"10 20 30 40 50\") == True\n assert candidate(s = \"start 1 end 2\") == True\n assert candidate(s = \"5 6 7 8 7\") == False\n assert candidate(s = \"but 100 99 98 are not\") == False\n assert candidate(s = \"100 99 98 97 96 95 94 93 92 91 90\") == False\n assert candidate(s = \"9 10 11 12 13\") == True\n assert candidate(s = \"i have 1 cat 2 dogs and 3 fish\") == True\n assert candidate(s = \"the temperature rose from 23 to 28 degrees\") == True\n assert candidate(s = \"hello world 5 x 5\") == False\n assert candidate(s = \"start 1 end 1\") == False\n assert candidate(s = \"the temperature is 23 degrees and will rise to 28 by afternoon\") == True\n assert candidate(s = \"he has 3 cats and 7 dogs\") == True\n assert candidate(s = \"the temperature is 23 degrees and rising to 28\") == True\n assert candidate(s = \"1 2 3 4 5 6 7 8 9\") == True\n assert candidate(s = \"2 apple 3 4 banana 5 6\") == True\n assert candidate(s = \"i have 1 apple 2 oranges and 3 bananas\") == True\n assert candidate(s = \"i saw 1 2 3 4 5 6 7 8 9 10\") == True\n assert candidate(s = \"i have 1 cat 2 dogs and 3 hamsters\") == True\n assert candidate(s = \"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\") == False\n assert candidate(s = \"9 10 11\") == True\n assert candidate(s = \"1 2 3 apple 4 5\") == True\n assert candidate(s = \"9 8 7 6 5 4 3 2 1\") == False\n assert candidate(s = \"0 is not a valid number 1 is\") == False\n assert candidate(s = \"3 14 15 9 26 53 59\") == False\n assert candidate(s = \"3 5 7 9 11 13 15\") == True\n assert candidate(s = \"the temperature is 23 degrees and will rise to 30\") == True\n assert candidate(s = \"5 6 7 8 9 10\") == True\n assert candidate(s = \"100 99\") == False\n assert candidate(s = \"100 101 102\") == True\n assert candidate(s = \"10 20 30 25 40\") == False\n assert candidate(s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\") == True\n assert candidate(s = \"one two 3 four 5 six 7\") == True\n assert candidate(s = \"she sold 12 eggs for 24 dollars\") == True\n assert candidate(s = \"we started with 50 employees and now we have 75\") == True\n assert candidate(s = \"the quick brown fox jumps over 13 lazy dogs and 14 sleeping cats\") == True\n assert candidate(s = \"there are 100 ants 110 bees and 120 wasps\") == True\n assert candidate(s = \"the measurements are 10 20 30 40 50 60 70\") == True\n assert candidate(s = \"1 car 2 trucks 3 motorcycles 4 bicycles\") == True\n assert candidate(s = \"she ate 2 apples and then 3 apples later\") == True\n assert candidate(s = \"123 124 125 126 127 128 129\") == True\n assert candidate(s = \"she turned 21 years old in 2022 and will turn 22 in 2023\") == False\n assert candidate(s = \"the heights are 30 45 60 75 90\") == True\n assert candidate(s = \"the sequence of numbers is 1 2 4 8 16 32 and 64\") == True\n assert candidate(s = \"he scored 50 60 75 80 and 90 in exams\") == True\n assert candidate(s = \"repeating numbers 1 1 2 2 3 3\") == False\n assert candidate(s = \"the journey took 3 hours and 4 hours on different days\") == True\n assert candidate(s = \"in the year 2001 we had 1 event in 2003 we had 4 events in 2005 we had 6 events\") == False\n assert candidate(s = \"lets count 1 2 3 4 5 6 7 8 9 10 and check if they are increasing\") == True\n assert candidate(s = \"the sequence is 1 2 3 4 5 6 7 8 9 10\") == True\n assert candidate(s = \"the temperature decreased from 30 degrees to 25 degrees then to 20 degrees\") == False\n assert candidate(s = \"3 little pigs 10 11 12 13 14 15\") == True\n assert candidate(s = \"1 one 2 two 3 three 4 four 5 five 6 six 7 seven\") == True\n assert candidate(s = \"in the year 1990 1995 there were 2000 2005 cars\") == True\n assert candidate(s = \"the sequence 1 3 5 7 9 is strictly increasing\") == True\n assert candidate(s = \"12 monkeys and 13 apes and 14 elephants\") == True\n assert candidate(s = \"the areas are 1 4 9 16 25 36 and 49\") == True\n assert candidate(s = \"a1 b2 c3 6 7 8 9 10\") == True\n assert candidate(s = \"1000 apples 2000 bananas 3000 cherries 4000 dates\") == True\n assert candidate(s = \"the book had 5 chapters and the next book had 8 chapters\") == True\n assert candidate(s = \"1 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(s = \"a1 b2 c3 4 d5 e6 f7 g8 h9 i10\") == True\n assert candidate(s = \"we have 100 books 200 magazines and 300 newspapers\") == True\n assert candidate(s = \"42 is the answer to life 43 the universe and 44 everything\") == True\n assert candidate(s = \"he received 10 calls in the morning and 15 in the afternoon\") == True\n assert candidate(s = \"the temperature rose from 20 degrees to 22 and then to 25\") == True\n assert candidate(s = \"one 2 three 4 five 6 seven 8 nine 10\") == True\n assert candidate(s = \"12 monkeys and 13 gorillas but only 7 chimpanzees\") == False\n assert candidate(s = \"the temperature was 10 degrees at 1 oclock and 12 degrees at 2 oclock and 15 degrees at 3 oclock\") == False\n assert candidate(s = \"the temperature rose from 20 to 22 then to 25\") == True\n assert candidate(s = \"the times are 12 24 36 48 and 60\") == True\n assert candidate(s = \"the weights are 1 2 3 5 8 13 and 21\") == True\n assert candidate(s = \"she baked 5 cakes 10 muffins and 15 brownies\") == True\n assert candidate(s = \"the steps are 100 200 300 400 500\") == True\n assert candidate(s = \"there are 100 ants 200 bees 300 flies and 400 spiders\") == True\n assert candidate(s = \"the number 10 comes before 20 and 30\") == True\n assert candidate(s = \"the sales increased from 100 units to 150 units last quarter\") == True\n assert candidate(s = \"the numbers 1 2 3 4 5 6 7 8 9 10 are in ascending order\") == True\n assert candidate(s = \"the increments are 1 2 3 4 5 6 7 8\") == True\n assert candidate(s = \"alpha 1 beta 2 gamma 3 delta 4 epsilon 5 zeta 6 eta 7 theta 8 iota 9 kappa 10 lambda 11 mu 12 nu 13 xi 14 omicron 15 pi 16 rho 17 sigma 18 tau 19 upsilon 20 phi 21 chi 22 psi 23 omega 24\") == True\n assert candidate(s = \"the sequence of numbers is 1 3 6 10 15 21 and 28\") == True\n assert candidate(s = \"in the year 1800 there were 1801 people in this town 1802\") == True\n assert candidate(s = \"20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39\") == True\n assert candidate(s = \"she baked 5 cakes 10 pies and 15 tarts\") == True\n assert candidate(s = \"the positions are 10 20 30 40 50 60 and 70\") == True\n assert candidate(s = \"58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77\") == True\n assert candidate(s = \"the volumes are 10 100 1000 10000 and 100000\") == True\n assert candidate(s = \"the temperature rose from 10 to 20 then to 30 degrees\") == True\n assert candidate(s = \"in the year 2000 we had 100 participants and in 2005 we had 150 participants\") == False\n assert candidate(s = \"the project took 1 month and then 2 months to complete\") == True\n assert candidate(s = \"the sequence 1 3 5 7 9 11 13 15 17 19 is strictly increasing\") == True\n assert candidate(s = \"the numbers are 1 2 3 but then 2 again\") == False\n assert candidate(s = \"a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p 16 q 17 r 18 s 19 t 20\") == True\n assert candidate(s = \"increasing by one 1 2 3 4 5 6 7 8 9\") == True\n assert candidate(s = \"the temperature today is 30 degrees 31 tomorrow 32 the day after\") == True\n assert candidate(s = \"the sequence is 1 3 5 7 9 11 13\") == True\n assert candidate(s = \"the garden has 1 tulip 3 roses 5 daisies 7 sunflowers\") == True\n assert candidate(s = \"we planted 50 trees 100 bushes and 200 flowers\") == True\n assert candidate(s = \"in 1999 there were 2000 cars and in 2001 there were 2002 cars\") == True\n assert candidate(s = \"we collected 15 apples 20 oranges and 25 bananas\") == True\n assert candidate(s = \"one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8 nine 9 ten 10 eleven 11\") == True\n assert candidate(s = \"3 cats 5 dogs 7 birds 9 fish\") == True\n assert candidate(s = \"99 98 97 96 95 94 93 92 91 90\") == False\n assert candidate(s = \"she sold 1 apple 2 oranges 3 bananas 4 grapes 5 watermelons 6 pineapples\") == True\n assert candidate(s = \"the speed increased from 20 kmph to 30 kmph and then to 40 kmph\") == True\n assert candidate(s = \"the distances are 1000 2000 3000 4000 and 5000\") == True\n assert candidate(s = \"we climbed 100 meters then 200 meters and finally 300 meters\") == True\n assert candidate(s = \"the time is 12 13 14 15 16 17 18 19 20 21 22 23\") == True\n assert candidate(s = \"there were 5 kids 6 teenagers 7 adults in the room\") == True\n assert candidate(s = \"the company grew from 1000 employees to 1500 employees last year\") == True\n assert candidate(s = \"he won 1 race and then 2 races in a row\") == True\n assert candidate(s = \"the first year 1990 was followed by 1991 and then 1992\") == True\n assert candidate(s = \"1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10\") == False\n assert candidate(s = \"the sequence 10 20 30 40 50 60 70 80 90 100 is ascending\") == True\n assert candidate(s = \"in the year 2020 2021 2022 and 2023\") == True\n assert candidate(s = \"the ages are 5 10 15 20 25 30\") == True\n assert candidate(s = \"the numbers 10 20 30 40 50 are increasing\") == True\n assert candidate(s = \"in the sequence 2 4 6 8 10 12 14 16 18 20 all numbers are in increasing order\") == True\n assert candidate(s = \"there are 2 cars 4 trucks and 6 motorcycles\") == True\n assert candidate(s = \"random 5 10 20 15 25 30 29 35 40 45\") == False\n assert candidate(s = \"20 apples and 25 oranges but only 15 bananas\") == False\n assert candidate(s = \"a quick brown fox jumps over 1 lazy dog then 2 sleepy dogs\") == True\n assert candidate(s = \"the ages are 25 30 35 40 45 50 55\") == True\n assert candidate(s = \"she sold sea shells by the sea shore 1 2 3 4 5 6 7 8 9 10 11 12\") == True\n assert candidate(s = \"39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58\") == True\n assert candidate(s = \"there are 100 bottles of beer on the wall 101 102 103\") == True\n assert candidate(s = \"in the year 2020 we had 21 cars 23 trucks and 25 buses\") == False\n assert candidate(s = \"compare these numbers 10 20 30 40 50 60 70 80 90 100\") == True\n assert candidate(s = \"decreasing numbers 5 4 3 2 1\") == False\n assert candidate(s = \"there are 30 apples 40 oranges 50 bananas 60 grapes 70 strawberries 80 blueberries\") == True\n assert candidate(s = \"the temperature rose from 20 to 25 to 30 degrees\") == True\n assert candidate(s = \"random order 1 3 2 4 5\") == False\n assert candidate(s = \"a1 b2 c3 d4 e5 f6 g7 h8 i9 j10 11 12 13 14 15 16 17 18 19 20\") == True\n assert candidate(s = \"the chapters are numbered 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\") == True\n assert candidate(s = \"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\") == True\n assert candidate(s = \"the ages are 5 10 15 20 25 30 35 40\") == True\n assert candidate(s = \"the quick brown fox jumps over 1 lazy dog 2\") == True\n assert candidate(s = \"she played 1 game 2 matches 3 tournaments\") == True\n assert candidate(s = \"we counted 1 bird 2 cats 3 dogs 4 elephants 5 foxes 6 giraffes 7 hippos\") == True\n assert candidate(s = \"she saw 5 stars 10 planets and 15 galaxies\") == True\n assert candidate(s = \"23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43\") == True\n assert candidate(s = \"even numbers 2 4 6 8 10 12 14 16 18 20\") == True\n assert candidate(s = \"strictly increasing 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\") == True\n assert candidate(s = \"in a race 10 runners came first 20 second and 30 third\") == True\n assert candidate(s = \"the clock struck 1 pm 2 pm 3 pm 4 pm\") == True\n assert candidate(s = \"the sequence of numbers is 3 9 27 81 and 243\") == True\n assert candidate(s = \"mixed numbers 1 20 2 30 3\") == False\n assert candidate(s = \"in the year 2000 2001 2002 the world changed\") == True\n assert candidate(s = \"a sequence of 1 2 3 4 5 6 7 8 9 10 numbers\") == True\n assert candidate(s = \"a sequence of numbers like 10 20 30 40 50 should be increasing\") == True\n assert candidate(s = \"the values are 2 4 8 16 32\") == True\n assert candidate(s = \"42 cats 43 dogs 44 elephants 45 flamingos\") == True\n assert candidate(s = \"77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96\") == True\n assert candidate(s = \"abc 1 def 2 ghi 3 jkl 4 mno 5 pqr 6 stu 7 vwx 8 yz 9 10\") == True\n assert candidate(s = \"nested numbers like 10 in 11 the 12 and 13 final\") == True\n assert candidate(s = \"99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115\") == True\n assert candidate(s = \"99 100 101 102 103 104 105 106\") == True\n assert candidate(s = \"96 97 98 99 100 101 102 103 104 105 106 107 108 109 110\") == True\n assert candidate(s = \"the children are 1 year old 2 years old 3 years old 4 years old\") == True\n assert candidate(s = \"100 apples 101 oranges 102 bananas\") == True\n assert candidate(s = \"my password is 123 and my pin is 124 and my secret number is 125\") == True\n assert candidate(s = \"the team scored 2 goals in the first half and 3 goals in the second half\") == True\n assert candidate(s = \"the prices are 5 10 15 20 25\") == True\n assert candidate(s = \"decreasing numbers 20 19 18 17 16 15 14 13 12 11 10\") == False\n assert candidate(s = \"the sequence is 1 4 9 16 25 and 36\") == True\n assert candidate(s = \"there are 3 cats 5 dogs and 7 birds in the zoo\") == True\n assert candidate(s = \"the quick brown fox jumps over the lazy dog 1 2 3 4 5\") == True\n assert candidate(s = \"he collected 2 seashells by the sea 4 on the beach and 6 in the sand\") == True\n assert candidate(s = \"1 2 3 4 5 6 7 8 9 10\") == True\n assert candidate(s = \"a quick brown fox jumps over the lazy dog 1 2 3 4 5\") == True\n assert candidate(s = \"there are 100 apples 101 oranges and 102 bananas\") == True\n assert candidate(s = \"the levels are 10 20 30 40 50 60 70 80 90\") == True\n assert candidate(s = \"007 is not a valid number but 7 8 9 are valid numbers\") == False\n assert candidate(s = \"two digit numbers 10 20 30 40 50\") == True\n assert candidate(s = \"the quick brown fox jumps over the lazy dog 1 2 3 4 5 6 7 8 9 10\") == True\n assert candidate(s = \"99 100 99 101 102 103 104 105 106 107 108 109 110 111 112 113 114\") == False\n assert candidate(s = \"a series of 1 3 5 7 9 11 13 15 17 19 odd numbers\") == True\n assert candidate(s = \"we have 10 apples 20 oranges 30 bananas and 30 grapes\") == False\n assert candidate(s = \"the number sequence is 1 2 3 4 5 6 7 8 9\") == True\n assert candidate(s = \"he ran 1 mile in 5 minutes then 2 miles in 10 minutes\") == False\n assert candidate(s = \"99 bottles of beer on the wall 98 bottles of beer\") == False\n assert candidate(s = \"the heights are 100 200 300 400 and 500\") == True\n assert candidate(s = \"the numbers 5 10 15 20 25 30 35 40 45 50 are increasing\") == True\n assert candidate(s = \"30 apples 40 oranges 50 bananas 60 grapes\") == True\n assert candidate(s = \"a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10\") == True\n assert candidate(s = \"21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40\") == True\n assert candidate(s = \"the counts are 1 2 3 4 5 6 7 8 9 10\") == True\n assert candidate(s = \"the first 2 books have 3 chapters each and the 5 next books have 6 chapters each\") == True\n assert candidate(s = \"1234 5678 91011 121314\") == True\n assert candidate(s = \"the temperature rose from 5 degrees to 10 degrees then to 15 degrees\") == True\n assert candidate(s = \"single digit numbers 1 2 3 4 5\") == True\n assert candidate(s = \"a quick brown fox jumps over 1 3 5 lazy dogs\") == True\n assert candidate(s = \"she has 10 red balloons 20 blue ones and 30 green ones\") == True\n assert candidate(s = \"a 1 digit number 10 two digit numbers 100 three digit numbers\") == True\n assert candidate(s = \"in the series 2 4 6 8 10 the numbers are strictly increasing\") == True\n assert candidate(s = \"we planted 1 tree 2 bushes 3 flowers 4 vines and 5 cacti\") == True\n assert candidate(s = \"the sequence is 1 1 2 3 5 8 and 13\") == False\n", "comparison": "exact"}, "public_tests": ["\"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"", "\"hello world 5 x 5\"", "\"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\""], "hints": ["Use string tokenization of your language to extract all the tokens of the string easily.", "For each token extracted, how can you tell if it is a number? Does the first letter being a digit mean something?", "Compare the number with the previously occurring number to check if ascending order is maintained."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().areNumbersAscending", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:09+00:00", "tests_total": 204, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function areNumbersAscending($s) {", "container": "Solution", "callable": "areNumbersAscending", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2044, "task_id": "count-number-of-maximum-bitwise-or-subsets", "difficulty": "Medium", "problem_description": "Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR.\n\nAn array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b. Two subsets are considered different if the indices of the elements chosen are different.\n\nThe bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).\n\nExample 1:\n\nInput: nums = [3,1]\nOutput: 2\nExplanation: The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:\n- [3]\n- [3,1]\n\nExample 2:\n\nInput: nums = [2,2,2]\nOutput: 7\nExplanation: All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 2^3 - 1 = 7 total subsets.\n\nExample 3:\n\nInput: nums = [3,2,1,5]\nOutput: 6\nExplanation: The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:\n- [3,5]\n- [3,1,5]\n- [3,2,5]\n- [3,2,1,5]\n- [2,5]\n- [2,1,5]\n\nConstraints:\n\n- 1 <= nums.length <= 16\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [15, 15, 15]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5]) == 255\n assert candidate(nums = [3, 2, 1, 5]) == 6\n assert candidate(nums = [6, 2, 1, 3, 4]) == 17\n assert candidate(nums = [6, 2, 1, 5, 4]) == 17\n assert candidate(nums = [5, 1, 1, 2, 5]) == 12\n assert candidate(nums = [1, 3, 5, 7, 9]) == 10\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [2, 2, 2]) == 7\n assert candidate(nums = [1, 3, 7, 15, 31]) == 16\n assert candidate(nums = [15, 15, 15, 15]) == 15\n assert candidate(nums = [1, 2, 4, 8]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50]) == 16\n assert candidate(nums = [5, 5, 5, 5, 5]) == 31\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 65535\n assert candidate(nums = [15, 7, 3, 1]) == 8\n assert candidate(nums = [16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [3, 1]) == 2\n assert candidate(nums = [1, 3, 7, 15]) == 8\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 255\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 65535\n assert candidate(nums = [10, 20, 30, 40]) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 64594\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35]) == 52\n assert candidate(nums = [5, 10, 15, 20, 25, 30]) == 44\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 1\n assert candidate(nums = [8, 4, 2, 1, 15, 7, 3]) == 85\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 65535\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]) == 32768\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 64594\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 859\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 128, 64, 32, 16, 8, 4, 2, 1]) == 6561\n assert candidate(nums = [16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384]) == 65535\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 32767\n assert candidate(nums = [32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1]) == 16203\n assert candidate(nums = [31, 15, 7, 3, 1, 31, 15, 7, 3, 1, 31, 15, 7, 3, 1, 31]) == 61440\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 32297\n assert candidate(nums = [13, 7, 15, 3, 1, 8, 2, 4]) == 205\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 32297\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 64897\n assert candidate(nums = [1, 5, 11, 5, 1, 11, 5, 1, 11, 5, 1, 11, 5, 1]) == 14880\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1023]) == 32768\n assert candidate(nums = [15, 7, 3, 1]) == 8\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 255\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 511\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64]) == 1\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 65535\n assert candidate(nums = [15, 15, 15, 15, 15]) == 31\n assert candidate(nums = [31, 15, 7, 3, 1]) == 16\n assert candidate(nums = [1, 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, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1]) == 128\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 64594\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 32768\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == 512\n assert candidate(nums = [31, 28, 29, 30, 31, 30, 29, 28]) == 228\n assert candidate(nums = [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17]) == 65535\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 171\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == 109\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 65535\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384]) == 21\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]) == 22336\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 255\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64]) == 109\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 257\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 65535\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40]) == 150\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128]) == 1\n assert candidate(nums = [31, 14, 7, 3, 1, 31, 14, 7, 3, 1]) == 768\n assert candidate(nums = [255, 255, 255, 255, 255, 255, 255, 255]) == 255\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == 62449\n assert candidate(nums = [14, 7, 3, 1, 14, 7, 3, 1]) == 189\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 65535\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562]) == 13\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8]) == 255\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1]) == 32768\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 128, 64, 32, 16, 8, 4, 2, 1]) == 6561\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144]) == 48108\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32, 64, 64, 128, 128]) == 6561\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == 170\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]) == 65535\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 512\n assert candidate(nums = [32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 16384\n assert candidate(nums = [5, 3, 10, 14, 15, 1, 2, 8, 4, 6, 7, 11, 12, 13, 9]) == 32297\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 48609\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 59421\n assert candidate(nums = [127, 63, 31, 15, 7, 3, 1]) == 64\n assert candidate(nums = [5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40]) == 59922\n assert candidate(nums = [31, 15, 7, 3, 1, 63, 127, 255, 511, 1023, 1, 2, 4, 8, 16, 32]) == 32768\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128]) == 1\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1]) == 128\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32767]) == 32769\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72]) == 109\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535]) == 32768\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240]) == 63775\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14]) == 65535\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 65535\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 32297\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3]) == 12611\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127]) == 64\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64]) == 1\n assert candidate(nums = [7, 3, 2, 1, 6, 5, 4, 8, 10, 9, 11, 12, 13, 14, 15, 16]) == 32297\n assert candidate(nums = [12, 14, 7, 1, 9, 3, 11]) == 102\n", "comparison": "exact"}, "public_tests": ["[3,1]", "[2,2,2]", "[3,2,1,5]"], "hints": ["Can we enumerate all possible subsets?", "The maximum bitwise-OR is the bitwise-OR of the whole array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countMaxOrSubsets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:12+00:00", "tests_total": 113, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "backtracking", "bit-manipulation", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countMaxOrSubsets($nums) {", "container": "Solution", "callable": "countMaxOrSubsets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2045, "task_id": "second-minimum-time-to-reach-destination", "difficulty": "Hard", "problem_description": "A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [u_i, v_i] denotes a bi-directional 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. The time taken to traverse any edge is time minutes.\n\nEach vertex has a traffic signal which changes its color from green to red and vice versa every change minutes. All signals change at the same time. You can enter a vertex at any time, but can leave a vertex only when the signal is green. You cannot wait at a vertex if the signal is green.\n\nThe second minimum value is defined as the smallest value strictly larger than the minimum value.\n\n- For example the second minimum value of [2, 3, 4] is 3, and the second minimum value of [2, 2, 4] is 4.\n\nGiven n, edges, time, and change, return the second minimum time it will take to go from vertex 1 to vertex n.\n\nNotes:\n\n- You can go through any vertex any number of times, including 1 and n.\n- You can assume that when the journey starts, all signals have just turned green.\n\nExample 1:\n\nInput: n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5\nOutput: 13\nExplanation:\nThe figure on the left shows the given graph.\nThe blue path in the figure on the right is the minimum time path.\nThe time taken is:\n- Start at 1, time elapsed=0\n- 1 -> 4: 3 minutes, time elapsed=3\n- 4 -> 5: 3 minutes, time elapsed=6\nHence the minimum time needed is 6 minutes.\n\nThe red path shows the path to get the second minimum time.\n- Start at 1, time elapsed=0\n- 1 -> 3: 3 minutes, time elapsed=3\n- 3 -> 4: 3 minutes, time elapsed=6\n- Wait at 4 for 4 minutes, time elapsed=10\n- 4 -> 5: 3 minutes, time elapsed=13\nHence the second minimum time is 13 minutes.\n\nExample 2:\n\nInput: n = 2, edges = [[1,2]], time = 3, change = 2\nOutput: 11\nExplanation:\nThe minimum time path is 1 -> 2 with time = 3 minutes.\nThe second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes.\n\nConstraints:\n\n- 2 <= n <= 10^4\n- n - 1 <= edges.length <= min(2 * 10^4, n * (n - 1) / 2)\n- edges[i].length == 2\n- 1 <= u_i, v_i <= n\n- u_i != v_i\n- There are no duplicate edges.\n- Each vertex can be reached directly or indirectly from every other vertex.\n- 1 <= time, change <= 10^3\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 2,edges = [[1, 2]],time = 3,change = 2) == 11\n assert candidate(n = 3,edges = [[1, 2], [2, 3]],time = 2,change = 3) == 10\n assert candidate(n = 3,edges = [[1, 2], [2, 3]],time = 5,change = 5) == 35\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [3, 5], [4, 5], [5, 6]],time = 2,change = 4) == 18\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 4], [1, 4]],time = 2,change = 3) == 8\n assert candidate(n = 4,edges = [[1, 2], [1, 3], [3, 4], [2, 4]],time = 2,change = 3) == 10\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 6]],time = 4,change = 7) == 32\n assert candidate(n = 5,edges = [[1, 2], [1, 3], [1, 4], [3, 4], [4, 5]],time = 3,change = 5) == 13\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 4]],time = 5,change = 7) == 33\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 5], [5, 6]],time = 4,change = 7) == 22\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 4], [4, 1]],time = 2,change = 3) == 8\n assert candidate(n = 14,edges = [[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]],time = 1,change = 2) == 29\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], [8, 9], [10, 11], [12, 13], [14, 15]],time = 8,change = 11) == 38\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 12], [10, 12], [11, 12], [1, 12]],time = 5,change = 7) == 19\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]],time = 2,change = 3) == 8\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 7], [6, 8], [7, 9], [8, 10]],time = 3,change = 5) == 13\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],time = 5,change = 4) == 29\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 12], [7, 8], [9, 10], [11, 12]],time = 3,change = 4) == 14\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]],time = 3,change = 5) == 33\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], [13, 24], [13, 25]],time = 5,change = 7) == 38\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 6], [3, 7], [4, 6], [4, 7], [5, 6], [5, 7]],time = 5,change = 8) == 26\n assert candidate(n = 15,edges = [[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]],time = 8,change = 12) == 184\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]],time = 4,change = 6) == 28\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 12], [10, 12], [11, 12]],time = 3,change = 5) == 26\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], [8, 10], [9, 11], [12, 14], [13, 15]],time = 5,change = 8) == 26\n assert candidate(n = 11,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 11], [7, 11], [8, 11], [9, 11], [10, 11]],time = 9,change = 12) == 57\n assert candidate(n = 11,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [1, 5], [1, 6], [1, 7], [2, 8], [2, 9], [3, 10], [3, 11]],time = 6,change = 8) == 28\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9]],time = 7,change = 10) == 47\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = 3,change = 5) == 53\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], [9, 20]],time = 6,change = 9) == 42\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15], [12, 13], [13, 14], [14, 15]],time = 5,change = 8) == 37\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 7]],time = 4,change = 5) == 24\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 6], [6, 7]],time = 3,change = 4) == 22\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],time = 3,change = 5) == 43\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],time = 4,change = 7) == 92\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]],time = 7,change = 9) == 43\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 12], [10, 11], [11, 12], [5, 7], [4, 6]],time = 3,change = 7) == 20\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 10]],time = 7,change = 10) == 47\n assert candidate(n = 14,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], [1, 5], [1, 7], [2, 8], [2, 10], [3, 9], [3, 11], [4, 12], [4, 14], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]],time = 6,change = 13) == 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], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],time = 3,change = 4) == 14\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 6], [7, 8], [9, 10]],time = 4,change = 5) == 14\n assert candidate(n = 16,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 5], [3, 7], [4, 6], [4, 7], [5, 8], [5, 9], [6, 8], [6, 10], [7, 9], [7, 10], [8, 11], [8, 12], [9, 11], [9, 12], [10, 13], [10, 14], [11, 13], [11, 15], [12, 14], [12, 15], [13, 16], [14, 16], [15, 16]],time = 5,change = 10) == 50\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8]],time = 4,change = 6) == 28\n assert candidate(n = 20,edges = [[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]],time = 4,change = 6) == 124\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 5], [3, 7], [4, 6], [4, 7], [5, 8], [5, 9], [6, 8], [6, 10], [7, 9], [7, 10], [8, 11], [8, 12], [9, 11], [10, 12]],time = 8,change = 12) == 64\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = 2,change = 3) == 32\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], [11, 16], [12, 17], [13, 18], [14, 19], [15, 20]],time = 5,change = 8) == 42\n assert candidate(n = 18,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [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]],time = 5,change = 6) == 101\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 8], [9, 10]],time = 2,change = 4) == 12\n assert candidate(n = 20,edges = [[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], [6, 16], [6, 17], [7, 18], [7, 19], [8, 20], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],time = 4,change = 7) == 22\n assert candidate(n = 11,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 11], [7, 11], [8, 11], [9, 11], [10, 11], [2, 3], [5, 7], [6, 8], [9, 10]],time = 3,change = 5) == 16\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [3, 5], [4, 6], [5, 7], [5, 8], [6, 9], [7, 9], [8, 9]],time = 5,change = 7) == 24\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [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]],time = 3,change = 5) == 93\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 8], [7, 8]],time = 4,change = 6) == 28\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10]],time = 7,change = 10) == 54\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 5], [3, 7], [4, 6], [4, 7], [5, 8], [6, 8], [7, 8]],time = 6,change = 5) == 46\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], [7, 12]],time = 2,change = 3) == 14\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [4, 6], [5, 6]],time = 10,change = 12) == 34\n assert candidate(n = 20,edges = [[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, 10], [5, 15], [9, 19]],time = 4,change = 6) == 32\n assert candidate(n = 16,edges = [[1, 2], [1, 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], [8, 9], [10, 11], [12, 13], [14, 15], [16, 15]],time = 3,change = 5) == 16\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [1, 12]],time = 2,change = 3) == 8\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = 6,change = 8) == 86\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 8], [7, 8]],time = 6,change = 9) == 42\n assert candidate(n = 20,edges = [[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]],time = 3,change = 6) == 123\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], [8, 10], [9, 11], [12, 14], [13, 15]],time = 2,change = 5) == 12\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 12], [7, 8], [9, 10], [11, 12]],time = 3,change = 5) == 16\n assert candidate(n = 15,edges = [[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]],time = 4,change = 3) == 94\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 6], [7, 8], [8, 9], [5, 8], [6, 7], [5, 7], [6, 8]],time = 4,change = 6) == 16\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10]],time = 3,change = 4) == 22\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],time = 7,change = 9) == 97\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],time = 6,change = 8) == 28\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], [8, 12], [9, 13], [10, 14], [11, 15]],time = 2,change = 3) == 10\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 9]],time = 6,change = 5) == 36\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],time = 3,change = 5) == 63\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 7], [6, 7]],time = 5,change = 4) == 29\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], [8, 9], [10, 11], [12, 13], [14, 15]],time = 5,change = 6) == 22\n assert candidate(n = 25,edges = [[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], [6, 16], [6, 17], [7, 18], [7, 19], [8, 20], [8, 21], [8, 22], [9, 23], [9, 24], [10, 25], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22], [23, 24], [24, 25]],time = 3,change = 6) == 18\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = 7,change = 13) == 137\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 6], [1, 4], [1, 5], [2, 6], [3, 4], [3, 6]],time = 7,change = 10) == 27\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 8], [7, 8]],time = 3,change = 4) == 19\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], [8, 9], [10, 11], [12, 13], [14, 15]],time = 3,change = 7) == 17\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10]],time = 3,change = 5) == 26\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [3, 5], [4, 6], [5, 7], [6, 7]],time = 7,change = 5) == 47\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]],time = 6,change = 5) == 56\n", "comparison": "exact"}, "public_tests": ["5\n[[1,2],[1,3],[1,4],[3,4],[4,5]]\n3\n5", "2\n[[1,2]]\n3\n2"], "hints": ["How much is change actually necessary while calculating the required path?", "How many extra edges do we need to add to the shortest path?"], "metadata": {"canonical_parameter_names": ["n", "edges", "time", "change"], "leetcode_dataset_entry_point": "Solution().secondMinimum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:14+00:00", "tests_total": 84, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["breadth-first-search", "graph", "shortest-path", "dijkstra", "k-shortest-path"]}, "language": "php", "interface": {"raw_signature": "function secondMinimum($n, $edges, $time, $change) {", "container": "Solution", "callable": "secondMinimum", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "time", "type": "Integer"}, {"name": "change", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2047, "task_id": "number-of-valid-words-in-a-sentence", "difficulty": "Easy", "problem_description": "A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.\n\nA token is a valid word if all three of the following are true:\n\n- It only contains lowercase letters, hyphens, and/or punctuation (no digits).\n- There is at most one hyphen '-'. If present, it must be surrounded by lowercase characters (\"a-b\" is valid, but \"-ab\" and \"ab-\" are not valid).\n- There is at most one punctuation mark. If present, it must be at the end of the token (\"ab,\", \"cd!\", and \".\" are valid, but \"a!b\" and \"c.,\" are not valid).\n\nExamples of valid words include \"a-b.\", \"afad\", \"ba-c\", \"a!\", and \"!\".\n\nGiven a string sentence, return the number of valid words in sentence.\n\nExample 1:\n\nInput: sentence = \"cat and dog\"\nOutput: 3\nExplanation: The valid words in the sentence are \"cat\", \"and\", and \"dog\".\n\nExample 2:\n\nInput: sentence = \"!this 1-s b8d!\"\nOutput: 0\nExplanation: There are no valid words in the sentence.\n\"!this\" is invalid because it starts with a punctuation mark.\n\"1-s\" and \"b8d\" are invalid because they contain digits.\n\nExample 3:\n\nInput: sentence = \"alice and bob are playing stone-game10\"\nOutput: 5\nExplanation: The valid words in the sentence are \"alice\", \"and\", \"bob\", \"are\", and \"playing\".\n\"stone-game10\" is invalid because it contains digits.\n\nConstraints:\n\n- 1 <= sentence.length <= 1000\n- sentence only contains lowercase English letters, digits, ' ', '-', '!', '.', and ','.\n- There will be at least 1 token.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentence = \"no-digits123 or symbols#allowed\") == 2\n assert candidate(sentence = \"a.b.c\") == 0\n assert candidate(sentence = \"hello-world, this-is-a-test\") == 1\n assert candidate(sentence = \"hello-\") == 0\n assert candidate(sentence = \"a-\") == 0\n assert candidate(sentence = \"singleletter a b c d e f g\") == 8\n assert candidate(sentence = \"valid-words only\") == 2\n assert candidate(sentence = \"a\") == 1\n assert candidate(sentence = \"hello world! this is a test.\") == 6\n assert candidate(sentence = \"hello-world, my.name-is Qwen\") == 2\n assert candidate(sentence = \"ending-with-punctuation!\") == 0\n assert candidate(sentence = \"invalid--double-dash\") == 0\n assert candidate(sentence = \"multiple spaces between words\") == 4\n assert candidate(sentence = \"123\") == 0\n assert candidate(sentence = \"multiple--hyphens\") == 0\n assert candidate(sentence = \"valid-hyphenated-word\") == 0\n assert candidate(sentence = \"-invalid invalid- invalid-!\") == 0\n assert candidate(sentence = \"well-well, well!\") == 2\n assert candidate(sentence = \"singleletter\") == 1\n assert candidate(sentence = \"a! b. c?\") == 3\n assert candidate(sentence = \"hello-world\") == 1\n assert candidate(sentence = \"a-b-c\") == 0\n assert candidate(sentence = \"-world\") == 0\n assert candidate(sentence = \"a-b-c d-e f-g\") == 2\n assert candidate(sentence = \"-b\") == 0\n assert candidate(sentence = \"no-digits-allowed 123 456-789\") == 0\n assert candidate(sentence = \"alice and bob are playing stone-game10\") == 5\n assert candidate(sentence = \"no-dash-here\") == 0\n assert candidate(sentence = \"a-b!\") == 1\n assert candidate(sentence = \"valid-word here!\") == 2\n assert candidate(sentence = \"a-b- c d\") == 2\n assert candidate(sentence = \"valid-word here and another-valid one!\") == 5\n assert candidate(sentence = \"a-b-c-d.e.f!\") == 0\n assert candidate(sentence = \"singleletter a b c\") == 4\n assert candidate(sentence = \"a-b. afad ba-c a! .\") == 5\n assert candidate(sentence = \"a.b-c\") == 0\n assert candidate(sentence = \"hello!world\") == 0\n assert candidate(sentence = \",\") == 1\n assert candidate(sentence = \"a!b\") == 0\n assert candidate(sentence = \"-ab cd- ef-\") == 0\n assert candidate(sentence = \"hello-world, my name is john-doe.\") == 5\n assert candidate(sentence = \"!this 1-s b8d!\") == 0\n assert candidate(sentence = \"trailingpunctuation. comma, exclamation!\") == 3\n assert candidate(sentence = \"punctuation,in,middle,a-b.c\") == 0\n assert candidate(sentence = \"invalid-end-\") == 0\n assert candidate(sentence = \"-invalid start\") == 1\n assert candidate(sentence = \"valid-word here! and here.\") == 4\n assert candidate(sentence = \"!\") == 1\n assert candidate(sentence = \"valid-word-here!\") == 0\n assert candidate(sentence = \"punctuation,at,end.\") == 0\n assert candidate(sentence = \"a-b.c\") == 0\n assert candidate(sentence = \"cat and dog\") == 3\n assert candidate(sentence = \".\") == 1\n assert candidate(sentence = \"-invalid-start\") == 0\n assert candidate(sentence = \"a.b\") == 0\n assert candidate(sentence = \"hello-world!\") == 1\n assert candidate(sentence = \"punctuation! marks, are: allowed?\") == 4\n assert candidate(sentence = \"punctuation.only,\") == 0\n assert candidate(sentence = \"valid-word- valid-word-\") == 0\n assert candidate(sentence = \"word-with-digit1\") == 0\n assert candidate(sentence = \"punctuation-after-hyphen-! invalid\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation-1,\") == 0\n assert candidate(sentence = \"valid-word, valid-word!\") == 2\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word?\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word@123\") == 1\n assert candidate(sentence = \"valid-word-with-hyphen-and-punctuation!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!\") == 1\n assert candidate(sentence = \"valid-word, invalid-word2\") == 1\n assert candidate(sentence = \"word-with-hyphen-and-punctuation-after-hyphen-,\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@\") == 1\n assert candidate(sentence = \"word-with-digit-and-hyphen-1b\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-1b-\") == 0\n assert candidate(sentence = \"valid-word-123\") == 0\n assert candidate(sentence = \"word-with-punctuation,at,end.\") == 0\n assert candidate(sentence = \"multiple---hyphens-in-a-row\") == 0\n assert candidate(sentence = \"word-with-hyphen-\") == 0\n assert candidate(sentence = \"word-with-digit-in-middle-1word\") == 0\n assert candidate(sentence = \"punctuation-inside-word!word\") == 0\n assert candidate(sentence = \"a-b-c d-e-f g-h\") == 1\n assert candidate(sentence = \"word-with-punctuation-and-digit1!\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation-after-hyphen-!\") == 0\n assert candidate(sentence = \"-word-with-leading-hyphen\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-b--1\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc\") == 1\n assert candidate(sentence = \"word-with-punctuation! word-without\") == 1\n assert candidate(sentence = \"word. word- word!\") == 2\n assert candidate(sentence = \"hyphenated-word- is valid\") == 2\n assert candidate(sentence = \"no-spaces\") == 1\n assert candidate(sentence = \"word-with-digit-and-hyphen-1-word\") == 0\n assert candidate(sentence = \"word! word- word. word?\") == 3\n assert candidate(sentence = \"hyphen-at-end-\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word!\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@!\") == 1\n assert candidate(sentence = \"multiple---hyphens\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-exclamation!\") == 0\n assert candidate(sentence = \"valid-word- valid-word!\") == 1\n assert candidate(sentence = \"word word, word! word.\") == 4\n assert candidate(sentence = \"word-with-digit-and-hyphen-b--\") == 0\n assert candidate(sentence = \"valid-word- word-with-hyphen\") == 0\n assert candidate(sentence = \"word-with-digit1-and-punctuation!\") == 0\n assert candidate(sentence = \"punctuation-in-middle-of-word!word\") == 0\n assert candidate(sentence = \"word!word\") == 0\n assert candidate(sentence = \"singleletter singleletter! singleletter.\") == 3\n assert candidate(sentence = \"word-with-digit-at-end1!\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-1--b\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#\") == 1\n assert candidate(sentence = \"word-with-punctuation-and-hyphen-word-123\") == 0\n assert candidate(sentence = \"multiple--dashes are invalid\") == 2\n assert candidate(sentence = \"word-with-punctuation.at.end,invalid\") == 0\n assert candidate(sentence = \"word-with-digit1-and-punctuation.\") == 0\n assert candidate(sentence = \"valid-word-with-punctuation-at-end,\") == 0\n assert candidate(sentence = \"single-hyphenated-word a-b\") == 1\n assert candidate(sentence = \"123 word- word! word?\") == 2\n assert candidate(sentence = \"a.b!\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation, word-with-hyphen-and-punctuation.\") == 0\n assert candidate(sentence = \"valid-word- valid-word- valid-word\") == 1\n assert candidate(sentence = \"punctuation-only! and !only-punctuation\") == 2\n assert candidate(sentence = \"hello-world- is not valid\") == 3\n assert candidate(sentence = \"word-with-valid-hyphen word-with--invalid-hyphen\") == 0\n assert candidate(sentence = \"valid-word valid-word- valid-word\") == 2\n assert candidate(sentence = \"word-with-digit-and-hyphen-and-punctuation-1-word!\") == 0\n assert candidate(sentence = \"invalid-1word and valid-word\") == 2\n assert candidate(sentence = \"word-with-punctuation,at,end!\") == 0\n assert candidate(sentence = \"word- word\") == 1\n assert candidate(sentence = \"word-with-punctuations!word-with-punctuations!word-with-punctuations.\") == 0\n assert candidate(sentence = \"valid-ending-punctuation.\") == 0\n assert candidate(sentence = \"word-with-punctuation,word\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!\") == 1\n assert candidate(sentence = \"word..\") == 0\n assert candidate(sentence = \"word-with-multiple-hyphens-and-punctuation-,\") == 0\n assert candidate(sentence = \"multiple-spaces between words\") == 3\n assert candidate(sentence = \"word-with-hyphen-123\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word-\") == 1\n assert candidate(sentence = \"word-with-punctuations!word-with-punctuations!word-with-punctuations!word-with-punctuations!word-with-punctuations.\") == 0\n assert candidate(sentence = \"valid!word\") == 0\n assert candidate(sentence = \"word- word- valid\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-123\") == 1\n assert candidate(sentence = \"a--b\") == 0\n assert candidate(sentence = \"word-hyphenated-word word- word. word?\") == 2\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!\") == 1\n assert candidate(sentence = \"word-with-digit-and-hyphen-b1\") == 0\n assert candidate(sentence = \"word- word! word@\") == 2\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc-def,word\") == 1\n assert candidate(sentence = \"word-with-hyphen- valid-word\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation1-,\") == 0\n assert candidate(sentence = \"validwordwithmultiplepunctuations,,,\") == 0\n assert candidate(sentence = \"valid-word-with-hyphen-and-comma, valid.\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#\") == 1\n assert candidate(sentence = \"word,word,word\") == 0\n assert candidate(sentence = \"valid-word-with-punctuation-at-end!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123!\") == 1\n assert candidate(sentence = \"word,with,commas and.punctuations\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word@!\") == 2\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123?\") == 1\n assert candidate(sentence = \"valid-word, valid-word. valid-word! valid-word\") == 4\n assert candidate(sentence = \"word-with-hyphen-and-punctuation,\") == 0\n assert candidate(sentence = \"word-with-space-in-word\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation word-with-hyphen-and-punctuation-\") == 0\n assert candidate(sentence = \"multiple---hyphens-in-word\") == 0\n assert candidate(sentence = \"word,word\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word?\") == 2\n assert candidate(sentence = \"123 456 789\") == 0\n assert candidate(sentence = \"punctuation!in!the!middle\") == 0\n assert candidate(sentence = \"multiple-punctuation,,\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-digit-1\") == 0\n assert candidate(sentence = \"word-with-digit123\") == 0\n assert candidate(sentence = \"word-with-digit123 and another-word!\") == 2\n assert candidate(sentence = \"a!b.c\") == 0\n assert candidate(sentence = \"multiple-punctuation!!\") == 0\n assert candidate(sentence = \"word-with123-hyphen\") == 0\n assert candidate(sentence = \"only!only only.only only-\") == 0\n assert candidate(sentence = \"word1 word2- word3- word4\") == 0\n assert candidate(sentence = \"word-with-hyphen- word\") == 1\n assert candidate(sentence = \"valid-word\") == 1\n assert candidate(sentence = \"-word\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word\") == 1\n assert candidate(sentence = \"word-with-1digit\") == 0\n assert candidate(sentence = \"word-with-punctuations,word-with-punctuations,word-with-punctuations,word-with-punctuations,word-with-punctuations!\") == 0\n assert candidate(sentence = \"valid-word, and invalid-word1\") == 2\n assert candidate(sentence = \"word-with-punctuation-in-middle.a\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word@?\") == 2\n assert candidate(sentence = \"word-with-hyphen-and-period.\") == 0\n assert candidate(sentence = \"word-with-multiple-hyphens-and-punctuation-,and valid-word!\") == 1\n assert candidate(sentence = \"word-with-punctuations,word-with-punctuations.\") == 0\n assert candidate(sentence = \"valid-word followed-by-number123\") == 1\n assert candidate(sentence = \"single-punctuation!\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@123\") == 1\n assert candidate(sentence = \"word word- word! word-\") == 2\n assert candidate(sentence = \"word-! word- word-\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc123\") == 1\n assert candidate(sentence = \"word-with-digit-and-hyphen-and-punctuation-word-1.\") == 0\n assert candidate(sentence = \"word-with-hyphen word-with-hyphen- word-with-hyphen\") == 0\n assert candidate(sentence = \"valid-word! another-valid-word?\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation1,\") == 0\n assert candidate(sentence = \"word-with-punctuation.at-end\") == 0\n assert candidate(sentence = \"valid-word, invalid-word123\") == 1\n assert candidate(sentence = \"!valid valid. valid-\") == 1\n assert candidate(sentence = \"valid-word.\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation1-.\") == 0\n assert candidate(sentence = \"a a-b a-b-c a-b-c-d\") == 2\n assert candidate(sentence = \"word-with-trailing-punctuation,\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation-after-hyphen-.\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@123\") == 1\n assert candidate(sentence = \"multiple spaces\") == 2\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word?\") == 1\n assert candidate(sentence = \"multiple-punctuation..\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc-123\") == 1\n assert candidate(sentence = \"word! word- word. word-\") == 2\n assert candidate(sentence = \"valid-word followed-by-digits123\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc\") == 1\n assert candidate(sentence = \"word-with-digit-and-hyphen--b-1\") == 0\n assert candidate(sentence = \"hello-world- is-not-valid\") == 0\n assert candidate(sentence = \"word-with-punctuations!word-with-punctuations!\") == 0\n assert candidate(sentence = \"-a\") == 0\n assert candidate(sentence = \"nohyphens here!\") == 2\n assert candidate(sentence = \"word-with-punctuation-at-start!word\") == 0\n assert candidate(sentence = \"leading!and-trailing!punctuation!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def!\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc\") == 1\n assert candidate(sentence = \"no-dashes-here but-here-are-too-many-dashes\") == 0\n assert candidate(sentence = \"word-hyphen- word\") == 1\n assert candidate(sentence = \"valid-word-with-hyphen-and-punctuation.\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation!\") == 0\n assert candidate(sentence = \"valid-word, valid-word. valid-word!\") == 3\n assert candidate(sentence = \"word-with-punctuation.at.end.\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word-\") == 1\n assert candidate(sentence = \"a!b!c\") == 0\n assert candidate(sentence = \"word-with-number1234 and valid-word\") == 2\n assert candidate(sentence = \"word,word!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word@\") == 2\n assert candidate(sentence = \"word1 word2 word3 word4\") == 0\n assert candidate(sentence = \"word-with-punctuation,at,end!invalid\") == 0\n assert candidate(sentence = \"complex-word-with-punctuation,\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc-def!\") == 1\n assert candidate(sentence = \"word-with-punctuations!word-with-punctuations!word-with-punctuations!word-with-punctuations.\") == 0\n assert candidate(sentence = \"single-letter-word a\") == 1\n assert candidate(sentence = \"word-with-trailing-hyphen-\") == 0\n assert candidate(sentence = \"punctuation.multiple\") == 0\n assert candidate(sentence = \"multi-hyphen-word-123\") == 0\n assert candidate(sentence = \"word-with-hyphen word-with-hyphen-\") == 0\n assert candidate(sentence = \"valid-word a valid-word- valid-word\") == 3\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc123\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation-1.\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-b-1--\") == 0\n assert candidate(sentence = \"word!word!\") == 0\n assert candidate(sentence = \"!word .word ,word\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation- word\") == 1\n assert candidate(sentence = \"invalid-punctuation, invalid-punctuation! invalid-punctuation?\") == 3\n assert candidate(sentence = \"a.b.c.d\") == 0\n assert candidate(sentence = \"multi-hyphenated-word-should-fail\") == 0\n assert candidate(sentence = \"valid-word!\") == 1\n assert candidate(sentence = \"punctuation!in!middle\") == 0\n assert candidate(sentence = \"trailing-hyphen- invalid-hyphen-\") == 0\n assert candidate(sentence = \"single-letter a\") == 2\n assert candidate(sentence = \"word-with-digit-and-hyphen--b1\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-period-and-comma,./\") == 0\n assert candidate(sentence = \"word-with-punctuations! word\") == 1\n assert candidate(sentence = \"word-with-2-hyphens-a-b-c\") == 0\n assert candidate(sentence = \"word-with--double-hyphen\") == 0\n assert candidate(sentence = \"a.b-c!d.e\") == 0\n assert candidate(sentence = \"this-is-valid-1\") == 0\n assert candidate(sentence = \"valid-word! valid-word!\") == 2\n assert candidate(sentence = \"word-with-hyphen-and-digit1-\") == 0\n assert candidate(sentence = \"a!b-c.d.e\") == 0\n assert candidate(sentence = \"a.b-c.d.e\") == 0\n assert candidate(sentence = \"word-with-digit-and-punctuation1-!\") == 0\n assert candidate(sentence = \"1word 12word word3\") == 0\n assert candidate(sentence = \"word-with-punctuation,word-with-punctuation, word-with-punctuation!word-with-punctuation.\") == 0\n assert candidate(sentence = \"a!b.c-d.e\") == 0\n assert candidate(sentence = \"valid-word-1 valid-word-2\") == 0\n assert candidate(sentence = \"word!word another-word,\") == 1\n assert candidate(sentence = \"a.b-c.d!e\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def\") == 1\n assert candidate(sentence = \"a-b.c.d\") == 0\n assert candidate(sentence = \"mid,dash\") == 0\n assert candidate(sentence = \"valid.word\") == 0\n assert candidate(sentence = \"valid-word valid-word-\") == 1\n assert candidate(sentence = \"word-with-punctuations,word\") == 0\n assert candidate(sentence = \"word-with-digit-and-punctuation1.\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-word-1\") == 0\n assert candidate(sentence = \"word-!\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-comma,\") == 0\n assert candidate(sentence = \"-hyphen-at-start\") == 0\n assert candidate(sentence = \"single-punctuation-mark.\") == 0\n assert candidate(sentence = \"!invalid-start-word invalid-end-word!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def!\") == 1\n assert candidate(sentence = \"a-b-c-d\") == 0\n assert candidate(sentence = \"word-with-punctuations,word-with-punctuations,word-with-punctuations!\") == 0\n assert candidate(sentence = \"word-with-digit-at-end1.\") == 0\n assert candidate(sentence = \"valid-word-!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc-def\") == 1\n assert candidate(sentence = \"multiple-hyphens-in--one-word\") == 0\n assert candidate(sentence = \"a valid-word- valid-word valid-word-\") == 2\n assert candidate(sentence = \"double--hyphen invalid\") == 1\n assert candidate(sentence = \"validwordwithmultiplepunctuations...\") == 0\n assert candidate(sentence = \"!a-b\") == 0\n assert candidate(sentence = \"word! word- word. word@\") == 3\n assert candidate(sentence = \"valid-word- valid-word valid-word\") == 2\n assert candidate(sentence = \"leading-hyphen invalid-hyphen\") == 2\n assert candidate(sentence = \"a.b.c!\") == 0\n assert candidate(sentence = \"invalid-word- punctuation-here.\") == 1\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def\") == 1\n assert candidate(sentence = \"valid-word-here, and-this.is!ok\") == 0\n assert candidate(sentence = \"valid-word, valid-word.\") == 2\n assert candidate(sentence = \"valid-word valid-word valid-word-\") == 2\n assert candidate(sentence = \"word-h word-hyphenated word-!\") == 2\n assert candidate(sentence = \"another!valid!word\") == 0\n assert candidate(sentence = \"word-with.punctuation\") == 0\n assert candidate(sentence = \"valid-word- valid-hyphenated-word\") == 0\n assert candidate(sentence = \"valid-word word-with-hyphen-\") == 1\n assert candidate(sentence = \"word-with-hyphen-and-punctuation! word-with-hyphen-and-punctuation!\") == 0\n assert candidate(sentence = \"single-letter a valid-word\") == 3\n assert candidate(sentence = \"valid-word-with-hyphen-and-punctuation,\") == 0\n assert candidate(sentence = \"word-with-hyphen-and-punctuation.\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word!\") == 1\n assert candidate(sentence = \"end! punctuation\") == 2\n assert candidate(sentence = \"word-with-digit-at-end1\") == 0\n assert candidate(sentence = \"hyphenated-word-\") == 0\n assert candidate(sentence = \"valid-word,\") == 1\n assert candidate(sentence = \"-word-with-hyphen\") == 0\n assert candidate(sentence = \"only-allowed-here\") == 0\n assert candidate(sentence = \"word-with-digit-in-hyphen-1-word\") == 0\n assert candidate(sentence = \"mixed-case Words Are Invalid\") == 4\n assert candidate(sentence = \"-leading-hyphen\") == 0\n assert candidate(sentence = \"word-with-punctuation!at!the!end\") == 0\n assert candidate(sentence = \"validwordwithmultiplepunctuations!!!\") == 0\n assert candidate(sentence = \"valid-word word-with-hyphen\") == 1\n assert candidate(sentence = \"word-with-digit1-and-punctuation,\") == 0\n assert candidate(sentence = \"word-with-hyphen123\") == 0\n assert candidate(sentence = \"word-with-punctuation!at!end\") == 0\n assert candidate(sentence = \"word-hyphenated word- word. word?\") == 3\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123\") == 1\n assert candidate(sentence = \"word-with-digit-at-end1,\") == 0\n assert candidate(sentence = \"word word- word! word?\") == 3\n assert candidate(sentence = \"valid-word,another-valid-word\") == 0\n assert candidate(sentence = \"trailing-punctuations,, are! invalid\") == 2\n assert candidate(sentence = \"word-with-punctuation!and-more\") == 0\n assert candidate(sentence = \"123abc and abc123 are invalid\") == 3\n assert candidate(sentence = \"word-with-digit-and-hyphen--b\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-b-1\") == 0\n assert candidate(sentence = \"valid-word! valid-word, valid-word.\") == 3\n assert candidate(sentence = \"no-hyphens allowed\") == 2\n assert candidate(sentence = \"word-with-digit-and-punctuation-1!\") == 0\n assert candidate(sentence = \"multiple spaces between words\") == 4\n assert candidate(sentence = \"triple-hyphen---word\") == 0\n assert candidate(sentence = \"punctuation,,comma and space\") == 2\n assert candidate(sentence = \"valid-word-2!\") == 0\n assert candidate(sentence = \"word-with-digit1-and-hyphen-b\") == 0\n assert candidate(sentence = \"valid-hyphen-word word- word\") == 1\n assert candidate(sentence = \"word- word- word- word.\") == 1\n assert candidate(sentence = \"word!!\") == 0\n assert candidate(sentence = \"trailing-hyphen-\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@\") == 1\n assert candidate(sentence = \"word- word- word- word\") == 1\n assert candidate(sentence = \"word-!!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-123\") == 1\n assert candidate(sentence = \"word-with-digit-and-punctuation1!\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#\") == 1\n assert candidate(sentence = \"word-with-multiple-punctuations!!!\") == 0\n assert candidate(sentence = \"word-with-punctuations!.\") == 0\n assert candidate(sentence = \"word1- word2- word3- word4-\") == 0\n assert candidate(sentence = \"multiple--hyphens-are!invalid\") == 0\n assert candidate(sentence = \"word-hyphenated-word- word- word. word-123@?!#abc-def,word@?!#abc-def,word@?!#abc123\") == 1\n assert candidate(sentence = \"valid-word- valid-word- valid-word-\") == 0\n assert candidate(sentence = \"valid-word-with-punctuation-at-end.\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen1-b\") == 0\n assert candidate(sentence = \"multi-hyphen-usage-is-not-allowed\") == 0\n assert candidate(sentence = \"word-with! punctuation\") == 2\n assert candidate(sentence = \"valid-word valid-word valid-word\") == 3\n assert candidate(sentence = \"valid-word-1 valid-word-2 valid-word-3\") == 0\n assert candidate(sentence = \"word-with-punctuations,word-with-punctuations,word-with-punctuations,word-with-punctuations!\") == 0\n assert candidate(sentence = \"word-with-digit-in-hyphen-word-1\") == 0\n assert candidate(sentence = \"word-\") == 0\n assert candidate(sentence = \"word-with-digit-and-hyphen-1-b\") == 0\n assert candidate(sentence = \"valid,word valid.word valid-word!\") == 1\n", "comparison": "exact"}, "public_tests": ["\"cat and dog\"", "\"!this 1-s b8d!\"", "\"alice and bob are playing stone-game10\""], "hints": ["Iterate through the string to split it by spaces.", "Count the number of characters of each type (letters, numbers, hyphens, and punctuations)."], "metadata": {"canonical_parameter_names": ["sentence"], "leetcode_dataset_entry_point": "Solution().countValidWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:19+00:00", "tests_total": 377, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function countValidWords($sentence) {", "container": "Solution", "callable": "countValidWords", "parameters": [{"name": "sentence", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2048, "task_id": "next-greater-numerically-balanced-number", "difficulty": "Medium", "problem_description": "An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.\n\nGiven an integer n, return the smallest numerically balanced number strictly greater than n.\n\nExample 1:\n\nInput: n = 1\nOutput: 22\nExplanation:\n22 is numerically balanced since:\n- The digit 2 occurs 2 times.\nIt is also the smallest numerically balanced number strictly greater than 1.\n\nExample 2:\n\nInput: n = 1000\nOutput: 1333\nExplanation:\n1333 is numerically balanced since:\n- The digit 1 occurs 1 time.\n- The digit 3 occurs 3 times.\nIt is also the smallest numerically balanced number strictly greater than 1000.\nNote that 1022 cannot be the answer because 0 appeared more than 0 times.\n\nExample 3:\n\nInput: n = 3000\nOutput: 3133\nExplanation:\n3133 is numerically balanced since:\n- The digit 1 occurs 1 time.\n- The digit 3 occurs 3 times.\nIt is also the smallest numerically balanced number strictly greater than 3000.\n\nConstraints:\n\n- 0 <= n <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 0) == 1\n assert candidate(n = 122333) == 123233\n assert candidate(n = 3000) == 3133\n assert candidate(n = 1222) == 1333\n assert candidate(n = 55555) == 122333\n assert candidate(n = 1234) == 1333\n assert candidate(n = 112233) == 122333\n assert candidate(n = 122133) == 122333\n assert candidate(n = 999999) == 1224444\n assert candidate(n = 123456) == 132233\n assert candidate(n = 1) == 22\n assert candidate(n = 1000) == 1333\n assert candidate(n = 987654) == 1224444\n assert candidate(n = 122) == 212\n assert candidate(n = 122444) == 123233\n assert candidate(n = 666666) == 1224444\n assert candidate(n = 444444) == 515555\n assert candidate(n = 123321) == 123323\n assert candidate(n = 98765) == 122333\n assert candidate(n = 400000) == 422444\n assert candidate(n = 111) == 122\n assert candidate(n = 1000000) == 1224444\n assert candidate(n = 4444) == 14444\n", "comparison": "exact"}, "public_tests": ["1", "1000", "3000"], "hints": ["How far away can the next greater numerically balanced number be from n?", "With the given constraints, what is the largest numerically balanced number?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().nextBeautifulNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:21+00:00", "tests_total": 58, "tests_dropped": 35, "flags": [], "topic_tags": ["hash-table", "math", "backtracking", "counting", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function nextBeautifulNumber($n) {", "container": "Solution", "callable": "nextBeautifulNumber", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2049, "task_id": "count-nodes-with-the-highest-score", "difficulty": "Medium", "problem_description": "There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since node 0 is the root, parents[0] == -1.\n\nEach node has a score. To find the score of a node, consider if the node and the edges connected to it were removed. The tree would become one or more non-empty subtrees. The size of a subtree is the number of the nodes in it. The score of the node is the product of the sizes of all those subtrees.\n\nReturn the number of nodes that have the highest score.\n\nExample 1:\n\nInput: parents = [-1,2,0,2,0]\nOutput: 3\nExplanation:\n- The score of node 0 is: 3 * 1 = 3\n- The score of node 1 is: 4 = 4\n- The score of node 2 is: 1 * 1 * 2 = 2\n- The score of node 3 is: 4 = 4\n- The score of node 4 is: 4 = 4\nThe highest score is 4, and three nodes (node 1, node 3, and node 4) have the highest score.\n\nExample 2:\n\nInput: parents = [-1,2,0]\nOutput: 2\nExplanation:\n- The score of node 0 is: 2 = 2\n- The score of node 1 is: 2 = 2\n- The score of node 2 is: 1 * 1 = 1\nThe highest score is 2, and two nodes (node 0 and node 1) have the highest score.\n\nConstraints:\n\n- n == parents.length\n- 2 <= n <= 10^5\n- parents[0] == -1\n- 0 <= parents[i] <= n - 1 for i != 0\n- parents represents a valid binary tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(parents = [-1, 0, 0, 2, 2, 3, 3]) == 5\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2]) == 1\n assert candidate(parents = [-1, 2, 0, 2, 0]) == 3\n assert candidate(parents = [-1, 0, 1, 2, 3]) == 3\n assert candidate(parents = [-1, 0, 1, 1, 2, 2, 3, 3, 4, 4]) == 2\n assert candidate(parents = [-1, 0, 1, 2, 2]) == 3\n assert candidate(parents = [-1, 0, 0, 1, 1]) == 3\n assert candidate(parents = [-1, 1, 1, 2, 2, 3, 3]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 3]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2]) == 3\n assert candidate(parents = [-1, 0, 1, 1, 3, 3]) == 4\n assert candidate(parents = [-1, 2, 0]) == 2\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3]) == 1\n assert candidate(parents = [-1, 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, 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]) == 1\n assert candidate(parents = [-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, 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]) == 1\n assert candidate(parents = [-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, 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]) == 1\n assert candidate(parents = [-1, 0, 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]) == 2\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 4, 4]) == 1\n assert candidate(parents = [-1, 0, 0, 0, 0, 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, 13, 13]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9]) == 1\n assert candidate(parents = [-1, 0, 0, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 0, 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, 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]) == 1\n assert candidate(parents = [-1, 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, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 1\n assert candidate(parents = [-1, 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, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 1\n assert candidate(parents = [-1, 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(parents = [-1, 0, 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, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 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]) == 1\n assert candidate(parents = [-1, 0, 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]) == 1\n assert candidate(parents = [-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, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 2\n assert candidate(parents = [-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, 14]) == 1\n assert candidate(parents = [-1, 0, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 0, 0, 0, 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]) == 1\n assert candidate(parents = [-1, 0, 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, 14, 15, 15, 16, 16]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 2\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30]) == 2\n assert candidate(parents = [-1, 0, 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]) == 1\n assert candidate(parents = [-1, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2, 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(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36]) == 1\n assert candidate(parents = [-1, 0, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8]) == 1\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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, 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]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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, 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]) == 2\n assert candidate(parents = [-1, 0, 1, 0, 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]) == 1\n assert candidate(parents = [-1, 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, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12]) == 2\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3]) == 1\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) == 1\n assert candidate(parents = [-1, 0, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(parents = [-1, 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, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 2, 3, 3, 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(parents = [-1, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4]) == 2\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 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\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6]) == 1\n assert candidate(parents = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 1\n assert candidate(parents = [-1, 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]) == 1\n assert candidate(parents = [-1, 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, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 2\n assert candidate(parents = [-1, 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]) == 2\n assert candidate(parents = [-1, 0, 0, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 1\n assert candidate(parents = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 2\n assert candidate(parents = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 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, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15]) == 1\n assert candidate(parents = [-1, 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]) == 1\n assert candidate(parents = [-1, 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, 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]) == 1\n assert candidate(parents = [-1, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32]) == 1\n assert candidate(parents = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(parents = [-1, 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]) == 1\n", "comparison": "exact"}, "public_tests": ["[-1,2,0,2,0]", "[-1,2,0]"], "hints": ["For each node, you need to find the sizes of the subtrees rooted in each of its children. Maybe DFS?", "How to determine the number of nodes in the rest of the tree? Can you subtract the size of the subtree rooted at the node from the total number of nodes of the tree?", "Use these values to compute the score of the node. Track the maximum score, and how many nodes achieve such score."], "metadata": {"canonical_parameter_names": ["parents"], "leetcode_dataset_entry_point": "Solution().countHighestScoreNodes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:23+00:00", "tests_total": 79, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "tree", "depth-first-search", "binary-tree", "dp-on-trees"]}, "language": "php", "interface": {"raw_signature": "function countHighestScoreNodes($parents) {", "container": "Solution", "callable": "countHighestScoreNodes", "parameters": [{"name": "parents", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2050, "task_id": "parallel-courses-iii", "difficulty": "Hard", "problem_description": "You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCourse_j, nextCourse_j] denotes that course prevCourse_j has to be completed before course nextCourse_j (prerequisite relationship). Furthermore, you are given a 0-indexed integer array time where time[i] denotes how many months it takes to complete the (i+1)^th course.\n\nYou must find the minimum number of months needed to complete all the courses following these rules:\n\n- You may start taking a course at any time if the prerequisites are met.\n- Any number of courses can be taken at the same time.\n\nReturn the minimum number of months needed to complete all the courses.\n\nNote: The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).\n\nExample 1:\n\nInput: n = 3, relations = [[1,3],[2,3]], time = [3,2,5]\nOutput: 8\nExplanation: The figure above represents the given graph and the time required to complete each course.\nWe start course 1 and course 2 simultaneously at month 0.\nCourse 1 takes 3 months and course 2 takes 2 months to complete respectively.\nThus, the earliest time we can start course 3 is at month 3, and the total time required is 3 + 5 = 8 months.\n\nExample 2:\n\nInput: n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]\nOutput: 12\nExplanation: The figure above represents the given graph and the time required to complete each course.\nYou can start courses 1, 2, and 3 at month 0.\nYou can complete them after 1, 2, and 3 months respectively.\nCourse 4 can be taken only after course 3 is completed, i.e., after 3 months. It is completed after 3 + 4 = 7 months.\nCourse 5 can be taken only after courses 1, 2, 3, and 4 have been completed, i.e., after max(1,2,3,7) = 7 months.\nThus, the minimum time needed to complete all the courses is 7 + 5 = 12 months.\n\nConstraints:\n\n- 1 <= n <= 5 * 10^4\n- 0 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)\n- relations[j].length == 2\n- 1 <= prevCourse_j, nextCourse_j <= n\n- prevCourse_j != nextCourse_j\n- All the pairs [prevCourse_j, nextCourse_j] are unique.\n- time.length == n\n- 1 <= time[i] <= 10^4\n- The given graph is a directed acyclic graph.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,relations = [[1, 2], [1, 3], [2, 4], [3, 4]],time = [4, 2, 3, 1]) == 8\n assert candidate(n = 3,relations = [[1, 3], [2, 3]],time = [3, 2, 5]) == 8\n assert candidate(n = 6,relations = [[1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [4, 6]],time = [1, 2, 3, 4, 5, 6]) == 16\n assert candidate(n = 1,relations = [],time = [5]) == 5\n assert candidate(n = 4,relations = [[1, 2], [2, 3], [3, 4]],time = [1, 2, 3, 4]) == 10\n assert candidate(n = 5,relations = [[1, 5], [2, 5], [3, 5], [3, 4], [4, 5]],time = [1, 2, 3, 4, 5]) == 12\n assert candidate(n = 9,relations = [[1, 4], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],time = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 35\n assert candidate(n = 12,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10], [10, 11], [10, 12]],time = [2, 3, 4, 1, 5, 6, 7, 8, 9, 3, 12, 4]) == 37\n assert candidate(n = 8,relations = [[1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8]],time = [2, 3, 2, 3, 2, 3, 4, 5]) == 11\n assert candidate(n = 8,relations = [[1, 2], [2, 4], [1, 3], [3, 5], [3, 6], [4, 6], [5, 7], [6, 7], [7, 8]],time = [1, 3, 2, 4, 5, 6, 1, 8]) == 23\n assert candidate(n = 20,relations = [[1, 11], [2, 11], [3, 11], [4, 11], [5, 11], [6, 11], [7, 11], [8, 11], [9, 11], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 20\n assert candidate(n = 9,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9]],time = [5, 10, 15, 20, 25, 30, 35, 40, 45]) == 100\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 5], [5, 6], [5, 7], [4, 8], [7, 8], [8, 9], [9, 10]],time = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 50\n assert candidate(n = 12,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10]],time = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 126\n assert candidate(n = 11,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 66\n assert candidate(n = 15,relations = [[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, 13], [9, 14], [10, 15], [11, 15]],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 62\n assert candidate(n = 12,relations = [[1, 6], [2, 6], [3, 6], [4, 7], [5, 7], [6, 8], [6, 9], [7, 10], [8, 11], [9, 11], [10, 12], [11, 12]],time = [1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 6, 7]) == 20\n assert candidate(n = 25,relations = [[1, 6], [2, 6], [3, 7], [4, 7], [5, 7], [6, 8], [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]],time = [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]) == 64\n assert candidate(n = 15,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15]],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 95\n assert candidate(n = 8,relations = [[1, 3], [2, 3], [3, 4], [4, 5], [4, 6], [5, 7], [6, 7], [7, 8]],time = [10, 20, 30, 40, 50, 60, 70, 80]) == 300\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 17\n assert candidate(n = 15,relations = [[1, 6], [2, 6], [3, 7], [4, 7], [5, 7], [6, 8], [7, 8], [8, 9], [8, 10], [9, 11], [10, 11], [11, 12], [11, 13], [12, 14], [13, 14], [14, 15]],time = [4, 5, 2, 6, 3, 1, 8, 9, 2, 7, 5, 6, 4, 3, 10]) == 54\n assert candidate(n = 7,relations = [[1, 3], [1, 4], [2, 3], [2, 4], [3, 5], [4, 5], [5, 7], [6, 7]],time = [2, 3, 4, 5, 1, 6, 7]) == 16\n assert candidate(n = 11,relations = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],time = [1, 2, 3, 4, 5, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(n = 6,relations = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 6]],time = [1, 2, 3, 4, 5, 6]) == 15\n assert candidate(n = 12,relations = [[1, 3], [2, 3], [3, 4], [3, 5], [4, 6], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],time = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 73\n assert candidate(n = 8,relations = [[1, 3], [2, 3], [3, 4], [3, 5], [4, 6], [5, 6], [6, 7], [6, 8]],time = [5, 3, 10, 2, 8, 4, 1, 6]) == 33\n assert candidate(n = 12,relations = [[1, 5], [2, 5], [3, 5], [1, 6], [2, 6], [3, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],time = [2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7]) == 32\n assert candidate(n = 15,relations = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [3, 6], [4, 6], [5, 6], [6, 7], [7, 8], [7, 9], [7, 10], [8, 11], [9, 11], [10, 11], [11, 12], [12, 13], [12, 14], [12, 15]],time = [2, 3, 4, 5, 1, 6, 7, 8, 9, 2, 5, 1, 3, 4, 5]) == 40\n assert candidate(n = 20,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(n = 7,relations = [[1, 2], [1, 4], [2, 3], [2, 5], [4, 6], [5, 6], [6, 7]],time = [5, 4, 3, 2, 1, 10, 15]) == 35\n assert candidate(n = 15,relations = [[1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 40\n assert candidate(n = 30,relations = [[1, 10], [2, 10], [3, 11], [4, 11], [5, 11], [6, 12], [7, 12], [8, 12], [9, 12], [10, 13], [11, 13], [12, 14], [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]],time = [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]) == 62\n assert candidate(n = 12,relations = [[1, 3], [2, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9], [6, 10], [7, 10], [8, 11], [9, 11], [10, 12], [11, 12]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 42\n assert candidate(n = 8,relations = [[1, 3], [2, 3], [3, 4], [1, 5], [2, 5], [5, 6], [6, 7], [7, 8]],time = [2, 3, 1, 2, 4, 3, 2, 1]) == 13\n assert candidate(n = 12,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [1, 6], [1, 7], [1, 8], [2, 9], [2, 10], [3, 11], [4, 12]],time = [3, 2, 5, 1, 6, 7, 4, 8, 9, 2, 5, 1]) == 53\n assert candidate(n = 7,relations = [[1, 4], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [4, 6], [5, 6], [4, 7], [5, 7]],time = [3, 2, 5, 4, 3, 7, 5]) == 16\n assert candidate(n = 9,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10]],time = [3, 2, 5, 4, 3, 2, 5, 4, 3, 2]) == 18\n assert candidate(n = 9,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [1, 6], [1, 7], [2, 8], [3, 9]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 45\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 47\n assert candidate(n = 15,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [8, 11], [9, 12], [9, 13], [10, 14], [11, 14], [12, 15], [13, 15]],time = [2, 3, 2, 4, 3, 1, 5, 6, 7, 8, 4, 3, 2, 5, 6]) == 28\n assert candidate(n = 20,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20]],time = [2, 3, 4, 5, 1, 6, 7, 8, 9, 2, 5, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 105\n assert candidate(n = 13,relations = [[1, 3], [2, 3], [3, 4], [3, 5], [4, 6], [5, 6], [6, 7], [6, 8], [7, 9], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]],time = [4, 3, 5, 2, 6, 7, 8, 9, 3, 4, 10, 1, 2]) == 51\n assert candidate(n = 15,relations = [[1, 10], [1, 11], [2, 10], [3, 11], [4, 12], [5, 12], [6, 13], [7, 13], [8, 14], [9, 14], [10, 15], [11, 15], [12, 15], [13, 15], [14, 15]],time = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1]) == 16\n assert candidate(n = 20,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 210\n assert candidate(n = 15,relations = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 7], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],time = [2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1]) == 35\n assert candidate(n = 9,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],time = [4, 3, 2, 1, 4, 3, 2, 1, 4]) == 24\n assert candidate(n = 8,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [4, 6], [5, 7], [6, 7], [7, 8]],time = [5, 4, 3, 2, 1, 1, 2, 3]) == 17\n assert candidate(n = 8,relations = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8]],time = [10, 20, 30, 40, 50, 60, 70, 80]) == 210\n assert candidate(n = 10,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(n = 20,relations = [[1, 5], [2, 6], [3, 7], [4, 8], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14], [7, 15], [8, 16], [9, 17], [10, 18], [11, 19], [12, 20], [13, 15], [14, 16], [15, 17], [16, 18], [17, 19], [18, 20], [19, 20]],time = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 12\n assert candidate(n = 20,relations = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [8, 11], [9, 12], [9, 13], [10, 14], [11, 14], [12, 15], [13, 15], [14, 16], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 138\n assert candidate(n = 7,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7]],time = [3, 2, 5, 4, 1, 6, 8]) == 27\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [4, 6], [5, 7], [6, 7], [7, 8], [8, 9], [9, 10]],time = [1, 2, 3, 2, 3, 2, 3, 4, 5, 6]) == 27\n assert candidate(n = 6,relations = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],time = [1000, 2000, 3000, 4000, 5000, 6000]) == 21000\n assert candidate(n = 7,relations = [[1, 4], [2, 4], [3, 4], [4, 5], [4, 6], [5, 7], [6, 7]],time = [1, 1, 1, 3, 2, 2, 1]) == 7\n assert candidate(n = 10,relations = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6], [5, 7], [6, 8], [7, 8], [8, 9], [9, 10]],time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 47\n", "comparison": "exact"}, "public_tests": ["3\n[[1,3],[2,3]]\n[3,2,5]", "5\n[[1,5],[2,5],[3,5],[3,4],[4,5]]\n[1,2,3,4,5]"], "hints": ["What is the earliest time a course can be taken?", "How would you solve the problem if all courses take equal time?", "How would you generalize this approach?"], "metadata": {"canonical_parameter_names": ["n", "relations", "time"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:26+00:00", "tests_total": 60, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "graph", "topological-sort", "directed-acyclic-graph"]}, "language": "php", "interface": {"raw_signature": "function minimumTime($n, $relations, $time) {", "container": "Solution", "callable": "minimumTime", "parameters": [{"name": "n", "type": "Integer"}, {"name": "relations", "type": "Integer[][]"}, {"name": "time", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2053, "task_id": "kth-distinct-string-in-an-array", "difficulty": "Easy", "problem_description": "A distinct string is a string that is present only once in an array.\n\nGiven an array of strings arr, and an integer k, return the k^th distinct string present in arr. If there are fewer than k distinct strings, return an empty string \"\".\n\nNote that the strings are considered in the order in which they appear in the array.\n\nExample 1:\n\nInput: arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2\nOutput: \"a\"\nExplanation:\nThe only distinct strings in arr are \"d\" and \"a\".\n\"d\" appears 1^st, so it is the 1^st distinct string.\n\"a\" appears 2^nd, so it is the 2^nd distinct string.\nSince k == 2, \"a\" is returned.\n\nExample 2:\n\nInput: arr = [\"aaa\",\"aa\",\"a\"], k = 1\nOutput: \"aaa\"\nExplanation:\nAll strings in arr are distinct, so the 1^st string \"aaa\" is returned.\n\nExample 3:\n\nInput: arr = [\"a\",\"b\",\"a\"], k = 3\nOutput: \"\"\nExplanation:\nThe only distinct string is \"b\". Since there are fewer than 3 distinct strings, we return an empty string \"\".\n\nConstraints:\n\n- 1 <= k <= arr.length <= 1000\n- 1 <= arr[i].length <= 5\n- arr[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = ['a'],k = 1) == \"a\"\n assert candidate(arr = ['a', 'a', 'b', 'b', 'c', 'c', 'd'],k = 1) == \"d\"\n assert candidate(arr = ['aaa', 'aa', 'a'],k = 1) == \"aaa\"\n assert candidate(arr = ['a', 'b', 'c', 'd', 'e', 'f'],k = 6) == \"f\"\n assert candidate(arr = ['hello', 'world', 'hello', 'world'],k = 2) == \"\"\n assert candidate(arr = ['x', 'y', 'z', 'x', 'y', 'z'],k = 2) == \"\"\n assert candidate(arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],k = 10) == \"j\"\n assert candidate(arr = ['same', 'same', 'same', 'same'],k = 1) == \"\"\n assert candidate(arr = ['a', 'b', 'a'],k = 3) == \"\"\n assert candidate(arr = ['one', 'two', 'three', 'four', 'five'],k = 5) == \"five\"\n assert candidate(arr = ['a', 'a', 'a', 'a', 'a'],k = 1) == \"\"\n assert candidate(arr = ['test', 'test', 'test'],k = 1) == \"\"\n assert candidate(arr = ['d', 'b', 'c', 'b', 'c', 'a'],k = 2) == \"a\"\n assert candidate(arr = ['xyz', 'zyx', 'zyx', 'xyz', 'zyx'],k = 1) == \"\"\n assert candidate(arr = ['same', 'word', 'same', 'word', 'same', 'word', 'same', 'word', 'same'],k = 1) == \"\"\n assert candidate(arr = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],k = 7) == \"seven\"\n assert candidate(arr = ['x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y'],k = 1) == \"\"\n assert candidate(arr = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yzab', 'cdef', 'ghij', 'klmn', 'opqr', 'stuv', 'wxyz'],k = 13) == \"wxyz\"\n assert candidate(arr = ['abcd', 'abc', 'ab', 'a', 'abcd', 'abc', 'ab', 'a', 'abcd', 'abc', 'ab', 'a'],k = 3) == \"\"\n assert candidate(arr = ['abc', 'def', 'ghi', 'abc', 'jkl', 'ghi', 'mno'],k = 4) == \"\"\n assert candidate(arr = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],k = 1) == \"\"\n assert candidate(arr = ['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'],k = 26) == \"z\"\n assert candidate(arr = ['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'],k = 27) == \"\"\n assert candidate(arr = ['xy', 'yx', 'xx', 'yy', 'xz', 'zx', 'yz', 'zy', 'xxyy', 'xyxy', 'yxyx', 'yxyy', 'xyyx', 'xyyy', 'yyxx', 'yyxy', 'yyyx', 'yyyy'],k = 10) == \"xyxy\"\n assert candidate(arr = ['xyz', 'zyx', 'wxy', 'yxw', 'uvw', 'vuw', 'wuv', 'abc', 'cab', 'bac'],k = 2) == \"zyx\"\n assert candidate(arr = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abc', 'def', 'ghi'],k = 5) == \"vwx\"\n assert candidate(arr = ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'],k = 10) == \"\"\n assert candidate(arr = ['aaaaa', 'aaaab', 'aaaba', 'aabaa', 'abaaa', 'baaaa', 'abcde', 'bcdea', 'cdeab', 'decab', 'efghi', 'fghie', 'ghief', 'hiefg', 'iefgh', 'jklmn', 'klmno', 'lmnop', 'mnopq', 'nopqr', 'opqrs', 'pqrst', 'qrstu', 'rstuv', 'stuvw', 'tuvwx', 'uvwxy', 'vwxyz'],k = 15) == \"iefgh\"\n assert candidate(arr = ['loop', 'pool', 'look', 'cool', 'cool', 'lopo', 'loopo'],k = 3) == \"look\"\n assert candidate(arr = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba'],k = 25) == \"dabc\"\n assert candidate(arr = ['same', 'word', 'same', 'word', 'same'],k = 2) == \"\"\n assert candidate(arr = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],k = 9) == \"\"\n assert candidate(arr = ['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'],k = 15) == \"o\"\n assert candidate(arr = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd'],k = 2) == \"\"\n assert candidate(arr = ['abcd', 'ab', 'a', 'abcde', 'abcd', 'abc', 'ab', 'a'],k = 3) == \"\"\n assert candidate(arr = ['aabb', 'abab', 'bbaa', 'abba', 'baab', 'baba', 'aabb', 'abab'],k = 1) == \"bbaa\"\n assert candidate(arr = ['a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', 'd'],k = 4) == \"\"\n assert candidate(arr = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],k = 5) == \"five\"\n assert candidate(arr = ['abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba'],k = 20) == \"dacb\"\n assert candidate(arr = ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'],k = 10) == \"\"\n assert candidate(arr = ['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'],k = 5) == \"e\"\n assert candidate(arr = ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa', 'aaaa', 'bbbb', 'cccc', 'dddd'],k = 5) == \"baba\"\n assert candidate(arr = ['aaa', 'aab', 'aac', 'aad', 'aae', 'aaf', 'aag', 'aah', 'aai', 'aaj', 'aak'],k = 10) == \"aaj\"\n assert candidate(arr = ['a', 'ab', 'abc', 'abcd', 'abcde', 'a', 'ab', 'abc', 'abcd'],k = 3) == \"\"\n assert candidate(arr = ['a', 'b', 'c', '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'],k = 10) == \"m\"\n assert candidate(arr = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],k = 1) == \"\"\n assert candidate(arr = ['aaaaa', 'aaaab', 'aaaba', 'aabaa', 'abaaa', 'baaaa', 'abcde', 'bcdea', 'cdeab', 'decab'],k = 8) == \"bcdea\"\n assert candidate(arr = ['abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd'],k = 1) == \"\"\n assert candidate(arr = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz'],k = 5) == \"mno\"\n assert candidate(arr = ['x', 'y', 'x', 'y', 'x', 'y', 'z', 'w', 'z', 'w', 'z', 'w', 'v', 'u', 'v', 'u', 't', 's', 'r', 'q', 'p'],k = 10) == \"\"\n assert candidate(arr = ['abcd', 'dcba', 'adbc', 'bdac', 'cadb', 'dacb', 'abcd', 'dcba'],k = 5) == \"\"\n assert candidate(arr = ['abc', 'def', 'abc', 'def', 'abc', 'def', 'abc', 'def', 'ghi', 'jkl'],k = 3) == \"\"\n assert candidate(arr = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba'],k = 3) == \"\"\n assert candidate(arr = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],k = 5) == \"\"\n", "comparison": "exact"}, "public_tests": ["[\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"]\n2", "[\"aaa\",\"aa\",\"a\"]\n1", "[\"a\",\"b\",\"a\"]\n3"], "hints": ["Try 'mapping' the strings to check if they are unique or not."], "metadata": {"canonical_parameter_names": ["arr", "k"], "leetcode_dataset_entry_point": "Solution().kthDistinct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:30+00:00", "tests_total": 110, "tests_dropped": 56, "flags": [], "topic_tags": ["array", "hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function kthDistinct($arr, $k) {", "container": "Solution", "callable": "kthDistinct", "parameters": [{"name": "arr", "type": "String[]"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2054, "task_id": "two-best-non-overlapping-events", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D integer array of events where events[i] = [startTime_i, endTime_i, value_i]. The i^th event starts at startTime_iand ends at endTime_i, and if you attend this event, you will receive a value of value_i. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized.\n\nReturn this maximum sum.\n\nNote that the start time and end time is inclusive: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time t, the next event must start at or after t + 1.\n\nExample 1:\n\nInput: events = [[1,3,2],[4,5,2],[2,4,3]]\nOutput: 4\nExplanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.\n\nExample 2:\n\nInput: events = [[1,3,2],[4,5,2],[1,5,5]]\nOutput: 5\nExplanation: Choose event 2 for a sum of 5.\n\nExample 3:\n\nInput: events = [[1,5,3],[1,5,1],[6,6,5]]\nOutput: 8\nExplanation: Choose events 0 and 2 for a sum of 3 + 5 = 8.\n\nConstraints:\n\n- 2 <= events.length <= 10^5\n- events[i].length == 3\n- 1 <= startTime_i <= endTime_i <= 10^9\n- 1 <= value_i <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(events = [[1, 1000000000, 1000000], [1000000000, 1000000000, 1000000]]) == 1000000\n assert candidate(events = [[1, 10, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [8, 9, 5]]) == 9\n assert candidate(events = [[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]]) == 19\n assert candidate(events = [[10, 20, 15], [20, 30, 10], [1, 10, 5]]) == 15\n assert candidate(events = [[1, 10, 4], [1, 10, 5], [5, 10, 3]]) == 5\n assert candidate(events = [[1, 3, 2], [4, 5, 2], [2, 4, 3]]) == 4\n assert candidate(events = [[1, 3, 2], [4, 5, 2], [1, 5, 5]]) == 5\n assert candidate(events = [[1, 2, 4], [3, 4, 3], [2, 3, 1]]) == 7\n assert candidate(events = [[1, 5, 3], [1, 5, 1], [6, 6, 5]]) == 8\n assert candidate(events = [[1, 3, 5], [2, 5, 6], [4, 6, 7], [5, 7, 8]]) == 13\n assert candidate(events = [[1, 5, 10], [6, 10, 10], [11, 15, 10], [16, 20, 10]]) == 20\n assert candidate(events = [[2, 2, 1], [3, 3, 2], [4, 4, 3], [5, 5, 4], [6, 6, 5]]) == 9\n assert candidate(events = [[1, 10, 10], [2, 3, 5], [4, 5, 7], [6, 7, 9]]) == 16\n assert candidate(events = [[1, 2, 100], [3, 4, 200], [5, 6, 300], [7, 8, 400], [9, 10, 500], [11, 12, 600]]) == 1100\n assert candidate(events = [[1, 5, 1], [1, 4, 2], [2, 5, 3], [2, 4, 4], [3, 6, 5], [3, 5, 6], [4, 7, 7], [4, 6, 8], [5, 8, 9], [5, 7, 10]]) == 14\n assert candidate(events = [[1, 10, 5], [1, 10, 6], [1, 10, 7], [1, 10, 8], [1, 10, 9]]) == 9\n assert candidate(events = [[1, 2, 1], [1, 2, 2], [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 2, 8], [1, 2, 9], [1, 2, 10], [1, 2, 11], [1, 2, 12], [1, 2, 13], [1, 2, 14], [1, 2, 15]]) == 15\n assert candidate(events = [[1, 3, 1], [2, 3, 2], [3, 3, 3], [4, 5, 4], [5, 5, 5], [6, 7, 6], [7, 7, 7]]) == 12\n assert candidate(events = [[1, 10, 1], [2, 9, 2], [3, 8, 3], [4, 7, 4], [5, 6, 5], [11, 20, 6], [12, 19, 7], [13, 18, 8], [14, 17, 9], [15, 16, 10]]) == 15\n assert candidate(events = [[1, 1000000, 1], [1000001, 2000000, 2], [2000001, 3000000, 3], [3000001, 4000000, 4], [4000001, 5000000, 5], [5000001, 6000000, 6], [6000001, 7000000, 7], [7000001, 8000000, 8], [8000001, 9000000, 9], [9000001, 10000000, 10]]) == 19\n assert candidate(events = [[1, 2, 1], [3, 4, 2], [5, 6, 3], [7, 8, 4], [9, 10, 5], [11, 12, 6], [13, 14, 7]]) == 13\n assert candidate(events = [[1, 5, 5], [6, 10, 10], [11, 15, 15], [16, 20, 20], [21, 25, 25]]) == 45\n assert candidate(events = [[1, 2, 100], [3, 4, 200], [5, 6, 300], [7, 8, 400], [9, 10, 500]]) == 900\n assert candidate(events = [[1, 5, 1], [6, 10, 2], [11, 15, 3], [16, 20, 4], [21, 25, 5], [26, 30, 6]]) == 11\n assert candidate(events = [[1, 2, 1000000], [2, 3, 900000], [3, 4, 800000], [4, 5, 700000], [5, 6, 600000], [6, 7, 500000], [7, 8, 400000], [8, 9, 300000], [9, 10, 200000], [10, 11, 100000]]) == 1800000\n assert candidate(events = [[1, 1000000000, 1], [2, 1000000000, 2], [3, 1000000000, 3], [4, 1000000000, 4], [5, 1000000000, 5]]) == 5\n assert candidate(events = [[1, 1000000000, 1], [1000000000, 1000000000, 1000000]]) == 1000000\n assert candidate(events = [[1, 5, 10], [2, 6, 20], [3, 7, 30], [4, 8, 40], [5, 9, 50]]) == 50\n assert candidate(events = [[1, 100, 1], [101, 200, 2], [201, 300, 3], [301, 400, 4], [401, 500, 5], [501, 600, 6], [601, 700, 7], [701, 800, 8], [801, 900, 9], [901, 1000, 10]]) == 19\n assert candidate(events = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500]]) == 800\n assert candidate(events = [[1, 1, 10], [2, 2, 20], [3, 3, 30], [4, 4, 40], [5, 5, 50], [6, 6, 60], [7, 7, 70], [8, 8, 80], [9, 9, 90], [10, 10, 100], [11, 11, 110], [12, 12, 120], [13, 13, 130], [14, 14, 140], [15, 15, 150]]) == 290\n assert candidate(events = [[1, 1, 10], [2, 2, 9], [3, 3, 8], [4, 4, 7], [5, 5, 6], [6, 6, 5], [7, 7, 4], [8, 8, 3], [9, 9, 2], [10, 10, 1], [11, 11, 100], [12, 12, 99], [13, 13, 98], [14, 14, 97], [15, 15, 96]]) == 199\n assert candidate(events = [[1, 1, 1000000], [2, 2, 999999], [3, 3, 999998], [4, 4, 999997], [5, 5, 999996]]) == 1999999\n assert candidate(events = [[1, 5, 100], [5, 10, 200], [10, 15, 300], [15, 20, 400], [20, 25, 500], [25, 30, 600], [30, 35, 700], [35, 40, 800], [40, 45, 900], [45, 50, 1000]]) == 1800\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120], [13, 14, 130], [14, 15, 140], [15, 16, 150]]) == 280\n assert candidate(events = [[1, 2, 1], [3, 4, 2], [5, 6, 3], [7, 8, 4], [9, 10, 5], [11, 12, 6], [13, 14, 7], [15, 16, 8], [17, 18, 9], [19, 20, 10], [21, 22, 11], [23, 24, 12], [25, 26, 13], [27, 28, 14], [29, 30, 15]]) == 29\n assert candidate(events = [[1, 2, 10], [3, 4, 20], [5, 6, 30], [7, 8, 40], [9, 10, 50], [11, 12, 60], [13, 14, 70], [15, 16, 80], [17, 18, 90], [19, 20, 100], [21, 22, 110], [23, 24, 120], [25, 26, 130], [27, 28, 140], [29, 30, 150]]) == 290\n assert candidate(events = [[1, 2, 1000000], [3, 4, 999999], [5, 6, 999998], [7, 8, 999997], [9, 10, 999996], [11, 12, 999995], [13, 14, 999994], [15, 16, 999993], [17, 18, 999992], [19, 20, 999991]]) == 1999999\n assert candidate(events = [[1, 5, 1000000], [1, 5, 900000], [1, 5, 800000], [1, 5, 700000], [1, 5, 600000], [1, 5, 500000], [1, 5, 400000], [1, 5, 300000], [1, 5, 200000], [1, 5, 100000]]) == 1000000\n assert candidate(events = [[1, 2, 10], [1, 2, 11], [1, 2, 12], [1, 2, 13], [1, 2, 14], [1, 2, 15]]) == 15\n assert candidate(events = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1, 7, 7], [1, 8, 8], [1, 9, 9], [1, 10, 10]]) == 10\n assert candidate(events = [[10, 20, 100], [20, 30, 200], [30, 40, 300], [40, 50, 400], [50, 60, 500], [60, 70, 600]]) == 1000\n assert candidate(events = [[1, 1, 100], [2, 2, 200], [3, 3, 300], [4, 4, 400], [5, 5, 500], [6, 6, 600], [7, 7, 700], [8, 8, 800], [9, 9, 900], [10, 10, 1000]]) == 1900\n assert candidate(events = [[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(events = [[1, 3, 100], [2, 5, 200], [3, 7, 300], [4, 10, 400], [5, 12, 500], [6, 15, 600], [7, 17, 700], [8, 18, 800], [9, 19, 900]]) == 1200\n assert candidate(events = [[1, 2, 10], [1, 3, 20], [1, 4, 30], [1, 5, 40], [1, 6, 50], [1, 7, 60], [1, 8, 70], [1, 9, 80], [1, 10, 90]]) == 90\n assert candidate(events = [[1, 5, 3], [1, 5, 1], [6, 6, 5], [7, 8, 4]]) == 9\n assert candidate(events = [[1, 5, 1], [2, 6, 2], [3, 7, 3], [4, 8, 4], [5, 9, 5], [6, 10, 6], [7, 11, 7], [8, 12, 8], [9, 13, 9], [10, 14, 10]]) == 15\n assert candidate(events = [[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]]) == 10\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [31, 40, 400], [41, 50, 500], [51, 60, 600], [61, 70, 700], [71, 80, 800], [81, 90, 900], [91, 100, 1000], [1, 50, 500000], [51, 100, 500000]]) == 1000000\n assert candidate(events = [[1, 3, 5], [3, 5, 5], [5, 7, 5], [7, 9, 5], [9, 11, 5]]) == 10\n assert candidate(events = [[1, 100, 1], [2, 99, 2], [3, 98, 3], [4, 97, 4], [5, 96, 5], [6, 95, 6], [7, 94, 7], [8, 93, 8], [9, 92, 9], [10, 91, 10]]) == 10\n assert candidate(events = [[1, 5, 10], [2, 6, 20], [3, 7, 30], [4, 8, 40], [5, 9, 50], [6, 10, 60], [7, 11, 70], [8, 12, 80], [9, 13, 90], [10, 14, 100]]) == 150\n assert candidate(events = [[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]]) == 2\n assert candidate(events = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50]]) == 80\n assert candidate(events = [[1, 5, 10], [2, 5, 20], [3, 5, 30], [4, 5, 40], [5, 5, 50], [6, 10, 60], [7, 10, 70], [8, 10, 80], [9, 10, 90], [10, 10, 100]]) == 150\n assert candidate(events = [[1, 1, 1000000], [1000000000, 1000000000, 1], [500000000, 500000000, 2], [600000000, 600000000, 3], [700000000, 700000000, 4], [800000000, 800000000, 5]]) == 1000005\n assert candidate(events = [[1, 10, 5], [10, 20, 10], [20, 30, 15], [30, 40, 20], [40, 50, 25], [50, 60, 30], [60, 70, 35], [70, 80, 40], [80, 90, 45], [90, 100, 50]]) == 90\n assert candidate(events = [[1, 1, 1000000], [2, 2, 999999], [3, 3, 999998], [4, 4, 999997], [5, 5, 999996], [6, 6, 999995], [7, 7, 999994], [8, 8, 999993], [9, 9, 999992], [10, 10, 999991]]) == 1999999\n assert candidate(events = [[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]]) == 28\n assert candidate(events = [[1, 5, 3], [2, 4, 5], [6, 8, 7], [9, 11, 10], [12, 15, 12], [16, 20, 15]]) == 27\n assert candidate(events = [[1, 10, 10], [2, 3, 20], [4, 5, 30], [6, 7, 40], [8, 9, 50], [11, 12, 60]]) == 110\n assert candidate(events = [[1, 10, 10], [11, 20, 20], [21, 30, 30], [31, 40, 40], [41, 50, 50], [51, 60, 60], [61, 70, 70], [71, 80, 80], [81, 90, 90], [91, 100, 100]]) == 190\n assert candidate(events = [[1, 3, 1], [4, 6, 2], [7, 9, 3], [10, 12, 4], [13, 15, 5], [16, 18, 6], [19, 21, 7], [22, 24, 8], [25, 27, 9], [28, 30, 10]]) == 19\n assert candidate(events = [[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]]) == 26\n assert candidate(events = [[1, 3, 3], [3, 5, 2], [5, 7, 1], [7, 9, 4], [9, 11, 5], [11, 13, 6]]) == 10\n assert candidate(events = [[1, 2, 5], [3, 4, 10], [5, 6, 15], [7, 8, 20], [9, 10, 25], [11, 12, 30], [13, 14, 35], [15, 16, 40]]) == 75\n assert candidate(events = [[1, 2, 1], [3, 4, 2], [5, 6, 3], [7, 8, 4], [9, 10, 5], [11, 12, 6], [13, 14, 7], [15, 16, 8], [17, 18, 9], [19, 20, 10]]) == 19\n assert candidate(events = [[1, 1000000000, 10], [2, 999999999, 20], [3, 999999998, 30], [4, 999999997, 40], [5, 999999996, 50], [6, 999999995, 60], [7, 999999994, 70], [8, 999999993, 80], [9, 999999992, 90], [10, 999999991, 100]]) == 100\n assert candidate(events = [[1, 1, 1000000], [2, 2, 1000000], [3, 3, 1000000], [4, 4, 1000000], [5, 5, 1000000], [6, 6, 1000000], [7, 7, 1000000], [8, 8, 1000000], [9, 9, 1000000], [10, 10, 1000000]]) == 2000000\n assert candidate(events = [[1, 1000000000, 1], [2, 1000000000, 2], [3, 1000000000, 3]]) == 3\n assert candidate(events = [[1, 10, 1], [10, 20, 2], [20, 30, 3], [30, 40, 4], [40, 50, 5], [50, 60, 6], [60, 70, 7], [70, 80, 8], [80, 90, 9], [90, 100, 10], [1, 100, 11], [2, 99, 12], [3, 98, 13], [4, 97, 14], [5, 96, 15]]) == 18\n assert candidate(events = [[1, 3, 2], [2, 4, 3], [3, 5, 4], [4, 6, 5], [5, 7, 6], [6, 8, 7], [7, 9, 8], [8, 10, 9], [9, 11, 10]]) == 17\n assert candidate(events = [[1, 1000000000, 1], [2, 1000000000, 2], [3, 1000000000, 3], [4, 1000000000, 4]]) == 4\n assert candidate(events = [[1, 3, 10], [2, 5, 8], [4, 6, 6], [7, 8, 5], [8, 10, 7], [9, 12, 4]]) == 17\n assert candidate(events = [[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]]) == 29\n assert candidate(events = [[1, 2, 50], [3, 4, 60], [5, 6, 70], [7, 8, 80], [9, 10, 90], [11, 12, 100], [13, 14, 110], [15, 16, 120], [17, 18, 130], [19, 20, 140], [21, 22, 150], [23, 24, 160], [25, 26, 170], [27, 28, 180], [29, 30, 190]]) == 370\n assert candidate(events = [[1, 3, 10], [2, 4, 20], [3, 5, 30], [4, 6, 40], [5, 7, 50], [6, 8, 60], [7, 9, 70], [8, 10, 80]]) == 130\n assert candidate(events = [[1, 2, 100], [3, 5, 200], [6, 8, 300], [9, 10, 400], [11, 12, 500]]) == 900\n assert candidate(events = [[1, 2, 1], [1, 2, 2], [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 2, 8], [1, 2, 9], [1, 2, 10]]) == 10\n assert candidate(events = [[1, 5, 5], [2, 6, 10], [3, 7, 15], [4, 8, 20], [5, 9, 25], [6, 10, 30], [7, 11, 35], [8, 12, 40], [9, 13, 45], [10, 14, 50]]) == 75\n assert candidate(events = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [7, 8, 7], [8, 9, 8]]) == 14\n assert candidate(events = [[1, 3, 2], [1, 3, 3], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 3, 7], [1, 3, 8], [1, 3, 9], [1, 3, 10], [1, 3, 11], [1, 3, 12], [1, 3, 13], [1, 3, 14], [1, 3, 15], [1, 3, 16]]) == 16\n assert candidate(events = [[1, 1000000000, 1000000], [2, 999999999, 999999], [3, 999999998, 999998]]) == 1000000\n assert candidate(events = [[1, 5, 10], [2, 6, 20], [3, 7, 30], [4, 8, 40], [5, 9, 50], [6, 10, 60], [7, 11, 70], [8, 12, 80], [9, 13, 90], [10, 14, 100], [11, 15, 110], [12, 16, 120], [13, 17, 130], [14, 18, 140], [15, 19, 150]]) == 250\n assert candidate(events = [[1, 10, 100], [11, 20, 200], [21, 30, 300], [31, 40, 400], [41, 50, 500], [51, 60, 600], [61, 70, 700], [71, 80, 800], [81, 90, 900], [91, 100, 1000]]) == 1900\n assert candidate(events = [[1, 1000000000, 1000000], [2, 3, 500000], [4, 5, 600000], [6, 7, 400000], [8, 9, 700000], [10, 1000000000, 800000]]) == 1500000\n assert candidate(events = [[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]]) == 22\n assert candidate(events = [[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]]) == 18\n assert candidate(events = [[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]]) == 16\n", "comparison": "exact"}, "public_tests": ["[[1,3,2],[4,5,2],[2,4,3]]", "[[1,3,2],[4,5,2],[1,5,5]]", "[[1,5,3],[1,5,1],[6,6,5]]"], "hints": ["How can sorting the events on the basis of their start times help? How about end times?", "How can we quickly get the maximum score of an interval not intersecting with the interval we chose?"], "metadata": {"canonical_parameter_names": ["events"], "leetcode_dataset_entry_point": "Solution().maxTwoEvents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:33+00:00", "tests_total": 97, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "dynamic-programming", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maxTwoEvents($events) {", "container": "Solution", "callable": "maxTwoEvents", "parameters": [{"name": "events", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2055, "task_id": "plates-between-candles", "difficulty": "Medium", "problem_description": "There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle.\n\nYou are also given a 0-indexed 2D integer array queries where queries[i] = [left_i, right_i] denotes the substring s[left_i...right_i] (inclusive). For each query, you need to find the number of plates between candles that are in the substring. A plate is considered between candles if there is at least one candle to its left and at least one candle to its right in the substring.\n\n- For example, s = \"||**||**|*\", and a query [3, 8] denotes the substring \"*||**|\". The number of plates between candles in this substring is 2, as each of the two plates has at least one candle in the substring to its left and right.\n\nReturn an integer array answer where answer[i] is the answer to the i^th query.\n\nExample 1:\n\nInput: s = \"**|**|***|\", queries = [[2,5],[5,9]]\nOutput: [2,3]\nExplanation:\n- queries[0] has two plates between candles.\n- queries[1] has three plates between candles.\n\nExample 2:\n\nInput: s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]\nOutput: [9,0,0,0,0]\nExplanation:\n- queries[0] has nine plates between candles.\n- The other queries have zero plates between candles.\n\nConstraints:\n\n- 3 <= s.length <= 10^5\n- s consists of '*' and '|' characters.\n- 1 <= queries.length <= 10^5\n- queries[i].length == 2\n- 0 <= left_i <= right_i < s.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"**|**|***|\",queries = [[2, 5], [5, 9]]) == [2, 3]\n assert candidate(s = \"***||***\",queries = [[0, 5], [2, 4]]) == [0, 0]\n assert candidate(s = \"*|*|*|*|*|*|*|\",queries = [[0, 7], [1, 6], [2, 5]]) == [3, 2, 1]\n assert candidate(s = \"|||***|||\",queries = [[0, 8], [1, 7], [2, 6]]) == [3, 3, 3]\n assert candidate(s = \"||*|*|*|*|*|*|\",queries = [[0, 10], [1, 9], [2, 8], [3, 7]]) == [4, 4, 2, 2]\n assert candidate(s = \"|||****|****|****||\",queries = [[0, 10], [5, 15], [1, 4]]) == [4, 4, 0]\n assert candidate(s = \"*|*|*|*|*|\",queries = [[0, 5], [1, 4]]) == [2, 1]\n assert candidate(s = \"|*|*|*|*|*|*|*|*|*|*|\",queries = [[0, 10], [1, 9], [2, 8], [3, 7]]) == [5, 3, 3, 1]\n assert candidate(s = \"|||*****|||\",queries = [[0, 2], [3, 8], [7, 10]]) == [0, 0, 0]\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|*|\",queries = [[0, 11], [1, 10], [2, 9], [3, 8]]) == [5, 4, 3, 2]\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|\",queries = [[0, 10], [1, 9], [2, 8], [3, 7]]) == [4, 4, 2, 2]\n assert candidate(s = \"***|**|*****|**||**|*\",queries = [[1, 17], [4, 5], [14, 17], [5, 11], [15, 16]]) == [9, 0, 0, 0, 0]\n assert candidate(s = \"***||****|**|\",queries = [[0, 4], [5, 8], [9, 11]]) == [0, 0, 0]\n", "comparison": "exact"}, "public_tests": ["\"**|**|***|\"\n[[2,5],[5,9]]", "\"***|**|*****|**||**|*\"\n[[1,17],[4,5],[14,17],[5,11],[15,16]]"], "hints": ["Can you find the indices of the most left and right candles for a given substring, perhaps by using binary search (or better) over an array of indices of all the bars?", "Once the indices of the most left and right bars are determined, how can you efficiently count the number of plates within the range? Prefix sums?"], "metadata": {"canonical_parameter_names": ["s", "queries"], "leetcode_dataset_entry_point": "Solution().platesBetweenCandles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:35+00:00", "tests_total": 13, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "string", "binary-search", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function platesBetweenCandles($s, $queries) {", "container": "Solution", "callable": "platesBetweenCandles", "parameters": [{"name": "s", "type": "String"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2056, "task_id": "number-of-valid-move-combinations-on-chessboard", "difficulty": "Hard", "problem_description": "There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the i^th piece. In addition, you are given a 2D integer array positions also of length n, where positions[i] = [r_i, c_i] indicates that the i^th piece is currently at the 1-based coordinate (r_i, c_i) on the chessboard.\n\nWhen making a move for a piece, you choose a destination square that the piece will travel toward and stop on.\n\n- A rook can only travel horizontally or vertically from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), or (r, c-1).\n- A queen can only travel horizontally, vertically, or diagonally from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), (r, c-1), (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\n- A bishop can only travel diagonally from (r, c) to the direction of (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\n\nYou must make a move for every piece on the board simultaneously. A move combination consists of all the moves performed on all the given pieces. Every second, each piece will instantaneously travel one square towards their destination if they are not already at it. All pieces start traveling at the 0^th second. A move combination is invalid if, at a given time, two or more pieces occupy the same square.\n\nReturn the number of valid move combinations.\n\nNotes:\n\n- No two pieces will start in the same square.\n- You may choose the square a piece is already on as its destination.\n- If two pieces are directly adjacent to each other, it is valid for them to move past each other and swap positions in one second.\n\nExample 1:\n\nInput: pieces = [\"rook\"], positions = [[1,1]]\nOutput: 15\nExplanation: The image above shows the possible squares the piece can move to.\n\nExample 2:\n\nInput: pieces = [\"queen\"], positions = [[1,1]]\nOutput: 22\nExplanation: The image above shows the possible squares the piece can move to.\n\nExample 3:\n\nInput: pieces = [\"bishop\"], positions = [[4,3]]\nOutput: 12\nExplanation: The image above shows the possible squares the piece can move to.\n\nConstraints:\n\n- n == pieces.length\n- n == positions.length\n- 1 <= n <= 4\n- pieces only contains the strings \"rook\", \"queen\", and \"bishop\".\n- There will be at most one queen on the chessboard.\n- 1 <= r_i, c_i <= 8\n- Each positions[i] is distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pieces = ['bishop'],positions = [[4, 3]]) == 12\n assert candidate(pieces = ['queen', 'rook'],positions = [[1, 1], [2, 2]]) == 309\n assert candidate(pieces = ['rook', 'rook'],positions = [[1, 1], [8, 8]]) == 223\n assert candidate(pieces = ['queen', 'rook'],positions = [[2, 2], [5, 5]]) == 340\n assert candidate(pieces = ['rook', 'queen', 'bishop'],positions = [[1, 1], [5, 5], [8, 8]]) == 2907\n assert candidate(pieces = ['rook', 'queen', 'bishop'],positions = [[1, 1], [2, 2], [3, 3]]) == 3289\n assert candidate(pieces = ['rook', 'rook'],positions = [[1, 1], [1, 3]]) == 189\n assert candidate(pieces = ['rook'],positions = [[1, 1]]) == 15\n assert candidate(pieces = ['rook', 'bishop'],positions = [[1, 1], [4, 3]]) == 173\n assert candidate(pieces = ['bishop', 'bishop'],positions = [[2, 2], [7, 7]]) == 80\n assert candidate(pieces = ['bishop', 'bishop'],positions = [[2, 2], [6, 6]]) == 84\n assert candidate(pieces = ['queen', 'bishop'],positions = [[1, 1], [4, 4]]) == 280\n assert candidate(pieces = ['bishop', 'rook', 'bishop'],positions = [[3, 4], [5, 5], [7, 6]]) == 1265\n assert candidate(pieces = ['queen'],positions = [[1, 1]]) == 22\n assert candidate(pieces = ['rook', 'bishop'],positions = [[1, 1], [4, 4]]) == 205\n assert candidate(pieces = ['rook', 'queen', 'bishop'],positions = [[1, 1], [5, 5], [4, 3]]) == 4421\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[1, 1], [2, 2], [4, 3]]) == 3161\n assert candidate(pieces = ['rook', 'bishop', 'rook', 'bishop'],positions = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 16893\n assert candidate(pieces = ['queen', 'rook'],positions = [[1, 1], [8, 8]]) == 327\n assert candidate(pieces = ['queen', 'rook', 'rook'],positions = [[1, 1], [8, 8], [1, 8]]) == 4163\n assert candidate(pieces = ['rook', 'queen', 'bishop'],positions = [[3, 3], [5, 5], [7, 2]]) == 3589\n assert candidate(pieces = ['queen', 'bishop', 'bishop'],positions = [[1, 1], [8, 8], [1, 8]]) == 1232\n assert candidate(pieces = ['queen', 'rook', 'bishop', 'rook'],positions = [[1, 1], [1, 8], [8, 1], [8, 8]]) == 32176\n assert candidate(pieces = ['queen', 'rook', 'bishop', 'rook'],positions = [[1, 1], [8, 8], [3, 3], [6, 6]]) == 44166\n assert candidate(pieces = ['queen', 'queen'],positions = [[3, 3], [6, 6]]) == 638\n assert candidate(pieces = ['rook', 'rook', 'rook', 'rook'],positions = [[1, 1], [1, 8], [8, 1], [8, 8]]) == 33009\n assert candidate(pieces = ['bishop', 'bishop', 'rook', 'rook'],positions = [[1, 1], [8, 8], [4, 4], [5, 5]]) == 7561\n assert candidate(pieces = ['queen', 'bishop', 'rook', 'bishop'],positions = [[1, 1], [8, 8], [4, 4], [4, 1]]) == 15440\n assert candidate(pieces = ['rook', 'rook', 'rook'],positions = [[1, 1], [1, 8], [8, 1]]) == 2753\n assert candidate(pieces = ['rook', 'queen', 'bishop', 'rook'],positions = [[1, 1], [8, 8], [4, 4], [2, 2]]) == 51937\n assert candidate(pieces = ['rook', 'queen', 'bishop', 'rook'],positions = [[1, 1], [5, 5], [8, 8], [8, 1]]) == 38251\n assert candidate(pieces = ['queen', 'rook', 'rook', 'bishop'],positions = [[1, 1], [1, 8], [8, 1], [8, 8]]) == 29034\n assert candidate(pieces = ['queen', 'queen', 'rook'],positions = [[3, 3], [4, 4], [2, 2]]) == 8446\n assert candidate(pieces = ['queen', 'bishop', 'rook', 'rook'],positions = [[1, 1], [8, 8], [1, 8], [8, 1]]) == 29034\n assert candidate(pieces = ['queen', 'rook'],positions = [[4, 4], [7, 7]]) == 400\n assert candidate(pieces = ['rook', 'rook', 'bishop'],positions = [[1, 1], [8, 8], [4, 4]]) == 3034\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[2, 2], [7, 7], [3, 8]]) == 2590\n assert candidate(pieces = ['rook', 'rook'],positions = [[4, 4], [5, 5]]) == 193\n assert candidate(pieces = ['rook', 'queen', 'bishop'],positions = [[1, 4], [4, 4], [7, 4]]) == 3784\n assert candidate(pieces = ['rook', 'bishop', 'queen'],positions = [[1, 1], [8, 8], [4, 4]]) == 2681\n assert candidate(pieces = ['bishop', 'bishop', 'bishop', 'bishop'],positions = [[2, 2], [2, 7], [7, 2], [7, 7]]) == 6400\n assert candidate(pieces = ['queen', 'bishop', 'rook'],positions = [[8, 1], [1, 8], [4, 4]]) == 2110\n assert candidate(pieces = ['queen', 'bishop', 'rook'],positions = [[2, 2], [3, 3], [5, 5]]) == 3484\n assert candidate(pieces = ['bishop', 'rook', 'queen', 'rook'],positions = [[3, 3], [4, 4], [5, 5], [6, 6]]) == 44433\n assert candidate(pieces = ['queen', 'bishop', 'bishop'],positions = [[1, 1], [3, 3], [6, 6]]) == 2162\n assert candidate(pieces = ['rook', 'queen', 'rook', 'bishop'],positions = [[1, 1], [5, 5], [8, 1], [1, 8]]) == 41166\n assert candidate(pieces = ['rook', 'rook', 'queen'],positions = [[1, 1], [1, 8], [8, 8]]) == 4163\n assert candidate(pieces = ['bishop', 'rook', 'queen'],positions = [[3, 3], [4, 3], [3, 4]]) == 3142\n assert candidate(pieces = ['rook', 'rook', 'bishop', 'bishop'],positions = [[1, 2], [1, 7], [2, 1], [2, 8]]) == 10952\n assert candidate(pieces = ['bishop', 'rook', 'rook', 'bishop'],positions = [[1, 2], [3, 3], [6, 7], [8, 6]]) == 10473\n assert candidate(pieces = ['rook', 'bishop', 'bishop', 'queen'],positions = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 26725\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[1, 1], [8, 8], [4, 4]]) == 4145\n assert candidate(pieces = ['bishop', 'rook', 'queen', 'rook'],positions = [[1, 8], [2, 2], [5, 5], [8, 1]]) == 42649\n assert candidate(pieces = ['queen', 'rook', 'bishop', 'rook'],positions = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 35461\n assert candidate(pieces = ['rook', 'rook', 'rook'],positions = [[1, 1], [2, 2], [3, 3]]) == 2709\n assert candidate(pieces = ['rook', 'bishop'],positions = [[2, 2], [3, 6]]) == 172\n assert candidate(pieces = ['queen', 'queen'],positions = [[1, 1], [8, 8]]) == 462\n assert candidate(pieces = ['rook', 'bishop'],positions = [[1, 1], [8, 1]]) == 118\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[1, 1], [2, 2], [3, 3]]) == 2842\n assert candidate(pieces = ['bishop', 'bishop', 'rook', 'rook'],positions = [[2, 2], [7, 7], [1, 1], [8, 8]]) == 13998\n assert candidate(pieces = ['queen', 'bishop', 'bishop', 'rook'],positions = [[4, 4], [3, 3], [6, 6], [1, 1]]) == 39585\n assert candidate(pieces = ['rook', 'rook', 'rook'],positions = [[1, 1], [8, 8], [4, 4]]) == 3079\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[1, 1], [4, 5], [8, 2]]) == 2308\n assert candidate(pieces = ['bishop', 'bishop'],positions = [[3, 3], [6, 6]]) == 124\n assert candidate(pieces = ['bishop', 'rook', 'rook'],positions = [[1, 1], [8, 1], [8, 8]]) == 1600\n assert candidate(pieces = ['rook', 'rook', 'bishop', 'queen'],positions = [[1, 1], [8, 8], [3, 3], [6, 6]]) == 56730\n assert candidate(pieces = ['rook', 'bishop', 'rook'],positions = [[2, 2], [3, 3], [4, 4]]) == 2185\n assert candidate(pieces = ['queen', 'rook', 'rook'],positions = [[1, 1], [5, 5], [5, 6]]) == 4182\n assert candidate(pieces = ['rook', 'rook', 'bishop', 'bishop'],positions = [[1, 1], [1, 8], [8, 1], [8, 8]]) == 12485\n assert candidate(pieces = ['queen', 'rook', 'rook'],positions = [[4, 4], [1, 1], [8, 8]]) == 5890\n assert candidate(pieces = ['bishop', 'bishop', 'rook'],positions = [[2, 2], [7, 7], [1, 8]]) == 1112\n assert candidate(pieces = ['bishop', 'bishop', 'rook', 'rook'],positions = [[1, 1], [1, 8], [8, 1], [8, 8]]) == 12485\n assert candidate(pieces = ['bishop', 'rook', 'rook', 'queen'],positions = [[4, 4], [1, 1], [1, 8], [8, 8]]) == 49107\n assert candidate(pieces = ['queen', 'rook', 'bishop', 'rook'],positions = [[3, 3], [5, 5], [2, 2], [6, 6]]) == 37434\n assert candidate(pieces = ['queen', 'bishop'],positions = [[2, 2], [7, 7]]) == 220\n assert candidate(pieces = ['queen', 'queen', 'queen'],positions = [[2, 2], [3, 3], [4, 4]]) == 13103\n assert candidate(pieces = ['queen', 'bishop'],positions = [[1, 1], [8, 8]]) == 156\n assert candidate(pieces = ['queen', 'queen'],positions = [[2, 2], [7, 7]]) == 548\n assert candidate(pieces = ['bishop', 'bishop', 'rook', 'rook'],positions = [[2, 2], [3, 3], [6, 6], [7, 7]]) == 18260\n assert candidate(pieces = ['rook', 'bishop', 'queen'],positions = [[3, 3], [6, 6], [5, 5]]) == 4230\n assert candidate(pieces = ['rook', 'bishop', 'rook', 'bishop'],positions = [[1, 1], [8, 8], [2, 2], [7, 7]]) == 10336\n assert candidate(pieces = ['queen', 'rook', 'rook'],positions = [[1, 1], [1, 8], [8, 1]]) == 4286\n assert candidate(pieces = ['queen', 'rook'],positions = [[4, 4], [8, 1]]) == 412\n assert candidate(pieces = ['rook', 'rook', 'queen', 'bishop'],positions = [[1, 1], [8, 8], [4, 4], [5, 5]]) == 74604\n assert candidate(pieces = ['queen', 'rook', 'rook'],positions = [[5, 5], [1, 1], [8, 8]]) == 5890\n assert candidate(pieces = ['bishop', 'bishop', 'rook'],positions = [[2, 2], [7, 7], [4, 4]]) == 1150\n assert candidate(pieces = ['queen', 'rook', 'bishop'],positions = [[4, 4], [1, 1], [8, 8]]) == 2681\n assert candidate(pieces = ['queen', 'bishop', 'rook'],positions = [[3, 3], [6, 6], [1, 1]]) == 4107\n assert candidate(pieces = ['queen', 'queen'],positions = [[1, 2], [8, 7]]) == 476\n assert candidate(pieces = ['queen', 'queen'],positions = [[2, 3], [3, 2]]) == 518\n assert candidate(pieces = ['bishop', 'bishop'],positions = [[1, 1], [8, 8]]) == 44\n assert candidate(pieces = ['bishop', 'bishop', 'bishop'],positions = [[2, 2], [5, 5], [8, 8]]) == 460\n assert candidate(pieces = ['rook', 'rook'],positions = [[1, 1], [1, 8]]) == 205\n assert candidate(pieces = ['rook', 'rook', 'bishop'],positions = [[1, 1], [8, 1], [4, 4]]) == 2764\n assert candidate(pieces = ['queen', 'queen', 'rook'],positions = [[1, 1], [8, 8], [4, 4]]) == 6380\n assert candidate(pieces = ['rook', 'queen', 'bishop', 'rook'],positions = [[1, 1], [2, 2], [3, 3], [4, 4]]) == 41894\n assert candidate(pieces = ['queen', 'rook'],positions = [[1, 1], [8, 1]]) == 309\n assert candidate(pieces = ['bishop', 'bishop', 'bishop'],positions = [[2, 3], [4, 5], [6, 7]]) == 728\n assert candidate(pieces = ['bishop', 'bishop', 'bishop'],positions = [[2, 2], [4, 4], [6, 6]]) == 792\n", "comparison": "exact"}, "public_tests": ["[\"rook\"]\n[[1,1]]", "[\"queen\"]\n[[1,1]]", "[\"bishop\"]\n[[4,3]]"], "hints": ["N is small, we can generate all possible move combinations.", "For each possible move combination, determine which ones are valid."], "metadata": {"canonical_parameter_names": ["pieces", "positions"], "leetcode_dataset_entry_point": "Solution().countCombinations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:38+00:00", "tests_total": 100, "tests_dropped": 1, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "string", "backtracking", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countCombinations($pieces, $positions) {", "container": "Solution", "callable": "countCombinations", "parameters": [{"name": "pieces", "type": "String[]"}, {"name": "positions", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2057, "task_id": "smallest-index-with-equal-value", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.\n\nx mod y denotes the remainder when x is divided by y.\n\nExample 1:\n\nInput: nums = [0,1,2]\nOutput: 0\nExplanation:\ni=0: 0 mod 10 = 0 == nums[0].\ni=1: 1 mod 10 = 1 == nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\nAll indices have i mod 10 == nums[i], so we return the smallest index 0.\n\nExample 2:\n\nInput: nums = [4,3,2,1]\nOutput: 2\nExplanation:\ni=0: 0 mod 10 = 0 != nums[0].\ni=1: 1 mod 10 = 1 != nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\ni=3: 3 mod 10 = 3 != nums[3].\n2 is the only index which has i mod 10 == nums[i].\n\nExample 3:\n\nInput: nums = [1,2,3,4,5,6,7,8,9,0]\nOutput: -1\nExplanation: No index satisfies i mod 10 == nums[i].\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 0 <= nums[i] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 5, 0, 5, 0, 5, 0, 5, 0, 5]) == 0\n assert candidate(nums = [4, 3, 2, 1]) == 2\n assert candidate(nums = [7, 8, 9, 0, 1, 2, 3, 4, 5, 6]) == -1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9]) == 9\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == -1\n assert candidate(nums = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0]) == -1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [3, 0, 1, 4, 2, 5, 9, 6, 7, 8]) == 5\n assert candidate(nums = [0, 1, 2]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == -1\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 8\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 9\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, 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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == -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\n assert candidate(nums = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5, 0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == 0\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7]) == 3\n assert candidate(nums = [0, 2, 4, 6, 8, 0, 2, 4, 6, 8]) == 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\n assert candidate(nums = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9]) == 9\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\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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]) == 1\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == -1\n assert candidate(nums = [4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5]) == 2\n assert candidate(nums = [6, 3, 8, 6, 2, 9, 1, 3, 4, 7, 6, 3, 8, 6, 2, 9, 1, 3, 4, 7]) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3]) == 1\n assert candidate(nums = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 0, 2, 4, 6, 8]) == -1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 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]) == 1\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == -1\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == -1\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3]) == -1\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 = [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]) == 4\n assert candidate(nums = [4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 1, 2, 3, 4, 5, 6]) == 1\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 8\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == -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\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 8\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\n assert candidate(nums = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 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\n assert candidate(nums = [1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 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]) == -1\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == -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\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\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\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 4\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [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 = [9, 0, 9, 0, 9, 0, 9, 0, 9, 0]) == -1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) == 8\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 = [8, 9, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == -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\n assert candidate(nums = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\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\n assert candidate(nums = [1, 0, 9, 8, 7, 6, 5, 4, 3, 2]) == -1\n assert candidate(nums = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == -1\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 8\n assert candidate(nums = [8, 6, 4, 2, 0, 9, 7, 5, 3, 1]) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == -1\n assert candidate(nums = [1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == -1\n assert candidate(nums = [6, 3, 9, 2, 4, 1, 5, 8, 0, 7, 6, 3, 9, 2, 4, 1, 5, 8, 0, 7, 6, 3, 9, 2, 4, 1, 5, 8, 0, 7, 6, 3, 9, 2, 4, 1, 5, 8, 0, 7]) == 4\n assert candidate(nums = [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, 1, 2]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == -1\n", "comparison": "exact"}, "public_tests": ["[0,1,2]", "[4,3,2,1]", "[1,2,3,4,5,6,7,8,9,0]"], "hints": ["Starting with i=0, check the condition for each index. The first one you find to be true is the smallest index."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().smallestEqual", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:40+00:00", "tests_total": 98, "tests_dropped": 12, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function smallestEqual($nums) {", "container": "Solution", "callable": "smallestEqual", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2059, "task_id": "minimum-operations-to-convert-number", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that it is converted to goal. You can perform the following operation repeatedly on the number x:\n\nIf 0 <= x <= 1000, then for any index i in the array (0 <= i < nums.length), you can set x to any of the following:\n\n- x + nums[i]\n- x - nums[i]\n- x ^ nums[i] (bitwise-XOR)\n\nNote that you can use each nums[i] any number of times in any order. Operations that set x to be out of the range 0 <= x <= 1000 are valid, but no more operations can be done afterward.\n\nReturn the minimum number of operations needed to convert x = start into goal, and -1 if it is not possible.\n\nExample 1:\n\nInput: nums = [2,4,12], start = 2, goal = 12\nOutput: 2\nExplanation: We can go from 2 → 14 → 12 with the following 2 operations.\n- 2 + 12 = 14\n- 14 - 2 = 12\n\nExample 2:\n\nInput: nums = [3,5,7], start = 0, goal = -4\nOutput: 2\nExplanation: We can go from 0 → 3 → -4 with the following 2 operations.\n- 0 + 3 = 3\n- 3 - 7 = -4\nNote that the last operation sets x out of the range 0 <= x <= 1000, which is valid.\n\nExample 3:\n\nInput: nums = [2,8,16], start = 0, goal = 1\nOutput: -1\nExplanation: There is no way to convert 0 into 1.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- -10^9 <= nums[i], goal <= 10^9\n- 0 <= start <= 1000\n- start != goal\n- All the integers in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30],start = 100,goal = 50) == 2\n assert candidate(nums = [5, 15, 25],start = 10,goal = 30) == 2\n assert candidate(nums = [10, 20, 30],start = 100,goal = 300) == 7\n assert candidate(nums = [1, 3, 5, 7, 9],start = 0,goal = 10) == 2\n assert candidate(nums = [1, 3, 5, 7, 9],start = 1000,goal = 0) == 112\n assert candidate(nums = [10, 20, 30, 40, 50],start = 100,goal = 0) == 2\n assert candidate(nums = [10, 20, 30],start = 100,goal = 200) == 4\n assert candidate(nums = [500, 501, 502],start = 500,goal = 505) == 4\n assert candidate(nums = [1000, -1000, 500],start = 0,goal = 1000) == 1\n assert candidate(nums = [7, 14, 28],start = 1,goal = 28) == 4\n assert candidate(nums = [100, 200, 300],start = 100,goal = 1000) == 3\n assert candidate(nums = [100, 200, 300],start = 500,goal = 1000) == 2\n assert candidate(nums = [1],start = 0,goal = 1000) == 1000\n assert candidate(nums = [7, 14, 21],start = 7,goal = 0) == 1\n assert candidate(nums = [1000],start = 1000,goal = 0) == 1\n assert candidate(nums = [2, 4, 12],start = 2,goal = 12) == 2\n assert candidate(nums = [1, 1000],start = 0,goal = 1001) == 2\n assert candidate(nums = [-1, -2, -3],start = 5,goal = -5) == 1\n assert candidate(nums = [100, 200, 300],start = 500,goal = 100) == 2\n assert candidate(nums = [1, 1000],start = 500,goal = 1500) == 1\n assert candidate(nums = [3, 5, 7],start = 0,goal = -4) == 2\n assert candidate(nums = [1, 2, 3],start = 1000,goal = 0) == 334\n assert candidate(nums = [10, 20, 30],start = 50,goal = 110) == 2\n assert candidate(nums = [2, 8, 16],start = 0,goal = 1) == -1\n assert candidate(nums = [1000, 500, 250],start = 1,goal = 1000) == -1\n assert candidate(nums = [1, 2, 3, 4, 5],start = 1,goal = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],start = 5,goal = 0) == 1\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],start = 50,goal = 1000) == 10\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987],start = 1,goal = 1000) == 3\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],start = 1000,goal = 0) == 22\n assert candidate(nums = [128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],start = 500,goal = 1000) == -1\n assert candidate(nums = [256, 512, 768, 1024],start = 0,goal = 1024) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],start = 500,goal = 1) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 10,goal = 1000) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],start = 1000,goal = 0) == 20\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],start = 500,goal = 1000) == 6\n assert candidate(nums = [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],start = 0,goal = 999) == 9\n assert candidate(nums = [13, 21, 34, 55, 89, 144, 233, 377, 610, 987],start = 500,goal = 1000) == 3\n assert candidate(nums = [256, 128, 64, 32, 16, 8, 4, 2, 1],start = 500,goal = 999) == 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],start = 1000,goal = 0) == 18\n assert candidate(nums = [999, 1, 2, 3, 4, 5],start = 0,goal = 999) == 1\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],start = 512,goal = 0) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],start = 5,goal = 100) == 10\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],start = 50,goal = 999) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],start = 1,goal = 98) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],start = 100,goal = 1000) == 48\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],start = 500,goal = 1000) == 17\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 100,goal = 256) == 3\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],start = 25,goal = 1000) == 20\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],start = 1,goal = 999) == 36\n assert candidate(nums = [10, 20, 30, 40, 50],start = 500,goal = -100) == -1\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29],start = 1,goal = 999) == 36\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],start = 50,goal = 999) == 21\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 500,goal = 0) == 5\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],start = 1,goal = 1000) == 33\n assert candidate(nums = [13, 19, 23, 29, 31, 37, 41, 43, 47, 53],start = 200,goal = 300) == 2\n assert candidate(nums = [1, 10, 100, 1000],start = 1,goal = 1000) == 2\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],start = 500,goal = 0) == 3\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],start = 100,goal = 1000) == 10\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41],start = 100,goal = 999) == 23\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],start = 10,goal = 1000) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 1,goal = 1000) == 5\n assert candidate(nums = [1, 100, 200, 300, 400, 500, 600, 700, 800, 900],start = 0,goal = 1000) == 2\n assert candidate(nums = [333, 667, 999],start = 1,goal = 999) == 2\n assert candidate(nums = [999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008],start = 1,goal = 1000) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 0,goal = 1000) == 4\n assert candidate(nums = [64, 128, 256, 512],start = 100,goal = 1024) == -1\n assert candidate(nums = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144],start = 10,goal = 200) == 3\n assert candidate(nums = [123, 456, 789],start = 321,goal = 654) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 1000,goal = 0) == 4\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],start = 50,goal = 1000) == 4\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987],start = 100,goal = 0) == 3\n assert candidate(nums = [999, 1000, 1001, 1002, 1003],start = 500,goal = 1500) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],start = 100,goal = 200) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 0,goal = 500) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],start = 500,goal = 1000) == 1\n assert candidate(nums = [100, 200, 300, 400, 500],start = 10,goal = 999) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],start = 100,goal = 999) == 31\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],start = 100,goal = 1000) == 9\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1000],start = 500,goal = 1500) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],start = 100,goal = 2048) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 100,goal = 511) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 50,goal = 1000) == 10\n assert candidate(nums = [123, 456, 789],start = 100,goal = 900) == 6\n assert candidate(nums = [29, 31, 37, 41, 43, 47, 53, 59, 61, 67],start = 5,goal = 1000) == 15\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],start = 50,goal = 500) == 6\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],start = 1,goal = 1000000000) == 2\n assert candidate(nums = [333, 667, 999],start = 500,goal = 1000) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],start = 500,goal = 400) == 6\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99],start = 500,goal = 200) == 4\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],start = 200,goal = 500) == 8\n assert candidate(nums = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26],start = 500,goal = 550) == 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],start = 1,goal = 1000) == 11\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 50,goal = 990) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],start = 100,goal = -100) == -1\n assert candidate(nums = [13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],start = 500,goal = 999) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],start = 0,goal = 500) == 10\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],start = 100,goal = 1000) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],start = 50,goal = 999) == 11\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 500,goal = 1024) == 3\n assert candidate(nums = [100, 200, 300, 400, 500],start = 999,goal = 1) == -1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],start = 512,goal = 1000) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],start = 50,goal = 150) == 1\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987],start = 50,goal = 987) == 3\n assert candidate(nums = [23, 45, 67, 89, 101],start = 100,goal = 1) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],start = 500,goal = 1024) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],start = 1,goal = 999) == 54\n assert candidate(nums = [100, 200, 300, 400, 500],start = 100,goal = 500) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],start = 500,goal = 1005) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],start = 1,goal = 1001) == 100\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],start = 1,goal = 999) == 1\n assert candidate(nums = [100, 200, 300, 400, 500],start = 50,goal = 500) == -1\n assert candidate(nums = [-1, 1, -2, 2, -4, 4, -8, 8, -16, 16],start = 500,goal = 1) == 33\n assert candidate(nums = [666, 333, 111, 777, 888, 999, 222, 444, 555],start = 111,goal = 777) == 1\n assert candidate(nums = [-100, -50, -25, 0, 25, 50, 100],start = 50,goal = 250) == 2\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],start = 1,goal = 1000) == 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],start = 1000,goal = 1) == 50\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],start = 10,goal = 99) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],start = 500,goal = 999) == 4\n", "comparison": "exact"}, "public_tests": ["[2,4,12]\n2\n12", "[3,5,7]\n0\n-4", "[2,8,16]\n0\n1"], "hints": ["Once x drops below 0 or goes above 1000, is it possible to continue performing operations on x?", "How can you use BFS to find the minimum operations?"], "metadata": {"canonical_parameter_names": ["nums", "start", "goal"], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:44+00:00", "tests_total": 134, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "breadth-first-search"]}, "language": "php", "interface": {"raw_signature": "function minimumOperations($nums, $start, $goal) {", "container": "Solution", "callable": "minimumOperations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "start", "type": "Integer"}, {"name": "goal", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2060, "task_id": "check-if-an-original-string-exists-given-two-encoded-strings", "difficulty": "Hard", "problem_description": "An original string, consisting of lowercase English letters, can be encoded by the following steps:\n\n- Arbitrarily split it into a sequence of some number of non-empty substrings.\n- Arbitrarily choose some elements (possibly none) of the sequence, and replace each with its length (as a numeric string).\n- Concatenate the sequence as the encoded string.\n\nFor example, one way to encode an original string \"abcdefghijklmnop\" might be:\n\n- Split it as a sequence: [\"ab\", \"cdefghijklmn\", \"o\", \"p\"].\n- Choose the second and third elements to be replaced by their lengths, respectively. The sequence becomes [\"ab\", \"12\", \"1\", \"p\"].\n- Concatenate the elements of the sequence to get the encoded string: \"ab121p\".\n\nGiven two encoded strings s1 and s2, consisting of lowercase English letters and digits 1-9 (inclusive), return true if there exists an original string that could be encoded as both s1 and s2. Otherwise, return false.\n\nNote: The test cases are generated such that the number of consecutive digits in s1 and s2 does not exceed 3.\n\nExample 1:\n\nInput: s1 = \"internationalization\", s2 = \"i18n\"\nOutput: true\nExplanation: It is possible that \"internationalization\" was the original string.\n- \"internationalization\"\n -> Split: [\"internationalization\"]\n -> Do not replace any element\n -> Concatenate: \"internationalization\", which is s1.\n- \"internationalization\"\n -> Split: [\"i\", \"nternationalizatio\", \"n\"]\n -> Replace: [\"i\", \"18\", \"n\"]\n -> Concatenate: \"i18n\", which is s2\n\nExample 2:\n\nInput: s1 = \"l123e\", s2 = \"44\"\nOutput: true\nExplanation: It is possible that \"leetcode\" was the original string.\n- \"leetcode\"\n -> Split: [\"l\", \"e\", \"et\", \"cod\", \"e\"]\n -> Replace: [\"l\", \"1\", \"2\", \"3\", \"e\"]\n -> Concatenate: \"l123e\", which is s1.\n- \"leetcode\"\n -> Split: [\"leet\", \"code\"]\n -> Replace: [\"4\", \"4\"]\n -> Concatenate: \"44\", which is s2.\n\nExample 3:\n\nInput: s1 = \"a5b\", s2 = \"c5b\"\nOutput: false\nExplanation: It is impossible.\n- The original string encoded as s1 must start with the letter 'a'.\n- The original string encoded as s2 must start with the letter 'c'.\n\nConstraints:\n\n- 1 <= s1.length, s2.length <= 40\n- s1 and s2 consist of digits 1-9 (inclusive), and lowercase English letters only.\n- The number of consecutive digits in s1 and s2 does not exceed 3.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s1 = \"a1b\",s2 = \"a1b1\") == False\n assert candidate(s1 = \"ab123cd\",s2 = \"a3bcd\") == False\n assert candidate(s1 = \"ab123cd\",s2 = \"abc5\") == False\n assert candidate(s1 = \"123\",s2 = \"onetwothree\") == False\n assert candidate(s1 = \"1a\",s2 = \"a\") == False\n assert candidate(s1 = \"a9b\",s2 = \"a10b\") == False\n assert candidate(s1 = \"a1b1c1d1\",s2 = \"abcd\") == False\n assert candidate(s1 = \"a1a1a1\",s2 = \"a3a3\") == False\n assert candidate(s1 = \"a1b1\",s2 = \"ab\") == False\n assert candidate(s1 = \"a5b\",s2 = \"c5b\") == False\n assert candidate(s1 = \"abc\",s2 = \"3\") == True\n assert candidate(s1 = \"h3ll0\",s2 = \"hello\") == False\n assert candidate(s1 = \"123\",s2 = \"3\") == False\n assert candidate(s1 = \"a1b2c3\",s2 = \"a1b23c\") == True\n assert candidate(s1 = \"internationalization\",s2 = \"i18n\") == True\n assert candidate(s1 = \"a1b\",s2 = \"ab\") == False\n assert candidate(s1 = \"a1b2c3\",s2 = \"a1b5\") == False\n assert candidate(s1 = \"z1x2c3v\",s2 = \"zx9\") == False\n assert candidate(s1 = \"a1b2c3d4\",s2 = \"a1b2c34d\") == True\n assert candidate(s1 = \"1a1b1c\",s2 = \"3abc\") == False\n assert candidate(s1 = \"a\",s2 = \"1\") == True\n assert candidate(s1 = \"ab1\",s2 = \"a1b\") == True\n assert candidate(s1 = \"123\",s2 = \"321\") == True\n assert candidate(s1 = \"ab\",s2 = \"a2\") == False\n assert candidate(s1 = \"a2b\",s2 = \"aaab\") == True\n assert candidate(s1 = \"a1b1\",s2 = \"2\") == False\n assert candidate(s1 = \"a1b2c3\",s2 = \"abc6\") == False\n assert candidate(s1 = \"abc\",s2 = \"abc\") == True\n assert candidate(s1 = \"hello\",s2 = \"5\") == True\n assert candidate(s1 = \"l123e\",s2 = \"44\") == True\n assert candidate(s1 = \"123abc\",s2 = \"3abc\") == False\n assert candidate(s1 = \"a5b5c5\",s2 = \"abc15\") == True\n assert candidate(s1 = \"a2b2c2\",s2 = \"aabbcc\") == False\n assert candidate(s1 = \"abc12def45\",s2 = \"abcdef123\") == False\n assert candidate(s1 = \"1a2b3c4d5e6f7g8h9i\",s2 = \"abcdefghi\") == False\n assert candidate(s1 = \"x9y8z7\",s2 = \"xyz321\") == True\n assert candidate(s1 = \"a1b2c3\",s2 = \"abc123\") == False\n assert candidate(s1 = \"123abc456\",s2 = \"9abc10\") == False\n assert candidate(s1 = \"123456\",s2 = \"654321\") == True\n assert candidate(s1 = \"abcdefghij123456789012\",s2 = \"abcdefghij123456789012\") == True\n assert candidate(s1 = \"1a2b3c4d\",s2 = \"aabbcccdddd\") == False\n assert candidate(s1 = \"abc12def45\",s2 = \"abcdef19\") == False\n assert candidate(s1 = \"abc1def2ghi3\",s2 = \"a1b1c1d1e1f1g1h1i1\") == False\n assert candidate(s1 = \"a1b1c1\",s2 = \"abc1\") == False\n assert candidate(s1 = \"1a2b3c4d\",s2 = \"1234abcd\") == True\n assert candidate(s1 = \"11a2b\",s2 = \"aaaaaaaaaab\") == False\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j0\",s2 = \"abcdefghij10\") == False\n assert candidate(s1 = \"abcdefghij123456789\",s2 = \"abcdefghij1234567891\") == False\n assert candidate(s1 = \"a5b5c5d5e5\",s2 = \"abcde25\") == True\n assert candidate(s1 = \"a2b3c4d5e6f7g8h9i10\",s2 = \"abcdefghi10\") == False\n assert candidate(s1 = \"abcdefghij1234567890\",s2 = \"abcdefghij123456789\") == True\n assert candidate(s1 = \"abc123def\",s2 = \"abc12def3\") == True\n assert candidate(s1 = \"a12b34c56\",s2 = \"a12b34c56\") == True\n assert candidate(s1 = \"l10n\",s2 = \"leetcode\") == False\n assert candidate(s1 = \"1a2b3c4d5e\",s2 = \"a1b2c3d4e5\") == True\n assert candidate(s1 = \"123abc\",s2 = \"321cba\") == False\n assert candidate(s1 = \"1a2b3c4d5e6f7g8h9i10j\",s2 = \"abcdefghij1\") == False\n assert candidate(s1 = \"a4b2c3\",s2 = \"aaaaabbbccc\") == False\n assert candidate(s1 = \"a3b\",s2 = \"aaab\") == False\n assert candidate(s1 = \"a2b3c4\",s2 = \"aaabbbcccc\") == False\n assert candidate(s1 = \"a2b3c\",s2 = \"aabbccc\") == False\n assert candidate(s1 = \"abc123def456ghi789\",s2 = \"abcdef789ghi123456\") == True\n assert candidate(s1 = \"a2b3c4\",s2 = \"a9\") == False\n assert candidate(s1 = \"abc123def\",s2 = \"abcdef123\") == True\n assert candidate(s1 = \"123abc\",s2 = \"12abc3\") == True\n assert candidate(s1 = \"111abc222def333\",s2 = \"333abc222def111\") == True\n assert candidate(s1 = \"abcdefghij1234567891\",s2 = \"abcdefghij123456789\") == False\n assert candidate(s1 = \"12abc\",s2 = \"a1b2c\") == True\n assert candidate(s1 = \"x1y2z3\",s2 = \"xyz123\") == False\n assert candidate(s1 = \"11abc\",s2 = \"abcdefghij1\") == False\n assert candidate(s1 = \"a5b5c5\",s2 = \"aaaaabbbbbccccc\") == False\n assert candidate(s1 = \"a5b3c2d\",s2 = \"abc10d\") == True\n assert candidate(s1 = \"9z\",s2 = \"zzzzzzzzz\") == False\n assert candidate(s1 = \"a1b2c3d4e5\",s2 = \"a1b2c3d4e5\") == True\n assert candidate(s1 = \"a1b1c1\",s2 = \"a1b1c1d0\") == False\n assert candidate(s1 = \"a12b\",s2 = \"aaaaaaaaaaaaab\") == True\n assert candidate(s1 = \"abcde123fghi\",s2 = \"abcdefghi123\") == True\n assert candidate(s1 = \"abc123def456\",s2 = \"abcdef123456\") == True\n assert candidate(s1 = \"123abc123\",s2 = \"321cba321\") == True\n assert candidate(s1 = \"abcdefghij1234567891\",s2 = \"abcdefghij1234567891\") == True\n assert candidate(s1 = \"a2b3c4\",s2 = \"ab2c3d4\") == False\n assert candidate(s1 = \"123abc\",s2 = \"15c\") == False\n assert candidate(s1 = \"abc12def\",s2 = \"a15f\") == False\n assert candidate(s1 = \"l123e\",s2 = \"leetcode\") == True\n assert candidate(s1 = \"abc12def\",s2 = \"abcdefghijkl\") == False\n assert candidate(s1 = \"1234\",s2 = \"1234\") == True\n assert candidate(s1 = \"abc12\",s2 = \"ab11c\") == False\n assert candidate(s1 = \"1a2b3c4d5e6f7g8h9i10j\",s2 = \"abcdefghij10\") == False\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j10\",s2 = \"abcdefghij10\") == False\n assert candidate(s1 = \"12ab3c\",s2 = \"a1b2c3\") == True\n assert candidate(s1 = \"abc1def2ghi3jkl4mno5pqr6stu7vwx8yz9\",s2 = \"a1b2c3d4e5f6g7h8i9jklmnopqrstuvwxyz\") == False\n assert candidate(s1 = \"a1b2c3d4\",s2 = \"a111b1111c11111d111111\") == False\n assert candidate(s1 = \"a9b8c7d6e5f4g3h2i1\",s2 = \"abcdefghi123456789\") == True\n assert candidate(s1 = \"abcdefghij123456789\",s2 = \"abcdefghij1234567890\") == True\n assert candidate(s1 = \"a1b1c1d1e1f1g1h1i1j1\",s2 = \"abcdefghij\") == False\n assert candidate(s1 = \"abcde1234567890\",s2 = \"0987654321edcba\") == True\n assert candidate(s1 = \"1a1b1c\",s2 = \"abc1\") == False\n assert candidate(s1 = \"abcd1234\",s2 = \"a3b2cd4\") == False\n assert candidate(s1 = \"ab1cd2ef3\",s2 = \"a1b1c1d1e1f1\") == False\n assert candidate(s1 = \"l10n\",s2 = \"leet1c2d\") == False\n assert candidate(s1 = \"1a2b3c4d5e\",s2 = \"11111\") == False\n assert candidate(s1 = \"123456789\",s2 = \"abcdefghi9\") == False\n assert candidate(s1 = \"1a2b3c4d5e6f7g8h9i10\",s2 = \"abcdefghij10\") == False\n assert candidate(s1 = \"a9b\",s2 = \"aaaaaaaaaab\") == True\n assert candidate(s1 = \"l10e\",s2 = \"leetcode\") == False\n assert candidate(s1 = \"12ab34cd56\",s2 = \"15abcd\") == False\n assert candidate(s1 = \"123abc\",s2 = \"abc123\") == True\n assert candidate(s1 = \"abcdefghij12345678901234\",s2 = \"abcdefghij12345678901234\") == True\n assert candidate(s1 = \"leetcode\",s2 = \"l2e8\") == False\n assert candidate(s1 = \"a1b2c3\",s2 = \"a12b3c\") == True\n assert candidate(s1 = \"1a2b3c\",s2 = \"6\") == False\n assert candidate(s1 = \"1a2b3c4d5e6f7g8h9i10j11k12\",s2 = \"abcdefghijk11lm12\") == False\n assert candidate(s1 = \"123abc456def789ghi101112\",s2 = \"123abc456def789ghi101112\") == True\n assert candidate(s1 = \"123abc456\",s2 = \"9abc101\") == False\n assert candidate(s1 = \"1a2a3a4a5a6a7a8a9a\",s2 = \"aaaaaaaaaab\") == False\n assert candidate(s1 = \"abcdefghij123456789\",s2 = \"abcdefghij123456789\") == True\n assert candidate(s1 = \"a1b2c3d4\",s2 = \"abcd\") == False\n assert candidate(s1 = \"a9b9c\",s2 = \"abcdefghiabcdefghi\") == False\n assert candidate(s1 = \"abc123\",s2 = \"a1b1c123\") == False\n assert candidate(s1 = \"abcdefghij123456789\",s2 = \"abcdefghij12345678\") == True\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9\",s2 = \"abcdefghi\") == False\n assert candidate(s1 = \"abc11\",s2 = \"abcdefghij1\") == False\n assert candidate(s1 = \"abcdefghij1234567890123\",s2 = \"abcdefghij1234567890123\") == True\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0\",s2 = \"abcdefghijklmnopqrst1020\") == False\n assert candidate(s1 = \"a1b1c1d1e1f1g1h1i1\",s2 = \"abcdefghi1\") == False\n assert candidate(s1 = \"a5b2c3\",s2 = \"aaaaaaaaabbccc\") == False\n assert candidate(s1 = \"a5b5c5d5\",s2 = \"10abcde5\") == False\n assert candidate(s1 = \"abcde123\",s2 = \"a4bcd3\") == True\n assert candidate(s1 = \"abc123\",s2 = \"123abc\") == True\n assert candidate(s1 = \"a12b3c4\",s2 = \"a1b22c4\") == False\n assert candidate(s1 = \"1a2b3c\",s2 = \"a1b2c3\") == True\n assert candidate(s1 = \"abc123def\",s2 = \"a1b1c3d4e5f6\") == False\n assert candidate(s1 = \"9a9b9c9d\",s2 = \"81abcd\") == False\n assert candidate(s1 = \"x9y9z9\",s2 = \"xxxxxxxxxxxyyyyyyyyzzzzzzzzz\") == False\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j10k11l12m13n14o15\",s2 = \"abcdefghijklmnop123456789101112131415\") == False\n assert candidate(s1 = \"abc1def2ghi3\",s2 = \"abcdefghi\") == False\n assert candidate(s1 = \"a9b9c9\",s2 = \"aaaaaaaaabbbbbbbbcccccccccc\") == False\n assert candidate(s1 = \"abc123\",s2 = \"a1b2c3123\") == False\n assert candidate(s1 = \"a1b1c\",s2 = \"abc\") == False\n assert candidate(s1 = \"a1b2c3d4\",s2 = \"abcd10\") == False\n assert candidate(s1 = \"a2b3c4d5e6f7g8h9i10j11\",s2 = \"abcdefghij10jk11\") == False\n assert candidate(s1 = \"abcdefghij12345678901\",s2 = \"abcdefghij12345678901\") == True\n assert candidate(s1 = \"a1b2c3d4e5\",s2 = \"15\") == False\n assert candidate(s1 = \"1a2b3c\",s2 = \"abc123\") == False\n assert candidate(s1 = \"ab3c\",s2 = \"abc3\") == True\n assert candidate(s1 = \"abcde12345\",s2 = \"abcde54321\") == True\n assert candidate(s1 = \"abc1def2ghi3\",s2 = \"abcdefg1h1i\") == False\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j10k11\",s2 = \"abcdefghijk11\") == False\n assert candidate(s1 = \"a1b2c3d4e5f6g7h8i9j10k11\",s2 = \"abcdefghijk123\") == False\n assert candidate(s1 = \"abcdefghij1234567890\",s2 = \"abcdefghij1234567890\") == True\n assert candidate(s1 = \"a10b\",s2 = \"aaaaaaaaaab\") == False\n", "comparison": "exact"}, "public_tests": ["\"internationalization\"\n\"i18n\"", "\"l123e\"\n\"44\"", "\"a5b\"\n\"c5b\""], "hints": ["For s1 and s2, divide each into a sequence of single alphabet strings and digital strings. The problem now becomes comparing if two sequences are equal.", "A single alphabet string has no variation, but a digital string has variations. For example: \"124\" can be interpreted as 1+2+4, 12+4, 1+24, and 124 wildcard characters.", "There are four kinds of comparisons: a single alphabet vs another; a single alphabet vs a number, a number vs a single alphabet, and a number vs another number. In the case of a number vs another (a single alphabet or a number), can you decrease the number by the min length of both?", "There is a recurrence relation in the search which ends when either a single alphabet != another, or one sequence ran out, or both sequences ran out."], "metadata": {"canonical_parameter_names": ["s1", "s2"], "leetcode_dataset_entry_point": "Solution().possiblyEquals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:47+00:00", "tests_total": 195, "tests_dropped": 44, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function possiblyEquals($s1, $s2) {", "container": "Solution", "callable": "possiblyEquals", "parameters": [{"name": "s1", "type": "String"}, {"name": "s2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2062, "task_id": "count-vowel-substrings-of-a-string", "difficulty": "Easy", "problem_description": "A substring is a contiguous (non-empty) sequence of characters within a string.\n\nA vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it.\n\nGiven a string word, return the number of vowel substrings in word.\n\nExample 1:\n\nInput: word = \"aeiouu\"\nOutput: 2\nExplanation: The vowel substrings of word are as follows (underlined):\n- \"aeiouu\"\n- \"aeiouu\"\n\nExample 2:\n\nInput: word = \"unicornarihan\"\nOutput: 0\nExplanation: Not all 5 vowels are present, so there are no vowel substrings.\n\nExample 3:\n\nInput: word = \"cuaieuouac\"\nOutput: 7\nExplanation: The vowel substrings of word are as follows (underlined):\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n\nConstraints:\n\n- 1 <= word.length <= 100\n- word consists of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aeiou\") == 1\n assert candidate(word = \"aeiofvuaeiou\") == 3\n assert candidate(word = \"uoiea\") == 1\n assert candidate(word = \"aeiouxaeeiaouoieua\") == 28\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\") == 175\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuoo\") == 55\n assert candidate(word = \"aeiouaeiouaeiou\") == 66\n assert candidate(word = \"unicornarihan\") == 0\n assert candidate(word = \"aaaaaeeeeeeiiiiioooooouuuuu\") == 25\n assert candidate(word = \"aeiouu\") == 2\n assert candidate(word = \"a\") == 0\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"vowelsaeiou\") == 1\n assert candidate(word = \"cuaieuouac\") == 7\n assert candidate(word = \"aeiooauuieoiau\") == 41\n assert candidate(word = \"bcdfeioau\") == 1\n assert candidate(word = \"zzzzzaeiouzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiou\") == 43\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 496\n assert candidate(word = \"aeiouxyzaeiouaeiou\") == 22\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 1326\n assert candidate(word = \"aeiouxyzaeiou\") == 2\n assert candidate(word = \"xyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyz\") == 63\n assert candidate(word = \"aeiouuuueeiooiaaaeeoioioiaaaeeuuuiooiiuaeiouaeiouaeiouaeiouaeiou\") == 1565\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiou\") == 231\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiouaeiou\") == 63\n assert candidate(word = \"uoieaueoiaueoiaueoiaueoi\") == 208\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 666\n assert candidate(word = \"aeioubcdfghjklmnpqrstvwxyzaeiou\") == 2\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyz\") == 63\n assert candidate(word = \"aeioubaeioucaeioudeaeioufaeioubaeioucaeioudeaeioufaeioubaeioucaeioudeaeiouf\") == 15\n assert candidate(word = \"bcdaeioufghijklmnopqrstuvwxyz\") == 1\n assert candidate(word = \"aeiouwxyzaeiouwxyzaeiouwxyzaeiouwxyz\") == 4\n assert candidate(word = \"xayaioeoiuaueoieoiauiouio\") == 139\n assert candidate(word = \"aeioubaeiouaeioubaeiouxyzaeiouaeiouaeioubaeiou\") == 90\n assert candidate(word = \"aeioubaeioucaeiou\") == 3\n assert candidate(word = \"bcaeiouaeiouaieouacb\") == 77\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyz\") == 42\n assert candidate(word = \"aieouaeiouaieouaeiouaieouaeiouaieou\") == 490\n assert candidate(word = \"aeiouuueeiooiaaaeeoioioiaaaeeuuuiooiiu\") == 348\n assert candidate(word = \"aeioubaeiouaeioucaeiou\") == 23\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouzzzzzzzzz\") == 231\n assert candidate(word = \"aeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiouxyz\") == 8\n assert candidate(word = \"aeiouxyzzyxwvutsrqponmlkjihgfedcbaeiouaeiou\") == 22\n assert candidate(word = \"aeiouxyaeiouaeiou\") == 22\n assert candidate(word = \"aeeeeiiiioouuuaeiouaaaeioueee\") == 247\n assert candidate(word = \"aeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiouxyz\") == 5\n assert candidate(word = \"aeioucaeioubaeiouaeiou\") == 23\n assert candidate(word = \"aeiouxyzaeiouxyzaeiouxyzaeiouxyzaeiou\") == 5\n assert candidate(word = \"xyzaeiouaeiouxyzaeiouaeiouxyz\") == 42\n assert candidate(word = \"mnopqrstuvwxyaeiouaeiouxyzaeiouxyzzyxwvutsrqponmlkjihgfedcbaeiou\") == 23\n assert candidate(word = \"bcaeiouc\") == 1\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 4656\n assert candidate(word = \"aeioueoiuaeiouaeioua\") == 125\n assert candidate(word = \"aabbccddeeeffgghhiijjkkllmmnnooouuupppqqrrsstttuuuvvvwwxxyyzz\") == 0\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 1081\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyz\") == 105\n assert candidate(word = \"aeiouaeiouxxxaeiouaeiou\") == 42\n assert candidate(word = \"aebcioudfeiauoceioua\") == 2\n assert candidate(word = \"aouieaeioueaouieaeiou\") == 139\n assert candidate(word = \"aeiouaeiouabcdeiouaeiouabcdeiouaeiou\") == 64\n assert candidate(word = \"zzzzzvvvvvaeeeiioouuuaeiou\") == 44\n assert candidate(word = \"uoieaueoiaueoiaueoiaueoiaeiou\") == 317\n assert candidate(word = \"bcdfeaioueaiouaeioueaioueaiou\") == 229\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 1596\n assert candidate(word = \"ueaiaoueoiuaeiouaeiouaeiou\") == 245\n assert candidate(word = \"aeiaeiouoieiouaeiou\") == 93\n assert candidate(word = \"uoieaueoiaueoiaueoiaueoiaeiouaeiouaeiouaeiouaeiou\") == 1027\n assert candidate(word = \"aeiooouiaeiouaeiou\") == 92\n assert candidate(word = \"aeioubaeiouaeioubaeiouxyzaeiouaeiouaeioubaeiouxyzaeiouaeioubaeiou\") == 112\n assert candidate(word = \"aabbccddeeffggahhiiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(word = \"xyzaeiouaeiouxyz\") == 21\n assert candidate(word = \"aeioueoiuaeiouaeioueoiuaeiouaeioueoiu\") == 529\n assert candidate(word = \"zzzzzaeiouzzzzzzzzzz\") == 1\n assert candidate(word = \"zbcdefghijklmnopqrstuvwxyaeiou\") == 1\n assert candidate(word = \"bcdfgohueaioeuncdfeoiu\") == 5\n assert candidate(word = \"aeioubaeioucaeioudaeioubaeioucaeioudaeioubaeioucaeiou\") == 9\n assert candidate(word = \"xaaaeeeiiiiooooouuuuuaaaeiiiou\") == 131\n assert candidate(word = \"eiaouoieaueioaeioaeiaoueioea\") == 253\n assert candidate(word = \"aeiouaeiouaeiouxyzaeiouaeiouaeiouxyzaeiouaeiou\") == 153\n assert candidate(word = \"aeiouxyzaeiouxyzaeiouxyz\") == 3\n assert candidate(word = \"mnopqrstuvwxyaeiouaeiouxyz\") == 21\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyz\") == 84\n assert candidate(word = \"xyzaeiouaeiouaeiouaeiouaeiouaeiouxyz\") == 351\n assert candidate(word = \"baeiouaeiouaeiouaeiouaeiou\") == 231\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(word = \"aeioubaeioucaeioudeaeiouf\") == 5\n assert candidate(word = \"oiueaeiouaeiouaeiouaeiouaeiouaeiou\") == 461\n assert candidate(word = \"aeioubaeiouaeiouaeiouaeiou\") == 137\n assert candidate(word = \"zzzzzaeiouzzzzz\") == 1\n assert candidate(word = \"baeioucaeiouaeioucb\") == 22\n assert candidate(word = \"eiouaeioua\") == 21\n assert candidate(word = \"aeioubaeiouaeioubaeiou\") == 23\n assert candidate(word = \"xyzabcdeioufghijklmnopqrstuvwaeiou\") == 1\n assert candidate(word = \"aeiouaeeeeeiioouuuuuaeiou\") == 146\n assert candidate(word = \"abcdeioua\") == 1\n assert candidate(word = \"aeioubaeioucaeioudeaeioufaeioubaeioucaeioudeaeiouf\") == 10\n assert candidate(word = \"aeioueaioueaioueaioueaioueaiou\") == 350\n assert candidate(word = \"aeioubaeiouaeioubaeiouaeiou\") == 43\n assert candidate(word = \"aeiouaeiouaebcdeaeiouaeiou\") == 63\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiou\") == 351\n assert candidate(word = \"aeiouaeiouaeiouaeiou\") == 136\n assert candidate(word = \"xyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiou\") == 84\n assert candidate(word = \"aeiouzyxwvutsrqponmlkjihgfedcbaeiou\") == 2\n assert candidate(word = \"aeiouzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(word = \"aeiouxyzzyxwvutsrqponmlkjihgfedcbaeiouaeiouaeiouxyzaeiouxyzzyxwvutsrqponmlkjihgfedcbaeiou\") == 69\n assert candidate(word = \"eiouaeiouaeiouaeiouaeiouaeiou\") == 325\n assert candidate(word = \"aeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyzaeiouaeiouxyz\") == 147\n assert candidate(word = \"xzaeiouaeiouaeiouaeiouaeioux\") == 231\n", "comparison": "exact"}, "public_tests": ["\"aeiouu\"", "\"unicornarihan\"", "\"cuaieuouac\""], "hints": ["While generating substrings starting at any index, do you need to continue generating larger substrings if you encounter a consonant?", "Can you store the count of characters to avoid generating substrings altogether?"], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().countVowelSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:51+00:00", "tests_total": 110, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function countVowelSubstrings($word) {", "container": "Solution", "callable": "countVowelSubstrings", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2063, "task_id": "vowels-of-all-substrings", "difficulty": "Medium", "problem_description": "Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.\n\nA substring is a contiguous (non-empty) sequence of characters within a string.\n\nNote: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.\n\nExample 1:\n\nInput: word = \"aba\"\nOutput: 6\nExplanation:\nAll possible substrings are: \"a\", \"ab\", \"aba\", \"b\", \"ba\", and \"a\".\n- \"b\" has 0 vowels in it\n- \"a\", \"ab\", \"ba\", and \"a\" have 1 vowel each\n- \"aba\" has 2 vowels in it\nHence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6.\n\nExample 2:\n\nInput: word = \"abc\"\nOutput: 3\nExplanation:\nAll possible substrings are: \"a\", \"ab\", \"abc\", \"b\", \"bc\", and \"c\".\n- \"a\", \"ab\", and \"abc\" have 1 vowel each\n- \"b\", \"bc\", and \"c\" have 0 vowels each\nHence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.\n\nExample 3:\n\nInput: word = \"ltcd\"\nOutput: 0\nExplanation: There are no vowels in any substring of \"ltcd\".\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 = \"e\") == 1\n assert candidate(word = \"aeiou\") == 35\n assert candidate(word = \"abc\") == 3\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiuiauuuuaeioaaaaeaiaioieoieiieoioioieouieiiaiaeiieoieouuiooaoaaiiaeiieeiooieiei\") == 209934\n assert candidate(word = \"bcbcbcbcbc\") == 0\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\") == 4960\n assert candidate(word = \"aeiaaioaaaaeiiiiouuuooaauuaeiuiaoiuuaeiuuaieiiaaaeeiuuoiuuuuuuu\") == 43680\n assert candidate(word = \"ltcd\") == 0\n assert candidate(word = \"aba\") == 6\n assert candidate(word = \"u\") == 1\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyz\") == 604\n assert candidate(word = \"a\") == 1\n assert candidate(word = \"o\") == 1\n assert candidate(word = \"b\") == 0\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(word = \"i\") == 1\n assert candidate(word = \"bbaaeekkeeaabbaaeekkeeaabbaaeekkeeaabb\") == 6576\n assert candidate(word = \"uvijqet\") == 34\n assert candidate(word = \"aieouaeiouaeiouaeiouaeiouaeiouaeiouaeiouaeiou\") == 16215\n assert candidate(word = \"uuygqijetbvrcw\") == 150\n assert candidate(word = \"mississippi\") == 98\n assert candidate(word = \"vowels\") == 22\n assert candidate(word = \"aeiouaeiouaeiou\") == 680\n assert candidate(word = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 3412\n assert candidate(word = \"cccccdcccc\") == 0\n assert candidate(word = \"aovnwqoeirqoweoirqoweoirquw\") == 1949\n assert candidate(word = \"congratulations\") == 299\n assert candidate(word = \"xyzaeiouxyzaeiouxyz\") == 820\n assert candidate(word = \"bcbcbcbcbcbcbcbcbcbc\") == 0\n assert candidate(word = \"vvvuuuooooiiiaaaaeeeee\") == 1900\n assert candidate(word = \"consonants\") == 76\n assert candidate(word = \"vowelvowelvowel\") == 278\n assert candidate(word = \"supercalifragilisticexpialidocious\") == 3282\n assert candidate(word = \"aquickbrownfoxjumpsoverthelazydog\") == 2016\n assert candidate(word = \"leetcode\") == 58\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 3860\n assert candidate(word = \"sequence\") == 62\n assert candidate(word = \"aovvoaoaueuioeaueoaiouaoieaouioeaouioiea\") == 11218\n assert candidate(word = \"aeeee\") == 35\n assert candidate(word = \"aeioouaeiou\") == 286\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(word = \"bbbbbbbbbbbbbbbbbbbbbbba\") == 24\n assert candidate(word = \"hello\") == 13\n assert candidate(word = \"uoiea\") == 35\n assert candidate(word = \"bcdfghjklmnpqrstvwxyz\") == 0\n assert candidate(word = \"ffaaabbbccc\") == 94\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiou\") == 2925\n assert candidate(word = \"qweoiauoieqweoiauoieqweoiauoie\") == 4016\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 4562\n assert candidate(word = \"rhythms\") == 0\n assert candidate(word = \"bbbbbebbbb\") == 30\n assert candidate(word = \"aabbccddeeeffgg\") == 221\n assert candidate(word = \"beautiful\") == 101\n assert candidate(word = \"aeiouaeiouaeiouaeiouaeiouaeiou\") == 4960\n assert candidate(word = \"dddddeoeddd\") == 103\n assert candidate(word = \"aeiouaeiouaeiouaeiou\") == 1540\n assert candidate(word = \"vowel\") == 16\n assert candidate(word = \"xylophone\") == 54\n assert candidate(word = \"repetitiveeeee\") == 350\n assert candidate(word = \"repetition\") == 118\n assert candidate(word = \"characters\") == 78\n assert candidate(word = \"uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\") == 13244\n assert candidate(word = \"uvaeiouz\") == 98\n assert candidate(word = \"aovylqjwhepfuciphg\") == 280\n assert candidate(word = \"uoieaoueioauoiea\") == 816\n assert candidate(word = \"zzzzzzzzzzz\") == 0\n assert candidate(word = \"eeeeeaeeee\") == 220\n assert candidate(word = \"aaaaabaaaaa\") == 250\n assert candidate(word = \"abacaxabayabac\") == 280\n assert candidate(word = \"aeiouaeiou\") == 220\n assert candidate(word = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(word = \"programming\") == 90\n assert candidate(word = \"aeiaoeiaoeiaoeiaoeiaoeiaoeiaoeiaoeiaoei\") == 10660\n assert candidate(word = \"ouqofyrcjgz\") == 63\n assert candidate(word = \"aeiaeaieaa\") == 220\n assert candidate(word = \"vowelsarefun\") == 158\n assert candidate(word = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 4718\n", "comparison": "exact"}, "public_tests": ["\"aba\"", "\"abc\"", "\"ltcd\""], "hints": ["Since generating substrings is not an option, can we count the number of substrings a vowel appears in?", "How much does each vowel contribute to the total sum?"], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().countVowels", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:53+00:00", "tests_total": 80, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "string", "dynamic-programming", "combinatorics"]}, "language": "php", "interface": {"raw_signature": "function countVowels($word) {", "container": "Solution", "callable": "countVowels", "parameters": [{"name": "word", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2064, "task_id": "minimized-maximum-of-products-distributed-to-any-store", "difficulty": "Medium", "problem_description": "You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the i^th product type.\n\nYou need to distribute all products to the retail stores following these rules:\n\n- A store can only be given at most one product type but can be given any amount of it.\n- After distribution, each store will have been given some number of products (possibly 0). Let x represent the maximum number of products given to any store. You want x to be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.\n\nReturn the minimum possible x.\n\nExample 1:\n\nInput: n = 6, quantities = [11,6]\nOutput: 3\nExplanation: One optimal way is:\n- The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3\n- The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3\nThe maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3.\n\nExample 2:\n\nInput: n = 7, quantities = [15,10,10]\nOutput: 5\nExplanation: One optimal way is:\n- The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5\n- The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5\n- The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5\nThe maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5.\n\nExample 3:\n\nInput: n = 1, quantities = [100000]\nOutput: 100000\nExplanation: The only optimal way is:\n- The 100000 products of type 0 are distributed to the only store.\nThe maximum number of products given to any store is max(100000) = 100000.\n\nConstraints:\n\n- m == quantities.length\n- 1 <= m <= n <= 10^5\n- 1 <= quantities[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,quantities = [10, 20, 30, 40, 50]) == 50\n assert candidate(n = 3,quantities = [100, 100, 100]) == 100\n assert candidate(n = 10,quantities = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100000]) == 100000\n assert candidate(n = 3,quantities = [1, 100000]) == 50000\n assert candidate(n = 2,quantities = [50000, 50000]) == 50000\n assert candidate(n = 50000,quantities = [1, 2, 3, 4, 5]) == 1\n assert candidate(n = 10,quantities = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == 100000\n assert candidate(n = 2,quantities = [100000, 100000]) == 100000\n assert candidate(n = 7,quantities = [15, 10, 10]) == 5\n assert candidate(n = 10,quantities = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(n = 5,quantities = [10, 10, 10, 10, 10]) == 10\n assert candidate(n = 5,quantities = [1, 1, 1, 1, 1]) == 1\n assert candidate(n = 6,quantities = [11, 6]) == 3\n assert candidate(n = 5,quantities = [1, 2, 3, 4, 5]) == 5\n assert candidate(n = 100000,quantities = [1]) == 1\n assert candidate(n = 10,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(n = 50000,quantities = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 4\n assert candidate(n = 50000,quantities = [100000, 100000]) == 4\n assert candidate(n = 100,quantities = [100000]) == 1000\n assert candidate(n = 10,quantities = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(n = 3,quantities = [50, 50, 50]) == 50\n assert candidate(n = 2,quantities = [100, 1]) == 100\n assert candidate(n = 3,quantities = [100, 200, 300]) == 300\n assert candidate(n = 1,quantities = [100000]) == 100000\n assert candidate(n = 100000,quantities = [100000]) == 1\n assert candidate(n = 8,quantities = [12, 24, 36, 48, 60, 72, 84, 96]) == 96\n assert candidate(n = 100000,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(n = 80000,quantities = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000]) == 2\n assert candidate(n = 50000,quantities = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(n = 100000,quantities = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == 2\n assert candidate(n = 75000,quantities = [1, 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(n = 100000,quantities = [10000, 20000, 30000, 40000, 50000]) == 2\n assert candidate(n = 45000,quantities = [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, 50000]) == 35\n assert candidate(n = 15000,quantities = [50000, 40000, 30000, 20000, 10000]) == 10\n assert candidate(n = 80000,quantities = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 1\n assert candidate(n = 20000,quantities = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1\n assert candidate(n = 90000,quantities = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1]) == 3\n assert candidate(n = 10,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(n = 40000,quantities = [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, 470]) == 1\n assert candidate(n = 100000,quantities = [100000, 50000, 30000, 20000, 10000]) == 3\n assert candidate(n = 40000,quantities = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 1\n assert candidate(n = 30000,quantities = [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]) == 2\n assert candidate(n = 50000,quantities = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999]) == 20\n assert candidate(n = 30000,quantities = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) == 6\n assert candidate(n = 60000,quantities = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980]) == 34\n assert candidate(n = 10,quantities = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 500\n assert candidate(n = 60000,quantities = [15000, 15000, 15000, 15000, 15000, 15000]) == 2\n assert candidate(n = 99999,quantities = [100000, 99999, 99998, 99997, 99996, 99995]) == 7\n assert candidate(n = 80000,quantities = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019]) == 1\n assert candidate(n = 6,quantities = [10, 20, 30, 40, 50, 60]) == 60\n assert candidate(n = 15,quantities = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 150\n assert candidate(n = 90000,quantities = [90000, 100, 200, 300, 400, 500, 600, 700, 800]) == 2\n assert candidate(n = 7,quantities = [5, 15, 25, 35, 45, 55, 65]) == 65\n assert candidate(n = 10,quantities = [1000, 2000, 3000, 4000, 5000]) == 2000\n assert candidate(n = 50000,quantities = [1, 10, 100, 1000, 10000, 100000]) == 3\n assert candidate(n = 100000,quantities = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 4\n assert candidate(n = 30000,quantities = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 8\n assert candidate(n = 20000,quantities = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 1\n assert candidate(n = 40000,quantities = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 14\n assert candidate(n = 75000,quantities = [99999, 1, 2, 3, 4, 5]) == 2\n assert candidate(n = 50000,quantities = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1\n assert candidate(n = 45000,quantities = [45000, 22500, 15000, 11250, 9000]) == 3\n assert candidate(n = 25000,quantities = [10000, 20000, 30000, 40000, 50000]) == 7\n assert candidate(n = 50000,quantities = [10000, 15000, 20000, 25000, 30000]) == 2\n assert candidate(n = 100000,quantities = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 1\n assert candidate(n = 90000,quantities = [9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000]) == 2\n assert candidate(n = 10000,quantities = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 22\n assert candidate(n = 75000,quantities = [20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000]) == 3\n assert candidate(n = 100000,quantities = [50000, 50000, 50000, 50000]) == 2\n assert candidate(n = 90000,quantities = [1, 10, 100, 1000, 10000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 17\n assert candidate(n = 99999,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(n = 50000,quantities = [25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000]) == 5\n assert candidate(n = 50000,quantities = [100000]) == 2\n assert candidate(n = 75000,quantities = [75000, 75000, 75000, 75000, 75000, 75000, 75000, 75000, 75000, 75000]) == 10\n assert candidate(n = 60000,quantities = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 10\n assert candidate(n = 50000,quantities = [1, 2, 3, 4, 5, 6, 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(n = 100000,quantities = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2\n assert candidate(n = 50000,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(n = 20,quantities = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110]) == 110\n assert candidate(n = 10000,quantities = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 10\n assert candidate(n = 30000,quantities = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 1\n assert candidate(n = 80000,quantities = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]) == 1\n assert candidate(n = 45000,quantities = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980]) == 45\n assert candidate(n = 90000,quantities = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(n = 3,quantities = [99999, 99999, 99999]) == 99999\n assert candidate(n = 60000,quantities = [1, 10, 100, 1000, 10000, 100000]) == 2\n assert candidate(n = 60000,quantities = [99999, 1, 1, 1, 1, 1, 1, 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(n = 60000,quantities = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999]) == 34\n assert candidate(n = 80000,quantities = [8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009]) == 2\n assert candidate(n = 20000,quantities = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 100\n assert candidate(n = 30000,quantities = [30000, 30001, 30002, 30003, 30004, 30005, 30006, 30007, 30008, 30009, 30010, 30011, 30012, 30013, 30014, 30015, 30016, 30017, 30018, 30019]) == 21\n assert candidate(n = 100000,quantities = [50000, 50000, 50000, 50000, 50000]) == 3\n assert candidate(n = 100000,quantities = [10000, 15000, 20000, 25000, 30000]) == 1\n assert candidate(n = 75000,quantities = [12345, 67890, 11111, 22222, 33333, 44444, 55555]) == 4\n assert candidate(n = 50000,quantities = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1\n assert candidate(n = 30000,quantities = [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999]) == 11\n assert candidate(n = 100,quantities = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 20\n assert candidate(n = 80000,quantities = [20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 20000]) == 17\n", "comparison": "exact"}, "public_tests": ["6\n[11,6]", "7\n[15,10,10]", "1\n[100000]"], "hints": ["There exists a monotonic nature such that when x is smaller than some number, there will be no way to distribute, and when x is not smaller than that number, there will always be a way to distribute.", "If you are given a number k, where the number of products given to any store does not exceed k, could you determine if all products can be distributed?", "Implement a function canDistribute(k), which returns true if you can distribute all products such that any store will not be given more than k products, and returns false if you cannot. Use this function to binary search for the smallest possible k."], "metadata": {"canonical_parameter_names": ["n", "quantities"], "leetcode_dataset_entry_point": "Solution().minimizedMaximum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:56+00:00", "tests_total": 108, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "binary-search", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimizedMaximum($n, $quantities) {", "container": "Solution", "callable": "minimizedMaximum", "parameters": [{"name": "n", "type": "Integer"}, {"name": "quantities", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2065, "task_id": "maximum-path-quality-of-a-graph", "difficulty": "Hard", "problem_description": "There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the i^th node. You are also given a 0-indexed 2D integer array edges, where each edges[j] = [u_j, v_j, time_j] indicates that there is an undirected edge between the nodes u_j and v_j,and it takes time_j seconds to travel between the two nodes. Finally, you are given an integer maxTime.\n\nA valid path in the graph is any path that starts at node 0, ends at node 0, and takes at most maxTime seconds to complete. You may visit the same node multiple times. The quality of a valid path is the sum of the values of the unique nodes visited in the path (each node's value is added at most once to the sum).\n\nReturn the maximum quality of a valid path.\n\nNote: There are at most four edges connected to each node.\n\nExample 1:\n\nInput: values = [0,32,10,43], edges = [[0,1,10],[1,2,15],[0,3,10]], maxTime = 49\nOutput: 75\nExplanation:\nOne possible path is 0 -> 1 -> 0 -> 3 -> 0. The total time taken is 10 + 10 + 10 + 10 = 40 <= 49.\nThe nodes visited are 0, 1, and 3, giving a maximal path quality of 0 + 32 + 43 = 75.\n\nExample 2:\n\nInput: values = [5,10,15,20], edges = [[0,1,10],[1,2,10],[0,3,10]], maxTime = 30\nOutput: 25\nExplanation:\nOne possible path is 0 -> 3 -> 0. The total time taken is 10 + 10 = 20 <= 30.\nThe nodes visited are 0 and 3, giving a maximal path quality of 5 + 20 = 25.\n\nExample 3:\n\nInput: values = [1,2,3,4], edges = [[0,1,10],[1,2,11],[2,3,12],[1,3,13]], maxTime = 50\nOutput: 7\nExplanation:\nOne possible path is 0 -> 1 -> 3 -> 1 -> 0. The total time taken is 10 + 13 + 13 + 10 = 46 <= 50.\nThe nodes visited are 0, 1, and 3, giving a maximal path quality of 1 + 2 + 4 = 7.\n\nConstraints:\n\n- n == values.length\n- 1 <= n <= 1000\n- 0 <= values[i] <= 10^8\n- 0 <= edges.length <= 2000\n- edges[j].length == 3\n- 0 <= u_j< v_j <= n - 1\n- 10 <= time_j, maxTime <= 100\n- All the pairs [u_j, v_j] are unique.\n- There are at most four edges connected to each node.\n- The graph may not be connected.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [2, 4, 40]],maxTime = 100) == 70\n assert candidate(values = [100, 200, 300, 400],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 0, 10]],maxTime = 50) == 1000\n assert candidate(values = [5, 5, 5, 5, 5],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 0, 10]],maxTime = 40) == 15\n assert candidate(values = [5, 5, 5, 5],edges = [[0, 1, 10], [0, 2, 10], [2, 3, 10]],maxTime = 25) == 10\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10]],maxTime = 50) == 3\n assert candidate(values = [1, 2, 3, 4, 5],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10]],maxTime = 20) == 4\n assert candidate(values = [1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10]],maxTime = 40) == 3\n assert candidate(values = [5, 10, 15, 20],edges = [[0, 1, 10], [1, 2, 10], [0, 3, 10]],maxTime = 30) == 25\n assert candidate(values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10]],maxTime = 100) == 27\n assert candidate(values = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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]],maxTime = 90) == 25\n assert candidate(values = [5, 5, 5, 5, 5, 5],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10]],maxTime = 30) == 10\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10]],maxTime = 50) == 90\n assert candidate(values = [5, 5, 5, 5],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 3, 10]],maxTime = 30) == 10\n assert candidate(values = [1, 2, 3, 4],edges = [[0, 1, 10], [1, 2, 11], [2, 3, 12], [1, 3, 13]],maxTime = 50) == 7\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [0, 2, 20], [1, 3, 15], [2, 3, 25], [3, 4, 10]],maxTime = 60) == 70\n assert candidate(values = [1, 2, 3, 4],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10]],maxTime = 10) == 1\n assert candidate(values = [1, 2, 3, 4, 5, 6],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10]],maxTime = 60) == 12\n assert candidate(values = [0, 32, 10, 43],edges = [[0, 1, 10], [1, 2, 15], [0, 3, 10]],maxTime = 49) == 75\n assert candidate(values = [10, 20, 30],edges = [[0, 1, 10], [1, 2, 10]],maxTime = 25) == 30\n assert candidate(values = [10, 20, 30],edges = [[0, 1, 10], [1, 2, 20]],maxTime = 30) == 30\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 0, 10]],maxTime = 50) == 150\n assert candidate(values = [10],edges = [],maxTime = 100) == 10\n assert candidate(values = [100, 0, 0, 0],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10]],maxTime = 10) == 100\n assert candidate(values = [100, 50, 200, 300, 150, 250, 400],edges = [[0, 1, 20], [0, 2, 30], [0, 3, 40], [1, 4, 10], [1, 5, 20], [2, 6, 30], [3, 6, 40], [4, 5, 50], [5, 6, 60]],maxTime = 120) == 700\n assert candidate(values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10]],maxTime = 80) == 2500\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 7, 10], [6, 8, 10], [7, 8, 10], [7, 9, 10], [8, 9, 10]],maxTime = 50) == 110\n assert candidate(values = [10, 10, 10, 10, 10],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 2, 10], [1, 3, 10], [1, 4, 10], [2, 3, 10], [2, 4, 10], [3, 4, 10]],maxTime = 40) == 40\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [1, 6, 10], [1, 7, 10], [2, 8, 10], [2, 9, 10], [3, 10, 10], [3, 11, 10], [4, 12, 10], [4, 13, 10], [5, 14, 10], [5, 15, 10], [6, 16, 10], [6, 17, 10], [7, 18, 10], [7, 19, 10], [8, 14, 10], [8, 15, 10], [9, 16, 10], [9, 17, 10], [10, 18, 10], [10, 19, 10], [11, 14, 10], [11, 15, 10], [12, 16, 10], [12, 17, 10], [13, 18, 10], [13, 19, 10]],maxTime = 100) == 10\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],edges = [[0, 1, 10], [0, 2, 20], [1, 3, 15], [2, 4, 25], [3, 5, 10], [4, 6, 15], [5, 7, 20], [6, 8, 10], [7, 9, 15], [8, 10, 20], [9, 11, 10]],maxTime = 120) == 210\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10], [5, 8, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10]],maxTime = 80) == 8\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],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], [9, 0, 10], [0, 2, 15], [1, 3, 15], [2, 4, 15], [3, 5, 15], [4, 6, 15], [5, 7, 15], [6, 8, 15], [7, 9, 15], [8, 0, 15], [9, 1, 15]],maxTime = 150) == 550\n assert candidate(values = [5, 10, 15, 20, 25, 30, 35],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 0, 10]],maxTime = 50) == 70\n assert candidate(values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],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]],maxTime = 55) == 600\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10]],maxTime = 50) == 9\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 2, 10], [1, 3, 10], [1, 4, 10], [2, 3, 10], [2, 4, 10], [3, 4, 10]],maxTime = 100) == 5\n assert candidate(values = [10, 20, 30, 40, 50, 60],edges = [[0, 1, 10], [0, 2, 10], [1, 2, 15], [1, 3, 20], [2, 4, 25], [3, 4, 30], [4, 5, 15]],maxTime = 70) == 90\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10], [8, 0, 10]],maxTime = 90) == 310\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 7, 10], [6, 8, 10], [7, 8, 10], [8, 9, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [2, 7, 10], [3, 8, 10], [4, 9, 10], [5, 6, 10]],maxTime = 60) == 37\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [3, 8, 10], [4, 9, 10], [4, 10, 10], [5, 11, 10], [5, 12, 10], [6, 13, 10], [6, 14, 10], [7, 15, 10], [7, 16, 10], [8, 17, 10], [8, 18, 10], [9, 19, 10]],maxTime = 150) == 8\n assert candidate(values = [1, 2, 3, 4, 5],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 4, 10]],maxTime = 40) == 9\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10]],maxTime = 100) == 310\n assert candidate(values = [100, 200, 100, 200, 100, 200, 100, 200],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10]],maxTime = 50) == 500\n assert candidate(values = [50, 20, 30, 40],edges = [[0, 1, 10], [0, 2, 20], [0, 3, 30], [1, 2, 15], [1, 3, 25], [2, 3, 10]],maxTime = 40) == 80\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 2, 10], [1, 3, 10], [1, 4, 10], [2, 3, 10], [2, 4, 10], [3, 4, 10]],maxTime = 35) == 100\n assert candidate(values = [5, 10, 15, 20, 25, 30],edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 30], [0, 3, 35], [1, 4, 40]],maxTime = 100) == 50\n assert candidate(values = [5, 10, 15, 20, 25, 30, 35, 40],edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 30], [5, 6, 35], [6, 7, 40], [0, 7, 10]],maxTime = 100) == 80\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10]],maxTime = 80) == 27\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 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], [9, 0, 10]],maxTime = 50) == 20\n assert candidate(values = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100],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], [9, 0, 10], [0, 5, 10], [1, 6, 10], [2, 7, 10], [3, 8, 10], [4, 9, 10]],maxTime = 150) == 550\n assert candidate(values = [30, 20, 10, 40, 50],edges = [[0, 1, 10], [0, 2, 15], [0, 3, 20], [0, 4, 25], [1, 2, 5], [1, 3, 15], [1, 4, 25], [2, 3, 10], [2, 4, 20], [3, 4, 5]],maxTime = 60) == 150\n assert candidate(values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],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], [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]],maxTime = 190) == 275\n assert candidate(values = [9, 8, 7, 6, 5, 4, 3, 2, 1],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [1, 4, 10], [1, 5, 10], [2, 6, 10], [2, 7, 10], [3, 8, 10], [4, 8, 10], [5, 6, 10]],maxTime = 60) == 31\n assert candidate(values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],edges = [[0, 1, 10], [1, 2, 10], [0, 3, 10], [3, 4, 10], [2, 5, 10], [5, 6, 10], [4, 7, 10], [7, 8, 10], [6, 9, 10]],maxTime = 100) == 145\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 15], [0, 2, 20], [1, 3, 25], [2, 4, 30], [3, 5, 35], [4, 6, 40], [5, 7, 45], [6, 8, 50], [7, 9, 55], [8, 9, 60]],maxTime = 150) == 13\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [1, 4, 10], [1, 5, 10], [2, 6, 10], [2, 7, 10], [3, 8, 10], [3, 9, 10]],maxTime = 50) == 150\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10], [14, 0, 10]],maxTime = 140) == 850\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10], [5, 8, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10]],maxTime = 100) == 510\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 10], [5, 6, 30], [6, 7, 10], [7, 8, 25], [8, 9, 20], [9, 10, 15], [10, 11, 20], [11, 12, 15], [12, 13, 10], [13, 14, 30]],maxTime = 200) == 210\n assert candidate(values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],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], [9, 0, 10]],maxTime = 90) == 3500\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [1, 6, 10], [2, 7, 10], [2, 8, 10], [3, 9, 10], [3, 10, 10], [4, 11, 10], [4, 12, 10], [5, 13, 10], [6, 14, 10], [7, 15, 10], [8, 16, 10], [9, 17, 10], [10, 18, 10], [11, 19, 10], [12, 13, 10], [14, 15, 10], [16, 17, 10], [18, 19, 10]],maxTime = 150) == 142\n assert candidate(values = [100, 200, 300, 400, 500],edges = [[0, 1, 20], [0, 2, 30], [1, 3, 25], [2, 4, 35], [3, 4, 40]],maxTime = 150) == 1500\n assert candidate(values = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10], [5, 8, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10], [3, 4, 15], [5, 6, 15]],maxTime = 120) == 950\n assert candidate(values = [100, 200, 300, 400, 500],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 0, 10]],maxTime = 50) == 1500\n assert candidate(values = [50, 20, 10, 30, 40, 60],edges = [[0, 1, 10], [1, 2, 15], [1, 3, 20], [2, 3, 25], [3, 4, 10], [4, 5, 30]],maxTime = 100) == 150\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 3, 10], [3, 4, 10], [1, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10], [7, 8, 10], [8, 9, 10], [9, 1, 10]],maxTime = 60) == 22\n assert candidate(values = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 7, 10], [6, 8, 10], [7, 8, 10]],maxTime = 100) == 40\n assert candidate(values = [5, 10, 15, 20, 25, 30],edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 30], [0, 5, 35]],maxTime = 70) == 35\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 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]],maxTime = 90) == 15\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10], [5, 8, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10], [0, 3, 30], [1, 5, 30], [2, 4, 30]],maxTime = 90) == 450\n assert candidate(values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1, 10], [0, 2, 15], [1, 3, 20], [2, 4, 25], [3, 5, 10], [4, 6, 30], [5, 7, 10], [6, 8, 25], [7, 9, 20]],maxTime = 150) == 3100\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 9, 10], [7, 9, 10], [8, 9, 10]],maxTime = 50) == 15\n assert candidate(values = [50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 20], [1, 3, 15], [2, 3, 25], [3, 4, 10], [4, 5, 15]],maxTime = 100) == 380\n assert candidate(values = [100, 200, 300, 400, 500],edges = [[0, 1, 20], [1, 2, 30], [2, 3, 25], [3, 4, 35], [4, 0, 40]],maxTime = 120) == 800\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 0, 10], [1, 3, 15], [2, 4, 20]],maxTime = 50) == 150\n assert candidate(values = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 7, 10], [5, 8, 10], [6, 8, 10], [7, 9, 10], [8, 9, 10], [0, 5, 20], [1, 6, 20], [2, 7, 20], [3, 8, 20], [4, 9, 20]],maxTime = 120) == 275\n assert candidate(values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [4, 8, 10], [5, 9, 10], [6, 7, 10], [6, 8, 10], [7, 8, 10], [8, 9, 10], [0, 3, 10], [0, 4, 10], [1, 5, 10], [2, 7, 10], [3, 8, 10], [4, 9, 10], [5, 6, 10], [0, 5, 10], [1, 6, 10], [2, 3, 10], [3, 9, 10], [4, 5, 10], [6, 9, 10], [7, 9, 10]],maxTime = 100) == 5500\n assert candidate(values = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10], [14, 15, 10]],maxTime = 150) == 40\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 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, 0, 10]],maxTime = 150) == 1180\n assert candidate(values = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [0, 5, 10], [0, 6, 10], [0, 7, 10], [0, 8, 10], [0, 9, 10], [1, 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]],maxTime = 50) == 3\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [1, 4, 10], [2, 5, 10], [2, 6, 10], [3, 7, 10], [3, 8, 10], [4, 9, 10], [5, 6, 10], [7, 8, 10], [8, 9, 10]],maxTime = 90) == 390\n assert candidate(values = [100, 200, 300, 400, 500],edges = [[0, 1, 20], [0, 2, 20], [1, 3, 20], [2, 3, 20], [3, 4, 20], [1, 2, 20]],maxTime = 80) == 1000\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],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], [9, 0, 10]],maxTime = 90) == 350\n assert candidate(values = [8, 6, 7, 5, 3, 0, 9],edges = [[0, 1, 15], [1, 2, 20], [2, 3, 25], [3, 4, 30], [4, 5, 35], [5, 6, 40], [6, 0, 45]],maxTime = 100) == 21\n assert candidate(values = [5, 10, 15, 20, 25, 30],edges = [[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 30], [0, 5, 10]],maxTime = 100) == 70\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1, 10], [0, 2, 10], [1, 3, 10], [2, 4, 10], [3, 5, 10], [4, 6, 10], [5, 7, 10], [6, 8, 10], [7, 9, 10], [9, 0, 10]],maxTime = 100) == 390\n assert candidate(values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10]],maxTime = 150) == 360\n assert candidate(values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1, 10], [0, 9, 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]],maxTime = 80) == 35\n assert candidate(values = [10, 20, 30, 40, 50],edges = [[0, 1, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [1, 2, 10], [1, 3, 10], [1, 4, 10], [2, 3, 10], [2, 4, 10], [3, 4, 10]],maxTime = 30) == 100\n", "comparison": "exact"}, "public_tests": ["[0,32,10,43]\n[[0,1,10],[1,2,15],[0,3,10]]\n49", "[5,10,15,20]\n[[0,1,10],[1,2,10],[0,3,10]]\n30", "[1,2,3,4]\n[[0,1,10],[1,2,11],[2,3,12],[1,3,13]]\n50"], "hints": ["How many nodes can you visit within maxTime seconds?", "Can you try every valid path?"], "metadata": {"canonical_parameter_names": ["values", "edges", "maxTime"], "leetcode_dataset_entry_point": "Solution().maximalPathQuality", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:39:58+00:00", "tests_total": 89, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "backtracking", "graph"]}, "language": "php", "interface": {"raw_signature": "function maximalPathQuality($values, $edges, $maxTime) {", "container": "Solution", "callable": "maximalPathQuality", "parameters": [{"name": "values", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}, {"name": "maxTime", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2068, "task_id": "check-whether-two-strings-are-almost-equivalent", "difficulty": "Easy", "problem_description": "Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3.\n\nGiven two strings word1 and word2, each of length n, return true if word1 and word2 are almost equivalent, or false otherwise.\n\nThe frequency of a letter x is the number of times it occurs in the string.\n\nExample 1:\n\nInput: word1 = \"aaaa\", word2 = \"bccb\"\nOutput: false\nExplanation: There are 4 'a's in \"aaaa\" but 0 'a's in \"bccb\".\nThe difference is 4, which is more than the allowed 3.\n\nExample 2:\n\nInput: word1 = \"abcdeef\", word2 = \"abaaacc\"\nOutput: true\nExplanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n- 'a' appears 1 time in word1 and 4 times in word2. The difference is 3.\n- 'b' appears 1 time in word1 and 1 time in word2. The difference is 0.\n- 'c' appears 1 time in word1 and 2 times in word2. The difference is 1.\n- 'd' appears 1 time in word1 and 0 times in word2. The difference is 1.\n- 'e' appears 2 times in word1 and 0 times in word2. The difference is 2.\n- 'f' appears 1 time in word1 and 0 times in word2. The difference is 1.\n\nExample 3:\n\nInput: word1 = \"cccddabba\", word2 = \"babababab\"\nOutput: true\nExplanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n- 'a' appears 2 times in word1 and 4 times in word2. The difference is 2.\n- 'b' appears 2 times in word1 and 5 times in word2. The difference is 3.\n- 'c' appears 3 times in word1 and 0 times in word2. The difference is 3.\n- 'd' appears 2 times in word1 and 0 times in word2. The difference is 2.\n\nConstraints:\n\n- n == word1.length == word2.length\n- 1 <= n <= 100\n- word1 and word2 consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word1 = \"cccddabba\",word2 = \"babababab\") == True\n assert candidate(word1 = \"aaa\",word2 = \"bbb\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"ccbbaa\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"abcdefghijklmnopqrstuvwxyz\") == True\n assert candidate(word1 = \"pqrstu\",word2 = \"utsrpq\") == True\n assert candidate(word1 = \"mnop\",word2 = \"ponm\") == True\n assert candidate(word1 = \"abcabcabc\",word2 = \"bcbcbcbcb\") == True\n assert candidate(word1 = \"aaaa\",word2 = \"bccb\") == False\n assert candidate(word1 = \"xyz\",word2 = \"zyx\") == True\n assert candidate(word1 = \"abcdeef\",word2 = \"abaaacc\") == True\n assert candidate(word1 = \"abc\",word2 = \"abc\") == True\n assert candidate(word1 = \"hello\",word2 = \"world\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggeeffddccbbaa\") == True\n assert candidate(word1 = \"abcabcabc\",word2 = \"abcabcabc\") == True\n assert candidate(word1 = \"zzzz\",word2 = \"zzzz\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"bbccdd\") == True\n assert candidate(word1 = \"abc\",word2 = \"xyz\") == True\n assert candidate(word1 = \"zzz\",word2 = \"zzz\") == True\n assert candidate(word1 = \"aabbcc\",word2 = \"abcabc\") == True\n assert candidate(word1 = \"abcdef\",word2 = \"fedcba\") == True\n assert candidate(word1 = \"abcd\",word2 = \"dcba\") == True\n assert candidate(word1 = \"abc\",word2 = \"def\") == True\n assert candidate(word1 = \"abcdefg\",word2 = \"gfedcba\") == True\n assert candidate(word1 = \"almostequivalent\",word2 = \"equivalentalmost\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyz\",word2 = \"zyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(word1 = \"abacabadabacabad\",word2 = \"babaabacabacabac\") == True\n assert candidate(word1 = \"aabbaabbaabb\",word2 = \"bbaabbaabbab\") == True\n assert candidate(word1 = \"frequency\",word2 = \"requeency\") == True\n assert candidate(word1 = \"xyzxyzxyzxyzxyz\",word2 = \"zyxzyxzyxzyxzyx\") == True\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzza\") == True\n assert candidate(word1 = \"xyzxyzxyzxyzxyzxyz\",word2 = \"xyzxyzxyzxyzxyzxyx\") == True\n assert candidate(word1 = \"xylophone\",word2 = \"polyxhnon\") == True\n assert candidate(word1 = \"aaaabbbb\",word2 = \"bbbbaaaa\") == True\n assert candidate(word1 = \"testtesttest\",word2 = \"setttestsett\") == True\n assert candidate(word1 = \"abcdefghij\",word2 = \"jihgfedcba\") == True\n assert candidate(word1 = \"banana\",word2 = \"nanaba\") == True\n assert candidate(word1 = \"almostequivalent\",word2 = \"quivalentalmosta\") == True\n assert candidate(word1 = \"frequency\",word2 = \"frequncey\") == True\n assert candidate(word1 = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",word2 = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqz\") == True\n assert candidate(word1 = \"frequencycheck\",word2 = \"checkfrequency\") == True\n assert candidate(word1 = \"aabbbccc\",word2 = \"bbaaccdd\") == True\n assert candidate(word1 = \"abcdefghijabcdefghij\",word2 = \"abcdefghijabcdefghii\") == True\n assert candidate(word1 = \"abababababababab\",word2 = \"babababababababa\") == True\n assert candidate(word1 = \"aaabbbccc\",word2 = \"bbbaacccd\") == True\n assert candidate(word1 = \"abcabcabcabc\",word2 = \"bcbcbcbcbcbc\") == False\n assert candidate(word1 = \"asdfghjkl\",word2 = \"lkjhgfdsa\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"acabacabacababa\") == True\n assert candidate(word1 = \"hellothere\",word2 = \"heellooerr\") == True\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(word1 = \"equaldiffffe\",word2 = \"equaldifffff\") == True\n assert candidate(word1 = \"racecar\",word2 = \"carrace\") == True\n assert candidate(word1 = \"mississippi\",word2 = \"bississippi\") == True\n assert candidate(word1 = \"aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkk\",word2 = \"ffffgggghhhhiiiijjjjkkkkaaaabbbbccccddddeeee\") == True\n assert candidate(word1 = \"pythonprogramming\",word2 = \"programmingpython\") == True\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(word1 = \"abcdefghijk\",word2 = \"abcdefghijl\") == True\n assert candidate(word1 = \"aaaaaaaaaaa\",word2 = \"bbbbbbbbbbb\") == False\n assert candidate(word1 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",word2 = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == True\n assert candidate(word1 = \"ababababababababababababababababababababab\",word2 = \"bababababababababababababababababababababa\") == True\n assert candidate(word1 = \"banana\",word2 = \"ananaa\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"cbacabacabacabc\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == True\n assert candidate(word1 = \"abcdabcdabcdabcd\",word2 = \"bcdbcdbcdbcdbcdb\") == False\n assert candidate(word1 = \"abcdabcdabcdabcd\",word2 = \"dcbaabcdabcdabcd\") == True\n assert candidate(word1 = \"abcdefghij\",word2 = \"abcdefghix\") == True\n assert candidate(word1 = \"abcdefghi\",word2 = \"ihgfedcba\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyza\",word2 = \"bcdefghijklmnopqrstuvwxyzzz\") == True\n assert candidate(word1 = \"frequency\",word2 = \"frequnecy\") == True\n assert candidate(word1 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",word2 = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == True\n assert candidate(word1 = \"abcde\",word2 = \"fghij\") == True\n assert candidate(word1 = \"abcdefghijklmnopqrstuvwxyzz\",word2 = \"abcdefghijklmnopqrstuvwxyyz\") == True\n assert candidate(word1 = \"aabbbcccdddee\",word2 = \"eeedddcccbbaa\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"abacabadabacaba\") == True\n assert candidate(word1 = \"abacabadabacaba\",word2 = \"abcabcabcabcabc\") == True\n assert candidate(word1 = \"qwerasdfzxcv\",word2 = \"asdfzxcvqwer\") == True\n assert candidate(word1 = \"mnopqr\",word2 = \"mnopqz\") == True\n assert candidate(word1 = \"mnopqr\",word2 = \"rqponm\") == True\n assert candidate(word1 = \"abcdefg\",word2 = \"ghijklm\") == True\n assert candidate(word1 = \"abcdabcdabcd\",word2 = \"dcbaefghefgh\") == True\n assert candidate(word1 = \"aaaabbbbcccc\",word2 = \"ddddeeeeffff\") == False\n assert candidate(word1 = \"programming\",word2 = \"grammipnorg\") == True\n assert candidate(word1 = \"aaaabbbbccccdddd\",word2 = \"ddddccccbbbbaaaa\") == True\n", "comparison": "exact"}, "public_tests": ["\"aaaa\"\n\"bccb\"", "\"abcdeef\"\n\"abaaacc\"", "\"cccddabba\"\n\"babababab\""], "hints": ["What data structure can we use to count the frequency of each character?", "Are there edge cases where a character is present in one string but not the other?"], "metadata": {"canonical_parameter_names": ["word1", "word2"], "leetcode_dataset_entry_point": "Solution().checkAlmostEquivalent", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:02+00:00", "tests_total": 148, "tests_dropped": 65, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function checkAlmostEquivalent($word1, $word2) {", "container": "Solution", "callable": "checkAlmostEquivalent", "parameters": [{"name": "word1", "type": "String"}, {"name": "word2", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2070, "task_id": "most-beautiful-item-for-each-query", "difficulty": "Medium", "problem_description": "You are given a 2D integer array items where items[i] = [price_i, beauty_i] denotes the price and beauty of an item respectively.\n\nYou are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is less than or equal to queries[j]. If no such item exists, then the answer to this query is 0.\n\nReturn an array answer of the same length as queries where answer[j] is the answer to the j^th query.\n\nExample 1:\n\nInput: items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6]\nOutput: [2,4,5,5,6,6]\nExplanation:\n- For queries[0]=1, [1,2] is the only item which has price <= 1. Hence, the answer for this query is 2.\n- For queries[1]=2, the items which can be considered are [1,2] and [2,4].\n The maximum beauty among them is 4.\n- For queries[2]=3 and queries[3]=4, the items which can be considered are [1,2], [3,2], [2,4], and [3,5].\n The maximum beauty among them is 5.\n- For queries[4]=5 and queries[5]=6, all items can be considered.\n Hence, the answer for them is the maximum beauty of all items, i.e., 6.\n\nExample 2:\n\nInput: items = [[1,2],[1,2],[1,3],[1,4]], queries = [1]\nOutput: [4]\nExplanation:\nThe price of every item is equal to 1, so we choose the item with the maximum beauty 4.\nNote that multiple items can have the same price and/or beauty.\n\nExample 3:\n\nInput: items = [[10,1000]], queries = [5]\nOutput: [0]\nExplanation:\nNo item has a price less than or equal to 5, so no item can be chosen.\nHence, the answer to the query is 0.\n\nConstraints:\n\n- 1 <= items.length, queries.length <= 10^5\n- items[i].length == 2\n- 1 <= price_i, beauty_i, queries[j] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(items = [[10, 1000]],queries = [5]) == [0]\n assert candidate(items = [[100, 5], [50, 4], [200, 3], [150, 2], [300, 1]],queries = [50, 100, 150, 200, 250, 300]) == [4, 5, 5, 5, 5, 5]\n assert candidate(items = [[1, 5], [2, 9], [3, 12], [4, 15], [5, 18]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [5, 12, 18, 18, 18, 18, 18, 18, 18, 18]\n assert candidate(items = [[5, 10], [4, 4], [6, 8], [7, 12]],queries = [3, 5, 7, 10]) == [0, 10, 12, 12]\n assert candidate(items = [[5, 10], [3, 5], [10, 15], [1, 1]],queries = [3, 7, 10]) == [5, 10, 15]\n assert candidate(items = [[1, 2], [1, 2], [1, 3], [1, 4]],queries = [1]) == [4]\n assert candidate(items = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]],queries = [1, 2, 3, 4, 5, 6]) == [5, 5, 5, 5, 5, 5]\n assert candidate(items = [[5, 1], [3, 2], [7, 4], [2, 3]],queries = [8, 6, 4, 2, 1]) == [4, 3, 3, 3, 0]\n assert candidate(items = [[1, 2], [3, 2], [2, 4], [5, 6], [3, 5]],queries = [1, 2, 3, 4, 5, 6]) == [2, 4, 5, 5, 6, 6]\n assert candidate(items = [[5, 10], [7, 15], [8, 20]],queries = [6, 9, 12]) == [10, 20, 20]\n assert candidate(items = [[100, 1], [99, 2], [98, 3], [97, 4], [96, 5]],queries = [96, 97, 98, 99, 100]) == [5, 5, 5, 5, 5]\n assert candidate(items = [[5, 1], [3, 2], [7, 4], [2, 6], [9, 8]],queries = [1, 3, 5, 7, 9, 11]) == [0, 6, 6, 6, 8, 8]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [5, 4, 3, 2, 1]) == [5, 4, 3, 2, 1]\n assert candidate(items = [[2, 3], [5, 5], [6, 7], [8, 8]],queries = [1, 4, 6, 9]) == [0, 3, 7, 8]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],queries = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate(items = [[1, 1], [2, 3], [2, 5], [3, 4], [3, 6], [4, 7], [4, 8], [5, 9]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 5, 6, 8, 9, 9, 9, 9, 9]\n assert candidate(items = [[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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500], [60, 600], [70, 700], [80, 800], [90, 900], [100, 1000]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(items = [[5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],queries = [4, 5, 6]) == [0, 10, 10]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]],queries = [1, 1, 1, 1, 1]) == [6, 6, 6, 6, 6]\n assert candidate(items = [[1, 1000], [1, 900], [1, 800], [1, 700], [1, 600], [1, 500], [1, 400], [1, 300], [1, 200], [1, 100]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\n assert candidate(items = [[1, 10], [2, 15], [3, 5], [4, 20], [5, 10], [6, 25], [7, 30], [8, 20], [9, 5], [10, 15]],queries = [1, 3, 5, 7, 9, 10]) == [10, 15, 20, 30, 30, 30]\n assert candidate(items = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\n assert candidate(items = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1000], [2, 900], [3, 800], [4, 700], [5, 600]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]\n assert candidate(items = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]) == [0, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90, 100, 100]\n assert candidate(items = [[1, 100], [10, 200], [100, 300], [1000, 400], [10000, 500]],queries = [1, 5, 50, 500, 5000, 50000, 100000]) == [100, 100, 200, 300, 400, 500, 500]\n assert candidate(items = [[2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]],queries = [99, 199, 299, 399, 499, 599, 699, 799, 899, 999, 1001]) == [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [1, 3, 5, 7, 9, 11]) == [1, 3, 5, 7, 9, 10]\n assert candidate(items = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40], [45, 45], [50, 50]],queries = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [0, 0, 5, 5, 10, 10, 10, 15, 15, 20]\n assert candidate(items = [[50, 100], [25, 200], [75, 150], [100, 250], [125, 300]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]) == [0, 0, 200, 200, 200, 200, 200, 200, 200, 250, 250, 250, 300]\n assert candidate(items = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5]],queries = [10]) == [5]\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(items = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [10, 60], [15, 70], [20, 80], [25, 90], [30, 100]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == [10, 30, 50, 50, 50, 60, 60, 70, 70, 70, 80, 80, 90, 90, 90, 100]\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(items = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5]],queries = [5, 10, 15]) == [0, 5, 5]\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(items = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]],queries = [5, 4, 3, 2, 1]) == [10, 10, 10, 10, 10]\n assert candidate(items = [[1, 10], [10, 1], [100, 100], [1000, 1], [10000, 10000], [100000, 1], [1000000, 1000000]],queries = [1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 1500000]) == [10, 10, 10, 10, 100, 100, 100, 100, 10000, 10000, 10000, 10000, 1000000, 1000000]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[100, 500], [200, 1000], [300, 1500], [400, 2000], [500, 2500]],queries = [50, 150, 250, 350, 450, 550]) == [0, 500, 1000, 1500, 2000, 2500]\n assert candidate(items = [[1, 10], [3, 20], [2, 30], [5, 40], [4, 50]],queries = [1, 2, 3, 4, 5]) == [10, 30, 30, 50, 50]\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1]) == [10]\n assert candidate(items = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [1, 5, 9, 13, 17, 19, 19, 19, 19, 19]\n assert candidate(items = [[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(items = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [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]) == [5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]\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]],queries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(items = [[1, 1], [10, 2], [100, 3], [1000, 4], [10000, 5], [100000, 6], [1000000, 7], [10000000, 8], [100000000, 9], [1000000000, 10]],queries = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [5, 6, 7, 8, 9, 10, 10, 10, 10, 10]\n assert candidate(items = [[10, 5], [20, 4], [30, 3], [40, 2], [50, 1]],queries = [15, 25, 35, 45, 55]) == [5, 5, 5, 5, 5]\n assert candidate(items = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10]],queries = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],queries = [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, 1, 1, 1, 1, 1]\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1]) == [10]\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], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20]],queries = [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(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]\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], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 20]\n assert candidate(items = [[1, 10], [10, 20], [100, 30], [1000, 40], [10000, 5], [100000, 6], [1000000, 7], [10000000, 8], [100000000, 9], [1000000000, 10]],queries = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == [10, 20, 30, 40, 40, 40, 40, 40, 40, 40]\n assert candidate(items = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500]],queries = [5, 15, 25, 35, 45, 55]) == [0, 100, 200, 300, 400, 500]\n assert candidate(items = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],queries = [50, 150, 250, 350, 450, 550]) == [0, 100, 200, 300, 400, 500]\n assert candidate(items = [[1, 100], [50, 50], [100, 10], [150, 1], [200, 50], [250, 100], [300, 150], [350, 200], [400, 250], [450, 300]],queries = [25, 50, 75, 125, 175, 225, 275, 325, 375, 425]) == [100, 100, 100, 100, 100, 100, 100, 150, 200, 250]\n assert candidate(items = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]\n assert candidate(items = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [0, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(items = [[1000000000, 1], [999999999, 2], [999999998, 3], [999999997, 4], [999999996, 5]],queries = [1, 2, 3, 4, 5]) == [0, 0, 0, 0, 0]\n assert candidate(items = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],queries = [10, 15, 20, 25]) == [10, 16, 20, 20]\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]],queries = [1, 3, 5, 7, 9, 11, 13, 15]) == [1, 3, 5, 7, 9, 11, 13, 15]\n assert candidate(items = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(items = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5]],queries = [4, 5, 6]) == [0, 5, 5]\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5]],queries = [1]) == [5]\n assert candidate(items = [[1, 2], [3, 5], [2, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20]],queries = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == [6, 8, 12, 16, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(items = [[1, 100], [100, 1], [1, 200], [100, 2], [1, 300], [100, 3], [1, 400], [100, 4], [1, 500], [100, 5]],queries = [1, 50, 100, 150, 200]) == [500, 500, 500, 500, 500]\n assert candidate(items = [[1, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1000000000], [1000000000, 1]],queries = [500000000, 1000000000]) == [1000000000, 1000000000]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [5, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]\n assert candidate(items = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [14, 13, 12, 11, 10, 9, 8, 7, 6, 5]\n assert candidate(items = [[5, 5], [5, 6], [5, 7], [5, 8], [5, 9]],queries = [1, 2, 3, 4, 5, 6]) == [0, 0, 0, 0, 9, 9]\n assert candidate(items = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(items = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 20, 30, 40, 50, 50, 50, 50, 50, 50]\n assert candidate(items = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996]],queries = [1, 2, 3, 4, 5]) == [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]\n assert candidate(items = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\n assert candidate(items = [[5, 20], [5, 18], [5, 16], [5, 14], [5, 12], [5, 10], [5, 8], [5, 6], [5, 4], [5, 2]],queries = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(items = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1], [2, 2], [2, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9], [6, 10]],queries = [2, 4, 6, 8, 10]) == [3, 7, 10, 10, 10]\n assert candidate(items = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],queries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(items = [[1, 1000000000], [1000000000, 1]],queries = [1, 1000000000]) == [1000000000, 1000000000]\n assert candidate(items = [[100, 500], [200, 400], [300, 300], [400, 200], [500, 100]],queries = [50, 150, 250, 350, 450, 550]) == [0, 500, 500, 500, 500, 500]\n assert candidate(items = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(items = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500], [60, 600], [70, 700], [80, 800], [90, 900], [100, 1000]],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(items = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]],queries = [1, 3, 5, 7, 9, 11]) == [100, 300, 500, 700, 900, 1000]\n assert candidate(items = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]],queries = [1, 5, 10, 15, 20, 25, 30]) == [1, 9, 19, 19, 19, 19, 19]\n assert candidate(items = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[3,2],[2,4],[5,6],[3,5]]\n[1,2,3,4,5,6]", "[[1,2],[1,2],[1,3],[1,4]]\n[1]", "[[10,1000]]\n[5]"], "hints": ["Can we process the queries in a smart order to avoid repeatedly checking the same items?", "How can we use the answer to a query for other queries?"], "metadata": {"canonical_parameter_names": ["items", "queries"], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:05+00:00", "tests_total": 106, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "binary-search", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maximumBeauty($items, $queries) {", "container": "Solution", "callable": "maximumBeauty", "parameters": [{"name": "items", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2071, "task_id": "maximum-number-of-tasks-you-can-assign", "difficulty": "Hard", "problem_description": "You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the i^th task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-indexed integer array workers, with the j^th worker having workers[j] strength. Each worker can only be assigned to a single task and must have a strength greater than or equal to the task's strength requirement (i.e., workers[j] >= tasks[i]).\n\nAdditionally, you have pills magical pills that will increase a worker's strength by strength. You can decide which workers receive the magical pills, however, you may only give each worker at most one magical pill.\n\nGiven the 0-indexed integer arrays tasks and workers and the integers pills and strength, return the maximum number of tasks that can be completed.\n\nExample 1:\n\nInput: tasks = [3,2,1], workers = [0,3,3], pills = 1, strength = 1\nOutput: 3\nExplanation:\nWe can assign the magical pill and tasks as follows:\n- Give the magical pill to worker 0.\n- Assign worker 0 to task 2 (0 + 1 >= 1)\n- Assign worker 1 to task 1 (3 >= 2)\n- Assign worker 2 to task 0 (3 >= 3)\n\nExample 2:\n\nInput: tasks = [5,4], workers = [0,0,0], pills = 1, strength = 5\nOutput: 1\nExplanation:\nWe can assign the magical pill and tasks as follows:\n- Give the magical pill to worker 0.\n- Assign worker 0 to task 0 (0 + 5 >= 5)\n\nExample 3:\n\nInput: tasks = [10,15,30], workers = [0,10,10,10,10], pills = 3, strength = 10\nOutput: 2\nExplanation:\nWe can assign the magical pills and tasks as follows:\n- Give the magical pill to worker 0 and worker 1.\n- Assign worker 0 to task 0 (0 + 10 >= 10)\n- Assign worker 1 to task 1 (10 + 10 >= 15)\nThe last pill is not given because it will not make any worker strong enough for the last task.\n\nConstraints:\n\n- n == tasks.length\n- m == workers.length\n- 1 <= n, m <= 5 * 10^4\n- 0 <= pills <= m\n- 0 <= tasks[i], workers[j], strength <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [100, 200, 300],workers = [50, 150, 250, 350],pills = 2,strength = 100) == 3\n assert candidate(tasks = [10, 20, 30],workers = [30, 40, 50],pills = 0,strength = 10) == 3\n assert candidate(tasks = [10, 15, 30],workers = [0, 10, 10, 10, 10],pills = 3,strength = 10) == 2\n assert candidate(tasks = [100, 200, 300],workers = [100, 100, 100, 100, 100],pills = 2,strength = 100) == 2\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [5, 5, 5, 5, 5],pills = 5,strength = 5) == 5\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [5, 5, 5, 5, 5],pills = 0,strength = 1) == 5\n assert candidate(tasks = [5, 5, 5, 5],workers = [1, 1, 1, 1],pills = 4,strength = 4) == 4\n assert candidate(tasks = [100, 200, 300],workers = [150, 250, 350],pills = 1,strength = 100) == 3\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [5, 5, 5, 5, 5],pills = 0,strength = 2) == 5\n assert candidate(tasks = [100, 200, 300],workers = [150, 250, 350],pills = 2,strength = 50) == 3\n assert candidate(tasks = [10, 20, 30, 40, 50],workers = [5, 15, 25, 35, 45],pills = 2,strength = 10) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [5, 5, 5, 5, 5],pills = 2,strength = 5) == 5\n assert candidate(tasks = [5, 4],workers = [0, 0, 0],pills = 1,strength = 5) == 1\n assert candidate(tasks = [10, 20, 30, 40, 50],workers = [1, 2, 3, 4, 5],pills = 5,strength = 10) == 1\n assert candidate(tasks = [10, 20, 30, 40, 50],workers = [5, 15, 25, 35, 45],pills = 0,strength = 10) == 4\n assert candidate(tasks = [9, 8, 7, 6, 5],workers = [4, 4, 4, 4, 4],pills = 5,strength = 5) == 5\n assert candidate(tasks = [3, 6, 7, 11],workers = [6, 8, 9],pills = 2,strength = 3) == 3\n assert candidate(tasks = [1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1],pills = 5,strength = 0) == 5\n assert candidate(tasks = [10, 20, 30, 40, 50],workers = [5, 15, 25, 35, 45],pills = 5,strength = 10) == 5\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [5, 5, 5, 5, 5],pills = 5,strength = 0) == 5\n assert candidate(tasks = [1, 1, 1, 1],workers = [1, 1, 1, 1],pills = 4,strength = 0) == 4\n assert candidate(tasks = [1, 10, 100, 1000],workers = [1, 10, 100, 1000],pills = 2,strength = 500) == 4\n assert candidate(tasks = [3, 2, 1],workers = [0, 3, 3],pills = 1,strength = 1) == 3\n assert candidate(tasks = [1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1],pills = 0,strength = 0) == 5\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],pills = 10,strength = 5) == 20\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pills = 0,strength = 1) == 10\n assert candidate(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],workers = [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],pills = 10,strength = 5) == 30\n assert candidate(tasks = [3, 6, 9, 12, 15],workers = [3, 6, 9, 12, 15],pills = 2,strength = 3) == 5\n assert candidate(tasks = [1000000000, 1000000000, 1000000000],workers = [1000000000, 1000000000, 1000000000],pills = 3,strength = 0) == 3\n assert candidate(tasks = [1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1],pills = 3,strength = 1) == 5\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],pills = 10,strength = 0) == 10\n assert candidate(tasks = [50, 100, 150, 200, 250],workers = [40, 80, 120, 160, 200],pills = 3,strength = 60) == 4\n assert candidate(tasks = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],pills = 5,strength = 20) == 11\n assert candidate(tasks = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],workers = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],pills = 5,strength = 1) == 10\n assert candidate(tasks = [100, 200, 300, 400, 500],workers = [100, 150, 200, 250, 300],pills = 2,strength = 100) == 4\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pills = 10,strength = 0) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 5,strength = 10) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [1, 1, 1, 1, 1],pills = 5,strength = 4) == 5\n assert candidate(tasks = [3, 6, 9, 12, 15],workers = [3, 6, 9, 12, 15],pills = 0,strength = 10) == 5\n assert candidate(tasks = [500000000, 500000000, 500000000, 500000000, 500000000],workers = [500000000, 500000000, 500000000, 500000000, 500000000],pills = 5,strength = 0) == 5\n assert candidate(tasks = [1, 3, 5, 7, 9],workers = [10, 20, 30, 40, 50],pills = 2,strength = 5) == 5\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pills = 5,strength = 0) == 10\n assert candidate(tasks = [1000000000],workers = [999999999],pills = 1,strength = 1) == 1\n assert candidate(tasks = [1, 2, 3, 4, 5],workers = [10, 20, 30, 40, 50],pills = 2,strength = 5) == 5\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950],pills = 5,strength = 100) == 9\n assert candidate(tasks = [1000, 2000, 3000],workers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],pills = 5,strength = 500) == 1\n assert candidate(tasks = [5, 15, 25, 35, 45],workers = [1, 11, 21, 31, 41],pills = 2,strength = 10) == 4\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],workers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],pills = 15,strength = 1) == 15\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 5,strength = 1) == 10\n assert candidate(tasks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],workers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],pills = 10,strength = 0) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],workers = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400],pills = 10,strength = 20) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pills = 10,strength = 0) == 10\n assert candidate(tasks = [1000, 2000, 3000, 4000, 5000],workers = [500, 1000, 1500, 2000, 2500],pills = 4,strength = 1000) == 3\n assert candidate(tasks = [10, 20, 30, 40, 50],workers = [10, 20, 30, 40, 50],pills = 0,strength = 0) == 5\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],workers = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145],pills = 7,strength = 50) == 15\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],pills = 5,strength = 5) == 10\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15],workers = [2, 4, 6, 8, 10, 12, 14, 16],pills = 3,strength = 2) == 8\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pills = 5,strength = 2) == 10\n assert candidate(tasks = [5, 10, 15, 20, 25, 30],workers = [10, 15, 20, 25, 30, 35],pills = 3,strength = 5) == 6\n assert candidate(tasks = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 3,strength = 5) == 10\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],pills = 5,strength = 50) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],pills = 5,strength = 10) == 20\n assert candidate(tasks = [100, 200, 300, 400, 500],workers = [150, 250, 350, 450, 550],pills = 3,strength = 100) == 5\n assert candidate(tasks = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 3,strength = 20) == 10\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],workers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pills = 5,strength = 1) == 10\n assert candidate(tasks = [5, 15, 25, 35, 45],workers = [1, 1, 1, 1, 1],pills = 5,strength = 40) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],pills = 10,strength = 4) == 10\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],pills = 5,strength = 50) == 10\n assert candidate(tasks = [50, 50, 50, 50, 50],workers = [100, 100, 100, 100, 100],pills = 2,strength = 10) == 5\n assert candidate(tasks = [500, 400, 300, 200, 100],workers = [100, 200, 300, 400, 500],pills = 2,strength = 100) == 5\n assert candidate(tasks = [100, 150, 200, 250, 300],workers = [50, 100, 150, 200, 250],pills = 2,strength = 50) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pills = 5,strength = 1) == 10\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],pills = 10,strength = 0) == 10\n assert candidate(tasks = [100, 200, 300, 400, 500],workers = [100, 200, 300, 400, 500],pills = 5,strength = 500) == 5\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 5,strength = 0) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],workers = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 7,strength = 3) == 15\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],workers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],pills = 5,strength = 0) == 10\n assert candidate(tasks = [999999999, 999999998, 999999997, 999999996, 999999995],workers = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],pills = 2,strength = 1) == 5\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 0,strength = 1) == 10\n assert candidate(tasks = [5, 25, 50, 75, 100],workers = [10, 20, 30, 40, 50],pills = 3,strength = 20) == 3\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pills = 0,strength = 0) == 10\n assert candidate(tasks = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 10,strength = 9) == 10\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],workers = [900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800],pills = 10,strength = 200) == 20\n assert candidate(tasks = [1, 5, 9, 13, 17, 21, 25],workers = [2, 6, 10, 14, 18, 22, 26],pills = 3,strength = 1) == 7\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 4,strength = 10) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pills = 5,strength = 1) == 10\n assert candidate(tasks = [500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],workers = [500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],pills = 3,strength = 200) == 11\n assert candidate(tasks = [1000, 2000, 3000, 4000, 5000],workers = [500, 1500, 2500, 3500, 4500],pills = 2,strength = 1000) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 10,strength = 1) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],pills = 5,strength = 1) == 10\n assert candidate(tasks = [1000000000, 1000000000],workers = [1000000000, 1000000000],pills = 1,strength = 0) == 2\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],pills = 10,strength = 10) == 10\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],pills = 5,strength = 10) == 2\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],workers = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],pills = 5,strength = 1) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],workers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 0,strength = 0) == 10\n assert candidate(tasks = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],workers = [20, 22, 24, 26, 28, 30, 32, 34, 36, 38],pills = 5,strength = 10) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],workers = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pills = 5,strength = 10) == 20\n assert candidate(tasks = [90, 80, 70, 60, 50, 40, 30, 20, 10],workers = [10, 20, 30, 40, 50, 60, 70, 80, 90],pills = 4,strength = 20) == 9\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],pills = 0,strength = 100) == 10\n assert candidate(tasks = [50, 60, 70, 80, 90],workers = [40, 50, 60, 70, 80],pills = 3,strength = 10) == 4\n assert candidate(tasks = [500, 500, 500, 500, 500],workers = [250, 250, 250, 250, 250],pills = 5,strength = 250) == 5\n assert candidate(tasks = [10, 10, 10, 10, 10],workers = [1, 1, 1, 1, 1],pills = 5,strength = 9) == 5\n assert candidate(tasks = [1000000000, 1000000000, 1000000000],workers = [1000000000, 1000000000, 1000000000],pills = 1,strength = 0) == 3\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950],pills = 5,strength = 50) == 9\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950],pills = 10,strength = 100) == 10\n assert candidate(tasks = [100, 200, 300, 400, 500, 600],workers = [100, 200, 300, 400, 500, 600],pills = 0,strength = 0) == 6\n assert candidate(tasks = [1000000000],workers = [1000000000],pills = 0,strength = 0) == 1\n assert candidate(tasks = [5, 15, 25, 35, 45, 55],workers = [10, 20, 30, 40, 50, 60],pills = 3,strength = 10) == 6\n assert candidate(tasks = [1000000000],workers = [1000000000],pills = 1,strength = 0) == 1\n assert candidate(tasks = [9, 8, 7, 6, 5, 4, 3, 2, 1],workers = [1, 2, 3, 4, 5, 6, 7, 8, 9],pills = 0,strength = 2) == 9\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],pills = 5,strength = 10) == 10\n assert candidate(tasks = [1, 3, 5, 7, 9],workers = [2, 4, 6, 8, 10],pills = 2,strength = 1) == 5\n assert candidate(tasks = [10000, 20000, 30000, 40000, 50000],workers = [1000, 2000, 3000, 4000, 5000],pills = 5,strength = 10000) == 1\n assert candidate(tasks = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],workers = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],pills = 5,strength = 5) == 9\n assert candidate(tasks = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],workers = [100, 200, 300, 400, 500],pills = 5,strength = 500) == 5\n assert candidate(tasks = [500000000, 500000000],workers = [500000000, 500000000],pills = 2,strength = 0) == 2\n assert candidate(tasks = [50, 100, 150, 200, 250],workers = [100, 150, 200, 250, 300],pills = 3,strength = 50) == 5\n assert candidate(tasks = [9, 18, 27, 36, 45, 54],workers = [12, 24, 36, 48, 60, 72],pills = 5,strength = 6) == 6\n assert candidate(tasks = [10, 10, 10, 10, 10],workers = [10, 10, 10, 10, 10],pills = 5,strength = 0) == 5\n", "comparison": "exact"}, "public_tests": ["[3,2,1]\n[0,3,3]\n1\n1", "[5,4]\n[0,0,0]\n1\n5", "[10,15,30]\n[0,10,10,10,10]\n3\n10"], "hints": ["Is it possible to assign the first k smallest tasks to the workers?", "How can you efficiently try every k?"], "metadata": {"canonical_parameter_names": ["tasks", "workers", "pills", "strength"], "leetcode_dataset_entry_point": "Solution().maxTaskAssign", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:08+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "greedy", "queue", "sorting", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function maxTaskAssign($tasks, $workers, $pills, $strength) {", "container": "Solution", "callable": "maxTaskAssign", "parameters": [{"name": "tasks", "type": "Integer[]"}, {"name": "workers", "type": "Integer[]"}, {"name": "pills", "type": "Integer"}, {"name": "strength", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2073, "task_id": "time-needed-to-buy-tickets", "difficulty": "Easy", "problem_description": "There are n people in a line queuing to buy tickets, where the 0^th person is at the front of the line and the (n - 1)^th person is at the back of the line.\n\nYou are given a 0-indexed integer array tickets of length n where the number of tickets that the i^th person would like to buy is tickets[i].\n\nEach person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line.\n\nReturn the time taken for the person initially at position k (0-indexed) to finish buying tickets.\n\nExample 1:\n\nInput: tickets = [2,3,2], k = 2\nOutput: 6\nExplanation:\n- The queue starts as [2,3,2], where the kth person is underlined.\n- After the person at the front has bought a ticket, the queue becomes [3,2,1] at 1 second.\n- Continuing this process, the queue becomes [2,1,2] at 2 seconds.\n- Continuing this process, the queue becomes [1,2,1] at 3 seconds.\n- Continuing this process, the queue becomes [2,1] at 4 seconds. Note: the person at the front left the queue.\n- Continuing this process, the queue becomes [1,1] at 5 seconds.\n- Continuing this process, the queue becomes [1] at 6 seconds. The kth person has bought all their tickets, so return 6.\n\nExample 2:\n\nInput: tickets = [5,1,1,1], k = 0\nOutput: 8\nExplanation:\n- The queue starts as [5,1,1,1], where the kth person is underlined.\n- After the person at the front has bought a ticket, the queue becomes [1,1,1,4] at 1 second.\n- Continuing this process for 3 seconds, the queue becomes [4] at 4 seconds.\n- Continuing this process for 4 seconds, the queue becomes [] at 8 seconds. The kth person has bought all their tickets, so return 8.\n\nConstraints:\n\n- n == tickets.length\n- 1 <= n <= 100\n- 1 <= tickets[i] <= 100\n- 0 <= k < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tickets = [5, 1, 1, 1],k = 0) == 8\n assert candidate(tickets = [4, 3, 2, 1],k = 1) == 9\n assert candidate(tickets = [100, 100, 100],k = 1) == 299\n assert candidate(tickets = [1],k = 0) == 1\n assert candidate(tickets = [10, 10, 10],k = 2) == 30\n assert candidate(tickets = [10, 10, 10],k = 0) == 28\n assert candidate(tickets = [10, 10, 10],k = 1) == 29\n assert candidate(tickets = [1, 2, 3, 4, 5],k = 4) == 15\n assert candidate(tickets = [2, 3, 2],k = 2) == 6\n assert candidate(tickets = [100, 100, 100],k = 2) == 300\n assert candidate(tickets = [1, 1, 1, 1],k = 2) == 3\n assert candidate(tickets = [1, 1, 1, 1],k = 1) == 2\n assert candidate(tickets = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 19) == 110\n assert candidate(tickets = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 10) == 59\n assert candidate(tickets = [9, 3, 5, 7, 1, 2, 6],k = 4) == 5\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 91\n assert candidate(tickets = [7, 2, 9, 1, 8, 3, 6, 4, 5],k = 6) == 39\n assert candidate(tickets = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],k = 15) == 86\n assert candidate(tickets = [1, 2, 3, 4, 5, 4, 3, 2, 1],k = 8) == 9\n assert candidate(tickets = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 15) == 76\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 91\n assert candidate(tickets = [25, 30, 15, 20, 10],k = 3) == 85\n assert candidate(tickets = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 44\n assert candidate(tickets = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 4) == 25\n assert candidate(tickets = [5, 2, 3, 1, 4],k = 2) == 11\n assert candidate(tickets = [5, 1, 2, 3, 4],k = 0) == 15\n assert candidate(tickets = [3, 1, 5, 4, 2],k = 3) == 14\n assert candidate(tickets = [7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 99\n assert candidate(tickets = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 10\n assert candidate(tickets = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 8) == 29\n assert candidate(tickets = [9, 3, 8, 4, 6, 7, 5, 2, 1],k = 1) == 19\n assert candidate(tickets = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 19) == 20\n assert candidate(tickets = [1, 5, 3, 4, 2, 6, 7, 8],k = 5) == 31\n assert candidate(tickets = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 15) == 28\n assert candidate(tickets = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2],k = 10) == 192\n assert candidate(tickets = [5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1],k = 19) == 20\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 0) == 81\n assert candidate(tickets = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4) == 395\n assert candidate(tickets = [1, 2, 3, 4, 3, 2, 1],k = 5) == 12\n assert candidate(tickets = [5, 3, 5, 2, 4, 1, 3],k = 3) == 11\n assert candidate(tickets = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4],k = 10) == 43\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 85\n assert candidate(tickets = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == 16\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == 45\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 9) == 90\n assert candidate(tickets = [1, 2, 3, 4, 5, 4, 3, 2, 1],k = 4) == 25\n assert candidate(tickets = [2, 6, 3, 4, 5, 1],k = 2) == 13\n assert candidate(tickets = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 10\n assert candidate(tickets = [20, 1, 20, 1, 20],k = 2) == 61\n assert candidate(tickets = [25, 30, 5, 10, 15],k = 1) == 85\n assert candidate(tickets = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 8) == 9\n assert candidate(tickets = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 4) == 35\n assert candidate(tickets = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 40\n assert candidate(tickets = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 45\n assert candidate(tickets = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 156\n assert candidate(tickets = [5, 4, 3, 2, 1],k = 0) == 15\n assert candidate(tickets = [4, 2, 3, 3, 1, 4, 2, 3],k = 5) == 22\n assert candidate(tickets = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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 = 50) == 104\n assert candidate(tickets = [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(tickets = [5, 6, 7, 8, 9],k = 2) == 30\n assert candidate(tickets = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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 = 49) == 162\n assert candidate(tickets = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 6\n assert candidate(tickets = [10, 15, 5, 20, 25, 30, 5],k = 4) == 104\n assert candidate(tickets = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 0) == 55\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 35\n assert candidate(tickets = [1, 5, 2, 3, 4, 5],k = 5) == 20\n assert candidate(tickets = [3, 1, 5, 2, 4, 6],k = 3) == 9\n assert candidate(tickets = [20, 15, 10, 5, 1],k = 0) == 51\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(tickets = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 19) == 20\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 41\n assert candidate(tickets = [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(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 156\n assert candidate(tickets = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 9) == 30\n assert candidate(tickets = [10, 1, 10, 1, 10, 1, 10],k = 3) == 4\n assert candidate(tickets = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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 = 0) == 163\n assert candidate(tickets = [10, 5, 4, 6, 3, 8, 2],k = 4) == 19\n assert candidate(tickets = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 55\n assert candidate(tickets = [2, 5, 3, 4, 1, 2],k = 2) == 13\n assert candidate(tickets = [10, 20, 30, 40, 50],k = 2) == 118\n assert candidate(tickets = [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, 8, 8, 8, 8, 8],k = 0) == 393\n assert candidate(tickets = [3, 2, 1, 4, 5, 6],k = 5) == 21\n assert candidate(tickets = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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) == 238\n assert candidate(tickets = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 5) == 36\n assert candidate(tickets = [20, 15, 10, 5, 1],k = 1) == 46\n assert candidate(tickets = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 9) == 10\n assert candidate(tickets = [3, 3, 3, 3, 3],k = 2) == 13\n assert candidate(tickets = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 96\n assert candidate(tickets = [50, 50, 50, 50, 50],k = 2) == 248\n assert candidate(tickets = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 7) == 38\n assert candidate(tickets = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],k = 9) == 110\n assert candidate(tickets = [7, 8, 9, 10, 11, 12, 13, 14],k = 5) == 79\n assert candidate(tickets = [3, 5, 2, 4, 1],k = 2) == 8\n assert candidate(tickets = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 24\n assert candidate(tickets = [1, 1, 1, 2, 2, 2, 3, 3, 3],k = 6) == 16\n assert candidate(tickets = [5, 4, 3, 2, 1],k = 2) == 12\n assert candidate(tickets = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 8) == 29\n assert candidate(tickets = [50, 30, 20, 10, 90, 80, 70, 60],k = 4) == 410\n", "comparison": "exact"}, "public_tests": ["[2,3,2]\n2", "[5,1,1,1]\n0"], "hints": ["Loop through the line of people and decrement the number of tickets for each to buy one at a time as if simulating the line moving forward. Keep track of how many tickets have been sold up until person k has no more tickets to buy.", "Remember that those who have no more tickets to buy will leave the line."], "metadata": {"canonical_parameter_names": ["tickets", "k"], "leetcode_dataset_entry_point": "Solution().timeRequiredToBuy", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:10+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function timeRequiredToBuy($tickets, $k) {", "container": "Solution", "callable": "timeRequiredToBuy", "parameters": [{"name": "tickets", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2075, "task_id": "decode-the-slanted-ciphertext", "difficulty": "Medium", "problem_description": "A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.\n\noriginalText is placed first in a top-left to bottom-right manner.\n\nThe blue cells are filled first, followed by the red cells, then the yellow cells, and so on, until we reach the end of originalText. The arrow indicates the order in which the cells are filled. All empty cells are filled with ' '. The number of columns is chosen such that the rightmost column will not be empty after filling in originalText.\n\nencodedText is then formed by appending all characters of the matrix in a row-wise fashion.\n\nThe characters in the blue cells are appended first to encodedText, then the red cells, and so on, and finally the yellow cells. The arrow indicates the order in which the cells are accessed.\n\nFor example, if originalText = \"cipher\" and rows = 3, then we encode it in the following manner:\n\nThe blue arrows depict how originalText is placed in the matrix, and the red arrows denote the order in which encodedText is formed. In the above example, encodedText = \"ch ie pr\".\n\nGiven the encoded string encodedText and number of rows rows, return the original string originalText.\n\nNote: originalText does not have any trailing spaces ' '. The test cases are generated such that there is only one possible originalText.\n\nExample 1:\n\nInput: encodedText = \"ch ie pr\", rows = 3\nOutput: \"cipher\"\nExplanation: This is the same example described in the problem description.\n\nExample 2:\n\nInput: encodedText = \"iveo eed l te olc\", rows = 4\nOutput: \"i love leetcode\"\nExplanation: The figure above denotes the matrix that was used to encode originalText.\nThe blue arrows show how we can find originalText from encodedText.\n\nExample 3:\n\nInput: encodedText = \"coding\", rows = 1\nOutput: \"coding\"\nExplanation: Since there is only 1 row, both originalText and encodedText are the same.\n\nConstraints:\n\n- 0 <= encodedText.length <= 10^6\n- encodedText consists of lowercase English letters and ' ' only.\n- encodedText is a valid encoding of some originalText that does not have trailing spaces.\n- 1 <= rows <= 1000\n- The testcases are generated such that there is only one possible originalText.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(encodedText = \"a\",rows = 1) == \"a\"\n assert candidate(encodedText = \"abcd efg hijk\",rows = 3) == \"aeibfjcgd\"\n assert candidate(encodedText = \"a b c d\",rows = 2) == \"a c b\"\n assert candidate(encodedText = \"coding\",rows = 1) == \"coding\"\n assert candidate(encodedText = \"abc def ghi jkl mno\",rows = 5) == \"adgbec\"\n assert candidate(encodedText = \"ab c de\",rows = 2) == \"a bd ec\"\n assert candidate(encodedText = \"ch ie pr\",rows = 3) == \"cipher\"\n assert candidate(encodedText = \"iveo eed l te olc\",rows = 4) == \"i love leetcode\"\n assert candidate(encodedText = \"python programming is fun\",rows = 4) == \"ppm yriftonuhggorn\"\n assert candidate(encodedText = \"algorithms and data structures\",rows = 5) == \"ah telmdrsgsauo trai\"\n assert candidate(encodedText = \"hello world from leetcode challenges\",rows = 6) == \"hrmt nel c gld ocl do fw\"\n assert candidate(encodedText = \"t a c o s e q u i r r e s e l l f o o d s o u p\",rows = 5) == \"t e s q f a s o u o c e u i o o l r s\"\n assert candidate(encodedText = \"one two three four five six\",rows = 3) == \"oh nrfeei ev e t wf oos ui rx\"\n assert candidate(encodedText = \"programming challenges are fun\",rows = 4) == \"pilrrneeogn g gfrceahm\"\n assert candidate(encodedText = \"filling the matrix in a slanted manner\",rows = 6) == \"f t aaitr nnlhi tnlexaei n g\"\n assert candidate(encodedText = \"p y trh e t s o n a\",rows = 3) == \"pe y t t nrs h\"\n assert candidate(encodedText = \"m e t a l l i c a\",rows = 3) == \"mai elc t\"\n assert candidate(encodedText = \"\",rows = 10) == \"\"\n assert candidate(encodedText = \"padding with spaces at the end \",rows = 5) == \"pwc aiet dtsh dh e i n g a s\"\n assert candidate(encodedText = \"a b c d e f g h i\",rows = 9) == \"abcd\"\n assert candidate(encodedText = \"qo su me ve rt\",rows = 5) == \"qsmvoue\"\n assert candidate(encodedText = \"sh jfuew xq z r e\",rows = 3) == \"sw h x jqrf u\"\n assert candidate(encodedText = \"this is a test string\",rows = 5) == \"ti ghstsi esa\"\n assert candidate(encodedText = \"abcdef ghijkl mnopqr stuvwx yz\",rows = 5) == \"agmsybhntzcioudjpekf\"\n assert candidate(encodedText = \"a quick brown fox jumps over the lazy dog\",rows = 6) == \"a fp z bostqrx uo iwc\"\n assert candidate(encodedText = \"wcy hmu eai xfi\",rows = 3) == \"wu c xy f ei ah\"\n assert candidate(encodedText = \"two words\",rows = 1) == \"two words\"\n assert candidate(encodedText = \"th qzih xof c \",rows = 3) == \"th h c x qoz\"\n assert candidate(encodedText = \"ab c d e f g h i j\",rows = 10) == \"a b ef d c\"\n assert candidate(encodedText = \"programming in python is fun\",rows = 3) == \"pgnr oiignsr apfmyumti\"\n assert candidate(encodedText = \"spaces in between words\",rows = 4) == \"s twpiwoanerc ede ns\"\n assert candidate(encodedText = \"qjewukcuvm xs ezmrg\",rows = 4) == \"qcsmju rev wmu\"\n assert candidate(encodedText = \"this is a longer example to test the decoding function\",rows = 8) == \"t epteharlei esle oi\"\n assert candidate(encodedText = \"q w e r t y u i o p\",rows = 4) == \"q y r w\"\n assert candidate(encodedText = \"a q o q r s\",rows = 6) == \"aqoq\"\n assert candidate(encodedText = \"abcdefghi jklmnop qrstuv wx yz\",rows = 5) == \"ahntybiouzc pvdj ekf\"\n assert candidate(encodedText = \"i s l a n d o f d r e a m s\",rows = 3) == \"i r s e o l a f a m n\"\n assert candidate(encodedText = \"s h e e l s s f i r e\",rows = 5) == \"se hls e\"\n assert candidate(encodedText = \"abc def ghi jkl mno pqr stu vwx yz\",rows = 6) == \"afjosb k cgl hd\"\n assert candidate(encodedText = \"hello world this is a test\",rows = 5) == \"hwtsteoh elri slls od\"\n assert candidate(encodedText = \"c o n s t a n t i n o p o l i s\",rows = 6) == \"csnno ott n\"\n assert candidate(encodedText = \"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\",rows = 5) == \"a l w g r b m x h s c n y i t d o j e\"\n assert candidate(encodedText = \"this is a test of the emergency broadcast system\",rows = 6) == \"t tedththnceieecamss ys te i mso\"\n assert candidate(encodedText = \"x w v u t s r q p o n m l k j i h g f e d c b a\",rows = 26) == \"x\"\n assert candidate(encodedText = \"keep it secret keep it safe\",rows = 6) == \"kicketre p\"\n assert candidate(encodedText = \"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\",rows = 26) == \"a\"\n assert candidate(encodedText = \"hello world from the other side\",rows = 4) == \"hr eeltrldh l esof rw\"\n assert candidate(encodedText = \"data structures and algorithms\",rows = 8) == \"d uast\"\n assert candidate(encodedText = \"abcdefghij klmnopqrst uvwxyz\",rows = 3) == \"a tbk cludmvenwfoxgpyhqi\"\n assert candidate(encodedText = \"singleword\",rows = 10) == \"s\"\n assert candidate(encodedText = \"the quick brown fox jumps over the lazy dog\",rows = 6) == \"tkfshdh o eoebxo r vqojuwi\"\n assert candidate(encodedText = \"thisisaverylongstringthatwillbereconstructedusingtheslantedciphertechnique\",rows = 7) == \"tlhcunehoaostcintniehsgwsndnisitgcstlrtarluvibenr\"\n assert candidate(encodedText = \"one\",rows = 1) == \"one\"\n assert candidate(encodedText = \"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\",rows = 5) == \"z o d t i y n c s h x m b r g w l q v\"\n assert candidate(encodedText = \"t h e q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g\",rows = 7) == \"tcnjohy hk uve ebfme d qropr uox i\"\n assert candidate(encodedText = \"abcdefgh ijklmnop qrstuvwx yz this is a test\",rows = 5) == \"ajs ibkt sclu dmv aenw foxtgp h\"\n assert candidate(encodedText = \"a quick movement of the enemy will jeopardize five gunboats\",rows = 7) == \"aofme b v yofoqet piumhwaieeicn kt\"\n assert candidate(encodedText = \"slantedtranspositioncipheriscomplexandfun\",rows = 7) == \"sdpoeltonarsnat\"\n assert candidate(encodedText = \"one two three four five six seven eight nine ten eleven twelve\",rows = 4) == \"oun nr ee el fietigvwvheoetn tsnthiiwrxnee eles ef\"\n assert candidate(encodedText = \"abcdefghij\",rows = 1) == \"abcdefghij\"\n assert candidate(encodedText = \"x y z \",rows = 3) == \"x zy\"\n assert candidate(encodedText = \"machine learning is fascinating\",rows = 7) == \"mnagaerc h\"\n assert candidate(encodedText = \"lqtk e o mu yzfe ot i g rya wne l oxtesn gdeo\",rows = 5) == \"luie q gtygldkz e frooeeyx aoo\"\n assert candidate(encodedText = \"p r o g r a m m i n g l a n g u a g e s\",rows = 5) == \"p n g a n r g e m g o m g\"\n assert candidate(encodedText = \"wecoloveleetcode\",rows = 2) == \"weeectocloodvee\"\n assert candidate(encodedText = \"example of a very long encoded text\",rows = 7) == \"e eon x rnca aygm po lfe\"\n assert candidate(encodedText = \"longer text with multiple spaces in between\",rows = 3) == \"lheo snm guielnrt ibtpeeltxewt e sewpi\"\n assert candidate(encodedText = \"it wof eit ss dp\",rows = 4) == \"iftst w\"\n assert candidate(encodedText = \"a b c d e\",rows = 5) == \"a b c\"\n assert candidate(encodedText = \"abcd efgh ijkl mnop qrst uvwx yz\",rows = 5) == \"ag rxbhms c ntdio je\"\n assert candidate(encodedText = \"the quick brown fox jumps over lazy dogs\",rows = 4) == \"trmzhopyews n dq ooufvgioescxrk\"\n assert candidate(encodedText = \"thisisaverylongtextthatneedstobeencodedusingaslantedtranspositioncipher\",rows = 8) == \"trtsdsaohyttelnilhodasoabuintesgnatv\"\n assert candidate(encodedText = \"spaces are handled correctly\",rows = 5) == \"s h tp a laancycrdoeels\"\n assert candidate(encodedText = \"f l e x i b l e r e s o u r c e s\",rows = 5) == \"fi oe lbrus ele x\"\n assert candidate(encodedText = \"t h e q u i c k b r o w n f o x j u m p s o v e r l a z y d o g s\",rows = 3) == \"t v n h e e r f o q l x u a i z j c y u k m d p b o s r g o\"\n assert candidate(encodedText = \"a b c d e f g h i\",rows = 9) == \"a de c b\"\n assert candidate(encodedText = \"python programming is fun\",rows = 3) == \"po ygitrsha omfnmu ip\"\n assert candidate(encodedText = \"spaces between words are preserved\",rows = 3) == \"sn p a c pewrsoe rs de srb ve et dwae\"\n assert candidate(encodedText = \"keep calm and code on\",rows = 2) == \"knede pc ocdael mo\"\n assert candidate(encodedText = \"abcdefgh ijklmnop qrstuv wxyz\",rows = 4) == \"a p bi wcjqxdkryelsfmg\"\n assert candidate(encodedText = \"decoding slanted transposition cipher is challenging\",rows = 7) == \"d si gestipcclrthoaaidnnitn\"\n assert candidate(encodedText = \"a quick brown fox jumps over the lazy dog\",rows = 3) == \"af otqxhu eij culkma pzbsyr oodwvn\"\n assert candidate(encodedText = \"the quick brown fox jumps over the lazy dog and then some more text to fill\",rows = 8) == \"tbj der hrutonefeomhg wpe sqns au lifocok\"\n assert candidate(encodedText = \"empty string test\",rows = 1) == \"empty string test\"\n assert candidate(encodedText = \"u p d o w n w i d e t h i n g s\",rows = 4) == \"uwdi pnen g dwt o\"\n assert candidate(encodedText = \"this is a test of the emergency broadcast system\",rows = 5) == \"tteythe isebsstmry eosiorasfg a\"\n assert candidate(encodedText = \"shorttext\",rows = 1) == \"shorttext\"\n assert candidate(encodedText = \"a quick brown fox jumps over the lazy dog\",rows = 5) == \"arjry ou qwmtdunphoi secf ko\"\n assert candidate(encodedText = \"a bcd efgh ijklm nopqrst uvwxy z\",rows = 5) == \"aekry fls gmtz h b nc d\"\n assert candidate(encodedText = \"one two three four five six seven eight nine ten\",rows = 4) == \"o x nf neosi uentrvew e ofnt i etvenheir e\"\n assert candidate(encodedText = \"a b c d e\",rows = 5) == \"abcd\"\n assert candidate(encodedText = \"thisisaverylongtextthatneedstobeencodedproperly\",rows = 6) == \"teeeerhrxenoiytdcsltsiohsna\"\n assert candidate(encodedText = \"the quick brown fox jumps over a lazy dog\",rows = 3) == \"tneh ref oaqx u lijacuzkmy p bsdr o\"\n assert candidate(encodedText = \"one two three four five six seven\",rows = 3) == \"oeene e s fitoxwu ors e v e ntfh\"\n assert candidate(encodedText = \"pythonprogramminglanguageisawesome\",rows = 5) == \"priuwyonaetggghrloan\"\n assert candidate(encodedText = \"sl yz vx qu tm\",rows = 4) == \"sz l\"\n assert candidate(encodedText = \"this is a long encoded text for testing\",rows = 7) == \"tsln fsh octoi noes gd a\"\n assert candidate(encodedText = \"abcdefghij klmnopqrst uvwxyz\",rows = 3) == \"a b ck dl emufnvgowhpxiqyjr\"\n assert candidate(encodedText = \"a quick brown fox jumps over the lazy dog\",rows = 4) == \"awsl n aq ozufvyioe cxrdk o jtbur\"\n assert candidate(encodedText = \"a b c d e\",rows = 5) == \"a b c\"\n assert candidate(encodedText = \"a bcd efgh ijklm nopqrst uvwxyz\",rows = 6) == \"a mqu r eibfc\"\n assert candidate(encodedText = \"a a a a a a a a a a\",rows = 10) == \"aaa\"\n assert candidate(encodedText = \"exampleofasingleword\",rows = 1) == \"exampleofasingleword\"\n assert candidate(encodedText = \"the quick brown fox jumps over lazy dogs\",rows = 5) == \"t xvdhb eoerjrg ou sqwmlunpi c\"\n assert candidate(encodedText = \"a very long text that is used to test the edge cases of the problem statement\",rows = 10) == \"ao ea ntut vghsee aerttye\"\n assert candidate(encodedText = \"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\",rows = 6) == \"ae n w j s f o xb k t g pc l hd\"\n assert candidate(encodedText = \"onewordonly\",rows = 1) == \"onewordonly\"\n assert candidate(encodedText = \"python is an interpreted high level general purpose programming language\",rows = 6) == \"piiepayngrrntthaoghe lguorl ranpepag rvumeieermstlp e adn\"\n assert candidate(encodedText = \"abcdefghijklmnopqrstuvwxyz\",rows = 10) == \"adb\"\n assert candidate(encodedText = \"abcdefghijklmnopqrstuvwxyz\",rows = 26) == \"a\"\n assert candidate(encodedText = \"slantedtranspositioncipherexample\",rows = 10) == \"strlea\"\n", "comparison": "exact"}, "public_tests": ["\"ch ie pr\"\n3", "\"iveo eed l te olc\"\n4", "\"coding\"\n1"], "hints": ["How can you use rows and encodedText to find the number of columns of the matrix?", "Once you have the number of rows and columns, you can create the matrix and place encodedText in it. How should you place it in the matrix?", "How should you traverse the matrix to \"decode\" originalText?"], "metadata": {"canonical_parameter_names": ["encodedText", "rows"], "leetcode_dataset_entry_point": "Solution().decodeCiphertext", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:15+00:00", "tests_total": 112, "tests_dropped": 1, "flags": ["figure_reference", "has_images"], "topic_tags": ["string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function decodeCiphertext($encodedText, $rows) {", "container": "Solution", "callable": "decodeCiphertext", "parameters": [{"name": "encodedText", "type": "String"}, {"name": "rows", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2076, "task_id": "process-restricted-friend-requests", "difficulty": "Hard", "problem_description": "You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.\n\nYou are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [x_i, y_i] means that person x_i and person y_i cannot become friends, either directly or indirectly through other people.\n\nInitially, no one is friends with each other. You are given a list of friend requests as a 0-indexed 2D integer array requests, where requests[j] = [u_j, v_j] is a friend request between person u_j and person v_j.\n\nA friend request is successful if u_j and v_j can be friends. Each friend request is processed in the given order (i.e., requests[j] occurs before requests[j + 1]), and upon a successful request, u_j and v_j become direct friends for all future friend requests.\n\nReturn a boolean array result, where each result[j] is true if the j^th friend request is successful or false if it is not.\n\nNote: If u_j and v_j are already direct friends, the request is still successful.\n\nExample 1:\n\nInput: n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]]\nOutput: [true,false]\nExplanation:\nRequest 0: Person 0 and person 2 can be friends, so they become direct friends.\nRequest 1: Person 2 and person 1 cannot be friends since person 0 and person 1 would be indirect friends (1--2--0).\n\nExample 2:\n\nInput: n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]]\nOutput: [true,false]\nExplanation:\nRequest 0: Person 1 and person 2 can be friends, so they become direct friends.\nRequest 1: Person 0 and person 2 cannot be friends since person 0 and person 1 would be indirect friends (0--2--1).\n\nExample 3:\n\nInput: n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,1],[3,4]]\nOutput: [true,false,true,false]\nExplanation:\nRequest 0: Person 0 and person 4 can be friends, so they become direct friends.\nRequest 1: Person 1 and person 2 cannot be friends since they are directly restricted.\nRequest 2: Person 3 and person 1 can be friends, so they become direct friends.\nRequest 3: Person 3 and person 4 cannot be friends since person 0 and person 1 would be indirect friends (0--4--3--1).\n\nConstraints:\n\n- 2 <= n <= 1000\n- 0 <= restrictions.length <= 1000\n- restrictions[i].length == 2\n- 0 <= x_i, y_i <= n - 1\n- x_i != y_i\n- 1 <= requests.length <= 1000\n- requests[j].length == 2\n- 0 <= u_j, v_j <= n - 1\n- u_j != v_j\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,restrictions = [[0, 2], [1, 3]],requests = [[0, 1], [2, 3], [0, 3]]) == [True, True, False]\n assert candidate(n = 4,restrictions = [],requests = [[0, 1], [1, 2], [2, 3], [3, 0]]) == [True, True, True, True]\n assert candidate(n = 4,restrictions = [[0, 2], [1, 3]],requests = [[0, 1], [2, 3], [1, 2]]) == [True, True, False]\n assert candidate(n = 5,restrictions = [[0, 1], [1, 2], [2, 3]],requests = [[0, 4], [1, 2], [3, 1], [3, 4]]) == [True, False, True, False]\n assert candidate(n = 6,restrictions = [[1, 4], [2, 5]],requests = [[0, 3], [1, 2], [3, 4]]) == [True, True, True]\n assert candidate(n = 6,restrictions = [[0, 1], [2, 3], [4, 5]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 0], [5, 1]]) == [True, True, True, True, True, True]\n assert candidate(n = 6,restrictions = [[0, 1], [2, 3], [4, 5]],requests = [[0, 2], [1, 3], [4, 5], [2, 4]]) == [True, True, False, True]\n assert candidate(n = 3,restrictions = [[0, 1]],requests = [[1, 2], [0, 2]]) == [True, False]\n assert candidate(n = 3,restrictions = [[0, 1]],requests = [[0, 2], [2, 1]]) == [True, False]\n assert candidate(n = 10,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],requests = [[0, 5], [2, 7], [4, 9], [1, 6]]) == [True, True, True, True]\n assert candidate(n = 12,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]],requests = [[0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11], [0, 5], [2, 7], [4, 9], [6, 11]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 7,restrictions = [[0, 6], [1, 5], [2, 4]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0]]) == [True, True, True, False, True, True, False]\n assert candidate(n = 20,restrictions = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19]],requests = [[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, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 10]]) == [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 9,restrictions = [[0, 3], [1, 4], [2, 5], [6, 8]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 0], [7, 1], [8, 2]]) == [True, True, False, True, True, True, True, False, True, True, False, False, True, True, True, False, False, True]\n assert candidate(n = 7,restrictions = [[0, 3], [1, 4], [2, 5], [3, 6], [4, 0], [5, 1], [6, 2]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0]]) == [True, True, False, True, True, False, False]\n assert candidate(n = 10,restrictions = [[0, 2], [1, 3], [4, 6], [5, 7], [8, 9]],requests = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 3], [5, 2], [6, 1], [7, 0], [8, 5], [9, 4]]) == [True, True, True, True, False, True, False, True, True, False, False, False, False, True, False]\n assert candidate(n = 15,restrictions = [[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]],requests = [[0, 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, 0], [14, 1]]) == [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False]\n assert candidate(n = 8,restrictions = [[0, 4], [1, 5], [2, 6], [3, 7]],requests = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 5]]) == [True, True, True, True, False]\n assert candidate(n = 10,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],requests = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [True, True, True, True, False]\n assert candidate(n = 8,restrictions = [[0, 7], [1, 6], [2, 5], [3, 4]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == [True, True, True, False, True, True, True, False]\n assert candidate(n = 9,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 0], [8, 1]],requests = [[0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 0], [6, 1], [7, 2], [8, 3]]) == [True, True, True, True, False, False, False, False, False]\n assert candidate(n = 12,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [True, True, True, True, True, True, True, True, True, True, False, False, False, False, False, False]\n assert candidate(n = 15,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 12], [12, 9], [13, 14], [14, 13]],requests = [[0, 3], [1, 4], [2, 0], [3, 1], [4, 2], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 5], [11, 6], [12, 7]]) == [True, True, False, False, False, False, True, True, True, False, True, True, True]\n assert candidate(n = 12,restrictions = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]],requests = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [0, 11]]) == [True, True, True, True, True, True, True]\n assert candidate(n = 8,restrictions = [[0, 4], [1, 5], [2, 6], [3, 7]],requests = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 5], [1, 6], [2, 7], [3, 4]]) == [True, True, True, True, True, True, True, True, False, False, False, False]\n assert candidate(n = 8,restrictions = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4]],requests = [[0, 4], [1, 5], [2, 6], [3, 7], [0, 5], [1, 6], [2, 7], [3, 4]]) == [True, True, True, True, False, False, False, False]\n assert candidate(n = 8,restrictions = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4]],requests = [[0, 4], [1, 5], [2, 6], [3, 7]]) == [True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],requests = [[0, 5], [2, 7], [4, 9], [1, 6], [3, 8]]) == [True, True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]],requests = [[0, 2], [1, 3], [4, 6], [5, 7], [8, 0], [9, 1]]) == [True, True, True, True, True, True]\n assert candidate(n = 7,restrictions = [[0, 3], [1, 4], [2, 5], [3, 6], [4, 0], [5, 1], [6, 2]],requests = [[0, 6], [1, 5], [2, 4], [3, 0], [4, 1], [5, 2], [6, 3]]) == [True, False, True, False, False, False, False]\n assert candidate(n = 15,restrictions = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14]],requests = [[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]]) == [True, True, True, True, False, True, True, True, True, False, True, True, True, True]\n assert candidate(n = 8,restrictions = [[0, 2], [1, 3], [4, 6], [5, 7]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 0], [6, 1], [7, 2]]) == [True, False, True, True, True, False, True, True, False, False, True, False, False, False, True, False]\n assert candidate(n = 15,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 0]],requests = [[0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14], [14, 1]]) == [True, True, True, True, True, True, False, True]\n assert candidate(n = 9,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [0, 8]],requests = [[0, 8], [1, 7], [2, 6], [3, 5], [4, 8], [0, 7], [1, 6], [2, 5], [3, 4]]) == [False, True, True, True, True, False, False, False, False]\n assert candidate(n = 10,restrictions = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 0]]) == [True, True, True, True, False, True, True, True, True, False, True, True, False, True, False]\n assert candidate(n = 10,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 0], [9, 1]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 15,restrictions = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14]],requests = [[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]]) == [True, True, True, True, False, True, True, True, True, False, True, True, True, True, True]\n assert candidate(n = 7,restrictions = [[0, 2], [1, 3], [4, 6]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0], [0, 3], [1, 4], [2, 5]]) == [True, False, True, True, True, False, True, False, False, True]\n assert candidate(n = 12,restrictions = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 6], [0, 7], [1, 8], [2, 9], [3, 10], [4, 11], [5, 6]]) == [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False, False, False, False]\n assert candidate(n = 10,restrictions = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]],requests = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [5, 0], [6, 1], [7, 2], [8, 3], [9, 4]]) == [True, True, False, True, True, False, False, False, False, False]\n assert candidate(n = 15,restrictions = [[0, 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, 0], [14, 1]],requests = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [7, 0]]) == [True, True, True, True, True, True, False, True]\n assert candidate(n = 12,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],requests = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 0], [7, 1], [8, 2], [9, 3], [10, 4], [11, 5]]) == [True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 7,restrictions = [[0, 2], [1, 3], [4, 6]],requests = [[0, 1], [2, 3], [4, 5], [5, 6], [0, 3], [2, 5]]) == [True, True, True, False, False, True]\n assert candidate(n = 9,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 0], [8, 1]]) == [True, True, True, True, True, True, False, False, False]\n assert candidate(n = 9,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 0]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 0], [8, 1], [0, 4]]) == [True, True, True, True, True, True, False, False, True, True]\n assert candidate(n = 15,restrictions = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]],requests = [[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, 13], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == [True, True, True, True, True, True, True, False, True, True, True, True, True, True, False, False, False, False, False, False, False, True]\n assert candidate(n = 5,restrictions = [[0, 2], [1, 3]],requests = [[0, 1], [2, 3], [1, 4], [3, 4]]) == [True, True, True, False]\n assert candidate(n = 7,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],requests = [[0, 6], [1, 5], [2, 4], [3, 0], [4, 1], [5, 2], [6, 3]]) == [True, True, True, True, False, False, True]\n assert candidate(n = 20,restrictions = [[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]],requests = [[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], [10, 15], [11, 16], [12, 17], [13, 18], [14, 19]]) == [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 1], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],requests = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [True, True, True, True, False]\n assert candidate(n = 8,restrictions = [[0, 1], [2, 3], [4, 5], [5, 6], [6, 7]],requests = [[0, 2], [1, 4], [3, 5], [5, 7], [0, 7], [4, 6]]) == [True, True, True, True, False, True]\n assert candidate(n = 15,restrictions = [[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]],requests = [[0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 0], [12, 1], [13, 2], [14, 3]]) == [True, True, True, True, True, True, True, True, True, True, True, False, False, False, False]\n assert candidate(n = 8,restrictions = [[0, 2], [1, 3], [4, 6], [5, 7]],requests = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 2], [1, 3], [4, 6], [5, 7], [0, 4], [2, 6], [1, 5], [3, 7], [0, 6], [2, 4], [1, 7], [3, 5]]) == [True, True, True, True, False, False, False, False, True, True, True, True, False, False, False, False]\n assert candidate(n = 7,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0]],requests = [[0, 3], [1, 4], [2, 5], [3, 6], [4, 0], [5, 1], [6, 2]]) == [True, True, True, False, False, False, False]\n assert candidate(n = 10,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],requests = [[0, 9], [1, 0], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6], [8, 7], [9, 8]]) == [False, False, False, False, False, False, False, False, False, False]\n assert candidate(n = 12,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],requests = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 0], [7, 1], [8, 2], [9, 3], [10, 4], [11, 5]]) == [True, True, True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]],requests = [[0, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == [True, True, True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == [True, True, True, True, False, True, True, True, True, False]\n assert candidate(n = 8,restrictions = [[0, 3], [1, 4], [2, 5], [3, 6], [4, 7]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [0, 7], [1, 6]]) == [True, True, True, True, True, True, False, False]\n assert candidate(n = 12,restrictions = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]],requests = [[0, 5], [1, 4], [2, 3], [6, 11], [7, 10], [8, 9], [0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [True, True, True, True, True, True, False, False, False, False, False, False]\n assert candidate(n = 10,restrictions = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 12,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]],requests = [[0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11], [0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [True, True, True, True, True, True, True, True, True, True, False, False]\n assert candidate(n = 11,restrictions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 0], [10, 1]]) == [True, True, True, True, True, True, True, True, True, False, False]\n assert candidate(n = 20,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19]],requests = [[0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11], [12, 14], [13, 15], [16, 18], [17, 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, False, False]\n assert candidate(n = 12,restrictions = [[0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 7], [1, 8], [2, 9], [3, 10], [4, 11], [5, 6]]) == [True, True, True, True, True, False, False, False, False, False, False]\n assert candidate(n = 15,restrictions = [[0, 7], [1, 8], [2, 9], [3, 10], [4, 11], [5, 12], [6, 13], [7, 14]],requests = [[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]]) == [True, True, True, True, True, True, False, True, True, True, True, True, True, False]\n assert candidate(n = 9,restrictions = [[0, 1], [2, 3], [4, 5], [6, 7]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 0], [8, 1], [0, 8], [1, 7], [2, 6], [3, 5], [4, 3], [5, 2], [6, 1], [7, 0], [8, 6], [0, 4], [1, 5], [2, 7], [3, 8]]) == [True, True, True, True, True, True, True, False, False, True, True, True, True, False, False, False, False, True, True, True, False, False]\n assert candidate(n = 12,restrictions = [[0, 3], [1, 4], [2, 5], [6, 9], [7, 10], [8, 11]],requests = [[0, 1], [1, 2], [3, 4], [4, 5], [6, 7], [7, 8], [9, 10], [10, 11], [0, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11]]) == [True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, False, False, True]\n assert candidate(n = 6,restrictions = [[0, 1], [2, 3], [4, 5]],requests = [[0, 2], [1, 3], [2, 4], [3, 5], [0, 5], [1, 4]]) == [True, True, True, True, False, False]\n assert candidate(n = 10,restrictions = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == [True, True, True, True, True, True, True, True, True, True]\n assert candidate(n = 10,restrictions = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]],requests = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == [True, True, True, True, False, True, True, True, True, False]\n assert candidate(n = 8,restrictions = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]],requests = [[0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [0, 1], [2, 3], [4, 5], [6, 7]]) == [True, True, True, True, True, False, False, False, False]\n", "comparison": "exact"}, "public_tests": ["3\n[[0,1]]\n[[0,2],[2,1]]", "3\n[[0,1]]\n[[1,2],[0,2]]", "5\n[[0,1],[1,2],[2,3]]\n[[0,4],[1,2],[3,1],[3,4]]"], "hints": ["For each request, we could loop through all restrictions. Can you think of doing a check-in close to O(1)?", "Could you use Union Find?"], "metadata": {"canonical_parameter_names": ["n", "restrictions", "requests"], "leetcode_dataset_entry_point": "Solution().friendRequests", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:17+00:00", "tests_total": 72, "tests_dropped": 0, "flags": [], "topic_tags": ["union-find", "graph"]}, "language": "php", "interface": {"raw_signature": "function friendRequests($n, $restrictions, $requests) {", "container": "Solution", "callable": "friendRequests", "parameters": [{"name": "n", "type": "Integer"}, {"name": "restrictions", "type": "Integer[][]"}, {"name": "requests", "type": "Integer[][]"}], "return_type": "Boolean[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2078, "task_id": "two-furthest-houses-with-different-colors", "difficulty": "Easy", "problem_description": "There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the i^th house.\n\nReturn the maximum distance between two houses with different colors.\n\nThe distance between the i^th and j^th houses is abs(i - j), where abs(x) is the absolute value of x.\n\nExample 1:\n\nInput: colors = [1,1,1,6,1,1,1]\nOutput: 3\nExplanation: In the above image, color 1 is blue, and color 6 is red.\nThe furthest two houses with different colors are house 0 and house 3.\nHouse 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3.\nNote that houses 3 and 6 can also produce the optimal answer.\n\nExample 2:\n\nInput: colors = [1,8,3,8,3]\nOutput: 4\nExplanation: In the above image, color 1 is blue, color 8 is yellow, and color 3 is green.\nThe furthest two houses with different colors are house 0 and house 4.\nHouse 0 has color 1, and house 4 has color 3. The distance between them is abs(0 - 4) = 4.\n\nExample 3:\n\nInput: colors = [0,1]\nOutput: 1\nExplanation: The furthest two houses with different colors are house 0 and house 1.\nHouse 0 has color 0, and house 1 has color 1. The distance between them is abs(0 - 1) = 1.\n\nConstraints:\n\n- n == colors.length\n- 2 <= n <= 100\n- 0 <= colors[i] <= 100\n- Test data are generated such that at least two houses have different colors.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(colors = [10, 20, 10, 10, 10]) == 3\n assert candidate(colors = [10, 20, 30, 40, 50]) == 4\n assert candidate(colors = [100, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 9\n assert candidate(colors = [3, 1, 3, 3, 3]) == 3\n assert candidate(colors = [1, 1, 1, 6, 1, 1, 1]) == 3\n assert candidate(colors = [1, 2, 3, 4, 5]) == 4\n assert candidate(colors = [5, 5, 5, 5, 1]) == 4\n assert candidate(colors = [5, 5, 5, 5, 5, 2]) == 5\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(colors = [7, 7, 7, 7, 7, 7, 7, 7, 7, 8]) == 9\n assert candidate(colors = [1, 1, 2, 1, 1]) == 2\n assert candidate(colors = [1, 1, 2, 1, 1, 1, 1]) == 4\n assert candidate(colors = [100, 99, 98, 97, 96, 95]) == 5\n assert candidate(colors = [2, 2, 2, 2, 3, 2]) == 4\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 2]) == 9\n assert candidate(colors = [0, 1]) == 1\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 9\n assert candidate(colors = [1, 1, 1, 1, 1, 2]) == 5\n assert candidate(colors = [1, 8, 3, 8, 3]) == 4\n assert candidate(colors = [1, 1, 2, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(colors = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 2]) == 7\n assert candidate(colors = [100, 0, 100, 100, 100]) == 3\n assert candidate(colors = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 9\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 2, 1]) == 8\n assert candidate(colors = [4, 4, 4, 4, 4, 4, 4, 4, 4, 2]) == 9\n assert candidate(colors = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == 18\n assert candidate(colors = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 0]) == 30\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, 1, 1, 1, 1, 2, 1]) == 33\n assert candidate(colors = [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, 2]) == 32\n assert candidate(colors = [2, 2, 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 32\n assert candidate(colors = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 57\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 55\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 20\n assert candidate(colors = [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]) == 29\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, 2]) == 21\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, 1, 1, 2]) == 31\n assert candidate(colors = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 71\n assert candidate(colors = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 29\n assert candidate(colors = [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]) == 29\n assert candidate(colors = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10]) == 20\n assert candidate(colors = [1, 1, 1, 1, 1, 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, 3]) == 52\n assert candidate(colors = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 77\n assert candidate(colors = [10, 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, 10]) == 54\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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]) == 80\n assert candidate(colors = [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, 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, 35]) == 81\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 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]) == 59\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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(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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 77\n assert candidate(colors = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 19\n assert candidate(colors = [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]) == 21\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, 1, 1, 1, 1, 1, 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(colors = [7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 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, 9]) == 75\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 17\n assert candidate(colors = [1, 1, 1, 1, 2, 1, 1, 1, 1, 1]) == 5\n assert candidate(colors = [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, 1]) == 29\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 52\n assert candidate(colors = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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]) == 55\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\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, 1, 1, 1, 1, 1, 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(colors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1]) == 19\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, 1, 1, 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]) == 55\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 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, 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]) == 90\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 19\n assert candidate(colors = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 99\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6]) == 56\n assert candidate(colors = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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]) == 75\n assert candidate(colors = [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, 34, 34, 34, 34, 34, 34, 34, 34, 35]) == 56\n assert candidate(colors = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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]) == 77\n assert candidate(colors = [1, 2, 2, 2, 2, 2, 2, 2, 2, 1]) == 8\n assert candidate(colors = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(colors = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1]) == 53\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5]) == 10\n assert candidate(colors = [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]) == 45\n assert candidate(colors = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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]) == 52\n assert candidate(colors = [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]) == 68\n assert candidate(colors = [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, 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]) == 78\n assert candidate(colors = [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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2]) == 78\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 17\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 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]) == 30\n assert candidate(colors = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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]) == 77\n assert candidate(colors = [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1]) == 5\n assert candidate(colors = [100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100]) == 29\n assert candidate(colors = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 0]) == 71\n assert candidate(colors = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9\n assert candidate(colors = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 11\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]) == 87\n assert candidate(colors = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1]) == 19\n assert candidate(colors = [1, 2, 3, 4, 5, 6, 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]) == 49\n", "comparison": "exact"}, "public_tests": ["[1,1,1,6,1,1,1]", "[1,8,3,8,3]", "[0,1]"], "hints": ["The constraints are small. Can you try the combination of every two houses?", "Greedily, the maximum distance will come from either the pair of the leftmost house and possibly some house on the right with a different color, or the pair of the rightmost house and possibly some house on the left with a different color."], "metadata": {"canonical_parameter_names": ["colors"], "leetcode_dataset_entry_point": "Solution().maxDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:22+00:00", "tests_total": 90, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maxDistance($colors) {", "container": "Solution", "callable": "maxDistance", "parameters": [{"name": "colors", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2079, "task_id": "watering-plants", "difficulty": "Medium", "problem_description": "You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.\n\nEach plant needs a specific amount of water. You will water the plants in the following way:\n\n- Water the plants in order from left to right.\n- After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.\n- You cannot refill the watering can early.\n\nYou are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.\n\nGiven a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the i^th plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.\n\nExample 1:\n\nInput: plants = [2,2,3,3], capacity = 5\nOutput: 14\nExplanation: Start at the river with a full watering can:\n- Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.\n- Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.\n- Since you cannot completely water plant 2, walk back to the river to refill (2 steps).\n- Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.\n- Since you cannot completely water plant 3, walk back to the river to refill (3 steps).\n- Walk to plant 3 (4 steps) and water it.\nSteps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.\n\nExample 2:\n\nInput: plants = [1,1,1,4,2,3], capacity = 4\nOutput: 30\nExplanation: Start at the river with a full watering can:\n- Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).\n- Water plant 3 (4 steps). Return to river (4 steps).\n- Water plant 4 (5 steps). Return to river (5 steps).\n- Water plant 5 (6 steps).\nSteps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.\n\nExample 3:\n\nInput: plants = [7,7,7,7,7,7,7], capacity = 8\nOutput: 49\nExplanation: You have to refill before watering each plant.\nSteps needed = 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 = 49.\n\nConstraints:\n\n- n == plants.length\n- 1 <= n <= 1000\n- 1 <= plants[i] <= 10^6\n- max(plants[i]) <= capacity <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(plants = [1000000],capacity = 1000000) == 1\n assert candidate(plants = [3, 2, 4, 2, 1],capacity = 6) == 17\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacity = 1) == 100\n assert candidate(plants = [5, 5, 5, 5, 5],capacity = 5) == 25\n assert candidate(plants = [10, 10, 10],capacity = 10) == 9\n assert candidate(plants = [1, 1, 1, 4, 2, 3],capacity = 4) == 30\n assert candidate(plants = [1, 2, 3, 4, 5],capacity = 10) == 13\n assert candidate(plants = [1, 2, 3],capacity = 6) == 3\n assert candidate(plants = [5, 8, 6],capacity = 10) == 9\n assert candidate(plants = [1, 1, 1, 1, 1],capacity = 5) == 5\n assert candidate(plants = [2, 2, 3, 3],capacity = 5) == 14\n assert candidate(plants = [3, 2, 4, 2, 1],capacity = 4) == 17\n assert candidate(plants = [7, 7, 7, 7, 7, 7, 7],capacity = 8) == 49\n assert candidate(plants = [2, 4, 5, 1, 2],capacity = 6) == 17\n assert candidate(plants = [10],capacity = 10) == 1\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 15) == 146\n assert candidate(plants = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacity = 5) == 961\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 25) == 242\n assert candidate(plants = [9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 10) == 41\n assert candidate(plants = [2, 3, 2, 1, 4, 2, 1, 3, 2, 1, 4, 2, 1],capacity = 6) == 77\n assert candidate(plants = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],capacity = 3) == 138\n assert candidate(plants = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacity = 50) == 88\n assert candidate(plants = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacity = 10) == 362\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 10) == 200\n assert candidate(plants = [2, 4, 5, 1, 2],capacity = 5) == 17\n assert candidate(plants = [7, 2, 5, 9, 3, 8, 4, 6, 1, 1, 1, 1],capacity = 15) == 42\n assert candidate(plants = [1, 3, 2, 4, 2, 1, 3, 2, 1, 4, 2, 1],capacity = 5) == 78\n assert candidate(plants = [5, 8, 6, 10, 2, 1, 1, 1, 1, 1],capacity = 12) == 32\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = 20) == 152\n assert candidate(plants = [2, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8],capacity = 12) == 71\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 10) == 54\n assert candidate(plants = [9, 1, 5, 3, 7, 8, 4, 2],capacity = 10) == 42\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],capacity = 20) == 213\n assert candidate(plants = [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],capacity = 30) == 2881\n assert candidate(plants = [2, 4, 6, 8, 10],capacity = 10) == 23\n assert candidate(plants = [1000000, 500000, 1000000, 500000, 1000000, 500000],capacity = 1000000) == 36\n assert candidate(plants = [100, 200, 300, 400, 500],capacity = 1000) == 13\n assert candidate(plants = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],capacity = 3) == 900\n assert candidate(plants = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],capacity = 150) == 68\n assert candidate(plants = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacity = 15) == 4499\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = 10) == 88\n assert candidate(plants = [1, 3, 2, 5, 4, 3, 2, 1],capacity = 5) == 50\n assert candidate(plants = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],capacity = 3) == 400\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = 18) == 52\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 10) == 249\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacity = 15) == 68\n assert candidate(plants = [9, 1, 2, 3, 4, 5, 6, 7, 8],capacity = 10) == 65\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 10) == 200\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],capacity = 20) == 88\n assert candidate(plants = [5, 8, 6, 7, 4, 9],capacity = 12) == 28\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 4) == 400\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 5) == 84\n assert candidate(plants = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],capacity = 5) == 200\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 25) == 180\n assert candidate(plants = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],capacity = 15) == 225\n assert candidate(plants = [2, 4, 6, 8, 10],capacity = 12) == 19\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 10) == 127\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 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 = 2) == 511\n assert candidate(plants = [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],capacity = 4) == 407\n assert candidate(plants = [5, 8, 6, 7, 9, 4, 2],capacity = 10) == 37\n assert candidate(plants = [7, 3, 5, 8, 10, 2, 6, 4, 9, 1],capacity = 15) == 52\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],capacity = 20) == 78\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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) == 6724\n assert candidate(plants = [7, 3, 6, 2, 5, 4, 9, 1, 8],capacity = 12) == 49\n assert candidate(plants = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],capacity = 15) == 126\n assert candidate(plants = [100, 200, 100],capacity = 150) == 9\n assert candidate(plants = [100, 200, 300, 400, 500],capacity = 1000) == 13\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 15) == 38\n assert candidate(plants = [100, 200, 300, 400, 500],capacity = 500) == 23\n assert candidate(plants = [5, 8, 6, 10, 2, 9, 4],capacity = 12) == 41\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 5) == 2878\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 10) == 10082\n assert candidate(plants = [1000000, 1000000, 1000000],capacity = 1000000) == 9\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 10) == 249\n assert candidate(plants = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacity = 10) == 146\n assert candidate(plants = [9, 8, 7, 6, 5, 4, 3, 2, 1],capacity = 5) == 67\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacity = 15) == 46\n assert candidate(plants = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],capacity = 14) == 200\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacity = 25) == 296\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],capacity = 20) == 177\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacity = 15) == 368\n assert candidate(plants = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],capacity = 14) == 200\n assert candidate(plants = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],capacity = 10) == 276\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 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) == 900\n", "comparison": "exact"}, "public_tests": ["[2,2,3,3]\n5", "[1,1,1,4,2,3]\n4", "[7,7,7,7,7,7,7]\n8"], "hints": ["Simulate the process.", "Return to refill the container once you meet a plant that needs more water than you have."], "metadata": {"canonical_parameter_names": ["plants", "capacity"], "leetcode_dataset_entry_point": "Solution().wateringPlants", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:24+00:00", "tests_total": 84, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function wateringPlants($plants, $capacity) {", "container": "Solution", "callable": "wateringPlants", "parameters": [{"name": "plants", "type": "Integer[]"}, {"name": "capacity", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2081, "task_id": "sum-of-k-mirror-numbers", "difficulty": "Hard", "problem_description": "A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.\n\n- For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.\n- On the contrary, 4 is not a 2-mirror number. The representation of 4 in base-2 is 100, which does not read the same both forward and backward.\n\nGiven the base k and the number n, return the sum of the n smallest k-mirror numbers.\n\nExample 1:\n\nInput: k = 2, n = 5\nOutput: 25\nExplanation:\nThe 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows:\n base-10 base-2\n 1 1\n 3 11\n 5 101\n 7 111\n 9 1001\nTheir sum = 1 + 3 + 5 + 7 + 9 = 25.\n\nExample 2:\n\nInput: k = 3, n = 7\nOutput: 499\nExplanation:\nThe 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows:\n base-10 base-3\n 1 1\n 2 2\n 4 11\n 8 22\n 121 11111\n 151 12121\n 212 21212\nTheir sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.\n\nExample 3:\n\nInput: k = 7, n = 17\nOutput: 20379000\nExplanation: The 17 smallest 7-mirror numbers are:\n1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596\n\nConstraints:\n\n- 2 <= k <= 9\n- 1 <= n <= 30\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(k = 2,n = 1) == 1\n assert candidate(k = 5,n = 8) == 638\n assert candidate(k = 8,n = 15) == 5818\n assert candidate(k = 9,n = 5) == 15\n assert candidate(k = 9,n = 6) == 21\n assert candidate(k = 8,n = 9) == 158\n assert candidate(k = 4,n = 8) == 1498\n assert candidate(k = 9,n = 30) == 18627530\n assert candidate(k = 2,n = 10) == 1772\n assert candidate(k = 4,n = 10) == 3224\n assert candidate(k = 3,n = 7) == 499\n assert candidate(k = 5,n = 10) == 1940\n assert candidate(k = 9,n = 10) == 509\n assert candidate(k = 9,n = 20) == 156242\n assert candidate(k = 4,n = 15) == 233041\n assert candidate(k = 6,n = 12) == 1297\n assert candidate(k = 8,n = 20) == 94182\n assert candidate(k = 3,n = 5) == 136\n assert candidate(k = 5,n = 15) == 20526195\n assert candidate(k = 2,n = 5) == 25\n assert candidate(k = 2,n = 30) == 2609044274\n assert candidate(k = 7,n = 17) == 20379000\n assert candidate(k = 7,n = 28) == 115121130305\n assert candidate(k = 5,n = 25) == 6849225412\n assert candidate(k = 3,n = 20) == 2863752\n assert candidate(k = 8,n = 28) == 7054305\n assert candidate(k = 9,n = 15) == 3203\n assert candidate(k = 5,n = 20) == 1000828708\n assert candidate(k = 7,n = 15) == 6822448\n assert candidate(k = 6,n = 25) == 7009551\n assert candidate(k = 8,n = 25) == 1651182\n assert candidate(k = 6,n = 30) == 28888231\n assert candidate(k = 2,n = 25) == 20005383\n assert candidate(k = 6,n = 28) == 19806423\n assert candidate(k = 4,n = 22) == 22726545\n assert candidate(k = 9,n = 29) == 16185088\n assert candidate(k = 5,n = 28) == 19101218022\n assert candidate(k = 9,n = 27) == 11349704\n assert candidate(k = 8,n = 17) == 27727\n assert candidate(k = 6,n = 15) == 4383\n assert candidate(k = 5,n = 30) == 43401017264\n assert candidate(k = 4,n = 28) == 721411086\n assert candidate(k = 3,n = 28) == 44192979\n assert candidate(k = 4,n = 20) == 12448815\n assert candidate(k = 9,n = 25) == 7586042\n assert candidate(k = 7,n = 19) == 91104965\n assert candidate(k = 9,n = 28) == 13750746\n assert candidate(k = 2,n = 28) == 759196316\n assert candidate(k = 4,n = 25) == 38898160\n assert candidate(k = 6,n = 20) == 156389\n assert candidate(k = 3,n = 30) == 155059889\n assert candidate(k = 8,n = 18) == 41058\n assert candidate(k = 7,n = 20) == 321578997\n assert candidate(k = 7,n = 25) == 3428700695\n assert candidate(k = 8,n = 30) == 66619574\n assert candidate(k = 6,n = 18) == 41849\n assert candidate(k = 7,n = 30) == 241030621167\n", "comparison": "exact"}, "public_tests": ["2\n5", "3\n7", "7\n17"], "hints": ["Since we need to reduce search space, instead of checking if every number is a palindrome in base-10, can we try to \"generate\" the palindromic numbers?", "If you are provided with a d digit number, how can you generate a palindrome with 2*d or 2*d - 1 digit?", "Try brute-forcing and checking if the palindrome you generated is a \"k-Mirror\" number."], "metadata": {"canonical_parameter_names": ["k", "n"], "leetcode_dataset_entry_point": "Solution().kMirror", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:26+00:00", "tests_total": 59, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function kMirror($k, $n) {", "container": "Solution", "callable": "kMirror", "parameters": [{"name": "k", "type": "Integer"}, {"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2085, "task_id": "count-common-words-with-one-occurrence", "difficulty": "Easy", "problem_description": "Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.\n\nExample 1:\n\nInput: words1 = [\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"], words2 = [\"amazing\",\"leetcode\",\"is\"]\nOutput: 2\nExplanation:\n- \"leetcode\" appears exactly once in each of the two arrays. We count this string.\n- \"amazing\" appears exactly once in each of the two arrays. We count this string.\n- \"is\" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.\n- \"as\" appears once in words1, but does not appear in words2. We do not count this string.\nThus, there are 2 strings that appear exactly once in each of the two arrays.\n\nExample 2:\n\nInput: words1 = [\"b\",\"bb\",\"bbb\"], words2 = [\"a\",\"aa\",\"aaa\"]\nOutput: 0\nExplanation: There are no strings that appear in each of the two arrays.\n\nExample 3:\n\nInput: words1 = [\"a\",\"ab\"], words2 = [\"a\",\"a\",\"a\",\"ab\"]\nOutput: 1\nExplanation: The only string that appears exactly once in each of the two arrays is \"ab\".\n\nConstraints:\n\n- 1 <= words1.length, words2.length <= 1000\n- 1 <= words1[i].length, words2[j].length <= 30\n- words1[i] and words2[j] consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words1 = ['one'],words2 = ['two']) == 0\n assert candidate(words1 = ['unique'],words2 = ['unique']) == 1\n assert candidate(words1 = ['b', 'bb', 'bbb'],words2 = ['a', 'aa', 'aaa']) == 0\n assert candidate(words1 = ['distinct'],words2 = ['distinct', 'distinct']) == 0\n assert candidate(words1 = ['a', 'b', 'c'],words2 = ['c', 'b', 'a']) == 3\n assert candidate(words1 = ['same', 'same'],words2 = ['same', 'same', 'same']) == 0\n assert candidate(words1 = ['a', 'ab'],words2 = ['a', 'a', 'a', 'ab']) == 1\n assert candidate(words1 = ['hello', 'world'],words2 = ['hello', 'world', 'hello']) == 1\n assert candidate(words1 = ['hello', 'world'],words2 = ['hello', 'world']) == 2\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'apple', 'date']) == 2\n assert candidate(words1 = ['leetcode', 'is', 'amazing', 'as', 'is'],words2 = ['amazing', 'leetcode', 'is']) == 2\n assert candidate(words1 = ['repeat', 'repeat'],words2 = ['repeat', 'repeat']) == 0\n assert candidate(words1 = ['abc', 'def', 'ghi', 'jkl'],words2 = ['def', 'ghi', 'jkl', 'mno', 'pqr', 'abc', 'def', 'ghi', 'jkl']) == 1\n assert candidate(words1 = ['alpha', 'beta', 'gamma', 'delta'],words2 = ['delta', 'gamma', 'beta', 'alpha', 'alpha', 'beta', 'gamma', 'delta']) == 0\n assert candidate(words1 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],words2 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z']) == 0\n assert candidate(words1 = ['one', 'two', 'three', 'four', 'five'],words2 = ['two', 'three', 'four', 'five', 'six', 'seven', 'eight']) == 4\n assert candidate(words1 = ['hello', 'world', 'hello'],words2 = ['world', 'hello', 'hello', 'world']) == 0\n assert candidate(words1 = ['cat', 'dog', 'bird', 'fish'],words2 = ['cat', 'dog', 'bird', 'fish', 'dog', 'bird']) == 2\n assert candidate(words1 = ['hello', 'hello', 'world'],words2 = ['hello', 'world', 'world', 'world']) == 0\n assert candidate(words1 = ['cat', 'dog', 'fish'],words2 = ['dog', 'cat', 'bird', 'fish', 'dog', 'fish']) == 1\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e'],words2 = ['f', 'g', 'h', 'i', 'j']) == 0\n assert candidate(words1 = ['alpha', 'beta', 'gamma', 'delta'],words2 = ['alpha', 'beta', 'gamma', 'delta', 'delta']) == 3\n assert candidate(words1 = ['one', 'two', 'three', 'four', 'five', 'six'],words2 = ['three', 'four', 'seven', 'eight', 'nine', 'one', 'two']) == 4\n assert candidate(words1 = ['one', 'two', 'three', 'four'],words2 = ['four', 'three', 'two', 'one', 'one', 'two', 'three', 'four', 'four', 'three', 'two', 'one']) == 0\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],words2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 0\n assert candidate(words1 = ['same', 'word', 'multiple'],words2 = ['same', 'word', 'multiple', 'same', 'word', 'multiple']) == 0\n assert candidate(words1 = ['test', 'case', 'one'],words2 = ['case', 'test', 'one', 'one', 'test', 'case']) == 0\n assert candidate(words1 = ['same', 'word', 'repeated'],words2 = ['same', 'word', 'repeated', 'same', 'word', 'repeated']) == 0\n assert candidate(words1 = ['hello', 'world', 'hello', 'world'],words2 = ['hello', 'world', 'hello', 'world', 'hello', 'world']) == 0\n assert candidate(words1 = ['x', 'y', 'z'],words2 = ['x', 'y', 'z', 'x', 'y', 'z']) == 0\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],words2 = ['a', 'b', 'b', 'c', 'd', 'd', 'e', 'f', 'f', 'g']) == 4\n assert candidate(words1 = ['car', 'truck', 'bus', 'van', 'car', 'truck'],words2 = ['bus', 'van', 'motorcycle', 'bicycle', 'bus', 'van', 'truck']) == 0\n assert candidate(words1 = ['cat', 'dog', 'fish', 'bird'],words2 = ['dog', 'cat', 'cat', 'fish', 'dog', 'bird']) == 2\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e'],words2 = ['f', 'g', 'h', 'i', 'j', 'a', 'b', 'c', 'd', 'e']) == 5\n assert candidate(words1 = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],words2 = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']) == 0\n assert candidate(words1 = ['same', 'word', 'repeated', 'multiple', 'times'],words2 = ['times', 'repeated', 'multiple', 'same', 'word', 'word']) == 4\n assert candidate(words1 = ['one', 'two', 'three', 'four'],words2 = ['four', 'three', 'two', 'one', 'one', 'two', 'three', 'four']) == 0\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'apple', 'cherry', 'apple']) == 2\n assert candidate(words1 = ['a', 'b', 'c', 'd'],words2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 4\n assert candidate(words1 = ['a', 'b', 'c', 'd'],words2 = ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd']) == 0\n assert candidate(words1 = ['x', 'y', 'z', 'w', 'v'],words2 = ['x', 'y', 'z', 'w', 'v', 'x', 'y', 'z', 'w', 'v', 'x', 'y', 'z', 'w', 'v', 'x', 'y', 'z', 'w', 'v']) == 0\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e'],words2 = ['e', 'd', 'c', 'b', 'a', 'a', 'b', 'c', 'd', 'e']) == 0\n assert candidate(words1 = ['unique', 'words', 'only', 'once', 'here'],words2 = ['words', 'only', 'once', 'here', 'unique', 'twice', 'unique']) == 4\n assert candidate(words1 = ['x', 'y', 'z'],words2 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z']) == 0\n assert candidate(words1 = ['cat', 'dog', 'elephant', 'frog', 'cat'],words2 = ['dog', 'frog', 'giraffe', 'elephant', 'hippo']) == 3\n assert candidate(words1 = ['cat', 'dog', 'fish'],words2 = ['fish', 'dog', 'cat', 'dog', 'cat']) == 1\n assert candidate(words1 = ['python', 'java', 'c', 'cpp'],words2 = ['python', 'java', 'java', 'csharp']) == 1\n assert candidate(words1 = ['unique', 'words', 'only', 'here'],words2 = ['here', 'only', 'words', 'unique', 'unique']) == 3\n assert candidate(words1 = ['hello', 'world', 'hello'],words2 = ['world', 'hello', 'world', 'hello', 'world', 'hello']) == 0\n assert candidate(words1 = ['hello', 'world', 'python', 'java', 'csharp'],words2 = ['python', 'java', 'csharp', 'hello', 'ruby', 'scala', 'world', 'python', 'java']) == 3\n assert candidate(words1 = ['x', 'y', 'z'],words2 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z']) == 0\n assert candidate(words1 = ['unique', 'word', 'only', 'in', 'this', 'array'],words2 = ['unique', 'only', 'word', 'in', 'that', 'array']) == 5\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'cherry', 'apple', 'apple']) == 2\n assert candidate(words1 = ['apple', 'banana', 'cherry', 'date'],words2 = ['banana', 'cherry', 'fig', 'grape']) == 2\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'apple', 'apple', 'cherry', 'date']) == 2\n assert candidate(words1 = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abc'],words2 = ['mno', 'pqr', 'stu', 'vwx', 'yz', 'abc', 'def', 'ghi', 'jkl', 'mno']) == 7\n assert candidate(words1 = ['apple', 'banana', 'cherry', 'date'],words2 = ['banana', 'date', 'fig', 'grape', 'apple']) == 3\n assert candidate(words1 = ['apple', 'banana', 'cherry', 'date', 'elderberry'],words2 = ['banana', 'cherry', 'elderberry', 'fig', 'grape', 'apple', 'date']) == 5\n assert candidate(words1 = ['a', 'b', 'c', 'a', 'b', 'c'],words2 = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']) == 0\n assert candidate(words1 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z'],words2 = ['x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z', 'x', 'y', 'z']) == 0\n assert candidate(words1 = ['sun', 'moon', 'star', 'planet', 'sun', 'moon'],words2 = ['star', 'planet', 'comet', 'asteroid', 'planet', 'star']) == 0\n assert candidate(words1 = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'],words2 = ['gamma', 'delta', 'zeta', 'eta', 'theta', 'epsilon', 'delta']) == 2\n assert candidate(words1 = ['python', 'java', 'csharp'],words2 = ['java', 'csharp', 'python', 'python']) == 2\n assert candidate(words1 = ['cat', 'dog', 'mouse'],words2 = ['dog', 'cat', 'cat', 'mouse', 'dog']) == 1\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'cherry', 'apple', 'banana']) == 2\n assert candidate(words1 = ['same', 'words', 'in', 'both', 'arrays'],words2 = ['same', 'words', 'in', 'both', 'arrays']) == 5\n assert candidate(words1 = ['single'],words2 = ['single', 'single', 'single', 'single']) == 0\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['cherry', 'banana', 'apple', 'apple']) == 2\n assert candidate(words1 = ['abc', 'def', 'ghi'],words2 = ['def', 'ghi', 'jkl', 'def', 'ghi']) == 0\n assert candidate(words1 = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault'],words2 = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'grault']) == 6\n assert candidate(words1 = ['foo', 'bar', 'baz', 'qux'],words2 = ['foo', 'bar', 'qux', 'quux']) == 3\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'apple', 'cherry', 'banana']) == 2\n assert candidate(words1 = ['hello', 'hello', 'world'],words2 = ['world', 'world', 'hello', 'hello', 'hello']) == 0\n assert candidate(words1 = ['one', 'two', 'three', 'four', 'five'],words2 = ['five', 'four', 'three', 'two', 'one']) == 5\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'apple', 'cherry', 'cherry']) == 2\n assert candidate(words1 = ['unique', 'words', 'only'],words2 = ['only', 'words', 'unique', 'words']) == 2\n assert candidate(words1 = ['red', 'blue', 'green'],words2 = ['red', 'red', 'blue', 'green', 'blue', 'green']) == 0\n assert candidate(words1 = ['cat', 'dog', 'mouse', 'elephant'],words2 = ['dog', 'mouse', 'cat', 'tiger', 'elephant', 'dog']) == 3\n assert candidate(words1 = ['test', 'case', 'input'],words2 = ['input', 'test', 'case', 'input', 'test', 'case', 'input', 'test', 'case']) == 0\n assert candidate(words1 = ['hello', 'world', 'hello', 'world'],words2 = ['hello', 'world', 'world', 'hello']) == 0\n assert candidate(words1 = ['first', 'second', 'third', 'fourth'],words2 = ['fourth', 'third', 'second', 'first', 'first', 'second', 'third', 'fourth', 'first', 'second', 'third', 'fourth']) == 0\n assert candidate(words1 = ['one', 'two', 'three', 'four', 'five'],words2 = ['two', 'three', 'five', 'six', 'seven', 'eight', 'nine', 'one', 'four']) == 5\n assert candidate(words1 = ['repeated', 'repeated', 'words', 'in', 'both', 'arrays'],words2 = ['repeated', 'words', 'in', 'both', 'arrays', 'arrays']) == 3\n assert candidate(words1 = ['x', 'y', 'z'],words2 = ['z', 'y', 'x']) == 3\n assert candidate(words1 = ['a', 'b', 'c', 'd'],words2 = ['a', 'a', 'b', 'c', 'c', 'd', 'd', 'd']) == 1\n assert candidate(words1 = ['single'],words2 = ['single']) == 1\n assert candidate(words1 = ['hello', 'world', 'python', 'java'],words2 = ['python', 'java', 'hello', 'world', 'world', 'hello']) == 2\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e'],words2 = ['a', 'a', 'b', 'c', 'c', 'd', 'e', 'e']) == 2\n assert candidate(words1 = ['python', 'java', 'c', 'cpp'],words2 = ['java', 'c', 'cpp', 'ruby']) == 3\n assert candidate(words1 = ['unique', 'string', 'in', 'each', 'array'],words2 = ['different', 'string', 'in', 'each', 'array']) == 4\n assert candidate(words1 = ['single'],words2 = ['single', 'single', 'single']) == 0\n assert candidate(words1 = ['apple', 'banana', 'cherry'],words2 = ['banana', 'cherry', 'date']) == 2\n assert candidate(words1 = ['repeat', 'repeat', 'repeat'],words2 = ['repeat', 'repeat', 'repeat', 'repeat']) == 0\n assert candidate(words1 = ['red', 'blue', 'green', 'yellow', 'red'],words2 = ['blue', 'green', 'purple', 'yellow', 'blue', 'green']) == 1\n assert candidate(words1 = ['foo', 'bar', 'baz', 'qux', 'quux'],words2 = ['qux', 'quux', 'foo', 'bar', 'baz', 'corge', 'grault', 'foo']) == 4\n assert candidate(words1 = ['example', 'test', 'case'],words2 = ['test', 'case', 'example', 'example', 'test', 'case']) == 0\n assert candidate(words1 = ['unique'],words2 = ['unique', 'unique', 'unique']) == 0\n assert candidate(words1 = ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'],words2 = ['x', 'y', 'z', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'x', 'y', 'z']) == 23\n assert candidate(words1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],words2 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g']) == 0\n assert candidate(words1 = ['unique'],words2 = ['unique', 'unique', 'unique', 'unique']) == 0\n", "comparison": "exact"}, "public_tests": ["[\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"]\n[\"amazing\",\"leetcode\",\"is\"]", "[\"b\",\"bb\",\"bbb\"]\n[\"a\",\"aa\",\"aaa\"]", "[\"a\",\"ab\"]\n[\"a\",\"a\",\"a\",\"ab\"]"], "hints": ["Could you try every word?", "Could you use a hash map to achieve a good complexity?"], "metadata": {"canonical_parameter_names": ["words1", "words2"], "leetcode_dataset_entry_point": "Solution().countWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:31+00:00", "tests_total": 103, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function countWords($words1, $words2) {", "container": "Solution", "callable": "countWords", "parameters": [{"name": "words1", "type": "String[]"}, {"name": "words2", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2086, "task_id": "minimum-number-of-food-buckets-to-feed-the-hamsters", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string hamsters where hamsters[i] is either:\n\n- 'H' indicating that there is a hamster at index i, or\n- '.' indicating that index i is empty.\n\nYou will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket to its left or to its right. More formally, a hamster at index i can be fed if you place a food bucket at index i - 1 and/or at index i + 1.\n\nReturn the minimum number of food buckets you should place at empty indices to feed all the hamsters or -1 if it is impossible to feed all of them.\n\nExample 1:\n\nInput: hamsters = \"H..H\"\nOutput: 2\nExplanation: We place two food buckets at indices 1 and 2.\nIt can be shown that if we place only one food bucket, one of the hamsters will not be fed.\n\nExample 2:\n\nInput: hamsters = \".H.H.\"\nOutput: 1\nExplanation: We place one food bucket at index 2.\n\nExample 3:\n\nInput: hamsters = \".HHH.\"\nOutput: -1\nExplanation: If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat.\n\nConstraints:\n\n- 1 <= hamsters.length <= 10^5\n- hamsters[i] is either'H' or '.'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(hamsters = \"H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H\") == 3\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H\") == 5\n assert candidate(hamsters = \".....\") == 0\n assert candidate(hamsters = \".\") == 0\n assert candidate(hamsters = \"H..H\") == 2\n assert candidate(hamsters = \"H.H\") == 1\n assert candidate(hamsters = \"H....H\") == 2\n assert candidate(hamsters = \"H.H.H.H.H\") == 3\n assert candidate(hamsters = \"HHHH\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H\") == 4\n assert candidate(hamsters = \"HH\") == -1\n assert candidate(hamsters = \"H.H.HH\") == -1\n assert candidate(hamsters = \".HHH.\") == -1\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == 8\n assert candidate(hamsters = \"HH.HH.HH\") == -1\n assert candidate(hamsters = \"H.H.H\") == 2\n assert candidate(hamsters = \"HH.H.H.H.H\") == -1\n assert candidate(hamsters = \"H.H.H.H\") == 2\n assert candidate(hamsters = \"HH.HH\") == -1\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \".H.H.\") == 1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H\") == 4\n assert candidate(hamsters = \"H.HH\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H.H.H\") == 7\n assert candidate(hamsters = \"HHHHHH\") == -1\n assert candidate(hamsters = \"HH.H.H\") == -1\n assert candidate(hamsters = \"HH.H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H\") == 5\n assert candidate(hamsters = \"HH.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == 10\n assert candidate(hamsters = \"HH.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == -1\n assert candidate(hamsters = \"HH.H.HH\") == -1\n assert candidate(hamsters = \"......\") == 0\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H\") == 6\n assert candidate(hamsters = \"...\") == 0\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H.H\") == 9\n assert candidate(hamsters = \"H.H.HH.H.H\") == 4\n assert candidate(hamsters = \"H.....H\") == 2\n assert candidate(hamsters = \"H.H.H.H.H.H.H\") == 4\n assert candidate(hamsters = \"H.....H\") == 2\n assert candidate(hamsters = \".......\") == 0\n assert candidate(hamsters = \"HH.HHHHH.HH\") == -1\n assert candidate(hamsters = \".H.H.\") == 1\n assert candidate(hamsters = \"H.H.H.H.HH\") == -1\n assert candidate(hamsters = \"........\") == 0\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H\") == 5\n assert candidate(hamsters = \"..H.H..\") == 1\n assert candidate(hamsters = \"H.H.H.H.H\") == 3\n assert candidate(hamsters = \"HH.H.H.HH\") == -1\n assert candidate(hamsters = \"HH\") == -1\n assert candidate(hamsters = \"H.HH.H\") == 2\n assert candidate(hamsters = \"HH.HH.HH.HH.HH.HH.HH.HH\") == -1\n assert candidate(hamsters = \"...\") == 0\n assert candidate(hamsters = \"H.\") == 1\n assert candidate(hamsters = \"H.H..H.H\") == 2\n assert candidate(hamsters = \"H.......H\") == 2\n assert candidate(hamsters = \"..H..H..\") == 2\n assert candidate(hamsters = \"HHHHH\") == -1\n assert candidate(hamsters = \"HH.HH\") == -1\n assert candidate(hamsters = \"HH.H.H.H.HH\") == -1\n assert candidate(hamsters = \"H...H\") == 2\n assert candidate(hamsters = \"HH.HHH.HH\") == -1\n assert candidate(hamsters = \"........\") == 0\n assert candidate(hamsters = \"H.H.H.HH.H\") == 3\n assert candidate(hamsters = \"HH.HH.HH.HH\") == -1\n assert candidate(hamsters = \"H.H.H.H\") == 2\n assert candidate(hamsters = \".\") == 0\n assert candidate(hamsters = \"HHHHHHHHHH\") == -1\n assert candidate(hamsters = \".HHH.\") == -1\n assert candidate(hamsters = \"H.H.H.HH\") == -1\n assert candidate(hamsters = \".H\") == 1\n assert candidate(hamsters = \".H.H.H.H.\") == 2\n assert candidate(hamsters = \"H.H.H\") == 2\n assert candidate(hamsters = \"H\") == -1\n assert candidate(hamsters = \".........\") == 0\n assert candidate(hamsters = \".H.H.H.H.H.H.H.H.H.\") == 5\n assert candidate(hamsters = \".H.H.H.H.H.H.H.H.\") == 4\n assert candidate(hamsters = \"HHHHHHH\") == -1\n assert candidate(hamsters = \"HH...HH\") == -1\n assert candidate(hamsters = \"H.H.H.H.H.H.H.H.H.H.H.H\") == 6\n assert candidate(hamsters = \"H......H\") == 2\n assert candidate(hamsters = \"H.H\") == 1\n assert candidate(hamsters = \"HH.HH.HH.HH.HH\") == -1\n assert candidate(hamsters = \"H..H\") == 2\n assert candidate(hamsters = \"HH..HH\") == -1\n assert candidate(hamsters = \"HHHH\") == -1\n", "comparison": "exact"}, "public_tests": ["\"H..H\"", "\".H.H.\"", "\".HHH.\""], "hints": ["When is it impossible to feed all the hamsters?", "When one or more hamsters do not have an empty space adjacent to it.", "Assuming all previous hamsters are fed. If there is a hamster at index i and you are able to place a bucket at index i - 1 or i + 1, where should you put it?", "It is always better to place a bucket at index i + 1 because it can feed the next hamster as well."], "metadata": {"canonical_parameter_names": ["hamsters"], "leetcode_dataset_entry_point": "Solution().minimumBuckets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:33+00:00", "tests_total": 91, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["string", "dynamic-programming", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumBuckets($hamsters) {", "container": "Solution", "callable": "minimumBuckets", "parameters": [{"name": "hamsters", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2087, "task_id": "minimum-cost-homecoming-of-a-robot-in-a-grid", "difficulty": "Medium", "problem_description": "There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [start_row, start_col] indicates that initially, a robot is at the cell (start_row, start_col). You are also given an integer array homePos where homePos = [home_row, home_col] indicates that its home is at the cell (home_row, home_col).\n\nThe robot needs to go to its home. It can move one cell in four directions: left, right, up, or down, and it can not move outside the boundary. Every move incurs some cost. You are further given two 0-indexed integer arrays: rowCosts of length m and colCosts of length n.\n\n- If the robot moves up or down into a cell whose row is r, then this move costs rowCosts[r].\n- If the robot moves left or right into a cell whose column is c, then this move costs colCosts[c].\n\nReturn the minimum total cost for this robot to return home.\n\nExample 1:\n\nInput: startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]\nOutput: 18\nExplanation: One optimal path is that:\nStarting from (1, 0)\n-> It goes down to (2, 0). This move costs rowCosts[2] = 3.\n-> It goes right to (2, 1). This move costs colCosts[1] = 2.\n-> It goes right to (2, 2). This move costs colCosts[2] = 6.\n-> It goes right to (2, 3). This move costs colCosts[3] = 7.\nThe total cost is 3 + 2 + 6 + 7 = 18\n\nExample 2:\n\nInput: startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]\nOutput: 0\nExplanation: The robot is already at its home. Since no moves occur, the total cost is 0.\n\nConstraints:\n\n- m == rowCosts.length\n- n == colCosts.length\n- 1 <= m, n <= 10^5\n- 0 <= rowCosts[r], colCosts[c] <= 10^4\n- startPos.length == 2\n- homePos.length == 2\n- 0 <= start_row, home_row < m\n- 0 <= start_col, home_col < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(startPos = [2, 2],homePos = [0, 0],rowCosts = [1, 10, 1],colCosts = [1, 10, 1]) == 22\n assert candidate(startPos = [3, 3],homePos = [0, 0],rowCosts = [10, 20, 30, 40],colCosts = [5, 15, 25, 35]) == 105\n assert candidate(startPos = [1, 0],homePos = [2, 3],rowCosts = [5, 4, 3],colCosts = [8, 2, 6, 7]) == 18\n assert candidate(startPos = [0, 0],homePos = [2, 2],rowCosts = [1, 10, 1],colCosts = [1, 10, 1]) == 22\n assert candidate(startPos = [0, 0],homePos = [2, 2],rowCosts = [1, 1, 1],colCosts = [1, 1, 1]) == 4\n assert candidate(startPos = [1, 1],homePos = [1, 1],rowCosts = [1, 2, 3],colCosts = [4, 5, 6]) == 0\n assert candidate(startPos = [2, 2],homePos = [0, 0],rowCosts = [1, 1, 1],colCosts = [1, 1, 1]) == 4\n assert candidate(startPos = [0, 1],homePos = [2, 1],rowCosts = [3, 2, 1],colCosts = [4, 5]) == 3\n assert candidate(startPos = [0, 0],homePos = [0, 0],rowCosts = [5],colCosts = [26]) == 0\n assert candidate(startPos = [2, 2],homePos = [2, 2],rowCosts = [1, 2],colCosts = [3, 4]) == 0\n assert candidate(startPos = [3, 2],homePos = [0, 0],rowCosts = [1, 2, 3, 4],colCosts = [5, 6, 7]) == 17\n assert candidate(startPos = [0, 1],homePos = [3, 3],rowCosts = [3, 2, 1, 4],colCosts = [4, 3, 2, 1]) == 10\n assert candidate(startPos = [0, 2],homePos = [2, 2],rowCosts = [10, 20, 30],colCosts = [5, 5, 5]) == 50\n assert candidate(startPos = [2, 3],homePos = [1, 1],rowCosts = [1, 1, 1],colCosts = [1, 1, 1, 1]) == 3\n assert candidate(startPos = [2, 3],homePos = [1, 0],rowCosts = [5, 4, 3],colCosts = [8, 2, 6, 7]) == 20\n assert candidate(startPos = [0, 1],homePos = [2, 2],rowCosts = [1, 2, 3],colCosts = [4, 5, 6]) == 11\n assert candidate(startPos = [3, 3],homePos = [7, 7],rowCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(startPos = [1, 2],homePos = [3, 4],rowCosts = [5, 4, 3, 2],colCosts = [1, 2, 3, 4, 5]) == 14\n assert candidate(startPos = [0, 4],homePos = [4, 0],rowCosts = [1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1]) == 8\n assert candidate(startPos = [9, 0],homePos = [9, 9],rowCosts = [100],colCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 540\n assert candidate(startPos = [0, 0],homePos = [9, 9],rowCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],colCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 99\n assert candidate(startPos = [9, 0],homePos = [0, 9],rowCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],colCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 99\n assert candidate(startPos = [2, 3],homePos = [2, 3],rowCosts = [5, 4, 3],colCosts = [8, 2, 6, 7]) == 0\n assert candidate(startPos = [5, 2],homePos = [0, 0],rowCosts = [1, 2, 3, 4, 5, 6],colCosts = [6, 5, 4, 3, 2, 1]) == 26\n assert candidate(startPos = [2, 1],homePos = [2, 1],rowCosts = [1000, 2000, 3000, 4000],colCosts = [5000, 6000, 7000, 8000, 9000]) == 0\n assert candidate(startPos = [0, 9],homePos = [0, 0],rowCosts = [1],colCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 450\n assert candidate(startPos = [2, 3],homePos = [4, 1],rowCosts = [3, 2, 1, 4, 5],colCosts = [6, 7, 8, 9]) == 24\n assert candidate(startPos = [1, 2],homePos = [3, 4],rowCosts = [1, 2, 3, 4],colCosts = [4, 3, 2, 1]) == 8\n assert candidate(startPos = [0, 9],homePos = [9, 0],rowCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],colCosts = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 1080\n assert candidate(startPos = [5, 2],homePos = [2, 5],rowCosts = [10, 20, 30, 40, 50, 60],colCosts = [60, 50, 40, 30, 20, 10]) == 180\n assert candidate(startPos = [1, 1],homePos = [3, 3],rowCosts = [5, 10, 15, 20],colCosts = [10, 20, 30, 40]) == 105\n assert candidate(startPos = [2, 2],homePos = [7, 2],rowCosts = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],colCosts = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 35\n assert candidate(startPos = [2, 4],homePos = [2, 4],rowCosts = [100, 200, 300],colCosts = [100, 200, 300, 400, 500]) == 0\n assert candidate(startPos = [2, 2],homePos = [2, 2],rowCosts = [100, 200, 300, 400, 500],colCosts = [100, 200, 300, 400, 500]) == 0\n assert candidate(startPos = [0, 5],homePos = [5, 0],rowCosts = [10, 20, 30, 40, 50, 60],colCosts = [60, 50, 40, 30, 20, 10]) == 400\n assert candidate(startPos = [1, 2],homePos = [4, 3],rowCosts = [100, 200, 300, 400, 500],colCosts = [10, 20, 30, 40]) == 1240\n assert candidate(startPos = [0, 3],homePos = [3, 0],rowCosts = [10, 20, 30, 40],colCosts = [5, 6, 7, 8]) == 108\n assert candidate(startPos = [4, 4],homePos = [0, 0],rowCosts = [10, 20, 30, 40, 50],colCosts = [1, 2, 3, 4, 5]) == 110\n assert candidate(startPos = [1, 3],homePos = [4, 1],rowCosts = [2, 3, 5, 7, 11],colCosts = [13, 17, 19, 23]) == 59\n assert candidate(startPos = [5, 0],homePos = [0, 5],rowCosts = [1, 1, 1, 1, 1],colCosts = [1, 2, 3, 4, 5]) == 19\n assert candidate(startPos = [5, 5],homePos = [0, 0],rowCosts = [1, 1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1, 1]) == 10\n assert candidate(startPos = [3, 3],homePos = [0, 0],rowCosts = [10000, 9000, 8000, 7000],colCosts = [6000, 5000, 4000, 3000]) == 42000\n assert candidate(startPos = [5, 5],homePos = [0, 0],rowCosts = [10, 20, 30, 40, 50, 60],colCosts = [6, 5, 4, 3, 2, 1]) == 170\n assert candidate(startPos = [0, 5],homePos = [5, 0],rowCosts = [2, 2, 2, 2, 2, 2],colCosts = [2, 2, 2, 2, 2, 2]) == 20\n assert candidate(startPos = [5, 5],homePos = [0, 0],rowCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],colCosts = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 550\n assert candidate(startPos = [3, 3],homePos = [1, 1],rowCosts = [100, 200, 300, 400],colCosts = [400, 300, 200, 100]) == 1000\n assert candidate(startPos = [7, 7],homePos = [2, 2],rowCosts = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2],colCosts = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 60\n assert candidate(startPos = [5, 5],homePos = [0, 0],rowCosts = [9, 8, 7, 6, 5, 4],colCosts = [3, 2, 1, 4, 5, 6]) == 50\n assert candidate(startPos = [0, 0],homePos = [4, 5],rowCosts = [10, 20, 30, 40, 50],colCosts = [5, 15, 25, 35, 45, 55]) == 315\n assert candidate(startPos = [4, 4],homePos = [6, 6],rowCosts = [5, 1, 2, 3, 4, 3, 2, 1, 5, 10],colCosts = [10, 1, 2, 3, 4, 3, 2, 1, 5, 10]) == 10\n assert candidate(startPos = [3, 3],homePos = [0, 0],rowCosts = [10, 20, 30, 40],colCosts = [40, 30, 20, 10]) == 150\n assert candidate(startPos = [0, 0],homePos = [5, 5],rowCosts = [1, 2, 3, 4, 5, 6],colCosts = [6, 5, 4, 3, 2, 1]) == 35\n assert candidate(startPos = [0, 9],homePos = [9, 0],rowCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 18\n assert candidate(startPos = [3, 2],homePos = [0, 0],rowCosts = [1, 1, 1, 1],colCosts = [1, 1, 1]) == 5\n assert candidate(startPos = [1, 0],homePos = [3, 2],rowCosts = [1, 1, 1, 1],colCosts = [1, 1, 1]) == 4\n assert candidate(startPos = [1, 2],homePos = [3, 0],rowCosts = [1, 1, 1, 1],colCosts = [1, 1, 1]) == 4\n assert candidate(startPos = [0, 0],homePos = [4, 4],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 4, 3, 2, 1]) == 24\n assert candidate(startPos = [10, 5],homePos = [10, 5],rowCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],colCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(startPos = [0, 0],homePos = [3, 3],rowCosts = [1, 2, 3, 4],colCosts = [1, 1, 1, 1]) == 12\n assert candidate(startPos = [5, 5],homePos = [1, 1],rowCosts = [10, 20, 30, 40, 50, 60],colCosts = [15, 25, 35, 45, 55, 65]) == 300\n assert candidate(startPos = [2, 2],homePos = [4, 4],rowCosts = [1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1]) == 4\n assert candidate(startPos = [0, 4],homePos = [4, 0],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 10, 15, 20, 25]) == 64\n assert candidate(startPos = [2, 0],homePos = [2, 4],rowCosts = [1, 2, 3],colCosts = [10, 20, 30, 40, 50]) == 140\n assert candidate(startPos = [3, 1],homePos = [0, 3],rowCosts = [5, 10, 15, 20],colCosts = [1, 2, 3, 4]) == 37\n assert candidate(startPos = [5, 5],homePos = [5, 5],rowCosts = [1, 1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(startPos = [2, 2],homePos = [2, 2],rowCosts = [100, 200, 300],colCosts = [100, 200, 300]) == 0\n assert candidate(startPos = [2, 2],homePos = [2, 2],rowCosts = [1000, 2000, 3000],colCosts = [100, 200, 300]) == 0\n assert candidate(startPos = [5, 5],homePos = [0, 0],rowCosts = [10, 20, 30, 40, 50, 60],colCosts = [5, 15, 25, 35, 45, 55]) == 275\n assert candidate(startPos = [0, 3],homePos = [4, 0],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 4, 3, 2, 1]) == 26\n assert candidate(startPos = [3, 4],homePos = [0, 0],rowCosts = [10, 20, 30, 40],colCosts = [5, 15, 25, 35, 45]) == 140\n assert candidate(startPos = [4, 4],homePos = [4, 4],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 4, 3, 2, 1]) == 0\n assert candidate(startPos = [2, 2],homePos = [4, 4],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 4, 3, 2, 1]) == 12\n assert candidate(startPos = [4, 4],homePos = [1, 1],rowCosts = [5, 10, 15, 20, 25],colCosts = [1, 2, 3, 4, 5]) == 54\n assert candidate(startPos = [0, 2],homePos = [4, 2],rowCosts = [10, 20, 30, 40, 50],colCosts = [1, 2, 3]) == 140\n assert candidate(startPos = [4, 0],homePos = [0, 4],rowCosts = [10, 20, 30, 40, 50],colCosts = [50, 40, 30, 20, 10]) == 200\n assert candidate(startPos = [0, 5],homePos = [5, 0],rowCosts = [1, 1, 1, 1, 1, 1],colCosts = [99, 98, 97, 96, 95, 94]) == 490\n assert candidate(startPos = [1, 1],homePos = [3, 3],rowCosts = [1, 1, 1, 1, 1],colCosts = [1, 1, 1, 1, 1]) == 4\n assert candidate(startPos = [3, 0],homePos = [0, 3],rowCosts = [1, 2, 3, 4],colCosts = [1, 1, 1, 1, 1]) == 9\n assert candidate(startPos = [4, 0],homePos = [4, 4],rowCosts = [1, 2, 3, 4, 5],colCosts = [5, 10, 15, 20, 25]) == 70\n assert candidate(startPos = [1, 5],homePos = [3, 2],rowCosts = [1, 2, 3, 4],colCosts = [5, 4, 3, 2, 1]) == 13\n", "comparison": "exact"}, "public_tests": ["[1,0]\n[2,3]\n[5,4,3]\n[8,2,6,7]", "[0,0]\n[0,0]\n[5]\n[26]"], "hints": ["Irrespective of what path the robot takes, it will have to traverse all the rows between startRow and homeRow and all the columns between startCol and homeCol.", "Hence, making any other move other than traversing the required rows and columns will potentially incur more cost which can be avoided."], "metadata": {"canonical_parameter_names": ["startPos", "homePos", "rowCosts", "colCosts"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:36+00:00", "tests_total": 80, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minCost($startPos, $homePos, $rowCosts, $colCosts) {", "container": "Solution", "callable": "minCost", "parameters": [{"name": "startPos", "type": "Integer[]"}, {"name": "homePos", "type": "Integer[]"}, {"name": "rowCosts", "type": "Integer[]"}, {"name": "colCosts", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2088, "task_id": "count-fertile-pyramids-in-a-land", "difficulty": "Hard", "problem_description": "A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.\n\nA pyramidal plot of land can be defined as a set of cells with the following criteria:\n\n1. The number of cells in the set has to be greater than 1 and all cells must be fertile.\n2. The apex of a pyramid is the topmost cell of the pyramid. The height of a pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r <= i <= r + h - 1 and c - (i - r) <= j <= c + (i - r).\n\nAn inverse pyramidal plot of land can be defined as a set of cells with similar criteria:\n\n1. The number of cells in the set has to be greater than 1 and all cells must be fertile.\n2. The apex of an inverse pyramid is the bottommost cell of the inverse pyramid. The height of an inverse pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r - h + 1 <= i <= r and c - (r - i) <= j <= c + (r - i).\n\nSome examples of valid and invalid pyramidal (and inverse pyramidal) plots are shown below. Black cells indicate fertile cells.\n\nGiven a 0-indexed m x n binary matrix grid representing the farmland, return the total number of pyramidal and inverse pyramidal plots that can be found in grid.\n\nExample 1:\n\nInput: grid = [[0,1,1,0],[1,1,1,1]]\nOutput: 2\nExplanation: The 2 possible pyramidal plots are shown in blue and red respectively.\nThere are no inverse pyramidal plots in this grid.\nHence total number of pyramidal and inverse pyramidal plots is 2 + 0 = 2.\n\nExample 2:\n\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: 2\nExplanation: The pyramidal plot is shown in blue, and the inverse pyramidal plot is shown in red.\nHence the total number of plots is 1 + 1 = 2.\n\nExample 3:\n\nInput: grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]]\nOutput: 13\nExplanation: There are 7 pyramidal plots, 3 of which are shown in the 2nd and 3rd figures.\nThere are 6 inverse pyramidal plots, 2 of which are shown in the last figure.\nThe total number of plots is 7 + 6 = 13.\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", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 0], [1, 1, 1, 1]]) == 2\n assert candidate(grid = [[1, 1, 0, 1, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == 5\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) == 0\n assert candidate(grid = [[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, 1]]) == 30\n assert candidate(grid = [[1, 1, 0, 1], [1, 1, 1, 1], [0, 1, 1, 0]]) == 3\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) == 14\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]]) == 8\n assert candidate(grid = [[1, 1, 1], [1, 1, 1]]) == 2\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 0, 0, 1]]) == 13\n assert candidate(grid = [[0, 1, 1, 0, 0, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1]]) == 4\n assert candidate(grid = [[1, 1], [1, 1]]) == 0\n assert candidate(grid = [[1, 0, 1], [0, 1, 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, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 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]]) == 15\n assert candidate(grid = [[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, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 5\n assert candidate(grid = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0]]) == 32\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, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 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, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 0, 0, 1, 1, 1, 1], [1, 1, 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, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 1, 1, 1, 1, 0, 1, 0]]) == 54\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]]) == 120\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]]) == 2\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], [0, 0, 0, 0, 0], [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]]) == 24\n assert candidate(grid = [[1, 1, 1, 0, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1]]) == 34\n assert candidate(grid = [[0, 0, 0, 0, 0, 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], [0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 32\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]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 6\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 0, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 0, 1, 1, 1, 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, 1, 1, 1, 0, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 36\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, 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], [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], [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\n assert candidate(grid = [[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], [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\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]]) == 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], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 24\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\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [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, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 41\n assert candidate(grid = [[0, 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, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]) == 88\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]]) == 80\n assert candidate(grid = [[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], [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], [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], [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\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, 1, 0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0]]) == 10\n assert candidate(grid = [[1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0]]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 1140\n assert candidate(grid = [[0, 0, 1, 0, 0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [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]]) == 75\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\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1]]) == 12\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], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 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, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 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 = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 4\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 1]]) == 8\n assert candidate(grid = [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0], [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, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [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], [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]]) == 50\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], [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], [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], [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], [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]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]) == 10\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]]) == 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, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 128\n assert candidate(grid = [[1, 0, 1, 0, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]) == 19\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 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]]) == 18\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, 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]]) == 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, 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, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 40\n assert candidate(grid = [[1, 1, 1, 0, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [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]]) == 14\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, 0, 1, 1, 1, 1, 1, 0, 1, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1, 1], [1, 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, 1, 1, 0, 1, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 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, 1, 1, 1, 1, 1]]) == 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, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0]]) == 177\n assert candidate(grid = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [0, 1, 0, 0, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 8\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 24\n assert candidate(grid = [[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, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 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, 1, 1, 1, 1, 1, 0, 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]]) == 53\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) == 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], [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]]) == 0\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, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]) == 200\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, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) == 54\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]]) == 0\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], [1, 0, 1, 0, 1, 0, 1, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 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], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0]]) == 112\n", "comparison": "exact"}, "public_tests": ["[[0,1,1,0],[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],[0,1,0,0,1]]"], "hints": ["Think about how dynamic programming can help solve the problem.", "For any fixed cell (r, c), can you calculate the maximum height of the pyramid for which it is the apex? Let us denote this value as dp[r][c].", "How will the values at dp[r+1][c-1] and dp[r+1][c+1] help in determining the value at dp[r][c]?", "For the cell (r, c), is there a relation between the number of pyramids for which it serves as the apex and dp[r][c]? How does it help in calculating the answer?"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().countPyramids", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:38+00:00", "tests_total": 74, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "php", "interface": {"raw_signature": "function countPyramids($grid) {", "container": "Solution", "callable": "countPyramids", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2089, "task_id": "find-target-indices-after-sorting-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums and a target element target.\n\nA target index is an index i such that nums[i] == target.\n\nReturn a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.\n\nExample 1:\n\nInput: nums = [1,2,5,2,3], target = 2\nOutput: [1,2]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe indices where nums[i] == 2 are 1 and 2.\n\nExample 2:\n\nInput: nums = [1,2,5,2,3], target = 3\nOutput: [3]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe index where nums[i] == 3 is 3.\n\nExample 3:\n\nInput: nums = [1,2,5,2,3], target = 5\nOutput: [4]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe index where nums[i] == 5 is 4.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i], target <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [100, 99, 98, 97, 96],target = 98) == [2]\n assert candidate(nums = [10, 20, 30, 40, 50],target = 50) == [4]\n assert candidate(nums = [7, 7, 7, 7, 7],target = 8) == []\n assert candidate(nums = [10, 20, 30, 40, 50],target = 25) == []\n assert candidate(nums = [50, 40, 30, 20, 10],target = 15) == []\n assert candidate(nums = [100, 100, 100],target = 100) == [0, 1, 2]\n assert candidate(nums = [1, 2, 5, 2, 3],target = 3) == [3]\n assert candidate(nums = [2, 4, 6, 8, 10],target = 2) == [0]\n assert candidate(nums = [5, 5, 5, 5, 5],target = 5) == [0, 1, 2, 3, 4]\n assert candidate(nums = [1, 1, 1, 1, 1],target = 1) == [0, 1, 2, 3, 4]\n assert candidate(nums = [5, 4, 3, 2, 1],target = 3) == [2]\n assert candidate(nums = [1, 3, 5, 7, 9],target = 2) == []\n assert candidate(nums = [1, 2, 2, 2, 3, 4],target = 2) == [1, 2, 3]\n assert candidate(nums = [1, 2, 5, 2, 3],target = 2) == [1, 2]\n assert candidate(nums = [50, 50, 50, 50, 50],target = 50) == [0, 1, 2, 3, 4]\n assert candidate(nums = [5, 5, 5, 5, 5],target = 6) == []\n assert candidate(nums = [1, 3, 5, 7, 9],target = 10) == []\n assert candidate(nums = [100, 1, 100, 1, 100],target = 1) == [0, 1]\n assert candidate(nums = [1, 2, 5, 2, 3],target = 5) == [4]\n assert candidate(nums = [1, 1, 1, 1, 1],target = 2) == []\n assert candidate(nums = [1, 3, 5, 7, 9],target = 4) == []\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 4) == [6, 7]\n assert candidate(nums = [5, 4, 3, 2, 1],target = 3) == [2]\n assert candidate(nums = [90, 80, 70, 60, 50, 40, 30, 20, 10],target = 45) == []\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 50) == [4]\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],target = 95) == [5]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],target = 7) == [6]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],target = 5) == [4]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],target = 27) == [8]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],target = 4) == [3]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],target = 5) == [4]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],target = 35) == [6]\n assert candidate(nums = [100, 100, 99, 99, 98, 98, 97, 97],target = 99) == [4, 5]\n assert candidate(nums = [45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31],target = 37) == [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 = 1) == [0]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 8) == [3]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 10) == []\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 5) == [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],target = 20) == []\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1],target = 4) == [3]\n assert candidate(nums = [42, 24, 36, 18, 54, 30, 48, 27, 60, 39],target = 30) == [3]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1],target = 5) == [4]\n assert candidate(nums = [100, 50, 30, 70, 20],target = 30) == [1]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 50) == [4]\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],target = 8) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [42, 23, 37, 23, 42, 37],target = 37) == [2, 3]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],target = 4) == [7, 8, 9, 10]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7],target = 15) == [8]\n assert candidate(nums = [100, 99, 98, 97, 96, 95],target = 98) == [3]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],target = 55) == [5]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = 15) == [7]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],target = 10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 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 = 10) == [9]\n assert candidate(nums = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1],target = 2) == [5, 6, 7, 8, 9]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 55) == []\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 1) == [0]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = 35) == [4]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],target = 3) == [6, 7, 8]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = 20) == [9]\n assert candidate(nums = [100, 99, 98, 97, 96],target = 97) == [1]\n assert candidate(nums = [8, 6, 6, 6, 8, 6, 8, 6, 8, 6, 6, 6, 6, 6],target = 6) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [42, 27, 89, 10, 56, 23, 50, 78, 34, 67],target = 50) == [5]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],target = 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],target = 10) == [18, 19]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],target = 40) == [3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 11) == []\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],target = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],target = 5) == [4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 10) == [9]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],target = 13) == [12]\n assert candidate(nums = [50, 20, 30, 40, 10],target = 30) == [2]\n assert candidate(nums = [100, 1, 50, 20, 30, 60, 40],target = 30) == [2]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 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],target = 15) == [14]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],target = 10) == [9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 15) == [14]\n assert candidate(nums = [50, 50, 50, 50, 50, 50],target = 50) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = 8) == [7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 11) == []\n assert candidate(nums = [10, 20, 30, 40, 50],target = 20) == [1]\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],target = 20) == [5, 6, 7, 8, 9]\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 15) == [5]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = 17) == []\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],target = 95) == [4]\n assert candidate(nums = [50, 20, 30, 10, 40],target = 30) == [2]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],target = 50) == [0, 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],target = 6) == []\n assert candidate(nums = [3, 1, 2, 5, 4, 2, 3, 3, 5, 1],target = 3) == [4, 5, 6]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],target = 50) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1],target = 2) == []\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],target = 6) == []\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = 18) == [8]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 5) == [4]\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100],target = 1) == [0, 1, 2]\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3],target = 2) == [3, 4, 5]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],target = 5) == [4]\n assert candidate(nums = [50, 20, 30, 40, 10],target = 20) == [1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],target = 10) == []\n assert candidate(nums = [50, 20, 30, 40, 10, 60, 70, 80, 90, 100],target = 40) == [3]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 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],target = 21) == []\n assert candidate(nums = [3, 1, 2, 5, 4],target = 4) == [3]\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],target = 15) == [8]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10],target = 15) == [5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],target = 55) == []\n assert candidate(nums = [10, 20, 10, 20, 10, 20],target = 10) == [0, 1, 2]\n assert candidate(nums = [50, 40, 30, 20, 10],target = 30) == [2]\n assert candidate(nums = [50, 40, 30, 20, 10],target = 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],target = 15) == [14]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],target = 6) == [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],target = 25) == [12]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],target = 5) == [4]\n assert candidate(nums = [3, 1, 2, 4, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],target = 3) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [42, 37, 58, 54, 19, 91, 49, 100, 65, 28, 74, 99, 96, 33, 80, 78, 60, 82, 97, 71],target = 74) == [11]\n", "comparison": "exact"}, "public_tests": ["[1,2,5,2,3]\n2", "[1,2,5,2,3]\n3", "[1,2,5,2,3]\n5"], "hints": ["Try \"sorting\" the array first.", "Now find all indices in the array whose values are equal to target."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().targetIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:40+00:00", "tests_total": 118, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "binary-search", "sorting"]}, "language": "php", "interface": {"raw_signature": "function targetIndices($nums, $target) {", "container": "Solution", "callable": "targetIndices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2090, "task_id": "k-radius-subarray-averages", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of n integers, and an integer k.\n\nThe k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-radius average is -1.\n\nBuild and return an array avgs of length n where avgs[i] is the k-radius average for the subarray centered at index i.\n\nThe average of x elements is the sum of the x elements divided by x, using integer division. The integer division truncates toward zero, which means losing its fractional part.\n\n- For example, the average of four elements 2, 3, 1, and 5 is (2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75, which truncates to 2.\n\nExample 1:\n\nInput: nums = [7,4,3,9,1,8,5,2,6], k = 3\nOutput: [-1,-1,-1,5,4,4,-1,-1,-1]\nExplanation:\n- avg[0], avg[1], and avg[2] are -1 because there are less than k elements before each index.\n- The sum of the subarray centered at index 3 with radius 3 is: 7 + 4 + 3 + 9 + 1 + 8 + 5 = 37.\n Using integer division, avg[3] = 37 / 7 = 5.\n- For the subarray centered at index 4, avg[4] = (4 + 3 + 9 + 1 + 8 + 5 + 2) / 7 = 4.\n- For the subarray centered at index 5, avg[5] = (3 + 9 + 1 + 8 + 5 + 2 + 6) / 7 = 4.\n- avg[6], avg[7], and avg[8] are -1 because there are less than k elements after each index.\n\nExample 2:\n\nInput: nums = [100000], k = 0\nOutput: [100000]\nExplanation:\n- The sum of the subarray centered at index 0 with radius 0 is: 100000.\n avg[0] = 100000 / 1 = 100000.\n\nExample 3:\n\nInput: nums = [8], k = 100000\nOutput: [-1]\nExplanation:\n- avg[0] is -1 because there are less than k elements before and after index 0.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- 0 <= nums[i], k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == [-1, -1, 3, 4, 5, 6, 7, 8, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0],k = 2) == [-1, -1, 0, -1, -1]\n assert candidate(nums = [100000],k = 0) == [100000]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == [-1, -1, -1, -1, 5, 5, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 2) == [-1, -1, 3, 4, 5, 6, 7, -1, -1]\n assert candidate(nums = [8],k = 100000) == [-1]\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == [-1, -1, 3, -1, -1]\n assert candidate(nums = [5],k = 0) == [5]\n assert candidate(nums = [5, 5, 5, 5, 5],k = 1) == [-1, 5, 5, 5, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == [-1, -1, -1, -1, 5, 6, -1, -1, -1, -1]\n assert candidate(nums = [7, 4, 3, 9, 1, 8, 5, 2, 6],k = 3) == [-1, -1, -1, 5, 4, 4, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == [-1, 2, 3, 4, -1]\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],k = 3) == [-1, -1, -1, 102, 103, 104, 105, 106, 107, -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],k = 7) == [-1, -1, -1, -1, -1, -1, -1, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 0) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 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 = 5) == [-1, -1, -1, -1, -1, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, -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],k = 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, -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],k = 5) == [-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, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 5) == [-1, -1, -1, -1, -1, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, -1, -1, -1, -1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == [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],k = 0) == [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, 5, 5, 5, 5, 5, 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) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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],k = 3) == [-1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, -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],k = 7) == [-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],k = 3) == [-1, -1, -1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 4) == [-1, -1, -1, -1, 5, 4, -1, -1, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 3) == [-1, -1, -1, 2, 1, 1, 1, 2, -1, -1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == [-1, -1, -1, -1, 6, 5, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 2) == [-1, -1, 3, 2, 1, 1, 1, 2, 3, -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],k = 7) == [-1, -1, -1, -1, -1, -1, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 3) == [-1, -1, -1, 7, 9, 11, 13, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 4) == [-1, -1, -1, -1, 0, 0, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2) == [-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 4) == [-1, -1, -1, -1, 5000, 6000, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1, -1, -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],k = 5) == [-1, -1, -1, -1, -1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, -1, -1, -1, -1, -1]\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 2) == [-1, -1, 99998, 99997, 99996, 99995, 99994, 99993, -1, -1]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],k = 4) == [-1, -1, -1, -1, 99995, 99994, -1, -1, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 4) == [-1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -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],k = 6) == [-1, -1, -1, -1, -1, -1, 7, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 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],k = 5) == [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == [-1, 8, 7, 6, 5, 4, 3, 2, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],k = 8) == [-1, -1, -1, -1, -1, -1, -1, -1, -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],k = 8) == [-1, -1, -1, -1, -1, -1, -1, -1, 90, 100, 110, 120, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [99999, 88888, 77777, 66666, 55555, 44444, 33333, 22222, 11111, 0],k = 4) == [-1, -1, -1, -1, 55555, 44444, -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],k = 9) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, -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],k = 9) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, -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, 21, 22, 23, 24, 25],k = 4) == [-1, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 0) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == [-1, -1, 3, 4, 5, 6, 7, 8, -1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [-1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 4) == [-1, -1, -1, -1, 60000, 50000, -1, -1, -1, -1]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 2) == [-1, -1, 15, 20, 25, 30, 35, 40, -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 = 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 9) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0],k = 2) == [-1, -1, 60000, 40000, 60000, 40000, 60000, 40000, -1, -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],k = 5) == [-1, -1, -1, -1, -1, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 5) == [-1, -1, -1, -1, -1, 600, 700, 800, 900, 1000, -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 = 5) == [-1, -1, -1, -1, -1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 3) == [-1, -1, -1, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, -1, -1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [-1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 0) == [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 4) == [-1, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, -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],k = 5) == [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -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, 21, 22, 23, 24, 25],k = 5) == [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == [-1, -1, -1, 40, 50, 60, 70, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3) == [-1, -1, -1, 0, 0, 0, 0, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == [-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1],k = 1) == [-1, 5, 5, 5, 5, 4, 6, 4, -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 = 5) == [-1, -1, -1, -1, -1, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],k = 2) == [-1, -1, 3, 2, 1, 1, 1, 2, 3, -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],k = 5) == [-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1]\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 2) == [-1, -1, 80000, 70000, 60000, 50000, 40000, 30000, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == [-1, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 2) == [-1, -1, 30, 40, 50, 60, 70, 80, -1, -1]\n assert candidate(nums = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],k = 4) == [-1, -1, -1, -1, 99999, 99999, -1, -1, -1, -1]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 4) == [-1, -1, -1, -1, 100000, -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],k = 20) == [-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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == [-1, -1, -1, 40, 50, 60, 70, -1, -1, -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],k = 7) == [-1, -1, -1, -1, -1, -1, -1, 15, 17, 19, 21, 23, 25, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 2) == [-1, -1, 300, 400, 500, 600, 700, 800, -1, -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],k = 5) == [-1, -1, -1, -1, -1, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, -1, -1, -1, -1, -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],k = 4) == [-1, -1, -1, -1, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == [-1, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -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],k = 5) == [-1, -1, -1, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 1) == [-1, 3, 5, 7, 9, 11, 13, 15, 17, -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],k = 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]\n assert candidate(nums = [6, 10, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == [-1, -1, 5, 5, 4, 4, 5, 5, 4, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 2) == [-1, -1, 0, 0, 0, 0, 0, 0, -1, -1]\n", "comparison": "exact"}, "public_tests": ["[7,4,3,9,1,8,5,2,6]\n3", "[100000]\n0", "[8]\n100000"], "hints": ["To calculate the average of a subarray, you need the sum and the K. K is already given. How could you quickly calculate the sum of a subarray?", "Use the Prefix Sums method to calculate the subarray sums.", "It is possible that the sum of all the elements does not fit in a 32-bit integer type. Be sure to use a 64-bit integer type for the prefix sum array."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().getAverages", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:42+00:00", "tests_total": 94, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function getAverages($nums, $k) {", "container": "Solution", "callable": "getAverages", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2091, "task_id": "removing-minimum-and-maximum-from-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of distinct integers nums.\n\nThere is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array.\n\nA deletion is defined as either removing an element from the front of the array or removing an element from the back of the array.\n\nReturn the minimum number of deletions it would take to remove both the minimum and maximum element from the array.\n\nExample 1:\n\nInput: nums = [2,10,7,5,4,1,8,6]\nOutput: 5\nExplanation:\nThe minimum element in the array is nums[5], which is 1.\nThe maximum element in the array is nums[1], which is 10.\nWe can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back.\nThis results in 2 + 3 = 5 deletions, which is the minimum number possible.\n\nExample 2:\n\nInput: nums = [0,-4,19,1,8,-2,-3,5]\nOutput: 3\nExplanation:\nThe minimum element in the array is nums[1], which is -4.\nThe maximum element in the array is nums[2], which is 19.\nWe can remove both the minimum and maximum by removing 3 elements from the front.\nThis results in only 3 deletions, which is the minimum number possible.\n\nExample 3:\n\nInput: nums = [101]\nOutput: 1\nExplanation:\nThere is only one element in the array, which makes it both the minimum and maximum element.\nWe can remove it with 1 deletion.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^5 <= nums[i] <= 10^5\n- The integers in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 10, 7, 5, 4, 1, 8, 6]) == 5\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 2\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [100000, -100000, 50000, -50000, 25000, -25000]) == 2\n assert candidate(nums = [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]) == 2\n assert candidate(nums = [101]) == 1\n assert candidate(nums = [3, 1, 2, 4, 5]) == 3\n assert candidate(nums = [100000, -100000, 50000, -50000, 0]) == 2\n assert candidate(nums = [0, -4, 19, 1, 8, -2, -3, 5]) == 3\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 3, 2]) == 2\n assert candidate(nums = [3, 1]) == 2\n assert candidate(nums = [3, 2, 1]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 2\n assert candidate(nums = [-1, 1]) == 2\n assert candidate(nums = [5, 3, 1, 2, 4]) == 3\n assert candidate(nums = [5, 3, 1, 4, 2]) == 3\n assert candidate(nums = [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]) == 2\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, -99979, -99978, -99977, -99976, -99975, -99974, -99973, -99972, -99971, -99970, 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, 99975, 99974, 99973, 99972, 99971, 99970]) == 32\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 2\n assert candidate(nums = [-50000, 49999, -49999, 49998, -49998, 49997, -49997, 49996, -49996, 49995]) == 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, 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]) == 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]) == 2\n assert candidate(nums = [3, 1, 2, 5, 4, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [-7, 10, 5, -3, 2, 8, 0, -1, 6, 4]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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]) == 2\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 10\n assert candidate(nums = [3, 7, 1, 9, 5, 2, 8, 4, 6]) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500]) == 6\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]) == 2\n assert candidate(nums = [30, 20, 10, 0, -10, -20, -30, 40, 50, 60, 70, 80, 90, 100]) == 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, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995]) == 2\n assert candidate(nums = [-1, -5, -3, -7, -2, -6, -4]) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500, 0]) == 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, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14]) == 13\n assert candidate(nums = [9, 3, 5, 2, 7, 6, 1, 8, 4]) == 4\n assert candidate(nums = [100000, -100000, 50000, -50000, 25000, -25000, 75000, -75000, 12500, -12500]) == 2\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 2\n assert candidate(nums = [3, 1, 2, 5, 4]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1]) == 2\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9]) == 2\n assert candidate(nums = [5, 2, 8, 3, 7, 6, 4, 10, 1, 9]) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 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]) == 2\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 2\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]) == 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]) == 2\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5]) == 2\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]) == 2\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]) == 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, 100]) == 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]) == 2\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 8, 7, 10, 9]) == 4\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [-5, -10, -3, -1, -8, -2, -7, -4, -6, -9]) == 4\n assert candidate(nums = [3, 1, 2]) == 2\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -1]) == 2\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]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2\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]) == 22\n assert candidate(nums = [40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21]) == 2\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, 0]) == 3\n assert candidate(nums = [1, 10, 3, 8, 5, 2, 7, 4, 6, 9]) == 2\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 6\n assert candidate(nums = [1000, 100, 10, 1, 0, -1, -10, -100, -1000, 500, 50, 5, 0.5, 0.05, 0.005, 0.0005, 5e-05]) == 9\n assert candidate(nums = [100000, -100000, 50000, -50000, 25000, -25000, 12500, -12500, 6250, -6250]) == 2\n assert candidate(nums = [-10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 2\n assert candidate(nums = [50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50]) == 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]) == 2\n assert candidate(nums = [10, 2, 8, 6, 7, 3, 5, 1, 9, 4]) == 4\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 11\n assert candidate(nums = [-100000, 100000, 1, -1, 50000, -50000, 99999, -99999, 42, -42]) == 2\n assert candidate(nums = [7, 3, 5, 2, 8, 6, 4, 1]) == 4\n assert candidate(nums = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 2\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\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]) == 2\n assert candidate(nums = [20, 18, 19, 16, 17, 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 1]) == 2\n assert candidate(nums = [9, 3, 15, 1, 12, 7, 8, 6, 10, 2]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 2\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6]) == 3\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 8, 18, 28, 38, 48, 58, 68, 78, 88, 98, 7, 17, 27, 37, 47, 57, 67, 77, 87, 97, 6, 16, 26, 36, 46, 56, 66, 76, 86, 96, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 4, 14, 24, 34, 44, 54, 64, 74, 84, 94, 3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 1, 11, 21, 31, 41, 51, 61, 71, 81, 91]) == 20\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\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991, 11, 99990, 12, 99989, 13, 99988, 14, 99987, 15, 99986, 16, 99985, 17, 99984, 18, 99983, 19, 99982, 20, 99981, 21, 99980, 22, 99979, 23, 99978, 24, 99977, 25, 99976, 26, 99975, 27, 99974, 28, 99973, 29, 99972, 30, 99971]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7]) == 2\n", "comparison": "exact"}, "public_tests": ["[2,10,7,5,4,1,8,6]", "[0,-4,19,1,8,-2,-3,5]", "[101]"], "hints": ["There can only be three scenarios for deletions such that both minimum and maximum elements are removed:", "Scenario 1: Both elements are removed by only deleting from the front.", "Scenario 2: Both elements are removed by only deleting from the back.", "Scenario 3: Delete from the front to remove one of the elements, and delete from the back to remove the other element.", "Compare which of the three scenarios results in the minimum number of moves."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumDeletions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:45+00:00", "tests_total": 102, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumDeletions($nums) {", "container": "Solution", "callable": "minimumDeletions", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2092, "task_id": "find-all-people-with-secret", "difficulty": "Hard", "problem_description": "You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [x_i, y_i, time_i] indicates that person x_i and person y_i have a meeting at time_i. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.\n\nPerson 0 has a secret and initially shares the secret with a person firstPerson at time 0. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person x_i has the secret at time_i, then they will share the secret with person y_i, and vice versa.\n\nThe secrets are shared instantaneously. That is, a person may receive the secret and share it with people in other meetings within the same time frame.\n\nReturn a list of all the people that have the secret after all the meetings have taken place. You may return the answer in any order.\n\nExample 1:\n\nInput: n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1\nOutput: [0,1,2,3,5]\nExplanation:\nAt time 0, person 0 shares the secret with person 1.\nAt time 5, person 1 shares the secret with person 2.\nAt time 8, person 2 shares the secret with person 3.\nAt time 10, person 1 shares the secret with person 5.\nThus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.\n\nExample 2:\n\nInput: n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3\nOutput: [0,1,3]\nExplanation:\nAt time 0, person 0 shares the secret with person 3.\nAt time 2, neither person 1 nor person 2 know the secret.\nAt time 3, person 3 shares the secret with person 0 and person 1.\nThus, people 0, 1, and 3 know the secret after all the meetings.\n\nExample 3:\n\nInput: n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1\nOutput: [0,1,2,3,4]\nExplanation:\nAt time 0, person 0 shares the secret with person 1.\nAt time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\nNote that person 2 can share the secret at the same time as receiving it.\nAt time 2, person 3 shares the secret with person 4.\nThus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 1 <= meetings.length <= 10^5\n- meetings[i].length == 3\n- 0 <= x_i, y_i<= n - 1\n- x_i != y_i\n- 1 <= time_i <= 10^5\n- 1 <= firstPerson <= n - 1\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, meetings=[[0, 1, 10], [1, 2, 20]], firstPerson=1), [0, 1, 2])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=3, meetings=[[0, 1, 1], [1, 2, 2], [0, 2, 3]], firstPerson=2), [0, 1, 2])\n assert answers_match(candidate(n=5, meetings=[[3, 4, 2], [1, 2, 1], [2, 3, 1]], firstPerson=1), [0, 1, 2, 3, 4])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 10], [1, 2, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=4, meetings=[[3, 1, 3], [1, 2, 2], [0, 3, 3]], firstPerson=3), [0, 1, 3])\n assert answers_match(candidate(n=7, meetings=[[0, 2, 1], [1, 3, 2], [2, 4, 3], [3, 5, 4], [4, 6, 5]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=3, meetings=[[0, 1, 10], [1, 2, 20], [2, 0, 30]], firstPerson=2), [0, 1, 2])\n assert answers_match(candidate(n=3, meetings=[[0, 1, 1], [1, 2, 2], [0, 2, 3]], firstPerson=1), [0, 1, 2])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=6, meetings=[[1, 2, 5], [2, 3, 8], [1, 5, 10]], firstPerson=1), [0, 1, 2, 3, 5])\n assert answers_match(candidate(n=7, meetings=[[0, 2, 1], [1, 3, 1], [4, 5, 1], [5, 6, 1]], firstPerson=2), [0, 2])\n assert answers_match(candidate(n=15, meetings=[[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], [9, 10, 50], [10, 11, 55], [11, 12, 60], [12, 13, 65], [13, 14, 70], [14, 0, 75]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=10, meetings=[[0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [1, 5, 2], [2, 6, 2], [3, 7, 2], [4, 8, 2], [5, 9, 3], [6, 9, 3], [7, 9, 3], [8, 9, 3]], firstPerson=9), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=12, meetings=[[0, 1, 1], [1, 2, 2], [2, 0, 3], [3, 4, 4], [4, 5, 5], [5, 3, 6], [6, 7, 7], [7, 8, 8], [8, 6, 9], [9, 10, 10], [10, 11, 11], [11, 9, 12]], firstPerson=1), [0, 1, 2])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [0, 2, 1], [1, 3, 2], [1, 4, 2], [2, 5, 3], [2, 6, 3]], firstPerson=2), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=11, meetings=[[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, 0, 11]], firstPerson=10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n assert answers_match(candidate(n=12, meetings=[[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, 2], [1, 6, 2], [2, 7, 2], [3, 8, 2], [4, 9, 2], [5, 10, 2], [6, 11, 2], [7, 0, 2], [8, 1, 2], [9, 2, 2], [10, 3, 2], [11, 4, 2]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=20, meetings=[[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]], firstPerson=10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])\n assert answers_match(candidate(n=12, meetings=[[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]], firstPerson=6), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=20, meetings=[[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, 0, 20]], firstPerson=10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])\n assert answers_match(candidate(n=8, meetings=[[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, 7, 9], [1, 6, 10], [2, 5, 11], [3, 4, 12]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=10, meetings=[[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, 2, 11], [1, 3, 12], [2, 4, 13], [3, 5, 14], [4, 6, 15], [5, 7, 16], [6, 8, 17], [7, 9, 18], [8, 0, 19], [9, 1, 20]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=12, meetings=[[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]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 0, 6]], firstPerson=1), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 0, 1]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=12, meetings=[[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]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=9, meetings=[[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]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8])\n assert answers_match(candidate(n=20, meetings=[[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]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])\n assert answers_match(candidate(n=15, meetings=[[0, 1, 10], [0, 2, 10], [1, 3, 20], [1, 4, 20], [2, 5, 30], [2, 6, 30], [3, 7, 40], [3, 8, 40], [4, 9, 50], [4, 10, 50], [5, 11, 60], [5, 12, 60], [6, 13, 70], [6, 14, 70]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=10, meetings=[[0, 9, 1], [1, 8, 2], [2, 7, 3], [3, 6, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 9, 9]], firstPerson=5), [0, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=15, meetings=[[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]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50]], firstPerson=1), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=10, meetings=[[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, 2], [1, 3, 3], [2, 4, 3], [3, 5, 3], [4, 6, 3], [5, 7, 3], [6, 8, 3], [7, 9, 3], [8, 0, 3], [9, 1, 3]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=10, meetings=[[0, 9, 1], [1, 8, 2], [2, 7, 3], [3, 6, 4], [4, 5, 5], [5, 4, 5], [6, 3, 4], [7, 2, 3], [8, 1, 2], [9, 0, 1]], firstPerson=5), [0, 4, 5, 9])\n assert answers_match(candidate(n=15, meetings=[[0, 1, 1], [0, 2, 1], [1, 3, 2], [1, 4, 2], [2, 5, 3], [2, 6, 3], [3, 7, 4], [3, 8, 4], [4, 9, 5], [4, 10, 5], [5, 11, 6], [5, 12, 6], [6, 13, 7], [6, 14, 7]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=10, meetings=[[0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=9, meetings=[[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, 10], [1, 3, 11], [2, 4, 12], [3, 5, 13], [4, 6, 14], [5, 7, 15], [6, 8, 16], [7, 0, 17], [8, 1, 18]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7, 8])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 0, 8], [1, 3, 9], [3, 5, 10], [5, 7, 11], [7, 1, 12]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=12, meetings=[[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], [0, 11, 13]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [0, 2, 1], [1, 3, 2], [1, 4, 2], [2, 5, 3], [2, 6, 3], [3, 4, 4], [3, 5, 5], [4, 6, 6], [5, 6, 7]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=15, meetings=[[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], [9, 10, 10], [10, 11, 10], [11, 12, 10], [12, 13, 10], [13, 14, 10]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 5, 50], [5, 6, 60], [0, 6, 70]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=10, meetings=[[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, 9, 11], [1, 8, 12], [2, 7, 13], [3, 6, 14], [4, 5, 15]], firstPerson=5), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 5], [4, 6, 6], [5, 6, 7]], firstPerson=2), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5]], firstPerson=1), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=10, meetings=[[0, 9, 10], [1, 2, 10], [3, 4, 10], [5, 6, 10], [7, 8, 10], [1, 3, 10], [2, 4, 10], [5, 7, 10], [6, 8, 10]], firstPerson=1), [0, 1, 2, 3, 4, 9])\n assert answers_match(candidate(n=10, meetings=[[0, 1, 1], [1, 2, 2], [2, 0, 3], [0, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 0, 11]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 1], [2, 3, 2], [4, 5, 3], [6, 7, 4], [0, 2, 5], [1, 3, 6], [2, 4, 7], [3, 5, 8], [4, 6, 9], [5, 7, 10]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [5, 6, 5], [6, 0, 5]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=8, meetings=[[0, 1, 10], [1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 1], [1, 2, 1], [2, 3, 2], [3, 4, 2], [4, 5, 3], [5, 0, 3], [1, 4, 4], [2, 5, 5]], firstPerson=2), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 10], [1, 2, 15], [2, 3, 20], [3, 4, 25], [4, 5, 30], [5, 6, 35], [6, 0, 40]], firstPerson=6), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=15, meetings=[[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]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=8, meetings=[[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, 3, 9], [1, 5, 10]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7])\n assert answers_match(candidate(n=10, meetings=[[0, 4, 5], [4, 5, 5], [0, 1, 6], [1, 2, 6], [2, 3, 7], [3, 4, 7], [4, 6, 8], [5, 7, 9], [6, 8, 10], [7, 9, 11]], firstPerson=4), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=20, meetings=[[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, 0, 20]], firstPerson=19), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])\n assert answers_match(candidate(n=15, meetings=[[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], [0, 7, 16], [7, 11, 17], [11, 14, 18]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 0, 7], [0, 6, 8]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=15, meetings=[[0, 1, 1], [2, 3, 1], [4, 5, 1], [6, 7, 1], [8, 9, 1], [10, 11, 1], [12, 13, 1], [13, 14, 1], [0, 2, 2], [1, 3, 2], [4, 6, 2], [5, 7, 2], [8, 10, 2], [9, 11, 2], [12, 14, 2], [13, 0, 3], [14, 1, 3], [0, 4, 3], [1, 5, 3], [2, 6, 3], [3, 7, 3], [4, 8, 3], [5, 9, 3], [6, 10, 3], [7, 11, 3], [8, 12, 3], [9, 13, 3], [10, 14, 3]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=10, meetings=[[0, 1, 1], [0, 2, 1], [1, 3, 2], [1, 4, 2], [2, 5, 3], [2, 6, 3], [3, 4, 4], [3, 5, 5], [4, 6, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 0, 11], [0, 3, 12], [1, 5, 13], [2, 4, 14]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=10, meetings=[[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]], firstPerson=9), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [1, 2, 2], [0, 3, 3], [3, 4, 4], [0, 5, 5], [5, 6, 6], [2, 4, 7], [1, 6, 8]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 5, 6]], firstPerson=1), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=15, meetings=[[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]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=10, meetings=[[0, 9, 10], [1, 8, 10], [2, 7, 10], [3, 6, 10], [4, 5, 10], [0, 1, 20], [1, 2, 20], [2, 3, 20], [3, 4, 20], [4, 5, 20]], firstPerson=9), [0, 1, 2, 3, 4, 5, 9])\n assert answers_match(candidate(n=12, meetings=[[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], [0, 6, 13], [1, 7, 14], [2, 8, 15], [3, 9, 16], [4, 10, 17], [5, 11, 18]], firstPerson=6), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=6, meetings=[[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5]], firstPerson=1), [0, 1, 2, 3, 4, 5])\n assert answers_match(candidate(n=9, meetings=[[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, 10], [1, 3, 11], [2, 4, 12], [3, 5, 13], [4, 6, 14], [5, 7, 15], [6, 8, 16], [7, 0, 17], [8, 1, 18]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8])\n assert answers_match(candidate(n=15, meetings=[[0, 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, 11, 20], [11, 12, 21], [12, 13, 22], [13, 14, 23]], firstPerson=7), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])\n assert answers_match(candidate(n=12, meetings=[[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]], firstPerson=1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])\n assert answers_match(candidate(n=7, meetings=[[0, 1, 1], [0, 2, 2], [0, 3, 3], [1, 4, 4], [1, 5, 5], [2, 6, 6], [3, 6, 6], [4, 5, 5], [4, 6, 6], [5, 6, 6]], firstPerson=3), [0, 1, 2, 3, 4, 5, 6])\n", "comparison": "unordered"}, "public_tests": ["6\n[[1,2,5],[2,3,8],[1,5,10]]\n1", "4\n[[3,1,3],[1,2,2],[0,3,3]]\n3", "5\n[[3,4,2],[1,2,1],[2,3,1]]\n1"], "hints": ["Could you model all the meetings happening at the same time as a graph?", "What data structure can you use to efficiently share the secret?", "You can use the union-find data structure to quickly determine who knows the secret and share the secret."], "metadata": {"canonical_parameter_names": ["n", "meetings", "firstPerson"], "leetcode_dataset_entry_point": "Solution().findAllPeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:48+00:00", "tests_total": 84, "tests_dropped": 4, "flags": ["any_order"], "topic_tags": ["depth-first-search", "breadth-first-search", "union-find", "graph", "sorting"]}, "language": "php", "interface": {"raw_signature": "function findAllPeople($n, $meetings, $firstPerson) {", "container": "Solution", "callable": "findAllPeople", "parameters": [{"name": "n", "type": "Integer"}, {"name": "meetings", "type": "Integer[][]"}, {"name": "firstPerson", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2094, "task_id": "finding-3-digit-even-numbers", "difficulty": "Easy", "problem_description": "You are given an integer array digits, where each element is a digit. The array may contain duplicates.\n\nYou need to find all the unique integers that follow the given requirements:\n\n- The integer consists of the concatenation of three elements from digits in any arbitrary order.\n- The integer does not have leading zeros.\n- The integer is even.\n\nFor example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements.\n\nReturn a sorted array of the unique integers.\n\nExample 1:\n\nInput: digits = [2,1,3,0]\nOutput: [102,120,130,132,210,230,302,310,312,320]\nExplanation: All the possible integers that follow the requirements are in the output array.\nNotice that there are no odd integers or integers with leading zeros.\n\nExample 2:\n\nInput: digits = [2,2,8,8,2]\nOutput: [222,228,282,288,822,828,882]\nExplanation: The same digit can be used as many times as it appears in digits.\nIn this example, the digit 8 is used twice each time in 288, 828, and 882.\n\nExample 3:\n\nInput: digits = [3,7,5]\nOutput: []\nExplanation: No even integers can be formed using the given digits.\n\nConstraints:\n\n- 3 <= digits.length <= 100\n- 0 <= digits[i] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(digits = [1, 1, 1, 1, 1, 1]) == []\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == []\n assert candidate(digits = [2, 4, 6, 8, 0]) == [204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 402, 406, 408, 420, 426, 428, 460, 462, 468, 480, 482, 486, 602, 604, 608, 620, 624, 628, 640, 642, 648, 680, 682, 684, 802, 804, 806, 820, 824, 826, 840, 842, 846, 860, 862, 864]\n assert candidate(digits = [1, 0, 2, 4, 3, 5, 7, 9]) == [102, 104, 120, 124, 130, 132, 134, 140, 142, 150, 152, 154, 170, 172, 174, 190, 192, 194, 204, 210, 214, 230, 234, 240, 250, 254, 270, 274, 290, 294, 302, 304, 310, 312, 314, 320, 324, 340, 342, 350, 352, 354, 370, 372, 374, 390, 392, 394, 402, 410, 412, 420, 430, 432, 450, 452, 470, 472, 490, 492, 502, 504, 510, 512, 514, 520, 524, 530, 532, 534, 540, 542, 570, 572, 574, 590, 592, 594, 702, 704, 710, 712, 714, 720, 724, 730, 732, 734, 740, 742, 750, 752, 754, 790, 792, 794, 902, 904, 910, 912, 914, 920, 924, 930, 932, 934, 940, 942, 950, 952, 954, 970, 972, 974]\n assert candidate(digits = [2, 1, 3, 0]) == [102, 120, 130, 132, 210, 230, 302, 310, 312, 320]\n assert candidate(digits = [0, 2, 4, 6, 8]) == [204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 402, 406, 408, 420, 426, 428, 460, 462, 468, 480, 482, 486, 602, 604, 608, 620, 624, 628, 640, 642, 648, 680, 682, 684, 802, 804, 806, 820, 824, 826, 840, 842, 846, 860, 862, 864]\n assert candidate(digits = [1, 0, 0, 0]) == [100]\n assert candidate(digits = [2, 4, 6, 8]) == [246, 248, 264, 268, 284, 286, 426, 428, 462, 468, 482, 486, 624, 628, 642, 648, 682, 684, 824, 826, 842, 846, 862, 864]\n assert candidate(digits = [1, 3, 5, 7, 9]) == []\n assert candidate(digits = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == []\n assert candidate(digits = [2, 2, 8, 8, 2]) == [222, 228, 282, 288, 822, 828, 882]\n assert candidate(digits = [3, 7, 5]) == []\n assert candidate(digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [0, 0, 0]) == []\n assert candidate(digits = [0, 2, 2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8]) == [202, 204, 206, 208, 220, 222, 224, 226, 228, 240, 242, 244, 246, 248, 260, 262, 264, 266, 268, 280, 282, 284, 286, 288, 402, 404, 406, 408, 420, 422, 424, 426, 428, 440, 442, 444, 446, 448, 460, 462, 464, 466, 468, 480, 482, 484, 486, 488, 602, 604, 606, 608, 620, 622, 624, 626, 628, 640, 642, 644, 646, 648, 660, 662, 664, 666, 668, 680, 682, 684, 686, 688, 802, 804, 806, 808, 820, 822, 824, 826, 828, 840, 842, 844, 846, 848, 860, 862, 864, 866, 868, 880, 882, 884, 886, 888]\n assert candidate(digits = [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]) == [100, 102, 110, 112, 120, 122, 130, 132, 200, 202, 210, 212, 220, 222, 230, 232, 300, 302, 310, 312, 320, 322, 330, 332]\n assert candidate(digits = [9, 9, 9, 0, 0, 0, 1, 1, 1, 2]) == [100, 102, 110, 112, 120, 190, 192, 200, 210, 290, 900, 902, 910, 912, 920, 990, 992]\n assert candidate(digits = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [0, 0, 0, 1, 1, 1, 2, 2, 2]) == [100, 102, 110, 112, 120, 122, 200, 202, 210, 212, 220, 222]\n assert candidate(digits = [0, 0, 2, 4, 6, 8]) == [200, 204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 400, 402, 406, 408, 420, 426, 428, 460, 462, 468, 480, 482, 486, 600, 602, 604, 608, 620, 624, 628, 640, 642, 648, 680, 682, 684, 800, 802, 804, 806, 820, 824, 826, 840, 842, 846, 860, 862, 864]\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 9, 0]) == [990]\n assert candidate(digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0]) == [200, 202, 220, 222]\n assert candidate(digits = [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]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [9, 9, 9, 0, 0, 0, 1, 1, 1]) == [100, 110, 190, 900, 910, 990]\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]) == [100, 110]\n assert candidate(digits = [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(digits = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0, 0]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == [888]\n assert candidate(digits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 0]) == [550]\n assert candidate(digits = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [5, 5, 5, 5, 5, 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(digits = [2, 2, 0, 0, 8, 8]) == [200, 202, 208, 220, 228, 280, 282, 288, 800, 802, 808, 820, 822, 828, 880, 882]\n assert candidate(digits = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [800, 808, 880, 888]\n assert candidate(digits = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == [112, 114, 122, 124, 132, 134, 142, 144, 212, 214, 222, 224, 232, 234, 242, 244, 312, 314, 322, 324, 332, 334, 342, 344, 412, 414, 422, 424, 432, 434, 442, 444]\n assert candidate(digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0]) == [550]\n assert candidate(digits = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == [200, 202, 204, 206, 208, 220, 224, 226, 228, 240, 242, 244, 246, 248, 260, 262, 264, 266, 268, 280, 282, 284, 286, 288, 400, 402, 404, 406, 408, 420, 422, 424, 426, 428, 440, 442, 446, 448, 460, 462, 464, 466, 468, 480, 482, 484, 486, 488, 600, 602, 604, 606, 608, 620, 622, 624, 626, 628, 640, 642, 644, 646, 648, 660, 662, 664, 668, 680, 682, 684, 686, 688, 800, 802, 804, 806, 808, 820, 822, 824, 826, 828, 840, 842, 844, 846, 848, 860, 862, 864, 866, 868, 880, 882, 884, 886]\n assert candidate(digits = [0, 0, 1, 2, 4, 6]) == [100, 102, 104, 106, 120, 124, 126, 140, 142, 146, 160, 162, 164, 200, 204, 206, 210, 214, 216, 240, 246, 260, 264, 400, 402, 406, 410, 412, 416, 420, 426, 460, 462, 600, 602, 604, 610, 612, 614, 620, 624, 640, 642]\n assert candidate(digits = [4, 4, 4, 4, 4, 4, 4]) == [444]\n assert candidate(digits = [4, 4, 4, 4, 1, 1, 1, 1, 0, 0, 0, 0]) == [100, 104, 110, 114, 140, 144, 400, 404, 410, 414, 440, 444]\n assert candidate(digits = [0, 2, 2, 0, 4, 6, 8]) == [200, 202, 204, 206, 208, 220, 224, 226, 228, 240, 242, 246, 248, 260, 262, 264, 268, 280, 282, 284, 286, 400, 402, 406, 408, 420, 422, 426, 428, 460, 462, 468, 480, 482, 486, 600, 602, 604, 608, 620, 622, 624, 628, 640, 642, 648, 680, 682, 684, 800, 802, 804, 806, 820, 822, 824, 826, 840, 842, 846, 860, 862, 864]\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [112, 122, 212, 222]\n assert candidate(digits = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [124, 126, 128, 132, 134, 136, 138, 142, 146, 148, 152, 154, 156, 158, 162, 164, 168, 172, 174, 176, 178, 182, 184, 186, 192, 194, 196, 198, 214, 216, 218, 234, 236, 238, 246, 248, 254, 256, 258, 264, 268, 274, 276, 278, 284, 286, 294, 296, 298, 312, 314, 316, 318, 324, 326, 328, 342, 346, 348, 352, 354, 356, 358, 362, 364, 368, 372, 374, 376, 378, 382, 384, 386, 392, 394, 396, 398, 412, 416, 418, 426, 428, 432, 436, 438, 452, 456, 458, 462, 468, 472, 476, 478, 482, 486, 492, 496, 498, 512, 514, 516, 518, 524, 526, 528, 532, 534, 536, 538, 542, 546, 548, 562, 564, 568, 572, 574, 576, 578, 582, 584, 586, 592, 594, 596, 598, 612, 614, 618, 624, 628, 632, 634, 638, 642, 648, 652, 654, 658, 672, 674, 678, 682, 684, 692, 694, 698, 712, 714, 716, 718, 724, 726, 728, 732, 734, 736, 738, 742, 746, 748, 752, 754, 756, 758, 762, 764, 768, 782, 784, 786, 792, 794, 796, 798, 812, 814, 816, 824, 826, 832, 834, 836, 842, 846, 852, 854, 856, 862, 864, 872, 874, 876, 892, 894, 896, 912, 914, 916, 918, 924, 926, 928, 932, 934, 936, 938, 942, 946, 948, 952, 954, 956, 958, 962, 964, 968, 972, 974, 976, 978, 982, 984, 986]\n assert candidate(digits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [100, 102, 110, 112, 120, 122, 200, 202, 210, 212, 220, 222]\n assert candidate(digits = [2, 4, 6, 8, 0, 0, 0, 0, 0, 0]) == [200, 204, 206, 208, 240, 246, 248, 260, 264, 268, 280, 284, 286, 400, 402, 406, 408, 420, 426, 428, 460, 462, 468, 480, 482, 486, 600, 602, 604, 608, 620, 624, 628, 640, 642, 648, 680, 682, 684, 800, 802, 804, 806, 820, 824, 826, 840, 842, 846, 860, 862, 864]\n assert candidate(digits = [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]) == [112, 114, 116, 118, 122, 124, 126, 128, 132, 134, 136, 138, 142, 144, 146, 148, 152, 154, 156, 158, 162, 164, 166, 168, 172, 174, 176, 178, 182, 184, 186, 188, 192, 194, 196, 198, 212, 214, 216, 218, 222, 224, 226, 228, 232, 234, 236, 238, 242, 244, 246, 248, 252, 254, 256, 258, 262, 264, 266, 268, 272, 274, 276, 278, 282, 284, 286, 288, 292, 294, 296, 298, 312, 314, 316, 318, 322, 324, 326, 328, 332, 334, 336, 338, 342, 344, 346, 348, 352, 354, 356, 358, 362, 364, 366, 368, 372, 374, 376, 378, 382, 384, 386, 388, 392, 394, 396, 398, 412, 414, 416, 418, 422, 424, 426, 428, 432, 434, 436, 438, 442, 444, 446, 448, 452, 454, 456, 458, 462, 464, 466, 468, 472, 474, 476, 478, 482, 484, 486, 488, 492, 494, 496, 498, 512, 514, 516, 518, 522, 524, 526, 528, 532, 534, 536, 538, 542, 544, 546, 548, 552, 554, 556, 558, 562, 564, 566, 568, 572, 574, 576, 578, 582, 584, 586, 588, 592, 594, 596, 598, 612, 614, 616, 618, 622, 624, 626, 628, 632, 634, 636, 638, 642, 644, 646, 648, 652, 654, 656, 658, 662, 664, 666, 668, 672, 674, 676, 678, 682, 684, 686, 688, 692, 694, 696, 698, 712, 714, 716, 718, 722, 724, 726, 728, 732, 734, 736, 738, 742, 744, 746, 748, 752, 754, 756, 758, 762, 764, 766, 768, 772, 774, 776, 778, 782, 784, 786, 788, 792, 794, 796, 798, 812, 814, 816, 818, 822, 824, 826, 828, 832, 834, 836, 838, 842, 844, 846, 848, 852, 854, 856, 858, 862, 864, 866, 868, 872, 874, 876, 878, 882, 884, 886, 888, 892, 894, 896, 898, 912, 914, 916, 918, 922, 924, 926, 928, 932, 934, 936, 938, 942, 944, 946, 948, 952, 954, 956, 958, 962, 964, 966, 968, 972, 974, 976, 978, 982, 984, 986, 988, 992, 994, 996, 998]\n assert candidate(digits = [0, 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]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 888, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [222]\n assert candidate(digits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == []\n assert candidate(digits = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [222]\n assert candidate(digits = [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]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == [112]\n assert candidate(digits = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == [112, 122, 132, 212, 222, 232, 312, 322, 332]\n assert candidate(digits = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == [102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == []\n assert candidate(digits = [1, 0, 2, 3, 4, 5, 6, 7, 8, 9]) == [102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [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, 0]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 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(digits = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(digits = [5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [222, 252, 522, 552]\n assert candidate(digits = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == [112, 122, 212, 222]\n assert candidate(digits = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0, 0, 0, 0]) == [100, 102, 104, 106, 108, 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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == [100, 110]\n assert candidate(digits = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [118, 188, 818, 888]\n assert candidate(digits = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == [500, 550]\n assert candidate(digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0, 0]) == [100, 102, 104, 106, 108, 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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998]\n assert candidate(digits = [2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2]) == [200, 202, 220, 222]\n assert candidate(digits = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == [100, 102, 104, 120, 124, 130, 132, 134, 140, 142, 150, 152, 154, 200, 204, 210, 214, 230, 234, 240, 250, 254, 300, 302, 304, 310, 312, 314, 320, 324, 340, 342, 350, 352, 354, 400, 402, 410, 412, 420, 430, 432, 450, 452, 500, 502, 504, 510, 512, 514, 520, 524, 530, 532, 534, 540, 542]\n assert candidate(digits = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == [444]\n assert candidate(digits = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [222]\n assert candidate(digits = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == []\n assert candidate(digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 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(digits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == []\n assert candidate(digits = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == [112, 122, 212, 222]\n assert candidate(digits = [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]) == [100, 102, 104, 106, 108, 120, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 200, 204, 206, 208, 210, 214, 216, 218, 230, 234, 236, 238, 240, 246, 248, 250, 254, 256, 258, 260, 264, 268, 270, 274, 276, 278, 280, 284, 286, 290, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 324, 326, 328, 340, 342, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 390, 392, 394, 396, 398, 400, 402, 406, 408, 410, 412, 416, 418, 420, 426, 428, 430, 432, 436, 438, 450, 452, 456, 458, 460, 462, 468, 470, 472, 476, 478, 480, 482, 486, 490, 492, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 546, 548, 560, 562, 564, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 590, 592, 594, 596, 598, 600, 602, 604, 608, 610, 612, 614, 618, 620, 624, 628, 630, 632, 634, 638, 640, 642, 648, 650, 652, 654, 658, 670, 672, 674, 678, 680, 682, 684, 690, 692, 694, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 768, 780, 782, 784, 786, 790, 792, 794, 796, 798, 800, 802, 804, 806, 810, 812, 814, 816, 820, 824, 826, 830, 832, 834, 836, 840, 842, 846, 850, 852, 854, 856, 860, 862, 864, 870, 872, 874, 876, 890, 892, 894, 896, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986]\n assert candidate(digits = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == [122, 124, 126, 132, 134, 136, 142, 144, 146, 152, 154, 156, 162, 164, 166, 212, 214, 216, 224, 226, 232, 234, 236, 242, 244, 246, 252, 254, 256, 262, 264, 266, 312, 314, 316, 322, 324, 326, 332, 334, 336, 342, 344, 346, 352, 354, 356, 362, 364, 366, 412, 414, 416, 422, 424, 426, 432, 434, 436, 442, 446, 452, 454, 456, 462, 464, 466, 512, 514, 516, 522, 524, 526, 532, 534, 536, 542, 544, 546, 552, 554, 556, 562, 564, 566, 612, 614, 616, 622, 624, 626, 632, 634, 636, 642, 644, 646, 652, 654, 656, 662, 664]\n assert candidate(digits = [0, 1, 2, 2, 4, 6, 8, 8, 8, 9]) == [102, 104, 106, 108, 120, 122, 124, 126, 128, 140, 142, 146, 148, 160, 162, 164, 168, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 224, 226, 228, 240, 242, 246, 248, 260, 262, 264, 268, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 402, 406, 408, 410, 412, 416, 418, 420, 422, 426, 428, 460, 462, 468, 480, 482, 486, 488, 490, 492, 496, 498, 602, 604, 608, 610, 612, 614, 618, 620, 622, 624, 628, 640, 642, 648, 680, 682, 684, 688, 690, 692, 694, 698, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 840, 842, 846, 848, 860, 862, 864, 868, 880, 882, 884, 886, 888, 890, 892, 894, 896, 898, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 940, 942, 946, 948, 960, 962, 964, 968, 980, 982, 984, 986, 988]\n assert candidate(digits = [2, 2, 2, 2, 2]) == [222]\n assert candidate(digits = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [112, 114, 122, 124, 132, 134, 142, 144, 152, 154, 212, 214, 224, 232, 234, 242, 244, 252, 254, 312, 314, 322, 324, 332, 334, 342, 344, 352, 354, 412, 414, 422, 424, 432, 434, 442, 452, 454, 512, 514, 522, 524, 532, 534, 542, 544, 552, 554]\n assert candidate(digits = [7, 7, 7, 7, 7, 8, 8, 8, 8, 8]) == [778, 788, 878, 888]\n assert candidate(digits = [0, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == [102, 110, 112, 120, 122, 130, 132, 202, 210, 212, 220, 222, 230, 232, 302, 310, 312, 320, 322, 330, 332]\n assert candidate(digits = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == []\n assert candidate(digits = [5, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8]) == [200, 202, 204, 206, 208, 220, 222, 224, 226, 228, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 280, 282, 284, 286, 288, 400, 402, 404, 406, 408, 420, 422, 424, 426, 428, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 480, 482, 484, 486, 488, 500, 502, 504, 506, 508, 520, 522, 524, 526, 528, 540, 542, 544, 546, 548, 560, 562, 564, 566, 568, 580, 582, 584, 586, 588, 600, 602, 604, 606, 608, 620, 622, 624, 626, 628, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 680, 682, 684, 686, 688, 800, 802, 804, 806, 808, 820, 822, 824, 826, 828, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 880, 882, 884, 886, 888]\n", "comparison": "exact"}, "public_tests": ["[2,1,3,0]", "[2,2,8,8,2]", "[3,7,5]"], "hints": ["The range of possible answers includes all even numbers between 100 and 999 inclusive. Could you check each possible answer to see if it could be formed from the digits in the array?"], "metadata": {"canonical_parameter_names": ["digits"], "leetcode_dataset_entry_point": "Solution().findEvenNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:40:53+00:00", "tests_total": 91, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "recursion", "sorting", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function findEvenNumbers($digits) {", "container": "Solution", "callable": "findEvenNumbers", "parameters": [{"name": "digits", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2097, "task_id": "valid-arrangement-of-pairs", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array pairs where pairs[i] = [start_i, end_i]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have end_{i-1} == start_i.\n\nReturn any valid arrangement of pairs.\n\nNote: The inputs will be generated such that there exists a valid arrangement of pairs.\n\nExample 1:\n\nInput: pairs = [[5,1],[4,5],[11,9],[9,4]]\nOutput: [[11,9],[9,4],[4,5],[5,1]]\nExplanation:\nThis is a valid arrangement since end_{i-1} always equals start_i.\nend_0 = 9 == 9 = start_1\nend_1 = 4 == 4 = start_2\nend_2 = 5 == 5 = start_3\n\nExample 2:\n\nInput: pairs = [[1,3],[3,2],[2,1]]\nOutput: [[1,3],[3,2],[2,1]]\nExplanation:\nThis is a valid arrangement since end_{i-1} always equals start_i.\nend_0 = 3 == 3 = start_1\nend_1 = 2 == 2 = start_2\nThe arrangements [[2,1],[1,3],[3,2]] and [[3,2],[2,1],[1,3]] are also valid.\n\nExample 3:\n\nInput: pairs = [[1,2],[1,3],[2,1]]\nOutput: [[1,2],[2,1],[1,3]]\nExplanation:\nThis is a valid arrangement since end_{i-1} always equals start_i.\nend_0 = 2 == 2 = start_1\nend_1 = 1 == 1 = start_2\n\nConstraints:\n\n- 1 <= pairs.length <= 10^5\n- pairs[i].length == 2\n- 0 <= start_i, end_i <= 10^9\n- start_i != end_i\n- No two pairs are exactly the same.\n- There exists a valid arrangement of pairs.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pairs = [[0, 1], [1, 2], [2, 3], [3, 4]]) == [[0, 1], [1, 2], [2, 3], [3, 4]]\n assert candidate(pairs = [[0, 1], [1, 2], [2, 3], [3, 0]]) == [[0, 1], [1, 2], [2, 3], [3, 0]]\n assert candidate(pairs = [[1, 2], [1, 3], [2, 1]]) == [[1, 2], [2, 1], [1, 3]]\n assert candidate(pairs = [[10, 20], [20, 30], [30, 40], [40, 50]]) == [[10, 20], [20, 30], [30, 40], [40, 50]]\n assert candidate(pairs = [[1, 3], [3, 2], [2, 1]]) == [[1, 3], [3, 2], [2, 1]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 100]]) == [[100, 200], [200, 300], [300, 100]]\n assert candidate(pairs = [[10, 20], [20, 30], [30, 40], [40, 10]]) == [[10, 20], [20, 30], [30, 40], [40, 10]]\n assert candidate(pairs = [[5, 1], [4, 5], [11, 9], [9, 4]]) == [[11, 9], [9, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 1]]) == [[1, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 1]]\n assert candidate(pairs = [[7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 7]]) == [[7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 7]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 100]]) == [[100, 200], [200, 300], [300, 400], [400, 500], [500, 100]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5], [5, 2], [2, 4], [4, 1]]) == [[1, 3], [3, 5], [5, 2], [2, 4], [4, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5]]) == [[1, 3], [3, 5], [5, 1], [1, 2], [2, 3], [3, 4], [4, 5]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 11], [11, 12], [12, 13], [13, 1]]) == [[1, 11], [11, 12], [12, 13], [13, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]\n assert candidate(pairs = [[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, 1]]\n assert candidate(pairs = [[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]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [1, 10], [10, 11], [11, 1]]) == [[1, 10], [10, 11], [11, 1], [1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 1]]) == [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7]]) == [[1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[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], [1, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 1], [1, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 1], [1, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 1]]) == [[1, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 1], [1, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 1], [1, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 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]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5]]) == [[1, 3], [3, 5], [5, 1], [1, 2], [2, 3], [3, 4], [4, 5]]\n assert candidate(pairs = [[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, 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, 1]]\n assert candidate(pairs = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1], [1, 5], [5, 1]]) == [[1, 5], [5, 1], [1, 4], [4, 1], [1, 3], [3, 1], [1, 2], [2, 1]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 1], [1, 60], [60, 70], [70, 80], [80, 1]]) == [[1, 60], [60, 70], [70, 80], [80, 1], [1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 1]]\n assert candidate(pairs = [[5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5]]) == [[5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 100], [100, 400], [400, 500], [500, 100]]) == [[100, 400], [400, 500], [500, 100], [100, 200], [200, 300], [300, 100]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [2, 7], [7, 8], [8, 9], [9, 10], [10, 2]]) == [[1, 2], [2, 7], [7, 8], [8, 9], [9, 10], [10, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]\n assert candidate(pairs = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 1], [1, 13], [13, 2]]) == [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 1], [1, 13], [13, 2]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 1], [1, 3], [3, 2], [2, 4], [4, 3], [3, 1], [1, 4], [4, 2], [2, 1]]) == [[1, 4], [4, 2], [2, 1], [1, 3], [3, 1], [1, 2], [2, 4], [4, 3], [3, 2], [2, 3], [3, 4], [4, 1]]\n assert candidate(pairs = [[1, 2], [3, 1], [2, 3], [4, 2], [3, 5], [5, 4], [4, 1]]) == [[3, 5], [5, 4], [4, 2], [4, 1], [1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [7, 8], [8, 9], [9, 10], [10, 7]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]\n assert candidate(pairs = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 10], [10, 30], [30, 50], [50, 20], [20, 40], [40, 10]]) == [[10, 30], [30, 50], [50, 20], [20, 40], [40, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 10]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [1, 10], [10, 11], [11, 1], [12, 13], [13, 14], [14, 12]]) == [[1, 10], [10, 11], [11, 1], [1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1, 999], [999, 2], [2, 998], [998, 3], [3, 997], [997, 4], [4, 996], [996, 5], [5, 995], [995, 1]]) == [[1, 999], [999, 2], [2, 998], [998, 3], [3, 997], [997, 4], [4, 996], [996, 5], [5, 995], [995, 1]]\n assert candidate(pairs = [[1, 9], [9, 7], [7, 3], [3, 5], [5, 1], [1, 8], [8, 6], [6, 2], [2, 4], [4, 1]]) == [[1, 8], [8, 6], [6, 2], [2, 4], [4, 1], [1, 9], [9, 7], [7, 3], [3, 5], [5, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == [[1, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 4]]) == [[1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1000000, 2000000], [2000000, 3000000], [3000000, 1000000], [500000, 1000000]]) == [[500000, 1000000], [1000000, 2000000], [2000000, 3000000], [3000000, 1000000]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 100]]) == [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 100]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 7], [7, 4], [8, 9], [9, 10], [10, 8]]) == [[1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[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]]) == [[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]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 4]]) == [[1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1000, 2000], [2000, 3000], [3000, 1000], [1000, 4000], [4000, 5000], [5000, 6000], [6000, 1000]]) == [[1000, 4000], [4000, 5000], [5000, 6000], [6000, 1000], [1000, 2000], [2000, 3000], [3000, 1000]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]\n assert candidate(pairs = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 5]]) == [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 5]]\n assert candidate(pairs = [[1, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 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, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 6], [6, 7], [7, 8], [8, 1], [1, 9], [9, 10], [10, 1]]) == [[1, 9], [9, 10], [10, 1], [1, 6], [6, 7], [7, 8], [8, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[5, 6], [6, 5], [5, 7], [7, 5], [5, 8], [8, 5], [5, 9], [9, 5], [5, 10], [10, 5]]) == [[5, 10], [10, 5], [5, 9], [9, 5], [5, 8], [8, 5], [5, 7], [7, 5], [5, 6], [6, 5]]\n assert candidate(pairs = [[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, 1], [1, 20], [20, 3], [3, 21], [21, 1]]) == [[1, 20], [20, 3], [3, 21], [21, 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, 1]]\n assert candidate(pairs = [[7, 8], [8, 9], [9, 10], [10, 11], [11, 7], [7, 12], [12, 8]]) == [[7, 12], [12, 8], [8, 9], [9, 10], [10, 11], [11, 7], [7, 8]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 100]]) == [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 100]]\n assert candidate(pairs = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55], [55, 60], [60, 5]]) == [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55], [55, 60], [60, 5]]\n assert candidate(pairs = [[7, 8], [8, 9], [9, 10], [10, 11], [11, 7], [7, 9], [9, 11], [11, 8]]) == [[7, 9], [9, 11], [11, 8], [8, 9], [9, 10], [10, 11], [11, 7], [7, 8]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 11], [14, 15], [15, 16], [16, 14], [17, 18], [18, 19], [19, 20], [20, 17]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 9], [9, 10], [10, 11], [11, 12], [12, 1], [1, 13], [13, 14], [14, 15], [15, 1], [1, 16], [16, 17], [17, 18], [18, 1]]) == [[1, 16], [16, 17], [17, 18], [18, 1], [1, 13], [13, 14], [14, 15], [15, 1], [1, 9], [9, 10], [10, 11], [11, 12], [12, 1]]\n assert candidate(pairs = [[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]]) == [[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]]\n assert candidate(pairs = [[1, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 61], [61, 71], [71, 81], [81, 91], [91, 1]]) == [[1, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 61], [61, 71], [71, 81], [81, 91], [91, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 10], [10, 2]]) == [[1, 10], [10, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 2]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 100], [100, 600], [600, 700], [700, 800], [800, 900], [900, 100]]) == [[100, 600], [600, 700], [700, 800], [800, 900], [900, 100], [100, 200], [200, 300], [300, 400], [400, 500], [500, 100]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 1], [60, 70], [70, 80], [80, 90], [90, 100], [100, 60]]) == [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 1]]\n assert candidate(pairs = [[5, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5]]) == [[5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5], [5, 1], [1, 2], [2, 3], [3, 4], [4, 5]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [1, 4], [4, 7], [7, 1]]) == [[1, 4], [4, 5], [5, 6], [6, 4], [4, 7], [7, 8], [8, 9], [9, 7], [7, 1], [1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 1]]) == [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 1]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 1]]) == [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 1]]\n assert candidate(pairs = [[1, 1000000000], [1000000000, 999999999], [999999999, 888888888], [888888888, 1]]) == [[1, 1000000000], [1000000000, 999999999], [999999999, 888888888], [888888888, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 10], [10, 11], [11, 12], [12, 1]]) == [[1, 10], [10, 11], [11, 12], [12, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 11], [14, 15], [15, 16], [16, 14], [17, 18], [18, 19], [19, 20], [20, 17], [21, 22], [22, 23], [23, 21]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 1], [1, 4], [4, 5], [5, 1], [1, 6], [6, 7], [7, 1]]) == [[1, 6], [6, 7], [7, 1], [1, 4], [4, 5], [5, 1], [1, 2], [2, 3], [3, 1]]\n assert candidate(pairs = [[3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 3]]) == [[3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 3]]\n assert candidate(pairs = [[11, 22], [22, 33], [33, 44], [44, 55], [55, 66], [66, 77], [77, 88], [88, 99], [99, 11]]) == [[11, 22], [22, 33], [33, 44], [44, 55], [55, 66], [66, 77], [77, 88], [88, 99], [99, 11]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 100], [100, 300], [300, 500], [500, 200]]) == [[100, 300], [300, 500], [500, 200], [200, 300], [300, 400], [400, 500], [500, 100], [100, 200]]\n assert candidate(pairs = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 1], [1, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 61], [61, 71], [71, 81], [81, 91], [91, 1]]) == [[1, 11], [11, 21], [21, 31], [31, 41], [41, 51], [51, 61], [61, 71], [71, 81], [81, 91], [91, 1], [1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 1]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 5]]) == [[1, 2], [2, 3], [3, 4], [4, 1]]\n assert candidate(pairs = [[1, 2], [2, 1], [1, 3], [3, 1], [1, 4], [4, 1], [1, 5], [5, 1], [1, 6], [6, 1], [1, 7], [7, 1], [1, 8], [8, 1], [1, 9], [9, 1], [1, 10], [10, 1]]) == [[1, 10], [10, 1], [1, 9], [9, 1], [1, 8], [8, 1], [1, 7], [7, 1], [1, 6], [6, 1], [1, 5], [5, 1], [1, 4], [4, 1], [1, 3], [3, 1], [1, 2], [2, 1]]\n assert candidate(pairs = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [1000, 100]]) == [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [1000, 100]]\n assert candidate(pairs = [[1, 2], [2, 3], [3, 4], [4, 1], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 4]]) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 4], [4, 1]]\n assert candidate(pairs = [[123, 456], [456, 789], [789, 101], [101, 112], [112, 234], [234, 345], [345, 123]]) == [[123, 456], [456, 789], [789, 101], [101, 112], [112, 234], [234, 345], [345, 123]]\n", "comparison": "exact"}, "public_tests": ["[[5,1],[4,5],[11,9],[9,4]]", "[[1,3],[3,2],[2,1]]", "[[1,2],[1,3],[2,1]]"], "hints": ["Could you convert this into a graph problem?", "Consider the pairs as edges and each number as a node.", "We have to find an Eulerian path of this graph. Hierholzer’s algorithm can be used."], "metadata": {"canonical_parameter_names": ["pairs"], "leetcode_dataset_entry_point": "Solution().validArrangement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:00+00:00", "tests_total": 79, "tests_dropped": 0, "flags": ["multiple_answers"], "topic_tags": ["array", "depth-first-search", "graph", "eulerian-circuit", "eulerian-path", "semi-eulerian-graph"]}, "language": "php", "interface": {"raw_signature": "function validArrangement($pairs) {", "container": "Solution", "callable": "validArrangement", "parameters": [{"name": "pairs", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2099, "task_id": "find-subsequence-of-length-k-with-the-largest-sum", "difficulty": "Easy", "problem_description": "You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.\n\nReturn any such subsequence as an integer array of length k.\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 = [2,1,3,3], k = 2\nOutput: [3,3]\nExplanation:\nThe subsequence has the largest sum of 3 + 3 = 6.\n\nExample 2:\n\nInput: nums = [-1,-2,3,4], k = 3\nOutput: [-1,3,4]\nExplanation:\nThe subsequence has the largest sum of -1 + 3 + 4 = 6.\n\nExample 3:\n\nInput: nums = [3,4,3,3], k = 2\nOutput: [3,4]\nExplanation:\nThe subsequence has the largest sum of 3 + 4 = 7.\nAnother possible subsequence is [4, 3].\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- -10^5 <= nums[i] <= 10^5\n- 1 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 3, 1, 2, 4],k = 5) == [5, 3, 1, 2, 4]\n assert candidate(nums = [10, 10, 10, 10, 10],k = 3) == [10, 10, 10]\n assert candidate(nums = [0, 0, 0, 0],k = 2) == [0, 0]\n assert candidate(nums = [-1, -2, 3, 4],k = 3) == [-1, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == [3, 4, 5]\n assert candidate(nums = [5, 1, 2, 3, 4],k = 3) == [5, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == [6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [-1, -2, -3, -4],k = 2) == [-1, -2]\n assert candidate(nums = [-1, -1, -1, -1, -1],k = 3) == [-1, -1, -1]\n assert candidate(nums = [100, 200, 300, 400, 500],k = 4) == [200, 300, 400, 500]\n assert candidate(nums = [1],k = 1) == [1]\n assert candidate(nums = [2, 1, 3, 3],k = 2) == [3, 3]\n assert candidate(nums = [-10, -20, -30, -40],k = 2) == [-10, -20]\n assert candidate(nums = [5, 4, 3, 2, 1],k = 4) == [5, 4, 3, 2]\n assert candidate(nums = [100000, -100000, 50000, -50000, 0],k = 2) == [100000, 50000]\n assert candidate(nums = [10, -2, 0, 5],k = 2) == [10, 5]\n assert candidate(nums = [5, 1, 2, 4, 3],k = 3) == [5, 4, 3]\n assert candidate(nums = [3, 4, 3, 3],k = 2) == [4, 3]\n assert candidate(nums = [-5, -4, -3, -2, -1],k = 2) == [-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],k = 10) == [16, 17, 18, 19, 20, 21, 22, 23, 24, 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],k = 15) == [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],k = 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 3) == [100, 90, 80]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 7) == [50, 50, 50, 50, 50, 50, 50]\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 3) == [-1, -2, -3]\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000],k = 4) == [300, 500, 700, 900]\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50],k = 7) == [10, 20, 30, 40, 50, -10, -20]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 7) == [-1, -2, -3, -4, -5, -6, -7]\n assert candidate(nums = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],k = 6) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [100000, -50000, 100000, -50000, 100000],k = 3) == [100000, 100000, 100000]\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],k = 5) == [10, 30, 50, 70, 90]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 15) == [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],k = 3) == [-1, -2, -3]\n assert candidate(nums = [100, 200, 300, 400, 500],k = 1) == [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, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50],k = 5) == [10, 20, 30, 40, 50]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],k = 7) == [70, 80, 90, 100, 110, 120, 130]\n assert candidate(nums = [-10, 100, -20, 200, -30, 300, -40, 400, -50, 500, -60, 600, -70, 700, -80, 800],k = 8) == [100, 200, 300, 400, 500, 600, 700, 800]\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, 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 = 15) == [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [10, -1, 2, 9, 3, 8, 4, 7, 5, 6],k = 5) == [10, 9, 8, 7, 6]\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],k = 15) == [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],k = 3) == [99999, 99998, 99997]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 3) == [100, 90, 80]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 5) == [1, 2, 3, 4, 5]\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 8) == [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]\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) == [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, 0, -1, -2, -3, -4, -5],k = 7) == [10, 9, 8, 7, 6, 5, 4]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == [1, 1, 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],k = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 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, 1, 1, 1, 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) == [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, -1, 2, -3, 4, -5, 6, -7, 8, -9],k = 5) == [10, 2, 4, 6, 8]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40, -50, -60, -70, -80, -90],k = 15) == [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30, -40]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == [9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500],k = 5) == [100, 200, 300, 400, 500]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 15) == [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, -1, -2, -3, -4, -5]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 4) == [-1, -2, -3, -4]\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 1100, -1200, 1300],k = 7) == [100, 300, 500, 700, 900, 1100, 1300]\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) == [6, 6, 7, 7, 8, 8, 9, 9, 10, 10]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 4) == [50, 50, 50, 50]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == [60, 70, 80, 90, 100]\n assert candidate(nums = [100000, -100000, 50000, -50000, 0, 25000, -25000, 75000, -75000],k = 3) == [100000, 50000, 75000]\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) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],k = 10) == [7, 6, 9, 8, 11, 10, 13, 12, 15, 14]\n assert candidate(nums = [-100, -200, -300, -400, -500],k = 3) == [-100, -200, -300]\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 8) == [1000, 900, 800, 700, 600, 500, 400, 300]\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, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],k = 5) == [1, 3, 5, 7, 9]\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 3) == [-10, -20, -30]\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],k = 10) == [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 6) == [1, -1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 10) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 6) == [9, 8, 7, 6, 5, 4]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 3) == [0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == [9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 10) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [10000, -10000, 20000, -20000, 30000, -30000, 40000, -40000],k = 4) == [10000, 20000, 30000, 40000]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 3) == [-1, -2, -3]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == [0, 0, 0, 0, 0]\n assert candidate(nums = [9, 1, 2, 3, 4, 5, 6, 7, 8, 10],k = 5) == [9, 6, 7, 8, 10]\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],k = 10) == [300, 400, 500, 300, 400, 500, 200, 300, 400, 500]\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 = 20) == [21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 6) == [25, 30, 35, 40, 45, 50]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 5) == [0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7) == [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],k = 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, 11, 12, 13, 14, 15],k = 10) == [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110],k = 5) == [-10, -20, -30, -40, -50]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == [15, 14, 13, 12, 11, 10, 9, 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, 5, 5, 5, 5],k = 25) == [5, 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 = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97, 48, 24, 12, 6, 3, 1],k = 10) == [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 8) == [1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [-10, -20, -30, -40, -50, 100, 200],k = 3) == [-10, 100, 200]\n", "comparison": "exact"}, "public_tests": ["[2,1,3,3]\n2", "[-1,-2,3,4]\n3", "[3,4,3,3]\n2"], "hints": ["From a greedy perspective, what k elements should you pick?", "Could you sort the array while maintaining the index?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maxSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:05+00:00", "tests_total": 99, "tests_dropped": 1, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maxSubsequence($nums, $k) {", "container": "Solution", "callable": "maxSubsequence", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2100, "task_id": "find-good-days-to-rob-the-bank", "difficulty": "Medium", "problem_description": "You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the i^th day. The days are numbered starting from 0. You are also given an integer time.\n\nThe i^th day is a good day to rob the bank if:\n\n- There are at least time days before and after the i^th day,\n- The number of guards at the bank for the time days before i are non-increasing, and\n- The number of guards at the bank for the time days after i are non-decreasing.\n\nMore formally, this means day i is a good day to rob the bank if and only if security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time].\n\nReturn a list of all days (0-indexed) that are good days to rob the bank. The order that the days are returned in does not matter.\n\nExample 1:\n\nInput: security = [5,3,3,3,5,6,2], time = 2\nOutput: [2,3]\nExplanation:\nOn day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4].\nOn day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5].\nNo other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.\n\nExample 2:\n\nInput: security = [1,1,1,1,1], time = 0\nOutput: [0,1,2,3,4]\nExplanation:\nSince time equals 0, every day is a good day to rob the bank, so return every day.\n\nExample 3:\n\nInput: security = [1,2,3,4,5,6], time = 2\nOutput: []\nExplanation:\nNo day has 2 days before it that have a non-increasing number of guards.\nThus, no day is a good day to rob the bank, so return an empty list.\n\nConstraints:\n\n- 1 <= security.length <= 10^5\n- 0 <= security[i], time <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(security = [3, 3, 5, 5, 5, 5, 2, 2, 2, 3],time = 2) == [6, 7]\n assert candidate(security = [1, 1, 1, 1, 1],time = 0) == [0, 1, 2, 3, 4]\n assert candidate(security = [1, 2, 2, 3, 3, 4, 5, 5, 6, 6],time = 1) == [2, 4, 7]\n assert candidate(security = [6, 5, 4, 3, 2, 1],time = 2) == []\n assert candidate(security = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],time = 1) == [2, 4, 6, 8]\n assert candidate(security = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],time = 0) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(security = [1, 2, 2, 3, 3, 4],time = 1) == [2, 4]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],time = 3) == []\n assert candidate(security = [1, 2, 2, 3, 3, 4, 5],time = 1) == [2, 4]\n assert candidate(security = [3, 3, 5, 5, 5, 5, 2, 2, 1, 1],time = 2) == []\n assert candidate(security = [1, 1, 1, 2, 2, 2, 3, 3, 3],time = 2) == [2, 5]\n assert candidate(security = [100, 90, 80, 70, 60, 50, 60, 70, 80, 90, 100],time = 4) == [5]\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3],time = 3) == [3]\n assert candidate(security = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],time = 4) == [4, 5]\n assert candidate(security = [1],time = 0) == [0]\n assert candidate(security = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],time = 2) == []\n assert candidate(security = [3, 3, 5, 5, 5, 5, 4, 4, 4, 3],time = 3) == []\n assert candidate(security = [1, 2, 3, 4, 5, 6],time = 2) == []\n assert candidate(security = [1, 2, 3, 3, 3, 3, 2, 2, 1],time = 2) == []\n assert candidate(security = [5, 3, 3, 3, 5, 6, 2],time = 2) == [2, 3]\n assert candidate(security = [1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3],time = 1) == [5, 7]\n assert candidate(security = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6],time = 2) == [5]\n assert candidate(security = [1, 2, 2, 3, 4, 5, 5, 4, 3, 2, 1],time = 3) == []\n assert candidate(security = [6, 5, 4, 3, 2, 1],time = 3) == []\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],time = 3) == []\n assert candidate(security = [1, 2],time = 1) == []\n assert candidate(security = [2, 1],time = 1) == []\n assert candidate(security = [1, 3, 3, 3, 3, 2, 2, 2, 2],time = 2) == [5, 6]\n assert candidate(security = [5, 6, 7, 8, 9, 10, 11, 12, 13, 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],time = 5) == [23]\n assert candidate(security = [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],time = 2) == [2, 6, 10, 14, 18, 22, 26]\n assert candidate(security = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],time = 10) == [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(security = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7],time = 2) == [8]\n assert candidate(security = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],time = 10) == [10, 11, 12, 13, 14, 15]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = 5) == [10]\n assert candidate(security = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],time = 0) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n assert candidate(security = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],time = 3) == [11]\n assert candidate(security = [5, 3, 3, 3, 3, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1],time = 3) == [3, 11, 12, 13]\n assert candidate(security = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1],time = 2) == [3, 6, 9, 13, 16, 19]\n assert candidate(security = [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],time = 2) == []\n assert candidate(security = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],time = 10) == [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(security = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],time = 2) == []\n assert candidate(security = [1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1],time = 2) == []\n assert candidate(security = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5],time = 2) == [8, 16]\n assert candidate(security = [7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7],time = 3) == [4, 8, 9, 10, 11, 15]\n assert candidate(security = [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],time = 1) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]\n assert candidate(security = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],time = 3) == [11]\n assert candidate(security = [1, 3, 2, 2, 2, 1, 2, 2, 2, 3, 1, 1, 1],time = 1) == [2, 3, 5, 7, 8, 10, 11]\n assert candidate(security = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],time = 4) == [8, 9, 17]\n assert candidate(security = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = 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, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]\n assert candidate(security = [1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2],time = 2) == [4, 8, 12]\n assert candidate(security = [10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10],time = 4) == [12]\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],time = 4) == [4, 5]\n assert candidate(security = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],time = 5) == [10]\n assert candidate(security = [5, 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, 3, 4],time = 5) == []\n assert candidate(security = [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],time = 6) == [10, 11, 12, 13, 14]\n assert candidate(security = [5, 3, 3, 3, 5, 6, 2, 2, 2, 1, 1, 1, 2, 2, 2],time = 3) == [9, 10, 11]\n assert candidate(security = [1, 2, 2, 1, 0, 0, 1, 1, 2, 2],time = 1) == [4, 5, 7]\n assert candidate(security = [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],time = 4) == [19]\n assert candidate(security = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],time = 4) == [9]\n assert candidate(security = [5, 3, 3, 3, 5, 6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],time = 2) == [2, 3, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],time = 5) == [5, 6, 7, 8, 9, 10, 11]\n assert candidate(security = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],time = 5) == []\n assert candidate(security = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0],time = 4) == []\n assert candidate(security = [2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 2, 1, 1, 2, 2],time = 2) == [5, 6, 12, 13]\n assert candidate(security = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],time = 3) == [4]\n assert candidate(security = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],time = 2) == []\n assert candidate(security = [10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],time = 4) == []\n assert candidate(security = [1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 10, 11, 12, 11, 12, 13],time = 4) == []\n assert candidate(security = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],time = 2) == [2, 5, 6, 7, 8, 9, 12]\n assert candidate(security = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5],time = 3) == [8, 16]\n assert candidate(security = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],time = 1) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],time = 3) == [10]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],time = 4) == [10]\n assert candidate(security = [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, 1, 2, 3, 4, 5],time = 4) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]\n assert candidate(security = [1, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5],time = 2) == []\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 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],time = 8) == [10]\n assert candidate(security = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],time = 7) == [7, 8, 9]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = 4) == [10]\n assert candidate(security = [3, 2, 1, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 2, 1, 0, 1, 0, 1, 2],time = 2) == []\n assert candidate(security = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],time = 3) == [11, 23]\n assert candidate(security = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],time = 3) == [5]\n assert candidate(security = [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, 1],time = 3) == []\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],time = 5) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(security = [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],time = 3) == []\n assert candidate(security = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],time = 5) == [10, 11]\n assert candidate(security = [9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1],time = 4) == [4]\n assert candidate(security = [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],time = 2) == [4, 5, 8, 9, 12, 13, 16, 17, 20, 21]\n assert candidate(security = [2, 2, 2, 2, 2, 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],time = 2) == [2, 5, 6, 7, 8, 9, 12, 13, 14, 17, 18, 19, 22, 23, 24, 27]\n assert candidate(security = [3, 3, 5, 5, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],time = 3) == [5]\n assert candidate(security = [3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0],time = 3) == [4, 8, 12, 13]\n assert candidate(security = [1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2],time = 2) == [4, 5, 6, 10, 11, 12, 16, 17, 18]\n assert candidate(security = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12, 11],time = 3) == []\n assert candidate(security = [10, 9, 8, 7, 6, 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],time = 4) == [5, 20]\n assert candidate(security = [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, 9, 8, 7, 6, 5, 4, 3, 2, 1],time = 7) == [19]\n assert candidate(security = [1, 2, 3, 2, 1, 2, 1, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],time = 3) == []\n assert candidate(security = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],time = 3) == [5]\n assert candidate(security = [1, 3, 2, 3, 1, 2, 3, 2, 1, 2, 1, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 3, 2, 1],time = 2) == [13]\n assert candidate(security = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],time = 5) == [5]\n assert candidate(security = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],time = 2) == [2, 3, 4, 5, 6, 7]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 5, 5, 6, 7, 8, 9, 10],time = 3) == [5, 6, 7]\n assert candidate(security = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],time = 5) == [5, 6, 7, 8, 9, 10]\n assert candidate(security = [8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8],time = 2) == [2, 5, 6, 7, 8, 9, 12]\n assert candidate(security = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],time = 10) == [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]\n assert candidate(security = [1, 3, 2, 3, 2, 1, 2, 3, 2, 1],time = 1) == [2, 5]\n assert candidate(security = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],time = 5) == []\n assert candidate(security = [1, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 7, 8, 9],time = 2) == [5, 11]\n assert candidate(security = [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],time = 6) == [7]\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],time = 12) == [12, 13]\n assert candidate(security = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],time = 7) == []\n assert candidate(security = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],time = 2) == [3, 4, 5, 6, 7, 8, 9]\n assert candidate(security = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10],time = 2) == [5]\n assert candidate(security = [5, 5, 4, 4, 4, 5, 6, 7, 8, 8],time = 2) == [2, 3, 4]\n assert candidate(security = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],time = 2) == [10, 11]\n assert candidate(security = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],time = 3) == [4]\n assert candidate(security = [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],time = 3) == []\n assert candidate(security = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],time = 5) == [5, 6, 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(security = [3, 3, 5, 5, 5, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1],time = 3) == [11]\n assert candidate(security = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3],time = 2) == [4, 8, 12]\n assert candidate(security = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],time = 5) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]\n assert candidate(security = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],time = 2) == []\n assert candidate(security = [1, 3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],time = 2) == []\n assert candidate(security = [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],time = 5) == [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(security = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1],time = 1) == [1, 4, 5, 8, 9, 12, 13, 16, 17, 20]\n", "comparison": "exact"}, "public_tests": ["[5,3,3,3,5,6,2]\n2", "[1,1,1,1,1]\n0", "[1,2,3,4,5,6]\n2"], "hints": ["The trivial solution is to check the time days before and after each day. There are a lot of repeated operations using this solution. How could we optimize this solution?", "We can use precomputation to make the solution faster.", "Use an array to store the number of days before the i^th day that is non-increasing, and another array to store the number of days after the i^th day that is non-decreasing."], "metadata": {"canonical_parameter_names": ["security", "time"], "leetcode_dataset_entry_point": "Solution().goodDaysToRobBank", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:07+00:00", "tests_total": 123, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function goodDaysToRobBank($security, $time) {", "container": "Solution", "callable": "goodDaysToRobBank", "parameters": [{"name": "security", "type": "Integer[]"}, {"name": "time", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2101, "task_id": "detonate-the-maximum-bombs", "difficulty": "Medium", "problem_description": "You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.\n\nThe bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [x_i, y_i, r_i]. x_i and y_i denote the X-coordinate and Y-coordinate of the location of the i^th bomb, whereas r_i denotes the radius of its range.\n\nYou may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.\n\nGiven the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.\n\nExample 1:\n\nInput: bombs = [[2,1,3],[6,1,4]]\nOutput: 2\nExplanation:\nThe above figure shows the positions and ranges of the 2 bombs.\nIf we detonate the left bomb, the right bomb will not be affected.\nBut if we detonate the right bomb, both bombs will be detonated.\nSo the maximum bombs that can be detonated is max(1, 2) = 2.\n\nExample 2:\n\nInput: bombs = [[1,1,5],[10,10,5]]\nOutput: 1\nExplanation:\nDetonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1.\n\nExample 3:\n\nInput: bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]\nOutput: 5\nExplanation:\nThe best bomb to detonate is bomb 0 because:\n- Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0.\n- Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2.\n- Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3.\nThus all 5 bombs are detonated.\n\nConstraints:\n\n- 1 <= bombs.length <= 100\n- bombs[i].length == 3\n- 1 <= x_i, y_i, r_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(bombs = [[10, 10, 5], [15, 15, 5], [20, 20, 5]]) == 1\n assert candidate(bombs = [[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5]]) == 4\n assert candidate(bombs = [[1, 1, 1], [2, 2, 1], [3, 3, 1]]) == 1\n assert candidate(bombs = [[1, 1, 100], [1, 1, 50], [1, 1, 25]]) == 3\n assert candidate(bombs = [[1, 1, 10], [10, 10, 10], [5, 5, 5]]) == 2\n assert candidate(bombs = [[1, 1, 10], [10, 10, 1], [5, 5, 5]]) == 2\n assert candidate(bombs = [[1, 1, 5], [10, 10, 5]]) == 1\n assert candidate(bombs = [[1, 2, 3], [2, 3, 1], [3, 4, 2], [4, 5, 3], [5, 6, 4]]) == 5\n assert candidate(bombs = [[5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1]]) == 1\n assert candidate(bombs = [[100, 100, 1], [101, 101, 1], [102, 102, 1]]) == 1\n assert candidate(bombs = [[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2]]) == 4\n assert candidate(bombs = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(bombs = [[2, 1, 3], [6, 1, 4]]) == 2\n assert candidate(bombs = [[1, 1, 3], [2, 2, 3], [3, 3, 3], [4, 4, 3]]) == 4\n assert candidate(bombs = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]) == 1\n assert candidate(bombs = [[5, 5, 3], [6, 6, 1], [7, 7, 4]]) == 3\n assert candidate(bombs = [[5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8]]) == 4\n assert candidate(bombs = [[10, 10, 10], [20, 20, 10], [30, 30, 10]]) == 1\n assert candidate(bombs = [[10, 10, 1], [20, 10, 1], [30, 10, 1], [40, 10, 1], [50, 10, 1], [60, 10, 1], [70, 10, 1], [80, 10, 1], [90, 10, 1], [100, 10, 1]]) == 1\n assert candidate(bombs = [[100, 100, 10], [100, 110, 10], [100, 120, 10], [110, 100, 10], [110, 110, 10], [110, 120, 10], [120, 100, 10], [120, 110, 10], [120, 120, 10]]) == 9\n assert candidate(bombs = [[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5], [35, 35, 5], [40, 40, 5]]) == 1\n assert candidate(bombs = [[50, 50, 10], [60, 60, 20], [70, 70, 30], [80, 80, 40], [90, 90, 50]]) == 5\n assert candidate(bombs = [[10, 10, 3], [10, 13, 3], [13, 10, 3], [13, 13, 3], [16, 16, 3], [16, 19, 3], [19, 16, 3], [19, 19, 3]]) == 4\n assert candidate(bombs = [[1, 1, 10], [1, 10, 10], [10, 1, 10], [10, 10, 10], [15, 15, 15], [15, 5, 15], [5, 15, 15], [20, 20, 5]]) == 8\n assert candidate(bombs = [[50, 50, 5], [55, 50, 5], [60, 50, 5], [65, 50, 5], [70, 50, 5], [75, 50, 5], [80, 50, 5], [85, 50, 5], [90, 50, 5], [95, 50, 5], [100, 50, 5], [105, 50, 5], [110, 50, 5], [115, 50, 5], [120, 50, 5], [125, 50, 5], [130, 50, 5], [135, 50, 5], [140, 50, 5], [145, 50, 5]]) == 20\n assert candidate(bombs = [[100, 100, 10], [110, 100, 10], [120, 100, 10], [130, 100, 10], [140, 100, 10], [150, 100, 10], [160, 100, 10], [170, 100, 10], [180, 100, 10]]) == 9\n assert candidate(bombs = [[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]]) == 1\n assert candidate(bombs = [[50, 50, 5], [60, 50, 5], [70, 50, 5], [80, 50, 5], [50, 60, 5], [50, 70, 5], [50, 80, 5], [50, 90, 5], [50, 100, 5], [60, 60, 15]]) == 6\n assert candidate(bombs = [[100, 100, 50], [200, 100, 50], [100, 200, 50], [200, 200, 50], [150, 150, 100]]) == 5\n assert candidate(bombs = [[10, 10, 1], [20, 20, 1], [30, 30, 1], [40, 40, 1], [50, 50, 1], [60, 60, 1], [70, 70, 1], [80, 80, 1], [90, 90, 1], [100, 100, 100]]) == 8\n assert candidate(bombs = [[5, 5, 5], [5, 15, 5], [15, 5, 5], [15, 15, 5], [10, 10, 20]]) == 5\n assert candidate(bombs = [[1, 1, 5], [2, 2, 10], [3, 3, 2], [4, 4, 8], [5, 5, 1]]) == 5\n assert candidate(bombs = [[1, 1, 100], [1, 1, 100], [1, 1, 100], [1, 1, 100], [1, 1, 100]]) == 5\n assert candidate(bombs = [[50, 50, 15], [60, 50, 20], [70, 50, 10], [50, 60, 25], [50, 70, 12], [50, 80, 5]]) == 6\n assert candidate(bombs = [[1, 1, 10], [10, 1, 10], [1, 10, 10], [10, 10, 10], [5, 5, 5], [15, 15, 15]]) == 6\n assert candidate(bombs = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1, 7, 7], [1, 8, 8], [1, 9, 9], [1, 10, 10]]) == 10\n assert candidate(bombs = [[1, 1, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10], [50, 50, 10], [60, 60, 10]]) == 1\n assert candidate(bombs = [[100, 100, 50], [200, 200, 50], [300, 300, 50], [100, 200, 60], [200, 300, 70]]) == 1\n assert candidate(bombs = [[10, 10, 1], [15, 15, 2], [20, 20, 3], [25, 25, 4], [30, 30, 5]]) == 1\n assert candidate(bombs = [[5, 5, 1], [5, 6, 1], [5, 7, 1], [5, 8, 1], [5, 9, 1]]) == 5\n assert candidate(bombs = [[1, 1, 10], [2, 2, 20], [3, 3, 30], [4, 4, 40], [5, 5, 50], [6, 6, 60]]) == 6\n assert candidate(bombs = [[5, 5, 20], [10, 5, 20], [15, 5, 20], [20, 5, 20], [25, 5, 20], [30, 5, 20], [35, 5, 20], [40, 5, 20], [45, 5, 20], [50, 5, 20]]) == 10\n assert candidate(bombs = [[1, 1, 100], [200, 200, 100], [400, 400, 100], [600, 600, 100], [800, 800, 100], [1000, 1000, 100], [1200, 1200, 100], [1400, 1400, 100], [1600, 1600, 100], [1800, 1800, 100]]) == 1\n assert candidate(bombs = [[10, 10, 15], [20, 20, 15], [30, 30, 15], [40, 40, 15], [50, 50, 15], [60, 60, 15], [70, 70, 15], [80, 80, 15], [90, 90, 15]]) == 9\n assert candidate(bombs = [[10, 10, 15], [20, 20, 15], [30, 30, 15], [40, 40, 15], [50, 50, 15], [60, 60, 15], [70, 70, 15]]) == 7\n assert candidate(bombs = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9], [10, 10, 10]]) == 10\n assert candidate(bombs = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10]]) == 8\n assert candidate(bombs = [[100, 100, 100], [200, 100, 100], [300, 100, 100], [400, 100, 100], [500, 100, 100], [600, 100, 100], [700, 100, 100], [800, 100, 100], [900, 100, 100]]) == 9\n assert candidate(bombs = [[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1]]) == 1\n assert candidate(bombs = [[10, 10, 5], [15, 10, 5], [20, 10, 5], [25, 10, 5], [30, 10, 5], [35, 10, 5], [40, 10, 5], [45, 10, 5]]) == 8\n assert candidate(bombs = [[1, 1, 100], [1, 101, 100], [101, 101, 100], [101, 1, 100], [51, 51, 100], [51, 1, 100], [1, 51, 100], [101, 51, 100], [51, 101, 100]]) == 9\n assert candidate(bombs = [[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2]]) == 6\n assert candidate(bombs = [[10, 10, 20], [30, 30, 20], [50, 50, 20], [70, 70, 20], [90, 90, 20], [110, 110, 20], [130, 130, 20], [150, 150, 20], [170, 170, 20], [190, 190, 20], [210, 210, 20], [230, 230, 20], [250, 250, 20], [270, 270, 20], [290, 290, 20]]) == 1\n assert candidate(bombs = [[5, 5, 2], [10, 5, 2], [15, 5, 2], [20, 5, 2], [25, 5, 2], [30, 5, 2], [35, 5, 2], [40, 5, 2], [45, 5, 2], [50, 5, 2], [55, 5, 2]]) == 1\n assert candidate(bombs = [[10, 10, 15], [20, 20, 25], [30, 30, 35], [40, 40, 45], [50, 50, 55]]) == 5\n assert candidate(bombs = [[100, 100, 100], [200, 200, 50], [300, 300, 25], [400, 400, 12.5]]) == 1\n assert candidate(bombs = [[5, 5, 10], [15, 5, 10], [5, 15, 10], [15, 15, 10], [10, 10, 5]]) == 5\n assert candidate(bombs = [[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]]) == 9\n assert candidate(bombs = [[10, 10, 25], [15, 10, 15], [10, 15, 20], [5, 10, 10], [10, 5, 15]]) == 5\n assert candidate(bombs = [[1, 1, 3], [4, 4, 3], [7, 1, 3], [4, 7, 3], [10, 10, 3]]) == 2\n assert candidate(bombs = [[1, 1, 5], [1, 6, 5], [6, 1, 5], [6, 6, 5], [3, 3, 1]]) == 5\n assert candidate(bombs = [[1, 1, 1000], [2, 2, 1000], [3, 3, 1000], [4, 4, 1000], [5, 5, 1000], [6, 6, 1000], [7, 7, 1000], [8, 8, 1000]]) == 8\n assert candidate(bombs = [[100, 100, 50], [150, 100, 50], [200, 100, 50], [250, 100, 50], [300, 100, 50], [350, 100, 50], [400, 100, 50], [450, 100, 50]]) == 8\n assert candidate(bombs = [[10, 10, 5], [15, 10, 5], [10, 15, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5]]) == 4\n assert candidate(bombs = [[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]]) == 15\n assert candidate(bombs = [[5, 5, 5], [10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5], [35, 35, 5], [40, 40, 5]]) == 1\n assert candidate(bombs = [[50, 50, 50], [60, 60, 50], [70, 70, 50], [80, 80, 50], [90, 90, 50], [100, 100, 50]]) == 6\n assert candidate(bombs = [[50, 50, 50], [100, 100, 50], [150, 150, 50], [200, 200, 50], [250, 250, 50], [300, 300, 50], [350, 350, 50], [400, 400, 50], [450, 450, 50]]) == 1\n assert candidate(bombs = [[10, 10, 5], [15, 15, 3], [20, 20, 4], [25, 25, 2], [30, 30, 6]]) == 1\n assert candidate(bombs = [[10, 10, 15], [15, 15, 15], [20, 20, 15], [25, 25, 15], [30, 30, 15]]) == 5\n assert candidate(bombs = [[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5]]) == 1\n assert candidate(bombs = [[1, 1, 100], [101, 101, 100], [201, 201, 100], [301, 301, 100], [401, 401, 100]]) == 1\n assert candidate(bombs = [[5, 5, 3], [7, 5, 3], [9, 5, 3], [11, 5, 3], [13, 5, 3]]) == 5\n assert candidate(bombs = [[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [5, 5, 5], [6, 6, 5], [7, 7, 5], [8, 8, 5], [9, 9, 5]]) == 9\n assert candidate(bombs = [[10000, 10000, 5000], [15000, 10000, 10000], [20000, 10000, 3000], [10000, 20000, 6000], [25000, 25000, 8000]]) == 3\n assert candidate(bombs = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1, 7, 7], [1, 8, 8], [1, 9, 9]]) == 9\n assert candidate(bombs = [[1000, 1000, 1000], [2000, 2000, 500], [3000, 3000, 250], [4000, 4000, 125]]) == 1\n assert candidate(bombs = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]) == 5\n assert candidate(bombs = [[10, 10, 50], [20, 20, 40], [30, 30, 30], [40, 40, 20], [50, 50, 10]]) == 5\n assert candidate(bombs = [[5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10], [30, 30, 10], [35, 35, 10]]) == 7\n assert candidate(bombs = [[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]]) == 1\n assert candidate(bombs = [[1, 1, 10], [10, 1, 5], [10, 10, 15], [20, 20, 10]]) == 4\n assert candidate(bombs = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]]) == 7\n assert candidate(bombs = [[1, 1, 10], [10, 1, 5], [1, 10, 5], [5, 5, 2], [7, 7, 7]]) == 5\n assert candidate(bombs = [[1, 1, 10000], [2, 2, 10000], [3, 3, 10000], [4, 4, 10000], [5, 5, 10000], [6, 6, 10000], [7, 7, 10000], [8, 8, 10000], [9, 9, 10000], [10, 10, 10000]]) == 10\n assert candidate(bombs = [[10, 10, 1], [11, 11, 2], [12, 12, 3], [13, 13, 4], [14, 14, 5], [15, 15, 6], [16, 16, 7], [17, 17, 8], [18, 18, 9], [19, 19, 10]]) == 10\n assert candidate(bombs = [[1, 1, 10], [11, 1, 10], [21, 1, 10], [1, 11, 10], [11, 11, 10], [21, 11, 10], [1, 21, 10], [11, 21, 10], [21, 21, 10]]) == 9\n assert candidate(bombs = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 5\n assert candidate(bombs = [[1, 1, 10], [2, 1, 10], [3, 1, 10], [4, 1, 10], [5, 1, 10], [6, 1, 10], [7, 1, 10], [8, 1, 10], [9, 1, 10], [10, 1, 10]]) == 10\n assert candidate(bombs = [[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [5, 5, 5], [6, 6, 5], [7, 7, 5], [8, 8, 5], [9, 9, 5], [10, 10, 5], [11, 11, 5], [12, 12, 5], [13, 13, 5], [14, 14, 5], [15, 15, 5]]) == 15\n assert candidate(bombs = [[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]]) == 9\n assert candidate(bombs = [[5, 5, 5], [10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5], [35, 35, 5], [40, 40, 5], [45, 45, 5], [50, 50, 5]]) == 1\n assert candidate(bombs = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5], [50, 50, 5], [60, 60, 5], [70, 70, 5], [80, 80, 5], [90, 90, 5], [100, 100, 5], [110, 110, 5], [120, 120, 5], [130, 130, 5], [140, 140, 5], [150, 150, 5]]) == 1\n assert candidate(bombs = [[10, 10, 3], [12, 12, 2], [15, 15, 1], [18, 18, 4], [20, 20, 5]]) == 2\n assert candidate(bombs = [[10, 10, 5], [15, 10, 10], [20, 10, 3], [10, 20, 6], [25, 25, 8]]) == 3\n assert candidate(bombs = [[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]]) == 13\n assert candidate(bombs = [[100, 100, 50], [200, 200, 50], [300, 300, 50], [250, 250, 100]]) == 3\n assert candidate(bombs = [[1, 1, 5], [5, 1, 5], [9, 1, 5], [13, 1, 5]]) == 4\n", "comparison": "exact"}, "public_tests": ["[[2,1,3],[6,1,4]]", "[[1,1,5],[10,10,5]]", "[[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]"], "hints": ["How can we model the relationship between different bombs? Can \"graphs\" help us?", "Bombs are nodes and are connected to other bombs in their range by directed edges.", "If we know which bombs will be affected when any bomb is detonated, how can we find the total number of bombs that will be detonated if we start from a fixed bomb?", "Run a Depth First Search (DFS) from every node, and all the nodes it reaches are the bombs that will be detonated."], "metadata": {"canonical_parameter_names": ["bombs"], "leetcode_dataset_entry_point": "Solution().maximumDetonation", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:09+00:00", "tests_total": 115, "tests_dropped": 17, "flags": ["has_images"], "topic_tags": ["array", "math", "depth-first-search", "breadth-first-search", "graph", "geometry"]}, "language": "php", "interface": {"raw_signature": "function maximumDetonation($bombs) {", "container": "Solution", "callable": "maximumDetonation", "parameters": [{"name": "bombs", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2103, "task_id": "rings-and-rods", "difficulty": "Easy", "problem_description": "There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.\n\nYou are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:\n\n- The first character of the i^th pair denotes the i^th ring's color ('R', 'G', 'B').\n- The second character of the i^th pair denotes the rod that the i^th ring is placed on ('0' to '9').\n\nFor example, \"R3G2B1\" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.\n\nReturn the number of rods that have all three colors of rings on them.\n\nExample 1:\n\nInput: rings = \"B0B6G0R6R0R6G9\"\nOutput: 1\nExplanation:\n- The rod labeled 0 holds 3 rings with all colors: red, green, and blue.\n- The rod labeled 6 holds 3 rings, but it only has red and blue.\n- The rod labeled 9 holds only a green ring.\nThus, the number of rods with all three colors is 1.\n\nExample 2:\n\nInput: rings = \"B0R0G0R9R0B0G0\"\nOutput: 1\nExplanation:\n- The rod labeled 0 holds 6 rings with all colors: red, green, and blue.\n- The rod labeled 9 holds only a red ring.\nThus, the number of rods with all three colors is 1.\n\nExample 3:\n\nInput: rings = \"G4\"\nOutput: 0\nExplanation:\nOnly one ring is given. Thus, no rods have all three colors.\n\nConstraints:\n\n- rings.length == 2 * n\n- 1 <= n <= 100\n- rings[i] where i is even is either 'R', 'G', or 'B' (0-indexed).\n- rings[i] where i is odd is a digit from '0' to '9' (0-indexed).\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2\") == 3\n assert candidate(rings = \"R9G9B9R9G9B9R9G9B9\") == 1\n assert candidate(rings = \"G4\") == 0\n assert candidate(rings = \"R0G0R0G0R0G0\") == 0\n assert candidate(rings = \"G0G1G2G3G4G5G6G7G8G9\") == 0\n assert candidate(rings = \"B0B1B2B3B4B5B6B7B8B9\") == 0\n assert candidate(rings = \"G1G2G3G4G5G6G7G8G9G0\") == 0\n assert candidate(rings = \"R1R2R3R4R5R6R7R8R9R0\") == 0\n assert candidate(rings = \"B0B6G0R6R0R6G9\") == 1\n assert candidate(rings = \"R9G9B9\") == 1\n assert candidate(rings = \"B1B2B3B4B5B6B7B8B9B0\") == 0\n assert candidate(rings = \"R0R0G0G0B0B0R1R1G1G1B1B1\") == 2\n assert candidate(rings = \"B0R0G0R9R0B0G0\") == 1\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9\") == 0\n assert candidate(rings = \"R1R1R1G1G1G1B1B1B1\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0R1R2R3R4R5R6R7R8R9\") == 0\n assert candidate(rings = \"R9G9B9R9G9B9\") == 1\n assert candidate(rings = \"R0G0B0R1G0B0R2G0B0R3G0B0R4G0B0R5G0B0R6G0B0R7G0B0R8G0B0R9G0B0\") == 1\n assert candidate(rings = \"R5G5B5R5G5B5R5G5B5\") == 1\n assert candidate(rings = \"R1G1B1R2G2B2R3G3B3\") == 3\n assert candidate(rings = \"B9B9B9G9G9G9R9R9R9\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R1G1B1R2G2B2\") == 2\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9\") == 10\n assert candidate(rings = \"R0G0B0R2G2B2R4G4B4R6G6B6R8G8B8\") == 5\n assert candidate(rings = \"R9G9B9R8G8B8R7G7B7\") == 3\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G1B1R1G1B1R1G1B1R1G1B1R2G2B2R2G2B2R2G2B2R2G2B2\") == 3\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9\") == 10\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9G0B1R2G3B4R5G6B7R8G9B0R1G2B3R4G5B6R7G8B9\") == 10\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9G0B1R2G3B4R5G6B7R8G9B0R1G2B3R4G5B6R7G8B9R0G1B2R3G4B5\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R0G0B0R1G1B1R2G2B2R3G3B3R0G0B0\") == 4\n assert candidate(rings = \"R0R0G0G0B0B0R1R1G1G1B1B1R2R2G2G2B2B2R3R3G3G3B3B3R4R4G4G4B4B4R5R5G5G5B5B5\") == 6\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R1G0B1R2G0B2R3G0B3R4G0B4R5G0B5R6G0B6R7G0B7R8G0B8R9G0B9R0G0B0R1G0B1R2G0B2R3G0B3R4G0B4R5G0B5R6G0B6R7G0B7R8G0B8R9G0B9\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R9G9B9\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5\") == 10\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9G0B1R2G3B4R5G6B7R8G9B0\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R1G1B1\") == 10\n assert candidate(rings = \"R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5R5G5B5\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1\") == 10\n assert candidate(rings = \"R0R0R0R0R0R0R0R0R0R0G0G0G0G0G0G0G0G0G0G0G0G0B0B0B0B0B0B0B0B0B0B0\") == 1\n assert candidate(rings = \"R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2\") == 0\n assert candidate(rings = \"R0G0B0R0G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9\") == 9\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0\") == 10\n assert candidate(rings = \"R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3\") == 0\n assert candidate(rings = \"R0G0B0R1G0B0R2G0B0R3G0B0R4G0B0R5G0B0R6G0B0R7G0B0R8G0B0R9G0B0R0G0B0R1G0B0\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R9G9B9R9G9B9\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R0G0B0R0G0B0\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3R3G3B3\") == 10\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9G0B1R2G3B4R5G6B7R8G9B0R1G1B1R2G2B2R3G3B3\") == 4\n assert candidate(rings = \"R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3R1G2B3\") == 0\n assert candidate(rings = \"R9G9B9R8G8B8R7G7B7R6G6B6R5G5B5R4G4B4R3G3B3R2G2B2R1G1B1R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R1G1B1R1G1B1R1G1B1R2G2B2R2G2B2R2G2B2R3G3B3\") == 4\n assert candidate(rings = \"R0R0R0R0R0R1R1R1R1R1R2R2R2R2R2R3R3R3R3R3R4R4R4R4R4R5R5R5R5R5R6R6R6R6R6R7R7R7R7R7R8R8R8R8R8R9R9R9R9R9\") == 0\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0G0B0R1G1B1R1G1B2G2B2R2G2B3G3B3R3G3B4G4B4R4G4B5G5B5R5G5B6G6B6R6G6B7G7B7R7G7B8G8B8R8G8B9G9B9R9G9B9\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R8G8B8\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1\") == 2\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1\") == 2\n assert candidate(rings = \"R9G8B7R6G5B4R3G2B1R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5\") == 6\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R7G7B7R7G7B7R7G7B7\") == 10\n assert candidate(rings = \"R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2\") == 0\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9\") == 10\n assert candidate(rings = \"R9G9B9R8G8B8R7G7B7R6G6B6R5G5B5R4G4B4R3G3B3R2G2B2R1G1B1R0G0B0\") == 10\n assert candidate(rings = \"R0G1B2R3G4B5R6G7B8R9G0B1R2G3B4R5G6B7R8G9B0R1G2B3R4G5B6R7G8B9R0G1B2R3G4B5R6G7B8R9G0\") == 10\n assert candidate(rings = \"R0B0G1R1B1G2R2B2G3R3B3G4R4B4G5R5B5G6R6B6G7R7B7G8R8B8G9R9B9\") == 9\n assert candidate(rings = \"R0G0B0G0B0R0B0G0R0R0G0B0R0G0B0R0R0G0R0G0B0R0B0G0R0G0R0B0G0R0\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0R0\") == 0\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R6G6B6R6G6B6R6G6B6R6G6B6\") == 10\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R4G4B4R4G4B4R4G4B4R4G4B4R4G4B4R4G4B4R4G4B4R4G4B4\") == 10\n assert candidate(rings = \"R0R0R0G0G0G0B0B0B0R1R1R1G1G1G1B1B1B1R2R2R2G2G2G2B2B2B2\") == 3\n assert candidate(rings = \"R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1R1G1B1\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0R0R0R0R0R0R0R0R0R0G0G0G0G0G0G0G0G0G0G0G0B0B0B0B0B0B0B0B0B0B0B0B0\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4\") == 10\n assert candidate(rings = \"R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2R0G1B2\") == 0\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G1B1R1G1B1R1G1B1R1G1B1\") == 2\n assert candidate(rings = \"G0B0R0G1B1R1G2B2R2G3B3R3G4B4R4G5B5R5G6B6R6G7B7R7G8B8R8G9B9R9G0B0R0G1B1R1G2B2R2G3B3R3G4B4R4G5B5R5G6B6R6G7B7R7G8B8R8G9B9R9\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0R1G0B0\") == 1\n assert candidate(rings = \"B9G9R9B8G8R8B7G7R7B6G6R6B5G5R5B4G4R4B3G3R3B2G2R2B1G1R1B0G0R0B9G9R9B8G8R8B7G7R7B6G6R6B5G5R5B4G4R4B3G3R3B2G2R2B1G1R1B0G0R0\") == 10\n assert candidate(rings = \"R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0\") == 10\n assert candidate(rings = \"B0G0B0G0B0R1G1R1G1R1B2G2B2G2G2R3G3R3G3G3B4G4B4G4G4R5G5R5G5G5B6G6B6G6G6R7G7R7G7G7B8G8B8G8G8R9G9R9G9G9B9G9B9G9G9\") == 1\n assert candidate(rings = \"G0B0R0G1B1R1G2B2R2G3B3R3G4B4R4G5B5R5G6B6R6G7B7R7G8B8R8G9B9R9G0B1R2G3B4R5G6B7R8G9B0\") == 10\n assert candidate(rings = \"R0G0B0R0G1B1R0G2B2R0G3B3R0G4B4R0G5B5R0G6B6R0G7B7R0G8B8R0G9B9\") == 1\n assert candidate(rings = \"R0G0B0R1G1B1R2G2B2R3G3B3R4G4B4R5G5B5R6G6B6R7G7B7R8G8B8R9G9B9R0G0B0\") == 10\n assert candidate(rings = \"R0B1G2R3B4G5R6B7G8R9B0G1R2B3G4R5B6G7R8B9G0R1B2G3R4B5G6R7B8G9\") == 10\n assert candidate(rings = \"B9G8R7B6G5R4B3G2R1B0G9R8B7G6R5B4G3R2B1G0R9B8G7R6B5G4R3B2G1R0\") == 10\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n assert candidate(rings = \"R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0R0G0B0\") == 1\n", "comparison": "exact"}, "public_tests": ["\"B0B6G0R6R0R6G9\"", "\"B0R0G0R9R0B0G0\"", "\"G4\""], "hints": ["For every rod, look through ‘rings’ to see if the rod contains all colors.", "Create 3 booleans, 1 for each color, to store if that color is present for the current rod. If all 3 are true after looking through the string, then the rod contains all the colors."], "metadata": {"canonical_parameter_names": ["rings"], "leetcode_dataset_entry_point": "Solution().countPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:12+00:00", "tests_total": 99, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function countPoints($rings) {", "container": "Solution", "callable": "countPoints", "parameters": [{"name": "rings", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2104, "task_id": "sum-of-subarray-ranges", "difficulty": "Medium", "problem_description": "You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.\n\nReturn the sum of all subarray ranges 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]\nOutput: 4\nExplanation: The 6 subarrays of nums are the following:\n[1], range = largest - smallest = 1 - 1 = 0\n[2], range = 2 - 2 = 0\n[3], range = 3 - 3 = 0\n[1,2], range = 2 - 1 = 1\n[2,3], range = 3 - 2 = 1\n[1,2,3], range = 3 - 1 = 2\nSo the sum of all ranges is 0 + 0 + 0 + 1 + 1 + 2 = 4.\n\nExample 2:\n\nInput: nums = [1,3,3]\nOutput: 4\nExplanation: The 6 subarrays of nums are the following:\n[1], range = largest - smallest = 1 - 1 = 0\n[3], range = 3 - 3 = 0\n[3], range = 3 - 3 = 0\n[1,3], range = 3 - 1 = 2\n[3,3], range = 3 - 3 = 0\n[1,3,3], range = 3 - 1 = 2\nSo the sum of all ranges is 0 + 0 + 0 + 2 + 0 + 2 = 4.\n\nExample 3:\n\nInput: nums = [4,-2,-3,4,1]\nOutput: 59\nExplanation: The sum of all subarray ranges of nums is 59.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- -10^9 <= nums[i] <= 10^9\n\nFollow-up: Could you find a solution with O(n) time complexity?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, -2, -3, -4]) == 10\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 165\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 165\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 30\n assert candidate(nums = [4, -2, -3, 4, 1]) == 59\n assert candidate(nums = [3, 2, 2, 2, 1]) == 8\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 20000000000\n assert candidate(nums = [10, 20, 30, 40, 50]) == 200\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 20\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 20\n assert candidate(nums = [100, 100, 100, 100]) == 0\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000]) == 12000000000\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30]) == 700\n assert candidate(nums = [10, 20, 30, 40, 50]) == 200\n assert candidate(nums = [1, 2, 2, 2, 3]) == 8\n assert candidate(nums = [5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [-10, -20, -30, -40, -50]) == 200\n assert candidate(nums = [1, 3, 3]) == 4\n assert candidate(nums = [1, 2, 3]) == 4\n assert candidate(nums = [-10, 100, -20, 200, -30, 300]) == 3580\n assert candidate(nums = [5]) == 0\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1]) == 66\n assert candidate(nums = [-1, 4, -2, 3, -3]) == 60\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 45\n assert candidate(nums = [1, 0, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 384\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 16500\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 64\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50]) == 2400\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, 25, 15, 10, 5, 2, 1, 0]) == 743\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 105\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 560\n assert candidate(nums = [5, 3, 8, 1, 4]) == 57\n assert candidate(nums = [10, 20, 30, 25, 15, 5]) == 240\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4]) == 168\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000]) == 12000000000\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 330\n assert candidate(nums = [5, 1, 4, 2, 8, 3]) == 77\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == 60\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]) == 1540\n assert candidate(nums = [100, 200, 300, 400, 500, -500, -400, -300, -200, -100]) == 29000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 560\n assert candidate(nums = [100, 200, 300, 400, 500]) == 2000\n assert candidate(nums = [10, 20, 30, 40, 50, -50, -40, -30, -20, -10]) == 2900\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == 20000000000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 635\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == 36000\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]) == 1540\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 40\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 10, 1, 0, 1, 10, 100]) == 1149\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1]) == 66\n assert candidate(nums = [9, -8, 7, -6, 5, -4, 3, -2, 1]) == 444\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 330\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 80\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1]) == 28\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 480\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 1655\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 240\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40]) == 1680\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10]) == 210\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 45\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 250000000, -250000000]) == 21000000000\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 5600\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 1650\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 330\n assert candidate(nums = [5, 8, 6, 7, 9, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1736\n assert candidate(nums = [9, 7, 5, 3, 1]) == 40\n assert candidate(nums = [5, 8, 3, 7, 9, 1]) == 87\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 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0]) == 22000\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10]) == 180\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 20\n assert candidate(nums = [10, -5, 3, 7, -2, 8]) == 172\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1]) == 42\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 165\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 330\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 90\n assert candidate(nums = [-1, -5, -9, -3, -6]) == 59\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == 3500\n assert candidate(nums = [1, 5, 3, 7, 9, 2, 6, 8, 4, 10]) == 283\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 560\n assert candidate(nums = [5, 4, 3, 2, 1]) == 20\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 165\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5]) == 240\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 1650\n assert candidate(nums = [5, 2, 9, 1, 5, 6]) == 99\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 328\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 651\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]) == 1540\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 285\n assert candidate(nums = [100, -100, 200, -200, 300]) == 4000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 8550\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 235\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 6150\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1000000000, 1000000000, -1000000000, -1000000000]) == 8000000000\n assert candidate(nums = [-1, 2, -3, 4, -5]) == 70\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000, 250000000]) == 15250000000\n assert candidate(nums = [100, -200, 300, -400, 500]) == 7000\n assert candidate(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5]) == 220\n assert candidate(nums = [5, 3, 1, 2, 4]) == 27\n assert candidate(nums = [5, 2, 3, 1, 4, 6, 8, 7, 9, 0]) == 244\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 2660\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 45\n assert candidate(nums = [5, 3, 8, 1, 4]) == 57\n assert candidate(nums = [5, 2, 4, 6, 1, 3]) == 60\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1]) == 56\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 330\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1650\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, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == 90\n assert candidate(nums = [5, 3, 8, 2, 7]) == 53\n assert candidate(nums = [5, 1, 4, 3, 2]) == 29\n assert candidate(nums = [1, 2, 3, -1, -2, -3, 4, 5, 6]) == 201\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15]) == 2135\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 1650\n assert candidate(nums = [1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 3]) == 392\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 165000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 5600\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7]) == 560\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]) == 1540\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[1,3,3]", "[4,-2,-3,4,1]"], "hints": ["Can you get the max/min of a certain subarray by using the max/min of a smaller subarray within it?", "Notice that the max of the subarray from index i to j is equal to max of (max of the subarray from index i to j-1) and nums[j]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().subArrayRanges", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:14+00:00", "tests_total": 127, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "stack", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function subArrayRanges($nums) {", "container": "Solution", "callable": "subArrayRanges", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2105, "task_id": "watering-plants-ii", "difficulty": "Medium", "problem_description": "Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i.\n\nEach plant needs a specific amount of water. Alice and Bob have a watering can each, initially full. They water the plants in the following way:\n\n- Alice waters the plants in order from left to right, starting from the 0^th plant. Bob waters the plants in order from right to left, starting from the (n - 1)^th plant. They begin watering the plants simultaneously.\n- It takes the same amount of time to water each plant regardless of how much water it needs.\n- Alice/Bob must water the plant if they have enough in their can to fully water it. Otherwise, they first refill their can (instantaneously) then water the plant.\n- In case both Alice and Bob reach the same plant, the one with more water currently in his/her watering can should water this plant. If they have the same amount of water, then Alice should water this plant.\n\nGiven a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the i^th plant needs, and two integers capacityA and capacityB representing the capacities of Alice's and Bob's watering cans respectively, return the number of times they have to refill to water all the plants.\n\nExample 1:\n\nInput: plants = [2,2,3,3], capacityA = 5, capacityB = 5\nOutput: 1\nExplanation:\n- Initially, Alice and Bob have 5 units of water each in their watering cans.\n- Alice waters plant 0, Bob waters plant 3.\n- Alice and Bob now have 3 units and 2 units of water respectively.\n- Alice has enough water for plant 1, so she waters it. Bob does not have enough water for plant 2, so he refills his can then waters it.\nSo, the total number of times they have to refill to water all the plants is 0 + 0 + 1 + 0 = 1.\n\nExample 2:\n\nInput: plants = [2,2,3,3], capacityA = 3, capacityB = 4\nOutput: 2\nExplanation:\n- Initially, Alice and Bob have 3 units and 4 units of water in their watering cans respectively.\n- Alice waters plant 0, Bob waters plant 3.\n- Alice and Bob now have 1 unit of water each, and need to water plants 1 and 2 respectively.\n- Since neither of them have enough water for their current plants, they refill their cans and then water the plants.\nSo, the total number of times they have to refill to water all the plants is 0 + 1 + 1 + 0 = 2.\n\nExample 3:\n\nInput: plants = [5], capacityA = 10, capacityB = 8\nOutput: 0\nExplanation:\n- There is only one plant.\n- Alice's watering can has 10 units of water, whereas Bob's can has 8 units. Since Alice has more water in her can, she waters this plant.\nSo, the total number of times they have to refill is 0.\n\nConstraints:\n\n- n == plants.length\n- 1 <= n <= 10^5\n- 1 <= plants[i] <= 10^6\n- max(plants[i]) <= capacityA, capacityB <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(plants = [5],capacityA = 10,capacityB = 8) == 0\n assert candidate(plants = [1000000, 1000000, 1000000],capacityA = 1000000,capacityB = 1000000) == 1\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 15,capacityB = 15) == 3\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 10,capacityB = 10) == 5\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 8\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacityA = 15,capacityB = 15) == 3\n assert candidate(plants = [2, 2, 3, 3],capacityA = 5,capacityB = 5) == 1\n assert candidate(plants = [1000000],capacityA = 1000000,capacityB = 1000000) == 0\n assert candidate(plants = [2, 2, 3, 3],capacityA = 3,capacityB = 4) == 2\n assert candidate(plants = [1, 10, 1, 10, 1, 10, 1, 10],capacityA = 10,capacityB = 10) == 6\n assert candidate(plants = [5, 8, 6],capacityA = 10,capacityB = 10) == 1\n assert candidate(plants = [10, 10, 10, 10, 10],capacityA = 10,capacityB = 10) == 3\n assert candidate(plants = [1, 2, 3, 4, 5],capacityA = 5,capacityB = 5) == 2\n assert candidate(plants = [10, 8, 6, 4, 2],capacityA = 10,capacityB = 8) == 2\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacityA = 5,capacityB = 5) == 8\n assert candidate(plants = [1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 3\n assert candidate(plants = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],capacityA = 150,capacityB = 100) == 4\n assert candidate(plants = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacityA = 50,capacityB = 50) == 5\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 29\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],capacityA = 30,capacityB = 30) == 8\n assert candidate(plants = [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],capacityA = 10,capacityB = 12) == 17\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacityA = 20,capacityB = 20) == 5\n assert candidate(plants = [1000000, 500000, 1000000, 500000, 1000000, 500000, 1000000, 500000, 1000000, 500000],capacityA = 1000000,capacityB = 1000000) == 8\n assert candidate(plants = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],capacityA = 15,capacityB = 15) == 18\n assert candidate(plants = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],capacityA = 20,capacityB = 30) == 9\n assert candidate(plants = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],capacityA = 10,capacityB = 10) == 12\n assert candidate(plants = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],capacityA = 55,capacityB = 65) == 8\n assert candidate(plants = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],capacityA = 5,capacityB = 5) == 22\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],capacityA = 15,capacityB = 20) == 6\n assert candidate(plants = [10, 20, 30, 40, 50, 40, 30, 20, 10],capacityA = 25,capacityB = 25) == 7\n assert candidate(plants = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],capacityA = 1000000,capacityB = 1000000) == 8\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacityA = 20,capacityB = 25) == 11\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 5,capacityB = 5) == 0\n assert candidate(plants = [1000000, 1000000, 1000000, 1000000, 1000000],capacityA = 1000000,capacityB = 1000000) == 3\n assert candidate(plants = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacityA = 30,capacityB = 35) == 7\n assert candidate(plants = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],capacityA = 50,capacityB = 60) == 16\n assert candidate(plants = [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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],capacityA = 100,capacityB = 100) == 11\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacityA = 10,capacityB = 10) == 12\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacityA = 10,capacityB = 10) == 16\n assert candidate(plants = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacityA = 10,capacityB = 35) == 9\n assert candidate(plants = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacityA = 15,capacityB = 20) == 6\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 10,capacityB = 5) == 7\n assert candidate(plants = [100, 150, 200, 250, 300, 350, 400, 450, 500],capacityA = 200,capacityB = 300) == 8\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 28\n assert candidate(plants = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 10,capacityB = 10) == 16\n assert candidate(plants = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],capacityA = 50,capacityB = 50) == 8\n assert candidate(plants = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],capacityA = 150,capacityB = 150) == 8\n assert candidate(plants = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981],capacityA = 2000000,capacityB = 2000000) == 8\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacityA = 20,capacityB = 10) == 13\n assert candidate(plants = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],capacityA = 150,capacityB = 120) == 4\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],capacityA = 15,capacityB = 15) == 19\n assert candidate(plants = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],capacityA = 30,capacityB = 60) == 8\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 2,capacityB = 2) == 8\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],capacityA = 7,capacityB = 8) == 12\n assert candidate(plants = [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],capacityA = 500,capacityB = 500) == 11\n assert candidate(plants = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],capacityA = 25,capacityB = 25) == 7\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],capacityA = 10,capacityB = 10) == 16\n assert candidate(plants = [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],capacityA = 25,capacityB = 30) == 19\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacityA = 5,capacityB = 5) == 28\n assert candidate(plants = [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, 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],capacityA = 50,capacityB = 50) == 115\n assert candidate(plants = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61],capacityA = 1000000,capacityB = 500000) == 1\n assert candidate(plants = [1000000, 500000, 1000000, 500000],capacityA = 1000000,capacityB = 1000000) == 2\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],capacityA = 20,capacityB = 20) == 10\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacityA = 5,capacityB = 10) == 13\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 5,capacityB = 5) == 8\n assert candidate(plants = [3, 2, 4, 1, 2, 4, 3, 1, 2, 3],capacityA = 5,capacityB = 5) == 4\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 28\n assert candidate(plants = [500, 400, 300, 200, 100, 100, 200, 300, 400, 500],capacityA = 500,capacityB = 500) == 6\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],capacityA = 15,capacityB = 15) == 7\n assert candidate(plants = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],capacityA = 100,capacityB = 100) == 18\n assert candidate(plants = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],capacityA = 500000,capacityB = 500000) == 3\n assert candidate(plants = [5, 7, 3, 8, 6, 10, 4, 9, 2, 1],capacityA = 10,capacityB = 12) == 5\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 2,capacityB = 2) == 8\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacityA = 15,capacityB = 15) == 7\n assert candidate(plants = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],capacityA = 500000,capacityB = 500000) == 10\n assert candidate(plants = [100, 200, 150, 50, 300, 250, 350, 400, 450, 500],capacityA = 500,capacityB = 600) == 4\n assert candidate(plants = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],capacityA = 2000000,capacityB = 1500000) == 6\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],capacityA = 14,capacityB = 16) == 12\n assert candidate(plants = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],capacityA = 25,capacityB = 20) == 10\n assert candidate(plants = [100, 200, 300, 400, 500, 400, 300, 200, 100],capacityA = 300,capacityB = 300) == 5\n assert candidate(plants = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],capacityA = 25,capacityB = 20) == 4\n assert candidate(plants = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],capacityA = 5,capacityB = 5) == 18\n assert candidate(plants = [3, 2, 4, 2, 1, 2, 4, 3, 2, 1, 3, 2, 4, 2, 1],capacityA = 5,capacityB = 5) == 7\n assert candidate(plants = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],capacityA = 500,capacityB = 400) == 8\n assert candidate(plants = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],capacityA = 1000000,capacityB = 1000000) == 8\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],capacityA = 15,capacityB = 15) == 8\n assert candidate(plants = [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],capacityA = 150,capacityB = 150) == 26\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],capacityA = 10,capacityB = 10) == 7\n assert candidate(plants = [5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5],capacityA = 10,capacityB = 10) == 9\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],capacityA = 25,capacityB = 25) == 14\n assert candidate(plants = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],capacityA = 5,capacityB = 5) == 13\n assert candidate(plants = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],capacityA = 5,capacityB = 5) == 20\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],capacityA = 10,capacityB = 10) == 11\n assert candidate(plants = [5, 8, 6, 7, 5, 4, 3, 2, 1, 9],capacityA = 10,capacityB = 8) == 7\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],capacityA = 20,capacityB = 25) == 11\n assert candidate(plants = [9, 8, 7, 6, 5, 4, 3, 2, 1],capacityA = 10,capacityB = 10) == 4\n assert candidate(plants = [10, 5, 15, 20, 25, 30, 35, 40, 45, 50],capacityA = 25,capacityB = 30) == 8\n assert candidate(plants = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],capacityA = 1,capacityB = 1) == 18\n assert candidate(plants = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],capacityA = 5,capacityB = 5) == 18\n assert candidate(plants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],capacityA = 12,capacityB = 15) == 20\n assert candidate(plants = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],capacityA = 15,capacityB = 15) == 8\n assert candidate(plants = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],capacityA = 25,capacityB = 30) == 8\n assert candidate(plants = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],capacityA = 100,capacityB = 100) == 5\n", "comparison": "exact"}, "public_tests": ["[2,2,3,3]\n5\n5", "[2,2,3,3]\n3\n4", "[5]\n10\n8"], "hints": ["Try \"simulating\" the process.", "Since watering each plant takes the same amount of time, where will Alice and Bob meet if they start watering the plants simultaneously? How can you use this to optimize your solution?", "What will you do when both Alice and Bob have to water the same plant?"], "metadata": {"canonical_parameter_names": ["plants", "capacityA", "capacityB"], "leetcode_dataset_entry_point": "Solution().minimumRefill", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:16+00:00", "tests_total": 104, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "php", "interface": {"raw_signature": "function minimumRefill($plants, $capacityA, $capacityB) {", "container": "Solution", "callable": "minimumRefill", "parameters": [{"name": "plants", "type": "Integer[]"}, {"name": "capacityA", "type": "Integer"}, {"name": "capacityB", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2106, "task_id": "maximum-fruits-harvested-after-at-most-k-steps", "difficulty": "Hard", "problem_description": "Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [position_i, amount_i] depicts amount_i fruits at the position position_i. fruits is already sorted by position_i in ascending order, and each position_i is unique.\n\nYou are also given an integer startPos and an integer k. Initially, you are at the position startPos. From any position, you can either walk to the left or right. It takes one step to move one unit on the x-axis, and you can walk at most k steps in total. For every position you reach, you harvest all the fruits at that position, and the fruits will disappear from that position.\n\nReturn the maximum total number of fruits you can harvest.\n\nExample 1:\n\nInput: fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4\nOutput: 9\nExplanation:\nThe optimal way is to:\n- Move right to position 6 and harvest 3 fruits\n- Move right to position 8 and harvest 6 fruits\nYou moved 3 steps and harvested 3 + 6 = 9 fruits in total.\n\nExample 2:\n\nInput: fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4\nOutput: 14\nExplanation:\nYou can move at most k = 4 steps, so you cannot reach position 0 nor 10.\nThe optimal way is to:\n- Harvest the 7 fruits at the starting position 5\n- Move left to position 4 and harvest 1 fruit\n- Move right to position 6 and harvest 2 fruits\n- Move right to position 7 and harvest 4 fruits\nYou moved 1 + 3 = 4 steps and harvested 7 + 1 + 2 + 4 = 14 fruits in total.\n\nExample 3:\n\nInput: fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2\nOutput: 0\nExplanation:\nYou can move at most k = 2 steps and cannot reach any position with fruits.\n\nConstraints:\n\n- 1 <= fruits.length <= 10^5\n- fruits[i].length == 2\n- 0 <= startPos, position_i <= 2 * 10^5\n- position_{i-1} < position_i for any i > 0 (0-indexed)\n- 1 <= amount_i <= 10^4\n- 0 <= k <= 2 * 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(fruits = [[0, 9], [4, 1], [5, 7], [6, 2], [7, 4], [10, 9]],startPos = 5,k = 4) == 14\n assert candidate(fruits = [[1, 100], [50, 100], [100, 100]],startPos = 75,k = 25) == 100\n assert candidate(fruits = [[100000, 10000]],startPos = 90000,k = 20000) == 10000\n assert candidate(fruits = [[0, 1], [2, 1], [4, 1], [6, 1], [8, 1], [10, 1]],startPos = 5,k = 5) == 3\n assert candidate(fruits = [[1, 100], [2, 100], [3, 100], [4, 100], [5, 100], [6, 100], [7, 100], [8, 100], [9, 100], [10, 100]],startPos = 5,k = 10) == 800\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],startPos = 1,k = 5) == 15\n assert candidate(fruits = [[1, 10], [2, 10], [3, 10]],startPos = 1,k = 5) == 30\n assert candidate(fruits = [[1, 2], [3, 4], [5, 6]],startPos = 4,k = 3) == 10\n assert candidate(fruits = [[1, 5], [2, 3], [4, 8], [6, 7], [8, 2]],startPos = 5,k = 5) == 18\n assert candidate(fruits = [[1, 10000], [20000, 10000]],startPos = 10000,k = 10000) == 10000\n assert candidate(fruits = [[10, 5], [20, 5], [30, 5], [40, 5], [50, 5]],startPos = 30,k = 15) == 10\n assert candidate(fruits = [[10000, 10000], [20000, 10000], [30000, 10000]],startPos = 20000,k = 10000) == 20000\n assert candidate(fruits = [[0, 3], [6, 4], [8, 5]],startPos = 3,k = 2) == 0\n assert candidate(fruits = [[1, 2], [3, 4], [7, 8], [10, 10]],startPos = 5,k = 5) == 18\n assert candidate(fruits = [[1, 2], [3, 4], [5, 6], [7, 8]],startPos = 4,k = 5) == 18\n assert candidate(fruits = [[10, 10], [20, 20], [30, 30]],startPos = 15,k = 10) == 20\n assert candidate(fruits = [[2, 8], [6, 3], [8, 6]],startPos = 5,k = 4) == 9\n assert candidate(fruits = [[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]],startPos = 8,k = 6) == 77\n assert candidate(fruits = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8], [17, 9], [19, 10]],startPos = 10,k = 9) == 40\n assert candidate(fruits = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9]],startPos = 45,k = 30) == 18\n assert candidate(fruits = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8], [17, 9]],startPos = 8,k = 12) == 39\n assert candidate(fruits = [[5, 20], [10, 15], [15, 10], [20, 5], [25, 10]],startPos = 12,k = 10) == 35\n assert candidate(fruits = [[1, 5], [4, 10], [6, 15], [10, 20], [15, 25], [20, 30]],startPos = 10,k = 15) == 75\n assert candidate(fruits = [[1, 1000], [10, 1000], [20, 1000], [30, 1000], [40, 1000]],startPos = 25,k = 20) == 2000\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]],startPos = 6,k = 10) == 72\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],startPos = 1,k = 10) == 55\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],startPos = 5,k = 5) == 45\n assert candidate(fruits = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9]],startPos = 50,k = 30) == 26\n assert candidate(fruits = [[2, 5], [5, 5], [7, 5], [10, 5], [15, 5], [20, 5], [25, 5], [30, 5]],startPos = 15,k = 15) == 25\n assert candidate(fruits = [[1, 50], [2, 50], [3, 50], [4, 50], [5, 50], [6, 50], [7, 50], [8, 50], [9, 50], [10, 50]],startPos = 5,k = 10) == 400\n assert candidate(fruits = [[5, 15], [10, 20], [15, 25], [20, 30], [25, 35], [30, 40]],startPos = 18,k = 12) == 105\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],startPos = 5,k = 4) == 35\n assert candidate(fruits = [[1, 5], [3, 10], [6, 15], [8, 20], [10, 25]],startPos = 5,k = 7) == 60\n assert candidate(fruits = [[5, 100], [10, 200], [15, 300], [20, 400], [25, 500], [30, 600], [35, 700], [40, 800], [45, 900]],startPos = 20,k = 20) == 3000\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],startPos = 5,k = 9) == 52\n assert candidate(fruits = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]],startPos = 5,k = 12) == 35\n assert candidate(fruits = [[2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15]],startPos = 7,k = 10) == 55\n assert candidate(fruits = [[2, 8], [5, 10], [7, 3], [11, 15], [15, 7]],startPos = 8,k = 10) == 28\n assert candidate(fruits = [[5, 2], [10, 4], [15, 6], [20, 8], [25, 10], [30, 12], [35, 14]],startPos = 18,k = 25) == 50\n assert candidate(fruits = [[1, 100], [10, 100], [20, 100], [30, 100], [40, 100], [50, 100]],startPos = 25,k = 20) == 200\n assert candidate(fruits = [[1, 100], [100, 200], [200, 300], [300, 400], [400, 500]],startPos = 250,k = 200) == 900\n assert candidate(fruits = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8], [17, 9], [19, 10]],startPos = 10,k = 10) == 40\n assert candidate(fruits = [[1, 5], [10, 5], [20, 5], [30, 5], [40, 5], [50, 5], [60, 5], [70, 5], [80, 5], [90, 5], [100, 5]],startPos = 50,k = 40) == 25\n assert candidate(fruits = [[1, 1000], [2, 1000], [3, 1000], [4, 1000], [5, 1000], [6, 1000], [7, 1000], [8, 1000], [9, 1000], [10, 1000]],startPos = 5,k = 9) == 8000\n assert candidate(fruits = [[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]],startPos = 7,k = 6) == 70\n assert candidate(fruits = [[1, 2000], [2, 2000], [3, 2000], [4, 2000], [5, 2000], [6, 2000], [7, 2000], [8, 2000], [9, 2000], [10, 2000]],startPos = 5,k = 10) == 16000\n assert candidate(fruits = [[2, 3], [4, 6], [6, 9], [8, 12], [10, 15]],startPos = 6,k = 8) == 42\n assert candidate(fruits = [[5, 100], [10, 200], [15, 300], [20, 400], [25, 500]],startPos = 12,k = 22) == 1400\n assert candidate(fruits = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],startPos = 5,k = 9) == 49\n assert candidate(fruits = [[2, 9], [5, 8], [12, 7], [18, 6], [25, 5], [32, 4], [39, 3], [46, 2], [53, 1]],startPos = 25,k = 20) == 26\n assert candidate(fruits = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],startPos = 10,k = 15) == 98\n assert candidate(fruits = [[1, 10], [4, 20], [6, 30], [9, 40], [12, 50], [15, 60], [18, 70], [21, 80], [24, 90]],startPos = 12,k = 18) == 390\n assert candidate(fruits = [[5, 3], [10, 5], [15, 8], [20, 12], [25, 15], [30, 20]],startPos = 18,k = 12) == 47\n assert candidate(fruits = [[2, 5], [4, 3], [5, 10], [7, 2], [8, 6], [10, 1]],startPos = 6,k = 7) == 21\n assert candidate(fruits = [[5, 1], [7, 2], [9, 3], [11, 4], [13, 5]],startPos = 10,k = 6) == 12\n assert candidate(fruits = [[1, 50], [2, 60], [3, 70], [4, 80], [5, 90], [6, 100], [7, 110], [8, 120], [9, 130], [10, 140]],startPos = 5,k = 15) == 950\n assert candidate(fruits = [[1, 10], [5, 20], [10, 30], [15, 40], [20, 50]],startPos = 15,k = 18) == 120\n assert candidate(fruits = [[5, 2], [10, 3], [15, 4], [20, 5], [25, 6], [30, 7], [35, 8], [40, 9]],startPos = 22,k = 12) == 18\n assert candidate(fruits = [[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]],startPos = 8,k = 12) == 10\n assert candidate(fruits = [[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]],startPos = 8,k = 7) == 8\n assert candidate(fruits = [[1, 1000], [5, 1000], [10, 1000], [15, 1000], [20, 1000], [25, 1000], [30, 1000], [35, 1000], [40, 1000]],startPos = 20,k = 25) == 5000\n assert candidate(fruits = [[1, 100], [5, 200], [10, 300], [15, 400], [20, 500]],startPos = 10,k = 18) == 1200\n assert candidate(fruits = [[1, 5], [3, 5], [5, 5], [7, 5], [9, 5], [11, 5], [13, 5], [15, 5], [17, 5], [19, 5]],startPos = 10,k = 9) == 25\n assert candidate(fruits = [[2, 8], [6, 3], [8, 6], [12, 4], [14, 2], [18, 10], [20, 7]],startPos = 10,k = 12) == 23\n assert candidate(fruits = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [110, 11], [120, 12], [130, 13], [140, 14], [150, 15]],startPos = 80,k = 30) == 38\n assert candidate(fruits = [[1, 10], [3, 20], [5, 30], [7, 40], [9, 50], [11, 60], [13, 70], [15, 80], [17, 90]],startPos = 8,k = 14) == 390\n assert candidate(fruits = [[0, 100], [10, 100], [20, 100], [30, 100], [40, 100]],startPos = 20,k = 10) == 200\n assert candidate(fruits = [[5, 10], [15, 10], [25, 10], [35, 10], [45, 10], [55, 10], [65, 10]],startPos = 15,k = 35) == 40\n assert candidate(fruits = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]],startPos = 5,k = 10) == 520\n assert candidate(fruits = [[1, 2], [4, 3], [7, 4], [10, 5], [13, 6], [16, 7], [19, 8], [22, 9], [25, 10]],startPos = 10,k = 10) == 26\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],startPos = 5,k = 9) == 52\n assert candidate(fruits = [[1, 1000], [2000, 1000], [3000, 1000], [4000, 1000], [5000, 1000]],startPos = 2500,k = 2000) == 2000\n assert candidate(fruits = [[5, 5], [15, 5], [25, 5], [35, 5], [45, 5], [55, 5], [65, 5]],startPos = 30,k = 25) == 15\n assert candidate(fruits = [[5, 10], [10, 20], [15, 30], [20, 40], [25, 50], [30, 60], [35, 70], [40, 80]],startPos = 25,k = 15) == 260\n assert candidate(fruits = [[2, 8], [6, 3], [8, 6], [12, 7], [16, 5]],startPos = 5,k = 8) == 16\n assert candidate(fruits = [[1, 10000], [2, 10000], [3, 10000], [4, 10000], [5, 10000]],startPos = 3,k = 100000) == 50000\n assert candidate(fruits = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],startPos = 50,k = 50) == 450\n assert candidate(fruits = [[1, 3], [4, 7], [6, 2], [8, 8], [10, 5]],startPos = 5,k = 7) == 22\n assert candidate(fruits = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]],startPos = 55,k = 30) == 105\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],startPos = 3,k = 15) == 55\n assert candidate(fruits = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500], [60, 600], [70, 700], [80, 800], [90, 900], [100, 1000]],startPos = 50,k = 40) == 3500\n assert candidate(fruits = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1], [60, 1], [70, 1], [80, 1], [90, 1], [100, 1]],startPos = 55,k = 45) == 5\n assert candidate(fruits = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7]],startPos = 20,k = 20) == 22\n assert candidate(fruits = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],startPos = 55,k = 45) == 400\n assert candidate(fruits = [[2, 5], [5, 10], [10, 8], [15, 7], [20, 6]],startPos = 12,k = 15) == 25\n assert candidate(fruits = [[5, 5], [15, 5], [25, 5], [35, 5], [45, 5], [55, 5]],startPos = 30,k = 18) == 10\n assert candidate(fruits = [[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]],startPos = 8,k = 10) == 99\n assert candidate(fruits = [[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]],startPos = 10,k = 15) == 182\n assert candidate(fruits = [[0, 9], [4, 1], [5, 7], [6, 2], [7, 4], [10, 9], [12, 5], [15, 6], [18, 7]],startPos = 5,k = 10) == 33\n assert candidate(fruits = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1], [11, 1], [13, 1], [15, 1], [17, 1], [19, 1]],startPos = 10,k = 9) == 5\n assert candidate(fruits = [[1, 5], [3, 10], [5, 15], [7, 20], [9, 25], [11, 30], [13, 35], [15, 40], [17, 45], [19, 50]],startPos = 10,k = 15) == 245\n assert candidate(fruits = [[1, 1000], [2000, 2000], [3000, 3000], [4000, 4000], [5000, 5000]],startPos = 2500,k = 2500) == 12000\n assert candidate(fruits = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5], [30, 6], [35, 7], [40, 8]],startPos = 22,k = 15) == 18\n assert candidate(fruits = [[2, 1], [5, 3], [8, 5], [11, 2], [14, 6]],startPos = 7,k = 9) == 13\n assert candidate(fruits = [[10, 5], [15, 10], [20, 15], [25, 20], [30, 25], [35, 30]],startPos = 20,k = 25) == 100\n assert candidate(fruits = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],startPos = 5,k = 15) == 45\n assert candidate(fruits = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]],startPos = 5,k = 4) == 25\n assert candidate(fruits = [[1, 100], [10, 100], [20, 100], [30, 100], [40, 100]],startPos = 25,k = 20) == 200\n assert candidate(fruits = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8], [17, 9], [19, 10]],startPos = 10,k = 8) == 30\n assert candidate(fruits = [[10, 5], [20, 5], [30, 5], [40, 5], [50, 5], [60, 5], [70, 5], [80, 5]],startPos = 40,k = 25) == 15\n assert candidate(fruits = [[2, 8], [6, 3], [8, 6], [10, 9], [12, 4], [14, 2], [16, 5]],startPos = 5,k = 8) == 22\n assert candidate(fruits = [[0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14]],startPos = 6,k = 6) == 44\n assert candidate(fruits = [[1, 5], [10, 10], [20, 15], [30, 20], [40, 25], [50, 30]],startPos = 25,k = 20) == 45\n assert candidate(fruits = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45]],startPos = 25,k = 20) == 105\n assert candidate(fruits = [[0, 100], [10, 100], [20, 100], [30, 100], [40, 100], [50, 100]],startPos = 25,k = 40) == 400\n assert candidate(fruits = [[10, 5000], [20, 5000], [30, 5000], [40, 5000], [50, 5000], [60, 5000], [70, 5000]],startPos = 35,k = 29) == 15000\n assert candidate(fruits = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]],startPos = 5,k = 12) == 35\n assert candidate(fruits = [[1, 1000], [5, 2000], [10, 3000], [20, 4000], [30, 5000]],startPos = 15,k = 18) == 9000\n assert candidate(fruits = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12]],startPos = 4,k = 10) == 68\n assert candidate(fruits = [[1, 1000], [10, 2000], [20, 3000], [30, 4000], [40, 5000], [50, 6000]],startPos = 25,k = 25) == 15000\n assert candidate(fruits = [[100, 10], [200, 20], [300, 30], [400, 40], [500, 50], [600, 60], [700, 70], [800, 80], [900, 90]],startPos = 500,k = 300) == 260\n assert candidate(fruits = [[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]],startPos = 10,k = 10) == 165\n assert candidate(fruits = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600]],startPos = 3,k = 10) == 2100\n assert candidate(fruits = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],startPos = 55,k = 40) == 30\n", "comparison": "exact"}, "public_tests": ["[[2,8],[6,3],[8,6]]\n5\n4", "[[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]]\n5\n4", "[[0,3],[6,4],[8,5]]\n3\n2"], "hints": ["Does an optimal path have very few patterns? For example, could a path that goes left, turns and goes right, then turns again and goes left be any better than a path that simply goes left, turns, and goes right?", "The optimal path turns at most once. That is, the optimal path is one of these: to go left only; to go right only; to go left, turn and go right; or to go right, turn and go left.", "Moving x steps left then k-x steps right gives you a range of positions that you can reach.", "Use prefix sums to get the sum of all fruits for each possible range.", "Use a similar strategy for all the paths that go right, then turn and go left."], "metadata": {"canonical_parameter_names": ["fruits", "startPos", "k"], "leetcode_dataset_entry_point": "Solution().maxTotalFruits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:19+00:00", "tests_total": 114, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxTotalFruits($fruits, $startPos, $k) {", "container": "Solution", "callable": "maxTotalFruits", "parameters": [{"name": "fruits", "type": "Integer[][]"}, {"name": "startPos", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2108, "task_id": "find-first-palindromic-string-in-the-array", "difficulty": "Easy", "problem_description": "Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string \"\".\n\nA string is palindromic if it reads the same forward and backward.\n\nExample 1:\n\nInput: words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]\nOutput: \"ada\"\nExplanation: The first string that is palindromic is \"ada\".\nNote that \"racecar\" is also palindromic, but it is not the first.\n\nExample 2:\n\nInput: words = [\"notapalindrome\",\"racecar\"]\nOutput: \"racecar\"\nExplanation: The first and only string that is palindromic is \"racecar\".\n\nExample 3:\n\nInput: words = [\"def\",\"ghi\"]\nOutput: \"\"\nExplanation: There are no palindromic strings, so the empty string is returned.\n\nConstraints:\n\n- 1 <= words.length <= 100\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 = ['hello', 'world', 'python', 'madam']) == \"madam\"\n assert candidate(words = ['hello', 'world', 'python']) == \"\"\n assert candidate(words = ['abba', 'abcba', 'abcdedcba', 'nonpalindrome']) == \"abba\"\n assert candidate(words = ['level', 'deified', 'civic', 'rotor']) == \"level\"\n assert candidate(words = ['abccba', 'def', 'ghi', 'jklmnoponmlkj']) == \"abccba\"\n assert candidate(words = ['abc', 'car', 'ada', 'racecar', 'cool']) == \"ada\"\n assert candidate(words = ['madam', 'refer', 'level', 'world']) == \"madam\"\n assert candidate(words = ['madam', 'racecar', 'refer', 'deed', 'peep', 'noon']) == \"madam\"\n assert candidate(words = ['reviled', 'civic', 'rotor', 'redder', 'repaper', 'deed']) == \"civic\"\n assert candidate(words = ['a', 'b', 'c', 'd', 'e']) == \"a\"\n assert candidate(words = ['a', 'b', 'c']) == \"a\"\n assert candidate(words = ['racecar', 'ada', 'cool', 'abc']) == \"racecar\"\n assert candidate(words = ['noon', 'level', 'deified', 'rotor', 'redder']) == \"noon\"\n assert candidate(words = ['notapalindrome', 'racecar']) == \"racecar\"\n assert candidate(words = ['racecar', 'car', 'level']) == \"racecar\"\n assert candidate(words = ['noon', 'moon', 'refer', 'deed']) == \"noon\"\n assert candidate(words = ['abcde', 'fghij', 'klmno', 'pqrst']) == \"\"\n assert candidate(words = ['madam', 'refer', 'deed', 'peep', 'level']) == \"madam\"\n assert candidate(words = ['abacaba', 'racecar', 'kayak', 'detartrated', 'repaper']) == \"abacaba\"\n assert candidate(words = ['hello', 'world', 'python', 'programming']) == \"\"\n assert candidate(words = ['level', 'deified', 'civic', 'rotor', 'kayak', 'reviled']) == \"level\"\n assert candidate(words = ['noon', 'level', 'world', 'deified']) == \"noon\"\n assert candidate(words = ['abccba', 'defed', 'ghi', 'jkllkj']) == \"abccba\"\n assert candidate(words = ['def', 'ghi']) == \"\"\n assert candidate(words = ['noon', 'civic', 'rotor', 'deified']) == \"noon\"\n assert candidate(words = ['abcba', 'xyz', 'madam', 'noon']) == \"abcba\"\n assert candidate(words = ['step', 'on', 'no', 'pets']) == \"\"\n assert candidate(words = ['noon', 'racecar', 'kayak', 'reviled', 'civic', 'madam', 'refer', 'deed', 'detartrated', 'repaper']) == \"noon\"\n assert candidate(words = ['notapalindrome', 'almostapalindrome', 'palindromebutnot', 'thisisnotapalindrome', 'palindromic', 'palindrome', 'palindromes', 'palindromicly']) == \"\"\n assert candidate(words = ['abba', 'acca', 'adda', 'aedd', 'aeeea', 'aeeeea', 'aeeeeea', 'aeeeeeea']) == \"abba\"\n assert candidate(words = ['algorithm', 'datastructure', 'python', 'java', 'csharp', 'javascript', 'typescript', 'ruby', 'swift', 'kotlin']) == \"\"\n assert candidate(words = ['notapalindrome', 'stillnotapalindrome', 'palindrome', 'palindromic', 'racecar', 'noon', 'level']) == \"racecar\"\n assert candidate(words = ['a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj']) == \"a\"\n assert candidate(words = ['abccba', 'defed', 'fedcbafedcba', 'zxyzyx', 'mnoponm', 'qwertyytrewq', 'poiuytghjklkjhgfdsapoiuytrewq']) == \"abccba\"\n assert candidate(words = ['racecar', 'level', 'civic', 'rotor', 'deified', 'repaper', 'reviver', 'rotator']) == \"racecar\"\n assert candidate(words = ['nonpalindrome', 'notapalindrome', 'neverpalindrome', 'nopalin', 'palindromeisnothere', 'stillnotapalindrome']) == \"\"\n assert candidate(words = ['racecar', 'refer', 'reviler', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'ananab', 'banana', 'anana', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'racecar']) == \"racecar\"\n assert candidate(words = ['noon', 'civic', 'rotor', 'deed', 'peep', 'reed']) == \"noon\"\n assert candidate(words = ['x', 'y', 'z', 'aa', 'bb', 'cc', 'aaa', 'bbb', 'ccc', 'aaaa', 'bbbb', 'cccc', 'abcba', 'abccba', 'abba', 'racecar', 'madam', 'refer', 'deed', 'peep']) == \"x\"\n assert candidate(words = ['nonpalindromic', 'string', 'without', 'any', 'palindrome', 'here']) == \"\"\n assert candidate(words = ['deed', 'peep', 'noon', 'radar', 'repaper', 'reviver', 'rotator']) == \"deed\"\n assert candidate(words = ['racecar', 'deified', 'civic', 'rotor', 'level', 'repaper', 'rotor', 'reviled', 'detartrated', 'redivider', 'deed', 'peep', 'radar', 'redder', 'refer', 'rotator', 'reviver', 'rotor', 'racecar', 'madam', 'refer', 'racecar', 'deified', 'civic', 'rotor', 'level', 'repaper', 'rotor', 'reviled', 'detartrated', 'redivider', 'deed', 'peep', 'radar', 'redder', 'refer', 'rotator', 'reviver', 'rotor', 'racecar', 'madam', 'refer', 'racecar', 'deified', 'civic', 'rotor', 'level', 'repaper', 'rotor', 'reviled', 'detartrated', 'redivider', 'deed', 'peep', 'radar', 'redder', 'refer', 'rotator', 'reviver', 'rotor', 'racecar', 'madam', 'refer']) == \"racecar\"\n assert candidate(words = ['aabbccdd', 'ddccbbaa', 'abcdeedcba', 'abcdefghihgfedcba', 'abcdefghijkjihgfedcba', 'abcdefghijllkjihgfedcba', 'abcdefghijllkjihgfedcbaf', 'mnopqrstsrqponm']) == \"abcdeedcba\"\n assert candidate(words = ['a', 'bb', 'ccc', 'dddd', 'eeeee']) == \"a\"\n assert candidate(words = ['xylophone', 'guitar', 'piano', 'violin', 'flute', 'saxophone', 'trombone', 'trumpet', 'harp', 'xylophone', 'guitar', 'piano', 'violin', 'flute', 'saxophone', 'trombone', 'trumpet', 'harp', 'a', 'ab', 'aba', 'abcba', 'abcdedcba', 'abcdecba', 'abba', 'abcba']) == \"a\"\n assert candidate(words = ['racecar', 'refer', 'deed', 'peep', 'wow', 'madam', 'rotor', 'level']) == \"racecar\"\n assert candidate(words = ['zzzzzzzz', 'zzzyzzzz', 'zzzyyzzz', 'zzzyyyzz', 'zzzyyyyzzz', 'zzzyyyyyzzzz', 'zzzyyyyyyzzzzz']) == \"zzzzzzzz\"\n assert candidate(words = ['notapalindrome', 'noon', 'racecar', 'rotor', 'notapalindrome', 'reviled', 'detartrated', 'redivider', 'notapalindrome', 'deed', 'peep', 'radar', 'redder', 'refer', 'rotator', 'reviver', 'rotor', 'racecar', 'madam', 'refer', 'notapalindrome']) == \"noon\"\n assert candidate(words = ['noon', 'level', 'rotor', 'deified', 'civic', 'radar']) == \"noon\"\n assert candidate(words = ['abcdcba', 'dcba', 'efgh', 'hgef', 'ijkl', 'lkji', 'mnop', 'ponm', 'qrst', 'tsrq', 'uvw', 'wvu', 'xyz', 'zyx', 'racecar', 'level', 'deified', 'rotor', 'deed', 'peep', 'wow', 'civic', 'radar', 'refer', 'detartrated', 'repaper']) == \"abcdcba\"\n assert candidate(words = ['this', 'is', 'not', 'a', 'palindrome', 'racecar', 'madam', 'refer', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'ananab', 'banana', 'anana', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'racecar']) == \"a\"\n assert candidate(words = ['repaper', 'deed', 'civic', 'level', 'rotor', 'kayak', 'racecar', 'reviled']) == \"repaper\"\n assert candidate(words = ['bobby', 'radar', 'level', 'rotor', 'deed', 'peep', 'wow', 'madam']) == \"radar\"\n assert candidate(words = ['abccba', 'abcde', 'fghij', 'klmno', 'pqrst', 'xyzzyx', 'mnopqr', 'stuvuts']) == \"abccba\"\n assert candidate(words = ['abccba', 'bcb', 'a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj']) == \"abccba\"\n assert candidate(words = ['abcdedcba', 'abcdecba', 'abba', 'abcba', 'a', 'ab', 'aba', 'noon', 'civic', 'rotor', 'level', 'deified', 'redivider', 'detartrated', 'deed', 'peep', 'racecar', 'refer', 'reviler', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'ananab', 'banana', 'anana', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'racecar']) == \"abcdedcba\"\n assert candidate(words = ['verylongpalindromesequenceeosuqeeqosuerosequencemosuqeeqoserev', 'nonpalindrome', 'anotherlongword', 'racecar', 'level', 'deified']) == \"racecar\"\n assert candidate(words = ['nonpalindrome', 'another', 'longwordthatshouldnotbeapalindrome', 'almostapalindromemordnilapalmo', 'racecar', 'noon']) == \"racecar\"\n assert candidate(words = ['aabbcc', 'racecar', 'level', 'noon', 'civic', 'rotor', 'kayak']) == \"racecar\"\n assert candidate(words = ['aabb', 'abba', 'abcba', 'abcdedcba', 'abcdeedcba', 'abcdefgfedcba', 'ghijklmnonmlkjihg', 'poiuytrewqmrewtuyiop']) == \"abba\"\n assert candidate(words = ['noon', 'civic', 'rotor', 'level', 'deified', 'redivider', 'detartrated', 'deed', 'peep', 'racecar', 'refer', 'reviler', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'ananab', 'banana', 'anana', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'racecar']) == \"noon\"\n assert candidate(words = ['abacaba', 'bcb', 'abcba', 'a', 'racecar', 'level', 'deified', 'rotor', 'deed', 'peep', 'wow', 'civic', 'radar', 'refer', 'detartrated', 'repaper']) == \"abacaba\"\n assert candidate(words = ['madam', 'refer', 'stats', 'civic', 'rotor', 'kayak']) == \"madam\"\n assert candidate(words = ['zxcvbnm', 'mnbvcxz', 'qwertyuiop', 'poiuytrewq', 'asdfghjkl', 'lkjhgfdsa', 'qwertyuiopasdfghjklzxcvbnm', 'mnbvcxzlkjhgfdsapoiuytrewq', 'noon', 'civic', 'rotor', 'level', 'deified', 'redivider', 'detartrated', 'deed', 'peep', 'racecar', 'refer', 'reviler', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'ananab', 'banana', 'anana', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'racecar']) == \"noon\"\n assert candidate(words = ['madam', 'refer', 'deed', 'peep', 'reed', 'level', 'deified', 'repaper', 'deed', 'wow', 'did', 'civic', 'rotor', 'kayak', 'reviled', 'redder', 'repaper', 'peep', 'deed', 'madam', 'refer', 'civic', 'rotor', 'kayak', 'reviled']) == \"madam\"\n assert candidate(words = ['no', 'on', 'civic', 'rotor', 'deed', 'peep', 'noon', 'radar', 'racecar', 'redder', 'repaper', 'level', 'deified']) == \"civic\"\n assert candidate(words = ['level', 'deified', 'civic', 'rotor', 'refer', 'deed', 'peep', 'wow', 'madam']) == \"level\"\n assert candidate(words = ['xylophone', 'keyboard', 'guitar', 'piano', 'violin', 'flute', 'drums', 'harp', 'saxophone', 'trumpet']) == \"\"\n assert candidate(words = ['xylophone', 'guitar', 'piano', 'drums', 'violin', 'harp', 'flute', 'trumpet']) == \"\"\n assert candidate(words = ['a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff']) == \"a\"\n assert candidate(words = ['aabb', 'bbcc', 'ccdd', 'ddeeff', 'ffeeggee', 'hhiijjkk', 'llmmnnoopp', 'qqrrssttuuvvww', 'xxxyyyyzzzz']) == \"\"\n assert candidate(words = ['racecar', 'refer', 'deified', 'civic', 'level', 'rotor', 'kayak', 'reviled', 'deed', 'noon', 'madam', 'repaper', 'elppa', 'stuvuts', 'xyzzyx']) == \"racecar\"\n assert candidate(words = ['noon', 'level', 'deified', 'rotor', 'repaper', 'reviled', 'detartrated', 'redivider', 'deed', 'peep', 'radar', 'redder', 'refer', 'rotator', 'reviver', 'rotor', 'racecar', 'madam', 'refer']) == \"noon\"\n assert candidate(words = ['qwerty', 'asdfgh', 'zxcvbn', 'police', 'museum', 'kayak']) == \"kayak\"\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'abcba', 'abccba', 'abcdcba', 'abcdeba', 'abcdefedcba', 'abcdeedcba']) == \"a\"\n assert candidate(words = ['ab', 'aba', 'abcba', 'abcdedcba', 'abcdeedcba', 'abcdefgfedcba']) == \"aba\"\n assert candidate(words = ['banana', 'ananab', 'mango', 'orange', 'grape', 'apple', 'elppa']) == \"\"\n assert candidate(words = ['noon', 'level', 'civic', 'rotor', 'deified', 'repaper', 'reviver', 'rotator', 'a', 'bb', 'ccc', 'dddd', 'eeeee', 'ffffff', 'ggggggg', 'hhhhhhhh', 'iiiiiiiii', 'jjjjjjjjjj']) == \"noon\"\n assert candidate(words = ['xyzzyx', 'xyzyx', 'xyx', 'xx', 'x', 'aaa', 'abba', 'abcba', 'abcdedcba', 'abcdefghihgfedcba']) == \"xyzzyx\"\n assert candidate(words = ['madam', 'refer', 'level', 'deified', 'rotor', 'kayak', 'reviled', 'rotor', 'redder', 'repaper']) == \"madam\"\n assert candidate(words = ['aaaaaaaa', 'abccba', 'abcddcba', 'abcdedcba', 'abcdefghihgfedcba', 'abcdefghgfedcba', 'abcdeffedcba']) == \"aaaaaaaa\"\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\"\n assert candidate(words = ['abba', 'acca', 'adca', 'aeia', 'afda', 'agga']) == \"abba\"\n assert candidate(words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwxyz']) == \"a\"\n assert candidate(words = ['abcdeedcba', 'fghihgf', 'jklmlkj', 'nopon', 'qrsrstq', 'tuvut', 'xyzzyx', 'abcdedcba', 'fghigfh', 'jklkjl', 'mnoponm', 'qrstsrq', 'tuvutuv', 'xyzyx', 'abccba', 'madam', 'refer', 'noon', 'peep', 'deed', 'racecar', 'repaper', 'redder']) == \"abcdeedcba\"\n assert candidate(words = ['level', 'deified', 'civic', 'rotor', 'kayak', 'madam', 'racecar', 'refer', 'reviled']) == \"level\"\n assert candidate(words = ['aabbcc', 'baccab', 'racecar', 'madam', 'refer', 'reviler', 'repaper', 'repaper', 'rotor', 'level', 'kayak', 'stats', 'rotor', 'refer', 'reviler', 'repaper', 'rotor', 'level', 'kayak', 'stats']) == \"baccab\"\n assert candidate(words = ['notapalindrome', 'almostapalindrome', 'palindromebutnot', 'thisisnotapalindrome', 'palindromic', 'palindrome', 'palindromes', 'palindromicly', 'a', 'aa', 'aaa', 'aaaa', 'abcba', 'abccba', 'abcdcba', 'abcdeba', 'abcdefedcba', 'abcdeedcba']) == \"a\"\n assert candidate(words = ['anana', 'banana', 'ananab', 'level', 'deed', 'civic', 'rotor', 'detartrated', 'redivider', 'deified', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats', 'repaper', 'reviler', 'rotor', 'level', 'kayak', 'stats']) == \"anana\"\n assert candidate(words = ['abccba', 'defg', 'hijklm', 'nopqrst', 'uvwxyz']) == \"abccba\"\n assert candidate(words = ['deified', 'repaper', 'detartrated', 'reviled', 'redder', 'repaid', 'deed']) == \"deified\"\n assert candidate(words = ['aabbccddeeff', 'ffeeddccbbaa', 'abcdefedcba', 'abcdefgihgfedcba', 'abcdefghijkjihgfedcba', 'abcdefghijllkjihgfedcba', 'abcdefghijllkjihgfedcbaf']) == \"abcdefedcba\"\n assert candidate(words = ['thisisnotapalindrome', 'neitheristhis', 'butthisoneis', 'civic', 'rotor', 'madam', 'refer', 'noon', 'deed', 'racecar', 'repaper', 'redder', 'level', 'deified', 'abccba', 'abcba', 'abba', 'baab', 'abcdedcba', 'fghigfh', 'jklkjl', 'mnoponm', 'qrstsrq', 'tuvutuv', 'xyzyx']) == \"civic\"\n assert candidate(words = ['noon', 'level', 'deified', 'rotor', 'reviled']) == \"noon\"\n assert candidate(words = ['level', 'deified', 'rotor', 'redder', 'repaper', 'deed', 'peep', 'wow', 'civic', 'radar']) == \"level\"\n assert candidate(words = ['madam', 'refer', 'level', 'deified', 'rotor', 'reviled']) == \"madam\"\n assert candidate(words = ['deified', 'level', 'civic', 'rotor', 'kayak', 'reviled', 'madam', 'refer', 'noon', 'peep', 'redder', 'repaper', 'racecar', 'deed']) == \"deified\"\n assert candidate(words = ['aabb', 'bbaa', 'abba', 'baab', 'abcba', 'abccba', 'madam', 'refer', 'noon', 'deed', 'racecar', 'repaper', 'redder', 'civic', 'rotor', 'kayak', 'reviled', 'deified', 'level', 'rotor', 'redder', 'repaper', 'level', 'deified']) == \"abba\"\n assert candidate(words = ['xylophone', 'guitar', 'piano', 'drums', 'flute', 'violin', 'harp']) == \"\"\n assert candidate(words = ['abcd', 'dcba', 'efgh', 'hgef', 'ijkl', 'lkji', 'mnop', 'ponm', 'qrst', 'tsrq', 'uvw', 'wvu', 'xyz', 'zyx']) == \"\"\n assert candidate(words = ['noon', 'civic', 'rotor', 'level', 'deified', 'redivider', 'detartrated', 'deed', 'peep', 'racecar']) == \"noon\"\n", "comparison": "exact"}, "public_tests": ["[\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]", "[\"notapalindrome\",\"racecar\"]", "[\"def\",\"ghi\"]"], "hints": ["Iterate through the elements in order. As soon as the current element is a palindrome, return it.", "To check if an element is a palindrome, can you reverse the string?"], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().firstPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:23+00:00", "tests_total": 104, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function firstPalindrome($words) {", "container": "Solution", "callable": "firstPalindrome", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2109, "task_id": "adding-spaces-to-a-string", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.\n\n- For example, given s = \"EnjoyYourCoffee\" and spaces = [5, 9], we place spaces before 'Y' and 'C', which are at indices 5 and 9 respectively. Thus, we obtain \"Enjoy Your Coffee\".\n\nReturn the modified string after the spaces have been added.\n\nExample 1:\n\nInput: s = \"LeetcodeHelpsMeLearn\", spaces = [8,13,15]\nOutput: \"Leetcode Helps Me Learn\"\nExplanation:\nThe indices 8, 13, and 15 correspond to the underlined characters in \"LeetcodeHelpsMeLearn\".\nWe then place spaces before those characters.\n\nExample 2:\n\nInput: s = \"icodeinpython\", spaces = [1,5,7,9]\nOutput: \"i code in py thon\"\nExplanation:\nThe indices 1, 5, 7, and 9 correspond to the underlined characters in \"icodeinpython\".\nWe then place spaces before those characters.\n\nExample 3:\n\nInput: s = \"spacing\", spaces = [0,1,2,3,4,5,6]\nOutput: \" s p a c i n g\"\nExplanation:\nWe are also able to place spaces before the first character of the string.\n\nConstraints:\n\n- 1 <= s.length <= 3 * 10^5\n- s consists only of lowercase and uppercase English letters.\n- 1 <= spaces.length <= 3 * 10^5\n- 0 <= spaces[i] <= s.length - 1\n- All the values of spaces are strictly increasing.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"spacing\",spaces = [0, 1, 2, 3, 4, 5, 6]) == \" s p a c i n g\"\n assert candidate(s = \"icodeinpython\",spaces = [1, 5, 7, 9]) == \"i code in py thon\"\n assert candidate(s = \"A\",spaces = [0]) == \" A\"\n assert candidate(s = \"icodeinpython\",spaces = [1, 5, 7, 9]) == \"i code in py thon\"\n assert candidate(s = \"InsertSpacesEverywhere\",spaces = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20]) == \"I n s e r t S p a c e s E v e r yw h e re\"\n assert candidate(s = \"LeetcodeHelpsMeLearn\",spaces = [8, 13, 15]) == \"Leetcode Helps Me Learn\"\n assert candidate(s = \"spacing\",spaces = [0, 1, 2, 3, 4, 5, 6]) == \" s p a c i n g\"\n assert candidate(s = \"PythonProgramming\",spaces = [6]) == \"Python Programming\"\n assert candidate(s = \"LeetcodeHelpsMeLearn\",spaces = [8, 13, 15]) == \"Leetcode Helps Me Learn\"\n assert candidate(s = \"AlibabaCloudisAmazing\",spaces = [7, 13, 19]) == \"Alibaba Cloudi sAmazi ng\"\n assert candidate(s = \"AugmentedReality\",spaces = [8, 14]) == \"Augmente dReali ty\"\n assert candidate(s = \"ParallelAndDistributedComputing\",spaces = [8, 26]) == \"Parallel AndDistributedComp uting\"\n assert candidate(s = \"Short\",spaces = [1, 2]) == \"S h ort\"\n assert candidate(s = \"InsertSpacesHere\",spaces = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == \"I n s e r t S p a c e sHere\"\n assert candidate(s = \"AlgorithmDesignAndAnalysis\",spaces = [9, 18, 22]) == \"Algorithm DesignAnd Anal ysis\"\n assert candidate(s = \"InformationSecurity\",spaces = [16]) == \"InformationSecur ity\"\n assert candidate(s = \"ComputerNetworking\",spaces = [13]) == \"ComputerNetwo rking\"\n assert candidate(s = \"HelloWorldFromPython\",spaces = [5, 11, 15]) == \"Hello WorldF romP ython\"\n assert candidate(s = \"OneTwoThreeFourFiveSixSevenEightNineTen\",spaces = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == \"One Two Thr eeF our Fiv eSi xSe ven Eig htNineTen\"\n assert candidate(s = \"EndWithSpaces\",spaces = [10, 11, 12]) == \"EndWithSpa c e s\"\n assert candidate(s = \"MultipleSpacesInARow\",spaces = [12, 13, 14, 15]) == \"MultipleSpac e s I nARow\"\n assert candidate(s = \"ZebraCrossing\",spaces = [5, 10]) == \"Zebra Cross ing\"\n assert candidate(s = \"abcdefghij\",spaces = [1, 3, 5, 7, 9]) == \"a bc de fg hi j\"\n assert candidate(s = \"BlockchainTechnology\",spaces = [9, 18]) == \"Blockchai nTechnolo gy\"\n assert candidate(s = \"BoundaryEdgeCases\",spaces = [0, 14]) == \" BoundaryEdgeCa ses\"\n assert candidate(s = \"ComplexPattern\",spaces = [1, 3, 5, 7, 9, 11]) == \"C om pl ex Pa tt ern\"\n assert candidate(s = \"ThisIsAVeryLongStringWithoutSpaces\",spaces = [4, 8, 12, 17, 21, 27, 32]) == \"This IsAV eryL ongSt ring Withou tSpac es\"\n assert candidate(s = \"ComputerVision\",spaces = [12]) == \"ComputerVisi on\"\n assert candidate(s = \"VirtualReality\",spaces = [7, 13]) == \"Virtual Realit y\"\n assert candidate(s = \"MultipleConsecutiveSpaces\",spaces = [7, 8, 9, 10, 11]) == \"Multipl e C o n secutiveSpaces\"\n assert candidate(s = \"OneBigSpaceInTheMiddle\",spaces = [10]) == \"OneBigSpac eInTheMiddle\"\n assert candidate(s = \"CloudComputingServices\",spaces = [5, 14, 21]) == \"Cloud Computing Service s\"\n assert candidate(s = \"MultipleSpaces\",spaces = [2, 5, 8, 11]) == \"Mu lti ple Spa ces\"\n assert candidate(s = \"TestStringWithSeveralSpaces\",spaces = [4, 8, 12, 16, 20, 24]) == \"Test Stri ngWi thSe vera lSpa ces\"\n assert candidate(s = \"AdvancedAlgorithmDesign\",spaces = [7, 21]) == \"Advance dAlgorithmDesi gn\"\n assert candidate(s = \"NaturalLanguageProcessing\",spaces = [11, 21]) == \"NaturalLang uageProces sing\"\n assert candidate(s = \"NeuralNetworks\",spaces = [6, 13]) == \"Neural Network s\"\n assert candidate(s = \"QuickBrownFox\",spaces = [5, 11]) == \"Quick BrownF ox\"\n assert candidate(s = \"SingleCharacter\",spaces = [0]) == \" SingleCharacter\"\n assert candidate(s = \"InternetOfThings\",spaces = [8, 13, 15]) == \"Internet OfThi ng s\"\n assert candidate(s = \"InternetOfThings\",spaces = [8, 14]) == \"Internet OfThin gs\"\n assert candidate(s = \"DataStructuresAndAlgorithms\",spaces = [4, 16, 23]) == \"Data StructuresAn dAlgori thms\"\n assert candidate(s = \"PythonIsFun\",spaces = [6, 8]) == \"Python Is Fun\"\n assert candidate(s = \"AddingSpacesEverywhere\",spaces = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == \"A dd in gS pa ce sE ve ry where\"\n assert candidate(s = \"SingleWord\",spaces = [5]) == \"Singl eWord\"\n assert candidate(s = \"EdgeCasesAtTheEnd\",spaces = [13, 14, 15]) == \"EdgeCasesAtTh e E nd\"\n assert candidate(s = \"RoboticsEngineering\",spaces = [8, 17]) == \"Robotics Engineeri ng\"\n assert candidate(s = \"QwenIsPowerful\",spaces = [4, 8, 12]) == \"Qwen IsPo werf ul\"\n assert candidate(s = \"TheQuickBrownFoxJumpsOverTheLazyDog\",spaces = [3, 9, 15, 21, 25, 30, 34]) == \"The QuickB rownFo xJumps Over TheLa zyDo g\"\n assert candidate(s = \"AddingSpacesInAString\",spaces = [5, 12, 16]) == \"Addin gSpaces InAS tring\"\n assert candidate(s = \"SingleSpaceAtEnd\",spaces = [13]) == \"SingleSpaceAt End\"\n assert candidate(s = \"ProgrammingLanguages\",spaces = [11]) == \"Programming Languages\"\n assert candidate(s = \"OneWord\",spaces = [0]) == \" OneWord\"\n assert candidate(s = \"ConsecutiveSpaces\",spaces = [4, 5, 11, 12]) == \"Cons e cutive S paces\"\n assert candidate(s = \"aLongStringWithoutSpaces\",spaces = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == \"a L o n g S t r i n g W i t h o u t S p a ces\"\n assert candidate(s = \"DatabaseSystems\",spaces = [10]) == \"DatabaseSy stems\"\n assert candidate(s = \"DistributedSystems\",spaces = [13]) == \"DistributedSy stems\"\n assert candidate(s = \"BlockChainTechnology\",spaces = [9, 18]) == \"BlockChai nTechnolo gy\"\n assert candidate(s = \"Alphabet\",spaces = [1, 2, 3, 4, 5, 6]) == \"A l p h a b et\"\n assert candidate(s = \"a\",spaces = [0]) == \" a\"\n assert candidate(s = \"AlibabaCloudServices\",spaces = [7, 18]) == \"Alibaba CloudServic es\"\n assert candidate(s = \"AlgorithmsAndDataStructures\",spaces = [10, 15, 20]) == \"Algorithms AndDa taStr uctures\"\n assert candidate(s = \"TestEdgeCases\",spaces = [0, 4, 8, 12]) == \" Test Edge Case s\"\n assert candidate(s = \"EdgeCasesHandled\",spaces = [0, 11, 13]) == \" EdgeCasesHa nd led\"\n assert candidate(s = \"CyberSecurity\",spaces = [10]) == \"CyberSecur ity\"\n assert candidate(s = \"StartWithSpaces\",spaces = [0, 1, 2]) == \" S t artWithSpaces\"\n assert candidate(s = \"ComputerVision\",spaces = [8, 13]) == \"Computer Visio n\"\n assert candidate(s = \"abcdefg\",spaces = [1, 2, 3, 4, 5, 6]) == \"a b c d e f g\"\n assert candidate(s = \"OperatingSystems\",spaces = [12]) == \"OperatingSys tems\"\n assert candidate(s = \"ArtificialIntelligence\",spaces = [9, 19]) == \"Artificia lIntellige nce\"\n assert candidate(s = \"AlgorithmsAndDataStructures\",spaces = [10, 15, 20, 25]) == \"Algorithms AndDa taStr uctur es\"\n", "comparison": "exact"}, "public_tests": ["\"LeetcodeHelpsMeLearn\"\n[8,13,15]", "\"icodeinpython\"\n[1,5,7,9]", "\"spacing\"\n[0,1,2,3,4,5,6]"], "hints": ["Create a new string, initially empty, as the modified string. Iterate through the original string and append each character of the original string to the new string. However, each time you reach a character that requires a space before it, append a space before appending the character.", "Since the array of indices for the space locations is sorted, use a pointer to keep track of the next index to place a space. Only increment the pointer once a space has been appended.", "Ensure that your append operation can be done in O(1)."], "metadata": {"canonical_parameter_names": ["s", "spaces"], "leetcode_dataset_entry_point": "Solution().addSpaces", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:26+00:00", "tests_total": 127, "tests_dropped": 56, "flags": [], "topic_tags": ["array", "two-pointers", "string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function addSpaces($s, $spaces) {", "container": "Solution", "callable": "addSpaces", "parameters": [{"name": "s", "type": "String"}, {"name": "spaces", "type": "Integer[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2110, "task_id": "number-of-smooth-descent-periods-of-a-stock", "difficulty": "Medium", "problem_description": "You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the i^th day.\n\nA smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower than the price on the preceding day by exactly 1. The first day of the period is exempted from this rule.\n\nReturn the number of smooth descent periods.\n\nExample 1:\n\nInput: prices = [3,2,1,4]\nOutput: 7\nExplanation: There are 7 smooth descent periods:\n[3], [2], [1], [4], [3,2], [2,1], and [3,2,1]\nNote that a period with one day is a smooth descent period by the definition.\n\nExample 2:\n\nInput: prices = [8,6,7,7]\nOutput: 4\nExplanation: There are 4 smooth descent periods: [8], [6], [7], and [7]\nNote that [8,6] is not a smooth descent period as 8 - 6 ≠ 1.\n\nExample 3:\n\nInput: prices = [1]\nOutput: 1\nExplanation: There is 1 smooth descent period: [1]\n\nConstraints:\n\n- 1 <= prices.length <= 10^5\n- 1 <= prices[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(prices = [10, 9, 4, 3, 2, 1]) == 13\n assert candidate(prices = [3, 3, 3, 3, 3]) == 5\n assert candidate(prices = [100000, 99999, 99998, 99997, 99996, 99995]) == 21\n assert candidate(prices = [8, 6, 7, 7]) == 4\n assert candidate(prices = [1]) == 1\n assert candidate(prices = [10, 9, 10, 9, 8, 7, 8, 7, 6, 5]) == 23\n assert candidate(prices = [3, 3, 3, 3, 3, 3, 3]) == 7\n assert candidate(prices = [5, 4, 5, 4, 3, 2, 1]) == 18\n assert candidate(prices = [3, 2, 1, 4]) == 7\n assert candidate(prices = [1, 3, 2, 1, 4, 3, 2, 1]) == 17\n assert candidate(prices = [5, 4, 3, 4, 3, 2, 1]) == 16\n assert candidate(prices = [5]) == 1\n assert candidate(prices = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 55\n assert candidate(prices = [10, 9, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 51\n assert candidate(prices = [1, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 19\n assert candidate(prices = [5, 4, 3, 2, 1]) == 15\n assert candidate(prices = [1, 2, 3, 4, 5]) == 5\n assert candidate(prices = [10, 9, 8, 9, 8, 7, 6, 5, 6, 7]) == 23\n assert candidate(prices = [2, 1, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 37\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 65\n assert candidate(prices = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 36\n assert candidate(prices = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 66\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 = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 210\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(prices = [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]) == 166\n assert candidate(prices = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11]) == 135\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5]) == 76\n assert candidate(prices = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == 210\n assert candidate(prices = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 29\n assert candidate(prices = [3, 2, 1, 2, 1, 3, 2, 1, 2, 1, 3, 2, 1, 2, 1]) == 27\n assert candidate(prices = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 28\n assert candidate(prices = [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(prices = [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, 2, 3, 4, 5]) == 60\n assert candidate(prices = [7, 6, 5, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]) == 73\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 6, 5, 4, 3, 2, 1]) == 42\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 64\n assert candidate(prices = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 29\n assert candidate(prices = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991, 49990, 49989, 49988, 49987, 49986, 49985, 49984, 49983, 49982, 49981]) == 210\n assert candidate(prices = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 70\n assert candidate(prices = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 41\n assert candidate(prices = [1, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2]) == 40\n assert candidate(prices = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 54\n assert candidate(prices = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 44\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 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, 79, 78, 77, 76, 75]) == 325\n assert candidate(prices = [10, 9, 8, 10, 9, 8, 7, 6, 5, 7, 6, 5, 4, 3, 2, 1]) == 55\n assert candidate(prices = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 210\n assert candidate(prices = [10, 9, 8, 7, 10, 9, 8, 7, 6, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 86\n assert candidate(prices = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 33\n assert candidate(prices = [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]) == 37\n assert candidate(prices = [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]) == 170\n assert candidate(prices = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 19\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 64\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 = [7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 109\n assert candidate(prices = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 231\n assert candidate(prices = [10, 9, 8, 9, 8, 7, 8, 7, 6, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 60\n assert candidate(prices = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1]) == 38\n assert candidate(prices = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 136\n assert candidate(prices = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 49\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 110\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(prices = [10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 201\n assert candidate(prices = [10, 9, 8, 9, 8, 7, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9]) == 62\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]) == 25\n assert candidate(prices = [1, 2, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 19\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 19\n assert candidate(prices = [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]) == 80\n assert candidate(prices = [10, 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]) == 147\n assert candidate(prices = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 55\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]) == 28\n assert candidate(prices = [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]) == 119\n assert candidate(prices = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4]) == 40\n assert candidate(prices = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 29\n assert candidate(prices = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 110\n assert candidate(prices = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 24\n assert candidate(prices = [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]) == 5050\n assert candidate(prices = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 22\n assert candidate(prices = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5]) == 44\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 64\n assert candidate(prices = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20]) == 211\n assert candidate(prices = [5, 6, 5, 4, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 41\n assert candidate(prices = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981, 99980]) == 210\n assert candidate(prices = [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]) == 69\n assert candidate(prices = [10, 9, 10, 9, 8, 7, 8, 7, 6, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5]) == 48\n assert candidate(prices = [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]) == 81\n assert candidate(prices = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 66\n assert candidate(prices = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 14\n assert candidate(prices = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 35\n assert candidate(prices = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(prices = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(prices = [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]) == 325\n assert candidate(prices = [5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 26\n assert candidate(prices = [10, 9, 8, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4]) == 70\n assert candidate(prices = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 11\n assert candidate(prices = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(prices = [7, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 79\n assert candidate(prices = [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]) == 240\n", "comparison": "exact"}, "public_tests": ["[3,2,1,4]", "[8,6,7,7]", "[1]"], "hints": ["Any array is a series of adjacent longest possible smooth descent periods. For example, [5,3,2,1,7,6] is [5] + [3,2,1] + [7,6].", "Think of a 2-pointer approach to traverse the array and find each longest possible period.", "Suppose you found the longest possible period with a length of k. How many periods are within that period? How can you count them quickly? Think of the formula to calculate the sum of 1, 2, 3, ..., k."], "metadata": {"canonical_parameter_names": ["prices"], "leetcode_dataset_entry_point": "Solution().getDescentPeriods", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:29+00:00", "tests_total": 116, "tests_dropped": 16, "flags": [], "topic_tags": ["array", "math", "two-pointers", "dynamic-programming", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function getDescentPeriods($prices) {", "container": "Solution", "callable": "getDescentPeriods", "parameters": [{"name": "prices", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2111, "task_id": "minimum-operations-to-make-the-array-k-increasing", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.\n\nThe array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.\n\n- For example, arr = [4, 1, 5, 2, 6, 2] is K-increasing for k = 2 because:\n - arr[0] <= arr[2] (4 <= 5)\n - arr[1] <= arr[3] (1 <= 2)\n - arr[2] <= arr[4] (5 <= 6)\n - arr[3] <= arr[5] (2 <= 2)\n- However, the same arr is not K-increasing for k = 1 (because arr[0] > arr[1]) or k = 3 (because arr[0] > arr[3]).\n\nIn one operation, you can choose an index i and change arr[i] into any positive integer.\n\nReturn the minimum number of operations required to make the array K-increasing for the given k.\n\nExample 1:\n\nInput: arr = [5,4,3,2,1], k = 1\nOutput: 4\nExplanation:\nFor k = 1, the resultant array has to be non-decreasing.\nSome of the K-increasing arrays that can be formed are [5,6,7,8,9], [1,1,1,1,1], [2,2,3,4,4]. All of them require 4 operations.\nIt is suboptimal to change the array to, for example, [6,7,8,9,10] because it would take 5 operations.\nIt can be shown that we cannot make the array K-increasing in less than 4 operations.\n\nExample 2:\n\nInput: arr = [4,1,5,2,6,2], k = 2\nOutput: 0\nExplanation:\nThis is the same example as the one in the problem description.\nHere, for every index i where 2 <= i <= 5, arr[i-2] <= arr[i].\nSince the given array is already K-increasing, we do not need to perform any operations.\n\nExample 3:\n\nInput: arr = [4,1,5,2,6,2], k = 3\nOutput: 2\nExplanation:\nIndices 3 and 5 are the only ones not satisfying arr[i-3] <= arr[i] for 3 <= i <= 5.\nOne of the ways we can make the array K-increasing is by changing arr[3] to 4 and arr[5] to 5.\nThe array will now be [4,1,5,4,6,5].\nNote that there can be other ways to make the array K-increasing, but none of them require less than 2 operations.\n\nConstraints:\n\n- 1 <= arr.length <= 10^5\n- 1 <= arr[i], k <= arr.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(arr = [4, 1, 5, 2, 6, 2],k = 3) == 2\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 0\n assert candidate(arr = [6, 5, 4, 3, 2, 1],k = 2) == 4\n assert candidate(arr = [5, 4, 3, 2, 1],k = 1) == 4\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 6\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6],k = 2) == 0\n assert candidate(arr = [5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(arr = [1, 2, 3, 4, 5],k = 1) == 0\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(arr = [1, 2, 3, 4, 5],k = 5) == 0\n assert candidate(arr = [7, 4, 2, 6, 3, 5, 1, 8],k = 3) == 3\n assert candidate(arr = [1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(arr = [2, 2, 2, 2, 2],k = 5) == 0\n assert candidate(arr = [9, 4, 2, 3, 1, 5, 7, 8, 6, 10],k = 1) == 4\n assert candidate(arr = [1, 2, 3, 4, 5, 6],k = 1) == 0\n assert candidate(arr = [4, 1, 5, 2, 6, 2],k = 2) == 0\n assert candidate(arr = [1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(arr = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 4) == 3\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(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],k = 5) == 20\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 9\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 = 3) == 0\n assert candidate(arr = [1, 3, 5, 2, 4, 6, 3, 5, 7, 4, 6, 8],k = 2) == 6\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == 0\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 16\n assert candidate(arr = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 7) == 0\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 = 1) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 0\n assert candidate(arr = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 2) == 0\n assert candidate(arr = [9, 7, 5, 3, 1, 10, 8, 6, 4, 2, 11],k = 5) == 0\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10],k = 5) == 7\n assert candidate(arr = [1, 3, 5, 2, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 15, 17, 16, 18, 20, 19, 21, 23, 22, 24, 26, 25, 27, 29, 28, 30, 32, 31, 33, 35, 34, 36, 38, 37, 39, 41, 40, 42, 44, 43, 45, 47, 46, 48, 50, 49],k = 3) == 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 = 4) == 0\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 = 20) == 0\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 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 = 10) == 0\n assert candidate(arr = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4],k = 5) == 4\n assert candidate(arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 4) == 4\n assert candidate(arr = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9],k = 3) == 3\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, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],k = 5) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 7\n assert candidate(arr = [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 = 3) == 27\n assert candidate(arr = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 1) == 0\n assert candidate(arr = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 3) == 0\n assert candidate(arr = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15],k = 3) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 20) == 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 = 2) == 0\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 0\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 9\n assert candidate(arr = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 1) == 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, 26, 27, 28, 29, 30],k = 10) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(arr = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10],k = 2) == 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 = 2) == 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) == 0\n assert candidate(arr = [1, 3, 2, 4, 6, 5, 7, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20],k = 3) == 0\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 0\n assert candidate(arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9],k = 2) == 3\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 = 1) == 0\n assert candidate(arr = [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 = 29) == 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],k = 10) == 0\n assert candidate(arr = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 8\n assert candidate(arr = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9],k = 1) == 12\n assert candidate(arr = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],k = 2) == 4\n assert candidate(arr = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 2) == 0\n assert candidate(arr = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4],k = 5) == 9\n assert candidate(arr = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 14\n assert candidate(arr = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == 2\n assert candidate(arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(arr = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 10\n assert candidate(arr = [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 = 2) == 0\n assert candidate(arr = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11],k = 3) == 0\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 = 4) == 0\n assert candidate(arr = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 12\n assert candidate(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 25\n assert candidate(arr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(arr = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5],k = 2) == 0\n assert candidate(arr = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10],k = 2) == 0\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 = 3) == 8\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 = 5) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 0\n assert candidate(arr = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],k = 2) == 0\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 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],k = 5) == 0\n assert candidate(arr = [5, 3, 8, 6, 2, 7, 4, 9, 1],k = 2) == 3\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 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 = 5) == 0\n", "comparison": "exact"}, "public_tests": ["[5,4,3,2,1]\n1", "[4,1,5,2,6,2]\n2", "[4,1,5,2,6,2]\n3"], "hints": ["Can we divide the array into non-overlapping subsequences and simplify the problem?", "In the final array, arr[i-k] ≤ arr[i] should hold. We can use this to divide the array into at most k non-overlapping sequences, where arr[i] will belong to the (i%k)th sequence.", "Now our problem boils down to performing the minimum operations on each sequence such that it becomes non-decreasing. Our answer will be the sum of operations on each sequence.", "Which indices of a sequence should we not change in order to count the minimum operations? Can finding the longest non-decreasing subsequence of the sequence help?"], "metadata": {"canonical_parameter_names": ["arr", "k"], "leetcode_dataset_entry_point": "Solution().kIncreasing", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:31+00:00", "tests_total": 133, "tests_dropped": 38, "flags": [], "topic_tags": ["array", "binary-search", "longest-increasing-subsequence"]}, "language": "php", "interface": {"raw_signature": "function kIncreasing($arr, $k) {", "container": "Solution", "callable": "kIncreasing", "parameters": [{"name": "arr", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2114, "task_id": "maximum-number-of-words-found-in-sentences", "difficulty": "Easy", "problem_description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n\nYou are given an array of strings sentences, where each sentences[i] represents a single sentence.\n\nReturn the maximum number of words that appear in a single sentence.\n\nExample 1:\n\nInput: sentences = [\"alice and bob love leetcode\", \"i think so too\", \"this is great thanks very much\"]\nOutput: 6\nExplanation:\n- The first sentence, \"alice and bob love leetcode\", has 5 words in total.\n- The second sentence, \"i think so too\", has 4 words in total.\n- The third sentence, \"this is great thanks very much\", has 6 words in total.\nThus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.\n\nExample 2:\n\nInput: sentences = [\"please wait\", \"continue to fight\", \"continue to win\"]\nOutput: 3\nExplanation: It is possible that multiple sentences contain the same number of words.\nIn this example, the second and third sentences (underlined) have the same number of words.\n\nConstraints:\n\n- 1 <= sentences.length <= 100\n- 1 <= sentences[i].length <= 100\n- sentences[i] consists only of lowercase English letters and ' ' only.\n- sentences[i] does not have leading or trailing spaces.\n- All the words in sentences[i] are separated by a single space.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentences = ['short', 'tiny', 'minuscule']) == 1\n assert candidate(sentences = ['one']) == 1\n assert candidate(sentences = ['alice and bob love leetcode', 'i think so too', 'this is great thanks very much']) == 6\n assert candidate(sentences = ['singleword', 'two words', 'three words here']) == 3\n assert candidate(sentences = ['one two three four five six seven eight nine ten']) == 10\n assert candidate(sentences = ['please wait', 'continue to fight', 'continue to win']) == 3\n assert candidate(sentences = ['hello world', 'hi there']) == 2\n assert candidate(sentences = ['singleword', 'another word', 'yet another example']) == 3\n assert candidate(sentences = ['a quick brown fox', 'jumps over the lazy dog']) == 5\n assert candidate(sentences = ['one two three', 'four five six seven', 'eight nine ten eleven twelve']) == 5\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z']) == 26\n assert candidate(sentences = ['longer sentences with more words to test the function', 'another sentence to check the word count correctly', 'yet another example sentence for validation', 'this is the last sentence for this test case']) == 9\n assert candidate(sentences = ['equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal', 'equal']) == 1\n assert candidate(sentences = ['all questions asked by five watched experts amaze the judge', 'jackdaws love my big sphinx of quartz', 'the five boxing wizards jump quickly on this new sentence']) == 10\n assert candidate(sentences = ['tiny', 'shorter', 'shortest', 'a bit longer', 'the longest sentence in the list']) == 6\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'this sentence is longer than the previous one', 'a']) == 9\n assert candidate(sentences = ['once upon a time in a world far far away', 'there lived a king and a queen', 'who were very very happy together']) == 10\n assert candidate(sentences = ['singleword', 'two words', 'three words are', 'four words are here', 'five words are here now', 'six words are here now indeed', 'seven words are here now indeed truly']) == 7\n assert candidate(sentences = ['this sentence has twelve words in it indeed', 'this one has seven words']) == 8\n assert candidate(sentences = ['a short sentence', 'a much longer sentence with many more words in it', 'tiny', 'an even longer sentence that seems to go on and on and on']) == 13\n assert candidate(sentences = ['one two three', 'four five six seven', 'eight nine ten eleven twelve', 'thirteen fourteen fifteen sixteen seventeen']) == 5\n assert candidate(sentences = ['equal number of words here', 'equal number of words here', 'equal number of words here']) == 5\n assert candidate(sentences = ['this is a single word', 'this is a two word phrase', 'this sentence has three words in it']) == 7\n assert candidate(sentences = ['one two three', 'four five six seven eight', 'nine ten eleven twelve thirteen fourteen fifteen']) == 7\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'this is a sentence with many many many words indeed']) == 26\n assert candidate(sentences = ['this is a test sentence with exactly ten words in it', 'another test sentence here with ten words too', 'and yet another test sentence that has ten words']) == 11\n assert candidate(sentences = ['singleword', 'anotherword', 'yetanotherword', 'onemoreword']) == 1\n assert candidate(sentences = ['python is fun', 'data structures and algorithms', 'object oriented programming is powerful']) == 5\n assert candidate(sentences = ['this is a test', 'another test sentence', 'yet another example to consider', 'the longest sentence in this batch is this one here']) == 10\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'pack my box with five dozen liquor jugs']) == 9\n assert candidate(sentences = ['abcd efgh ijkl mnop qrst uvwx yz', 'abcd efgh ijkl mnop qrst uvwx yz abcd', 'abcd efgh ijkl mnop qrst uvwx yz abcd efgh', 'abcd efgh ijkl mnop qrst uvwx yz abcd efgh ijkl mnop']) == 11\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'every good boy does fine', 'to be or not to be that is the question']) == 10\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'the rain in spain stays mainly in the plain', 'i am six']) == 26\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'a b c d e f g h i j k l m n o p q r s t u v w x y', 'a b c d e f g h i j k l m n o p q r s t u v w x']) == 26\n assert candidate(sentences = ['words words words words words words words words words words', 'just a couple', 'quite a bit more words than before']) == 10\n assert candidate(sentences = ['the best way to achieve success is through hard work', 'persistence is key to overcoming challenges', 'never give up on your dreams']) == 10\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'quick fox jumps', 'lazy dog']) == 26\n assert candidate(sentences = ['one', 'two words', 'three words here', 'four words here now', 'five words here now indeed', 'six words here now indeed truly']) == 6\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'every good boy does fine', 'pack my box with five dozen liquor jugs']) == 9\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'short sentence']) == 26\n assert candidate(sentences = ['one', 'two three', 'four five six', 'seven eight nine ten', 'eleven twelve thirteen fourteen fifteen']) == 5\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'pack my box with five dozen liquor jugs', 'how vexingly quick daft zebras jump']) == 9\n assert candidate(sentences = ['repeat repeat repeat repeat repeat repeat repeat repeat repeat repeat', 'different repeat different repeat', 'unique sentence']) == 10\n assert candidate(sentences = ['a quick brown fox jumps over the lazy dog', 'this is a longer sentence with more words in it', 'short']) == 10\n assert candidate(sentences = ['equal length words here', 'equal length words here', 'equal length words here']) == 4\n assert candidate(sentences = ['one two three four five', 'six seven eight nine ten eleven', 'twelve thirteen fourteen fifteen sixteen seventeen', 'eighteen nineteen twenty']) == 6\n assert candidate(sentences = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyzabcdefghijkl']) == 1\n assert candidate(sentences = ['equal length', 'equal length', 'equal length', 'equal length', 'equal length', 'equal length']) == 2\n assert candidate(sentences = ['lorem ipsum dolor sit amet', 'consectetur adipiscing elit', 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua']) == 11\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'a quick movement of the enemy will jeopardize six gunboats', 'five boxing wizards jump quickly']) == 10\n assert candidate(sentences = ['an apple a day keeps the doctor away', 'once upon a time in a land far far away', 'hello world hello universe']) == 10\n assert candidate(sentences = ['the longest sentence in this list is the last one which contains many many words indeed']) == 16\n assert candidate(sentences = ['the quick brown fox jumps over the lazy dog', 'how now brown cow', 'she sells sea shells by the sea shore']) == 9\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'jumps over the lazy dog']) == 26\n assert candidate(sentences = ['the secret to a happy life is simple', 'be kind to others', 'live each day to the fullest', 'love what you do']) == 8\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'i am a sentence with many words indeed', 'this is another test sentence']) == 26\n assert candidate(sentences = ['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']) == 26\n assert candidate(sentences = ['python is a great programming language', 'java is also a great programming language', 'c plus plus is another popular language']) == 7\n assert candidate(sentences = ['singleword', 'two words', 'three words here', 'four words are in this', 'five words make a phrase', 'six words is a complete sentence']) == 6\n assert candidate(sentences = ['longer sentences are more challenging to process correctly', 'even longer sentences that contain a greater number of words for testing', 'tiny']) == 12\n assert candidate(sentences = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij']) == 1\n assert candidate(sentences = ['to be or not to be that is the question', 'that is the question indeed', 'whether tis nobler in the mind to suffer']) == 10\n assert candidate(sentences = ['python is great', 'i love programming', 'data science is fascinating', 'machine learning and ai are transforming industries']) == 7\n assert candidate(sentences = ['this is a very long sentence indeed that should test the boundaries of the problem constraints']) == 16\n assert candidate(sentences = ['singleword', 'two words', 'three words here', 'four words make a sentence', 'five words in this sentence']) == 5\n assert candidate(sentences = ['complex sentences are interesting', 'they can have many clauses and ideas', 'and sometimes they even have subordinate clauses']) == 7\n assert candidate(sentences = ['very very very long sentence to test the length', 'short sentence', 'another medium length sentence here']) == 9\n assert candidate(sentences = ['very long sentence with many many many words indeed', 'short one', 'medium length sentence']) == 9\n assert candidate(sentences = ['a singleword', 'two words here', 'three words in this', 'four words make up']) == 4\n assert candidate(sentences = ['this is a sentence with seven words', 'another one with five words', 'and yet another with eight words here']) == 7\n assert candidate(sentences = ['a b c d e f g h i j k l m n o p q r s t u v w x y z', 'the cat in the hat']) == 26\n assert candidate(sentences = ['this is a longer sentence with more words', 'tiny', 'another sentence with quite a few words indeed']) == 8\n assert candidate(sentences = ['python is an amazing language for data science and machine learning', 'the early morning sun illuminated the dew covered grass', 'she sells sea shells by the sea shore']) == 11\n assert candidate(sentences = ['same same same same same same same', 'another same same same', 'and yet another same same']) == 7\n assert candidate(sentences = ['one', 'two three', 'four five six', 'seven eight nine ten']) == 4\n", "comparison": "exact"}, "public_tests": ["[\"alice and bob love leetcode\",\"i think so too\",\"this is great thanks very much\"]", "[\"please wait\",\"continue to fight\",\"continue to win\"]"], "hints": ["Process each sentence separately and count the number of words by looking for the number of space characters in the sentence and adding it by 1."], "metadata": {"canonical_parameter_names": ["sentences"], "leetcode_dataset_entry_point": "Solution().mostWordsFound", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:36+00:00", "tests_total": 78, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function mostWordsFound($sentences) {", "container": "Solution", "callable": "mostWordsFound", "parameters": [{"name": "sentences", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2115, "task_id": "find-all-possible-recipes-from-given-supplies", "difficulty": "Medium", "problem_description": "You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The i^th recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. A recipe can also be an ingredient for other recipes, i.e., ingredients[i] may contain a string that is in recipes.\n\nYou are also given a string array supplies containing all the ingredients that you initially have, and you have an infinite supply of all of them.\n\nReturn a list of all the recipes that you can create. You may return the answer in any order.\n\nNote that two recipes may contain each other in their ingredients.\n\nExample 1:\n\nInput: recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\",\"flour\",\"corn\"]\nOutput: [\"bread\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\n\nExample 2:\n\nInput: recipes = [\"bread\",\"sandwich\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"]], supplies = [\"yeast\",\"flour\",\"meat\"]\nOutput: [\"bread\",\"sandwich\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\nWe can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".\n\nExample 3:\n\nInput: recipes = [\"bread\",\"sandwich\",\"burger\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]], supplies = [\"yeast\",\"flour\",\"meat\"]\nOutput: [\"bread\",\"sandwich\",\"burger\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\nWe can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".\nWe can create \"burger\" since we have the ingredient \"meat\" and can create the ingredients \"bread\" and \"sandwich\".\n\nConstraints:\n\n- n == recipes.length == ingredients.length\n- 1 <= n <= 100\n- 1 <= ingredients[i].length, supplies.length <= 100\n- 1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10\n- recipes[i], ingredients[i][j], and supplies[k] consist only of lowercase English letters.\n- All the values of recipes and supplies combined are unique.\n- Each ingredients[i] does not contain any duplicate values.\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(recipes=['bread', 'sandwich'], ingredients=[['yeast', 'flour'], ['bread', 'meat']], supplies=['yeast', 'flour', 'meat']), ['bread', 'sandwich'])\n assert answers_match(candidate(recipes=['pasta', 'salad'], ingredients=[['noodles', 'sauce'], ['lettuce', 'tomato']], supplies=['noodles', 'sauce', 'lettuce']), ['pasta'])\n assert answers_match(candidate(recipes=['bread', 'sandwich', 'burger'], ingredients=[['yeast', 'flour'], ['bread', 'meat'], ['sandwich', 'meat', 'bread']], supplies=['yeast', 'flour', 'meat']), ['bread', 'sandwich', 'burger'])\n assert answers_match(candidate(recipes=['cake', 'muffin'], ingredients=[['flour', 'sugar'], ['flour', 'eggs']], supplies=['flour', 'sugar']), ['cake'])\n assert answers_match(candidate(recipes=['bread'], ingredients=[['yeast', 'flour']], supplies=['yeast', 'flour', 'corn']), ['bread'])\n assert answers_match(candidate(recipes=['cake', 'muffin', 'brownie'], ingredients=[['flour', 'sugar', 'eggs'], ['flour', 'sugar', 'butter'], ['flour', 'sugar', 'chocolate']], supplies=['flour', 'sugar', 'eggs']), ['cake'])\n assert answers_match(candidate(recipes=['cake', 'muffin'], ingredients=[['flour', 'sugar', 'eggs'], ['flour', 'sugar', 'eggs', 'butter']], supplies=['flour', 'sugar', 'eggs', 'butter']), ['cake', 'muffin'])\n assert answers_match(candidate(recipes=['pizza', 'pasta'], ingredients=[['dough', 'tomato', 'cheese'], ['noodles', 'sauce']], supplies=['dough', 'tomato', 'cheese', 'noodles', 'sauce']), ['pizza', 'pasta'])\n assert answers_match(candidate(recipes=['soup', 'stew'], ingredients=[['water', 'vegetables', 'spices'], ['water', 'meat', 'vegetables', 'spices']], supplies=['water', 'vegetables', 'spices']), ['soup'])\n assert answers_match(candidate(recipes=['sushi', 'ramen'], ingredients=[['rice', 'seaweed', 'salmon'], ['noodles', 'water', 'meat', 'vegetables']], supplies=['rice', 'noodles', 'water', 'meat']), [])\n assert answers_match(candidate(recipes=['cake', 'pudding', 'pie'], ingredients=[['flour', 'sugar', 'eggs'], ['milk', 'sugar', 'flour'], ['crust', 'fruit', 'filling']], supplies=['flour', 'sugar', 'eggs', 'milk', 'crust', 'fruit', 'filling']), ['cake', 'pudding', 'pie'])\n assert answers_match(candidate(recipes=['cake', 'brownie'], ingredients=[['flour', 'sugar', 'eggs'], ['flour', 'cocoa', 'sugar']], supplies=['flour', 'sugar', 'eggs']), ['cake'])\n assert answers_match(candidate(recipes=['omelette', 'pancake', 'waffle'], ingredients=[['eggs', 'milk'], ['flour', 'eggs', 'milk'], ['flour', 'eggs', 'milk', 'butter']], supplies=['eggs', 'milk', 'flour', 'butter', 'sugar']), ['omelette', 'pancake', 'waffle'])\n assert answers_match(candidate(recipes=['bread', 'sandwich', 'burger', 'wrap'], ingredients=[['yeast', 'flour'], ['bread', 'meat'], ['bread', 'meat', 'cheese'], ['bread', 'cheese', 'lettuce']], supplies=['yeast', 'flour', 'meat', 'cheese', 'lettuce']), ['bread', 'sandwich', 'burger', 'wrap'])\n assert answers_match(candidate(recipes=['soup', 'stew'], ingredients=[['carrot', 'onion'], ['carrot', 'potato', 'beef']], supplies=['carrot', 'onion', 'beef', 'potato', 'pepper']), ['soup', 'stew'])\n assert answers_match(candidate(recipes=['pizza', 'pasta', 'omelette'], ingredients=[['dough', 'tomato', 'cheese'], ['noodles', 'sauce'], ['eggs', 'milk']], supplies=['dough', 'tomato', 'cheese', 'noodles', 'sauce', 'eggs', 'milk', 'flour']), ['pizza', 'pasta', 'omelette'])\n assert answers_match(candidate(recipes=['juice', 'smoothie'], ingredients=[['fruit', 'water'], ['fruit', 'yogurt', 'banana']], supplies=['fruit', 'water', 'yogurt', 'banana', 'milk']), ['juice', 'smoothie'])\n assert answers_match(candidate(recipes=['steak', 'chicken', 'beef'], ingredients=[['beef', 'salt'], ['chicken', 'pepper'], ['salt', 'spice']], supplies=['salt', 'pepper', 'spice', 'chicken']), ['beef', 'chicken', 'steak'])\n assert answers_match(candidate(recipes=['soup', 'stew'], ingredients=[['water', 'vegetables', 'meat'], ['water', 'vegetables', 'meat', 'tomato']], supplies=['water', 'vegetables', 'meat', 'tomato', 'salt']), ['soup', 'stew'])\n assert answers_match(candidate(recipes=['pizza', 'taco', 'pasta'], ingredients=[['dough', 'tomato', 'cheese'], ['tortilla', 'meat', 'cheese'], ['noodles', 'sauce', 'meat']], supplies=['dough', 'tomato', 'cheese', 'tortilla', 'meat', 'noodles', 'sauce']), ['pizza', 'taco', 'pasta'])\n assert answers_match(candidate(recipes=['smoothie', 'juice'], ingredients=[['banana', 'orange', 'milk'], ['apple', 'orange', 'water']], supplies=['banana', 'orange', 'water']), [])\n assert answers_match(candidate(recipes=['omelette', 'frittata'], ingredients=[['eggs', 'cheese'], ['eggs', 'cheese', 'spinach', 'tomato']], supplies=['eggs', 'cheese', 'spinach']), ['omelette'])\n assert answers_match(candidate(recipes=['omelette', 'pancakes'], ingredients=[['eggs', 'milk'], ['eggs', 'flour', 'milk']], supplies=['eggs', 'milk', 'flour', 'butter']), ['omelette', 'pancakes'])\n assert answers_match(candidate(recipes=['sandwich', 'burger', 'omelet'], ingredients=[['bread', 'meat', 'cheese'], ['bread', 'patty', 'cheese'], ['eggs', 'cheese', 'spinach']], supplies=['bread', 'meat', 'cheese', 'patty', 'eggs', 'spinach']), ['sandwich', 'burger', 'omelet'])\n assert answers_match(candidate(recipes=['cake', 'brownie'], ingredients=[['sugar', 'flour', 'eggs'], ['sugar', 'chocolate', 'eggs']], supplies=['sugar', 'eggs']), [])\n assert answers_match(candidate(recipes=['cake', 'pie', 'tiramisu'], ingredients=[['flour', 'eggs', 'sugar'], ['apple', 'flour', 'sugar'], ['cake', 'coffee', 'mascarpone']], supplies=['flour', 'eggs', 'sugar', 'apple', 'coffee', 'mascarpone']), ['cake', 'pie', 'tiramisu'])\n assert answers_match(candidate(recipes=['soup', 'stew', 'salad', 'sandwich'], ingredients=[['carrot', 'onion'], ['carrot', 'potato', 'beef'], ['lettuce', 'cucumber'], ['bread', 'cheese']], supplies=['carrot', 'onion', 'beef', 'potato', 'pepper', 'lettuce', 'cucumber', 'bread', 'cheese', 'eggs']), ['soup', 'stew', 'salad', 'sandwich'])\n assert answers_match(candidate(recipes=['pancake', 'waffle', 'muffin'], ingredients=[['flour', 'eggs', 'milk'], ['flour', 'eggs', 'milk', 'butter'], ['flour', 'sugar', 'eggs']], supplies=['flour', 'eggs', 'milk', 'butter', 'sugar']), ['pancake', 'waffle', 'muffin'])\n assert answers_match(candidate(recipes=['pizza', 'pasta', 'soup'], ingredients=[['dough', 'tomato', 'cheese'], ['noodles', 'sauce'], ['carrots', 'onions', 'water']], supplies=['dough', 'tomato', 'noodles', 'carrots']), [])\n assert answers_match(candidate(recipes=['a', 'b', 'c', 'd'], ingredients=[['e', 'f'], ['a', 'g'], ['b', 'h'], ['c', 'i']], supplies=['e', 'f', 'g', 'h', 'i']), ['a', 'b', 'c', 'd'])\n assert answers_match(candidate(recipes=['beer', 'wine'], ingredients=[['grains', 'water', 'hops'], ['grapes', 'yeast', 'sugar']], supplies=['grains', 'water', 'hops', 'grapes', 'yeast', 'sugar']), ['beer', 'wine'])\n assert answers_match(candidate(recipes=['pizza', 'pasta', 'salad'], ingredients=[['dough', 'sauce', 'cheese'], ['noodles', 'sauce'], ['lettuce', 'tomato']], supplies=['dough', 'cheese', 'noodles', 'sauce', 'lettuce', 'tomato', 'spinach']), ['pizza', 'pasta', 'salad'])\n assert answers_match(candidate(recipes=['smoothie', 'juice'], ingredients=[['banana', 'strawberry', 'milk'], ['apple', 'orange', 'water']], supplies=['banana', 'strawberry', 'milk', 'apple', 'orange']), ['smoothie'])\n assert answers_match(candidate(recipes=['omelette', 'pancake'], ingredients=[['eggs', 'milk'], ['flour', 'eggs', 'milk']], supplies=['eggs', 'milk', 'flour', 'butter']), ['omelette', 'pancake'])\n assert answers_match(candidate(recipes=['bread', 'toast', 'baguette'], ingredients=[['flour', 'yeast'], ['bread'], ['flour', 'yeast', 'oil']], supplies=['flour', 'yeast', 'oil', 'butter']), ['bread', 'baguette', 'toast'])\n assert answers_match(candidate(recipes=['soup', 'stew', 'omelette'], ingredients=[['water', 'vegetables', 'salt'], ['water', 'meat', 'vegetables'], ['eggs', 'cheese', 'pepper']], supplies=['water', 'vegetables', 'meat', 'eggs', 'cheese', 'pepper']), ['stew', 'omelette'])\n assert answers_match(candidate(recipes=['pizza', 'fries', 'burger'], ingredients=[['dough', 'tomato', 'cheese'], ['potato', 'salt'], ['patty', 'cheese', 'bun']], supplies=['dough', 'tomato', 'cheese', 'potato', 'salt', 'patty', 'bun']), ['pizza', 'fries', 'burger'])\n assert answers_match(candidate(recipes=['sushi', 'ramen'], ingredients=[['rice', 'fish', 'seaweed'], ['noodles', 'broth', 'egg']], supplies=['rice', 'fish', 'seaweed', 'noodles', 'broth', 'egg']), ['sushi', 'ramen'])\n assert answers_match(candidate(recipes=['soup', 'stew', 'salad'], ingredients=[['carrot', 'onion'], ['carrot', 'potato', 'beef'], ['lettuce', 'cucumber']], supplies=['carrot', 'onion', 'beef', 'potato', 'pepper', 'lettuce', 'cucumber']), ['soup', 'stew', 'salad'])\n assert answers_match(candidate(recipes=['cake', 'pie'], ingredients=[['flour', 'eggs', 'sugar'], ['apple', 'flour', 'sugar']], supplies=['flour', 'eggs', 'sugar', 'milk']), ['cake'])\n assert answers_match(candidate(recipes=['pasta', 'pizza', 'lasagna'], ingredients=[['noodles', 'sauce'], ['dough', 'sauce', 'cheese'], ['noodles', 'sauce', 'cheese', 'milk']], supplies=['noodles', 'sauce', 'cheese', 'dough', 'milk']), ['pasta', 'pizza', 'lasagna'])\n assert answers_match(candidate(recipes=['omelette', 'pancake'], ingredients=[['eggs', 'cheese', 'bacon'], ['flour', 'eggs', 'milk']], supplies=['eggs', 'flour', 'milk']), ['pancake'])\n assert answers_match(candidate(recipes=['pizza', 'sandwich', 'omelette', 'burger'], ingredients=[['dough', 'tomato', 'cheese'], ['bread', 'cheese', 'meat'], ['egg', 'milk', 'cheese'], ['patty', 'cheese', 'bun']], supplies=['dough', 'tomato', 'cheese', 'bread', 'meat', 'egg', 'milk', 'patty', 'bun']), ['pizza', 'sandwich', 'omelette', 'burger'])\n assert answers_match(candidate(recipes=['cake', 'pudding', 'pie'], ingredients=[['flour', 'eggs', 'sugar'], ['milk', 'cornstarch'], ['crust', 'apple', 'sugar']], supplies=['flour', 'eggs', 'milk', 'sugar']), ['cake'])\n assert answers_match(candidate(recipes=['salad', 'soup', 'stew'], ingredients=[['lettuce', 'tomato', 'onion'], ['carrot', 'potato', 'beef'], ['carrot', 'potato', 'beef', 'tomato']], supplies=['lettuce', 'tomato', 'onion', 'carrot', 'potato']), ['salad'])\n assert answers_match(candidate(recipes=['omelette', 'scramble', 'frittata'], ingredients=[['eggs', 'cheese'], ['eggs'], ['eggs', 'cheese', 'spinach']], supplies=['eggs', 'cheese', 'spinach', 'milk']), ['scramble', 'omelette', 'frittata'])\n assert answers_match(candidate(recipes=['cake', 'brownie', 'pudding'], ingredients=[['flour', 'sugar', 'eggs', 'milk'], ['flour', 'sugar', 'chocolate'], ['milk', 'sugar', 'gelatin']], supplies=['flour', 'sugar', 'eggs', 'milk', 'chocolate', 'gelatin']), ['cake', 'brownie', 'pudding'])\n assert answers_match(candidate(recipes=['soup', 'stew', 'chili'], ingredients=[['water', 'carrot', 'potato'], ['water', 'tomato', 'carrot', 'potato'], ['water', 'tomato', 'beef', 'potato']], supplies=['water', 'carrot', 'potato', 'tomato', 'beef']), ['soup', 'stew', 'chili'])\n assert answers_match(candidate(recipes=['pizza', 'lasagna', 'taco'], ingredients=[['dough', 'tomato', 'cheese'], ['pasta', 'mozzarella', 'sauce'], ['tortilla', 'meat', 'cheese']], supplies=['dough', 'tomato', 'cheese', 'pasta', 'mozzarella', 'sauce', 'tortilla', 'meat']), ['pizza', 'lasagna', 'taco'])\n assert answers_match(candidate(recipes=['bread', 'cake', 'pudding'], ingredients=[['flour', 'yeast', 'water'], ['flour', 'eggs', 'sugar'], ['milk', 'cornstarch', 'water']], supplies=['flour', 'yeast', 'eggs', 'sugar', 'milk']), ['cake'])\n assert answers_match(candidate(recipes=['cake', 'brownie', 'tiramisu'], ingredients=[['flour', 'sugar', 'eggs'], ['flour', 'sugar', 'chocolate'], ['coffee', 'brownie', 'cream']], supplies=['flour', 'sugar', 'eggs', 'chocolate', 'coffee', 'cream']), ['cake', 'brownie', 'tiramisu'])\n assert answers_match(candidate(recipes=['pizza', 'calzone', 'taco', 'burrito'], ingredients=[['dough', 'sauce', 'cheese'], ['dough', 'cheese', 'meat'], ['tortilla', 'meat', 'lettuce'], ['tortilla', 'meat', 'beans']], supplies=['dough', 'sauce', 'cheese', 'meat', 'tortilla', 'lettuce', 'beans']), ['pizza', 'calzone', 'taco', 'burrito'])\n assert answers_match(candidate(recipes=['steak', 'chicken', 'beef'], ingredients=[['meat', 'seasoning'], ['meat', 'vegetables'], ['meat', 'sauce']], supplies=['meat', 'seasoning', 'vegetables']), ['steak', 'chicken'])\n assert answers_match(candidate(recipes=['taco', 'burrito'], ingredients=[['tortilla', 'beef', 'cheese'], ['tortilla', 'chicken', 'cheese', 'lettuce']], supplies=['tortilla', 'cheese', 'lettuce']), [])\n assert answers_match(candidate(recipes=['muffin', 'brownie', 'cupcake'], ingredients=[['flour', 'eggs', 'milk', 'sugar'], ['flour', 'eggs', 'chocolate', 'sugar'], ['muffin', 'icing']], supplies=['flour', 'eggs', 'milk', 'sugar', 'chocolate', 'icing']), ['muffin', 'brownie', 'cupcake'])\n assert answers_match(candidate(recipes=['soup', 'stew'], ingredients=[['water', 'carrot', 'potato'], ['water', 'tomato', 'carrot', 'potato']], supplies=['water', 'carrot', 'potato', 'tomato']), ['soup', 'stew'])\n assert answers_match(candidate(recipes=['taco', 'burrito'], ingredients=[['shell', 'meat', 'cheese'], ['wrap', 'meat', 'cheese', 'lettuce']], supplies=['shell', 'wrap', 'meat', 'cheese', 'lettuce', 'tomato']), ['taco', 'burrito'])\n assert answers_match(candidate(recipes=['cake', 'brownie'], ingredients=[['flour', 'eggs', 'sugar'], ['flour', 'eggs', 'chocolate']], supplies=['flour', 'eggs', 'sugar', 'chocolate']), ['cake', 'brownie'])\n assert answers_match(candidate(recipes=['cake', 'muffin', 'brownie'], ingredients=[['flour', 'sugar', 'eggs'], ['flour', 'sugar', 'eggs', 'butter'], ['flour', 'sugar', 'chocolate']], supplies=['flour', 'sugar', 'eggs', 'butter', 'chocolate']), ['cake', 'muffin', 'brownie'])\n assert answers_match(candidate(recipes=['muffin', 'pancake', 'scone'], ingredients=[['flour', 'sugar', 'milk'], ['flour', 'eggs', 'milk'], ['flour', 'butter', 'milk']], supplies=['flour', 'eggs', 'butter', 'milk']), ['pancake', 'scone'])\n assert answers_match(candidate(recipes=['juice', 'smoothie'], ingredients=[['orange', 'apple'], ['banana', 'orange', 'milk']], supplies=['orange', 'apple', 'banana', 'milk', 'water']), ['juice', 'smoothie'])\n assert answers_match(candidate(recipes=['pancake', 'waffle', 'omelette'], ingredients=[['flour', 'eggs', 'milk'], ['flour', 'eggs', 'syrup'], ['eggs', 'milk', 'cheese']], supplies=['flour', 'eggs', 'milk', 'syrup', 'cheese']), ['pancake', 'waffle', 'omelette'])\n assert answers_match(candidate(recipes=['pizza', 'pasta'], ingredients=[['dough', 'sauce', 'cheese'], ['noodles', 'sauce']], supplies=['dough', 'sauce', 'cheese', 'noodles', 'tomato']), ['pizza', 'pasta'])\n assert answers_match(candidate(recipes=['pizza', 'spaghetti'], ingredients=[['dough', 'sauce', 'cheese'], ['pasta', 'sauce', 'meat']], supplies=['dough', 'sauce', 'pasta']), [])\n", "comparison": "unordered"}, "public_tests": ["[\"bread\"]\n[[\"yeast\",\"flour\"]]\n[\"yeast\",\"flour\",\"corn\"]", "[\"bread\",\"sandwich\"]\n[[\"yeast\",\"flour\"],[\"bread\",\"meat\"]]\n[\"yeast\",\"flour\",\"meat\"]", "[\"bread\",\"sandwich\",\"burger\"]\n[[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]]\n[\"yeast\",\"flour\",\"meat\"]"], "hints": ["Can we use a data structure to quickly query whether we have a certain ingredient?", "Once we verify that we can make a recipe, we can add it to our ingredient data structure. We can then check if we can make more recipes as a result of this."], "metadata": {"canonical_parameter_names": ["recipes", "ingredients", "supplies"], "leetcode_dataset_entry_point": "Solution().findAllRecipes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:39+00:00", "tests_total": 103, "tests_dropped": 39, "flags": ["any_order"], "topic_tags": ["array", "hash-table", "string", "graph", "topological-sort", "directed-acyclic-graph"]}, "language": "php", "interface": {"raw_signature": "function findAllRecipes($recipes, $ingredients, $supplies) {", "container": "Solution", "callable": "findAllRecipes", "parameters": [{"name": "recipes", "type": "String[]"}, {"name": "ingredients", "type": "String[][]"}, {"name": "supplies", "type": "String[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2116, "task_id": "check-if-a-parentheses-string-can-be-valid", "difficulty": "Medium", "problem_description": "A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n\n- It is ().\n- It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\n- It can be written as (A), where A is a valid parentheses string.\n\nYou are given a parentheses string s and a string locked, both of length n. locked is a binary string consisting only of '0's and '1's. For each index i of locked,\n\n- If locked[i] is '1', you cannot change s[i].\n- But if locked[i] is '0', you can change s[i] to either '(' or ')'.\n\nReturn true if you can make s a valid parentheses string. Otherwise, return false.\n\nExample 1:\n\nInput: s = \"))()))\", locked = \"010100\"\nOutput: true\nExplanation: locked[1] == '1' and locked[3] == '1', so we cannot change s[1] or s[3].\nWe change s[0] and s[4] to '(' while leaving s[2] and s[5] unchanged to make s valid.\n\nExample 2:\n\nInput: s = \"()()\", locked = \"0000\"\nOutput: true\nExplanation: We do not need to make any changes because s is already valid.\n\nExample 3:\n\nInput: s = \")\", locked = \"0\"\nOutput: false\nExplanation: locked permits us to change s[0].\nChanging s[0] to either '(' or ')' will not make s valid.\n\nExample 4:\n\nInput: s = \"(((())(((())\", locked = \"111111010111\"\nOutput: true\nExplanation: locked permits us to change s[6] and s[8].\nWe change s[6] and s[8] to ')' to make s valid.\n\nConstraints:\n\n- n == s.length == locked.length\n- 1 <= n <= 10^5\n- s[i] is either '(' or ')'.\n- locked[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"(((())(((())\",locked = \"111111010111\") == True\n assert candidate(s = \"()))()\",locked = \"010100\") == True\n assert candidate(s = \"()()\",locked = \"0000\") == True\n assert candidate(s = \")\",locked = \"0\") == False\n assert candidate(s = \"()()()()()()()()\",locked = \"0000000000000000\") == True\n assert candidate(s = \"(((((())))))\",locked = \"000000000000\") == True\n assert candidate(s = \"((((()))))))\",locked = \"000111000111\") == True\n assert candidate(s = \"(()())\",locked = \"100101\") == True\n assert candidate(s = \"((()()(()))\",locked = \"10000000000\") == False\n assert candidate(s = \"(((())))()()\",locked = \"000010000000\") == True\n assert candidate(s = \"()((()))()((()))\",locked = \"0011110000111100\") == True\n assert candidate(s = \"(()())\",locked = \"000000\") == True\n assert candidate(s = \"(()(()))\",locked = \"00101000\") == True\n assert candidate(s = \"((()()(())))\",locked = \"010000101001\") == True\n assert candidate(s = \"((((((()))))\",locked = \"000000000001\") == True\n assert candidate(s = \"(()))(\",locked = \"101010\") == True\n assert candidate(s = \"((((((((((((()))))))))))\",locked = \"111111111111110000000000\") == False\n assert candidate(s = \"(((((())))()())\",locked = \"010010000001000\") == False\n assert candidate(s = \"((())())\",locked = \"10010010\") == True\n assert candidate(s = \"((((()))))((((()))))\",locked = \"11111111111111111111\") == True\n assert candidate(s = \"()()(()(()))\",locked = \"000001100100\") == True\n assert candidate(s = \"(()(()(()(()))))\",locked = \"1010101010101010\") == True\n assert candidate(s = \"((((((()))))))\",locked = \"01010101010101\") == True\n assert candidate(s = \"(((())))(((())))\",locked = \"1111111111111111\") == True\n assert candidate(s = \"())(()\",locked = \"001010\") == True\n assert candidate(s = \"(((())))\",locked = \"11111111\") == True\n assert candidate(s = \"((()))\",locked = \"000000\") == True\n assert candidate(s = \"((())()(()))\",locked = \"110101001101\") == True\n assert candidate(s = \"(((((())))))\",locked = \"111111100001\") == True\n assert candidate(s = \"((())()(()))\",locked = \"101010101010\") == True\n assert candidate(s = \"(((((())))))\",locked = \"111100001111\") == True\n assert candidate(s = \"(((((((())))))))\",locked = \"0101010101010101\") == True\n assert candidate(s = \"()()()()\",locked = \"11111111\") == True\n assert candidate(s = \")()(()(()))(\",locked = \"010101010100\") == True\n assert candidate(s = \"()()()()()()()()()()\",locked = \"00000000000000000000\") == True\n assert candidate(s = \"(()(()))()()\",locked = \"010100101000\") == True\n assert candidate(s = \"(()(()))((()(())))\",locked = \"010010010010110010\") == True\n assert candidate(s = \"()(()())\",locked = \"10010010\") == True\n assert candidate(s = \"(()())((()))\",locked = \"000000000000\") == True\n assert candidate(s = \"((())()(()))\",locked = \"101001010100\") == True\n assert candidate(s = \"((())()(()))\",locked = \"000000000000\") == True\n assert candidate(s = \"()()()()\",locked = \"00000000\") == True\n assert candidate(s = \"(((((())))))\",locked = \"011100111001\") == True\n assert candidate(s = \"(()())()()()\",locked = \"000000000000\") == True\n assert candidate(s = \")(()(()(()))\",locked = \"011001101001\") == True\n", "comparison": "exact"}, "public_tests": ["\"))()))\"\n\"010100\"", "\"()()\"\n\"0000\"", "\")\"\n\"0\"", "\"(((())(((())\"\n\"111111010111\""], "hints": ["Can an odd length string ever be valid?", "From left to right, if a locked ')' is encountered, it must be balanced with either a locked '(' or an unlocked index on its left. If neither exist, what conclusion can be drawn? If both exist, which one is more preferable to use?", "After the above, we may have locked indices of '(' and additional unlocked indices. How can you balance out the locked '(' now? What if you cannot balance any locked '('?"], "metadata": {"canonical_parameter_names": ["s", "locked"], "leetcode_dataset_entry_point": "Solution().canBeValid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:41+00:00", "tests_total": 81, "tests_dropped": 36, "flags": ["has_images"], "topic_tags": ["string", "stack", "greedy", "bracket-sequences"]}, "language": "php", "interface": {"raw_signature": "function canBeValid($s, $locked) {", "container": "Solution", "callable": "canBeValid", "parameters": [{"name": "s", "type": "String"}, {"name": "locked", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2117, "task_id": "abbreviating-the-product-of-a-range", "difficulty": "Hard", "problem_description": "You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].\n\nSince the product may be very large, you will abbreviate it following these steps:\n\n1. Count all trailing zeros in the product and remove them. Let us denote this count as C.\n - For example, there are 3 trailing zeros in 1000, and there are 0 trailing zeros in 546.\n2. Denote the remaining number of digits in the product as d. If d > 10, then express the product as
...where denotes the first 5 digits of the product, anddenotes the last 5 digits of the product after removing all trailing zeros. If d <= 10, we keep it unchanged.\n - For example, we express 1234567654321 as 12345...54321, but 1234567 is represented as 1234567.\n3. Finally, represent the product as a string \" ...eC\".\n - For example, 12345678987600000 will be represented as \"12345...89876e5\".\n\nReturn a string denoting the abbreviated product of all integers in the inclusive range [left, right].\n\nExample 1:\n\nInput: left = 1, right = 4\nOutput: \"24e0\"\nExplanation: The product is 1 × 2 × 3 × 4 = 24.\nThere are no trailing zeros, so 24 remains the same. The abbreviation will end with \"e0\".\nSince the number of digits is 2, which is less than 10, we do not have to abbreviate it further.\nThus, the final representation is \"24e0\".\n\nExample 2:\n\nInput: left = 2, right = 11\nOutput: \"399168e2\"\nExplanation: The product is 39916800.\nThere are 2 trailing zeros, which we remove to get 399168. The abbreviation will end with \"e2\".\nThe number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.\nHence, the abbreviated product is \"399168e2\".\n\nExample 3:\n\nInput: left = 371, right = 375\nOutput: \"7219856259e3\"\nExplanation: The product is 7219856259000.\n\nConstraints:\n\n- 1 <= left <= right <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(left = 100,right = 105) == \"1158727752e3\"\n assert candidate(left = 1,right = 10000) == \"28462...79008e2499\"\n assert candidate(left = 10,right = 20) == \"6704425728e3\"\n assert candidate(left = 371,right = 375) == \"7219856259e3\"\n assert candidate(left = 1000,right = 1010) == \"10563...82688e5\"\n assert candidate(left = 5000,right = 5010) == \"49367...34144e6\"\n assert candidate(left = 1234,right = 1238) == \"28846...40584e1\"\n assert candidate(left = 999,right = 1000) == \"999e3\"\n assert candidate(left = 1,right = 10) == \"36288e2\"\n assert candidate(left = 1234,right = 1240) == \"44318...63424e2\"\n assert candidate(left = 5,right = 5) == \"5e0\"\n assert candidate(left = 1000,right = 1000) == \"1e3\"\n assert candidate(left = 10,right = 15) == \"36036e2\"\n assert candidate(left = 1000,right = 1004) == \"10100...50024e3\"\n assert candidate(left = 500,right = 510) == \"54464...59744e5\"\n assert candidate(left = 1,right = 100) == \"93326...16864e24\"\n assert candidate(left = 995,right = 1000) == \"98508...27388e4\"\n assert candidate(left = 9995,right = 10000) == \"99850...73988e5\"\n assert candidate(left = 1,right = 4) == \"24e0\"\n assert candidate(left = 2,right = 11) == \"399168e2\"\n assert candidate(left = 500,right = 505) == \"16099...69356e4\"\n assert candidate(left = 5000,right = 5005) == \"15671...18506e5\"\n assert candidate(left = 5,right = 10) == \"1512e2\"\n assert candidate(left = 8000,right = 8003) == \"40990...04048e3\"\n assert candidate(left = 5555,right = 6666) == \"28137...34688e279\"\n assert candidate(left = 9000,right = 9005) == \"53232...19508e4\"\n assert candidate(left = 100,right = 150) == \"61219...44768e15\"\n assert candidate(left = 5,right = 20) == \"10137...00736e4\"\n assert candidate(left = 3000,right = 3100) == \"81710...90592e27\"\n assert candidate(left = 1234,right = 1244) == \"10562...94176e2\"\n assert candidate(left = 1,right = 5000) == \"42285...33472e1249\"\n assert candidate(left = 9000,right = 9050) == \"53429...51328e15\"\n assert candidate(left = 100,right = 1000) == \"43116...46048e227\"\n assert candidate(left = 6000,right = 6005) == \"46772...86472e4\"\n assert candidate(left = 7000,right = 7020) == \"57553...63648e7\"\n assert candidate(left = 100,right = 200) == \"84505...02048e27\"\n assert candidate(left = 1234,right = 1250) == \"39811...24736e7\"\n assert candidate(left = 4000,right = 4100) == \"22481...83456e27\"\n assert candidate(left = 1000,right = 1050) == \"35045...20832e15\"\n assert candidate(left = 4995,right = 5000) == \"15578...18494e5\"\n assert candidate(left = 9500,right = 10000) == \"29333...52864e128\"\n assert candidate(left = 2000,right = 3000) == \"25024...18624e252\"\n assert candidate(left = 6000,right = 6100) == \"90528...09184e27\"\n assert candidate(left = 100,right = 2000) == \"35534...18272e477\"\n assert candidate(left = 7000,right = 7050) == \"15097...01664e15\"\n assert candidate(left = 5500,right = 5510) == \"14071...33184e5\"\n assert candidate(left = 9999,right = 10000) == \"9999e4\"\n assert candidate(left = 8000,right = 8010) == \"86491...39904e5\"\n assert candidate(left = 5,right = 50) == \"12672...06688e12\"\n assert candidate(left = 5000,right = 6000) == \"31736...43584e253\"\n assert candidate(left = 8000,right = 8020) == \"94684...81312e7\"\n assert candidate(left = 8000,right = 9000) == \"12498...67872e253\"\n assert candidate(left = 6500,right = 6530) == \"17034...07232e10\"\n assert candidate(left = 3000,right = 3010) == \"18042...06464e5\"\n assert candidate(left = 1000,right = 9999) == \"70734...94464e2249\"\n assert candidate(left = 5000,right = 5015) == \"15629...41184e7\"\n assert candidate(left = 3000,right = 3025) == \"28318...52192e9\"\n assert candidate(left = 1234,right = 5678) == \"11390...64288e1112\"\n assert candidate(left = 1000,right = 2000) == \"82415...74464e253\"\n assert candidate(left = 9000,right = 9999) == \"31626...93632e250\"\n assert candidate(left = 4321,right = 4325) == \"15098...31038e2\"\n assert candidate(left = 8765,right = 8780) == \"12301...69504e5\"\n assert candidate(left = 9990,right = 10000) == \"99451...72288e6\"\n assert candidate(left = 2000,right = 2010) == \"21050...98176e5\"\n assert candidate(left = 9990,right = 9999) == \"99451...72288e2\"\n assert candidate(left = 5000,right = 5050) == \"57259...77056e16\"\n assert candidate(left = 2500,right = 2600) == \"11420...49216e28\"\n assert candidate(left = 2500,right = 2510) == \"24371...13072e6\"\n assert candidate(left = 3000,right = 4000) == \"13222...08128e254\"\n assert candidate(left = 1000,right = 10000) == \"70734...94464e2253\"\n assert candidate(left = 7500,right = 7510) == \"42545...13216e6\"\n assert candidate(left = 9000,right = 9010) == \"31573...64992e5\"\n", "comparison": "exact"}, "public_tests": ["1\n4", "2\n11", "371\n375"], "hints": ["Calculating the number of trailing zeros, the last five digits, and the first five digits can all be done separately.", "Use a prime factorization property to find the number of trailing zeros. Use modulo to find the last 5 digits. Use a logarithm property to find the first 5 digits.", "The number of trailing zeros C is nothing but the number of times the product is completely divisible by 10. Since 2 and 5 are the only prime factors of 10, C will be equal to the minimum number of times 2 or 5 appear in the prime factorization of the product.", "Iterate through the integers from left to right. For every integer, keep dividing it by 2 as long as it is divisible by 2 and C occurrences of 2 haven't been removed in total. Repeat this process for 5. Finally, multiply the integer under modulo of 10^5 with the product obtained till now to obtain the last five digits.", "The product P can be represented as P=10^(x+y) where x is the integral part and y is the fractional part of x+y. Using the property \"if S = A * B, then log(S) = log(A) + log(B)\", we can write x+y = log_10(P) = sum(log_10(i)) for each integer i in [left, right]. Once we obtain the sum, the first five digits can be represented as floor(10^(y+4))."], "metadata": {"canonical_parameter_names": ["left", "right"], "leetcode_dataset_entry_point": "Solution().abbreviateProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:43+00:00", "tests_total": 74, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function abbreviateProduct($left, $right) {", "container": "Solution", "callable": "abbreviateProduct", "parameters": [{"name": "left", "type": "Integer"}, {"name": "right", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2119, "task_id": "a-number-after-a-double-reversal", "difficulty": "Easy", "problem_description": "Reversing an integer means to reverse all its digits.\n\n- For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.\n\nGiven an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.\n\nExample 1:\n\nInput: num = 526\nOutput: true\nExplanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.\n\nExample 2:\n\nInput: num = 1800\nOutput: false\nExplanation: Reverse num to get 81, then reverse 81 to get 18, which does not equal num.\n\nExample 3:\n\nInput: num = 0\nOutput: true\nExplanation: Reverse num to get 0, then reverse 0 to get 0, which equals num.\n\nConstraints:\n\n- 0 <= num <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 1001) == True\n assert candidate(num = 1000000) == False\n assert candidate(num = 999999) == True\n assert candidate(num = 1200) == False\n assert candidate(num = 0) == True\n assert candidate(num = 1800) == False\n assert candidate(num = 526) == True\n assert candidate(num = 100) == False\n assert candidate(num = 123) == True\n assert candidate(num = 10) == False\n assert candidate(num = 10001) == True\n assert candidate(num = 500500) == False\n assert candidate(num = 100001) == True\n assert candidate(num = 1000) == False\n assert candidate(num = 101010) == False\n assert candidate(num = 100000) == False\n assert candidate(num = 123456) == True\n assert candidate(num = 10000) == False\n", "comparison": "exact"}, "public_tests": ["526", "1800", "0"], "hints": ["Other than the number 0 itself, any number that ends with 0 would lose some digits permanently when reversed."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().isSameAfterReversals", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:45+00:00", "tests_total": 66, "tests_dropped": 48, "flags": [], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function isSameAfterReversals($num) {", "container": "Solution", "callable": "isSameAfterReversals", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2120, "task_id": "execution-of-all-suffix-instructions-staying-in-a-grid", "difficulty": "Medium", "problem_description": "There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [start_row, start_col] indicates that a robot is initially at cell (start_row, start_col).\n\nYou are also given a 0-indexed string s of length m where s[i] is the i^th instruction for the robot: 'L' (move left), 'R' (move right), 'U' (move up), and 'D' (move down).\n\nThe robot can begin executing from any i^th instruction in s. It executes the instructions one by one towards the end of s but it stops if either of these conditions is met:\n\n- The next instruction will move the robot off the grid.\n- There are no more instructions left to execute.\n\nReturn an array answer of length m where answer[i] is the number of instructions the robot can execute if the robot begins executing from the i^th instruction in s.\n\nExample 1:\n\nInput: n = 3, startPos = [0,1], s = \"RRDDLU\"\nOutput: [1,5,4,3,1,0]\nExplanation: Starting from startPos and beginning execution from the i^th instruction:\n- 0^th: \"RRDDLU\". Only one instruction \"R\" can be executed before it moves off the grid.\n- 1^st: \"RDDLU\". All five instructions can be executed while it stays in the grid and ends at (1, 1).\n- 2^nd: \"DDLU\". All four instructions can be executed while it stays in the grid and ends at (1, 0).\n- 3^rd: \"DLU\". All three instructions can be executed while it stays in the grid and ends at (0, 0).\n- 4^th: \"LU\". Only one instruction \"L\" can be executed before it moves off the grid.\n- 5^th: \"U\". If moving up, it would move off the grid.\n\nExample 2:\n\nInput: n = 2, startPos = [1,1], s = \"LURD\"\nOutput: [4,1,0,0]\nExplanation:\n- 0^th: \"LURD\".\n- 1^st: \"URD\".\n- 2^nd: \"RD\".\n- 3^rd: \"D\".\n\nExample 3:\n\nInput: n = 1, startPos = [0,0], s = \"LRUD\"\nOutput: [0,0,0,0]\nExplanation: No matter which instruction the robot begins execution from, it would move off the grid.\n\nConstraints:\n\n- m == s.length\n- 1 <= n, m <= 500\n- startPos.length == 2\n- 0 <= start_row, start_col < n\n- s consists of 'L', 'R', 'U', and 'D'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1,startPos = [0, 0],s = \"LRUD\") == [0, 0, 0, 0]\n assert candidate(n = 4,startPos = [2, 2],s = \"DDDD\") == [1, 1, 1, 1]\n assert candidate(n = 5,startPos = [2, 2],s = \"LUDDRL\") == [6, 5, 4, 3, 2, 1]\n assert candidate(n = 4,startPos = [0, 3],s = \"RRRR\") == [0, 0, 0, 0]\n assert candidate(n = 3,startPos = [2, 0],s = \"RRU\") == [3, 2, 1]\n assert candidate(n = 4,startPos = [1, 2],s = \"LURDLU\") == [6, 5, 4, 3, 2, 1]\n assert candidate(n = 4,startPos = [2, 2],s = \"UUDDLLRR\") == [8, 7, 1, 5, 4, 3, 1, 1]\n assert candidate(n = 3,startPos = [0, 1],s = \"RRDDLU\") == [1, 5, 4, 3, 1, 0]\n assert candidate(n = 4,startPos = [3, 0],s = \"DDDD\") == [0, 0, 0, 0]\n assert candidate(n = 5,startPos = [0, 0],s = \"DRDLUR\") == [6, 5, 1, 0, 0, 1]\n assert candidate(n = 2,startPos = [1, 1],s = \"LURD\") == [4, 1, 0, 0]\n assert candidate(n = 5,startPos = [3, 3],s = \"DDDDRRRRUUUULLLL\") == [1, 1, 1, 2, 1, 1, 1, 4, 3, 6, 5, 4, 3, 3, 2, 1]\n assert candidate(n = 3,startPos = [0, 2],s = \"LLD\") == [3, 2, 1]\n assert candidate(n = 4,startPos = [2, 2],s = \"UDLRUDLR\") == [8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 5,startPos = [0, 0],s = \"RRRRUUUUDDDDLLLL\") == [4, 3, 2, 1, 0, 0, 0, 0, 4, 3, 2, 1, 0, 0, 0, 0]\n assert candidate(n = 5,startPos = [3, 3],s = \"RRRDDDDLLLLUUUU\") == [1, 1, 2, 1, 1, 1, 4, 3, 6, 5, 4, 3, 3, 2, 1]\n assert candidate(n = 7,startPos = [3, 3],s = \"LDRURLDRU\") == [9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 15,startPos = [14, 0],s = \"LLLLDDDDDDDDDDDDUUUUUUUUUUUUUUUU\") == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 14, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 6,startPos = [2, 2],s = \"UDLRUDLR\") == [8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [1, 6],s = \"RULDDRRULLUUDD\") == [6, 10, 12, 3, 2, 1, 4, 3, 3, 2, 1, 3, 2, 1]\n assert candidate(n = 9,startPos = [8, 0],s = \"DDDDDDDDDDDDDDDDDD\") == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 5,startPos = [0, 4],s = \"LLLLDDRRRRUUUU\") == [12, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 13,startPos = [1, 1],s = \"LRRUDLRLRLUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUD\") == [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(n = 8,startPos = [0, 0],s = \"RRRRDDDDLLLLUUUUDDDDLLLLUUUU\") == [20, 10, 8, 6, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,startPos = [7, 2],s = \"DRLLURDDRLUUDDRR\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 7,startPos = [3, 3],s = \"LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR\") == [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(n = 5,startPos = [4, 4],s = \"LULULULULULULULULULU\") == [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 6,startPos = [0, 5],s = \"LLLLDDRRUUDDLLRRUUDDLLRRUUDD\") == [28, 27, 26, 4, 2, 1, 0, 0, 0, 0, 18, 6, 4, 2, 0, 0, 0, 0, 10, 6, 4, 2, 0, 0, 0, 0, 2, 1]\n assert candidate(n = 10,startPos = [5, 5],s = \"LRUDLRUDLRUD\") == [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [7, 0],s = \"RRRRDDDDLLLLUUUU\") == [4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2, 1]\n assert candidate(n = 6,startPos = [2, 3],s = \"LRRUDLRLRLUDUDUDUD\") == [18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 11,startPos = [3, 3],s = \"LRRLDDUUDDUUDDRRLLRRRRUUUUDDDDLLLL\") == [34, 33, 32, 31, 30, 29, 19, 27, 26, 25, 15, 23, 22, 21, 11, 10, 9, 8, 7, 6, 5, 4, 3, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1]\n assert candidate(n = 400,startPos = [0, 0],s = \"RRRRUUUUDDDDLLLL\") == [4, 3, 2, 1, 0, 0, 0, 0, 4, 3, 2, 1, 0, 0, 0, 0]\n assert candidate(n = 7,startPos = [0, 6],s = \"LLLLLLLLLLLLLLLLLLL\") == [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 6,startPos = [3, 3],s = \"LURDLURDLURDLURD\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 7,startPos = [0, 6],s = \"LLLLLLLLRRRRRRRRUUUUUUUDDDDDDD\") == [6, 6, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 7,startPos = [3, 3],s = \"LLLLDDDDRRRRUUUU\") == [3, 6, 5, 4, 3, 6, 5, 4, 3, 6, 5, 4, 3, 3, 2, 1]\n assert candidate(n = 9,startPos = [4, 4],s = \"LURDLURDLURDLURD\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 5,startPos = [2, 2],s = \"LRLRLRLRLRLRLRLR\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 300,startPos = [299, 299],s = \"DDDDRRRRUUUULLLL\") == [0, 0, 0, 0, 0, 0, 0, 0, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 12,startPos = [5, 5],s = \"UDLRUDLRUDLRUDLRUDLR\") == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 10,startPos = [5, 2],s = \"DDUUDDUUDDUUDDUUDDUUDDUUDDUUDDUU\") == [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(n = 6,startPos = [5, 0],s = \"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1]\n assert candidate(n = 15,startPos = [14, 14],s = \"LLLLLLLLLLLLLLL\") == [14, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 9,startPos = [4, 4],s = \"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [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, 3, 2, 1]\n assert candidate(n = 6,startPos = [0, 5],s = \"DDDDDDRRRRRDDDRRLUUL\") == [5, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 3, 2, 1, 0, 0, 1, 0, 0, 1]\n assert candidate(n = 8,startPos = [7, 0],s = \"RRRRRRRRUUUUUUUUDDDDDDDDLLLLLLLL\") == [7, 14, 13, 12, 11, 10, 9, 8, 7, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 5,startPos = [0, 4],s = \"LLLLDDDDRRRRUUUU\") == [16, 10, 8, 6, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 5,startPos = [0, 4],s = \"RRRRRRRRRRRRRRRRRRRR\") == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 9,startPos = [1, 1],s = \"DRDLDRDLDRDLDRDLDRDLDRDLDRDLDRDL\") == [14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 7,startPos = [3, 3],s = \"LUDDRRUULLDD\") == [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 5,startPos = [0, 0],s = \"RLRLRLRLRLRLRLRLRLRL\") == [20, 0, 18, 0, 16, 0, 14, 0, 12, 0, 10, 0, 8, 0, 6, 0, 4, 0, 2, 0]\n assert candidate(n = 10,startPos = [5, 5],s = \"LLLLUUUUDDDDRRRRLLLLUUUUDDDDRRRR\") == [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(n = 5,startPos = [2, 2],s = \"DDRRUULLUU\") == [10, 8, 6, 5, 4, 4, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [1, 1],s = \"DDDDUUUUDDDDUUUUDDDDUUUUDDDDUUUUDDDDUUUU\") == [40, 39, 5, 3, 1, 1, 1, 33, 32, 31, 5, 3, 1, 1, 1, 25, 24, 23, 5, 3, 1, 1, 1, 17, 16, 15, 5, 3, 1, 1, 1, 9, 8, 7, 5, 3, 1, 1, 1, 1]\n assert candidate(n = 6,startPos = [4, 5],s = \"RRRDDDDLUUUULLLRRUUDD\") == [0, 0, 0, 1, 1, 1, 12, 10, 9, 9, 11, 10, 9, 8, 2, 0, 0, 4, 3, 1, 1]\n assert candidate(n = 12,startPos = [6, 6],s = \"RRDDLLUUDDRRLLUUDDRRLLUUDDRRLLUUDDRRLLUUDD\") == [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(n = 11,startPos = [5, 5],s = \"DDDDDDDDDDDDLLLLLLLLLLLLUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [5, 5, 5, 5, 5, 5, 5, 10, 9, 8, 7, 6, 5, 5, 5, 5, 5, 5, 5, 10, 9, 8, 7, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1]\n assert candidate(n = 20,startPos = [19, 0],s = \"RRRRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == [19, 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]\n assert candidate(n = 8,startPos = [4, 4],s = \"UDLRUDLRUDLRUDLR\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 4,startPos = [2, 3],s = \"LLLDDDLLLLUUUUDDDD\") == [4, 3, 2, 1, 1, 4, 3, 5, 4, 3, 2, 2, 5, 3, 1, 1, 1, 1]\n assert candidate(n = 5,startPos = [4, 0],s = \"DDDDDDDDDDDDDDDDDDDD\") == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 10,startPos = [5, 5],s = \"UUUUDDDDLLLLRRRR\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [7, 7],s = \"LLLLUUUUDDDDRRRRLLLLUUUUDDDD\") == [28, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 12, 11, 10, 9, 8, 6, 4, 2, 0, 0, 0, 0]\n assert candidate(n = 6,startPos = [4, 1],s = \"LDDRRULUDR\") == [2, 1, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 7,startPos = [6, 6],s = \"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [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, 5, 4, 3, 2, 1]\n assert candidate(n = 5,startPos = [2, 2],s = \"LUDDRRUUDDLL\") == [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 4,startPos = [2, 0],s = \"RRRDDDLLLLUUUUDDDD\") == [4, 3, 2, 1, 1, 1, 0, 0, 0, 0, 2, 2, 5, 3, 1, 1, 1, 1]\n assert candidate(n = 5,startPos = [2, 2],s = \"RRDDLLUUURRDDDLLUUU\") == [19, 18, 17, 16, 4, 3, 2, 12, 11, 4, 3, 2, 7, 6, 4, 3, 2, 2, 1]\n assert candidate(n = 10,startPos = [0, 0],s = \"RRRDDDLLLUUUDDDRRRLUUDLLUURDDLL\") == [30, 7, 5, 3, 2, 1, 0, 0, 0, 0, 0, 0, 18, 12, 6, 4, 3, 2, 0, 0, 0, 1, 0, 0, 0, 0, 4, 2, 1, 0, 0]\n assert candidate(n = 3,startPos = [1, 1],s = \"RLLDDRRUUULLDD\") == [4, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 1]\n assert candidate(n = 9,startPos = [4, 4],s = \"DDDDDDDDUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [4, 4, 4, 4, 12, 10, 8, 6, 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, 3, 2, 1]\n assert candidate(n = 6,startPos = [2, 2],s = \"LRLRLRLRLRLRLR\") == [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [0, 7],s = \"RRRRRRRRUUUUUUUUDDDDDDDDLDDDDDDD\") == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 9,startPos = [8, 0],s = \"RRRRRRRRDDDDDDDDDLLLLLLLLLLLLUUUUUUUUUUUUUUUU\") == [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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 12,startPos = [0, 11],s = \"LLLLLLLLLLLL\") == [11, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 9,startPos = [5, 4],s = \"UUDDLLRRUUDDLLRR\") == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 10,startPos = [5, 5],s = \"UUUUDDDDLLLLRRRRUUUUDDDDLLLLRRRR\") == [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(n = 20,startPos = [10, 10],s = \"LDRURLDRURLDRURLDRU\") == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 15,startPos = [7, 7],s = \"RRRRUUUULLLLDDDDRRRRUUUULLLLDDDD\") == [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(n = 7,startPos = [3, 3],s = \"UUUUDDDDLLLLRRRRUUDDLL\") == [3, 10, 9, 8, 3, 6, 5, 4, 3, 13, 12, 11, 3, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(n = 9,startPos = [0, 8],s = \"LLLLLLLLUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\") == [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, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(n = 7,startPos = [1, 1],s = \"DDRRLLUUDDRRLLUUDDRRLLUU\") == [24, 23, 5, 4, 1, 2, 1, 17, 16, 15, 5, 4, 1, 2, 1, 9, 8, 7, 5, 4, 1, 2, 1, 1]\n assert candidate(n = 10,startPos = [2, 5],s = \"RRLLRRLLRRLLRRLLRRLLRRLLRRLLRRLL\") == [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(n = 10,startPos = [5, 5],s = \"UUUUUUUUUUDDDDDDDDDDLLLLLLLLLLRRRRRRRRRR\") == [5, 5, 5, 5, 5, 14, 12, 10, 8, 6, 4, 4, 4, 4, 4, 4, 9, 8, 7, 6, 5, 5, 5, 5, 5, 14, 12, 10, 8, 6, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1]\n assert candidate(n = 10,startPos = [9, 0],s = \"RRRRRRRRRRUUUUUUUUUUDDDDDDDDDDDLLLLLLLLLL\") == [9, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 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]\n assert candidate(n = 12,startPos = [6, 6],s = \"UUUUUUUUUUUUDDDDDDDDDDDDLLLLLLLLLLLLRRRRRRRRRRRR\") == [6, 6, 6, 6, 6, 6, 17, 15, 13, 11, 9, 7, 5, 5, 5, 5, 5, 5, 5, 11, 10, 9, 8, 7, 6, 6, 6, 6, 6, 6, 17, 15, 13, 11, 9, 7, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1]\n assert candidate(n = 8,startPos = [3, 4],s = \"RRDLULLLUUDDDDRRRRLU\") == [20, 19, 18, 17, 16, 15, 14, 13, 9, 8, 7, 6, 5, 4, 3, 5, 4, 3, 2, 1]\n assert candidate(n = 10,startPos = [5, 5],s = \"LURDLURDLURDLURDLURDLURD\") == [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", "comparison": "exact"}, "public_tests": ["3\n[0,1]\n\"RRDDLU\"", "2\n[1,1]\n\"LURD\"", "1\n[0,0]\n\"LRUD\""], "hints": ["The constraints are not very large. Can we simulate the execution by starting from each index of s?", "Before any of the stopping conditions is met, stop the simulation for that index and set the answer for that index."], "metadata": {"canonical_parameter_names": ["n", "startPos", "s"], "leetcode_dataset_entry_point": "Solution().executeInstructions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:48+00:00", "tests_total": 89, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function executeInstructions($n, $startPos, $s) {", "container": "Solution", "callable": "executeInstructions", "parameters": [{"name": "n", "type": "Integer"}, {"name": "startPos", "type": "Integer[]"}, {"name": "s", "type": "String"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2121, "task_id": "intervals-between-identical-elements", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of n integers arr.\n\nThe interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.\n\nReturn an array intervals of length n where intervals[i] is the sum of intervals between arr[i] and each element in arr with the same value as arr[i].\n\nNote: |x| is the absolute value of x.\n\nExample 1:\n\nInput: arr = [2,1,3,1,2,3,3]\nOutput: [4,2,7,2,4,4,5]\nExplanation:\n- Index 0: Another 2 is found at index 4. |0 - 4| = 4\n- Index 1: Another 1 is found at index 3. |1 - 3| = 2\n- Index 2: Two more 3s are found at indices 5 and 6. |2 - 5| + |2 - 6| = 7\n- Index 3: Another 1 is found at index 1. |3 - 1| = 2\n- Index 4: Another 2 is found at index 0. |4 - 0| = 4\n- Index 5: Two more 3s are found at indices 2 and 6. |5 - 2| + |5 - 6| = 4\n- Index 6: Two more 3s are found at indices 2 and 5. |6 - 2| + |6 - 5| = 5\n\nExample 2:\n\nInput: arr = [10,5,10,10]\nOutput: [5,0,3,4]\nExplanation:\n- Index 0: Two more 10s are found at indices 2 and 3. |0 - 2| + |0 - 3| = 5\n- Index 1: There is only one 5 in the array, so its sum of intervals to identical elements is 0.\n- Index 2: Two more 10s are found at indices 0 and 3. |2 - 0| + |2 - 3| = 3\n- Index 3: Two more 10s are found at indices 0 and 2. |3 - 0| + |3 - 2| = 4\n\nConstraints:\n\n- n == arr.length\n- 1 <= n <= 10^5\n- 1 <= arr[i] <= 10^5\n\nNote: This question is the same as 2615: Sum of Distances.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arr = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == [20, 0, 14, 0, 12, 0, 14, 0, 20, 0]\n assert candidate(arr = [5, 4, 3, 2, 1]) == [0, 0, 0, 0, 0]\n assert candidate(arr = [1, 3, 2, 3, 1, 4, 2, 3, 1, 4, 2]) == [12, 8, 12, 6, 8, 4, 8, 10, 12, 4, 12]\n assert candidate(arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(arr = [1, 2, 3, 4, 5]) == [0, 0, 0, 0, 0]\n assert candidate(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(arr = [10, 5, 10, 10]) == [5, 0, 3, 4]\n assert candidate(arr = [5, 5, 5, 5, 5]) == [10, 7, 6, 7, 10]\n assert candidate(arr = [1, 1, 1, 1, 1]) == [10, 7, 6, 7, 10]\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4]) == [1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(arr = [2, 1, 3, 1, 2, 3, 3]) == [4, 2, 7, 2, 4, 4, 5]\n assert candidate(arr = [1, 2, 2, 1, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == [3, 1, 1, 3, 3, 2, 3, 6, 4, 4, 6, 10, 7, 6, 7, 10, 15, 11, 9, 9, 11, 15]\n assert candidate(arr = [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(arr = [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(arr = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == [38, 34, 30, 26, 22, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 26, 30, 34, 38]\n assert candidate(arr = [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(arr = [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(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(arr = [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(arr = [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(arr = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(arr = [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]) == [1, 1, 1, 1, 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(arr = [5, 3, 2, 5, 3, 5, 2, 5, 2, 5, 2, 3]) == [24, 13, 18, 15, 10, 13, 10, 15, 10, 21, 14, 17]\n assert candidate(arr = [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(arr = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15]\n assert candidate(arr = [100000, 50000, 100000, 25000, 100000, 12500, 100000, 6250, 100000, 3125]) == [20, 0, 14, 0, 12, 0, 14, 0, 20, 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, 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(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [45, 37, 31, 27, 25, 25, 27, 31, 37, 45]\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 48, 43, 40, 39, 40, 43, 48, 55, 64]\n assert candidate(arr = [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(arr = [100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996, 99996, 99995, 99995]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [861, 821, 783, 747, 713, 681, 651, 623, 597, 573, 551, 531, 513, 497, 483, 471, 461, 453, 447, 443, 441, 441, 443, 447, 453, 461, 471, 483, 497, 513, 531, 551, 573, 597, 623, 651, 681, 713, 747, 783, 821, 861]\n assert candidate(arr = [5, 3, 2, 3, 5, 3, 2, 5, 2, 2, 5, 2, 3]) == [21, 17, 26, 13, 13, 13, 14, 13, 12, 13, 19, 19, 27]\n assert candidate(arr = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(arr = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 1]) == [21, 3, 19, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 36]\n assert candidate(arr = [5, 2, 5, 5, 3, 2, 5, 3, 5]) == [19, 4, 13, 12, 3, 4, 15, 3, 21]\n assert candidate(arr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(arr = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99999]) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]\n assert candidate(arr = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == [20, 20, 14, 14, 12, 12, 14, 14, 20, 20]\n assert candidate(arr = [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, 4, 4, 5, 5, 5]) == [51, 47, 45, 51, 47, 45, 51, 47, 45, 51, 47, 45, 51, 47, 45, 45, 47, 51, 45, 47, 51, 45, 47, 51, 45, 47, 51, 45, 47, 51]\n assert candidate(arr = [1, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2]) == [57, 63, 47, 45, 48, 38, 33, 39, 35, 27, 36, 38, 27, 39, 47, 33, 48, 62, 45, 63]\n assert candidate(arr = [10, 20, 30, 40, 50, 40, 30, 20, 10, 20, 30, 40, 50, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50]) == [43, 47, 43, 39, 35, 33, 31, 29, 27, 27, 27, 27, 19, 19, 30, 32, 34, 27, 29, 43, 47, 51, 37]\n assert candidate(arr = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == [69, 57, 45, 47, 49, 33, 38, 40, 27, 35, 37, 27, 38, 40, 33, 47, 49, 45, 62, 64]\n assert candidate(arr = [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, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [48, 65, 63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 39, 51, 53, 55, 57, 59, 61, 63, 65, 67]\n assert candidate(arr = [100000, 99999, 100000, 99998, 100000, 99997, 100000, 99996, 100000, 99995]) == [20, 0, 14, 0, 12, 0, 14, 0, 20, 0]\n assert candidate(arr = [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(arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(arr = [7, 4, 7, 2, 7, 4, 2, 7, 4, 2, 7]) == [23, 11, 17, 9, 15, 7, 6, 18, 10, 9, 27]\n assert candidate(arr = [7, 3, 7, 3, 7, 3, 7, 3, 7, 3]) == [20, 20, 14, 14, 12, 12, 14, 14, 20, 20]\n assert candidate(arr = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]) == [30, 40, 24, 28, 31, 21, 16, 20, 27, 25, 6, 11, 20, 32, 40, 0, 6, 17, 32, 50]\n assert candidate(arr = [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(arr = [50000, 1, 50000, 2, 50000, 3, 50000, 4, 50000, 5, 50000, 6, 50000, 7, 50000, 8, 50000, 9, 50000, 10]) == [90, 0, 74, 0, 62, 0, 54, 0, 50, 0, 50, 0, 54, 0, 62, 0, 74, 0, 90, 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, 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(arr = [5, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == [6, 13, 5, 5, 5, 9, 6, 5, 5, 5, 14]\n assert candidate(arr = [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(arr = [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]) == [0, 1, 1, 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(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [22, 20, 22, 20, 22, 20, 22, 20, 22, 20, 20, 22, 20, 22, 20, 22, 20, 22, 20, 22]\n assert candidate(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(arr = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [300, 277, 256, 237, 220, 205, 192, 181, 172, 165, 160, 157, 156, 157, 160, 165, 172, 181, 192, 205, 220, 237, 256, 277, 300]\n assert candidate(arr = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [36, 34, 28, 26, 20, 18, 12, 10, 3, 2, 3, 10, 12, 18, 20, 26, 28, 34, 36]\n assert candidate(arr = [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]) == [42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42, 40, 42]\n assert candidate(arr = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [26, 24, 24, 22, 22, 20, 20, 18, 18, 16, 24, 22, 20, 18, 16, 34, 32, 30, 28, 26]\n assert candidate(arr = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == [25, 29, 25, 21, 17, 17, 17, 17, 17, 17, 17, 17, 9, 10, 23, 27, 31, 26]\n assert candidate(arr = [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(arr = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [190, 172, 156, 142, 130, 120, 112, 106, 102, 100, 100, 102, 106, 112, 120, 130, 142, 156, 172, 190]\n assert candidate(arr = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(arr = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == [105, 92, 81, 72, 65, 60, 57, 56, 57, 60, 65, 72, 81, 92, 105]\n assert candidate(arr = [5, 3, 5, 2, 3, 3, 5, 3, 2, 2, 5]) == [18, 13, 14, 11, 7, 7, 14, 11, 6, 7, 22]\n assert candidate(arr = [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(arr = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(arr = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == [20, 20, 14, 14, 12, 12, 14, 14, 20, 20]\n assert candidate(arr = [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(arr = [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(arr = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(arr = [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(arr = [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]) == [50, 50, 50, 50, 50, 35, 35, 35, 35, 35, 30, 30, 30, 30, 30, 35, 35, 35, 35, 35, 50, 50, 50, 50, 50]\n assert candidate(arr = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [46, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 30, 32, 34, 36, 38, 40, 42, 44, 28, 38, 50, 52, 54, 56, 58, 60, 62, 64, 38]\n assert candidate(arr = [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(arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == [37, 16, 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16, 19, 20]\n assert candidate(arr = [7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7]) == [154, 0, 130, 0, 110, 0, 94, 0, 82, 0, 74, 0, 70, 70, 72, 76, 82, 90, 100, 112]\n assert candidate(arr = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(arr = [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(arr = [7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3]) == [90, 90, 74, 74, 62, 62, 54, 54, 50, 50, 50, 50, 54, 54, 62, 62, 74, 74, 90, 90]\n assert candidate(arr = [9, 7, 5, 3, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1]) == [39, 33, 27, 21, 30, 17, 19, 21, 23, 20, 17, 19, 21, 23, 20, 27, 29, 31, 33, 30]\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]) == [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(arr = [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, 1, 1, 1, 1, 1, 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", "comparison": "exact"}, "public_tests": ["[2,1,3,1,2,3,3]", "[10,5,10,10]"], "hints": ["For each unique value found in the array, store a sorted list of indices of elements that have this value in the array.", "One way of doing this is to use a HashMap that maps the values to their list of indices. Update this mapping as you iterate through the array.", "Process each list of indices separately and get the sum of intervals for the elements of that value by utilizing prefix sums.", "For each element, keep track of the sum of indices of the identical elements that have come before and that will come after respectively. Use this to calculate the sum of intervals for that element to the rest of the elements with identical values."], "metadata": {"canonical_parameter_names": ["arr"], "leetcode_dataset_entry_point": "Solution().getDistances", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:50+00:00", "tests_total": 89, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function getDistances($arr) {", "container": "Solution", "callable": "getDistances", "parameters": [{"name": "arr", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2122, "task_id": "recover-the-original-array", "difficulty": "Hard", "problem_description": "Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:\n\n1. lower[i] = arr[i] - k, for every index i where 0 <= i < n\n2. higher[i] = arr[i] + k, for every index i where 0 <= i < n\n\nUnfortunately, Alice lost all three arrays. However, she remembers the integers that were present in the arrays lower and higher, but not the array each integer belonged to. Help Alice and recover the original array.\n\nGiven an array nums consisting of 2n integers, where exactly n of the integers were present in lower and the remaining in higher, return the original array arr. In case the answer is not unique, return any valid array.\n\nNote: The test cases are generated such that there exists at least one valid array arr.\n\nExample 1:\n\nInput: nums = [2,10,6,4,8,12]\nOutput: [3,7,11]\nExplanation:\nIf arr = [3,7,11] and k = 1, we get lower = [2,6,10] and higher = [4,8,12].\nCombining lower and higher gives us [2,6,10,4,8,12], which is a permutation of nums.\nAnother valid possibility is that arr = [5,7,9] and k = 3. In that case, lower = [2,4,6] and higher = [8,10,12].\n\nExample 2:\n\nInput: nums = [1,1,3,3]\nOutput: [2,2]\nExplanation:\nIf arr = [2,2] and k = 1, we get lower = [1,1] and higher = [3,3].\nCombining lower and higher gives us [1,1,3,3], which is equal to nums.\nNote that arr cannot be [1,3] because in that case, the only possible way to obtain [1,1,3,3] is with k = 0.\nThis is invalid since k must be positive.\n\nExample 3:\n\nInput: nums = [5,435]\nOutput: [220]\nExplanation:\nThe only possible combination is arr = [220] and k = 215. Using them, we get lower = [5] and higher = [435].\n\nConstraints:\n\n- 2 * n == nums.length\n- 1 <= n <= 1000\n- 1 <= nums[i] <= 10^9\n- The test cases are generated such that there exists at least one valid array arr.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 1, 5, 7, 9, 11]) == [2, 6, 10]\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == [15, 35, 55]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == [2, 3, 6, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == []\n assert candidate(nums = [2, 10, 6, 4, 8, 12]) == [3, 7, 11]\n assert candidate(nums = [1, 3, 5, 7]) == [2, 6]\n assert candidate(nums = [7, 9, 11, 13, 15, 17]) == [8, 12, 16]\n assert candidate(nums = [100, 200, 300, 400, 500, 600]) == [150, 350, 550]\n assert candidate(nums = [9, 11, 13, 15, 17, 19]) == [10, 14, 18]\n assert candidate(nums = [5, 435]) == [220]\n assert candidate(nums = [1, 1, 3, 3]) == [2, 2]\n assert candidate(nums = [1000000000, 1]) == []\n assert candidate(nums = [2, 2, 2, 2]) == []\n assert candidate(nums = [3, 9, 3, 9, 5, 7]) == []\n assert candidate(nums = [3, 3, 3, 9, 9, 9]) == [6, 6, 6]\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]) == [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]\n assert candidate(nums = [10, 22, 30, 42, 50, 62, 70, 82, 90, 102, 110, 122]) == [16, 36, 56, 76, 96, 116]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == [2, 6, 10, 14, 18, 22, 26, 30]\n assert candidate(nums = [10, 100, 20, 110, 30, 120, 40, 130, 50, 140, 60, 150, 70, 160, 80, 170]) == [15, 35, 55, 75, 105, 125, 145, 165]\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, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16]) == [2, 3, 6, 7, 10, 11, 14, 15, 18, 19]\n assert candidate(nums = [2, 4, 8, 10, 16, 18, 24, 26, 32, 34, 40, 42, 48, 50, 56, 58, 64, 66, 72, 74, 80, 82, 88, 90, 96, 98, 104, 106, 112, 114, 120, 122, 128, 130, 136, 138, 144, 146, 152, 154, 160, 162, 168, 170, 176, 178, 184, 186, 192, 194, 200]) == [3, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145, 153, 161, 169, 177, 185, 193]\n assert candidate(nums = [1, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 17, 17, 19]) == []\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == [2, 6, 10, 14, 18, 22, 26, 30]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16]) == [3, 7, 11, 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]) == []\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == [150, 350, 550, 750, 950, 1150, 1350, 1550, 1750, 1950]\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]) == []\n assert candidate(nums = [5, 9, 13, 17, 21, 25, 29, 33]) == [7, 15, 23, 31]\n assert candidate(nums = [10, 20, 15, 25, 30, 40, 35, 45, 50, 60, 55, 65, 70, 80, 75, 85]) == [15, 20, 35, 40, 55, 60, 75, 80]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == [3, 11, 19, 27, 35]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [2, 3, 6, 7, 10, 11, 14, 15]\n assert candidate(nums = [7, 21, 14, 28, 21, 42, 28, 56, 35, 70, 42, 84, 49, 98, 56, 112]) == []\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995]) == [499999998, 499999999, 500000000, 500000001, 500000002, 500000003]\n assert candidate(nums = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == [11, 15, 19, 23, 27, 31, 35, 39]\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997]) == [2, 3, 999999998, 999999999]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80]) == [15, 35, 55, 75]\n assert candidate(nums = [5, 5, 5, 5, 9, 9, 9, 9]) == [7, 7, 7, 7]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]) == [6, 6, 6, 6, 6, 6, 6, 6, 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]) == []\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10]) == []\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39]) == [5, 13, 21, 29, 37]\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, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46]\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69]) == [6, 18, 30, 42, 54, 66]\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45]) == [6, 18, 30, 42]\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]) == []\n assert candidate(nums = [5, 5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15]) == []\n assert candidate(nums = [10, 22, 34, 46, 58, 70, 82, 94, 106, 118, 130, 142, 154, 166, 178]) == [16, 40, 64, 88, 112, 136, 160]\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]) == [2, 3, 3, 4, 6, 7, 7, 8, 10, 11, 11]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == [150, 350, 550, 750, 950, 1150]\n assert candidate(nums = [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]) == [2, 6, 10, 14, 18, 22, 26]\n assert candidate(nums = [2, 6, 10, 4, 8, 12, 16, 20]) == []\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14]) == []\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53]) == [3, 11, 19, 27, 35, 43, 51]\n assert candidate(nums = [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49]) == [7, 15, 23, 31, 39, 47]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) == []\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]) == []\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == [3, 7, 11, 15, 19, 23, 27, 31]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115]) == [10, 30, 50, 70, 90, 110]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == [150, 350, 550, 750, 950, 1150, 1350, 1550]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == [3, 7, 11, 15, 19, 23, 27, 31, 35, 39]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [10, 30, 50, 70, 90]\n assert candidate(nums = [10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86]) == [12, 20, 28, 36, 44, 52, 60, 68, 76, 84]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 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]) == [2, 3, 6, 7, 10, 11, 14, 15, 18, 19]\n assert candidate(nums = [1, 1, 1, 1, 3, 3, 3, 3]) == [2, 2, 2, 2]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == [3, 7, 11, 15, 19, 23, 27, 31]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == [3, 7, 11, 15, 19, 23]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == [6, 9, 18, 21, 30, 33, 42, 45, 54, 57]\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]) == []\n assert candidate(nums = [1, 2, 5, 6, 9, 10, 13, 14, 17, 18]) == []\n assert candidate(nums = [1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105]) == [5, 21, 37, 53, 69, 85, 101]\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]) == [10, 15, 30, 35, 50, 55, 70, 75, 90, 95, 110, 115, 130, 135, 150, 155, 170, 175, 190, 195]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [2, 6, 10, 14, 18]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [15, 35, 55, 75, 95]\n assert candidate(nums = [2, 14, 8, 6, 10, 18, 12, 4]) == []\n assert candidate(nums = [100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175]) == [105, 110, 125, 130, 145, 150, 165, 170]\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]) == [15, 35, 55, 75, 95, 115, 135, 155, 175, 195, 215, 235]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == [15, 35, 55, 75, 95, 115, 135, 155]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [3, 7, 11, 15, 19]\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105]) == [15, 20, 35, 40, 55, 60, 75, 80, 95, 100]\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == [3, 11, 19, 27, 35]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [15, 35, 55, 75, 95, 115, 135]\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165]) == [20, 40, 60, 80, 100, 120, 140, 160]\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, 3, 6, 7, 10, 11, 14, 15, 18, 19]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == [15, 35, 55, 75, 95, 115]\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47]) == [5, 13, 21, 29, 37, 45]\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]) == [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 assert candidate(nums = [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65]) == [7, 15, 23, 31, 39, 47, 55, 63]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [10, 15, 30, 35, 50, 55, 70, 75, 90, 95]\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]) == [15, 35, 55, 75, 95, 115, 135, 155, 175, 195, 215, 235]\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, 6, 10, 14, 18, 22, 26, 30, 34, 38]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == [15, 35, 55, 75, 95, 115, 135, 155]\n assert candidate(nums = [1, 1, 1, 1, 5, 5, 5, 5]) == [3, 3, 3, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [15, 35, 55, 75, 95]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [3, 7, 11, 15, 19]\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]) == []\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125]) == [20, 40, 60, 80, 100, 120]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]) == [10, 15, 30, 35, 50, 55, 70, 75]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == [2, 6, 10, 14, 18, 22]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80]) == [15, 35, 55, 75]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [150, 350, 550, 750, 950]\n assert candidate(nums = [100, 101, 200, 201, 300, 301, 400, 401]) == [150, 151, 350, 351]\n", "comparison": "exact"}, "public_tests": ["[2,10,6,4,8,12]", "[1,1,3,3]", "[5,435]"], "hints": ["If we fix the value of k, how can we check if an original array exists for the fixed k?", "The smallest value of nums is obtained by subtracting k from the smallest value of the original array. How can we use this to reduce the search space for finding a valid k?", "You can compute every possible k by using the smallest value of nums (as lower[i]) against every other value in nums (as the corresponding higher[i]).", "For every computed k, greedily pair up the values in nums. This can be done sorting nums, then using a map to store previous values and searching that map for a corresponding lower[i] for the current nums[j] (as higher[i])."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().recoverArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:52+00:00", "tests_total": 111, "tests_dropped": 6, "flags": ["multiple_answers"], "topic_tags": ["array", "hash-table", "two-pointers", "sorting", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function recoverArray($nums) {", "container": "Solution", "callable": "recoverArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2124, "task_id": "check-if-all-as-appears-before-all-bs", "difficulty": "Easy", "problem_description": "Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.\n\nExample 1:\n\nInput: s = \"aaabbb\"\nOutput: true\nExplanation:\nThe 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.\nHence, every 'a' appears before every 'b' and we return true.\n\nExample 2:\n\nInput: s = \"abab\"\nOutput: false\nExplanation:\nThere is an 'a' at index 2 and a 'b' at index 1.\nHence, not every 'a' appears before every 'b' and we return false.\n\nExample 3:\n\nInput: s = \"bbb\"\nOutput: true\nExplanation:\nThere are no 'a's, hence, every 'a' appears before every 'b' and we return true.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s[i] is either 'a' or 'b'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"b\") == True\n assert candidate(s = \"aaaaabbbbb\") == True\n assert candidate(s = \"bbb\") == True\n assert candidate(s = \"ab\") == True\n assert candidate(s = \"aabbaa\") == False\n assert candidate(s = \"ba\") == False\n assert candidate(s = \"bba\") == False\n assert candidate(s = \"aaa\") == True\n assert candidate(s = \"aabbaabb\") == False\n assert candidate(s = \"aaabbb\") == True\n assert candidate(s = \"a\") == True\n assert candidate(s = \"aabbabbb\") == False\n assert candidate(s = \"abab\") == False\n assert candidate(s = \"abbb\") == True\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\") == True\n assert candidate(s = \"abababbabababbab\") == False\n assert candidate(s = \"baaa\") == False\n assert candidate(s = \"bbbbbbbbbb\") == True\n assert candidate(s = \"aabababababbb\") == False\n assert candidate(s = \"bbbbbaaaaaaaaa\") == False\n assert candidate(s = \"ababbab\") == False\n assert candidate(s = \"aaaabbbbbaaabb\") == False\n assert candidate(s = \"baaabbb\") == False\n assert candidate(s = \"bbaaabbb\") == False\n assert candidate(s = \"abbbab\") == False\n assert candidate(s = \"aabbbbbba\") == False\n assert candidate(s = \"aabbbbbaaab\") == False\n assert candidate(s = \"aabaa\") == False\n assert candidate(s = \"aabaaabba\") == False\n assert candidate(s = \"aabbbbabbab\") == False\n assert candidate(s = \"aaaaaaaaaa\") == True\n assert candidate(s = \"babbaabbaabbaabb\") == False\n assert candidate(s = \"baaabaaa\") == False\n assert candidate(s = \"bbbbbbbaaaaaa\") == False\n assert candidate(s = \"aaaababbbb\") == False\n assert candidate(s = \"aabbbbaaa\") == False\n assert candidate(s = \"aaaa\") == True\n assert candidate(s = \"bbbbbbbbbaaaaaaaaa\") == False\n assert candidate(s = \"bbbbbaaaa\") == False\n assert candidate(s = \"aabbaabbabba\") == False\n assert candidate(s = \"aaaaaaaaa\") == True\n assert candidate(s = \"aaabbaabbb\") == False\n assert candidate(s = \"bbbbbaaaaa\") == False\n assert candidate(s = \"aaabba\") == False\n assert candidate(s = \"bbbbaaab\") == False\n assert candidate(s = \"aabbabb\") == False\n assert candidate(s = \"bbab\") == False\n assert candidate(s = \"baaaab\") == False\n assert candidate(s = \"bbbbabaa\") == False\n assert candidate(s = \"aabbbbba\") == False\n assert candidate(s = \"baaabbbb\") == False\n assert candidate(s = \"bbbaaa\") == False\n assert candidate(s = \"abbbbaaaaa\") == False\n assert candidate(s = \"aaaaaabbbbbb\") == True\n assert candidate(s = \"aaabbbaa\") == False\n assert candidate(s = \"bbbbba\") == False\n assert candidate(s = \"aaaabbbbaaaa\") == False\n assert candidate(s = \"bab\") == False\n assert candidate(s = \"bbaabbba\") == False\n assert candidate(s = \"aaaaabbbbbaaa\") == False\n assert candidate(s = \"baaaabbb\") == False\n assert candidate(s = \"aabbaabbb\") == False\n assert candidate(s = \"aaaabbbbba\") == False\n assert candidate(s = \"bababababa\") == False\n assert candidate(s = \"abbbbaaa\") == False\n assert candidate(s = \"bbaaaabbb\") == False\n assert candidate(s = \"aabbbbbbaaaa\") == False\n assert candidate(s = \"aaabb\") == True\n assert candidate(s = \"aabaaaabbb\") == False\n assert candidate(s = \"aaaaaaaaaabbbbbbbb\") == True\n assert candidate(s = \"aaabbbaaab\") == False\n assert candidate(s = \"ababababababab\") == False\n assert candidate(s = \"aabbabaa\") == False\n assert candidate(s = \"bbbbaa\") == False\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbbb\") == True\n assert candidate(s = \"bbbbbaab\") == False\n assert candidate(s = \"bbbbbaaabbaabbaabb\") == False\n assert candidate(s = \"abbbbbba\") == False\n assert candidate(s = \"aaaaaaaaabbbbbbbb\") == True\n assert candidate(s = \"bbbaaaaa\") == False\n assert candidate(s = \"abbbba\") == False\n assert candidate(s = \"aaaabbbbbbba\") == False\n assert candidate(s = \"aaaaaab\") == True\n assert candidate(s = \"babababaab\") == False\n assert candidate(s = \"abababab\") == False\n assert candidate(s = \"aaaaa\") == True\n assert candidate(s = \"bbaaaa\") == False\n assert candidate(s = \"aabbbbaa\") == False\n assert candidate(s = \"aababbaa\") == False\n assert candidate(s = \"aabbbbbaa\") == False\n assert candidate(s = \"abbbbbbaaaaa\") == False\n assert candidate(s = \"aaabbbbbba\") == False\n assert candidate(s = \"bbbbbbbbaaaa\") == False\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbb\") == True\n assert candidate(s = \"bbbbbaaaaabbb\") == False\n assert candidate(s = \"bbaabbabaa\") == False\n assert candidate(s = \"aabb\") == True\n assert candidate(s = \"ababbabababbab\") == False\n assert candidate(s = \"bbbbbbbbbaaaaa\") == False\n assert candidate(s = \"aaaabbbaaabb\") == False\n assert candidate(s = \"bababaaaabbbb\") == False\n assert candidate(s = \"bbaaa\") == False\n assert candidate(s = \"aabbaaabaaaabbbb\") == False\n assert candidate(s = \"aabababb\") == False\n assert candidate(s = \"bbbb\") == True\n assert candidate(s = \"aabbaabbbb\") == False\n assert candidate(s = \"baaaaa\") == False\n assert candidate(s = \"bbbbbaaaaabbbb\") == False\n assert candidate(s = \"aabbaaa\") == False\n assert candidate(s = \"ababab\") == False\n assert candidate(s = \"babbba\") == False\n assert candidate(s = \"bbbbbbbb\") == True\n assert candidate(s = \"aaabbbab\") == False\n assert candidate(s = \"bbaaaaaaab\") == False\n assert candidate(s = \"aaaaabbbbbbbba\") == False\n assert candidate(s = \"bbbbaaaaaa\") == False\n assert candidate(s = \"aabbabbbaabbb\") == False\n assert candidate(s = \"bababababab\") == False\n assert candidate(s = \"bbbaa\") == False\n assert candidate(s = \"bbbbbbbbb\") == True\n assert candidate(s = \"baaaabbbb\") == False\n assert candidate(s = \"aaaaabbbbbbbbb\") == True\n assert candidate(s = \"aabbba\") == False\n assert candidate(s = \"bababbababababab\") == False\n assert candidate(s = \"bbbbbbbbbaaab\") == False\n assert candidate(s = \"baab\") == False\n assert candidate(s = \"baaabb\") == False\n assert candidate(s = \"ababababbabababb\") == False\n assert candidate(s = \"bababbab\") == False\n assert candidate(s = \"ababababab\") == False\n assert candidate(s = \"bbbaaaaabbbbbbbbaaaa\") == False\n assert candidate(s = \"aabbbbbaaaa\") == False\n assert candidate(s = \"aabbbbb\") == True\n assert candidate(s = \"bbaa\") == False\n assert candidate(s = \"bbbaababbb\") == False\n assert candidate(s = \"bbbbaaaa\") == False\n assert candidate(s = \"baaab\") == False\n assert candidate(s = \"aaaaaabbbbba\") == False\n assert candidate(s = \"abaaa\") == False\n assert candidate(s = \"bbbaaabbb\") == False\n assert candidate(s = \"babababa\") == False\n assert candidate(s = \"aab\") == True\n assert candidate(s = \"bbbbbbbaaaaaaaaa\") == False\n assert candidate(s = \"abbbabab\") == False\n assert candidate(s = \"bbbbaabbaabb\") == False\n assert candidate(s = \"aabbbba\") == False\n assert candidate(s = \"aaaaaaaa\") == True\n assert candidate(s = \"aababbababaa\") == False\n assert candidate(s = \"aabbababab\") == False\n assert candidate(s = \"abbbbaaaab\") == False\n assert candidate(s = \"bbaaabbaaab\") == False\n assert candidate(s = \"aabbaab\") == False\n", "comparison": "exact"}, "public_tests": ["\"aaabbb\"", "\"abab\"", "\"bbb\""], "hints": ["You can check the opposite: check if there is a ‘b’ before an ‘a’. Then, negate and return that answer.", "s should not have any occurrences of “ba” as a substring."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().checkString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:41:57+00:00", "tests_total": 152, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function checkString($s) {", "container": "Solution", "callable": "checkString", "parameters": [{"name": "s", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2125, "task_id": "number-of-laser-beams-in-a-bank", "difficulty": "Medium", "problem_description": "Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the i^th row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.\n\nThere is one laser beam between any two security devices if both conditions are met:\n\n- The two devices are located on two different rows: r_1 and r_2, where r_1 < r_2.\n- For each row i where r_1 < i < r_2, there are no security devices in the i^th row.\n\nLaser beams are independent, i.e., one beam does not interfere nor join with another.\n\nReturn the total number of laser beams in the bank.\n\nExample 1:\n\nInput: bank = [\"011001\",\"000000\",\"010100\",\"001000\"]\nOutput: 8\nExplanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:\n * bank[0][1] -- bank[2][1]\n * bank[0][1] -- bank[2][3]\n * bank[0][2] -- bank[2][1]\n * bank[0][2] -- bank[2][3]\n * bank[0][5] -- bank[2][1]\n * bank[0][5] -- bank[2][3]\n * bank[2][1] -- bank[3][2]\n * bank[2][3] -- bank[3][2]\nNote that there is no beam between any device on the 0^th row with any on the 3^rd row.\nThis is because the 2^nd row contains security devices, which breaks the second condition.\n\nExample 2:\n\nInput: bank = [\"000\",\"111\",\"000\"]\nOutput: 0\nExplanation: There does not exist two devices located on two different rows.\n\nConstraints:\n\n- m == bank.length\n- n == bank[i].length\n- 1 <= m, n <= 500\n- bank[i][j] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(bank = ['00000', '00000', '00000', '00000']) == 0\n assert candidate(bank = ['001', '000', '101', '000', '110']) == 6\n assert candidate(bank = ['111', '000', '111']) == 9\n assert candidate(bank = ['0000', '0000', '0000', '0000']) == 0\n assert candidate(bank = ['11111', '11111', '11111']) == 50\n assert candidate(bank = ['000', '000', '000']) == 0\n assert candidate(bank = ['101', '010', '101', '010']) == 6\n assert candidate(bank = ['000', '111', '000']) == 0\n assert candidate(bank = ['001', '000', '110', '000', '101']) == 6\n assert candidate(bank = ['1', '0', '1', '0', '1']) == 2\n assert candidate(bank = ['111', '000', '111', '000', '111']) == 18\n assert candidate(bank = ['10101', '01010', '10101', '01010']) == 18\n assert candidate(bank = ['001', '010', '100']) == 2\n assert candidate(bank = ['111', '111', '111', '111']) == 27\n assert candidate(bank = ['101', '000', '101', '111']) == 10\n assert candidate(bank = ['1010', '0101', '1010', '0101']) == 12\n assert candidate(bank = ['1111', '0000', '1111', '0000']) == 16\n assert candidate(bank = ['000', '000', '000', '111']) == 0\n assert candidate(bank = ['000', '000', '000', '000']) == 0\n assert candidate(bank = ['11111', '00000', '00000', '00000', '11111']) == 25\n assert candidate(bank = ['11111', '00000', '11111', '00000']) == 25\n assert candidate(bank = ['00000', '00001', '00010', '00100', '01000', '10000']) == 4\n assert candidate(bank = ['011001', '000000', '010100', '001000']) == 8\n assert candidate(bank = ['1', '1', '1', '1']) == 3\n assert candidate(bank = ['1100', '0011', '0000', '1100']) == 8\n assert candidate(bank = ['00100', '01010', '10001']) == 6\n assert candidate(bank = ['01010', '01010', '01010', '01010']) == 12\n assert candidate(bank = ['1111', '0000', '1111', '0000', '1111']) == 32\n assert candidate(bank = ['000000', '110111', '000000', '111011', '000000', '101010', '000000']) == 40\n assert candidate(bank = ['1010101010', '0101010101', '0000000000', '1111111111', '0000000000', '1010101010']) == 125\n assert candidate(bank = ['11111111111111111111', '00000000000000000000', '11111111111111111111', '00000000000000000000', '11111111111111111111']) == 800\n assert candidate(bank = ['100100', '001100', '010101', '101010', '000000', '111111']) == 37\n assert candidate(bank = ['10101', '01010', '10101', '01010', '10101']) == 24\n assert candidate(bank = ['00100', '01010', '10001', '01010', '10001', '01010']) == 18\n assert candidate(bank = ['100000', '010000', '001000', '000100', '000010', '000001']) == 5\n assert candidate(bank = ['1111111111', '0000000000', '1010101010', '0101010101', '0000000000', '1111111111']) == 125\n assert candidate(bank = ['101010', '101010', '101010', '101010', '101010', '101010']) == 45\n assert candidate(bank = ['10001', '01010', '00100', '00000', '10001', '01010', '00100']) == 14\n assert candidate(bank = ['10000001', '00100100', '00011000', '00000000', '11111111', '00000000', '10101010']) == 56\n assert candidate(bank = ['000', '111', '101', '010', '111', '000', '111']) == 20\n assert candidate(bank = ['01010101', '00000000', '10101010', '00000000', '10101010', '00000000', '10101010']) == 48\n assert candidate(bank = ['110011', '000000', '010100', '001000', '000000', '101010']) == 13\n assert candidate(bank = ['000000000', '000000000', '000000000', '000000000', '111111111', '000000000', '111111111', '000000000', '000000000', '000000000']) == 81\n assert candidate(bank = ['11111', '00000', '10001', '00100', '00000', '10001']) == 14\n assert candidate(bank = ['11111', '10001', '01110', '10001', '11111']) == 32\n assert candidate(bank = ['000000000', '000101000', '000000000', '000010000', '000000000', '100000001']) == 4\n assert candidate(bank = ['000000', '000000', '000000', '000000', '000000', '000000']) == 0\n assert candidate(bank = ['0101010101', '1010101010', '0101010101', '1010101010', '0101010101', '1010101010', '0101010101', '1010101010', '0101010101', '1010101010']) == 225\n assert candidate(bank = ['10000001', '00000000', '00010000', '00000000', '00001000', '00000000', '00000100', '00000000']) == 4\n assert candidate(bank = ['00000', '00000', '00000', '00000', '11111', '11111', '00000', '11111']) == 50\n assert candidate(bank = ['111', '111', '111', '111', '111', '111', '111']) == 54\n assert candidate(bank = ['00000', '00000', '00000', '00000', '00000', '11111', '00000', '11111', '00000', '11111']) == 50\n assert candidate(bank = ['1110011', '0000000', '0111011', '0010100', '1111111', '0000000', '1000010']) == 63\n assert candidate(bank = ['00000', '00100', '01110', '00100', '00000', '11111']) == 11\n assert candidate(bank = ['101010', '010101', '101010', '000000', '010101']) == 27\n assert candidate(bank = ['000000', '101010', '010101', '000000', '101010']) == 18\n assert candidate(bank = ['0000000000', '0000000000', '0000000000', '1111111111', '0000000000', '1010101010', '0101010101', '0000000000']) == 75\n assert candidate(bank = ['0010100', '1011011', '0000000', '0000000', '1100110', '0000000', '1001001', '0101010', '0000000', '0000000', '0000000', '1111111']) == 72\n assert candidate(bank = ['111', '000', '000', '000', '111', '111', '000', '000', '111', '111']) == 36\n assert candidate(bank = ['1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1']) == 7\n assert candidate(bank = ['1111111111', '0000000000', '0000000000', '0000000000', '0000000000', '0000000000', '0000000000', '0000000000', '1111111111', '0000000000']) == 100\n assert candidate(bank = ['110000', '001100', '000011', '001100', '110000', '000000', '110000', '001100', '000011', '001100']) == 32\n assert candidate(bank = ['111111', '000000', '000000', '000000', '111111', '000000', '111111']) == 72\n assert candidate(bank = ['101010', '010101', '101010', '000000', '111111']) == 36\n assert candidate(bank = ['1', '0', '1', '0', '1', '0', '1']) == 3\n assert candidate(bank = ['000000000000000000', '111111111111111111', '000000000000000000', '000000000000000000', '111111111111111111', '000000000000000000', '111111111111111111']) == 648\n assert candidate(bank = ['1010101010', '0101010101', '0000000000', '1111111111', '0000000000', '1010101010', '0101010101']) == 150\n assert candidate(bank = ['1010101010', '0000000000', '0000000000', '1010101010', '0000000000', '0000000000', '1010101010']) == 50\n assert candidate(bank = ['00000', '11111', '10101', '01010', '11111', '00000']) == 31\n assert candidate(bank = ['00000000', '00000000', '00000000', '00000001', '00000010', '00000100', '00001000', '00010000', '00100000', '01000000', '10000000', '00000000', '00000000', '00000000']) == 7\n assert candidate(bank = ['1', '0', '1', '0', '1', '0', '1', '0', '1']) == 4\n assert candidate(bank = ['00000', '10001', '01010', '00100', '10001', '01010', '00100', '10001', '01010', '00100']) == 22\n assert candidate(bank = ['000000', '100101', '001000', '000100', '111111', '000000', '110111']) == 40\n assert candidate(bank = ['010101010101010101', '101010101010101010', '000000000000000000', '000000000000000000', '111111111111111111', '000000000000000000', '101010101010101010']) == 405\n assert candidate(bank = ['111000', '000111', '111000', '000111', '111000', '000111']) == 45\n assert candidate(bank = ['0000000', '0000000', '0000000', '0000000', '0000000', '0000000', '1111111', '1111111']) == 49\n assert candidate(bank = ['111111', '010101', '111111', '000000', '111111']) == 72\n assert candidate(bank = ['0101010101', '0000000000', '1111111111', '0000000000', '1111111111', '0000000000', '0101010101', '1010101010', '0000000000', '1111111111']) == 275\n assert candidate(bank = ['0000000', '0000000', '0101010', '0000000', '1010101', '0000000', '0101010']) == 24\n assert candidate(bank = ['000000', '000000', '101010', '010101', '101010', '000000']) == 18\n assert candidate(bank = ['1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0', '1', '0']) == 9\n assert candidate(bank = ['110101', '000000', '011001', '000000', '100100']) == 18\n assert candidate(bank = ['1001', '0110', '0000', '1101', '0010', '1010', '0101', '0000', '1111']) == 27\n assert candidate(bank = ['111111', '000000', '000000', '000000', '111111', '000000', '111111', '000000', '111111']) == 108\n assert candidate(bank = ['0000000000000000000000', '1111111111111111111111', '0000000000000000000000', '0000000000000000000000', '0000000000000000000000', '0000000000000000000000', '1111111111111111111111']) == 484\n assert candidate(bank = ['111', '111', '000', '111', '111', '000', '111', '111', '000', '111']) == 54\n assert candidate(bank = ['01010101', '10101010', '00000000', '11111111', '01010101']) == 80\n assert candidate(bank = ['111000', '000111', '111000', '000111', '111000']) == 36\n assert candidate(bank = ['00000', '11100', '00111', '01010', '10101', '11111', '00000', '11100', '00111', '01010', '10101']) == 72\n assert candidate(bank = ['111111', '000000', '000000', '000000', '000000', '111111']) == 36\n assert candidate(bank = ['0000000001', '0000000010', '0000000100', '0000001000', '0000010000', '0000100000', '0001000000', '0010000000', '0100000000', '1000000000']) == 9\n assert candidate(bank = ['000000', '000100', '100010', '001000', '010000', '100001', '111111']) == 19\n assert candidate(bank = ['00000', '00000', '00000', '11111', '00000', '11111', '00000', '11111']) == 50\n assert candidate(bank = ['10001', '01100', '00000', '00000', '00000', '01100', '10001', '10001', '01100', '00000', '00000', '10001']) == 24\n assert candidate(bank = ['01110', '00000', '11001', '00000', '01110', '00000', '10010']) == 24\n assert candidate(bank = ['111111', '111111', '111111', '111111', '111111', '111111']) == 180\n assert candidate(bank = ['111000', '000111', '111000', '000111', '111000', '000111', '111000', '000111']) == 63\n assert candidate(bank = ['00100', '01010', '00000', '10001', '01010']) == 10\n assert candidate(bank = ['1010101010', '0101010101', '1010101010', '0000000000', '0000000000', '1010101010', '0101010101', '1010101010']) == 125\n assert candidate(bank = ['0000000', '0011000', '0000000', '1100110', '0000000', '0101010', '0000000', '1000100']) == 26\n assert candidate(bank = ['110101', '000000', '101010', '000000', '110101']) == 24\n assert candidate(bank = ['100100', '011011', '000000', '000000', '100100', '011011']) == 24\n assert candidate(bank = ['001000', '001000', '001000', '001000', '001000', '001000']) == 5\n assert candidate(bank = ['1100011', '0000000', '0110101', '0011001', '1010101', '1111111', '0000000', '1111111']) == 117\n assert candidate(bank = ['010101', '101010', '010101', '101010', '010101', '101010', '010101']) == 54\n assert candidate(bank = ['11111', '00000', '00000', '00000', '11111', '00000', '00000', '11111']) == 50\n assert candidate(bank = ['111111', '000000', '110011', '001100', '111111', '000000', '111111']) == 80\n assert candidate(bank = ['110000', '001100', '000011', '000000', '110000', '001100', '000011']) == 20\n assert candidate(bank = ['0000000', '0010000', '0000100', '0000010', '0000001', '0000000', '0000000']) == 3\n assert candidate(bank = ['000000', '000000', '000000', '000000', '110111', '000000', '101010']) == 15\n assert candidate(bank = ['1111111', '0000000', '0101010', '0000000', '1010101', '0000000', '1111111']) == 61\n assert candidate(bank = ['001000', '010100', '000010', '100001', '000000', '100100', '010010', '001001']) == 18\n assert candidate(bank = ['000000', '010101', '101010', '000000', '111111', '000000']) == 27\n assert candidate(bank = ['000000', '000100', '001010', '010001', '100010', '010100', '100001', '001000']) == 20\n assert candidate(bank = ['1010101', '0101010', '1010101', '0101010', '1010101']) == 48\n assert candidate(bank = ['1111111111', '0000000000', '1111111111', '0000000000', '1111111111', '0000000000', '1111111111', '0000000000', '1111111111', '0000000000']) == 400\n assert candidate(bank = ['1111111111', '0000000000', '0000000000', '0000000000', '0000000000', '1111111111']) == 100\n", "comparison": "exact"}, "public_tests": ["[\"011001\",\"000000\",\"010100\",\"001000\"]", "[\"000\",\"111\",\"000\"]"], "hints": ["What is the commonality between security devices on the same row?", "Each device on the same row has the same number of beams pointing towards the devices on the next row with devices.", "If you were given an integer array where each element is the number of security devices on each row, can you solve it?", "Convert the input to such an array, skip any row with no security device, then find the sum of the product between adjacent elements."], "metadata": {"canonical_parameter_names": ["bank"], "leetcode_dataset_entry_point": "Solution().numberOfBeams", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:00+00:00", "tests_total": 117, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "math", "string", "matrix"]}, "language": "php", "interface": {"raw_signature": "function numberOfBeams($bank) {", "container": "Solution", "callable": "numberOfBeams", "parameters": [{"name": "bank", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2126, "task_id": "destroying-asteroids", "difficulty": "Medium", "problem_description": "You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the i^th asteroid.\n\nYou can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.\n\nReturn true if all asteroids can be destroyed. Otherwise, return false.\n\nExample 1:\n\nInput: mass = 10, asteroids = [3,9,19,5,21]\nOutput: true\nExplanation: One way to order the asteroids is [9,19,5,3,21]:\n- The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19\n- The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38\n- The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43\n- The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46\n- The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67\nAll asteroids are destroyed.\n\nExample 2:\n\nInput: mass = 5, asteroids = [4,9,23,4]\nOutput: false\nExplanation:\nThe planet cannot ever gain enough mass to destroy the asteroid with a mass of 23.\nAfter the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22.\nThis is less than 23, so a collision would not destroy the last asteroid.\n\nConstraints:\n\n- 1 <= mass <= 10^5\n- 1 <= asteroids.length <= 10^5\n- 1 <= asteroids[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mass = 1,asteroids = [100000]) == False\n assert candidate(mass = 1,asteroids = [1, 2, 3, 4, 5]) == True\n assert candidate(mass = 5,asteroids = [4, 9, 23, 4]) == False\n assert candidate(mass = 10,asteroids = [10, 10, 10, 10, 10]) == True\n assert candidate(mass = 20,asteroids = [10, 10, 10, 10, 10]) == True\n assert candidate(mass = 10,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(mass = 100000,asteroids = [100000]) == True\n assert candidate(mass = 10,asteroids = [5, 5, 5, 5, 5]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1, 1]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1]) == True\n assert candidate(mass = 10,asteroids = [3, 9, 19, 5, 21]) == True\n assert candidate(mass = 1,asteroids = [2, 2, 2, 2, 2]) == False\n assert candidate(mass = 100,asteroids = [10, 20, 30, 40, 50]) == True\n assert candidate(mass = 25,asteroids = [5, 10, 15]) == True\n assert candidate(mass = 6,asteroids = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(mass = 30,asteroids = [15, 15, 15, 15, 15]) == True\n assert candidate(mass = 100,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(mass = 1000,asteroids = [500, 250, 125, 62, 31, 15, 7, 3, 1]) == True\n assert candidate(mass = 20,asteroids = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(mass = 50,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]) == False\n assert candidate(mass = 25,asteroids = [10, 20, 5, 15, 25, 30, 5, 10, 20, 5]) == True\n assert candidate(mass = 500,asteroids = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == True\n assert candidate(mass = 30,asteroids = [1, 2, 3, 4, 5, 6, 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(mass = 100,asteroids = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == True\n assert candidate(mass = 1,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 100000]) == False\n assert candidate(mass = 25,asteroids = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == True\n assert candidate(mass = 150,asteroids = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == True\n assert candidate(mass = 10,asteroids = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == True\n assert candidate(mass = 300,asteroids = [250, 200, 150, 100, 50, 300]) == True\n assert candidate(mass = 100,asteroids = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == True\n assert candidate(mass = 100,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(mass = 9,asteroids = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(mass = 50,asteroids = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == True\n assert candidate(mass = 25,asteroids = [20, 10, 5, 15, 25, 30, 35, 40, 45, 50]) == True\n assert candidate(mass = 1000,asteroids = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == True\n assert candidate(mass = 1,asteroids = [100000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(mass = 1000,asteroids = [900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 25, 10, 5, 1]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(mass = 1000,asteroids = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == True\n assert candidate(mass = 200,asteroids = [100, 50, 150, 75, 25, 125, 225, 175, 200, 130]) == True\n assert candidate(mass = 75,asteroids = [50, 25, 12, 6, 3, 1, 50, 25, 12, 6, 3, 1, 50, 25, 12, 6, 3, 1]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(mass = 5,asteroids = [3, 7, 2, 8, 6, 4, 10, 1]) == True\n assert candidate(mass = 15,asteroids = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(mass = 5,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(mass = 20,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(mass = 10,asteroids = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == True\n assert candidate(mass = 5,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(mass = 30,asteroids = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == True\n assert candidate(mass = 25,asteroids = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == True\n assert candidate(mass = 75,asteroids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == True\n assert candidate(mass = 25,asteroids = [20, 15, 10, 5, 30, 25, 35, 40, 45, 50]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(mass = 10,asteroids = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == False\n assert candidate(mass = 10,asteroids = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == True\n assert candidate(mass = 50,asteroids = [100, 50, 25, 12, 6, 3, 1]) == True\n assert candidate(mass = 200,asteroids = [100, 150, 50, 200, 250, 300, 350, 400, 450, 500]) == True\n assert candidate(mass = 10,asteroids = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1]) == True\n assert candidate(mass = 1,asteroids = [2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == True\n assert candidate(mass = 1,asteroids = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(mass = 50,asteroids = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(mass = 50000,asteroids = [10000, 20000, 15000, 5000, 25000, 30000, 40000, 60000]) == True\n assert candidate(mass = 500,asteroids = [100, 200, 150, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000]) == True\n assert candidate(mass = 5,asteroids = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(mass = 50,asteroids = [100, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == True\n assert candidate(mass = 100,asteroids = [20, 30, 50, 10, 40, 60, 70]) == True\n assert candidate(mass = 10000,asteroids = [9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990]) == True\n assert candidate(mass = 100,asteroids = [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(mass = 100,asteroids = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(mass = 100,asteroids = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == True\n assert candidate(mass = 50,asteroids = [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]) == True\n assert candidate(mass = 5,asteroids = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(mass = 50000,asteroids = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == True\n assert candidate(mass = 20,asteroids = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == True\n assert candidate(mass = 15,asteroids = [20, 25, 30, 5, 10, 15, 35, 40]) == True\n assert candidate(mass = 10,asteroids = [1, 100000, 2, 99999, 3, 99998, 4, 99997]) == False\n assert candidate(mass = 15,asteroids = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == True\n assert candidate(mass = 120,asteroids = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == True\n assert candidate(mass = 50,asteroids = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == True\n assert candidate(mass = 15,asteroids = [10, 5, 15, 20, 25, 5]) == True\n assert candidate(mass = 25,asteroids = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == True\n assert candidate(mass = 100000,asteroids = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == True\n assert candidate(mass = 50,asteroids = [10, 20, 30, 40, 50]) == True\n assert candidate(mass = 100,asteroids = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]) == True\n assert candidate(mass = 15,asteroids = [1, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == True\n assert candidate(mass = 25,asteroids = [24, 23, 22, 21, 20, 19, 18, 17, 16, 15]) == True\n assert candidate(mass = 5,asteroids = [1, 3, 2, 4, 6, 8, 7, 5, 9, 10]) == True\n assert candidate(mass = 20,asteroids = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == True\n", "comparison": "exact"}, "public_tests": ["10\n[3,9,19,5,21]", "5\n[4,9,23,4]"], "hints": ["Choosing the asteroid to collide with can be done greedily.", "If an asteroid will destroy the planet, then every bigger asteroid will also destroy the planet.", "You only need to check the smallest asteroid at each collision. If it will destroy the planet, then every other asteroid will also destroy the planet.", "Sort the asteroids in non-decreasing order by mass, then greedily try to collide with the asteroids in that order."], "metadata": {"canonical_parameter_names": ["mass", "asteroids"], "leetcode_dataset_entry_point": "Solution().asteroidsDestroyed", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:02+00:00", "tests_total": 88, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function asteroidsDestroyed($mass, $asteroids) {", "container": "Solution", "callable": "asteroidsDestroyed", "parameters": [{"name": "mass", "type": "Integer"}, {"name": "asteroids", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2127, "task_id": "maximum-employees-to-be-invited-to-a-meeting", "difficulty": "Hard", "problem_description": "A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.\n\nThe employees are numbered from 0 to n - 1. Each employee has a favorite person and they will attend the meeting only if they can sit next to their favorite person at the table. The favorite person of an employee is not themself.\n\nGiven a 0-indexed integer array favorite, where favorite[i] denotes the favorite person of the i^th employee, return the maximum number of employees that can be invited to the meeting.\n\nExample 1:\n\nInput: favorite = [2,2,1,2]\nOutput: 3\nExplanation:\nThe above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table.\nAll employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously.\nNote that the company can also invite employees 1, 2, and 3, and give them their desired seats.\nThe maximum number of employees that can be invited to the meeting is 3.\n\nExample 2:\n\nInput: favorite = [1,2,0]\nOutput: 3\nExplanation:\nEach employee is the favorite person of at least one other employee, and the only way the company can invite them is if they invite every employee.\nThe seating arrangement will be the same as that in the figure given in example 1:\n- Employee 0 will sit between employees 2 and 1.\n- Employee 1 will sit between employees 0 and 2.\n- Employee 2 will sit between employees 1 and 0.\nThe maximum number of employees that can be invited to the meeting is 3.\n\nExample 3:\n\nInput: favorite = [3,0,1,4,1]\nOutput: 4\nExplanation:\nThe above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table.\nEmployee 2 cannot be invited because the two spots next to their favorite employee 1 are taken.\nSo the company leaves them out of the meeting.\nThe maximum number of employees that can be invited to the meeting is 4.\n\nConstraints:\n\n- n == favorite.length\n- 2 <= n <= 10^5\n- 0 <= favorite[i] <= n - 1\n- favorite[i] != i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(favorite = [1, 0, 0, 2]) == 4\n assert candidate(favorite = [5, 4, 3, 2, 1, 0]) == 6\n assert candidate(favorite = [2, 0, 1, 4, 5, 3]) == 3\n assert candidate(favorite = [5, 4, 0, 2, 0, 1]) == 4\n assert candidate(favorite = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 10\n assert candidate(favorite = [1, 2, 0]) == 3\n assert candidate(favorite = [3, 0, 1, 4, 1]) == 4\n assert candidate(favorite = [1, 0, 3, 2]) == 4\n assert candidate(favorite = [3, 3, 0, 2]) == 3\n assert candidate(favorite = [2, 2, 1, 2]) == 3\n assert candidate(favorite = [1, 0, 0, 2, 1, 4, 2]) == 6\n assert candidate(favorite = [1, 0, 3, 4, 2]) == 3\n assert candidate(favorite = [1, 0, 3, 2, 5, 4]) == 6\n assert candidate(favorite = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1]) == 8\n assert candidate(favorite = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == 10\n assert candidate(favorite = [2, 2, 1, 0, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 11\n assert candidate(favorite = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 15, 14, 13, 12]) == 16\n assert candidate(favorite = [1, 2, 0, 5, 6, 3, 4, 9, 7, 8]) == 4\n assert candidate(favorite = [1, 2, 0, 4, 5, 3, 7, 8, 9, 6]) == 4\n assert candidate(favorite = [1, 2, 3, 0, 1, 2, 3, 4, 5, 6]) == 4\n assert candidate(favorite = [1, 3, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 16\n assert candidate(favorite = [1, 2, 0, 4, 5, 3, 7, 8, 9, 10, 11, 12, 13, 14, 6]) == 9\n assert candidate(favorite = [3, 0, 1, 0, 7, 6, 5, 4, 9, 8]) == 10\n assert candidate(favorite = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 16\n assert candidate(favorite = [2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1]) == 15\n assert candidate(favorite = [2, 0, 1, 5, 3, 4, 8, 6, 7, 12, 9, 10, 11, 16, 13, 14, 15, 18, 19, 17]) == 4\n assert candidate(favorite = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == 10\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 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, 1, 2, 3, 4, 5, 6, 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(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 10]) == 10\n assert candidate(favorite = [1, 3, 0, 2, 5, 4, 7, 6, 9, 8]) == 6\n assert candidate(favorite = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 20\n assert candidate(favorite = [2, 2, 1, 2, 3, 3, 5, 5, 7, 7]) == 6\n assert candidate(favorite = [1, 4, 3, 6, 5, 8, 7, 2, 9, 0]) == 6\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 0, 10, 11, 12, 8, 9, 15, 16, 13, 14, 18, 19, 17]) == 8\n assert candidate(favorite = [3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 1, 0]) == 8\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 10\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0]) == 15\n assert candidate(favorite = [2, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 9\n assert candidate(favorite = [1, 0, 3, 4, 5, 6, 7, 8, 9, 2]) == 8\n assert candidate(favorite = [3, 2, 1, 0, 8, 8, 8, 8, 5, 5, 5, 5, 11, 11, 11, 11]) == 9\n assert candidate(favorite = [1, 2, 0, 4, 5, 6, 3, 8, 9, 7]) == 4\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 12]) == 12\n assert candidate(favorite = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1]) == 10\n assert candidate(favorite = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == 10\n assert candidate(favorite = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5]) == 8\n assert candidate(favorite = [1, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 2]) == 13\n assert candidate(favorite = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10]) == 10\n assert candidate(favorite = [1, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 0]) == 16\n assert candidate(favorite = [1, 3, 5, 7, 9, 0, 2, 4, 6, 8]) == 10\n assert candidate(favorite = [2, 0, 3, 2, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 21\n assert candidate(favorite = [3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18]) == 20\n assert candidate(favorite = [3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12]) == 16\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]) == 16\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 10\n assert candidate(favorite = [3, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]) == 18\n assert candidate(favorite = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 4\n assert candidate(favorite = [2, 3, 1, 0, 6, 7, 8, 9, 5, 10, 11, 4]) == 8\n assert candidate(favorite = [7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 11, 10, 13, 12, 15, 14]) == 16\n assert candidate(favorite = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 22\n assert candidate(favorite = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 14, 15, 12, 13]) == 6\n assert candidate(favorite = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]) == 20\n assert candidate(favorite = [1, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]) == 41\n assert candidate(favorite = [3, 0, 1, 4, 5, 3, 5, 6, 7, 8]) == 3\n", "comparison": "exact"}, "public_tests": ["[2,2,1,2]", "[1,2,0]", "[3,0,1,4,1]"], "hints": ["From the given array favorite, create a graph where for every index i, there is a directed edge from favorite[i] to i. The graph will be a combination of cycles and chains of acyclic edges. Now, what are the ways in which we can choose employees to sit at the table?", "The first way by which we can choose employees is by selecting a cycle of the graph. It can be proven that in this case, the employees that do not lie in the cycle can never be seated at the table (unless the cycle has a length of 2).", "The second way is by combining acyclic chains. At most two chains can be combined by a cycle of length 2, where each chain ends on one of the employees in the cycle."], "metadata": {"canonical_parameter_names": ["favorite"], "leetcode_dataset_entry_point": "Solution().maximumInvitations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:04+00:00", "tests_total": 127, "tests_dropped": 64, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "depth-first-search", "graph", "topological-sort", "kosarajus-algorithm", "tarjans-scc-algorithm"]}, "language": "php", "interface": {"raw_signature": "function maximumInvitations($favorite) {", "container": "Solution", "callable": "maximumInvitations", "parameters": [{"name": "favorite", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2129, "task_id": "capitalize-the-title", "difficulty": "Easy", "problem_description": "You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:\n\n- If the length of the word is 1 or 2 letters, change all letters to lowercase.\n- Otherwise, change the first letter to uppercase and the remaining letters to lowercase.\n\nReturn the capitalized title.\n\nExample 1:\n\nInput: title = \"capiTalIze tHe titLe\"\nOutput: \"Capitalize The Title\"\nExplanation:\nSince all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.\n\nExample 2:\n\nInput: title = \"First leTTeR of EACH Word\"\nOutput: \"First Letter of Each Word\"\nExplanation:\nThe word \"of\" has length 2, so it is all lowercase.\nThe remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.\n\nExample 3:\n\nInput: title = \"i lOve leetcode\"\nOutput: \"i Love Leetcode\"\nExplanation:\nThe word \"i\" has length 1, so it is lowercase.\nThe remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.\n\nConstraints:\n\n- 1 <= title.length <= 100\n- title consists of words separated by a single space without any leading or trailing spaces.\n- Each word consists of uppercase and lowercase English letters and is non-empty.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(title = \"ai and ml\") == \"ai And ml\"\n assert candidate(title = \"First leTTeR of EACH Word\") == \"First Letter of Each Word\"\n assert candidate(title = \"tHis iS a tEsT\") == \"This is a Test\"\n assert candidate(title = \"a b c\") == \"a b c\"\n assert candidate(title = \"HELLO WORLD\") == \"Hello World\"\n assert candidate(title = \"a b c d e f g\") == \"a b c d e f g\"\n assert candidate(title = \"sMaLl wOrDs\") == \"Small Words\"\n assert candidate(title = \"mY nAmE is Qwen\") == \"my Name is Qwen\"\n assert candidate(title = \"abc\") == \"Abc\"\n assert candidate(title = \"mY sOLution IS Awesome\") == \"my Solution is Awesome\"\n assert candidate(title = \"ab\") == \"ab\"\n assert candidate(title = \"Python Programming\") == \"Python Programming\"\n assert candidate(title = \"this is a test\") == \"This is a Test\"\n assert candidate(title = \"i lOve leetcode\") == \"i Love Leetcode\"\n assert candidate(title = \"mY NaMe Is Qwen\") == \"my Name is Qwen\"\n assert candidate(title = \"capiTalIze tHe titLe\") == \"Capitalize The Title\"\n assert candidate(title = \"Alibaba Cloud\") == \"Alibaba Cloud\"\n assert candidate(title = \"machine learning\") == \"Machine Learning\"\n assert candidate(title = \"tHis is a TeSt\") == \"This is a Test\"\n assert candidate(title = \"a\") == \"a\"\n assert candidate(title = \"hello world\") == \"Hello World\"\n assert candidate(title = \"tHis is A tEsT cASE\") == \"This is a Test Case\"\n assert candidate(title = \"data science\") == \"Data Science\"\n assert candidate(title = \"data science and machine learning\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"the quick\") == \"The Quick\"\n assert candidate(title = \"tiny a big BIGGEST\") == \"Tiny a Big Biggest\"\n assert candidate(title = \"advanced DATABASE MANAGEMENT SYSTEM\") == \"Advanced Database Management System\"\n assert candidate(title = \"FLASK and DJANGO web FRAMEWORKS\") == \"Flask And Django Web Frameworks\"\n assert candidate(title = \"sINGLEcHaRaCters AND twOCHaRaCters\") == \"Singlecharacters And Twocharacters\"\n assert candidate(title = \"PYTHON pROGRAMMING\") == \"Python Programming\"\n assert candidate(title = \"pyThOn cOdInG chAlLenge\") == \"Python Coding Challenge\"\n assert candidate(title = \"data sCience and MaChine LeArning\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"PYTHON programming LANGUAGE\") == \"Python Programming Language\"\n assert candidate(title = \"DESIGN PATTERNS in software ENGINEERING\") == \"Design Patterns in Software Engineering\"\n assert candidate(title = \"lowercase with small words like a and the\") == \"Lowercase With Small Words Like a And The\"\n assert candidate(title = \"wHy cApItAlIzE sOmE wOrDs\") == \"Why Capitalize Some Words\"\n assert candidate(title = \"data sCience and MaChInE lEaRnInG\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"WEB DEVELOPMENT essentials\") == \"Web Development Essentials\"\n assert candidate(title = \"an\") == \"an\"\n assert candidate(title = \"Data Science and Machine Learning\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"INformation TECHNOLOGY\") == \"Information Technology\"\n assert candidate(title = \"cryptography and SECURITY\") == \"Cryptography And Security\"\n assert candidate(title = \"UPPER lower CASE\") == \"Upper Lower Case\"\n assert candidate(title = \"SOFTWARE ENGINEERING principles\") == \"Software Engineering Principles\"\n assert candidate(title = \"LONGEST wORD\") == \"Longest Word\"\n assert candidate(title = \"pYtHoN pRoGrAmMiNg\") == \"Python Programming\"\n assert candidate(title = \"multiple spaces here\") == \"Multiple Spaces Here\"\n assert candidate(title = \"sInGlE\") == \"Single\"\n assert candidate(title = \"openai gpt four\") == \"Openai Gpt Four\"\n assert candidate(title = \"user INTERFACE and user EXPERIENCE\") == \"User Interface And User Experience\"\n assert candidate(title = \"VIRTUALIZATION technology\") == \"Virtualization Technology\"\n assert candidate(title = \"in the land OF wonder AND magic\") == \"in The Land of Wonder And Magic\"\n assert candidate(title = \"CoMpLeX wOrDs LiKe SuPeRcAlIfR aNd qUiXoTtIc\") == \"Complex Words Like Supercalifr And Quixottic\"\n assert candidate(title = \"tHis is A tEsT String\") == \"This is a Test String\"\n assert candidate(title = \"INTERNET of THINGS iot\") == \"Internet of Things Iot\"\n assert candidate(title = \"tHiS is a sHoRt TeSt\") == \"This is a Short Test\"\n assert candidate(title = \"python programming LANGUAGE\") == \"Python Programming Language\"\n assert candidate(title = \"a quick brown fox jumps over the lazy dog\") == \"a Quick Brown Fox Jumps Over The Lazy Dog\"\n assert candidate(title = \"UPPERCASE lowercase MIXEDcase\") == \"Uppercase Lowercase Mixedcase\"\n assert candidate(title = \"a SHORT story IN a SMALL town\") == \"a Short Story in a Small Town\"\n assert candidate(title = \"single\") == \"Single\"\n assert candidate(title = \"data STRUCTURE and ALGORITHMS\") == \"Data Structure And Algorithms\"\n assert candidate(title = \"this is a test STRING with MIXED CASE\") == \"This is a Test String With Mixed Case\"\n assert candidate(title = \"to be or not to be\") == \"to be or Not to be\"\n assert candidate(title = \"wordlengthsofthreetwoone\") == \"Wordlengthsofthreetwoone\"\n assert candidate(title = \"wiTh lOnG wOrDs liKe suPercalifragilisticexpialidocious\") == \"With Long Words Like Supercalifragilisticexpialidocious\"\n assert candidate(title = \"this is a longer sentence with more words to test the function\") == \"This is a Longer Sentence With More Words to Test The Function\"\n assert candidate(title = \"very Very LONG title with MANY Words indeed\") == \"Very Very Long Title With Many Words Indeed\"\n assert candidate(title = \"Algorithms and DATA structures\") == \"Algorithms And Data Structures\"\n assert candidate(title = \"tEsTiNg WoRdS wItH vArIoUs lEnGtHs\") == \"Testing Words With Various Lengths\"\n assert candidate(title = \"a quick brown fox\") == \"a Quick Brown Fox\"\n assert candidate(title = \"tExT pRoCeSsInG\") == \"Text Processing\"\n assert candidate(title = \"the quick BROWN fox JUMPS OVER the LAZY DOG\") == \"The Quick Brown Fox Jumps Over The Lazy Dog\"\n assert candidate(title = \"algorithms and data structures\") == \"Algorithms And Data Structures\"\n assert candidate(title = \"a short AND a LONG word\") == \"a Short And a Long Word\"\n assert candidate(title = \"AlGoRiThM aNd dAtA sTrUcTuRe\") == \"Algorithm And Data Structure\"\n assert candidate(title = \"data sCIENCE and maCHine LEARNING\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"cOnsIdEr tHiS eXaMpLe\") == \"Consider This Example\"\n assert candidate(title = \"cloud COMPUTING\") == \"Cloud Computing\"\n assert candidate(title = \"fLASK aNd dJANGO\") == \"Flask And Django\"\n assert candidate(title = \"To be OR not TO be\") == \"to be or Not to be\"\n assert candidate(title = \"multiple words of varying length and CASE\") == \"Multiple Words of Varying Length And Case\"\n assert candidate(title = \"network SECURITY\") == \"Network Security\"\n assert candidate(title = \"programming IN python\") == \"Programming in Python\"\n assert candidate(title = \"the QUICK brown FOX jumps OVER the LAZY dog\") == \"The Quick Brown Fox Jumps Over The Lazy Dog\"\n assert candidate(title = \"MiXcAsE wOrDlEnGtH\") == \"Mixcase Wordlength\"\n assert candidate(title = \"in\") == \"in\"\n assert candidate(title = \"wiTh grEat pOwEr cOmEs gReAt rEsPoNsIbIlItY\") == \"With Great Power Comes Great Responsibility\"\n assert candidate(title = \"algorithms AND dataSTRUCTURES\") == \"Algorithms And Datastructures\"\n assert candidate(title = \"wiTh gReAt pOWeR cOmEs gReAt rEsPoNsIbIlItY\") == \"With Great Power Comes Great Responsibility\"\n assert candidate(title = \"A B c D E F G\") == \"a b c d e f g\"\n assert candidate(title = \"AI and MACHINE LEARNING\") == \"ai And Machine Learning\"\n assert candidate(title = \"big DATA ANALYSIS\") == \"Big Data Analysis\"\n assert candidate(title = \"mUlTiPlE sMaLl wOrDs\") == \"Multiple Small Words\"\n assert candidate(title = \"LEETcode IS coOL\") == \"Leetcode is Cool\"\n assert candidate(title = \"two Words\") == \"Two Words\"\n assert candidate(title = \"introduction to ARTIFICIAL INTELLIGENCE\") == \"Introduction to Artificial Intelligence\"\n assert candidate(title = \"sOlVe tHe rObOt wOrLd cHAlLeNgEs\") == \"Solve The Robot World Challenges\"\n assert candidate(title = \"mIxEd cAsE iNpUt\") == \"Mixed Case Input\"\n assert candidate(title = \"EACH WORD IN THE TITLE\") == \"Each Word in The Title\"\n assert candidate(title = \"programming in PYTHON\") == \"Programming in Python\"\n assert candidate(title = \"one two three four five six seven eight nine ten\") == \"One Two Three Four Five Six Seven Eight Nine Ten\"\n assert candidate(title = \"very very LONG words in THIS sentence\") == \"Very Very Long Words in This Sentence\"\n assert candidate(title = \"leet code CHALLENGE\") == \"Leet Code Challenge\"\n assert candidate(title = \"the\") == \"The\"\n assert candidate(title = \"double two\") == \"Double Two\"\n assert candidate(title = \"a B c D E F G\") == \"a b c d e f g\"\n assert candidate(title = \"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\"\n assert candidate(title = \"in The HoLlyWoOd\") == \"in The Hollywood\"\n assert candidate(title = \"tHis is a tEsT string\") == \"This is a Test String\"\n assert candidate(title = \"MiXeD CaSe wOrDs\") == \"Mixed Case Words\"\n assert candidate(title = \"multiple small words in here\") == \"Multiple Small Words in Here\"\n assert candidate(title = \"in the HEART of the CITY\") == \"in The Heart of The City\"\n assert candidate(title = \"randomly CaPiTaLiZed WoRds\") == \"Randomly Capitalized Words\"\n assert candidate(title = \"To BE OR NOT to BE\") == \"to be or Not to be\"\n assert candidate(title = \"MiNiMaL MaXiMaL\") == \"Minimal Maximal\"\n assert candidate(title = \"HELLO wORLD\") == \"Hello World\"\n assert candidate(title = \"THE quick BROWN fox JUMPS OVER the LAZY dog\") == \"The Quick Brown Fox Jumps Over The Lazy Dog\"\n assert candidate(title = \"data SCIENCE and MACHINE LEARNING\") == \"Data Science And Machine Learning\"\n assert candidate(title = \"pYthon programming lanGuage\") == \"Python Programming Language\"\n assert candidate(title = \"OpenAI GPT-4\") == \"Openai Gpt-4\"\n assert candidate(title = \"triple three words\") == \"Triple Three Words\"\n assert candidate(title = \"eNcYcLopEdIa oF pHySiCs aNd mAtHeMaTiCs\") == \"Encyclopedia of Physics And Mathematics\"\n assert candidate(title = \"a a a a a a a\") == \"a a a a a a a\"\n assert candidate(title = \"openAI GPT AND machineLEARNING\") == \"Openai Gpt And Machinelearning\"\n assert candidate(title = \"PYTHON programming\") == \"Python Programming\"\n assert candidate(title = \"sOFTWARE dEVELOPMENT\") == \"Software Development\"\n assert candidate(title = \"tHiS iS a TeSt CaSe\") == \"This is a Test Case\"\n assert candidate(title = \"wEb dEveLopMeNt fOr bEgInNeRs\") == \"Web Development For Beginners\"\n assert candidate(title = \"one\") == \"One\"\n assert candidate(title = \"Data STRUCTURES and ALGORITHMs\") == \"Data Structures And Algorithms\"\n assert candidate(title = \"aBcDeFgHiJ kLmNoPqRsT\") == \"Abcdefghij Klmnopqrst\"\n assert candidate(title = \"Python Programming Language\") == \"Python Programming Language\"\n assert candidate(title = \"blockCHAIN technology\") == \"Blockchain Technology\"\n assert candidate(title = \"Python Programming Is Fun\") == \"Python Programming is Fun\"\n assert candidate(title = \"LoNg WoRdS aNd sHoRt wOrDs\") == \"Long Words And Short Words\"\n assert candidate(title = \"tHe qUiCk bRoWn fOx\") == \"The Quick Brown Fox\"\n", "comparison": "exact"}, "public_tests": ["\"capiTalIze tHe titLe\"", "\"First leTTeR of EACH Word\"", "\"i lOve leetcode\""], "hints": ["Firstly, try to find all the words present in the string.", "On the basis of each word's lengths, simulate the process explained in Problem."], "metadata": {"canonical_parameter_names": ["title"], "leetcode_dataset_entry_point": "Solution().capitalizeTitle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:09+00:00", "tests_total": 137, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function capitalizeTitle($title) {", "container": "Solution", "callable": "capitalizeTitle", "parameters": [{"name": "title", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2131, "task_id": "longest-palindrome-by-concatenating-two-letter-words", "difficulty": "Medium", "problem_description": "You are given an array of strings words. Each element of words consists of two lowercase English letters.\n\nCreate the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most once.\n\nReturn the length of the longest palindrome that you can create. If it is impossible to create any palindrome, return 0.\n\nA palindrome is a string that reads the same forward and backward.\n\nExample 1:\n\nInput: words = [\"lc\",\"cl\",\"gg\"]\nOutput: 6\nExplanation: One longest palindrome is \"lc\" + \"gg\" + \"cl\" = \"lcggcl\", of length 6.\nNote that \"clgglc\" is another longest palindrome that can be created.\n\nExample 2:\n\nInput: words = [\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]\nOutput: 8\nExplanation: One longest palindrome is \"ty\" + \"lc\" + \"cl\" + \"yt\" = \"tylcclyt\", of length 8.\nNote that \"lcyttycl\" is another longest palindrome that can be created.\n\nExample 3:\n\nInput: words = [\"cc\",\"ll\",\"xx\"]\nOutput: 2\nExplanation: One longest palindrome is \"cc\", of length 2.\nNote that \"ll\" is another longest palindrome that can be created, and so is \"xx\".\n\nConstraints:\n\n- 1 <= words.length <= 10^5\n- words[i].length == 2\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['xy', 'yx', 'xy', 'yx', 'xy', 'yx']) == 12\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee']) == 2\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz']) == 22\n assert candidate(words = ['ab', 'ba', 'cc', 'dd', 'dc', 'ca', 'ac']) == 10\n assert candidate(words = ['cc', 'll', 'xx']) == 2\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', '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']) == 104\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba']) == 16\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qp', 'pq', 'rs', 'sr', 'tu', 'ut', 'vu', 'uv']) == 24\n assert candidate(words = ['zz', 'aa', 'bb', 'cc', 'zz', 'aa']) == 10\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba']) == 52\n assert candidate(words = ['ab', 'ty', 'yt', 'lc', 'cl', 'ab']) == 8\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj']) == 2\n assert candidate(words = ['lc', 'cl', 'gg']) == 6\n assert candidate(words = ['aa', 'aa', 'aa', 'aa']) == 8\n assert candidate(words = ['aa', 'aa', 'aa', 'aa', 'aa']) == 10\n assert candidate(words = ['ab', 'ba', 'cc', 'dd', 'ab', 'ba']) == 10\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']) == 52\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba']) == 12\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']) == 2\n assert candidate(words = ['aa', 'aa', 'aa', 'bb', 'bb', 'cc', 'cc', 'cc', 'cc', 'dd', 'dd', 'dd', 'dd']) == 26\n assert candidate(words = ['aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa', 'aa']) == 52\n assert candidate(words = ['aa', 'aa', 'aa', 'aa', 'ab', 'ba', 'ab', 'ba', 'ac', 'ca', 'ac', 'ca', 'ad', 'da', 'ad', 'da', 'ae', 'ea', 'ae', 'ea', 'af', 'fa', 'af', 'fa', 'ag', 'ga', 'ag', 'ga', 'ah', 'ha', 'ah', 'ha', 'ai', 'ia', 'ai', 'ia', 'aj', 'ja', 'aj', 'ja', 'ak', 'ka', 'ak', 'ka', 'al', 'la', 'al', 'la', 'am', 'ma', 'am', 'ma', 'an', 'na', 'an', 'na', 'ao', 'oa', 'ao', 'oa', 'ap', 'pa', 'ap', 'pa', 'aq', 'qa', 'aq', 'qa', 'ar', 'ra', 'ar', 'ra', 'as', 'sa', 'as', 'sa', 'at', 'ta', 'at', 'ta', 'au', 'ua', 'au', 'ua', 'av', 'va', 'av', 'va', 'aw', 'wa', 'aw', 'wa', 'ax', 'xa', 'ax', 'xa', 'ay', 'ya', 'ay', 'ya', 'az', 'za', 'az', 'za', 'bb', 'bb', 'bb', 'bb', 'cc', 'cc', 'cc', 'cc', 'dd', 'dd', 'dd', 'dd', 'ee', 'ee', 'ee', 'ee', 'ff', 'ff', 'ff', 'ff', 'gg', 'gg', 'gg', 'gg', 'hh', 'hh', 'hh', 'hh', 'ii', 'ii', 'ii', 'ii', 'jj', 'jj', 'jj', 'jj', 'kk', 'kk', 'kk', 'kk', 'll', 'll', 'll', 'll', 'mm', 'mm', 'mm', 'mm', 'nn', 'nn', 'nn', 'nn', 'oo', 'oo', 'oo', 'oo', 'pp', 'pp', 'pp', 'pp', 'qq', 'qq', 'qq', 'qq', 'rr', 'rr', 'rr', 'rr', 'ss', 'ss', 'ss', 'ss', 'tt', 'tt', 'tt', 'tt', 'uu', 'uu', 'uu', 'uu', 'vv', 'vv', 'vv', 'vv', 'ww', 'ww', 'ww', 'ww', 'xx', 'xx', 'xx', 'xx', 'yy', 'yy', 'yy', 'yy', 'zz', 'zz', 'zz', 'zz']) == 408\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji']) == 24\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', 'zz', 'yy', 'xx', 'ww', 'vv', 'uu', 'tt', 'ss', 'rr', 'qq', 'pp', 'oo', 'nn', 'mm', 'll', 'kk', 'jj', 'ii', 'hh', 'gg', 'ff', 'ee', 'dd', 'cc', 'bb', 'aa']) == 104\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd']) == 18\n assert candidate(words = ['zz', 'zz', 'xy', 'yx', 'yx', 'xy', 'ab', 'ba', 'ab', 'ba', 'zz', 'zz']) == 24\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'ab', 'ba', 'xy', 'yx', 'zy', 'yz']) == 72\n assert candidate(words = ['xy', 'yx', 'xx', 'yy', 'xy', 'yx', 'xx', 'yy', 'xy', 'yx', 'xx', 'yy']) == 22\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', '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']) == 18\n assert candidate(words = ['aa', 'bb', 'aa', 'bb', 'cc', 'dd', 'cc', 'dd', 'ee', 'ff', 'ee', 'ff']) == 24\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd']) == 64\n assert candidate(words = ['xy', 'yx', 'zz', 'zz', 'yx', 'xz', 'zx', 'zz']) == 14\n assert candidate(words = ['aa', 'bb', 'cc', 'dd', 'aa', 'bb', 'cc', 'dd', 'aa']) == 18\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk']) == 24\n assert candidate(words = ['aa', 'aa', 'aa', 'aa', 'bb', 'bb', 'bb', 'bb', 'cc', 'cc', 'cc', 'cc', 'dd', 'dd', 'dd', 'dd', 'ee', 'ee', 'ee', 'ee', 'ff', 'ff', 'ff', 'ff', 'gg', 'gg', 'gg', 'gg', 'hh', 'hh', 'hh', 'hh']) == 64\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', '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', 'xy', 'yx', 'cd', 'dc', 'ef', 'fe', 'gh', 'hg', 'ij', 'ji', 'kl', 'lk', 'mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy']) == 112\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'cd', 'dc', 'cd', 'dc', 'ef', 'fe', 'ef', 'fe', 'gh', 'hg', 'gh', 'hg']) == 36\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', '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']) == 54\n assert candidate(words = ['xy', 'yx', 'yx', 'xy', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx', 'xy', 'xy', 'yx', 'yx']) == 304\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'bc', 'cb', 'bd', 'db']) == 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', 'zx', 'xz', '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', 'zx', 'xz']) == 112\n assert candidate(words = ['xy', 'yx', 'yy', 'xx', 'zz', 'zz', 'zz', 'zz', 'xy', 'yx', 'xx', 'yy', 'zz', 'zz']) == 28\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', 'xz', 'zx', 'yz', 'zy', 'yx', 'zx', 'yz', 'zy', 'yx', 'zx', 'yz', 'zy', 'yx', 'zx', 'yz', 'zy', 'yx', 'zx', 'yz', 'zy']) == 30\n assert candidate(words = ['ab', 'ba', 'cd', 'dc', 'cd', 'dc', 'ab', 'ba', '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', 'gh', 'hg']) == 76\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', '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']) == 102\n assert candidate(words = ['mn', 'nm', 'op', 'po', 'qr', 'rq', 'st', 'ts', 'uv', 'vu', 'wx', 'xw', 'yz', 'zy', 'aa', 'bb', 'cc', 'dd']) == 30\n assert candidate(words = ['ab', 'ba', 'xy', 'yx', 'zy', 'yz', 'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn', 'oo', 'pp']) == 14\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', 'zx', 'xz', 'yz', 'zy', 'zx', 'xz', 'yz', 'zy', 'zx', 'xz', 'yz', 'zy', 'zx', 'xz', 'yz', 'zy', 'zx', 'xz']) == 88\n assert candidate(words = ['qq', 'ww', 'ee', 'rr', 'tt', 'yy', 'uu', 'ii', 'oo', 'pp', 'aa', 'ss', 'dd', 'ff', 'gg', 'hh', 'jj', 'kk', 'll', 'zz', 'xx', 'cc', 'vv', 'bb', 'nn', 'mm', 'll', 'kk', 'jj', 'ii', 'hh', 'gg', 'ff', 'dd', 'ss', 'aa', 'pp', 'oo', 'nn', 'mm', 'zz', 'xx', 'vv', 'cc', 'uu', 'tt', 'rr', 'ee', 'ww', 'qq']) == 98\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', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz', 'zz']) == 92\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', 'zz', 'zz', 'aa', 'aa', 'bb', 'bb', 'cc', 'cc', 'dd', 'dd', 'ee', 'ee', 'ff', 'ff', 'gg', 'gg', 'hh', 'hh', 'ii', 'ii', 'jj', 'jj', 'kk', 'kk', 'll', 'll', 'mm', 'mm', 'nn', 'nn', 'oo', 'oo', 'pp', 'pp', 'qq', 'qq', 'rr', 'rr', 'ss', 'ss', 'tt', 'tt', 'uu', 'uu', 'vv', 'vv', 'ww', 'ww', 'xx', 'xx', 'yy', 'yy']) == 156\n assert candidate(words = ['aa', 'bb', 'cc', 'aa', 'bb', 'cc', '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', 'aa', 'bb', 'cc']) == 26\n", "comparison": "exact"}, "public_tests": ["[\"lc\",\"cl\",\"gg\"]", "[\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]", "[\"cc\",\"ll\",\"xx\"]"], "hints": ["A palindrome must be mirrored over the center. Suppose we have a palindrome. If we prepend the word \"ab\" on the left, what must we append on the right to keep it a palindrome?", "We must append \"ba\" on the right. The number of times we can do this is the minimum of (occurrences of \"ab\") and (occurrences of \"ba\").", "For words that are already palindromes, e.g. \"aa\", we can prepend and append these in pairs as described in the previous hint. We can also use exactly one in the middle to form an even longer palindrome."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().longestPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:13+00:00", "tests_total": 52, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "string", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function longestPalindrome($words) {", "container": "Solution", "callable": "longestPalindrome", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2132, "task_id": "stamping-the-grid", "difficulty": "Hard", "problem_description": "You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).\n\nYou are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:\n\n1. Cover all the empty cells.\n2. Do not cover any of the occupied cells.\n3. We can put as many stamps as we want.\n4. Stamps can overlap with each other.\n5. Stamps are not allowed to be rotated.\n6. Stamps must stay completely inside the grid.\n\nReturn true if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return false.\n\nExample 1:\n\nInput: grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3\nOutput: true\nExplanation: We have two overlapping stamps (labeled 1 and 2 in the image) that are able to cover all the empty cells.\n\nExample 2:\n\nInput: grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2\nOutput: false\nExplanation: There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid.\n\nConstraints:\n\n- m == grid.length\n- n == grid[r].length\n- 1 <= m, n <= 10^5\n- 1 <= m * n <= 2 * 10^5\n- grid[r][c] is either 0 or 1.\n- 1 <= stampHeight, stampWidth <= 10^5\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]],stampHeight = 2,stampWidth = 2) == True\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],stampHeight = 1,stampWidth = 1) == True\n assert candidate(grid = [[0, 0], [0, 0]],stampHeight = 1,stampWidth = 1) == True\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]],stampHeight = 3,stampWidth = 3) == True\n assert candidate(grid = [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]],stampHeight = 4,stampWidth = 3) == True\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == True\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, 0]],stampHeight = 3,stampWidth = 2) == False\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]],stampHeight = 2,stampWidth = 2) == False\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]],stampHeight = 3,stampWidth = 3) == False\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]],stampHeight = 4,stampWidth = 4) == True\n assert candidate(grid = [[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, 0, 0, 0, 1, 0]],stampHeight = 2,stampWidth = 2) == False\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]],stampHeight = 3,stampWidth = 3) == True\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]],stampHeight = 5,stampWidth = 5) == True\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]],stampHeight = 3,stampWidth = 5) == True\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]],stampHeight = 2,stampWidth = 3) == False\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]],stampHeight = 5,stampWidth = 5) == True\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == False\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]],stampHeight = 3,stampWidth = 3) == False\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]],stampHeight = 4,stampWidth = 4) == True\n assert candidate(grid = [[1, 1, 1, 0, 0, 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, 1, 1, 1]],stampHeight = 2,stampWidth = 3) == True\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]],stampHeight = 3,stampWidth = 5) == True\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]],stampHeight = 3,stampWidth = 3) == True\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0]],stampHeight = 2,stampWidth = 3) == False\n assert candidate(grid = [[1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 4) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\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]],stampHeight = 2,stampWidth = 2) == False\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, 1, 0, 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]],stampHeight = 4,stampWidth = 4) == False\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[1, 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, 1]],stampHeight = 2,stampWidth = 2) == True\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]],stampHeight = 4,stampWidth = 4) == False\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]],stampHeight = 4,stampWidth = 4) == False\n assert candidate(grid = [[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, 1, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == True\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, 1, 1, 1, 1, 1, 1, 1]],stampHeight = 2,stampWidth = 2) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0]],stampHeight = 2,stampWidth = 3) == False\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]],stampHeight = 5,stampWidth = 10) == True\n assert candidate(grid = [[1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1]],stampHeight = 3,stampWidth = 3) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0]],stampHeight = 3,stampWidth = 2) == False\n assert candidate(grid = [[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, 1, 0, 0], [0, 0, 0, 1, 0, 0]],stampHeight = 2,stampWidth = 2) == True\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]],stampHeight = 5,stampWidth = 4) == True\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]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]],stampHeight = 2,stampWidth = 4) == False\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], [0, 0, 0, 1, 0, 0]],stampHeight = 2,stampWidth = 3) == False\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]],stampHeight = 2,stampWidth = 2) == False\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]],stampHeight = 2,stampWidth = 2) == False\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, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]],stampHeight = 4,stampWidth = 4) == False\n assert candidate(grid = [[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]],stampHeight = 4,stampWidth = 3) == False\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]],stampHeight = 4,stampWidth = 4) == False\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[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]],stampHeight = 4,stampWidth = 5) == True\n assert candidate(grid = [[0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]],stampHeight = 2,stampWidth = 2) == False\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, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 2) == True\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]],stampHeight = 4,stampWidth = 5) == True\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]],stampHeight = 2,stampWidth = 3) == False\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, 1]],stampHeight = 2,stampWidth = 3) == True\n assert candidate(grid = [[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, 1, 0, 0, 0, 0]],stampHeight = 2,stampWidth = 3) == False\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0, 1, 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, 1, 0, 1, 0, 1, 0, 1, 0]],stampHeight = 3,stampWidth = 3) == False\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, 1]],stampHeight = 3,stampWidth = 4) == True\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]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\n assert candidate(grid = [[1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [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]],stampHeight = 3,stampWidth = 2) == False\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]],stampHeight = 1,stampWidth = 1) == True\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]],stampHeight = 3,stampWidth = 3) == False\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, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]],stampHeight = 4,stampWidth = 5) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]],stampHeight = 3,stampWidth = 3) == False\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]],stampHeight = 3,stampWidth = 4) == True\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, 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]],stampHeight = 4,stampWidth = 4) == False\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]],stampHeight = 5,stampWidth = 4) == True\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]],stampHeight = 5,stampWidth = 5) == True\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, 1, 1, 1, 1, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 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]],stampHeight = 4,stampWidth = 4) == False\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, 1]],stampHeight = 2,stampWidth = 3) == False\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]],stampHeight = 2,stampWidth = 2) == True\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]],stampHeight = 3,stampWidth = 3) == True\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, 0, 1, 0]],stampHeight = 2,stampWidth = 2) == False\n assert candidate(grid = [[0, 1, 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]],stampHeight = 3,stampWidth = 2) == False\n", "comparison": "exact"}, "public_tests": ["[[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]]\n4\n3", "[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]\n2\n2"], "hints": ["Can we use prefix sums here?"], "metadata": {"canonical_parameter_names": ["grid", "stampHeight", "stampWidth"], "leetcode_dataset_entry_point": "Solution().possibleToStamp", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:16+00:00", "tests_total": 81, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "greedy", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function possibleToStamp($grid, $stampHeight, $stampWidth) {", "container": "Solution", "callable": "possibleToStamp", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "stampHeight", "type": "Integer"}, {"name": "stampWidth", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2133, "task_id": "check-if-every-row-and-column-contains-all-numbers", "difficulty": "Easy", "problem_description": "An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).\n\nGiven an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.\n\nExample 1:\n\nInput: matrix = [[1,2,3],[3,1,2],[2,3,1]]\nOutput: true\nExplanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3.\nHence, we return true.\n\nExample 2:\n\nInput: matrix = [[1,1,1],[1,2,3],[1,2,3]]\nOutput: false\nExplanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3.\nHence, we return false.\n\nConstraints:\n\n- n == matrix.length == matrix[i].length\n- 1 <= n <= 100\n- 1 <= matrix[i][j] <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]) == True\n assert candidate(matrix = [[4, 3, 2, 1], [1, 4, 3, 2], [2, 1, 4, 3], [3, 2, 1, 4]]) == True\n assert candidate(matrix = [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]]) == False\n assert candidate(matrix = [[1]]) == True\n assert candidate(matrix = [[1, 1, 1], [1, 2, 3], [1, 2, 3]]) == False\n assert candidate(matrix = [[1, 2, 3], [3, 1, 2], [2, 3, 1]]) == True\n assert candidate(matrix = [[1, 2], [2, 1]]) == True\n assert candidate(matrix = [[4, 3, 2, 1], [1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2]]) == False\n assert candidate(matrix = [[7, 4, 3, 8, 5, 6, 2, 1], [1, 5, 6, 2, 8, 3, 7, 4], [8, 1, 7, 4, 2, 5, 3, 6], [2, 6, 5, 3, 7, 1, 8, 5], [6, 7, 8, 5, 1, 4, 5, 2], [3, 8, 4, 6, 5, 2, 1, 7], [5, 2, 1, 7, 6, 8, 4, 3], [4, 3, 2, 1, 4, 7, 6, 5]]) == False\n assert candidate(matrix = [[4, 3, 2, 1], [1, 2, 3, 4], [2, 4, 1, 3], [3, 1, 4, 2]]) == True\n assert candidate(matrix = [[7, 2, 5, 3, 8, 9, 4, 6, 1], [6, 4, 9, 1, 7, 5, 3, 2, 8], [1, 8, 3, 6, 4, 2, 5, 7, 9], [8, 9, 4, 5, 6, 7, 2, 1, 3], [5, 6, 7, 8, 9, 3, 1, 4, 2], [3, 1, 2, 4, 5, 6, 8, 9, 7], [2, 7, 6, 9, 1, 4, 9, 3, 5], [4, 5, 8, 2, 3, 1, 6, 7, 9], [9, 3, 1, 7, 2, 8, 4, 5, 6]]) == False\n assert candidate(matrix = [[4, 3, 2, 1], [3, 2, 1, 4], [2, 1, 4, 3], [1, 4, 3, 2]]) == True\n assert candidate(matrix = [[2, 3, 1, 4], [3, 1, 4, 2], [1, 4, 2, 3], [4, 2, 3, 1]]) == True\n assert candidate(matrix = [[7, 3, 5, 1, 6, 2, 4], [4, 6, 2, 5, 3, 7, 1], [1, 2, 4, 7, 1, 5, 3], [5, 4, 3, 6, 7, 1, 2], [3, 1, 6, 2, 4, 5, 7], [2, 7, 1, 4, 5, 3, 6], [6, 5, 7, 3, 2, 4, 1]]) == False\n assert candidate(matrix = [[7, 6, 5, 4, 3, 2, 1], [1, 7, 6, 5, 4, 3, 2], [2, 1, 7, 6, 5, 4, 3], [3, 2, 1, 7, 6, 5, 4], [4, 3, 2, 1, 7, 6, 5], [5, 4, 3, 2, 1, 7, 6], [6, 5, 4, 3, 2, 1, 7]]) == True\n assert candidate(matrix = [[7, 6, 5, 4, 3, 2, 1], [2, 7, 6, 5, 4, 3, 1], [4, 3, 2, 1, 7, 6, 5], [6, 5, 4, 3, 2, 1, 7], [3, 2, 1, 7, 6, 5, 4], [1, 7, 6, 5, 4, 3, 2], [5, 4, 3, 2, 1, 7, 6]]) == False\n assert candidate(matrix = [[2, 3, 1], [3, 1, 2], [1, 2, 3]]) == True\n assert candidate(matrix = [[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], [6, 7, 8, 9, 10, 1, 2, 3, 4, 5], [7, 8, 9, 10, 1, 2, 3, 4, 5, 6], [8, 9, 10, 1, 2, 3, 4, 5, 6, 7], [9, 10, 1, 2, 3, 4, 5, 6, 7, 8], [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) == True\n assert candidate(matrix = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 4, 1, 3], [3, 1, 4, 2]]) == True\n assert candidate(matrix = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]]) == True\n assert candidate(matrix = [[9, 5, 7, 4, 3, 8, 1, 2, 6], [4, 2, 6, 8, 7, 1, 3, 9, 5], [8, 1, 3, 9, 5, 4, 7, 6, 2], [5, 7, 4, 3, 8, 6, 9, 1, 2], [2, 8, 1, 6, 9, 5, 4, 3, 7], [3, 6, 9, 1, 2, 7, 8, 5, 4], [7, 4, 2, 5, 1, 9, 6, 8, 3], [6, 9, 5, 7, 4, 3, 2, 1, 8], [1, 3, 8, 2, 6, 2, 5, 4, 9]]) == False\n assert candidate(matrix = [[2, 3, 1, 4], [1, 4, 2, 3], [3, 1, 4, 2], [4, 2, 3, 1]]) == True\n assert candidate(matrix = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 3, 4, 5, 6, 7, 8, 9, 1], [3, 4, 5, 6, 7, 8, 9, 1, 2], [4, 5, 6, 7, 8, 9, 1, 2, 3], [5, 6, 7, 8, 9, 1, 2, 3, 4], [6, 7, 8, 9, 1, 2, 3, 4, 5], [7, 8, 9, 1, 2, 3, 4, 5, 6], [8, 9, 1, 2, 3, 4, 5, 6, 7], [9, 1, 2, 3, 4, 5, 6, 7, 8]]) == False\n assert candidate(matrix = [[5, 2, 1, 4, 3], [3, 5, 4, 2, 1], [4, 1, 3, 5, 2], [2, 4, 5, 1, 3], [1, 3, 2, 3, 4]]) == False\n assert candidate(matrix = [[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]]) == True\n assert candidate(matrix = [[5, 3, 4, 1, 2], [1, 2, 5, 3, 4], [2, 4, 1, 5, 3], [3, 5, 2, 4, 1], [4, 1, 3, 2, 5]]) == True\n assert candidate(matrix = [[5, 1, 4, 2, 3], [2, 3, 5, 4, 1], [4, 5, 2, 1, 3], [3, 4, 1, 5, 2], [1, 2, 3, 3, 4]]) == False\n assert candidate(matrix = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [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], [6, 7, 8, 9, 10, 1, 2, 3, 4, 5], [7, 8, 9, 10, 1, 2, 3, 4, 5, 6], [8, 9, 10, 1, 2, 3, 4, 5, 6, 7], [9, 10, 1, 2, 3, 4, 5, 6, 7, 8]]) == False\n assert candidate(matrix = [[8, 7, 6, 5, 4, 3, 2, 1], [1, 8, 7, 6, 5, 4, 3, 2], [2, 1, 8, 7, 6, 5, 4, 3], [3, 2, 1, 8, 7, 6, 5, 4], [4, 3, 2, 1, 8, 7, 6, 5], [5, 4, 3, 2, 1, 8, 7, 6], [6, 5, 4, 3, 2, 1, 8, 7], [7, 6, 5, 4, 3, 2, 1, 8]]) == True\n assert candidate(matrix = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 8, 7, 6, 5, 4, 3, 2, 1, 10], [8, 7, 6, 5, 4, 3, 2, 1, 10, 9], [7, 6, 5, 4, 3, 2, 1, 10, 9, 8], [6, 5, 4, 3, 2, 1, 10, 9, 8, 7], [5, 4, 3, 2, 1, 10, 9, 8, 7, 6], [4, 3, 2, 1, 10, 9, 8, 7, 6, 5], [3, 2, 1, 10, 9, 8, 7, 6, 5, 4], [2, 1, 10, 9, 8, 7, 6, 5, 4, 3], [1, 10, 9, 8, 7, 6, 5, 4, 3, 2]]) == True\n assert candidate(matrix = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [9, 8, 7, 6, 5, 4, 3, 2, 1, 10], [8, 7, 6, 5, 4, 3, 2, 1, 10, 9], [7, 6, 5, 4, 3, 2, 1, 10, 9, 8], [6, 5, 4, 3, 2, 1, 10, 9, 8, 7], [5, 4, 3, 2, 1, 10, 9, 8, 7, 6], [4, 3, 2, 1, 10, 9, 8, 7, 6, 5], [3, 2, 1, 10, 9, 8, 7, 6, 5, 4], [2, 1, 10, 9, 8, 7, 6, 5, 4, 3], [1, 10, 9, 8, 7, 6, 5, 4, 3, 2]]) == True\n assert candidate(matrix = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 1, 10, 9, 8, 7, 6, 5, 4, 3], [3, 2, 1, 10, 9, 8, 7, 6, 5, 4], [4, 3, 2, 1, 10, 9, 8, 7, 6, 5], [5, 4, 3, 2, 1, 10, 9, 8, 7, 6], [6, 5, 4, 3, 2, 1, 10, 9, 8, 7], [7, 6, 5, 4, 3, 2, 1, 10, 9, 8], [8, 7, 6, 5, 4, 3, 2, 1, 10, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == False\n assert candidate(matrix = [[9, 3, 1, 4, 2, 6, 8, 7, 5], [6, 7, 2, 1, 9, 5, 3, 4, 8], [1, 4, 8, 6, 3, 7, 2, 5, 9], [8, 5, 9, 7, 4, 2, 6, 1, 3], [4, 2, 6, 8, 5, 3, 1, 9, 7], [7, 1, 3, 9, 6, 4, 5, 8, 2], [5, 8, 4, 2, 1, 9, 7, 3, 6], [2, 6, 7, 3, 8, 1, 4, 9, 5], [3, 9, 5, 5, 7, 8, 9, 2, 4]]) == False\n assert candidate(matrix = [[9, 7, 5, 2, 6, 8, 3, 1, 4], [4, 3, 1, 7, 9, 5, 8, 2, 6], [6, 8, 2, 4, 1, 3, 7, 9, 5], [3, 5, 9, 6, 7, 1, 2, 4, 8], [8, 2, 4, 9, 5, 7, 6, 3, 1], [1, 6, 7, 3, 8, 4, 9, 5, 2], [5, 9, 6, 1, 2, 8, 4, 7, 3], [7, 4, 8, 5, 3, 9, 1, 6, 2], [2, 1, 3, 8, 4, 6, 5, 7, 9]]) == False\n assert candidate(matrix = [[9, 5, 1, 6, 7, 2, 8, 4, 3], [2, 8, 7, 4, 1, 3, 6, 9, 5], [6, 4, 3, 8, 2, 5, 9, 1, 7], [5, 9, 6, 1, 4, 7, 3, 2, 8], [8, 2, 4, 9, 3, 1, 5, 7, 6], [7, 1, 9, 5, 6, 8, 4, 3, 2], [3, 6, 5, 7, 9, 4, 2, 8, 1], [4, 7, 8, 2, 5, 6, 1, 3, 9], [1, 3, 2, 3, 8, 9, 7, 5, 4]]) == False\n assert candidate(matrix = [[2, 3, 1], [1, 2, 3], [3, 1, 2]]) == True\n assert candidate(matrix = [[7, 5, 6, 4, 3, 2, 1], [1, 7, 5, 6, 4, 3, 2], [2, 1, 7, 5, 6, 4, 3], [3, 2, 1, 7, 5, 6, 4], [4, 3, 2, 1, 7, 5, 6], [5, 4, 3, 2, 1, 7, 5], [6, 5, 4, 3, 2, 1, 7]]) == False\n assert candidate(matrix = [[6, 5, 4, 3, 2, 1], [1, 6, 5, 4, 3, 2], [2, 1, 6, 5, 4, 3], [3, 2, 1, 6, 5, 4], [4, 3, 2, 1, 6, 5], [5, 4, 3, 2, 1, 6]]) == True\n assert candidate(matrix = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]]) == True\n assert candidate(matrix = [[6, 5, 4, 3, 2, 1], [2, 1, 6, 5, 4, 3], [4, 3, 2, 1, 6, 5], [5, 4, 3, 2, 1, 6], [3, 2, 1, 6, 5, 4], [1, 6, 5, 4, 3, 2]]) == True\n assert candidate(matrix = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 10, 9, 8, 7, 6, 5, 4, 3, 2], [2, 1, 10, 9, 8, 7, 6, 5, 4, 3], [3, 2, 1, 10, 9, 8, 7, 6, 5, 4], [4, 3, 2, 1, 10, 9, 8, 7, 6, 5], [5, 4, 3, 2, 1, 10, 9, 8, 7, 6], [6, 5, 4, 3, 2, 1, 10, 9, 8, 7], [7, 6, 5, 4, 3, 2, 1, 10, 9, 8], [8, 7, 6, 5, 4, 3, 2, 1, 10, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]]) == True\n assert candidate(matrix = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 1, 5, 4], [4, 5, 2, 1, 3], [3, 1, 4, 3, 2]]) == False\n assert candidate(matrix = [[2, 3, 1, 5, 4], [4, 1, 5, 2, 3], [5, 4, 2, 3, 1], [1, 5, 3, 4, 2], [3, 2, 4, 1, 5]]) == True\n assert candidate(matrix = [[5, 3, 4, 1, 2], [2, 1, 5, 3, 4], [4, 5, 3, 2, 1], [1, 4, 2, 5, 3], [3, 2, 1, 4, 5]]) == True\n assert candidate(matrix = [[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], [5, 4, 3, 2, 1, 9, 8, 7, 6], [4, 3, 2, 1, 9, 8, 7, 6, 5], [3, 2, 1, 9, 8, 7, 6, 5, 4], [2, 1, 9, 8, 7, 6, 5, 4, 3], [1, 9, 8, 7, 6, 5, 4, 3, 2]]) == True\n assert candidate(matrix = [[1, 2, 3, 4], [3, 4, 1, 2], [2, 1, 4, 3], [4, 3, 2, 1]]) == True\n assert candidate(matrix = [[1, 2, 3], [2, 1, 3], [3, 2, 1]]) == False\n assert candidate(matrix = [[5, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3]]) == True\n assert candidate(matrix = [[9, 3, 7, 1, 2, 8, 5, 6, 4], [5, 8, 4, 7, 6, 2, 3, 9, 1], [6, 1, 2, 5, 9, 3, 4, 7, 8], [7, 4, 9, 2, 5, 6, 1, 3, 8], [8, 6, 5, 9, 3, 1, 7, 4, 2], [2, 7, 3, 6, 4, 8, 9, 1, 5], [1, 5, 6, 8, 7, 9, 2, 4, 3], [3, 9, 1, 4, 2, 5, 8, 6, 7], [4, 2, 8, 3, 1, 7, 6, 5, 9]]) == False\n assert candidate(matrix = [[1, 2, 3], [2, 1, 3], [3, 1, 2]]) == False\n assert candidate(matrix = [[10, 6, 3, 7, 5, 9, 1, 2, 4, 8], [7, 4, 1, 5, 9, 2, 6, 3, 8, 10], [1, 9, 2, 6, 3, 8, 10, 4, 5, 7], [4, 5, 9, 1, 2, 6, 8, 7, 10, 3], [6, 8, 5, 4, 7, 3, 2, 1, 9, 10], [2, 3, 10, 8, 6, 4, 5, 9, 7, 1], [8, 2, 7, 9, 4, 1, 3, 10, 6, 5], [9, 7, 6, 3, 1, 5, 10, 2, 4, 8], [5, 1, 8, 10, 3, 7, 4, 6, 1, 9], [3, 10, 4, 2, 8, 9, 7, 5, 2, 6]]) == False\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[3,1,2],[2,3,1]]", "[[1,1,1],[1,2,3],[1,2,3]]"], "hints": ["Use for loops to check each row for every number from 1 to n. Similarly, do the same for each column.", "For each check, you can keep a set of the unique elements in the checked row/col. By the end of the check, the size of the set should be n."], "metadata": {"canonical_parameter_names": ["matrix"], "leetcode_dataset_entry_point": "Solution().checkValid", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:18+00:00", "tests_total": 57, "tests_dropped": 6, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "matrix"]}, "language": "php", "interface": {"raw_signature": "function checkValid($matrix) {", "container": "Solution", "callable": "checkValid", "parameters": [{"name": "matrix", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2134, "task_id": "minimum-swaps-to-group-all-1s-together-ii", "difficulty": "Medium", "problem_description": "A swap is defined as taking two distinct positions in an array and swapping the values in them.\n\nA circular array is defined as an array where we consider the first element and the last element to be adjacent.\n\nGiven a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.\n\nExample 1:\n\nInput: nums = [0,1,0,1,1,0,0]\nOutput: 1\nExplanation: Here are a few of the ways to group all the 1's together:\n[0,0,1,1,1,0,0] using 1 swap.\n[0,1,1,1,0,0,0] using 1 swap.\n[1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).\nThere is no way to group all 1's together with 0 swaps.\nThus, the minimum number of swaps required is 1.\n\nExample 2:\n\nInput: nums = [0,1,1,1,0,0,1,1,0]\nOutput: 2\nExplanation: Here are a few of the ways to group all the 1's together:\n[1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).\n[1,1,1,1,1,0,0,0,0] using 2 swaps.\nThere is no way to group all 1's together with 0 or 1 swaps.\nThus, the minimum number of swaps required is 2.\n\nExample 3:\n\nInput: nums = [1,1,0,0,1]\nOutput: 0\nExplanation: All the 1's are already grouped together due to the circular property of the array.\nThus, the minimum number of swaps required is 0.\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 = [1, 0, 0, 0, 1, 1, 1, 0, 0, 1]) == 2\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0]) == 2\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1]) == 0\n assert candidate(nums = [0, 1, 0, 1, 1, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1]) == 2\n assert candidate(nums = [1, 1, 0, 0, 1]) == 0\n assert candidate(nums = [1, 0, 0, 1, 0, 1]) == 1\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 = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 1, 1, 1, 0, 0, 1, 1, 0]) == 2\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 0, 1, 0]) == 1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0]) == 3\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1]) == 2\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\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]) == 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\n assert candidate(nums = [0, 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, 0]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1]) == 2\n assert candidate(nums = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0]) == 4\n assert candidate(nums = [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]) == 7\n assert candidate(nums = [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, 0]) == 6\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1]) == 2\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]) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 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]) == 5\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 4\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]) == 5\n assert candidate(nums = [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, 0, 0, 0, 0, 0, 0]) == 0\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, 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]) == 9\n assert candidate(nums = [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0]) == 4\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\n assert candidate(nums = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]) == 4\n assert candidate(nums = [1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1]) == 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, 0, 1, 0, 1, 0, 1]) == 7\n assert candidate(nums = [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]) == 5\n assert candidate(nums = [1, 1, 1, 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]) == 8\n assert candidate(nums = [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0]) == 5\n assert candidate(nums = [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) == 3\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, 0, 0]) == 0\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]) == 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, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 10\n assert candidate(nums = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 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, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == 7\n assert candidate(nums = [1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 3\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]) == 0\n assert candidate(nums = [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, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]) == 6\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) == 3\n assert candidate(nums = [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\n assert candidate(nums = [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]) == 7\n assert candidate(nums = [1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1]) == 10\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]) == 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\n assert candidate(nums = [1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1]) == 4\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0]) == 0\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]) == 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, 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\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 3\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, 0, 1, 1, 1]) == 0\n assert candidate(nums = [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]) == 5\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]) == 5\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]) == 4\n assert candidate(nums = [1, 1, 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]) == 6\n assert candidate(nums = [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1]) == 1\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]) == 0\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, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 5\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) == 3\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, 1, 1, 0, 0, 1, 1]) == 8\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\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]) == 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, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 17\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]) == 3\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]) == 0\n assert candidate(nums = [0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0]) == 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]) == 6\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 2\n assert candidate(nums = [1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 3\n assert candidate(nums = [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]) == 0\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]) == 5\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == 4\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0]) == 5\n assert candidate(nums = [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\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == 0\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]) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 4\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 5\n assert candidate(nums = [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\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0]) == 4\n assert candidate(nums = [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1]) == 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, 0, 1, 0, 1, 0, 1, 0]) == 8\n assert candidate(nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]) == 3\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]) == 0\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == 3\n", "comparison": "exact"}, "public_tests": ["[0,1,0,1,1,0,0]", "[0,1,1,1,0,0,1,1,0]", "[1,1,0,0,1]"], "hints": ["Notice that the number of 1’s to be grouped together is fixed. It is the number of 1's the whole array has.", "Call this number total. We should then check for every subarray of size total (possibly wrapped around), how many swaps are required to have the subarray be all 1’s.", "The number of swaps required is the number of 0’s in the subarray.", "To eliminate the circular property of the array, we can append the original array to itself. Then, we check each subarray of length total.", "How do we avoid recounting the number of 0’s in the subarray each time? The Sliding Window technique can help."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minSwaps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:20+00:00", "tests_total": 117, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function minSwaps($nums) {", "container": "Solution", "callable": "minSwaps", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2135, "task_id": "count-words-obtained-after-adding-a-letter", "difficulty": "Medium", "problem_description": "You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.\n\nFor each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords.\n\nThe conversion operation is described in the following two steps:\n\n1. Append any lowercase letter that is not present in the string to its end.\n - For example, if the string is \"abc\", the letters 'd', 'e', or 'y' can be added to it, but not 'a'. If 'd' is added, the resulting string will be \"abcd\".\n2. Rearrange the letters of the new string in any arbitrary order.\n - For example, \"abcd\" can be rearranged to \"acbd\", \"bacd\", \"cbda\", and so on. Note that it can also be rearranged to \"abcd\" itself.\n\nReturn the number of strings in targetWords that can be obtained by performing the operations on any string of startWords.\n\nNote that you will only be verifying if the string in targetWords can be obtained from a string in startWords by performing the operations. The strings in startWords do not actually change during this process.\n\nExample 1:\n\nInput: startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]\nOutput: 2\nExplanation:\n- In order to form targetWords[0] = \"tack\", we use startWords[1] = \"act\", append 'k' to it, and rearrange \"actk\" to \"tack\".\n- There is no string in startWords that can be used to obtain targetWords[1] = \"act\".\n Note that \"act\" does exist in startWords, but we must append one letter to the string before rearranging it.\n- In order to form targetWords[2] = \"acti\", we use startWords[1] = \"act\", append 'i' to it, and rearrange \"acti\" to \"acti\" itself.\n\nExample 2:\n\nInput: startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]\nOutput: 1\nExplanation:\n- In order to form targetWords[0] = \"abc\", we use startWords[0] = \"ab\", add 'c' to it, and rearrange it to \"abc\".\n- There is no string in startWords that can be used to obtain targetWords[1] = \"abcd\".\n\nConstraints:\n\n- 1 <= startWords.length, targetWords.length <= 5 * 10^4\n- 1 <= startWords[i].length, targetWords[j].length <= 26\n- Each string of startWords and targetWords consists of lowercase English letters only.\n- No letter occurs more than once in any string of startWords or targetWords.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(startWords = ['ant', 'act', 'tack'],targetWords = ['tack', 'act', 'acti']) == 2\n assert candidate(startWords = ['ab', 'a'],targetWords = ['abc', 'abcd']) == 1\n assert candidate(startWords = ['pqrst', 'vwxyz', 'abcdef'],targetWords = ['qrstuvw', 'vwxyzab', 'abcdefg', 'pqrstuv', 'mnopqr']) == 1\n assert candidate(startWords = ['python', 'java', 'c'],targetWords = ['pythonx', 'javaz', 'cb']) == 3\n assert candidate(startWords = ['abcdexyz', 'mnopqr', 'stuv'],targetWords = ['abcdexyzw', 'mnopqrs', 'stuvq']) == 3\n assert candidate(startWords = ['python', 'java', 'csharp'],targetWords = ['pythonic', 'javacoffee', 'csharptool', 'pythonjava', 'javacsharp']) == 0\n assert candidate(startWords = ['abc', 'def', 'ghi', 'jkl', 'mno'],targetWords = ['abcd', 'abce', 'abcf', 'abck', 'abcm']) == 5\n assert candidate(startWords = ['xyz', 'uvw', 'rst'],targetWords = ['xyza', 'uvwq', 'rstv', 'rstw']) == 4\n assert candidate(startWords = ['abcd', 'bcde', 'cdef'],targetWords = ['abcde', 'bcdefg', 'abcdef', 'bcd']) == 1\n assert candidate(startWords = ['a', 'bc', 'def', 'ghij', 'klmno'],targetWords = ['ab', 'bcd', 'cdef', 'defgh', 'efghij', 'fghijk']) == 3\n assert candidate(startWords = ['abcde', 'fghij', 'klmno'],targetWords = ['bcdef', 'ghijk', 'klmnoa', 'mnopqr', 'stuvwx']) == 1\n assert candidate(startWords = ['hello', 'world', 'abc'],targetWords = ['helloa', 'worldb', 'abcd']) == 3\n assert candidate(startWords = ['mnopqr', 'stuvwx', 'yzabcd'],targetWords = ['mnopqrs', 'stuvwxy', 'yzabcde', 'mnopqrst', 'stuvwxyz', 'yzabcdef', 'mnopqrstuv', 'stuvwxyzab', 'yzabcdefg', 'mnopqrstu', 'stuvwxyzabc', 'yzabcdefg', 'mnopqrstuvw', 'stuvwxyzabcd', 'yzabcdefgh', 'mnopqrstuvwx', 'stuvwxyzabcde', 'yzabcdefgij', 'mnopqrstuvwxy', 'stuvwxyzabcdef', 'yzabcdefgijk']) == 3\n assert candidate(startWords = ['xyz', 'uvw', 'qrst'],targetWords = ['xyza', 'uvwxy', 'qrstuv', 'qrstuvw', 'uvwq']) == 2\n assert candidate(startWords = ['mnopqr', 'stuvwx', 'yzabcd', 'efghij', 'klmno'],targetWords = ['mnopqrs', 'stuvwxy', 'yzabcdx', 'efghijk', 'klmnop', 'abcdefgh']) == 5\n assert candidate(startWords = ['abc', 'def', 'ghi'],targetWords = ['abcd', 'abcf', 'defg', 'ghij']) == 4\n assert candidate(startWords = ['abc', 'def', 'ghi'],targetWords = ['abcd', 'efg', 'hij', 'defg', 'ghik']) == 3\n assert candidate(startWords = ['xyz', 'mnop', 'qrst'],targetWords = ['xyzw', 'mnopq', 'qrstuvw']) == 2\n assert candidate(startWords = ['a', 'b', 'c', 'd'],targetWords = ['ab', 'bc', 'cd', 'da', 'abc', 'bcd', 'cda', 'dab']) == 4\n assert candidate(startWords = ['abcdefghij', 'klmnopqr', 'stuvwxyz'],targetWords = ['abcdefghijk', 'klmnopqrs', 'stuvwxyzab', 'abcdefghijl', 'klmnopqrt', 'stuvwxyzabc', 'abcdefghijm', 'klmnopqru', 'stuvwxyzabcd', 'abcdefghijn', 'klmnopqrv', 'stuvwxyzabcde', 'abcdefghijo', 'klmnopqrw', 'stuvwxyzabcdef', 'abcdefghijp', 'klmnopqrx', 'stuvwxyzabcdefg', 'abcdefghirq', 'klmnopqry', 'stuvwxyzabcdefgh', 'abcdefghirs', 'klmnopqrz', 'stuvwxyzabcdefghi', 'abcdefghirt', 'klmnopqs', 'stuvwxyzabcdefghij', 'abcdefghiru', 'klmnopqt', 'stuvwxyzabcdefghijk', 'abcdefghirv', 'klmnopqu', 'stuvwxyzabcdefghijl', 'abcdefghirw', 'klmnopqv', 'stuvwxyzabcdefghijm', 'abcdefghirx', 'klmnopqw', 'stuvwxyzabcdefghijn', 'abcdefghiry', 'klmnopqx', 'stuvwxyzabcdefghijo', 'abcdefghirz', 'klmnopqy', 'stuvwxyzabcdefghijp', 'klmnopqz', 'stuvwxyzabcdefghirq']) == 14\n assert candidate(startWords = ['quick', 'brown', 'fox'],targetWords = ['quicks', 'brownf', 'foxj', 'quickm', 'brownx']) == 5\n assert candidate(startWords = ['a', 'b', 'c'],targetWords = ['ab', 'bc', 'ca', 'abc', 'abcd']) == 3\n assert candidate(startWords = ['abc', 'def', 'ghi'],targetWords = ['abcd', 'efg', 'ghij']) == 2\n assert candidate(startWords = ['zebra', 'dog', 'cat'],targetWords = ['zebrao', 'doge', 'taco']) == 3\n assert candidate(startWords = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],targetWords = ['ab', 'bc', 'cd', 'de', 'ef', 'fg', 'gh', 'ha']) == 8\n assert candidate(startWords = ['abcdefgh', 'ijklmnop', 'qrstuvwxyz'],targetWords = ['abcdefghi', 'ijklmnopq', 'qrstuvwxyzx', 'abcdefghjkl', 'ijklmnopqr']) == 2\n assert candidate(startWords = ['xyz', 'abc', 'uvw', 'def', 'ghi'],targetWords = ['xyzab', 'uvwxy', 'defgh', 'abcdef', 'mnopq']) == 0\n assert candidate(startWords = ['pqr', 'stu', 'vwx'],targetWords = ['pqrs', 'stuv', 'vwxy', 'pqrst', 'stuvw', 'vwxys', 'mnopq']) == 3\n assert candidate(startWords = ['quick', 'brown', 'fox'],targetWords = ['quickly', 'brownly', 'foxes', 'quickbrown', 'brownfox']) == 0\n assert candidate(startWords = ['a', 'b', 'c', 'd'],targetWords = ['ab', 'bc', 'cd', 'abc', 'abcd']) == 3\n assert candidate(startWords = ['aabbcc', 'ddeeff', 'gghhii'],targetWords = ['aabbccx', 'ddeeffx', 'gghhia', 'ddeeffg', 'gghhiih']) == 2\n assert candidate(startWords = ['abc', 'de', 'fgh', 'xyz'],targetWords = ['abcd', 'def', 'efg', 'xyzz']) == 2\n assert candidate(startWords = ['jump', 'over', 'lazy'],targetWords = ['jumpo', 'overj', 'lazyr', 'jumpr', 'overv']) == 4\n assert candidate(startWords = ['mnop', 'qrst', 'uvwx'],targetWords = ['mnopq', 'qrstu', 'vwxyz', 'mnopqr', 'qrstuv']) == 2\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl'],targetWords = ['abcde', 'efghi', 'ijklm', 'abcdx', 'efghy', 'ijklz']) == 6\n assert candidate(startWords = ['hello', 'world', 'abc'],targetWords = ['helloz', 'worldy', 'abcd']) == 3\n assert candidate(startWords = ['mnop', 'qrst', 'uvwx'],targetWords = ['mnopq', 'qrstuv', 'uvwxy', 'mnopqr', 'qrstuvw', 'uvwxzy', 'mnopqrst', 'qrstuvwx', 'uvwxyza', 'mnopqrstuvwxyz']) == 2\n assert candidate(startWords = ['programming', 'is', 'fun'],targetWords = ['programmings', 'isis', 'funny', 'programmingis', 'isfun']) == 0\n assert candidate(startWords = ['jump', 'over', 'lazy'],targetWords = ['jumped', 'overly', 'lazily', 'jumpover', 'overlazy']) == 0\n assert candidate(startWords = ['abcdefghij'],targetWords = ['abcdefghijk', 'abcdefghijl', 'abcdefghijm', 'abcdefghijn', 'abcdefghijo', 'abcdefghijp', 'abcdefghijq', 'abcdefghijr', 'abcdefghjis', 'abcdefghijt', 'abcdefghiju', 'abcdefghijv', 'abcdefghijw', 'abcdefghijx', 'abcdefghijy', 'abcdefghijz']) == 16\n assert candidate(startWords = ['abc', 'bcd', 'efg'],targetWords = ['abcd', 'bcde', 'efgh']) == 3\n assert candidate(startWords = ['zebra', 'panda', 'giraffe'],targetWords = ['zebrac', 'pandaf', 'giraffeb', 'zebrad', 'pandaq']) == 5\n assert candidate(startWords = ['jump', 'over', 'lazy'],targetWords = ['jumper', 'overt', 'lazier']) == 1\n assert candidate(startWords = ['a', 'b', 'c'],targetWords = ['ab', 'bc', 'ca', 'abc', 'abcd', 'abcde']) == 3\n assert candidate(startWords = ['xyz', 'wxy', 'uvw'],targetWords = ['xyza', 'wxyb', 'uvwz', 'uvwxy']) == 3\n assert candidate(startWords = ['abcdefgh', 'ijklmnop', 'qrstuvwxyz', 'abcxyz', 'uvwxy'],targetWords = ['abcdefghi', 'ijklmnopq', 'qrstuvwxyzx', 'abcxyzw', 'uvwxyza', 'mnopqrstu']) == 3\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl'],targetWords = ['abcde', 'efghi', 'jklmn', 'abcd']) == 2\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl'],targetWords = ['abcde', 'efghi', 'ijklm', 'mnop']) == 3\n assert candidate(startWords = ['xyz', 'uvw', 'rst'],targetWords = ['xyza', 'uvwq', 'rstu', 'rstuv']) == 3\n assert candidate(startWords = ['abc', 'def', 'ghi'],targetWords = ['abcd', 'defg', 'ghij', 'hijk', 'mnop', 'qrst', 'uvw', 'xyz']) == 3\n assert candidate(startWords = ['quick', 'brown', 'fox'],targetWords = ['quickly', 'brownie', 'foxy', 'quicklybrown', 'brownief', 'quickbrown', 'quickfox', 'brownfox']) == 1\n assert candidate(startWords = ['quick', 'brown', 'fox'],targetWords = ['quickly', 'brownish', 'foxy']) == 1\n assert candidate(startWords = ['apple', 'banana', 'cherry'],targetWords = ['appleb', 'bananac', 'cherryd', 'applef', 'bananag']) == 4\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl'],targetWords = ['abcde', 'efghi', 'ijklm']) == 3\n assert candidate(startWords = ['one', 'two', 'three'],targetWords = ['onet', 'twot', 'threet', 'oneto', 'twoto', 'threeto', 'onetwo', 'twotwo', 'threetwo', 'onetwothree', 'twotwothree', 'threetwothree', 'onetwofour', 'twotwofour', 'threetwofour']) == 1\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl'],targetWords = ['abcde', 'efghi', 'ijklm', 'mnopq']) == 3\n assert candidate(startWords = ['hello', 'world'],targetWords = ['hellow', 'worlds', 'dlrow']) == 2\n assert candidate(startWords = ['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'],targetWords = ['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']) == 26\n assert candidate(startWords = ['pqr', 'stu', 'vwx', 'yz', 'abc'],targetWords = ['pqrs', 'stuv', 'vwxy', 'yzab', 'uvwxy', 'mnopq']) == 3\n assert candidate(startWords = ['abcd', 'efgh', 'ijkl', 'mnop'],targetWords = ['abcde', 'efghi', 'ijklm', 'nopqr']) == 3\n assert candidate(startWords = ['hello', 'world'],targetWords = ['ehllo', 'dlrow', 'owrld', 'helloa', 'worldb']) == 2\n assert candidate(startWords = ['a', 'b', 'c', 'd'],targetWords = ['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']) == 5\n assert candidate(startWords = ['mnopq', 'rstuv', 'wxyz'],targetWords = ['mnopqr', 'rstuvw', 'wxyza', 'mnopqs', 'rstuvx', 'wxyzab', 'mnopqt', 'rstuvy', 'wxyzac', 'mnopqu', 'rstuvz', 'wxyzad', 'mnopqv', 'rstuvw', 'wxyzae']) == 11\n assert candidate(startWords = ['a', 'b', 'c', 'd'],targetWords = ['ab', 'bc', 'cd', 'da']) == 4\n", "comparison": "exact"}, "public_tests": ["[\"ant\",\"act\",\"tack\"]\n[\"tack\",\"act\",\"acti\"]", "[\"ab\",\"a\"]\n[\"abc\",\"abcd\"]"], "hints": ["Which data structure can be used to efficiently check if a string exists in startWords?", "After appending a letter, all letters of a string can be rearranged in any possible way. How can we use this to reduce our search space while checking if a string in targetWords can be obtained from a string in startWords?"], "metadata": {"canonical_parameter_names": ["startWords", "targetWords"], "leetcode_dataset_entry_point": "Solution().wordCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:23+00:00", "tests_total": 68, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "string", "bit-manipulation", "sorting"]}, "language": "php", "interface": {"raw_signature": "function wordCount($startWords, $targetWords) {", "container": "Solution", "callable": "wordCount", "parameters": [{"name": "startWords", "type": "String[]"}, {"name": "targetWords", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2136, "task_id": "earliest-possible-day-of-full-bloom", "difficulty": "Hard", "problem_description": "You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:\n\n- plantTime[i] is the number of full days it takes you to plant the i^th seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total.\n- growTime[i] is the number of full days it takes the i^th seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.\n\nFrom the beginning of day 0, you can plant the seeds in any order.\n\nReturn the earliest possible day where all seeds are blooming.\n\nExample 1:\n\nInput: plantTime = [1,4,3], growTime = [2,3,1]\nOutput: 9\nExplanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\nOne optimal way is:\nOn day 0, plant the 0^th seed. The seed grows for 2 full days and blooms on day 3.\nOn days 1, 2, 3, and 4, plant the 1^st seed. The seed grows for 3 full days and blooms on day 8.\nOn days 5, 6, and 7, plant the 2^nd seed. The seed grows for 1 full day and blooms on day 9.\nThus, on day 9, all the seeds are blooming.\n\nExample 2:\n\nInput: plantTime = [1,2,3,2], growTime = [2,1,2,1]\nOutput: 9\nExplanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\nOne optimal way is:\nOn day 1, plant the 0^th seed. The seed grows for 2 full days and blooms on day 4.\nOn days 0 and 3, plant the 1^st seed. The seed grows for 1 full day and blooms on day 5.\nOn days 2, 4, and 5, plant the 2^nd seed. The seed grows for 2 full days and blooms on day 8.\nOn days 6 and 7, plant the 3^rd seed. The seed grows for 1 full day and blooms on day 9.\nThus, on day 9, all the seeds are blooming.\n\nExample 3:\n\nInput: plantTime = [1], growTime = [1]\nOutput: 2\nExplanation: On day 0, plant the 0^th seed. The seed grows for 1 full day and blooms on day 2.\nThus, on day 2, all the seeds are blooming.\n\nConstraints:\n\n- n == plantTime.length == growTime.length\n- 1 <= n <= 10^5\n- 1 <= plantTime[i], growTime[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(plantTime = [1],growTime = [1]) == 2\n assert candidate(plantTime = [2, 2, 2],growTime = [3, 3, 3]) == 9\n assert candidate(plantTime = [2, 2, 2],growTime = [3, 2, 1]) == 7\n assert candidate(plantTime = [10000, 10000],growTime = [10000, 10000]) == 30000\n assert candidate(plantTime = [1, 1, 1, 1, 1],growTime = [5, 4, 3, 2, 1]) == 6\n assert candidate(plantTime = [3, 2, 1],growTime = [10, 20, 30]) == 31\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(plantTime = [1, 3, 5, 7],growTime = [7, 5, 3, 1]) == 17\n assert candidate(plantTime = [10, 20, 30],growTime = [1, 2, 3]) == 61\n assert candidate(plantTime = [5, 5, 5],growTime = [5, 5, 5]) == 20\n assert candidate(plantTime = [5, 4, 3, 2, 1],growTime = [1, 2, 3, 4, 5]) == 16\n assert candidate(plantTime = [3, 2, 1],growTime = [2, 1, 3]) == 7\n assert candidate(plantTime = [2, 3, 4],growTime = [3, 2, 1]) == 10\n assert candidate(plantTime = [10000, 10000],growTime = [1, 1]) == 20001\n assert candidate(plantTime = [1, 4, 3],growTime = [2, 3, 1]) == 9\n assert candidate(plantTime = [100, 200, 300],growTime = [100, 200, 300]) == 700\n assert candidate(plantTime = [2, 2, 2, 2],growTime = [4, 3, 2, 1]) == 9\n assert candidate(plantTime = [1, 2, 3, 2],growTime = [2, 1, 2, 1]) == 9\n assert candidate(plantTime = [1, 1, 1, 1],growTime = [1, 1, 1, 1]) == 5\n assert candidate(plantTime = [10, 5, 7],growTime = [4, 6, 8]) == 26\n assert candidate(plantTime = [5, 2, 4],growTime = [3, 1, 2]) == 12\n assert candidate(plantTime = [3, 3, 3],growTime = [3, 3, 3]) == 12\n assert candidate(plantTime = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],growTime = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 105\n assert candidate(plantTime = [5, 10, 15, 20],growTime = [20, 15, 10, 5]) == 55\n assert candidate(plantTime = [5, 10, 15, 20],growTime = [20, 15, 10, 5]) == 55\n assert candidate(plantTime = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],growTime = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 101\n assert candidate(plantTime = [100, 200, 300, 400],growTime = [1000, 500, 700, 200]) == 1200\n assert candidate(plantTime = [500, 500, 500, 500, 500],growTime = [500, 500, 500, 500, 500]) == 3000\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1501\n assert candidate(plantTime = [1000, 2000, 3000, 4000, 5000],growTime = [1, 2, 3, 4, 5]) == 15001\n assert candidate(plantTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 101\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 21\n assert candidate(plantTime = [10, 20, 30, 40, 50],growTime = [50, 40, 30, 20, 10]) == 160\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(plantTime = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],growTime = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6]) == 556\n assert candidate(plantTime = [100, 200, 300, 400, 500],growTime = [500, 400, 300, 200, 100]) == 1600\n assert candidate(plantTime = [10, 20, 30, 40, 50],growTime = [5, 10, 15, 20, 25]) == 155\n assert candidate(plantTime = [5, 10, 4, 6, 8],growTime = [10, 2, 7, 4, 5]) == 35\n assert candidate(plantTime = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],growTime = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 35\n assert candidate(plantTime = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16],growTime = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7]) == 122\n assert candidate(plantTime = [5, 4, 1, 3, 2],growTime = [8, 7, 6, 5, 4]) == 19\n assert candidate(plantTime = [5, 3, 8, 6],growTime = [10, 7, 2, 4]) == 24\n assert candidate(plantTime = [1, 3, 5, 7, 9],growTime = [9, 7, 5, 3, 1]) == 26\n assert candidate(plantTime = [5, 4, 3, 2, 1],growTime = [10, 20, 30, 40, 50]) == 51\n assert candidate(plantTime = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60],growTime = [60, 55, 50, 45, 40, 35, 30, 25, 20, 15]) == 390\n assert candidate(plantTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],growTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 551\n assert candidate(plantTime = [7, 5, 9, 3, 6, 4, 8],growTime = [2, 8, 1, 5, 4, 7, 3]) == 43\n assert candidate(plantTime = [100, 200, 150, 300],growTime = [50, 100, 200, 150]) == 800\n assert candidate(plantTime = [5, 3, 8, 6],growTime = [10, 7, 2, 4]) == 24\n assert candidate(plantTime = [10, 5, 7, 3, 8],growTime = [15, 12, 6, 4, 9]) == 37\n assert candidate(plantTime = [7, 6, 5, 4, 3, 2, 1],growTime = [1, 2, 3, 4, 5, 6, 7]) == 29\n assert candidate(plantTime = [10, 5, 15, 20],growTime = [1, 1, 1, 1]) == 51\n assert candidate(plantTime = [5, 10, 3, 1, 4],growTime = [10, 5, 7, 8, 2]) == 25\n assert candidate(plantTime = [5, 1, 8, 3, 2],growTime = [10, 6, 2, 4, 5]) == 21\n assert candidate(plantTime = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 61\n assert candidate(plantTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],growTime = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 560\n assert candidate(plantTime = [500, 400, 300, 200, 100],growTime = [5, 4, 3, 2, 1]) == 1501\n assert candidate(plantTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 121\n assert candidate(plantTime = [100, 50, 75, 25],growTime = [50, 100, 75, 25]) == 275\n assert candidate(plantTime = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],growTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 5510\n assert candidate(plantTime = [1, 1, 1, 1, 1],growTime = [1000, 1000, 1000, 1000, 1000]) == 1005\n assert candidate(plantTime = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],growTime = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 31\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 16\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],growTime = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 211\n assert candidate(plantTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],growTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 110\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],growTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 56\n assert candidate(plantTime = [100, 200, 300, 400, 500],growTime = [1000, 2000, 3000, 4000, 5000]) == 5500\n assert candidate(plantTime = [1000, 2000, 3000, 4000, 5000],growTime = [5000, 4000, 3000, 2000, 1000]) == 16000\n assert candidate(plantTime = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 31\n assert candidate(plantTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(plantTime = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],growTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 105\n assert candidate(plantTime = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],growTime = [9, 7, 3, 8, 5, 3, 8, 2, 9, 4, 6]) == 46\n assert candidate(plantTime = [4, 4, 4, 4, 4, 4, 4, 4],growTime = [1, 2, 3, 4, 5, 6, 7, 8]) == 33\n assert candidate(plantTime = [1, 3, 5, 7, 9],growTime = [9, 7, 5, 3, 1]) == 26\n assert candidate(plantTime = [10, 10, 10, 10, 10],growTime = [20, 20, 20, 20, 20]) == 70\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 10001\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],growTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 110\n assert candidate(plantTime = [1, 1, 1, 1, 1],growTime = [10000, 9999, 9998, 9997, 9996]) == 10001\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 101\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11\n assert candidate(plantTime = [1, 10, 100, 1000, 10000],growTime = [10000, 1000, 100, 10, 1]) == 11112\n assert candidate(plantTime = [100, 200, 300, 400, 500],growTime = [1, 2, 3, 4, 5]) == 1501\n assert candidate(plantTime = [7, 14, 21, 28, 35],growTime = [10, 20, 30, 40, 50]) == 118\n assert candidate(plantTime = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],growTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 110\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],growTime = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 121\n assert candidate(plantTime = [100, 200, 150, 300],growTime = [500, 400, 300, 200]) == 950\n assert candidate(plantTime = [4, 4, 4, 4, 4],growTime = [9, 8, 7, 6, 5]) == 25\n assert candidate(plantTime = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],growTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 56\n assert candidate(plantTime = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],growTime = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 103\n assert candidate(plantTime = [3, 5, 7, 9, 11, 13, 15],growTime = [2, 4, 6, 8, 10, 12, 14]) == 65\n assert candidate(plantTime = [100, 200, 300, 400, 500],growTime = [1, 1, 1, 1, 1]) == 1501\n assert candidate(plantTime = [4, 3, 2, 1, 5, 6, 7, 8, 9, 10],growTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 56\n assert candidate(plantTime = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],growTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 21\n assert candidate(plantTime = [50, 40, 30, 20, 10],growTime = [1, 2, 3, 4, 5]) == 151\n assert candidate(plantTime = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],growTime = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 101\n assert candidate(plantTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],growTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 551\n assert candidate(plantTime = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],growTime = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 560\n assert candidate(plantTime = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],growTime = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(plantTime = [7, 6, 5, 4, 3, 2, 1],growTime = [1, 2, 3, 4, 5, 6, 7]) == 29\n assert candidate(plantTime = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],growTime = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 46\n", "comparison": "exact"}, "public_tests": ["[1,4,3]\n[2,3,1]", "[1,2,3,2]\n[2,1,2,1]", "[1]\n[1]"], "hints": ["List the planting like the diagram above shows, where a row represents the timeline of a seed. A row i is above another row j if the last day planting seed i is ahead of the last day for seed j. Does it have any advantage to spend some days to plant seed j before completely planting seed i?", "No. It does not help seed j but could potentially delay the completion of seed i, resulting in a worse final answer. Remaining focused is a part of the optimal solution.", "Sort the seeds by their growTime in descending order. Can you prove why this strategy is the other part of the optimal solution? Note the bloom time of a seed is the sum of plantTime of all seeds preceding this seed plus the growTime of this seed.", "There is no way to improve this strategy. The seed to bloom last dominates the final answer. Exchanging the planting of this seed with another seed with either a larger or smaller growTime will result in a potentially worse answer."], "metadata": {"canonical_parameter_names": ["plantTime", "growTime"], "leetcode_dataset_entry_point": "Solution().earliestFullBloom", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:26+00:00", "tests_total": 102, "tests_dropped": 1, "flags": ["has_images"], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function earliestFullBloom($plantTime, $growTime) {", "container": "Solution", "callable": "earliestFullBloom", "parameters": [{"name": "plantTime", "type": "Integer[]"}, {"name": "growTime", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2138, "task_id": "divide-a-string-into-groups-of-size-k", "difficulty": "Easy", "problem_description": "A string s can be partitioned into groups of size k using the following procedure:\n\n- The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each element can be a part of exactly one group.\n- For the last group, if the string does not have k characters remaining, a character fill is used to complete the group.\n\nNote that the partition is done so that after removing the fill character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be s.\n\nGiven the string s, the size of each group k and the character fill, return a string array denoting the composition of every group s has been divided into, using the above procedure.\n\nExample 1:\n\nInput: s = \"abcdefghi\", k = 3, fill = \"x\"\nOutput: [\"abc\",\"def\",\"ghi\"]\nExplanation:\nThe first 3 characters \"abc\" form the first group.\nThe next 3 characters \"def\" form the second group.\nThe last 3 characters \"ghi\" form the third group.\nSince all groups can be completely filled by characters from the string, we do not need to use fill.\nThus, the groups formed are \"abc\", \"def\", and \"ghi\".\n\nExample 2:\n\nInput: s = \"abcdefghij\", k = 3, fill = \"x\"\nOutput: [\"abc\",\"def\",\"ghi\",\"jxx\"]\nExplanation:\nSimilar to the previous example, we are forming the first three groups \"abc\", \"def\", and \"ghi\".\nFor the last group, we can only use the character 'j' from the string. To complete this group, we add 'x' twice.\nThus, the 4 groups formed are \"abc\", \"def\", \"ghi\", and \"jxx\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of lowercase English letters only.\n- 1 <= k <= 100\n- fill is a lowercase English letter.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghij\",k = 3,fill = \"x\") == ['abc', 'def', 'ghi', 'jxx']\n assert candidate(s = \"abcdefg\",k = 2,fill = \"z\") == ['ab', 'cd', 'ef', 'gz']\n assert candidate(s = \"abcdefghi\",k = 3,fill = \"x\") == ['abc', 'def', 'ghi']\n assert candidate(s = \"a\",k = 1,fill = \"y\") == ['a']\n assert candidate(s = \"python\",k = 6,fill = \"q\") == ['python']\n assert candidate(s = \"programming\",k = 1,fill = \"a\") == ['p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']\n assert candidate(s = \"hello\",k = 2,fill = \"q\") == ['he', 'll', 'oq']\n assert candidate(s = \"abc\",k = 5,fill = \"z\") == ['abczz']\n assert candidate(s = \"a\",k = 5,fill = \"y\") == ['ayyyy']\n assert candidate(s = \"boundarycase\",k = 8,fill = \"b\") == ['boundary', 'casebbbb']\n assert candidate(s = \"thisisaverylongstring\",k = 5,fill = \"p\") == ['thisi', 'saver', 'ylong', 'strin', 'gpppp']\n assert candidate(s = \"abcdexyz\",k = 2,fill = \"g\") == ['ab', 'cd', 'ex', 'yz']\n assert candidate(s = \"repeatedcharacters\",k = 7,fill = \"e\") == ['repeate', 'dcharac', 'terseee']\n assert candidate(s = \"interview\",k = 2,fill = \"z\") == ['in', 'te', 'rv', 'ie', 'wz']\n assert candidate(s = \"abcdefg\",k = 7,fill = \"z\") == ['abcdefg']\n assert candidate(s = \"abcdefghijk\",k = 5,fill = \"m\") == ['abcde', 'fghij', 'kmmmm']\n assert candidate(s = \"abcdef\",k = 8,fill = \"n\") == ['abcdefnn']\n assert candidate(s = \"programming\",k = 3,fill = \"a\") == ['pro', 'gra', 'mmi', 'nga']\n assert candidate(s = \"complexstringwithfill\",k = 9,fill = \"r\") == ['complexst', 'ringwithf', 'illrrrrrr']\n assert candidate(s = \"abcd\",k = 5,fill = \"t\") == ['abcdt']\n assert candidate(s = \"almostfill\",k = 9,fill = \"l\") == ['almostfil', 'lllllllll']\n assert candidate(s = \"partitioning\",k = 3,fill = \"z\") == ['par', 'tit', 'ion', 'ing']\n assert candidate(s = \"abcdefgxyz\",k = 1,fill = \"m\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z']\n assert candidate(s = \"abcdefg\",k = 1,fill = \"d\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n assert candidate(s = \"hello\",k = 4,fill = \"o\") == ['hell', 'oooo']\n assert candidate(s = \"abcdefghijabcdefghij\",k = 11,fill = \"c\") == ['abcdefghija', 'bcdefghijcc']\n assert candidate(s = \"repeatthispattern\",k = 8,fill = \"m\") == ['repeatth', 'ispatter', 'nmmmmmmm']\n assert candidate(s = \"ab\",k = 2,fill = \"l\") == ['ab']\n assert candidate(s = \"example\",k = 2,fill = \"z\") == ['ex', 'am', 'pl', 'ez']\n assert candidate(s = \"fill\",k = 1,fill = \"f\") == ['f', 'i', 'l', 'l']\n assert candidate(s = \"thisisaverylongstringthatneedstobedivided\",k = 5,fill = \"a\") == ['thisi', 'saver', 'ylong', 'strin', 'gthat', 'needs', 'tobed', 'ivide', 'daaaa']\n assert candidate(s = \"abcdefghijk\",k = 1,fill = \"m\") == ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']\n assert candidate(s = \"short\",k = 5,fill = \"q\") == ['short']\n assert candidate(s = \"thisisaverylongstring\",k = 5,fill = \"m\") == ['thisi', 'saver', 'ylong', 'strin', 'gmmmm']\n assert candidate(s = \"abcdefghij\",k = 2,fill = \"w\") == ['ab', 'cd', 'ef', 'gh', 'ij']\n assert candidate(s = \"hello\",k = 4,fill = \"p\") == ['hell', 'oppp']\n assert candidate(s = \"almostfullgroup\",k = 10,fill = \"a\") == ['almostfull', 'groupaaaaa']\n assert candidate(s = \"qwen\",k = 2,fill = \"q\") == ['qw', 'en']\n assert candidate(s = \"hello\",k = 1,fill = \"b\") == ['h', 'e', 'l', 'l', 'o']\n assert candidate(s = \"abcd\",k = 2,fill = \"p\") == ['ab', 'cd']\n assert candidate(s = \"partitioning\",k = 5,fill = \"p\") == ['parti', 'tioni', 'ngppp']\n assert candidate(s = \"thisisanexample\",k = 3,fill = \"y\") == ['thi', 'sis', 'ane', 'xam', 'ple']\n assert candidate(s = \"abcdefg\",k = 10,fill = \"q\") == ['abcdefgqqq']\n assert candidate(s = \"samecharacter\",k = 2,fill = \"s\") == ['sa', 'me', 'ch', 'ar', 'ac', 'te', 'rs']\n assert candidate(s = \"fillingwithx\",k = 7,fill = \"x\") == ['filling', 'withxxx']\n assert candidate(s = \"longerstring\",k = 6,fill = \"p\") == ['longer', 'string']\n assert candidate(s = \"algorithm\",k = 4,fill = \"m\") == ['algo', 'rith', 'mmmm']\n assert candidate(s = \"xylophone\",k = 6,fill = \"o\") == ['xyloph', 'oneooo']\n assert candidate(s = \"thisisaverylongstringthatneedstobedivided\",k = 5,fill = \"x\") == ['thisi', 'saver', 'ylong', 'strin', 'gthat', 'needs', 'tobed', 'ivide', 'dxxxx']\n assert candidate(s = \"abcdeabcdeabcdea\",k = 4,fill = \"w\") == ['abcd', 'eabc', 'deab', 'cdea']\n assert candidate(s = \"xyz\",k = 1,fill = \"v\") == ['x', 'y', 'z']\n assert candidate(s = \"evenlydivisible\",k = 2,fill = \"q\") == ['ev', 'en', 'ly', 'di', 'vi', 'si', 'bl', 'eq']\n assert candidate(s = \"programming\",k = 3,fill = \"w\") == ['pro', 'gra', 'mmi', 'ngw']\n assert candidate(s = \"boundarycase\",k = 9,fill = \"b\") == ['boundaryc', 'asebbbbbb']\n assert candidate(s = \"onemoretestcase\",k = 6,fill = \"t\") == ['onemor', 'etestc', 'asettt']\n assert candidate(s = \"abcdefg\",k = 3,fill = \"v\") == ['abc', 'def', 'gvv']\n assert candidate(s = \"equalgroups\",k = 5,fill = \"w\") == ['equal', 'group', 'swwww']\n assert candidate(s = \"equalgroups\",k = 3,fill = \"c\") == ['equ', 'alg', 'rou', 'psc']\n assert candidate(s = \"quickbrownfox\",k = 3,fill = \"y\") == ['qui', 'ckb', 'row', 'nfo', 'xyy']\n assert candidate(s = \"abcdef\",k = 7,fill = \"n\") == ['abcdefn']\n assert candidate(s = \"abcdefghij\",k = 4,fill = \"x\") == ['abcd', 'efgh', 'ijxx']\n assert candidate(s = \"abcdef\",k = 7,fill = \"z\") == ['abcdefz']\n assert candidate(s = \"zebra\",k = 1,fill = \"x\") == ['z', 'e', 'b', 'r', 'a']\n assert candidate(s = \"abcdef\",k = 2,fill = \"o\") == ['ab', 'cd', 'ef']\n assert candidate(s = \"thisisalongstring\",k = 4,fill = \"x\") == ['this', 'isal', 'ongs', 'trin', 'gxxx']\n assert candidate(s = \"partitioning\",k = 7,fill = \"f\") == ['partiti', 'oningff']\n assert candidate(s = \"example\",k = 10,fill = \"z\") == ['examplezzz']\n assert candidate(s = \"abcdefghij\",k = 4,fill = \"e\") == ['abcd', 'efgh', 'ijee']\n assert candidate(s = \"programmingisfun\",k = 5,fill = \"a\") == ['progr', 'ammin', 'gisfu', 'naaaa']\n assert candidate(s = \"thisisaverylongstringthatwillneedfilling\",k = 7,fill = \"a\") == ['thisisa', 'verylon', 'gstring', 'thatwil', 'lneedfi', 'llingaa']\n assert candidate(s = \"onetwothreefourfive\",k = 6,fill = \"j\") == ['onetwo', 'threef', 'ourfiv', 'ejjjjj']\n assert candidate(s = \"world\",k = 10,fill = \"c\") == ['worldccccc']\n assert candidate(s = \"xyz\",k = 10,fill = \"a\") == ['xyzaaaaaaa']\n assert candidate(s = \"abcdefgxyz\",k = 4,fill = \"a\") == ['abcd', 'efgx', 'yzaa']\n assert candidate(s = \"abcdefghijk\",k = 4,fill = \"x\") == ['abcd', 'efgh', 'ijkx']\n assert candidate(s = \"partition\",k = 1,fill = \"m\") == ['p', 'a', 'r', 't', 'i', 't', 'i', 'o', 'n']\n assert candidate(s = \"algorithms\",k = 7,fill = \"b\") == ['algorit', 'hmsbbbb']\n assert candidate(s = \"repeatedcharacterstest\",k = 7,fill = \"z\") == ['repeate', 'dcharac', 'terstes', 'tzzzzzz']\n assert candidate(s = \"almostfull\",k = 4,fill = \"i\") == ['almo', 'stfu', 'llii']\n assert candidate(s = \"filler\",k = 11,fill = \"l\") == ['fillerlllll']\n assert candidate(s = \"abcdefghijk\",k = 3,fill = \"n\") == ['abc', 'def', 'ghi', 'jkn']\n assert candidate(s = \"elephants\",k = 3,fill = \"p\") == ['ele', 'pha', 'nts']\n assert candidate(s = \"short\",k = 10,fill = \"p\") == ['shortppppp']\n assert candidate(s = \"abcd\",k = 6,fill = \"w\") == ['abcdww']\n assert candidate(s = \"abcdef\",k = 2,fill = \"x\") == ['ab', 'cd', 'ef']\n assert candidate(s = \"quickbrownfox\",k = 4,fill = \"x\") == ['quic', 'kbro', 'wnfo', 'xxxx']\n assert candidate(s = \"qwert\",k = 10,fill = \"n\") == ['qwertnnnnn']\n assert candidate(s = \"machinelearning\",k = 8,fill = \"d\") == ['machinel', 'earningd']\n assert candidate(s = \"abcdef\",k = 1,fill = \"z\") == ['a', 'b', 'c', 'd', 'e', 'f']\n assert candidate(s = \"short\",k = 10,fill = \"b\") == ['shortbbbbb']\n assert candidate(s = \"programming\",k = 7,fill = \"a\") == ['program', 'mingaaa']\n assert candidate(s = \"datastructure\",k = 5,fill = \"a\") == ['datas', 'truct', 'ureaa']\n assert candidate(s = \"abcdefghijkmnopqrstuvwxyz\",k = 5,fill = \"x\") == ['abcde', 'fghij', 'kmnop', 'qrstu', 'vwxyz']\n assert candidate(s = \"abcdefghijk\",k = 3,fill = \"p\") == ['abc', 'def', 'ghi', 'jkp']\n assert candidate(s = \"divisiblebyk\",k = 2,fill = \"h\") == ['di', 'vi', 'si', 'bl', 'eb', 'yk']\n assert candidate(s = \"qwenassistant\",k = 7,fill = \"a\") == ['qwenass', 'istanta']\n assert candidate(s = \"cloudcomputing\",k = 6,fill = \"c\") == ['cloudc', 'omputi', 'ngcccc']\n assert candidate(s = \"longerstringexample\",k = 6,fill = \"n\") == ['longer', 'string', 'exampl', 'ennnnn']\n assert candidate(s = \"abcdefghijklnm\",k = 4,fill = \"r\") == ['abcd', 'efgh', 'ijkl', 'nmrr']\n assert candidate(s = \"algorithm\",k = 5,fill = \"b\") == ['algor', 'ithmb']\n assert candidate(s = \"quickbrownfox\",k = 3,fill = \"m\") == ['qui', 'ckb', 'row', 'nfo', 'xmm']\n assert candidate(s = \"abcd\",k = 4,fill = \"x\") == ['abcd']\n assert candidate(s = \"almostfull\",k = 8,fill = \"o\") == ['almostfu', 'lloooooo']\n", "comparison": "exact"}, "public_tests": ["\"abcdefghi\"\n3\n\"x\"", "\"abcdefghij\"\n3\n\"x\""], "hints": ["Using the length of the string and k, can you count the number of groups the string can be divided into?", "Try completing each group using characters from the string. If there aren’t enough characters for the last group, use the fill character to complete the group."], "metadata": {"canonical_parameter_names": ["s", "k", "fill"], "leetcode_dataset_entry_point": "Solution().divideString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:30+00:00", "tests_total": 110, "tests_dropped": 7, "flags": [], "topic_tags": ["string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function divideString($s, $k, $fill) {", "container": "Solution", "callable": "divideString", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}, {"name": "fill", "type": "String"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2139, "task_id": "minimum-moves-to-reach-target-score", "difficulty": "Medium", "problem_description": "You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.\n\nIn one move, you can either:\n\n- Increment the current integer by one (i.e., x = x + 1).\n- Double the current integer (i.e., x = 2 * x).\n\nYou can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.\n\nGiven the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.\n\nExample 1:\n\nInput: target = 5, maxDoubles = 0\nOutput: 4\nExplanation: Keep incrementing by 1 until you reach target.\n\nExample 2:\n\nInput: target = 19, maxDoubles = 2\nOutput: 7\nExplanation: Initially, x = 1\nIncrement 3 times so x = 4\nDouble once so x = 8\nIncrement once so x = 9\nDouble again so x = 18\nIncrement once so x = 19\n\nExample 3:\n\nInput: target = 10, maxDoubles = 4\nOutput: 4\nExplanation: Initially, x = 1\nIncrement once so x = 2\nDouble once so x = 4\nIncrement once so x = 5\nDouble again so x = 10\n\nConstraints:\n\n- 1 <= target <= 10^9\n- 0 <= maxDoubles <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(target = 2,maxDoubles = 1) == 1\n assert candidate(target = 6,maxDoubles = 0) == 5\n assert candidate(target = 1000000000,maxDoubles = 100) == 41\n assert candidate(target = 8,maxDoubles = 3) == 3\n assert candidate(target = 100,maxDoubles = 10) == 8\n assert candidate(target = 256,maxDoubles = 8) == 8\n assert candidate(target = 3,maxDoubles = 1) == 2\n assert candidate(target = 3,maxDoubles = 2) == 2\n assert candidate(target = 7,maxDoubles = 1) == 4\n assert candidate(target = 100,maxDoubles = 5) == 8\n assert candidate(target = 10,maxDoubles = 4) == 4\n assert candidate(target = 100,maxDoubles = 0) == 99\n assert candidate(target = 100,maxDoubles = 1) == 50\n assert candidate(target = 5,maxDoubles = 0) == 4\n assert candidate(target = 7,maxDoubles = 0) == 6\n assert candidate(target = 1,maxDoubles = 5) == 0\n assert candidate(target = 1,maxDoubles = 1) == 0\n assert candidate(target = 1,maxDoubles = 10) == 0\n assert candidate(target = 20,maxDoubles = 0) == 19\n assert candidate(target = 19,maxDoubles = 2) == 7\n assert candidate(target = 6,maxDoubles = 1) == 3\n assert candidate(target = 1023,maxDoubles = 10) == 18\n assert candidate(target = 1000000000,maxDoubles = 50) == 41\n assert candidate(target = 8193,maxDoubles = 13) == 14\n assert candidate(target = 4095,maxDoubles = 10) == 22\n assert candidate(target = 32768,maxDoubles = 16) == 15\n assert candidate(target = 123456789,maxDoubles = 30) == 41\n assert candidate(target = 987654321,maxDoubles = 25) == 66\n assert candidate(target = 32767,maxDoubles = 15) == 28\n assert candidate(target = 524288,maxDoubles = 20) == 19\n assert candidate(target = 246813579,maxDoubles = 0) == 246813578\n assert candidate(target = 333333333,maxDoubles = 100) == 43\n assert candidate(target = 8192,maxDoubles = 12) == 13\n assert candidate(target = 15,maxDoubles = 1) == 8\n assert candidate(target = 63,maxDoubles = 3) == 12\n assert candidate(target = 16,maxDoubles = 4) == 4\n assert candidate(target = 255,maxDoubles = 7) == 14\n assert candidate(target = 2,maxDoubles = 2) == 1\n assert candidate(target = 8192,maxDoubles = 13) == 13\n assert candidate(target = 131072,maxDoubles = 18) == 17\n assert candidate(target = 4,maxDoubles = 1) == 2\n assert candidate(target = 131071,maxDoubles = 17) == 32\n assert candidate(target = 8,maxDoubles = 0) == 7\n assert candidate(target = 1,maxDoubles = 0) == 0\n assert candidate(target = 999999999,maxDoubles = 100) == 49\n assert candidate(target = 777777777,maxDoubles = 75) == 46\n assert candidate(target = 95,maxDoubles = 6) == 11\n assert candidate(target = 500,maxDoubles = 9) == 13\n assert candidate(target = 999999999,maxDoubles = 0) == 999999998\n assert candidate(target = 987654321,maxDoubles = 50) == 45\n assert candidate(target = 19,maxDoubles = 1) == 10\n assert candidate(target = 1001,maxDoubles = 10) == 15\n assert candidate(target = 8,maxDoubles = 4) == 3\n assert candidate(target = 16,maxDoubles = 5) == 4\n assert candidate(target = 23,maxDoubles = 3) == 7\n assert candidate(target = 65535,maxDoubles = 16) == 30\n assert candidate(target = 16,maxDoubles = 3) == 4\n assert candidate(target = 31,maxDoubles = 3) == 8\n assert candidate(target = 500000,maxDoubles = 15) == 32\n assert candidate(target = 47,maxDoubles = 5) == 9\n assert candidate(target = 1023,maxDoubles = 0) == 1022\n assert candidate(target = 199999999,maxDoubles = 100) == 46\n assert candidate(target = 500,maxDoubles = 0) == 499\n assert candidate(target = 987654321,maxDoubles = 0) == 987654320\n assert candidate(target = 2048,maxDoubles = 15) == 11\n assert candidate(target = 19,maxDoubles = 3) == 6\n assert candidate(target = 123456789,maxDoubles = 50) == 41\n assert candidate(target = 1023,maxDoubles = 5) == 40\n assert candidate(target = 10000,maxDoubles = 100) == 17\n assert candidate(target = 4,maxDoubles = 2) == 2\n assert candidate(target = 15,maxDoubles = 3) == 6\n assert candidate(target = 23456789,maxDoubles = 20) == 51\n assert candidate(target = 8,maxDoubles = 2) == 3\n assert candidate(target = 4095,maxDoubles = 12) == 22\n assert candidate(target = 11,maxDoubles = 2) == 5\n assert candidate(target = 511,maxDoubles = 8) == 16\n assert candidate(target = 127,maxDoubles = 4) == 14\n assert candidate(target = 1000000,maxDoubles = 0) == 999999\n assert candidate(target = 9,maxDoubles = 1) == 5\n assert candidate(target = 32768,maxDoubles = 15) == 15\n assert candidate(target = 8192,maxDoubles = 0) == 8191\n assert candidate(target = 123456,maxDoubles = 20) == 21\n assert candidate(target = 987654321,maxDoubles = 10) == 964519\n assert candidate(target = 262143,maxDoubles = 18) == 34\n assert candidate(target = 128,maxDoubles = 7) == 7\n assert candidate(target = 131072,maxDoubles = 16) == 17\n assert candidate(target = 1048576,maxDoubles = 21) == 20\n assert candidate(target = 31,maxDoubles = 5) == 8\n assert candidate(target = 987654321,maxDoubles = 45) == 45\n assert candidate(target = 65536,maxDoubles = 17) == 16\n assert candidate(target = 127,maxDoubles = 6) == 12\n assert candidate(target = 2,maxDoubles = 0) == 1\n assert candidate(target = 16,maxDoubles = 0) == 15\n assert candidate(target = 1023,maxDoubles = 9) == 18\n assert candidate(target = 500000000,maxDoubles = 10) == 488291\n assert candidate(target = 25,maxDoubles = 3) == 6\n assert candidate(target = 1024,maxDoubles = 10) == 10\n assert candidate(target = 8191,maxDoubles = 10) == 26\n assert candidate(target = 16384,maxDoubles = 16) == 14\n assert candidate(target = 678901234,maxDoubles = 50) == 45\n assert candidate(target = 7,maxDoubles = 3) == 4\n assert candidate(target = 63,maxDoubles = 5) == 10\n assert candidate(target = 999999999,maxDoubles = 1) == 500000000\n assert candidate(target = 1048575,maxDoubles = 20) == 38\n assert candidate(target = 64,maxDoubles = 6) == 6\n assert candidate(target = 135792468,maxDoubles = 10) == 132623\n assert candidate(target = 8,maxDoubles = 1) == 4\n assert candidate(target = 1048576,maxDoubles = 20) == 20\n assert candidate(target = 123456789,maxDoubles = 25) == 41\n assert candidate(target = 888888888,maxDoubles = 88) == 46\n assert candidate(target = 32,maxDoubles = 5) == 5\n assert candidate(target = 65535,maxDoubles = 0) == 65534\n assert candidate(target = 1000000000,maxDoubles = 1) == 500000000\n assert candidate(target = 16,maxDoubles = 1) == 8\n assert candidate(target = 2047,maxDoubles = 10) == 20\n assert candidate(target = 2048,maxDoubles = 10) == 11\n assert candidate(target = 16,maxDoubles = 2) == 5\n assert candidate(target = 1000,maxDoubles = 10) == 14\n assert candidate(target = 1000000000,maxDoubles = 0) == 999999999\n assert candidate(target = 999999999,maxDoubles = 50) == 49\n assert candidate(target = 65535,maxDoubles = 15) == 30\n assert candidate(target = 7,maxDoubles = 2) == 4\n assert candidate(target = 31,maxDoubles = 4) == 8\n assert candidate(target = 262144,maxDoubles = 19) == 18\n assert candidate(target = 524287,maxDoubles = 19) == 36\n assert candidate(target = 19,maxDoubles = 4) == 6\n assert candidate(target = 268435456,maxDoubles = 28) == 28\n assert candidate(target = 1000000000,maxDoubles = 30) == 41\n assert candidate(target = 512,maxDoubles = 9) == 9\n assert candidate(target = 16383,maxDoubles = 14) == 26\n assert candidate(target = 8973424,maxDoubles = 50) == 32\n", "comparison": "exact"}, "public_tests": ["5\n0", "19\n2", "10\n4"], "hints": ["Solve the opposite problem: start at the given score and move to 1.", "It is better to use the move of the second type once we can to lose more scores fast."], "metadata": {"canonical_parameter_names": ["target", "maxDoubles"], "leetcode_dataset_entry_point": "Solution().minMoves", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:32+00:00", "tests_total": 140, "tests_dropped": 9, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minMoves($target, $maxDoubles) {", "container": "Solution", "callable": "minMoves", "parameters": [{"name": "target", "type": "Integer"}, {"name": "maxDoubles", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2140, "task_id": "solving-questions-with-brainpower", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D integer array questions where questions[i] = [points_i, brainpower_i].\n\nThe array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you points_i points but you will be unable to solve each of the next brainpower_i questions. If you skip question i, you get to make the decision on the next question.\n\n- For example, given questions = [[3, 2], [4, 3], [4, 4], [2, 5]]:\n - If question 0 is solved, you will earn 3 points but you will be unable to solve questions 1 and 2.\n - If instead, question 0 is skipped and question 1 is solved, you will earn 4 points but you will be unable to solve questions 2 and 3.\n\nReturn the maximum points you can earn for the exam.\n\nExample 1:\n\nInput: questions = [[3,2],[4,3],[4,4],[2,5]]\nOutput: 5\nExplanation: The maximum points can be earned by solving questions 0 and 3.\n- Solve question 0: Earn 3 points, will be unable to solve the next 2 questions\n- Unable to solve questions 1 and 2\n- Solve question 3: Earn 2 points\nTotal points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.\n\nExample 2:\n\nInput: questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]\nOutput: 7\nExplanation: The maximum points can be earned by solving questions 1 and 4.\n- Skip question 0\n- Solve question 1: Earn 2 points, will be unable to solve the next 2 questions\n- Unable to solve questions 2 and 3\n- Solve question 4: Earn 5 points\nTotal points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.\n\nConstraints:\n\n- 1 <= questions.length <= 10^5\n- questions[i].length == 2\n- 1 <= points_i, brainpower_i <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(questions = [[5, 10], [10, 5], [15, 1]]) == 15\n assert candidate(questions = [[10, 1], [10, 1], [10, 1], [10, 1], [10, 1]]) == 30\n assert candidate(questions = [[5, 1], [2, 2], [3, 3], [1, 1], [4, 4]]) == 9\n assert candidate(questions = [[1, 5], [2, 3], [3, 2], [4, 1]]) == 4\n assert candidate(questions = [[5, 1], [2, 2], [1, 1]]) == 6\n assert candidate(questions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 6\n assert candidate(questions = [[1, 99], [2, 98], [3, 97], [4, 96], [5, 95]]) == 5\n assert candidate(questions = [[3, 2], [4, 3], [4, 4], [2, 5]]) == 5\n assert candidate(questions = [[100000, 99999], [1, 1], [1, 1], [1, 1], [1, 1]]) == 100000\n assert candidate(questions = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]]) == 3\n assert candidate(questions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 7\n assert candidate(questions = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [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(questions = [[10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10], [90, 10], [100, 10]]) == 100\n assert candidate(questions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == 11\n assert candidate(questions = [[10, 2], [5, 1], [1, 3], [8, 4], [6, 1]]) == 18\n assert candidate(questions = [[50, 4], [30, 1], [20, 2], [10, 3], [5, 5], [1, 6], [2, 7], [3, 8]]) == 53\n assert candidate(questions = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 22\n assert candidate(questions = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 9\n assert candidate(questions = [[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]]) == 230\n assert candidate(questions = [[50000, 10000], [10000, 5000], [5000, 1000], [1000, 500], [500, 100], [100, 50]]) == 50000\n assert candidate(questions = [[100, 100], [200, 99], [300, 98], [400, 97], [500, 96], [600, 95], [700, 94], [800, 93], [900, 92], [1000, 91]]) == 1000\n assert candidate(questions = [[3, 1], [4, 2], [5, 3], [6, 4], [7, 5], [8, 6], [9, 7], [10, 8]]) == 18\n assert candidate(questions = [[100000, 99999], [2, 1], [3, 2], [4, 3], [5, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 100000\n assert candidate(questions = [[1000, 500], [900, 450], [800, 400], [700, 350], [600, 300], [500, 250], [400, 200], [300, 150], [200, 100], [100, 50]]) == 1000\n assert candidate(questions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8]]) == 120\n assert candidate(questions = [[1, 99999], [2, 99998], [3, 99997], [4, 99996], [5, 99995]]) == 5\n assert candidate(questions = [[1, 99999], [2, 99998], [3, 99997], [4, 99996], [5, 99995], [6, 99994], [7, 99993], [8, 99992], [9, 99991], [10, 99990]]) == 10\n assert candidate(questions = [[1, 1], [1, 1], [1, 1], [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(questions = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 10\n assert candidate(questions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 10\n assert candidate(questions = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995], [7, 99994], [8, 99993], [9, 99992], [10, 99991]]) == 10\n assert candidate(questions = [[100, 99], [90, 98], [80, 97], [70, 96], [60, 95], [50, 94], [40, 93], [30, 92], [20, 91], [10, 90]]) == 100\n assert candidate(questions = [[1, 100000], [2, 100000], [3, 100000], [4, 100000], [5, 100000], [6, 100000]]) == 6\n assert candidate(questions = [[1, 99998], [2, 99997], [3, 99996], [4, 99995], [5, 99994], [6, 99993], [7, 99992], [8, 99991], [9, 99990], [10, 99989]]) == 10\n assert candidate(questions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 10\n assert candidate(questions = [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [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(questions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 15\n assert candidate(questions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6]]) == 80\n assert candidate(questions = [[5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1], [5, 1], [3, 1]]) == 50\n assert candidate(questions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12]]) == 19\n assert candidate(questions = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995], [7, 99994], [8, 99993], [9, 99992], [10, 99991]]) == 10\n assert candidate(questions = [[100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1], [100000, 1]]) == 1000000\n assert candidate(questions = [[100, 10], [90, 9], [80, 8], [70, 7], [60, 6], [50, 5], [40, 4], [30, 3], [20, 2], [10, 1]]) == 100\n assert candidate(questions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7]]) == 110\n assert candidate(questions = [[10, 2], [20, 3], [30, 4], [40, 5], [50, 6], [60, 7], [70, 8], [80, 9], [90, 10], [100, 11]]) == 150\n assert candidate(questions = [[10000, 9999], [9999, 9998], [9998, 9997], [9997, 9996], [9996, 9995], [9995, 9994], [9994, 9993], [9993, 9992], [9992, 9991], [9991, 9990]]) == 10000\n assert candidate(questions = [[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]]) == 4\n assert candidate(questions = [[20, 3], [15, 2], [10, 5], [5, 1], [1, 1], [2, 2], [3, 3]]) == 24\n assert candidate(questions = [[1, 10], [10, 1], [100, 10], [1000, 100], [10000, 1000], [100000, 10000]]) == 100010\n", "comparison": "exact"}, "public_tests": ["[[3,2],[4,3],[4,4],[2,5]]", "[[1,1],[2,2],[3,3],[4,4],[5,5]]"], "hints": ["For each question, we can either solve it or skip it. How can we use Dynamic Programming to decide the most optimal option for each problem?", "We store for each question the maximum points we can earn if we started the exam on that question.", "If we skip a question, then the answer for it will be the same as the answer for the next question.", "If we solve a question, then the answer for it will be the points of the current question plus the answer for the next solvable question.", "The maximum of these two values will be the answer to the current question."], "metadata": {"canonical_parameter_names": ["questions"], "leetcode_dataset_entry_point": "Solution().mostPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:35+00:00", "tests_total": 108, "tests_dropped": 59, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function mostPoints($questions) {", "container": "Solution", "callable": "mostPoints", "parameters": [{"name": "questions", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2141, "task_id": "maximum-running-time-of-n-computers", "difficulty": "Hard", "problem_description": "You have n computers. You are given the integer n and a 0-indexed integer array batteries where the i^th battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.\n\nInitially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.\n\nNote that the batteries cannot be recharged.\n\nReturn the maximum number of minutes you can run all the n computers simultaneously.\n\nExample 1:\n\nInput: n = 2, batteries = [3,3,3]\nOutput: 4\nExplanation:\nInitially, insert battery 0 into the first computer and battery 1 into the second computer.\nAfter two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.\nAt the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.\nBy the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.\nWe can run the two computers simultaneously for at most 4 minutes, so we return 4.\n\nExample 2:\n\nInput: n = 2, batteries = [1,1,1,1]\nOutput: 2\nExplanation:\nInitially, insert battery 0 into the first computer and battery 2 into the second computer.\nAfter one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer.\nAfter another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.\nWe can run the two computers simultaneously for at most 2 minutes, so we return 2.\n\nConstraints:\n\n- 1 <= n <= batteries.length <= 10^5\n- 1 <= batteries[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,batteries = [1, 2, 3, 4, 5]) == 1\n assert candidate(n = 4,batteries = [10, 10, 3, 5]) == 3\n assert candidate(n = 2,batteries = [1000000000, 1000000000]) == 1000000000\n assert candidate(n = 2,batteries = [9, 4, 10]) == 11\n assert candidate(n = 3,batteries = [10, 20, 30, 40]) == 30\n assert candidate(n = 3,batteries = [5, 8, 5]) == 5\n assert candidate(n = 10,batteries = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(n = 5,batteries = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 18\n assert candidate(n = 4,batteries = [1, 2, 3, 4, 5]) == 3\n assert candidate(n = 2,batteries = [1, 1, 1, 1]) == 2\n assert candidate(n = 2,batteries = [3, 3, 3]) == 4\n assert candidate(n = 1,batteries = [5]) == 5\n assert candidate(n = 1,batteries = [100]) == 100\n assert candidate(n = 1,batteries = [10]) == 10\n assert candidate(n = 5,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(n = 10,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(n = 3,batteries = [10, 10, 3, 5]) == 8\n assert candidate(n = 3,batteries = [1, 2, 3, 4, 5, 6]) == 7\n assert candidate(n = 3,batteries = [10, 10, 10]) == 10\n assert candidate(n = 5,batteries = [1, 1, 1, 1, 1000000000]) == 1\n assert candidate(n = 3,batteries = [2, 6, 4, 5]) == 5\n assert candidate(n = 4,batteries = [5, 5, 5, 5, 5]) == 6\n assert candidate(n = 5,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(n = 3,batteries = [1, 2, 999999999]) == 1\n assert candidate(n = 2,batteries = [10, 20]) == 10\n assert candidate(n = 2,batteries = [2, 3, 4, 5]) == 7\n assert candidate(n = 3,batteries = [5, 5, 5, 5, 5]) == 8\n assert candidate(n = 4,batteries = [8, 8, 8, 8, 8, 8]) == 12\n assert candidate(n = 10,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 110\n assert candidate(n = 5,batteries = [500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 350\n assert candidate(n = 10,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 11\n assert candidate(n = 4,batteries = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 2500000000\n assert candidate(n = 5,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(n = 15,batteries = [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\n assert candidate(n = 5,batteries = [10, 20, 30, 40, 50, 60]) == 30\n assert candidate(n = 5,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 420\n assert candidate(n = 4,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 13\n assert candidate(n = 10,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 1\n assert candidate(n = 4,batteries = [100, 100, 100, 1]) == 1\n assert candidate(n = 5,batteries = [1000000, 2000000, 3000000, 4000000, 5000000]) == 1000000\n assert candidate(n = 3,batteries = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 70\n assert candidate(n = 3,batteries = [1000000000, 1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 13\n assert candidate(n = 15,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100]) == 3\n assert candidate(n = 2,batteries = [1, 1000000000]) == 1\n assert candidate(n = 5,batteries = [10, 20, 30, 40, 50]) == 10\n assert candidate(n = 10,batteries = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(n = 10,batteries = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 1]) == 50\n assert candidate(n = 3,batteries = [1000000000, 1000000000, 1000000000, 1]) == 1000000000\n assert candidate(n = 6,batteries = [100, 100, 100, 100, 100, 100, 1]) == 100\n assert candidate(n = 7,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1714\n assert candidate(n = 4,batteries = [100, 100, 100, 100, 1, 1, 1, 1]) == 101\n assert candidate(n = 5,batteries = [10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 18\n assert candidate(n = 5,batteries = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 18\n assert candidate(n = 1,batteries = [1000000000]) == 1000000000\n assert candidate(n = 4,batteries = [2, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 16\n assert candidate(n = 2,batteries = [1000000000, 1]) == 1\n assert candidate(n = 4,batteries = [1, 1, 1, 1, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000001\n assert candidate(n = 4,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 52\n assert candidate(n = 8,batteries = [8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(n = 7,batteries = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == 46\n assert candidate(n = 7,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(n = 5,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 110\n assert candidate(n = 10,batteries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(n = 5,batteries = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 2000\n assert candidate(n = 10,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 500\n assert candidate(n = 3,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 108\n assert candidate(n = 6,batteries = [100, 100, 100, 100, 100, 100, 1, 1, 1, 1]) == 100\n assert candidate(n = 8,batteries = [8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 24\n assert candidate(n = 5,batteries = [999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999, 999999999]) == 1999999998\n assert candidate(n = 4,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 13\n assert candidate(n = 5,batteries = [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]) == 125\n assert candidate(n = 3,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(n = 15,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 110\n assert candidate(n = 6,batteries = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == 30\n assert candidate(n = 8,batteries = [50, 40, 30, 20, 10, 5, 3, 1, 2, 4, 6, 8, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 75\n assert candidate(n = 5,batteries = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 200\n assert candidate(n = 8,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(n = 4,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 116\n assert candidate(n = 9,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 23\n assert candidate(n = 3,batteries = [1, 1000000000, 1]) == 1\n assert candidate(n = 3,batteries = [1000, 1000, 1000, 1, 1, 1, 1, 1, 1, 1]) == 1002\n assert candidate(n = 7,batteries = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 85\n assert candidate(n = 2,batteries = [1000000000, 1000000000]) == 1000000000\n assert candidate(n = 5,batteries = [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]) == 250\n assert candidate(n = 3,batteries = [1000000000, 1000000000, 1000000000, 1000000000, 1]) == 1333333333\n assert candidate(n = 5,batteries = [1, 1, 1, 1, 1, 1000]) == 1\n assert candidate(n = 7,batteries = [50, 40, 30, 20, 10, 5, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(n = 8,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 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(n = 5,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1100\n assert candidate(n = 2,batteries = [1000000000, 1000000000, 1000000000, 1000000000]) == 2000000000\n assert candidate(n = 3,batteries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 18\n assert candidate(n = 7,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 70\n assert candidate(n = 4,batteries = [100, 100, 100, 100, 1]) == 100\n assert candidate(n = 6,batteries = [100, 100, 100, 100, 100, 100, 1, 1, 1, 1, 1, 1]) == 101\n assert candidate(n = 10,batteries = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 999999991\n assert candidate(n = 3,batteries = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 30\n assert candidate(n = 10,batteries = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(n = 4,batteries = [1000000000, 1000000000, 1000000000, 1000000000, 1]) == 1000000000\n assert candidate(n = 5,batteries = [10, 20, 30, 40, 50, 60]) == 30\n assert candidate(n = 6,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(n = 3,batteries = [10, 20, 30, 40, 50]) == 50\n assert candidate(n = 10,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 100\n assert candidate(n = 7,batteries = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 14\n assert candidate(n = 6,batteries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 90\n assert candidate(n = 7,batteries = [1, 1, 1, 1, 1, 1, 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(n = 4,batteries = [10, 20, 30, 40, 50]) == 30\n assert candidate(n = 2,batteries = [999999999, 1]) == 1\n assert candidate(n = 6,batteries = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 57\n assert candidate(n = 7,batteries = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 28\n assert candidate(n = 6,batteries = [1000, 2000, 3000, 4000, 5000, 6000]) == 1000\n assert candidate(n = 10,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 1100\n assert candidate(n = 3,batteries = [1000000000, 1000000000, 1000000000, 1000000000]) == 1333333333\n assert candidate(n = 5,batteries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1100\n assert candidate(n = 20,batteries = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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", "comparison": "exact"}, "public_tests": ["2\n[3,3,3]", "2\n[1,1,1,1]"], "hints": ["For a given running time, can you determine if it is possible to run all n computers simultaneously?", "Try to use Binary Search to find the maximal running time"], "metadata": {"canonical_parameter_names": ["n", "batteries"], "leetcode_dataset_entry_point": "Solution().maxRunTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:37+00:00", "tests_total": 114, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxRunTime($n, $batteries) {", "container": "Solution", "callable": "maxRunTime", "parameters": [{"name": "n", "type": "Integer"}, {"name": "batteries", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2144, "task_id": "minimum-cost-of-buying-candies-with-discount", "difficulty": "Easy", "problem_description": "A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.\n\nThe customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.\n\n- For example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they can take the candy with cost 1 for free, but not the candy with cost 4.\n\nGiven a 0-indexed integer array cost, where cost[i] denotes the cost of the i^th candy, return the minimum cost of buying all the candies.\n\nExample 1:\n\nInput: cost = [1,2,3]\nOutput: 5\nExplanation: We buy the candies with costs 2 and 3, and take the candy with cost 1 for free.\nThe total cost of buying all candies is 2 + 3 = 5. This is the only way we can buy the candies.\nNote that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free.\nThe cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.\n\nExample 2:\n\nInput: cost = [6,5,7,9,2,2]\nOutput: 23\nExplanation: The way in which we can get the minimum cost is described below:\n- Buy candies with costs 9 and 7\n- Take the candy with cost 6 for free\n- We buy candies with costs 5 and 2\n- Take the last remaining candy with cost 2 for free\nHence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.\n\nExample 3:\n\nInput: cost = [5,5]\nOutput: 10\nExplanation: Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free.\nHence, the minimum cost to buy all candies is 5 + 5 = 10.\n\nConstraints:\n\n- 1 <= cost.length <= 100\n- 1 <= cost[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(cost = [100]) == 100\n assert candidate(cost = [1, 1, 1, 1, 1, 1]) == 4\n assert candidate(cost = [10, 20, 30, 40, 50]) == 120\n assert candidate(cost = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 663\n assert candidate(cost = [10, 20]) == 30\n assert candidate(cost = [1]) == 1\n assert candidate(cost = [100, 100, 100, 100, 100, 100]) == 400\n assert candidate(cost = [80, 80, 80, 80, 80, 80, 80, 80, 80, 80]) == 560\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(cost = [5, 5]) == 10\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 40\n assert candidate(cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 40\n assert candidate(cost = [3, 2, 1]) == 5\n assert candidate(cost = [1, 2]) == 3\n assert candidate(cost = [1, 2, 3]) == 5\n assert candidate(cost = [6, 5, 7, 9, 2, 2]) == 23\n assert candidate(cost = [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]) == 1483\n assert candidate(cost = [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]) == 2575\n assert candidate(cost = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 700\n assert candidate(cost = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 70\n assert candidate(cost = [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]) == 1700\n assert candidate(cost = [3, 6, 1, 9, 4, 8, 2, 7, 5, 10]) == 40\n assert candidate(cost = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 663\n assert candidate(cost = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 130\n assert candidate(cost = [30, 15, 45, 10, 25, 55, 5, 35, 20, 40, 60, 65, 50, 70, 75, 80, 85, 90, 95, 100, 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]) == 2433\n assert candidate(cost = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6, 93, 7, 92, 8, 91, 9, 90, 10]) == 700\n assert candidate(cost = [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]) == 3333\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(cost = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]) == 350\n assert candidate(cost = [1, 3, 2, 6, 5, 4, 9, 8, 7, 12, 11, 10]) == 56\n assert candidate(cost = [10, 20, 30, 40, 50, 60]) == 160\n assert candidate(cost = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 400\n assert candidate(cost = [3, 6, 1, 8, 2, 7, 4, 5, 9]) == 33\n assert candidate(cost = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 147\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 56\n assert candidate(cost = [100, 1, 100, 2, 100, 3, 100, 4, 100, 5, 100, 6, 100, 7, 100, 8, 100, 9, 100, 10]) == 737\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 40\n assert candidate(cost = [45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) == 315\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(cost = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91]) == 707\n assert candidate(cost = [100, 50, 25, 10, 5, 1, 100, 50, 25, 10, 5, 1]) == 301\n assert candidate(cost = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 760\n assert candidate(cost = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == 17\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]) == 225\n assert candidate(cost = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10]) == 707\n assert candidate(cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\n assert candidate(cost = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 1253\n assert candidate(cost = [33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33]) == 528\n assert candidate(cost = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 84\n assert candidate(cost = [30, 40, 10, 50, 60, 20]) == 160\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 65\n assert candidate(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, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50]) == 2567\n assert candidate(cost = [50, 40, 30, 20, 10, 5, 4, 3, 2, 1]) == 128\n assert candidate(cost = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86]) == 935\n assert candidate(cost = [1, 3, 2, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13]) == 85\n assert candidate(cost = [1, 3, 2, 4, 6, 5, 7, 9, 8, 11, 13, 12, 15, 17, 16, 19, 21, 20, 23, 25, 24, 27, 29, 28, 31, 33, 32, 35, 37, 36, 39, 41, 40, 43, 45, 44, 47, 49, 48, 50]) == 680\n assert candidate(cost = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 1253\n assert candidate(cost = [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]) == 1700\n assert candidate(cost = [45, 30, 10, 20, 50, 60, 15, 25, 35, 40]) == 240\n assert candidate(cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 77\n assert candidate(cost = [100, 100, 100, 99, 99, 99, 98, 98, 98, 97, 97, 97, 96, 96, 96, 95, 95, 95, 94, 94, 94, 93, 93, 93, 92, 92, 92, 91, 91, 91, 90, 90, 90, 89, 89, 89, 88, 88, 88, 87, 87, 87, 86, 86, 86, 85, 85, 85]) == 2960\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, 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]) == 3400\n assert candidate(cost = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11]) == 85\n assert candidate(cost = [30, 10, 20, 40, 50, 60]) == 160\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 147\n assert candidate(cost = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 400\n assert candidate(cost = [30, 10, 40, 20, 50, 60, 70]) == 210\n assert candidate(cost = [45, 30, 75, 60, 90, 15, 10, 5]) == 255\n assert candidate(cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 400\n assert candidate(cost = [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]) == 500\n assert candidate(cost = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 1400\n assert candidate(cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 85\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]) == 320\n assert candidate(cost = [5, 4, 3, 2, 1, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86]) == 947\n assert candidate(cost = [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]) == 3500\n assert candidate(cost = [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]) == 867\n assert candidate(cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 40\n assert candidate(cost = [23, 45, 12, 89, 34, 78, 67, 56, 90, 11]) == 370\n assert candidate(cost = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 70\n assert candidate(cost = [8, 12, 15, 7, 10, 14, 9]) == 55\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 43\n assert candidate(cost = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 50\n assert candidate(cost = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 735\n assert candidate(cost = [42, 23, 65, 12, 89, 34, 78, 56, 90, 21, 33, 55, 77, 66, 88, 44, 55, 66, 77, 88]) == 808\n", "comparison": "exact"}, "public_tests": ["[1,2,3]", "[6,5,7,9,2,2]", "[5,5]"], "hints": ["If we consider costs from high to low, what is the maximum cost of a single candy that we can get for free?", "How can we generalize this approach to maximize the costs of the candies we get for free?", "Can “sorting” the array help us find the minimum cost?"], "metadata": {"canonical_parameter_names": ["cost"], "leetcode_dataset_entry_point": "Solution().minimumCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:41+00:00", "tests_total": 96, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumCost($cost) {", "container": "Solution", "callable": "minimumCost", "parameters": [{"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2145, "task_id": "count-the-hidden-sequences", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].\n\nYou are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain.\n\n- For example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).\n - [3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.\n - [5, 6, 3, 7] is not possible since it contains an element greater than 6.\n - [1, 2, 3, 4] is not possible since the differences are not correct.\n\nReturn the number of possible hidden sequences there are. If there are no possible sequences, return 0.\n\nExample 1:\n\nInput: differences = [1,-3,4], lower = 1, upper = 6\nOutput: 2\nExplanation: The possible hidden sequences are:\n- [3, 4, 1, 5]\n- [4, 5, 2, 6]\nThus, we return 2.\n\nExample 2:\n\nInput: differences = [3,-4,5,1,-2], lower = -4, upper = 5\nOutput: 4\nExplanation: The possible hidden sequences are:\n- [-3, 0, -4, 1, 2, 0]\n- [-2, 1, -3, 2, 3, 1]\n- [-1, 2, -2, 3, 4, 2]\n- [0, 3, -1, 4, 5, 3]\nThus, we return 4.\n\nExample 3:\n\nInput: differences = [4,-7,2], lower = 3, upper = 6\nOutput: 0\nExplanation: There are no possible hidden sequences. Thus, we return 0.\n\nConstraints:\n\n- n == differences.length\n- 1 <= n <= 10^5\n- -10^5 <= differences[i] <= 10^5\n- -10^5 <= lower <= upper <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(differences = [0, 0, 0],lower = 1,upper = 1) == 1\n assert candidate(differences = [5, -5, 5, -5],lower = -10,upper = 10) == 16\n assert candidate(differences = [3, -4, 5, 1, -2],lower = -4,upper = 5) == 4\n assert candidate(differences = [1, -3, 4],lower = 1,upper = 6) == 2\n assert candidate(differences = [-1, -1, -1],lower = -3,upper = 3) == 4\n assert candidate(differences = [-1],lower = -2,upper = -1) == 1\n assert candidate(differences = [-1, -2, -3, -4, -5],lower = -100,upper = 1) == 87\n assert candidate(differences = [100000, -100000, 100000, -100000],lower = -100000,upper = 100000) == 100001\n assert candidate(differences = [10, -5, 15, -10],lower = -10,upper = 10) == 1\n assert candidate(differences = [0, 0, 0],lower = 1,upper = 5) == 5\n assert candidate(differences = [1, 1, 1],lower = -5,upper = -1) == 2\n assert candidate(differences = [100000, -100000],lower = -100000,upper = 100000) == 100001\n assert candidate(differences = [1, 2, 3],lower = 0,upper = 10) == 5\n assert candidate(differences = [-1, -2, -3],lower = -10,upper = 0) == 5\n assert candidate(differences = [10, -10, 10, -10],lower = -5,upper = 5) == 1\n assert candidate(differences = [100000, -100000, 100000],lower = -100000,upper = 100000) == 100001\n assert candidate(differences = [0, 0, 0],lower = 0,upper = 0) == 1\n assert candidate(differences = [1],lower = 1,upper = 2) == 1\n assert candidate(differences = [-1, -2, -3],lower = -5,upper = 5) == 5\n assert candidate(differences = [-1, -1, -1],lower = 1,upper = 5) == 2\n assert candidate(differences = [1, 2, 3, 4, 5],lower = 1,upper = 100) == 85\n assert candidate(differences = [0, 0, 0],lower = 0,upper = 10) == 11\n assert candidate(differences = [4, -7, 2],lower = 3,upper = 6) == 0\n assert candidate(differences = [2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],lower = -15,upper = 15) == 21\n assert candidate(differences = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],lower = -10,upper = 10) == 11\n assert candidate(differences = [2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 0,upper = 100) == 47\n assert candidate(differences = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10],lower = 0,upper = 500) == 0\n assert candidate(differences = [5, 10, 15, 20, 25, 30],lower = 0,upper = 100) == 0\n assert candidate(differences = [1000, -500, 200, -100, 50, -25, 10],lower = -1000,upper = 1000) == 1001\n assert candidate(differences = [-5, -10, -15, -20, -25, -30],lower = -100,upper = 0) == 0\n assert candidate(differences = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],lower = 0,upper = 2) == 2\n assert candidate(differences = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],lower = 10,upper = 60) == 1\n assert candidate(differences = [5, -2, 8, -3, 7],lower = -5,upper = 20) == 11\n assert candidate(differences = [10000, -20000, 30000, -40000, 50000],lower = -100000,upper = 100000) == 150001\n assert candidate(differences = [-1, 2, -1, 2, -1],lower = -10,upper = 10) == 18\n assert candidate(differences = [-1, 0, 1, 0, -1],lower = -5,upper = 5) == 10\n assert candidate(differences = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],lower = -20,upper = -10) == 0\n assert candidate(differences = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],lower = 1,upper = 50) == 20\n assert candidate(differences = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],lower = 0,upper = 1) == 1\n assert candidate(differences = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 0,upper = 10) == 1\n assert candidate(differences = [50000, -50000, 50000, -50000, 50000, -50000, 50000, -50000],lower = -100000,upper = 100000) == 150001\n assert candidate(differences = [-1, 1, -1, 1, -1],lower = 0,upper = 5) == 5\n assert candidate(differences = [10000, -10000, 20000, -20000],lower = -50000,upper = 50000) == 80001\n assert candidate(differences = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],lower = -10,upper = 10) == 11\n assert candidate(differences = [-5, 10, -15, 20, -25],lower = -30,upper = 30) == 36\n assert candidate(differences = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = 5,upper = 5) == 1\n assert candidate(differences = [0, 0, 0, 0, 0],lower = -1,upper = 1) == 3\n assert candidate(differences = [-1, 2, -3, 4, -5, 6, -7, 8],lower = -10,upper = 10) == 13\n assert candidate(differences = [-1, 2, -3, 4, -5, 6, -7],lower = -20,upper = 20) == 34\n assert candidate(differences = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],lower = 0,upper = 100) == 0\n assert candidate(differences = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 1,upper = 1000) == 450\n assert candidate(differences = [5, -2, 3, 7, -4],lower = 1,upper = 20) == 7\n assert candidate(differences = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],lower = -100,upper = 0) == 0\n assert candidate(differences = [5, -5, 5, -5, 5, -5],lower = -10,upper = 10) == 16\n assert candidate(differences = [0, 0, 0, 0, 0],lower = 1,upper = 1) == 1\n assert candidate(differences = [-1, 2, -2, 1, -1],lower = -5,upper = 5) == 9\n assert candidate(differences = [10, 20, 30, 40, 50],lower = 0,upper = 200) == 51\n assert candidate(differences = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 1,upper = 10) == 0\n assert candidate(differences = [50, -25, 75, -37, 100, -50, 125, -62, 150, -75, 175, -87, 200, -93, 225, -100, 250, -112, 275, -125],lower = 0,upper = 300) == 0\n assert candidate(differences = [100000, -100000, 100000, -100000, 100000],lower = -50000,upper = 50000) == 1\n assert candidate(differences = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],lower = -100,upper = 100) == 151\n assert candidate(differences = [1, -1, 1, -1, 1],lower = 1,upper = 5) == 4\n assert candidate(differences = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],lower = -55,upper = -45) == 0\n assert candidate(differences = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],lower = -10,upper = 0) == 0\n assert candidate(differences = [1, 2, -3, 4, -5, 6],lower = 1,upper = 10) == 4\n assert candidate(differences = [100, -50, 200, -100, 50, -200, 100],lower = -1000,upper = 1000) == 1751\n assert candidate(differences = [-1, 1, -1, 1, -1, 1, -1, 1, -1, 1],lower = -1,upper = 1) == 2\n assert candidate(differences = [-1, -2, -3, -4, -5, -6],lower = -15,upper = -5) == 0\n assert candidate(differences = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],lower = -1000,upper = 1) == 452\n assert candidate(differences = [-15, 14, -13, 12, -11, 10, -9, 8, -7, 6, -5, 4, -3, 2, -1],lower = -20,upper = 20) == 26\n assert candidate(differences = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],lower = -10,upper = 10) == 16\n assert candidate(differences = [5, 10, -15, 20, -25],lower = -100,upper = 100) == 176\n assert candidate(differences = [100000, -50000, 50000, -100000, 50000],lower = -100000,upper = 100000) == 100001\n assert candidate(differences = [100, -50, 25, -10, 5],lower = 0,upper = 200) == 101\n assert candidate(differences = [-5, -5, -5, -5, -5, -5, -5, -5, -5, -5],lower = -50,upper = 0) == 1\n assert candidate(differences = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 10,upper = 20) == 0\n assert candidate(differences = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],lower = 100,upper = 1000) == 351\n assert candidate(differences = [5, -2, 3, -4, 1],lower = 1,upper = 10) == 4\n assert candidate(differences = [2, -1, 3, -2, 4, -3, 5, -4],lower = -5,upper = 10) == 8\n assert candidate(differences = [0, 0, 0, 0, 0],lower = 0,upper = 10) == 11\n assert candidate(differences = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],lower = -10,upper = -1) == 0\n assert candidate(differences = [5, -2, 3, -1, 4],lower = -5,upper = 5) == 2\n assert candidate(differences = [100000, -50000, 25000, -12500, 6250, -3125, 1562, -781, 390, -195],lower = 0,upper = 100000) == 1\n assert candidate(differences = [-10, 20, -30, 40, -50, 60],lower = -20,upper = 20) == 0\n assert candidate(differences = [-10, -20, -30, -40, -50],lower = -200,upper = 0) == 51\n assert candidate(differences = [5, 10, -5, -10, 15, -15, 20, -20],lower = -100,upper = 100) == 181\n assert candidate(differences = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],lower = -10,upper = 0) == 1\n assert candidate(differences = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],lower = 0,upper = 50) == 1\n assert candidate(differences = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10],lower = -50,upper = 50) == 91\n assert candidate(differences = [20, -10, 30, -15, 5, -1],lower = -100,upper = 100) == 161\n assert candidate(differences = [2, 3, -2, 1, -3, 2],lower = -5,upper = 15) == 16\n assert candidate(differences = [2, 3, -5, 2, 3, -5],lower = -3,upper = 3) == 2\n assert candidate(differences = [100, -50, 25, -10, 5],lower = -20,upper = 200) == 121\n assert candidate(differences = [-100000, 50000, -50000, 100000, -50000],lower = -100000,upper = 100000) == 100001\n assert candidate(differences = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = -1,upper = 1) == 3\n assert candidate(differences = [1, -1, 1, -1, 1, -1],lower = 1,upper = 5) == 4\n assert candidate(differences = [1, 2, 3, -1, -2, -3, 1, 2, 3, -1, -2, -3],lower = -5,upper = 5) == 5\n assert candidate(differences = [10, -10, 10, -10, 10, -10, 10, -10],lower = 0,upper = 20) == 11\n assert candidate(differences = [10, -20, 30, -40, 50],lower = 5,upper = 15) == 0\n assert candidate(differences = [2, 4, -6, 8, -10, 12, -14],lower = -15,upper = 15) == 17\n assert candidate(differences = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],lower = 0,upper = 10) == 0\n assert candidate(differences = [10, 20, 30, 40, 50],lower = 100,upper = 200) == 0\n assert candidate(differences = [5, -5, 10, -10, 15, -15],lower = -50,upper = 50) == 86\n assert candidate(differences = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],lower = -50,upper = 0) == 0\n assert candidate(differences = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1],lower = -1,upper = 1) == 2\n assert candidate(differences = [5, -2, 8, -6, 3],lower = 2,upper = 12) == 0\n assert candidate(differences = [100, -50, 25, -12, 6, -3, 1],lower = 0,upper = 500) == 401\n assert candidate(differences = [1, 2, 3, 4, 5, 6],lower = 5,upper = 15) == 0\n assert candidate(differences = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],lower = 0,upper = 50) == 0\n assert candidate(differences = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],lower = -10,upper = 10) == 16\n assert candidate(differences = [0, 0, 0, 0, 0],lower = 0,upper = 0) == 1\n assert candidate(differences = [5, -2, 3, -4, 7, -1],lower = -5,upper = 15) == 12\n assert candidate(differences = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],lower = 0,upper = 0) == 1\n assert candidate(differences = [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3],lower = -50,upper = -1) == 20\n assert candidate(differences = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16],lower = -100,upper = 100) == 185\n assert candidate(differences = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15],lower = -50,upper = 50) == 86\n assert candidate(differences = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],lower = -1000,upper = -100) == 351\n assert candidate(differences = [5, -2, 3, 7, -5, 8, -6],lower = -10,upper = 20) == 15\n assert candidate(differences = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10],lower = -5,upper = 5) == 1\n assert candidate(differences = [-1, -2, -3, -4, -5],lower = -15,upper = -5) == 0\n", "comparison": "exact"}, "public_tests": ["[1,-3,4]\n1\n6", "[3,-4,5,1,-2]\n-4\n5", "[4,-7,2]\n3\n6"], "hints": ["Fix the first element of the hidden sequence to any value x and ignore the given bounds. Notice that we can then determine all the other elements of the sequence by using the differences array.", "We will also be able to determine the difference between the minimum and maximum elements of the sequence. Notice that the value of x does not affect this.", "We now have the ‘range’ of the sequence (difference between min and max element), we can then calculate how many ways there are to fit this range into the given range of lower to upper.", "Answer is (upper - lower + 1) - (range of sequence)"], "metadata": {"canonical_parameter_names": ["differences", "lower", "upper"], "leetcode_dataset_entry_point": "Solution().numberOfArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:44+00:00", "tests_total": 123, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function numberOfArrays($differences, $lower, $upper) {", "container": "Solution", "callable": "numberOfArrays", "parameters": [{"name": "differences", "type": "Integer[]"}, {"name": "lower", "type": "Integer"}, {"name": "upper", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2146, "task_id": "k-highest-ranked-items-within-a-price-range", "difficulty": "Medium", "problem_description": "You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:\n\n- 0 represents a wall that you cannot pass through.\n- 1 represents an empty cell that you can freely move to and from.\n- All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.\n\nIt takes 1 step to travel between adjacent grid cells.\n\nYou are also given integer arrays pricing and start where pricing = [low, high] and start = [row, col] indicates that you start at the position (row, col) and are interested only in items with a price in the range of [low, high] (inclusive). You are further given an integer k.\n\nYou are interested in the positions of the k highest-ranked items whose prices are within the given price range. The rank is determined by the first of these criteria that is different:\n\n1. Distance, defined as the length of the shortest path from the start (shorter distance has a higher rank).\n2. Price (lower price has a higher rank, but it must be in the price range).\n3. The row number (smaller row number has a higher rank).\n4. The column number (smaller column number has a higher rank).\n\nReturn the k highest-ranked items within the price range sorted by their rank (highest to lowest). If there are fewer than k reachable items within the price range, return all of them.\n\nExample 1:\n\nInput: grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3\nOutput: [[0,1],[1,1],[2,1]]\nExplanation: You start at (0,0).\nWith a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2).\nThe ranks of these items are:\n- (0,1) with distance 1\n- (1,1) with distance 2\n- (2,1) with distance 3\n- (2,2) with distance 4\nThus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).\n\nExample 2:\n\nInput: grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2\nOutput: [[2,1],[1,2]]\nExplanation: You start at (2,3).\nWith a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1).\nThe ranks of these items are:\n- (2,1) with distance 2, price 2\n- (1,2) with distance 2, price 3\n- (1,1) with distance 3\n- (0,1) with distance 4\nThus, the 2 highest ranked items in the price range are (2,1) and (1,2).\n\nExample 3:\n\nInput: grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3\nOutput: [[2,1],[2,0]]\nExplanation: You start at (0,0).\nWith a price range of [2,3], we can take items from (2,0) and (2,1).\nThe ranks of these items are:\n- (2,1) with distance 5\n- (2,0) with distance 6\nThus, the 2 highest ranked items in the price range are (2,1) and (2,0).\nNote that k = 3 but there are only 2 reachable items within the price range.\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] <= 10^5\n- pricing.length == 2\n- 2 <= low <= high <= 10^5\n- start.length == 2\n- 0 <= row <= m - 1\n- 0 <= col <= n - 1\n- grid[row][col] > 0\n- 1 <= k <= m * n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [0, 0, 1], [2, 3, 4]],pricing = [2, 3],start = [0, 0],k = 3) == [[2, 1], [2, 0]]\n assert candidate(grid = [[1, 2, 0, 1], [1, 3, 3, 1], [0, 2, 5, 1]],pricing = [2, 3],start = [2, 3],k = 2) == [[2, 1], [1, 2]]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],pricing = [15, 85],start = [1, 1],k = 5) == [[1, 1], [0, 1], [1, 0], [1, 2], [2, 1]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 1, 1, 1]],pricing = [1, 1],start = [0, 0],k = 10) == [[0, 0], [0, 1], [1, 0], [0, 2], [2, 0], [0, 3], [2, 1], [3, 0], [1, 3], [2, 2]]\n assert candidate(grid = [[1, 2, 0, 1], [1, 3, 0, 1], [0, 2, 5, 1]],pricing = [2, 5],start = [0, 0],k = 3) == [[0, 1], [1, 1], [2, 1]]\n assert candidate(grid = [[1, 3, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 0, 1, 1, 1]],pricing = [2, 3],start = [0, 0],k = 1) == [[0, 1]]\n assert candidate(grid = [[100, 200, 0, 300], [400, 500, 600, 700], [0, 0, 800, 0], [900, 1000, 1100, 1200]],pricing = [300, 900],start = [1, 1],k = 8) == [[1, 1], [1, 0], [1, 2], [1, 3], [2, 2], [0, 3], [3, 0]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],pricing = [1, 9],start = [0, 0],k = 9) == [[0, 0], [0, 1], [1, 0], [0, 2], [1, 1], [2, 0], [1, 2], [2, 1], [2, 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]],pricing = [1, 1],start = [2, 2],k = 15) == [[2, 2], [1, 2], [2, 1], [2, 3], [3, 2], [0, 2], [1, 1], [1, 3], [2, 0], [2, 4], [3, 1], [3, 3], [4, 2], [0, 1], [0, 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]],pricing = [2, 4],start = [1, 1],k = 7) == [[0, 1], [2, 1], [0, 2], [2, 2], [2, 3], [0, 3]]\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 10, 20, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 30, 40, 1, 0], [0, 0, 1, 1, 0, 0]],pricing = [5, 30],start = [1, 1],k = 5) == [[1, 2], [1, 3], [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, 20], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]],pricing = [5, 25],start = [1, 1],k = 15) == [[1, 1], [1, 0], [1, 2], [2, 1], [1, 3], [2, 0], [2, 2], [1, 4], [2, 3], [0, 4], [1, 5], [2, 4], [0, 5], [1, 6], [0, 6]]\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]],pricing = [5, 25],start = [0, 5],k = 15) == [[0, 5], [0, 4], [1, 5], [1, 4], [2, 5], [1, 3], [2, 4], [3, 5], [1, 2], [2, 3], [3, 4], [1, 1], [2, 2], [3, 3], [1, 0]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 1], [1, 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, 1], [1, 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, 1], [1, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [4, 6],start = [5, 5],k = 20) == [[5, 5], [5, 6], [4, 5], [5, 4], [4, 4], [7, 5], [4, 3], [2, 5], [7, 4], [8, 5], [2, 6], [7, 3], [8, 6], [1, 5], [2, 4], [8, 4], [1, 4], [1, 3]]\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, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [3, 3],k = 10) == [[2, 3], [3, 2], [2, 2]]\n assert candidate(grid = [[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]],pricing = [2, 8],start = [1, 1],k = 15) == [[1, 1], [0, 1], [2, 1], [1, 2], [0, 2], [2, 2], [1, 3], [0, 3], [2, 3], [1, 4], [0, 4], [2, 4], [1, 5], [0, 5], [2, 5]]\n assert candidate(grid = [[5, 0, 5, 0, 5], [0, 5, 0, 5, 0], [5, 0, 5, 0, 5], [0, 5, 0, 5, 0], [5, 0, 5, 0, 5]],pricing = [4, 6],start = [0, 0],k = 10) == [[0, 0]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 0, 0, 0, 0], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [0, 0, 0, 0, 0], [5, 4, 3, 2, 1]],pricing = [2, 4],start = [1, 1],k = 12) == [[0, 1], [2, 1], [3, 1], [0, 2], [2, 2], [2, 3], [3, 2], [0, 3], [3, 3]]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],pricing = [5, 15],start = [0, 2],k = 10) == [[1, 2], [1, 1], [2, 2], [2, 1], [3, 2], [2, 0], [3, 1], [4, 2], [3, 0], [4, 1]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 1], [1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [2, 2],k = 7) == [[1, 2], [2, 1], [2, 3], [3, 2], [0, 2], [2, 0], [4, 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]],pricing = [1, 1],start = [2, 2],k = 5) == [[2, 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, 1]],pricing = [1, 1],start = [0, 0],k = 1) == [[0, 0]]\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1], [1, 0, 1, 1, 1]],pricing = [2, 3],start = [0, 0],k = 5) == []\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [3, 3],k = 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]],pricing = [10, 20],start = [0, 0],k = 10) == [[2, 0], [2, 1], [3, 0], [2, 2], [3, 1], [1, 4], [2, 3], [3, 2], [2, 4], [3, 3]]\n assert candidate(grid = [[1, 2, 0, 0, 5], [0, 3, 4, 0, 6], [7, 0, 8, 9, 0], [0, 10, 11, 0, 12], [13, 0, 14, 15, 0]],pricing = [1, 15],start = [0, 4],k = 15) == [[0, 4], [1, 4]]\n assert candidate(grid = [[0, 0, 0, 0], [0, 10, 20, 0], [0, 30, 40, 0], [0, 0, 0, 0]],pricing = [10, 40],start = [1, 1],k = 2) == [[1, 1], [1, 2]]\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]],pricing = [1, 1],start = [2, 2],k = 4) == [[1, 2], [2, 1], [2, 3], [3, 2]]\n assert candidate(grid = [[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]],pricing = [200, 400],start = [2, 5],k = 12) == [[2, 5], [2, 4], [2, 6], [3, 5], [2, 3], [2, 7], [3, 4], [3, 6], [2, 2], [2, 8], [3, 3], [3, 7]]\n assert candidate(grid = [[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [0, 0, 0, 0, 0], [1, 1, 0, 1, 1], [1, 1, 0, 1, 1]],pricing = [1, 1],start = [2, 2],k = 5) == []\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900], [1000, 1100, 1200]],pricing = [250, 1050],start = [1, 1],k = 8) == [[1, 1], [1, 0], [1, 2], [2, 1], [0, 2], [2, 0], [2, 2], [3, 0]]\n assert candidate(grid = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]],pricing = [15, 95],start = [0, 9],k = 8) == [[0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [0, 1]]\n assert candidate(grid = [[1, 2, 3, 0, 5], [0, 6, 0, 7, 8], [9, 10, 11, 12, 0], [13, 14, 0, 15, 16]],pricing = [5, 15],start = [0, 0],k = 5) == [[1, 1], [2, 1], [2, 0], [2, 2], [3, 1]]\n assert candidate(grid = [[5, 15, 25, 35, 45], [10, 20, 30, 40, 50], [55, 65, 75, 85, 95]],pricing = [10, 90],start = [1, 2],k = 15) == [[1, 2], [1, 1], [0, 2], [1, 3], [2, 2], [1, 0], [0, 1], [0, 3], [1, 4], [2, 1], [2, 3], [0, 4], [2, 0]]\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]],pricing = [1, 9],start = [2, 2],k = 8) == [[2, 2], [1, 2], [2, 1], [2, 3], [3, 2], [1, 1], [1, 3], [3, 1]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],pricing = [1, 10],start = [0, 0],k = 10) == [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 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], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]],pricing = [5, 35],start = [1, 2],k = 12) == [[1, 2], [1, 1], [1, 3], [2, 2], [1, 0], [1, 4], [2, 1], [2, 3], [3, 2], [0, 4], [1, 5], [2, 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]],pricing = [5, 15],start = [0, 0],k = 10) == [[1, 0], [1, 1], [1, 2], [0, 4], [1, 3], [0, 5], [1, 4], [0, 6], [0, 7], [0, 8]]\n assert candidate(grid = [[10, 0, 30, 40, 50], [10, 0, 30, 40, 50], [10, 20, 0, 40, 50], [10, 20, 30, 0, 50], [10, 20, 30, 40, 0]],pricing = [20, 40],start = [0, 0],k = 5) == [[2, 1], [3, 1], [4, 1], [3, 2], [4, 2]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 0, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]],pricing = [5, 15],start = [2, 2],k = 10) == [[1, 2], [2, 1], [2, 3], [1, 1], [1, 3], [2, 0], [2, 4], [1, 0], [1, 4], [0, 4]]\n assert candidate(grid = [[100, 200, 300, 400, 500], [600, 700, 0, 800, 900], [1000, 1100, 1200, 1300, 0], [0, 1400, 1500, 1600, 1700]],pricing = [300, 1500],start = [1, 1],k = 10) == [[1, 1], [1, 0], [2, 1], [0, 2], [2, 0], [2, 2], [3, 1], [0, 3], [2, 3], [3, 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]],pricing = [1, 1],start = [0, 0],k = 8) == [[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, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]],pricing = [1, 1],start = [2, 2],k = 15) == [[2, 2]]\n assert candidate(grid = [[5, 0, 5, 0, 5, 0, 5, 0, 5], [0, 5, 0, 5, 0, 5, 0, 5, 0], [5, 0, 5, 0, 5, 0, 5, 0, 5], [0, 5, 0, 5, 0, 5, 0, 5, 0], [5, 0, 5, 0, 5, 0, 5, 0, 5]],pricing = [5, 5],start = [4, 4],k = 15) == [[4, 4]]\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]],pricing = [1, 1],start = [2, 2],k = 8) == [[1, 2], [2, 1], [1, 1], [1, 3], [3, 1], [1, 4], [4, 1], [2, 4]]\n assert candidate(grid = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [5, 1, 1, 1, 1, 1, 1, 1, 1, 5], [5, 1, 5, 5, 5, 5, 5, 5, 1, 5], [5, 1, 5, 1, 1, 1, 1, 5, 1, 5], [5, 1, 5, 1, 5, 5, 1, 5, 1, 5], [5, 1, 5, 1, 5, 0, 1, 5, 1, 5], [5, 1, 5, 1, 1, 1, 1, 5, 1, 5], [5, 1, 5, 5, 5, 5, 5, 5, 1, 5], [5, 1, 1, 1, 1, 1, 1, 1, 1, 5], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]],pricing = [1, 5],start = [5, 5],k = 20) == [[5, 6], [6, 5], [4, 5], [5, 4], [3, 5], [4, 6], [5, 3], [6, 4], [6, 6], [4, 4], [5, 7], [7, 5], [3, 4], [3, 6], [4, 3], [5, 8], [6, 3], [8, 5], [2, 5], [4, 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], [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], [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]],pricing = [1, 10],start = [0, 0],k = 15) == [[0, 0], [0, 1], [1, 0], [2, 0], [0, 2], [1, 1], [2, 1], [0, 3], [1, 2], [3, 0], [4, 0], [2, 2], [0, 4], [1, 3], [3, 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, 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]],pricing = [5, 9],start = [2, 4],k = 20) == [[2, 4], [1, 4], [2, 5], [3, 4], [0, 4], [1, 5], [3, 5], [4, 4], [1, 3], [2, 6], [3, 3], [0, 5], [4, 5], [1, 2], [2, 7], [3, 2], [0, 6], [4, 6], [1, 1], [2, 8]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [4, 4],k = 20) == [[4, 4]]\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]],pricing = [5, 25],start = [0, 0],k = 15) == [[1, 0], [1, 1], [2, 0], [1, 2], [2, 1], [0, 4], [1, 3], [2, 2], [0, 5], [1, 4], [2, 3], [0, 6], [1, 5], [2, 4], [0, 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], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],pricing = [3, 8],start = [0, 0],k = 15) == [[0, 2], [0, 3], [1, 2], [2, 2], [0, 4], [1, 3], [2, 3], [0, 5], [1, 4], [1, 5], [2, 4], [0, 6], [1, 6], [2, 5], [0, 7]]\n assert candidate(grid = [[10, 10, 10, 10, 10], [10, 2, 2, 2, 10], [10, 2, 3, 2, 10], [10, 2, 2, 2, 10], [10, 10, 10, 10, 10]],pricing = [2, 3],start = [2, 2],k = 8) == [[2, 2], [1, 2], [2, 1], [2, 3], [3, 2], [1, 1], [1, 3], [3, 1]]\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]],pricing = [1, 1],start = [0, 0],k = 15) == [[0, 0]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [3, 3],k = 5) == [[2, 3], [3, 2], [3, 4], [4, 3], [2, 2]]\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], [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]],pricing = [3, 7],start = [2, 4],k = 15) == [[2, 4], [2, 3], [1, 4], [3, 4], [2, 5], [2, 2], [1, 5], [3, 5], [0, 4], [4, 4], [1, 3], [3, 3], [2, 6], [1, 6], [3, 6]]\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]],pricing = [3, 8],start = [4, 4],k = 10) == [[3, 4], [4, 3], [2, 4], [3, 3], [4, 2], [1, 4], [2, 3], [3, 2], [4, 1], [0, 4]]\n assert candidate(grid = [[100, 200, 300, 400, 500], [100, 200, 300, 400, 500], [100, 200, 300, 400, 500], [100, 200, 300, 400, 500], [100, 200, 300, 400, 500]],pricing = [150, 450],start = [2, 2],k = 15) == [[2, 2], [2, 1], [1, 2], [3, 2], [2, 3], [1, 1], [3, 1], [0, 2], [4, 2], [1, 3], [3, 3], [0, 1], [4, 1], [0, 3], [4, 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], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [0, 0],k = 20) == [[0, 0], [0, 1], [1, 0], [0, 2], [1, 1], [2, 0], [0, 3], [1, 2], [2, 1], [3, 0], [0, 4], [1, 3], [2, 2], [3, 1], [4, 0], [0, 5], [1, 4], [2, 3], [3, 2], [4, 1]]\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, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [2, 8],start = [4, 4],k = 20) == []\n assert candidate(grid = [[5, 10, 15, 20, 25, 30], [35, 40, 45, 50, 55, 60], [65, 70, 75, 80, 85, 90]],pricing = [20, 70],start = [1, 2],k = 12) == [[1, 2], [1, 1], [1, 3], [0, 3], [1, 0], [1, 4], [2, 1], [0, 4], [1, 5], [2, 0], [0, 5]]\n assert candidate(grid = [[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], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]],pricing = [15, 45],start = [2, 2],k = 10) == [[2, 2], [1, 2], [3, 2], [2, 3], [0, 2], [4, 2], [1, 3], [3, 3], [2, 4], [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]],pricing = [1, 100],start = [2, 2],k = 1) == []\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]],pricing = [1, 1],start = [1, 1],k = 3) == [[0, 1], [1, 0], [0, 0]]\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]],pricing = [1, 1],start = [2, 2],k = 8) == []\n assert candidate(grid = [[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]],pricing = [500, 2000],start = [2, 2],k = 10) == [[2, 2], [1, 2], [2, 1], [2, 3], [3, 2], [1, 1], [1, 3], [2, 0], [2, 4], [3, 1]]\n assert candidate(grid = [[5, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],pricing = [1, 5],start = [2, 2],k = 10) == [[3, 2], [3, 1], [3, 3], [4, 2], [3, 0], [3, 4], [4, 1], [4, 3], [2, 0], [2, 4]]\n assert candidate(grid = [[5, 2, 3, 4, 1], [0, 0, 0, 0, 0], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]],pricing = [1, 20],start = [0, 0],k = 15) == [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]]\n assert candidate(grid = [[1, 2, 3, 0, 0], [4, 5, 6, 0, 0], [7, 8, 9, 0, 0], [10, 11, 12, 0, 0], [13, 14, 15, 0, 0]],pricing = [5, 10],start = [0, 0],k = 10) == [[1, 1], [2, 0], [1, 2], [2, 1], [3, 0], [2, 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]],pricing = [1, 1],start = [2, 2],k = 5) == [[2, 2]]\n assert candidate(grid = [[10, 15, 20, 0, 25], [5, 0, 30, 0, 35], [40, 45, 50, 55, 60]],pricing = [10, 50],start = [0, 0],k = 7) == [[0, 0], [0, 1], [0, 2], [2, 0], [1, 2], [2, 1], [2, 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, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1]],pricing = [1, 1],start = [0, 0],k = 10) == [[0, 0]]\n assert candidate(grid = [[100000, 0, 100000, 0, 100000], [0, 100000, 0, 100000, 0], [100000, 0, 100000, 0, 100000], [0, 100000, 0, 100000, 0], [100000, 0, 100000, 0, 100000]],pricing = [50000, 150000],start = [1, 1],k = 12) == [[1, 1]]\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]],pricing = [3, 7],start = [0, 0],k = 8) == [[1, 0], [0, 2], [1, 1], [1, 2], [2, 1], [0, 3], [0, 4], [2, 2]]\n assert candidate(grid = [[1, 2, 3, 0, 4, 5, 6], [7, 8, 9, 0, 10, 11, 12], [0, 0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19]],pricing = [1, 18],start = [2, 2],k = 5) == [[2, 2], [2, 3], [3, 2], [1, 2], [0, 2]]\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, 0, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [1, 1],start = [4, 5],k = 10) == [[4, 5], [4, 4], [5, 4], [6, 4], [7, 4], [8, 4], [9, 4], [9, 3], [9, 5], [9, 2]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],pricing = [1, 10],start = [4, 0],k = 10) == [[4, 0], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9]]\n assert candidate(grid = [[10, 10, 10, 10], [10, 0, 0, 10], [10, 10, 10, 10], [10, 10, 10, 10]],pricing = [5, 15],start = [1, 1],k = 1) == [[0, 1]]\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, 0, 2, 3, 4, 5, 6, 7, 0, 1], [1, 0, 8, 9, 10, 11, 12, 13, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],pricing = [2, 12],start = [2, 2],k = 7) == [[2, 2], [2, 3], [3, 2], [2, 4], [3, 3], [2, 5], [3, 4]]\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 0, 0, 0, 1], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]],pricing = [2, 4],start = [2, 2],k = 5) == [[1, 2], [3, 2], [1, 3], [3, 3], [0, 2]]\n", "comparison": "exact"}, "public_tests": ["[[1,2,0,1],[1,3,0,1],[0,2,5,1]]\n[2,5]\n[0,0]\n3", "[[1,2,0,1],[1,3,3,1],[0,2,5,1]]\n[2,3]\n[2,3]\n2", "[[1,1,1],[0,0,1],[2,3,4]]\n[2,3]\n[0,0]\n3"], "hints": ["Could you determine the rank of every item efficiently?", "We can perform a breadth-first search from the starting position and know the length of the shortest path from start to every item.", "Sort all the items according to the conditions listed in the problem, and return the first k (or all if less than k exist) items as the answer."], "metadata": {"canonical_parameter_names": ["grid", "pricing", "start", "k"], "leetcode_dataset_entry_point": "Solution().highestRankedKItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:46+00:00", "tests_total": 79, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "breadth-first-search", "sorting", "heap-priority-queue", "matrix"]}, "language": "php", "interface": {"raw_signature": "function highestRankedKItems($grid, $pricing, $start, $k) {", "container": "Solution", "callable": "highestRankedKItems", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "pricing", "type": "Integer[]"}, {"name": "start", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2147, "task_id": "number-of-ways-to-divide-a-long-corridor", "difficulty": "Hard", "problem_description": "Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.\n\nOne room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.\n\nDivide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.\n\nReturn the number of ways to divide the corridor. Since the answer may be very large, return it modulo 10^9 + 7. If there is no way, return 0.\n\nExample 1:\n\nInput: corridor = \"SSPPSPS\"\nOutput: 3\nExplanation: There are 3 different ways to divide the corridor.\nThe black bars in the above image indicate the two room dividers already installed.\nNote that in each of the ways, each section has exactly two seats.\n\nExample 2:\n\nInput: corridor = \"PPSPSP\"\nOutput: 1\nExplanation: There is only 1 way to divide the corridor, by not installing any additional dividers.\nInstalling any would create some section that does not have exactly two seats.\n\nExample 3:\n\nInput: corridor = \"S\"\nOutput: 0\nExplanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats.\n\nConstraints:\n\n- n == corridor.length\n- 1 <= n <= 10^5\n- corridor[i] is either 'S' or 'P'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(corridor = \"PPPPSSPPPPSSPPPP\") == 5\n assert candidate(corridor = \"SSSSSSSSSS\") == 1\n assert candidate(corridor = \"SPSPSPSP\") == 2\n assert candidate(corridor = \"SSSPPSS\") == 0\n assert candidate(corridor = \"PSSPSPSPPS\") == 0\n assert candidate(corridor = \"SS\") == 1\n assert candidate(corridor = \"PPPP\") == 0\n assert candidate(corridor = \"SSPPSS\") == 3\n assert candidate(corridor = \"SSSSPPSSSS\") == 3\n assert candidate(corridor = \"SSPSSP\") == 2\n assert candidate(corridor = \"SSPSSPSS\") == 4\n assert candidate(corridor = \"SSPPPPPSSPPPPSS\") == 30\n assert candidate(corridor = \"SSPSPSPSPS\") == 4\n assert candidate(corridor = \"SSSS\") == 1\n assert candidate(corridor = \"SSSPPPSS\") == 0\n assert candidate(corridor = \"SSSPPS\") == 1\n assert candidate(corridor = \"PPSSPPSSPP\") == 3\n assert candidate(corridor = \"SSPPSSPPSS\") == 9\n assert candidate(corridor = \"SSPPSPS\") == 3\n assert candidate(corridor = \"SSPPSPPS\") == 3\n assert candidate(corridor = \"S\") == 0\n assert candidate(corridor = \"PPSPSP\") == 1\n assert candidate(corridor = \"SPPSPPSPPS\") == 3\n assert candidate(corridor = \"PPSPSPSPSPSPSPSPSP\") == 8\n assert candidate(corridor = \"SSSPSSSSPPSSPPSSSSPPSSSSPPSSSSSSSSSS\") == 0\n assert candidate(corridor = \"SPPSPSPSPSPSPSPSPS\") == 0\n assert candidate(corridor = \"SSPSSPSSPSSPSSPSSPSS\") == 64\n assert candidate(corridor = \"PPSSPPSPSSPPSS\") == 0\n assert candidate(corridor = \"SSPPSSSSSSSSPPSSSSSSSSPPSSSSSSSSSS\") == 27\n assert candidate(corridor = \"SSPPSSPPSSPPSS\") == 27\n assert candidate(corridor = \"SPSSPSSPSSPSSPSS\") == 0\n assert candidate(corridor = \"PPPPPPSSPPPPSSPPPP\") == 5\n assert candidate(corridor = \"SSPPPPPPSSPPPPSSPPPPSSPPSS\") == 525\n assert candidate(corridor = \"PPSSPPSSPPSSPPSS\") == 27\n assert candidate(corridor = \"PPPPSSPPPPSSPPPPSSPPPPSSPPPPSSPPPP\") == 625\n assert candidate(corridor = \"SSSPSPSPSPSPSSSSPSPS\") == 0\n assert candidate(corridor = \"SSPPSPSPSSSSPPPPSS\") == 30\n assert candidate(corridor = \"SSPPSSSSSSSSSSSSSS\") == 3\n assert candidate(corridor = \"PPPPPPPPPPPPPPPPPP\") == 0\n assert candidate(corridor = \"SPPSPSPSPSPSPSPSPSPS\") == 16\n assert candidate(corridor = \"SPSPPSPSPPSPSPPSPSPP\") == 27\n assert candidate(corridor = \"PPSSPPSSPPSSPP\") == 9\n assert candidate(corridor = \"SSPSPSPSPSPS\") == 0\n assert candidate(corridor = \"SSSPSSSPSSSPSSSPSS\") == 4\n assert candidate(corridor = \"PPSSPPSSSSSSSSSSSS\") == 3\n assert candidate(corridor = \"SSPPPPPPPPSSPPPPSS\") == 45\n assert candidate(corridor = \"SSPPSSSSSSPPSS\") == 9\n assert candidate(corridor = \"SSPPPPPPSSPPPPPSS\") == 42\n assert candidate(corridor = \"SSSSPPPPSSPPSSPPSSSSPPPPSSSSSS\") == 225\n assert candidate(corridor = \"SSPPPPSSPPSS\") == 15\n assert candidate(corridor = \"SSSSPPPPSSPPPPSSSSPPPPSS\") == 125\n assert candidate(corridor = \"SSPPPPSSPPPPSSPPPPSSPPPPSS\") == 625\n assert candidate(corridor = \"SSPPSPSSSSSSSSSSPPSS\") == 0\n assert candidate(corridor = \"SPPSPPSPPSPPS\") == 0\n assert candidate(corridor = \"SSPSPPSPSPSPSPPPSS\") == 0\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSS\") == 177147\n assert candidate(corridor = \"PPPPPPSPPPPSPPPPSPPPPS\") == 5\n assert candidate(corridor = \"SSSSSSSSSSSSSSSS\") == 1\n assert candidate(corridor = \"SSPPSPSSPPSPSSPPSPSS\") == 0\n assert candidate(corridor = \"PPSSPPSSPPSS\") == 9\n assert candidate(corridor = \"SSPPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS\") == 1536\n assert candidate(corridor = \"SSSPSSPPSSPPSSSSPPSSPPSSPPSSSSPPSSSS\") == 0\n assert candidate(corridor = \"SSSSSSSSSSSSSSSSSSSSSSSSSS\") == 1\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSSSPPSSSSPPSSSS\") == 729\n assert candidate(corridor = \"SSPPSPPPSPSPPS\") == 6\n assert candidate(corridor = \"SSPPPPSSPPPPSSPPSSPPPPSS\") == 375\n assert candidate(corridor = \"SSPPPPPPSPPPPPSSSSPP\") == 0\n assert candidate(corridor = \"PPSSSSPPPPSS\") == 5\n assert candidate(corridor = \"SSPPSPPPSSSSPPSPSS\") == 6\n assert candidate(corridor = \"PPPPPPSSPPSS\") == 3\n assert candidate(corridor = \"SSPPSPSSPPSPSSPPSPSSPPSPSS\") == 36\n assert candidate(corridor = \"SSSPSSSPSSSPSSSPSSSPSSSPSSS\") == 0\n assert candidate(corridor = \"SSSPSSSSPPSSPPSSSSPPSSSSPPSSSS\") == 0\n assert candidate(corridor = \"SPPPPPPPPPPP\") == 0\n assert candidate(corridor = \"PPPPSPSPPPPSPSPPPPSP\") == 0\n assert candidate(corridor = \"PPSSPPSSPPSSPPSSPPSSPPSSPPSS\") == 729\n assert candidate(corridor = \"PPPPPPPPPPPPPPPPPPPP\") == 0\n assert candidate(corridor = \"SSPSSPSSPSSPSSPSSPSSPSS\") == 128\n assert candidate(corridor = \"SSPPPPSPSPPPSS\") == 20\n assert candidate(corridor = \"PPSSPSSPPSSPSSPPSSPSSPPSS\") == 216\n assert candidate(corridor = \"SSPPPSSPPPSSPPPSS\") == 64\n assert candidate(corridor = \"SSPSSSPSSPSSPSSPSS\") == 0\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPPSSPPSS\") == 729\n assert candidate(corridor = \"PPSSPPPPSSPPPPSS\") == 25\n assert candidate(corridor = \"SPSSSPSSSPSSSPSSSPSS\") == 0\n assert candidate(corridor = \"PSPSPSPSPSPSPSPSPS\") == 0\n assert candidate(corridor = \"SSPPSSPSPSPSSP\") == 12\n assert candidate(corridor = \"SSSSSSSSSSSSSSSSSS\") == 1\n assert candidate(corridor = \"SSPPSSPPSSPPSPSSPPSS\") == 0\n assert candidate(corridor = \"SSPPSPSPPPSSSPPSS\") == 0\n assert candidate(corridor = \"SSPPSSSSPPSSSSPPS\") == 0\n assert candidate(corridor = \"SSPPPPPPSSSSSSSSSS\") == 7\n assert candidate(corridor = \"SSPPPPSSPPPPSSSSPPPPSSSSPPPPSSSS\") == 625\n assert candidate(corridor = \"SSSSSSSSSSPPPPPPSS\") == 7\n assert candidate(corridor = \"SSSSPPSSSSSSPPSSSS\") == 9\n assert candidate(corridor = \"SSPSSPSSPSSPSSPSSPSSPSSPSSPS\") == 0\n assert candidate(corridor = \"SSPPSPSPSPPSS\") == 0\n assert candidate(corridor = \"PPSSPPPPSSPPSSPP\") == 15\n assert candidate(corridor = \"SPSSSPSSSPSSSPSS\") == 4\n assert candidate(corridor = \"PSPPSPSPSPSPSPSPSPSP\") == 0\n assert candidate(corridor = \"SSSSSSPPSSSSSSPPSSSSSSPPSSSSSS\") == 27\n assert candidate(corridor = \"SSPPSSPSSPPSSPSSPPSS\") == 108\n assert candidate(corridor = \"SSSPSPSPSPSPSPSPSPSPSP\") == 16\n assert candidate(corridor = \"PPPPPPSSPPPP\") == 1\n assert candidate(corridor = \"PPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSS\") == 19683\n assert candidate(corridor = \"SSPPSPSSPSPSSPSPSSPSPSS\") == 24\n assert candidate(corridor = \"SSSPPSSSPPPSSS\") == 0\n assert candidate(corridor = \"SSSSSSSSSSSS\") == 1\n assert candidate(corridor = \"SSSSSPPPSSSSSPPPSSSS\") == 4\n assert candidate(corridor = \"SSSSSSSSPPPPPPPPSSSSSSSSPPPPPPPPSSSS\") == 81\n assert candidate(corridor = \"SSSSSS\") == 1\n assert candidate(corridor = \"SSPPPPPPSSSSSSPPSSPP\") == 21\n assert candidate(corridor = \"SSPSPSPSPSPSPSPSPSPSPSPSPSPSPS\") == 128\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSS\") == 81\n assert candidate(corridor = \"SSSSPPPPSSSSPPPPSSSS\") == 25\n assert candidate(corridor = \"SSPSPPSSPSPPSSPSPPSS\") == 0\n assert candidate(corridor = \"SPSPSP\") == 0\n assert candidate(corridor = \"SSPPPPSPSSPPPSS\") == 0\n assert candidate(corridor = \"SSSSPSPSPSPS\") == 4\n assert candidate(corridor = \"PPPPPP\") == 0\n assert candidate(corridor = \"SSPPPPPPPPPPSSPPPPSSPPSS\") == 165\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPPSSPPSSPPSSPPSS\") == 6561\n assert candidate(corridor = \"SSPPPPSSPPPPSSPPSS\") == 75\n assert candidate(corridor = \"SSSSSSSSSSSSSSSSSSSS\") == 1\n assert candidate(corridor = \"SSSSPPPPSSSSPPSSSS\") == 15\n assert candidate(corridor = \"PPPPPPPPPPPPPPPP\") == 0\n assert candidate(corridor = \"SSSPSPSPSPSPSPSPSPSS\") == 16\n assert candidate(corridor = \"SSPPSPSSSSPPSPSSSS\") == 6\n assert candidate(corridor = \"SSPSSPSSPSSPSSPSS\") == 32\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPP\") == 81\n assert candidate(corridor = \"PPPPSSPPPPSSPPPPSSPPPPSSPPPPSS\") == 625\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPPSSPPSSPPSS\") == 2187\n assert candidate(corridor = \"SSSSPPSSSSPPSSSS\") == 9\n assert candidate(corridor = \"SSSSSSPPPPSSSSPPPPSSSSSSPPPP\") == 25\n assert candidate(corridor = \"SSPPSSPPSSPPSSPPSSPPSS\") == 243\n assert candidate(corridor = \"SSPPSSPPSSPPSSSS\") == 27\n assert candidate(corridor = \"SSPSPSPSPSPSPSPS\") == 0\n assert candidate(corridor = \"SSPPSPSPSPSPSS\") == 12\n assert candidate(corridor = \"SPSPSPSPSPSPSPSPSPSP\") == 16\n assert candidate(corridor = \"SSPPSSSSPPPPSSSSSSSS\") == 15\n assert candidate(corridor = \"PPPPSSPPSSPPSSPPPP\") == 9\n assert candidate(corridor = \"SPSPPSPSPPSPSPPSPSPPSP\") == 0\n assert candidate(corridor = \"PPSPSPSPSPSPPSPSPS\") == 8\n assert candidate(corridor = \"SPSPSPSPPSPS\") == 6\n assert candidate(corridor = \"SSPPSSPPSSPPSSSSPPSSPPSSSSPPSS\") == 729\n", "comparison": "exact"}, "public_tests": ["\"SSPPSPS\"", "\"PPSPSP\"", "\"S\""], "hints": ["Divide the corridor into segments. Each segment has two seats, starts precisely with one seat, and ends precisely with the other seat.", "How many dividers can you install between two adjacent segments? You must install precisely one. Otherwise, you would have created a section with not exactly two seats.", "If there are k plants between two adjacent segments, there are k + 1 positions (ways) you could install the divider you must install.", "The problem now becomes: Find the product of all possible positions between every two adjacent segments."], "metadata": {"canonical_parameter_names": ["corridor"], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:49+00:00", "tests_total": 145, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["math", "string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function numberOfWays($corridor) {", "container": "Solution", "callable": "numberOfWays", "parameters": [{"name": "corridor", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2148, "task_id": "count-elements-with-strictly-smaller-and-greater-elements", "difficulty": "Easy", "problem_description": "Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.\n\nExample 1:\n\nInput: nums = [11,7,2,15]\nOutput: 2\nExplanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.\nElement 11 has element 7 strictly smaller than it and element 15 strictly greater than it.\nIn total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.\n\nExample 2:\n\nInput: nums = [-3,3,3,90]\nOutput: 2\nExplanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.\nSince there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- -10^5 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 4\n assert candidate(nums = [-100000, 100000]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 8\n assert candidate(nums = [100000, -100000, 0, 1, 2]) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 8, 9]) == 1\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 2\n assert candidate(nums = [100000, -100000, 0, 10, 20]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 6\n assert candidate(nums = [11, 7, 2, 15]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500]) == 3\n assert candidate(nums = [0, 0, 0, 1]) == 0\n assert candidate(nums = [-1, 0, 1]) == 1\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5]) == 5\n assert candidate(nums = [-3, 3, 3, 90]) == 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]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 11]) == 12\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\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]) == 19\n assert candidate(nums = [50000, -50000, 0, 1000, 500, 250, 750, 150, 300, 600]) == 8\n assert candidate(nums = [100000, 100000, 99999, 99999, 50000, 50000, -50000, -50000, -99999, -99999, -100000, -100000]) == 8\n assert candidate(nums = [50, 20, 30, 40, 10, 60, 70, 80, 90, 100]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(nums = [50000, -50000, 25000, -25000, 12500, -12500, 6250, -6250, 3125, -3125]) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]) == 8\n assert candidate(nums = [-1000, -500, -250, -100, -50, -25, 0, 25, 50, 100, 250, 500, 1000]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 6\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 13\n assert candidate(nums = [-10, 10, -20, 20, -30, 30, -40, 40, -50, 50]) == 8\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996]) == 8\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9, 10]) == 8\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 8\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 13\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 18\n assert candidate(nums = [10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12]) == 4\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 6\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 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]) == 28\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 11, 12, 13, 14, 15, 15, 15, 15, 15]) == 4\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991, 49990, 49989, 49988, 49987, 49986, 49985, 49984, 49983, 49982, 49981]) == 18\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 13\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 15\n assert candidate(nums = [-100000, 100000, -90000, 90000, -80000, 80000, -70000, 70000, -60000, 60000]) == 8\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90]) == 9\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500]) == 12\n assert candidate(nums = [10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 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]) == 16\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 10\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 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]) == 23\n assert candidate(nums = [-10000, -9999, -9998, -9997, -9996, -9995, -9994, -9993, -9992, -9991]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10]) == 8\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, -1, -1, -1, -1]) == 4\n assert candidate(nums = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1, 10, 100, 1000, 10000, 100000]) == 8\n assert candidate(nums = [50, 50, 50, 50, 50, 49, 48, 47, 46, 45, 51, 52, 53, 54, 55]) == 13\n assert candidate(nums = [-100000, -99999, -99998, -99997, -99996]) == 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]) == 18\n assert candidate(nums = [10000, 10000, 10001, 10001, 9999, 9999, 9998, 9998, 10002, 10002]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5]) == 18\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 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]) == 18\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\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\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 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, 21, 22, 23, 24, 25]) == 23\n assert candidate(nums = [30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == 13\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]) == 15\n assert candidate(nums = [300, 200, 100, 400, 500, 600, 150, 250, 350, 450]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -10, -20, -30, -40, -50]) == 13\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == 6\n assert candidate(nums = [1, 100000, -1, -100000, 50000, 50001, 50002, 50003, 50004, 50005]) == 8\n assert candidate(nums = [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, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 13\n assert candidate(nums = [-1000, -2000, -3000, -4000, -5000, -6000, -7000, -8000, -9000, -10000, -1000, -2000, -3000, -4000, -5000]) == 12\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 16\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 12\n assert candidate(nums = [50, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 9\n assert candidate(nums = [100, 101, 99, 102, 98, 103, 97, 104, 96, 105]) == 8\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 8\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 14\n assert candidate(nums = [100000, 100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996]) == 6\n assert candidate(nums = [-50000, 50000, 0, 1, 2, -1, -2, -3, 3, 4, -4, 5, -5, 6, -6]) == 13\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]) == 16\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1]) == 8\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 8\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8, 9, 10]) == 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]) == 18\n assert candidate(nums = [50000, 50000, 50000, 40000, 60000, 30000, 70000, 20000, 80000, 10000]) == 8\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == 18\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 8\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 1000, 2000, 3000, 4000, 5000]) == 12\n assert candidate(nums = [12345, -12345, 67890, -67890, 11111, -11111, 22222, -22222, 33333, -33333, 44444, -44444, 55555, -55555]) == 12\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 13\n assert candidate(nums = [-100000, -50000, -10000, -5000, -1000, -500, -100, -50, -10, -5, 0, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000]) == 19\n assert candidate(nums = [10, 20, 20, 30, 30, 40, 40, 50, 50]) == 6\n", "comparison": "exact"}, "public_tests": ["[11,7,2,15]", "[-3,3,3,90]"], "hints": ["All the elements in the array should be counted except for the minimum and maximum elements.", "If the array has n elements, the answer will be n - count(min(nums)) - count(max(nums))", "This formula will not work in case the array has all the elements equal, why?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countElements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:51+00:00", "tests_total": 120, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function countElements($nums) {", "container": "Solution", "callable": "countElements", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2149, "task_id": "rearrange-array-elements-by-sign", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.\n\nYou should return the array of nums such that the array follows the given conditions:\n\n1. Every consecutive pair of integers have opposite signs.\n2. For all integers with the same sign, the order in which they were present in nums is preserved.\n3. The rearranged array begins with a positive integer.\n\nReturn the modified array after rearranging the elements to satisfy the aforementioned conditions.\n\nExample 1:\n\nInput: nums = [3,1,-2,-5,2,-4]\nOutput: [3,-2,1,-5,2,-4]\nExplanation:\nThe positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].\nThe only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].\nOther ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.\n\nExample 2:\n\nInput: nums = [-1,1]\nOutput: [1,-1]\nExplanation:\n1 is the only positive integer and -1 the only negative integer in nums.\nSo nums is rearranged to [1,-1].\n\nConstraints:\n\n- 2 <= nums.length <= 2 * 10^5\n- nums.length is even\n- 1 <= |nums[i]| <= 10^5\n- nums consists of equal number of positive and negative integers.\n\nIt is not required to do the modifications in-place.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 2, -3, -1, 5, -6]) == [4, -3, 2, -1, 5, -6]\n assert candidate(nums = [1, -1, 2, -2, 3, -3]) == [1, -1, 2, -2, 3, -3]\n assert candidate(nums = [4, -3, 2, -5, 6, -7]) == [4, -3, 2, -5, 6, -7]\n assert candidate(nums = [3, 1, -2, -5, 2, -4]) == [3, -2, 1, -5, 2, -4]\n assert candidate(nums = [10, -10, 20, -20, 30, -30]) == [10, -10, 20, -20, 30, -30]\n assert candidate(nums = [7, 10, -5, -3, 2, -8]) == [7, -5, 10, -3, 2, -8]\n assert candidate(nums = [-1, 1]) == [1, -1]\n assert candidate(nums = [8, 5, -7, -3, 4, -6]) == [8, -7, 5, -3, 4, -6]\n assert candidate(nums = [5, -5, 6, -6, 7, -7]) == [5, -5, 6, -6, 7, -7]\n assert candidate(nums = [9, -2, 6, -1, 3, -4]) == [9, -2, 6, -1, 3, -4]\n assert candidate(nums = [4, -3, 2, -1, 6, -5]) == [4, -3, 2, -1, 6, -5]\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, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40, 45, -45, 50, -50]\n assert candidate(nums = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5]) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]\n assert candidate(nums = [-2, 2, -4, 4, -6, 6, -8, 8, -10, 10, -12, 12, -14, 14, -16, 16, -18, 18, -20, 20]) == [2, -2, 4, -4, 6, -6, 8, -8, 10, -10, 12, -12, 14, -14, 16, -16, 18, -18, 20, -20]\n assert candidate(nums = [21, -21, 22, -22, 23, -23, 24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30]) == [21, -21, 22, -22, 23, -23, 24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30]\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600]) == [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600]\n assert candidate(nums = [6, -2, 3, -1, 7, -5, 8, -4, 9, -6, 10, -8, 11, -7, 12, -9]) == [6, -2, 3, -1, 7, -5, 8, -4, 9, -6, 10, -8, 11, -7, 12, -9]\n assert candidate(nums = [5, 15, 25, 35, 45, -5, -15, -25, -35, -45, 65, -65]) == [5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 65, -65]\n assert candidate(nums = [21, 19, 17, 15, 13, 11, 9, 7, 5, 3, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3]) == [21, -21, 19, -19, 17, -17, 15, -15, 13, -13, 11, -11, 9, -9, 7, -7, 5, -5, 3, -3]\n assert candidate(nums = [12, -12, 24, -24, 36, -36, 48, -48, 60, -60, 72, -72]) == [12, -12, 24, -24, 36, -36, 48, -48, 60, -60, 72, -72]\n assert candidate(nums = [42, -84, 21, -42, 63, -126, 84, -168, 105, -210]) == [42, -84, 21, -42, 63, -126, 84, -168, 105, -210]\n assert candidate(nums = [2, 4, 6, 8, 10, -2, -4, -6, -8, -10, 12, 14, -12, -14, 16, -16, 18, -18]) == [2, -2, 4, -4, 6, -6, 8, -8, 10, -10, 12, -12, 14, -14, 16, -16, 18, -18]\n assert candidate(nums = [10, -11, 20, -21, 30, -31, 40, -41, 50, -51, 60, -61, 70, -71, 80, -81, 90, -91, 100, -101, 110, -111, 120, -121]) == [10, -11, 20, -21, 30, -31, 40, -41, 50, -51, 60, -61, 70, -71, 80, -81, 90, -91, 100, -101, 110, -111, 120, -121]\n assert candidate(nums = [10, 20, 30, -1, -2, -3, 40, -4, 50, -5]) == [10, -1, 20, -2, 30, -3, 40, -4, 50, -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, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]\n assert candidate(nums = [-10, 11, -12, 13, -14, 15, -16, 17, -18, 19]) == [11, -10, 13, -12, 15, -14, 17, -16, 19, -18]\n assert candidate(nums = [100000, 50000, -50000, -100000, 25000, -25000, 12500, -12500, 6250, -6250]) == [100000, -50000, 50000, -100000, 25000, -25000, 12500, -12500, 6250, -6250]\n assert candidate(nums = [20, 10, -10, -20, 30, 40, -30, -40, 50, 60, -50, -60]) == [20, -10, 10, -20, 30, -30, 40, -40, 50, -50, 60, -60]\n assert candidate(nums = [2, 4, 6, 8, 10, -2, -4, -6, -8, -10, 12, 14, 16, 18, 20, -12, -14, -16, -18, -20]) == [2, -2, 4, -4, 6, -6, 8, -8, 10, -10, 12, -12, 14, -14, 16, -16, 18, -18, 20, -20]\n assert candidate(nums = [15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85]) == [15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85]\n assert candidate(nums = [5, 10, -5, -10, 15, 20, -15, -20, 25, 30, -25, -30]) == [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30]\n assert candidate(nums = [5, -3, 2, -8, 6, -1, 4, -7]) == [5, -3, 2, -8, 6, -1, 4, -7]\n assert candidate(nums = [100, 200, -100, -200, 300, -300, 400, -400, 500, -500]) == [100, -100, 200, -200, 300, -300, 400, -400, 500, -500]\n assert candidate(nums = [50, -25, 75, -37, 100, -50, 125, -62, 150, -75, 175, -87, 200, -100]) == [50, -25, 75, -37, 100, -50, 125, -62, 150, -75, 175, -87, 200, -100]\n assert candidate(nums = [100000, 200000, -100000, -200000, 300000, 400000, -300000, -400000, 500000, -500000]) == [100000, -100000, 200000, -200000, 300000, -300000, 400000, -400000, 500000, -500000]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15]) == [1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15]\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65]) == [5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65]\n assert candidate(nums = [5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14]) == [5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13, 14, -14]\n assert candidate(nums = [7, -7, 14, -14, 21, -21, 28, -28, 35, -35]) == [7, -7, 14, -14, 21, -21, 28, -28, 35, -35]\n assert candidate(nums = [100, 200, -50, -150, 300, -250, 400, -350, 500, -450]) == [100, -50, 200, -150, 300, -250, 400, -350, 500, -450]\n assert candidate(nums = [15, 3, -9, -6, 12, -5, 20, -7, 18, -11]) == [15, -9, 3, -6, 12, -5, 20, -7, 18, -11]\n assert candidate(nums = [99, -98, 97, -96, 95, -94, 93, -92, 91, -90, 89, -88, 87, -86, 85, -84]) == [99, -98, 97, -96, 95, -94, 93, -92, 91, -90, 89, -88, 87, -86, 85, -84]\n assert candidate(nums = [50, -50, 25, -25, 75, -75, 100, -100, 200, -200, 300, -300]) == [50, -50, 25, -25, 75, -75, 100, -100, 200, -200, 300, -300]\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40]) == [10, -10, 20, -20, 30, -30, 40, -40]\n assert candidate(nums = [7, -7, 14, -14, 21, -21, 28, -28, 35, -35, 42, -42, 49, -49, 56, -56]) == [7, -7, 14, -14, 21, -21, 28, -28, 35, -35, 42, -42, 49, -49, 56, -56]\n assert candidate(nums = [15, -20, 25, -30, 35, -40, 45, -50, 55, -60]) == [15, -20, 25, -30, 35, -40, 45, -50, 55, -60]\n assert candidate(nums = [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000, 6000, -6000]) == [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000, 6000, -6000]\n assert candidate(nums = [1, 3, 5, 7, 9, -1, -3, -5, -7, -9, 2, 4, 6, 8, 10, -2, -4, -6, -8, -10]) == [1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 2, -2, 4, -4, 6, -6, 8, -8, 10, -10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, -1, -3, -5, -7, -9, -11]) == [1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11]\n assert candidate(nums = [31, 41, 59, 26, -31, -41, -59, -26, 53, 58, 97, 93, -53, -58, -97, -93, 23, 84, -23, -84]) == [31, -31, 41, -41, 59, -59, 26, -26, 53, -53, 58, -58, 97, -97, 93, -93, 23, -23, 84, -84]\n assert candidate(nums = [-9, 1, -8, 2, -7, 3, -6, 4, -5, 5, -4, 6, -3, 7, -2, 8, -1, 9]) == [1, -9, 2, -8, 3, -7, 4, -6, 5, -5, 6, -4, 7, -3, 8, -2, 9, -1]\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500]) == [100, -100, 200, -200, 300, -300, 400, -400, 500, -500]\n assert candidate(nums = [9, 11, -9, -11, 12, 13, -12, -13, 14, -14, 15, -15, 16, -16]) == [9, -9, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16]\n assert candidate(nums = [1, 1, 1, 1, -1, -1, -1, -1, 2, 2, 2, 2, -2, -2, -2, -2, 3, 3, 3, 3, -3, -3, -3, -3]) == [1, -1, 1, -1, 1, -1, 1, -1, 2, -2, 2, -2, 2, -2, 2, -2, 3, -3, 3, -3, 3, -3, 3, -3]\n assert candidate(nums = [7, -7, 6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]) == [7, -7, 6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1563, 782, 391, 195, -100000, -50000, -25000, -12500, -6250, -3125, -1563, -782, -391, -195]) == [100000, -100000, 50000, -50000, 25000, -25000, 12500, -12500, 6250, -6250, 3125, -3125, 1563, -1563, 782, -782, 391, -391, 195, -195]\n assert candidate(nums = [6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]) == [6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]\n assert candidate(nums = [9, -9, 8, -8, 7, -7, 6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]) == [9, -9, 8, -8, 7, -7, 6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]\n assert candidate(nums = [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000, 6000, -6000, 7000, -7000, 8000, -8000, 9000, -9000, 10000, -10000]) == [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000, 6000, -6000, 7000, -7000, 8000, -8000, 9000, -9000, 10000, -10000]\n assert candidate(nums = [10, 20, -10, 30, -20, 40, -30, 50, -40, 60, -50, -60, 70, 80, -70, -80]) == [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80]\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 = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50]) == [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]\n assert candidate(nums = [7, 14, -7, -14, 21, 28, -21, -28, 35, 42, -35, -42, 49, 56, -49, -56]) == [7, -7, 14, -14, 21, -21, 28, -28, 35, -35, 42, -42, 49, -49, 56, -56]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, -1, -2, -3, -4, -5, -6]) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6]\n assert candidate(nums = [7, 11, -3, -8, 9, -4, 6, -2, 13, -5]) == [7, -3, 11, -8, 9, -4, 6, -2, 13, -5]\n assert candidate(nums = [22, 33, -22, -33, 44, 55, -44, -55, 66, 77, -66, -77, 88, 99, -88, -99, 11, 22, -11, -22]) == [22, -22, 33, -33, 44, -44, 55, -55, 66, -66, 77, -77, 88, -88, 99, -99, 11, -11, 22, -22]\n assert candidate(nums = [100, -99, 101, -98, 102, -97, 103, -96, 104, -95]) == [100, -99, 101, -98, 102, -97, 103, -96, 104, -95]\n assert candidate(nums = [10, 15, -5, -10, 20, -20, 25, -25]) == [10, -5, 15, -10, 20, -20, 25, -25]\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000]) == [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000]\n assert candidate(nums = [34, 56, -34, -56, 78, 90, -78, -90, 12, 34, -12, -34, 56, 78, -56, -78]) == [34, -34, 56, -56, 78, -78, 90, -90, 12, -12, 34, -34, 56, -56, 78, -78]\n assert candidate(nums = [101, 202, 303, 404, 505, -101, -202, -303, -404, -505, 606, 707, -606, -707, 808, 909, -808, -909]) == [101, -101, 202, -202, 303, -303, 404, -404, 505, -505, 606, -606, 707, -707, 808, -808, 909, -909]\n assert candidate(nums = [15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85, 95, -95, 105, -105, 115, -115, 125, -125]) == [15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85, 95, -95, 105, -105, 115, -115, 125, -125]\n assert candidate(nums = [21, -21, 32, -32, 43, -43, 54, -54, 65, -65, 76, -76, 87, -87, 98, -98, 109, -109, 120, -120]) == [21, -21, 32, -32, 43, -43, 54, -54, 65, -65, 76, -76, 87, -87, 98, -98, 109, -109, 120, -120]\n assert candidate(nums = [10, 9, -10, -9, 8, 7, -8, -7, 6, 5, -6, -5, 4, 3, -4, -3, 2, 1, -2, -1]) == [10, -10, 9, -9, 8, -8, 7, -7, 6, -6, 5, -5, 4, -4, 3, -3, 2, -2, 1, -1]\n assert candidate(nums = [21, -21, 22, -22, 23, -23, 24, -24, 25, -25, 26, -26, 27, -27, 28, -28]) == [21, -21, 22, -22, 23, -23, 24, -24, 25, -25, 26, -26, 27, -27, 28, -28]\n assert candidate(nums = [9, -9, 7, -7, 5, -5, 3, -3, 1, -1]) == [9, -9, 7, -7, 5, -5, 3, -3, 1, -1]\n assert candidate(nums = [3, -3, 6, -6, 9, -9, 12, -12, 15, -15, 18, -18, 21, -21, 24, -24, 27, -27]) == [3, -3, 6, -6, 9, -9, 12, -12, 15, -15, 18, -18, 21, -21, 24, -24, 27, -27]\n assert candidate(nums = [6, -6, 3, -3, 9, -9, 12, -12, 15, -15, 18, -18]) == [6, -6, 3, -3, 9, -9, 12, -12, 15, -15, 18, -18]\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]) == [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]\n assert candidate(nums = [7, 3, -3, -7, 9, -9, 11, -11, 13, -13]) == [7, -3, 3, -7, 9, -9, 11, -11, 13, -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, 11, -11, 12, -12]) == [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 = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == [2, -1, 4, -3, 6, -5, 8, -7, 10, -9]\n assert candidate(nums = [15, -5, 20, -10, 25, -15, 30, -20, 35, -25, 40, -30, 45, -35]) == [15, -5, 20, -10, 25, -15, 30, -20, 35, -25, 40, -30, 45, -35]\n assert candidate(nums = [7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13]) == [7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12, 13, -13]\n assert candidate(nums = [100, -50, 75, -25, 125, -62, 150, -87, 200, -12]) == [100, -50, 75, -25, 125, -62, 150, -87, 200, -12]\n assert candidate(nums = [10, 20, -10, -20, 30, -30, 40, -40]) == [10, -10, 20, -20, 30, -30, 40, -40]\n assert candidate(nums = [20, -30, 21, -31, 22, -32, 23, -33, 24, -34, 25, -35]) == [20, -30, 21, -31, 22, -32, 23, -33, 24, -34, 25, -35]\n assert candidate(nums = [13, -13, 11, -11, 9, -9, 7, -7, 5, -5, 3, -3, 1, -1, 14, -14, 12, -12, 10, -10, 8, -8, 6, -6, 4, -4, 2, -2]) == [13, -13, 11, -11, 9, -9, 7, -7, 5, -5, 3, -3, 1, -1, 14, -14, 12, -12, 10, -10, 8, -8, 6, -6, 4, -4, 2, -2]\n assert candidate(nums = [7, 10, -1, -4, 9, -2, 6, -8]) == [7, -1, 10, -4, 9, -2, 6, -8]\n assert candidate(nums = [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, 3, 5, 7, -1, -3, -5, -7, 9, 11, -9, -11, 13, 15, -13, -15]) == [1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -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, 21, -22, 23, -24, 25, -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, -25]\n assert candidate(nums = [10, -1, 12, -2, 14, -3, 15, -4, 16, -5]) == [10, -1, 12, -2, 14, -3, 15, -4, 16, -5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, -10, -20, -30, -40, -50, -60]) == [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60]\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, -20, -18, -16, -14, -12, -10, -8, -6, -4, -2]) == [20, -20, 18, -18, 16, -16, 14, -14, 12, -12, 10, -10, 8, -8, 6, -6, 4, -4, 2, -2]\n assert candidate(nums = [7, 10, -2, -8, 1, -3, 9, -4, 5, -6]) == [7, -2, 10, -8, 1, -3, 9, -4, 5, -6]\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]\n", "comparison": "exact"}, "public_tests": ["[3,1,-2,-5,2,-4]", "[-1,1]"], "hints": ["Divide the array into two parts- one comprising of only positive integers and the other of negative integers.", "Merge the two parts to get the resultant array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().rearrangeArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:53+00:00", "tests_total": 99, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "php", "interface": {"raw_signature": "function rearrangeArray($nums) {", "container": "Solution", "callable": "rearrangeArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2150, "task_id": "find-all-lonely-numbers-in-the-array", "difficulty": "Medium", "problem_description": "You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.\n\nReturn all lonely numbers in nums. You may return the answer in any order.\n\nExample 1:\n\nInput: nums = [10,6,5,8]\nOutput: [10,8]\nExplanation:\n- 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.\n- 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.\n- 5 is not a lonely number since 6 appears in nums and vice versa.\nHence, the lonely numbers in nums are [10, 8].\nNote that [8, 10] may also be returned.\n\nExample 2:\n\nInput: nums = [1,3,5,3]\nOutput: [1,5]\nExplanation:\n- 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.\n- 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.\n- 3 is not a lonely number since it appears twice.\nHence, the lonely numbers in nums are [1, 5].\nNote that [5, 1] may also be returned.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^6\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(nums=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), [])\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12, 14]), [2, 4, 6, 8, 10, 12, 14])\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), [])\n assert answers_match(candidate(nums=[10, 6, 5, 8]), [10, 8])\n assert answers_match(candidate(nums=[7, 7, 7, 7, 7, 7, 7]), [])\n assert answers_match(candidate(nums=[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]), [])\n assert answers_match(candidate(nums=[1, 2, 3, 5, 7, 9, 11]), [5, 7, 9, 11])\n assert answers_match(candidate(nums=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), [])\n assert answers_match(candidate(nums=[1, 2, 3, 5, 7, 8, 10]), [5, 10])\n assert answers_match(candidate(nums=[1, 1, 3, 3, 5, 5, 7, 7, 9, 9]), [])\n assert answers_match(candidate(nums=[2]), [2])\n assert answers_match(candidate(nums=[5, 5, 5, 5, 5]), [])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0]), [])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1]), [])\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5]), [])\n assert answers_match(candidate(nums=[1, 2, 4, 6, 8, 10]), [4, 6, 8, 10])\n assert answers_match(candidate(nums=[1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 10]), [])\n assert answers_match(candidate(nums=[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]), [])\n assert answers_match(candidate(nums=[1000000]), [1000000])\n assert answers_match(candidate(nums=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [])\n assert answers_match(candidate(nums=[0, 1, 2, 3, 4, 5, 6]), [])\n assert answers_match(candidate(nums=[1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10]), [])\n assert answers_match(candidate(nums=[7, 7, 8, 8, 9, 9, 10, 10, 11, 11]), [])\n assert answers_match(candidate(nums=[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]), [])\n assert answers_match(candidate(nums=[1, 3, 5, 3]), [1, 5])\n assert answers_match(candidate(nums=[1, 1, 1, 2, 2, 2, 3, 3, 3]), [])\n assert answers_match(candidate(nums=[5]), [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]), [])\n assert answers_match(candidate(nums=[5, 7, 9, 11, 13, 15]), [5, 7, 9, 11, 13, 15])\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31])\n assert answers_match(candidate(nums=[1, 3, 6, 8, 10, 12, 15, 17, 19, 21, 24, 26, 28, 30, 33, 35, 37]), [1, 3, 6, 8, 10, 12, 15, 17, 19, 21, 24, 26, 28, 30, 33, 35, 37])\n assert answers_match(candidate(nums=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100])\n assert answers_match(candidate(nums=[500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520]), [])\n assert answers_match(candidate(nums=[100000, 99998, 100002, 99996, 99994, 100004, 100006, 100010, 100012, 100014]), [100000, 99998, 100002, 99996, 99994, 100004, 100006, 100010, 100012, 100014])\n assert answers_match(candidate(nums=[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]), [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000])\n assert answers_match(candidate(nums=[1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]), [4, 6, 8, 10, 12, 14, 16, 18, 20])\n assert answers_match(candidate(nums=[100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000]), [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000])\n assert answers_match(candidate(nums=[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29]), [])\n assert answers_match(candidate(nums=[1000000, 999998, 999999, 1, 0, 2, 3, 4, 5, 6, 7, 8, 9]), [])\n assert answers_match(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]), [])\n assert answers_match(candidate(nums=[3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 19, 20, 21, 23, 24, 25, 27, 28]), [])\n assert answers_match(candidate(nums=[3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117]), [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117])\n assert answers_match(candidate(nums=[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]), [])\n assert answers_match(candidate(nums=[8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136]), [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136])\n assert answers_match(candidate(nums=[1, 2, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55]), [4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55])\n assert answers_match(candidate(nums=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29])\n assert answers_match(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, 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])\n assert answers_match(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, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39])\n assert answers_match(candidate(nums=[999999, 999997, 999995, 999993, 999991, 999989, 999987, 999985, 999983, 999981, 999979, 999977, 999975]), [999999, 999997, 999995, 999993, 999991, 999989, 999987, 999985, 999983, 999981, 999979, 999977, 999975])\n assert answers_match(candidate(nums=[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]), [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 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]), [])\n assert answers_match(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, 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])\n assert answers_match(candidate(nums=[1, 1, 2, 3, 3, 5, 7, 8, 8, 10, 11, 13, 13, 15]), [5, 15])\n assert answers_match(candidate(nums=[2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78]), [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78])\n assert answers_match(candidate(nums=[1, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9, 10]), [])\n assert answers_match(candidate(nums=[100, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125]), [103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125])\n assert answers_match(candidate(nums=[2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59]), [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59])\n assert answers_match(candidate(nums=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85])\n assert answers_match(candidate(nums=[8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160]), [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160])\n assert answers_match(candidate(nums=[5, 5, 5, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45]), [45])\n assert answers_match(candidate(nums=[15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]), [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100])\n assert answers_match(candidate(nums=[5, 9, 15, 21, 27, 33, 39, 45, 51, 57]), [5, 9, 15, 21, 27, 33, 39, 45, 51, 57])\n assert answers_match(candidate(nums=[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]), [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])\n assert answers_match(candidate(nums=[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]), [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])\n assert answers_match(candidate(nums=[11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]), [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89])\n assert answers_match(candidate(nums=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50])\n assert answers_match(candidate(nums=[100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120]), [100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120])\n assert answers_match(candidate(nums=[100, 102, 104, 105, 107, 109, 110, 112, 114]), [100, 102, 107, 112, 114])\n assert answers_match(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, 27, 28, 29, 30]), [])\n assert answers_match(candidate(nums=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]), [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42])\n assert answers_match(candidate(nums=[11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220]), [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220])\n assert answers_match(candidate(nums=[42, 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]), [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 assert answers_match(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]), [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])\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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]), [])\n assert answers_match(candidate(nums=[2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35]), [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35])\n assert answers_match(candidate(nums=[10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 80, 90, 90]), [])\n assert answers_match(candidate(nums=[10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]), [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30])\n assert answers_match(candidate(nums=[100000, 100001, 100003, 100005, 100007, 100009, 100011, 100013, 100015, 100017]), [100003, 100005, 100007, 100009, 100011, 100013, 100015, 100017])\n assert answers_match(candidate(nums=[1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]), [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38])\n assert answers_match(candidate(nums=[10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28]), [])\n assert answers_match(candidate(nums=[1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51]), [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51])\n assert answers_match(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, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49])\n assert answers_match(candidate(nums=[1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77]), [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77])\n assert answers_match(candidate(nums=[1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]), [])\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]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40])\n assert answers_match(candidate(nums=[0, 0, 0, 1, 1, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16]), [])\n assert answers_match(candidate(nums=[1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58]), [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58])\n assert answers_match(candidate(nums=[5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]), [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41])\n assert answers_match(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]), [])\n assert answers_match(candidate(nums=[500000, 500002, 500004, 500006, 500008, 500010, 500012, 500014, 500016, 500018, 500020]), [500000, 500002, 500004, 500006, 500008, 500010, 500012, 500014, 500016, 500018, 500020])\n assert answers_match(candidate(nums=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]), [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60])\n assert answers_match(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]), [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])\n assert answers_match(candidate(nums=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]), [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384])\n assert answers_match(candidate(nums=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32])\n assert answers_match(candidate(nums=[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]), [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60])\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]), [])\n assert answers_match(candidate(nums=[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]), [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39])\n assert answers_match(candidate(nums=[50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78]), [50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78])\n assert answers_match(candidate(nums=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]), [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43])\n assert answers_match(candidate(nums=[1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 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 answers_match(candidate(nums=[1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 29, 30, 33, 34]), [])\n assert answers_match(candidate(nums=[6, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31]), [])\n assert answers_match(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]), [])\n assert answers_match(candidate(nums=[5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81]), [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81])\n assert answers_match(candidate(nums=[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26]), [])\n assert answers_match(candidate(nums=[2, 4, 7, 9, 11, 13, 16, 18, 20, 22, 25, 27, 29, 31, 34, 36, 38]), [2, 4, 7, 9, 11, 13, 16, 18, 20, 22, 25, 27, 29, 31, 34, 36, 38])\n assert answers_match(candidate(nums=[1000, 1002, 1004, 1006, 1008, 1010, 1012, 1014, 1016, 1018, 1020, 1022, 1024]), [1000, 1002, 1004, 1006, 1008, 1010, 1012, 1014, 1016, 1018, 1020, 1022, 1024])\n assert answers_match(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, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200])\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]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40])\n assert answers_match(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]), [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])\n assert answers_match(candidate(nums=[1000000, 999998, 999996, 999994, 999992, 999990, 999988]), [1000000, 999998, 999996, 999994, 999992, 999990, 999988])\n assert answers_match(candidate(nums=[2, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52]), [2, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52])\n assert answers_match(candidate(nums=[100000, 100001, 100003, 100005, 100007, 100009, 100011, 100013, 100015, 100017, 100019, 100021, 100023, 100025, 100027, 100029, 100031]), [100003, 100005, 100007, 100009, 100011, 100013, 100015, 100017, 100019, 100021, 100023, 100025, 100027, 100029, 100031])\n assert answers_match(candidate(nums=[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29]), [])\n assert answers_match(candidate(nums=[1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31]), [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31])\n assert answers_match(candidate(nums=[1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]), [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200])\n assert answers_match(candidate(nums=[5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]), [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195])\n assert answers_match(candidate(nums=[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]), [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140])\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]), [])\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, 42]), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42])\n assert answers_match(candidate(nums=[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]), [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98])\n assert answers_match(candidate(nums=[1, 1, 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 answers_match(candidate(nums=[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]), [5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946])\n assert answers_match(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, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39])\n assert answers_match(candidate(nums=[3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43]), [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43])\n assert answers_match(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, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200])\n assert answers_match(candidate(nums=[5, 7, 12, 15, 16, 18, 20, 22, 25, 26, 27, 30]), [5, 7, 12, 18, 20, 22, 30])\n assert answers_match(candidate(nums=[100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138]), [100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138])\n assert answers_match(candidate(nums=[1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18, 19, 20]), [])\n assert answers_match(candidate(nums=[1000, 1002, 1003, 1005, 1007, 1008, 1010, 1011, 1013, 1015, 1017, 1019]), [1000, 1005, 1013, 1015, 1017, 1019])\n assert answers_match(candidate(nums=[1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]), [])\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]), [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])\n assert answers_match(candidate(nums=[3, 4, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31, 32, 35, 36]), [])\n assert answers_match(candidate(nums=[1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010]), [])\n assert answers_match(candidate(nums=[2, 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]), [2, 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])\n assert answers_match(candidate(nums=[1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81]), [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81])\n assert answers_match(candidate(nums=[15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300]), [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300])\n assert answers_match(candidate(nums=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]), [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55])\n assert answers_match(candidate(nums=[100, 101, 103, 104, 106, 108, 110, 111, 113, 115, 117, 119]), [106, 108, 113, 115, 117, 119])\n assert answers_match(candidate(nums=[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]), [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])\n assert answers_match(candidate(nums=[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]), [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150])\n assert answers_match(candidate(nums=[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20]), [])\n assert answers_match(candidate(nums=[4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60]), [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60])\n assert answers_match(candidate(nums=[42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840]), [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672, 714, 756, 798, 840])\n", "comparison": "unordered"}, "public_tests": ["[10,6,5,8]", "[1,3,5,3]"], "hints": ["For a given element x, how can you quickly check if x - 1 and x + 1 are present in the array without reiterating through the entire array?", "Use a set or a hash map."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findLonely", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:55+00:00", "tests_total": 148, "tests_dropped": 4, "flags": ["any_order"], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function findLonely($nums) {", "container": "Solution", "callable": "findLonely", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2151, "task_id": "maximum-good-people-based-on-statements", "difficulty": "Hard", "problem_description": "There are two types of persons:\n\n- The good person: The person who always tells the truth.\n- The bad person: The person who might tell the truth and might lie.\n\nYou are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statements[i][j] could be one of the following:\n\n- 0 which represents a statement made by person i that person j is a bad person.\n- 1 which represents a statement made by person i that person j is a good person.\n- 2 represents that no statement is made by person i about person j.\n\nAdditionally, no person ever makes a statement about themselves. Formally, we have that statements[i][i] = 2 for all 0 <= i < n.\n\nReturn the maximum number of people who can be good based on the statements made by the n people.\n\nExample 1:\n\nInput: statements = [[2,1,2],[1,2,2],[2,0,2]]\nOutput: 2\nExplanation: Each person makes a single statement.\n- Person 0 states that person 1 is good.\n- Person 1 states that person 0 is good.\n- Person 2 states that person 1 is bad.\nLet's take person 2 as the key.\n- Assuming that person 2 is a good person:\n - Based on the statement made by person 2, person 1 is a bad person.\n - Now we know for sure that person 1 is bad and person 2 is good.\n - Based on the statement made by person 1, and since person 1 is bad, they could be:\n - telling the truth. There will be a contradiction in this case and this assumption is invalid.\n - lying. In this case, person 0 is also a bad person and lied in their statement.\n - Following that person 2 is a good person, there will be only one good person in the group.\n- Assuming that person 2 is a bad person:\n - Based on the statement made by person 2, and since person 2 is bad, they could be:\n - telling the truth. Following this scenario, person 0 and 1 are both bad as explained before.\n - Following that person 2 is bad but told the truth, there will be no good persons in the group.\n - lying. In this case person 1 is a good person.\n - Since person 1 is a good person, person 0 is also a good person.\n - Following that person 2 is bad and lied, there will be two good persons in the group.\nWe can see that at most 2 persons are good in the best case, so we return 2.\nNote that there is more than one way to arrive at this conclusion.\n\nExample 2:\n\nInput: statements = [[2,0],[0,2]]\nOutput: 1\nExplanation: Each person makes a single statement.\n- Person 0 states that person 1 is bad.\n- Person 1 states that person 0 is bad.\nLet's take person 0 as the key.\n- Assuming that person 0 is a good person:\n - Based on the statement made by person 0, person 1 is a bad person and was lying.\n - Following that person 0 is a good person, there will be only one good person in the group.\n- Assuming that person 0 is a bad person:\n - Based on the statement made by person 0, and since person 0 is bad, they could be:\n - telling the truth. Following this scenario, person 0 and 1 are both bad.\n - Following that person 0 is bad but told the truth, there will be no good persons in the group.\n - lying. In this case person 1 is a good person.\n - Following that person 0 is bad and lied, there will be only one good person in the group.\nWe can see that at most, one person is good in the best case, so we return 1.\nNote that there is more than one way to arrive at this conclusion.\n\nConstraints:\n\n- n == statements.length == statements[i].length\n- 2 <= n <= 15\n- statements[i][j] is either 0, 1, or 2.\n- statements[i][i] == 2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(statements = [[2, 1, 2], [1, 2, 2], [2, 0, 2]]) == 2\n assert candidate(statements = [[2, 1, 0, 2], [1, 2, 2, 0], [0, 2, 2, 1], [2, 0, 1, 2]]) == 2\n assert candidate(statements = [[2, 2], [2, 2]]) == 2\n assert candidate(statements = [[2, 1, 0, 0], [0, 2, 1, 0], [1, 1, 2, 0], [0, 0, 0, 2]]) == 1\n assert candidate(statements = [[2, 1, 1], [0, 2, 1], [0, 0, 2]]) == 1\n assert candidate(statements = [[2, 2, 0, 0], [2, 2, 0, 0], [0, 0, 2, 1], [0, 0, 1, 2]]) == 2\n assert candidate(statements = [[2, 0, 0], [0, 2, 0], [0, 0, 2]]) == 1\n assert candidate(statements = [[2, 2, 2], [2, 2, 2], [2, 2, 2]]) == 3\n assert candidate(statements = [[2, 0, 0, 0, 0], [0, 2, 1, 1, 1], [0, 1, 2, 1, 0], [0, 1, 1, 2, 1], [0, 1, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 1], [0, 2]]) == 1\n assert candidate(statements = [[2, 1, 0], [1, 2, 1], [0, 1, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 2], [2, 2, 0, 2], [2, 0, 2, 2], [2, 2, 2, 2]]) == 3\n assert candidate(statements = [[2, 0, 0, 0], [0, 2, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]]) == 1\n assert candidate(statements = [[2, 1, 1], [1, 2, 1], [1, 1, 2]]) == 3\n assert candidate(statements = [[2, 0], [0, 2]]) == 1\n assert candidate(statements = [[2, 2, 2, 0], [2, 2, 2, 1], [2, 2, 2, 0], [1, 0, 1, 2]]) == 2\n assert candidate(statements = [[2, 0, 1], [0, 2, 1], [1, 1, 2]]) == 0\n assert candidate(statements = [[2, 0, 1, 2], [1, 2, 0, 2], [0, 0, 2, 1], [2, 2, 1, 2]]) == 2\n assert candidate(statements = [[2, 0, 0, 1, 0, 1], [0, 2, 1, 0, 0, 0], [0, 1, 2, 1, 1, 0], [1, 0, 1, 2, 1, 1], [0, 0, 1, 1, 2, 0], [1, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 2, 1, 2, 1, 2, 0], [1, 2, 2, 0, 1, 0, 1, 0, 1], [0, 2, 2, 1, 0, 1, 0, 1, 0], [2, 0, 1, 2, 0, 2, 1, 2, 1], [1, 1, 0, 0, 2, 1, 0, 1, 0], [2, 0, 1, 2, 1, 2, 1, 2, 0], [1, 0, 1, 0, 0, 1, 2, 1, 1], [2, 1, 0, 2, 0, 2, 1, 2, 0], [0, 1, 0, 1, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 2, 1], [1, 2, 1, 0, 2], [0, 1, 2, 1, 0], [2, 0, 1, 2, 0], [1, 2, 0, 0, 2]]) == 0\n assert candidate(statements = [[2, 0, 2, 1, 0, 2, 0], [0, 2, 0, 0, 2, 0, 1], [2, 0, 2, 0, 2, 1, 0], [1, 0, 0, 2, 0, 0, 1], [0, 2, 2, 0, 2, 0, 0], [2, 0, 1, 0, 0, 2, 1], [0, 1, 0, 1, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2], [2, 2, 1, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0, 0], [2, 0, 1, 2, 1, 0, 0], [2, 0, 0, 1, 2, 1, 0], [2, 0, 0, 0, 1, 2, 1], [2, 0, 0, 0, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 0, 0, 1, 1, 0], [0, 2, 1, 0, 1, 1], [0, 1, 2, 1, 0, 0], [1, 0, 1, 2, 1, 1], [1, 1, 0, 1, 2, 0], [0, 1, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 1, 0, 0, 1, 0], [2, 2, 1, 1, 0, 2, 2, 0], [2, 1, 2, 2, 0, 0, 2, 1], [1, 1, 2, 2, 2, 1, 0, 0], [0, 0, 0, 2, 2, 0, 2, 1], [0, 2, 0, 1, 0, 2, 2, 1], [1, 2, 2, 0, 2, 2, 2, 0], [0, 0, 1, 0, 1, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 2, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 2, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 2, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 2, 0], [2, 0, 0, 0, 0, 0, 0, 0, 0, 2]]) == 2\n assert candidate(statements = [[2, 1, 1, 0, 0], [1, 2, 1, 0, 0], [1, 1, 2, 1, 1], [0, 0, 1, 2, 0], [0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 1, 0], [1, 2, 1, 0, 1], [0, 1, 2, 0, 0], [1, 0, 0, 2, 1], [0, 1, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 0, 0, 1, 0, 0], [0, 2, 1, 0, 1, 0], [0, 1, 2, 0, 0, 1], [1, 0, 0, 2, 1, 0], [0, 1, 0, 1, 2, 0], [0, 0, 1, 0, 0, 2]]) == 0\n assert candidate(statements = [[2, 0, 1, 0, 1, 1, 0, 1, 0], [0, 2, 1, 0, 1, 0, 1, 1, 0], [1, 1, 2, 0, 1, 0, 0, 0, 1], [0, 0, 0, 2, 1, 1, 1, 0, 1], [1, 1, 1, 1, 2, 1, 0, 0, 0], [1, 0, 0, 1, 1, 2, 1, 0, 1], [0, 1, 0, 1, 0, 1, 2, 1, 0], [1, 1, 0, 0, 0, 0, 1, 2, 1], [0, 0, 1, 1, 0, 1, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 0, 1, 1, 0, 0, 1, 0, 1, 1], [0, 2, 0, 0, 1, 1, 0, 1, 0, 0], [1, 0, 2, 1, 0, 1, 0, 1, 1, 0], [1, 0, 1, 2, 0, 1, 1, 0, 0, 1], [0, 1, 0, 0, 2, 1, 0, 1, 1, 0], [0, 1, 1, 1, 1, 2, 0, 0, 1, 1], [1, 0, 1, 0, 0, 0, 2, 1, 1, 0], [0, 1, 0, 1, 1, 0, 1, 2, 0, 1], [1, 0, 1, 0, 1, 1, 1, 0, 2, 0], [1, 0, 0, 1, 0, 1, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0, 0], [0, 1, 2, 1, 0, 0, 0, 0], [0, 0, 1, 2, 1, 0, 0, 0], [0, 0, 0, 1, 2, 1, 0, 0], [0, 0, 0, 0, 1, 2, 1, 0], [0, 0, 0, 0, 0, 1, 2, 1], [0, 0, 0, 0, 0, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 2, 1, 0, 2, 0, 2, 1, 0, 1, 2], [2, 2, 0, 1, 2, 0, 2, 0, 1, 0, 2], [1, 0, 2, 2, 0, 1, 2, 1, 2, 0, 1], [0, 1, 2, 2, 1, 0, 2, 0, 1, 2, 0], [2, 2, 0, 1, 2, 0, 2, 0, 1, 0, 2], [0, 0, 1, 0, 0, 2, 2, 0, 0, 1, 1], [2, 2, 2, 0, 2, 2, 2, 0, 2, 0, 2], [1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 1], [0, 1, 2, 1, 1, 0, 2, 1, 2, 0, 0], [1, 0, 0, 2, 0, 1, 0, 0, 0, 2, 1], [2, 2, 1, 0, 2, 1, 2, 1, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 0, 1, 1, 0, 1, 0], [0, 2, 0, 0, 1, 0, 1], [1, 0, 2, 0, 0, 1, 0], [1, 0, 0, 2, 1, 0, 1], [0, 1, 0, 1, 2, 1, 0], [1, 0, 1, 0, 1, 2, 1], [0, 1, 0, 1, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 0, 1, 0], [2, 2, 0, 1, 0, 1], [2, 0, 2, 1, 1, 0], [0, 1, 1, 2, 2, 2], [1, 0, 1, 2, 2, 0], [0, 1, 0, 2, 0, 2]]) == 0\n assert candidate(statements = [[2, 0, 1, 0, 1, 1], [0, 2, 0, 0, 0, 0], [1, 0, 2, 1, 1, 0], [0, 0, 1, 2, 0, 1], [1, 0, 1, 0, 2, 1], [1, 0, 0, 1, 1, 2]]) == 1\n assert candidate(statements = [[2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2]]) == 1\n assert candidate(statements = [[2, 1, 0, 2, 1], [1, 2, 1, 2, 0], [0, 1, 2, 0, 2], [2, 2, 0, 2, 1], [1, 0, 2, 1, 2]]) == 0\n assert candidate(statements = [[2, 0, 0, 0, 0, 0, 0], [0, 2, 1, 1, 1, 1, 0], [0, 1, 2, 1, 0, 0, 1], [0, 1, 1, 2, 1, 0, 1], [0, 1, 0, 1, 2, 1, 0], [0, 1, 0, 0, 1, 2, 1], [0, 0, 1, 1, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 2, 2, 0, 0, 0, 0, 0], [2, 2, 0, 2, 0, 0, 0, 0], [2, 0, 2, 0, 2, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 2, 0, 2, 0, 2], [0, 0, 0, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 2, 0, 2]]) == 2\n assert candidate(statements = [[2, 2, 1, 0, 0], [2, 2, 0, 0, 1], [1, 0, 2, 0, 1], [0, 0, 0, 2, 0], [0, 1, 1, 0, 2]]) == 1\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2], [2, 2, 0, 0, 0, 0, 0], [2, 0, 2, 0, 1, 0, 1], [2, 0, 0, 2, 0, 1, 0], [2, 0, 1, 0, 2, 0, 1], [2, 0, 0, 1, 0, 2, 0], [2, 0, 1, 0, 1, 0, 2]]) == 4\n assert candidate(statements = [[2, 1, 0, 0, 0, 0, 1], [1, 2, 1, 1, 1, 0, 0], [0, 1, 2, 0, 1, 1, 1], [0, 1, 0, 2, 1, 0, 0], [0, 1, 1, 1, 2, 1, 0], [0, 0, 1, 0, 1, 2, 1], [1, 0, 1, 0, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 2, 0, 1, 1, 0], [2, 2, 1, 1, 0, 0], [0, 1, 2, 0, 1, 1], [1, 1, 0, 2, 0, 1], [1, 0, 1, 0, 2, 0], [0, 0, 1, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 2, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 2, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 2, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]]) == 10\n assert candidate(statements = [[2, 0, 1, 1, 0, 0], [0, 2, 2, 1, 1, 0], [1, 2, 2, 0, 0, 1], [1, 1, 0, 2, 2, 1], [0, 1, 0, 2, 2, 0], [0, 0, 1, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 0, 0, 1, 1, 0, 0], [2, 0, 2, 1, 2, 0, 1, 1], [2, 0, 1, 2, 0, 1, 0, 1], [2, 1, 2, 0, 2, 0, 1, 0], [2, 1, 0, 1, 0, 2, 1, 0], [2, 0, 1, 0, 1, 1, 2, 1], [2, 0, 1, 1, 0, 0, 1, 2]]) == 1\n assert candidate(statements = [[2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2]]) == 8\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [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(statements = [[2, 2, 2, 2, 1, 0], [2, 2, 2, 1, 0, 2], [2, 2, 2, 1, 2, 1], [2, 1, 1, 2, 0, 1], [1, 0, 2, 0, 2, 2], [0, 2, 1, 1, 2, 2]]) == 4\n assert candidate(statements = [[2, 1, 0, 0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 1, 1, 1, 1, 1], [0, 1, 2, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 2, 0, 0], [0, 1, 0, 0, 0, 0, 0, 2, 0], [0, 1, 0, 0, 0, 0, 0, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 1, 0, 0, 0, 0, 0], [2, 2, 0, 1, 0, 0, 0, 0], [1, 0, 2, 0, 1, 0, 0, 0], [0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 1, 0, 2, 0, 1], [0, 0, 0, 0, 1, 0, 2, 0], [0, 0, 0, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 1, 0, 1], [1, 2, 0, 1, 0], [1, 0, 2, 0, 1], [0, 1, 0, 2, 1], [1, 0, 1, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 1, 1, 0, 1], [1, 2, 0, 0, 1, 0], [1, 0, 2, 1, 0, 0], [1, 0, 1, 2, 1, 0], [0, 1, 0, 1, 2, 1], [1, 0, 0, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 2, 1, 0, 1, 0], [0, 0, 0, 0, 0, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 2, 0, 1], [0, 0, 0, 0, 0, 1, 0, 0, 2, 0], [0, 0, 0, 0, 1, 0, 0, 1, 0, 2]]) == 2\n assert candidate(statements = [[2, 2, 2, 2, 0, 0, 0, 0], [2, 2, 2, 2, 0, 0, 0, 0], [2, 2, 2, 2, 0, 0, 0, 0], [2, 2, 2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 2, 2, 2, 2], [0, 0, 0, 0, 2, 2, 2, 2], [0, 0, 0, 0, 2, 2, 2, 2], [0, 0, 0, 0, 2, 2, 2, 2]]) == 4\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2, 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], [2, 2, 2, 1, 2, 2, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2, 2, 2]]) == 9\n assert candidate(statements = [[2, 1, 1, 0, 1, 2, 0], [1, 2, 0, 1, 0, 1, 0], [1, 0, 2, 1, 0, 0, 1], [0, 1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 2, 1, 1], [2, 1, 0, 0, 1, 2, 0], [0, 0, 1, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 0, 0, 1, 0, 0], [0, 2, 1, 0, 1, 1], [0, 1, 2, 1, 0, 0], [1, 0, 1, 2, 0, 1], [0, 1, 0, 0, 2, 0], [0, 1, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0, 0], [1, 1, 2, 1, 1, 1, 0], [0, 0, 1, 2, 1, 0, 1], [0, 0, 1, 1, 2, 1, 0], [0, 0, 1, 0, 1, 2, 1], [0, 0, 0, 1, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 2, 0, 2, 1, 2, 0, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 0, 2, 1, 2, 0, 2, 1], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2], [2, 1, 2, 0, 2, 1, 2, 0, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 0, 2, 1, 2, 0, 2, 1], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2], [2, 1, 2, 0, 2, 1, 2, 0, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]]) == 8\n assert candidate(statements = [[2, 1, 1, 1, 0, 1, 1, 0], [1, 2, 0, 0, 1, 0, 1, 0], [1, 0, 2, 1, 0, 0, 0, 1], [1, 0, 1, 2, 1, 0, 1, 0], [0, 1, 0, 1, 2, 1, 1, 0], [1, 0, 0, 0, 1, 2, 0, 1], [1, 1, 0, 1, 1, 0, 2, 0], [0, 0, 1, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 1, 1, 1, 0, 0], [1, 2, 0, 0, 1, 1], [1, 0, 2, 1, 0, 0], [1, 0, 1, 2, 1, 0], [0, 1, 0, 1, 2, 1], [0, 1, 0, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 1, 0, 0, 0, 0, 0, 0], [1, 2, 0, 1, 0, 0, 0, 0, 0], [1, 0, 2, 0, 1, 0, 0, 0, 0], [0, 1, 0, 2, 0, 1, 0, 0, 0], [0, 0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 0, 1, 0, 2, 0, 1], [0, 0, 0, 0, 0, 1, 0, 2, 0], [0, 0, 0, 0, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 1, 2, 0, 1, 0], [2, 2, 2, 0, 2, 1, 0, 1], [2, 2, 2, 1, 0, 0, 0, 0], [1, 0, 1, 2, 2, 1, 0, 0], [2, 2, 0, 2, 2, 0, 1, 0], [0, 1, 0, 1, 0, 2, 0, 1], [1, 0, 0, 0, 1, 0, 2, 0], [0, 1, 0, 0, 0, 1, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2], [2, 2, 1, 1, 0, 0, 0], [2, 1, 2, 0, 2, 1, 0], [2, 1, 0, 2, 2, 0, 1], [2, 0, 2, 2, 2, 1, 1], [2, 0, 1, 0, 1, 2, 0], [2, 0, 0, 1, 1, 0, 2]]) == 1\n assert candidate(statements = [[2, 1, 0, 2, 1, 2], [1, 2, 2, 0, 1, 0], [0, 2, 2, 1, 0, 1], [2, 0, 1, 2, 0, 2], [1, 1, 0, 0, 2, 1], [2, 0, 1, 2, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 2, 0, 1, 0, 1, 0, 0], [1, 2, 0, 1, 0, 1, 0, 1, 1], [2, 0, 2, 1, 0, 0, 1, 0, 0], [0, 1, 1, 2, 0, 0, 0, 1, 1], [1, 0, 0, 0, 2, 1, 1, 0, 0], [0, 1, 0, 1, 1, 2, 0, 1, 1], [1, 0, 1, 0, 1, 0, 2, 0, 0], [0, 1, 0, 1, 0, 1, 0, 2, 1], [0, 1, 0, 1, 0, 1, 0, 1, 2]]) == 0\n assert candidate(statements = [[2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 1, 1, 0, 0], [0, 0, 0, 2, 0, 0, 1, 0], [0, 0, 1, 0, 2, 0, 0, 1], [0, 0, 1, 0, 0, 2, 1, 0], [0, 0, 0, 1, 0, 1, 2, 0], [0, 0, 0, 0, 1, 0, 0, 2]]) == 2\n assert candidate(statements = [[2, 1, 1, 0, 0, 0, 0, 0, 0], [1, 2, 0, 1, 0, 0, 0, 0, 0], [1, 0, 2, 1, 0, 0, 0, 0, 0], [0, 1, 1, 2, 0, 1, 0, 0, 0], [0, 0, 0, 0, 2, 0, 1, 0, 1], [0, 0, 0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 0, 1, 0, 2, 1, 0], [0, 0, 0, 0, 0, 1, 1, 2, 0], [0, 0, 0, 0, 1, 0, 0, 0, 2]]) == 0\n assert candidate(statements = [[2, 2, 2, 2, 2, 2, 2], [2, 2, 0, 1, 1, 1, 0], [2, 0, 2, 0, 1, 0, 0], [2, 1, 0, 2, 0, 1, 1], [2, 1, 1, 0, 2, 0, 1], [2, 1, 0, 1, 0, 2, 0], [2, 0, 0, 1, 1, 0, 2]]) == 1\n", "comparison": "exact"}, "public_tests": ["[[2,1,2],[1,2,2],[2,0,2]]", "[[2,0],[0,2]]"], "hints": ["You should test every possible assignment of good and bad people, using a bitmask.", "In each bitmask, if the person i is good, then his statements should be consistent with the bitmask in order for the assignment to be valid.", "If the assignment is valid, count how many people are good and keep track of the maximum."], "metadata": {"canonical_parameter_names": ["statements"], "leetcode_dataset_entry_point": "Solution().maximumGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:42:58+00:00", "tests_total": 75, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "backtracking", "bit-manipulation", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function maximumGood($statements) {", "container": "Solution", "callable": "maximumGood", "parameters": [{"name": "statements", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2154, "task_id": "keep-multiplying-found-values-by-two", "difficulty": "Easy", "problem_description": "You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.\n\nYou then do the following steps:\n\n1. If original is found in nums, multiply it by two (i.e., set original = 2 * original).\n2. Otherwise, stop the process.\n3. Repeat this process with the new number as long as you keep finding the number.\n\nReturn the final value of original.\n\nExample 1:\n\nInput: nums = [5,3,6,1,12], original = 3\nOutput: 24\nExplanation:\n- 3 is found in nums. 3 is multiplied by 2 to obtain 6.\n- 6 is found in nums. 6 is multiplied by 2 to obtain 12.\n- 12 is found in nums. 12 is multiplied by 2 to obtain 24.\n- 24 is not found in nums. Thus, 24 is returned.\n\nExample 2:\n\nInput: nums = [2,7,9], original = 4\nOutput: 4\nExplanation:\n- 4 is not found in nums. Thus, 4 is returned.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i], original <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],original = 5) == 5\n assert candidate(nums = [1000, 500, 250, 125, 625],original = 5) == 5\n assert candidate(nums = [3, 6, 9, 12, 15],original = 3) == 24\n assert candidate(nums = [1, 2, 4, 8],original = 1) == 16\n assert candidate(nums = [8, 16, 32, 64, 128],original = 8) == 256\n assert candidate(nums = [2, 7, 9],original = 4) == 4\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000],original = 1000) == 2000\n assert candidate(nums = [1, 3, 5, 7, 9],original = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],original = 10) == 80\n assert candidate(nums = [2, 2, 2, 2, 2],original = 2) == 4\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512],original = 4) == 4\n assert candidate(nums = [1000, 500, 250, 125, 62, 31],original = 1) == 1\n assert candidate(nums = [1, 1, 1, 1, 1],original = 1) == 2\n assert candidate(nums = [1, 2, 4, 8, 16],original = 1) == 32\n assert candidate(nums = [4, 8, 16, 32, 64],original = 2) == 2\n assert candidate(nums = [5, 3, 6, 1, 12],original = 3) == 24\n assert candidate(nums = [1000, 500, 250, 125],original = 125) == 2000\n assert candidate(nums = [10, 20, 40, 80, 160],original = 10) == 320\n assert candidate(nums = [7, 14, 28, 56, 112],original = 7) == 224\n assert candidate(nums = [1, 3, 5, 7, 9],original = 1) == 2\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448],original = 7) == 896\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21],original = 3) == 24\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],original = 10) == 160\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],original = 1) == 2\n assert candidate(nums = [2, 3, 5, 6, 7, 10, 11, 13, 14, 17, 19, 21, 22, 23, 26, 29, 31],original = 2) == 4\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180],original = 9) == 288\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],original = 2) == 32\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],original = 2) == 2\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80],original = 4) == 128\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],original = 1) == 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],original = 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],original = 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],original = 2) == 4\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300],original = 15) == 480\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],original = 10) == 160\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],original = 1) == 1024\n assert candidate(nums = [4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144],original = 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],original = 1) == 32\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],original = 10) == 320\n assert candidate(nums = [3, 9, 27, 81, 243, 729],original = 3) == 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, 41, 43, 45, 47, 49],original = 1) == 2\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],original = 13) == 208\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],original = 7) == 112\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198, 209, 220],original = 11) == 352\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],original = 10) == 320\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],original = 5) == 80\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],original = 7) == 112\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],original = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],original = 1) == 16\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66],original = 6) == 96\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],original = 1) == 2\n assert candidate(nums = [6, 12, 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],original = 6) == 192\n assert candidate(nums = [13, 26, 52, 104, 208, 416, 832],original = 13) == 1664\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],original = 1) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],original = 5) == 80\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],original = 15) == 240\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140],original = 7) == 224\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990],original = 990) == 1980\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260],original = 13) == 416\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],original = 5) == 160\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],original = 9) == 144\n assert candidate(nums = [500, 501, 502, 503, 504, 505, 506, 507, 508, 509],original = 500) == 1000\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],original = 7) == 112\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289, 306, 323, 340],original = 17) == 544\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],original = 4) == 128\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31],original = 2) == 4\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400],original = 1) == 2\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980],original = 980) == 1960\n assert candidate(nums = [1, 2, 3, 5, 6, 10, 12, 15, 20, 30, 60, 120, 240, 480, 960],original = 1) == 4\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896],original = 7) == 1792\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],original = 8) == 128\n assert candidate(nums = [11, 22, 44, 88, 176, 352, 704],original = 11) == 1408\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512],original = 2) == 1024\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, 3, 3, 3],original = 3) == 6\n", "comparison": "exact"}, "public_tests": ["[5,3,6,1,12]\n3", "[2,7,9]\n4"], "hints": ["Repeatedly iterate through the array and check if the current value of original is in the array.", "If original is not found, stop and return its current value.", "Otherwise, multiply original by 2 and repeat the process.", "Use set data structure to check the existence faster."], "metadata": {"canonical_parameter_names": ["nums", "original"], "leetcode_dataset_entry_point": "Solution().findFinalValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:02+00:00", "tests_total": 115, "tests_dropped": 41, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "simulation"]}, "language": "php", "interface": {"raw_signature": "function findFinalValue($nums, $original) {", "container": "Solution", "callable": "findFinalValue", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "original", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2155, "task_id": "all-divisions-with-the-highest-score-of-a-binary-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) nums_left and nums_right:\n\n- nums_left has all the elements of nums between index 0 and i - 1 (inclusive), while nums_right has all the elements of nums between index i and n - 1 (inclusive).\n- If i == 0, nums_left is empty, while nums_right has all the elements of nums.\n- If i == n, nums_left has all the elements of nums, while nums_right is empty.\n\nThe division score of an index i is the sum of the number of 0's in nums_left and the number of 1's in nums_right.\n\nReturn all distinct indices that have the highest possible division score. You may return the answer in any order.\n\nExample 1:\n\nInput: nums = [0,0,1,0]\nOutput: [2,4]\nExplanation: Division at index\n- 0: nums_left is []. nums_right is [0,0,1,0]. The score is 0 + 1 = 1.\n- 1: nums_left is [0]. nums_right is [0,1,0]. The score is 1 + 1 = 2.\n- 2: nums_left is [0,0]. nums_right is [1,0]. The score is 2 + 1 = 3.\n- 3: nums_left is [0,0,1]. nums_right is [0]. The score is 2 + 0 = 2.\n- 4: nums_left is [0,0,1,0]. nums_right is []. The score is 3 + 0 = 3.\nIndices 2 and 4 both have the highest possible division score 3.\nNote the answer [4,2] would also be accepted.\n\nExample 2:\n\nInput: nums = [0,0,0]\nOutput: [3]\nExplanation: Division at index\n- 0: nums_left is []. nums_right is [0,0,0]. The score is 0 + 0 = 0.\n- 1: nums_left is [0]. nums_right is [0,0]. The score is 1 + 0 = 1.\n- 2: nums_left is [0,0]. nums_right is [0]. The score is 2 + 0 = 2.\n- 3: nums_left is [0,0,0]. nums_right is []. The score is 3 + 0 = 3.\nOnly index 3 has the highest possible division score 3.\n\nExample 3:\n\nInput: nums = [1,1]\nOutput: [0]\nExplanation: Division at index\n- 0: nums_left is []. nums_right is [1,1]. The score is 0 + 2 = 2.\n- 1: nums_left is [1]. nums_right is [1]. The score is 0 + 1 = 1.\n- 2: nums_left is [1,1]. nums_right is []. The score is 0 + 0 = 0.\nOnly index 0 has the highest possible division score 2.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- nums[i] is either 0 or 1.\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(nums=[1, 0, 0, 0, 1, 1, 1]), [4])\n assert answers_match(candidate(nums=[0, 0, 0]), [3])\n assert answers_match(candidate(nums=[0, 0, 1, 0]), [2, 4])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0, 1]), [1, 3, 5])\n assert answers_match(candidate(nums=[1, 0, 1, 0, 1]), [0, 2, 4])\n assert answers_match(candidate(nums=[1, 1]), [0])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0]), [7])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0]), [1, 3, 5])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1]), [0])\n assert answers_match(candidate(nums=[1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]), [6, 16])\n assert answers_match(candidate(nums=[0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1]), [4, 8])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]), [0, 12, 24])\n assert answers_match(candidate(nums=[1, 0, 1, 0, 1, 0, 1, 0]), [0, 2, 4, 6, 8])\n assert answers_match(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, 5, 9, 13, 17, 21, 25, 29])\n assert answers_match(candidate(nums=[1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]), [5, 11, 17])\n assert answers_match(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, 0, 0]), [0, 8, 16, 24])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1]), [6, 18, 30])\n assert answers_match(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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29])\n assert answers_match(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, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28])\n assert answers_match(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 answers_match(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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [0])\n assert answers_match(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 answers_match(candidate(nums=[1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]), [0])\n assert answers_match(candidate(nums=[1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1]), [16])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]), [0])\n assert answers_match(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, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]), [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40])\n assert answers_match(candidate(nums=[1, 0, 0, 1, 0, 0, 1, 1, 0, 0]), [6, 10])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1]), [4])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [10])\n assert answers_match(candidate(nums=[0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]), [1, 5, 9, 13, 17])\n assert answers_match(candidate(nums=[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]), [3, 17])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]), [22])\n assert answers_match(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, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22])\n assert answers_match(candidate(nums=[0, 0, 0, 1, 1, 1, 0, 0, 0]), [3, 9])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [1, 3, 5, 7, 9, 11, 13, 15, 17])\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=[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]), [0, 12])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]), [5])\n assert answers_match(candidate(nums=[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [0, 2, 4, 6, 8, 10, 12, 14, 16])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]), [2, 6, 10, 14])\n assert answers_match(candidate(nums=[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]), [1])\n assert answers_match(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]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0]), [0, 12, 24])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]), [2])\n assert answers_match(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]), [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 0, 0, 0, 0, 1, 1]), [0, 8])\n assert answers_match(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]), [4, 12, 20, 28])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), [0])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [12])\n assert answers_match(candidate(nums=[0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1]), [1])\n assert answers_match(candidate(nums=[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0]), [3])\n assert answers_match(candidate(nums=[1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0]), [30])\n assert answers_match(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, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 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, 52, 54, 56, 58, 60, 62, 64, 66, 68])\n assert answers_match(candidate(nums=[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20])\n assert answers_match(candidate(nums=[1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [0, 2, 4, 6, 8, 10])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0]), [0, 10])\n assert answers_match(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])\n assert answers_match(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, 5, 9, 13, 17, 21, 25])\n assert answers_match(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]), [30])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]), [2, 6, 10, 14, 18, 22])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [15])\n assert answers_match(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, 0, 0, 1, 0, 0]), [38])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0]), [22])\n assert answers_match(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, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]), [4, 12])\n assert answers_match(candidate(nums=[1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]), [0, 4, 8, 12])\n assert answers_match(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])\n assert answers_match(candidate(nums=[0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [1])\n assert answers_match(candidate(nums=[1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0]), [6])\n assert answers_match(candidate(nums=[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]), [9])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0]), [2])\n assert answers_match(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, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), [20])\n assert answers_match(candidate(nums=[1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1]), [3, 7, 11, 15, 19])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0]), [5, 15])\n assert answers_match(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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])\n assert answers_match(candidate(nums=[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]), [15])\n assert answers_match(candidate(nums=[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]), [8])\n assert answers_match(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]), [3, 9, 15, 21])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1]), [0, 10])\n assert answers_match(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, 4, 8, 12, 16, 20])\n assert answers_match(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]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25])\n assert answers_match(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, 1, 1]), [31])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1]), [0, 8, 10])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), [0])\n assert answers_match(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]), [3, 7, 11, 15, 19, 23, 27])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]), [2, 6, 10])\n assert answers_match(candidate(nums=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]), [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])\n assert answers_match(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, 1]), [27])\n assert answers_match(candidate(nums=[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, 0, 0, 0, 0, 0]), [0, 16])\n assert answers_match(candidate(nums=[0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1]), [2])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]), [0, 8, 16])\n assert answers_match(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]), [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32])\n assert answers_match(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, 1, 1]), [0, 4, 8, 12, 16, 20, 24, 28])\n assert answers_match(candidate(nums=[1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1]), [0, 6, 12])\n assert answers_match(candidate(nums=[1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1]), [0, 8, 12])\n", "comparison": "unordered"}, "public_tests": ["[0,0,1,0]", "[0,0,0]", "[1,1]"], "hints": ["When you iterate the array, maintain the number of zeros and ones on the left side. Can you quickly calculate the number of ones on the right side?", "The number of ones on the right side equals the number of ones in the whole array minus the number of ones on the left side.", "Alternatively, you can quickly calculate it by using a prefix sum array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maxScoreIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:05+00:00", "tests_total": 98, "tests_dropped": 0, "flags": ["any_order"], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function maxScoreIndices($nums) {", "container": "Solution", "callable": "maxScoreIndices", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2156, "task_id": "find-substring-with-given-hash-value", "difficulty": "Hard", "problem_description": "The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:\n\n- hash(s, p, m) = (val(s[0]) * p^0 + val(s[1]) * p^1 + ... + val(s[k-1]) * p^{k-1}) mod m.\n\nWhere val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.\n\nYou are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue.\n\nThe test cases will be generated such that an answer always exists.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"leetcode\", power = 7, modulo = 20, k = 2, hashValue = 0\nOutput: \"ee\"\nExplanation: The hash of \"ee\" can be computed to be hash(\"ee\", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0.\n\"ee\" is the first substring of length 2 with hashValue 0. Hence, we return \"ee\".\n\nExample 2:\n\nInput: s = \"fbxzaad\", power = 31, modulo = 100, k = 3, hashValue = 32\nOutput: \"fbx\"\nExplanation: The hash of \"fbx\" can be computed to be hash(\"fbx\", 31, 100) = (6 * 1 + 2 * 31 + 24 * 31^2) mod 100 = 23132 mod 100 = 32.\nThe hash of \"bxz\" can be computed to be hash(\"bxz\", 31, 100) = (2 * 1 + 24 * 31 + 26 * 31^2) mod 100 = 25732 mod 100 = 32.\n\"fbx\" is the first substring of length 3 with hashValue 32. Hence, we return \"fbx\".\nNote that \"bxz\" also has a hash of 32 but it appears later than \"fbx\".\n\nConstraints:\n\n- 1 <= k <= s.length <= 2 * 10^4\n- 1 <= power, modulo <= 10^9\n- 0 <= hashValue < modulo\n- s consists of lowercase English letters only.\n- The test cases are generated such that an answer always exists.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abracadabra\",power = 5,modulo = 11,k = 3,hashValue = 4) == \"dab\"\n assert candidate(s = \"leetcode\",power = 7,modulo = 20,k = 2,hashValue = 0) == \"ee\"\n assert candidate(s = \"fbxzaad\",power = 31,modulo = 100,k = 3,hashValue = 32) == \"fbx\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",power = 26,modulo = 101,k = 5,hashValue = 53) == \"vwxyz\"\n assert candidate(s = \"a\",power = 1,modulo = 1,k = 1,hashValue = 0) == \"a\"\n assert candidate(s = \"zaz\",power = 26,modulo = 29,k = 2,hashValue = 27) == \"az\"\n assert candidate(s = \"a\",power = 13,modulo = 97,k = 1,hashValue = 1) == \"a\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",power = 13,modulo = 50,k = 5,hashValue = 37) == \"klmno\"\n assert candidate(s = \"abcde\",power = 2,modulo = 11,k = 3,hashValue = 7) == \"cde\"\n assert candidate(s = \"a\",power = 5,modulo = 13,k = 1,hashValue = 1) == \"a\"\n assert candidate(s = \"mmcp\",power = 13,modulo = 457,k = 2,hashValue = 33) == \"cp\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",power = 29,modulo = 101,k = 20,hashValue = 95) == \"zzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"hellothereeveryone\",power = 37,modulo = 101,k = 6,hashValue = 74) == \"eryone\"\n assert candidate(s = \"a\",power = 7,modulo = 13,k = 1,hashValue = 1) == \"a\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",power = 11,modulo = 79,k = 20,hashValue = 10) == \"zzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\",power = 19,modulo = 83,k = 15,hashValue = 28) == \"abcabcabcabcabc\"\n assert candidate(s = \"powerrangers\",power = 29,modulo = 97,k = 4,hashValue = 53) == \"gers\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",power = 17,modulo = 53,k = 10,hashValue = 49) == \"qrstuvwxyz\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",power = 2,modulo = 13,k = 8,hashValue = 7) == \"bcdefghi\"\n assert candidate(s = \"thisisjustanexampleofalongsstringwithseveralhashvalues\",power = 3,modulo = 100,k = 4,hashValue = 15) == \"lues\"\n assert candidate(s = \"mississippiisaverypopularstring\",power = 23,modulo = 107,k = 9,hashValue = 62) == \"larstring\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\",power = 29,modulo = 999983,k = 9,hashValue = 456789) == \"bcdefghij\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",power = 10,modulo = 10007,k = 10,hashValue = 7007) == \"zzzzzzzzzz\"\n assert candidate(s = \"abacabadabacaba\",power = 10,modulo = 61,k = 5,hashValue = 31) == \"acaba\"\n assert candidate(s = \"thisisaverylongstringthatwillbeusedtohashandfindthesubstring\",power = 19,modulo = 1000003,k = 12,hashValue = 876543) == \"thesubstring\"\n assert candidate(s = \"xyzabcxyz\",power = 17,modulo = 101,k = 4,hashValue = 70) == \"cxyz\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydog\",power = 11,modulo = 997,k = 12,hashValue = 896) == \"erthelazydog\"\n assert candidate(s = \"banana\",power = 5,modulo = 10007,k = 2,hashValue = 22) == \"na\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",power = 19,modulo = 47,k = 15,hashValue = 29) == \"onmlkjihgfedcba\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzz\",power = 23,modulo = 999983,k = 15,hashValue = 123456) == \"zzzzzzzzzzzzzzz\"\n assert candidate(s = \"thepowerofhashing\",power = 17,modulo = 10007,k = 9,hashValue = 9999) == \"ofhashing\"\n assert candidate(s = \"racecarannakayak\",power = 37,modulo = 109,k = 7,hashValue = 87) == \"nakayak\"\n assert candidate(s = \"abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\",power = 7,modulo = 13,k = 5,hashValue = 5) == \"eabcd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",power = 27,modulo = 10007,k = 26,hashValue = 4750) == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"ababababababababababababababababababababababababab\",power = 23,modulo = 29,k = 7,hashValue = 17) == \"bababab\"\n assert candidate(s = \"aaaaabbbbbccccdddddeeeeefffffggggghhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooo\",power = 11,modulo = 100000007,k = 13,hashValue = 111222) == \"mmmnnnnnooooo\"\n assert candidate(s = \"thisisaverylongstringthatshouldworkwiththehashingfunctioncorrectly\",power = 13,modulo = 107,k = 25,hashValue = 67) == \"ehashingfunctioncorrectly\"\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",power = 97,modulo = 10007,k = 6,hashValue = 10001) == \"cdabcd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",power = 17,modulo = 89,k = 10,hashValue = 67) == \"qrstuvwxyz\"\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzz\",power = 11,modulo = 97,k = 6,hashValue = 76) == \"xyzzxy\"\n assert candidate(s = \"abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\",power = 5,modulo = 17,k = 14,hashValue = 11) == \"abcdeabcdeabcd\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",power = 13,modulo = 101,k = 10,hashValue = 97) == \"qrstuvwxyz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",power = 13,modulo = 101,k = 10,hashValue = 60) == \"xyzabcdefg\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",power = 23,modulo = 41,k = 7,hashValue = 35) == \"cdefghi\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",power = 5,modulo = 1000,k = 7,hashValue = 500) == \"wxxyyzz\"\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef\",power = 41,modulo = 997,k = 12,hashValue = 500) == \"abcdefabcdef\"\n", "comparison": "exact"}, "public_tests": ["\"leetcode\"\n7\n20\n2\n0", "\"fbxzaad\"\n31\n100\n3\n32"], "hints": ["How can we update the hash value efficiently while iterating instead of recalculating it each time?", "Use the rolling hash method."], "metadata": {"canonical_parameter_names": ["s", "power", "modulo", "k", "hashValue"], "leetcode_dataset_entry_point": "Solution().subStrHash", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:07+00:00", "tests_total": 96, "tests_dropped": 50, "flags": [], "topic_tags": ["string", "sliding-window", "rolling-hash", "hash-function"]}, "language": "php", "interface": {"raw_signature": "function subStrHash($s, $power, $modulo, $k, $hashValue) {", "container": "Solution", "callable": "subStrHash", "parameters": [{"name": "s", "type": "String"}, {"name": "power", "type": "Integer"}, {"name": "modulo", "type": "Integer"}, {"name": "k", "type": "Integer"}, {"name": "hashValue", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2157, "task_id": "groups-of-strings", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.\n\nTwo strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operations:\n\n- Adding exactly one letter to the set of the letters of s1.\n- Deleting exactly one letter from the set of the letters of s1.\n- Replacing exactly one letter from the set of the letters of s1 with any letter, including itself.\n\nThe array words can be divided into one or more non-intersecting groups. A string belongs to a group if any one of the following is true:\n\n- It is connected to at least one other string of the group.\n- It is the only string present in the group.\n\nNote that the strings in words should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.\n\nReturn an array ans of size 2 where:\n\n- ans[0] is the maximum number of groups words can be divided into, and\n- ans[1] is the size of the largest group.\n\nExample 1:\n\nInput: words = [\"a\",\"b\",\"ab\",\"cde\"]\nOutput: [2,3]\nExplanation:\n- words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2].\n- words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2].\n- words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1].\n- words[3] is not connected to any string in words.\nThus, words can be divided into 2 groups [\"a\",\"b\",\"ab\"] and [\"cde\"]. The size of the largest group is 3.\n\nExample 2:\n\nInput: words = [\"a\",\"ab\",\"abc\"]\nOutput: [1,3]\nExplanation:\n- words[0] is connected to words[1].\n- words[1] is connected to words[0] and words[2].\n- words[2] is connected to words[1].\nSince all strings are connected to each other, they should be grouped together.\nThus, the size of the largest group is 3.\n\nConstraints:\n\n- 1 <= words.length <= 2 * 10^4\n- 1 <= words[i].length <= 26\n- words[i] consists of lowercase English letters only.\n- No letter occurs more than once in words[i].\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'bcd', 'ace', 'bce']) == [1, 4]\n assert candidate(words = ['abcd', 'ac', 'ab', 'abc', 'a']) == [1, 5]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde']) == [1, 7]\n assert candidate(words = ['a', 'b', 'ab', 'cde']) == [2, 3]\n assert candidate(words = ['abcd', 'ab', 'cd', 'a', 'b', 'c', 'd']) == [2, 6]\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g']) == [1, 7]\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == [9, 1]\n assert candidate(words = ['a', 'ab', 'abc']) == [1, 3]\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']) == [1, 26]\n assert candidate(words = ['abc', 'abcd', 'abde', 'acde', 'bcde']) == [1, 5]\n assert candidate(words = ['abc', 'bcd', 'ace', 'xyz']) == [2, 3]\n assert candidate(words = ['xyz', 'xy', 'yz', 'xz', 'x', 'y', 'z']) == [1, 7]\n assert candidate(words = ['abc', 'bcd', 'ace', 'bd', 'abcde']) == [2, 4]\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijl', 'abcdefghijkml', 'abcdefghijkmn', 'abcdefghijkop', 'abcdefghijkmnop', 'abcdefghijkmnopq']) == [5, 30]\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'ghijkl', 'hijklm', 'ijklmn', 'jklmno', 'klmnop', 'lmnopq', 'mnopqr', 'nopqrs', 'opqrst', 'pqrstu', 'qrstuv', 'rstuvw', 'stuvwx', 'tuvwxy', 'uvwxyz']) == [1, 21]\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'ghijkl', 'hijklm', 'ijklmn', 'jklmno', 'klmnop', 'lmnopq', 'mnopqr', 'nopqrs', 'opqrst', 'pqrs']) == [2, 15]\n assert candidate(words = ['abc', 'ab', 'a', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij']) == [1, 10]\n assert candidate(words = ['pqrst', 'pqrstuvw', 'pqrstu', 'pqrs', 'pqr', 'pq', 'p', 'qrstuv', 'qrstu', 'qrst', 'qrs', 'qr', 'q', 'rstuv', 'rstu', 'rst', 'rs', 'r', 'stuv', 'stu', 'st', 's', 'tuv', 'tu', 't', 'uv', 'u', 'v']) == [2, 27]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu']) == [2, 4]\n assert candidate(words = ['abc', 'abcd', 'ab', 'a', 'bc', 'b', 'c', 'ac', 'd', 'de', 'def', 'defg', 'defgh', 'defghi', 'defghij', 'defghijk', 'defghijkl', 'defghijklm', 'defghijklmn', 'defghijklmno', 'defghijklmnop', 'defghijklmnopq', 'defghijklmnopqr', 'defghijklmnopqrs', 'defghijklmnopqrst', 'defghijklmnopqrstu', 'defghijklmnopqrstuv', 'defghijklmnopqrstuvw', 'defghijklmnopqrstuvwx', 'defghijklmnopqrstuvwxy', 'defghijklmnopqrstuvwxyz']) == [1, 31]\n assert candidate(words = ['ab', 'ac', 'ad', 'bc', 'bd', 'cd', 'abc', 'abd', 'acd', 'bcd', 'abcd', 'abcde', 'abcf', 'abcdg', 'abde', 'acde', 'bcde', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwxyz']) == [4, 17]\n assert candidate(words = ['ab', 'ac', 'ad', 'bc', 'bd', 'cd', 'abcd', 'abef', 'acde', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop', 'nopq', 'opqr', 'pqrs', 'qrst', 'rstu', 'stuv', 'tuvw', 'uvwx', 'vwxy', 'wxyz']) == [3, 24]\n assert candidate(words = ['abc', 'abd', 'abe', 'abf', 'abg', 'abh', 'abi', 'abj', 'abk', 'abl', 'abm', 'abn', 'abo', 'abp', 'abq', 'abr', 'abs', 'abt', 'abu', 'abv', 'abw', 'abx', 'aby', 'abz', 'acb', 'adb', 'aeb', 'afb', 'agb', 'ahb', 'aib', 'ajb', 'akb', 'alb', 'amb', 'anb', 'aob', 'apb', 'aqb', 'arb', 'asb', 'atb', 'aub', 'avb', 'awb', 'axb', 'ayb', 'azb']) == [1, 48]\n assert candidate(words = ['abcd', 'abcf', 'acdf', 'bcdf', 'abcdg', 'abcfg', 'abdfg', 'acdfg', 'bcdfg', 'abcdef', 'abcdfg', 'abcfgh', 'abcdefg', 'abcdefh', 'abcddef', 'abcedef', 'abcfdef', 'abcdefg', 'abcdefh', 'abcdefi', 'abcdefj', 'abcdefk', 'abcdefl', 'abcdefm', 'abcdefn', 'abcdefo', 'abcdefp', 'abcdefq', 'abcdefr', 'abcdefs', 'abcdeft', 'abcdefu', 'abcdefv', 'abcdefw', 'abcdefx', 'abcdefy', 'abcdefz']) == [1, 37]\n assert candidate(words = ['a', 'b', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh']) == [1, 9]\n assert candidate(words = ['xyz', 'xy', 'xz', 'yz', 'x', 'y', 'z', 'abc', 'ab', 'ac', 'bc', 'a', 'b', 'c', 'abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmnop']) == [2, 30]\n assert candidate(words = ['xyz', 'xy', 'yz', 'xz', 'x', 'y', 'z', 'xyw', 'yzw', 'xzw', 'w', 'xyzw']) == [1, 12]\n assert candidate(words = ['abc', 'ac', 'ab', 'b', 'c', 'bcd', 'bc', 'cd', 'd', 'abcd', 'abdc', 'bacd', 'cabd', 'acbd', 'bcad', 'bcda']) == [1, 16]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqr', 'abcdefghijklmnopq', 'abcdefghijklmnop', 'abcdefghijklmno']) == [3, 4]\n assert candidate(words = ['abcdefg', 'abc', 'def', 'ghijkl', 'mnopqr', 'stuv', 'wxyz', 'abcdefghij']) == [8, 1]\n assert candidate(words = ['xyz', 'xy', 'xz', 'yz', 'a', 'b', 'c', 'abc', 'abcd']) == [3, 4]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde', 'abcdf', 'abcef', 'abdef', 'acdef', 'bcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwxyz']) == [2, 20]\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy', 'zabcd', 'efghi', 'jklmn', 'opqrs', 'tuvwx', 'yzabc', 'defgh', 'ijklm', 'nopqr', 'stuvw', 'xyzab', 'cdefg', 'hijkl', 'mnopq', 'rstuv', 'wxyza', 'bcdef', 'ghijk', 'lmnop', 'opqrs', 'tuvwx', 'yzabc']) == [11, 22]\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yzab', 'cdef', 'ghij', 'klmn', 'opqr', 'stuv', 'wxyz', 'abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yzab']) == [14, 3]\n assert candidate(words = ['abcd', 'abcf', 'abdf', 'acdf', 'bcdf', 'abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'ghijkl', 'hijklm', 'ijklmn', 'jklmno', 'klmnop', 'lmnopq', 'mnopqr', 'nopqrs', 'opqrst', 'pqrstu', 'qrstuv', 'rstuvw', 'stuvwx', 'tuvwxy', 'uvwxy']) == [2, 21]\n assert candidate(words = ['pqr', 'pq', 'pr', 'qr', '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']) == [1, 30]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw']) == [1, 4]\n assert candidate(words = ['abcd', 'abef', 'acgh', 'bcdf', 'cdef', 'efgh', 'efgi', 'efgj', 'efgk', 'efgl', 'efgm', 'efgn', 'efgo', 'efgp', 'efgq', 'efgr', 'efgs', 'efgt', 'efgu', 'efgv', 'efgw', 'efgx', 'efgy', 'efgz']) == [4, 19]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqr', 'abcdefghijklmnopq', 'abcdefghijklmnop', 'abcdefghijklmno', 'abcdefghijklmn', 'abcdefghijklm', 'abcdefghijkl', 'abcdefghijk', 'abcdefghij', 'abcdefghi', 'abcdefgh', 'abcdefg', 'abcdef', 'abcde', 'abcd', 'abc', 'ab', 'a']) == [2, 18]\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']) == [1, 26]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde', 'abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde']) == [1, 14]\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba']) == [1, 30]\n assert candidate(words = ['a', 'b', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstvwxy', 'abcdefghijklmnopqrstuvwxyz']) == [3, 24]\n assert candidate(words = ['abcdef', 'abc', 'def', 'abcd', 'abef', 'acdf', 'bcde', 'abcf', 'abcdg', 'abcde', 'abcdefg']) == [2, 10]\n assert candidate(words = ['mnop', 'mno', 'mnp', 'mop', 'nop', 'npp', 'ppp', 'pp', 'p', 'z', 'zz', 'zzz', 'zzzz', 'zzzzz', 'zzzzzz', 'zzzzzzz', 'zzzzzzzz', 'zzzzzzzzz', 'zzzzzzzzzz']) == [1, 19]\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abcdefghi', 'jklmnopqr', 'stuvwxyz', 'abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy', 'z', 'abcdefghijkl', 'mnopqrstu', 'vwxyz', 'abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yz']) == [18, 4]\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzab', 'cdefgh', 'ijklmn', 'opqrst', 'uvwxyl', 'zabcde', 'fghijk', 'lmnopq', 'rstuvw', 'xylzab', 'cdefgh', 'ijklmn', 'opqrst', 'vwxyza', 'yzabcd', 'efghij', 'klmnop', 'qrstuv', 'wxylza', 'bcdefg', 'hijklm', 'nopqrs', 'tuvwxy', 'zabcde', 'fghijk', 'lmnopq', 'rstuvw', 'wxylza', 'cdefgh', 'ijklmn', 'opqrst', 'vwxyza', 'yzabcd']) == [15, 9]\n assert candidate(words = ['xyz', 'xy', 'xz', 'yz', 'x', 'y', 'z', 'xyza', 'xyzb', 'xyzc', 'xyzd', 'xyze', 'xyzf', 'xyzg', 'xyzh', 'xyzi', 'xyzj', 'xyzk', 'xyzl', 'xyzm', 'xyzn', 'xyzo', 'xyzp', 'xyzq', 'xyxr', 'xyxs', 'xyxt', 'xyxu', 'xyxv', 'xyxw', 'xyxx', 'xyxy', 'xyxz']) == [1, 33]\n assert candidate(words = ['a', 'b', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwxyz']) == [2, 15]\n assert candidate(words = ['abcdefg', 'abcdef', 'abcde', 'abcd', 'abc', 'ab', 'a', 'b', 'c', 'd', 'e', 'f', 'g']) == [1, 13]\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'abcde', 'bcdef', 'cdefg', 'defgh', 'efghi', 'fghij']) == [2, 6]\n assert candidate(words = ['abcdef', 'abcdeg', 'abcef', 'bcdef', 'acdef', 'abdef', 'abcdf', 'abcdg', 'abc', 'ab', 'ac', 'ad', 'ae', 'af', 'ag', 'a', 'b', 'c', 'd', 'e', 'f', 'g']) == [2, 14]\n assert candidate(words = ['ab', 'ac', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ba', 'ca', 'da', 'ea', 'fa', 'ga', 'ha', 'ia', 'ja', 'ka', 'la', 'ma', 'na', 'oa', 'pa', 'qa', 'ra', 'sa', 'ta', 'ua', 'va', 'wa', 'xa', 'ya', 'za']) == [1, 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', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy']) == [1, 25]\n assert candidate(words = ['abcdef', 'abcde', 'abcef', 'abdef', 'acdef', 'bcdef', 'abcdefg', 'abcdefgh', 'abcdefghi']) == [1, 9]\n assert candidate(words = ['a', 'b', 'c', 'ab', 'bc', 'ac', 'abc', 'abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl', 'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmnop', 'abcdefghijklmnopq', 'abcdefghijklmnopqr', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrst', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwxyz', 'mnopqrstuvwxy', 'mnopqrstuvwx', 'mnopqrstuvw', 'mnopqrstuv', 'mnopqrstu', 'mnopqrst', 'mnopqr', 'mnopq', 'mnop', 'mon', 'mo', 'm', 'nopqrstuvwxyz', 'nopqrstuvwx', 'nopqrstuvw', 'nopqrstuv', 'nopqrstu', 'nopqrst', 'nopqr', 'nopq', 'nop', 'no', 'n', 'opqrstuvwxyz', 'opqrstuvwx', 'opqrstuvw', 'opqrstuv', 'opqrstu', 'opqrst', 'opqr', 'opq', 'op', 'o', 'pqrstuvwxyz', 'pqrstuvwx', 'pqrstuvw', 'pqrstuv', 'pqrstu', 'pqrs', 'pqr', 'pq', 'p']) == [3, 42]\n assert candidate(words = ['mnopqr', 'mnopqs', 'mnopqt', 'mnoprs', 'mnoprt', 'mnopst', 'mnoqrs', 'mnoqrt', 'mnoqst', 'mnoprs', 'mnoprt', 'mnopst', 'mnoqrt', 'mnoqst', 'mnoprt', 'mnopst', 'mnoqrs', 'mnopqr', 'mnopqs', 'mnopqt', 'mnoprs', 'mnoprt', 'mnopst', 'mnoqrt', 'mnoqst', 'mnoprt', 'mnopst']) == [1, 27]\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abde', 'acde', 'bcde', 'abcde', 'bcdef', 'acdef', 'abcef', 'abdef', 'acdefg', 'bcdefg', 'cdefgh', 'defghi']) == [1, 15]\n assert candidate(words = ['xyz', 'xy', 'xz', 'yz', 'x', 'y', 'z', 'xyzu', 'xyvz', 'xywz', 'xyxz', 'xyyz', 'xyzv', 'xyzw', 'xyzz', 'xzu', 'xvz', 'xwz', 'xxz', 'xzz', 'yzu', 'yvz', 'ywz', 'yyz', 'yzv', 'yzw', 'yzz', 'zvu', 'zwv', 'zzv', 'zzw', 'zzz', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'abcd', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop', 'nopq', 'opqr', 'pqrs', 'qrst', 'rstu', 'stuv', 'tuvw', 'uvwx', 'vwxy', 'wxyz', 'vwxyz', 'vwxyza', 'vwxyzab', 'vwxyzabc', 'vwxyzabcd']) == [1, 84]\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', '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']) == [1, 51]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstu']) == [1, 10]\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'abcd', 'ab', 'ac', 'ad', 'bc', 'bd', 'cd', 'a', 'b', 'c', 'd']) == [1, 15]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxy', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu']) == [1, 13]\n assert candidate(words = ['abc', 'abd', 'acd', 'bcd', 'abcd', 'ab', 'bc', 'cd', 'ac', 'a', 'b', 'c', 'd']) == [1, 13]\n assert candidate(words = ['pqrst', 'pqsrt', 'pqrst', 'pqrsu', 'pqrs', 'pqrt', 'pqst', 'prst', 'qrst', 'pq', 'qr', 'qs', 'qt', 'pr', 'ps', 'pt', 'rs', 'rt', 'st', 'p', 'q', 'r', 's', 't']) == [2, 15]\n assert candidate(words = ['abcdefghij', 'abcdefgh', 'abcdefg', 'abcdef', 'abcde', 'abcd', 'abc', 'ab', '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']) == [2, 33]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvw', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrstuv', 'abcdefghijklmnopqrstu', 'abcdefghijklmnopqrs', 'abcdefghijklmnopqrt', 'abcdefghijklmnopqr', 'abcdefghijklmnopq', 'abcdefghijklmnop', 'abcdefghijklmno', 'abcdefghijklmn', 'abcdefghijklm', 'abcdefghijkl', 'abcdefghijk', 'abcdefghij', 'abcdefghi', 'abcdefgh', 'abcdefg', 'abcdef', 'abcde', 'abcd', 'abc', 'ab', 'a']) == [3, 20]\n", "comparison": "exact"}, "public_tests": ["[\"a\",\"b\",\"ab\",\"cde\"]", "[\"a\",\"ab\",\"abc\"]"], "hints": ["Can we build a graph from words, where there exists an edge between nodes i and j if words[i] and words[j] are connected?", "The problem now boils down to finding the total number of components and the size of the largest component in the graph.", "How can we use bit masking to reduce the search space while adding edges to node i?"], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().groupStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:10+00:00", "tests_total": 70, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "string", "bit-manipulation", "union-find"]}, "language": "php", "interface": {"raw_signature": "function groupStrings($words) {", "container": "Solution", "callable": "groupStrings", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2160, "task_id": "minimum-sum-of-four-digit-number-after-splitting-digits", "difficulty": "Easy", "problem_description": "You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.\n\n- For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].\n\nReturn the minimum possible sum of new1 and new2.\n\nExample 1:\n\nInput: num = 2932\nOutput: 52\nExplanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.\nThe minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.\n\nExample 2:\n\nInput: num = 4009\nOutput: 13\nExplanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc.\nThe minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13.\n\nConstraints:\n\n- 1000 <= num <= 9999\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 8765) == 125\n assert candidate(num = 2309) == 32\n assert candidate(num = 5678) == 125\n assert candidate(num = 1098) == 27\n assert candidate(num = 1111) == 22\n assert candidate(num = 3333) == 66\n assert candidate(num = 4009) == 13\n assert candidate(num = 9999) == 198\n assert candidate(num = 1000) == 1\n assert candidate(num = 2932) == 52\n assert candidate(num = 9876) == 147\n assert candidate(num = 4321) == 37\n assert candidate(num = 1234) == 37\n assert candidate(num = 2020) == 4\n assert candidate(num = 6666) == 132\n assert candidate(num = 5631) == 51\n assert candidate(num = 7899) == 168\n assert candidate(num = 8821) == 46\n assert candidate(num = 9503) == 44\n assert candidate(num = 3867) == 105\n assert candidate(num = 5555) == 110\n assert candidate(num = 6789) == 147\n assert candidate(num = 1928) == 47\n assert candidate(num = 9900) == 18\n assert candidate(num = 6600) == 12\n assert candidate(num = 4444) == 88\n assert candidate(num = 4628) == 74\n assert candidate(num = 1119) == 30\n assert candidate(num = 2229) == 51\n assert candidate(num = 6644) == 92\n assert candidate(num = 1122) == 24\n assert candidate(num = 7824) == 75\n assert candidate(num = 3223) == 46\n assert candidate(num = 1201) == 13\n assert candidate(num = 9990) == 108\n assert candidate(num = 1221) == 24\n assert candidate(num = 2345) == 59\n assert candidate(num = 1357) == 52\n assert candidate(num = 1199) == 38\n assert candidate(num = 5600) == 11\n assert candidate(num = 6677) == 134\n assert candidate(num = 2099) == 38\n assert candidate(num = 3939) == 78\n assert candidate(num = 5611) == 31\n assert candidate(num = 7700) == 14\n assert candidate(num = 7711) == 34\n assert candidate(num = 2288) == 56\n assert candidate(num = 9009) == 18\n assert candidate(num = 5647) == 103\n assert candidate(num = 3928) == 67\n assert candidate(num = 7654) == 103\n assert candidate(num = 1991) == 38\n assert candidate(num = 8231) == 41\n assert candidate(num = 1001) == 2\n assert candidate(num = 8888) == 176\n assert candidate(num = 3456) == 81\n assert candidate(num = 6084) == 54\n assert candidate(num = 7209) == 36\n assert candidate(num = 2468) == 74\n assert candidate(num = 2019) == 21\n assert candidate(num = 1129) == 31\n assert candidate(num = 5551) == 70\n assert candidate(num = 5234) == 59\n assert candidate(num = 2233) == 46\n assert candidate(num = 6633) == 72\n assert candidate(num = 1299) == 48\n assert candidate(num = 3030) == 6\n assert candidate(num = 1100) == 2\n assert candidate(num = 7891) == 97\n assert candidate(num = 3405) == 39\n assert candidate(num = 7111) == 28\n assert candidate(num = 2244) == 48\n assert candidate(num = 8800) == 16\n assert candidate(num = 1298) == 47\n assert candidate(num = 7777) == 154\n assert candidate(num = 6530) == 41\n assert candidate(num = 7770) == 84\n assert candidate(num = 9000) == 9\n assert candidate(num = 9123) == 42\n assert candidate(num = 5670) == 63\n assert candidate(num = 1179) == 36\n assert candidate(num = 1987) == 97\n assert candidate(num = 4466) == 92\n", "comparison": "exact"}, "public_tests": ["2932", "4009"], "hints": ["Notice that the most optimal way to obtain the minimum possible sum using 4 digits is by summing up two 2-digit numbers.", "We can use the two smallest digits out of the four as the digits found in the tens place respectively.", "Similarly, we use the final 2 larger digits as the digits found in the ones place."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().minimumSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:14+00:00", "tests_total": 83, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumSum($num) {", "container": "Solution", "callable": "minimumSum", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2161, "task_id": "partition-array-according-to-given-pivot", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:\n\n- Every element less than pivot appears before every element greater than pivot.\n- Every element equal to pivot appears in between the elements less than and greater than pivot.\n- The relative order of the elements less than pivot and the elements greater than pivot is maintained.\n - More formally, consider every p_i, p_j where p_i is the new position of the i^th element and p_j is the new position of the j^th element. If i < j and both elements are smaller (or larger) than pivot, then p_i < p_j.\n\nReturn nums after the rearrangement.\n\nExample 1:\n\nInput: nums = [9,12,5,10,14,3,10], pivot = 10\nOutput: [9,5,3,10,10,12,14]\nExplanation:\nThe elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.\nThe elements 12 and 14 are greater than the pivot so they are on the right side of the array.\nThe relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.\n\nExample 2:\n\nInput: nums = [-3,4,3,2], pivot = 2\nOutput: [-3,2,4,3]\nExplanation:\nThe element -3 is less than the pivot so it is on the left side of the array.\nThe elements 4 and 3 are greater than the pivot so they are on the right side of the array.\nThe relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- -10^6 <= nums[i] <= 10^6\n- pivot equals to an element of nums.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0],pivot = 0) == [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1]\n assert candidate(nums = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0],pivot = 1) == [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]\n assert candidate(nums = [5, 4, 3, 2, 1],pivot = 3) == [2, 1, 3, 5, 4]\n assert candidate(nums = [10, 10, 10, 10],pivot = 10) == [10, 10, 10, 10]\n assert candidate(nums = [5, 5, 5, 5, 5],pivot = 5) == [5, 5, 5, 5, 5]\n assert candidate(nums = [4, 3, 2, 2, 5, 2, 3],pivot = 2) == [2, 2, 2, 4, 3, 5, 3]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pivot = 5) == [4, 3, 2, 1, 5, 10, 9, 8, 7, 6]\n assert candidate(nums = [10, 10, 10, 10, 10],pivot = 10) == [10, 10, 10, 10, 10]\n assert candidate(nums = [10, 9, 8, 7, 6],pivot = 8) == [7, 6, 8, 10, 9]\n assert candidate(nums = [5, -1, 3, 2, 4, 6, 0],pivot = 4) == [-1, 3, 2, 0, 4, 5, 6]\n assert candidate(nums = [10, 9, 8, 7, 6],pivot = 7) == [6, 7, 10, 9, 8]\n assert candidate(nums = [9, 12, 5, 10, 14, 3, 10],pivot = 10) == [9, 5, 3, 10, 10, 12, 14]\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3],pivot = 3) == [3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [5, -10, 4],pivot = 5) == [-10, 4, 5]\n assert candidate(nums = [-3, 4, 3, 2],pivot = 2) == [-3, 2, 4, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pivot = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5],pivot = 3) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1000000, -1000000, 500000, -500000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],pivot = 0) == [-1000000, -500000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000, 500000]\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],pivot = 0) == [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000, 0, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]\n assert candidate(nums = [100, 200, 300, 400, 500, 400, 300, 200, 100],pivot = 300) == [100, 200, 200, 100, 300, 300, 400, 500, 400]\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, 3, 9, 3, 2, 8, 5, 6, 9, 0],pivot = 5) == [3, 1, 4, 1, 2, 3, 3, 2, 3, 4, 2, 4, 3, 3, 3, 2, 0, 2, 4, 1, 1, 3, 3, 2, 0, 5, 5, 5, 5, 5, 9, 6, 9, 7, 9, 8, 6, 6, 8, 7, 9, 8, 8, 9, 7, 9, 8, 6, 9]\n assert candidate(nums = [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],pivot = 13) == [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 13, 14, 16, 15, 18, 17, 20, 19, 22, 21, 24, 23, 26, 25]\n assert candidate(nums = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],pivot = 10) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10, 19, 18, 17, 16, 15, 14, 13, 12, 11]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],pivot = 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 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],pivot = 3) == [3, 3, 3, 3, 3, 3, 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(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pivot = 10) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],pivot = 50) == [10, 20, 30, 40, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],pivot = 5) == [1, 2, 3, 4, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 6, 5, 1, 0, 8, 9, 10, 11, 2, 3, 4],pivot = 5) == [1, 0, 2, 3, 4, 5, 7, 6, 8, 9, 10, 11]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 10, 20, 30, 40, 60, 70, 80, 90, 100, 50],pivot = 50) == [10, 20, 30, 40, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [3, 6, 3, 8, 8, 6, 1, 2, 1, 2, 6, 8, 3, 6, 8, 3, 6, 3, 6, 8],pivot = 6) == [3, 3, 1, 2, 1, 2, 3, 3, 3, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8]\n assert candidate(nums = [10, 20, 5, 15, 0, 25, 10, 5, 30, 10],pivot = 10) == [5, 0, 5, 10, 10, 10, 20, 15, 25, 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],pivot = 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 = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10],pivot = 0) == [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 5, 3, 8, 2, 9, 1, 4, 6, 0, 11, 12, 13],pivot = 5) == [3, 2, 1, 4, 0, 5, 7, 8, 9, 6, 11, 12, 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],pivot = 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 = [100, 200, 300, 400, 500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500],pivot = 300) == [100, 200, 200, 100, 0, -100, -200, -300, -400, -500, 300, 300, 400, 500, 400]\n assert candidate(nums = [-1, -2, -3, -4, -5, 0, 5, 4, 3, 2, 1],pivot = 0) == [-1, -2, -3, -4, -5, 0, 5, 4, 3, 2, 1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],pivot = 500) == [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10],pivot = 10) == [10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pivot = 8) == [7, 6, 5, 4, 3, 2, 1, 8, 15, 14, 13, 12, 11, 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],pivot = 5) == [4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 5, 5, 9, 8, 7, 6, 9, 8, 7, 6]\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],pivot = 31250) == [15625, 7812, 3906, 1953, 31250, 1000000, 500000, 250000, 125000, 62500]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],pivot = 5) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 6, 7, 8, 9]\n assert candidate(nums = [-10, -20, -30, -40, -50, -40, -30, -20, -10],pivot = -30) == [-40, -50, -40, -30, -30, -10, -20, -20, -10]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3],pivot = 2) == [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],pivot = 995) == [994, 993, 992, 991, 995, 1000, 999, 998, 997, 996]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],pivot = 5) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],pivot = 0) == [-1, -2, -3, -4, -5, 0, 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],pivot = 8) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],pivot = 0) == [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 0, 9, 8, 7, 6, 5, 4, 3, 2, 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],pivot = 10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [7, 1, 5, 2, 3, 6, 4, 5, 8, 1, 9, 5, 5, 5],pivot = 5) == [1, 2, 3, 4, 1, 5, 5, 5, 5, 5, 7, 6, 8, 9]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],pivot = 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 = [-10, 100, -50, 50, -20, 20, -30, 30, -40, 40],pivot = 0) == [-10, -50, -20, -30, -40, 100, 50, 20, 30, 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],pivot = 15) == [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15, 20, 19, 18, 17, 16]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5],pivot = 5) == [3, 1, 4, 1, 2, 3, 2, 3, 5, 5, 5, 5, 5, 9, 6, 9, 6]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0],pivot = 5) == [4, 3, 2, 1, 0, 5, 5, 5, 5, 5, 10, 9, 8, 7, 6]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5],pivot = 3) == [2, 1, 0, -1, -2, -3, -4, -5, 3, 10, 9, 8, 7, 6, 5, 4]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, -10, -20, -30],pivot = 50) == [40, 30, 20, 10, 0, -10, -20, -30, 50, 100, 90, 80, 70, 60]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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],pivot = 30) == [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]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],pivot = 5) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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],pivot = 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 = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],pivot = 5) == [3, 1, 4, 1, 2, 3, 5, 5, 5, 9, 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],pivot = 5) == [4, 3, 2, 1, 4, 3, 2, 1, 5, 5, 10, 9, 8, 7, 6, 10, 9, 8, 7, 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],pivot = 6) == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10],pivot = 5) == [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7],pivot = 0) == [-1, -2, -3, -4, -5, -6, -7, 0, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pivot = 5) == [1, 2, 3, 4, 4, 3, 2, 1, 5, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6]\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],pivot = -5) == [-6, -7, -8, -9, -10, -5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 11, 13, 15, 17, 19],pivot = 10) == [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 11, 13, 15, 17, 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],pivot = 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 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],pivot = 25) == [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, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],pivot = 7) == [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],pivot = -5) == [-6, -7, -8, -9, -10, -5, -1, -2, -3, -4]\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],pivot = 2) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(nums = [2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1],pivot = 2) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]\n assert candidate(nums = [1000000, -1000000, 500000, -500000, 250000, -250000, 0, 1000000, -1000000],pivot = 0) == [-1000000, -500000, -250000, -1000000, 0, 1000000, 500000, 250000, 1000000]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 1, 3, 5, 7, 9],pivot = 10) == [1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],pivot = 3) == [1, 2, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 4, 5]\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],pivot = -8) == [-9, -10, -11, -12, -13, -14, -15, -8, -1, -2, -3, -4, -5, -6, -7]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100],pivot = 500) == [100, 200, 300, 400, 100, 500, 600, 700, 800, 900, 1000]\n assert candidate(nums = [7, 3, 5, 10, 8, 5, 1, 9, 4, 5],pivot = 5) == [3, 1, 4, 5, 5, 5, 7, 10, 8, 9]\n assert candidate(nums = [-1000000, -500000, -250000, -125000, -62500, -31250, -15625, -7812, -3906, -1953],pivot = -125000) == [-1000000, -500000, -250000, -125000, -62500, -31250, -15625, -7812, -3906, -1953]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],pivot = 1) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],pivot = 5) == [1, 2, 3, 4, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 6, 7, 8, 9, 6, 7, 8, 9]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 7],pivot = 21) == [7, 14, 7, 21, 28, 35, 42, 49, 56, 63, 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, 5],pivot = 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 = [1000000, 100000, 10000, 1000, 100, 10, 1, 0, -1, -10, -100, -1000, -10000, -100000, -1000000],pivot = 100) == [10, 1, 0, -1, -10, -100, -1000, -10000, -100000, -1000000, 100, 1000000, 100000, 10000, 1000]\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],pivot = -500) == [-600, -700, -800, -900, -1000, -500, -100, -200, -300, -400]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],pivot = 10) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],pivot = 125000) == [62500, 31250, 15625, 7812, 3906, 1953, 125000, 1000000, 500000, 250000]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],pivot = 70) == [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140]\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],pivot = 15) == [1, 2, 3, 4, 5, 6, 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, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49],pivot = 25) == [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]\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],pivot = 10) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]\n assert candidate(nums = [3, 8, 2, 4, 5, 7, 9, 1],pivot = 5) == [3, 2, 4, 1, 5, 8, 7, 9]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000],pivot = 7000) == [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000]\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],pivot = 300) == [100, 200, 100, 200, 100, 200, 300, 300, 300, 400, 500, 400, 500, 400, 500]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 5, 10, 15, 20, 25],pivot = 25) == [5, 10, 15, 20, 5, 10, 15, 20, 25, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [5, 3, 1, 2, 4, 1, 5, 3, 2, 4, 1, 5, 3, 2, 4, 1, 5, 3, 2, 4, 1, 5, 3, 2, 4],pivot = 3) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4]\n", "comparison": "exact"}, "public_tests": ["[9,12,5,10,14,3,10]\n10", "[-3,4,3,2]\n2"], "hints": ["Could you put the elements smaller than the pivot and greater than the pivot in a separate list as in the sequence that they occur?", "With the separate lists generated, could you then generate the result?"], "metadata": {"canonical_parameter_names": ["nums", "pivot"], "leetcode_dataset_entry_point": "Solution().pivotArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:17+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "php", "interface": {"raw_signature": "function pivotArray($nums, $pivot) {", "container": "Solution", "callable": "pivotArray", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "pivot", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2162, "task_id": "minimum-cost-to-set-cooking-time", "difficulty": "Medium", "problem_description": "A generic microwave supports cooking times for:\n\n- at least 1 second.\n- at most 99 minutes and 99 seconds.\n\nTo set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time. For example,\n\n- You push 9 5 4 (three digits). It is normalized as 0954 and interpreted as 9 minutes and 54 seconds.\n- You push 0 0 0 8 (four digits). It is interpreted as 0 minutes and 8 seconds.\n- You push 8 0 9 0. It is interpreted as 80 minutes and 90 seconds.\n- You push 8 1 3 0. It is interpreted as 81 minutes and 30 seconds.\n\nYou are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.\n\nThere can be multiple ways to set the microwave to cook for targetSeconds seconds but you are interested in the way with the minimum cost.\n\nReturn the minimum cost to set targetSeconds seconds of cooking time.\n\nRemember that one minute consists of 60 seconds.\n\nExample 1:\n\nInput: startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600\nOutput: 6\nExplanation: The following are the possible ways to set the cooking time.\n- 1 0 0 0, interpreted as 10 minutes and 0 seconds.\n The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1).\n The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost.\n- 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds.\n The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12.\n- 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds.\n The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9.\n\nExample 2:\n\nInput: startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76\nOutput: 6\nExplanation: The optimal way is to push two digits: 7 6, interpreted as 76 seconds.\nThe finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). The total cost is: 1 + 2 + 1 + 2 = 6\nNote other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost.\n\nConstraints:\n\n- 0 <= startAt <= 9\n- 1 <= moveCost, pushCost <= 10^5\n- 1 <= targetSeconds <= 6039\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(startAt = 1,moveCost = 2,pushCost = 1,targetSeconds = 600) == 6\n assert candidate(startAt = 0,moveCost = 1,pushCost = 2,targetSeconds = 76) == 6\n assert candidate(startAt = 2,moveCost = 2,pushCost = 3,targetSeconds = 599) == 15\n assert candidate(startAt = 6,moveCost = 3,pushCost = 2,targetSeconds = 3599) == 20\n assert candidate(startAt = 9,moveCost = 5,pushCost = 10,targetSeconds = 99) == 20\n assert candidate(startAt = 5,moveCost = 1,pushCost = 1,targetSeconds = 120) == 5\n assert candidate(startAt = 3,moveCost = 3,pushCost = 2,targetSeconds = 300) == 12\n assert candidate(startAt = 8,moveCost = 2,pushCost = 1,targetSeconds = 1) == 3\n assert candidate(startAt = 7,moveCost = 4,pushCost = 5,targetSeconds = 180) == 23\n assert candidate(startAt = 4,moveCost = 1,pushCost = 1,targetSeconds = 6039) == 5\n assert candidate(startAt = 7,moveCost = 6,pushCost = 3,targetSeconds = 59) == 18\n assert candidate(startAt = 8,moveCost = 3,pushCost = 5,targetSeconds = 3001) == 29\n assert candidate(startAt = 9,moveCost = 2,pushCost = 1,targetSeconds = 1) == 3\n assert candidate(startAt = 9,moveCost = 1,pushCost = 10,targetSeconds = 6039) == 40\n assert candidate(startAt = 4,moveCost = 30,pushCost = 20,targetSeconds = 1234) == 170\n assert candidate(startAt = 0,moveCost = 6,pushCost = 5,targetSeconds = 99) == 16\n assert candidate(startAt = 6,moveCost = 5,pushCost = 1,targetSeconds = 480) == 13\n assert candidate(startAt = 0,moveCost = 1,pushCost = 10,targetSeconds = 1000) == 44\n assert candidate(startAt = 1,moveCost = 8,pushCost = 5,targetSeconds = 1234) == 36\n assert candidate(startAt = 7,moveCost = 200,pushCost = 150,targetSeconds = 99) == 500\n assert candidate(startAt = 9,moveCost = 5,pushCost = 2,targetSeconds = 6039) == 8\n assert candidate(startAt = 8,moveCost = 2,pushCost = 2,targetSeconds = 2039) == 14\n assert candidate(startAt = 6,moveCost = 2,pushCost = 1,targetSeconds = 99) == 4\n assert candidate(startAt = 6,moveCost = 1,pushCost = 1,targetSeconds = 59) == 4\n assert candidate(startAt = 5,moveCost = 15,pushCost = 25,targetSeconds = 2345) == 160\n assert candidate(startAt = 7,moveCost = 2,pushCost = 1,targetSeconds = 99) == 4\n assert candidate(startAt = 1,moveCost = 20,pushCost = 5,targetSeconds = 900) == 60\n assert candidate(startAt = 2,moveCost = 5,pushCost = 3,targetSeconds = 5999) == 27\n assert candidate(startAt = 9,moveCost = 10,pushCost = 1,targetSeconds = 1234) == 34\n assert candidate(startAt = 2,moveCost = 1,pushCost = 5,targetSeconds = 240) == 17\n assert candidate(startAt = 9,moveCost = 5,pushCost = 3,targetSeconds = 6039) == 12\n assert candidate(startAt = 1,moveCost = 4,pushCost = 4,targetSeconds = 3159) == 28\n assert candidate(startAt = 4,moveCost = 3,pushCost = 7,targetSeconds = 60) == 20\n assert candidate(startAt = 8,moveCost = 3,pushCost = 7,targetSeconds = 119) == 30\n assert candidate(startAt = 0,moveCost = 20,pushCost = 10,targetSeconds = 3600) == 80\n assert candidate(startAt = 3,moveCost = 2,pushCost = 3,targetSeconds = 3540) == 18\n assert candidate(startAt = 3,moveCost = 5,pushCost = 3,targetSeconds = 5999) == 27\n assert candidate(startAt = 6,moveCost = 3,pushCost = 7,targetSeconds = 2900) == 40\n assert candidate(startAt = 5,moveCost = 5,pushCost = 3,targetSeconds = 5999) == 27\n assert candidate(startAt = 0,moveCost = 7,pushCost = 2,targetSeconds = 4567) == 36\n assert candidate(startAt = 9,moveCost = 10,pushCost = 1,targetSeconds = 6039) == 4\n assert candidate(startAt = 5,moveCost = 7,pushCost = 2,targetSeconds = 5432) == 29\n assert candidate(startAt = 1,moveCost = 1,pushCost = 10,targetSeconds = 300) == 32\n assert candidate(startAt = 4,moveCost = 10,pushCost = 1,targetSeconds = 1800) == 24\n assert candidate(startAt = 8,moveCost = 10,pushCost = 5,targetSeconds = 900) == 50\n assert candidate(startAt = 5,moveCost = 7,pushCost = 4,targetSeconds = 1234) == 37\n assert candidate(startAt = 2,moveCost = 15,pushCost = 3,targetSeconds = 480) == 39\n assert candidate(startAt = 1,moveCost = 100,pushCost = 50,targetSeconds = 120) == 350\n assert candidate(startAt = 6,moveCost = 50,pushCost = 25,targetSeconds = 1800) == 200\n assert candidate(startAt = 7,moveCost = 1,pushCost = 2,targetSeconds = 6000) == 11\n assert candidate(startAt = 3,moveCost = 2,pushCost = 3,targetSeconds = 300) == 13\n assert candidate(startAt = 2,moveCost = 4,pushCost = 6,targetSeconds = 2345) == 40\n assert candidate(startAt = 0,moveCost = 1,pushCost = 1000,targetSeconds = 60) == 2002\n assert candidate(startAt = 4,moveCost = 7,pushCost = 4,targetSeconds = 360) == 26\n assert candidate(startAt = 5,moveCost = 20,pushCost = 10,targetSeconds = 3540) == 80\n assert candidate(startAt = 9,moveCost = 7,pushCost = 4,targetSeconds = 5999) == 30\n assert candidate(startAt = 4,moveCost = 3,pushCost = 4,targetSeconds = 1000) == 28\n assert candidate(startAt = 1,moveCost = 1,pushCost = 9,targetSeconds = 50) == 20\n assert candidate(startAt = 6,moveCost = 2,pushCost = 1,targetSeconds = 59) == 6\n assert candidate(startAt = 9,moveCost = 10,pushCost = 2,targetSeconds = 5959) == 28\n assert candidate(startAt = 0,moveCost = 2,pushCost = 1,targetSeconds = 120) == 7\n assert candidate(startAt = 4,moveCost = 2,pushCost = 3,targetSeconds = 60) == 10\n assert candidate(startAt = 7,moveCost = 4,pushCost = 2,targetSeconds = 60) == 12\n assert candidate(startAt = 3,moveCost = 2,pushCost = 3,targetSeconds = 4321) == 20\n assert candidate(startAt = 3,moveCost = 5,pushCost = 3,targetSeconds = 2345) == 27\n assert candidate(startAt = 8,moveCost = 2,pushCost = 3,targetSeconds = 100) == 15\n assert candidate(startAt = 7,moveCost = 9,pushCost = 3,targetSeconds = 3598) == 48\n assert candidate(startAt = 8,moveCost = 7,pushCost = 4,targetSeconds = 1000) == 44\n assert candidate(startAt = 2,moveCost = 15,pushCost = 3,targetSeconds = 123) == 39\n assert candidate(startAt = 5,moveCost = 10,pushCost = 5,targetSeconds = 3149) == 40\n assert candidate(startAt = 1,moveCost = 9,pushCost = 2,targetSeconds = 999) == 26\n assert candidate(startAt = 8,moveCost = 15,pushCost = 8,targetSeconds = 4321) == 92\n assert candidate(startAt = 1,moveCost = 1,pushCost = 1,targetSeconds = 359) == 5\n assert candidate(startAt = 5,moveCost = 1,pushCost = 10,targetSeconds = 3959) == 43\n assert candidate(startAt = 9,moveCost = 2,pushCost = 4,targetSeconds = 5999) == 20\n assert candidate(startAt = 2,moveCost = 6,pushCost = 2,targetSeconds = 5678) == 32\n assert candidate(startAt = 8,moveCost = 3,pushCost = 4,targetSeconds = 6039) == 19\n assert candidate(startAt = 3,moveCost = 5,pushCost = 3,targetSeconds = 5400) == 22\n assert candidate(startAt = 6,moveCost = 3,pushCost = 4,targetSeconds = 999) == 25\n assert candidate(startAt = 3,moveCost = 1,pushCost = 5,targetSeconds = 90) == 12\n assert candidate(startAt = 0,moveCost = 10,pushCost = 1,targetSeconds = 5999) == 34\n assert candidate(startAt = 9,moveCost = 1,pushCost = 2,targetSeconds = 123) == 9\n assert candidate(startAt = 3,moveCost = 4,pushCost = 2,targetSeconds = 300) == 14\n assert candidate(startAt = 5,moveCost = 7,pushCost = 3,targetSeconds = 1234) == 33\n assert candidate(startAt = 8,moveCost = 5,pushCost = 3,targetSeconds = 60) == 16\n assert candidate(startAt = 8,moveCost = 3,pushCost = 2,targetSeconds = 99) == 7\n assert candidate(startAt = 3,moveCost = 2,pushCost = 3,targetSeconds = 60) == 10\n assert candidate(startAt = 9,moveCost = 5,pushCost = 10,targetSeconds = 5999) == 50\n assert candidate(startAt = 8,moveCost = 3,pushCost = 5,targetSeconds = 59) == 16\n assert candidate(startAt = 2,moveCost = 4,pushCost = 5,targetSeconds = 720) == 32\n assert candidate(startAt = 4,moveCost = 4,pushCost = 4,targetSeconds = 5432) == 28\n assert candidate(startAt = 7,moveCost = 7,pushCost = 8,targetSeconds = 1) == 15\n assert candidate(startAt = 0,moveCost = 5,pushCost = 10,targetSeconds = 360) == 40\n assert candidate(startAt = 0,moveCost = 7,pushCost = 1,targetSeconds = 5999) == 25\n assert candidate(startAt = 6,moveCost = 4,pushCost = 6,targetSeconds = 200) == 30\n assert candidate(startAt = 9,moveCost = 10,pushCost = 1,targetSeconds = 5432) == 34\n assert candidate(startAt = 2,moveCost = 2,pushCost = 3,targetSeconds = 3600) == 16\n assert candidate(startAt = 5,moveCost = 10,pushCost = 5,targetSeconds = 3999) == 50\n assert candidate(startAt = 2,moveCost = 10,pushCost = 5,targetSeconds = 3660) == 50\n assert candidate(startAt = 0,moveCost = 3,pushCost = 7,targetSeconds = 90) == 20\n assert candidate(startAt = 3,moveCost = 1,pushCost = 1,targetSeconds = 599) == 6\n assert candidate(startAt = 7,moveCost = 6,pushCost = 4,targetSeconds = 4567) == 34\n assert candidate(startAt = 3,moveCost = 20,pushCost = 5,targetSeconds = 300) == 55\n assert candidate(startAt = 4,moveCost = 6,pushCost = 2,targetSeconds = 900) == 26\n assert candidate(startAt = 1,moveCost = 5,pushCost = 1,targetSeconds = 540) == 13\n assert candidate(startAt = 6,moveCost = 15,pushCost = 5,targetSeconds = 999) == 65\n assert candidate(startAt = 5,moveCost = 1,pushCost = 2,targetSeconds = 480) == 8\n assert candidate(startAt = 0,moveCost = 3,pushCost = 2,targetSeconds = 120) == 12\n assert candidate(startAt = 2,moveCost = 1,pushCost = 1,targetSeconds = 99) == 3\n assert candidate(startAt = 1,moveCost = 6,pushCost = 1,targetSeconds = 59) == 14\n assert candidate(startAt = 7,moveCost = 2,pushCost = 6,targetSeconds = 1000) == 32\n assert candidate(startAt = 4,moveCost = 4,pushCost = 3,targetSeconds = 1500) == 24\n assert candidate(startAt = 0,moveCost = 1,pushCost = 1,targetSeconds = 1234) == 7\n assert candidate(startAt = 2,moveCost = 20,pushCost = 10,targetSeconds = 1020) == 100\n assert candidate(startAt = 4,moveCost = 8,pushCost = 2,targetSeconds = 100) == 30\n assert candidate(startAt = 7,moveCost = 5,pushCost = 2,targetSeconds = 1234) == 23\n", "comparison": "exact"}, "public_tests": ["1\n2\n1\n600", "0\n1\n2\n76"], "hints": ["Define a separate function Cost(mm, ss) where 0 <= mm <= 99 and 0 <= ss <= 99. This function should calculate the cost of setting the cooking time to mm minutes and ss seconds", "The range of the minutes is small (i.e., [0, 99]), how can you use that?", "For every mm in [0, 99], calculate the needed ss to make mm:ss equal to targetSeconds and minimize the cost of setting the cooking time to mm:ss", "Be careful in some cases when ss is not in the valid range [0, 99]."], "metadata": {"canonical_parameter_names": ["startAt", "moveCost", "pushCost", "targetSeconds"], "leetcode_dataset_entry_point": "Solution().minCostSetTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:19+00:00", "tests_total": 118, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["math", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function minCostSetTime($startAt, $moveCost, $pushCost, $targetSeconds) {", "container": "Solution", "callable": "minCostSetTime", "parameters": [{"name": "startAt", "type": "Integer"}, {"name": "moveCost", "type": "Integer"}, {"name": "pushCost", "type": "Integer"}, {"name": "targetSeconds", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2163, "task_id": "minimum-difference-in-sums-after-removal-of-elements", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums consisting of 3 * n elements.\n\nYou are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:\n\n- The first n elements belonging to the first part and their sum is sum_first.\n- The next n elements belonging to the second part and their sum is sum_second.\n\nThe difference in sums of the two parts is denoted as sum_first - sum_second.\n\n- For example, if sum_first = 3 and sum_second = 2, their difference is 1.\n- Similarly, if sum_first = 2 and sum_second = 3, their difference is -1.\n\nReturn the minimum difference possible between the sums of the two parts after the removal of n elements.\n\nExample 1:\n\nInput: nums = [3,1,2]\nOutput: -1\nExplanation: Here, nums has 3 elements, so n = 1.\nThus we have to remove 1 element from nums and divide the array into two equal parts.\n- If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.\n- If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.\n- If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.\nThe minimum difference between sums of the two parts is min(-1,1,2) = -1.\n\nExample 2:\n\nInput: nums = [7,9,5,8,1,3]\nOutput: 1\nExplanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.\nIf we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.\nTo obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.\nIt can be shown that it is not possible to obtain a difference smaller than 1.\n\nConstraints:\n\n- nums.length == 3 * n\n- 1 <= n <= 10^5\n- 1 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == -80\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -180\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -18\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == -36\n assert candidate(nums = [1, 2, 3, 100, 100, 100]) == -197\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == -8\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1]) == -99999\n assert candidate(nums = [3, 1, 2]) == -1\n assert candidate(nums = [7, 9, 5, 8, 1, 3]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 50\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]) == 0\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6]) == -147\n assert candidate(nums = [5, 3, 8, 1, 4, 7, 2, 6, 9]) == -14\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]) == -18000\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12]) == -20\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == -80\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 160\n assert candidate(nums = [2, 1, 3, 2, 1, 3, 2, 1, 3]) == -4\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 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]) == -54\n assert candidate(nums = [1, 2, 3, 100, 200, 300, 4, 5, 6]) == -594\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8]) == -12\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 = [1, 100000, 1, 2, 100000, 2, 3, 100000, 3, 4, 100000, 4]) == -200002\n assert candidate(nums = [3, 5, 2, 8, 1, 9]) == -12\n assert candidate(nums = [6, 1, 5, 2, 4, 3]) == -4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == -100\n assert candidate(nums = [99999, 99999, 99999, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [3, 2, 1, 6, 5, 4, 9, 8, 7]) == -18\n assert candidate(nums = [1, 1, 1, 1, 100000, 100000, 100000, 100000, 100000]) == -299997\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 1, 2, 3]) == 9\n assert candidate(nums = [100000, 1, 2, 3, 100000, 4, 5, 6, 100000]) == -200000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -50\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14]) == -34\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 0\n assert candidate(nums = [100000, 100000, 100000, 1, 1, 1, 100000, 100000, 100000]) == -299997\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == -1800\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == -3\n assert candidate(nums = [9, 7, 5, 3, 1, 11, 13, 15, 17, 19, 21, 23]) == -64\n assert candidate(nums = [100000, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == -99999\n assert candidate(nums = [200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100]) == -200\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995]) == -199989\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1, 10, 100]) == -110889\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == -32\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12]) == -26\n assert candidate(nums = [1, 2, 100000, 3, 100000, 4, 5, 100000, 6]) == -200000\n assert candidate(nums = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1]) == -199998\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == -1800\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1, 10, 100, 1000, 10000, 100000]) == -218889\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 2, 4, 6]) == -18\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == -16\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == -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]) == -162\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5]) == -199994\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == -3200\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == -180\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100]) == -200\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88]) == 16\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 5, 3, 8]) == -13\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -50\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == -30\n assert candidate(nums = [30000, 20000, 10000, 50000, 40000, 60000, 90000, 80000, 70000]) == -180000\n assert candidate(nums = [1, 1, 1, 100000, 100000, 100000, 1, 1, 1]) == -299997\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 100000, 100000, 100000]) == -299997\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 100000, 100000, 100000]) == -299997\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95]) == -284\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == -300\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == -320\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]) == -360\n assert candidate(nums = [99999, 99998, 99997, 1, 2, 3, 4, 5, 6]) == -9\n assert candidate(nums = [1, 2, 3, 100000, 100000, 100000]) == -199997\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992]) == 9\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == -16\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1]) == -2\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == -10\n assert candidate(nums = [12345, 67890, 54321, 98765, 43210, 87654, 32109, 76543, 21098]) == -128406\n assert candidate(nums = [9, 3, 6, 3, 9, 3, 6, 3, 9, 3, 6, 3, 9, 3, 6, 3, 9, 3, 6, 3, 9, 3, 6, 3]) == -21\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 1, 2, 3, 4, 5, 6]) == 199976\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1]) == -10\n assert candidate(nums = [50, 50, 50, 1, 1, 1, 100, 100, 100]) == -297\n assert candidate(nums = [50, 25, 100, 75, 150, 125, 200, 175, 225]) == -450\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == -199998\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == -20\n assert candidate(nums = [50000, 40000, 30000, 20000, 10000, 90000, 80000, 70000, 60000]) == -180000\n assert candidate(nums = [5, 4, 3, 2, 1, 9, 8, 7, 6]) == -18\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]) == -72\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20]) == 90\n assert candidate(nums = [99999, 1, 99998, 2, 99997, 3, 99996, 4, 99995]) == -199989\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -18\n assert candidate(nums = [7, 3, 5, 1, 9, 4, 6, 8, 2, 10, 12, 11]) == -28\n assert candidate(nums = [1, 3, 5, 2, 4, 6]) == -7\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8]) == -15\n assert candidate(nums = [3, 1, 2, 5, 4, 6, 9, 7, 8]) == -18\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6]) == -12\n assert candidate(nums = [100000, 100000, 1, 1, 100000, 100000, 1, 1, 100000]) == -199998\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995]) == -299984\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5, 600, 6]) == -1497\n assert candidate(nums = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18]) == -36\n assert candidate(nums = [6, 2, 8, 4, 10, 12, 1, 3, 5, 7, 9, 11]) == -22\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 1, 2, 3]) == -900\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n", "comparison": "exact"}, "public_tests": ["[3,1,2]", "[7,9,5,8,1,3]"], "hints": ["The lowest possible difference can be obtained when the sum of the first n elements in the resultant array is minimum, and the sum of the next n elements is maximum.", "For every index i, think about how you can find the minimum possible sum of n elements with indices lesser or equal to i, if possible.", "Similarly, for every index i, try to find the maximum possible sum of n elements with indices greater or equal to i, if possible.", "Now for all indices, check if we can consider it as the partitioning index and hence find the answer."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:22+00:00", "tests_total": 117, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "dynamic-programming", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function minimumDifference($nums) {", "container": "Solution", "callable": "minimumDifference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2164, "task_id": "sort-even-and-odd-indices-independently", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:\n\n1. Sort the values at odd indices of nums in non-increasing order.\n - For example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasing order.\n2. Sort the values at even indices of nums in non-decreasing order.\n - For example, if nums = [4,1,2,3] before this step, it becomes [2,1,4,3] after. The values at even indices 0 and 2 are sorted in non-decreasing order.\n\nReturn the array formed after rearranging the values of nums.\n\nExample 1:\n\nInput: nums = [4,1,2,3]\nOutput: [2,3,4,1]\nExplanation:\nFirst, we sort the values present at odd indices (1 and 3) in non-increasing order.\nSo, nums changes from [4,1,2,3] to [4,3,2,1].\nNext, we sort the values present at even indices (0 and 2) in non-decreasing order.\nSo, nums changes from [4,1,2,3] to [2,3,4,1].\nThus, the array formed after rearranging the values is [2,3,4,1].\n\nExample 2:\n\nInput: nums = [2,1]\nOutput: [2,1]\nExplanation:\nSince there is exactly one odd index and one even index, no rearrangement of values takes place.\nThe resultant array formed is [2,1], which is the same as the initial array.\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]) == [1]\n assert candidate(nums = [100, 99, 98, 97, 96, 95]) == [96, 99, 98, 97, 100, 95]\n assert candidate(nums = [1, 3, 2, 2, 3, 1]) == [1, 3, 2, 2, 3, 1]\n assert candidate(nums = [1, 9, 3, 7, 5, 6, 2, 8, 4]) == [1, 9, 2, 8, 3, 7, 4, 6, 5]\n assert candidate(nums = [5, 3, 2, 4, 1, 6]) == [1, 6, 2, 4, 5, 3]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70]) == [10, 60, 30, 40, 50, 20, 70]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5]) == [1, 9, 2, 8, 3, 7, 4, 6, 5]\n assert candidate(nums = [10, 20, 30, 40, 50]) == [10, 40, 30, 20, 50]\n assert candidate(nums = [4, 1, 2, 3]) == [2, 3, 4, 1]\n assert candidate(nums = [5, 3, 2, 8, 1, 4]) == [1, 8, 2, 4, 5, 3]\n assert candidate(nums = [2, 1]) == [2, 1]\n assert candidate(nums = [5, 6, 3, 4, 7]) == [3, 6, 5, 4, 7]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [2, 9, 4, 7, 6, 5, 8, 3, 10, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 10, 3, 8, 5, 6, 7, 4, 9, 2]\n assert candidate(nums = [1, 9, 3, 7, 5, 11, 2, 8, 4, 6, 10, 12, 14, 13, 15]) == [1, 13, 2, 12, 3, 11, 4, 9, 5, 8, 10, 7, 14, 6, 15]\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, 19, 4, 17, 6, 15, 8, 13, 10, 11, 12, 9, 14, 7, 16, 5, 18, 3, 20, 1]\n assert candidate(nums = [7, 5, 9, 3, 8, 6, 10, 2, 4]) == [4, 6, 7, 5, 8, 3, 9, 2, 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]) == [1, 20, 3, 18, 5, 16, 7, 14, 9, 12, 11, 10, 13, 8, 15, 6, 17, 4, 19, 2, 21]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 15, 2, 13, 3, 11, 4, 9, 5, 7, 6, 6, 7, 5, 8, 4, 10, 3, 12, 2, 14, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == [1, 31, 5, 27, 9, 23, 13, 19, 17, 15, 21, 11, 25, 7, 29, 3]\n assert candidate(nums = [9, 7, 5, 3, 1, 8, 6, 4, 2]) == [1, 8, 2, 7, 5, 4, 6, 3, 9]\n assert candidate(nums = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [2, 15, 4, 13, 6, 11, 8, 9, 10, 7, 12, 5, 14, 3, 16, 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]) == [1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6, 6, 7, 5, 8, 4, 9, 3, 10, 2, 11, 1]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [2, 9, 3, 6, 4, 3, 5, 1, 5, 1, 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]) == [2, 19, 4, 17, 6, 15, 8, 13, 10, 11, 12, 9, 14, 7, 16, 5, 18, 3, 20, 1]\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 45, 35, 25, 15, 55, 45, 35, 25, 15, 5, 65, 55, 45, 35, 25, 15, 5]) == [5, 55, 10, 45, 15, 40, 25, 35, 25, 35, 30, 25, 35, 20, 45, 15, 45, 15, 50, 5, 55, 5, 65]\n assert candidate(nums = [64, 34, 25, 12, 22, 11, 90]) == [22, 34, 25, 12, 64, 11, 90]\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95]) == [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 14, 3, 12, 5, 10, 7, 8, 9, 6, 11, 4, 13, 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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [34, 23, 12, 45, 56, 78, 89, 90, 100, 11, 22, 33]) == [12, 90, 22, 78, 34, 45, 56, 33, 89, 23, 100, 11]\n assert candidate(nums = [15, 10, 25, 20, 35, 30, 45, 40, 55, 50, 65, 60]) == [15, 60, 25, 50, 35, 40, 45, 30, 55, 20, 65, 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, 42, 42]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10]) == [1, 10, 2, 9, 3, 8, 4, 7, 5, 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, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]) == [1, 59, 5, 55, 9, 51, 13, 47, 17, 43, 21, 39, 25, 35, 29, 31, 33, 27, 37, 23, 41, 19, 45, 15, 49, 11, 53, 7, 57, 3]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 14, 3, 12, 5, 10, 7, 8, 9, 6, 11, 4, 13, 2, 15]\n assert candidate(nums = [42, 84, 21, 63, 42, 84, 21, 63, 42, 84, 21, 63]) == [21, 84, 21, 84, 21, 84, 42, 63, 42, 63, 42, 63]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 20, 3, 18, 5, 16, 7, 14, 9, 12, 11, 10, 13, 8, 15, 6, 17, 4, 19, 2]\n assert candidate(nums = [34, 78, 23, 67, 89, 45, 12, 90, 100, 56, 34, 23, 56, 78, 90, 12]) == [12, 90, 23, 78, 34, 78, 34, 67, 56, 56, 89, 45, 90, 23, 100, 12]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 14, 3, 12, 5, 10, 7, 8, 9, 6, 11, 4, 13, 2, 15]\n assert candidate(nums = [33, 1, 66, 2, 99, 3, 44, 4, 77, 5, 88, 6, 11, 7, 22, 8, 55, 9, 33, 10]) == [11, 10, 22, 9, 33, 8, 33, 7, 44, 6, 55, 5, 66, 4, 77, 3, 88, 2, 99, 1]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5]) == [96, 5, 97, 4, 98, 3, 99, 2, 100, 1]\n assert candidate(nums = [7, 11, 5, 15, 3, 19, 1, 23, 9, 29, 6, 33, 2, 37, 8, 41]) == [1, 41, 2, 37, 3, 33, 5, 29, 6, 23, 7, 19, 8, 15, 9, 11]\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == [3, 29, 7, 25, 11, 21, 15, 17, 19, 13, 23, 9, 27, 5, 31, 1]\n assert candidate(nums = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) == [21, 30, 23, 28, 25, 26, 27, 24, 29, 22, 31]\n assert candidate(nums = [25, 20, 15, 10, 5, 30, 25, 20, 15, 10, 5, 35, 30, 25, 20, 15, 10, 5, 40, 35, 30, 25, 20, 15, 10, 5]) == [5, 35, 5, 35, 10, 30, 10, 25, 15, 25, 15, 20, 20, 20, 20, 15, 25, 15, 25, 10, 30, 10, 30, 5, 40, 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]\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6, 93, 7, 92, 8, 91, 9, 90, 10]) == [90, 10, 91, 9, 92, 8, 93, 7, 94, 6, 95, 5, 96, 4, 97, 3, 98, 2, 99, 1]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == [1, 27, 5, 23, 9, 19, 13, 15, 17, 11, 21, 7, 25, 3, 29]\n assert candidate(nums = [8, 1, 6, 3, 4, 5, 2, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == [2, 15, 4, 13, 6, 11, 8, 9, 10, 7, 12, 5, 14, 3, 16, 1]\n assert candidate(nums = [23, 18, 34, 15, 29, 10, 40, 25, 39, 20, 22, 35, 41, 5, 38]) == [22, 35, 23, 25, 29, 20, 34, 18, 38, 15, 39, 10, 40, 5, 41]\n assert candidate(nums = [5, 1, 9, 3, 7, 5, 3, 2, 6, 8, 4, 10, 12, 11]) == [3, 11, 4, 10, 5, 8, 6, 5, 7, 3, 9, 2, 12, 1]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == [90, 99, 92, 97, 94, 95, 96, 93, 98, 91, 100]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10]) == [91, 10, 92, 9, 93, 8, 94, 7, 95, 6, 96, 5, 97, 4, 98, 3, 99, 2, 100, 1]\n assert candidate(nums = [45, 67, 23, 89, 12, 34, 56, 78, 90]) == [12, 89, 23, 78, 45, 67, 56, 34, 90]\n assert candidate(nums = [8, 1, 6, 3, 5, 7, 4, 9, 2]) == [2, 9, 4, 7, 5, 3, 6, 1, 8]\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 5, 5]) == [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 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]) == [1, 20, 3, 18, 5, 16, 7, 14, 9, 12, 11, 10, 13, 8, 15, 6, 17, 4, 19, 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, 2, 1, 2]) == [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(nums = [50, 51, 49, 52, 48, 53, 47, 54, 46, 55, 45, 56, 44, 57, 43, 58]) == [43, 58, 44, 57, 45, 56, 46, 55, 47, 54, 48, 53, 49, 52, 50, 51]\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]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == [1, 15, 2, 13, 4, 11, 6, 9, 8, 7, 10, 5, 12, 3, 14]\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89]) == [90, 99, 92, 97, 94, 95, 96, 93, 98, 91, 100, 89]\n assert candidate(nums = [55, 22, 66, 33, 77, 44, 88, 55, 99, 66, 11, 77, 33, 44, 22, 88]) == [11, 88, 22, 77, 33, 66, 55, 55, 66, 44, 77, 44, 88, 33, 99, 22]\n assert candidate(nums = [50, 10, 40, 20, 30, 30, 20, 40, 10, 50]) == [10, 50, 20, 40, 30, 30, 40, 20, 50, 10]\n assert candidate(nums = [1, 9, 3, 7, 5, 11, 2, 8, 6, 4, 10]) == [1, 11, 2, 9, 3, 8, 5, 7, 6, 4, 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]) == [2, 29, 4, 27, 6, 25, 8, 23, 10, 21, 12, 19, 14, 17, 16, 15, 18, 13, 20, 11, 22, 9, 24, 7, 26, 5, 28, 3, 30, 1]\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16]) == [1, 20, 3, 18, 5, 16, 7, 14, 9, 12, 11, 10, 13, 8, 15, 6, 17, 4, 19, 2]\n assert candidate(nums = [8, 2, 4, 6, 10, 1, 9, 3, 7, 5, 11, 13, 15, 17, 19, 21]) == [4, 21, 7, 17, 8, 13, 9, 6, 10, 5, 11, 3, 15, 2, 19, 1]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6]) == [95, 6, 96, 5, 97, 4, 98, 3, 99, 2, 100, 1]\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95]) == [95, 5, 96, 4, 97, 3, 98, 2, 99, 1, 100]\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, 40, 6, 36, 10, 32, 14, 28, 18, 24, 22, 20, 26, 16, 30, 12, 34, 8, 38, 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]\n assert candidate(nums = [50, 25, 45, 15, 35, 5, 20, 10, 30, 40]) == [20, 40, 30, 25, 35, 15, 45, 10, 50, 5]\n assert candidate(nums = [7, 5, 3, 1, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14]) == [2, 15, 3, 12, 6, 11, 7, 8, 9, 5, 10, 4, 13, 1, 14]\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == [1, 10, 4, 7, 5, 6, 8, 3, 9, 2]\n assert candidate(nums = [45, 32, 21, 18, 30, 29, 20, 19, 25, 15, 35, 10, 40, 5, 50, 1]) == [20, 32, 21, 29, 25, 19, 30, 18, 35, 15, 40, 10, 45, 5, 50, 1]\n assert candidate(nums = [34, 78, 12, 56, 90, 32, 45, 89, 23, 67, 54, 10, 76, 9, 5, 11]) == [5, 89, 12, 78, 23, 67, 34, 56, 45, 32, 54, 11, 76, 10, 90, 9]\n assert candidate(nums = [5, 1, 9, 3, 7, 5, 11, 7, 13, 9, 15, 11, 17, 13, 19, 15, 21, 17, 23, 19, 25, 21, 27, 23, 29, 25, 31, 27, 33, 29, 35]) == [5, 29, 7, 27, 9, 25, 11, 23, 13, 21, 15, 19, 17, 17, 19, 15, 21, 13, 23, 11, 25, 9, 27, 7, 29, 5, 31, 3, 33, 1, 35]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 8, 9, 10]) == [1, 10, 3, 8, 5, 6, 7, 4, 9, 2]\n assert candidate(nums = [42, 24, 31, 29, 48, 17, 11, 35, 22, 44, 55, 50, 47, 60, 53, 58, 65, 62, 63, 68, 70, 72, 71, 80, 79, 78, 77, 76, 75, 74, 73]) == [11, 80, 22, 78, 31, 76, 42, 74, 47, 72, 48, 68, 53, 62, 55, 60, 63, 58, 65, 50, 70, 44, 71, 35, 73, 29, 75, 24, 77, 17, 79]\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]\n assert candidate(nums = [40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [4, 38, 8, 34, 12, 30, 16, 26, 20, 22, 24, 18, 28, 14, 32, 10, 36, 6, 40, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [1, 16, 3, 14, 5, 12, 7, 10, 9, 8, 11, 6, 13, 4, 15, 2]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10]) == [1, 11, 2, 9, 4, 7, 6, 5, 8, 3, 10]\n assert candidate(nums = [5, 9, 1, 8, 3, 7, 2, 6, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [1, 30, 2, 28, 3, 26, 4, 24, 5, 22, 11, 20, 13, 18, 15, 16, 17, 14, 19, 12, 21, 10, 23, 9, 25, 8, 27, 7, 29, 6]\n", "comparison": "exact"}, "public_tests": ["[4,1,2,3]", "[2,1]"], "hints": ["Try to separate the elements at odd indices from the elements at even indices.", "Sort the two groups of elements individually.", "Combine them to form the resultant array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().sortEvenOdd", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:24+00:00", "tests_total": 107, "tests_dropped": 20, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "php", "interface": {"raw_signature": "function sortEvenOdd($nums) {", "container": "Solution", "callable": "sortEvenOdd", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2165, "task_id": "smallest-value-of-the-rearranged-number", "difficulty": "Medium", "problem_description": "You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.\n\nReturn the rearranged number with minimal value.\n\nNote that the sign of the number does not change after rearranging the digits.\n\nExample 1:\n\nInput: num = 310\nOutput: 103\nExplanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.\nThe arrangement with the smallest value that does not contain any leading zeros is 103.\n\nExample 2:\n\nInput: num = -7605\nOutput: -7650\nExplanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.\nThe arrangement with the smallest value that does not contain any leading zeros is -7650.\n\nConstraints:\n\n- -10^15 <= num <= 10^15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 2020) == 2002\n assert candidate(num = 10) == 10\n assert candidate(num = -10000000000) == -10000000000\n assert candidate(num = 10000000000) == 10000000000\n assert candidate(num = 10001) == 10001\n assert candidate(num = 123456789) == 123456789\n assert candidate(num = 9876543210) == 1023456789\n assert candidate(num = 310) == 103\n assert candidate(num = 1000) == 1000\n assert candidate(num = -10001) == -11000\n assert candidate(num = -9876543210) == -9876543210\n assert candidate(num = 1001) == 1001\n assert candidate(num = 987654321) == 123456789\n assert candidate(num = -100) == -100\n assert candidate(num = 0) == 0\n assert candidate(num = -7605) == -7650\n assert candidate(num = -1001) == -1100\n assert candidate(num = -123456789) == -987654321\n assert candidate(num = 100) == 100\n assert candidate(num = -12345) == -54321\n assert candidate(num = 54321) == 12345\n assert candidate(num = -10) == -10\n assert candidate(num = -900) == -900\n assert candidate(num = -600500400300201) == -654321000000000\n assert candidate(num = -999999999) == -999999999\n assert candidate(num = 101010101010101) == 100000001111111\n assert candidate(num = 505050505050505) == 500000005555555\n assert candidate(num = -123456789012345) == -987655443322110\n assert candidate(num = -1230456) == -6543210\n assert candidate(num = 1000000000) == 1000000000\n assert candidate(num = -202020202020202) == -222222220000000\n assert candidate(num = 213004005) == 100002345\n assert candidate(num = -999999999999999) == -999999999999999\n assert candidate(num = -987654321012345) == -987655443322110\n assert candidate(num = -543210000) == -543210000\n assert candidate(num = -12000210) == -22110000\n assert candidate(num = -99999999999999) == -99999999999999\n assert candidate(num = 101010101) == 100001111\n assert candidate(num = 303030303030303) == 300000003333333\n assert candidate(num = 56789) == 56789\n assert candidate(num = 1230000000) == 1000000023\n assert candidate(num = 100000000000001) == 100000000000001\n assert candidate(num = 1000100) == 1000001\n assert candidate(num = 120030400500600) == 100000000023456\n assert candidate(num = 20000000000000) == 20000000000000\n assert candidate(num = 1000000000000000) == 1000000000000000\n assert candidate(num = -111111111111111) == -111111111111111\n assert candidate(num = -300000000000000) == -300000000000000\n assert candidate(num = 100000000000000) == 100000000000000\n assert candidate(num = 202020202020202) == 200000002222222\n assert candidate(num = 1002003004) == 1000000234\n assert candidate(num = 1000000001) == 1000000001\n assert candidate(num = -123456789098765) == -998877665543210\n assert candidate(num = -200100000000000) == -210000000000000\n assert candidate(num = -111222333) == -333222111\n assert candidate(num = -9999999999999) == -9999999999999\n assert candidate(num = 12003004005) == 10000002345\n assert candidate(num = 999999999) == 999999999\n assert candidate(num = -50000000000000) == -50000000000000\n assert candidate(num = 1111111111111) == 1111111111111\n assert candidate(num = 1010101010) == 1000001111\n assert candidate(num = -111000000) == -111000000\n assert candidate(num = -1) == -1\n assert candidate(num = -543210987654321) == -987655443322110\n assert candidate(num = 2003005006) == 2000000356\n assert candidate(num = 30000123) == 10000233\n assert candidate(num = 1000002) == 1000002\n assert candidate(num = 999999999999999) == 999999999999999\n assert candidate(num = -999888777666) == -999888777666\n assert candidate(num = 100001000010000) == 100000000000011\n assert candidate(num = 500000000000000) == 500000000000000\n assert candidate(num = -222222222) == -222222222\n assert candidate(num = -200000000000001) == -210000000000000\n assert candidate(num = 2000000001) == 1000000002\n assert candidate(num = -100000000000001) == -110000000000000\n assert candidate(num = 111000222333) == 100011222333\n assert candidate(num = -900000000000001) == -910000000000000\n assert candidate(num = -1000000000000000) == -1000000000000000\n assert candidate(num = 111111111111111) == 111111111111111\n assert candidate(num = -303030303030303) == -333333330000000\n assert candidate(num = 503020104) == 100002345\n assert candidate(num = 900000000000000) == 900000000000000\n assert candidate(num = 200000000000001) == 100000000000002\n assert candidate(num = -50006007008) == -87650000000\n assert candidate(num = 100020003000) == 100000000023\n assert candidate(num = 99999999999999) == 99999999999999\n assert candidate(num = 3003003) == 3000033\n assert candidate(num = -10000100001000) == -11100000000000\n assert candidate(num = -100000000000000) == -100000000000000\n assert candidate(num = 1234567890) == 1023456789\n assert candidate(num = 10000000000000) == 10000000000000\n assert candidate(num = -2100300) == -3210000\n assert candidate(num = 123456789012345) == 101223344556789\n assert candidate(num = 123000456) == 100023456\n assert candidate(num = -987000000000000) == -987000000000000\n assert candidate(num = -202020202) == -222220000\n assert candidate(num = 2003004005) == 2000000345\n assert candidate(num = -1234567890) == -9876543210\n assert candidate(num = -5000000) == -5000000\n assert candidate(num = -56789) == -98765\n", "comparison": "exact"}, "public_tests": ["310", "-7605"], "hints": ["For positive numbers, the leading digit should be the smallest nonzero digit. Then the remaining digits follow in ascending order.", "For negative numbers, the digits should be arranged in descending order."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().smallestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:26+00:00", "tests_total": 121, "tests_dropped": 21, "flags": [], "topic_tags": ["math", "sorting"]}, "language": "php", "interface": {"raw_signature": "function smallestNumber($num) {", "container": "Solution", "callable": "smallestNumber", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2167, "task_id": "minimum-time-to-remove-all-cars-containing-illegal-goods", "difficulty": "Hard", "problem_description": "You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the i^th car does not contain illegal goods and s[i] = '1' denotes that the i^th car does contain illegal goods.\n\nAs the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations any number of times:\n\n1. Remove a train car from the left end (i.e., remove s[0]) which takes 1 unit of time.\n2. Remove a train car from the right end (i.e., remove s[s.length - 1]) which takes 1 unit of time.\n3. Remove a train car from anywhere in the sequence which takes 2 units of time.\n\nReturn the minimum time to remove all the cars containing illegal goods.\n\nNote that an empty sequence of cars is considered to have no cars containing illegal goods.\n\nExample 1:\n\nInput: s = \"1100101\"\nOutput: 5\nExplanation:\nOne way to remove all the cars containing illegal goods from the sequence is to\n- remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n- remove a car from the right end. Time taken is 1.\n- remove the car containing illegal goods found in the middle. Time taken is 2.\nThis obtains a total time of 2 + 1 + 2 = 5.\n\nAn alternative way is to\n- remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n- remove a car from the right end 3 times. Time taken is 3 * 1 = 3.\nThis also obtains a total time of 2 + 3 = 5.\n\n5 is the minimum time taken to remove all the cars containing illegal goods.\nThere are no other ways to remove them with less time.\n\nExample 2:\n\nInput: s = \"0010\"\nOutput: 2\nExplanation:\nOne way to remove all the cars containing illegal goods from the sequence is to\n- remove a car from the left end 3 times. Time taken is 3 * 1 = 3.\nThis obtains a total time of 3.\n\nAnother way to remove all the cars containing illegal goods from the sequence is to\n- remove the car containing illegal goods found in the middle. Time taken is 2.\nThis obtains a total time of 2.\n\nAnother way to remove all the cars containing illegal goods from the sequence is to\n- remove a car from the right end 2 times. Time taken is 2 * 1 = 2.\nThis obtains a total time of 2.\n\n2 is the minimum time taken to remove all the cars containing illegal goods.\nThere are no other ways to remove them with less time.\n\nConstraints:\n\n- 1 <= s.length <= 2 * 10^5\n- s[i] is either '0' or '1'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100100\") == 7\n assert candidate(s = \"110110110110110110110110110110110110110110110110\") == 47\n assert candidate(s = \"1100101\") == 5\n assert candidate(s = \"1001001001\") == 6\n assert candidate(s = \"11111\") == 5\n assert candidate(s = \"111111\") == 6\n assert candidate(s = \"0101010101\") == 9\n assert candidate(s = \"0\") == 0\n assert candidate(s = \"000000\") == 0\n assert candidate(s = \"0010\") == 2\n assert candidate(s = \"111000111\") == 6\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"000111000\") == 6\n assert candidate(s = \"1010101010\") == 9\n assert candidate(s = \"101101101101101\") == 14\n assert candidate(s = \"111100001111\") == 8\n assert candidate(s = \"1\") == 1\n assert candidate(s = \"101010101010101\") == 14\n assert candidate(s = \"1101001010111001010111001010111001010111001010111001\") == 50\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101\") == 62\n assert candidate(s = \"111000111000111000\") == 15\n assert candidate(s = \"11010101010101010101010101010101010101\") == 37\n assert candidate(s = \"0000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"010101010101010101010101010101010101\") == 35\n assert candidate(s = \"111111111111111111111111111111111111111111111111\") == 48\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\") == 49\n assert candidate(s = \"1000100010001000100010001000100010001000100010001000\") == 25\n assert candidate(s = \"000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"111011101110111011101110111011101110111011101110\") == 47\n assert candidate(s = \"010101010101010101010101\") == 23\n assert candidate(s = \"00001111000011110000\") == 16\n assert candidate(s = \"111000111000111\") == 12\n assert candidate(s = \"100011110000111100001111\") == 20\n assert candidate(s = \"10101010101010101010101010101010101010101010101\") == 46\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010\") == 53\n assert candidate(s = \"110101010101010101010101010101010101010101010101\") == 47\n assert candidate(s = \"111111111110111111111111\") == 23\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100\") == 50\n assert candidate(s = \"1000000000000000000001\") == 2\n assert candidate(s = \"000001000001000001000001\") == 7\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"11110000000000001111\") == 8\n assert candidate(s = \"111111000000111111000000\") == 18\n assert candidate(s = \"111100001111000011110000\") == 20\n assert candidate(s = \"0010101010101010101010101010101010101010101010101010\") == 50\n assert candidate(s = \"0111111111111111111111111111111111111110\") == 39\n assert candidate(s = \"011011011011011011011011011011011011011011011011\") == 47\n assert candidate(s = \"1010101010101010101010101010101010101010101010101011\") == 51\n assert candidate(s = \"00001010101010101000\") == 14\n assert candidate(s = \"1110010100101001010010100101001010010100101001010010\") == 41\n assert candidate(s = \"11111111111111111111111111111111111111111111111\") == 47\n assert candidate(s = \"010101010101010101010101010101010101010101010101\") == 47\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101010101010101010101\") == 71\n assert candidate(s = \"000000000000111111111111000000000000111111111111\") == 36\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000\") == 57\n assert candidate(s = \"110011001100110011001100110011001100110011001100\") == 46\n assert candidate(s = \"101010101010101010101010101010101010101\") == 38\n assert candidate(s = \"00000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"1110001110001110001110001110001110001110001110001110\") == 49\n assert candidate(s = \"000000000000000011111111111111110000000000000000\") == 32\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010101010101010\") == 63\n assert candidate(s = \"000110001100011000110001100011000110001100011000110001100011\") == 46\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111\") == 52\n assert candidate(s = \"00110011001100110011001100\") == 24\n assert candidate(s = \"1000000000000000000000000000000000000000000000000000\") == 1\n assert candidate(s = \"111100001111000011110000111100001111000011110000\") == 44\n assert candidate(s = \"01010101010101010101010101010101\") == 31\n assert candidate(s = \"11110000111100001111000011110000111100001111000011110000\") == 52\n assert candidate(s = \"00000000111111110000000011111111000000001111111100000000\") == 48\n assert candidate(s = \"0000011111000001111100000111110000011111000001111100\") == 47\n assert candidate(s = \"1101010101010101010101\") == 21\n assert candidate(s = \"010101010101010101010101010101010101010101010101010101\") == 53\n assert candidate(s = \"1111100000111110000011111000001111100000111110000011\") == 47\n assert candidate(s = \"000000000000000\") == 0\n assert candidate(s = \"00000000000000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111\") == 54\n assert candidate(s = \"100010001000100010001000100010001000100010001000\") == 23\n assert candidate(s = \"1111111111111111111111111111111111111111\") == 40\n assert candidate(s = \"0001001001001001001001001001001001001001001001001001\") == 33\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001\") == 38\n assert candidate(s = \"1001100110011001100110011001100110011001100110011001100110011001\") == 62\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101\") == 51\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"111111000000111111000000111111000000111111000000111111000000\") == 54\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101\") == 55\n assert candidate(s = \"1110000111100001111000011110000111100001111000011110\") == 48\n assert candidate(s = \"11010101010101010101\") == 19\n assert candidate(s = \"1010101010101010101010101010101010101010101010\") == 45\n assert candidate(s = \"0000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"1010101010101010101010\") == 21\n assert candidate(s = \"0000000000000000000000000000000000000000000000001\") == 1\n assert candidate(s = \"1111000001111000001111\") == 16\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100\") == 62\n assert candidate(s = \"1010101010101010101010101010101010101010101010101010\") == 51\n assert candidate(s = \"011001100110011001100110011001100110011001100110\") == 46\n assert candidate(s = \"000000000001000000000001\") == 3\n assert candidate(s = \"10000000000000000001\") == 2\n assert candidate(s = \"011011011011011011011011011011011011011011011011011011011011011011011011\") == 71\n assert candidate(s = \"0001111111000000111111111000000111111111100000011111\") == 46\n assert candidate(s = \"10101010101010101010\") == 19\n assert candidate(s = \"0000000000000000000000\") == 0\n", "comparison": "exact"}, "public_tests": ["\"1100101\"", "\"0010\""], "hints": ["Build an array withoutFirst where withoutFirst[i] stores the minimum time to remove all the cars containing illegal goods from the ‘suffix’ of the sequence starting from the ith car without using any type 1 operations.", "Next, build an array onlyFirst where onlyFirst[i] stores the minimum time to remove all the cars containing illegal goods from the ‘prefix’ of the sequence ending on the ith car using only type 1 operations.", "Finally, we can compare the best way to split the operations amongst these two types by finding the minimum time across all onlyFirst[i] + withoutFirst[i + 1]."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:28+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function minimumTime($s) {", "container": "Solution", "callable": "minimumTime", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2169, "task_id": "count-operations-to-obtain-zero", "difficulty": "Easy", "problem_description": "You are given two non-negative integers num1 and num2.\n\nIn one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.\n\n- For example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.\n\nReturn the number of operations required to make either num1 = 0 or num2 = 0.\n\nExample 1:\n\nInput: num1 = 2, num2 = 3\nOutput: 3\nExplanation:\n- Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.\n- Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.\n- Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.\nNow num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.\nSo the total number of operations required is 3.\n\nExample 2:\n\nInput: num1 = 10, num2 = 10\nOutput: 1\nExplanation:\n- Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.\nNow num1 = 0 and num2 = 10. Since num1 == 0, we are done.\nSo the total number of operations required is 1.\n\nConstraints:\n\n- 0 <= num1, num2 <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num1 = 0,num2 = 5) == 0\n assert candidate(num1 = 100,num2 = 1) == 100\n assert candidate(num1 = 123,num2 = 456) == 12\n assert candidate(num1 = 8,num2 = 12) == 3\n assert candidate(num1 = 1,num2 = 1) == 1\n assert candidate(num1 = 100000,num2 = 100000) == 1\n assert candidate(num1 = 100000,num2 = 1) == 100000\n assert candidate(num1 = 100,num2 = 50) == 2\n assert candidate(num1 = 5,num2 = 0) == 0\n assert candidate(num1 = 2,num2 = 3) == 3\n assert candidate(num1 = 10,num2 = 10) == 1\n assert candidate(num1 = 7,num2 = 3) == 5\n assert candidate(num1 = 81,num2 = 27) == 3\n assert candidate(num1 = 99999,num2 = 1) == 99999\n assert candidate(num1 = 333,num2 = 111) == 3\n assert candidate(num1 = 10000,num2 = 9999) == 10000\n assert candidate(num1 = 2020,num2 = 1870) == 22\n assert candidate(num1 = 60,num2 = 20) == 3\n assert candidate(num1 = 101,num2 = 100) == 101\n assert candidate(num1 = 42,num2 = 29) == 10\n assert candidate(num1 = 100000,num2 = 0) == 0\n assert candidate(num1 = 45678,num2 = 45678) == 1\n assert candidate(num1 = 88888,num2 = 22222) == 4\n assert candidate(num1 = 618,num2 = 359) == 15\n assert candidate(num1 = 100000,num2 = 99999) == 100000\n assert candidate(num1 = 42,num2 = 7) == 6\n assert candidate(num1 = 98765,num2 = 43210) == 1241\n assert candidate(num1 = 2,num2 = 34567) == 17285\n assert candidate(num1 = 1,num2 = 99999) == 99999\n assert candidate(num1 = 1000,num2 = 333) == 336\n assert candidate(num1 = 88888,num2 = 11111) == 8\n assert candidate(num1 = 9,num2 = 1) == 9\n assert candidate(num1 = 1000,num2 = 1) == 1000\n assert candidate(num1 = 55555,num2 = 22222) == 4\n assert candidate(num1 = 87,num2 = 3) == 29\n assert candidate(num1 = 15,num2 = 10) == 3\n assert candidate(num1 = 60000,num2 = 30000) == 2\n assert candidate(num1 = 22222,num2 = 11111) == 2\n assert candidate(num1 = 65536,num2 = 1) == 65536\n assert candidate(num1 = 65432,num2 = 12345) == 80\n assert candidate(num1 = 20,num2 = 30) == 3\n assert candidate(num1 = 50000,num2 = 25000) == 2\n assert candidate(num1 = 13579,num2 = 24680) == 39\n assert candidate(num1 = 777,num2 = 111) == 7\n assert candidate(num1 = 88888,num2 = 44444) == 2\n assert candidate(num1 = 12345,num2 = 54321) == 177\n assert candidate(num1 = 5000,num2 = 7500) == 3\n assert candidate(num1 = 25,num2 = 5) == 5\n assert candidate(num1 = 23456,num2 = 65432) == 44\n assert candidate(num1 = 45678,num2 = 87654) == 45\n assert candidate(num1 = 12345,num2 = 67890) == 418\n assert candidate(num1 = 42,num2 = 30) == 5\n assert candidate(num1 = 789,num2 = 987) == 70\n assert candidate(num1 = 99999,num2 = 99999) == 1\n assert candidate(num1 = 456,num2 = 123) == 12\n assert candidate(num1 = 0,num2 = 0) == 0\n assert candidate(num1 = 55,num2 = 20) == 6\n assert candidate(num1 = 33333,num2 = 22222) == 3\n assert candidate(num1 = 54321,num2 = 12345) == 177\n assert candidate(num1 = 1,num2 = 100000) == 100000\n assert candidate(num1 = 32768,num2 = 16384) == 2\n assert candidate(num1 = 1000,num2 = 100) == 10\n assert candidate(num1 = 2,num2 = 8) == 4\n assert candidate(num1 = 75,num2 = 25) == 3\n assert candidate(num1 = 83456,num2 = 37821) == 38\n assert candidate(num1 = 23456,num2 = 12345) == 262\n assert candidate(num1 = 123,num2 = 321) == 11\n assert candidate(num1 = 8,num2 = 3) == 5\n assert candidate(num1 = 50,num2 = 25) == 2\n assert candidate(num1 = 13,num2 = 13) == 1\n assert candidate(num1 = 12345,num2 = 1) == 12345\n assert candidate(num1 = 55555,num2 = 55555) == 1\n assert candidate(num1 = 3,num2 = 8) == 5\n assert candidate(num1 = 30000,num2 = 15000) == 2\n assert candidate(num1 = 999,num2 = 999) == 1\n assert candidate(num1 = 56789,num2 = 12345) == 260\n assert candidate(num1 = 25,num2 = 15) == 4\n", "comparison": "exact"}, "public_tests": ["2\n3", "10\n10"], "hints": ["Try simulating the process until either of the two integers is zero.", "Count the number of operations done."], "metadata": {"canonical_parameter_names": ["num1", "num2"], "leetcode_dataset_entry_point": "Solution().countOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:33+00:00", "tests_total": 78, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countOperations($num1, $num2) {", "container": "Solution", "callable": "countOperations", "parameters": [{"name": "num1", "type": "Integer"}, {"name": "num2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2170, "task_id": "minimum-operations-to-make-the-array-alternating", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of n positive integers.\n\nThe array nums is called alternating if:\n\n- nums[i - 2] == nums[i], where 2 <= i <= n - 1.\n- nums[i - 1] != nums[i], where 1 <= i <= n - 1.\n\nIn one operation, you can choose an index i and change nums[i] into any positive integer.\n\nReturn the minimum number of operations required to make the array alternating.\n\nExample 1:\n\nInput: nums = [3,1,3,2,4,3]\nOutput: 3\nExplanation:\nOne way to make the array alternating is by converting it to [3,1,3,1,3,1].\nThe number of operations required in this case is 3.\nIt can be proven that it is not possible to make the array alternating in less than 3 operations.\n\nExample 2:\n\nInput: nums = [1,2,2,2,2]\nOutput: 2\nExplanation:\nOne way to make the array alternating is by converting it to [1,2,1,2,1].\nThe number of operations required in this case is 2.\nNote that the array cannot be converted to [2,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array.\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, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5]) == 0\n assert candidate(nums = [2, 2, 2, 2, 2, 1]) == 2\n assert candidate(nums = [1, 3, 1, 3, 2, 3, 1, 3, 1, 3]) == 1\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1]) == 0\n assert candidate(nums = [1, 3, 2, 3, 2, 3]) == 1\n assert candidate(nums = [100000, 1, 100000, 1, 100000, 1]) == 0\n assert candidate(nums = [3, 1, 3, 2, 4, 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]) == 18\n assert candidate(nums = [1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [2, 3, 2, 3, 2, 3]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 4\n assert candidate(nums = [1, 2, 2, 2, 2]) == 2\n assert candidate(nums = [1, 3, 1, 3, 1, 3]) == 0\n assert candidate(nums = [100000, 99999, 100000, 99999, 100000]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [100000, 99999, 100000, 99999, 100000]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [1, 100000, 1, 100000, 1, 100000, 1]) == 0\n assert candidate(nums = [1, 3, 5, 3, 1]) == 1\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1]) == 0\n assert candidate(nums = [10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9]) == 0\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]) == 13\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 10\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 70, 10, 80, 10, 90, 10, 100, 10, 110]) == 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]) == 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]) == 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, 10, 20]) == 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, 3]) == 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]) == 23\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 = [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 = [1, 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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 14\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]) == 17\n assert candidate(nums = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 0\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]) == 13\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]) == 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]) == 28\n assert candidate(nums = [100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101]) == 0\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 = [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, 1, 1, 1, 2, 2, 2]) == 24\n assert candidate(nums = [99999, 1, 99999, 2, 99999, 3, 99999, 4, 99999, 5]) == 4\n assert candidate(nums = [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]) == 20\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1]) == 5\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]) == 0\n assert candidate(nums = [2, 1, 2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11]) == 9\n assert candidate(nums = [42, 17, 42, 17, 42, 17, 42, 17, 42, 17, 42, 17, 42, 17, 42, 17]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50]) == 11\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]) == 0\n assert candidate(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1]) == 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, 7]) == 10\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]) == 18\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]) == 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]) == 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]) == 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]) == 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, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2]) == 13\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11]) == 16\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]) == 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, 5]) == 0\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5, 10]) == 9\n assert candidate(nums = [1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000, 1, 100000]) == 0\n assert candidate(nums = [50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51, 50, 51]) == 0\n assert candidate(nums = [5, 6, 5, 7, 5, 8, 5, 9, 5, 10, 5, 11, 5, 12]) == 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]) == 18\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999]) == 0\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 10\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1]) == 3\n assert candidate(nums = [100000, 99999, 100000, 99999, 100000, 99999, 100000, 99999, 100000, 99999]) == 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]) == 14\n assert candidate(nums = [1, 2, 1, 3, 4, 1, 2, 1, 3, 4, 1, 2, 1, 3, 4, 1, 2, 1, 3, 4, 1]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 16\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6]) == 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, 1, 2, 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 = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1]) == 5\n assert candidate(nums = [10, 9, 10, 8, 10, 7, 10, 6, 10, 5, 10, 4, 10, 3, 10, 2, 10, 1]) == 8\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5, 10]) == 9\n assert candidate(nums = [100000, 99999, 100000, 99998, 100000, 99997, 100000, 99996, 100000, 99995]) == 4\n assert candidate(nums = [2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 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, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15]) == 41\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 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]) == 10\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 11\n assert candidate(nums = [1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1]) == 3\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5]) == 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]) == 18\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]) == 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]) == 0\n assert candidate(nums = [7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11]) == 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]) == 0\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]) == 16\n assert candidate(nums = [99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1, 99999, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 16\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, 7]) == 0\n assert candidate(nums = [6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2]) == 0\n assert candidate(nums = [2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 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]) == 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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 28\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]) == 0\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 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]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 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]) == 9\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8]) == 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, 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]) == 24\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]) == 15\n assert candidate(nums = [100000, 1, 100000, 2, 100000, 3, 100000, 4, 100000, 5, 100000]) == 4\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]) == 0\n assert candidate(nums = [50000, 50000, 50001, 50001, 50002, 50002, 50003, 50003, 50004, 50004, 50005, 50005, 50006, 50006, 50007, 50007]) == 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]) == 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]) == 10\n assert candidate(nums = [99999, 99998, 99999, 99998, 99999, 99998, 99999, 99998, 99999, 99997]) == 1\n assert candidate(nums = [7, 5, 7, 2, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 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, 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]) == 48\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 11\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]) == 24\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 0\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 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]) == 17\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]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 0\n", "comparison": "exact"}, "public_tests": ["[3,1,3,2,4,3]", "[1,2,2,2,2]"], "hints": ["Count the frequency of each element in odd positions in the array. Do the same for elements in even positions.", "To minimize the number of operations we need to maximize the number of elements we keep from the original array.", "What are the possible combinations of elements we can choose from odd indices and even indices so that the number of unchanged elements is maximized?"], "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-30T20:43:35+00:00", "tests_total": 135, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function minimumOperations($nums) {", "container": "Solution", "callable": "minimumOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2171, "task_id": "removing-minimum-number-of-magic-beans", "difficulty": "Medium", "problem_description": "You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.\n\nRemove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean has been removed from a bag, you are not allowed to return it to any of the bags.\n\nReturn the minimum number of magic beans that you have to remove.\n\nExample 1:\n\nInput: beans = [4,1,6,5]\nOutput: 4\nExplanation:\n- We remove 1 bean from the bag with only 1 bean.\n This results in the remaining bags: [4,0,6,5]\n- Then we remove 2 beans from the bag with 6 beans.\n This results in the remaining bags: [4,0,4,5]\n- Then we remove 1 bean from the bag with 5 beans.\n This results in the remaining bags: [4,0,4,4]\nWe removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.\nThere are no other solutions that remove 4 beans or fewer.\n\nExample 2:\n\nInput: beans = [2,10,3,2]\nOutput: 7\nExplanation:\n- We remove 2 beans from one of the bags with 2 beans.\n This results in the remaining bags: [0,10,3,2]\n- Then we remove 2 beans from the other bag with 2 beans.\n This results in the remaining bags: [0,10,3,0]\n- Then we remove 3 beans from the bag with 3 beans.\n This results in the remaining bags: [0,10,0,0]\nWe removed a total of 2 + 2 + 3 = 7 beans to make the remaining non-empty bags have an equal number of beans.\nThere are no other solutions that removes 7 beans or fewer.\n\nConstraints:\n\n- 1 <= beans.length <= 10^5\n- 1 <= beans[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(beans = [4, 1, 6, 5]) == 4\n assert candidate(beans = [5, 5, 5, 5]) == 0\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 100000]) == 45\n assert candidate(beans = [10, 10, 10, 10]) == 0\n assert candidate(beans = [5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 18\n assert candidate(beans = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 9\n assert candidate(beans = [1, 2, 3, 4, 5]) == 6\n assert candidate(beans = [100000, 99999, 99998, 99997, 99996]) == 10\n assert candidate(beans = [100000, 1, 100000, 1, 100000]) == 2\n assert candidate(beans = [1]) == 0\n assert candidate(beans = [100000]) == 0\n assert candidate(beans = [5, 5, 5, 5, 5]) == 0\n assert candidate(beans = [1, 1, 1, 1, 1]) == 0\n assert candidate(beans = [99999, 99999, 99999, 99999, 99999]) == 0\n assert candidate(beans = [2, 10, 3, 2]) == 7\n assert candidate(beans = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 25\n assert candidate(beans = [5, 4, 3, 2, 1]) == 6\n assert candidate(beans = [100000, 1, 100000, 1, 100000]) == 2\n assert candidate(beans = [100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(beans = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 19\n assert candidate(beans = [1, 100000, 1, 100000]) == 2\n assert candidate(beans = [10, 1, 10, 1, 10]) == 2\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100000]) == 19\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100000]) == 9\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100]) == 55\n assert candidate(beans = [9, 7, 3, 8, 6, 4]) == 13\n assert candidate(beans = [100, 50, 150, 200, 250, 300]) == 450\n assert candidate(beans = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 0\n assert candidate(beans = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996]) == 25\n assert candidate(beans = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 55\n assert candidate(beans = [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, 1]) == 313\n assert candidate(beans = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 2500\n assert candidate(beans = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 1]) == 1\n assert candidate(beans = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195]) == 99803\n assert candidate(beans = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 50\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 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]) == 625\n assert candidate(beans = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 3, 1]) == 259\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 100\n assert candidate(beans = [1, 99999, 2, 99998, 3, 99997, 4, 99996]) == 16\n assert candidate(beans = [50, 50, 50, 50, 50, 1, 1, 1, 1, 1]) == 5\n assert candidate(beans = [50000, 50000, 50000, 50000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 16\n assert candidate(beans = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(beans = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 190\n assert candidate(beans = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 18\n assert candidate(beans = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 12\n assert candidate(beans = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 190\n assert candidate(beans = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 0\n assert candidate(beans = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 78\n assert candidate(beans = [10, 20, 30, 40, 50]) == 60\n assert candidate(beans = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40, 50, 50, 50]) == 180\n assert candidate(beans = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 45\n assert candidate(beans = [210, 190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1]) == 805\n assert candidate(beans = [5, 7, 8, 9, 9, 10, 10, 10, 10, 10]) == 24\n assert candidate(beans = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 560\n assert candidate(beans = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 120\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 25\n assert candidate(beans = [50000, 50000, 50000, 50000, 50000, 1, 2, 3, 4, 5]) == 15\n assert candidate(beans = [100, 100, 200, 200, 300, 300, 400, 400, 500, 500]) == 1200\n assert candidate(beans = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 120\n assert candidate(beans = [1, 2, 3, 4, 5, 6, 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(beans = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(beans = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 10\n assert candidate(beans = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60]) == 130\n assert candidate(beans = [99999, 100000, 99998, 100000, 99997, 100000]) == 12\n assert candidate(beans = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 50\n assert candidate(beans = [2, 4, 6, 8, 10, 8, 6, 4, 2]) == 20\n assert candidate(beans = [1, 10, 100, 1000, 10000, 100000, 100000, 10000, 1000, 100]) == 22211\n assert candidate(beans = [20000, 20000, 20000, 20000, 20000, 10000, 10000, 10000, 10000, 10000, 10000]) == 50000\n assert candidate(beans = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 805\n assert candidate(beans = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(beans = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(beans = [1, 10, 100, 1000, 10000, 100000, 1, 10, 100, 1000, 10000, 100000, 1, 10, 100, 1000, 10000, 100000, 1, 10]) == 33344\n assert candidate(beans = [99999, 99999, 99999, 99999, 99999, 1, 2, 3, 4, 5]) == 15\n assert candidate(beans = [99999, 99998, 99997, 99996, 99995]) == 10\n assert candidate(beans = [33, 33, 33, 33, 33, 1, 2, 3, 4, 5]) == 15\n assert candidate(beans = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 45\n assert candidate(beans = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 500\n assert candidate(beans = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 250000\n assert candidate(beans = [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]) == 0\n assert candidate(beans = [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]) == 2915\n assert candidate(beans = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 250\n assert candidate(beans = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 50\n assert candidate(beans = [5, 1, 1, 1, 5, 5, 5, 1, 5, 1, 1, 5]) == 6\n assert candidate(beans = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 9\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(beans = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 100\n assert candidate(beans = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 120\n assert candidate(beans = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 5600\n assert candidate(beans = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 12\n assert candidate(beans = [7, 5, 9, 3, 6, 2, 8, 1, 4, 10]) == 25\n assert candidate(beans = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 2500\n assert candidate(beans = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(beans = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == 150\n assert candidate(beans = [50000, 50000, 50000, 50000, 50000, 1, 1, 1]) == 3\n assert candidate(beans = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 25000\n assert candidate(beans = [3, 6, 1, 9, 4, 2, 8, 7, 5]) == 20\n assert candidate(beans = [50, 40, 30, 20, 10, 50, 40, 30, 20, 10, 50, 40, 30, 20, 10, 50, 40, 30, 20, 10]) == 240\n assert candidate(beans = [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]) == 312\n assert candidate(beans = [1, 100, 1000, 10000, 100000]) == 11101\n assert candidate(beans = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 1]) == 1\n assert candidate(beans = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 25\n assert candidate(beans = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 24\n assert candidate(beans = [10, 10, 20, 20, 30, 30, 40, 40]) == 80\n assert candidate(beans = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 31\n", "comparison": "exact"}, "public_tests": ["[4,1,6,5]", "[2,10,3,2]"], "hints": ["Notice that if we choose to make x bags of beans empty, we should choose the x bags with the least amount of beans.", "Notice that if the minimum number of beans in a non-empty bag is m, then the best way to make all bags have an equal amount of beans is to reduce all the bags to have m beans.", "Can we iterate over how many bags we should remove and choose the one that minimizes the total amount of beans to remove?", "Sort the bags of beans first."], "metadata": {"canonical_parameter_names": ["beans"], "leetcode_dataset_entry_point": "Solution().minimumRemoval", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:38+00:00", "tests_total": 107, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "greedy", "sorting", "enumeration", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minimumRemoval($beans) {", "container": "Solution", "callable": "minimumRemoval", "parameters": [{"name": "beans", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2172, "task_id": "maximum-and-sum-of-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.\n\nYou have to place all n integers into the slots such that each slot contains at most two numbers. The AND sum of a given placement is the sum of the bitwise AND of every number with its respective slot number.\n\n- For example, the AND sum of placing the numbers [1, 3] into slot 1 and [4, 6] into slot 2 is equal to (1 AND 1) + (3 AND 1) + (4 AND 2) + (6 AND 2) = 1 + 1 + 0 + 2 = 4.\n\nReturn the maximum possible AND sum of nums given numSlots slots.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5,6], numSlots = 3\nOutput: 9\nExplanation: One possible placement is [1, 4] into slot 1, [2, 6] into slot 2, and [3, 5] into slot 3.\nThis gives the maximum AND sum of (1 AND 1) + (4 AND 1) + (2 AND 2) + (6 AND 2) + (3 AND 3) + (5 AND 3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.\n\nExample 2:\n\nInput: nums = [1,3,10,4,7,1], numSlots = 9\nOutput: 24\nExplanation: One possible placement is [1, 1] into slot 1, [3] into slot 3, [4] into slot 4, [7] into slot 7, and [10] into slot 9.\nThis gives the maximum AND sum of (1 AND 1) + (1 AND 1) + (3 AND 3) + (4 AND 4) + (7 AND 7) + (10 AND 9) = 1 + 1 + 3 + 4 + 7 + 8 = 24.\nNote that slots 2, 5, 6, and 8 are empty which is permitted.\n\nConstraints:\n\n- n == nums.length\n- 1 <= numSlots <= 9\n- 1 <= n <= 2 * numSlots\n- 1 <= nums[i] <= 15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1],numSlots = 2) == 2\n assert candidate(nums = [1, 2, 3],numSlots = 2) == 5\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15],numSlots = 8) == 52\n assert candidate(nums = [15, 15, 15],numSlots = 2) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6],numSlots = 3) == 9\n assert candidate(nums = [7, 11, 4, 1, 3, 10, 4, 9],numSlots = 5) == 23\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],numSlots = 8) == 8\n assert candidate(nums = [1, 2],numSlots = 1) == 1\n assert candidate(nums = [4, 10, 7, 6, 9, 8, 3, 9, 8, 1, 2, 6, 8, 7, 8],numSlots = 9) == 72\n assert candidate(nums = [1, 1, 1, 1, 1, 1],numSlots = 3) == 4\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],numSlots = 6) == 42\n assert candidate(nums = [1, 3, 10, 4, 7, 1],numSlots = 9) == 24\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],numSlots = 8) == 8\n assert candidate(nums = [7, 11, 4, 1],numSlots = 3) == 7\n assert candidate(nums = [1, 2, 3],numSlots = 3) == 6\n assert candidate(nums = [1],numSlots = 1) == 1\n assert candidate(nums = [15, 10, 5, 1, 14, 9, 4, 2, 13, 8, 3, 6, 12, 7, 11],numSlots = 8) == 71\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],numSlots = 9) == 84\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15],numSlots = 9) == 84\n assert candidate(nums = [15, 10, 5, 3, 8, 2, 7, 1, 14, 12, 9, 13, 4, 6, 11],numSlots = 8) == 71\n assert candidate(nums = [15, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 15, 1, 2],numSlots = 9) == 90\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],numSlots = 9) == 84\n assert candidate(nums = [8, 5, 6, 7, 1, 2, 3, 4, 9, 10, 11, 12, 13, 14, 15],numSlots = 8) == 71\n assert candidate(nums = [11, 5, 7, 3, 14, 10, 9, 8],numSlots = 4) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1],numSlots = 9) == 85\n assert candidate(nums = [12, 6, 7, 10, 5, 11, 4, 8, 15, 14, 2, 13, 3, 9, 1],numSlots = 8) == 71\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],numSlots = 9) == 86\n assert candidate(nums = [5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6],numSlots = 9) == 84\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],numSlots = 9) == 84\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],numSlots = 8) == 71\n assert candidate(nums = [14, 3, 5, 7, 10, 2, 8, 13],numSlots = 4) == 19\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8],numSlots = 5) == 29\n assert candidate(nums = [7, 5, 2, 9, 1, 12, 3, 8, 6, 11, 14, 15],numSlots = 6) == 40\n assert candidate(nums = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],numSlots = 7) == 49\n assert candidate(nums = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],numSlots = 8) == 64\n assert candidate(nums = [14, 7, 9, 12, 11, 8, 5, 10, 3, 2, 15, 6, 1, 4, 13],numSlots = 8) == 71\n assert candidate(nums = [13, 9, 7, 5, 3, 1],numSlots = 4) == 16\n assert candidate(nums = [15, 13, 11, 9, 7, 5, 3, 1],numSlots = 4) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],numSlots = 9) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],numSlots = 8) == 71\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9],numSlots = 8) == 71\n assert candidate(nums = [14, 14, 14, 14, 14, 14, 14, 14, 14, 14],numSlots = 5) == 24\n assert candidate(nums = [8, 6, 4, 2, 10, 14, 12, 1],numSlots = 5) == 21\n assert candidate(nums = [15, 8, 7, 1, 2, 3, 14, 9, 10, 11, 12, 13, 4, 5, 6],numSlots = 8) == 71\n assert candidate(nums = [3, 5, 15, 7, 9, 11, 13, 14, 12, 10],numSlots = 6) == 39\n assert candidate(nums = [10, 14, 7, 11, 8, 12, 13, 9, 6, 4, 5, 2, 3, 15, 1],numSlots = 8) == 71\n assert candidate(nums = [8, 9, 10, 11, 12, 13, 14],numSlots = 7) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],numSlots = 9) == 90\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],numSlots = 8) == 40\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 2, 4, 6, 8, 10, 12, 14],numSlots = 8) == 71\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],numSlots = 6) == 39\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15],numSlots = 8) == 72\n assert candidate(nums = [1, 13, 5, 9, 11, 15, 3, 7, 14, 12, 2, 6, 10, 4, 8],numSlots = 8) == 71\n assert candidate(nums = [14, 7, 13, 5, 11, 6, 2, 9],numSlots = 4) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],numSlots = 8) == 72\n assert candidate(nums = [9, 6, 11, 12, 14, 15, 7, 8, 10],numSlots = 5) == 26\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 8, 7, 15, 14, 13, 12, 11, 10, 9],numSlots = 9) == 84\n assert candidate(nums = [7, 13, 11, 1, 15, 5, 9, 3, 14, 12, 8, 10, 6, 2, 4],numSlots = 8) == 71\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1],numSlots = 4) == 19\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],numSlots = 8) == 40\n assert candidate(nums = [14, 12, 10, 8, 6, 4, 2, 15, 13, 11, 9, 7, 5, 3, 1],numSlots = 8) == 71\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 15, 14, 13, 12, 11, 10, 9],numSlots = 8) == 71\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],numSlots = 9) == 84\n assert candidate(nums = [15, 1, 7, 15, 9, 7, 3, 10, 2, 14, 11, 13, 5, 4, 6, 8],numSlots = 9) == 87\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15],numSlots = 9) == 86\n assert candidate(nums = [15, 9, 6, 11, 13, 7, 12, 1, 5, 3, 2, 4, 8, 14, 10],numSlots = 8) == 71\n assert candidate(nums = [10, 15, 9, 4, 14, 8, 13, 7, 12, 2, 3, 11, 6, 5, 1],numSlots = 8) == 71\n assert candidate(nums = [5, 14, 12, 3, 7, 9, 1, 13, 11, 8, 6, 4, 2, 15, 10],numSlots = 8) == 71\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6]\n3", "[1,3,10,4,7,1]\n9"], "hints": ["Can you think of a dynamic programming solution to this problem?", "Can you use a bitmask to represent the state of the slots?"], "metadata": {"canonical_parameter_names": ["nums", "numSlots"], "leetcode_dataset_entry_point": "Solution().maximumANDSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:40+00:00", "tests_total": 89, "tests_dropped": 21, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function maximumANDSum($nums, $numSlots) {", "container": "Solution", "callable": "maximumANDSum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "numSlots", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2176, "task_id": "count-equal-and-divisible-pairs-in-an-array", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.\n\nExample 1:\n\nInput: nums = [3,1,2,2,2,1,3], k = 2\nOutput: 4\nExplanation:\nThere are 4 pairs that meet all the requirements:\n- nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2.\n- nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2.\n- nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2.\n- nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4], k = 1\nOutput: 0\nExplanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i], k <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 0\n assert candidate(nums = [6, 6, 6, 6],k = 2) == 5\n assert candidate(nums = [3, 1, 2, 2, 2, 1, 3],k = 2) == 4\n assert candidate(nums = [9, 9, 9],k = 9) == 2\n assert candidate(nums = [10, 20, 10, 20, 10],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 30\n assert candidate(nums = [10, 20, 10, 20, 10],k = 5) == 2\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 6\n assert candidate(nums = [7, 11, 7, 11, 7, 11],k = 3) == 4\n assert candidate(nums = [1, 3, 1, 3, 1, 3],k = 3) == 4\n assert candidate(nums = [7, 3, 8, 7, 3, 8, 7],k = 7) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7],k = 1) == 28\n assert candidate(nums = [2, 4, 6, 8, 10],k = 2) == 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) == 70\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 0\n assert candidate(nums = [100, 100, 100],k = 3) == 2\n assert candidate(nums = [1, 2, 3, 4],k = 1) == 0\n assert candidate(nums = [5, 5, 5, 5],k = 2) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 45\n assert candidate(nums = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99],k = 99) == 21\n assert candidate(nums = [2, 3, 4, 2, 5, 3, 2, 2, 4, 2],k = 4) == 5\n assert candidate(nums = [25, 10, 10, 25, 10, 10, 25, 25, 25, 10, 10, 25],k = 10) == 12\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],k = 25) == 63\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, 8, 9, 8, 9, 8, 9, 8],k = 2) == 120\n assert candidate(nums = [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],k = 100) == 129\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 = 1) == 465\n assert candidate(nums = [15, 15, 10, 15, 10, 15, 10, 15, 10],k = 15) == 5\n assert candidate(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9, 1],k = 3) == 14\n assert candidate(nums = [21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21],k = 7) == 140\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 2) == 15\n assert candidate(nums = [3, 5, 3, 3, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5],k = 15) == 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],k = 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],k = 4) == 95\n assert candidate(nums = [15, 25, 15, 25, 15, 25, 15, 25],k = 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],k = 1) == 190\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 1) == 0\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 = 10) == 120\n assert candidate(nums = [60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60],k = 15) == 418\n assert candidate(nums = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15],k = 4) == 56\n assert candidate(nums = [5, 5, 5, 5, 10, 10, 10, 10],k = 5) == 6\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],k = 2) == 330\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) == 20\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],k = 25) == 210\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10],k = 5) == 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],k = 1) == 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],k = 3) == 7\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],k = 20) == 392\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 = 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 = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 25) == 69\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) == 145\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 = 2) == 145\n assert candidate(nums = [11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11],k = 4) == 95\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20],k = 5) == 3\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50],k = 10) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 17\n assert candidate(nums = [21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21],k = 7) == 21\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],k = 8) == 152\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 2, 4, 6, 8, 10],k = 10) == 1\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],k = 4) == 25\n assert candidate(nums = [10, 20, 10, 30, 10, 20, 10],k = 5) == 4\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 30\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],k = 10) == 563\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],k = 6) == 215\n assert candidate(nums = [15, 15, 20, 20, 25, 25, 30, 30, 35, 35, 40, 40, 45, 45, 50, 50, 55, 55, 60, 60],k = 10) == 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],k = 50) == 164\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 6) == 8\n assert candidate(nums = [5, 15, 25, 5, 25, 15, 5, 15, 25, 5],k = 10) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],k = 3) == 15\n assert candidate(nums = [15, 15, 25, 25, 15, 25, 15, 25, 15, 25],k = 5) == 8\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 3) == 30\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) == 65\n assert candidate(nums = [6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3],k = 9) == 28\n assert candidate(nums = [2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4],k = 2) == 210\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 = 14) == 45\n assert candidate(nums = [11, 11, 22, 22, 33, 33, 44, 44, 55, 55, 66, 66, 77, 77, 88, 88, 99, 99, 100, 100],k = 11) == 2\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70],k = 10) == 0\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10],k = 10) == 3\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 18) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5) == 17\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) == 70\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 18\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 = 7) == 140\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 9) == 28\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 11, 22, 33, 44, 55, 66, 77, 88, 99],k = 11) == 2\n", "comparison": "exact"}, "public_tests": ["[3,1,2,2,2,1,3]\n2", "[1,2,3,4]\n1"], "hints": ["For every possible pair of indices (i, j) where i < j, check if it satisfies the given conditions."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:45+00:00", "tests_total": 89, "tests_dropped": 2, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function countPairs($nums, $k) {", "container": "Solution", "callable": "countPairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2177, "task_id": "find-three-consecutive-integers-that-sum-to-a-given-number", "difficulty": "Medium", "problem_description": "Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.\n\nExample 1:\n\nInput: num = 33\nOutput: [10,11,12]\nExplanation: 33 can be expressed as 10 + 11 + 12 = 33.\n10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].\n\nExample 2:\n\nInput: num = 4\nOutput: []\nExplanation: There is no way to express 4 as the sum of 3 consecutive integers.\n\nConstraints:\n\n- 0 <= num <= 10^15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 9) == [2, 3, 4]\n assert candidate(num = 1000000000001) == []\n assert candidate(num = 0) == [-1, 0, 1]\n assert candidate(num = 4) == []\n assert candidate(num = 33) == [10, 11, 12]\n assert candidate(num = 1000000000000) == []\n assert candidate(num = 3) == [0, 1, 2]\n assert candidate(num = 15) == [4, 5, 6]\n assert candidate(num = 100000000000000) == []\n assert candidate(num = 300000000000003) == [100000000000000, 100000000000001, 100000000000002]\n assert candidate(num = 3000000000) == [999999999, 1000000000, 1000000001]\n assert candidate(num = 3000000000000) == [999999999999, 1000000000000, 1000000000001]\n assert candidate(num = 999) == [332, 333, 334]\n assert candidate(num = 1000000000003) == []\n assert candidate(num = 27) == [8, 9, 10]\n assert candidate(num = 45) == [14, 15, 16]\n assert candidate(num = 999999999999) == [333333333332, 333333333333, 333333333334]\n assert candidate(num = 300000000000000) == [99999999999999, 100000000000000, 100000000000001]\n assert candidate(num = 99) == [32, 33, 34]\n assert candidate(num = 1234567890125) == []\n assert candidate(num = 3000000000001) == []\n assert candidate(num = 123456789) == [41152262, 41152263, 41152264]\n assert candidate(num = 777777777777777) == [259259259259258, 259259259259259, 259259259259260]\n assert candidate(num = 2999999999997) == [999999999998, 999999999999, 1000000000000]\n assert candidate(num = 299999999999997) == [99999999999998, 99999999999999, 100000000000000]\n assert candidate(num = 105) == [34, 35, 36]\n assert candidate(num = 999999999999999) == [333333333333332, 333333333333333, 333333333333334]\n assert candidate(num = 1000) == []\n assert candidate(num = 81) == [26, 27, 28]\n assert candidate(num = 1000000000002) == [333333333333, 333333333334, 333333333335]\n assert candidate(num = 987654321) == [329218106, 329218107, 329218108]\n assert candidate(num = 7500000000000) == [2499999999999, 2500000000000, 2500000000001]\n assert candidate(num = 1001) == []\n assert candidate(num = 21) == [6, 7, 8]\n assert candidate(num = 123456789012345) == [41152263004114, 41152263004115, 41152263004116]\n assert candidate(num = 6) == [1, 2, 3]\n assert candidate(num = 299792458) == []\n assert candidate(num = 2) == []\n assert candidate(num = 1) == []\n assert candidate(num = 100) == []\n assert candidate(num = 1500000000000) == [499999999999, 500000000000, 500000000001]\n assert candidate(num = 999999999) == [333333332, 333333333, 333333334]\n assert candidate(num = 500000000000001) == [166666666666666, 166666666666667, 166666666666668]\n assert candidate(num = 1000000) == []\n assert candidate(num = 1234567890123) == [411522630040, 411522630041, 411522630042]\n assert candidate(num = 1234567890124) == []\n assert candidate(num = 1000000000000000) == []\n assert candidate(num = 180) == [59, 60, 61]\n assert candidate(num = 101) == []\n assert candidate(num = 8999999999997) == [2999999999998, 2999999999999, 3000000000000]\n", "comparison": "exact"}, "public_tests": ["33", "4"], "hints": ["Notice that if a solution exists, we can represent them as x-1, x, x+1. What does this tell us about the number?", "Notice the sum of the numbers will be 3x. Can you solve for x?"], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().sumOfThree", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:47+00:00", "tests_total": 52, "tests_dropped": 2, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function sumOfThree($num) {", "container": "Solution", "callable": "sumOfThree", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2178, "task_id": "maximum-split-of-positive-even-integers", "difficulty": "Medium", "problem_description": "You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.\n\n- For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum number of integers. Note that finalSum cannot be split into (2 + 2 + 4 + 4) as all the numbers should be unique.\n\nReturn a list of integers that represent a valid split containing a maximum number of integers. If no valid split exists for finalSum, return an empty list. You may return the integers in any order.\n\nExample 1:\n\nInput: finalSum = 12\nOutput: [2,4,6]\nExplanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).\n(2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].\nNote that [2,6,4], [6,2,4], etc. are also accepted.\n\nExample 2:\n\nInput: finalSum = 7\nOutput: []\nExplanation: There are no valid splits for the given finalSum.\nThus, we return an empty array.\n\nExample 3:\n\nInput: finalSum = 28\nOutput: [6,8,2,12]\nExplanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24).\n(6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].\nNote that [10,2,4,12], [6,2,4,16], etc. are also accepted.\n\nConstraints:\n\n- 1 <= finalSum <= 10^10\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(finalSum=10), [2, 8])\n assert answers_match(candidate(finalSum=7), [])\n assert answers_match(candidate(finalSum=28), [2, 4, 6, 16])\n assert answers_match(candidate(finalSum=2), [2])\n assert answers_match(candidate(finalSum=12), [2, 4, 6])\n assert answers_match(candidate(finalSum=100), [2, 4, 6, 8, 10, 12, 14, 16, 28])\n assert answers_match(candidate(finalSum=198), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 42])\n assert answers_match(candidate(finalSum=300), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 60])\n assert answers_match(candidate(finalSum=2048), [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, 156])\n assert answers_match(candidate(finalSum=4), [4])\n assert answers_match(candidate(finalSum=512), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 50])\n assert answers_match(candidate(finalSum=60), [2, 4, 6, 8, 10, 12, 18])\n assert answers_match(candidate(finalSum=50), [2, 4, 6, 8, 10, 20])\n assert answers_match(candidate(finalSum=101), [])\n assert answers_match(candidate(finalSum=200), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 44])\n assert answers_match(candidate(finalSum=32), [2, 4, 6, 8, 12])\n assert answers_match(candidate(finalSum=123456789), [])\n assert answers_match(candidate(finalSum=8192), [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, 182])\n assert answers_match(candidate(finalSum=254), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 44])\n assert answers_match(candidate(finalSum=256), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 46])\n assert answers_match(candidate(finalSum=9999999999), [])\n assert answers_match(candidate(finalSum=450), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 70])\n assert answers_match(candidate(finalSum=8), [2, 6])\n assert answers_match(candidate(finalSum=30), [2, 4, 6, 8, 10])\n assert answers_match(candidate(finalSum=1998), [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, 106])\n assert answers_match(candidate(finalSum=3), [])\n assert answers_match(candidate(finalSum=128), [2, 4, 6, 8, 10, 12, 14, 16, 18, 38])\n assert answers_match(candidate(finalSum=5050), [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, 220])\n assert answers_match(candidate(finalSum=100000), [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 1090])\n assert answers_match(candidate(finalSum=1000000), [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, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 888, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998, 1000, 1002, 1004, 1006, 1008, 1010, 1012, 1014, 1016, 1018, 1020, 1022, 1024, 1026, 1028, 1030, 1032, 1034, 1036, 1038, 1040, 1042, 1044, 1046, 1048, 1050, 1052, 1054, 1056, 1058, 1060, 1062, 1064, 1066, 1068, 1070, 1072, 1074, 1076, 1078, 1080, 1082, 1084, 1086, 1088, 1090, 1092, 1094, 1096, 1098, 1100, 1102, 1104, 1106, 1108, 1110, 1112, 1114, 1116, 1118, 1120, 1122, 1124, 1126, 1128, 1130, 1132, 1134, 1136, 1138, 1140, 1142, 1144, 1146, 1148, 1150, 1152, 1154, 1156, 1158, 1160, 1162, 1164, 1166, 1168, 1170, 1172, 1174, 1176, 1178, 1180, 1182, 1184, 1186, 1188, 1190, 1192, 1194, 1196, 1198, 1200, 1202, 1204, 1206, 1208, 1210, 1212, 1214, 1216, 1218, 1220, 1222, 1224, 1226, 1228, 1230, 1232, 1234, 1236, 1238, 1240, 1242, 1244, 1246, 1248, 1250, 1252, 1254, 1256, 1258, 1260, 1262, 1264, 1266, 1268, 1270, 1272, 1274, 1276, 1278, 1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298, 1300, 1302, 1304, 1306, 1308, 1310, 1312, 1314, 1316, 1318, 1320, 1322, 1324, 1326, 1328, 1330, 1332, 1334, 1336, 1338, 1340, 1342, 1344, 1346, 1348, 1350, 1352, 1354, 1356, 1358, 1360, 1362, 1364, 1366, 1368, 1370, 1372, 1374, 1376, 1378, 1380, 1382, 1384, 1386, 1388, 1390, 1392, 1394, 1396, 1398, 1400, 1402, 1404, 1406, 1408, 1410, 1412, 1414, 1416, 1418, 1420, 1422, 1424, 1426, 1428, 1430, 1432, 1434, 1436, 1438, 1440, 1442, 1444, 1446, 1448, 1450, 1452, 1454, 1456, 1458, 1460, 1462, 1464, 1466, 1468, 1470, 1472, 1474, 1476, 1478, 1480, 1482, 1484, 1486, 1488, 1490, 1492, 1494, 1496, 1498, 1500, 1502, 1504, 1506, 1508, 1510, 1512, 1514, 1516, 1518, 1520, 1522, 1524, 1526, 1528, 1530, 1532, 1534, 1536, 1538, 1540, 1542, 1544, 1546, 1548, 1550, 1552, 1554, 1556, 1558, 1560, 1562, 1564, 1566, 1568, 1570, 1572, 1574, 1576, 1578, 1580, 1582, 1584, 1586, 1588, 1590, 1592, 1594, 1596, 1598, 1600, 1602, 1604, 1606, 1608, 1610, 1612, 1614, 1616, 1618, 1620, 1622, 1624, 1626, 1628, 1630, 1632, 1634, 1636, 1638, 1640, 1642, 1644, 1646, 1648, 1650, 1652, 1654, 1656, 1658, 1660, 1662, 1664, 1666, 1668, 1670, 1672, 1674, 1676, 1678, 1680, 1682, 1684, 1686, 1688, 1690, 1692, 1694, 1696, 1698, 1700, 1702, 1704, 1706, 1708, 1710, 1712, 1714, 1716, 1718, 1720, 1722, 1724, 1726, 1728, 1730, 1732, 1734, 1736, 1738, 1740, 1742, 1744, 1746, 1748, 1750, 1752, 1754, 1756, 1758, 1760, 1762, 1764, 1766, 1768, 1770, 1772, 1774, 1776, 1778, 1780, 1782, 1784, 1786, 1788, 1790, 1792, 1794, 1796, 1798, 1800, 1802, 1804, 1806, 1808, 1810, 1812, 1814, 1816, 1818, 1820, 1822, 1824, 1826, 1828, 1830, 1832, 1834, 1836, 1838, 1840, 1842, 1844, 1846, 1848, 1850, 1852, 1854, 1856, 1858, 1860, 1862, 1864, 1866, 1868, 1870, 1872, 1874, 1876, 1878, 1880, 1882, 1884, 1886, 1888, 1890, 1892, 1894, 1896, 1898, 1900, 1902, 1904, 1906, 1908, 1910, 1912, 1914, 1916, 1918, 1920, 1922, 1924, 1926, 1928, 1930, 1932, 1934, 1936, 1938, 1940, 1942, 1944, 1946, 1948, 1950, 1952, 1954, 1956, 1958, 1960, 1962, 1964, 1966, 1968, 1970, 1972, 1974, 1976, 1978, 1980, 1982, 1984, 1986, 1988, 1990, 1992, 1994, 1996, 2998])\n assert answers_match(candidate(finalSum=1024), [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, 94])\n assert answers_match(candidate(finalSum=64), [2, 4, 6, 8, 10, 12, 22])\n assert answers_match(candidate(finalSum=26), [2, 4, 6, 14])\n assert answers_match(candidate(finalSum=498), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 78])\n assert answers_match(candidate(finalSum=18), [2, 4, 12])\n assert answers_match(candidate(finalSum=1111111111), [])\n assert answers_match(candidate(finalSum=500), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 80])\n assert answers_match(candidate(finalSum=16), [2, 4, 10])\n assert answers_match(candidate(finalSum=2000), [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, 108])\n assert answers_match(candidate(finalSum=20), [2, 4, 6, 8])\n assert answers_match(candidate(finalSum=1000), [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, 70])\n assert answers_match(candidate(finalSum=1999), [])\n assert answers_match(candidate(finalSum=150), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40])\n assert answers_match(candidate(finalSum=88), [2, 4, 6, 8, 10, 12, 14, 32])\n assert answers_match(candidate(finalSum=1), [])\n assert answers_match(candidate(finalSum=1000000001), [])\n assert answers_match(candidate(finalSum=10000), [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, 298])\n assert answers_match(candidate(finalSum=42), [2, 4, 6, 8, 10, 12])\n assert answers_match(candidate(finalSum=37), [])\n assert answers_match(candidate(finalSum=33), [])\n", "comparison": "unordered"}, "public_tests": ["12", "7", "28"], "hints": ["First, check if finalSum is divisible by 2. If it isn’t, then we cannot split it into even integers.", "Let k be the number of elements in our split. As we want the maximum number of elements, we should try to use the first k - 1 even elements to grow our sum as slowly as possible.", "Thus, we find the maximum sum of the first k - 1 even elements which is less than finalSum.", "We then add the difference over to the kth element."], "metadata": {"canonical_parameter_names": ["finalSum"], "leetcode_dataset_entry_point": "Solution().maximumEvenSplit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:49+00:00", "tests_total": 50, "tests_dropped": 0, "flags": ["any_order"], "topic_tags": ["math", "backtracking", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumEvenSplit($finalSum) {", "container": "Solution", "callable": "maximumEvenSplit", "parameters": [{"name": "finalSum", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2179, "task_id": "count-good-triplets-in-an-array", "difficulty": "Hard", "problem_description": "You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].\n\nA good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1_v as the index of the value v in nums1 and pos2_v as the index of the value v in nums2, then a good triplet will be a set (x, y, z) where 0 <= x, y, z <= n - 1, such that pos1_x < pos1_y < pos1_z and pos2_x < pos2_y < pos2_z.\n\nReturn the total number of good triplets.\n\nExample 1:\n\nInput: nums1 = [2,0,1,3], nums2 = [0,1,2,3]\nOutput: 1\nExplanation:\nThere are 4 triplets (x,y,z) such that pos1_x < pos1_y < pos1_z. They are (2,0,1), (2,0,3), (2,1,3), and (0,1,3).\nOut of those triplets, only the triplet (0,1,3) satisfies pos2_x < pos2_y < pos2_z. Hence, there is only 1 good triplet.\n\nExample 2:\n\nInput: nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3]\nOutput: 4\nExplanation: The 4 good triplets are (4,0,3), (4,0,2), (4,1,3), and (4,1,2).\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 3 <= n <= 10^5\n- 0 <= nums1[i], nums2[i] <= n - 1\n- nums1 and nums2 are permutations of [0, 1, ..., n - 1].\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [0, 1, 2, 3],nums2 = [3, 2, 1, 0]) == 0\n assert candidate(nums1 = [1, 0, 3, 2],nums2 = [2, 3, 0, 1]) == 0\n assert candidate(nums1 = [2, 0, 1, 3],nums2 = [0, 1, 2, 3]) == 1\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [0, 1, 2, 3, 4, 5]) == 20\n assert candidate(nums1 = [3, 2, 1, 0],nums2 = [3, 2, 1, 0]) == 4\n assert candidate(nums1 = [0, 1, 2, 3, 4],nums2 = [0, 1, 2, 3, 4]) == 10\n assert candidate(nums1 = [3, 2, 1, 0],nums2 = [0, 1, 2, 3]) == 0\n assert candidate(nums1 = [0, 1, 2],nums2 = [2, 1, 0]) == 0\n assert candidate(nums1 = [5, 4, 3, 2, 1, 0],nums2 = [5, 4, 3, 2, 1, 0]) == 20\n assert candidate(nums1 = [4, 0, 1, 3, 2],nums2 = [4, 1, 0, 2, 3]) == 4\n assert candidate(nums1 = [1, 0, 2, 3],nums2 = [3, 2, 1, 0]) == 0\n assert candidate(nums1 = [1, 0, 3, 2, 5, 4],nums2 = [0, 5, 2, 4, 3, 1]) == 2\n assert candidate(nums1 = [5, 3, 4, 0, 2, 1],nums2 = [1, 2, 0, 5, 4, 3]) == 0\n assert candidate(nums1 = [5, 1, 4, 2, 3, 0, 6],nums2 = [0, 1, 2, 3, 4, 5, 6]) == 5\n assert candidate(nums1 = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 84\n assert candidate(nums1 = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],nums2 = [9, 1, 3, 5, 7, 0, 2, 4, 6, 8]) == 68\n assert candidate(nums1 = [7, 3, 5, 0, 2, 6, 4, 1],nums2 = [1, 0, 4, 6, 2, 7, 5, 3]) == 0\n assert candidate(nums1 = [5, 2, 6, 0, 3, 1, 4],nums2 = [0, 1, 2, 3, 4, 5, 6]) == 3\n assert candidate(nums1 = [10, 7, 2, 9, 3, 5, 1, 6, 8, 0, 4],nums2 = [4, 0, 5, 8, 10, 6, 9, 2, 1, 7, 3]) == 5\n assert candidate(nums1 = [6, 3, 2, 1, 5, 0, 4],nums2 = [3, 2, 5, 6, 4, 0, 1]) == 8\n assert candidate(nums1 = [2, 4, 6, 1, 3, 5, 0],nums2 = [6, 5, 0, 1, 2, 3, 4]) == 2\n assert candidate(nums1 = [1, 4, 5, 6, 7, 8, 9, 0, 2, 3],nums2 = [5, 6, 7, 8, 9, 0, 1, 4, 2, 3]) == 60\n assert candidate(nums1 = [2, 8, 0, 1, 5, 9, 6, 7, 4, 3],nums2 = [7, 6, 3, 5, 8, 0, 9, 1, 2, 4]) == 8\n assert candidate(nums1 = [2, 1, 3, 0, 5, 4],nums2 = [0, 4, 5, 1, 3, 2]) == 0\n assert candidate(nums1 = [1, 3, 2, 5, 4, 0, 6, 7],nums2 = [0, 1, 2, 3, 4, 5, 6, 7]) == 26\n assert candidate(nums1 = [1, 2, 0, 3, 4, 5],nums2 = [0, 1, 5, 3, 2, 4]) == 3\n assert candidate(nums1 = [2, 1, 3, 0, 5, 4],nums2 = [5, 4, 2, 0, 3, 1]) == 0\n assert candidate(nums1 = [3, 0, 1, 4, 2, 5],nums2 = [2, 1, 0, 5, 3, 4]) == 0\n assert candidate(nums1 = [4, 2, 3, 5, 1, 0],nums2 = [1, 5, 4, 2, 0, 3]) == 2\n assert candidate(nums1 = [0, 3, 1, 5, 2, 4],nums2 = [5, 2, 4, 0, 3, 1]) == 2\n assert candidate(nums1 = [7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7]) == 0\n assert candidate(nums1 = [0, 3, 2, 5, 4, 1],nums2 = [2, 3, 1, 0, 5, 4]) == 3\n assert candidate(nums1 = [1, 0, 7, 6, 5, 4, 3, 2],nums2 = [3, 2, 5, 7, 6, 0, 4, 1]) == 1\n assert candidate(nums1 = [2, 4, 1, 3, 5, 0, 6],nums2 = [5, 6, 2, 0, 4, 1, 3]) == 4\n assert candidate(nums1 = [3, 0, 1, 4, 2, 5],nums2 = [5, 2, 4, 3, 1, 0]) == 0\n assert candidate(nums1 = [2, 4, 6, 8, 0, 3, 5, 7, 9, 1],nums2 = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == 68\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [3, 1, 2, 5, 4, 0, 6],nums2 = [6, 0, 5, 2, 1, 4, 3]) == 0\n assert candidate(nums1 = [2, 1, 0, 3, 4, 5, 6, 7, 8],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8]) == 65\n assert candidate(nums1 = [5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [9, 5, 4, 7, 6, 3, 8, 0, 1, 2],nums2 = [0, 2, 1, 9, 3, 5, 4, 8, 7, 6]) == 14\n assert candidate(nums1 = [8, 6, 7, 5, 3, 0, 9, 4, 2, 1],nums2 = [1, 2, 4, 9, 0, 3, 5, 7, 8, 6]) == 0\n assert candidate(nums1 = [6, 2, 0, 4, 5, 1, 3],nums2 = [4, 2, 0, 6, 3, 5, 1]) == 7\n assert candidate(nums1 = [7, 2, 4, 3, 0, 6, 5, 1],nums2 = [4, 0, 7, 1, 3, 6, 2, 5]) == 12\n assert candidate(nums1 = [6, 4, 8, 5, 3, 9, 1, 2, 7, 0],nums2 = [7, 1, 2, 6, 0, 8, 5, 3, 4, 9]) == 12\n assert candidate(nums1 = [6, 3, 0, 4, 2, 5, 1],nums2 = [5, 1, 2, 6, 0, 4, 3]) == 1\n assert candidate(nums1 = [5, 2, 4, 0, 3, 1],nums2 = [3, 1, 0, 5, 4, 2]) == 0\n assert candidate(nums1 = [8, 5, 7, 6, 2, 9, 3, 4, 0, 1],nums2 = [4, 0, 8, 7, 5, 6, 1, 2, 9, 3]) == 36\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]) == 0\n assert candidate(nums1 = [3, 0, 5, 2, 7, 6, 1, 4, 8],nums2 = [7, 5, 8, 4, 0, 3, 6, 1, 2]) == 4\n assert candidate(nums1 = [5, 1, 4, 2, 3, 0, 8, 6, 7, 9],nums2 = [1, 0, 2, 3, 4, 5, 6, 7, 8, 9]) == 46\n assert candidate(nums1 = [5, 3, 4, 0, 2, 1],nums2 = [1, 0, 2, 5, 4, 3]) == 0\n assert candidate(nums1 = [0, 4, 1, 5, 2, 6, 3, 7],nums2 = [7, 3, 6, 2, 5, 1, 4, 0]) == 0\n assert candidate(nums1 = [6, 0, 1, 5, 2, 3, 4],nums2 = [1, 3, 5, 4, 6, 2, 0]) == 3\n assert candidate(nums1 = [0, 2, 1, 4, 3],nums2 = [4, 0, 1, 2, 3]) == 2\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [4, 3, 7, 8, 9, 1, 5, 6, 2, 0],nums2 = [6, 5, 0, 2, 1, 8, 9, 7, 3, 4]) == 0\n assert candidate(nums1 = [7, 5, 6, 3, 4, 1, 2, 0],nums2 = [3, 6, 2, 7, 0, 1, 4, 5]) == 2\n assert candidate(nums1 = [8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8]) == 0\n assert candidate(nums1 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 240\n assert candidate(nums1 = [10, 1, 5, 9, 8, 2, 6, 7, 3, 4, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 13\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7]) == 0\n assert candidate(nums1 = [0, 4, 1, 5, 2, 6, 3],nums2 = [1, 2, 3, 4, 5, 6, 0]) == 4\n assert candidate(nums1 = [3, 0, 2, 4, 5, 1, 6],nums2 = [6, 1, 3, 5, 0, 2, 4]) == 4\n assert candidate(nums1 = [1, 9, 2, 8, 3, 7, 4, 6, 5, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 20\n assert candidate(nums1 = [3, 0, 5, 2, 4, 1],nums2 = [4, 1, 0, 5, 3, 2]) == 1\n assert candidate(nums1 = [0, 2, 5, 3, 1, 4],nums2 = [1, 4, 3, 0, 2, 5]) == 1\n assert candidate(nums1 = [8, 6, 7, 2, 5, 4, 3, 0, 1],nums2 = [1, 0, 2, 5, 4, 3, 8, 7, 6]) == 4\n assert candidate(nums1 = [1, 2, 3, 4, 5, 0],nums2 = [0, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [5, 3, 2, 4, 1, 6, 0],nums2 = [0, 3, 1, 5, 2, 4, 6]) == 8\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums2 = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 84\n assert candidate(nums1 = [7, 3, 0, 4, 6, 1, 5, 2],nums2 = [5, 2, 6, 0, 3, 7, 4, 1]) == 3\n assert candidate(nums1 = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5],nums2 = [5, 4, 6, 3, 7, 2, 8, 1, 9, 0]) == 0\n assert candidate(nums1 = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 84\n assert candidate(nums1 = [5, 0, 2, 1, 3, 4],nums2 = [0, 1, 4, 2, 5, 3]) == 3\n assert candidate(nums1 = [3, 1, 2, 0, 7, 5, 6, 4],nums2 = [7, 5, 6, 4, 3, 1, 2, 0]) == 8\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums2 = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 120\n assert candidate(nums1 = [3, 5, 7, 0, 2, 4, 6, 8, 1, 9],nums2 = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8]) == 19\n assert candidate(nums1 = [2, 5, 3, 1, 0, 4],nums2 = [3, 5, 1, 4, 0, 2]) == 4\n assert candidate(nums1 = [5, 3, 8, 6, 2, 7, 4, 0, 1, 9],nums2 = [9, 1, 0, 2, 4, 6, 3, 8, 7, 5]) == 1\n assert candidate(nums1 = [1, 6, 3, 2, 7, 4, 5, 0],nums2 = [0, 5, 7, 2, 3, 1, 6, 4]) == 1\n assert candidate(nums1 = [4, 7, 1, 8, 3, 0, 9, 2, 5, 6],nums2 = [9, 2, 6, 0, 7, 3, 5, 8, 4, 1]) == 3\n assert candidate(nums1 = [6, 3, 0, 5, 2, 8, 1, 7, 4, 9],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 28\n assert candidate(nums1 = [4, 0, 3, 5, 2, 6, 1, 7],nums2 = [1, 5, 0, 3, 6, 2, 4, 7]) == 9\n assert candidate(nums1 = [2, 1, 4, 3, 6, 5, 8, 7, 0, 9],nums2 = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == 10\n assert candidate(nums1 = [5, 1, 4, 3, 2, 0],nums2 = [0, 2, 1, 5, 4, 3]) == 2\n assert candidate(nums1 = [9, 7, 1, 5, 6, 8, 0, 2, 3, 4],nums2 = [7, 4, 1, 5, 6, 0, 8, 2, 9, 3]) == 50\n assert candidate(nums1 = [0, 1, 5, 4, 3, 2, 6],nums2 = [6, 0, 5, 3, 2, 1, 4]) == 6\n assert candidate(nums1 = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums1 = [6, 5, 4, 3, 2, 1, 0],nums2 = [0, 1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],nums2 = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums1 = [0, 3, 1, 6, 5, 4, 2],nums2 = [1, 6, 4, 5, 3, 0, 2]) == 7\n assert candidate(nums1 = [1, 3, 5, 7, 9, 0, 2, 4, 6, 8],nums2 = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == 20\n assert candidate(nums1 = [1, 3, 2, 0, 5, 4],nums2 = [4, 0, 5, 2, 1, 3]) == 0\n assert candidate(nums1 = [2, 0, 4, 3, 5, 1],nums2 = [5, 4, 1, 0, 3, 2]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,0,1,3]\n[0,1,2,3]", "[4,0,1,3,2]\n[4,1,0,2,3]"], "hints": ["For every value y, how can you find the number of values x (0 ≤ x, y ≤ n - 1) such that x appears before y in both of the arrays?", "Similarly, for every value y, try finding the number of values z (0 ≤ y, z ≤ n - 1) such that z appears after y in both of the arrays.", "Now, for every value y, count the number of good triplets that can be formed if y is considered as the middle element."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().goodTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:51+00:00", "tests_total": 100, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "divide-and-conquer", "binary-indexed-tree", "segment-tree", "merge-sort", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function goodTriplets($nums1, $nums2) {", "container": "Solution", "callable": "goodTriplets", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2180, "task_id": "count-integers-with-even-digit-sum", "difficulty": "Easy", "problem_description": "Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.\n\nThe digit sum of a positive integer is the sum of all its digits.\n\nExample 1:\n\nInput: num = 4\nOutput: 2\nExplanation:\nThe only integers less than or equal to 4 whose digit sums are even are 2 and 4.\n\nExample 2:\n\nInput: num = 30\nOutput: 14\nExplanation:\nThe 14 integers less than or equal to 30 whose digit sums are even are\n2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.\n\nConstraints:\n\n- 1 <= num <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 30) == 14\n assert candidate(num = 10) == 4\n assert candidate(num = 999) == 499\n assert candidate(num = 500) == 249\n assert candidate(num = 4) == 2\n assert candidate(num = 2) == 1\n assert candidate(num = 1) == 0\n assert candidate(num = 100) == 49\n assert candidate(num = 750) == 375\n assert candidate(num = 1000) == 499\n assert candidate(num = 432) == 215\n assert candidate(num = 666) == 333\n assert candidate(num = 456) == 227\n assert candidate(num = 250) == 124\n assert candidate(num = 345) == 172\n assert candidate(num = 99) == 49\n assert candidate(num = 222) == 111\n assert candidate(num = 200) == 100\n assert candidate(num = 444) == 222\n assert candidate(num = 555) == 277\n assert candidate(num = 888) == 444\n assert candidate(num = 123) == 61\n assert candidate(num = 789) == 394\n assert candidate(num = 333) == 166\n assert candidate(num = 375) == 187\n assert candidate(num = 256) == 127\n assert candidate(num = 800) == 400\n assert candidate(num = 678) == 338\n assert candidate(num = 623) == 311\n assert candidate(num = 600) == 300\n assert candidate(num = 777) == 388\n assert candidate(num = 850) == 424\n assert candidate(num = 899) == 449\n assert candidate(num = 299) == 149\n", "comparison": "exact"}, "public_tests": ["4", "30"], "hints": ["Iterate through all integers from 1 to num.", "For any integer, extract the individual digits to compute their sum and check if it is even."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().countEven", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:54+00:00", "tests_total": 34, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countEven($num) {", "container": "Solution", "callable": "countEven", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2182, "task_id": "construct-string-with-repeat-limit", "difficulty": "Medium", "problem_description": "You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.\n\nReturn the lexicographically largest repeatLimitedString possible.\n\nA string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b. If the first min(a.length, b.length) characters do not differ, then the longer string is the lexicographically larger one.\n\nExample 1:\n\nInput: s = \"cczazcc\", repeatLimit = 3\nOutput: \"zzcccac\"\nExplanation: We use all of the characters from s to construct the repeatLimitedString \"zzcccac\".\nThe letter 'a' appears at most 1 time in a row.\nThe letter 'c' appears at most 3 times in a row.\nThe letter 'z' appears at most 2 times in a row.\nHence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\nThe string is the lexicographically largest repeatLimitedString possible so we return \"zzcccac\".\nNote that the string \"zzcccca\" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString.\n\nExample 2:\n\nInput: s = \"aababab\", repeatLimit = 2\nOutput: \"bbabaa\"\nExplanation: We use only some of the characters from s to construct the repeatLimitedString \"bbabaa\".\nThe letter 'a' appears at most 2 times in a row.\nThe letter 'b' appears at most 2 times in a row.\nHence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\nThe string is the lexicographically largest repeatLimitedString possible so we return \"bbabaa\".\nNote that the string \"bbabaaa\" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString.\n\nConstraints:\n\n- 1 <= repeatLimit <= s.length <= 10^5\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbccddeeff\",repeatLimit = 1) == \"fefedcdcbaba\"\n assert candidate(s = \"aabbccddeeff\",repeatLimit = 3) == \"ffeeddccbbaa\"\n assert candidate(s = \"cczazcc\",repeatLimit = 3) == \"zzcccac\"\n assert candidate(s = \"zzzzzzyyy\",repeatLimit = 2) == \"zzyzzyzzy\"\n assert candidate(s = \"zzzzzzzzz\",repeatLimit = 3) == \"zzz\"\n assert candidate(s = \"aababab\",repeatLimit = 2) == \"bbabaa\"\n assert candidate(s = \"leetcode\",repeatLimit = 3) == \"toleeedc\"\n assert candidate(s = \"a\",repeatLimit = 1) == \"a\"\n assert candidate(s = \"aabbcc\",repeatLimit = 1) == \"cbcba\"\n assert candidate(s = \"bbccddeee\",repeatLimit = 2) == \"eededccbb\"\n assert candidate(s = \"abcd\",repeatLimit = 1) == \"dcba\"\n assert candidate(s = \"zzzzzzzzzz\",repeatLimit = 2) == \"zz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",repeatLimit = 2) == \"zz\"\n assert candidate(s = \"abcabcabc\",repeatLimit = 1) == \"cbcbcba\"\n assert candidate(s = \"aaaaaabbbccc\",repeatLimit = 1) == \"cbcbcba\"\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpppppppppppppppppppppppppppppppp\",repeatLimit = 5) == \"qqqqqpqqqqqpqqqqqpqqqqqpqqqqqpqqqqqpqqppppp\"\n assert candidate(s = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeeffffffffggggggggghhhhhhhhhiiiiiiiiijjjjjjjjkkkkkkkkklllllllllmmmmmmmmmnnnnnnnnnoooooooooppppppppqqqqqqqqqrrrrrrrrrssssssssstttttttttuuuuuuuuuvvvvvvvvvwwwwwwwwwxxxxxxxxxyyyyyyyyzzzzzzzzz\",repeatLimit = 4) == \"zzzzyzzzzyzyyyyxyyxxxxwxxxxwwwwvwwwwvvvvuvvvvuuuutuuuuttttsttttssssrssssrrrrqrrrrqqqqpqqqqppppopppoooonoooonnnnmnnnnmmmmlmmmmllllkllllkkkkjkkkkjjjjijjjiiiihiiiihhhhghhhhggggfggggffffefffeeeedeeeeddddcdddccccbcccbbbbabbbaaaa\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",repeatLimit = 5) == \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"mmmmmmmllllllkkkkkkjjjjjjiiiiiihhhhhhggggggffffffeeeeee\",repeatLimit = 4) == \"mmmmlmmmllllklkkkkjkjjjjijiiiihihhhhghggggfgffffefeeee\"\n assert candidate(s = \"mnbvcxzlkjhgfdsapoiuytrewq\",repeatLimit = 1) == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 10) == \"zzzzzzzzzz\"\n assert candidate(s = \"aabbbccccddeeeffffgggghhhhiiiiijjjjkkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxxyyyyyzzzzzzzzzzzz\",repeatLimit = 4) == \"zzzzyzzzzyzzzzyyyxxxxwxwwwvvvvuuuuttttssssrrrrqqqqppppoooonnnnmmmmllllkkkkjkjjjiiiihihhhggggffffeeeddccccbbbaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",repeatLimit = 2) == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",repeatLimit = 1) == \"zyzyxwxwvuvutstsrqrqpoponmnmlklkjijihghgfefedcdcbaba\"\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggg\",repeatLimit = 4) == \"ggggffffeeeeddddccccbbbbaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzyyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\",repeatLimit = 1) == \"zyzyzyzyzyzyzyzyzyzyzyzxzxzxzxwxwxwxwxwvwvuvuvuvuvutututststststrtrtrqrqpqpqpqpqoqnqnmnmnmlmlklkjkjijihihigfgfgfgfefefdcdcdcbab\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxxyyyyyzzzzz\",repeatLimit = 2) == \"zzyzzyzyyxyxxwxxwwvwvvuvuututtstssrsrrqrqqpqppopoononnmnmmlmllklkkjkjjijiihihhggfgffeededdccbcbbaa\"\n assert candidate(s = \"pppppppppooooooonnnnmmmllllkkkkjjjjiiiihhhhhggggfffffeeeee\",repeatLimit = 4) == \"ppppoppppopoooononnnmmmllllkkkkjjjjiiiihhhhghgggffffefeeee\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",repeatLimit = 2) == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"zzzzzzzzzzzzzzzyyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\",repeatLimit = 5) == \"zzzzzyzzzzzyzzzzzyyyyyxyyyyxxxxxwxxwwwwwvvvvvuvuuuuututttttstttsssrrrrqqqqqpqqqppponnnnmmmmlllkkkjjjiiiihhggggfffffefedddcccbba\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",repeatLimit = 1) == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeefffffff\",repeatLimit = 3) == \"fffefffefeeedeeededddcdddcccbcccbcbbbabbbaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 1) == \"z\"\n assert candidate(s = \"zzzzzzzzzzzzzzzyyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\",repeatLimit = 3) == \"zzzyzzzyzzzyzzzyzzzyyyxyyyxyxxxwxxxwwwvwwvvvuvvuuutuuutttstttsttssrrrqrqqqpqqqpqpponnnmnmmmlllkkkjjjiiihihgggfgfffeffedddcccbba\"\n assert candidate(s = \"zzzzzzzzzzzzzzzyyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\",repeatLimit = 10) == \"zzzzzzzzzzyzzzzzyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\"\n assert candidate(s = \"xyzzzzzzzzzzyx\",repeatLimit = 5) == \"zzzzzyzzzzzyxx\"\n assert candidate(s = \"zzzzzzzzzzzzzzzyyyyyyyyyyyxxxxxxxxwwwwwwvvvvvvuuuuuuutttttttttssssrrrrqqqqqqqqpppponnnnmmmmlllkkkjjjiiiihhggggffffffeedddcccbba\",repeatLimit = 2) == \"zzyzzyzzyzzyzzyzzyzzyzyyxyyxxwxxwxxwxwwvwvvuvvuvuutuututtsttsttstsrrqrrqqpqqpqqpqponnmnnmmlmllkkjkjjiihiihggfggffeffefddcdccbba\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 5) == \"zzzzzyzzzzzxzzzzzwzzzzzvzzzzzuzzzzztzzzzzszzzzzrzzqponmlkjihgfedcba\"\n assert candidate(s = \"nnnnnnnnnmmmmmmmmmllllllllllkkkkkkkkkkjjjjjjjjjjiiiiiiiiiihhhhhhhhhhggggggggggffffffeeeeeeeeddddddddccccccccbbbaaaaaaaa\",repeatLimit = 10) == \"nnnnnnnnnmmmmmmmmmllllllllllkkkkkkkkkkjjjjjjjjjjiiiiiiiiiihhhhhhhhhhggggggggggffffffeeeeeeeeddddddddccccccccbbbaaaaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 5) == \"zzzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 5) == \"zzzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 5) == \"zzzzz\"\n assert candidate(s = \"mnlkjihgfedcba\",repeatLimit = 1) == \"nmlkjihgfedcba\"\n assert candidate(s = \"aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddd\",repeatLimit = 5) == \"dddddcdddddcdddddcdddddcdddddcdddddcdddddcdddddcddcccccbcccccbcccccbcccccbbbbbabbbbbabbbbbabaaaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 1) == \"z\"\n assert candidate(s = \"pppppqqqqqrrrrrssssstttttuuuuuvvvvvwwwwwxxxxxyyyyyzzzzz\",repeatLimit = 2) == \"zzyzzyzyyxyxxwxxwwvwwvvuvvuutuuttsttssrssrrqrrqqpqqpp\"\n assert candidate(s = \"aaaaaaaaaaaaaabbbbbbbbbbbbccccccccccccddddddddddddd\",repeatLimit = 3) == \"dddcdddcdddcdddcdcccbcccbccbbbabbbabbbabaaa\"\n assert candidate(s = \"zzzzzyyyyxxxxwwvvuttrrssqqppoonnmmllkkjjiihhggffeeddccbbaaa\",repeatLimit = 10) == \"zzzzzyyyyxxxxwwvvuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 3) == \"zzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 15) == \"zzzzzzzzzzzzzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 10) == \"zzzzzzzzzz\"\n assert candidate(s = \"zzzzzyyyyxxwwvvuuuutttssrrqqppoonnmmllkkjjiihhhggffeeddccbbaa\",repeatLimit = 2) == \"zzyzzyzyyxxwwvvuutuuttssrrqqppoonnmmllkkjjiihhghgffeeddccbbaa\"\n assert candidate(s = \"abacabadabacaba\",repeatLimit = 2) == \"dccbbabbaa\"\n assert candidate(s = \"ssssssssssssssssssssssssssssssss\",repeatLimit = 2) == \"ss\"\n assert candidate(s = \"zzzzzzzyyyy\",repeatLimit = 3) == \"zzzyzzzyzyy\"\n assert candidate(s = \"pppppppppppppppppppppppppppppppp\",repeatLimit = 3) == \"ppp\"\n assert candidate(s = \"zzzzzyyyyxxxxwwvvuttrrssqqppoonnmmllkkjjiihhggffeeddccbbaaa\",repeatLimit = 2) == \"zzyzzyzyyxxwxxwvvuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 5) == \"zzzzz\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",repeatLimit = 4) == \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 10) == \"zzzzzzzzzz\"\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",repeatLimit = 7) == \"qqqqqqq\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",repeatLimit = 1) == \"z\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",repeatLimit = 1) == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",repeatLimit = 3) == \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",repeatLimit = 10) == \"zyxwvutsrqponmlkjihgfedcba\"\n", "comparison": "exact"}, "public_tests": ["\"cczazcc\"\n3", "\"aababab\"\n2"], "hints": ["Start constructing the string in descending order of characters.", "When repeatLimit is reached, pick the next largest character."], "metadata": {"canonical_parameter_names": ["s", "repeatLimit"], "leetcode_dataset_entry_point": "Solution().repeatLimitedString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:43:59+00:00", "tests_total": 66, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "greedy", "heap-priority-queue", "counting"]}, "language": "php", "interface": {"raw_signature": "function repeatLimitedString($s, $repeatLimit) {", "container": "Solution", "callable": "repeatLimitedString", "parameters": [{"name": "s", "type": "String"}, {"name": "repeatLimit", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2183, "task_id": "count-array-pairs-divisible-by-k", "difficulty": "Hard", "problem_description": "Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:\n\n- 0 <= i < j <= n - 1 and\n- nums[i] * nums[j] is divisible by k.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], k = 2\nOutput: 7\nExplanation:\nThe 7 pairs of indices whose corresponding products are divisible by 2 are\n(0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).\nTheir products are 2, 4, 6, 8, 10, 12, and 20 respectively.\nOther pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4], k = 5\nOutput: 0\nExplanation: There does not exist any pair of indices whose corresponding product is divisible by 5.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i], k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 10\n assert candidate(nums = [5, 5, 5, 5],k = 5) == 6\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 7\n assert candidate(nums = [6, 12, 18, 24],k = 12) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],k = 3) == 7\n assert candidate(nums = [7, 14, 21, 28, 35],k = 7) == 10\n assert candidate(nums = [2, 4, 6, 8, 10],k = 3) == 4\n assert candidate(nums = [10, 20, 30, 40],k = 10) == 6\n assert candidate(nums = [5, 10, 15, 20, 25],k = 5) == 10\n assert candidate(nums = [7, 14, 21, 28],k = 7) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],k = 2) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],k = 4) == 10\n assert candidate(nums = [1, 2, 3, 4],k = 5) == 0\n assert candidate(nums = [3, 5, 7, 11],k = 1) == 6\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 45\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240],k = 12) == 190\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],k = 101) == 45\n assert candidate(nums = [100, 200, 300, 400, 500, 600],k = 100) == 15\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 5) == 45\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 13) == 45\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 13) == 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],k = 6) == 185\n assert candidate(nums = [24, 48, 72, 96, 120],k = 24) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 9) == 45\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24],k = 3) == 28\n assert candidate(nums = [5, 10, 15, 20, 25, 30],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],k = 1) == 190\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) == 190\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 45\n assert candidate(nums = [8, 12, 18, 24, 30, 36, 42],k = 6) == 21\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 10\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255],k = 17) == 105\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 45\n assert candidate(nums = [15, 25, 35, 45, 55],k = 15) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 5) == 105\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195],k = 13) == 105\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 14) == 35\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132],k = 11) == 66\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 45\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77],k = 11) == 21\n assert candidate(nums = [7, 14, 28, 56, 112],k = 14) == 10\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81],k = 9) == 36\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 100000) == 9\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],k = 100000) == 15\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],k = 9) == 55\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996],k = 5) == 4\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],k = 8) == 45\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 10) == 17\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 4) == 45\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170],k = 17) == 45\n assert candidate(nums = [13, 26, 39, 52, 65],k = 13) == 10\n assert candidate(nums = [6, 12, 18, 24, 30],k = 12) == 10\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 15) == 45\n assert candidate(nums = [77, 154, 231, 308, 385, 462, 539, 616, 693, 770],k = 11) == 45\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],k = 9) == 66\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 21) == 45\n assert candidate(nums = [6, 12, 18, 24, 30],k = 6) == 10\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],k = 101) == 45\n assert candidate(nums = [9, 18, 27, 36, 45],k = 9) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 16) == 101\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 = 5) == 190\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 21) == 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],k = 1) == 190\n assert candidate(nums = [49, 98, 147, 196, 245, 294, 343, 392, 441, 490],k = 49) == 45\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 11) == 45\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 9) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 0\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190],k = 19) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 3) == 60\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],k = 100) == 32\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105],k = 15) == 21\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],k = 7) == 105\n assert candidate(nums = [6, 8, 10, 12, 14, 16, 18],k = 12) == 15\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21],k = 3) == 21\n assert candidate(nums = [8, 16, 32, 64, 128],k = 8) == 10\n assert candidate(nums = [15, 30, 45, 60, 75],k = 15) == 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 = 3) == 112\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135],k = 9) == 105\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90],k = 6) == 105\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 5) == 66\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 45\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 15) == 45\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 = 2) == 300\n assert candidate(nums = [15, 25, 35, 45, 55],k = 5) == 10\n assert candidate(nums = [6, 12, 18, 24, 30, 36],k = 12) == 15\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 9) == 45\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 45\n assert candidate(nums = [11, 22, 33, 44, 55],k = 11) == 10\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],k = 8) == 105\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247, 260],k = 13) == 190\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 45\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230],k = 23) == 45\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64],k = 16) == 28\n assert candidate(nums = [25, 50, 75, 100, 125, 150],k = 25) == 15\n assert candidate(nums = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116],k = 11) == 37\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 3) == 34\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],k = 5) == 44\n assert candidate(nums = [10, 20, 30, 40, 50],k = 20) == 10\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 11) == 45\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96],k = 8) == 66\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n2", "[1,2,3,4]\n5"], "hints": ["For any element in the array, what is the smallest number it should be multiplied with such that the product is divisible by k?", "The smallest number which should be multiplied with nums[i] so that the product is divisible by k is k / gcd(k, nums[i]). Now think about how you can store and update the count of such numbers present in the array efficiently."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:01+00:00", "tests_total": 102, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function countPairs($nums, $k) {", "container": "Solution", "callable": "countPairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2185, "task_id": "counting-words-with-a-given-prefix", "difficulty": "Easy", "problem_description": "You are given an array of strings words and a string pref.\n\nReturn the number of strings in words that contain pref as a prefix.\n\nA prefix of a string s is any leading contiguous substring of s.\n\nExample 1:\n\nInput: words = [\"pay\",\"attention\",\"practice\",\"attend\"], pref = \"at\"\nOutput: 2\nExplanation: The 2 strings that contain \"at\" as a prefix are: \"attention\" and \"attend\".\n\nExample 2:\n\nInput: words = [\"leetcode\",\"win\",\"loops\",\"success\"], pref = \"code\"\nOutput: 0\nExplanation: There are no strings that contain \"code\" as a prefix.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length, pref.length <= 100\n- words[i] and pref consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['test', 'testing', 'tested', 'testing'],pref = \"test\") == 4\n assert candidate(words = ['abc', 'bcd', 'cde'],pref = \"a\") == 1\n assert candidate(words = ['hello', 'world', 'helium', 'helper'],pref = \"hel\") == 3\n assert candidate(words = ['banana', 'bandana', 'banner', 'balance'],pref = \"ban\") == 3\n assert candidate(words = ['hello', 'hell', 'hero', 'herald'],pref = \"he\") == 4\n assert candidate(words = ['pay', 'attention', 'practice', 'attend'],pref = \"at\") == 2\n assert candidate(words = ['hello', 'world'],pref = \"hi\") == 0\n assert candidate(words = ['hello', 'hell', 'helper'],pref = \"hel\") == 3\n assert candidate(words = ['apple', 'apricot', 'application'],pref = \"app\") == 2\n assert candidate(words = ['apple', 'apricot', 'application', 'appetite'],pref = \"app\") == 3\n assert candidate(words = ['cat', 'caterpillar', 'catalog', 'category'],pref = \"cat\") == 4\n assert candidate(words = ['apple', 'apricot', 'banana', 'apex'],pref = \"ap\") == 3\n assert candidate(words = ['banana', 'band', 'ball'],pref = \"ba\") == 3\n assert candidate(words = ['banana', 'bandana', 'baptism'],pref = \"ban\") == 2\n assert candidate(words = ['apple', 'application', 'apricot', 'apex'],pref = \"ap\") == 4\n assert candidate(words = ['leetcode', 'win', 'loops', 'success'],pref = \"code\") == 0\n assert candidate(words = ['database', 'datacenter', 'datamine', 'data'],pref = \"data\") == 4\n assert candidate(words = ['integration', 'integrate', 'interact', 'interactive'],pref = \"inte\") == 4\n assert candidate(words = ['algorithm', 'array', 'application', 'arithmetic'],pref = \"arr\") == 1\n assert candidate(words = ['intersection', 'interface', 'internal', 'interact'],pref = \"inter\") == 4\n assert candidate(words = ['unpredictable', 'unpredicted', 'unpredictably', 'unpredicting'],pref = \"unpred\") == 4\n assert candidate(words = ['prefix', 'prepend', 'presentation', 'preference'],pref = \"pre\") == 4\n assert candidate(words = ['challenge', 'champion', 'chance', 'character'],pref = \"cha\") == 4\n assert candidate(words = ['management', 'manager', 'manufacture', 'maintain'],pref = \"man\") == 3\n assert candidate(words = ['interpolation', 'interpolate', 'interpolator', 'interpolated'],pref = \"inter\") == 4\n assert candidate(words = ['technology', 'technique', 'technical', 'technological'],pref = \"tech\") == 4\n assert candidate(words = ['universe', 'uniform', 'unique', 'unit'],pref = \"uni\") == 4\n assert candidate(words = ['programming', 'python', 'problem', 'project', 'practice'],pref = \"pro\") == 3\n assert candidate(words = ['document', 'documentation', 'documentary', 'documents'],pref = \"docu\") == 4\n assert candidate(words = ['environment', 'envelope', 'encyclopedia', 'enterprise'],pref = \"env\") == 2\n assert candidate(words = ['interview', 'international', 'internet', 'introduce'],pref = \"inter\") == 3\n assert candidate(words = ['communication', 'community', 'commemoration', 'commentary'],pref = \"comm\") == 4\n assert candidate(words = ['algorithm', 'array', 'application', 'apricot'],pref = \"app\") == 1\n assert candidate(words = ['cryptography', 'cryptanalysis', 'cryptographic', 'cryptology'],pref = \"crypto\") == 3\n assert candidate(words = ['interact', 'interaction', 'interactive', 'interior', 'intercept'],pref = \"inter\") == 5\n assert candidate(words = ['fantastic', 'fancy', 'fantasy', 'fanatic'],pref = \"fan\") == 4\n assert candidate(words = ['pseudo', 'pseudocode', 'pseudorandom', 'pseudoscience'],pref = \"pseudo\") == 4\n assert candidate(words = ['mathematical', 'mathematics', 'mathematically', 'mathematize'],pref = \"math\") == 4\n assert candidate(words = ['programming', 'problem', 'prefix', 'preference'],pref = \"pre\") == 2\n assert candidate(words = ['biography', 'biologist', 'biological', 'biographical'],pref = \"bio\") == 4\n assert candidate(words = ['unbelievable', 'universe', 'unique', 'unanimous'],pref = \"un\") == 4\n assert candidate(words = ['congratulations', 'congratulate', 'congratulatory', 'congregate', 'congruity'],pref = \"cong\") == 5\n assert candidate(words = ['supplementary', 'supplement', 'supplier', 'suppose'],pref = \"sup\") == 4\n assert candidate(words = ['community', 'commune', 'communicate', 'common'],pref = \"comm\") == 4\n assert candidate(words = ['extraterrestrial', 'extraterrestrial', 'extraterrestrial', 'extraterrestrial'],pref = \"extra\") == 4\n assert candidate(words = ['algorithm', 'array', 'application', 'applet'],pref = \"app\") == 2\n assert candidate(words = ['abracadabra', 'abstract', 'absorb', 'academic'],pref = \"abs\") == 2\n assert candidate(words = ['congruence', 'congruent', 'congruently', 'congruency'],pref = \"congru\") == 4\n assert candidate(words = ['meticulous', 'meticulate', 'metaphor', 'metaphysics'],pref = \"metic\") == 2\n assert candidate(words = ['biological', 'biography', 'biologist', 'biology', 'bioluminescence'],pref = \"biol\") == 4\n assert candidate(words = ['application', 'approach', 'appetizer', 'append'],pref = \"app\") == 4\n assert candidate(words = ['scientific', 'scientist', 'science', 'sciences'],pref = \"sci\") == 4\n assert candidate(words = ['communication', 'community', 'common', 'commodity'],pref = \"com\") == 4\n assert candidate(words = ['quantization', 'quantize', 'quantitative', 'quantitative'],pref = \"quant\") == 4\n assert candidate(words = ['prefix', 'prepend', 'presentation', 'premature'],pref = \"pre\") == 4\n assert candidate(words = ['continuous', 'concurrent', 'conclusion', 'condition'],pref = \"con\") == 4\n assert candidate(words = ['programming', 'program', 'pro', 'professor'],pref = \"pro\") == 4\n assert candidate(words = ['management', 'manager', 'manage', 'mandate'],pref = \"man\") == 4\n assert candidate(words = ['transformation', 'transmit', 'transparent', 'transient'],pref = \"tran\") == 4\n assert candidate(words = ['administrator', 'administration', 'administrative', 'administratively'],pref = \"admin\") == 4\n assert candidate(words = ['circumstance', 'circuit', 'circulate', 'circulation', 'circular'],pref = \"circu\") == 5\n assert candidate(words = ['characterization', 'character', 'characteristic', 'characterization'],pref = \"char\") == 4\n assert candidate(words = ['environment', 'envy', 'envelope', 'evening'],pref = \"env\") == 3\n assert candidate(words = ['database', 'data', 'datagram', 'datastructure'],pref = \"data\") == 4\n assert candidate(words = ['celebration', 'celebrate', 'celebrity', 'celebratory', 'celestial'],pref = \"celeb\") == 4\n assert candidate(words = ['cryptography', 'crypt', 'crypto', 'cryptanalysis'],pref = \"crypt\") == 4\n assert candidate(words = ['photography', 'photo', 'photobook', 'photographer'],pref = \"photo\") == 4\n assert candidate(words = ['magnify', 'magnificent', 'magnetic', 'magnetism'],pref = \"mag\") == 4\n assert candidate(words = ['organization', 'organize', 'organ', 'organically'],pref = \"org\") == 4\n assert candidate(words = ['algorithm', 'algebra', 'almond', 'alert'],pref = \"alg\") == 2\n assert candidate(words = ['algorithm', 'array', 'application', 'apple'],pref = \"app\") == 2\n assert candidate(words = ['communication', 'community', 'commitment', 'common'],pref = \"comm\") == 4\n assert candidate(words = ['developer', 'debug', 'deploy', 'document'],pref = \"de\") == 3\n assert candidate(words = ['perpendicular', 'perpendicularity', 'perpendicularity', 'perpendicularly'],pref = \"perpendicular\") == 4\n assert candidate(words = ['environment', 'engine', 'error', 'example'],pref = \"en\") == 2\n assert candidate(words = ['university', 'uniform', 'unique', 'universe'],pref = \"uni\") == 4\n assert candidate(words = ['community', 'communist', 'common', 'comment'],pref = \"comm\") == 4\n assert candidate(words = ['literature', 'literacy', 'literary', 'literate'],pref = \"lit\") == 4\n assert candidate(words = ['sequoia', 'sequence', 'series', 'serial'],pref = \"ser\") == 2\n assert candidate(words = ['communication', 'community', 'companion', 'commune'],pref = \"comm\") == 3\n assert candidate(words = ['algorithm', 'algebra', 'alignment', 'algorithmic'],pref = \"algo\") == 2\n assert candidate(words = ['character', 'chart', 'chapter', 'charge'],pref = \"char\") == 3\n assert candidate(words = ['transport', 'trap', 'trapezium', 'traverse'],pref = \"tra\") == 4\n assert candidate(words = ['communication', 'commute', 'community', 'commotion', 'common'],pref = \"comm\") == 5\n assert candidate(words = ['environment', 'energy', 'engage', 'engageable'],pref = \"en\") == 4\n assert candidate(words = ['identification', 'individual', 'idea', 'illegal'],pref = \"iden\") == 1\n assert candidate(words = ['supreme', 'superior', 'surpass', 'surround'],pref = \"sur\") == 2\n assert candidate(words = ['transformation', 'transmit', 'transit', 'transformation', 'transition'],pref = \"trans\") == 5\n assert candidate(words = ['automation', 'automatic', 'automate', 'auto'],pref = \"auto\") == 4\n assert candidate(words = ['configuration', 'compute', 'container', 'cloud'],pref = \"con\") == 2\n assert candidate(words = ['communication', 'community', 'commitment', 'compassionate'],pref = \"comm\") == 3\n assert candidate(words = ['programming', 'program', 'pro', 'progress'],pref = \"pro\") == 4\n assert candidate(words = ['absolutely', 'absolute', 'absorb', 'abnormal'],pref = \"abs\") == 3\n assert candidate(words = ['statistics', 'statistical', 'statue', 'status'],pref = \"stat\") == 4\n assert candidate(words = ['prefix', 'prefixes', 'preferring', 'preference'],pref = \"pref\") == 4\n assert candidate(words = ['congratulations', 'congratulate', 'congratulatory', 'congratulated'],pref = \"congrat\") == 4\n assert candidate(words = ['environment', 'essential', 'establish', 'engage'],pref = \"en\") == 2\n assert candidate(words = ['substitution', 'substitute', 'substituted', 'substituting'],pref = \"sub\") == 4\n assert candidate(words = ['distribution', 'distribute', 'disastrous', 'discuss', 'disease'],pref = \"dis\") == 5\n assert candidate(words = ['development', 'deploy', 'debug', 'document'],pref = \"de\") == 3\n assert candidate(words = ['super', 'superhero', 'supercalifragilisticexpialidocious', 'supervillain'],pref = \"super\") == 4\n assert candidate(words = ['maintenance', 'maintain', 'maintenance', 'maintained'],pref = \"maint\") == 4\n assert candidate(words = ['python', 'pyramid', 'pythia', 'pyrotechnic'],pref = \"pyt\") == 2\n assert candidate(words = ['algorithm', 'algebra', 'alibi', 'alien', 'alimony'],pref = \"ali\") == 3\n assert candidate(words = ['remarkable', 'remark', 'remember', 'remind'],pref = \"rem\") == 4\n assert candidate(words = ['septagon', 'septagonal', 'septembre', 'septenary'],pref = \"sept\") == 4\n assert candidate(words = ['programming', 'progress', 'prompt', 'priority'],pref = \"pro\") == 3\n assert candidate(words = ['document', 'documentation', 'documentary', 'documents'],pref = \"doc\") == 4\n assert candidate(words = ['monarch', 'monarchy', 'monarchic', 'monarchically'],pref = \"monarch\") == 4\n assert candidate(words = ['hemisphere', 'hemispherical', 'hemispheres', 'hemispheric'],pref = \"hemis\") == 4\n assert candidate(words = ['environment', 'engage', 'enhance', 'enforce', 'ensure'],pref = \"enf\") == 1\n assert candidate(words = ['persistent', 'perspective', 'personality', 'person', 'personnel'],pref = \"pers\") == 5\n assert candidate(words = ['prefix', 'preference', 'presentation', 'prevent', 'president'],pref = \"pre\") == 5\n assert candidate(words = ['parallelogram', 'parallelepiped', 'parallel', 'parallelograms'],pref = \"parallel\") == 4\n assert candidate(words = ['intelligence', 'integrate', 'intensity', 'interact'],pref = \"inte\") == 4\n assert candidate(words = ['information', 'infrastructure', 'insurance', 'initial'],pref = \"in\") == 4\n assert candidate(words = ['transport', 'transmit', 'transformation', 'transition'],pref = \"trans\") == 4\n assert candidate(words = ['establish', 'estimate', 'essential', 'establishment'],pref = \"est\") == 3\n assert candidate(words = ['algorithm', 'algebra', 'alchemist', 'alchemy'],pref = \"alg\") == 2\n assert candidate(words = ['environment', 'envelope', 'engage', 'enhance'],pref = \"en\") == 4\n assert candidate(words = ['transport', 'transmit', 'transit', 'transformation', 'transition'],pref = \"trans\") == 5\n assert candidate(words = ['programming', 'problem', 'process', 'productivity'],pref = \"pro\") == 4\n assert candidate(words = ['programming', 'pro', 'processor', 'productivity'],pref = \"pro\") == 4\n assert candidate(words = ['encyclopedia', 'encyclopedias', 'encyclopedic', 'encyclopedically'],pref = \"ency\") == 4\n assert candidate(words = ['apple', 'application', 'appetite', 'apparent'],pref = \"app\") == 4\n assert candidate(words = ['zebra', 'zephyr', 'zoo', 'zealous'],pref = \"ze\") == 3\n assert candidate(words = ['prefix', 'prefixes', 'preference', 'preferring'],pref = \"pref\") == 4\n assert candidate(words = ['communication', 'community', 'commitment', 'commission'],pref = \"com\") == 4\n assert candidate(words = ['hypothesis', 'historical', 'hyphen', 'hydrogen'],pref = \"hy\") == 3\n assert candidate(words = ['transformation', 'transfer', 'transform', 'transformer'],pref = \"trans\") == 4\n assert candidate(words = ['transaction', 'transfer', 'transition', 'transportation'],pref = \"tran\") == 4\n assert candidate(words = ['abracadabra', 'abrakadabras', 'abracadabrac', 'abracadabrad'],pref = \"abrac\") == 3\n assert candidate(words = ['interview', 'integrate', 'interaction', 'interface'],pref = \"inte\") == 4\n assert candidate(words = ['fantastic', 'fantasy', 'fancy', 'fantastician'],pref = \"fant\") == 3\n assert candidate(words = ['communication', 'communicate', 'communist', 'commune'],pref = \"comm\") == 4\n assert candidate(words = ['environment', 'environ', 'environmental', 'envelope'],pref = \"env\") == 4\n assert candidate(words = ['education', 'educational', 'educate', 'educator'],pref = \"edu\") == 4\n assert candidate(words = ['automation', 'automobile', 'automatic', 'automate'],pref = \"auto\") == 4\n assert candidate(words = ['customization', 'customize', 'custom', 'customarily'],pref = \"cust\") == 4\n assert candidate(words = ['environment', 'encourage', 'endure', 'ensure'],pref = \"en\") == 4\n assert candidate(words = ['prefix', 'predict', 'prevent', 'preach', 'prelude'],pref = \"pre\") == 5\n assert candidate(words = ['elephant', 'elegant', 'elephantine', 'election'],pref = \"ele\") == 4\n assert candidate(words = ['celebration', 'celebrity', 'celebratory', 'celebration'],pref = \"celeb\") == 4\n assert candidate(words = ['achievement', 'achieve', 'achiever', 'achievable'],pref = \"achi\") == 4\n assert candidate(words = ['development', 'debug', 'document', 'disk'],pref = \"de\") == 2\n assert candidate(words = ['prefix', 'preference', 'prevent', 'president'],pref = \"pre\") == 4\n assert candidate(words = ['automobile', 'automatic', 'automate', 'automaton'],pref = \"auto\") == 4\n assert candidate(words = ['terrific', 'terrify', 'terrestrial', 'territory'],pref = \"terr\") == 4\n assert candidate(words = ['synchronization', 'synchronous', 'synchronize', 'synchronized'],pref = \"synch\") == 4\n assert candidate(words = ['abbreviation', 'abrupt', 'absorb', 'absolute'],pref = \"abs\") == 2\n assert candidate(words = ['repetition', 'reproductive', 'represent', 'reputation', 'reprehend'],pref = \"rep\") == 5\n assert candidate(words = ['apple', 'application', 'applicant', 'appetite'],pref = \"app\") == 4\n assert candidate(words = ['xylophone', 'xylography', 'xylophone', 'xylophone'],pref = \"xy\") == 4\n", "comparison": "exact"}, "public_tests": ["[\"pay\",\"attention\",\"practice\",\"attend\"]\n\"at\"", "[\"leetcode\",\"win\",\"loops\",\"success\"]\n\"code\""], "hints": ["Go through each word in words and increment the answer if pref is a prefix of the word."], "metadata": {"canonical_parameter_names": ["words", "pref"], "leetcode_dataset_entry_point": "Solution().prefixCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:06+00:00", "tests_total": 153, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "string-matching"]}, "language": "php", "interface": {"raw_signature": "function prefixCount($words, $pref) {", "container": "Solution", "callable": "prefixCount", "parameters": [{"name": "words", "type": "String[]"}, {"name": "pref", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2186, "task_id": "minimum-number-of-steps-to-make-two-strings-anagram-ii", "difficulty": "Medium", "problem_description": "You are given two strings s and t. In one step, you can append any character to either s or t.\n\nReturn the minimum number of steps to make s and t anagrams of each other.\n\nAn anagram of a string is a string that contains the same characters with a different (or the same) ordering.\n\nExample 1:\n\nInput: s = \"leetcode\", t = \"coats\"\nOutput: 7\nExplanation:\n- In 2 steps, we can append the letters in \"as\" onto s = \"leetcode\", forming s = \"leetcodeas\".\n- In 5 steps, we can append the letters in \"leede\" onto t = \"coats\", forming t = \"coatsleede\".\n\"leetcodeas\" and \"coatsleede\" are now anagrams of each other.\nWe used a total of 2 + 5 = 7 steps.\nIt can be shown that there is no way to make them anagrams of each other with less than 7 steps.\n\nExample 2:\n\nInput: s = \"night\", t = \"thing\"\nOutput: 0\nExplanation: The given strings are already anagrams of each other. Thus, we do not need any further steps.\n\nConstraints:\n\n- 1 <= s.length, t.length <= 2 * 10^5\n- s and t consist of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aaaa\",t = \"bbbb\") == 8\n assert candidate(s = \"aabbcc\",t = \"abc\") == 3\n assert candidate(s = \"anagram\",t = \"nagaram\") == 0\n assert candidate(s = \"rat\",t = \"car\") == 2\n assert candidate(s = \"xyz\",t = \"zyxwvut\") == 4\n assert candidate(s = \"leetcode\",t = \"coats\") == 7\n assert candidate(s = \"aaaaa\",t = \"bbbbb\") == 10\n assert candidate(s = \"ab\",t = \"ba\") == 0\n assert candidate(s = \"night\",t = \"thing\") == 0\n assert candidate(s = \"abacabadaba\",t = \"zzzzz\") == 16\n assert candidate(s = \"aa\",t = \"bb\") == 4\n assert candidate(s = \"a\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"dcba\") == 0\n assert candidate(s = \"abc\",t = \"def\") == 6\n assert candidate(s = \"a\",t = \"b\") == 2\n assert candidate(s = \"abacabadabacaba\",t = \"abcde\") == 12\n assert candidate(s = \"same\",t = \"same\") == 0\n assert candidate(s = \"aabbccddeeff\",t = \"abcdef\") == 6\n assert candidate(s = \"oneonetwothree\",t = \"threeonetwoone\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"aaaaaaaaaaaaaaaaaaaaaaaaaa\") == 50\n assert candidate(s = \"thisisateststring\",t = \"testingstring\") == 8\n assert candidate(s = \"anagram\",t = \"mangaar\") == 0\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",t = \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == 88\n assert candidate(s = \"hello\",t = \"world\") == 6\n assert candidate(s = \"mississippi\",t = \"ississimppimiss\") == 4\n assert candidate(s = \"pythonprogramming\",t = \"javaprogramming\") == 10\n assert candidate(s = \"repeatrepeatrepeat\",t = \"peatpeatpeatre\") == 4\n assert candidate(s = \"xxyyzz\",t = \"zzzzyyxx\") == 2\n assert candidate(s = \"deified\",t = \"deified\") == 0\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",t = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"pythonprogramming\",t = \"programmingpython\") == 0\n assert candidate(s = \"thisisalongstringsample\",t = \"samplesamplealongstringthisis\") == 6\n assert candidate(s = \"complexinputfortesting\",t = \"testingfortestingcomplex\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzxxccvvaabbeeffgghhiijjkkllmmnnooppqqrrssttuuvvww\") == 6\n assert candidate(s = \"abracadabra\",t = \"barbarian\") == 6\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == 1\n assert candidate(s = \"abracadabra\",t = \"abrakadabracadabra\") == 7\n assert candidate(s = \"balancedstring\",t = \"stringbalanced\") == 0\n assert candidate(s = \"abcdefghij\",t = \"abcdefghijjihgfedcba\") == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(s = \"aaabbbccc\",t = \"bbbaaaccc\") == 0\n assert candidate(s = \"thisisatest\",t = \"testthisis\") == 1\n assert candidate(s = \"encyclopedia\",t = \"dictionary\") == 8\n assert candidate(s = \"mississippi\",t = \"missisippi\") == 1\n assert candidate(s = \"aaaaabbbbbcccccd\",t = \"dddddccccbbbbbaaaaa\") == 5\n assert candidate(s = \"repeatedcharacterss\",t = \"charactersrepeatedss\") == 1\n assert candidate(s = \"thisisananagram\",t = \"isananagramthis\") == 0\n assert candidate(s = \"abcdefg\",t = \"hijklmn\") == 14\n assert candidate(s = \"aaaabbbbccccdddd\",t = \"ddddccccbbbbaaaa\") == 0\n assert candidate(s = \"rhinoceros\",t = \"orchestrer\") == 6\n assert candidate(s = \"samecharacters\",t = \"characterssame\") == 0\n assert candidate(s = \"onetwothreefourfivesixseveneightnine\",t = \"nineseveneightsixfvierthreeonotwo\") == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyz\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccbbaa\") == 0\n assert candidate(s = \"anagram\",t = \"manga\") == 2\n assert candidate(s = \"samestring\",t = \"samestring\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"thisisaverylongstringthatwearegoingtouseasourtestcase\",t = \"anotherlongstringthatwillbeusedasourtestcase\") == 17\n assert candidate(s = \"uniquecharacters\",t = \"charactersunique\") == 0\n assert candidate(s = \"elephant\",t = \"television\") == 8\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",t = \"abcdefghijklmnopqrstuvwxyz\") == 44\n assert candidate(s = \"repeatedcharactersrepeated\",t = \"charactersrepeatedcharacters\") == 10\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",t = \"doglazytheoverjumpsonbrowquickthe\") == 2\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"abcd\",t = \"efghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"a\",t = \"abcdefghijklmnopqrstuvwxyz\") == 25\n assert candidate(s = \"level\",t = \"level\") == 0\n assert candidate(s = \"equalnumberofchars\",t = \"equalnumberofchars\") == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(s = \"supercalifragilisticexpialidocious\",t = \"pneumonoultramicroscopicsilicovolcanoconiosis\") == 25\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",t = \"zzzzzzzzzzzzzzzzzzzz\") == 68\n assert candidate(s = \"longstringwithrepeatedcharacters\",t = \"characterswithrepeatedlongstring\") == 0\n assert candidate(s = \"uniquecharacters\",t = \"differentcharacters\") == 9\n assert candidate(s = \"mississippi\",t = \"pensil\") == 11\n assert candidate(s = \"xyxxyxyxyx\",t = \"yyxyxyxyxy\") == 4\n assert candidate(s = \"abracadabra\",t = \"abracadabracadabra\") == 7\n assert candidate(s = \"redder\",t = \"redder\") == 0\n assert candidate(s = \"hello\",t = \"billion\") == 6\n assert candidate(s = \"xylophone\",t = \"xylophon\") == 1\n assert candidate(s = \"thqwhrwhrwhr\",t = \"tttttttttttt\") == 22\n assert candidate(s = \"xylophone\",t = \"polyrhythm\") == 9\n assert candidate(s = \"unique\",t = \"distinct\") == 10\n assert candidate(s = \"mississippi\",t = \"pensylvania\") == 16\n assert candidate(s = \"xyzxyzxyz\",t = \"abcabcabc\") == 18\n assert candidate(s = \"racecar\",t = \"carrace\") == 0\n assert candidate(s = \"abcdefg\",t = \"hijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",t = \"mnbvcxzlkjhgfdsapoiuytrewq\") == 0\n assert candidate(s = \"abcde\",t = \"fghij\") == 10\n assert candidate(s = \"abcdabcdabcdabcd\",t = \"dcba\") == 12\n assert candidate(s = \"longerstringwithmorecharacters\",t = \"shortstring\") == 19\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(s = \"longerstringhere\",t = \"short\") == 11\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzyyxxwwvvuuttssrrqqppoonnmlkkjjiihhggffeeeeddccbbaa\") == 5\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",t = \"thequickbrownfoxjumpsoverthelazydog\") == 0\n assert candidate(s = \"abcdefghijkllllllllllllmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 11\n assert candidate(s = \"xxyyzz\",t = \"xxxyyyzzz\") == 3\n assert candidate(s = \"elephant\",t = \"relevant\") == 4\n assert candidate(s = \"pythonprogramming\",t = \"java\") == 19\n assert candidate(s = \"mississippi\",t = \"pennsylvania\") == 17\n assert candidate(s = \"aaaaa\",t = \"bbbbbbaaaaa\") == 6\n assert candidate(s = \"rotor\",t = \"rotor\") == 0\n", "comparison": "exact"}, "public_tests": ["\"leetcode\"\n\"coats\"", "\"night\"\n\"thing\""], "hints": ["Notice that for anagrams, the order of the letters is irrelevant.", "For each letter, we can count its frequency in s and t.", "For each letter, its contribution to the answer is the absolute difference between its frequency in s and t."], "metadata": {"canonical_parameter_names": ["s", "t"], "leetcode_dataset_entry_point": "Solution().minSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:09+00:00", "tests_total": 110, "tests_dropped": 8, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function minSteps($s, $t) {", "container": "Solution", "callable": "minSteps", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2187, "task_id": "minimum-time-to-complete-trips", "difficulty": "Medium", "problem_description": "You are given an array time where time[i] denotes the time taken by the i^th bus to complete one trip.\n\nEach bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.\n\nYou are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.\n\nExample 1:\n\nInput: time = [1,2,3], totalTrips = 5\nOutput: 3\nExplanation:\n- At time t = 1, the number of trips completed by each bus are [1,0,0].\n The total number of trips completed is 1 + 0 + 0 = 1.\n- At time t = 2, the number of trips completed by each bus are [2,1,0].\n The total number of trips completed is 2 + 1 + 0 = 3.\n- At time t = 3, the number of trips completed by each bus are [3,1,1].\n The total number of trips completed is 3 + 1 + 1 = 5.\nSo the minimum time needed for all buses to complete at least 5 trips is 3.\n\nExample 2:\n\nInput: time = [2], totalTrips = 1\nOutput: 2\nExplanation:\nThere is only one bus, and it will complete its first trip at t = 2.\nSo the minimum time needed to complete 1 trip is 2.\n\nConstraints:\n\n- 1 <= time.length <= 10^5\n- 1 <= time[i], totalTrips <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(time = [1, 2, 3],totalTrips = 5) == 3\n assert candidate(time = [10000000],totalTrips = 10000000) == 100000000000000\n assert candidate(time = [10, 20, 30],totalTrips = 100) == 550\n assert candidate(time = [1, 1, 1, 1, 1],totalTrips = 100000) == 20000\n assert candidate(time = [1, 1, 1, 1, 1],totalTrips = 10000) == 2000\n assert candidate(time = [5, 10, 15],totalTrips = 9) == 30\n assert candidate(time = [5, 10, 15],totalTrips = 10) == 30\n assert candidate(time = [2],totalTrips = 1) == 2\n assert candidate(time = [1, 1, 1, 1],totalTrips = 10) == 3\n assert candidate(time = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],totalTrips = 15000) == 3000\n assert candidate(time = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],totalTrips = 500) == 305\n assert candidate(time = [7, 14, 21, 28, 35, 42],totalTrips = 100) == 294\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],totalTrips = 50000) == 13900\n assert candidate(time = [3, 6, 9, 12],totalTrips = 20) == 30\n assert candidate(time = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],totalTrips = 100000) == 100000\n assert candidate(time = [100, 200, 300, 400],totalTrips = 500) == 24000\n assert candidate(time = [5, 8, 12, 16, 20],totalTrips = 100) == 195\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],totalTrips = 100) == 36\n assert candidate(time = [2, 3, 5, 7, 11, 13, 17, 19],totalTrips = 50) == 36\n assert candidate(time = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],totalTrips = 50000) == 21408\n assert candidate(time = [2, 3, 4, 5, 6, 7, 8, 9, 10],totalTrips = 50) == 28\n assert candidate(time = [3, 5, 7, 9],totalTrips = 20) == 27\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 5000) == 17090\n assert candidate(time = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],totalTrips = 1500) == 1539\n assert candidate(time = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],totalTrips = 1000000) == 250000\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],totalTrips = 5000) == 1392\n assert candidate(time = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],totalTrips = 150) == 132\n assert candidate(time = [100, 200, 300, 400, 500],totalTrips = 1500) == 65800\n assert candidate(time = [10, 20, 30, 40, 50],totalTrips = 50) == 230\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],totalTrips = 1000000) == 500004\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64, 128],totalTrips = 1000) == 504\n assert candidate(time = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],totalTrips = 5000) == 731\n assert candidate(time = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],totalTrips = 10000) == 2500\n assert candidate(time = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],totalTrips = 1000) == 655\n assert candidate(time = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],totalTrips = 1000) == 500\n assert candidate(time = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],totalTrips = 15000) == 6425\n assert candidate(time = [3, 6, 9, 12],totalTrips = 25) == 36\n assert candidate(time = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],totalTrips = 15000) == 46107\n assert candidate(time = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],totalTrips = 5000) == 2500\n assert candidate(time = [3, 6, 9, 12, 15],totalTrips = 20) == 30\n assert candidate(time = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],totalTrips = 100) == 49\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 1000) == 3430\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64],totalTrips = 5000) == 2521\n assert candidate(time = [100, 200, 300, 400, 500],totalTrips = 5000) == 219000\n assert candidate(time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],totalTrips = 10000) == 17080\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],totalTrips = 1023) == 512\n assert candidate(time = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],totalTrips = 50000) == 17072000\n assert candidate(time = [7, 14, 21, 28, 35],totalTrips = 30) == 98\n assert candidate(time = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],totalTrips = 100) == 18\n assert candidate(time = [10000000, 9999999, 9999998, 9999997, 9999996],totalTrips = 10000000) == 20000000000000\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 500) == 1720\n assert candidate(time = [10000, 5000, 2500, 1250, 625],totalTrips = 1000000) == 322581250\n assert candidate(time = [3, 6, 9, 12, 15],totalTrips = 25) == 36\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64],totalTrips = 1000) == 506\n assert candidate(time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],totalTrips = 10000) == 17080\n assert candidate(time = [2, 5, 7, 10],totalTrips = 20) == 22\n assert candidate(time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],totalTrips = 1000) == 1400\n assert candidate(time = [2, 4, 6, 8, 10, 12, 14],totalTrips = 70) == 56\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 10000) == 34160\n assert candidate(time = [2, 5, 8, 11],totalTrips = 20) == 24\n assert candidate(time = [3, 6, 9, 12, 15, 18],totalTrips = 100) == 126\n assert candidate(time = [3, 9, 27, 81],totalTrips = 100) == 207\n assert candidate(time = [100, 200, 300, 400, 500],totalTrips = 5000) == 219000\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],totalTrips = 10000) == 3016\n assert candidate(time = [100000, 200000, 300000, 400000, 500000],totalTrips = 1000000) == 43795700000\n assert candidate(time = [3, 6, 9, 12],totalTrips = 20) == 30\n assert candidate(time = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],totalTrips = 1000) == 1372\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],totalTrips = 20000) == 60300\n assert candidate(time = [10000, 20000, 30000, 40000],totalTrips = 100000) == 480000000\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],totalTrips = 100000) == 34144\n assert candidate(time = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],totalTrips = 3000) == 1959\n assert candidate(time = [100, 200, 300, 400, 500],totalTrips = 1000) == 43900\n assert candidate(time = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],totalTrips = 25000) == 15072\n assert candidate(time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],totalTrips = 150) == 265\n assert candidate(time = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630],totalTrips = 10000) == 126672\n assert candidate(time = [7, 14, 21, 28, 35],totalTrips = 100) == 315\n assert candidate(time = [10, 20, 30, 40, 50, 60],totalTrips = 100) == 420\n assert candidate(time = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],totalTrips = 2500) == 5870\n assert candidate(time = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],totalTrips = 200000) == 277965\n assert candidate(time = [4, 8, 12, 16, 20],totalTrips = 50) == 92\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 10000) == 34160\n assert candidate(time = [2, 3, 5, 7, 11],totalTrips = 30) == 25\n assert candidate(time = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],totalTrips = 20000) == 88790\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64],totalTrips = 100000) == 50396\n assert candidate(time = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],totalTrips = 200) == 96\n assert candidate(time = [7, 14, 21, 28, 35, 42],totalTrips = 100) == 294\n assert candidate(time = [2, 3, 5, 7],totalTrips = 20) == 18\n assert candidate(time = [3, 6, 9, 12],totalTrips = 15) == 24\n assert candidate(time = [7, 14, 21, 28, 35],totalTrips = 50) == 161\n assert candidate(time = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],totalTrips = 500000) == 48814545\n assert candidate(time = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],totalTrips = 200) == 700\n assert candidate(time = [10000, 20000, 30000],totalTrips = 100000) == 545460000\n assert candidate(time = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],totalTrips = 1000000) == 550002\n assert candidate(time = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],totalTrips = 1000000) == 403282\n assert candidate(time = [7, 14, 21, 28],totalTrips = 25) == 84\n assert candidate(time = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],totalTrips = 300) == 184\n assert candidate(time = [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],totalTrips = 100000) == 38597\n assert candidate(time = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],totalTrips = 100000) == 50050\n assert candidate(time = [1, 3, 7, 15],totalTrips = 30) == 21\n assert candidate(time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],totalTrips = 1000) == 343\n assert candidate(time = [4, 5, 6, 7, 8],totalTrips = 30) == 36\n assert candidate(time = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],totalTrips = 200) == 490\n assert candidate(time = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],totalTrips = 500) == 110\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n5", "[2]\n1"], "hints": ["For a given amount of time, how can we count the total number of trips completed by all buses within that time?", "Consider using binary search."], "metadata": {"canonical_parameter_names": ["time", "totalTrips"], "leetcode_dataset_entry_point": "Solution().minimumTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:12+00:00", "tests_total": 103, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function minimumTime($time, $totalTrips) {", "container": "Solution", "callable": "minimumTime", "parameters": [{"name": "time", "type": "Integer[]"}, {"name": "totalTrips", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2188, "task_id": "minimum-time-to-finish-the-race", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array tires where tires[i] = [f_i, r_i] indicates that the i^th tire can finish its x^th successive lap in f_i * r_i^(x-1) seconds.\n\n- For example, if f_i = 3 and r_i = 2, then the tire would finish its 1^st lap in 3 seconds, its 2^nd lap in 3 * 2 = 6 seconds, its 3^rd lap in 3 * 2^2 = 12 seconds, etc.\n\nYou are also given an integer changeTime and an integer numLaps.\n\nThe race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.\n\nReturn the minimum time to finish the race.\n\nExample 1:\n\nInput: tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4\nOutput: 21\nExplanation:\nLap 1: Start with tire 0 and finish the lap in 2 seconds.\nLap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\nLap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.\nLap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\nTotal time = 2 + 6 + 5 + 2 + 6 = 21 seconds.\nThe minimum time to complete the race is 21 seconds.\n\nExample 2:\n\nInput: tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5\nOutput: 25\nExplanation:\nLap 1: Start with tire 1 and finish the lap in 2 seconds.\nLap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\nLap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.\nLap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\nLap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.\nTotal time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.\nThe minimum time to complete the race is 25 seconds.\n\nConstraints:\n\n- 1 <= tires.length <= 10^5\n- tires[i].length == 2\n- 1 <= f_i, changeTime <= 10^5\n- 2 <= r_i <= 10^5\n- 1 <= numLaps <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tires = [[2, 3], [3, 4]],changeTime = 5,numLaps = 4) == 21\n assert candidate(tires = [[5, 2], [3, 3]],changeTime = 4,numLaps = 3) == 17\n assert candidate(tires = [[5, 5], [3, 3]],changeTime = 10,numLaps = 6) == 56\n assert candidate(tires = [[100000, 2]],changeTime = 100000,numLaps = 1000) == 199900000\n assert candidate(tires = [[5, 2]],changeTime = 3,numLaps = 3) == 21\n assert candidate(tires = [[10, 10], [5, 5], [2, 2]],changeTime = 5,numLaps = 3) == 13\n assert candidate(tires = [[10, 5], [20, 2]],changeTime = 7,numLaps = 8) == 129\n assert candidate(tires = [[1, 2]],changeTime = 3,numLaps = 1) == 1\n assert candidate(tires = [[5, 5], [10, 2]],changeTime = 7,numLaps = 3) == 29\n assert candidate(tires = [[10, 5], [2, 2]],changeTime = 1,numLaps = 10) == 29\n assert candidate(tires = [[5, 2]],changeTime = 3,numLaps = 2) == 13\n assert candidate(tires = [[1, 10], [2, 2], [3, 4]],changeTime = 6,numLaps = 5) == 25\n assert candidate(tires = [[1, 2]],changeTime = 3,numLaps = 10) == 27\n assert candidate(tires = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],changeTime = 5,numLaps = 750) == 4495\n assert candidate(tires = [[2, 3], [3, 4], [5, 6], [7, 8]],changeTime = 5,numLaps = 15) == 93\n assert candidate(tires = [[1, 100000], [2, 90000], [3, 80000], [4, 70000], [5, 60000], [6, 50000], [7, 40000], [8, 30000], [9, 20000], [10, 10000]],changeTime = 100000,numLaps = 1000) == 99900500\n assert candidate(tires = [[10, 5], [2, 2], [3, 3]],changeTime = 6,numLaps = 20) == 114\n assert candidate(tires = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],changeTime = 1,numLaps = 900) == 1799\n assert candidate(tires = [[1, 5], [2, 3], [3, 2]],changeTime = 7,numLaps = 15) == 92\n assert candidate(tires = [[1, 2], [1, 3], [1, 4], [1, 5]],changeTime = 1,numLaps = 50) == 99\n assert candidate(tires = [[5, 3], [2, 8], [7, 2]],changeTime = 5,numLaps = 200) == 1395\n assert candidate(tires = [[100, 100], [200, 200], [300, 300]],changeTime = 50,numLaps = 1000) == 149950\n assert candidate(tires = [[2, 10], [3, 9], [4, 8], [5, 7], [6, 6], [7, 5], [8, 4], [9, 3], [10, 2]],changeTime = 5,numLaps = 500) == 3495\n assert candidate(tires = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]],changeTime = 20,numLaps = 500) == 12480\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],changeTime = 5,numLaps = 50) == 195\n assert candidate(tires = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],changeTime = 50,numLaps = 750) == 12100\n assert candidate(tires = [[2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],changeTime = 10,numLaps = 999) == 8984\n assert candidate(tires = [[1, 2], [3, 4], [5, 6]],changeTime = 10,numLaps = 15) == 75\n assert candidate(tires = [[2, 3], [3, 4], [1, 5]],changeTime = 5,numLaps = 10) == 50\n assert candidate(tires = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],changeTime = 10,numLaps = 25) == 190\n assert candidate(tires = [[2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8]],changeTime = 7,numLaps = 50) == 318\n assert candidate(tires = [[100, 2], [200, 3], [300, 4], [400, 5]],changeTime = 150,numLaps = 600) == 134850\n assert candidate(tires = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],changeTime = 10,numLaps = 1000) == 7990\n assert candidate(tires = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],changeTime = 1,numLaps = 1000) == 1999\n assert candidate(tires = [[1000, 2], [500, 3], [250, 4]],changeTime = 500,numLaps = 100) == 74500\n assert candidate(tires = [[5, 3], [7, 4], [2, 2]],changeTime = 10,numLaps = 20) == 150\n assert candidate(tires = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6]],changeTime = 5,numLaps = 500) == 5495\n assert candidate(tires = [[1, 2], [1, 3], [1, 4], [1, 5]],changeTime = 1,numLaps = 100) == 199\n assert candidate(tires = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],changeTime = 100000,numLaps = 1) == 1\n assert candidate(tires = [[1, 10000], [2, 5000], [3, 1000], [4, 500], [5, 250], [6, 125], [7, 62], [8, 31], [9, 15], [10, 7]],changeTime = 1000,numLaps = 1000) == 522400\n assert candidate(tires = [[1, 10], [2, 5], [3, 3]],changeTime = 15,numLaps = 500) == 6485\n assert candidate(tires = [[1, 10], [2, 2], [3, 4], [4, 5]],changeTime = 5,numLaps = 30) == 160\n assert candidate(tires = [[100, 100], [200, 50], [300, 25]],changeTime = 100,numLaps = 300) == 59900\n assert candidate(tires = [[10, 10], [20, 20], [30, 30]],changeTime = 50,numLaps = 750) == 44950\n assert candidate(tires = [[2, 2], [3, 2], [4, 2], [5, 2], [6, 2]],changeTime = 10,numLaps = 500) == 3990\n assert candidate(tires = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],changeTime = 15,numLaps = 50) == 470\n assert candidate(tires = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],changeTime = 5,numLaps = 15) == 55\n assert candidate(tires = [[3, 5], [2, 3], [4, 4]],changeTime = 10,numLaps = 15) == 128\n assert candidate(tires = [[5, 10], [3, 3], [2, 2]],changeTime = 10,numLaps = 20) == 150\n assert candidate(tires = [[100000, 100000], [50000, 50000], [25000, 25000], [12500, 12500], [6250, 6250]],changeTime = 100000,numLaps = 1000) == 106150000\n assert candidate(tires = [[100, 10], [50, 5], [25, 2]],changeTime = 20,numLaps = 1000) == 44980\n assert candidate(tires = [[2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],changeTime = 3,numLaps = 40) == 197\n assert candidate(tires = [[10, 10], [20, 20], [30, 30]],changeTime = 100,numLaps = 50) == 5150\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5]],changeTime = 1,numLaps = 1) == 1\n assert candidate(tires = [[10000, 2], [5000, 3], [1000, 4], [500, 5], [250, 6], [125, 7], [62, 8], [31, 9], [15, 10], [7, 11]],changeTime = 10000,numLaps = 1000) == 3639260\n assert candidate(tires = [[3, 2], [4, 3], [5, 4], [6, 5], [7, 6]],changeTime = 15,numLaps = 30) == 345\n assert candidate(tires = [[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]],changeTime = 5,numLaps = 200) == 795\n assert candidate(tires = [[5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5], [5, 5]],changeTime = 10,numLaps = 1000) == 14990\n assert candidate(tires = [[1, 2], [1, 3], [1, 4], [1, 5]],changeTime = 5,numLaps = 15) == 55\n assert candidate(tires = [[5, 2], [8, 3], [1, 2]],changeTime = 20,numLaps = 20) == 155\n assert candidate(tires = [[5, 2], [10, 2], [15, 2]],changeTime = 20,numLaps = 1000) == 17480\n assert candidate(tires = [[9, 9], [8, 8], [7, 7], [6, 6], [5, 5]],changeTime = 10,numLaps = 800) == 11990\n assert candidate(tires = [[2, 3], [5, 7], [8, 9]],changeTime = 5,numLaps = 20) == 125\n assert candidate(tires = [[5, 3], [10, 2], [2, 6]],changeTime = 7,numLaps = 15) == 128\n assert candidate(tires = [[5, 2], [3, 3], [4, 4]],changeTime = 10,numLaps = 20) == 210\n assert candidate(tires = [[2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],changeTime = 7,numLaps = 60) == 443\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5]],changeTime = 5,numLaps = 30) == 115\n assert candidate(tires = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]],changeTime = 1,numLaps = 1000) == 1999\n assert candidate(tires = [[50, 50], [25, 25], [10, 10], [5, 5], [2, 2]],changeTime = 25,numLaps = 750) == 9725\n assert candidate(tires = [[100000, 2], [50000, 3]],changeTime = 50000,numLaps = 500) == 49950000\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],changeTime = 5,numLaps = 50) == 195\n assert candidate(tires = [[3, 5], [5, 3], [7, 2]],changeTime = 15,numLaps = 200) == 3285\n assert candidate(tires = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2]],changeTime = 10,numLaps = 200) == 1125\n assert candidate(tires = [[2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],changeTime = 20,numLaps = 800) == 11180\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],changeTime = 5,numLaps = 50) == 195\n assert candidate(tires = [[10, 10], [5, 5], [1, 2]],changeTime = 5,numLaps = 30) == 115\n assert candidate(tires = [[1, 100000], [2, 50000], [3, 25000], [4, 10000], [5, 5000]],changeTime = 100000,numLaps = 1000) == 62402500\n assert candidate(tires = [[10, 10], [20, 20], [30, 30]],changeTime = 15,numLaps = 100) == 2485\n assert candidate(tires = [[1, 10], [2, 20], [3, 30], [4, 40]],changeTime = 100,numLaps = 500) == 27650\n assert candidate(tires = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2]],changeTime = 100,numLaps = 900) == 23480\n assert candidate(tires = [[1000, 1000], [1000, 1000], [1000, 1000]],changeTime = 100000,numLaps = 1000) == 100900000\n assert candidate(tires = [[2, 3], [5, 7], [3, 4]],changeTime = 8,numLaps = 100) == 792\n assert candidate(tires = [[2, 5], [3, 4], [4, 3]],changeTime = 10,numLaps = 100) == 1090\n assert candidate(tires = [[1, 10], [2, 5], [3, 2]],changeTime = 10,numLaps = 999) == 9482\n assert candidate(tires = [[5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],changeTime = 25,numLaps = 1000) == 27475\n assert candidate(tires = [[1, 100], [2, 50], [3, 25], [4, 10]],changeTime = 5,numLaps = 50) == 295\n assert candidate(tires = [[1, 2], [1, 3], [1, 4]],changeTime = 5,numLaps = 50) == 195\n assert candidate(tires = [[7, 2], [6, 3], [5, 4], [4, 5], [3, 6], [2, 7], [1, 8]],changeTime = 8,numLaps = 100) == 842\n assert candidate(tires = [[5, 2], [4, 3], [3, 4], [2, 5]],changeTime = 1,numLaps = 999) == 2996\n assert candidate(tires = [[1000, 100], [500, 50], [250, 25], [100, 10], [50, 5]],changeTime = 500,numLaps = 500) == 199500\n assert candidate(tires = [[2, 2], [3, 3], [4, 4]],changeTime = 10,numLaps = 25) == 190\n assert candidate(tires = [[100, 100], [50, 50], [25, 25], [10, 10]],changeTime = 20,numLaps = 50) == 1480\n assert candidate(tires = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2]],changeTime = 1,numLaps = 1000) == 1999\n assert candidate(tires = [[2, 5], [1, 3], [3, 2], [2, 4]],changeTime = 7,numLaps = 30) == 158\n assert candidate(tires = [[1, 2], [2, 3], [3, 4], [4, 5]],changeTime = 2,numLaps = 100) == 248\n assert candidate(tires = [[1, 2], [1, 2], [1, 2], [1, 2]],changeTime = 10,numLaps = 50) == 275\n assert candidate(tires = [[100000, 100000]],changeTime = 100000,numLaps = 1000) == 199900000\n assert candidate(tires = [[1, 1000], [2, 500], [3, 250]],changeTime = 50,numLaps = 20) == 970\n", "comparison": "exact"}, "public_tests": ["[[2,3],[3,4]]\n5\n4", "[[1,10],[2,2],[3,4]]\n6\n5"], "hints": ["What is the maximum number of times we would want to go around the track without changing tires?", "Can we precompute the minimum time to go around the track x times without changing tires?", "Can we use dynamic programming to solve this efficiently using the precomputed values?"], "metadata": {"canonical_parameter_names": ["tires", "changeTime", "numLaps"], "leetcode_dataset_entry_point": "Solution().minimumFinishTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:14+00:00", "tests_total": 100, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function minimumFinishTime($tires, $changeTime, $numLaps) {", "container": "Solution", "callable": "minimumFinishTime", "parameters": [{"name": "tires", "type": "Integer[][]"}, {"name": "changeTime", "type": "Integer"}, {"name": "numLaps", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2190, "task_id": "most-frequent-number-following-key-in-an-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.\n\nFor every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:\n\n- 0 <= i <= nums.length - 2,\n- nums[i] == key and,\n- nums[i + 1] == target.\n\nReturn the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.\n\nExample 1:\n\nInput: nums = [1,100,200,1,100], key = 1\nOutput: 100\nExplanation: For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.\nNo other integers follow an occurrence of key, so we return 100.\n\nExample 2:\n\nInput: nums = [2,2,2,2,3], key = 2\nOutput: 2\nExplanation: For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.\nFor target = 3, there is only one occurrence at index 4 which follows an occurrence of key.\ntarget = 2 has the maximum number of occurrences following an occurrence of key, so we return 2.\n\nConstraints:\n\n- 2 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n- The test cases will be generated such that the answer is unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],key = 1) == 2\n assert candidate(nums = [1, 2, 2, 3, 2, 1, 2, 4],key = 2) == 2\n assert candidate(nums = [3, 1, 3, 1, 3, 1, 3, 1, 3, 2],key = 1) == 3\n assert candidate(nums = [10, 20, 20, 10, 10, 30, 20, 10],key = 10) == 20\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5],key = 5) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2],key = 1) == 2\n assert candidate(nums = [2, 2, 2, 2, 3],key = 2) == 2\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],key = 5) == 1\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5],key = 5) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3],key = 3) == 3\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3],key = 1) == 2\n assert candidate(nums = [5, 1, 4, 1, 5, 1, 4, 1, 5],key = 1) == 4\n assert candidate(nums = [1, 2, 3, 4, 1, 2, 3, 1, 2, 1],key = 1) == 2\n assert candidate(nums = [1, 3, 2, 3, 2, 1, 3, 2, 1],key = 3) == 2\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4],key = 5) == 1\n assert candidate(nums = [1, 100, 200, 1, 100],key = 1) == 100\n assert candidate(nums = [500, 100, 500, 200, 500, 300, 500, 400, 500, 500, 500, 600],key = 500) == 500\n assert candidate(nums = [666, 111, 666, 222, 666, 333, 666, 444, 666, 555, 666, 111, 666, 222, 666, 333, 666, 444, 666, 555, 666, 111, 666, 222, 666, 333, 666, 444, 666, 555],key = 666) == 111\n assert candidate(nums = [9, 5, 9, 9, 1, 9, 5, 9, 5, 5],key = 9) == 5\n assert candidate(nums = [10, 20, 30, 10, 20, 10, 30, 10, 20, 10, 30, 10, 20, 10, 30],key = 10) == 20\n assert candidate(nums = [11, 22, 33, 44, 11, 22, 33, 44, 11, 22, 33, 44, 11],key = 11) == 22\n assert candidate(nums = [100, 200, 100, 300, 100, 200, 100, 400, 100, 500, 100, 600, 100, 700],key = 100) == 200\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 1, 5, 2, 5, 3, 5, 4, 5, 1, 5, 2],key = 5) == 1\n assert candidate(nums = [7, 8, 9, 7, 8, 7, 9, 7, 8, 7, 8, 7, 8, 7, 9],key = 7) == 8\n assert candidate(nums = [4, 6, 4, 4, 4, 3, 4, 6, 4, 4, 6, 4],key = 4) == 4\n assert candidate(nums = [7, 3, 7, 4, 7, 5, 7, 6, 7, 3, 7, 4],key = 7) == 3\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],key = 5) == 5\n assert candidate(nums = [10, 11, 10, 12, 10, 13, 10, 14, 10, 15, 10, 16, 10, 17, 10, 18],key = 10) == 11\n assert candidate(nums = [8, 2, 8, 3, 8, 4, 8, 5, 8, 6, 8, 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],key = 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],key = 1) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10],key = 1) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],key = 1) == 2\n assert candidate(nums = [99, 88, 77, 66, 55, 99, 88, 77, 66, 55, 99, 88, 77, 66],key = 99) == 88\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1],key = 9) == 1\n assert candidate(nums = [4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11, 4, 12, 4, 13, 4, 14],key = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2],key = 1) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1],key = 1) == 1\n assert candidate(nums = [123, 456, 123, 789, 123, 456, 123, 789, 123, 456, 123, 789, 123, 456, 123, 789, 123, 456, 123, 789, 123, 456, 123, 789, 123, 456, 123, 789],key = 123) == 456\n assert candidate(nums = [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],key = 3) == 3\n assert candidate(nums = [11, 22, 11, 33, 11, 44, 11, 55, 11, 66, 11, 77, 11, 88, 11, 99, 11, 100, 11, 111],key = 11) == 22\n assert candidate(nums = [42, 10, 42, 20, 42, 30, 42, 10, 42, 20, 42, 30, 42, 10],key = 42) == 10\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3],key = 3) == 3\n assert candidate(nums = [3, 3, 3, 4, 4, 4, 3, 4, 3, 4, 3, 3, 4, 3, 3, 3, 4, 3, 3, 3, 3, 4, 3, 3, 3, 4, 3, 3],key = 3) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500],key = 100) == 200\n assert candidate(nums = [3, 7, 3, 8, 3, 7, 3, 8, 3, 9],key = 3) == 7\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100, 200, 300, 100],key = 100) == 200\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990],key = 999) == 998\n assert candidate(nums = [42, 84, 42, 168, 42, 210, 42, 252, 42, 294, 42, 336],key = 42) == 84\n assert candidate(nums = [7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3, 7, 3, 3],key = 7) == 3\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8],key = 7) == 7\n assert candidate(nums = [7, 3, 7, 7, 4, 7, 3, 7, 3, 7, 5],key = 7) == 3\n assert candidate(nums = [9, 3, 9, 5, 9, 3, 9, 5, 9, 2, 9],key = 9) == 3\n assert candidate(nums = [42, 13, 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, 13],key = 42) == 42\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],key = 1) == 2\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10],key = 1) == 2\n assert candidate(nums = [500, 400, 300, 200, 100, 500, 400, 300, 200, 100, 500, 400],key = 500) == 400\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50],key = 10) == 20\n assert candidate(nums = [6, 7, 8, 9, 10, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10, 6],key = 6) == 7\n assert candidate(nums = [3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1, 3, 2, 3, 1],key = 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, 1, 2, 3, 4, 5],key = 5) == 6\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 1, 5, 9],key = 5) == 9\n assert candidate(nums = [8, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 8, 1],key = 8) == 8\n assert candidate(nums = [9, 1, 2, 9, 1, 2, 9, 1, 2, 9, 1, 2, 9, 1],key = 9) == 1\n assert candidate(nums = [999, 1, 999, 2, 999, 3, 999, 4, 999, 5, 999, 1, 999, 2, 999, 3, 999, 4, 999, 5],key = 999) == 1\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],key = 4) == 4\n assert candidate(nums = [100, 200, 300, 100, 100, 200, 100, 300, 100, 200, 100, 300, 100],key = 100) == 200\n assert candidate(nums = [500, 600, 500, 700, 500, 800, 500, 900, 500, 1000],key = 500) == 600\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 5, 5, 6, 6, 6, 5, 6, 6, 6, 5, 6],key = 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],key = 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],key = 1) == 2\n assert candidate(nums = [1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2],key = 1) == 1\n assert candidate(nums = [500, 400, 300, 200, 100, 500, 400, 300, 200, 100, 500, 400, 300, 200, 100, 500, 400, 300, 200, 100],key = 500) == 400\n assert candidate(nums = [200, 300, 200, 300, 200, 300, 200, 300, 200, 300, 200, 300, 200, 300, 200, 300, 200, 300, 200, 200],key = 200) == 300\n assert candidate(nums = [7, 7, 7, 8, 9, 8, 10, 8, 7, 11, 7, 8, 8, 9],key = 7) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 1) == 2\n assert candidate(nums = [10, 1, 10, 2, 10, 3, 10, 4, 10, 5, 10, 6, 10, 7, 10, 8, 10, 9, 10, 1, 10, 2, 10, 3, 10, 4, 10, 5],key = 10) == 1\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60],key = 10) == 20\n assert candidate(nums = [6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],key = 6) == 6\n assert candidate(nums = [3, 1, 9, 3, 1, 9, 3, 1, 9, 10],key = 3) == 1\n assert candidate(nums = [7, 3, 7, 2, 7, 7, 3, 3, 2, 7],key = 7) == 3\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43],key = 42) == 42\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, 1, 2, 1, 2],key = 2) == 1\n assert candidate(nums = [999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000, 999],key = 999) == 1000\n assert candidate(nums = [888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999, 777, 888, 999],key = 888) == 999\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 90],key = 10) == 20\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 100, 200, 300, 400, 500, 600, 700, 800, 900, 100, 100],key = 100) == 200\n assert candidate(nums = [15, 20, 15, 25, 15, 30, 15, 35, 15, 40, 15, 45, 15, 50, 15, 55, 15, 60, 15, 65, 15, 70, 15, 75, 15, 80, 15, 85, 15, 90, 15, 95, 15, 100],key = 15) == 20\n assert candidate(nums = [666, 777, 666, 888, 666, 999, 666, 111, 666, 222, 666, 333, 666, 444, 666, 555],key = 666) == 777\n assert candidate(nums = [555, 666, 555, 666, 555, 666, 555, 666, 555, 666, 555, 666, 555, 666, 555, 666, 555, 666, 555, 777],key = 555) == 666\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 1],key = 1) == 2\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],key = 7) == 7\n assert candidate(nums = [2, 3, 4, 3, 2, 3, 4, 5, 6, 4, 3, 2, 3, 4, 3, 3, 3, 4],key = 3) == 4\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10, 30],key = 10) == 30\n assert candidate(nums = [123, 456, 123, 789, 123, 101, 123, 102, 123, 103, 123, 104],key = 123) == 456\n assert candidate(nums = [100, 200, 100, 300, 400, 500, 600, 100, 700, 800, 900, 100, 100, 100, 100, 100],key = 100) == 100\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9],key = 9) == 8\n assert candidate(nums = [42, 99, 42, 55, 42, 99, 42, 66, 42, 55, 42, 99],key = 42) == 99\n assert candidate(nums = [7, 11, 7, 11, 7, 11, 7, 8, 7, 9],key = 7) == 11\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 50],key = 50) == 100\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10],key = 10) == 20\n assert candidate(nums = [999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 999, 1, 2, 3, 4, 5, 6, 7, 8, 999],key = 999) == 1\n", "comparison": "exact"}, "public_tests": ["[1,100,200,1,100]\n1", "[2,2,2,2,3]\n2"], "hints": ["Count the number of times each target value follows the key in the array.", "Choose the target with the maximum count and return it."], "metadata": {"canonical_parameter_names": ["nums", "key"], "leetcode_dataset_entry_point": "Solution().mostFrequent", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:19+00:00", "tests_total": 103, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function mostFrequent($nums, $key) {", "container": "Solution", "callable": "mostFrequent", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "key", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2191, "task_id": "sort-the-jumbled-numbers", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.\n\nThe mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.\n\nYou are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.\n\nNotes:\n\n- Elements with the same mapped values should appear in the same relative order as in the input.\n- The elements of nums should only be sorted based on their mapped values and not be replaced by them.\n\nExample 1:\n\nInput: mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]\nOutput: [338,38,991]\nExplanation:\nMap the number 991 as follows:\n1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.\n2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.\nTherefore, the mapped value of 991 is 669.\n338 maps to 007, or 7 after removing the leading zeros.\n38 maps to 07, which is also 7 after removing leading zeros.\nSince 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.\nThus, the sorted array is [338,38,991].\n\nExample 2:\n\nInput: mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]\nOutput: [123,456,789]\nExplanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].\n\nConstraints:\n\n- mapping.length == 10\n- 0 <= mapping[i] <= 9\n- All the values of mapping[i] are unique.\n- 1 <= nums.length <= 3 * 10^4\n- 0 <= nums[i] < 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(mapping = [5, 8, 9, 2, 1, 6, 7, 0, 3, 4],nums = [345, 123, 678]) == [345, 678, 123]\n assert candidate(mapping = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5],nums = [10, 100, 1000, 10000]) == [10, 100, 1000, 10000]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [90, 12, 34]) == [90, 12, 34]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [10, 20, 30, 40, 50]) == [10, 20, 30, 40, 50]\n assert candidate(mapping = [8, 9, 4, 0, 2, 1, 3, 5, 7, 6],nums = [991, 338, 38]) == [338, 38, 991]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [10, 20, 30]) == [30, 20, 10]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [123, 456, 789]) == [789, 456, 123]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [90, 81, 72]) == [90, 72, 81]\n assert candidate(mapping = [5, 8, 9, 0, 1, 2, 3, 4, 6, 7],nums = [555, 888, 999]) == [555, 888, 999]\n assert candidate(mapping = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums = [789, 456, 123]) == [123, 456, 789]\n assert candidate(mapping = [5, 8, 1, 2, 9, 4, 6, 0, 3, 7],nums = [512, 345, 890]) == [345, 890, 512]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [100, 200, 300]) == [300, 200, 100]\n assert candidate(mapping = [5, 8, 9, 2, 1, 6, 3, 7, 0, 4],nums = [12, 34, 56, 78, 90]) == [34, 90, 56, 78, 12]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [1234, 5678, 91011]) == [5678, 1234, 91011]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [12345, 67890, 11111]) == [67890, 12345, 11111]\n assert candidate(mapping = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4],nums = [123, 456, 789]) == [789, 123, 456]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [10, 20, 30]) == [10, 20, 30]\n assert candidate(mapping = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8],nums = [13579, 24680, 101010, 202020, 303030, 123123123]) == [13579, 101010, 24680, 303030, 202020, 123123123]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [999999999, 888888888, 777777777, 666666666, 555555555]) == [999999999, 888888888, 777777777, 666666666, 555555555]\n assert candidate(mapping = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8],nums = [999, 888, 777, 666, 555, 444, 333, 222, 111, 0]) == [111, 0, 222, 333, 444, 555, 666, 777, 888, 999]\n assert candidate(mapping = [5, 9, 8, 2, 7, 6, 3, 1, 4, 0],nums = [555, 999, 888, 222, 777, 666, 333, 111, 444, 0]) == [999, 0, 777, 333, 666, 888, 555, 444, 222, 111]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [101010, 202020, 303030, 404040, 505050]) == [505050, 404040, 303030, 202020, 101010]\n assert candidate(mapping = [6, 5, 4, 3, 2, 1, 0, 9, 8, 7],nums = [654321, 123456, 987654]) == [654321, 123456, 987654]\n assert candidate(mapping = [0, 2, 1, 4, 3, 6, 5, 8, 7, 9],nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == [222222222, 123456789, 111111111, 444444444, 333333333, 666666666, 555555555, 888888888, 777777777, 987654321, 999999999]\n assert candidate(mapping = [5, 0, 1, 2, 3, 4, 6, 7, 8, 9],nums = [501234, 55555, 12345]) == [12345, 55555, 501234]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [987654321, 876543210, 765432109]) == [987654321, 765432109, 876543210]\n assert candidate(mapping = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8],nums = [900, 899, 798, 697, 596, 495, 394, 293, 192, 91]) == [91, 192, 293, 394, 495, 596, 697, 798, 899, 900]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 0]) == [999, 0, 111, 222, 333, 444, 555, 666, 777, 888]\n assert candidate(mapping = [2, 1, 4, 3, 6, 5, 8, 7, 0, 9],nums = [24680, 13579, 112233]) == [13579, 24680, 112233]\n assert candidate(mapping = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6],nums = [543210, 109876, 210987, 678905, 432109]) == [543210, 432109, 210987, 109876, 678905]\n assert candidate(mapping = [7, 6, 5, 4, 3, 2, 1, 0, 9, 8],nums = [7654321, 6543210, 5432109, 4321098, 3210987]) == [7654321, 6543210, 5432109, 4321098, 3210987]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [111111111, 222222222, 333333333, 444444444]) == [111111111, 222222222, 333333333, 444444444]\n assert candidate(mapping = [0, 2, 1, 3, 4, 5, 6, 7, 8, 9],nums = [987654321, 123456789]) == [123456789, 987654321]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [123456789, 234567890, 345678901, 456789012]) == [123456789, 234567890, 345678901, 456789012]\n assert candidate(mapping = [0, 2, 1, 4, 3, 6, 5, 8, 7, 9],nums = [123456789, 987654321, 43210]) == [43210, 123456789, 987654321]\n assert candidate(mapping = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],nums = [13579, 24680, 97531, 86420, 12345]) == [97531, 12345, 13579, 24680, 86420]\n assert candidate(mapping = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums = [987654321, 123456789, 111111111]) == [987654321, 123456789, 111111111]\n assert candidate(mapping = [0, 2, 1, 4, 3, 6, 5, 8, 7, 9],nums = [10000, 20001, 30002, 40003, 50004, 60005, 70006, 80007, 90008]) == [20001, 10000, 40003, 30002, 60005, 50004, 80007, 70006, 90008]\n assert candidate(mapping = [2, 0, 4, 6, 8, 1, 3, 5, 7, 9],nums = [123456789, 987654321, 246801357]) == [123456789, 246801357, 987654321]\n assert candidate(mapping = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5],nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == [2222, 4444, 6666, 8888, 9999, 7777, 5555, 3333, 1111]\n assert candidate(mapping = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0],nums = [99999, 88888, 77777, 66666, 55555]) == [99999, 55555, 66666, 77777, 88888]\n assert candidate(mapping = [3, 4, 5, 6, 7, 8, 9, 0, 1, 2],nums = [10000, 10001, 10010, 10100, 11000, 123456789, 987654321]) == [10000, 10001, 10010, 10100, 11000, 987654321, 123456789]\n assert candidate(mapping = [9, 7, 5, 3, 1, 8, 6, 4, 2, 0],nums = [999, 777, 555, 333, 111, 888, 666, 444, 222, 0]) == [999, 0, 444, 888, 333, 777, 222, 666, 111, 555]\n assert candidate(mapping = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9],nums = [13579, 24680, 11111, 22222]) == [11111, 13579, 22222, 24680]\n assert candidate(mapping = [2, 0, 1, 3, 4, 5, 6, 7, 8, 9],nums = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == [21, 22, 20, 23, 24, 25, 26, 27, 28, 29]\n assert candidate(mapping = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9],nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == [888, 777, 666, 555, 444, 333, 222, 111, 999]\n assert candidate(mapping = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8],nums = [1122, 2233, 3344, 4455, 5566]) == [1122, 3344, 2233, 5566, 4455]\n assert candidate(mapping = [8, 6, 4, 2, 0, 9, 7, 5, 3, 1],nums = [24680, 13579, 86420, 97531]) == [97531, 86420, 24680, 13579]\n assert candidate(mapping = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],nums = [1, 10, 100, 1000, 10000, 100000]) == [1, 10, 100, 1000, 10000, 100000]\n assert candidate(mapping = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],nums = [999, 888, 777, 666, 555, 444, 333, 222, 111, 0]) == [999, 0, 111, 222, 333, 444, 555, 666, 777, 888]\n assert candidate(mapping = [2, 0, 9, 1, 5, 6, 3, 8, 4, 7],nums = [1029, 2056, 3084, 4073]) == [1029, 3084, 4073, 2056]\n assert candidate(mapping = [8, 3, 5, 2, 7, 1, 9, 4, 0, 6],nums = [321, 654, 987, 123, 456, 789]) == [321, 123, 789, 987, 456, 654]\n assert candidate(mapping = [9, 0, 8, 1, 7, 2, 6, 3, 5, 4],nums = [999999999, 111111111, 123456789, 987654321, 135792468, 864201357]) == [111111111, 135792468, 123456789, 999999999, 987654321, 864201357]\n assert candidate(mapping = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums = [123456789, 987654321, 111222333]) == [987654321, 123456789, 111222333]\n assert candidate(mapping = [9, 7, 5, 3, 1, 8, 6, 4, 2, 0],nums = [97531, 86420, 13579]) == [97531, 86420, 13579]\n", "comparison": "exact"}, "public_tests": ["[8,9,4,0,2,1,3,5,7,6]\n[991,338,38]", "[0,1,2,3,4,5,6,7,8,9]\n[789,456,123]"], "hints": ["Map the original numbers to new numbers by the mapping rule and sort the new numbers.", "To maintain the same relative order for equal mapped values, use the index in the original input array as a tiebreaker."], "metadata": {"canonical_parameter_names": ["mapping", "nums"], "leetcode_dataset_entry_point": "Solution().sortJumbled", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:21+00:00", "tests_total": 110, "tests_dropped": 55, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "php", "interface": {"raw_signature": "function sortJumbled($mapping, $nums) {", "container": "Solution", "callable": "sortJumbled", "parameters": [{"name": "mapping", "type": "Integer[]"}, {"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2192, "task_id": "all-ancestors-of-a-node-in-a-directed-acyclic-graph", "difficulty": "Medium", "problem_description": "You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).\n\nYou are also given a 2D integer array edges, where edges[i] = [from_i, to_i] denotes that there is a unidirectional edge from from_i to to_i in the graph.\n\nReturn a list answer, where answer[i] is the list of ancestors of the i^th node, sorted in ascending order.\n\nA node u is an ancestor of another node v if u can reach v via a set of edges.\n\nExample 1:\n\nInput: n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]\nOutput: [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]\nExplanation:\nThe above diagram represents the input graph.\n- Nodes 0, 1, and 2 do not have any ancestors.\n- Node 3 has two ancestors 0 and 1.\n- Node 4 has two ancestors 0 and 2.\n- Node 5 has three ancestors 0, 1, and 3.\n- Node 6 has five ancestors 0, 1, 2, 3, and 4.\n- Node 7 has four ancestors 0, 1, 2, and 3.\n\nExample 2:\n\nInput: n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]\nOutput: [[],[0],[0,1],[0,1,2],[0,1,2,3]]\nExplanation:\nThe above diagram represents the input graph.\n- Node 0 does not have any ancestor.\n- Node 1 has one ancestor 0.\n- Node 2 has two ancestors 0 and 1.\n- Node 3 has three ancestors 0, 1, and 2.\n- Node 4 has four ancestors 0, 1, 2, and 3.\n\nConstraints:\n\n- 1 <= n <= 1000\n- 0 <= edges.length <= min(2000, n * (n - 1) / 2)\n- edges[i].length == 2\n- 0 <= from_i, to_i <= n - 1\n- from_i != to_i\n- There are no duplicate edges.\n- The graph is directed and acyclic.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 2], [2, 3], [1, 3], [4, 5]]) == [[], [], [0], [0, 1, 2], [], [4]]\n assert candidate(n = 4,edges = [[0, 1], [1, 2], [2, 3]]) == [[], [0], [0, 1], [0, 1, 2]]\n assert candidate(n = 8,edges = [[0, 3], [0, 4], [1, 3], [2, 4], [2, 7], [3, 5], [3, 6], [3, 7], [4, 6]]) == [[], [], [], [0, 1], [0, 2], [0, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3]]\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2]]\n assert candidate(n = 3,edges = [[0, 1], [0, 2]]) == [[], [0], [0]]\n assert candidate(n = 1,edges = []) == [[]]\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3]]\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]]\n assert candidate(n = 25,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], [14, 20], [15, 21], [16, 22], [17, 23], [18, 24]]) == [[], [0], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 3], [0, 3], [0, 1, 4], [0, 1, 5], [0, 2, 6], [0, 2, 7], [0, 3, 8], [0, 3, 9], [0, 1, 4, 10], [0, 1, 5, 11], [0, 2, 6, 12], [0, 2, 7, 13], [0, 3, 8, 14], [0, 3, 9, 15], [0, 1, 4, 10, 16], [0, 1, 5, 11, 17], [0, 2, 6, 12, 18]]\n assert candidate(n = 12,edges = [[0, 3], [1, 3], [2, 3], [0, 4], [1, 4], [2, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 9], [8, 9], [9, 10], [10, 11]]) == [[], [], [], [0, 1, 2], [0, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(n = 12,edges = [[0, 3], [1, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [6, 9], [7, 10], [8, 10], [9, 11]]) == [[], [], [], [0, 1], [2], [0, 1, 3], [0, 1, 3], [2, 4], [2, 4], [0, 1, 3, 5, 6], [2, 4, 7, 8], [0, 1, 3, 5, 6, 9]]\n assert candidate(n = 14,edges = [[0, 4], [1, 4], [2, 5], [2, 6], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 10], [6, 11], [7, 12], [8, 12], [9, 13], [10, 13], [11, 13]]) == [[], [], [], [], [0, 1], [2], [2, 3], [0, 1, 4], [0, 1, 4], [2, 5], [2, 3, 5, 6], [2, 3, 6], [0, 1, 4, 7, 8], [2, 3, 5, 6, 9, 10, 11]]\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], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(n = 10,edges = [[0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 5], [2, 6], [3, 6], [4, 6], [5, 7], [6, 7], [6, 8], [7, 9], [8, 9]]) == [[], [], [0, 1], [0, 1], [0], [1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\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, 16], [8, 17], [9, 17], [9, 18], [10, 18], [10, 19], [11, 19], [12, 19], [13, 19], [14, 19]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 2, 5], [0, 2, 5], [0, 2, 6], [0, 2, 6], [0, 1, 3, 7], [0, 1, 3, 7, 8], [0, 1, 3, 4, 8, 9], [0, 1, 4, 9, 10], [0, 1, 2, 4, 5, 6, 10, 11, 12, 13, 14]]\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, 11], [7, 8], [8, 9], [9, 10], [10, 11]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3, 7], [0, 1, 3, 4, 7, 8], [0, 1, 3, 4, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(n = 18,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]]) == [[], [0], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 3], [0, 3], [0, 1, 4], [0, 1, 5], [0, 2, 6], [0, 2, 7], [0, 3, 8], [0, 3, 9], [0, 1, 4, 10], [0, 1, 5, 11]]\n assert candidate(n = 10,edges = [[0, 5], [1, 5], [2, 6], [3, 6], [4, 7], [5, 8], [6, 8], [7, 9], [8, 9]]) == [[], [], [], [], [], [0, 1], [2, 3], [4], [0, 1, 2, 3, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\n assert candidate(n = 15,edges = [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [5, 12], [6, 13], [6, 14]]) == [[], [], [], [0, 1, 2], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 2, 4], [0, 1, 2, 3, 5], [0, 1, 2, 3, 5], [0, 1, 2, 3, 6], [0, 1, 2, 3, 6]]\n assert candidate(n = 18,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 5], [2, 6], [3, 6], [3, 7], [4, 8], [5, 8], [5, 9], [6, 9], [6, 10], [7, 10], [8, 11], [9, 11], [9, 12], [10, 12], [11, 13], [12, 13], [12, 14], [13, 15], [14, 15], [14, 16], [15, 17]]) == [[], [0], [0], [0], [0, 1], [0, 1, 2], [0, 2, 3], [0, 3], [0, 1, 2, 4, 5], [0, 1, 2, 3, 5, 6], [0, 2, 3, 6, 7], [0, 1, 2, 3, 4, 5, 6, 8, 9], [0, 1, 2, 3, 5, 6, 7, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [0, 1, 2, 3, 5, 6, 7, 9, 10, 12], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [0, 1, 2, 3, 5, 6, 7, 9, 10, 12, 14], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 7], [4, 9], [5, 8], [5, 10], [6, 9], [6, 10], [7, 11], [8, 11], [9, 11], [10, 11], [11, 12], [11, 13], [12, 14], [12, 15], [13, 14], [13, 16], [14, 17], [15, 17], [15, 18], [16, 18], [16, 19], [17, 19], [18, 19]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3, 4], [0, 1, 2, 3, 5], [0, 1, 2, 4, 6], [0, 2, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [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], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]]\n assert candidate(n = 20,edges = [[0, 5], [0, 10], [0, 15], [1, 5], [1, 6], [2, 6], [2, 7], [3, 7], [3, 8], [4, 8], [4, 9], [5, 10], [5, 11], [6, 11], [6, 12], [7, 12], [7, 13], [8, 13], [8, 14], [9, 14], [10, 15], [10, 16], [11, 16], [11, 17], [12, 17], [12, 18], [13, 18], [13, 19], [14, 19]]) == [[], [], [], [], [], [0, 1], [1, 2], [2, 3], [3, 4], [4], [0, 1, 5], [0, 1, 2, 5, 6], [1, 2, 3, 6, 7], [2, 3, 4, 7, 8], [3, 4, 8, 9], [0, 1, 5, 10], [0, 1, 2, 5, 6, 10, 11], [0, 1, 2, 3, 5, 6, 7, 11, 12], [1, 2, 3, 4, 6, 7, 8, 12, 13], [2, 3, 4, 7, 8, 9, 13, 14]]\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, 11], [7, 8], [8, 9], [9, 10]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3, 7], [0, 1, 3, 4, 7, 8], [0, 1, 3, 4, 7, 8, 9], [0, 2, 5, 6]]\n assert candidate(n = 15,edges = [[0, 5], [0, 6], [1, 5], [1, 7], [2, 6], [2, 8], [3, 7], [3, 9], [4, 8], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14]]) == [[], [], [], [], [], [0, 1], [0, 2], [1, 3], [2, 4], [3], [4], [0, 1, 5], [0, 2, 6], [1, 3, 7], [2, 4, 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]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 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], [0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [1, 8], [1, 9], [2, 9]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\n assert candidate(n = 9,edges = [[0, 1], [0, 4], [0, 5], [1, 2], [1, 3], [2, 4], [2, 6], [3, 5], [3, 7], [4, 6], [4, 8], [5, 7], [6, 8], [7, 8]]) == [[], [0], [0, 1], [0, 1], [0, 1, 2], [0, 1, 3], [0, 1, 2, 4], [0, 1, 3, 5], [0, 1, 2, 3, 4, 5, 6, 7]]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 8], [5, 9], [6, 9]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3, 4], [0, 2, 5, 6]]\n assert candidate(n = 16,edges = [[0, 3], [1, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 10], [6, 11], [7, 12], [8, 12], [9, 13], [10, 13], [10, 14], [11, 14], [12, 15], [13, 15], [14, 15]]) == [[], [], [], [0, 1], [2], [0, 1, 3], [0, 1, 3], [2, 4], [2, 4], [0, 1, 3, 5], [0, 1, 3, 5, 6], [0, 1, 3, 6], [2, 4, 7, 8], [0, 1, 3, 5, 6, 9, 10], [0, 1, 3, 5, 6, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 3], [2, 4], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6], [5, 7], [6, 7], [6, 8], [7, 8], [7, 9], [8, 9]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\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], [7, 9], [8, 9]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\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, 10], [5, 11], [6, 12], [6, 13], [7, 12], [7, 13], [8, 14], [9, 14], [10, 14], [11, 14], [12, 14], [13, 14]]) == [[], [0], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 3], [0, 3], [0, 1, 4, 5], [0, 1, 4, 5], [0, 2, 6, 7], [0, 2, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]\n assert candidate(n = 12,edges = [[0, 3], [0, 4], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 11], [8, 11], [9, 10], [10, 11]]) == [[], [], [], [0, 1], [0, 1], [2], [2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 2, 4, 5, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\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], [10, 19], [11, 19], [12, 19], [13, 19], [14, 19]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 2, 5], [0, 2, 5], [0, 2, 6], [0, 2, 6], [0, 1, 3, 7], [0, 1, 3, 7], [0, 1, 3, 8], [0, 1, 3, 8], [0, 1, 2, 4, 5, 6, 9, 10, 11, 12, 13, 14]]\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], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 2, 5]]\n assert candidate(n = 30,edges = [[0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20], [6, 21], [7, 22], [8, 23], [9, 24], [10, 25], [11, 26], [12, 27], [13, 28], [14, 29], [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], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [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, 14]]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 8], [4, 9], [5, 9], [6, 9]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3, 4], [0, 1, 2, 4, 5, 6]]\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [5, 6]]) == [[], [0], [0, 1], [0, 1], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 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]]) == [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]\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], [7, 11], [8, 12], [9, 13], [10, 13]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 1, 2, 3, 5, 7], [0, 1, 2, 3, 5, 8], [0, 1, 2, 4, 6, 9, 10]]\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 5], [4, 5], [5, 6], [5, 7], [6, 8], [7, 8]]) == [[], [0], [0], [0, 1, 2], [0, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6, 7]]\n assert candidate(n = 10,edges = [[0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 5], [3, 6], [4, 5], [4, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 9], [8, 9]]) == [[], [], [0, 1], [0, 1], [0, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\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], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 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]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 2, 5], [0, 2, 5], [0, 2, 6], [0, 2, 6]]\n assert candidate(n = 15,edges = [[0, 5], [0, 6], [1, 6], [1, 7], [2, 7], [2, 8], [3, 8], [3, 9], [4, 9], [4, 10], [5, 11], [6, 11], [7, 12], [8, 12], [9, 13], [10, 13], [11, 14], [12, 14]]) == [[], [], [], [], [], [0], [0, 1], [1, 2], [2, 3], [3, 4], [4], [0, 1, 5, 6], [1, 2, 3, 7, 8], [3, 4, 9, 10], [0, 1, 2, 3, 5, 6, 7, 8, 11, 12]]\n assert candidate(n = 20,edges = [[0, 5], [0, 6], [1, 7], [1, 8], [2, 9], [2, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [6, 15], [7, 16], [8, 16], [9, 17], [10, 17], [11, 18], [12, 18], [13, 19], [14, 19], [15, 19], [16, 19], [17, 19], [18, 19]]) == [[], [], [], [], [], [0], [0], [1], [1], [2], [2], [3], [3], [4], [4], [0, 5, 6], [1, 7, 8], [2, 9, 10], [3, 11, 12], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]]\n assert candidate(n = 15,edges = [[0, 5], [1, 5], [1, 6], [2, 7], [2, 8], [3, 8], [3, 9], [4, 9], [4, 10], [5, 11], [5, 12], [6, 12], [7, 13], [7, 14], [8, 14], [9, 14]]) == [[], [], [], [], [], [0, 1], [1], [2], [2, 3], [3, 4], [4], [0, 1, 5], [0, 1, 5, 6], [2, 7], [2, 3, 4, 7, 8, 9]]\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8], [7, 8]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3, 4], [0, 1, 2, 3, 4, 5, 6, 7]]\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 3], [2, 5], [3, 6], [4, 6], [4, 7], [5, 7], [6, 8], [7, 8]]) == [[], [0], [0], [0, 1, 2], [0, 1], [0, 2], [0, 1, 2, 3, 4], [0, 1, 2, 4, 5], [0, 1, 2, 3, 4, 5, 6, 7]]\n assert candidate(n = 12,edges = [[0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 8], [6, 9], [7, 9], [8, 10], [9, 10], [10, 11]]) == [[], [], [], [], [0], [1], [2], [3], [0, 1, 4, 5], [2, 3, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [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], [7, 11], [8, 12]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3], [0, 1, 3], [0, 1, 4], [0, 1, 4], [0, 1, 2, 3, 5, 7], [0, 1, 2, 3, 5, 8], [0, 2, 6], [0, 2, 6]]\n assert candidate(n = 20,edges = [[0, 5], [0, 6], [1, 7], [1, 8], [2, 9], [2, 10], [3, 11], [3, 12], [4, 13], [4, 14], [5, 15], [5, 16], [6, 17], [6, 18], [7, 19], [8, 19], [9, 19], [10, 19], [11, 19], [12, 19], [13, 19], [14, 19]]) == [[], [], [], [], [], [0], [0], [1], [1], [2], [2], [3], [3], [4], [4], [0, 5], [0, 5], [0, 6], [0, 6], [1, 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14]]\n assert candidate(n = 20,edges = [[0, 5], [1, 5], [2, 6], [3, 6], [4, 7], [5, 8], [5, 9], [6, 10], [6, 11], [7, 12], [8, 13], [9, 13], [10, 14], [10, 15], [11, 14], [12, 15], [13, 16], [13, 17], [14, 18], [14, 19], [15, 18], [16, 19]]) == [[], [], [], [], [], [0, 1], [2, 3], [4], [0, 1, 5], [0, 1, 5], [2, 3, 6], [2, 3, 6], [4, 7], [0, 1, 5, 8, 9], [2, 3, 6, 10, 11], [2, 3, 4, 6, 7, 10, 12], [0, 1, 5, 8, 9, 13], [0, 1, 5, 8, 9, 13], [2, 3, 4, 6, 7, 10, 11, 12, 14, 15], [0, 1, 2, 3, 5, 6, 8, 9, 10, 11, 13, 14, 16]]\n assert candidate(n = 10,edges = [[0, 5], [0, 6], [1, 5], [1, 7], [2, 6], [2, 8], [3, 7], [3, 9], [4, 8], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9]]) == [[], [], [], [], [], [0, 1], [0, 2], [1, 3], [2, 4], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\n assert candidate(n = 20,edges = [[0, 10], [1, 10], [2, 10], [3, 11], [4, 11], [5, 11], [6, 12], [7, 12], [8, 12], [9, 13], [10, 14], [11, 14], [12, 14], [13, 15], [14, 16], [15, 17], [16, 18], [17, 19]]) == [[], [], [], [], [], [], [], [], [], [], [0, 1, 2], [3, 4, 5], [6, 7, 8], [9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], [9, 13], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 14], [9, 13, 15], [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 14, 16], [9, 13, 15, 17]]\n assert candidate(n = 11,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 7], [4, 9], [5, 8], [5, 10], [6, 9], [6, 10], [7, 10], [8, 10], [9, 10]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3, 4], [0, 1, 2, 3, 5], [0, 1, 2, 4, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n assert candidate(n = 20,edges = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [0, 2], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9], [], [0, 1, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1], [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, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 5], [2, 6], [3, 6], [4, 7], [5, 7], [6, 7], [7, 8], [8, 9]]) == [[], [0], [0], [0], [0, 1], [0, 1, 2], [0, 2, 3], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8]]\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 7], [4, 8], [5, 9], [5, 10], [6, 9], [6, 10], [7, 11], [8, 11], [9, 11], [10, 11]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3, 4], [0, 1, 3, 4], [0, 2, 5, 6], [0, 2, 5, 6], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 8], [6, 8], [7, 9]]) == [[], [0], [0], [0, 1], [0, 1], [0, 2], [0, 2], [0, 1, 3, 4], [0, 2, 5, 6], [0, 1, 3, 4, 7]]\n assert candidate(n = 25,edges = [[0, 12], [0, 13], [1, 12], [1, 13], [2, 14], [2, 15], [3, 15], [3, 16], [4, 16], [4, 17], [5, 17], [5, 18], [6, 18], [6, 19], [7, 19], [7, 20], [8, 20], [8, 21], [9, 21], [9, 22], [10, 22], [10, 23], [11, 23], [11, 24]]) == [[], [], [], [], [], [], [], [], [], [], [], [], [0, 1], [0, 1], [2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11]]\n assert candidate(n = 20,edges = [[0, 10], [0, 11], [1, 10], [1, 11], [2, 12], [2, 13], [3, 13], [3, 14], [4, 14], [4, 15], [5, 15], [5, 16], [6, 16], [6, 17], [7, 17], [7, 18], [8, 18], [8, 19], [9, 19]]) == [[], [], [], [], [], [], [], [], [], [], [0, 1], [0, 1], [2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]\n assert candidate(n = 12,edges = [[0, 5], [0, 6], [1, 6], [1, 7], [2, 7], [2, 8], [3, 8], [3, 9], [4, 9], [5, 10], [6, 10], [7, 10], [8, 11], [9, 11], [10, 11]]) == [[], [], [], [], [], [0], [0, 1], [1, 2], [2, 3], [3, 4], [0, 1, 2, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n", "comparison": "exact"}, "public_tests": ["8\n[[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]", "5\n[[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]"], "hints": ["Consider how reversing each edge of the graph can help us.", "How can performing BFS/DFS on the reversed graph help us find the ancestors of every node?"], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().getAncestors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:24+00:00", "tests_total": 63, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "graph", "topological-sort", "directed-acyclic-graph"]}, "language": "php", "interface": {"raw_signature": "function getAncestors($n, $edges) {", "container": "Solution", "callable": "getAncestors", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2193, "task_id": "minimum-number-of-moves-to-make-palindrome", "difficulty": "Hard", "problem_description": "You are given a string s consisting only of lowercase English letters.\n\nIn one move, you can select any two adjacent characters of s and swap them.\n\nReturn the minimum number of moves needed to make s a palindrome.\n\nNote that the input will be generated such that s can always be converted to a palindrome.\n\nExample 1:\n\nInput: s = \"aabb\"\nOutput: 2\nExplanation:\nWe can obtain two palindromes from s, \"abba\" and \"baab\".\n- We can obtain \"abba\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"abba\".\n- We can obtain \"baab\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"baab\".\nThus, the minimum number of moves needed to make s a palindrome is 2.\n\nExample 2:\n\nInput: s = \"letelt\"\nOutput: 2\nExplanation:\nOne of the palindromes we can obtain from s in 2 moves is \"lettel\".\nOne of the ways we can obtain it is \"letelt\" -> \"letetl\" -> \"lettel\".\nOther palindromes such as \"tleelt\" can also be obtained in 2 moves.\nIt can be shown that it is not possible to obtain a palindrome in less than 2 moves.\n\nConstraints:\n\n- 1 <= s.length <= 2000\n- s consists only of lowercase English letters.\n- s can be converted to a palindrome using a finite number of moves.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcba\") == 0\n assert candidate(s = \"letelt\") == 2\n assert candidate(s = \"abcdcba\") == 0\n assert candidate(s = \"aabbaa\") == 0\n assert candidate(s = \"abcdedcba\") == 0\n assert candidate(s = \"mamad\") == 3\n assert candidate(s = \"aabbc\") == 4\n assert candidate(s = \"aabb\") == 2\n assert candidate(s = \"racecar\") == 0\n assert candidate(s = \"abcdefgfedcba\") == 0\n assert candidate(s = \"noon\") == 0\n assert candidate(s = \"deeee\") == 2\n assert candidate(s = \"nnnnn\") == 0\n assert candidate(s = \"aabbcc\") == 6\n assert candidate(s = \"elvtoelvtoe\") == 6\n assert candidate(s = \"aabbab\") == 3\n assert candidate(s = \"asflkj\") == 5\n assert candidate(s = \"abca\") == 1\n assert candidate(s = \"abcdefghgfedcba\") == 0\n assert candidate(s = \"zzzyzzyzz\") == 1\n assert candidate(s = \"noonappa\") == 8\n assert candidate(s = \"abcdcbad\") == 3\n assert candidate(s = \"aabaaabbaaaaaabbbbaa\") == 11\n assert candidate(s = \"aabbaabbaabb\") == 6\n assert candidate(s = \"jlvaj\") == 1\n assert candidate(s = \"xyzyzyzyzyx\") == 0\n assert candidate(s = \"qpwoeirutoip\") == 12\n assert candidate(s = \"abbbacaba\") == 3\n assert candidate(s = \"abcabcabcabc\") == 6\n assert candidate(s = \"noonnoon\") == 0\n assert candidate(s = \"aaaaabbbb\") == 10\n assert candidate(s = \"mnopqponmlkjihgfedcbaaaabbbccc\") == 161\n assert candidate(s = \"aabbccddeeefffgggggffffeeeeddccbaaabb\") == 37\n assert candidate(s = \"lplllp\") == 1\n assert candidate(s = \"aabbbbaaa\") == 2\n assert candidate(s = \"aaabbbcccdddcccbbaaa\") == 5\n assert candidate(s = \"mmnmm\") == 0\n assert candidate(s = \"mnvovnm\") == 0\n assert candidate(s = \"aabbccddeee\") == 24\n assert candidate(s = \"xyzzyx\") == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmmlkjhgfdsapoiuytrewq\") == 9\n assert candidate(s = \"aabbaabbaabbaabb\") == 8\n assert candidate(s = \"abcdddcb\") == 4\n assert candidate(s = \"abcdxyzzyxcba\") == 3\n assert candidate(s = \"aabbccddeeeeddcbaabbaa\") == 22\n assert candidate(s = \"aabbccddeeefffgggghhhggggfffeeeedddccbbaa\") == 20\n assert candidate(s = \"aaaabbbbccccddddeeeeffffggggggg\") == 204\n assert candidate(s = \"ppqqrrssrqqpp\") == 1\n assert candidate(s = \"aaabbbb\") == 6\n assert candidate(s = \"abcdedcbaa\") == 4\n assert candidate(s = \"aabbccddeeffeecdccbbaa\") == 7\n assert candidate(s = \"aabbccddeeefffggggffffeeeeddccbaaabb\") == 38\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(s = \"abcdeedcba\") == 0\n assert candidate(s = \"abacabad\") == 4\n assert candidate(s = \"xyzyxzyxzyxzyx\") == 2\n assert candidate(s = \"aaabbbaaa\") == 0\n assert candidate(s = \"aabbabaa\") == 1\n assert candidate(s = \"abcbaabcba\") == 0\n assert candidate(s = \"zazbzazbzaz\") == 0\n assert candidate(s = \"abcdeffedcba\") == 0\n assert candidate(s = \"abcbca\") == 1\n assert candidate(s = \"abcdefedcba\") == 0\n assert candidate(s = \"aabbccdd\") == 12\n assert candidate(s = \"level\") == 0\n assert candidate(s = \"abcabcba\") == 1\n assert candidate(s = \"aaaabbbb\") == 8\n assert candidate(s = \"madam\") == 0\n assert candidate(s = \"aabababaab\") == 3\n assert candidate(s = \"aabccbaa\") == 0\n assert candidate(s = \"abacabadabacaba\") == 0\n assert candidate(s = \"aabbccddeeeffffgggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwxxyyzz\") == 1192\n assert candidate(s = \"qwertewq\") == 1\n assert candidate(s = \"qwertytrewq\") == 0\n assert candidate(s = \"abcbad\") == 3\n assert candidate(s = \"abbaaccdaabb\") == 5\n assert candidate(s = \"aababbaaabbbbbaaaaa\") == 8\n assert candidate(s = \"aabaaa\") == 1\n assert candidate(s = \"aaabaaaabbaa\") == 4\n assert candidate(s = \"xyzyzyx\") == 0\n assert candidate(s = \"abccba\") == 0\n assert candidate(s = \"zxcvbnmlkjhgfdasqwertyuiopoiuytrewqasdfghjklmnbvcxz\") == 1\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbbaaaaaaaaa\") == 6\n assert candidate(s = \"aabbccddeeeeddcbbbaa\") == 10\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 650\n assert candidate(s = \"aabbabba\") == 2\n assert candidate(s = \"mmnnllkkjjiihhggffeeddccbbaa\") == 182\n assert candidate(s = \"aaaaabbbaaaa\") == 2\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"nnnmmmnnn\") == 0\n assert candidate(s = \"repaper\") == 0\n assert candidate(s = \"abacdfgdcaba\") == 1\n assert candidate(s = \"aabbccddeeefffgggfhheeeddccbaa\") == 22\n assert candidate(s = \"abbaabba\") == 0\n assert candidate(s = \"zyxzyzyx\") == 4\n assert candidate(s = \"abcddcba\") == 0\n assert candidate(s = \"rotor\") == 0\n assert candidate(s = \"abcdefghihgfedcba\") == 0\n assert candidate(s = \"aabbccddeeeffggffeeddccbbaa\") == 3\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaedcba\") == 115\n assert candidate(s = \"aabbccddeeeffffgggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz\") == 1311\n assert candidate(s = \"levellol\") == 6\n assert candidate(s = \"mississippi\") == 13\n assert candidate(s = \"abcdeffgfedcba\") == 1\n assert candidate(s = \"aabbccddeedcbaa\") == 6\n", "comparison": "exact"}, "public_tests": ["\"aabb\"", "\"letelt\""], "hints": ["Consider a greedy strategy.", "Let’s start by making the leftmost and rightmost characters match with some number of swaps.", "If we figure out how to do that using the minimum number of swaps, then we can delete the leftmost and rightmost characters and solve the problem recursively."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().minMovesToMakePalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:26+00:00", "tests_total": 105, "tests_dropped": 0, "flags": [], "topic_tags": ["two-pointers", "string", "greedy", "binary-indexed-tree"]}, "language": "php", "interface": {"raw_signature": "function minMovesToMakePalindrome($s) {", "container": "Solution", "callable": "minMovesToMakePalindrome", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2194, "task_id": "cells-in-a-range-on-an-excel-sheet", "difficulty": "Easy", "problem_description": "A cell (r, c) of an excel sheet is represented as a string \" \" where:\n\n-
denotes the column number c of the cell. It is represented by alphabetical letters.\n - For example, the 1^st column is denoted by 'A', the 2^nd by 'B', the 3^rd by 'C', and so on.\n- is the row number r of the cell. The r^th row is represented by the integer r.\n\nYou are given a string s in the format \"
: \", where represents the column c1, represents the row r1, represents the column c2, and represents the row r2, such that r1 <= r2 and c1 <= c2.\n\nReturn the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.\n\nExample 1:\n\nInput: s = \"K1:L2\"\nOutput: [\"K1\",\"K2\",\"L1\",\"L2\"]\nExplanation:\nThe above diagram shows the cells which should be present in the list.\nThe red arrows denote the order in which the cells should be presented.\n\nExample 2:\n\nInput: s = \"A1:F1\"\nOutput: [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\nExplanation:\nThe above diagram shows the cells which should be present in the list.\nThe red arrow denotes the order in which the cells should be presented.\n\nConstraints:\n\n- s.length == 5\n- 'A' <= s[0] <= s[3] <= 'Z'\n- '1' <= s[1] <= s[4] <= '9'\n- s consists of uppercase English letters, digits and ':'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"D4:H6\") == ['D4', 'D5', 'D6', 'E4', 'E5', 'E6', 'F4', 'F5', 'F6', 'G4', 'G5', 'G6', 'H4', 'H5', 'H6']\n assert candidate(s = \"K1:L2\") == ['K1', 'K2', 'L1', 'L2']\n assert candidate(s = \"A1:F1\") == ['A1', 'B1', 'C1', 'D1', 'E1', 'F1']\n assert candidate(s = \"B2:D3\") == ['B2', 'B3', 'C2', 'C3', 'D2', 'D3']\n assert candidate(s = \"Z1:Z9\") == ['Z1', 'Z2', 'Z3', 'Z4', 'Z5', 'Z6', 'Z7', 'Z8', 'Z9']\n assert candidate(s = \"Z1:Z5\") == ['Z1', 'Z2', 'Z3', 'Z4', 'Z5']\n assert candidate(s = \"A1:A1\") == ['A1']\n assert candidate(s = \"B2:C3\") == ['B2', 'B3', 'C2', 'C3']\n assert candidate(s = \"Y2:Z8\") == ['Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7', 'Y8', 'Z2', 'Z3', 'Z4', 'Z5', 'Z6', 'Z7', 'Z8']\n assert candidate(s = \"L2:W7\") == ['L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7']\n assert candidate(s = \"Y5:Z8\") == ['Y5', 'Y6', 'Y7', 'Y8', 'Z5', 'Z6', 'Z7', 'Z8']\n assert candidate(s = \"T1:U8\") == ['T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8']\n assert candidate(s = \"D5:D5\") == ['D5']\n assert candidate(s = \"J2:L3\") == ['J2', 'J3', 'K2', 'K3', 'L2', 'L3']\n assert candidate(s = \"A1:Z9\") == ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9', 'J1', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'J9', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'O1', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'O8', 'O9', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'Y1', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7', 'Y8', 'Y9', 'Z1', 'Z2', 'Z3', 'Z4', 'Z5', 'Z6', 'Z7', 'Z8', 'Z9']\n assert candidate(s = \"S1:T7\") == ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7']\n assert candidate(s = \"M3:P7\") == ['M3', 'M4', 'M5', 'M6', 'M7', 'N3', 'N4', 'N5', 'N6', 'N7', 'O3', 'O4', 'O5', 'O6', 'O7', 'P3', 'P4', 'P5', 'P6', 'P7']\n assert candidate(s = \"F4:H7\") == ['F4', 'F5', 'F6', 'F7', 'G4', 'G5', 'G6', 'G7', 'H4', 'H5', 'H6', 'H7']\n assert candidate(s = \"Q1:Z2\") == ['Q1', 'Q2', 'R1', 'R2', 'S1', 'S2', 'T1', 'T2', 'U1', 'U2', 'V1', 'V2', 'W1', 'W2', 'X1', 'X2', 'Y1', 'Y2', 'Z1', 'Z2']\n assert candidate(s = \"M1:N6\") == ['M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6']\n assert candidate(s = \"M3:N4\") == ['M3', 'M4', 'N3', 'N4']\n assert candidate(s = \"T2:U5\") == ['T2', 'T3', 'T4', 'T5', 'U2', 'U3', 'U4', 'U5']\n assert candidate(s = \"N3:O5\") == ['N3', 'N4', 'N5', 'O3', 'O4', 'O5']\n assert candidate(s = \"G1:V9\") == ['G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9', 'J1', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'J9', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'O1', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'O8', 'O9', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9']\n assert candidate(s = \"D1:D9\") == ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9']\n assert candidate(s = \"R1:T4\") == ['R1', 'R2', 'R3', 'R4', 'S1', 'S2', 'S3', 'S4', 'T1', 'T2', 'T3', 'T4']\n assert candidate(s = \"Y1:Z2\") == ['Y1', 'Y2', 'Z1', 'Z2']\n assert candidate(s = \"I2:J5\") == ['I2', 'I3', 'I4', 'I5', 'J2', 'J3', 'J4', 'J5']\n assert candidate(s = \"E3:G7\") == ['E3', 'E4', 'E5', 'E6', 'E7', 'F3', 'F4', 'F5', 'F6', 'F7', 'G3', 'G4', 'G5', 'G6', 'G7']\n assert candidate(s = \"V5:X8\") == ['V5', 'V6', 'V7', 'V8', 'W5', 'W6', 'W7', 'W8', 'X5', 'X6', 'X7', 'X8']\n assert candidate(s = \"N5:N9\") == ['N5', 'N6', 'N7', 'N8', 'N9']\n assert candidate(s = \"X1:Y2\") == ['X1', 'X2', 'Y1', 'Y2']\n assert candidate(s = \"F3:K8\") == ['F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8']\n assert candidate(s = \"J2:T6\") == ['J2', 'J3', 'J4', 'J5', 'J6', 'K2', 'K3', 'K4', 'K5', 'K6', 'L2', 'L3', 'L4', 'L5', 'L6', 'M2', 'M3', 'M4', 'M5', 'M6', 'N2', 'N3', 'N4', 'N5', 'N6', 'O2', 'O3', 'O4', 'O5', 'O6', 'P2', 'P3', 'P4', 'P5', 'P6', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'R2', 'R3', 'R4', 'R5', 'R6', 'S2', 'S3', 'S4', 'S5', 'S6', 'T2', 'T3', 'T4', 'T5', 'T6']\n assert candidate(s = \"X1:X9\") == ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9']\n assert candidate(s = \"D1:G3\") == ['D1', 'D2', 'D3', 'E1', 'E2', 'E3', 'F1', 'F2', 'F3', 'G1', 'G2', 'G3']\n assert candidate(s = \"A1:Z1\") == ['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1', 'M1', 'N1', 'O1', 'P1', 'Q1', 'R1', 'S1', 'T1', 'U1', 'V1', 'W1', 'X1', 'Y1', 'Z1']\n assert candidate(s = \"T1:U5\") == ['T1', 'T2', 'T3', 'T4', 'T5', 'U1', 'U2', 'U3', 'U4', 'U5']\n assert candidate(s = \"B1:Z9\") == ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9', 'J1', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'J9', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'O1', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'O8', 'O9', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'Y1', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7', 'Y8', 'Y9', 'Z1', 'Z2', 'Z3', 'Z4', 'Z5', 'Z6', 'Z7', 'Z8', 'Z9']\n assert candidate(s = \"P1:S4\") == ['P1', 'P2', 'P3', 'P4', 'Q1', 'Q2', 'Q3', 'Q4', 'R1', 'R2', 'R3', 'R4', 'S1', 'S2', 'S3', 'S4']\n assert candidate(s = \"R2:S6\") == ['R2', 'R3', 'R4', 'R5', 'R6', 'S2', 'S3', 'S4', 'S5', 'S6']\n assert candidate(s = \"M1:N1\") == ['M1', 'N1']\n assert candidate(s = \"G2:H2\") == ['G2', 'H2']\n assert candidate(s = \"C2:Y7\") == ['C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7']\n assert candidate(s = \"X3:Y7\") == ['X3', 'X4', 'X5', 'X6', 'X7', 'Y3', 'Y4', 'Y5', 'Y6', 'Y7']\n assert candidate(s = \"C3:D7\") == ['C3', 'C4', 'C5', 'C6', 'C7', 'D3', 'D4', 'D5', 'D6', 'D7']\n assert candidate(s = \"C1:D5\") == ['C1', 'C2', 'C3', 'C4', 'C5', 'D1', 'D2', 'D3', 'D4', 'D5']\n assert candidate(s = \"A1:X9\") == ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'I9', 'J1', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7', 'J8', 'J9', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'N1', 'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'O1', 'O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'O8', 'O9', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9']\n assert candidate(s = \"H8:H8\") == ['H8']\n assert candidate(s = \"G7:H9\") == ['G7', 'G8', 'G9', 'H7', 'H8', 'H9']\n assert candidate(s = \"Y1:Z3\") == ['Y1', 'Y2', 'Y3', 'Z1', 'Z2', 'Z3']\n assert candidate(s = \"X1:Y6\") == ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'Y1', 'Y2', 'Y3', 'Y4', 'Y5', 'Y6']\n assert candidate(s = \"D1:F9\") == ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9']\n assert candidate(s = \"B4:E8\") == ['B4', 'B5', 'B6', 'B7', 'B8', 'C4', 'C5', 'C6', 'C7', 'C8', 'D4', 'D5', 'D6', 'D7', 'D8', 'E4', 'E5', 'E6', 'E7', 'E8']\n assert candidate(s = \"D5:H7\") == ['D5', 'D6', 'D7', 'E5', 'E6', 'E7', 'F5', 'F6', 'F7', 'G5', 'G6', 'G7', 'H5', 'H6', 'H7']\n assert candidate(s = \"X1:Z1\") == ['X1', 'Y1', 'Z1']\n assert candidate(s = \"S1:Z3\") == ['S1', 'S2', 'S3', 'T1', 'T2', 'T3', 'U1', 'U2', 'U3', 'V1', 'V2', 'V3', 'W1', 'W2', 'W3', 'X1', 'X2', 'X3', 'Y1', 'Y2', 'Y3', 'Z1', 'Z2', 'Z3']\n assert candidate(s = \"I5:K7\") == ['I5', 'I6', 'I7', 'J5', 'J6', 'J7', 'K5', 'K6', 'K7']\n assert candidate(s = \"J1:K5\") == ['J1', 'J2', 'J3', 'J4', 'J5', 'K1', 'K2', 'K3', 'K4', 'K5']\n assert candidate(s = \"M5:T8\") == ['M5', 'M6', 'M7', 'M8', 'N5', 'N6', 'N7', 'N8', 'O5', 'O6', 'O7', 'O8', 'P5', 'P6', 'P7', 'P8', 'Q5', 'Q6', 'Q7', 'Q8', 'R5', 'R6', 'R7', 'R8', 'S5', 'S6', 'S7', 'S8', 'T5', 'T6', 'T7', 'T8']\n assert candidate(s = \"A2:A9\") == ['A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9']\n assert candidate(s = \"J2:L5\") == ['J2', 'J3', 'J4', 'J5', 'K2', 'K3', 'K4', 'K5', 'L2', 'L3', 'L4', 'L5']\n assert candidate(s = \"G5:I8\") == ['G5', 'G6', 'G7', 'G8', 'H5', 'H6', 'H7', 'H8', 'I5', 'I6', 'I7', 'I8']\n assert candidate(s = \"A3:C6\") == ['A3', 'A4', 'A5', 'A6', 'B3', 'B4', 'B5', 'B6', 'C3', 'C4', 'C5', 'C6']\n assert candidate(s = \"Q1:R9\") == ['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9']\n assert candidate(s = \"X5:Z9\") == ['X5', 'X6', 'X7', 'X8', 'X9', 'Y5', 'Y6', 'Y7', 'Y8', 'Y9', 'Z5', 'Z6', 'Z7', 'Z8', 'Z9']\n assert candidate(s = \"T1:U4\") == ['T1', 'T2', 'T3', 'T4', 'U1', 'U2', 'U3', 'U4']\n assert candidate(s = \"A1:A9\") == ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9']\n assert candidate(s = \"F1:F9\") == ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9']\n assert candidate(s = \"M5:O8\") == ['M5', 'M6', 'M7', 'M8', 'N5', 'N6', 'N7', 'N8', 'O5', 'O6', 'O7', 'O8']\n assert candidate(s = \"J1:K3\") == ['J1', 'J2', 'J3', 'K1', 'K2', 'K3']\n assert candidate(s = \"F2:J7\") == ['F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'J2', 'J3', 'J4', 'J5', 'J6', 'J7']\n assert candidate(s = \"A1:B1\") == ['A1', 'B1']\n assert candidate(s = \"G5:H8\") == ['G5', 'G6', 'G7', 'G8', 'H5', 'H6', 'H7', 'H8']\n assert candidate(s = \"R3:X8\") == ['R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8']\n assert candidate(s = \"C3:F7\") == ['C3', 'C4', 'C5', 'C6', 'C7', 'D3', 'D4', 'D5', 'D6', 'D7', 'E3', 'E4', 'E5', 'E6', 'E7', 'F3', 'F4', 'F5', 'F6', 'F7']\n assert candidate(s = \"C1:C5\") == ['C1', 'C2', 'C3', 'C4', 'C5']\n assert candidate(s = \"H1:H9\") == ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9']\n assert candidate(s = \"C4:E6\") == ['C4', 'C5', 'C6', 'D4', 'D5', 'D6', 'E4', 'E5', 'E6']\n assert candidate(s = \"E5:F7\") == ['E5', 'E6', 'E7', 'F5', 'F6', 'F7']\n assert candidate(s = \"P1:Q9\") == ['P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9']\n assert candidate(s = \"V1:W3\") == ['V1', 'V2', 'V3', 'W1', 'W2', 'W3']\n assert candidate(s = \"C4:D8\") == ['C4', 'C5', 'C6', 'C7', 'C8', 'D4', 'D5', 'D6', 'D7', 'D8']\n assert candidate(s = \"F1:H4\") == ['F1', 'F2', 'F3', 'F4', 'G1', 'G2', 'G3', 'G4', 'H1', 'H2', 'H3', 'H4']\n assert candidate(s = \"G1:H1\") == ['G1', 'H1']\n assert candidate(s = \"W3:X6\") == ['W3', 'W4', 'W5', 'W6', 'X3', 'X4', 'X5', 'X6']\n assert candidate(s = \"N3:Q6\") == ['N3', 'N4', 'N5', 'N6', 'O3', 'O4', 'O5', 'O6', 'P3', 'P4', 'P5', 'P6', 'Q3', 'Q4', 'Q5', 'Q6']\n assert candidate(s = \"J4:L7\") == ['J4', 'J5', 'J6', 'J7', 'K4', 'K5', 'K6', 'K7', 'L4', 'L5', 'L6', 'L7']\n assert candidate(s = \"F2:H5\") == ['F2', 'F3', 'F4', 'F5', 'G2', 'G3', 'G4', 'G5', 'H2', 'H3', 'H4', 'H5']\n assert candidate(s = \"X5:Y8\") == ['X5', 'X6', 'X7', 'X8', 'Y5', 'Y6', 'Y7', 'Y8']\n assert candidate(s = \"W2:Y5\") == ['W2', 'W3', 'W4', 'W5', 'X2', 'X3', 'X4', 'X5', 'Y2', 'Y3', 'Y4', 'Y5']\n assert candidate(s = \"W1:X3\") == ['W1', 'W2', 'W3', 'X1', 'X2', 'X3']\n assert candidate(s = \"P1:Q1\") == ['P1', 'Q1']\n", "comparison": "exact"}, "public_tests": ["\"K1:L2\"", "\"A1:F1\""], "hints": ["From the given string, find the corresponding rows and columns.", "Iterate through the columns in ascending order and for each column, iterate through the rows in ascending order to obtain the required cells in sorted order."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().cellsInRange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:28+00:00", "tests_total": 175, "tests_dropped": 82, "flags": ["has_images"], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function cellsInRange($s) {", "container": "Solution", "callable": "cellsInRange", "parameters": [{"name": "s", "type": "String"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2195, "task_id": "append-k-integers-with-minimal-sum", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.\n\nReturn the sum of the k integers appended to nums.\n\nExample 1:\n\nInput: nums = [1,4,25,10,25], k = 2\nOutput: 5\nExplanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.\nThe resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.\nThe sum of the two integers appended is 2 + 3 = 5, so we return 5.\n\nExample 2:\n\nInput: nums = [5,6], k = 6\nOutput: 25\nExplanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.\nThe resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum.\nThe sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 21\n assert candidate(nums = [1, 4, 25, 10, 25],k = 2) == 5\n assert candidate(nums = [1000000000],k = 100000) == 5000050000\n assert candidate(nums = [1000000000],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 10) == 95\n assert candidate(nums = [1],k = 1) == 2\n assert candidate(nums = [1, 3, 5, 7, 9],k = 5) == 30\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 15\n assert candidate(nums = [5, 6],k = 6) == 25\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 2\n assert candidate(nums = [1000000000],k = 100000000) == 5000000050000000\n assert candidate(nums = [10, 20, 30],k = 5) == 15\n assert candidate(nums = [5, 15, 25, 35, 45],k = 15) == 133\n assert candidate(nums = [100, 200, 300, 400, 500],k = 50) == 1275\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],k = 50) == 1445\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 155\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 30) == 603\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, 85, 89, 93, 97],k = 25) == 442\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 65\n assert candidate(nums = [1],k = 1000000) == 500001500000\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],k = 50) == 1513\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 = 50) == 1390\n assert candidate(nums = [999999998, 999999999, 1000000000],k = 100000) == 5000050000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 20) == 210\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 100000) == 5000050000\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) == 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],k = 25) == 950\n assert candidate(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18],k = 15) == 264\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],k = 500000) == 125000250000\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 10) == 57\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 126\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 215\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 20) == 233\n assert candidate(nums = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5],k = 15) == 175\n assert candidate(nums = [1000000000],k = 1000000) == 500000500000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 155\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 241\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) == 570\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 1390\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 = 25) == 391\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 1390\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 50000) == 1250025000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 25) == 391\n assert candidate(nums = [1, 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) == 6940\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) == 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],k = 20) == 610\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 30) == 691\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 = 100) == 6815\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 10) == 105\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) == 115\n assert candidate(nums = [500000000, 600000000, 700000000, 800000000, 900000000],k = 100000) == 5000050000\n assert candidate(nums = [5, 15, 25, 35, 45],k = 10) == 61\n assert candidate(nums = [2, 4, 6, 8, 10],k = 5) == 25\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],k = 25) == 361\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) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 50) == 2775\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 10) == 100\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 10) == 63\n assert candidate(nums = [2],k = 1000000) == 500001499999\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23],k = 15) == 224\n assert candidate(nums = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46],k = 20) == 315\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 = 50) == 3275\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 15) == 225\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],k = 100) == 5556\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],k = 35) == 766\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 = 100) == 10050\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],k = 100000) == 5000050000\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 223\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],k = 25) == 433\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 100) == 5556\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50) == 1275\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29],k = 20) == 520\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 15) == 215\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100],k = 15) == 160\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50) == 1275\n assert candidate(nums = [999999990, 999999991, 999999992, 999999993, 999999994],k = 5) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 110\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 100000) == 5000050000\n assert candidate(nums = [3, 9, 2, 8, 6, 7],k = 3) == 10\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, 210, 220, 230, 240],k = 30) == 534\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) == 115\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 65\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 365\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],k = 100) == 6330\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 20) == 223\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) == 810\n assert candidate(nums = [999999998, 999999999, 1000000000],k = 3) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 365\n assert candidate(nums = [1000000000],k = 500000) == 125000250000\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],k = 20) == 295\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],k = 200) == 21990\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],k = 10000) == 50005000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 25) == 391\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 = 100) == 10050\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) == 7050\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, 85, 89, 93, 97],k = 25) == 442\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) == 255\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 30\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 15) == 141\n assert candidate(nums = [3, 5, 7, 9, 11],k = 10) == 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, 21, 22, 23, 24, 25],k = 30) == 1215\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],k = 500000) == 125000250000\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) == 2775\n assert candidate(nums = [5, 15, 25, 35, 45],k = 10) == 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],k = 100) == 7050\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100) == 6050\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 110\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 = 15) == 225\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 56\n", "comparison": "exact"}, "public_tests": ["[1,4,25,10,25]\n2", "[5,6]\n6"], "hints": ["The k smallest numbers that do not appear in nums will result in the minimum sum.", "Recall that the sum of the first n positive numbers is equal to n * (n+1) / 2.", "Initialize the answer as the sum of 1 to k. Then, adjust the answer depending on the values in nums."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().minimalKSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:30+00:00", "tests_total": 111, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimalKSum($nums, $k) {", "container": "Solution", "callable": "minimalKSum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2197, "task_id": "replace-non-coprime-numbers-in-array", "difficulty": "Hard", "problem_description": "You are given an array of integers nums. Perform the following steps:\n\n1. Find any two adjacent numbers in nums that are non-coprime.\n2. If no such numbers are found, stop the process.\n3. Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).\n4. Repeat this process as long as you keep finding two adjacent non-coprime numbers.\n\nReturn the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result.\n\nThe test cases are generated such that the values in the final array are less than or equal to 10^8.\n\nTwo values x and y are non-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 = [6,4,3,2,7,6,2]\nOutput: [12,7,6]\nExplanation:\n- (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [12,3,2,7,6,2].\n- (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [12,2,7,6,2].\n- (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [12,7,6,2].\n- (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,6].\nThere are no more adjacent non-coprime numbers in nums.\nThus, the final modified array is [12,7,6].\nNote that there are other ways to obtain the same resultant array.\n\nExample 2:\n\nInput: nums = [2,2,1,1,3,3,3]\nOutput: [2,1,1,3]\nExplanation:\n- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3,3].\n- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3].\n- (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [2,1,1,3].\nThere are no more adjacent non-coprime numbers in nums.\nThus, the final modified array is [2,1,1,3].\nNote that there are other ways to obtain the same resultant array.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- The test cases are generated such that the values in the final array are less than or equal to 10^8.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 6, 8, 10, 12]) == [120]\n assert candidate(nums = [100000, 100000, 100000, 100000]) == [100000]\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 = [2, 2, 1, 1, 3, 3, 3]) == [2, 1, 1, 3]\n assert candidate(nums = [9, 27, 81, 243, 729]) == [729]\n assert candidate(nums = [42, 56, 70, 84, 98]) == [5880]\n assert candidate(nums = [7, 3, 5, 2, 8, 6]) == [7, 3, 5, 24]\n assert candidate(nums = [9, 3, 6, 12, 24, 48]) == [144]\n assert candidate(nums = [100, 200, 300, 400, 500]) == [6000]\n assert candidate(nums = [7, 11, 13, 17, 19]) == [7, 11, 13, 17, 19]\n assert candidate(nums = [7, 3, 5, 2, 11]) == [7, 3, 5, 2, 11]\n assert candidate(nums = [5, 10, 15, 20, 25]) == [300]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == [9]\n assert candidate(nums = [5, 10, 15, 20]) == [60]\n assert candidate(nums = [60, 45, 30, 15, 5]) == [180]\n assert candidate(nums = [6, 4, 3, 2, 7, 6, 2]) == [12, 7, 6]\n assert candidate(nums = [8, 12, 18, 24, 30]) == [360]\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == [3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16]) == [1680]\n assert candidate(nums = [2, 3, 5, 6, 9, 15, 20, 30, 45]) == [180]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == [17640]\n assert candidate(nums = [225, 315, 405, 15, 21, 27, 33, 39, 45]) == [2027025]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125]) == [100000]\n assert candidate(nums = [9, 3, 27, 81, 243, 729, 2187]) == [2187]\n assert candidate(nums = [9, 15, 18, 24, 30, 36, 45]) == [360]\n assert candidate(nums = [210, 154, 110, 77, 49, 35, 21, 7]) == [16170]\n assert candidate(nums = [360, 420, 480, 12, 15, 18, 21, 24, 27]) == [30240]\n assert candidate(nums = [25, 15, 10, 20, 12, 30, 18]) == [900]\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [1024]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == [2522520]\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 = [9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == [1081080]\n assert candidate(nums = [14, 21, 35, 56, 98, 112]) == [11760]\n assert candidate(nums = [72, 48, 32, 16, 8, 4, 2]) == [288]\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == [720720]\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40]) == [4200]\n assert candidate(nums = [525, 630, 735, 15, 21, 27, 33, 39, 45]) == [9459450]\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60]) == [15120]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49]) == [2940]\n assert candidate(nums = [21, 28, 35, 42, 49, 56, 63, 70, 77, 84]) == [194040]\n assert candidate(nums = [204, 260, 312, 13, 17, 21, 23, 29, 31]) == [185640, 23, 29, 31]\n assert candidate(nums = [18, 24, 30, 12, 15, 20, 25, 35, 40]) == [12600]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [12600]\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130]) == [32760]\n assert candidate(nums = [15, 10, 20, 25, 30, 35, 40, 45, 50]) == [12600]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\n assert candidate(nums = [1000, 1250, 1500, 1750, 2000, 2250, 2500]) == [630000]\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500]) == [126000]\n assert candidate(nums = [9, 15, 21, 27, 33, 39, 45, 51, 57, 63]) == [43648605]\n assert candidate(nums = [256, 192, 128, 64, 32, 16, 8, 4, 2]) == [768]\n assert candidate(nums = [110, 154, 198, 11, 14, 18, 22, 26, 30]) == [90090]\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == [32768]\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [72747675]\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95]) == [72747675]\n assert candidate(nums = [210, 273, 330, 21, 27, 33, 39, 45, 51]) == [4594590]\n assert candidate(nums = [18, 27, 36, 45, 54, 63, 72, 81, 90, 99]) == [249480]\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165]) == [3963960]\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == [101, 102, 103, 104, 105, 106, 107, 108, 109, 110]\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500]) == [126000]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == [17640]\n assert candidate(nums = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [138600]\n assert candidate(nums = [12, 15, 20, 25, 30, 35]) == [2100]\n assert candidate(nums = [495, 595, 693, 11, 13, 17, 19, 23, 29]) == [58905, 13, 17, 19, 23, 29]\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [1024]\n assert candidate(nums = [100, 25, 50, 20, 40, 80, 160]) == [800]\n assert candidate(nums = [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == [720720]\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [138600]\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]\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010]) == [254520]\n assert candidate(nums = [100, 50, 25, 125, 200, 80]) == [2000]\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110]) == [27720]\n assert candidate(nums = [8, 4, 2, 1, 2, 4, 8, 16, 32, 64]) == [8, 1, 64]\n assert candidate(nums = [21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]) == [2522520]\n assert candidate(nums = [25, 45, 65, 85, 105, 125]) == [1740375]\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]\n assert candidate(nums = [63, 77, 91, 14, 18, 22, 26, 30, 34]) == [1531530]\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [210, 105, 35, 10, 5, 7, 14, 28, 56]) == [840]\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560]) == [2560]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [25200]\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == [59049]\n assert candidate(nums = [98, 49, 21, 14, 7, 3, 1]) == [294, 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]) == [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]\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 = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == [2162160]\n assert candidate(nums = [100, 75, 150, 25, 50, 125, 200]) == [3000]\n assert candidate(nums = [121, 143, 169, 11, 13, 17, 19, 23, 29]) == [20449, 17, 19, 23, 29]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [5040]\n assert candidate(nums = [98, 42, 56, 28, 14, 7, 1]) == [1176, 1]\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [18, 27, 36, 45, 54, 63]) == [3780]\n assert candidate(nums = [45, 90, 135, 270, 540, 1080, 2160]) == [2160]\n assert candidate(nums = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]) == [10240]\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250]) == [63000]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700]) == [42000]\n assert candidate(nums = [20, 30, 40, 50, 60, 70, 80, 90, 100]) == [25200]\n assert candidate(nums = [231, 105, 63, 21, 7, 1]) == [3465, 1]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == [7560]\n assert candidate(nums = [720, 360, 180, 90, 45, 22, 11]) == [7920]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1163962800]\n assert candidate(nums = [49, 42, 35, 28, 21, 14, 7]) == [2940]\n assert candidate(nums = [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]) == [99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109]\n assert candidate(nums = [9, 15, 45, 30, 18, 60, 20]) == [180]\n assert candidate(nums = [42, 56, 70, 84, 98, 112, 126, 140, 154, 168, 182, 196]) == [5045040]\n assert candidate(nums = [6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42]) == [1081080]\n assert candidate(nums = [42, 56, 98, 14, 28, 49, 7, 35]) == [5880]\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66]) == [166320]\n assert candidate(nums = [105, 135, 165, 15, 25, 35, 45, 55, 65]) == [675675]\n assert candidate(nums = [100, 75, 50, 25, 10, 5, 1]) == [300, 1]\n assert candidate(nums = [12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1163962800]\n assert candidate(nums = [10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120]) == [5120]\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == [1024, 1]\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66]) == [166320]\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]) == [1536]\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == [59049]\n assert candidate(nums = [18, 24, 30, 42, 54, 66, 78, 90, 102, 114]) == [349188840]\n assert candidate(nums = [1000, 1500, 2000, 2500, 3000]) == [30000]\n assert candidate(nums = [144, 180, 216, 12, 15, 18, 21, 24, 27]) == [15120]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 15625]) == [500000]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [252000]\n", "comparison": "exact"}, "public_tests": ["[6,4,3,2,7,6,2]", "[2,2,1,1,3,3,3]"], "hints": ["Notice that the order of merging two numbers into their LCM does not matter so we can greedily merge elements to its left if possible.", "If a new value is formed, we should recursively check if it can be merged with the value to its left.", "To simulate the merge efficiently, we can maintain a stack that stores processed elements. When we iterate through the array, we only compare with the top of the stack (which is the value to its left)."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().replaceNonCoprimes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:36+00:00", "tests_total": 134, "tests_dropped": 13, "flags": [], "topic_tags": ["array", "math", "stack", "number-theory", "least-common-multiple", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function replaceNonCoprimes($nums) {", "container": "Solution", "callable": "replaceNonCoprimes", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2200, "task_id": "find-all-k-distant-indices-in-an-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.\n\nReturn a list of all k-distant indices sorted in increasing order.\n\nExample 1:\n\nInput: nums = [3,4,9,1,3,9,5], key = 9, k = 1\nOutput: [1,2,3,4,5,6]\nExplanation: Here, nums[2] == key and nums[5] == key.\n- For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j where |0 - j| <= k and nums[j] == key. Thus, 0 is not a k-distant index.\n- For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index.\n- For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index.\n- For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index.\n- For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index.\n- For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index.\n- For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index.\nThus, we return [1,2,3,4,5,6] which is sorted in increasing order.\n\nExample 2:\n\nInput: nums = [2,2,2,2,2], key = 2, k = 2\nOutput: [0,1,2,3,4]\nExplanation: For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index.\nHence, we return [0,1,2,3,4].\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n- key is an integer from the array nums.\n- 1 <= k <= nums.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 1, 4, 1, 5],key = 5,k = 2) == [0, 1, 2, 3, 4]\n assert candidate(nums = [1, 1, 1, 1, 1, 1],key = 1,k = 3) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 3, 5, 7, 9],key = 3,k = 2) == [0, 1, 2, 3]\n assert candidate(nums = [5, 5, 5, 5, 5, 5],key = 5,k = 3) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 20],key = 20,k = 2) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5],key = 1,k = 2) == [0, 1, 2]\n assert candidate(nums = [2, 2, 2, 2, 2],key = 2,k = 2) == [0, 1, 2, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5],key = 5,k = 2) == [2, 3, 4]\n assert candidate(nums = [10, 20, 30, 40, 50],key = 30,k = 2) == [0, 1, 2, 3, 4]\n assert candidate(nums = [5, 1, 5, 1, 5],key = 5,k = 1) == [0, 1, 2, 3, 4]\n assert candidate(nums = [3, 4, 9, 1, 3, 9, 5],key = 9,k = 1) == [1, 2, 3, 4, 5, 6]\n assert candidate(nums = [5, 4, 3, 2, 1],key = 1,k = 1) == [3, 4]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],key = 60,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],key = 50,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = [10, 20, 30, 40, 50, 20, 30, 40, 50],key = 20,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],key = 5,k = 7) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],key = 996,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 5,k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4],key = 4,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],key = 11,k = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],key = 7,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],key = 1,k = 3) == [5, 6, 7, 8]\n assert candidate(nums = [7, 3, 4, 7, 1, 7, 5, 7, 3, 7],key = 7,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],key = 16,k = 4) == [3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],key = 500,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],key = 3,k = 4) == [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],key = 7,k = 2) == [10, 11, 12, 13, 14, 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],key = 5,k = 2) == [6, 7, 8, 9, 10, 11]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],key = 10,k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71],key = 13,k = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 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],key = 7,k = 10) == [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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],key = 10,k = 10) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],key = 6,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],key = 7,k = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10],key = 30,k = 1) == [1, 2, 3, 5, 6, 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],key = 3,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],key = 7,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],key = 15,k = 2) == [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],key = 100,k = 5) == [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],key = 500,k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [999, 1000, 999, 1000, 999, 1000, 999, 1000, 999, 1000],key = 999,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],key = 5,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 5,k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],key = 3,k = 1) == [3, 4, 5, 6]\n assert candidate(nums = [7, 1, 5, 3, 6, 2, 4, 8, 9, 7, 5, 3, 1],key = 7,k = 3) == [0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 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],key = 10,k = 5) == [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],key = 80,k = 5) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],key = 50,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],key = 5,k = 10) == [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, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 10,k = 4) == [5, 6, 7, 8, 9]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],key = 49,k = 5) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],key = 10,k = 3) == [6, 7, 8, 9, 10, 11, 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],key = 3,k = 1) == [3, 4, 5, 6]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],key = 25,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],key = 60,k = 1) == [4, 5, 6]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],key = 1,k = 3) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],key = 30,k = 1) == [1, 2, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],key = 1,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],key = 8,k = 3) == [4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],key = 3,k = 2) == [2, 3, 4, 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],key = 10,k = 5) == [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [7, 1, 5, 3, 9, 5, 7, 5, 2, 5],key = 5,k = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],key = 7,k = 5) == [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, 300, 200, 100],key = 300,k = 2) == [0, 1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],key = 13,k = 4) == [2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],key = 3,k = 3) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],key = 15,k = 5) == [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],key = 8,k = 5) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],key = 50,k = 4) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],key = 500,k = 3) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19],key = 7,k = 2) == [0, 1, 2, 3, 4]\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],key = 13,k = 2) == [3, 4, 5, 6, 7]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],key = 5,k = 2) == [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],key = 10,k = 4) == [5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],key = 5,k = 1) == [3, 4, 5, 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],key = 3,k = 2) == [2, 3, 4, 5, 6, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 5,k = 1) == [3, 4, 5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],key = 5,k = 3) == [2, 3, 4, 5, 6, 7, 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],key = 5,k = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],key = 5,k = 2) == [2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],key = 5,k = 5) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],key = 15,k = 6) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],key = 5,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(nums = [1, 3, 2, 3, 1, 3, 2, 3, 1, 3],key = 3,k = 1) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],key = 5,k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],key = 7,k = 4) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 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],key = 15,k = 5) == [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],key = 9,k = 5) == [0, 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, 110, 120, 130, 140, 150],key = 90,k = 4) == [4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],key = 15,k = 3) == [4, 5, 6, 7, 8, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],key = 7,k = 3) == [0, 1, 2, 3, 4, 5, 6]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42],key = 21,k = 6) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],key = 5,k = 2) == [2, 3, 4, 5, 6, 10, 11, 12, 13, 14]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],key = 19,k = 7) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],key = 3,k = 3) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n", "comparison": "exact"}, "public_tests": ["[3,4,9,1,3,9,5]\n9\n1", "[2,2,2,2,2]\n2\n2"], "hints": ["For every occurrence of key in nums, find all indices within distance k from it.", "Use a hash table to remove duplicate indices."], "metadata": {"canonical_parameter_names": ["nums", "key", "k"], "leetcode_dataset_entry_point": "Solution().findKDistantIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:40+00:00", "tests_total": 107, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "two-pointers"]}, "language": "php", "interface": {"raw_signature": "function findKDistantIndices($nums, $key, $k) {", "container": "Solution", "callable": "findKDistantIndices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "key", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2201, "task_id": "count-artifacts-that-can-be-extracted", "difficulty": "Medium", "problem_description": "There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1_i, c1_i, r2_i, c2_i] denotes that the i^th artifact is buried in the subgrid where:\n\n- (r1_i, c1_i) is the coordinate of the top-left cell of the i^th artifact and\n- (r2_i, c2_i) is the coordinate of the bottom-right cell of the i^th artifact.\n\nYou will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.\n\nGiven a 0-indexed 2D integer array dig where dig[i] = [r_i, c_i] indicates that you will excavate the cell (r_i, c_i), return the number of artifacts that you can extract.\n\nThe test cases are generated such that:\n\n- No two artifacts overlap.\n- Each artifact only covers at most 4 cells.\n- The entries of dig are unique.\n\nExample 1:\n\nInput: n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]]\nOutput: 1\nExplanation:\nThe different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid.\nThere is 1 artifact that can be extracted, namely the red artifact.\nThe blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it.\nThus, we return 1.\n\nExample 2:\n\nInput: n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]]\nOutput: 2\nExplanation: Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2.\n\nConstraints:\n\n- 1 <= n <= 1000\n- 1 <= artifacts.length, dig.length <= min(n^2, 10^5)\n- artifacts[i].length == 4\n- dig[i].length == 2\n- 0 <= r1_i, c1_i, r2_i, c2_i, r_i, c_i <= n - 1\n- r1_i <= r2_i\n- c1_i <= c2_i\n- No two artifacts will overlap.\n- The number of cells covered by an artifact is at most 4.\n- The entries of dig are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,artifacts = [[0, 0, 0, 0], [1, 1, 2, 2], [3, 3, 3, 3]],dig = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 2\n assert candidate(n = 5,artifacts = [[0, 0, 0, 1], [1, 1, 2, 2], [3, 3, 4, 4]],dig = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4]]) == 3\n assert candidate(n = 5,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 4, 4]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4]]) == 3\n assert candidate(n = 3,artifacts = [[0, 0, 0, 1], [1, 0, 1, 1], [2, 0, 2, 1]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]) == 3\n assert candidate(n = 3,artifacts = [[0, 0, 0, 1], [1, 1, 2, 2]],dig = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 1], [2, 2]]) == 2\n assert candidate(n = 3,artifacts = [[0, 0, 0, 1], [1, 1, 2, 2]],dig = [[0, 0], [0, 1], [1, 1], [2, 2]]) == 1\n assert candidate(n = 4,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3]]) == 2\n assert candidate(n = 3,artifacts = [[0, 0, 1, 1], [1, 2, 2, 2]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [1, 2], [2, 2]]) == 2\n assert candidate(n = 4,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],dig = [[0, 0], [1, 1], [2, 2], [3, 3]]) == 4\n assert candidate(n = 5,artifacts = [[0, 0, 0, 1], [1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, 4]],dig = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 4]]) == 4\n assert candidate(n = 3,artifacts = [[0, 0, 1, 1], [1, 1, 2, 2]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2]]) == 1\n assert candidate(n = 3,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2]],dig = [[0, 0], [1, 1], [2, 2]]) == 3\n assert candidate(n = 2,artifacts = [[0, 0, 0, 0], [0, 1, 1, 1]],dig = [[0, 0], [0, 1], [1, 1]]) == 2\n assert candidate(n = 2,artifacts = [[0, 0, 0, 0], [0, 1, 1, 1]],dig = [[0, 0], [0, 1]]) == 1\n assert candidate(n = 3,artifacts = [[0, 0, 0, 1], [1, 1, 1, 2]],dig = [[0, 0], [0, 1], [1, 1]]) == 1\n assert candidate(n = 7,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 6, 6], [0, 2, 1, 3], [2, 4, 3, 6], [4, 0, 5, 2]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1], [5, 2], [6, 6]]) == 4\n assert candidate(n = 8,artifacts = [[0, 0, 1, 2], [2, 3, 3, 4], [4, 5, 5, 6], [6, 7, 7, 7]],dig = [[0, 0], [0, 1], [0, 2], [2, 3], [2, 4], [3, 3], [3, 4], [4, 5], [4, 6], [5, 5], [5, 6], [6, 7], [7, 7]]) == 3\n assert candidate(n = 10,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 8, 8], [7, 7, 9, 9]],dig = [[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], [6, 7], [6, 8], [7, 6], [7, 7], [7, 8], [8, 6], [8, 7], [8, 8], [7, 7], [7, 8], [9, 7], [9, 8], [9, 9]]) == 3\n assert candidate(n = 9,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 8, 8]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [6, 6], [6, 7], [6, 8], [7, 6], [7, 7], [7, 8], [8, 6], [8, 7], [8, 8]]) == 2\n assert candidate(n = 10,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7], [8, 8, 9, 9]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9]]) == 5\n assert candidate(n = 7,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 4, 4], [5, 5, 6, 6]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == 1\n assert candidate(n = 8,artifacts = [[0, 0, 0, 1], [1, 0, 1, 1], [2, 0, 2, 1], [3, 0, 3, 1], [4, 0, 4, 1], [5, 0, 5, 1], [6, 0, 6, 1], [7, 0, 7, 1]],dig = [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0], [5, 1], [6, 0], [7, 1], [0, 1], [1, 0], [2, 1], [3, 0], [4, 1], [5, 0], [6, 1], [7, 0]]) == 8\n assert candidate(n = 20,artifacts = [[0, 0, 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, 14, 15, 15], [16, 16, 17, 17], [18, 18, 19, 19]],dig = [[0, 0], [0, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9], [10, 10], [10, 11], [11, 10], [11, 11], [12, 12], [12, 13], [13, 12], [13, 13], [14, 14], [14, 15], [15, 14], [15, 15], [16, 16], [16, 17], [17, 16], [17, 17], [18, 18], [18, 19], [19, 18], [19, 19]]) == 10\n assert candidate(n = 15,artifacts = [[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, 14, 14]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9], [10, 10], [10, 11], [11, 10], [11, 11], [12, 12], [12, 13], [13, 12], [13, 13], [14, 14]]) == 8\n assert candidate(n = 15,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 8, 8], [9, 9, 11, 11], [12, 12, 14, 14]],dig = [[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], [6, 7], [6, 8], [7, 6], [7, 7], [7, 8], [8, 6], [8, 7], [8, 8], [9, 9], [9, 10], [9, 11], [10, 9], [10, 10], [10, 11], [11, 9], [11, 10], [11, 11], [12, 12], [12, 13], [12, 14], [13, 12], [13, 13], [13, 14], [14, 12], [14, 13], [14, 14]]) == 5\n assert candidate(n = 20,artifacts = [[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], [10, 10, 10, 10], [11, 11, 11, 11], [12, 12, 12, 12], [13, 13, 13, 13], [14, 14, 14, 14], [15, 15, 15, 15], [16, 16, 16, 16], [17, 17, 17, 17], [18, 18, 18, 18], [19, 19, 19, 19]],dig = [[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]]) == 20\n assert candidate(n = 500,artifacts = [[0, 0, 1, 1], [498, 498, 499, 499]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [498, 498], [498, 499], [499, 498], [499, 499]]) == 2\n assert candidate(n = 7,artifacts = [[0, 0, 0, 3], [1, 1, 2, 2], [3, 3, 4, 4], [5, 5, 6, 6]],dig = [[0, 0], [0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6]]) == 4\n assert candidate(n = 7,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 6, 6]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6]]) == 4\n assert candidate(n = 15,artifacts = [[0, 0, 0, 3], [1, 1, 1, 4], [2, 2, 2, 5], [3, 3, 3, 6], [4, 4, 4, 7], [5, 5, 5, 8], [6, 6, 6, 9], [7, 7, 7, 10], [8, 8, 8, 11], [9, 9, 9, 12]],dig = [[0, 0], [0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [1, 3], [1, 4], [2, 2], [2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [5, 8], [6, 6], [6, 7], [6, 8], [6, 9], [7, 7], [7, 8], [7, 9], [7, 10], [8, 8], [8, 9], [8, 10], [8, 11], [9, 9], [9, 10], [9, 11], [9, 12]]) == 10\n assert candidate(n = 6,artifacts = [[0, 0, 2, 1], [3, 2, 4, 3], [1, 4, 2, 5], [4, 0, 5, 1]],dig = [[0, 0], [0, 1], [1, 4], [1, 5], [2, 0], [2, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2], [4, 3], [5, 0], [5, 1]]) == 2\n assert candidate(n = 1000,artifacts = [[0, 0, 0, 0], [999, 999, 999, 999]],dig = [[0, 0], [999, 999]]) == 2\n assert candidate(n = 12,artifacts = [[0, 0, 0, 2], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7], [8, 8, 9, 9], [10, 10, 11, 11]],dig = [[0, 0], [0, 1], [0, 2], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9], [10, 10], [10, 11], [11, 10], [11, 11]]) == 6\n assert candidate(n = 5,artifacts = [[0, 0, 1, 2], [2, 0, 3, 1], [4, 2, 4, 4]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [3, 0], [3, 1], [4, 2], [4, 3], [4, 4]]) == 3\n assert candidate(n = 100,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [98, 98, 98, 98], [99, 99, 99, 99]],dig = [[0, 0], [1, 1], [98, 98], [99, 99]]) == 4\n assert candidate(n = 20,artifacts = [[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]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9], [10, 10], [10, 11], [11, 10], [11, 11], [12, 12], [12, 13], [13, 12], [13, 13], [14, 14], [14, 15], [15, 14], [15, 15], [16, 16], [16, 17], [17, 16], [17, 17], [18, 18], [18, 19], [19, 18], [19, 19]]) == 10\n assert candidate(n = 1000,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [998, 998, 999, 999]],dig = [[0, 0], [1, 1], [998, 998], [999, 999]]) == 2\n assert candidate(n = 6,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 6\n assert candidate(n = 10,artifacts = [[0, 0, 2, 1], [3, 3, 5, 4], [6, 6, 8, 7]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1], [3, 3], [3, 4], [4, 3], [4, 4], [5, 3], [5, 4], [6, 6], [6, 7], [7, 6], [7, 7], [8, 6], [8, 7]]) == 3\n assert candidate(n = 8,artifacts = [[0, 0, 0, 1], [1, 2, 2, 3], [3, 4, 4, 5], [5, 6, 6, 7]],dig = [[0, 0], [0, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 4], [3, 5], [4, 4], [4, 5], [5, 6], [5, 7], [6, 6], [6, 7]]) == 4\n assert candidate(n = 10,artifacts = [[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, 9]],dig = [[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]]) == 10\n assert candidate(n = 12,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7], [8, 8, 9, 9], [10, 10, 11, 11]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9], [10, 10], [10, 11], [11, 10], [11, 11]]) == 6\n assert candidate(n = 7,artifacts = [[0, 0, 1, 1], [2, 2, 2, 3], [3, 3, 4, 4], [5, 5, 6, 6]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6]]) == 4\n assert candidate(n = 10,artifacts = [[0, 0, 2, 2], [3, 3, 4, 4], [5, 5, 6, 6], [7, 7, 8, 8], [1, 1, 2, 2], [3, 5, 4, 6], [7, 9, 8, 9]],dig = [[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], [5, 6], [6, 5], [6, 6], [7, 7], [7, 8], [7, 9], [8, 7], [8, 8], [8, 9], [3, 5], [3, 6], [4, 5], [4, 6]]) == 7\n assert candidate(n = 8,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 0], [7, 1]]) == 4\n assert candidate(n = 5,artifacts = [[0, 0, 1, 1], [1, 2, 2, 3], [3, 4, 3, 4]],dig = [[0, 0], [0, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 4]]) == 2\n assert candidate(n = 9,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7], [8, 8, 8, 8], [0, 2, 1, 3], [2, 4, 3, 6], [4, 0, 5, 2], [6, 4, 7, 6]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [5, 0], [5, 1], [5, 2], [6, 4], [6, 5], [6, 6], [7, 4], [7, 5], [7, 6], [8, 8]]) == 5\n assert candidate(n = 20,artifacts = [[0, 0, 3, 3], [4, 4, 7, 7], [8, 8, 11, 11], [12, 12, 15, 15], [16, 16, 19, 19]],dig = [[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], [4, 4], [4, 5], [4, 6], [4, 7], [5, 4], [5, 5], [5, 6], [5, 7], [6, 4], [6, 5], [6, 6], [6, 7], [7, 4], [7, 5], [7, 6], [7, 7], [8, 8], [8, 9], [8, 10], [8, 11], [9, 8], [9, 9], [9, 10], [9, 11], [10, 8], [10, 9], [10, 10], [10, 11], [11, 8], [11, 9], [11, 10], [11, 11], [12, 12], [12, 13], [12, 14], [12, 15], [13, 12], [13, 13], [13, 14], [13, 15], [14, 12], [14, 13], [14, 14], [14, 15], [15, 12], [15, 13], [15, 14], [15, 15], [16, 16], [16, 17], [16, 18], [16, 19], [17, 16], [17, 17], [17, 18], [17, 19], [18, 16], [18, 17], [18, 18], [18, 19], [19, 16], [19, 17], [19, 18], [19, 19]]) == 5\n assert candidate(n = 10,artifacts = [[0, 0, 1, 1], [3, 3, 4, 4], [6, 6, 7, 7], [9, 9, 9, 9]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [3, 3], [3, 4], [4, 3], [4, 4], [6, 6], [6, 7], [7, 6], [7, 7], [9, 9]]) == 4\n assert candidate(n = 6,artifacts = [[0, 0, 0, 1], [1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, 4], [4, 4, 4, 5], [5, 5, 5, 5]],dig = [[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 4], [4, 4], [4, 5], [5, 5]]) == 6\n assert candidate(n = 1000,artifacts = [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == 5\n assert candidate(n = 10,artifacts = [[0, 0, 1, 1], [3, 3, 5, 5], [7, 7, 9, 9]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [4, 4], [5, 3], [5, 4], [5, 5], [7, 7], [7, 8], [7, 9], [8, 7], [8, 8], [8, 9], [9, 7], [9, 8], [9, 9]]) == 2\n assert candidate(n = 10,artifacts = [[0, 0, 0, 3], [1, 1, 2, 2], [3, 3, 3, 3]],dig = [[0, 0], [0, 1], [0, 2], [0, 3], [1, 1], [1, 2], [2, 1], [2, 2], [3, 3]]) == 3\n assert candidate(n = 10,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 8, 8], [9, 9, 9, 9]],dig = [[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], [6, 7], [6, 8], [7, 6], [7, 7], [7, 8], [8, 6], [8, 7], [8, 8], [9, 9]]) == 4\n assert candidate(n = 8,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 7, 7]],dig = [[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], [6, 7], [7, 6], [7, 7]]) == 3\n assert candidate(n = 8,artifacts = [[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], [0, 2, 1, 3], [2, 4, 3, 5], [4, 6, 5, 7]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [2, 4], [3, 2], [3, 3], [3, 4], [3, 5], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6], [5, 7], [6, 6], [6, 7]]) == 7\n assert candidate(n = 5,artifacts = [[0, 0, 2, 2], [1, 1, 3, 3]],dig = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2]]) == 1\n assert candidate(n = 15,artifacts = [[1, 1, 2, 2], [3, 3, 4, 4], [5, 5, 6, 6], [7, 7, 8, 8]],dig = [[1, 1], [1, 2], [2, 1], [2, 2], [3, 3], [3, 4], [4, 3], [4, 4], [5, 5], [5, 6], [6, 5], [6, 6], [7, 7], [7, 8], [8, 7], [8, 8]]) == 4\n assert candidate(n = 15,artifacts = [[0, 0, 0, 1], [1, 0, 1, 1], [2, 0, 2, 1], [3, 0, 3, 1], [4, 0, 4, 1], [5, 0, 5, 1], [6, 0, 6, 1], [7, 0, 7, 1], [8, 0, 8, 1], [9, 0, 9, 1], [10, 0, 10, 1], [11, 0, 11, 1], [12, 0, 12, 1], [13, 0, 13, 1], [14, 0, 14, 1]],dig = [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0], [5, 1], [6, 0], [7, 1], [8, 0], [9, 1], [10, 0], [11, 1], [12, 0], [13, 1], [14, 0]]) == 0\n assert candidate(n = 9,artifacts = [[0, 0, 1, 1], [2, 2, 3, 3], [4, 4, 5, 5], [6, 6, 7, 7], [8, 8, 8, 8]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 3], [3, 2], [3, 3], [4, 4], [4, 5], [5, 4], [5, 5], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8]]) == 5\n assert candidate(n = 10,artifacts = [[0, 0, 1, 1], [3, 3, 4, 4], [6, 6, 7, 7], [8, 8, 9, 9]],dig = [[0, 0], [0, 1], [1, 0], [1, 1], [3, 3], [3, 4], [4, 3], [4, 4], [6, 6], [6, 7], [7, 6], [7, 7], [8, 8], [8, 9], [9, 8], [9, 9]]) == 4\n assert candidate(n = 10,artifacts = [[0, 0, 0, 1], [1, 0, 1, 1], [2, 0, 2, 1], [3, 0, 3, 1], [4, 0, 4, 1], [5, 0, 5, 1], [6, 0, 6, 1], [7, 0, 7, 1], [8, 0, 8, 1], [9, 0, 9, 1]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [0, 1], [1, 0], [2, 1], [3, 0], [4, 1], [5, 0], [6, 1], [7, 0], [8, 1], [9, 0]]) == 2\n assert candidate(n = 8,artifacts = [[0, 0, 0, 2], [1, 1, 1, 3], [2, 2, 2, 4], [3, 3, 3, 5], [4, 4, 4, 6], [5, 5, 5, 7], [6, 6, 6, 7]],dig = [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [2, 4], [3, 3], [3, 4], [3, 5], [4, 4], [4, 5], [4, 6], [5, 5], [5, 6], [5, 7], [6, 6], [6, 7]]) == 7\n assert candidate(n = 10,artifacts = [[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]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 10\n assert candidate(n = 9,artifacts = [[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]],dig = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]]) == 9\n assert candidate(n = 10,artifacts = [[0, 0, 2, 2], [3, 3, 5, 5], [6, 6, 8, 8], [7, 7, 9, 9]],dig = [[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], [6, 7], [6, 8], [7, 6], [7, 7], [7, 8], [8, 6], [8, 7], [8, 8], [7, 7], [9, 9]]) == 3\n", "comparison": "exact"}, "public_tests": ["2\n[[0,0,0,0],[0,1,1,1]]\n[[0,0],[0,1]]", "2\n[[0,0,0,0],[0,1,1,1]]\n[[0,0],[0,1],[1,1]]"], "hints": ["Check if each coordinate of each artifact has been excavated. How can we do this quickly without iterating over the dig array every time?", "Consider marking all excavated cells in a 2D boolean array."], "metadata": {"canonical_parameter_names": ["n", "artifacts", "dig"], "leetcode_dataset_entry_point": "Solution().digArtifacts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:43+00:00", "tests_total": 66, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "simulation"]}, "language": "php", "interface": {"raw_signature": "function digArtifacts($n, $artifacts, $dig) {", "container": "Solution", "callable": "digArtifacts", "parameters": [{"name": "n", "type": "Integer"}, {"name": "artifacts", "type": "Integer[][]"}, {"name": "dig", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2202, "task_id": "maximize-the-topmost-element-after-k-moves", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile.\n\nIn one move, you can perform either of the following:\n\n- If the pile is not empty, remove the topmost element of the pile.\n- If there are one or more removed elements, add any one of them back onto the pile. This element becomes the new topmost element.\n\nYou are also given an integer k, which denotes the total number of moves to be made.\n\nReturn the maximum value of the topmost element of the pile possible after exactly k moves. In case it is not possible to obtain a non-empty pile after k moves, return -1.\n\nExample 1:\n\nInput: nums = [5,2,2,4,0,6], k = 4\nOutput: 5\nExplanation:\nOne of the ways we can end with 5 at the top of the pile after 4 moves is as follows:\n- Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].\n- Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].\n- Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].\n- Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].\nNote that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.\n\nExample 2:\n\nInput: nums = [2], k = 1\nOutput: -1\nExplanation:\nIn the first move, our only option is to pop the topmost element of the pile.\nSince it is not possible to obtain a non-empty pile after one move, we return -1.\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 = [7, 7, 7, 7, 7],k = 2) == 7\n assert candidate(nums = [9, 8, 7, 6, 5],k = 5) == 9\n assert candidate(nums = [10],k = 2) == 10\n assert candidate(nums = [8, 6, 4, 2, 0],k = 7) == 8\n assert candidate(nums = [7, 7, 7, 7, 7],k = 3) == 7\n assert candidate(nums = [1000000000],k = 0) == 1000000000\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 5\n assert candidate(nums = [1],k = 2) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 10) == 9\n assert candidate(nums = [3, 3, 3, 3, 3, 3],k = 1000000000) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 4\n assert candidate(nums = [2],k = 1) == -1\n assert candidate(nums = [9, 7, 5, 3, 1],k = 5) == 9\n assert candidate(nums = [10],k = 0) == 10\n assert candidate(nums = [1, 3, 5, 7, 9],k = 2) == 5\n assert candidate(nums = [9],k = 0) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 10\n assert candidate(nums = [0, 0, 0, 0, 0],k = 5) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],k = 0) == 1\n assert candidate(nums = [1000000000],k = 1000000000) == 1000000000\n assert candidate(nums = [1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(nums = [5, 2, 2, 4, 0, 6],k = 4) == 5\n assert candidate(nums = [1, 2],k = 2) == 1\n assert candidate(nums = [3, 3, 3, 3, 3],k = 5) == 3\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 9\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 9) == 9\n assert candidate(nums = [1, 1, 1, 1, 1],k = 0) == 1\n assert candidate(nums = [1, 2, 3, 4, 5],k = 0) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 5) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 11) == 10\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 6\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2],k = 9) == 20\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 15) == 19\n assert candidate(nums = [3, 7, 2, 8, 6, 4, 1, 9],k = 3) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 11) == 10\n assert candidate(nums = [5, 2, 9, 1, 5, 6, 7, 3, 4, 8],k = 15) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 7) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 19) == 10\n assert candidate(nums = [5, 2, 2, 4, 0, 6],k = 6) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 1) == 9\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 7) == 9\n assert candidate(nums = [90, 80, 70, 60, 50, 40, 30, 20, 10],k = 7) == 90\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 90\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 60\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],k = 9) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 18) == 19\n assert candidate(nums = [1],k = 1000000000) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 8) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 90\n assert candidate(nums = [1000000000, 1000000000, 1000000000],k = 2) == 1000000000\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 20) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 7) == 8\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],k = 11) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 20) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 10\n assert candidate(nums = [10, 20, 30, 40, 50],k = 2) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 21) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 25) == 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 = 20) == 19\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 10) == 9\n assert candidate(nums = [5, 1, 3, 2, 8, 7],k = 3) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],k = 7) == 1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 9\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 10) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 11) == 20\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],k = 3) == 7\n assert candidate(nums = [5, 2, 9, 1, 5, 6],k = 3) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 8) == 45\n assert candidate(nums = [10, 20, 30, 40, 50],k = 3) == 40\n assert candidate(nums = [7, 3, 5, 4, 1, 9, 8, 6, 2],k = 6) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 60\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 8) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 1\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10) == 100\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 10) == 7\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 999999) == 0\n assert candidate(nums = [1, 2, 3, 4, 5],k = 5) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 10\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 8) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 14) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 12) == 13\n assert candidate(nums = [1, 2, 3, 4, 5],k = 100) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 13) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 17\n assert candidate(nums = [7, 1, 5, 3, 6, 4],k = 3) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 9) == 1\n assert candidate(nums = [3, 7, 2, 5, 8, 6, 1],k = 10) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 999999999) == 100\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 6\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, 6, 7, 9],k = 100) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 19\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 9) == 100\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 7) == 9\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 10) == 9\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5],k = 9) == 5\n assert candidate(nums = [5, 1, 3, 2, 8, 7],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],k = 18) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 9) == 5\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],k = 12) == 14\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 2) == 30\n assert candidate(nums = [1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 5) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 20) == 19\n assert candidate(nums = [100, 90, 80, 70, 60],k = 6) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 4\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777],k = 4) == 1000000000\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 4) == 100\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],k = 9) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 12) == 10\n assert candidate(nums = [5, 3, 1, 4, 9, 8],k = 5) == 8\n assert candidate(nums = [100, 200, 300, 400, 500],k = 2) == 300\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 11) == 9\n assert candidate(nums = [1, 3, 5, 7, 9],k = 5) == 7\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 9) == 2\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 15) == 100\n assert candidate(nums = [1, 2, 3, 4, 5],k = 0) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 7) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 9) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15) == 9\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],k = 9) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 0) == 1\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666],k = 10) == 1000000000\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1, 9],k = 8) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100) == 10\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 9\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 5\n assert candidate(nums = [50, 50, 50, 50, 50],k = 4) == 50\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 9) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 20\n", "comparison": "exact"}, "public_tests": ["[5,2,2,4,0,6]\n4", "[2]\n1"], "hints": ["For each index i, how can we check if nums[i] can be present at the top of the pile or not after k moves?", "For which conditions will we end up with an empty pile?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumTop", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:45+00:00", "tests_total": 148, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumTop($nums, $k) {", "container": "Solution", "callable": "maximumTop", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2203, "task_id": "minimum-weighted-subgraph-with-the-required-paths", "difficulty": "Hard", "problem_description": "You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1.\n\nYou are also given a 2D integer array edges where edges[i] = [from_i, to_i, weight_i] denotes that there exists a directed edge from from_i to to_i with weight weight_i.\n\nLastly, you are given three distinct integers src1, src2, and dest denoting three distinct nodes of the graph.\n\nReturn the minimum weight of a subgraph of the graph such that it is possible to reach dest from both src1 and src2 via a set of edges of this subgraph. In case such a subgraph does not exist, return -1.\n\nA subgraph is a graph whose vertices and edges are subsets of the original graph. The weight of a subgraph is the sum of weights of its constituent edges.\n\nExample 1:\n\nInput: n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5\nOutput: 9\nExplanation:\nThe above figure represents the input graph.\nThe blue edges represent one of the subgraphs that yield the optimal answer.\nNote that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.\n\nExample 2:\n\nInput: n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2\nOutput: -1\nExplanation:\nThe above figure represents the input graph.\nIt can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints.\n\nConstraints:\n\n- 3 <= n <= 10^5\n- 0 <= edges.length <= 10^5\n- edges[i].length == 3\n- 0 <= from_i, to_i, src1, src2, dest <= n - 1\n- from_i != to_i\n- src1, src2, and dest are pairwise distinct.\n- 1 <= weight[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 2, 2], [0, 5, 6], [1, 0, 3], [1, 4, 5], [2, 1, 1], [2, 3, 3], [2, 3, 4], [3, 4, 2], [4, 5, 1]],src1 = 0,src2 = 1,dest = 5) == 9\n assert candidate(n = 6,edges = [[1, 2, 2], [1, 3, 1], [2, 4, 5], [3, 4, 3], [4, 5, 2]],src1 = 1,src2 = 2,dest = 5) == 9\n assert candidate(n = 3,edges = [[0, 1, 1], [2, 1, 1]],src1 = 0,src2 = 1,dest = 2) == -1\n assert candidate(n = 5,edges = [[0, 1, 10], [1, 2, 20], [2, 3, 30], [3, 4, 40], [4, 0, 50]],src1 = 0,src2 = 2,dest = 4) == 100\n assert candidate(n = 4,edges = [[0, 1, 2], [0, 2, 2], [1, 3, 1], [2, 3, 1]],src1 = 0,src2 = 1,dest = 3) == 3\n assert candidate(n = 5,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 0, 5]],src1 = 0,src2 = 1,dest = 4) == 10\n assert candidate(n = 5,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 1], [1, 4, 2], [2, 3, 4], [2, 4, 3]],src1 = 0,src2 = 1,dest = 4) == 10\n assert candidate(n = 5,edges = [[0, 1, 10], [0, 2, 3], [1, 3, 2], [2, 1, 4], [2, 3, 8], [2, 4, 2]],src1 = 0,src2 = 2,dest = 3) == 9\n assert candidate(n = 4,edges = [[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 1, 4]],src1 = 0,src2 = 2,dest = 3) == 6\n assert candidate(n = 5,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [2, 3, 1], [2, 4, 4]],src1 = 0,src2 = 2,dest = 3) == 4\n assert candidate(n = 4,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 1], [2, 3, 3]],src1 = 0,src2 = 1,dest = 3) == 3\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 1], [1, 4, 2], [2, 5, 1], [2, 6, 2], [3, 6, 1], [4, 6, 2]],src1 = 0,src2 = 1,dest = 6) == 3\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]],src1 = 0,src2 = 6,dest = 11) == 66\n assert candidate(n = 10,edges = [[0, 1, 20], [0, 2, 30], [1, 3, 40], [1, 4, 50], [2, 4, 60], [2, 5, 70], [3, 6, 80], [3, 7, 90], [4, 7, 100], [4, 8, 110], [5, 8, 120], [5, 9, 130], [6, 9, 140], [7, 9, 150]],src1 = 0,src2 = 2,dest = 9) == 230\n assert candidate(n = 6,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 4, 4], [3, 5, 5], [4, 5, 6]],src1 = 0,src2 = 1,dest = 5) == 9\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], [19, 0, 20], [0, 10, 1], [1, 11, 2], [2, 12, 3], [3, 13, 4], [4, 14, 5], [5, 15, 6], [6, 16, 7], [7, 17, 8], [8, 18, 9], [9, 19, 10], [10, 0, 11], [11, 1, 12], [12, 2, 13], [13, 3, 14], [14, 4, 15], [15, 5, 16], [16, 6, 17], [17, 7, 18], [18, 8, 19], [19, 9, 20]],src1 = 0,src2 = 2,dest = 19) == 55\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 5], [2, 4, 6], [3, 5, 7], [3, 6, 8], [4, 5, 9], [4, 6, 10], [5, 7, 11], [6, 7, 12]],src1 = 0,src2 = 3,dest = 7) == 22\n assert candidate(n = 15,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 3], [1, 4, 1], [2, 3, 1], [2, 4, 5], [3, 5, 2], [4, 5, 3], [5, 6, 4], [6, 7, 1], [7, 8, 3], [8, 9, 2], [9, 10, 4], [10, 11, 5], [11, 12, 6], [12, 13, 7], [13, 14, 8]],src1 = 0,src2 = 1,dest = 14) == 46\n assert candidate(n = 9,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, 8, 9], [6, 7, 10]],src1 = 0,src2 = 2,dest = 8) == 16\n assert candidate(n = 12,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 5], [2, 4, 6], [3, 5, 7], [3, 6, 8], [4, 5, 9], [4, 6, 10], [5, 7, 11], [6, 7, 12], [7, 8, 13], [8, 9, 14], [8, 10, 15], [9, 11, 16], [10, 11, 17]],src1 = 0,src2 = 5,dest = 11) == 65\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], [0, 5, 1], [1, 6, 2], [2, 7, 3], [3, 8, 4], [4, 9, 5], [5, 10, 6], [6, 11, 7], [7, 0, 8], [8, 1, 9], [9, 2, 10], [10, 3, 11], [11, 4, 12]],src1 = 0,src2 = 2,dest = 11) == 21\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 5], [2, 4, 6], [3, 5, 7], [3, 6, 8], [4, 5, 9], [4, 6, 10], [5, 7, 11], [6, 7, 12], [7, 8, 13]],src1 = 0,src2 = 4,dest = 8) == 38\n assert candidate(n = 8,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 2], [2, 4, 3], [3, 5, 1], [3, 6, 2], [4, 5, 2], [4, 6, 3], [5, 7, 1], [6, 7, 2]],src1 = 0,src2 = 2,dest = 7) == 6\n assert candidate(n = 7,edges = [[0, 1, 3], [0, 2, 5], [1, 2, 2], [1, 3, 8], [2, 3, 4], [2, 4, 9], [3, 4, 1], [3, 5, 6], [4, 5, 7], [4, 6, 10], [5, 6, 5]],src1 = 0,src2 = 2,dest = 6) == 20\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 5], [2, 3, 1], [2, 5, 7], [3, 6, 3], [4, 6, 2], [5, 6, 6]],src1 = 0,src2 = 2,dest = 6) == 7\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], [9, 0, 10], [0, 9, 15], [1, 8, 14], [2, 7, 13], [3, 6, 12], [4, 5, 11]],src1 = 0,src2 = 1,dest = 9) == 24\n assert candidate(n = 8,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 3], [1, 4, 5], [2, 4, 1], [2, 5, 6], [3, 6, 7], [4, 6, 8], [4, 7, 9], [5, 7, 3], [6, 7, 10]],src1 = 0,src2 = 1,dest = 7) == 16\n assert candidate(n = 12,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, 0, 13], [0, 5, 1], [1, 6, 2], [2, 7, 3], [3, 8, 4], [4, 9, 5], [5, 10, 6], [6, 11, 7], [7, 0, 8], [8, 1, 9], [9, 2, 10], [10, 3, 11], [11, 4, 12]],src1 = 0,src2 = 6,dest = 11) == 11\n assert candidate(n = 8,edges = [[0, 1, 5], [1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 0, 40], [0, 3, 2], [1, 4, 3], [2, 5, 4], [3, 6, 5], [4, 7, 6]],src1 = 0,src2 = 1,dest = 7) == 14\n assert candidate(n = 10,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [0, 3, 5], [1, 4, 6], [2, 5, 7], [3, 6, 8], [4, 7, 9], [5, 8, 10], [6, 9, 11]],src1 = 0,src2 = 2,dest = 9) == 25\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], [5, 7, 9], [6, 7, 10]],src1 = 0,src2 = 1,dest = 7) == 11\n assert candidate(n = 8,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [1, 4, 40], [2, 5, 50], [2, 6, 60], [3, 7, 70], [4, 7, 80], [5, 7, 90], [6, 7, 100]],src1 = 0,src2 = 2,dest = 7) == 160\n assert candidate(n = 7,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 5], [2, 4, 6], [3, 5, 7], [4, 5, 8], [5, 6, 9]],src1 = 0,src2 = 1,dest = 6) == 20\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], [9, 0, 10]],src1 = 0,src2 = 5,dest = 9) == 45\n assert candidate(n = 9,edges = [[0, 1, 1], [0, 2, 2], [1, 3, 3], [1, 4, 4], [2, 3, 5], [2, 5, 6], [3, 6, 7], [3, 7, 8], [4, 7, 9], [4, 8, 10], [5, 8, 11], [6, 8, 12]],src1 = 0,src2 = 2,dest = 8) == 19\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]],src1 = 0,src2 = 7,dest = 14) == 105\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 1], [1, 4, 4], [2, 1, 2], [2, 3, 6], [3, 4, 2], [4, 5, 7], [5, 6, 1], [6, 7, 2], [7, 8, 3], [8, 9, 1]],src1 = 0,src2 = 2,dest = 9) == 22\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 4], [2, 5, 6], [2, 6, 7], [3, 7, 8], [4, 8, 1], [5, 9, 2], [6, 9, 3], [7, 9, 9], [8, 9, 6]],src1 = 0,src2 = 2,dest = 9) == 11\n assert candidate(n = 11,edges = [[0, 1, 10], [0, 2, 20], [1, 3, 30], [1, 4, 40], [2, 4, 50], [2, 5, 60], [3, 6, 70], [3, 7, 80], [4, 7, 90], [4, 8, 100], [5, 8, 110], [5, 9, 120], [6, 9, 130], [6, 10, 140], [7, 10, 150], [8, 10, 160]],src1 = 0,src2 = 2,dest = 10) == 310\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], [9, 12, 19], [10, 13, 20], [11, 13, 21], [12, 14, 22]],src1 = 0,src2 = 5,dest = 14) == 62\n assert candidate(n = 15,edges = [[0, 1, 10], [0, 5, 20], [1, 2, 5], [1, 3, 15], [2, 4, 10], [3, 6, 20], [4, 7, 5], [5, 8, 15], [6, 9, 20], [7, 10, 10], [8, 11, 20], [9, 12, 25], [10, 13, 15], [11, 14, 25], [12, 13, 5], [13, 14, 20]],src1 = 0,src2 = 5,dest = 14) == 80\n assert candidate(n = 7,edges = [[0, 1, 10], [0, 2, 5], [1, 3, 1], [1, 4, 2], [2, 5, 4], [2, 6, 5], [3, 4, 3], [4, 5, 2], [5, 6, 1]],src1 = 0,src2 = 1,dest = 6) == 14\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], [5, 7, 9], [6, 7, 10], [3, 4, 11], [5, 6, 12]],src1 = 0,src2 = 2,dest = 7) == 16\n assert candidate(n = 15,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 1], [1, 4, 2], [2, 5, 4], [2, 6, 5], [3, 7, 6], [4, 8, 7], [5, 9, 8], [6, 10, 9], [7, 11, 10], [8, 12, 11], [9, 13, 12], [10, 14, 13], [11, 14, 14]],src1 = 0,src2 = 1,dest = 14) == 33\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, 8, 10], [7, 9, 11], [8, 9, 12]],src1 = 0,src2 = 2,dest = 9) == 16\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], [11, 14, 15], [12, 14, 16]],src1 = 0,src2 = 2,dest = 14) == 32\n assert candidate(n = 7,edges = [[0, 1, 5], [0, 2, 10], [1, 3, 3], [1, 4, 4], [2, 1, 6], [2, 4, 8], [2, 5, 7], [3, 6, 2], [4, 6, 5], [5, 6, 1]],src1 = 0,src2 = 2,dest = 6) == 16\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], [11, 12, 15], [12, 13, 16], [13, 14, 17]],src1 = 0,src2 = 1,dest = 14) == 58\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, 10]],src1 = 0,src2 = 1,dest = 9) == -1\n assert candidate(n = 10,edges = [[0, 1, 2], [0, 2, 4], [1, 3, 1], [1, 4, 3], [2, 5, 2], [2, 6, 5], [3, 7, 1], [4, 7, 2], [5, 8, 3], [6, 8, 4], [7, 9, 5], [8, 9, 6]],src1 = 0,src2 = 2,dest = 9) == 15\n assert candidate(n = 7,edges = [[0, 1, 2], [0, 2, 3], [1, 3, 4], [1, 4, 6], [2, 3, 5], [2, 5, 1], [3, 6, 3], [4, 6, 2], [5, 6, 7]],src1 = 0,src2 = 1,dest = 6) == 9\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], [0, 6, 8], [1, 5, 9], [2, 4, 10]],src1 = 0,src2 = 3,dest = 6) == 21\n assert candidate(n = 10,edges = [[0, 1, 5], [0, 2, 3], [1, 3, 2], [1, 4, 4], [2, 3, 1], [2, 5, 7], [3, 6, 3], [4, 6, 2], [5, 7, 6], [6, 8, 2], [7, 8, 5], [8, 9, 10]],src1 = 0,src2 = 1,dest = 9) == 21\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], [9, 11, 13], [10, 11, 14]],src1 = 0,src2 = 2,dest = 11) == 29\n assert candidate(n = 6,edges = [[0, 1, 100], [1, 2, 200], [2, 3, 300], [3, 4, 400], [4, 5, 500], [5, 0, 600]],src1 = 0,src2 = 3,dest = 5) == 1500\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], [0, 19, 1]],src1 = 0,src2 = 10,dest = 19) == 136\n assert candidate(n = 10,edges = [[0, 1, 10], [0, 2, 3], [1, 3, 2], [1, 4, 4], [2, 1, 4], [2, 3, 8], [2, 4, 2], [3, 5, 1], [4, 5, 3], [5, 6, 2], [6, 7, 1], [7, 8, 3], [8, 9, 2], [9, 6, 4]],src1 = 0,src2 = 2,dest = 8) == 14\n assert candidate(n = 6,edges = [[0, 1, 1000], [1, 2, 2000], [2, 3, 3000], [3, 4, 4000], [4, 5, 5000], [5, 0, 6000], [0, 2, 1500], [1, 3, 2500], [2, 4, 3500], [3, 5, 4500]],src1 = 0,src2 = 1,dest = 5) == 8000\n", "comparison": "exact"}, "public_tests": ["6\n[[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]]\n0\n1\n5", "3\n[[0,1,1],[2,1,1]]\n0\n1\n2"], "hints": ["Consider what the paths from src1 to dest and src2 to dest would look like in the optimal solution.", "It can be shown that in an optimal solution, the two paths from src1 and src2 will coincide at one node, and the remaining part to dest will be the same for both paths. Now consider how to find the node where the paths will coincide.", "How can algorithms for finding the shortest path between two nodes help us?"], "metadata": {"canonical_parameter_names": ["n", "edges", "src1", "src2", "dest"], "leetcode_dataset_entry_point": "Solution().minimumWeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:48+00:00", "tests_total": 58, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["graph", "heap-priority-queue", "shortest-path"]}, "language": "php", "interface": {"raw_signature": "function minimumWeight($n, $edges, $src1, $src2, $dest) {", "container": "Solution", "callable": "minimumWeight", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "src1", "type": "Integer"}, {"name": "src2", "type": "Integer"}, {"name": "dest", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2206, "task_id": "divide-array-into-equal-pairs", "difficulty": "Easy", "problem_description": "You are given an integer array nums consisting of 2 * n integers.\n\nYou need to divide nums into n pairs such that:\n\n- Each element belongs to exactly one pair.\n- The elements present in a pair are equal.\n\nReturn true if nums can be divided into n pairs, otherwise return false.\n\nExample 1:\n\nInput: nums = [3,2,3,2,2,2]\nOutput: true\nExplanation:\nThere are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.\nIf nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: false\nExplanation:\nThere is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.\n\nConstraints:\n\n- nums.length == 2 * n\n- 1 <= n <= 500\n- 1 <= nums[i] <= 500\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4]) == True\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 2, 1, 3, 2, 3]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [100, 100, 200, 200, 300, 300]) == True\n assert candidate(nums = [100, 200, 100, 200, 100, 200]) == False\n assert candidate(nums = [4, 4, 5, 5, 6, 6, 7, 7]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == True\n assert candidate(nums = [1, 2, 3, 4]) == False\n assert candidate(nums = [4, 4, 5, 5, 6, 6]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 7, 8, 8]) == True\n assert candidate(nums = [499, 499, 500, 500, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 2]) == False\n assert candidate(nums = [2, 3, 2, 3, 2, 3]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == True\n assert candidate(nums = [10, 10, 10, 10, 10, 10]) == True\n assert candidate(nums = [3, 2, 3, 2, 2, 2]) == True\n assert candidate(nums = [8, 8, 8, 8, 9, 9, 9, 9]) == 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 = [5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == False\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [500, 500, 499, 499, 498, 498]) == True\n assert candidate(nums = [1, 2, 1, 2, 3, 3]) == True\n assert candidate(nums = [499, 499, 498, 498, 497, 497]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]) == 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == True\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 = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499, 499]) == True\n assert candidate(nums = [499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491, 490, 490]) == 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]) == False\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]) == True\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]) == 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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == True\n assert candidate(nums = [50, 50, 50, 50, 20, 20, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40, 10, 10, 10, 10, 60, 60, 60, 60, 70, 70, 70, 70]) == 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, 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 = [250, 250, 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 = [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]) == 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, 1, 2, 3, 4, 5, 6, 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 = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493]) == 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 = [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]) == 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]) == 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]) == 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]) == True\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, 250, 250, 250, 250, 250, 250, 250, 250]) == 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]) == 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 = [100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107]) == 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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == True\n assert candidate(nums = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491, 490, 490, 489, 489, 488, 488, 487, 487, 486, 486]) == True\n assert candidate(nums = [450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6]) == False\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]) == True\n assert candidate(nums = [100, 100, 200, 200, 300, 300, 400, 400, 500, 500, 100, 200, 300, 400, 500, 100, 200, 300, 400, 500]) == True\n assert candidate(nums = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491, 490, 490, 489, 489, 488, 488, 487, 487, 486, 486, 485, 485, 484, 484, 483, 483, 482, 482, 481, 481, 480, 480]) == 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, 110, 110, 120, 120]) == 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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 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, 2]) == True\n assert candidate(nums = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495]) == True\n assert candidate(nums = [1, 1, 1, 1, 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]) == 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, 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]) == 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, 11, 11, 12, 12, 13, 13]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\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]) == False\n assert candidate(nums = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 7, 7, 7, 7, 9, 9, 9, 9, 8, 8, 8, 8, 6, 6, 6, 6, 4, 4, 4, 4]) == True\n assert candidate(nums = [10, 10, 20, 20, 20, 20, 30, 30, 30, 30, 30, 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, 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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == False\n assert candidate(nums = [500, 500, 499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491, 490, 490, 489, 489, 488, 488, 487, 487, 486, 486, 485, 485]) == True\n assert candidate(nums = [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]) == True\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]) == True\n assert candidate(nums = [499, 499, 498, 498, 497, 497, 496, 496, 495, 495, 494, 494, 493, 493, 492, 492, 491, 491, 490, 490]) == True\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10]) == 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]) == True\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255, 255, 256, 256, 257, 257, 258, 258, 259, 259, 260, 260]) == True\n assert candidate(nums = [150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250]) == True\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]) == True\n assert candidate(nums = [100, 100, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108]) == True\n assert candidate(nums = [150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150]) == 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, 2]) == False\n", "comparison": "exact"}, "public_tests": ["[3,2,3,2,2,2]", "[1,2,3,4]"], "hints": ["For any number x in the range [1, 500], count the number of elements in nums whose values are equal to x.", "The elements with equal value can be divided completely into pairs if and only if their count is even."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().divideArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:52+00:00", "tests_total": 91, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function divideArray($nums) {", "container": "Solution", "callable": "divideArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2207, "task_id": "maximize-number-of-subsequences-in-a-string", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.\n\nYou can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.\n\nReturn the maximum number of times pattern can occur as a subsequence of the modified text.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nExample 1:\n\nInput: text = \"abdcdbc\", pattern = \"ac\"\nOutput: 4\nExplanation:\nIf we add pattern[0] = 'a' in between text[1] and text[2], we get \"abadcdbc\". Now, the number of times \"ac\" occurs as a subsequence is 4.\nSome other strings which have 4 subsequences \"ac\" after adding a character to text are \"aabdcdbc\" and \"abdacdbc\".\nHowever, strings such as \"abdcadbc\", \"abdccdbc\", and \"abdcdbcc\", although obtainable, have only 3 subsequences \"ac\" and are thus suboptimal.\nIt can be shown that it is not possible to get more than 4 subsequences \"ac\" by adding only one character.\n\nExample 2:\n\nInput: text = \"aabb\", pattern = \"ab\"\nOutput: 6\nExplanation:\nSome of the strings which can be obtained from text and have 6 subsequences \"ab\" are \"aaabb\", \"aaabb\", and \"aabbb\".\n\nConstraints:\n\n- 1 <= text.length <= 10^5\n- pattern.length == 2\n- text and pattern consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(text = \"bbbb\",pattern = \"bb\") == 10\n assert candidate(text = \"aaaaa\",pattern = \"aa\") == 15\n assert candidate(text = \"zzzz\",pattern = \"zz\") == 10\n assert candidate(text = \"abdcdbc\",pattern = \"ac\") == 4\n assert candidate(text = \"abc\",pattern = \"ca\") == 1\n assert candidate(text = \"babab\",pattern = \"ba\") == 6\n assert candidate(text = \"zzz\",pattern = \"zz\") == 6\n assert candidate(text = \"abcabc\",pattern = \"aa\") == 3\n assert candidate(text = \"a\",pattern = \"ab\") == 1\n assert candidate(text = \"ab\",pattern = \"ba\") == 1\n assert candidate(text = \"aabb\",pattern = \"ab\") == 6\n assert candidate(text = \"aaa\",pattern = \"aa\") == 6\n assert candidate(text = \"b\",pattern = \"ab\") == 1\n assert candidate(text = \"aaaa\",pattern = \"aa\") == 10\n assert candidate(text = \"xyzxyz\",pattern = \"yx\") == 3\n assert candidate(text = \"abcabc\",pattern = \"ac\") == 5\n assert candidate(text = \"xyz\",pattern = \"xz\") == 2\n assert candidate(text = \"abxyabxyabxy\",pattern = \"bx\") == 9\n assert candidate(text = \"zxyzxyzxyz\",pattern = \"yz\") == 10\n assert candidate(text = \"xyzyzyzyzyzx\",pattern = \"yx\") == 10\n assert candidate(text = \"zzzzzzzzzzz\",pattern = \"zz\") == 66\n assert candidate(text = \"pqrsrstq\",pattern = \"pq\") == 4\n assert candidate(text = \"bbabbaaa\",pattern = \"ba\") == 18\n assert candidate(text = \"ababababab\",pattern = \"ba\") == 15\n assert candidate(text = \"aaaaabbbbb\",pattern = \"ab\") == 30\n assert candidate(text = \"aaabbbccc\",pattern = \"ac\") == 12\n assert candidate(text = \"abacabacaba\",pattern = \"ac\") == 12\n assert candidate(text = \"abcdefabcdef\",pattern = \"cf\") == 5\n assert candidate(text = \"bbaabb\",pattern = \"ba\") == 8\n assert candidate(text = \"bcbcbcbcbb\",pattern = \"bc\") == 16\n assert candidate(text = \"bbaabaabaabbb\",pattern = \"ab\") == 31\n assert candidate(text = \"bbbbba\",pattern = \"ba\") == 10\n assert candidate(text = \"acbacbacba\",pattern = \"ac\") == 10\n assert candidate(text = \"mnopqr\",pattern = \"pq\") == 2\n assert candidate(text = \"xyxzyxzyxzyx\",pattern = \"yx\") == 15\n assert candidate(text = \"zzyzxzyzxzy\",pattern = \"yz\") == 12\n assert candidate(text = \"xyyxxyyxxyy\",pattern = \"yx\") == 18\n assert candidate(text = \"aabbccdd\",pattern = \"ac\") == 6\n assert candidate(text = \"abcdabcdabcd\",pattern = \"ac\") == 9\n assert candidate(text = \"mississippi\",pattern = \"is\") == 10\n assert candidate(text = \"zzzzzzzzzz\",pattern = \"zz\") == 55\n assert candidate(text = \"ababababab\",pattern = \"ab\") == 20\n assert candidate(text = \"aabbaabbaabbaabbaabbaabbaabbaabb\",pattern = \"bb\") == 136\n assert candidate(text = \"qwertyuiop\",pattern = \"qp\") == 2\n assert candidate(text = \"aaaaaaa\",pattern = \"aa\") == 28\n assert candidate(text = \"abcdabcdabcd\",pattern = \"da\") == 6\n assert candidate(text = \"zzzzz\",pattern = \"zz\") == 15\n assert candidate(text = \"abababababab\",pattern = \"ba\") == 21\n assert candidate(text = \"abababababa\",pattern = \"ab\") == 21\n assert candidate(text = \"abcabcabcabc\",pattern = \"ac\") == 14\n assert candidate(text = \"aabbbcc\",pattern = \"ac\") == 6\n assert candidate(text = \"aabbaabbaabbaabbaabb\",pattern = \"aa\") == 55\n assert candidate(text = \"babcbabcba\",pattern = \"bc\") == 11\n assert candidate(text = \"aabbccddeeff\",pattern = \"bf\") == 6\n assert candidate(text = \"abcabcabc\",pattern = \"ab\") == 9\n assert candidate(text = \"bcbcbcbcbc\",pattern = \"bc\") == 20\n assert candidate(text = \"xyxxyxyxyx\",pattern = \"yx\") == 17\n assert candidate(text = \"abcabcabcabcabcabc\",pattern = \"ca\") == 21\n assert candidate(text = \"xzyxzyxzyz\",pattern = \"zy\") == 10\n assert candidate(text = \"zzzzzz\",pattern = \"zz\") == 21\n assert candidate(text = \"aabbbaaabbbb\",pattern = \"ab\") == 33\n assert candidate(text = \"aaabbb\",pattern = \"ab\") == 12\n assert candidate(text = \"nnaaaannaa\",pattern = \"an\") == 14\n assert candidate(text = \"xyxyxyxyxy\",pattern = \"yx\") == 15\n assert candidate(text = \"cccccc\",pattern = \"cc\") == 21\n assert candidate(text = \"abacabadabacaba\",pattern = \"ba\") == 24\n assert candidate(text = \"bababababababababa\",pattern = \"bb\") == 45\n assert candidate(text = \"dcbabcdabcba\",pattern = \"ab\") == 9\n assert candidate(text = \"xyzzyxzyxzyxzyx\",pattern = \"zy\") == 19\n assert candidate(text = \"aaaaaabbbb\",pattern = \"ab\") == 30\n assert candidate(text = \"cccccccc\",pattern = \"cc\") == 36\n assert candidate(text = \"babcbacbab\",pattern = \"bc\") == 10\n assert candidate(text = \"abcdefghijklmnopqrstuvwxyz\",pattern = \"zy\") == 1\n assert candidate(text = \"zzzyyy\",pattern = \"yz\") == 3\n assert candidate(text = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",pattern = \"zz\") == 406\n assert candidate(text = \"mnopqrqpomn\",pattern = \"mn\") == 5\n assert candidate(text = \"aabbaabb\",pattern = \"bb\") == 10\n assert candidate(text = \"aabbccddeeffgg\",pattern = \"ag\") == 6\n assert candidate(text = \"ccbaaa\",pattern = \"ab\") == 3\n assert candidate(text = \"xyzzyxzyzxzyxzyx\",pattern = \"yz\") == 20\n assert candidate(text = \"aaaaaaaaa\",pattern = \"aa\") == 45\n assert candidate(text = \"aabbaabb\",pattern = \"ab\") == 16\n assert candidate(text = \"bababababababa\",pattern = \"ba\") == 35\n assert candidate(text = \"bababababa\",pattern = \"ba\") == 20\n assert candidate(text = \"zyxwvutsrqponmlkjihgfedcba\",pattern = \"yz\") == 1\n assert candidate(text = \"qqqqqqqqqq\",pattern = \"qp\") == 10\n assert candidate(text = \"qwertyuiopasdfghjklzxcvbnm\",pattern = \"mn\") == 1\n assert candidate(text = \"abcabcdabc\",pattern = \"bc\") == 9\n assert candidate(text = \"zzzzyyyy\",pattern = \"zy\") == 20\n assert candidate(text = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",pattern = \"xz\") == 6\n assert candidate(text = \"abacabacab\",pattern = \"ac\") == 11\n assert candidate(text = \"fedcba\",pattern = \"ab\") == 1\n assert candidate(text = \"ccccbbbaaa\",pattern = \"ba\") == 12\n assert candidate(text = \"mmnnnmmnnm\",pattern = \"mn\") == 19\n assert candidate(text = \"abcabcabc\",pattern = \"ba\") == 6\n assert candidate(text = \"xyzxyzxyzxyz\",pattern = \"yx\") == 10\n assert candidate(text = \"qqqqqppppp\",pattern = \"pq\") == 5\n assert candidate(text = \"aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb\",pattern = \"ba\") == 20\n assert candidate(text = \"abbaba\",pattern = \"ab\") == 7\n assert candidate(text = \"zzzzzzzzzzzzz\",pattern = \"zz\") == 91\n assert candidate(text = \"zzyzxzyzxzyz\",pattern = \"yz\") == 16\n assert candidate(text = \"aabbaabb\",pattern = \"aa\") == 10\n assert candidate(text = \"abcabcabcabcabc\",pattern = \"ab\") == 20\n assert candidate(text = \"babbabababababababa\",pattern = \"ba\") == 63\n assert candidate(text = \"aaabbbcccddd\",pattern = \"ad\") == 12\n assert candidate(text = \"abcdef\",pattern = \"fe\") == 1\n assert candidate(text = \"bbbbbbbbbb\",pattern = \"bb\") == 55\n assert candidate(text = \"bbbbbaaaaa\",pattern = \"ab\") == 5\n assert candidate(text = \"abcde\",pattern = \"ae\") == 2\n assert candidate(text = \"abracadabra\",pattern = \"ra\") == 10\n assert candidate(text = \"abcdefghij\",pattern = \"ae\") == 2\n assert candidate(text = \"aaabbbccc\",pattern = \"ab\") == 12\n assert candidate(text = \"abcdefghij\",pattern = \"aj\") == 2\n assert candidate(text = \"xyzzyxzyxzyxzyxzyxzyxzyx\",pattern = \"zx\") == 43\n assert candidate(text = \"mmnmmnmmn\",pattern = \"mn\") == 18\n assert candidate(text = \"aabbccddeeff\",pattern = \"ef\") == 6\n assert candidate(text = \"zzzzzzzz\",pattern = \"zz\") == 36\n assert candidate(text = \"ccccccc\",pattern = \"cc\") == 28\n assert candidate(text = \"abcabcabc\",pattern = \"bc\") == 9\n assert candidate(text = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",pattern = \"az\") == 6\n assert candidate(text = \"abcdefghij\",pattern = \"af\") == 2\n assert candidate(text = \"bbbbbaaaaa\",pattern = \"ba\") == 30\n assert candidate(text = \"xyzyxzyxzy\",pattern = \"yx\") == 9\n assert candidate(text = \"aabccbaa\",pattern = \"ac\") == 8\n assert candidate(text = \"abacabadabacaba\",pattern = \"ab\") == 24\n assert candidate(text = \"aabccccdddd\",pattern = \"cd\") == 20\n assert candidate(text = \"aaaaaaaaaa\",pattern = \"aa\") == 55\n assert candidate(text = \"aaaabbbb\",pattern = \"ab\") == 20\n assert candidate(text = \"aaaaaaaaaaaabbbbbbbbbbbb\",pattern = \"ab\") == 156\n assert candidate(text = \"abcdefghijklnmopqrstuvwxyz\",pattern = \"az\") == 2\n assert candidate(text = \"abcd\",pattern = \"da\") == 1\n assert candidate(text = \"abcdabcdabcd\",pattern = \"ad\") == 9\n assert candidate(text = \"lkjqwpmr\",pattern = \"qw\") == 2\n assert candidate(text = \"aabbaabbcc\",pattern = \"ab\") == 16\n assert candidate(text = \"abcabcabc\",pattern = \"ac\") == 9\n assert candidate(text = \"baabbaab\",pattern = \"ba\") == 12\n", "comparison": "exact"}, "public_tests": ["\"abdcdbc\"\n\"ac\"", "\"aabb\"\n\"ab\""], "hints": ["Find the optimal position to add pattern[0] so that the number of subsequences is maximized. Similarly, find the optimal position to add pattern[1].", "For each of the above cases, count the number of times the pattern occurs as a subsequence in text. The larger count is the required answer."], "metadata": {"canonical_parameter_names": ["text", "pattern"], "leetcode_dataset_entry_point": "Solution().maximumSubsequenceCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:55+00:00", "tests_total": 138, "tests_dropped": 2, "flags": [], "topic_tags": ["string", "greedy", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maximumSubsequenceCount($text, $pattern) {", "container": "Solution", "callable": "maximumSubsequenceCount", "parameters": [{"name": "text", "type": "String"}, {"name": "pattern", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2208, "task_id": "minimum-operations-to-halve-array-sum", "difficulty": "Medium", "problem_description": "You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)\n\nReturn the minimum number of operations to reduce the sum of nums by at least half.\n\nExample 1:\n\nInput: nums = [5,19,8,1]\nOutput: 3\nExplanation: The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.\nThe following is one of the ways to reduce the sum by at least half:\nPick the number 19 and reduce it to 9.5.\nPick the number 9.5 and reduce it to 4.75.\nPick the number 8 and reduce it to 4.\nThe final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75.\nThe sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.\nOverall, 3 operations were used so we return 3.\nIt can be shown that we cannot reduce the sum by at least half in less than 3 operations.\n\nExample 2:\n\nInput: nums = [3,8,20]\nOutput: 3\nExplanation: The initial sum of nums is equal to 3 + 8 + 20 = 31.\nThe following is one of the ways to reduce the sum by at least half:\nPick the number 20 and reduce it to 10.\nPick the number 10 and reduce it to 5.\nPick the number 3 and reduce it to 1.5.\nThe final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5.\nThe sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5.\nOverall, 3 operations were used so we return 3.\nIt can be shown that we cannot reduce the sum by at least half in less than 3 operations.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10]) == 4\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [100, 100, 100, 100]) == 4\n assert candidate(nums = [3, 8, 20]) == 3\n assert candidate(nums = [10000000]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [5, 19, 8, 1]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [10, 10, 10, 10, 10]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 10\n assert candidate(nums = [10, 20, 30, 40]) == 4\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 13\n assert candidate(nums = [9999999, 9999998, 9999997, 9999996, 9999995]) == 5\n assert candidate(nums = [5000000, 5000000, 5000000, 5000000, 5000000]) == 5\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 3\n assert candidate(nums = [1000, 500, 250, 125, 62.5, 31.25]) == 3\n assert candidate(nums = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250]) == 3\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584]) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 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]) == 24\n assert candidate(nums = [1, 1000000, 100000, 10000, 1000]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 3\n assert candidate(nums = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == 9\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000]) == 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]) == 16\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 3\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 3\n assert candidate(nums = [5000000, 3000000, 2000000, 1000000, 500000, 300000, 200000, 100000]) == 4\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]) == 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]) == 30\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 15\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250]) == 3\n assert candidate(nums = [1234567, 2345678, 3456789, 4567890, 5678901, 6789012, 7890123, 8901234, 9012345]) == 8\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500]) == 16\n assert candidate(nums = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062, 19531]) == 3\n assert candidate(nums = [9999999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000]) == 4\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1]) == 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]) == 18\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 3\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == 9\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [1, 10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062, 19531, 9765, 4882, 2441, 1220, 610, 305, 152, 76, 38]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 2\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 20\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000]) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 12\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996]) == 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]) == 25\n assert candidate(nums = [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, 100000]) == 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]) == 20\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 14\n assert candidate(nums = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062.5, 19531.25]) == 3\n assert candidate(nums = [10000000, 1, 2, 3, 4, 5, 6, 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\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]) == 2\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 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]) == 20\n assert candidate(nums = [9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990]) == 10\n assert candidate(nums = [5000000, 5000000, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [9999999, 8888888, 7777777, 6666666, 5555555, 4444444, 3333333, 2222222, 1111111]) == 8\n assert candidate(nums = [9999999, 1, 1, 1]) == 2\n assert candidate(nums = [10000000, 9000000, 8000000, 7000000, 6000000, 5000000, 4000000, 3000000, 2000000, 1000000]) == 9\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 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]) == 16\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 12\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 12\n assert candidate(nums = [9999999, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000]) == 9\n assert candidate(nums = [5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000]) == 10\n assert candidate(nums = [5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062.5, 19531.25, 9765.625]) == 3\n assert candidate(nums = [5000000, 3000000, 2000000, 4000000, 1000000]) == 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]) == 20\n assert candidate(nums = [5000000, 4000000, 3000000, 2000000, 1000000, 500000, 250000, 125000, 62500, 31250]) == 5\n", "comparison": "exact"}, "public_tests": ["[5,19,8,1]", "[3,8,20]"], "hints": ["It is always optimal to halve the largest element.", "What data structure allows for an efficient query of the maximum element?", "Use a heap or priority queue to maintain the current elements."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().halveArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:57+00:00", "tests_total": 81, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function halveArray($nums) {", "container": "Solution", "callable": "halveArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2209, "task_id": "minimum-white-tiles-after-covering-with-carpets", "difficulty": "Hard", "problem_description": "You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:\n\n- floor[i] = '0' denotes that the i^th tile of the floor is colored black.\n- On the other hand, floor[i] = '1' denotes that the i^th tile of the floor is colored white.\n\nYou are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.\n\nReturn the minimum number of white tiles still visible.\n\nExample 1:\n\nInput: floor = \"10110101\", numCarpets = 2, carpetLen = 2\nOutput: 2\nExplanation:\nThe figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.\nNo other way of covering the tiles with the carpets can leave less than 2 white tiles visible.\n\nExample 2:\n\nInput: floor = \"11111\", numCarpets = 2, carpetLen = 3\nOutput: 0\nExplanation:\nThe figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.\nNote that the carpets are able to overlap one another.\n\nConstraints:\n\n- 1 <= carpetLen <= floor.length <= 1000\n- floor[i] is either '0' or '1'.\n- 1 <= numCarpets <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(floor = \"111100001111\",numCarpets = 4,carpetLen = 4) == 0\n assert candidate(floor = \"110011\",numCarpets = 3,carpetLen = 2) == 0\n assert candidate(floor = \"11111\",numCarpets = 2,carpetLen = 3) == 0\n assert candidate(floor = \"1010101010\",numCarpets = 5,carpetLen = 1) == 0\n assert candidate(floor = \"11001100\",numCarpets = 3,carpetLen = 2) == 0\n assert candidate(floor = \"11010110\",numCarpets = 3,carpetLen = 1) == 2\n assert candidate(floor = \"10110101\",numCarpets = 2,carpetLen = 2) == 2\n assert candidate(floor = \"1110111\",numCarpets = 1,carpetLen = 4) == 3\n assert candidate(floor = \"111000111\",numCarpets = 2,carpetLen = 4) == 0\n assert candidate(floor = \"00000\",numCarpets = 1,carpetLen = 1) == 0\n assert candidate(floor = \"00000\",numCarpets = 1,carpetLen = 2) == 0\n assert candidate(floor = \"1111001111001111001111001111001111001111001111001111001111\",numCarpets = 12,carpetLen = 5) == 0\n assert candidate(floor = \"110011001100110011001100110011001100110011001100\",numCarpets = 5,carpetLen = 3) == 14\n assert candidate(floor = \"10101010101010101010101010101010101010101010\",numCarpets = 20,carpetLen = 5) == 0\n assert candidate(floor = \"110011001100110011001100110011001100110011001100\",numCarpets = 15,carpetLen = 4) == 0\n assert candidate(floor = \"010101010101010101010101010101010101010101010101\",numCarpets = 10,carpetLen = 5) == 0\n assert candidate(floor = \"111101010101010101010101010101010101010101\",numCarpets = 10,carpetLen = 7) == 0\n assert candidate(floor = \"110001001001001001001001001001001001001001001001\",numCarpets = 20,carpetLen = 4) == 0\n assert candidate(floor = \"1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\",numCarpets = 20,carpetLen = 5) == 0\n assert candidate(floor = \"1111000011110000111100001111\",numCarpets = 6,carpetLen = 4) == 0\n assert candidate(floor = \"0000000000000000000000000000\",numCarpets = 10,carpetLen = 10) == 0\n assert candidate(floor = \"11111111111111111111111111111111111111\",numCarpets = 1000,carpetLen = 1) == 0\n assert candidate(floor = \"11111000001111111100\",numCarpets = 4,carpetLen = 4) == 0\n assert candidate(floor = \"11110111101111011110111101\",numCarpets = 10,carpetLen = 2) == 1\n assert candidate(floor = \"010101010101010101010101010101010101010101010101\",numCarpets = 18,carpetLen = 7) == 0\n assert candidate(floor = \"101010101010101010101010101010101010101010101010\",numCarpets = 25,carpetLen = 2) == 0\n assert candidate(floor = \"10000000000000000000000000\",numCarpets = 1,carpetLen = 10) == 0\n assert candidate(floor = \"11100011111000111000\",numCarpets = 5,carpetLen = 4) == 0\n assert candidate(floor = \"111111111111111111111111111111111111111111111111\",numCarpets = 10,carpetLen = 5) == 0\n assert candidate(floor = \"10101010101010101010101010101010101010101010101010\",numCarpets = 15,carpetLen = 4) == 0\n assert candidate(floor = \"10001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000\",numCarpets = 25,carpetLen = 8) == 0\n assert candidate(floor = \"00001111000011110000111100001111\",numCarpets = 12,carpetLen = 4) == 0\n assert candidate(floor = \"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",numCarpets = 50,carpetLen = 10) == 0\n assert candidate(floor = \"0000000000000000000000000000000000000000\",numCarpets = 20,carpetLen = 5) == 0\n assert candidate(floor = \"1010101010101010101010101010101010101010101010101010\",numCarpets = 10,carpetLen = 2) == 16\n assert candidate(floor = \"10010010010010010010010010010010010010\",numCarpets = 10,carpetLen = 3) == 3\n assert candidate(floor = \"01010101010101010101\",numCarpets = 5,carpetLen = 4) == 0\n assert candidate(floor = \"0001111111000111111000111111\",numCarpets = 6,carpetLen = 5) == 0\n assert candidate(floor = \"01010101010101010101010101010101010101\",numCarpets = 8,carpetLen = 2) == 11\n assert candidate(floor = \"11111000011111000011111000011111\",numCarpets = 4,carpetLen = 5) == 0\n assert candidate(floor = \"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",numCarpets = 100,carpetLen = 10) == 0\n assert candidate(floor = \"0101010101010101010101010101\",numCarpets = 10,carpetLen = 3) == 0\n assert candidate(floor = \"11100011100011100011\",numCarpets = 6,carpetLen = 3) == 0\n assert candidate(floor = \"11111111111111111111\",numCarpets = 3,carpetLen = 5) == 5\n assert candidate(floor = \"111111000011111100001111110000111111\",numCarpets = 8,carpetLen = 5) == 0\n assert candidate(floor = \"1111111111111111111111111111111111111111\",numCarpets = 16,carpetLen = 10) == 0\n assert candidate(floor = \"1010101010101010101010101010101010101010101010101010101010101010\",numCarpets = 20,carpetLen = 6) == 0\n assert candidate(floor = \"11001100110011001100110011001100\",numCarpets = 8,carpetLen = 2) == 0\n assert candidate(floor = \"00100100100100100100100100\",numCarpets = 10,carpetLen = 3) == 0\n assert candidate(floor = \"11111111111111111111111111\",numCarpets = 15,carpetLen = 2) == 0\n assert candidate(floor = \"1111011011111100001101110111\",numCarpets = 5,carpetLen = 6) == 0\n assert candidate(floor = \"111111111111111111111111111111111111111111111111\",numCarpets = 50,carpetLen = 1) == 0\n assert candidate(floor = \"110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100\",numCarpets = 15,carpetLen = 4) == 24\n assert candidate(floor = \"11101110111011101110111011\",numCarpets = 7,carpetLen = 4) == 0\n assert candidate(floor = \"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\",numCarpets = 15,carpetLen = 4) == 18\n assert candidate(floor = \"100110011001100110011001100110011001\",numCarpets = 8,carpetLen = 4) == 2\n assert candidate(floor = \"10101010101010101010101010101010\",numCarpets = 7,carpetLen = 4) == 2\n assert candidate(floor = \"1111000011110000111100001111000011110000111100001111000011110000111100001111000011110000\",numCarpets = 10,carpetLen = 7) == 4\n assert candidate(floor = \"111100001111000011110000111100001111000011110000\",numCarpets = 5,carpetLen = 4) == 4\n assert candidate(floor = \"11111111111111111111111111\",numCarpets = 10,carpetLen = 6) == 0\n assert candidate(floor = \"10001000100010001000100010001000\",numCarpets = 9,carpetLen = 3) == 0\n assert candidate(floor = \"111000111000111000111000111000111000\",numCarpets = 10,carpetLen = 2) == 2\n assert candidate(floor = \"111111000000111111000000111111000000111111000000111111\",numCarpets = 15,carpetLen = 7) == 0\n assert candidate(floor = \"111111111111111111111111111111111111\",numCarpets = 10,carpetLen = 7) == 0\n assert candidate(floor = \"11111111111111111111111111111111\",numCarpets = 5,carpetLen = 5) == 7\n assert candidate(floor = \"01010101010101010101010101\",numCarpets = 10,carpetLen = 5) == 0\n assert candidate(floor = \"1010101010101010101010101010101010101010101010101010101010101010\",numCarpets = 30,carpetLen = 4) == 0\n assert candidate(floor = \"1010101010101010101010101010\",numCarpets = 10,carpetLen = 5) == 0\n assert candidate(floor = \"01010101010101010101\",numCarpets = 3,carpetLen = 2) == 7\n assert candidate(floor = \"11111111111111111111\",numCarpets = 5,carpetLen = 5) == 0\n assert candidate(floor = \"1111000011110000111100001111000011110000111100001111000011110000111100001111000011110000\",numCarpets = 30,carpetLen = 5) == 0\n assert candidate(floor = \"11110000111100001111\",numCarpets = 4,carpetLen = 5) == 0\n assert candidate(floor = \"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",numCarpets = 50,carpetLen = 12) == 0\n assert candidate(floor = \"10101010101010101010101010\",numCarpets = 15,carpetLen = 2) == 0\n assert candidate(floor = \"11010101010101010101\",numCarpets = 5,carpetLen = 3) == 1\n assert candidate(floor = \"11101110111011101110111011101110\",numCarpets = 10,carpetLen = 2) == 6\n assert candidate(floor = \"000000000000000000000000000000000000000000000000\",numCarpets = 10,carpetLen = 15) == 0\n assert candidate(floor = \"11111111111111111111111111111111\",numCarpets = 15,carpetLen = 5) == 0\n assert candidate(floor = \"111111111111111111111111111111111111111111111111\",numCarpets = 25,carpetLen = 10) == 0\n assert candidate(floor = \"11111111000000001111111100000000\",numCarpets = 3,carpetLen = 8) == 0\n assert candidate(floor = \"110110110110110110110110110110110110110110110110\",numCarpets = 12,carpetLen = 6) == 0\n assert candidate(floor = \"1111000011110000111100001111000011110000111100001111\",numCarpets = 10,carpetLen = 8) == 0\n assert candidate(floor = \"01010101010101010101010101010101010101010101\",numCarpets = 4,carpetLen = 7) == 6\n assert candidate(floor = \"1111111111111111111111111111\",numCarpets = 15,carpetLen = 4) == 0\n assert candidate(floor = \"11111111111111111111\",numCarpets = 6,carpetLen = 5) == 0\n assert candidate(floor = \"111111111100000000000000111111111111111111111111\",numCarpets = 5,carpetLen = 10) == 0\n assert candidate(floor = \"100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100\",numCarpets = 20,carpetLen = 6) == 0\n assert candidate(floor = \"1111100000111110000011111\",numCarpets = 3,carpetLen = 6) == 0\n assert candidate(floor = \"01010101010101010101010101010101\",numCarpets = 10,carpetLen = 3) == 0\n assert candidate(floor = \"11110111101111011110\",numCarpets = 5,carpetLen = 3) == 2\n assert candidate(floor = \"00101010101010101010\",numCarpets = 5,carpetLen = 3) == 0\n assert candidate(floor = \"11111111111111111111\",numCarpets = 10,carpetLen = 2) == 0\n assert candidate(floor = \"111000111000111000111000111000111\",numCarpets = 8,carpetLen = 4) == 0\n assert candidate(floor = \"10101010101010101010\",numCarpets = 5,carpetLen = 3) == 0\n assert candidate(floor = \"11110000111100001111000011110000\",numCarpets = 6,carpetLen = 4) == 0\n assert candidate(floor = \"10101010101010101010101010101010101010101010101010101010101010101010101010101010\",numCarpets = 20,carpetLen = 5) == 0\n assert candidate(floor = \"111000111000111000111\",numCarpets = 4,carpetLen = 3) == 0\n assert candidate(floor = \"10101010101010101010\",numCarpets = 3,carpetLen = 4) == 4\n assert candidate(floor = \"000000000000000000000000000000000000000000000000\",numCarpets = 10,carpetLen = 3) == 0\n assert candidate(floor = \"1001001001001001001001001\",numCarpets = 7,carpetLen = 4) == 0\n assert candidate(floor = \"01010101010101010101010101010101010101010101010101010101010\",numCarpets = 25,carpetLen = 3) == 0\n assert candidate(floor = \"11111111111111111111\",numCarpets = 5,carpetLen = 3) == 5\n assert candidate(floor = \"101010101010101010101010101010101010\",numCarpets = 15,carpetLen = 6) == 0\n assert candidate(floor = \"111101110111011101110111011101110111\",numCarpets = 5,carpetLen = 4) == 12\n assert candidate(floor = \"1010101010101010101010101010\",numCarpets = 8,carpetLen = 3) == 0\n assert candidate(floor = \"000101001010100110010010001000101010010101010101\",numCarpets = 15,carpetLen = 3) == 0\n assert candidate(floor = \"11001100110011001100\",numCarpets = 8,carpetLen = 3) == 0\n assert candidate(floor = \"1110111011101110111011101110111011101110111011101110111011101110\",numCarpets = 8,carpetLen = 3) == 24\n", "comparison": "exact"}, "public_tests": ["\"10110101\"\n2\n2", "\"11111\"\n2\n3"], "hints": ["Can you think of a DP solution?", "Let DP[i][j] denote the minimum number of white tiles still visible from indices i to floor.length-1 after covering with at most j carpets.", "The transition will be whether to put down the carpet at position i (if possible), or not."], "metadata": {"canonical_parameter_names": ["floor", "numCarpets", "carpetLen"], "leetcode_dataset_entry_point": "Solution().minimumWhiteTiles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:44:59+00:00", "tests_total": 110, "tests_dropped": 2, "flags": ["figure_reference", "has_images"], "topic_tags": ["string", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minimumWhiteTiles($floor, $numCarpets, $carpetLen) {", "container": "Solution", "callable": "minimumWhiteTiles", "parameters": [{"name": "floor", "type": "String"}, {"name": "numCarpets", "type": "Integer"}, {"name": "carpetLen", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2210, "task_id": "count-hills-and-valleys-in-an-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or valley if nums[i] == nums[j].\n\nNote that for an index to be part of a hill or valley, it must have a non-equal neighbor on both the left and right of the index.\n\nReturn the number of hills and valleys in nums.\n\nExample 1:\n\nInput: nums = [2,4,1,1,6,5]\nOutput: 3\nExplanation:\nAt index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley.\nAt index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill.\nAt index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley.\nAt index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2.\nAt index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill.\nAt index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley.\nThere are 3 hills and valleys so we return 3.\n\nExample 2:\n\nInput: nums = [6,6,5,5,4,1]\nOutput: 0\nExplanation:\nAt index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley.\nAt index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley.\nAt index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley.\nAt index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley.\nAt index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley.\nAt index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley.\nThere are 0 hills and valleys so we return 0.\n\nConstraints:\n\n- 3 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 4, 3, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 0\n assert candidate(nums = [100, 99, 100, 98, 99, 100]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [5, 4, 4, 3, 3, 2, 2, 1]) == 0\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(nums = [1, 3, 2, 3, 1]) == 3\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 0\n assert candidate(nums = [1, 3, 2, 4, 3, 5]) == 4\n assert candidate(nums = [3, 1, 2, 1, 3, 2, 1]) == 4\n assert candidate(nums = [2, 4, 1, 1, 6, 5]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 1, 1]) == 1\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 1]) == 3\n assert candidate(nums = [6, 6, 5, 5, 4, 1]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 2, 1]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 2, 2, 2, 3]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3]) == 2\n assert candidate(nums = [1, 3, 1, 2, 1, 3, 1]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2]) == 2\n assert candidate(nums = [50, 50, 49, 51, 49, 51, 50]) == 4\n assert candidate(nums = [9, 8, 9, 8, 9, 8, 9]) == 5\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3]) == 3\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 96, 97, 98, 99, 100]) == 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, 2, 3, 4, 3, 2]) == 9\n assert candidate(nums = [3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3]) == 11\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 4, 3, 2, 1]) == 5\n assert candidate(nums = [3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1]) == 10\n assert candidate(nums = [50, 50, 50, 50, 51, 50, 50, 50, 50, 51, 50, 50, 50, 50]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 4, 3, 2, 1, 1, 1]) == 1\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2]) == 5\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9]) == 12\n assert candidate(nums = [10, 9, 8, 7, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 6, 7, 8, 9]) == 3\n assert candidate(nums = [1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2]) == 17\n assert candidate(nums = [100, 90, 100, 90, 100, 90, 100, 80, 90, 80]) == 8\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4]) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 2, 2, 1, 1]) == 1\n assert candidate(nums = [3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2]) == 3\n assert candidate(nums = [1, 3, 2, 3, 1, 3, 2, 1, 2, 3, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 2, 3, 1, 2, 1]) == 7\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 = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [2, 2, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == 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 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 1, 1, 1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 2\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]) == 28\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3]) == 4\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, 10, 9, 8, 7, 6, 5]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 8\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 2, 1, 3, 2, 3, 1]) == 9\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 7\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 7\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [10, 20, 10, 30, 10, 20, 10, 30, 10, 20, 10]) == 9\n assert candidate(nums = [50, 51, 52, 51, 50, 51, 52, 51, 50, 51, 52, 51]) == 5\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4]) == 8\n assert candidate(nums = [1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1]) == 9\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 5, 6, 5, 7, 4, 8, 3, 9, 2, 10]) == 18\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 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]) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9]) == 12\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2]) == 8\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [30, 20, 10, 20, 30, 20, 10, 20, 30, 20, 10]) == 4\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 13\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 8\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 0\n assert candidate(nums = [2, 2, 2, 3, 3, 2, 2, 2, 1, 1, 2, 2, 2]) == 2\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 8\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9]) == 13\n assert candidate(nums = [100, 99, 98, 97, 98, 99, 100, 99, 98, 97, 96, 97, 98, 99, 100, 99]) == 4\n assert candidate(nums = [1, 1, 2, 3, 2, 1, 1, 2, 3, 2, 1, 1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2]) == 8\n assert candidate(nums = [1, 1, 1, 2, 3, 4, 5, 5, 5, 4, 3, 2, 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]) == 0\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 96, 97, 98, 99, 100]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1]) == 3\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6, 5]) == 8\n assert candidate(nums = [7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 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]) == 19\n assert candidate(nums = [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]) == 14\n assert candidate(nums = [10, 9, 8, 7, 6, 7, 8, 9, 10, 9]) == 2\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2]) == 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]) == 9\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 2, 3, 2, 1, 3, 2, 1, 2, 3, 2, 1, 3, 2, 1, 2, 3]) == 16\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [10, 9, 8, 7, 8, 9, 10, 9, 8, 7, 6]) == 2\n assert candidate(nums = [1, 1, 2, 3, 4, 3, 2, 1, 1, 2, 3, 4, 3, 2, 1, 1, 2, 3, 4]) == 4\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2]) == 7\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 7, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 7, 8]) == 10\n assert candidate(nums = [50, 49, 50, 49, 50, 49, 50, 49, 50, 49, 50, 49, 50, 49, 50, 49, 50, 49, 50]) == 17\n assert candidate(nums = [2, 2, 2, 1, 2, 2, 3, 2, 2, 2, 1, 2, 2, 3, 2, 2, 2, 1, 2, 2]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 1\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 11\n assert candidate(nums = [1, 3, 2, 1, 2, 1, 2, 1, 2, 1, 3, 2, 1, 2, 1]) == 11\n assert candidate(nums = [1, 2, 2, 2, 3, 2, 2, 2, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 7\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 = [1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 3, 4]) == 8\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 11\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 0\n assert candidate(nums = [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]) == 14\n assert candidate(nums = [20, 21, 20, 22, 21, 23, 22, 24, 23, 25, 24, 23, 22, 21, 20, 19, 20, 21, 22, 21]) == 11\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 2, 1, 3, 3, 3, 2, 2, 2]) == 3\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 3\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 3\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 13\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2]) == 2\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]) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 18\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 18\n assert candidate(nums = [10, 9, 8, 7, 8, 9, 10, 9, 8, 7, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6]) == 11\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 2, 2, 2]) == 1\n assert candidate(nums = [3, 3, 3, 2, 2, 1, 1, 1, 2, 2, 3, 3, 3, 2, 2, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2, 2, 1, 2, 3, 3, 2, 1, 2, 3, 4, 4, 3, 2, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == 8\n assert candidate(nums = [1, 3, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [9, 8, 7, 8, 7, 8, 9, 10, 9, 10, 9, 8, 7, 8, 7, 6, 5, 4, 5, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8]) == 13\n assert candidate(nums = [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]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 3, 3, 2, 2, 1]) == 1\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10]) == 7\n", "comparison": "exact"}, "public_tests": ["[2,4,1,1,6,5]", "[6,6,5,5,4,1]"], "hints": ["For each index, could you find the closest non-equal neighbors?", "Ensure that adjacent indices that are part of the same hill or valley are not double-counted."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countHillValley", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:01+00:00", "tests_total": 154, "tests_dropped": 0, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function countHillValley($nums) {", "container": "Solution", "callable": "countHillValley", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2211, "task_id": "count-collisions-on-a-road", "difficulty": "Medium", "problem_description": "There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.\n\nYou are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the i^th car is moving towards the left, towards the right, or staying at its current point respectively. Each moving car has the same speed.\n\nThe number of collisions can be calculated as follows:\n\n- When two cars moving in opposite directions collide with each other, the number of collisions increases by 2.\n- When a moving car collides with a stationary car, the number of collisions increases by 1.\n\nAfter a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.\n\nReturn the total number of collisions that will happen on the road.\n\nExample 1:\n\nInput: directions = \"RLRSLL\"\nOutput: 5\nExplanation:\nThe collisions that will happen on the road are:\n- Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2.\n- Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3.\n- Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4.\n- Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5.\nThus, the total number of collisions that will happen on the road is 5.\n\nExample 2:\n\nInput: directions = \"LLRR\"\nOutput: 0\nExplanation:\nNo cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0.\n\nConstraints:\n\n- 1 <= directions.length <= 10^5\n- directions[i] is either 'L', 'R', or 'S'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(directions = \"SSRLSL\") == 3\n assert candidate(directions = \"LRLRLR\") == 4\n assert candidate(directions = \"RRRR\") == 0\n assert candidate(directions = \"LRRSLRLR\") == 5\n assert candidate(directions = \"LSRL\") == 2\n assert candidate(directions = \"SSSS\") == 0\n assert candidate(directions = \"RLSLRL\") == 5\n assert candidate(directions = \"RSLSLSLS\") == 4\n assert candidate(directions = \"SSSRRSLL\") == 4\n assert candidate(directions = \"LRSLSR\") == 2\n assert candidate(directions = \"RLSL\") == 3\n assert candidate(directions = \"RLLLLLL\") == 7\n assert candidate(directions = \"RRRRRRS\") == 6\n assert candidate(directions = \"LLRR\") == 0\n assert candidate(directions = \"RRLR\") == 3\n assert candidate(directions = \"SSLSLS\") == 2\n assert candidate(directions = \"RLRRLL\") == 6\n assert candidate(directions = \"RRRSSSLL\") == 5\n assert candidate(directions = \"SSSSS\") == 0\n assert candidate(directions = \"LLLLL\") == 0\n assert candidate(directions = \"RLRSLL\") == 5\n assert candidate(directions = \"LSLR\") == 1\n assert candidate(directions = \"LLLL\") == 0\n assert candidate(directions = \"RSLRS\") == 3\n assert candidate(directions = \"RSLRLRLS\") == 6\n assert candidate(directions = \"RRSLRR\") == 3\n assert candidate(directions = \"LRLR\") == 2\n assert candidate(directions = \"RRRSSSLLLRRR\") == 6\n assert candidate(directions = \"LSRLSL\") == 3\n assert candidate(directions = \"LRLL\") == 3\n assert candidate(directions = \"SSRLSS\") == 2\n assert candidate(directions = \"RRRRR\") == 0\n assert candidate(directions = \"RSLR\") == 2\n assert candidate(directions = \"SSS\") == 0\n assert candidate(directions = \"LRRLRRLL\") == 7\n assert candidate(directions = \"RSLRSL\") == 4\n assert candidate(directions = \"LSSRLL\") == 3\n assert candidate(directions = \"RSLRLR\") == 4\n assert candidate(directions = \"SSRSLLS\") == 3\n assert candidate(directions = \"RRRRRSSSSSLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLSSSSSSSSSSS\") == 43\n assert candidate(directions = \"LRLRLRLRLRLR\") == 10\n assert candidate(directions = \"RRLRLRLRLRLRLRLRLRLR\") == 19\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"SSRSLRRRLLSLSSS\") == 8\n assert candidate(directions = \"RRRRRSSLLLLLRRRR\") == 10\n assert candidate(directions = \"RLLLLRRRRLLLLRRRRRLLLLRRRR\") == 22\n assert candidate(directions = \"RSSSSRRRRRRRRRRSSSLL\") == 13\n assert candidate(directions = \"RRRRRRRRRRSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 10\n assert candidate(directions = \"LRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"RLRLRLRLRLRLRLRL\") == 16\n assert candidate(directions = \"RRRSSLLLLRRRSSLLLL\") == 14\n assert candidate(directions = \"RRRLRSSRRRLRRRRRSLRRRRRR\") == 15\n assert candidate(directions = \"RLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 2\n assert candidate(directions = \"RSLRRSLRRSLR\") == 8\n assert candidate(directions = \"LLLSRSSRRRLRRRRRSLRRRRRR\") == 11\n assert candidate(directions = \"RLRSLLRSLLRSLLRSLLRS\") == 15\n assert candidate(directions = \"LLLLLLLLLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RSLRSLRSLRSLRSLRSLRSLRSLRL\") == 18\n assert candidate(directions = \"LLLLSSSSRRRRRRRRRLLLLL\") == 14\n assert candidate(directions = \"RRRRSSSSLLLLRRRRRRSSSSLLLLRRRRRRSSSSLLLL\") == 28\n assert candidate(directions = \"RRRRRRRRRRRR\") == 0\n assert candidate(directions = \"SLRLRLRLRLRSLSLSL\") == 13\n assert candidate(directions = \"LLLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSRRRRRR\") == 0\n assert candidate(directions = \"RSSSSRRRLLLLRRRSL\") == 12\n assert candidate(directions = \"RRRRRRRRRRSSSSSSSSSLLLLLLLL\") == 18\n assert candidate(directions = \"LRRRRRLLLLLS\") == 10\n assert candidate(directions = \"SLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 44\n assert candidate(directions = \"LLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"RRRSLSLSSSLLLLRRRS\") == 12\n assert candidate(directions = \"LLLLRRRRRRRR\") == 0\n assert candidate(directions = \"RLRSRLRSRLRSRLRS\") == 12\n assert candidate(directions = \"SSSSSSSSSSSSSSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 52\n assert candidate(directions = \"RLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 2\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"SSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RSLRSLSRLRSLSR\") == 8\n assert candidate(directions = \"RRRSLSLRSLRRRRLLL\") == 14\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"SSSSSRRRRRSSSSS\") == 5\n assert candidate(directions = \"RRRRSSSLLLLLRRRR\") == 9\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRR\") == 44\n assert candidate(directions = \"SSRRRRLLLLSSRRRRLLLLSS\") == 16\n assert candidate(directions = \"RSLRSLSRLSRLSRLRSLSR\") == 12\n assert candidate(directions = \"RRRRRRRRLLLLLLLL\") == 16\n assert candidate(directions = \"SLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 46\n assert candidate(directions = \"RRRLLRRRLLLLLSS\") == 13\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRRR\") == 43\n assert candidate(directions = \"LLLLLRRRRRLLLLLRRRRRLLLLLRRRRRLLLLLRRRRR\") == 30\n assert candidate(directions = \"LLLLRRRRRRSSSSSLLLL\") == 10\n assert candidate(directions = \"RLRLRLRLRLRL\") == 12\n assert candidate(directions = \"RLRSLRSLRSLRSLRS\") == 11\n assert candidate(directions = \"RRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"SLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 48\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRR\") == 44\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRR\") == 44\n assert candidate(directions = \"SSSSSSRRRRRSSSSSSSSS\") == 5\n assert candidate(directions = \"LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR\") == 38\n assert candidate(directions = \"SSSLRRRLLSSL\") == 7\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RRRLRLRLRLRLRLRLRLRLRLRLRLRRRRRRRRRRRR\") == 26\n assert candidate(directions = \"SSSSRRRRLLLLRRRRLLLL\") == 16\n assert candidate(directions = \"RRRRRLSLLSLLLL\") == 12\n assert candidate(directions = \"SSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RRRRRSSSSLLLLLLLL\") == 13\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"RLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 2\n assert candidate(directions = \"SSRRRRRSSSSLLLSSSL\") == 9\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"RLRRLLRLRRLLRLRR\") == 14\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLLLLLLSSSS\") == 0\n assert candidate(directions = \"RRRRSSSSSSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRL\") == 38\n assert candidate(directions = \"LSRSSRSLLRSRLS\") == 7\n assert candidate(directions = \"LLLLLLRRRRRRLLLLRRRRRR\") == 10\n assert candidate(directions = \"LLLLSSSSRRRRSSSSLLLL\") == 8\n assert candidate(directions = \"SSSSSSSSSSSRRRRRRSSSSSSLLLLLLLLSSSSSSSSSSS\") == 14\n assert candidate(directions = \"RRRSSLRLRLRSLL\") == 11\n assert candidate(directions = \"RSLSLRLSLSLRLSLR\") == 10\n assert candidate(directions = \"SSSSSRRRRRSSSSSLLLLL\") == 10\n assert candidate(directions = \"SSSSRRRRSSSSSSSSSSSSSSSSSSS\") == 4\n assert candidate(directions = \"SSSSRRRRRRLLLLSSSSSLLLL\") == 14\n assert candidate(directions = \"SSLRRRSSLLSL\") == 7\n assert candidate(directions = \"RRSSSLRSLSSSRRSSSLRSL\") == 10\n assert candidate(directions = \"LSLSLSLSLSLSLSLSLRRRRRR\") == 8\n assert candidate(directions = \"LLLLSSRRRRSSSSRRRR\") == 4\n assert candidate(directions = \"RSLSRSLSRSLSRS\") == 7\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RSLRSSLSRSSL\") == 6\n assert candidate(directions = \"LRLRLRLRLRLRLRLRLRLR\") == 18\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLRRRRRR\") == 43\n assert candidate(directions = \"RRRRRSSSLLLLLLLLRRRR\") == 13\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"LLLLRRRRSSSSLLRRRR\") == 6\n assert candidate(directions = \"LRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"LLLSRLRLRLRLRLL\") == 11\n assert candidate(directions = \"RRRRSSSSLLLL\") == 8\n assert candidate(directions = \"RLRLRLRLRLRLRLRLRLRL\") == 20\n assert candidate(directions = \"LLLLRRRRSSSSLLLL\") == 8\n assert candidate(directions = \"LRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLL\") == 46\n assert candidate(directions = \"RRRRRRRRRSSSSSSSLLLLLLLLSSSSSSSSSSSSSSSSSS\") == 17\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRLLSSSSSSSSSSSSSSSSSL\") == 22\n assert candidate(directions = \"RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL\") == 40\n assert candidate(directions = \"LRRRSLRRRLSLSLLSLRR\") == 12\n assert candidate(directions = \"LRRRLRRLLRLLRLRRRLLR\") == 18\n assert candidate(directions = \"RRRRLLLLRRRRLLLLRRRRLLLLRRRRLLLLRRRRLLLL\") == 40\n assert candidate(directions = \"SRLRSRLRSRLRSRLRSRLRSRLRSRLRSRLRSRLRSR\") == 27\n assert candidate(directions = \"RRRRRSSLLLLLLLLLL\") == 15\n assert candidate(directions = \"SSSSRRRRLLLLSSSS\") == 8\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"SSSSRRRRLLLLSSSSRRRR\") == 8\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"SRRRRRLRRRRLLSRRRRLLL\") == 19\n assert candidate(directions = \"RRRLLLLLSSSSRRRLLLLL\") == 16\n assert candidate(directions = \"RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\") == 0\n assert candidate(directions = \"RLLLLLRRRRRR\") == 6\n assert candidate(directions = \"RSLRRSLSLSLSLSLSL\") == 10\n assert candidate(directions = \"RLRSLRSLRSLRSLRSLRSLRSLRSLRSLRSLR\") == 22\n assert candidate(directions = \"RRRRRRRRRRLLLLLLLLLL\") == 20\n assert candidate(directions = \"RRRRSSSLLLLLLLRRRRRR\") == 11\n assert candidate(directions = \"SSSSRRRRLLLLLRRRRLLLLLSSSSRRRRLLLLLRRRRLLLLL\") == 36\n assert candidate(directions = \"LLLLLLLLLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSRRRR\") == 0\n assert candidate(directions = \"RRRRRRRRRRRRRRSSSLSSSSSSSSSSSSSSSSSSSSSSSL\") == 16\n assert candidate(directions = \"RRRRRRSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSLLLLLL\") == 12\n assert candidate(directions = \"RRRRLLLLSSSSRRRLLL\") == 14\n assert candidate(directions = \"LLLLLLLLLLLLLLLLLLLL\") == 0\n assert candidate(directions = \"RLRRRLRLRLRLRLRLRLRLRLRLRLRR\") == 26\n assert candidate(directions = \"RRRRRSSSSSSLLLLSSSSSS\") == 9\n assert candidate(directions = \"SSRRRRRLLLLLSS\") == 10\n assert candidate(directions = \"RRRRRRRRRRRRRLLLLLLLLLLLL\") == 25\n assert candidate(directions = \"RRRRRRRRRRSSSSSSSSSSSSSSSSSSSSSSSSSSSSSLLLL\") == 14\n assert candidate(directions = \"RSLSLRSLRRSLRSLRL\") == 12\n assert candidate(directions = \"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\") == 0\n assert candidate(directions = \"RSSSSSSRRRRRRRLLLLLLLLLLLLLRRRRRR\") == 21\n assert candidate(directions = \"RLRSLRLRSLRL\") == 10\n", "comparison": "exact"}, "public_tests": ["\"RLRSLL\"", "\"LLRR\""], "hints": ["In what circumstances does a moving car not collide with another car?", "If we disregard the moving cars that do not collide with another car, what does each moving car contribute to the answer?", "Will stationary cars contribute towards the answer?"], "metadata": {"canonical_parameter_names": ["directions"], "leetcode_dataset_entry_point": "Solution().countCollisions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:04+00:00", "tests_total": 177, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "stack", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countCollisions($directions) {", "container": "Solution", "callable": "countCollisions", "parameters": [{"name": "directions", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2212, "task_id": "maximum-points-in-an-archery-competition", "difficulty": "Medium", "problem_description": "Alice and Bob are opponents in an archery competition. The competition has set the following rules:\n\n1. Alice first shoots numArrows arrows and then Bob shoots numArrows arrows.\n2. The points are then calculated as follows:\n 1. The target has integer scoring sections ranging from 0 to 11 inclusive.\n 2. For each section of the target with score k (in between 0 to 11), say Alice and Bob have shot a_k and b_k arrows on that section respectively. If a_k >= b_k, then Alice takes k points. If a_k < b_k, then Bob takes k points.\n 3. However, if a_k == b_k == 0, then nobody takes k points.\n\n-\nFor example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.\n\nYou are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.\n\nReturn the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.\n\nIf there are multiple ways for Bob to earn the maximum total points, return any one of them.\n\nExample 1:\n\nInput: numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]\nOutput: [0,0,0,0,1,1,0,0,1,2,3,1]\nExplanation: The table above shows how the competition is scored.\nBob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.\nIt can be shown that Bob cannot obtain a score higher than 47 points.\n\nExample 2:\n\nInput: numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]\nOutput: [0,0,0,0,0,0,0,0,1,1,1,0]\nExplanation: The table above shows how the competition is scored.\nBob earns a total point of 8 + 9 + 10 = 27.\nIt can be shown that Bob cannot obtain a score higher than 27 points.\n\nConstraints:\n\n- 1 <= numArrows <= 10^5\n- aliceArrows.length == bobArrows.length == 12\n- 0 <= aliceArrows[i], bobArrows[i] <= numArrows\n- sum(aliceArrows[i]) == numArrows\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(numArrows = 100000,aliceArrows = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == [9991, 0, 0, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001, 10001]\n assert candidate(numArrows = 5,aliceArrows = [0, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2]\n assert candidate(numArrows = 15,aliceArrows = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3]\n assert candidate(numArrows = 12,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 20,aliceArrows = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4]\n assert candidate(numArrows = 3,aliceArrows = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2]) == [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0]\n assert candidate(numArrows = 9,aliceArrows = [1, 1, 0, 1, 0, 0, 2, 1, 0, 1, 2, 0]) == [0, 0, 0, 0, 1, 1, 0, 0, 1, 2, 3, 1]\n assert candidate(numArrows = 5,aliceArrows = [2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 10,aliceArrows = [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(numArrows = 9,aliceArrows = [2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2]) == [0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 3]\n assert candidate(numArrows = 20,aliceArrows = [3, 0, 2, 1, 4, 0, 2, 1, 3, 0, 2, 1]) == [1, 1, 0, 2, 0, 1, 3, 2, 4, 1, 3, 2]\n assert candidate(numArrows = 100,aliceArrows = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [1, 0, 0, 11, 11, 11, 11, 11, 11, 11, 11, 11]\n assert candidate(numArrows = 50,aliceArrows = [10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0]) == [0, 0, 11, 11, 11, 11, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 80,aliceArrows = [0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15]) == [11, 0, 1, 0, 1, 16, 1, 16, 1, 16, 1, 16]\n assert candidate(numArrows = 85,aliceArrows = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [19, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(numArrows = 72,aliceArrows = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [0, 0, 0, 0, 0, 9, 10, 11, 0, 13, 14, 15]\n assert candidate(numArrows = 99,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [22, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(numArrows = 90,aliceArrows = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == [2, 0, 0, 0, 0, 0, 0, 0, 19, 21, 23, 25]\n assert candidate(numArrows = 25,aliceArrows = [2, 2, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3]) == [0, 0, 0, 0, 0, 3, 4, 4, 3, 3, 4, 4]\n assert candidate(numArrows = 30,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 29]) == [10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0]\n assert candidate(numArrows = 30,aliceArrows = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [3, 0, 0, 0, 0, 0, 7, 6, 5, 4, 3, 2]\n assert candidate(numArrows = 77,aliceArrows = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == [41, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1]\n assert candidate(numArrows = 85,aliceArrows = [0, 0, 5, 10, 15, 20, 0, 0, 0, 0, 0, 0]) == [24, 1, 6, 11, 16, 21, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 80,aliceArrows = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == [38, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2]\n assert candidate(numArrows = 60,aliceArrows = [2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]) == [27, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4]\n assert candidate(numArrows = 25,aliceArrows = [0, 0, 0, 0, 5, 4, 3, 2, 1, 0, 0, 0]) == [0, 0, 1, 1, 6, 5, 4, 3, 2, 1, 1, 1]\n assert candidate(numArrows = 66,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 0, 0, 4, 5, 0, 7, 8, 9, 10, 11, 12]\n assert candidate(numArrows = 20,aliceArrows = [1, 3, 2, 4, 1, 2, 3, 4, 2, 1, 3, 2]) == [0, 0, 0, 0, 0, 3, 0, 5, 3, 2, 4, 3]\n assert candidate(numArrows = 50,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]) == [40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 90,aliceArrows = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1]) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 2]\n assert candidate(numArrows = 40,aliceArrows = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0]) == [6, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 1]\n assert candidate(numArrows = 23,aliceArrows = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3]\n assert candidate(numArrows = 85,aliceArrows = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == [1, 0, 0, 0, 0, 0, 0, 0, 18, 20, 22, 24]\n assert candidate(numArrows = 20,aliceArrows = [1, 3, 2, 5, 0, 0, 4, 3, 1, 2, 3, 1]) == [0, 0, 3, 0, 1, 1, 0, 4, 2, 3, 4, 2]\n assert candidate(numArrows = 20,aliceArrows = [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 4]) == [2, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 5]\n assert candidate(numArrows = 90,aliceArrows = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [3, 0, 0, 0, 0, 0, 0, 41, 46, 0, 0, 0]\n assert candidate(numArrows = 30,aliceArrows = [0, 3, 0, 0, 5, 0, 0, 0, 3, 0, 0, 0]) == [8, 4, 1, 1, 6, 1, 1, 1, 4, 1, 1, 1]\n assert candidate(numArrows = 30,aliceArrows = [6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5]) == [0, 0, 0, 4, 3, 2, 1, 2, 3, 4, 5, 6]\n assert candidate(numArrows = 50,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [0, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0]\n assert candidate(numArrows = 75,aliceArrows = [15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [64, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 100,aliceArrows = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [34, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(numArrows = 75,aliceArrows = [10, 5, 5, 5, 10, 5, 5, 5, 10, 5, 5, 5]) == [5, 0, 6, 6, 11, 6, 6, 6, 11, 6, 6, 6]\n assert candidate(numArrows = 60,aliceArrows = [0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10]) == [0, 1, 1, 1, 1, 1, 0, 11, 11, 11, 11, 11]\n assert candidate(numArrows = 15,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]) == [5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 40,aliceArrows = [10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0]) == [1, 1, 0, 1, 0, 1, 11, 1, 11, 1, 11, 1]\n assert candidate(numArrows = 25,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 0, 0, 0, 0, 0, 7, 8, 0, 10, 0, 0]\n assert candidate(numArrows = 25,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25]) == [15, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 120,aliceArrows = [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 100]) == [2, 0, 1, 3, 1, 3, 1, 3, 1, 3, 1, 101]\n assert candidate(numArrows = 85,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85]) == [75, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 120,aliceArrows = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == [43, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]\n assert candidate(numArrows = 40,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]) == [0, 0, 0, 0, 0, 0, 8, 9, 10, 11, 0, 2]\n assert candidate(numArrows = 20,aliceArrows = [0, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 100,aliceArrows = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [3, 0, 0, 0, 0, 0, 0, 0, 46, 51, 0, 0]\n assert candidate(numArrows = 60,aliceArrows = [0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5]) == [34, 6, 1, 1, 1, 1, 6, 1, 1, 1, 1, 6]\n assert candidate(numArrows = 8,aliceArrows = [3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0]) == [3, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 40,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 11, 12]\n assert candidate(numArrows = 25,aliceArrows = [4, 3, 5, 3, 4, 5, 6, 3, 4, 5, 6, 2]) == [0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 3]\n assert candidate(numArrows = 12,aliceArrows = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3]\n assert candidate(numArrows = 120,aliceArrows = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == [104, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]\n assert candidate(numArrows = 30,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 11, 0]\n assert candidate(numArrows = 99,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]) == [23, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1]\n assert candidate(numArrows = 60,aliceArrows = [0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10]) == [0, 0, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11]\n assert candidate(numArrows = 20,aliceArrows = [5, 3, 4, 2, 6, 3, 7, 2, 4, 5, 6, 3]) == [0, 0, 0, 0, 0, 0, 0, 3, 0, 6, 7, 4]\n assert candidate(numArrows = 80,aliceArrows = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == [0, 0, 0, 0, 0, 0, 0, 18, 19, 0, 21, 22]\n assert candidate(numArrows = 150,aliceArrows = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [2, 0, 0, 0, 0, 0, 0, 41, 0, 51, 56, 0]\n assert candidate(numArrows = 50,aliceArrows = [0, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0]) == [19, 1, 1, 1, 11, 1, 1, 1, 11, 1, 1, 1]\n assert candidate(numArrows = 60,aliceArrows = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0]) == [29, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1]\n assert candidate(numArrows = 25,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 42,aliceArrows = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [0, 0, 0, 0, 0, 0, 9, 10, 11, 12, 0, 0]\n assert candidate(numArrows = 60,aliceArrows = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]) == [1, 0, 0, 0, 0, 0, 0, 0, 28, 31, 0, 0]\n assert candidate(numArrows = 20,aliceArrows = [3, 2, 1, 4, 3, 2, 1, 2, 3, 4, 5, 6]) == [0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 0]\n assert candidate(numArrows = 50,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]) == [40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 88,aliceArrows = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [22, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(numArrows = 70,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70]) == [60, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 100,aliceArrows = [10, 10, 0, 10, 0, 0, 20, 10, 0, 10, 20, 0]) == [9, 11, 1, 11, 1, 1, 21, 11, 1, 11, 21, 1]\n assert candidate(numArrows = 85,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(numArrows = 120,aliceArrows = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72]) == [4, 0, 0, 0, 0, 0, 0, 0, 55, 61, 0, 0]\n assert candidate(numArrows = 50,aliceArrows = [5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0]) == [29, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 55,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]) == [0, 0, 0, 0, 6, 7, 8, 0, 10, 11, 12, 1]\n assert candidate(numArrows = 150,aliceArrows = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0]) == [49, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1]\n assert candidate(numArrows = 20,aliceArrows = [0, 3, 1, 2, 0, 4, 1, 0, 5, 2, 1, 1]) == [0, 0, 0, 3, 1, 0, 2, 1, 6, 3, 2, 2]\n assert candidate(numArrows = 60,aliceArrows = [0, 10, 20, 30, 40, 50, 60, 0, 0, 0, 0, 0]) == [3, 0, 21, 31, 0, 0, 0, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 100,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [12, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n assert candidate(numArrows = 120,aliceArrows = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [43, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(numArrows = 50,aliceArrows = [10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0]) == [10, 0, 11, 11, 11, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 40,aliceArrows = [2, 0, 1, 0, 3, 0, 2, 0, 1, 0, 1, 0]) == [21, 1, 2, 1, 4, 1, 3, 1, 2, 1, 2, 1]\n assert candidate(numArrows = 60,aliceArrows = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60]) == [50, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(numArrows = 50,aliceArrows = [0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [2, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(numArrows = 90,aliceArrows = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [46, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(numArrows = 75,aliceArrows = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [9, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]\n assert candidate(numArrows = 75,aliceArrows = [0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20]) == [7, 1, 1, 1, 1, 1, 0, 0, 0, 21, 21, 21]\n assert candidate(numArrows = 100,aliceArrows = [10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0]) == [49, 11, 11, 11, 11, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(numArrows = 18,aliceArrows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]) == [0, 0, 0, 0, 0, 7, 0, 9, 0, 0, 0, 2]\n assert candidate(numArrows = 30,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == [1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11]\n assert candidate(numArrows = 75,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [0, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(numArrows = 10,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 1]\n assert candidate(numArrows = 100,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [78, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 60,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [38, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 7,aliceArrows = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) == [0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 2, 2]\n assert candidate(numArrows = 100,aliceArrows = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == [1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(numArrows = 30,aliceArrows = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == [0, 0, 0, 0, 0, 0, 14, 16, 0, 0, 0, 0]\n assert candidate(numArrows = 90,aliceArrows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [13, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(numArrows = 30,aliceArrows = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(numArrows = 100,aliceArrows = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0]) == [44, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]\n assert candidate(numArrows = 10,aliceArrows = [3, 1, 2, 2, 3, 1, 4, 2, 3, 4, 5, 1]) == [0, 0, 0, 0, 0, 0, 0, 3, 0, 5, 0, 2]\n assert candidate(numArrows = 60,aliceArrows = [3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 0, 2, 3, 4, 0, 6, 7, 8, 9, 10, 11]\n assert candidate(numArrows = 75,aliceArrows = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6]) == [43, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7]\n assert candidate(numArrows = 120,aliceArrows = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [43, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(numArrows = 100,aliceArrows = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == [64, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1]\n", "comparison": "exact"}, "public_tests": ["9\n[1,1,0,1,0,0,2,1,0,1,2,0]", "3\n[0,0,1,0,0,0,0,0,0,0,0,2]"], "hints": ["To obtain points for some certain section x, what is the minimum number of arrows Bob must shoot?", "Given the small number of sections, can we brute force which sections Bob wants to win?", "For every set of sections Bob wants to win, check if we have the required amount of arrows. If we do, it is a valid selection."], "metadata": {"canonical_parameter_names": ["numArrows", "aliceArrows"], "leetcode_dataset_entry_point": "Solution().maximumBobPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:06+00:00", "tests_total": 109, "tests_dropped": 0, "flags": ["multiple_answers", "has_images"], "topic_tags": ["array", "backtracking", "bit-manipulation", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function maximumBobPoints($numArrows, $aliceArrows) {", "container": "Solution", "callable": "maximumBobPoints", "parameters": [{"name": "numArrows", "type": "Integer"}, {"name": "aliceArrows", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2213, "task_id": "longest-substring-of-one-repeating-character", "difficulty": "Hard", "problem_description": "You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.\n\nThe i^th query updates the character in s at index queryIndices[i] to the character queryCharacters[i].\n\nReturn an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the i^th query is performed.\n\nExample 1:\n\nInput: s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3]\nOutput: [3,3,4]\nExplanation:\n- 1^st query updates s = \"bbbacc\". The longest substring consisting of one repeating character is \"bbb\" with length 3.\n- 2^nd query updates s = \"bbbccc\".\n The longest substring consisting of one repeating character can be \"bbb\" or \"ccc\" with length 3.\n- 3^rd query updates s = \"bbbbcc\". The longest substring consisting of one repeating character is \"bbbb\" with length 4.\nThus, we return [3,3,4].\n\nExample 2:\n\nInput: s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1]\nOutput: [2,3]\nExplanation:\n- 1^st query updates s = \"abazz\". The longest substring consisting of one repeating character is \"zz\" with length 2.\n- 2^nd query updates s = \"aaazz\". The longest substring consisting of one repeating character is \"aaa\" with length 3.\nThus, we return [2,3].\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of lowercase English letters.\n- k == queryCharacters.length == queryIndices.length\n- 1 <= k <= 10^5\n- queryCharacters consists of lowercase English letters.\n- 0 <= queryIndices[i] < s.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcde\",queryCharacters = \"aaaaa\",queryIndices = [0, 1, 2, 3, 4]) == [1, 2, 3, 4, 5]\n assert candidate(s = \"abyzz\",queryCharacters = \"aa\",queryIndices = [2, 1]) == [2, 3]\n assert candidate(s = \"abcde\",queryCharacters = \"ee\",queryIndices = [2, 4]) == [1, 1]\n assert candidate(s = \"zzzzz\",queryCharacters = \"abcd\",queryIndices = [0, 1, 2, 3]) == [4, 3, 2, 1]\n assert candidate(s = \"babacc\",queryCharacters = \"bcb\",queryIndices = [1, 3, 3]) == [3, 3, 4]\n assert candidate(s = \"abcde\",queryCharacters = \"ee\",queryIndices = [0, 4]) == [1, 1]\n assert candidate(s = \"aaaaa\",queryCharacters = \"bb\",queryIndices = [1, 3]) == [3, 1]\n assert candidate(s = \"z\",queryCharacters = \"z\",queryIndices = [0]) == [1]\n assert candidate(s = \"zzzzz\",queryCharacters = \"xy\",queryIndices = [0, 4]) == [4, 3]\n assert candidate(s = \"aaaaa\",queryCharacters = \"b\",queryIndices = [2]) == [2]\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",queryCharacters = \"zzzzzzzzzzzzzzzzzzzz\",queryIndices = [0, 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]\n assert candidate(s = \"ababababab\",queryCharacters = \"aaaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 3, 3, 5, 5, 7, 7, 9, 9, 10]\n assert candidate(s = \"abcdefghij\",queryCharacters = \"jjjjjjjjjj\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 10, 10]\n assert candidate(s = \"abcdefg\",queryCharacters = \"hijklmn\",queryIndices = [0, 1, 2, 3, 4, 5, 6]) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(s = \"abacabadabacaba\",queryCharacters = \"aaaaaaaaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15]\n assert candidate(s = \"aabbccddeeffgghhiijjkk\",queryCharacters = \"llll\",queryIndices = [2, 4, 6, 8]) == [2, 2, 2, 2]\n assert candidate(s = \"zzzzzzzzzz\",queryCharacters = \"yyyyyyyyyy\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9, 8, 7, 6, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"aabbaabb\",queryCharacters = \"cccc\",queryIndices = [1, 3, 5, 7]) == [2, 2, 2, 1]\n assert candidate(s = \"pppqqqrrrsssttt\",queryCharacters = \"uuuuuuuuuuuuuuu\",queryIndices = [2, 5, 8, 11, 14, 2, 5, 8, 11, 14, 2, 5, 8, 11, 14]) == [3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(s = \"xyzzxxxyyy\",queryCharacters = \"zzz\",queryIndices = [1, 3, 5]) == [3, 3, 3]\n assert candidate(s = \"abababababababab\",queryCharacters = \"cccccccc\",queryIndices = [0, 2, 4, 6, 8, 10, 12, 14]) == [1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(s = \"mnopqrstu\",queryCharacters = \"aaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(s = \"abcdefghij\",queryCharacters = \"z\",queryIndices = [5]) == [1]\n assert candidate(s = \"aaabbbccc\",queryCharacters = \"dddddd\",queryIndices = [0, 3, 6, 1, 4, 7]) == [3, 3, 2, 2, 2, 2]\n assert candidate(s = \"aabaaa\",queryCharacters = \"bbccc\",queryIndices = [1, 1, 3, 3, 4]) == [3, 3, 2, 2, 2]\n assert candidate(s = \"abcabcabc\",queryCharacters = \"aaa\",queryIndices = [0, 3, 6]) == [1, 1, 1]\n assert candidate(s = \"abcabcabc\",queryCharacters = \"ddddddd\",queryIndices = [0, 3, 6, 1, 4, 7, 2]) == [1, 1, 1, 2, 2, 2, 5]\n assert candidate(s = \"aabbaa\",queryCharacters = \"bb\",queryIndices = [0, 4]) == [2, 3]\n assert candidate(s = \"abcdabcdabcdabcd\",queryCharacters = \"zzzz\",queryIndices = [1, 3, 5, 7]) == [1, 1, 1, 1]\n assert candidate(s = \"abcabcabcabc\",queryCharacters = \"dddddddddddd\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(s = \"mississippi\",queryCharacters = \"llll\",queryIndices = [0, 1, 2, 3]) == [2, 2, 3, 4]\n assert candidate(s = \"xyxxyxyxyx\",queryCharacters = \"zzzzzzzzzz\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [2, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"aabbbccccc\",queryCharacters = \"bbb\",queryIndices = [2, 3, 7]) == [5, 5, 3]\n assert candidate(s = \"abccba\",queryCharacters = \"bbccc\",queryIndices = [2, 3, 2, 3, 4]) == [2, 4, 2, 2, 3]\n assert candidate(s = \"xyxyxyxyxyxy\",queryCharacters = \"zzzzzzzzzzzz\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n assert candidate(s = \"aaaaaaaaaa\",queryCharacters = \"bbbbbbbbbb\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9, 8, 7, 6, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"abcdefg\",queryCharacters = \"zzzzzzz\",queryIndices = [6, 5, 4, 3, 2, 1, 0]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",queryCharacters = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",queryIndices = [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]) == [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, 26]\n assert candidate(s = \"mmmmnnnnoooo\",queryCharacters = \"ppppqqqqrrrr\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(s = \"abccba\",queryCharacters = \"cccccc\",queryIndices = [1, 2, 3, 4, 5, 0]) == [3, 3, 3, 4, 5, 6]\n assert candidate(s = \"abcdefghij\",queryCharacters = \"abcdefghij\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(s = \"abcdeabcdeabcdeabcde\",queryCharacters = \"abcdeabcdeabcdeabcde\",queryIndices = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(s = \"aabbccddeeffgg\",queryCharacters = \"hhhhhhhh\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7]) == [2, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(s = \"aabbcc\",queryCharacters = \"ffffff\",queryIndices = [0, 1, 2, 3, 4, 5]) == [2, 2, 3, 4, 5, 6]\n assert candidate(s = \"mmmmmmmmmm\",queryCharacters = \"llllllllll\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9, 8, 7, 6, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",queryCharacters = \"abcdefghijklmnopqrstuvwxyz\",queryIndices = [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]) == [1, 1, 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 = \"xyxyxyxyxyx\",queryCharacters = \"yyyyy\",queryIndices = [1, 3, 5, 7, 9]) == [1, 1, 1, 1, 1]\n assert candidate(s = \"abcdefghij\",queryCharacters = \"jjjjj\",queryIndices = [8, 7, 6, 5, 4]) == [2, 3, 4, 5, 6]\n assert candidate(s = \"abcdefghij\",queryCharacters = \"aaaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"abcdefghijabcdefghij\",queryCharacters = \"jjjjjjjjjj\",queryIndices = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [2, 3, 4, 5, 6, 7, 8, 9, 11, 11]\n assert candidate(s = \"abababababab\",queryCharacters = \"cccc\",queryIndices = [0, 2, 4, 6]) == [1, 1, 1, 1]\n assert candidate(s = \"aabbccddeeff\",queryCharacters = \"abcdef\",queryIndices = [1, 3, 5, 7, 9, 11]) == [2, 2, 2, 2, 2, 2]\n assert candidate(s = \"abacaba\",queryCharacters = \"aaaaa\",queryIndices = [1, 2, 3, 4, 5]) == [3, 3, 5, 5, 7]\n assert candidate(s = \"xyzxyzxyzxyz\",queryCharacters = \"zzzz\",queryIndices = [0, 1, 2, 3]) == [1, 3, 3, 4]\n assert candidate(s = \"zzzzzzzzzz\",queryCharacters = \"aaaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9, 8, 7, 6, 5, 6, 7, 8, 9, 10]\n assert candidate(s = \"abcdabcdabcd\",queryCharacters = \"aaaabbbb\",queryIndices = [0, 1, 8, 9, 4, 5, 10, 11]) == [1, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(s = \"aabbccddeeff\",queryCharacters = \"hhhhhhh\",queryIndices = [1, 3, 5, 7, 9, 11, 1]) == [2, 2, 2, 2, 2, 1, 1]\n assert candidate(s = \"aabbccddeeff\",queryCharacters = \"zzzzzz\",queryIndices = [1, 3, 5, 7, 9, 11]) == [2, 2, 2, 2, 2, 1]\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",queryCharacters = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",queryIndices = [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]) == [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, 26]\n assert candidate(s = \"aabbaa\",queryCharacters = \"cccccc\",queryIndices = [0, 1, 2, 3, 4, 5]) == [2, 2, 3, 4, 5, 6]\n assert candidate(s = \"zzzzzzyyyyy\",queryCharacters = \"xyyxz\",queryIndices = [0, 5, 6, 7, 10]) == [5, 6, 6, 4, 4]\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbbbcccccccccc\",queryCharacters = \"dddddddddd\",queryIndices = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [11, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(s = \"abacabadabacaba\",queryCharacters = \"zzzzzzzzzzz\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(s = \"abababab\",queryCharacters = \"bbbbbbbb\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7]) == [2, 2, 4, 4, 6, 6, 8, 8]\n assert candidate(s = \"abacabadabacaba\",queryCharacters = \"ccccccc\",queryIndices = [0, 1, 2, 3, 4, 5, 6]) == [1, 2, 4, 4, 5, 6, 7]\n assert candidate(s = \"aabbccddeeff\",queryCharacters = \"gggggg\",queryIndices = [0, 1, 2, 3, 4, 5]) == [2, 2, 3, 4, 5, 6]\n assert candidate(s = \"zzzzzzzzzzzz\",queryCharacters = \"aaaaaaaaaa\",queryIndices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [11, 10, 9, 8, 7, 6, 7, 8, 9, 10]\n assert candidate(s = \"abccbaabc\",queryCharacters = \"cccc\",queryIndices = [2, 3, 5, 6]) == [2, 2, 2, 2]\n assert candidate(s = \"xyxyxyxyxyx\",queryCharacters = \"aaaaaa\",queryIndices = [0, 2, 4, 6, 8, 10]) == [1, 1, 1, 1, 1, 1]\n", "comparison": "exact"}, "public_tests": ["\"babacc\"\n\"bcb\"\n[1,3,3]", "\"abyzz\"\n\"aa\"\n[2,1]"], "hints": ["Use a segment tree to perform fast point updates and range queries.", "We need each segment tree node to store the length of the longest substring of that segment consisting of only 1 repeating character.", "We will also have each segment tree node store the leftmost and rightmost character of the segment, the max length of a prefix substring consisting of only 1 repeating character, and the max length of a suffix substring consisting of only 1 repeating character.", "Use this information to properly merge the two segment tree nodes together."], "metadata": {"canonical_parameter_names": ["s", "queryCharacters", "queryIndices"], "leetcode_dataset_entry_point": "Solution().longestRepeating", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:09+00:00", "tests_total": 80, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "string", "segment-tree", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function longestRepeating($s, $queryCharacters, $queryIndices) {", "container": "Solution", "callable": "longestRepeating", "parameters": [{"name": "s", "type": "String"}, {"name": "queryCharacters", "type": "String"}, {"name": "queryIndices", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2215, "task_id": "find-the-difference-of-two-arrays", "difficulty": "Easy", "problem_description": "Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:\n\n- answer[0] is a list of all distinct integers in nums1 which are not present in nums2.\n- answer[1] is a list of all distinct integers in nums2 which are not present in nums1.\n\nNote that the integers in the lists may be returned in any order.\n\nExample 1:\n\nInput: nums1 = [1,2,3], nums2 = [2,4,6]\nOutput: [[1,3],[4,6]]\nExplanation:\nFor nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].\nFor nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums1. Therefore, answer[1] = [4,6].\n\nExample 2:\n\nInput: nums1 = [1,2,3,3], nums2 = [1,1,2,2]\nOutput: [[3],[]]\nExplanation:\nFor nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].\nEvery integer in nums2 is present in nums1. Therefore, answer[1] = [].\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 1000\n- -1000 <= nums1[i], nums2[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [0, -1, -2],nums2 = [1, -1, 2]) == [[0, -2], [1, 2]]\n assert candidate(nums1 = [5, 7, 8],nums2 = [9, 10, 5]) == [[8, 7], [9, 10]]\n assert candidate(nums1 = [10, 20, 30],nums2 = [5, 15, 25, 35]) == [[10, 20, 30], [25, 35, 5, 15]]\n assert candidate(nums1 = [5, 7, 8],nums2 = [9, 10, 11]) == [[8, 5, 7], [9, 10, 11]]\n assert candidate(nums1 = [1000, -1000],nums2 = [-1000, 1000]) == [[], []]\n assert candidate(nums1 = [1000, -1000],nums2 = [-1000, 1000]) == [[], []]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == [[], []]\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = [2, 4, 6, 8]) == [[1, 3, 5, 7], [8, 2, 4, 6]]\n assert candidate(nums1 = [1, 2, 3, 3],nums2 = [1, 1, 2, 2]) == [[3], []]\n assert candidate(nums1 = [100, 200, 300],nums2 = [100, 200, 300]) == [[], []]\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 2, 2, 2]) == [[1], [2]]\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]\n assert candidate(nums1 = [-1, -2, -3],nums2 = [-3, -4, -5]) == [[-1, -2], [-5, -4]]\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 40, 50]) == [[10, 20], [40, 50]]\n assert candidate(nums1 = [5, 7, 9],nums2 = [5, 8, 10]) == [[9, 7], [8, 10]]\n assert candidate(nums1 = [-1, -2, -3],nums2 = [-2, -3, -4]) == [[-1], [-4]]\n assert candidate(nums1 = [1],nums2 = [2]) == [[1], [2]]\n assert candidate(nums1 = [-1000, 0, 1000],nums2 = [0]) == [[-1000, 1000], []]\n assert candidate(nums1 = [5, 6, 7],nums2 = [7, 8, 9]) == [[5, 6], [8, 9]]\n assert candidate(nums1 = [1, 2, 3],nums2 = [2, 4, 6]) == [[1, 3], [4, 6]]\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == [[1, 2, 3], [4, 5, 6]]\n assert candidate(nums1 = [-1, 0, 1],nums2 = [0, 1, 2]) == [[-1], [2]]\n assert candidate(nums1 = [0],nums2 = [0]) == [[], []]\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0]) == [[], []]\n assert candidate(nums1 = [10, 20, 30],nums2 = [15, 25, 35]) == [[10, 20, 30], [25, 35, 15]]\n assert candidate(nums1 = [-1, -2, -3, -4, -5, 0, 5, 10],nums2 = [-5, -4, -3, -2, -1, 0, 1, 2]) == [[10, 5], [1, 2]]\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0]) == [[], []]\n assert candidate(nums1 = [6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5]) == [[6, 7, 8, 9, 10], [1, 2, 3, 4, 5]]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4],nums2 = [4, 4, 5, 5, 6, 6, 7, 7]) == [[1, 2, 3], [5, 6, 7]]\n assert candidate(nums1 = [-5, -10, -15, -20],nums2 = [-10, -15, -20, -25]) == [[-5], [-25]]\n assert candidate(nums1 = [1000, 999, 998, 997, 996],nums2 = [996, 995, 994, 993, 992]) == [[1000, 997, 998, 999], [992, 993, 994, 995]]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4],nums2 = [2, 2, 3, 3, 5, 5, 6, 6]) == [[1, 4], [5, 6]]\n assert candidate(nums1 = [10, 20, 30, 40],nums2 = [30, 40, 50, 60]) == [[10, 20], [50, 60]]\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]) == [[1, 2, 3, 4], [11, 12, 13, 14]]\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]) == [[], []]\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, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], []]\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5]) == [[], []]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [100, 200, 300, 400, 500]) == [[], []]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [200, 400, 600, 800, 1000]) == [[100, 500, 300], [800, 1000, 600]]\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], []]\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, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 1, 1, 1]) == [[0], [1]]\n assert candidate(nums1 = [-1, -2, -3, -4],nums2 = [-3, -4, -5, -6]) == [[-1, -2], [-6, -5]]\n assert candidate(nums1 = [1, 2, 2, 3, 4, 4, 5],nums2 = [2, 4, 6, 7, 8, 8, 9]) == [[1, 3, 5], [8, 9, 6, 7]]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [2, 2, 4, 4, 5, 5]) == [[1, 3], [4, 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]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]\n assert candidate(nums1 = [1, 2, 3],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [[], [4, 5, 6, 7, 8, 9, 10]]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]) == [[], [35, 45, 15, 55, 25]]\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], []]\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [300, 400, 500, 600]) == [[200, 100], [600, 500]]\n assert candidate(nums1 = [-1000, -999, -998],nums2 = [-1000, -999, -997]) == [[-998], [-997]]\n assert candidate(nums1 = [1000, -1000, 0, 500, -500],nums2 = [-1000, 0, 500, -500, 1000]) == [[], []]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == [[1, 3, 5, 7, 9, 11, 13, 15], [2, 4, 6, 8, 10, 12, 14, 16]]\n assert candidate(nums1 = [100, -50, 0, 200, 300],nums2 = [-50, 0, 100, 400, 500]) == [[200, 300], [400, 500]]\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]) == [[], []]\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [100, 300, 500, 600]) == [[200, 400], [600, 500]]\n assert candidate(nums1 = [-1, -2, -3, -4, -5],nums2 = [-5, -4, -3, -2, -1]) == [[], []]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == [[], []]\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 1, 2, 3, 4, 5]) == [[], [1, 2, 3, 4, 5]]\n assert candidate(nums1 = [-1, 0, 1],nums2 = [0, -1, 2]) == [[1], [2]]\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]) == [[1], [2]]\n assert candidate(nums1 = [-1000, -500, 0, 500, 1000],nums2 = [-1000, -500, 0, 500, 1000]) == [[], []]\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]) == [[800, 900, 100, 1000, 200, 300, 400, 500, 600, 700], [-800, -700, -600, -500, -400, -900, -300, -200, -1000, -100]]\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [3, 3, 4, 4, 5, 5]) == [[1, 2], [4, 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]) == [[100, 70, 40, 10, 80, 50, 20, 90, 60, 30], [65, 35, 5, 75, 45, 15, 85, 55, 25, 95]]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [50, 60, 70, 80, 90]) == [[40, 10, 20, 30], [80, 90, 60, 70]]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45, 55]) == [[40, 10, 50, 20, 30], [35, 5, 45, 15, 55, 25]]\n assert candidate(nums1 = [500, 501, 502, 503, 504],nums2 = [502, 503, 504, 505, 506]) == [[500, 501], [505, 506]]\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]) == [[], []]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == [[40, 10, 50, 20, 30], [35, 5, 45, 15, 25]]\n assert candidate(nums1 = [-1000, 1000, 0],nums2 = [0, -1000, 1000]) == [[], []]\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [2, 4, 6, 8, 10, 12]) == [[1, 3, 5, 7, 9, 11], [2, 4, 6, 8, 10, 12]]\n assert candidate(nums1 = [100, 200, 300],nums2 = [300, 200, 100, 400, 500]) == [[], [400, 500]]\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, 3, 5, 7, 9], [12, 14, 16, 18, 20]]\n assert candidate(nums1 = [500, 501, 502, 503, 504, 505],nums2 = [503, 504, 505, 506, 507, 508]) == [[500, 501, 502], [506, 507, 508]]\n assert candidate(nums1 = [-1, -2, -3],nums2 = [-3, -4, -5]) == [[-1, -2], [-5, -4]]\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 20, 10]) == [[], []]\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [[], []]\n assert candidate(nums1 = [100, -50, 200, 300, -100],nums2 = [-50, 200, 400, 500, -100]) == [[100, 300], [400, 500]]\n assert candidate(nums1 = [1000, 500, -500, -1000],nums2 = [500, -500, 1000, -1000]) == [[], []]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9]) == [[1, 2, 3, 4], [8, 9, 6, 7]]\n assert candidate(nums1 = [1000, -1000, 500, -500, 0],nums2 = [0, 500, -500, 1000, -1000]) == [[], []]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100]) == [[], []]\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]\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]) == [[], []]\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 40, 50, 10, 20]) == [[], [40, 50]]\n assert candidate(nums1 = [500, 600, 700],nums2 = [800, 900, 1000, 500, 600]) == [[700], [800, 1000, 900]]\n assert candidate(nums1 = [100, -50, 23, 7, 3, 100],nums2 = [-50, 23, 8, 9, 100, 101]) == [[3, 7], [8, 9, 101]]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5]) == [[], []]\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [5, 6, 7, 8, 9, 0]) == [[1, 2, 3, 4], [8, 9, 6, 7]]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [150, 250, 350, 450, 550]) == [[100, 200, 300, 400, 500], [450, 550, 150, 250, 350]]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 600, 700, 800, 900]) == [[200, 100, 400, 300], [800, 700, 600, 900]]\n assert candidate(nums1 = [-10, -20, -30],nums2 = [-30, -40, -50, -10]) == [[-20], [-40, -50]]\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [6, 7, 8, 9, 10]) == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [100, 200, 300, 500]) == [[400], [500]]\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [101, 201, 301, 401, 501]) == [[100, 200, 300, 400, 500], [101, 201, 301, 401, 501]]\n assert candidate(nums1 = [-1, -2, -3, -4, -5],nums2 = [-5, -6, -7, -8, -9]) == [[-4, -3, -2, -1], [-8, -7, -6, -9]]\n assert candidate(nums1 = [0, -1, -2, -3, -4],nums2 = [-2, -4, -6, -8, -10]) == [[0, -3, -1], [-8, -6, -10]]\n assert candidate(nums1 = [100, 200, 300],nums2 = [100, 200, 300, 400, 500]) == [[], [400, 500]]\n assert candidate(nums1 = [-1, -2, -3, -4],nums2 = [-4, -5, -6, -7]) == [[-3, -1, -2], [-7, -6, -5]]\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5],nums2 = [3, 4, 5, 6, 7, 8]) == [[0, 1, 2], [8, 6, 7]]\n assert candidate(nums1 = [-1000, -500, 0, 500, 1000],nums2 = [1000, 500, 0, -500, -1000]) == [[], []]\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55]) == [[40, 10, 50, 20, 30], [35, 45, 15, 55, 25]]\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],nums2 = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46]) == [[35, 5, 40, 10, 45, 15, 50, 20, 25, 30], [1, 36, 6, 41, 11, 46, 16, 21, 26, 31]]\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],nums2 = [3, 3, 4, 4, 5, 5, 6, 6]) == [[1, 2], [5, 6]]\n assert candidate(nums1 = [-1000, -999, -998, -997],nums2 = [-999, -998, -997, -996]) == [[-1000], [-996]]\n", "comparison": "exact"}, "public_tests": ["[1,2,3]\n[2,4,6]", "[1,2,3,3]\n[1,1,2,2]"], "hints": ["For each integer in nums1, check if it exists in nums2.", "Do the same for each integer in nums2."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().findDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:13+00:00", "tests_total": 112, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "php", "interface": {"raw_signature": "function findDifference($nums1, $nums2) {", "container": "Solution", "callable": "findDifference", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2216, "task_id": "minimum-deletions-to-make-array-beautiful", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. The array nums is beautiful if:\n\n- nums.length is even.\n- nums[i] != nums[i + 1] for all i % 2 == 0.\n\nNote that an empty array is considered beautiful.\n\nYou can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.\n\nReturn the minimum number of elements to delete from nums to make it beautiful.\n\nExample 1:\n\nInput: nums = [1,1,2,3,5]\nOutput: 1\nExplanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.\n\nExample 2:\n\nInput: nums = [1,1,2,2,3,3]\nOutput: 2\nExplanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000]) == 6\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == 2\n assert candidate(nums = [100000, 100000, 99999, 99999, 99998, 99998]) == 2\n assert candidate(nums = [2, 2, 2, 2, 2, 2]) == 6\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 1\n assert candidate(nums = [0, 1, 0, 1, 0, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4]) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [1, 1, 2, 3, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 1\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2]) == 5\n assert candidate(nums = [1, 3, 2, 3, 3, 2]) == 0\n assert candidate(nums = [1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5]) == 16\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 5]) == 2\n assert candidate(nums = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 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, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 6\n assert candidate(nums = [1, 1, 1, 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]) == 24\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 10\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\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, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 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]) == 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]) == 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, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 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]) == 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, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 12\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 24\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, 2, 3, 4, 5, 6, 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, 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]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 13, 14]) == 4\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]) == 0\n assert candidate(nums = [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, 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]) == 12\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, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 3\n assert candidate(nums = [1, 2, 2, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 1, 2, 2]) == 2\n assert candidate(nums = [1, 2, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 2\n assert candidate(nums = [5, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0]) == 6\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9, 9]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 1\n assert candidate(nums = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 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, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 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]) == 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]) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 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]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5]) == 8\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\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, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 8\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 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, 21, 22, 23, 24, 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, 1, 1, 1, 1, 1]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 1\n assert candidate(nums = [1, 2, 3, 3, 4, 5, 5, 6, 7, 8]) == 2\n assert candidate(nums = [100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 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 = [100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996, 99996, 99995, 99995, 99994, 99994, 99993, 99993, 99992, 99992, 99991, 99991, 99990, 99990, 99989, 99989, 99988, 99988]) == 2\n assert candidate(nums = [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]) == 0\n assert candidate(nums = [1, 1, 1, 2, 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, 10, 10, 10, 10]) == 15\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 82\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 12\n assert candidate(nums = [1, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2]) == 8\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 6\n assert candidate(nums = [1, 1, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 13\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, 1, 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, 11, 11, 12, 12, 13, 13, 14, 14]) == 2\n assert candidate(nums = [1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 1\n assert candidate(nums = [1, 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, 5, 5]) == 12\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, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 0\n assert candidate(nums = [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5]) == 8\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]) == 22\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]) == 0\n assert candidate(nums = [100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997]) == 2\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == 3\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000]) == 6\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 9]) == 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]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10, 10]) == 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]) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]) == 0\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]) == 3\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 0\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11]) == 0\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]) == 11\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 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]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\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]) == 1\n assert candidate(nums = [100000, 100000, 99999, 99999, 99998, 99998, 99997, 99997, 99996, 99996]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 1\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10]) == 5\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 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]) == 31\n assert candidate(nums = [1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10]) == 3\n assert candidate(nums = [1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 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", "comparison": "exact"}, "public_tests": ["[1,1,2,3,5]", "[1,1,2,2,3,3]"], "hints": ["Delete as many adjacent equal elements as necessary.", "If the length of nums is odd after the entire process, delete the last element."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minDeletion", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:15+00:00", "tests_total": 125, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "stack", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minDeletion($nums) {", "container": "Solution", "callable": "minDeletion", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2217, "task_id": "find-palindrome-with-fixed-length", "difficulty": "Medium", "problem_description": "Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]^th smallest positive palindrome of length intLength or -1 if no such palindrome exists.\n\nA palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.\n\nExample 1:\n\nInput: queries = [1,2,3,4,5,90], intLength = 3\nOutput: [101,111,121,131,141,999]\nExplanation:\nThe first few palindromes of length 3 are:\n101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...\nThe 90^th palindrome of length 3 is 999.\n\nExample 2:\n\nInput: queries = [2,4,6], intLength = 4\nOutput: [1111,1331,1551]\nExplanation:\nThe first six palindromes of length 4 are:\n1001, 1111, 1221, 1331, 1441, and 1551.\n\nConstraints:\n\n- 1 <= queries.length <= 5 * 10^4\n- 1 <= queries[i] <= 10^9\n- 1 <= intLength <= 15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(queries = [10, 20, 30],intLength = 2) == [-1, -1, -1]\n assert candidate(queries = [1, 3, 5, 7, 9],intLength = 5) == [10001, 10201, 10401, 10601, 10801]\n assert candidate(queries = [50000],intLength = 15) == [100499999994001]\n assert candidate(queries = [1, 1000000],intLength = 15) == [100000000000001, 109999999999901]\n assert candidate(queries = [1, 2, 3, 4, 5, 90],intLength = 3) == [101, 111, 121, 131, 141, 999]\n assert candidate(queries = [10, 20, 30],intLength = 6) == [109901, 119911, 129921]\n assert candidate(queries = [2, 4, 6],intLength = 4) == [1111, 1331, 1551]\n assert candidate(queries = [100, 200, 300],intLength = 7) == [1099901, 1199911, 1299921]\n assert candidate(queries = [1, 10, 100, 1000],intLength = 7) == [1000001, 1009001, 1099901, 1999991]\n assert candidate(queries = [10, 20, 30],intLength = 6) == [109901, 119911, 129921]\n assert candidate(queries = [100, 200, 300],intLength = 7) == [1099901, 1199911, 1299921]\n assert candidate(queries = [1, 1, 1, 1],intLength = 1) == [1, 1, 1, 1]\n assert candidate(queries = [1, 100000000],intLength = 1) == [1, -1]\n assert candidate(queries = [5000000],intLength = 1) == [-1]\n assert candidate(queries = [1000000000],intLength = 15) == [-1]\n assert candidate(queries = [1, 10, 100, 1000, 10000],intLength = 5) == [10001, 10901, 19991, -1, -1]\n assert candidate(queries = [100000],intLength = 15) == [100999999999001]\n assert candidate(queries = [1, 2, 3],intLength = 1) == [1, 2, 3]\n assert candidate(queries = [5, 15, 25],intLength = 2) == [55, -1, -1]\n assert candidate(queries = [123456, 654321],intLength = 10) == [-1, -1]\n assert candidate(queries = [50000, 100000, 150000, 200000, 250000, 300000, 350000, 400000],intLength = 13) == [1049999999401, 1099999999901, 1149999999411, 1199999999911, 1249999999421, 1299999999921, 1349999999431, 1399999999931]\n assert candidate(queries = [100, 1000, 10000, 100000, 1000000],intLength = 15) == [100000999000001, 100009999900001, 100099999990001, 100999999999001, 109999999999901]\n assert candidate(queries = [1, 9, 99, 999, 9999, 99999],intLength = 15) == [100000000000001, 100000080000001, 100000989000001, 100009989900001, 100099989990001, 100999989999001]\n assert candidate(queries = [1, 10, 100, 1000, 10000, 100000],intLength = 3) == [101, 191, -1, -1, -1, -1]\n assert candidate(queries = [90000000, 95000000, 99000000],intLength = 15) == [999999999999999, -1, -1]\n assert candidate(queries = [123456789],intLength = 15) == [-1]\n assert candidate(queries = [1, 123456, 987654, 999999],intLength = 5) == [10001, -1, -1, -1]\n assert candidate(queries = [98765, 43210, 54321, 67890],intLength = 5) == [-1, -1, -1, -1]\n assert candidate(queries = [1000000, 2000000, 3000000, 4000000, 5000000],intLength = 11) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],intLength = 5) == [10001, 10101, 10201, 10301, 10401, 10501, 10601, 10701, 10801, 10901]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],intLength = 15) == [100000000000001, 100000010000001, 100000020000001, 100000030000001, 100000040000001, 100000050000001, 100000060000001, 100000070000001, 100000080000001, 100000090000001]\n assert candidate(queries = [123, 456, 789, 101112, 131415],intLength = 11) == [10012221001, 10045554001, 10078887001, 20111111102, 23141414132]\n assert candidate(queries = [1, 10, 100, 1000, 10000],intLength = 9) == [100000001, 100090001, 100999001, 109999901, 199999991]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],intLength = 9) == [100000001, 100010001, 100020001, 100030001, 100040001, 100050001, 100060001, 100070001, 100080001, 100090001]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],intLength = 2) == [11, 22, 33, 44, 55, 66, 77, 88, 99, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(queries = [1, 2, 3, 4, 5, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],intLength = 5) == [10001, 10101, 10201, 10301, 10401, 19991, 29992, 39993, 49994, 59995, 69996, 79997, 89998, 99999, -1]\n assert candidate(queries = [100000000, 200000000, 300000000],intLength = 12) == [-1, -1, -1]\n assert candidate(queries = [100000000, 100000001, 100000002],intLength = 13) == [-1, -1, -1]\n assert candidate(queries = [500000000, 600000000, 700000000],intLength = 9) == [-1, -1, -1]\n assert candidate(queries = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50],intLength = 14) == [10000000000001, 10000044000001, 10000099000001, 10000144100001, 10000199100001, 10000244200001, 10000299200001, 10000344300001, 10000399300001, 10000444400001, 10000499400001]\n assert candidate(queries = [100000, 200000, 300000],intLength = 11) == [19999999991, 29999999992, 39999999993]\n assert candidate(queries = [10000, 20000, 30000, 40000, 50000],intLength = 13) == [1009999999001, 1019999999101, 1029999999201, 1039999999301, 1049999999401]\n assert candidate(queries = [500000, 600000, 700000, 800000],intLength = 13) == [1499999999941, 1599999999951, 1699999999961, 1799999999971]\n assert candidate(queries = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000],intLength = 6) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(queries = [10000, 10001, 10002, 10003, 10004],intLength = 6) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [5000, 6000, 7000, 8000, 9000, 10000],intLength = 11) == [10499999401, 10599999501, 10699999601, 10799999701, 10899999801, 10999999901]\n assert candidate(queries = [999999999],intLength = 15) == [-1]\n assert candidate(queries = [1000, 2000, 3000, 4000, 5000],intLength = 6) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1, 5, 10, 15, 20, 25, 30],intLength = 5) == [10001, 10401, 10901, 11411, 11911, 12421, 12921]\n assert candidate(queries = [100000, 100001, 100002],intLength = 11) == [19999999991, 20000000002, 20000100002]\n assert candidate(queries = [1000, 2000, 3000, 4000, 5000],intLength = 5) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [50000, 150000, 250000],intLength = 11) == [14999999941, 24999999942, 34999999943]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],intLength = 2) == [11, 22, 33, 44, 55, 66, 77, 88, 99, -1, -1, -1, -1, -1, -1]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],intLength = 4) == [1001, 1111, 1221, 1331, 1441, 1551, 1661, 1771, 1881, 1991, 2002, 2112, 2222, 2332, 2442, 2552, 2662, 2772, 2882, 2992]\n assert candidate(queries = [1, 50000000, 100000000],intLength = 15) == [100000000000001, 599999999999995, -1]\n assert candidate(queries = [5000000, 6000000, 7000000],intLength = 11) == [-1, -1, -1]\n assert candidate(queries = [10, 20, 30, 40, 50],intLength = 5) == [10901, 11911, 12921, 13931, 14941]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],intLength = 14) == [10000000000001, 10000011000001, 10000022000001, 10000033000001, 10000044000001, 10000055000001, 10000066000001, 10000077000001, 10000088000001, 10000099000001]\n assert candidate(queries = [100000, 99999, 88888],intLength = 15) == [100999999999001, 100999989999001, 100888878888001]\n assert candidate(queries = [999999, 999998, 999997],intLength = 7) == [-1, -1, -1]\n assert candidate(queries = [123456, 654321, 111111],intLength = 9) == [-1, -1, -1]\n assert candidate(queries = [1, 2, 3, 4, 5, 1000000, 2000000, 3000000, 4000000, 5000000],intLength = 7) == [1000001, 1001001, 1002001, 1003001, 1004001, -1, -1, -1, -1, -1]\n assert candidate(queries = [1000000, 2000000, 3000000, 4000000, 5000000],intLength = 15) == [109999999999901, 119999999999911, 129999999999921, 139999999999931, 149999999999941]\n assert candidate(queries = [12345, 67890, 111111, 222222, 333333],intLength = 7) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1, 100000000, 50000000, 25000000, 75000000, 90000000, 100000000, 85000000, 65000000, 45000000],intLength = 8) == [10000001, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(queries = [100, 200, 300, 400, 500],intLength = 15) == [100000999000001, 100001999100001, 100002999200001, 100003999300001, 100004999400001]\n assert candidate(queries = [10000, 20000, 30000],intLength = 7) == [-1, -1, -1]\n assert candidate(queries = [1, 123456, 987654, 1000000],intLength = 5) == [10001, -1, -1, -1]\n assert candidate(queries = [10000, 20000, 30000, 40000, 50000],intLength = 8) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1000, 2000, 3000, 4000, 5000],intLength = 11) == [10099999001, 10199999101, 10299999201, 10399999301, 10499999401]\n assert candidate(queries = [1, 10, 100, 1000, 10000, 100000],intLength = 11) == [10000000001, 10000900001, 10009990001, 10099999001, 10999999901, 19999999991]\n assert candidate(queries = [5000, 10000, 15000, 20000],intLength = 10) == [1499999941, 1999999991, 2499999942, 2999999992]\n assert candidate(queries = [999999, 888888, 777777, 666666, 555555],intLength = 10) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1, 1000000, 9999999, 10000000],intLength = 13) == [1000000000001, 1999999999991, -1, -1]\n assert candidate(queries = [98765, 43210, 11111, 22222, 33333],intLength = 11) == [19876467891, 14320902341, 11111011111, 12222122221, 13333233331]\n assert candidate(queries = [500000, 600000, 700000],intLength = 13) == [1499999999941, 1599999999951, 1699999999961]\n assert candidate(queries = [987654321],intLength = 15) == [-1]\n assert candidate(queries = [123456789],intLength = 9) == [-1]\n assert candidate(queries = [123456789, 987654321, 500000000, 300000000, 200000000],intLength = 15) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [123, 456, 789],intLength = 10) == [1012222101, 1045555401, 1078888701]\n assert candidate(queries = [100000, 200000, 300000],intLength = 9) == [-1, -1, -1]\n assert candidate(queries = [100000000],intLength = 15) == [-1]\n assert candidate(queries = [999999999, 999999998, 999999997, 999999996, 999999995],intLength = 15) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1, 999999999],intLength = 15) == [100000000000001, -1]\n assert candidate(queries = [100000, 1000000, 10000000, 100000000, 1000000000],intLength = 11) == [19999999991, -1, -1, -1, -1]\n assert candidate(queries = [5000, 10000, 15000, 20000],intLength = 7) == [5999995, -1, -1, -1]\n assert candidate(queries = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],intLength = 9) == [100000001, 100090001, 100999001, 109999901, 199999991, -1, -1, -1, -1, -1]\n assert candidate(queries = [500, 1000, 1500, 2000, 2500, 3000],intLength = 7) == [1499941, 1999991, 2499942, 2999992, 3499943, 3999993]\n assert candidate(queries = [1000000000],intLength = 9) == [-1]\n assert candidate(queries = [10000, 20000, 30000, 40000],intLength = 11) == [10999999901, 11999999911, 12999999921, 13999999931]\n assert candidate(queries = [987654, 987655, 987656, 987657, 987658],intLength = 13) == [1987653567891, 1987654567891, 1987655567891, 1987656567891, 1987657567891]\n assert candidate(queries = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95],intLength = 3) == [101, 141, 191, 242, 292, 343, 393, 444, 494, 545, 595, 646, 696, 747, 797, 848, 898, 949, 999, -1]\n assert candidate(queries = [123456789, 987654321, 567891234],intLength = 15) == [-1, -1, -1]\n assert candidate(queries = [1, 123456789, 987654321, 500000000],intLength = 9) == [100000001, -1, -1, -1]\n assert candidate(queries = [1000000, 1000001, 1000002, 1000003, 1000004],intLength = 13) == [1999999999991, 2000000000002, 2000001000002, 2000002000002, 2000003000002]\n assert candidate(queries = [5000, 10000, 15000, 20000],intLength = 9) == [149999941, 199999991, 249999942, 299999992]\n assert candidate(queries = [100000000, 99999999, 88888888, 77777777],intLength = 13) == [-1, -1, -1, -1]\n assert candidate(queries = [123456789],intLength = 10) == [-1]\n assert candidate(queries = [100000000, 99999999, 99999998, 99999997, 99999996],intLength = 2) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [1000000, 1000001, 1000002],intLength = 15) == [109999999999901, 110000000000011, 110000010000011]\n assert candidate(queries = [999999, 999998, 999997, 999996, 999995],intLength = 6) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1],intLength = 11) == [-1, -1, -1, 19999999991, 10999999901, 10099999001, 10009990001, 10000900001, 10000000001]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],intLength = 2) == [11, 22, 33, 44, 55, 66, 77, 88, 99, -1]\n assert candidate(queries = [1, 10, 100, 1000, 10000, 100000],intLength = 14) == [10000000000001, 10000099000001, 10000999900001, 10009999990001, 10099999999001, 10999999999901]\n assert candidate(queries = [987654321, 123456789],intLength = 8) == [-1, -1]\n assert candidate(queries = [10000000, 10000001, 10000002, 10000003, 10000004],intLength = 7) == [-1, -1, -1, -1, -1]\n assert candidate(queries = [500000, 500001, 500002, 500003, 500004],intLength = 13) == [1499999999941, 1500000000051, 1500001000051, 1500002000051, 1500003000051]\n assert candidate(queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 10000, 100000, 1000000],intLength = 5) == [10001, 10101, 10201, 10301, 10401, 10501, 10601, 10701, 10801, 10901, 19991, -1, -1, -1, -1]\n assert candidate(queries = [99999999, 100000000, 100000001],intLength = 9) == [-1, -1, -1]\n assert candidate(queries = [500000, 500001, 500002, 500003, 500004, 500005],intLength = 13) == [1499999999941, 1500000000051, 1500001000051, 1500002000051, 1500003000051, 1500004000051]\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,90]\n3", "[2,4,6]\n4"], "hints": ["For any value of queries[i] and intLength, how can you check if there exists at least queries[i] palindromes of length intLength?", "Since a palindrome reads the same forwards and backwards, consider how you can efficiently find the first half (ceil(intLength/2) digits) of the palindrome."], "metadata": {"canonical_parameter_names": ["queries", "intLength"], "leetcode_dataset_entry_point": "Solution().kthPalindrome", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:18+00:00", "tests_total": 110, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math"]}, "language": "php", "interface": {"raw_signature": "function kthPalindrome($queries, $intLength) {", "container": "Solution", "callable": "kthPalindrome", "parameters": [{"name": "queries", "type": "Integer[]"}, {"name": "intLength", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2218, "task_id": "maximum-value-of-k-coins-from-piles", "difficulty": "Hard", "problem_description": "There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.\n\nIn one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.\n\nGiven a list piles, where piles[i] is a list of integers denoting the composition of the i^th pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.\n\nExample 1:\n\nInput: piles = [[1,100,3],[7,8,9]], k = 2\nOutput: 101\nExplanation:\nThe above diagram shows the different ways we can choose k coins.\nThe maximum total we can obtain is 101.\n\nExample 2:\n\nInput: piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7\nOutput: 706\nExplanation:\nThe maximum total can be obtained if we choose all coins from the last pile.\n\nConstraints:\n\n- n == piles.length\n- 1 <= n <= 1000\n- 1 <= piles[i][j] <= 10^5\n- 1 <= k <= sum(piles[i].length) <= 2000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(piles = [[30, 10], [50, 20, 10]],k = 3) == 100\n assert candidate(piles = [[1, 2], [3, 4], [5, 6]],k = 5) == 19\n assert candidate(piles = [[10, 20], [5, 5, 5, 5], [1, 1, 1, 1, 1]],k = 5) == 45\n assert candidate(piles = [[1, 2, 3], [4, 5, 6]],k = 3) == 15\n assert candidate(piles = [[30, 10, 20], [10, 20, 30], [5, 5, 5]],k = 5) == 100\n assert candidate(piles = [[1], [2], [3], [4], [5]],k = 3) == 12\n assert candidate(piles = [[10]],k = 1) == 10\n assert candidate(piles = [[10, 20, 30], [30, 20, 10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 10) == 124\n assert candidate(piles = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 5) == 33\n assert candidate(piles = [[1, 100, 3], [7, 8, 9]],k = 2) == 101\n assert candidate(piles = [[100], [100], [100], [100], [100], [100], [1, 1, 1, 1, 1, 1, 700]],k = 7) == 706\n assert candidate(piles = [[3, 1, 5], [1, 2, 3], [4, 6]],k = 3) == 13\n assert candidate(piles = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],k = 4) == 16\n assert candidate(piles = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]],k = 10) == 55\n assert candidate(piles = [[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 = 25) == 55\n assert candidate(piles = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]],k = 10) == 55\n assert candidate(piles = [[1, 3, 5, 7, 9], [2, 4, 6, 8], [10, 20, 30, 40, 50, 60]],k = 12) == 237\n assert candidate(piles = [[10000, 20000, 30000, 40000, 50000], [10000, 20000, 30000, 40000, 50000], [10000, 20000, 30000, 40000, 50000]],k = 10) == 300000\n assert candidate(piles = [[100, 90, 80], [70, 60, 50, 40], [30, 20, 10]],k = 7) == 490\n assert candidate(piles = [[1, 100, 3, 50], [7, 8, 9, 100], [1, 2, 3, 4, 5]],k = 7) == 228\n assert candidate(piles = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]],k = 10) == 550\n assert candidate(piles = [[5, 1, 2, 3], [4, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],k = 8) == 100\n assert candidate(piles = [[100, 200, 300, 400], [500, 600, 700, 800], [900, 1000, 1100, 1200], [1300, 1400, 1500, 1600]],k = 8) == 10000\n assert candidate(piles = [[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]],k = 50) == 400\n assert candidate(piles = [[1000, 900, 800], [700, 600, 500], [400, 300, 200], [100, 90, 80], [70, 60, 50], [40, 30, 20], [10, 9, 8], [7, 6, 5]],k = 20) == 5959\n assert candidate(piles = [[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(piles = [[1000, 2000, 3000], [1000, 1000, 1000, 1000], [500, 500, 500, 500, 500, 500], [200, 200, 200]],k = 10) == 11500\n assert candidate(piles = [[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 = 15) == 40\n assert candidate(piles = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]],k = 20) == 210\n assert candidate(piles = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]],k = 10) == 35\n assert candidate(piles = [[10, 20], [30, 40, 50, 60], [70, 80, 90], [100]],k = 7) == 460\n assert candidate(piles = [[10, 15, 20], [25, 30, 35], [40, 45, 50], [5, 10, 15], [1, 2, 3]],k = 12) == 300\n assert candidate(piles = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]],k = 15) == 195\n assert candidate(piles = [[99999, 99998, 99997, 99996, 99995], [99994, 99993, 99992, 99991, 99990], [99989, 99988, 99987, 99986, 99985], [99984, 99983, 99982, 99981, 99980]],k = 15) == 1499880\n assert candidate(piles = [[1, 2], [3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13, 14]],k = 8) == 81\n assert candidate(piles = [[10, 20, 30], [5, 15, 25], [1, 2, 3], [9, 18, 27]],k = 8) == 134\n assert candidate(piles = [[1000, 500, 250, 125, 62, 31, 15, 7, 3, 1], [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]],k = 20) == 3017\n assert candidate(piles = [[100, 90, 80, 70, 60], [50, 40, 30, 20, 10], [1, 2, 3, 4, 5]],k = 10) == 550\n assert candidate(piles = [[10, 20, 30], [40, 50, 60, 70], [80, 90]],k = 8) == 420\n assert candidate(piles = [[100000], [100000], [100000], [100000], [100000], [100000], [100000]],k = 7) == 700000\n assert candidate(piles = [[10, 20, 30, 40, 50], [20, 30, 40, 50, 60], [30, 40, 50, 60, 70]],k = 6) == 270\n assert candidate(piles = [[5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2]],k = 15) == 59\n assert candidate(piles = [[10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10], [10]],k = 15) == 150\n assert candidate(piles = [[100000], [100000], [100000], [100000], [100000], [100000], [100000], [100000], [100000], [100000]],k = 5) == 500000\n assert candidate(piles = [[1, 2, 3, 4, 5], [10, 20, 30, 40, 50], [100, 200, 300, 400, 500], [1000, 2000, 3000, 4000, 5000]],k = 10) == 16500\n assert candidate(piles = [[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) == 105\n assert candidate(piles = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]],k = 10) == 55\n assert candidate(piles = [[1, 10, 30, 50], [10, 20, 30, 40], [5, 15, 25, 35]],k = 10) == 211\n assert candidate(piles = [[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]],k = 10) == 1009\n assert candidate(piles = [[10, 20, 30], [1, 2, 3, 4, 5], [100, 200], [50, 60, 70]],k = 7) == 510\n assert candidate(piles = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [10, 9, 8, 7, 6]],k = 15) == 95\n assert candidate(piles = [[1000, 900, 800], [700, 600], [500, 400, 300, 200, 100]],k = 12) == 5500\n assert candidate(piles = [[1], [1, 1, 1], [1, 1, 1, 1, 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) == 20\n assert candidate(piles = [[100, 100, 100], [100, 100, 100], [100, 100, 100], [100, 100, 100]],k = 8) == 800\n assert candidate(piles = [[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]],k = 15) == 140\n assert candidate(piles = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1]],k = 15) == 70\n assert candidate(piles = [[1000, 2000, 3000], [1500, 2500, 3500], [1200, 2200, 3200]],k = 5) == 10900\n assert candidate(piles = [[10, 20, 30, 40], [5, 15, 25], [100], [50, 75]],k = 6) == 285\n assert candidate(piles = [[1, 1000, 2000], [3000, 4000, 5000], [6000, 7000, 8000], [9000, 10000, 11000]],k = 6) == 51000\n assert candidate(piles = [[5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [7, 7, 7, 7, 7, 7, 7, 7, 7, 7]],k = 25) == 135\n assert candidate(piles = [[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 = 20) == 40\n assert candidate(piles = [[10, 20, 30], [15, 25, 35, 45], [5, 10, 15, 20, 25]],k = 10) == 210\n assert candidate(piles = [[1, 100, 3], [7, 8, 9], [4, 5, 6], [10, 20, 30], [1000, 2000, 3000]],k = 12) == 6189\n assert candidate(piles = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]],k = 10) == 155\n assert candidate(piles = [[1, 2, 3, 4, 5, 6, 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) == 320\n assert candidate(piles = [[10, 20, 30, 40], [50, 60, 70], [80, 90, 100, 110, 120], [130, 140]],k = 10) == 950\n assert candidate(piles = [[100], [200], [300], [400], [500], [600], [700], [800], [900], [1000]],k = 5) == 4000\n assert candidate(piles = [[50], [20], [10], [5]],k = 3) == 80\n assert candidate(piles = [[9, 7, 5, 3, 1], [8, 6, 4, 2], [10, 20, 30], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 15) == 108\n assert candidate(piles = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 4, 6, 8, 10], [10, 8, 6, 4, 2]],k = 15) == 78\n assert candidate(piles = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [2, 12, 22, 32, 42]],k = 10) == 275\n assert candidate(piles = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]],k = 20) == 210\n assert candidate(piles = [[1000, 2000], [100, 200, 300, 400, 500], [50]],k = 8) == 4550\n assert candidate(piles = [[5, 10, 15], [20, 25, 30, 35, 40], [1, 1, 1, 1, 1, 1, 1], [99, 98, 97, 96]],k = 10) == 545\n assert candidate(piles = [[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], [1000]],k = 20) == 1038\n assert candidate(piles = [[10, 20, 30, 40, 50], [5, 10, 15, 20, 25], [1, 2, 3, 4, 5], [100, 200, 300, 400, 500]],k = 10) == 1650\n assert candidate(piles = [[1000, 2000, 3000], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [500, 600, 700, 800, 900], [10, 20, 30, 40, 50]],k = 15) == 9653\n assert candidate(piles = [[1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]],k = 12) == 147\n assert candidate(piles = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]],k = 10) == 300\n assert candidate(piles = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]],k = 14) == 105\n assert candidate(piles = [[5, 4, 3, 2, 1], [10, 9, 8, 7, 6], [15, 14, 13, 12, 11]],k = 15) == 120\n assert candidate(piles = [[100, 200, 300], [400, 500, 600], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],k = 15) == 2145\n assert candidate(piles = [[100, 200, 300], [50, 60, 70, 80], [10, 20, 30, 40, 50]],k = 15) == 1010\n assert candidate(piles = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]],k = 18) == 90\n assert candidate(piles = [[5, 1, 2], [3, 10, 1], [4, 4, 4], [2, 8, 6]],k = 6) == 34\n assert candidate(piles = [[1, 100, 3], [7, 8, 9], [5, 6, 7], [4, 5, 6]],k = 10) == 152\n assert candidate(piles = [[1, 1, 1, 1, 1], [2, 2, 2], [3, 3], [4], [5, 5, 5, 5]],k = 10) == 36\n assert candidate(piles = [[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], [6, 8, 10, 12, 14], [7, 9, 11, 13, 15], [8, 10, 12, 14, 16], [9, 11, 13, 15, 17], [10, 12, 14, 16, 18]],k = 25) == 300\n assert candidate(piles = [[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]],k = 15) == 95\n assert candidate(piles = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]],k = 15) == 120\n assert candidate(piles = [[10, 20, 30], [5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 8) == 81\n assert candidate(piles = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]],k = 8) == 100\n assert candidate(piles = [[100, 200], [50, 150, 250], [200, 300, 400, 500], [300, 400, 500, 600, 700]],k = 15) == 4650\n assert candidate(piles = [[1, 2], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19, 20], [21, 22, 23]],k = 12) == 201\n", "comparison": "exact"}, "public_tests": ["[[1,100,3],[7,8,9]]\n2", "[[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]]\n7"], "hints": ["For each pile i, what will be the total value of coins we can collect if we choose the first j coins?", "How can we use dynamic programming to combine the results from different piles to find the most optimal answer?"], "metadata": {"canonical_parameter_names": ["piles", "k"], "leetcode_dataset_entry_point": "Solution().maxValueOfCoins", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:20+00:00", "tests_total": 96, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxValueOfCoins($piles, $k) {", "container": "Solution", "callable": "maxValueOfCoins", "parameters": [{"name": "piles", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2220, "task_id": "minimum-bit-flips-to-convert-number", "difficulty": "Easy", "problem_description": "A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.\n\n- For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.\n\nGiven two integers start and goal, return the minimum number of bit flips to convert start to goal.\n\nExample 1:\n\nInput: start = 10, goal = 7\nOutput: 3\nExplanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:\n- Flip the first bit from the right: 1010 -> 1011.\n- Flip the third bit from the right: 1011 -> 1111.\n- Flip the fourth bit from the right: 1111 -> 0111.\nIt can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.\n\nExample 2:\n\nInput: start = 3, goal = 4\nOutput: 3\nExplanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:\n- Flip the first bit from the right: 011 -> 010.\n- Flip the second bit from the right: 010 -> 000.\n- Flip the third bit from the right: 000 -> 100.\nIt can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.\n\nConstraints:\n\n- 0 <= start, goal <= 10^9\n\nNote: This question is the same as 461: Hamming Distance.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(start = 123456789,goal = 987654321) == 15\n assert candidate(start = 5,goal = 2) == 3\n assert candidate(start = 1000000000,goal = 500000000) == 14\n assert candidate(start = 8,goal = 15) == 3\n assert candidate(start = 15,goal = 8) == 3\n assert candidate(start = 5,goal = 8) == 3\n assert candidate(start = 1000000000,goal = 999999999) == 10\n assert candidate(start = 1023,goal = 0) == 10\n assert candidate(start = 3,goal = 4) == 3\n assert candidate(start = 29,goal = 15) == 2\n assert candidate(start = 10,goal = 7) == 3\n assert candidate(start = 54321,goal = 12345) == 5\n assert candidate(start = 1023,goal = 512) == 9\n assert candidate(start = 512,goal = 256) == 2\n assert candidate(start = 0,goal = 0) == 0\n assert candidate(start = 255,goal = 0) == 8\n assert candidate(start = 15,goal = 0) == 4\n assert candidate(start = 1,goal = 1) == 0\n assert candidate(start = 1,goal = 1023) == 9\n assert candidate(start = 5,goal = 10) == 4\n assert candidate(start = 111111111,goal = 999999999) == 13\n assert candidate(start = 101010101,goal = 111111111) == 10\n assert candidate(start = 987654321,goal = 123456789) == 15\n assert candidate(start = 1000000000,goal = 0) == 13\n assert candidate(start = 888888888,goal = 111111111) == 18\n assert candidate(start = 67890,goal = 54321) == 9\n assert candidate(start = 536870912,goal = 858993459) == 15\n assert candidate(start = 1048575,goal = 2097151) == 1\n assert candidate(start = 987654321,goal = 876543219) == 11\n assert candidate(start = 123,goal = 321) == 5\n assert candidate(start = 1000000000,goal = 1) == 14\n assert candidate(start = 999999999,goal = 111111111) == 13\n assert candidate(start = 999999999,goal = 999999998) == 1\n assert candidate(start = 293847,goal = 987654) == 11\n assert candidate(start = 111111111,goal = 222222222) == 14\n assert candidate(start = 1001001,goal = 1100110) == 15\n assert candidate(start = 123456789,goal = 123456788) == 1\n assert candidate(start = 500000000,goal = 500000001) == 1\n assert candidate(start = 33554431,goal = 67108864) == 26\n assert candidate(start = 8388607,goal = 8388608) == 24\n assert candidate(start = 13579,goal = 24680) == 8\n assert candidate(start = 134217727,goal = 268435455) == 1\n assert candidate(start = 54321,goal = 100000) == 7\n assert candidate(start = 16777215,goal = 8388608) == 23\n assert candidate(start = 86420,goal = 13579) == 10\n assert candidate(start = 1,goal = 1000000000) == 14\n assert candidate(start = 0,goal = 1000000000) == 13\n assert candidate(start = 789012345,goal = 543210987) == 16\n assert candidate(start = 123456789,goal = 987654322) == 17\n assert candidate(start = 134217728,goal = 268435455) == 27\n assert candidate(start = 536870912,goal = 268435456) == 2\n assert candidate(start = 54321,goal = 65432) == 8\n assert candidate(start = 268435455,goal = 67108863) == 2\n assert candidate(start = 999999999,goal = 888888888) == 17\n assert candidate(start = 135792468,goal = 246813579) == 16\n assert candidate(start = 8675309,goal = 5309867) == 12\n assert candidate(start = 999999999,goal = 1) == 20\n assert candidate(start = 1048575,goal = 1) == 19\n assert candidate(start = 100000000,goal = 1) == 13\n assert candidate(start = 134217728,goal = 134217729) == 1\n assert candidate(start = 67890,goal = 98765) == 10\n assert candidate(start = 1234,goal = 5678) == 8\n assert candidate(start = 67890,goal = 12345) == 8\n assert candidate(start = 123456,goal = 654321) == 8\n assert candidate(start = 65535,goal = 32768) == 15\n assert candidate(start = 555555555,goal = 444444444) == 20\n", "comparison": "exact"}, "public_tests": ["10\n7", "3\n4"], "hints": ["If the value of a bit in start and goal differ, then we need to flip that bit.", "Consider using the XOR operation to determine which bits need a bit flip."], "metadata": {"canonical_parameter_names": ["start", "goal"], "leetcode_dataset_entry_point": "Solution().minBitFlips", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:25+00:00", "tests_total": 85, "tests_dropped": 19, "flags": [], "topic_tags": ["bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function minBitFlips($start, $goal) {", "container": "Solution", "callable": "minBitFlips", "parameters": [{"name": "start", "type": "Integer"}, {"name": "goal", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2221, "task_id": "find-triangular-sum-of-an-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).\n\nThe triangular sum of nums is the value of the only element present in nums after the following process terminates:\n\n1. Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.\n2. For each index i, where 0 <= i < n - 1, assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.\n3. Replace the array nums with newNums.\n4. Repeat the entire process starting from step 1.\n\nReturn the triangular sum of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 8\nExplanation:\nThe above diagram depicts the process from which we obtain the triangular sum of the array.\n\nExample 2:\n\nInput: nums = [5]\nOutput: 5\nExplanation:\nSince there is only one element in nums, the triangular sum is the value of that element itself.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 0 <= nums[i] <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 6\n assert candidate(nums = [4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 2]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 6\n assert candidate(nums = [5]) == 5\n assert candidate(nums = [1, 0, 1, 0, 1]) == 8\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 6\n assert candidate(nums = [9, 9, 9, 9, 9]) == 4\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [6, 7, 3, 5, 9, 4, 2, 8, 1, 0]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 8\n assert candidate(nums = [9, 9, 9, 9]) == 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]) == 2\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 6\n assert candidate(nums = [6, 3, 8, 1, 7, 4, 9, 2, 5, 0, 6, 3, 8, 1, 7, 4, 9, 2, 5, 0]) == 6\n assert candidate(nums = [8, 6, 7, 5, 3, 0, 9, 1, 2, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == 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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9, 1]) == 6\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 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]) == 8\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 = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 8\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\n assert candidate(nums = [8, 1, 9, 1, 8, 1, 9, 1, 8, 1, 9, 1, 8, 1, 9, 1, 8, 1, 9, 1]) == 4\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0]) == 4\n assert candidate(nums = [7, 1, 5, 9, 2, 6, 5, 3, 5, 7]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 4\n assert candidate(nums = [0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8]) == 2\n assert candidate(nums = [7, 3, 1, 4, 6, 2, 9, 0, 5]) == 2\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 8\n assert candidate(nums = [7, 3, 5, 1, 9, 8, 7, 6, 4, 2, 0]) == 8\n assert candidate(nums = [7, 1, 3, 5, 2, 8, 6, 4, 9, 0, 7, 1, 3, 5, 2, 8, 6, 4, 9, 0]) == 7\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, 6, 9, 2, 5, 8, 1, 4, 7, 0]) == 8\n assert candidate(nums = [6, 2, 8, 4, 0, 1, 3, 5, 7, 9]) == 8\n assert candidate(nums = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(nums = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == 4\n assert candidate(nums = [3, 6, 9, 2, 5, 8, 1, 4, 7, 0, 3, 6, 9, 2, 5, 8, 1, 4, 7, 0]) == 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\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 0\n assert candidate(nums = [8, 1, 4, 1, 8, 1, 4, 1, 8, 1, 4]) == 4\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 6\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2, 4, 6, 8, 0]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [9, 2, 3, 4, 5, 6, 7, 8, 1, 0, 9, 2, 3, 4, 5, 6, 7, 8, 1, 0]) == 8\n assert candidate(nums = [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, 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, 6, 7, 9]) == 8\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 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]) == 0\n assert candidate(nums = [1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2]) == 2\n assert candidate(nums = [6, 2, 9, 5, 4, 8, 7, 1, 3, 6, 2, 9, 5, 4, 8, 7, 1, 3, 6, 2]) == 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]) == 4\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1]) == 6\n assert candidate(nums = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4]) == 4\n assert candidate(nums = [5, 3, 8, 9, 1, 4, 6, 7]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 1, 3, 5, 7, 9]) == 0\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 4\n assert candidate(nums = [8, 6, 4, 2, 0, 9, 7, 5, 3, 1, 8, 6, 4, 2, 0, 9, 7, 5, 3, 1]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 6\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9]) == 0\n assert candidate(nums = [7, 3, 5, 2, 8, 6, 4, 9, 1, 0, 7, 3, 5, 2, 8, 6, 4, 9, 1, 0]) == 5\n assert candidate(nums = [7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0]) == 8\n assert candidate(nums = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums = [6, 2, 8, 4, 0, 1, 5, 9, 3, 7]) == 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]) == 0\n assert candidate(nums = [2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 2]) == 8\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 6\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 5\n assert candidate(nums = [0, 9, 0, 9, 0, 9, 0, 9, 0, 9]) == 4\n assert candidate(nums = [1, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 0]) == 7\n assert candidate(nums = [7, 3, 1, 2, 5, 8, 6, 4, 9, 0]) == 5\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [7, 1, 9, 3, 7, 1, 9, 3, 7, 1, 9, 3, 7, 1, 9, 3, 7, 1, 9, 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]) == 8\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 4\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 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\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9]) == 0\n assert candidate(nums = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 4\n assert candidate(nums = [2, 7, 1, 8, 2, 8, 1, 8, 2, 8, 4, 5, 9, 0, 4, 5, 2, 3, 5, 3]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]", "[5]"], "hints": ["Try simulating the entire process.", "To reduce space, use a temporary array to update nums in every step instead of creating a new array at each step."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().triangularSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:27+00:00", "tests_total": 96, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "math", "simulation", "combinatorics", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function triangularSum($nums) {", "container": "Solution", "callable": "triangularSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2222, "task_id": "number-of-ways-to-select-buildings", "difficulty": "Medium", "problem_description": "You are given a 0-indexed binary string s which represents the types of buildings along a street where:\n\n- s[i] = '0' denotes that the i^th building is an office and\n- s[i] = '1' denotes that the i^th building is a restaurant.\n\nAs a city official, you would like to select 3 buildings for random inspection. However, to ensure variety, no two consecutive buildings out of the selected buildings can be of the same type.\n\n- For example, given s = \"001101\", we cannot select the 1^st, 3^rd, and 5^th buildings as that would form \"011\" which is not allowed due to having two consecutive buildings of the same type.\n\nReturn the number of valid ways to select 3 buildings.\n\nExample 1:\n\nInput: s = \"001101\"\nOutput: 6\nExplanation:\nThe following sets of indices selected are valid:\n- [0,2,4] from \"001101\" forms \"010\"\n- [0,3,4] from \"001101\" forms \"010\"\n- [1,2,4] from \"001101\" forms \"010\"\n- [1,3,4] from \"001101\" forms \"010\"\n- [2,4,5] from \"001101\" forms \"101\"\n- [3,4,5] from \"001101\" forms \"101\"\nNo other selection is valid. Thus, there are 6 total ways.\n\nExample 2:\n\nInput: s = \"11100\"\nOutput: 0\nExplanation: It can be shown that there are no valid selections.\n\nConstraints:\n\n- 3 <= 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 = \"100100100\") == 24\n assert candidate(s = \"101010101\") == 30\n assert candidate(s = \"000111000\") == 27\n assert candidate(s = \"111\") == 0\n assert candidate(s = \"0000000001\") == 0\n assert candidate(s = \"01010\") == 5\n assert candidate(s = \"010101010\") == 30\n assert candidate(s = \"1001001\") == 12\n assert candidate(s = \"011001100\") == 28\n assert candidate(s = \"101101101\") == 27\n assert candidate(s = \"10101\") == 5\n assert candidate(s = \"1111111110\") == 0\n assert candidate(s = \"1010101010101010101\") == 285\n assert candidate(s = \"001001001\") == 24\n assert candidate(s = \"001101\") == 6\n assert candidate(s = \"1001001001\") == 36\n assert candidate(s = \"11111\") == 0\n assert candidate(s = \"0011001100\") == 40\n assert candidate(s = \"000\") == 0\n assert candidate(s = \"010101\") == 8\n assert candidate(s = \"1100110011\") == 40\n assert candidate(s = \"101010\") == 8\n assert candidate(s = \"11100\") == 0\n assert candidate(s = \"0101010101\") == 40\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"0110110\") == 12\n assert candidate(s = \"110011001\") == 28\n assert candidate(s = \"010101001010101010\") == 240\n assert candidate(s = \"101010101010101010\") == 240\n assert candidate(s = \"000111000111000111000\") == 378\n assert candidate(s = \"101010101010101\") == 140\n assert candidate(s = \"010101010101010101010101010101010101\") == 1938\n assert candidate(s = \"111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"001001001001001001001001001001001001001001001001\") == 4080\n assert candidate(s = \"00000000000000000000000000000000\") == 0\n assert candidate(s = \"100001000010000100001\") == 240\n assert candidate(s = \"10101010101010101010101010\") == 728\n assert candidate(s = \"1010101010101010101010101010101\") == 1240\n assert candidate(s = \"111000111000111\") == 135\n assert candidate(s = \"110011001100110011001\") == 380\n assert candidate(s = \"000111000111000111\") == 216\n assert candidate(s = \"101010101010101010101010\") == 572\n assert candidate(s = \"010010100101001010010100101001\") == 1074\n assert candidate(s = \"101010101010101010101\") == 385\n assert candidate(s = \"1010101010\") == 40\n assert candidate(s = \"111111111100000000111111111\") == 720\n assert candidate(s = \"111111111111111111111\") == 0\n assert candidate(s = \"010101010101010101\") == 240\n assert candidate(s = \"010010010010010010\") == 216\n assert candidate(s = \"101010101010101010101010101\") == 819\n assert candidate(s = \"000000000000000000000000000\") == 0\n assert candidate(s = \"000111000111000111000111\") == 540\n assert candidate(s = \"101010101010101010101010101010\") == 1120\n assert candidate(s = \"110011001100\") == 64\n assert candidate(s = \"110011001100110011\") == 240\n assert candidate(s = \"111100001111000011110000\") == 512\n assert candidate(s = \"10011001100110011001\") == 330\n assert candidate(s = \"01001001001001\") == 100\n assert candidate(s = \"0101010101010101010101010101010\") == 1240\n assert candidate(s = \"100100100100100100\") == 210\n assert candidate(s = \"000000000000000000000\") == 0\n assert candidate(s = \"000111000111\") == 54\n assert candidate(s = \"0101010101010101010101010101010101\") == 1632\n assert candidate(s = \"000000000011111111000000000\") == 720\n assert candidate(s = \"010101010101010101010101010\") == 819\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010\") == 7308\n assert candidate(s = \"111111000000111111\") == 216\n assert candidate(s = \"111111111111111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"01010010100101001010\") == 320\n assert candidate(s = \"1111111000000111111000000\") == 468\n assert candidate(s = \"1001001001001001001001001001001001001001001001\") == 3600\n assert candidate(s = \"0100100101010010010100100\") == 614\n assert candidate(s = \"0000011111\") == 0\n assert candidate(s = \"11111111111111111111\") == 0\n assert candidate(s = \"1101010101010101010101010101010101\") == 1632\n assert candidate(s = \"00000001111111100000001111111110000000\") == 2170\n assert candidate(s = \"0011011011100101010101010\") == 633\n assert candidate(s = \"110011001100110\") == 136\n assert candidate(s = \"000001111110000011111\") == 300\n assert candidate(s = \"0110110110110110110110110110110110110110110110\") == 3600\n assert candidate(s = \"111111111111111111\") == 0\n assert candidate(s = \"1010101010101010101010101010101010\") == 1632\n assert candidate(s = \"10101010100000001010101010\") == 630\n assert candidate(s = \"000000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"00000000000011111111111\") == 0\n assert candidate(s = \"00000111110000011111\") == 250\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001001\") == 56316\n assert candidate(s = \"00110011001100110011001100\") == 728\n assert candidate(s = \"01010111100001110101\") == 320\n assert candidate(s = \"11001100110011001100\") == 320\n assert candidate(s = \"11100011100011100011\") == 324\n assert candidate(s = \"01010101010101010101010101010101\") == 1360\n assert candidate(s = \"1010101010101010101010101010\") == 910\n assert candidate(s = \"01110111011101110111\") == 240\n assert candidate(s = \"111000111000\") == 54\n assert candidate(s = \"10110110110110110110110110110110110\") == 1584\n assert candidate(s = \"111111000111111000\") == 162\n assert candidate(s = \"11111100000011111100000011111100000\") == 1620\n assert candidate(s = \"11110000111100001111000011110000\") == 1280\n assert candidate(s = \"010101010101\") == 70\n assert candidate(s = \"01010101010101010101010101010101010\") == 1785\n assert candidate(s = \"1100110011001100110011001\") == 644\n assert candidate(s = \"11111111111111111111111111111111\") == 0\n assert candidate(s = \"011001100110011001\") == 240\n assert candidate(s = \"1111111111100000000000\") == 0\n assert candidate(s = \"011011011011011011011011011\") == 720\n assert candidate(s = \"000111000111000111000111000111000\") == 1485\n assert candidate(s = \"101010101010010101\") == 240\n assert candidate(s = \"0101010101010101010101010101\") == 910\n assert candidate(s = \"01101001101001101001101001101001\") == 1360\n assert candidate(s = \"0110011001100110011001\") == 440\n assert candidate(s = \"111110000011111000001\") == 325\n assert candidate(s = \"01010101011111110101010101\") == 630\n assert candidate(s = \"000011110000111100001111\") == 512\n assert candidate(s = \"10001000100010001000\") == 240\n assert candidate(s = \"1001001001001001001001001001001001\") == 1452\n assert candidate(s = \"100010001000100010001000100010001000100010001000\") == 3432\n assert candidate(s = \"00001111000011110000111100001111\") == 1280\n assert candidate(s = \"1110001110001110001110001110001110\") == 1620\n assert candidate(s = \"000000000000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"00110011001100110011\") == 320\n assert candidate(s = \"11101110111\") == 39\n assert candidate(s = \"0000010000100001\") == 92\n assert candidate(s = \"1010101010101\") == 91\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"1111100000\") == 0\n assert candidate(s = \"0001100011000110001100011\") == 600\n assert candidate(s = \"1001001001001001001001001\") == 576\n assert candidate(s = \"00011110001111000111\") == 300\n assert candidate(s = \"001010010010100\") == 131\n assert candidate(s = \"000000000000000000\") == 0\n assert candidate(s = \"11010101010101010101\") == 330\n assert candidate(s = \"01010101010101\") == 112\n assert candidate(s = \"101010101010101010101010101010101010101010101010\") == 4600\n assert candidate(s = \"10100101001010010100101001010010\") == 1302\n assert candidate(s = \"110110110110110110110110110110110110110110110110\") == 4080\n assert candidate(s = \"010101010101010101010\") == 385\n assert candidate(s = \"1010101010101010101010\") == 440\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 2660\n assert candidate(s = \"1111100001111000011110000\") == 560\n assert candidate(s = \"0110110110110110110110110110110110\") == 1452\n assert candidate(s = \"01010101010101010101010101010101010101010101\") == 3542\n assert candidate(s = \"01101101101101101101101101101101101101101101\") == 3150\n assert candidate(s = \"00000011111100000011111100000011111\") == 1620\n assert candidate(s = \"01010101010101010101\") == 330\n assert candidate(s = \"11001100110011\") == 112\n assert candidate(s = \"000001111100000111\") == 200\n assert candidate(s = \"1001001001001001001001001001\") == 810\n assert candidate(s = \"00101010101010101010\") == 330\n assert candidate(s = \"01101101101101101101\") == 294\n assert candidate(s = \"10101010101010101010\") == 330\n assert candidate(s = \"111110000001111100000\") == 300\n assert candidate(s = \"111111111111111111111111111\") == 0\n assert candidate(s = \"1101010101\") == 40\n assert candidate(s = \"111000111000111000111000\") == 540\n assert candidate(s = \"01110111011101110111011101110111011101110111\") == 2640\n assert candidate(s = \"110110110110110110\") == 210\n assert candidate(s = \"0000000000011111111111\") == 0\n assert candidate(s = \"10101000011110101010\") == 322\n assert candidate(s = \"000111000111000\") == 135\n assert candidate(s = \"011110111101111011110\") == 240\n assert candidate(s = \"000111111000111110\") == 192\n", "comparison": "exact"}, "public_tests": ["\"001101\"", "\"11100\""], "hints": ["There are only 2 valid patterns: ‘101’ and ‘010’. Think about how we can construct these 2 patterns from smaller patterns.", "Count the number of subsequences of the form ‘01’ or ‘10’ first. Let n01[i] be the number of ‘01’ subsequences that exist in the prefix of s up to the ith building. How can you compute n01[i]?", "Let n0[i] and n1[i] be the number of ‘0’s and ‘1’s that exists in the prefix of s up to i respectively. Then n01[i] = n01[i – 1] if s[i] == ‘0’, otherwise n01[i] = n01[i – 1] + n0[i – 1].", "The same logic applies to building the n10 array and subsequently the n101 and n010 arrays for the number of ‘101’ and ‘010‘ subsequences."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:29+00:00", "tests_total": 162, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function numberOfWays($s) {", "container": "Solution", "callable": "numberOfWays", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2223, "task_id": "sum-of-scores-of-built-strings", "difficulty": "Hard", "problem_description": "You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled s_i.\n\n- For example, for s = \"abaca\", s_1 == \"a\", s_2 == \"ca\", s_3 == \"aca\", etc.\n\nThe score of s_i is the length of the longest common prefix between s_i and s_n (Note that s == s_n).\n\nGiven the final string s, return the sum of the score of every s_i.\n\nExample 1:\n\nInput: s = \"babab\"\nOutput: 9\nExplanation:\nFor s_1 == \"b\", the longest common prefix is \"b\" which has a score of 1.\nFor s_2 == \"ab\", there is no common prefix so the score is 0.\nFor s_3 == \"bab\", the longest common prefix is \"bab\" which has a score of 3.\nFor s_4 == \"abab\", there is no common prefix so the score is 0.\nFor s_5 == \"babab\", the longest common prefix is \"babab\" which has a score of 5.\nThe sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.\n\nExample 2:\n\nInput: s = \"azbazbzaz\"\nOutput: 14\nExplanation:\nFor s_2 == \"az\", the longest common prefix is \"az\" which has a score of 2.\nFor s_6 == \"azbzaz\", the longest common prefix is \"azb\" which has a score of 3.\nFor s_9 == \"azbazbzaz\", the longest common prefix is \"azbazbzaz\" which has a score of 9.\nFor all other s_i, the score is 0.\nThe sum of the scores is 2 + 3 + 9 = 14, so we return 14.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"xyzxyzxyz\") == 18\n assert candidate(s = \"abcabcabc\") == 18\n assert candidate(s = \"aabbcc\") == 7\n assert candidate(s = \"abacabadabacaba\") == 32\n assert candidate(s = \"zzzzz\") == 15\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abacaba\") == 12\n assert candidate(s = \"babab\") == 9\n assert candidate(s = \"azbazbzaz\") == 14\n assert candidate(s = \"abcde\") == 5\n assert candidate(s = \"zazazaz\") == 16\n assert candidate(s = \"aaaaa\") == 15\n assert candidate(s = \"aabbaabb\") == 14\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abcdefg\") == 7\n assert candidate(s = \"aabbccddeeff\") == 13\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\") == 65\n assert candidate(s = \"abacabadabacabadabacaba\") == 60\n assert candidate(s = \"abcdefgfedcbabcdefgfedcbabcdefgfedcbabcdefgfedcbabcdefgfedcb\") == 180\n assert candidate(s = \"xyxyxyxyxyxyxyxy\") == 72\n assert candidate(s = \"zxyzyxzyxzyxzyxzyxzyxzyx\") == 31\n assert candidate(s = \"aaaabbbbccccaaaabbbbcccc\") == 48\n assert candidate(s = \"mississippimississippimississippimississippi\") == 110\n assert candidate(s = \"aaaaaaaaaabaaaa\") == 70\n assert candidate(s = \"rotorrotor\") == 17\n assert candidate(s = \"abracadabra\") == 18\n assert candidate(s = \"abcabcabcabc\") == 30\n assert candidate(s = \"abcabcabcabcabcd\") == 46\n assert candidate(s = \"zzzzzzzzzzzzzzz\") == 120\n assert candidate(s = \"zzyyxxwwvvuuttssrrqqppoonnmmllkkiijjhhggffeeddccbbbaaa\") == 55\n assert candidate(s = \"aaaaaaaaaabaaaaaaaaab\") == 111\n assert candidate(s = \"abcabcabcabcabcabca\") == 70\n assert candidate(s = \"abcabcabcabca\") == 35\n assert candidate(s = \"abcdabcdabcd\") == 24\n assert candidate(s = \"abacabadabacabad\") == 34\n assert candidate(s = \"abababababababababababababababab\") == 272\n assert candidate(s = \"aaaaabbbbccccdddd\") == 27\n assert candidate(s = \"aaaaabbbbbccccdddd\") == 28\n assert candidate(s = \"aaaaabbbbb\") == 20\n assert candidate(s = \"aaaaabbbbccccddddeeeee\") == 32\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabc\") == 234\n assert candidate(s = \"abcdefedcbafedcbafedcba\") == 26\n assert candidate(s = \"mississippimississippi\") == 33\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabc\") == 273\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 630\n assert candidate(s = \"aabbaabbaabbaabb\") == 44\n assert candidate(s = \"bananaananabanana\") == 23\n assert candidate(s = \"abcabcabcabcabcabcab\") == 77\n assert candidate(s = \"abcabcabcabcabcabcabc\") == 84\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 612\n assert candidate(s = \"qwertyuiopqwertyuiop\") == 30\n assert candidate(s = \"aabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccdd\") == 145\n assert candidate(s = \"abcdefghjihgfedcba\") == 19\n assert candidate(s = \"acabacabacabacabacabacabacabacabacabacab\") == 230\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 165\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 360\n assert candidate(s = \"abcabcabcab\") == 26\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 408\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 26\n assert candidate(s = \"abcdefedcbafedcbafedcbafedcbafedcbafedcbafedcbafedcbafedcbafedcba\") == 75\n assert candidate(s = \"abcdeedcbaabcdeedcba\") == 32\n assert candidate(s = \"ababababababab\") == 56\n assert candidate(s = \"abcdeedcba\") == 11\n assert candidate(s = \"abababababababab\") == 72\n assert candidate(s = \"noon\") == 5\n assert candidate(s = \"abababababab\") == 42\n assert candidate(s = \"ababababababababab\") == 90\n assert candidate(s = \"abcabcabcabcabcabc\") == 63\n assert candidate(s = \"aabbccddeeffgghhii\") == 19\n assert candidate(s = \"abcdabcdabcdabcd\") == 40\n assert candidate(s = \"level\") == 6\n assert candidate(s = \"levellevellevel\") == 33\n assert candidate(s = \"abcdabcdabcdabcdabcd\") == 60\n assert candidate(s = \"abcdefghijk\") == 11\n assert candidate(s = \"aaaaaaaaaaa\") == 66\n assert candidate(s = \"qwertyuiopqwertyuiopqwertyuiopqwertyuiop\") == 100\n assert candidate(s = \"bananaananab\") == 13\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 210\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 666\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 315\n assert candidate(s = \"banana\") == 6\n assert candidate(s = \"zzyzxzyzxzyzxzyz\") == 24\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy\") == 272\n assert candidate(s = \"zxyzyxzyxzyxzyxzyx\") == 23\n assert candidate(s = \"abracadabraabracadabra\") == 47\n assert candidate(s = \"abcdedcbaabcdedcba\") == 29\n assert candidate(s = \"abcdefghij\") == 10\n assert candidate(s = \"abcdedcbafedcbafedcbafedcbafedcba\") == 38\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 53\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 21\n assert candidate(s = \"aabbccddeeffaabbccddeeff\") == 38\n assert candidate(s = \"aaaaaabbccddeeffgg\") == 33\n assert candidate(s = \"aaaaabbbbbaaaaa\") == 40\n assert candidate(s = \"racecarracecar\") == 23\n assert candidate(s = \"abacabadabacabadabacabad\") == 63\n assert candidate(s = \"deified\") == 8\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbb\") == 525\n assert candidate(s = \"aaaaaabbbbbccccc\") == 31\n assert candidate(s = \"aaaaaabbbbccccdddd\") == 33\n assert candidate(s = \"abcbaabcbaabcba\") == 33\n assert candidate(s = \"ababababcabababa\") == 44\n assert candidate(s = \"abcdabcdbabc\") == 19\n assert candidate(s = \"abababababababababababab\") == 156\n assert candidate(s = \"ababababab\") == 30\n assert candidate(s = \"abacabadabacabadabacab\") == 55\n assert candidate(s = \"civic\") == 6\n assert candidate(s = \"rotor\") == 6\n assert candidate(s = \"racecar\") == 8\n assert candidate(s = \"abcabcabcabcabcabcabcabcabc\") == 135\n assert candidate(s = \"abcdefghijabcdefghij\") == 30\n assert candidate(s = \"zazbzcbzazbzcb\") == 25\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 108\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\") == 46\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabc\") == 198\n assert candidate(s = \"abcabcabcabcabcab\") == 57\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 2211\n assert candidate(s = \"abcdefabcdeabcdeabc\") == 32\n assert candidate(s = \"mississippi\") == 11\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzz\") == 71\n assert candidate(s = \"hellohellohellohello\") == 50\n assert candidate(s = \"abcabcabcabcabc\") == 45\n assert candidate(s = \"xyzzzyxyzzzyxyzzzyxyzzzy\") == 60\n", "comparison": "exact"}, "public_tests": ["\"babab\"", "\"azbazbzaz\""], "hints": ["Each s_i is a suffix of the string s, so consider algorithms that can determine the longest prefix that is also a suffix.", "Could you use the Z array from the Z algorithm to find the score of each s_i?"], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().sumScores", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:32+00:00", "tests_total": 123, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "binary-search", "rolling-hash", "suffix-array", "string-matching", "hash-function", "z-algorithm", "knuth-morris-pratt-algorithm"]}, "language": "php", "interface": {"raw_signature": "function sumScores($s) {", "container": "Solution", "callable": "sumScores", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2224, "task_id": "minimum-number-of-operations-to-convert-time", "difficulty": "Easy", "problem_description": "You are given two strings current and correct representing two 24-hour times.\n\n24-hour times are formatted as \"HH:MM\", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.\n\nIn one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.\n\nReturn the minimum number of operations needed to convert current to correct.\n\nExample 1:\n\nInput: current = \"02:30\", correct = \"04:35\"\nOutput: 3\nExplanation:\nWe can convert current to correct in 3 operations as follows:\n- Add 60 minutes to current. current becomes \"03:30\".\n- Add 60 minutes to current. current becomes \"04:30\".\n- Add 5 minutes to current. current becomes \"04:35\".\nIt can be proven that it is not possible to convert current to correct in fewer than 3 operations.\n\nExample 2:\n\nInput: current = \"11:00\", correct = \"11:01\"\nOutput: 1\nExplanation: We only have to add one minute to current, so the minimum number of operations needed is 1.\n\nConstraints:\n\n- current and correct are in the format \"HH:MM\"\n- current <= correct\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(current = \"01:59\",correct = \"02:00\") == 1\n assert candidate(current = \"00:01\",correct = \"00:02\") == 1\n assert candidate(current = \"02:30\",correct = \"04:35\") == 3\n assert candidate(current = \"12:00\",correct = \"13:00\") == 1\n assert candidate(current = \"00:00\",correct = \"23:59\") == 32\n assert candidate(current = \"23:45\",correct = \"23:59\") == 6\n assert candidate(current = \"00:01\",correct = \"00:05\") == 4\n assert candidate(current = \"01:15\",correct = \"01:20\") == 1\n assert candidate(current = \"12:45\",correct = \"15:30\") == 5\n assert candidate(current = \"23:00\",correct = \"23:15\") == 1\n assert candidate(current = \"09:15\",correct = \"09:15\") == 0\n assert candidate(current = \"12:34\",correct = \"12:59\") == 3\n assert candidate(current = \"11:00\",correct = \"11:01\") == 1\n assert candidate(current = \"18:00\",correct = \"18:14\") == 6\n assert candidate(current = \"15:30\",correct = \"16:45\") == 2\n assert candidate(current = \"12:45\",correct = \"12:45\") == 0\n assert candidate(current = \"01:00\",correct = \"02:00\") == 1\n assert candidate(current = \"21:45\",correct = \"22:00\") == 1\n assert candidate(current = \"12:00\",correct = \"12:15\") == 1\n assert candidate(current = \"09:40\",correct = \"10:00\") == 2\n assert candidate(current = \"05:30\",correct = \"05:35\") == 1\n assert candidate(current = \"01:59\",correct = \"03:00\") == 2\n assert candidate(current = \"23:59\",correct = \"23:59\") == 0\n assert candidate(current = \"22:45\",correct = \"23:40\") == 5\n assert candidate(current = \"06:40\",correct = \"06:55\") == 1\n assert candidate(current = \"09:50\",correct = \"10:10\") == 2\n assert candidate(current = \"06:10\",correct = \"06:25\") == 1\n assert candidate(current = \"06:30\",correct = \"07:00\") == 2\n assert candidate(current = \"05:47\",correct = \"06:02\") == 1\n assert candidate(current = \"09:47\",correct = \"18:23\") == 12\n assert candidate(current = \"14:20\",correct = \"14:40\") == 2\n assert candidate(current = \"03:33\",correct = \"04:08\") == 3\n assert candidate(current = \"20:15\",correct = \"21:10\") == 5\n assert candidate(current = \"08:30\",correct = \"09:40\") == 3\n assert candidate(current = \"05:40\",correct = \"07:20\") == 5\n assert candidate(current = \"17:45\",correct = \"19:00\") == 2\n assert candidate(current = \"19:55\",correct = \"20:10\") == 1\n assert candidate(current = \"14:50\",correct = \"15:05\") == 1\n assert candidate(current = \"14:59\",correct = \"15:10\") == 3\n assert candidate(current = \"05:55\",correct = \"06:00\") == 1\n assert candidate(current = \"01:01\",correct = \"02:56\") == 6\n assert candidate(current = \"08:20\",correct = \"08:35\") == 1\n assert candidate(current = \"05:00\",correct = \"09:55\") == 9\n assert candidate(current = \"09:30\",correct = \"20:35\") == 12\n assert candidate(current = \"07:30\",correct = \"07:31\") == 1\n assert candidate(current = \"01:23\",correct = \"02:18\") == 5\n assert candidate(current = \"17:55\",correct = \"18:00\") == 1\n assert candidate(current = \"16:50\",correct = \"18:25\") == 4\n assert candidate(current = \"10:05\",correct = \"14:40\") == 7\n assert candidate(current = \"01:05\",correct = \"02:10\") == 2\n assert candidate(current = \"03:15\",correct = \"03:30\") == 1\n assert candidate(current = \"20:30\",correct = \"22:35\") == 3\n assert candidate(current = \"18:10\",correct = \"19:10\") == 1\n assert candidate(current = \"03:00\",correct = \"07:15\") == 5\n assert candidate(current = \"03:14\",correct = \"06:09\") == 7\n assert candidate(current = \"07:45\",correct = \"08:30\") == 3\n assert candidate(current = \"09:14\",correct = \"09:44\") == 2\n assert candidate(current = \"01:01\",correct = \"04:04\") == 6\n assert candidate(current = \"13:59\",correct = \"14:00\") == 1\n assert candidate(current = \"02:22\",correct = \"02:27\") == 1\n assert candidate(current = \"05:30\",correct = \"05:45\") == 1\n assert candidate(current = \"11:20\",correct = \"12:55\") == 4\n assert candidate(current = \"17:30\",correct = \"18:05\") == 3\n assert candidate(current = \"11:59\",correct = \"12:04\") == 1\n assert candidate(current = \"08:37\",correct = \"09:02\") == 3\n assert candidate(current = \"16:00\",correct = \"16:16\") == 2\n assert candidate(current = \"18:34\",correct = \"19:50\") == 3\n assert candidate(current = \"19:10\",correct = \"21:25\") == 3\n assert candidate(current = \"05:05\",correct = \"11:10\") == 7\n assert candidate(current = \"13:20\",correct = \"17:50\") == 6\n assert candidate(current = \"20:59\",correct = \"21:59\") == 1\n assert candidate(current = \"04:30\",correct = \"06:10\") == 5\n assert candidate(current = \"16:25\",correct = \"17:00\") == 3\n assert candidate(current = \"08:59\",correct = \"09:00\") == 1\n assert candidate(current = \"03:23\",correct = \"03:58\") == 3\n assert candidate(current = \"14:45\",correct = \"20:30\") == 8\n assert candidate(current = \"19:47\",correct = \"21:00\") == 6\n assert candidate(current = \"00:01\",correct = \"23:59\") == 31\n assert candidate(current = \"22:25\",correct = \"22:40\") == 1\n assert candidate(current = \"17:30\",correct = \"20:00\") == 4\n assert candidate(current = \"14:10\",correct = \"15:35\") == 4\n assert candidate(current = \"00:01\",correct = \"00:06\") == 1\n assert candidate(current = \"01:15\",correct = \"02:45\") == 3\n assert candidate(current = \"13:47\",correct = \"18:23\") == 8\n assert candidate(current = \"09:00\",correct = \"09:09\") == 5\n assert candidate(current = \"06:55\",correct = \"07:10\") == 1\n assert candidate(current = \"13:45\",correct = \"15:30\") == 4\n assert candidate(current = \"13:45\",correct = \"15:10\") == 4\n assert candidate(current = \"09:55\",correct = \"11:40\") == 4\n assert candidate(current = \"20:15\",correct = \"21:25\") == 3\n assert candidate(current = \"11:59\",correct = \"12:00\") == 1\n assert candidate(current = \"17:31\",correct = \"20:00\") == 9\n assert candidate(current = \"01:01\",correct = \"22:59\") == 29\n assert candidate(current = \"12:25\",correct = \"14:15\") == 5\n assert candidate(current = \"10:30\",correct = \"10:55\") == 3\n assert candidate(current = \"13:25\",correct = \"13:40\") == 1\n assert candidate(current = \"16:10\",correct = \"16:55\") == 3\n assert candidate(current = \"07:40\",correct = \"07:55\") == 1\n assert candidate(current = \"05:20\",correct = \"06:50\") == 3\n assert candidate(current = \"08:30\",correct = \"20:45\") == 13\n assert candidate(current = \"14:15\",correct = \"14:15\") == 0\n assert candidate(current = \"13:45\",correct = \"14:10\") == 3\n assert candidate(current = \"09:05\",correct = \"09:10\") == 1\n assert candidate(current = \"17:00\",correct = \"18:30\") == 3\n assert candidate(current = \"20:50\",correct = \"21:50\") == 1\n assert candidate(current = \"12:45\",correct = \"13:30\") == 3\n assert candidate(current = \"18:44\",correct = \"19:59\") == 2\n assert candidate(current = \"05:20\",correct = \"05:25\") == 1\n assert candidate(current = \"05:45\",correct = \"10:30\") == 7\n assert candidate(current = \"03:00\",correct = \"04:59\") == 10\n assert candidate(current = \"10:10\",correct = \"11:55\") == 4\n assert candidate(current = \"04:59\",correct = \"05:00\") == 1\n assert candidate(current = \"01:45\",correct = \"02:00\") == 1\n assert candidate(current = \"00:59\",correct = \"01:00\") == 1\n assert candidate(current = \"13:12\",correct = \"13:57\") == 3\n assert candidate(current = \"19:50\",correct = \"21:00\") == 3\n assert candidate(current = \"10:10\",correct = \"10:55\") == 3\n assert candidate(current = \"09:01\",correct = \"09:16\") == 1\n assert candidate(current = \"22:15\",correct = \"23:00\") == 3\n assert candidate(current = \"17:00\",correct = \"19:45\") == 5\n assert candidate(current = \"06:30\",correct = \"08:45\") == 3\n assert candidate(current = \"22:00\",correct = \"23:00\") == 1\n assert candidate(current = \"14:45\",correct = \"15:05\") == 2\n assert candidate(current = \"04:55\",correct = \"05:00\") == 1\n assert candidate(current = \"10:05\",correct = \"10:10\") == 1\n assert candidate(current = \"13:47\",correct = \"15:12\") == 4\n assert candidate(current = \"09:45\",correct = \"11:20\") == 4\n assert candidate(current = \"17:40\",correct = \"18:20\") == 4\n assert candidate(current = \"22:15\",correct = \"22:50\") == 3\n assert candidate(current = \"08:00\",correct = \"08:05\") == 1\n assert candidate(current = \"14:05\",correct = \"14:14\") == 5\n assert candidate(current = \"00:05\",correct = \"01:05\") == 1\n assert candidate(current = \"01:23\",correct = \"05:47\") == 10\n assert candidate(current = \"22:15\",correct = \"23:45\") == 3\n assert candidate(current = \"20:30\",correct = \"22:45\") == 3\n", "comparison": "exact"}, "public_tests": ["\"02:30\"\n\"04:35\"", "\"11:00\"\n\"11:01\""], "hints": ["Convert the times to minutes.", "Use the operation with the biggest value possible at each step."], "metadata": {"canonical_parameter_names": ["current", "correct"], "leetcode_dataset_entry_point": "Solution().convertTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:34+00:00", "tests_total": 138, "tests_dropped": 3, "flags": [], "topic_tags": ["string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function convertTime($current, $correct) {", "container": "Solution", "callable": "convertTime", "parameters": [{"name": "current", "type": "String"}, {"name": "correct", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2225, "task_id": "find-players-with-zero-or-one-losses", "difficulty": "Medium", "problem_description": "You are given an integer array matches where matches[i] = [winner_i, loser_i] indicates that the player winner_i defeated player loser_i in a match.\n\nReturn a list answer of size 2 where:\n\n- answer[0] is a list of all players that have not lost any matches.\n- answer[1] is a list of all players that have lost exactly one match.\n\nThe values in the two lists should be returned in increasing order.\n\nNote:\n\n- You should only consider the players that have played at least one match.\n- The testcases will be generated such that no two matches will have the same outcome.\n\nExample 1:\n\nInput: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]\nOutput: [[1,2,10],[4,5,7,8]]\nExplanation:\nPlayers 1, 2, and 10 have not lost any matches.\nPlayers 4, 5, 7, and 8 each have lost one match.\nPlayers 3, 6, and 9 each have lost two matches.\nThus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].\n\nExample 2:\n\nInput: matches = [[2,3],[1,3],[5,4],[6,4]]\nOutput: [[1,2,5,6],[]]\nExplanation:\nPlayers 1, 2, 5, and 6 have not lost any matches.\nPlayers 3 and 4 each have lost two matches.\nThus, answer[0] = [1,2,5,6] and answer[1] = [].\n\nConstraints:\n\n- 1 <= matches.length <= 10^5\n- matches[i].length == 2\n- 1 <= winner_i, loser_i <= 10^5\n- winner_i != loser_i\n- All matches[i] are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matches = [[1, 2]]) == [[1], [2]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == [[], [1, 2, 3, 4, 5]]\n assert candidate(matches = [[100, 200], [200, 300], [100, 300], [400, 500]]) == [[100, 400], [200, 500]]\n assert candidate(matches = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5]]) == [[1], [2, 3, 5]]\n assert candidate(matches = [[5, 3], [5, 4], [4, 5], [3, 4]]) == [[], [3, 5]]\n assert candidate(matches = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600]]) == [[100], [200, 300, 400, 500, 600]]\n assert candidate(matches = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]\n assert candidate(matches = [[1, 3], [2, 3], [3, 6], [5, 6], [5, 7], [4, 5], [4, 8], [4, 9], [10, 4], [10, 9]]) == [[1, 2, 10], [4, 5, 7, 8]]\n assert candidate(matches = [[100, 200], [200, 300], [100, 300]]) == [[100], [200]]\n assert candidate(matches = [[100000, 1], [99999, 2], [99998, 3], [99997, 4], [99996, 5]]) == [[99996, 99997, 99998, 99999, 100000], [1, 2, 3, 4, 5]]\n assert candidate(matches = [[2, 3], [1, 3], [5, 4], [6, 4]]) == [[1, 2, 5, 6], []]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [[1], [2, 3, 4, 5]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 3], [3, 5], [5, 7], [7, 9], [2, 4], [4, 6], [6, 8], [8, 10]]) == [[], [1, 2]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [2, 4], [3, 5], [4, 1], [5, 2], [6, 7], [7, 8], [8, 9], [9, 6], [7, 9], [8, 6], [9, 7]]) == [[], [8]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [4, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7]]) == [[1], [2]]\n assert candidate(matches = [[10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 10], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 21]]) == [[], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]]\n assert candidate(matches = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [100, 300], [300, 500], [500, 700], [700, 900], [100, 400], [400, 600], [600, 800], [800, 1000], [100, 500], [500, 900], [100, 600], [600, 1000], [100, 700], [100, 800], [100, 900], [100, 1000]]) == [[100], [200]]\n assert candidate(matches = [[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]]) == [[1], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8], [10, 11], [11, 10], [12, 13], [13, 12], [14, 15], [15, 14], [16, 17], [17, 16], [18, 19], [19, 18], [20, 21], [21, 20]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]]\n assert candidate(matches = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 2], [10, 1]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9], [11, 12], [12, 11]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]\n assert candidate(matches = [[1, 3], [2, 3], [3, 6], [5, 6], [5, 7], [4, 5], [4, 8], [4, 9], [10, 4], [10, 9], [11, 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, 30], [29, 31], [30, 32], [31, 33], [32, 34], [33, 35], [34, 36], [35, 37], [36, 38], [37, 39], [38, 40], [39, 41], [40, 42], [41, 43], [42, 44], [43, 45], [44, 46], [45, 47], [46, 48], [47, 49], [48, 50], [49, 51], [50, 52], [51, 53], [52, 54], [53, 55], [54, 56], [55, 57], [56, 58], [57, 59], [58, 60], [59, 61], [60, 62], [61, 63], [62, 64], [63, 65], [64, 66], [65, 67], [66, 68], [67, 69], [68, 70], [69, 71], [70, 72], [71, 73], [72, 74], [73, 75], [74, 76], [75, 77], [76, 78], [77, 79], [78, 80], [79, 81], [80, 82], [81, 83], [82, 84], [83, 85], [84, 86], [85, 87], [86, 88], [87, 89], [88, 90], [89, 91], [90, 92], [91, 93], [92, 94], [93, 95], [94, 96], [95, 97], [96, 98], [97, 99], [98, 100], [99, 101], [100, 102], [101, 103], [102, 104], [103, 105], [104, 106], [105, 107], [106, 108], [107, 109], [108, 110], [109, 111], [110, 112], [111, 113], [112, 114], [113, 115], [114, 116], [115, 117], [116, 118], [117, 119], [118, 120], [119, 121], [120, 122], [121, 123], [122, 124], [123, 125], [124, 126], [125, 127], [126, 128], [127, 129], [128, 130], [129, 131], [130, 132], [131, 133], [132, 134], [133, 135], [134, 136], [135, 137], [136, 138], [137, 139], [138, 140], [139, 141], [140, 142], [141, 143], [142, 144], [143, 145], [144, 146], [145, 147], [146, 148], [147, 149], [148, 150], [149, 151], [150, 152], [151, 153], [152, 154], [153, 155], [154, 156], [155, 157], [156, 158], [157, 159], [158, 160], [159, 161], [160, 162], [161, 163], [162, 164], [163, 165], [164, 166], [165, 167], [166, 168], [167, 169], [168, 170], [169, 171], [170, 172], [171, 173], [172, 174], [173, 175], [174, 176], [175, 177], [176, 178], [177, 179], [178, 180], [179, 181], [180, 182], [181, 183], [182, 184], [183, 185], [184, 186], [185, 187], [186, 188], [187, 189], [188, 190], [189, 191], [190, 192], [191, 193], [192, 194], [193, 195], [194, 196], [195, 197], [196, 198], [197, 199], [198, 200], [199, 201], [200, 202]]) == [[1, 2, 10, 11], [4, 5, 7, 8, 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, 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, 201, 202]]\n assert candidate(matches = [[1, 10], [2, 10], [3, 11], [4, 11], [5, 12], [6, 12], [7, 13], [8, 13], [9, 14], [10, 15], [11, 15], [12, 16], [13, 16], [14, 17], [15, 18], [16, 18], [17, 19], [18, 20], [19, 20]]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9], [14, 17, 19]]\n assert candidate(matches = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12], [11, 1], [12, 2], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == [[], [1, 2, 3, 4, 5, 6]]\n assert candidate(matches = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 1], [10, 2]]) == [[], []]\n assert candidate(matches = [[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], [17, 18], [18, 17], [19, 20], [20, 19]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]\n assert candidate(matches = [[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, 21], [20, 1]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]]\n assert candidate(matches = [[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], [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]]) == [[], [2]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5]]) == [[1], [2, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 3], [3, 5], [5, 7], [7, 9], [9, 1], [2, 4], [4, 6], [6, 8], [8, 10], [10, 2]]) == [[], []]\n assert candidate(matches = [[1, 10], [2, 10], [3, 11], [4, 11], [5, 12], [6, 12], [7, 13], [8, 13], [9, 14], [1, 15], [2, 15], [3, 16], [4, 16], [5, 17], [6, 17], [7, 18], [8, 18], [9, 19]]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9], [14, 19]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10]]) == [[1], [2]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 3], [3, 5], [2, 4], [4, 1], [5, 3]]) == [[], [2]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 11], [7, 12], [8, 12], [9, 13], [10, 13], [11, 14], [12, 14], [13, 15], [14, 15], [1, 16], [2, 16], [3, 17], [4, 17], [5, 18], [6, 18], [7, 19], [8, 19], [9, 20], [10, 20], [11, 21], [12, 21], [13, 22], [14, 22], [15, 23], [16, 23], [17, 24], [18, 24], [19, 25], [20, 25], [21, 26], [22, 26], [23, 27], [24, 27], [25, 28], [26, 28], [27, 29], [28, 29]]) == [[1], [2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [1, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [2, 6], [3, 7], [4, 8], [5, 9]]) == [[], [2, 3, 4, 5, 10]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1], [2, 3], [3, 2], [2, 4], [4, 2], [2, 5], [5, 2], [2, 6], [6, 2], [2, 7], [7, 2], [2, 8], [8, 2], [2, 9], [9, 2], [2, 10], [10, 2]]) == [[], []]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [4, 1], [4, 2], [4, 3], [5, 6], [6, 7], [7, 5], [7, 8], [8, 6], [8, 9], [9, 7], [9, 10], [10, 8]]) == [[], [1, 5, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 9]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [1000, 1100], [1100, 1200], [1200, 1300], [1300, 1400], [1400, 1500], [1500, 1600], [1600, 1700], [1700, 1800], [1800, 1900], [1900, 2000], [2000, 2100]]) == [[100], [200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100]]\n assert candidate(matches = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 10], [9, 10]]) == [[1], [2, 3]]\n assert candidate(matches = [[5, 1], [2, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 2], [9, 3], [10, 4]]) == [[], [1, 2, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5], [7, 6], [8, 7], [9, 8], [10, 9], [1, 10]]) == [[], []]\n assert candidate(matches = [[1, 4], [1, 5], [2, 4], [2, 6], [3, 5], [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]]) == [[1, 2, 3], [6, 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]]\n assert candidate(matches = [[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], [17, 18], [18, 17], [19, 20], [20, 19], [1, 11], [11, 1], [2, 12], [12, 2], [3, 13], [13, 3], [4, 14], [14, 4], [5, 15], [15, 5], [6, 16], [16, 6], [7, 17], [17, 7], [8, 18], [18, 8], [9, 19], [19, 9], [10, 20], [20, 10]]) == [[], []]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [7, 8], [8, 9], [9, 10], [10, 7]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [[1], [2, 5, 6, 7, 8]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13], [16, 17], [17, 18], [18, 19], [19, 16], [20, 21], [21, 22], [22, 20], [23, 24], [24, 25], [25, 23], [26, 27], [27, 28], [28, 29], [29, 26]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]]\n assert candidate(matches = [[1, 10], [2, 10], [3, 10], [4, 11], [5, 11], [6, 12], [7, 12], [8, 13], [9, 13], [10, 14], [11, 14], [12, 15], [13, 15], [14, 16], [15, 16]]) == [[1, 2, 3, 4, 5, 6, 7, 8, 9], []]\n assert candidate(matches = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 1]]) == [[], [1, 10, 20, 30, 40, 50, 60, 70, 80, 90]]\n assert candidate(matches = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [[1], [2, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 10]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]\n assert candidate(matches = [[10, 11], [12, 13], [11, 12], [13, 10], [14, 15], [16, 17], [15, 16], [17, 14], [18, 19], [19, 20]]) == [[18], [10, 11, 12, 13, 14, 15, 16, 17, 19, 20]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 10], [10, 2], [2, 11], [11, 3], [3, 12], [12, 4], [4, 13], [13, 5], [5, 14], [14, 6], [6, 15], [15, 7], [7, 16], [16, 8], [8, 17], [17, 9], [9, 18], [18, 10], [10, 19], [19, 1]]) == [[], [11, 12, 13, 14, 15, 16, 17, 18, 19]]\n assert candidate(matches = [[10, 1], [11, 10], [12, 11], [13, 12], [14, 13], [15, 14], [1, 15]]) == [[], [1, 10, 11, 12, 13, 14, 15]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 1], [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, 20], [20, 21], [21, 19], [22, 23], [23, 24], [24, 22], [25, 26], [26, 27], [27, 25], [28, 29], [29, 30], [30, 28]]) == [[], [1, 2, 3, 4, 5, 6, 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(matches = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]\n assert candidate(matches = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [1, 3], [2, 4], [5, 7], [6, 8], [9, 11], [10, 12], [13, 15], [14, 16], [17, 19], [18, 20]]) == [[1, 5, 9, 13, 17], [2, 3, 6, 7, 10, 11, 14, 15, 18, 19]]\n assert candidate(matches = [[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, 21], [20, 22]]) == [[1, 2], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]]\n assert candidate(matches = [[1, 2], [2, 3], [3, 1], [1, 4], [4, 5], [5, 6], [6, 4], [4, 7], [7, 8], [8, 9], [9, 10], [10, 7]]) == [[], [1, 2, 3, 5, 6, 8, 9, 10]]\n assert candidate(matches = [[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], [17, 18], [18, 17], [19, 20], [20, 19], [21, 22], [22, 21], [23, 24], [24, 23], [25, 26], [26, 25], [27, 28], [28, 27], [29, 30], [30, 29], [31, 32], [32, 31], [33, 34], [34, 33], [35, 36], [36, 35], [37, 38], [38, 37], [39, 40], [40, 39]]) == [[], [1, 2, 3, 4, 5, 6, 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(matches = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [11, 20], [12, 21], [13, 22], [14, 23], [15, 24], [16, 25], [17, 26], [18, 27], [19, 28], [20, 29], [21, 30], [22, 31], [23, 32], [24, 33], [25, 34], [26, 35], [27, 36], [28, 37], [29, 38], [30, 39], [31, 40], [32, 1], [33, 2], [34, 3], [35, 4], [36, 5], [37, 6], [38, 7], [39, 8], [40, 9]]) == [[], [1, 2, 3, 4, 5, 6, 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(matches = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [2, 3], [4, 5], [6, 7], [8, 9], [10, 1]]) == [[], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n assert candidate(matches = [[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, 22], [8, 23], [8, 24], [8, 25], [9, 26], [9, 27], [9, 28], [10, 29], [10, 30], [10, 31]]) == [[1], [2, 3, 4, 5, 6, 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", "comparison": "exact"}, "public_tests": ["[[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]", "[[2,3],[1,3],[5,4],[6,4]]"], "hints": ["Count the number of times a player loses while iterating through the matches."], "metadata": {"canonical_parameter_names": ["matches"], "leetcode_dataset_entry_point": "Solution().findWinners", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:36+00:00", "tests_total": 69, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function findWinners($matches) {", "container": "Solution", "callable": "findWinners", "parameters": [{"name": "matches", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2226, "task_id": "maximum-candies-allocated-to-k-children", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.\n\nYou are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can be allocated candies from only one pile of candies and some piles of candies may go unused.\n\nReturn the maximum number of candies each child can get.\n\nExample 1:\n\nInput: candies = [5,8,6], k = 3\nOutput: 5\nExplanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.\n\nExample 2:\n\nInput: candies = [2,5], k = 11\nOutput: 0\nExplanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0.\n\nConstraints:\n\n- 1 <= candies.length <= 10^5\n- 1 <= candies[i] <= 10^7\n- 1 <= k <= 10^12\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(candies = [10000000, 10000000, 10000000],k = 10000000) == 2\n assert candidate(candies = [7, 14, 10, 7],k = 3) == 7\n assert candidate(candies = [5, 8, 6],k = 3) == 5\n assert candidate(candies = [3, 9, 7],k = 6) == 3\n assert candidate(candies = [10, 20, 30, 40, 50],k = 15) == 10\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(candies = [7, 10, 10, 10],k = 4) == 7\n assert candidate(candies = [10000000],k = 1) == 10000000\n assert candidate(candies = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 5) == 7\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 6\n assert candidate(candies = [10, 20, 30, 40, 50],k = 3) == 30\n assert candidate(candies = [10, 20, 30, 40, 50],k = 30) == 5\n assert candidate(candies = [10000000, 10000000, 10000000],k = 3) == 10000000\n assert candidate(candies = [1000000],k = 1) == 1000000\n assert candidate(candies = [2, 5],k = 11) == 0\n assert candidate(candies = [7, 7, 7, 7, 7],k = 5) == 7\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(candies = [1, 2, 3, 4, 5],k = 15) == 1\n assert candidate(candies = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],k = 300000) == 1\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 500000) == 40\n assert candidate(candies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 60\n assert candidate(candies = [10000000, 5000000, 2500000, 1250000, 625000],k = 1000000) == 19\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 1\n assert candidate(candies = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 1\n assert candidate(candies = [10000000],k = 10000001) == 0\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 1000000000) == 0\n assert candidate(candies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000000000) == 0\n assert candidate(candies = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000],k = 45000000) == 1\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000],k = 1000000) == 50\n assert candidate(candies = [1000000, 999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111],k = 1000000) == 5\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000],k = 5000000) == 10\n assert candidate(candies = [9999999, 9999999, 9999999, 9999999, 9999999],k = 1) == 9999999\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 10) == 1000000\n assert candidate(candies = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 100) == 10\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 5000000) == 2\n assert candidate(candies = [5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000],k = 10) == 5000000\n assert candidate(candies = [1234567, 8901234, 5678901, 2345678, 9012345],k = 10000000) == 2\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1000000) == 0\n assert candidate(candies = [5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000],k = 5) == 5000000\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000],k = 1000000000000) == 0\n assert candidate(candies = [9999999, 9999999, 9999999, 9999999, 9999999],k = 49999995) == 1\n assert candidate(candies = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10) == 9\n assert candidate(candies = [5000000, 5000000, 5000000, 5000000, 5000000],k = 10000000) == 2\n assert candidate(candies = [10000000, 10000000, 10000000],k = 1000000) == 29\n assert candidate(candies = [10000000, 10000000, 10000000],k = 3000000) == 10\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 0\n assert candidate(candies = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50) == 100\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 1\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 7\n assert candidate(candies = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 100) == 3\n assert candidate(candies = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 15000) == 1\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1\n assert candidate(candies = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 10) == 400\n assert candidate(candies = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 25) == 10\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 3\n assert candidate(candies = [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(candies = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20) == 13\n assert candidate(candies = [10000000, 1000000, 100000, 10000, 1000, 100, 10, 1],k = 10000000) == 1\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 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(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 45) == 1\n assert candidate(candies = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1000000000) == 0\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000],k = 4) == 1000000\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000],k = 10000000) == 10\n assert candidate(candies = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 55) == 10\n assert candidate(candies = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250],k = 1000000) == 19\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000],k = 50000000) == 2\n assert candidate(candies = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],k = 100) == 4\n assert candidate(candies = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 25) == 600\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 55) == 1\n assert candidate(candies = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 35) == 1\n assert candidate(candies = [9999999, 9999998, 9999997, 9999996, 9999995],k = 1000000000000) == 0\n assert candidate(candies = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 20) == 5\n assert candidate(candies = [10000, 20000, 30000, 40000, 50000],k = 150000) == 1\n assert candidate(candies = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1024) == 1\n assert candidate(candies = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000],k = 500000000) == 0\n assert candidate(candies = [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(candies = [1000000, 1000000, 1000000, 1000000, 1000000],k = 250000) == 20\n assert candidate(candies = [10000000, 10000000, 10000000, 10000000, 10000000],k = 5) == 10000000\n assert candidate(candies = [5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000],k = 5000000) == 10\n assert candidate(candies = [10000000, 5000000, 3000000, 2000000, 1000000],k = 1000000) == 20\n", "comparison": "exact"}, "public_tests": ["[5,8,6]\n3", "[2,5]\n11"], "hints": ["For a fixed number of candies c, how can you check if each child can get c candies?", "Use binary search to find the maximum c as the answer."], "metadata": {"canonical_parameter_names": ["candies", "k"], "leetcode_dataset_entry_point": "Solution().maximumCandies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:39+00:00", "tests_total": 82, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "binary-search"]}, "language": "php", "interface": {"raw_signature": "function maximumCandies($candies, $k) {", "container": "Solution", "callable": "maximumCandies", "parameters": [{"name": "candies", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2231, "task_id": "largest-number-after-digit-swaps-by-parity", "difficulty": "Easy", "problem_description": "You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).\n\nReturn the largest possible value of num after any number of swaps.\n\nExample 1:\n\nInput: num = 1234\nOutput: 3412\nExplanation: Swap the digit 3 with the digit 1, this results in the number 3214.\nSwap the digit 2 with the digit 4, this results in the number 3412.\nNote that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.\nAlso note that we may not swap the digit 4 with the digit 1 since they are of different parities.\n\nExample 2:\n\nInput: num = 65875\nOutput: 87655\nExplanation: Swap the digit 8 with the digit 6, this results in the number 85675.\nSwap the first digit 5 with the digit 7, this results in the number 87655.\nNote that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.\n\nConstraints:\n\n- 1 <= num <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 24680) == 86420\n assert candidate(num = 987654321) == 987654321\n assert candidate(num = 13524687) == 75386421\n assert candidate(num = 1000000) == 1000000\n assert candidate(num = 2222) == 2222\n assert candidate(num = 222222) == 222222\n assert candidate(num = 111111) == 111111\n assert candidate(num = 1111) == 1111\n assert candidate(num = 975318642) == 975318642\n assert candidate(num = 13579) == 97531\n assert candidate(num = 2468) == 8642\n assert candidate(num = 135246) == 531642\n assert candidate(num = 111) == 111\n assert candidate(num = 1234) == 3412\n assert candidate(num = 65875) == 87655\n assert candidate(num = 198765432) == 978563412\n assert candidate(num = 1000000000) == 1000000000\n assert candidate(num = 123456789) == 987654321\n assert candidate(num = 973518642) == 975318642\n assert candidate(num = 973159731) == 997753311\n", "comparison": "exact"}, "public_tests": ["1234", "65875"], "hints": ["The bigger digit should appear first (more to the left) because it contributes more to the value of the number.", "Get all the even digits, as well as odd digits. Sort them separately.", "Reconstruct the number by giving the earlier digits the highest available digit of the same parity."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().largestInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:43+00:00", "tests_total": 78, "tests_dropped": 58, "flags": [], "topic_tags": ["sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function largestInteger($num) {", "container": "Solution", "callable": "largestInteger", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2232, "task_id": "minimize-result-by-adding-parentheses-to-expression", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string expression of the form \" + \" where and represent positive integers.\n\nAdd a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'.\n\nReturn expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them.\n\nThe input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.\n\nExample 1:\n\nInput: expression = \"247+38\"\nOutput: \"2(47+38)\"\nExplanation: The expression evaluates to 2 * (47 + 38) = 2 * 85 = 170.\nNote that \"2(4)7+38\" is invalid because the right parenthesis must be to the right of the '+'.\nIt can be shown that 170 is the smallest possible value.\n\nExample 2:\n\nInput: expression = \"12+34\"\nOutput: \"1(2+3)4\"\nExplanation: The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.\n\nExample 3:\n\nInput: expression = \"999+999\"\nOutput: \"(999+999)\"\nExplanation: The expression evaluates to 999 + 999 = 1998.\n\nConstraints:\n\n- 3 <= expression.length <= 10\n- expression consists of digits from '1' to '9' and '+'.\n- expression starts and ends with digits.\n- expression contains exactly one '+'.\n- The original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(expression = \"56+78\") == \"(56+78)\"\n assert candidate(expression = \"5+6\") == \"(5+6)\"\n assert candidate(expression = \"3+8\") == \"(3+8)\"\n assert candidate(expression = \"111+222\") == \"1(11+22)2\"\n assert candidate(expression = \"3+2\") == \"(3+2)\"\n assert candidate(expression = \"5+678\") == \"(5+67)8\"\n assert candidate(expression = \"247+38\") == \"2(47+38)\"\n assert candidate(expression = \"3+12\") == \"(3+1)2\"\n assert candidate(expression = \"11+11\") == \"1(1+1)1\"\n assert candidate(expression = \"8+9\") == \"(8+9)\"\n assert candidate(expression = \"1+2\") == \"(1+2)\"\n assert candidate(expression = \"123+456\") == \"1(23+45)6\"\n assert candidate(expression = \"9+9\") == \"(9+9)\"\n assert candidate(expression = \"12+34\") == \"1(2+3)4\"\n assert candidate(expression = \"88+11\") == \"8(8+1)1\"\n assert candidate(expression = \"999+999\") == \"(999+999)\"\n assert candidate(expression = \"1+9\") == \"(1+9)\"\n assert candidate(expression = \"333+444\") == \"(333+444)\"\n assert candidate(expression = \"555+666\") == \"(555+666)\"\n assert candidate(expression = \"9+99\") == \"(9+99)\"\n assert candidate(expression = \"9+1\") == \"(9+1)\"\n assert candidate(expression = \"5+9\") == \"(5+9)\"\n assert candidate(expression = \"1+1\") == \"(1+1)\"\n assert candidate(expression = \"12+3\") == \"1(2+3)\"\n assert candidate(expression = \"555+555\") == \"(555+555)\"\n assert candidate(expression = \"123+4\") == \"1(23+4)\"\n assert candidate(expression = \"9+876\") == \"(9+87)6\"\n assert candidate(expression = \"12345+6789\") == \"1(2345+6789)\"\n assert candidate(expression = \"56+789\") == \"(56+789)\"\n assert candidate(expression = \"1111+2222\") == \"1(111+222)2\"\n assert candidate(expression = \"123+4567\") == \"1(23+456)7\"\n assert candidate(expression = \"6666+7777\") == \"(6666+7777)\"\n assert candidate(expression = \"9999+1\") == \"9(999+1)\"\n assert candidate(expression = \"12+345\") == \"1(2+34)5\"\n assert candidate(expression = \"567+89\") == \"(567+89)\"\n assert candidate(expression = \"8+7654\") == \"(8+765)4\"\n assert candidate(expression = \"987+654\") == \"(987+654)\"\n assert candidate(expression = \"33+44\") == \"(33+44)\"\n assert candidate(expression = \"1234+56789\") == \"1(234+5678)9\"\n assert candidate(expression = \"99+11\") == \"9(9+1)1\"\n assert candidate(expression = \"333+666\") == \"(333+666)\"\n assert candidate(expression = \"345+678\") == \"(345+678)\"\n assert candidate(expression = \"123+45\") == \"1(23+45)\"\n assert candidate(expression = \"5+55\") == \"(5+5)5\"\n assert candidate(expression = \"678+9\") == \"6(78+9)\"\n assert candidate(expression = \"12+345678\") == \"1(2+34)5678\"\n assert candidate(expression = \"12+3456789\") == \"1(2+34)56789\"\n assert candidate(expression = \"99+88\") == \"(99+88)\"\n assert candidate(expression = \"9+1234\") == \"(9+123)4\"\n assert candidate(expression = \"1234+56\") == \"1(234+56)\"\n assert candidate(expression = \"44+555\") == \"(44+55)5\"\n assert candidate(expression = \"9+87654321\") == \"(9+8765432)1\"\n assert candidate(expression = \"2222+3333\") == \"2(222+333)3\"\n assert candidate(expression = \"1+999\") == \"(1+99)9\"\n assert candidate(expression = \"9876+5432\") == \"(9876+5432)\"\n assert candidate(expression = \"4321+9\") == \"43(21+9)\"\n assert candidate(expression = \"5432+1\") == \"543(2+1)\"\n assert candidate(expression = \"1+9999\") == \"(1+999)9\"\n assert candidate(expression = \"3456+789\") == \"3(456+789)\"\n assert candidate(expression = \"5555+666\") == \"5(555+666)\"\n assert candidate(expression = \"123+6\") == \"1(23+6)\"\n assert candidate(expression = \"8888+9999\") == \"(8888+9999)\"\n assert candidate(expression = \"213+456\") == \"(213+456)\"\n assert candidate(expression = \"23+4567\") == \"(23+456)7\"\n assert candidate(expression = \"9+8765432\") == \"(9+876543)2\"\n assert candidate(expression = \"111+111\") == \"1(11+11)1\"\n assert candidate(expression = \"99+1\") == \"9(9+1)\"\n assert candidate(expression = \"3+9999\") == \"(3+999)9\"\n assert candidate(expression = \"234+567\") == \"(234+567)\"\n assert candidate(expression = \"2+9999\") == \"(2+999)9\"\n assert candidate(expression = \"4321+876\") == \"4(321+876)\"\n assert candidate(expression = \"11+111\") == \"1(1+11)1\"\n assert candidate(expression = \"5+6789\") == \"(5+678)9\"\n assert candidate(expression = \"1+23456\") == \"(1+2)3456\"\n assert candidate(expression = \"999+1\") == \"9(99+1)\"\n assert candidate(expression = \"4444+5555\") == \"(4444+5555)\"\n assert candidate(expression = \"55+55\") == \"(55+55)\"\n assert candidate(expression = \"777+888\") == \"(777+888)\"\n assert candidate(expression = \"98765+4321\") == \"9(8765+432)1\"\n assert candidate(expression = \"654+321\") == \"6(54+32)1\"\n assert candidate(expression = \"77+88\") == \"(77+88)\"\n assert candidate(expression = \"222+333\") == \"2(22+33)3\"\n assert candidate(expression = \"123+45678\") == \"1(23+4567)8\"\n assert candidate(expression = \"9+8765\") == \"(9+876)5\"\n assert candidate(expression = \"5678+123\") == \"5(678+123)\"\n assert candidate(expression = \"1234+567\") == \"1(234+567)\"\n assert candidate(expression = \"234+56789\") == \"(234+5678)9\"\n assert candidate(expression = \"987654+321\") == \"987(654+32)1\"\n assert candidate(expression = \"876+54\") == \"(876+54)\"\n assert candidate(expression = \"123456+789\") == \"1(23456+789)\"\n assert candidate(expression = \"9876+543\") == \"(9876+543)\"\n assert candidate(expression = \"789+12\") == \"7(89+12)\"\n assert candidate(expression = \"1111+1111\") == \"1(111+111)1\"\n assert candidate(expression = \"55+5\") == \"5(5+5)\"\n assert candidate(expression = \"1+99999\") == \"(1+9999)9\"\n assert candidate(expression = \"11+22\") == \"1(1+2)2\"\n assert candidate(expression = \"321+654\") == \"(321+654)\"\n assert candidate(expression = \"55+66\") == \"(55+66)\"\n assert candidate(expression = \"56789+12\") == \"5(6789+12)\"\n assert candidate(expression = \"1234+5678\") == \"1(234+5678)\"\n assert candidate(expression = \"6+66\") == \"(6+6)6\"\n assert candidate(expression = \"54321+6789\") == \"5(4321+6789)\"\n assert candidate(expression = \"123+456789\") == \"1(23+456)789\"\n assert candidate(expression = \"54+32\") == \"5(4+3)2\"\n assert candidate(expression = \"21+89\") == \"(21+89)\"\n", "comparison": "exact"}, "public_tests": ["\"247+38\"", "\"12+34\"", "\"999+999\""], "hints": ["The maximum length of expression is very low. We can try every possible spot to place the parentheses.", "Every possibility of expression is of the form a * (b + c) * d where a, b, c, d represent integers. Note the edge cases where a and/or d do not exist, in which case use 1 instead of them."], "metadata": {"canonical_parameter_names": ["expression"], "leetcode_dataset_entry_point": "Solution().minimizeResult", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:46+00:00", "tests_total": 134, "tests_dropped": 29, "flags": ["multiple_answers"], "topic_tags": ["string", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function minimizeResult($expression) {", "container": "Solution", "callable": "minimizeResult", "parameters": [{"name": "expression", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2233, "task_id": "maximum-product-after-k-increments", "difficulty": "Medium", "problem_description": "You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.\n\nReturn the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 10^9 + 7. Note that you should maximize the product before taking the modulo.\n\nExample 1:\n\nInput: nums = [0,4], k = 5\nOutput: 20\nExplanation: Increment the first number 5 times.\nNow nums = [5, 4], with a product of 5 * 4 = 20.\nIt can be shown that 20 is maximum product possible, so we return 20.\nNote that there may be other ways to increment nums to have the maximum product.\n\nExample 2:\n\nInput: nums = [6,3,3,2], k = 2\nOutput: 216\nExplanation: Increment the second number 1 time and increment the fourth number 1 time.\nNow nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.\nIt can be shown that 216 is maximum product possible, so we return 216.\nNote that there may be other ways to increment nums to have the maximum product.\n\nConstraints:\n\n- 1 <= nums.length, k <= 10^5\n- 0 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 7776\n assert candidate(nums = [1, 2, 3, 4],k = 3) == 108\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 94500000\n assert candidate(nums = [0, 4],k = 5) == 20\n assert candidate(nums = [0, 0, 0, 0],k = 10) == 36\n assert candidate(nums = [1, 2, 3, 4, 5],k = 3) == 540\n assert candidate(nums = [5, 5, 5, 5],k = 4) == 1296\n assert candidate(nums = [1, 1, 1, 1, 1],k = 10) == 243\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 508243680\n assert candidate(nums = [9, 9, 9, 9],k = 8) == 14641\n assert candidate(nums = [10, 10, 10],k = 5) == 1584\n assert candidate(nums = [6, 3, 3, 2],k = 2) == 216\n assert candidate(nums = [0, 0, 0, 0],k = 1) == 0\n assert candidate(nums = [1, 2, 3],k = 6) == 64\n assert candidate(nums = [10, 20, 30],k = 15) == 15180\n assert candidate(nums = [1, 2, 3],k = 3) == 27\n assert candidate(nums = [1, 1, 1, 1],k = 10) == 144\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 10000) == 500226898\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 55) == 937424426\n assert candidate(nums = [100, 100, 100, 100, 100],k = 250) == 937499475\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 10) == 18750\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 = 200) == 138022365\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 = 1000) == 24010000\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 100) == 858490890\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 45) == 1000000000\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) == 836777896\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 100) == 385000049\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],k = 500) == 514152040\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 508243680\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 50) == 209024971\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 48999587\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 20) == 248832\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 = 100) == 4900\n assert candidate(nums = [100, 200, 300, 400, 500],k = 1000) == 999781257\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 100) == 460935215\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) == 414469870\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 50) == 60466176\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 20) == 786432\n assert candidate(nums = [999999, 999998, 999997, 999996],k = 10000) == 58871243\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 50) == 913512597\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],k = 50) == 904899965\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 200) == 340513509\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 = 150) == 322349693\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100000) == 570617225\n assert candidate(nums = [1, 3, 5, 7, 9],k = 20) == 59049\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 30) == 176221081\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 235146240\n assert candidate(nums = [1, 10, 100, 1000, 10000],k = 10000) == 49587669\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995],k = 100000) == 817421264\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 50) == 999999937\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],k = 200) == 73636025\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 1024\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 50) == 608131681\n assert candidate(nums = [1, 3, 5, 7, 9],k = 25) == 100000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 937424426\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],k = 50) == 73741817\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 = 100) == 911705284\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 30) == 60466176\n assert candidate(nums = [1, 10, 100, 1000, 10000],k = 100000) == 501184279\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) == 1048576\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 100) == 937424426\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15) == 235146240\n assert candidate(nums = [1],k = 100000) == 100001\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 312500000\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 = 50) == 467201634\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100000) == 346266448\n assert candidate(nums = [1, 2, 3, 4, 5],k = 10) == 3125\n assert candidate(nums = [1, 1000000, 2, 999999, 3, 999998, 4, 999997, 5, 999996],k = 10000) == 607510375\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 50) == 73741817\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 0, 0, 0, 0],k = 25) == 983040\n assert candidate(nums = [10, 20, 30, 40, 50],k = 30) == 54000000\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],k = 1000) == 461240680\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 105099888\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 30) == 191102976\n assert candidate(nums = [1, 2, 3, 4, 5],k = 20) == 16807\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 25) == 550731776\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],k = 100) == 47899023\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996],k = 10000) == 233771963\n assert candidate(nums = [1, 10, 100, 1000, 10000],k = 50000) == 901582326\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 50) == 650386593\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1000) == 889950771\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 312500000\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 = 5000) == 881212280\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) == 785571733\n assert candidate(nums = [1, 2, 3, 4, 5],k = 15) == 7776\n", "comparison": "exact"}, "public_tests": ["[0,4]\n5", "[6,3,3,2]\n2"], "hints": ["If you can increment only once, which number should you increment?", "We should always prioritize the smallest number. What kind of data structure could we use?", "Use a min heap to hold all the numbers. Each time we do an operation, replace the top of the heap x by x + 1."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().maximumProduct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:48+00:00", "tests_total": 101, "tests_dropped": 16, "flags": [], "topic_tags": ["array", "greedy", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maximumProduct($nums, $k) {", "container": "Solution", "callable": "maximumProduct", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2234, "task_id": "maximum-total-beauty-of-the-gardens", "difficulty": "Hard", "problem_description": "Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.\n\nYou are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the i^th garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.\n\nA garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:\n\n- The number of complete gardens multiplied by full.\n- The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.\n\nReturn the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.\n\nExample 1:\n\nInput: flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1\nOutput: 14\nExplanation: Alice can plant\n- 2 flowers in the 0^th garden\n- 3 flowers in the 1^st garden\n- 1 flower in the 2^nd garden\n- 1 flower in the 3^rd garden\nThe gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.\nThere is 1 garden that is complete.\nThe minimum number of flowers in the incomplete gardens is 2.\nThus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.\nNo other way of planting flowers can obtain a total beauty higher than 14.\n\nExample 2:\n\nInput: flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6\nOutput: 30\nExplanation: Alice can plant\n- 3 flowers in the 0^th garden\n- 0 flowers in the 1^st garden\n- 0 flowers in the 2^nd garden\n- 2 flowers in the 3^rd garden\nThe gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.\nThere are 3 gardens that are complete.\nThe minimum number of flowers in the incomplete gardens is 4.\nThus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.\nNo other way of planting flowers can obtain a total beauty higher than 30.\nNote that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty.\n\nConstraints:\n\n- 1 <= flowers.length <= 10^5\n- 1 <= flowers[i], target <= 10^5\n- 1 <= newFlowers <= 10^10\n- 1 <= full, partial <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(flowers = [10, 20, 30, 40, 50],newFlowers = 100,target = 25,full = 5,partial = 2) == 68\n assert candidate(flowers = [1, 1, 1, 1],newFlowers = 15,target = 3,full = 5,partial = 3) == 21\n assert candidate(flowers = [5, 5, 5, 5],newFlowers = 10,target = 5,full = 10,partial = 5) == 40\n assert candidate(flowers = [10, 20, 30],newFlowers = 100,target = 25,full = 50,partial = 10) == 340\n assert candidate(flowers = [10, 1, 2, 3],newFlowers = 15,target = 10,full = 5,partial = 2) == 20\n assert candidate(flowers = [1, 2, 3, 4, 5],newFlowers = 15,target = 5,full = 10,partial = 5) == 60\n assert candidate(flowers = [5, 5, 5, 5],newFlowers = 10,target = 5,full = 10,partial = 1) == 40\n assert candidate(flowers = [2, 4, 5, 3],newFlowers = 10,target = 5,full = 2,partial = 6) == 30\n assert candidate(flowers = [100000, 100000, 100000],newFlowers = 300000,target = 100000,full = 100000,partial = 100000) == 300000\n assert candidate(flowers = [1, 2, 3, 4, 5],newFlowers = 15,target = 4,full = 20,partial = 5) == 100\n assert candidate(flowers = [1, 2, 3, 4, 5],newFlowers = 15,target = 5,full = 10,partial = 3) == 52\n assert candidate(flowers = [5, 5, 5, 5],newFlowers = 10,target = 5,full = 10,partial = 10) == 40\n assert candidate(flowers = [5, 5, 5, 5],newFlowers = 10,target = 5,full = 2,partial = 6) == 8\n assert candidate(flowers = [1, 1, 1, 1],newFlowers = 20,target = 3,full = 7,partial = 3) == 28\n assert candidate(flowers = [1, 3, 1, 1],newFlowers = 7,target = 6,full = 12,partial = 1) == 14\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 100,target = 10,full = 100,partial = 1) == 1000\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 100,target = 10,full = 30,partial = 20) == 450\n assert candidate(flowers = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],newFlowers = 1000000,target = 50000,full = 500,partial = 250) == 12504250\n assert candidate(flowers = [50000, 100000, 25000, 75000],newFlowers = 100000,target = 80000,full = 500,partial = 200) == 16001300\n assert candidate(flowers = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],newFlowers = 10000,target = 2000,full = 1000,partial = 500) == 1008500\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 7,full = 15,partial = 3) == 153\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 500,target = 55,full = 15,partial = 7) == 513\n assert candidate(flowers = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],newFlowers = 1000000,target = 90000,full = 1000,partial = 500) == 10000\n assert candidate(flowers = [1, 10, 100, 1000, 10000, 100000],newFlowers = 100000,target = 50000,full = 1000,partial = 500) == 11112000\n assert candidate(flowers = [1, 5, 9, 13, 17, 21],newFlowers = 25,target = 15,full = 10,partial = 3) == 74\n assert candidate(flowers = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],newFlowers = 1000000,target = 100000,full = 1,partial = 1) == 10\n assert candidate(flowers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],newFlowers = 5000,target = 500,full = 100,partial = 50) == 25850\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 50,target = 10,full = 15,partial = 5) == 180\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],newFlowers = 50,target = 8,full = 50,partial = 10) == 770\n assert candidate(flowers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],newFlowers = 50,target = 8,full = 20,partial = 5) == 215\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 100,target = 5,full = 20,partial = 15) == 240\n assert candidate(flowers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],newFlowers = 100,target = 4,full = 100,partial = 50) == 1050\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 5,full = 10,partial = 1) == 100\n assert candidate(flowers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],newFlowers = 50,target = 5,full = 100,partial = 50) == 1000\n assert candidate(flowers = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],newFlowers = 150,target = 35,full = 20,partial = 3) == 249\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 10,full = 20,partial = 10) == 270\n assert candidate(flowers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],newFlowers = 1000,target = 5,full = 100,partial = 50) == 1000\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],newFlowers = 100,target = 10,full = 30,partial = 15) == 555\n assert candidate(flowers = [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, 50000, 50000, 50000],newFlowers = 1000000,target = 100000,full = 100000,partial = 100000) == 8030300000\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],newFlowers = 1000,target = 100,full = 50,partial = 25) == 3175\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 10000000000,target = 1,full = 100,partial = 50) == 1000\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],newFlowers = 500,target = 20,full = 150,partial = 75) == 5775\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],newFlowers = 500,target = 15,full = 25,partial = 10) == 615\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 5,full = 10,partial = 3) == 102\n assert candidate(flowers = [99990, 99991, 99992, 99993, 99994, 99995, 99996, 99997, 99998, 99999],newFlowers = 100000,target = 100000,full = 100000,partial = 100000) == 10000800000\n assert candidate(flowers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],newFlowers = 100,target = 11,full = 50,partial = 25) == 950\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 100,target = 5,full = 50,partial = 20) == 530\n assert candidate(flowers = [90, 90, 90, 90, 90, 90, 90, 90, 90, 90],newFlowers = 100,target = 95,full = 1000,partial = 500) == 56000\n assert candidate(flowers = [90000, 80000, 70000, 60000, 50000],newFlowers = 300000,target = 100000,full = 1000,partial = 500) == 50003500\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1,target = 1,full = 100,partial = 50) == 1000\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],newFlowers = 300,target = 15,full = 100,partial = 50) == 2600\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 10,full = 20,partial = 10) == 270\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 10000000000,target = 2,full = 1,partial = 1) == 10\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 1000,target = 60,full = 50,partial = 25) == 1925\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 5,full = 100,partial = 10) == 1000\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 1000,target = 55,full = 50,partial = 10) == 990\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 7,full = 20,partial = 5) == 210\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 100,target = 10,full = 20,partial = 5) == 225\n assert candidate(flowers = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],newFlowers = 1000000,target = 100000,full = 100000,partial = 50000) == 1000000\n assert candidate(flowers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],newFlowers = 50,target = 10,full = 20,partial = 10) == 270\n assert candidate(flowers = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],newFlowers = 500,target = 3,full = 20,partial = 10) == 200\n assert candidate(flowers = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],newFlowers = 500,target = 45,full = 50,partial = 10) == 890\n assert candidate(flowers = [5, 5, 5, 5, 5],newFlowers = 25,target = 7,full = 50,partial = 5) == 250\n assert candidate(flowers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],newFlowers = 3000,target = 500,full = 50,partial = 25) == 12925\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 50,target = 10,full = 10,partial = 1) == 100\n assert candidate(flowers = [50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195, 97],newFlowers = 100000,target = 10000,full = 1000,partial = 500) == 5008500\n assert candidate(flowers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],newFlowers = 20,target = 6,full = 20,partial = 10) == 230\n assert candidate(flowers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],newFlowers = 5000,target = 500,full = 1000,partial = 100) == 58900\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 1000,target = 60,full = 50,partial = 10) == 1040\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 5,full = 100,partial = 50) == 2100\n assert candidate(flowers = [50, 30, 20, 10, 5],newFlowers = 150,target = 25,full = 10,partial = 5) == 160\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 2,full = 50,partial = 25) == 4250\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 30,target = 6,full = 10,partial = 3) == 105\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 1000,target = 5,full = 100,partial = 50) == 8400\n assert candidate(flowers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],newFlowers = 100,target = 10,full = 20,partial = 10) == 270\n assert candidate(flowers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],newFlowers = 1000,target = 40,full = 50,partial = 20) == 1230\n assert candidate(flowers = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],newFlowers = 200,target = 25,full = 100,partial = 50) == 2100\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 500,target = 40,full = 20,partial = 10) == 570\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],newFlowers = 700,target = 20,full = 50,partial = 20) == 1580\n assert candidate(flowers = [100, 200, 300, 400, 500],newFlowers = 1000,target = 350,full = 15,partial = 5) == 1805\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 15,target = 5,full = 100,partial = 10) == 1000\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 150,target = 80,full = 150,partial = 75) == 4950\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 30,target = 7,full = 10,partial = 5) == 120\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 1,target = 1,full = 1000,partial = 500) == 10000\n assert candidate(flowers = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90],newFlowers = 200,target = 55,full = 100,partial = 50) == 3600\n assert candidate(flowers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],newFlowers = 50,target = 10,full = 100,partial = 50) == 1350\n assert candidate(flowers = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],newFlowers = 1000000,target = 50000,full = 1000,partial = 500) == 25008500\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 250,target = 5,full = 100,partial = 50) == 1100\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],newFlowers = 500,target = 15,full = 75,partial = 35) == 1915\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 8,full = 20,partial = 10) == 250\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 100,target = 5,full = 100,partial = 50) == 1100\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 7,full = 100,partial = 50) == 1200\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 100,target = 5,full = 50,partial = 25) == 1050\n assert candidate(flowers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],newFlowers = 250,target = 30,full = 200,partial = 100) == 4700\n assert candidate(flowers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],newFlowers = 100,target = 7,full = 20,partial = 5) == 210\n assert candidate(flowers = [1, 2, 3, 4, 5],newFlowers = 1000000,target = 10,full = 100000,partial = 10000) == 500000\n assert candidate(flowers = [2, 4, 6, 8, 10, 12, 14],newFlowers = 30,target = 15,full = 7,partial = 5) == 71\n assert candidate(flowers = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991],newFlowers = 10000,target = 995,full = 100,partial = 50) == 50600\n assert candidate(flowers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],newFlowers = 500,target = 75,full = 1000,partial = 100) == 16400\n assert candidate(flowers = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],newFlowers = 5000,target = 750,full = 250,partial = 125) == 97125\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],newFlowers = 200,target = 10,full = 50,partial = 25) == 925\n assert candidate(flowers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],newFlowers = 50,target = 10,full = 10,partial = 1) == 100\n assert candidate(flowers = [100000, 99999, 99998, 99997, 99996, 99995],newFlowers = 150000,target = 100000,full = 100000,partial = 100000) == 10000400000\n assert candidate(flowers = [1, 5, 9, 13, 17, 21],newFlowers = 20,target = 15,full = 10,partial = 3) == 67\n assert candidate(flowers = [50, 40, 30, 20, 10],newFlowers = 100,target = 35,full = 100,partial = 50) == 2100\n assert candidate(flowers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],newFlowers = 100,target = 5,full = 5,partial = 2) == 53\n", "comparison": "exact"}, "public_tests": ["[1,3,1,1]\n7\n6\n12\n1", "[2,4,5,3]\n10\n5\n2\n6"], "hints": ["Say we choose k gardens to be complete, is there an optimal way of choosing which gardens to plant more flowers to achieve this?", "For a given k, we should greedily fill-up the k gardens with the most flowers planted already. This gives us the most remaining flowers to fill up the other gardens.", "After sorting flowers, we can thus try every possible k and what is left is to find the highest minimum flowers we can obtain by planting the remaining flowers in the other gardens.", "To find the highest minimum in the other gardens, we can use binary search to find the most optimal way of planting."], "metadata": {"canonical_parameter_names": ["flowers", "newFlowers", "target", "full", "partial"], "leetcode_dataset_entry_point": "Solution().maximumBeauty", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:50+00:00", "tests_total": 113, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "greedy", "sorting", "enumeration", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maximumBeauty($flowers, $newFlowers, $target, $full, $partial) {", "container": "Solution", "callable": "maximumBeauty", "parameters": [{"name": "flowers", "type": "Integer[]"}, {"name": "newFlowers", "type": "Integer"}, {"name": "target", "type": "Integer"}, {"name": "full", "type": "Integer"}, {"name": "partial", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2235, "task_id": "add-two-integers", "difficulty": "Easy", "problem_description": "Given two integers num1 and num2, return the sum of the two integers.\n\nExample 1:\n\nInput: num1 = 12, num2 = 5\nOutput: 17\nExplanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.\n\nExample 2:\n\nInput: num1 = -10, num2 = 4\nOutput: -6\nExplanation: num1 + num2 = -6, so -6 is returned.\n\nConstraints:\n\n- -100 <= num1, num2 <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num1 = 100,num2 = -100) == 0\n assert candidate(num1 = -10,num2 = 4) == -6\n assert candidate(num1 = 25,num2 = 25) == 50\n assert candidate(num1 = -50,num2 = 50) == 0\n assert candidate(num1 = 99,num2 = 1) == 100\n assert candidate(num1 = -50,num2 = 25) == -25\n assert candidate(num1 = -30,num2 = -70) == -100\n assert candidate(num1 = 100,num2 = 100) == 200\n assert candidate(num1 = 12,num2 = 5) == 17\n assert candidate(num1 = 0,num2 = 0) == 0\n assert candidate(num1 = -100,num2 = -100) == -200\n assert candidate(num1 = -99,num2 = -1) == -100\n assert candidate(num1 = 50,num2 = -50) == 0\n assert candidate(num1 = -45,num2 = -55) == -100\n assert candidate(num1 = -73,num2 = -27) == -100\n assert candidate(num1 = 80,num2 = -30) == 50\n assert candidate(num1 = 23,num2 = -23) == 0\n assert candidate(num1 = -75,num2 = 20) == -55\n assert candidate(num1 = 100,num2 = 0) == 100\n assert candidate(num1 = 0,num2 = -100) == -100\n assert candidate(num1 = -1,num2 = -99) == -100\n assert candidate(num1 = -45,num2 = 65) == 20\n assert candidate(num1 = 22,num2 = 78) == 100\n assert candidate(num1 = 98,num2 = 2) == 100\n assert candidate(num1 = 45,num2 = -55) == -10\n assert candidate(num1 = -75,num2 = 25) == -50\n assert candidate(num1 = -88,num2 = 12) == -76\n assert candidate(num1 = -75,num2 = -25) == -100\n assert candidate(num1 = 1,num2 = 99) == 100\n assert candidate(num1 = -100,num2 = 0) == -100\n assert candidate(num1 = 42,num2 = -42) == 0\n assert candidate(num1 = -49,num2 = 51) == 2\n assert candidate(num1 = -99,num2 = 1) == -98\n assert candidate(num1 = 0,num2 = 100) == 100\n assert candidate(num1 = 45,num2 = -45) == 0\n assert candidate(num1 = 50,num2 = -60) == -10\n assert candidate(num1 = 88,num2 = 12) == 100\n assert candidate(num1 = -45,num2 = 55) == 10\n assert candidate(num1 = 67,num2 = -33) == 34\n assert candidate(num1 = -33,num2 = -67) == -100\n assert candidate(num1 = -30,num2 = 70) == 40\n assert candidate(num1 = -67,num2 = 33) == -34\n assert candidate(num1 = 99,num2 = -1) == 98\n assert candidate(num1 = 73,num2 = 27) == 100\n assert candidate(num1 = 75,num2 = -25) == 50\n assert candidate(num1 = -45,num2 = 45) == 0\n assert candidate(num1 = -100,num2 = 100) == 0\n assert candidate(num1 = -23,num2 = 23) == 0\n assert candidate(num1 = 67,num2 = 33) == 100\n assert candidate(num1 = 50,num2 = 50) == 100\n assert candidate(num1 = -50,num2 = -50) == -100\n assert candidate(num1 = 28,num2 = -28) == 0\n assert candidate(num1 = 45,num2 = 55) == 100\n assert candidate(num1 = 33,num2 = 67) == 100\n assert candidate(num1 = 75,num2 = 25) == 100\n assert candidate(num1 = 49,num2 = 51) == 100\n assert candidate(num1 = -23,num2 = 77) == 54\n assert candidate(num1 = 37,num2 = 63) == 100\n assert candidate(num1 = 29,num2 = 71) == 100\n", "comparison": "exact"}, "public_tests": ["12\n5", "-10\n4"], "hints": [], "metadata": {"canonical_parameter_names": ["num1", "num2"], "leetcode_dataset_entry_point": "Solution().sum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:53+00:00", "tests_total": 59, "tests_dropped": 0, "flags": [], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function sum($num1, $num2) {", "container": "Solution", "callable": "sum", "parameters": [{"name": "num1", "type": "Integer"}, {"name": "num2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2239, "task_id": "find-closest-number-to-zero", "difficulty": "Easy", "problem_description": "Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.\n\nExample 1:\n\nInput: nums = [-4,-2,1,4,8]\nOutput: 1\nExplanation:\nThe distance from -4 to 0 is |-4| = 4.\nThe distance from -2 to 0 is |-2| = 2.\nThe distance from 1 to 0 is |1| = 1.\nThe distance from 4 to 0 is |4| = 4.\nThe distance from 8 to 0 is |8| = 8.\nThus, the closest number to 0 in the array is 1.\n\nExample 2:\n\nInput: nums = [2,-1,1]\nOutput: 1\nExplanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.\n\nConstraints:\n\n- 1 <= n <= 1000\n- -10^5 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, -3, 2, -2, 1, -1]) == 1\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 50000\n assert candidate(nums = [100000, -100000, 50000, -50000]) == 50000\n assert candidate(nums = [7, -10, 4, 3, -20, 2]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [0, 5, -5]) == 0\n assert candidate(nums = [-5, -3, -1, -4, -2]) == -1\n assert candidate(nums = [0, 1, -1]) == 0\n assert candidate(nums = [-1]) == -1\n assert candidate(nums = [-10, -9, 9, 10]) == 9\n assert candidate(nums = [-5, -5, -5, -5, -5]) == -5\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [-3, -2, -1, 0, 1, 2, 3]) == 0\n assert candidate(nums = [-100000, 100000]) == 100000\n assert candidate(nums = [-10, -5, 0, 5, 10]) == 0\n assert candidate(nums = [-10, 10, 0]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [-5, -4, -3, -2, -1]) == -1\n assert candidate(nums = [-4, -2, 1, 4, 8]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [100000, -100000, 50000, -50000, 0]) == 0\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 1\n assert candidate(nums = [-100000]) == -100000\n assert candidate(nums = [-10, -3, -1, 0, 1, 3, 10]) == 0\n assert candidate(nums = [100000]) == 100000\n assert candidate(nums = [-10, -5, 0, 5, 10]) == 0\n assert candidate(nums = [-5, -4, -3, -2, -1]) == -1\n assert candidate(nums = [5, 3, 1, 4, 2]) == 1\n assert candidate(nums = [2, -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, 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 = [12345, -12345, 11111, -11111, 22222, -22222, 33333, -33333, 44444, -44444, 55555, -55555, 66666, -66666, 77777, -77777, 88888, -88888, 99999, -99999]) == 11111\n assert candidate(nums = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1, -1, -3, -7, -15, -31, -62, -125, -250, -500, -1000]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 7\n assert candidate(nums = [5000, -5000, 2500, -2500, 1250, -1250, 625, -625, 312, -312, 156, -156]) == 156\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984, 9983, 9982, 9981, 9980, -9980, -9981, -9982, -9983, -9984, -9985, -9986, -9987, -9988, -9989, -9990, -9991, -9992, -9993, -9994, -9995, -9996, -9997, -9998, -9999, -10000]) == 9980\n assert candidate(nums = [-1, -1, -1, -1, 1, 1, 1, 1]) == 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, 0]) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, 0, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [-99999, -50000, -10000, -1000, -100, -10, -1, 0, 1, 10, 100, 1000, 10000, 50000, 99999]) == 0\n assert candidate(nums = [-50, -25, 0, 25, 50, -12, 12, -7, 7, -3, 3, -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]) == 0\n assert candidate(nums = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [-50000, -49999, 49999, 50000, 0]) == 0\n assert candidate(nums = [-10000, -9999, -9998, -9997, 9997, 9998, 9999, 10000, 0]) == 0\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, 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 = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900]) == 100\n assert candidate(nums = [50, -50, 25, -25, 12, -12, 6, -6, 3, -3, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [3, -1, -3, 1, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 1\n assert candidate(nums = [-50000, -25000, -12500, -6250, -3125, -1562, -781, -390, -195, -97, -48, -24, -12, -6, -3, -1, 1, 3, 6, 12, 24, 48, 97, 195, 390, 781, 1562, 3125, 6250, 12500, 25000, 50000]) == 1\n assert candidate(nums = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -10, -20, -30, -40, -50, -60, -70, -80, -90, -100, 5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85, 95, -95]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500, 0]) == 0\n assert candidate(nums = [0, -1, 1, -100000, 100000]) == 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\n assert candidate(nums = [82345, -82345, 67890, -67890, 54321, -54321, 43210, -43210, 32109, -32109, 21098, -21098]) == 21098\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, 100000, -100000, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 1\n assert candidate(nums = [-7, -14, -21, -28, -35, -42, -49, -56, -63, -70]) == -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, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [0, -100000, 100000, -99999, 99999]) == 0\n assert candidate(nums = [-1000, 1000, 0, 500, -500, 250, -250, 125, -125, 62, -62, 31, -31, 15, -15, 7, -7, 3, -3, 1, -1]) == 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, -11, 11, -12, 12, -13, 13, -14, 14, -15, 15]) == 1\n assert candidate(nums = [-100000, -99999, 99999, 100000]) == 99999\n assert candidate(nums = [1000, 1001, 999, 998, 1002, 997, 1003, 996, 1004, 995, 0, -1, -2, -3, -4]) == 0\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, -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]) == 70\n assert candidate(nums = [-50, -25, 0, 25, 50]) == 0\n assert candidate(nums = [0, 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 = [98765, 43210, 87654, 32109, 76543, 21098, 65432, 10987, 54321, 9876, 4321, 8765, 3210, 7654, 2109, 6543, 1098, 5432, 987, 432, 876, 321, 765, 210, 654, 109, 543, 98, 43, 87, 32, 76, 21, 65, 10, 5, 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]) == 1\n assert candidate(nums = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991, -49991, -49992, -49993, -49994, -49995, -49996, -49997, -49998, -49999, -50000]) == 49991\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [99998, -99998, 99999, -99999, 0]) == 0\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 = [-98765, 98765, -87654, 87654, -76543, 76543, -65432, 65432, -54321, 54321, -43210, 43210, -32109, 32109, -21098, 21098, -10987, 10987, -9876, 9876]) == 9876\n assert candidate(nums = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 100\n assert candidate(nums = [-33333, 33333, -66666, 66666, -100000, 100000, 0, 1, -1, 2, -2]) == 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, 99980, 99979, 99978, 99977, 99976, 99975, 99974, 99973, 99972, 99971, 99970, -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, -99975, -99974, -99973, -99972, -99971, -99970]) == 99970\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 = [50000, -50000, 49999, -49999, 49998, -49998, 100000, -100000]) == 49998\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]) == 0\n assert candidate(nums = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, 9989, 9988, 9987, 9986, 9985, 9984, 9983, 9982, 9981, 9980, 9979, 9978, 9977, 9976, 9975, 9974, 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, 9924, 9923, 9922, 9921, 9920, 9919, 9918, 9917, 9916, 9915, 9914, 9913, 9912, 9911, 9910, 9909, 9908, 9907, 9906, 9905, 9904, 9903, 9902, 9901, 9900, 9899, 9898, 9897, 9896, 9895, 9894, 9893, 9892, 9891, 9890, 9889, 9888, 9887, 9886, 9885, 9884, 9883, 9882, 9881, 9880, 9879, 9878, 9877, 9876, 9875, 9874, 9873, 9872, 9871, 9870, 9869, 9868, 9867, 9866, 9865, 9864, 9863, 9862, 9861, 9860, 9859, 9858, 9857, 9856, 9855, 9854, 9853, 9852, 9851, 9850, 9849, 9848, 9847, 9846, 9845, 9844, 9843, 9842, 9841, 9840, 9839, 9838, 9837, 9836, 9835, 9834, 9833, 9832, 9831, 9830, 9829, 9828, 9827, 9826, 9825, 9824, 9823, 9822, 9821, 9820, 9819, 9818, 9817, 9816, 9815, 9814, 9813, 9812, 9811, 9810, 9809, 9808, 9807, 9806, 9805, 9804, 9803, 9802, 9801, 9800]) == 9800\n assert candidate(nums = [-1000, -500, -250, -125, -62, -31, -15, -7, -3, -1, 1, 3, 7, 15, 31, 62, 125, 250, 500, 1000]) == 1\n assert candidate(nums = [-5000, 5000, -1000, 1000, -2000, 2000, -3000, 3000, -4000, 4000, -6000, 6000, -7000, 7000, -8000, 8000]) == 1000\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]) == 0\n assert candidate(nums = [100000, -99999, 99999, -100000, 50000, -49999, 49999, -50000]) == 49999\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 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 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -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 = [-99999, -99998, -99997, 99997, 99998, 99999]) == 99997\n assert candidate(nums = [-50000, 50000, -49999, 49999, -49998, 49998, 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, -100000, 100000, -99999, 99999, -99998, 99998, -99997, 99997, -99996, 99996, -99995, 99995, -99994, 99994, -99993, 99993, -99992, 99992, -99991, 99991, -99990, 99990, -99989, 99989, -99988, 99988, -99987, 99987, -99986, 99986, -99985, 99985, -99984, 99984, -99983, 99983, -99982, 99982, -99981, 99981, -99980, 99980, -99979, 99979, -99978, 99978, -99977, 99977, -99976, 99976, -99975, 99975, -99974, 99974, -99973, 99973, -99972, 99972, -99971, 99971, -99970, 99970]) == 0\n assert candidate(nums = [10000, -10000, 5000, -5000, 1000, -1000, 500, -500, 100, -100, 50, -50, 10, -10, 5, -5, 1, -1]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [23, -23, 46, -46, 92, -92, 184, -184, 368, -368, 736, -736, 1472, -1472, 2944, -2944]) == 23\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, -99979, -99978, -99977, -99976, -99975, -99974, -99973, -99972, -99971, -99970]) == -99970\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 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 0\n assert candidate(nums = [100, 200, -150, 150, 0, -50, 50, -200]) == 0\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90]) == 90\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000]) == 100\n assert candidate(nums = [99999, -99999, 99998, -99998, 99997, -99997, 99996, -99996, 99995, -99995, 0]) == 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]) == 1\n assert candidate(nums = [98765, -98765, 43210, -43210, 86421, -86421, 12345, -12345, 0]) == 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, 11, -11, 12, -12]) == 1\n assert candidate(nums = [-1000, -999, -998, 998, 999, 1000, 500, -500, 250, -250]) == 250\n assert candidate(nums = [99995, 99996, 99997, 99998, 99999, -99995, -99996, -99997, -99998, -99999]) == 99995\n assert candidate(nums = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40]) == 5\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]) == 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, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, -99991, -99992, -99993, -99994, -99995, -99996, -99997, -99998, -99999, -100000]) == 99991\n assert candidate(nums = [-10000, -5000, -1000, -500, -100, -50, -10, -5, -1, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000]) == 1\n assert candidate(nums = [-54321, 54321, -12345, 12345, -6789, 6789, -3456, 3456, -789, 789]) == 789\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, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 1\n assert candidate(nums = [-99999, 99999, -50000, 50000, -25000, 25000, -12500, 12500, -6250, 6250, -3125, 3125]) == 3125\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]) == 0\n assert candidate(nums = [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, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15, 16, -16, 17, -17, 18, -18, 19, -19, 20, -20]) == 1\n assert candidate(nums = [3, 5, -3, -5, 7, -7, 2, -2, 0]) == 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]) == 1\n assert candidate(nums = [-50000, -25000, -10000, -5000, -1000, -500, -100, -50, -10, -1, 0, 1, 10, 50, 100, 500, 1000, 5000, 10000, 25000, 50000]) == 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, 99980, 99979, 99978, 99977, 99976, 99975, 99974, 99973, 99972, 99971, 99970]) == 99970\n assert candidate(nums = [-99999, -99998, -99997, -99996, 99996, 99997, 99998, 99999]) == 99996\n assert candidate(nums = [-500, -250, 0, 250, 500, -249, 249]) == 0\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, 0]) == 0\n assert candidate(nums = [0, -1, 1, -100000, 100000, -99999, 99999, -10, 10, -5, 5, -2, 2, -3, 3]) == 0\n", "comparison": "exact"}, "public_tests": ["[-4,-2,1,4,8]", "[2,-1,1]"], "hints": ["Keep track of the number closest to 0 as you iterate through the array.", "Ensure that if multiple numbers are closest to 0, you store the one with the largest value."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findClosestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:45:59+00:00", "tests_total": 128, "tests_dropped": 1, "flags": ["multiple_answers"], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function findClosestNumber($nums) {", "container": "Solution", "callable": "findClosestNumber", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2240, "task_id": "number-of-ways-to-buy-pens-and-pencils", "difficulty": "Medium", "problem_description": "You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.\n\nReturn the number of distinct ways you can buy some number of pens and pencils.\n\nExample 1:\n\nInput: total = 20, cost1 = 10, cost2 = 5\nOutput: 9\nExplanation: The price of a pen is 10 and the price of a pencil is 5.\n- If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.\n- If you buy 1 pen, you can buy 0, 1, or 2 pencils.\n- If you buy 2 pens, you cannot buy any pencils.\nThe total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.\n\nExample 2:\n\nInput: total = 5, cost1 = 10, cost2 = 10\nOutput: 1\nExplanation: The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.\n\nConstraints:\n\n- 1 <= total, cost1, cost2 <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(total = 20,cost1 = 10,cost2 = 5) == 9\n assert candidate(total = 1000,cost1 = 1,cost2 = 1) == 501501\n assert candidate(total = 5,cost1 = 10,cost2 = 10) == 1\n assert candidate(total = 5,cost1 = 10,cost2 = 10) == 1\n assert candidate(total = 100,cost1 = 1,cost2 = 1) == 5151\n assert candidate(total = 50,cost1 = 7,cost2 = 11) == 23\n assert candidate(total = 100,cost1 = 20,cost2 = 30) == 14\n assert candidate(total = 50,cost1 = 10,cost2 = 20) == 12\n assert candidate(total = 1000000,cost1 = 500000,cost2 = 500000) == 6\n assert candidate(total = 20,cost1 = 10,cost2 = 5) == 9\n assert candidate(total = 1000000,cost1 = 500000,cost2 = 500000) == 6\n assert candidate(total = 1000000,cost1 = 500000,cost2 = 300000) == 7\n assert candidate(total = 10,cost1 = 3,cost2 = 7) == 6\n assert candidate(total = 10,cost1 = 5,cost2 = 2) == 10\n assert candidate(total = 1,cost1 = 1,cost2 = 1) == 3\n assert candidate(total = 50,cost1 = 25,cost2 = 20) == 6\n assert candidate(total = 100,cost1 = 1,cost2 = 1) == 5151\n assert candidate(total = 500,cost1 = 250,cost2 = 250) == 6\n assert candidate(total = 1,cost1 = 2,cost2 = 3) == 1\n assert candidate(total = 500,cost1 = 5,cost2 = 7) == 3665\n assert candidate(total = 150,cost1 = 25,cost2 = 15) == 40\n assert candidate(total = 100,cost1 = 100,cost2 = 100) == 3\n assert candidate(total = 1234,cost1 = 123,cost2 = 456) == 21\n assert candidate(total = 800,cost1 = 120,cost2 = 30) == 105\n assert candidate(total = 100,cost1 = 50,cost2 = 100) == 4\n assert candidate(total = 100,cost1 = 50,cost2 = 50) == 6\n assert candidate(total = 1000,cost1 = 100,cost2 = 200) == 36\n assert candidate(total = 100000,cost1 = 1000,cost2 = 500) == 10201\n assert candidate(total = 999999,cost1 = 99999,cost2 = 1) == 5500055\n assert candidate(total = 80,cost1 = 8,cost2 = 5) == 95\n assert candidate(total = 200,cost1 = 15,cost2 = 4) == 368\n assert candidate(total = 1000,cost1 = 150,cost2 = 100) == 44\n assert candidate(total = 100,cost1 = 7,cost2 = 3) == 265\n assert candidate(total = 1000,cost1 = 150,cost2 = 75) == 56\n assert candidate(total = 1000000,cost1 = 999999,cost2 = 999999) == 3\n assert candidate(total = 123456,cost1 = 11111,cost2 = 22222) == 42\n assert candidate(total = 100000,cost1 = 33333,cost2 = 33333) == 10\n assert candidate(total = 999999,cost1 = 1000,cost2 = 999) == 501501\n assert candidate(total = 10000,cost1 = 100,cost2 = 50) == 10201\n assert candidate(total = 200,cost1 = 50,cost2 = 25) == 25\n assert candidate(total = 500000,cost1 = 999999,cost2 = 1) == 500001\n assert candidate(total = 150,cost1 = 5,cost2 = 3) == 796\n assert candidate(total = 999999,cost1 = 100000,cost2 = 50000) == 110\n assert candidate(total = 123456,cost1 = 12345,cost2 = 6543) == 109\n assert candidate(total = 10000,cost1 = 50,cost2 = 30) == 33634\n assert candidate(total = 500,cost1 = 250,cost2 = 100) == 10\n assert candidate(total = 100000,cost1 = 1,cost2 = 1) == 5000150001\n assert candidate(total = 250,cost1 = 75,cost2 = 25) == 26\n assert candidate(total = 500,cost1 = 150,cost2 = 125) == 11\n assert candidate(total = 1000,cost1 = 10,cost2 = 1) == 50601\n assert candidate(total = 999,cost1 = 1,cost2 = 1) == 500500\n assert candidate(total = 1000,cost1 = 500,cost2 = 250) == 9\n assert candidate(total = 200,cost1 = 10,cost2 = 100) == 33\n assert candidate(total = 120,cost1 = 30,cost2 = 20) == 19\n assert candidate(total = 60,cost1 = 20,cost2 = 30) == 7\n assert candidate(total = 999999,cost1 = 1,cost2 = 2) == 250000500000\n assert candidate(total = 300,cost1 = 150,cost2 = 100) == 7\n assert candidate(total = 150,cost1 = 50,cost2 = 50) == 10\n assert candidate(total = 1000,cost1 = 333,cost2 = 111) == 22\n assert candidate(total = 100,cost1 = 25,cost2 = 30) == 11\n assert candidate(total = 500,cost1 = 150,cost2 = 50) == 26\n assert candidate(total = 999999,cost1 = 99999,cost2 = 99999) == 66\n assert candidate(total = 800,cost1 = 400,cost2 = 200) == 9\n assert candidate(total = 120,cost1 = 40,cost2 = 60) == 7\n assert candidate(total = 600,cost1 = 100,cost2 = 150) == 19\n assert candidate(total = 500,cost1 = 250,cost2 = 200) == 6\n assert candidate(total = 500000,cost1 = 1,cost2 = 2) == 62500500001\n assert candidate(total = 999999,cost1 = 1,cost2 = 1) == 500000500000\n assert candidate(total = 75,cost1 = 15,cost2 = 10) == 27\n assert candidate(total = 200,cost1 = 1,cost2 = 1) == 20301\n assert candidate(total = 1000,cost1 = 500,cost2 = 100) == 18\n assert candidate(total = 100,cost1 = 1,cost2 = 2) == 2601\n assert candidate(total = 70,cost1 = 5,cost2 = 3) == 185\n assert candidate(total = 300,cost1 = 100,cost2 = 150) == 7\n assert candidate(total = 1000,cost1 = 300,cost2 = 500) == 7\n assert candidate(total = 999999,cost1 = 999999,cost2 = 1) == 1000001\n assert candidate(total = 1000000,cost1 = 1,cost2 = 1) == 500001500001\n assert candidate(total = 1000000,cost1 = 1,cost2 = 1000000) == 1000002\n assert candidate(total = 1000,cost1 = 5,cost2 = 3) == 33634\n assert candidate(total = 5000,cost1 = 50,cost2 = 100) == 2601\n assert candidate(total = 100000,cost1 = 20000,cost2 = 30000) == 14\n assert candidate(total = 1000,cost1 = 100,cost2 = 10) == 561\n assert candidate(total = 100,cost1 = 30,cost2 = 70) == 6\n assert candidate(total = 100,cost1 = 30,cost2 = 7) == 34\n assert candidate(total = 123456,cost1 = 123,cost2 = 456) == 136511\n assert candidate(total = 300,cost1 = 50,cost2 = 25) == 49\n assert candidate(total = 100,cost1 = 5,cost2 = 3) == 364\n assert candidate(total = 10000,cost1 = 100,cost2 = 10) == 50601\n assert candidate(total = 200,cost1 = 150,cost2 = 50) == 7\n assert candidate(total = 500,cost1 = 100,cost2 = 50) == 36\n assert candidate(total = 999999,cost1 = 100000,cost2 = 10000) == 550\n assert candidate(total = 500,cost1 = 100,cost2 = 10) == 156\n assert candidate(total = 300,cost1 = 50,cost2 = 75) == 19\n assert candidate(total = 100,cost1 = 99,cost2 = 1) == 103\n assert candidate(total = 100,cost1 = 25,cost2 = 7) == 39\n assert candidate(total = 200,cost1 = 7,cost2 = 11) == 285\n assert candidate(total = 300,cost1 = 150,cost2 = 50) == 12\n assert candidate(total = 100,cost1 = 50,cost2 = 25) == 9\n assert candidate(total = 120,cost1 = 20,cost2 = 15) == 33\n assert candidate(total = 500,cost1 = 200,cost2 = 150) == 8\n assert candidate(total = 1,cost1 = 1,cost2 = 2) == 2\n", "comparison": "exact"}, "public_tests": ["20\n10\n5", "5\n10\n10"], "hints": ["Fix the number of pencils purchased and calculate the number of ways to buy pens.", "Sum up the number of ways to buy pens for each amount of pencils purchased to get the answer."], "metadata": {"canonical_parameter_names": ["total", "cost1", "cost2"], "leetcode_dataset_entry_point": "Solution().waysToBuyPensPencils", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:01+00:00", "tests_total": 102, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function waysToBuyPensPencils($total, $cost1, $cost2) {", "container": "Solution", "callable": "waysToBuyPensPencils", "parameters": [{"name": "total", "type": "Integer"}, {"name": "cost1", "type": "Integer"}, {"name": "cost2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2242, "task_id": "maximum-score-of-a-node-sequence", "difficulty": "Hard", "problem_description": "There is an undirected graph with n nodes, numbered from 0 to n - 1.\n\nYou are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i.\n\nA node sequence is valid if it meets the following conditions:\n\n- There is an edge connecting every pair of adjacent nodes in the sequence.\n- No node appears more than once in the sequence.\n\nThe score of a node sequence is defined as the sum of the scores of the nodes in the sequence.\n\nReturn the maximum score of a valid node sequence with a length of 4. If no such sequence exists, return -1.\n\nExample 1:\n\nInput: scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]\nOutput: 24\nExplanation: The figure above shows the graph and the chosen node sequence [0,1,2,3].\nThe score of the node sequence is 5 + 2 + 9 + 8 = 24.\nIt can be shown that no other node sequence has a score of more than 24.\nNote that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.\nThe sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.\n\nExample 2:\n\nInput: scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]\nOutput: -1\nExplanation: The figure above shows the graph.\nThere are no valid node sequences of length 4, so we return -1.\n\nConstraints:\n\n- n == scores.length\n- 4 <= n <= 5 * 10^4\n- 1 <= scores[i] <= 10^8\n- 0 <= edges.length <= 5 * 10^4\n- edges[i].length == 2\n- 0 <= a_i, b_i <= n - 1\n- a_i != b_i\n- There are no duplicate edges.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(scores = [5, 2, 9, 8, 4],edges = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3], [2, 4]]) == 24\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 4\n assert candidate(scores = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 0]]) == 40\n assert candidate(scores = [9, 20, 6, 4, 11, 12],edges = [[0, 3], [5, 3], [2, 4], [1, 3]]) == -1\n assert candidate(scores = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 40\n assert candidate(scores = [10, 20, 30, 40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 140\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == 20\n assert candidate(scores = [10, 10, 10, 10, 10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 40\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 20\n assert candidate(scores = [1, 2, 3, 4],edges = [[0, 1], [1, 2], [2, 3]]) == 10\n assert candidate(scores = [90, 80, 70, 60, 50, 40, 30, 20, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [0, 8], [1, 7], [2, 6], [3, 5]]) == 300\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 5], [6, 7], [8, 9], [0, 4], [1, 3], [2, 5], [4, 6], [5, 7], [0, 8], [1, 9], [4, 7], [6, 8], [7, 9], [0, 5], [1, 6], [2, 4], [3, 7], [0, 7], [1, 8], [2, 9], [3, 6], [4, 8], [5, 9]]) == 340\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == 540\n assert candidate(scores = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 111100000\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 3400\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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, 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, 0], [14, 1]]) == 540\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 2], [1, 3], [4, 6], [5, 7], [0, 4], [1, 5], [2, 6], [3, 7], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [0, 8], [1, 6], [2, 7], [3, 8], [4, 9]]) == 34\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [19, 0], [0, 5], [5, 10], [10, 15]]) == 4\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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]]) == 540\n assert candidate(scores = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 340000000\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 4], [5, 9]]) == 34\n assert candidate(scores = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 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, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14], [14, 0]]) == 200\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 340\n assert candidate(scores = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 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, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 0]]) == 48\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 19]]) == 4\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == 2200\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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]]) == 20\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]]) == 180\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2], [0, 1]]) == -1\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 2], [1, 3], [4, 6], [5, 7]]) == 3400\n assert candidate(scores = [5, 15, 10, 20, 25, 30, 5, 10, 15, 20],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 3], [3, 6], [6, 9], [1, 4], [4, 7]]) == 85\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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, 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, 0], [19, 1]]) == 74\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 34\n assert candidate(scores = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 0]]) == 64\n assert candidate(scores = [5, 10, 15, 20, 25, 30, 35, 40],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [0, 7], [5, 6], [5, 4], [6, 3], [7, 0]]) == 130\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 9], [0, 1], [1, 9], [1, 2], [2, 9], [2, 3], [3, 9], [3, 4], [4, 9], [4, 5], [5, 9], [5, 6], [6, 9], [6, 7], [7, 9], [7, 8], [8, 9]]) == 34\n assert candidate(scores = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 4], [3, 7], [3, 8]]) == 330000000\n assert candidate(scores = [50, 20, 30, 40, 10, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 4], [5, 9]]) == 340\n assert candidate(scores = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],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]]) == 400\n assert candidate(scores = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],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, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14], [14, 0], [1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 1], [1, 5], [5, 9], [9, 13], [13, 1]]) == 270\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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, 0]]) == 20\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 0]]) == 3400\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [19, 0], [0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10]]) == 4\n assert candidate(scores = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 40\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],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, 9], [9, 14], [14, 19], [19, 4], [4, 9], [9, 14], [0, 7], [7, 12], [12, 17]]) == 740\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 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]]) == 114\n assert candidate(scores = [9, 8, 7, 6, 5, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8]]) == 30\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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, 14]]) == 540\n assert candidate(scores = [100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 2], [2, 4], [4, 6], [6, 0]]) == 400000000\n assert candidate(scores = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [0, 7], [1, 3], [2, 4], [0, 5], [1, 6], [0, 6], [2, 7]]) == 399999994\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],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, 9], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [11, 13], [12, 14], [15, 17], [16, 18]]) == 740\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 2], [1, 3], [4, 6], [5, 7], [2, 4], [3, 5]]) == 20\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 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],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]]) == 154\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 0], [8, 1], [9, 2]]) == 3400\n assert candidate(scores = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991, 99999990, 99999989, 99999988, 99999987, 99999986],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]]) == 399999994\n assert candidate(scores = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],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], [7, 12], [12, 4], [1, 8], [8, 13]]) == 104\n assert candidate(scores = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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]]) == 20\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],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, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14], [14, 0]]) == 540\n assert candidate(scores = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]]) == 4\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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]]) == 54\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[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], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == 340\n assert candidate(scores = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],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]]) == 144\n assert candidate(scores = [100, 200, 300, 400, 500],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [0, 2], [1, 3], [2, 0], [3, 1], [4, 2]]) == 1400\n assert candidate(scores = [100000000, 1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 4], [5, 9]]) == 100000024\n assert candidate(scores = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == 340000000\n assert candidate(scores = [50, 40, 30, 20, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 140\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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], [7, 12], [12, 4], [1, 8], [8, 13]]) == 54\n assert candidate(scores = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == 340\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],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], [6, 3], [3, 9], [9, 1], [1, 7], [7, 4], [4, 10], [10, 5], [5, 11], [11, 2], [2, 8], [8, 0]]) == 420\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 340\n assert candidate(scores = [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],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, 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, 21], [20, 22], [21, 23], [22, 24], [23, 0], [24, 1]]) == 200\n assert candidate(scores = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [1, 7], [2, 8], [2, 9], [3, 10], [3, 11], [4, 12], [4, 13], [5, 14]]) == 310\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14]]) == -1\n assert candidate(scores = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 4], [4, 8], [8, 3], [3, 7], [7, 2], [2, 6], [6, 1], [1, 5]]) == 1900\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 0], [9, 1]]) == 28\n assert candidate(scores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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, 19]]) == 74\n assert candidate(scores = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],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, 14]]) == 5400\n", "comparison": "exact"}, "public_tests": ["[5,2,9,8,4]\n[[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]", "[9,20,6,4,11,12]\n[[0,3],[5,3],[2,4],[1,3]]"], "hints": ["For every node sequence of length 4, there are 3 relevant edges. How can we consider valid triplets of edges?", "Fix the middle 2 nodes connected by an edge in the node sequence. Can you determine the other 2 nodes that will give the highest possible score?", "The other 2 nodes must each be connected to one of the middle nodes. If we only consider nodes with the highest scores, how many should we store to ensure we don’t choose duplicate nodes?", "For each node, we should store the 3 adjacent nodes with the highest scores to ensure we can find a sequence with no duplicate nodes via the method above."], "metadata": {"canonical_parameter_names": ["scores", "edges"], "leetcode_dataset_entry_point": "Solution().maximumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:04+00:00", "tests_total": 80, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "graph", "sorting", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function maximumScore($scores, $edges) {", "container": "Solution", "callable": "maximumScore", "parameters": [{"name": "scores", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2243, "task_id": "calculate-digit-sum-of-a-string", "difficulty": "Easy", "problem_description": "You are given a string s consisting of digits and an integer k.\n\nA round can be completed if the length of s is greater than k. In one round, do the following:\n\n1. Divide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k.\n2. Replace each group of s with a string representing the sum of all its digits. For example, \"346\" is replaced with \"13\" because 3 + 4 + 6 = 13.\n3. Merge consecutive groups together to form a new string. If the length of the string is greater than k, repeat from step 1.\n\nReturn s after all rounds have been completed.\n\nExample 1:\n\nInput: s = \"11111222223\", k = 3\nOutput: \"135\"\nExplanation:\n- For the first round, we divide s into groups of size 3: \"111\", \"112\", \"222\", and \"23\".\n Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.\n So, s becomes \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" after the first round.\n- For the second round, we divide s into \"346\" and \"5\".\n Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.\n So, s becomes \"13\" + \"5\" = \"135\" after second round.\nNow, s.length <= k, so we return \"135\" as the answer.\n\nExample 2:\n\nInput: s = \"00000000\", k = 3\nOutput: \"000\"\nExplanation:\nWe divide s into \"000\", \"000\", and \"00\".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.\ns becomes \"0\" + \"0\" + \"0\" = \"000\", whose length is equal to k, so we return \"000\".\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 2 <= k <= 100\n- s consists of digits only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"00000000\",k = 3) == \"000\"\n assert candidate(s = \"111\",k = 5) == \"111\"\n assert candidate(s = \"987654321\",k = 2) == \"36\"\n assert candidate(s = \"11111222223\",k = 3) == \"135\"\n assert candidate(s = \"9876543210\",k = 2) == \"36\"\n assert candidate(s = \"123\",k = 5) == \"123\"\n assert candidate(s = \"9999999999\",k = 5) == \"4545\"\n assert candidate(s = \"1234567890\",k = 2) == \"99\"\n assert candidate(s = \"111\",k = 2) == \"21\"\n assert candidate(s = \"56789\",k = 4) == \"269\"\n assert candidate(s = \"999999999999999999\",k = 5) == \"2214\"\n assert candidate(s = \"9876543210\",k = 5) == \"3510\"\n assert candidate(s = \"22222222222222222222222222222222\",k = 10) == \"2020204\"\n assert candidate(s = \"369121518212427303336394245485154576063666972757881848790939699\",k = 12) == \"414756647424\"\n assert candidate(s = \"222222222222222222222222222222222\",k = 7) == \"165\"\n assert candidate(s = \"56565656565656565656\",k = 8) == \"444422\"\n assert candidate(s = \"0123456789012345678901234567890123456789\",k = 10) == \"45454545\"\n assert candidate(s = \"1001001001001001001001001001001\",k = 5) == \"92\"\n assert candidate(s = \"55555555555555555555555555555555555555555555555555\",k = 33) == \"16585\"\n assert candidate(s = \"8888888888888888888888888888888888888888888888888\",k = 18) == \"144144104\"\n assert candidate(s = \"55555555555555555555555555555555555555555555555555\",k = 5) == \"1816\"\n assert candidate(s = \"9999999999999999999999999999999999999999999999999\",k = 25) == \"225216\"\n assert candidate(s = \"111111111111111111111111111111111111111111111111111\",k = 11) == \"111111117\"\n assert candidate(s = \"13579135791357913579\",k = 3) == \"73\"\n assert candidate(s = \"0123456789012345678901234567890123456789012345678901234567890\",k = 11) == \"585\"\n assert candidate(s = \"00000000000000000000\",k = 15) == \"00\"\n assert candidate(s = \"01234567890123456789012345678901234567890123456789\",k = 12) == \"4650545817\"\n assert candidate(s = \"99999999999999999999999999999999\",k = 15) == \"13513518\"\n assert candidate(s = \"246802468024680246802468024680246802468024680246802468024680246\",k = 7) == \"22257\"\n assert candidate(s = \"11111111111111111111\",k = 20) == \"11111111111111111111\"\n assert candidate(s = \"19876543210987654321098765432109876543210987654321\",k = 23) == \"10810810\"\n assert candidate(s = \"3336669991234567890123456789012345678901234567890\",k = 22) == \"1059930\"\n assert candidate(s = \"555555555555555555555555555555555555555555555555\",k = 4) == \"168\"\n assert candidate(s = \"4738691209384762938746293874623987462938746293874623987462938\",k = 6) == \"243\"\n assert candidate(s = \"2222222222222222222222222222222222222222222222\",k = 3) == \"281\"\n assert candidate(s = \"111222333444555666777888999000111222333444555\",k = 9) == \"184572936\"\n assert candidate(s = \"9999999999\",k = 4) == \"189\"\n assert candidate(s = \"432143214321432143214321432143214321432143214321\",k = 6) == \"201612\"\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111111111\",k = 10) == \"59\"\n assert candidate(s = \"12345678901234567890\",k = 4) == \"9126\"\n assert candidate(s = \"4321098765432109876543210987654321098765432109876\",k = 7) == \"3415\"\n assert candidate(s = \"9999999999999999999999999999999999999999999999999999999999999\",k = 2) == \"99\"\n assert candidate(s = \"5972841563974856321\",k = 4) == \"86\"\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111\",k = 40) == \"4020\"\n assert candidate(s = \"111222333444555666777888999000111\",k = 8) == \"381\"\n assert candidate(s = \"10101010101010101010101010101010101010101010101010\",k = 10) == \"55555\"\n assert candidate(s = \"111111111111111111111111111111111111111111111111111\",k = 25) == \"25251\"\n assert candidate(s = \"55555555555555555555555555555555555555555555555555\",k = 20) == \"10010050\"\n assert candidate(s = \"000000000000000000000000000000000000000000000000000\",k = 25) == \"000\"\n assert candidate(s = \"1234512345123451234512345123451234\",k = 6) == \"2413\"\n assert candidate(s = \"11111222223333344444\",k = 5) == \"122\"\n assert candidate(s = \"012345678901234567890123456789012345678901234567890123456789\",k = 5) == \"1314\"\n assert candidate(s = \"123456789012345678901234567890\",k = 10) == \"454545\"\n assert candidate(s = \"923847239874239874239874239874239874239874239874239874239874\",k = 10) == \"537\"\n assert candidate(s = \"9876543210987654321098765432109876543210\",k = 15) == \"805545\"\n assert candidate(s = \"112233445566778899001122334455667788990011223344\",k = 12) == \"42546638\"\n assert candidate(s = \"55555555555555555555\",k = 10) == \"5050\"\n assert candidate(s = \"24681357911131517191\",k = 7) == \"292324\"\n assert candidate(s = \"123123123123123123123123123123123123123123123123123123123123123123123123123123123123\",k = 22) == \"43444536\"\n assert candidate(s = \"111122223333444455556666777788889999\",k = 8) == \"279\"\n assert candidate(s = \"000000000000000000000000000000000000000000000000000000000000\",k = 20) == \"000\"\n assert candidate(s = \"1111111111222222222233333333334444444444\",k = 8) == \"262\"\n assert candidate(s = \"11111111111111111111111111111111\",k = 7) == \"77774\"\n assert candidate(s = \"222444666888000222444666888000\",k = 12) == \"603624\"\n assert candidate(s = \"123456789123456789123456789123456789123456789\",k = 11) == \"485256609\"\n assert candidate(s = \"12345678901234567890123456789012345678901234567890\",k = 15) == \"60756030\"\n assert candidate(s = \"123456789012345678901234567890123456789012345678901234567890\",k = 8) == \"3024\"\n assert candidate(s = \"13579135791357913579\",k = 6) == \"217\"\n assert candidate(s = \"43210987654321098765432109876543210987654321098765\",k = 15) == \"55805535\"\n assert candidate(s = \"111222333444555666777888999\",k = 6) == \"2214\"\n assert candidate(s = \"10101010101010101010\",k = 5) == \"3232\"\n assert candidate(s = \"12312312312312312312\",k = 3) == \"21\"\n assert candidate(s = \"55555555555555555555555555555555\",k = 10) == \"50505010\"\n assert candidate(s = \"98765432109876543210987654321098765432109876543210\",k = 6) == \"262215\"\n assert candidate(s = \"1234567890098765432112345678900987654321\",k = 25) == \"10575\"\n assert candidate(s = \"999999999999999999999999999999999999999999999999999\",k = 10) == \"459\"\n assert candidate(s = \"99999999999999999999\",k = 9) == \"818118\"\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111\",k = 13) == \"1313131310\"\n assert candidate(s = \"55555555555555555555555555555555555555555555555555\",k = 10) == \"5050505050\"\n assert candidate(s = \"87654321098765432109\",k = 6) == \"189\"\n assert candidate(s = \"0987654321098765432109876543210987654321098765432109876543210987654321\",k = 18) == \"87837966\"\n assert candidate(s = \"111122223333444455556666777788889999\",k = 5) == \"153\"\n assert candidate(s = \"48375926195487326594873265984736259847326598473265984732659\",k = 12) == \"6364726064\"\n assert candidate(s = \"111111111111111111111111111111111111111111111111111\",k = 9) == \"999996\"\n assert candidate(s = \"987654321098765432109876543210\",k = 11) == \"545328\"\n assert candidate(s = \"24680246802468024680\",k = 4) == \"5129\"\n assert candidate(s = \"000111222333444555666777888999\",k = 11) == \"155565\"\n assert candidate(s = \"101010101010101010101010101010101010101010101010101\",k = 8) == \"4444442\"\n assert candidate(s = \"00000000000000000000000000000000000000000000000000\",k = 12) == \"00000\"\n assert candidate(s = \"99999999999999999999999999999999999999999999999999999999999999999999\",k = 20) == \"18018018072\"\n assert candidate(s = \"56789012345678901234567890\",k = 6) == \"2015\"\n assert candidate(s = \"111222333444555666777888999000111222333444555666777888999000\",k = 9) == \"4518\"\n assert candidate(s = \"8888888888888888888888888888888888888888\",k = 2) == \"41\"\n assert candidate(s = \"99999999999999999999999999999999999999999999999999\",k = 20) == \"18018090\"\n assert candidate(s = \"0000000000000000000000000000000000000000\",k = 100) == \"0000000000000000000000000000000000000000\"\n assert candidate(s = \"102030405060708090\",k = 3) == \"711\"\n assert candidate(s = \"987654321098765432109876543210\",k = 3) == \"99\"\n assert candidate(s = \"9999999999\",k = 2) == \"99\"\n assert candidate(s = \"12345678901234567890\",k = 10) == \"4545\"\n assert candidate(s = \"98765432109876543210987654321098765432109876543210\",k = 18) == \"898551\"\n assert candidate(s = \"12345678901234567890\",k = 7) == \"282735\"\n assert candidate(s = \"111222333444555666777888999000111222333444555666777888999000\",k = 10) == \"4113\"\n assert candidate(s = \"543210543210543210543210543210\",k = 12) == \"303015\"\n assert candidate(s = \"987654321098765432109876543210987654321098765432109876543210\",k = 12) == \"6258545046\"\n", "comparison": "exact"}, "public_tests": ["\"11111222223\"\n3", "\"00000000\"\n3"], "hints": ["Try simulating the entire process to find the final answer."], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().digitSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:06+00:00", "tests_total": 109, "tests_dropped": 5, "flags": [], "topic_tags": ["string", "simulation"]}, "language": "php", "interface": {"raw_signature": "function digitSum($s, $k) {", "container": "Solution", "callable": "digitSum", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2244, "task_id": "minimum-rounds-to-complete-all-tasks", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.\n\nReturn the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.\n\nExample 1:\n\nInput: tasks = [2,2,3,3,2,4,4,4,4,4]\nOutput: 4\nExplanation: To complete all the tasks, a possible plan is:\n- In the first round, you complete 3 tasks of difficulty level 2.\n- In the second round, you complete 2 tasks of difficulty level 3.\n- In the third round, you complete 3 tasks of difficulty level 4.\n- In the fourth round, you complete 2 tasks of difficulty level 4.\nIt can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.\n\nExample 2:\n\nInput: tasks = [2,3,3]\nOutput: -1\nExplanation: There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.\n\nConstraints:\n\n- 1 <= tasks.length <= 10^5\n- 1 <= tasks[i] <= 10^9\n\nNote: This question is the same as 2870: Minimum Number of Operations to Make Array Empty.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 5\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 5\n assert candidate(tasks = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 7\n assert candidate(tasks = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(tasks = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 5\n assert candidate(tasks = [1]) == -1\n assert candidate(tasks = [2, 3, 3]) == -1\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 10\n assert candidate(tasks = [2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 7\n assert candidate(tasks = [1, 1, 1, 1, 1, 1]) == 2\n assert candidate(tasks = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 8\n assert candidate(tasks = [10, 10, 10, 20, 20, 30, 30, 30, 30]) == 4\n assert candidate(tasks = [2, 2, 3, 3, 2, 4, 4, 4, 4, 4]) == 4\n assert candidate(tasks = [1, 2, 3, 4, 5]) == -1\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(tasks = [5, 5, 5, 5, 5, 5]) == 2\n assert candidate(tasks = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 6\n assert candidate(tasks = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 5\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(tasks = [1, 1, 1, 2, 2, 2, 3]) == -1\n assert candidate(tasks = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 4\n assert candidate(tasks = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 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(tasks = [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]) == -1\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 9\n assert candidate(tasks = [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]) == 9\n assert candidate(tasks = [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]) == 11\n assert candidate(tasks = [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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 13\n assert candidate(tasks = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 300, 300, 300, 300, 300]) == 10\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 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(tasks = [1, 1, 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, 3, 3, 3, 3, 3, 3, 3, 3]) == 14\n assert candidate(tasks = [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]) == 16\n assert candidate(tasks = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 15\n assert candidate(tasks = [400, 400, 400, 400, 500, 500, 500, 500, 500, 600, 600, 600, 600, 600, 600, 700, 700, 700, 700, 700, 700, 700]) == 9\n assert candidate(tasks = [1, 1, 1, 2, 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]) == 13\n assert candidate(tasks = [1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 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]) == 17\n assert candidate(tasks = [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]) == 16\n assert candidate(tasks = [3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 14\n assert candidate(tasks = [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\n assert candidate(tasks = [100, 100, 100, 101, 101, 101, 101, 101, 102, 102, 102, 103, 103, 103, 103, 103, 103, 104, 104]) == 7\n assert candidate(tasks = [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(tasks = [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, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]) == 16\n assert candidate(tasks = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 13\n assert candidate(tasks = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == -1\n assert candidate(tasks = [7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 11\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 8\n assert candidate(tasks = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 19\n assert candidate(tasks = [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]) == 15\n assert candidate(tasks = [6, 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]) == 13\n assert candidate(tasks = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 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(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == -1\n assert candidate(tasks = [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]) == 10\n assert candidate(tasks = [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, 6, 6, 6, 6, 6, 6]) == 14\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(tasks = [1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 14\n assert candidate(tasks = [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]) == 9\n", "comparison": "exact"}, "public_tests": ["[2,2,3,3,2,4,4,4,4,4]", "[2,3,3]"], "hints": ["Which data structure can you use to store the number of tasks of each difficulty level?", "For any particular difficulty level, what can be the optimal strategy to complete the tasks using minimum rounds?", "When can we not complete all tasks of a difficulty level?"], "metadata": {"canonical_parameter_names": ["tasks"], "leetcode_dataset_entry_point": "Solution().minimumRounds", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:09+00:00", "tests_total": 58, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function minimumRounds($tasks) {", "container": "Solution", "callable": "minimumRounds", "parameters": [{"name": "tasks", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2245, "task_id": "maximum-trailing-zeros-in-a-cornered-path", "difficulty": "Medium", "problem_description": "You are given a 2D integer array grid of size m x n, where each cell contains a positive integer.\n\nA cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.\n\nThe product of a path is defined as the product of all the values in the path.\n\nReturn the maximum number of trailing zeros in the product of a cornered path found in grid.\n\nNote:\n\n- Horizontal movement means moving in either the left or right direction.\n- Vertical movement means moving in either the up or down direction.\n\nExample 1:\n\nInput: grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]\nOutput: 3\nExplanation: The grid on the left shows a valid cornered path.\nIt has a product of 15 * 20 * 6 * 1 * 10 = 18000 which has 3 trailing zeros.\nIt can be shown that this is the maximum trailing zeros in the product of a cornered path.\n\nThe grid in the middle is not a cornered path as it has more than one turn.\nThe grid on the right is not a cornered path as it requires a return to a previously visited cell.\n\nExample 2:\n\nInput: grid = [[4,3,2],[7,6,1],[8,8,8]]\nOutput: 0\nExplanation: The grid is shown in the figure above.\nThere are no cornered paths in the grid that result in a product with a trailing zero.\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- 1 <= grid[i][j] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 0\n assert candidate(grid = [[5, 10, 15], [20, 25, 30], [35, 40, 45]]) == 5\n assert candidate(grid = [[2, 4, 6, 8], [10, 20, 30, 40], [50, 60, 70, 80]]) == 6\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 = [[23, 17, 15, 3, 20], [8, 1, 20, 27, 11], [9, 4, 6, 2, 21], [40, 9, 1, 10, 6], [22, 7, 4, 5, 3]]) == 3\n assert candidate(grid = [[10, 5, 2], [6, 3, 8], [4, 7, 1]]) == 2\n assert candidate(grid = [[2, 5], [10, 5]]) == 2\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 1\n assert candidate(grid = [[4, 3, 2], [7, 6, 1], [8, 8, 8]]) == 0\n assert candidate(grid = [[2, 4, 8, 16], [3, 6, 12, 24], [5, 10, 20, 40]]) == 4\n assert candidate(grid = [[8, 8, 8, 8], [5, 5, 5, 5], [10, 10, 10, 10], [20, 20, 20, 20]]) == 6\n assert candidate(grid = [[4, 5, 25, 20], [8, 12, 15, 30], [10, 6, 2, 24], [20, 2, 5, 4]]) == 6\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]]) == 5\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]]) == 6\n assert candidate(grid = [[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]]) == 13\n assert candidate(grid = [[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]) == 24\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]]) == 3\n assert candidate(grid = [[25, 50, 75, 100], [5, 10, 15, 20], [1, 2, 3, 4], [125, 250, 375, 500]]) == 9\n assert candidate(grid = [[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]]) == 1\n assert candidate(grid = [[12, 15, 25, 20, 5], [2, 4, 16, 40, 100], [10, 20, 30, 40, 50], [5, 10, 15, 20, 25]]) == 9\n assert candidate(grid = [[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]]) == 11\n assert candidate(grid = [[125, 250, 500], [25, 50, 100], [5, 10, 20]]) == 7\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 6, 10, 14, 18], [4, 12, 20, 28, 36], [8, 24, 40, 56, 72], [16, 48, 80, 112, 144]]) == 5\n assert candidate(grid = [[1, 2, 4, 8, 16], [3, 6, 12, 24, 48], [5, 10, 20, 40, 80], [7, 14, 28, 56, 112], [9, 18, 36, 72, 144]]) == 5\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]]) == 9\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 90]]) == 1\n assert candidate(grid = [[8, 12, 15, 25, 20, 5], [4, 16, 40, 100, 8, 2], [10, 20, 30, 40, 50, 10], [5, 10, 15, 20, 25, 12], [2, 6, 10, 15, 20, 25], [3, 5, 10, 15, 20, 25]]) == 11\n assert candidate(grid = [[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(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]]) == 0\n assert candidate(grid = [[2, 4, 8, 16, 32, 64, 128], [1, 3, 5, 7, 9, 11, 13], [25, 50, 75, 100, 125, 150, 175]]) == 11\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, 4]]) == 0\n assert candidate(grid = [[4, 8, 16, 32, 64], [2, 4, 8, 16, 32], [1, 2, 4, 8, 16], [128, 64, 32, 16, 8], [4, 2, 1, 2, 4]]) == 0\n assert candidate(grid = [[2, 3, 5, 7, 11], [4, 6, 10, 14, 22], [8, 12, 20, 28, 44], [16, 24, 40, 56, 88], [32, 48, 80, 112, 176]]) == 5\n assert candidate(grid = [[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]]) == 10\n assert candidate(grid = [[20, 40, 60, 80, 100], [10, 20, 30, 40, 50], [1, 2, 3, 4, 5], [5, 10, 15, 20, 25], [2, 4, 6, 8, 10]]) == 12\n assert candidate(grid = [[2, 3, 5, 7, 11, 13, 17, 19, 23, 29], [30, 31, 37, 41, 43, 47, 53, 59, 61, 67], [71, 73, 79, 83, 89, 97, 101, 103, 107, 109]]) == 2\n assert candidate(grid = [[2, 3, 5, 7], [15, 21, 25, 35], [50, 75, 125, 175], [100, 150, 250, 350]]) == 7\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]]) == 7\n assert candidate(grid = [[8, 6, 2, 10, 5], [2, 5, 1, 9, 4], [3, 6, 5, 1, 7], [8, 4, 3, 9, 6], [5, 2, 1, 8, 4]]) == 3\n assert candidate(grid = [[2, 5, 10, 20, 25], [4, 8, 12, 16, 32], [3, 6, 9, 12, 15], [5, 10, 15, 20, 25], [2, 4, 8, 16, 32]]) == 8\n assert candidate(grid = [[400, 200, 100], [200, 100, 50], [100, 50, 25]]) == 10\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]) == 2\n assert candidate(grid = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [11, 22, 33, 44, 55]]) == 9\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], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55], [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33]]) == 14\n assert candidate(grid = [[32, 32, 32, 32, 32], [64, 64, 64, 64, 64], [128, 128, 128, 128, 128], [256, 256, 256, 256, 256], [512, 512, 512, 512, 512]]) == 0\n assert candidate(grid = [[12, 18, 15, 30, 25], [16, 20, 24, 10, 5], [21, 14, 7, 35, 40], [8, 12, 16, 40, 25], [15, 25, 35, 20, 40]]) == 9\n assert candidate(grid = [[999, 1000, 500, 250], [10, 5, 2, 1], [15, 3, 6, 12], [7, 14, 28, 56], [21, 42, 84, 168]]) == 9\n assert candidate(grid = [[50, 25, 10, 5, 2], [2, 5, 10, 25, 50], [10, 25, 50, 125, 250], [250, 125, 50, 25, 10], [10, 25, 50, 125, 250]]) == 7\n assert candidate(grid = [[3, 6, 9, 12, 15], [18, 21, 24, 27, 30], [33, 36, 39, 42, 45], [48, 51, 54, 57, 60]]) == 4\n assert candidate(grid = [[2, 5, 2, 5, 2, 5, 2, 5, 2, 5], [5, 2, 5, 2, 5, 2, 5, 2, 5, 2], [2, 5, 2, 5, 2, 5, 2, 5, 2, 5], [5, 2, 5, 2, 5, 2, 5, 2, 5, 2]]) == 6\n assert candidate(grid = [[20, 5, 10], [4, 15, 50], [10, 10, 10]]) == 5\n assert candidate(grid = [[20, 50, 25], [5, 10, 15], [2, 4, 8]]) == 6\n assert candidate(grid = [[2, 5, 10, 20], [1, 10, 100, 1000], [4, 20, 100, 500], [8, 40, 200, 1000]]) == 13\n assert candidate(grid = [[12, 25, 50], [6, 100, 200], [15, 5, 5]]) == 6\n assert candidate(grid = [[2, 4, 8, 16, 32], [3, 6, 12, 24, 48], [5, 10, 20, 40, 80], [15, 30, 60, 120, 240], [45, 90, 180, 360, 720]]) == 7\n assert candidate(grid = [[2, 5, 2, 5, 2, 5, 2, 5, 2, 5], [5, 2, 5, 2, 5, 2, 5, 2, 5, 2], [2, 5, 2, 5, 2, 5, 2, 5, 2, 5], [5, 2, 5, 2, 5, 2, 5, 2, 5, 2], [2, 5, 2, 5, 2, 5, 2, 5, 2, 5], [5, 2, 5, 2, 5, 2, 5, 2, 5, 2]]) == 7\n assert candidate(grid = [[100, 200, 300, 400, 500], [2, 4, 6, 8, 10], [5, 10, 15, 20, 25], [10, 20, 30, 40, 50]]) == 15\n assert candidate(grid = [[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(grid = [[2, 3, 5, 7, 11, 13, 17, 19, 23, 29], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [4, 8, 12, 16, 20, 24, 28, 32, 36, 40], [25, 50, 75, 100, 125, 150, 175, 200, 225, 250], [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]]) == 15\n assert candidate(grid = [[1000, 1000, 1000], [1000, 1000, 1000], [1000, 1000, 1000]]) == 15\n assert candidate(grid = [[12, 15, 20, 25, 30], [24, 30, 35, 40, 45], [50, 55, 60, 65, 70], [75, 80, 85, 90, 95], [100, 105, 110, 115, 120]]) == 11\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]]) == 3\n assert candidate(grid = [[998, 999, 1000], [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == 4\n assert candidate(grid = [[2, 4, 8, 16, 32], [3, 6, 12, 24, 48], [5, 10, 20, 40, 80], [7, 14, 28, 56, 112], [11, 22, 44, 88, 176]]) == 5\n assert candidate(grid = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [25, 50, 75, 100, 125, 150, 175, 200, 225, 250], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30], [35, 70, 105, 140, 175, 210, 245, 280, 315, 350], [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]]) == 16\n assert candidate(grid = [[6, 2, 3, 10, 15], [2, 4, 5, 20, 25], [3, 6, 9, 30, 45], [4, 8, 12, 40, 60], [5, 10, 15, 50, 75]]) == 9\n assert candidate(grid = [[25, 16, 4, 2], [5, 10, 20, 8], [1, 12, 6, 4], [3, 6, 9, 15]]) == 5\n assert candidate(grid = [[4, 3, 2, 1, 5], [7, 6, 1, 8, 9], [8, 8, 8, 1, 2], [1, 1, 1, 3, 4]]) == 1\n assert candidate(grid = [[8, 16, 32, 64, 128], [4, 8, 16, 32, 64], [2, 4, 8, 16, 32], [1, 2, 4, 8, 16], [1, 1, 1, 1, 2]]) == 0\n assert candidate(grid = [[2, 5, 10, 15], [20, 25, 30, 35], [40, 45, 50, 55], [60, 65, 70, 75]]) == 7\n assert candidate(grid = [[5, 10, 15, 20, 25], [1, 2, 3, 4, 5], [6, 12, 18, 24, 30], [7, 14, 21, 28, 35], [8, 16, 24, 32, 40]]) == 7\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]]) == 3\n assert candidate(grid = [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512], [512, 256, 128, 64, 32, 16, 8, 4, 2, 1], [1, 5, 10, 15, 20, 25, 30, 35, 40, 45], [45, 40, 35, 30, 25, 20, 15, 10, 5, 1]]) == 11\n assert candidate(grid = [[12, 34, 56, 78, 90], [23, 45, 67, 89, 101], [123, 145, 167, 189, 201], [11, 22, 33, 44, 55], [66, 77, 88, 99, 110]]) == 3\n assert candidate(grid = [[4, 8, 16, 32, 64, 128, 256], [3, 6, 12, 24, 48, 96, 192], [5, 10, 20, 40, 80, 160, 320], [7, 14, 28, 56, 112, 224, 448]]) == 7\n assert candidate(grid = [[2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]]) == 3\n", "comparison": "exact"}, "public_tests": ["[[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]", "[[4,3,2],[7,6,1],[8,8,8]]"], "hints": ["What actually tells us the trailing zeros of the product of a path?", "It is the sum of the exponents of 2 and sum of the exponents of 5 of the prime factorizations of the numbers on that path. The smaller of the two is the answer for that path.", "We can then treat each cell as the elbow point and calculate the largest minimum (sum of 2 exponents, sum of 5 exponents) from the combination of top-left, top-right, bottom-left and bottom-right.", "To do this efficiently, we should use the prefix sum technique."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maxTrailingZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:11+00:00", "tests_total": 84, "tests_dropped": 8, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxTrailingZeros($grid) {", "container": "Solution", "callable": "maxTrailingZeros", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2246, "task_id": "longest-path-with-different-adjacent-characters", "difficulty": "Hard", "problem_description": "You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\n\nYou are also given a string s of length n, where s[i] is the character assigned to node i.\n\nReturn the length of the longest path in the tree such that no pair of adjacent nodes on the path have the same character assigned to them.\n\nExample 1:\n\nInput: parent = [-1,0,0,1,1,2], s = \"abacbe\"\nOutput: 3\nExplanation: The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.\nIt can be proven that there is no longer path that satisfies the conditions.\n\nExample 2:\n\nInput: parent = [-1,0,0,0], s = \"aabc\"\nOutput: 3\nExplanation: The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned.\n\nConstraints:\n\n- n == parent.length == s.length\n- 1 <= n <= 10^5\n- 0 <= parent[i] <= n - 1 for all i >= 1\n- parent[0] == -1\n- parent represents a valid tree.\n- s consists of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(parent = [-1, 0, 0, 2, 2, 2],s = \"abbccc\") == 4\n assert candidate(parent = [-1, 0, 0, 0],s = \"aabc\") == 3\n assert candidate(parent = [-1, 0, 0, 1, 1, 2],s = \"abacbe\") == 3\n assert candidate(parent = [-1, 0, 1, 2, 3, 4, 5],s = \"abcdefg\") == 7\n assert candidate(parent = [-1, 0, 0, 0, 0, 0, 0],s = \"abcdefg\") == 3\n assert candidate(parent = [-1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6],s = \"aabbaaccddcceeddffgeee\") == 5\n assert candidate(parent = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 4],s = \"abcdefghij\") == 6\n assert candidate(parent = [-1, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6],s = \"aabbccddeee\") == 5\n assert candidate(parent = [-1, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7],s = \"abcdefghijklmnopqrstuvwx\") == 7\n assert candidate(parent = [-1, 0, 0, 0, 1, 1, 2, 2, 3, 3],s = \"aababbccdd\") == 3\n assert candidate(parent = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4],s = \"abcdefghij\") == 6\n assert candidate(parent = [-1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4],s = \"aaabbbcccdd\") == 5\n", "comparison": "exact"}, "public_tests": ["[-1,0,0,1,1,2]\n\"abacbe\"", "[-1,0,0,0]\n\"aabc\""], "hints": ["Do a DFS from the root. At each node, calculate the longest path we can make from two branches of that subtree.", "To do that, we need to find the length of the longest path from each of the node’s children."], "metadata": {"canonical_parameter_names": ["parent", "s"], "leetcode_dataset_entry_point": "Solution().longestPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:14+00:00", "tests_total": 49, "tests_dropped": 37, "flags": ["has_images"], "topic_tags": ["array", "string", "tree", "depth-first-search", "graph", "topological-sort"]}, "language": "php", "interface": {"raw_signature": "function longestPath($parent, $s) {", "container": "Solution", "callable": "longestPath", "parameters": [{"name": "parent", "type": "Integer[]"}, {"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2248, "task_id": "intersection-of-multiple-arrays", "difficulty": "Easy", "problem_description": "Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.\n\nExample 1:\n\nInput: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]\nOutput: [3,4]\nExplanation:\nThe only integers present in each of nums[0] = [3,1,2,4,5], nums[1] = [1,2,3,4], and nums[2] = [3,4,5,6] are 3 and 4, so we return [3,4].\n\nExample 2:\n\nInput: nums = [[1,2,3],[4,5,6]]\nOutput: []\nExplanation:\nThere does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= sum(nums[i].length) <= 1000\n- 1 <= nums[i][j] <= 1000\n- All the values of nums[i] are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [30, 60, 70]]) == [30]\n assert candidate(nums = [[3, 1, 2, 4, 5], [1, 2, 3, 4], [3, 4, 5, 6]]) == [3, 4]\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50]]) == [30]\n assert candidate(nums = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]) == []\n assert candidate(nums = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]) == [3, 4, 5]\n assert candidate(nums = [[5, 10], [10, 15], [15, 20], [20, 25], [5, 25]]) == []\n assert candidate(nums = [[10, 20, 30], [10, 20, 40], [10, 30, 40]]) == [10]\n assert candidate(nums = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]) == [3, 4]\n assert candidate(nums = [[1, 2], [2, 3], [3, 4]]) == []\n assert candidate(nums = [[1, 2, 3, 4, 5], [2, 3, 5, 7], [3, 5, 8, 9]]) == [3, 5]\n assert candidate(nums = [[1, 2, 3], [4, 5, 6]]) == []\n assert candidate(nums = [[10, 20, 30], [10, 20, 40], [10, 30, 50]]) == [10]\n assert candidate(nums = [[2, 4, 6, 8, 10], [2, 4, 6, 8, 10, 12], [2, 4, 6, 8, 10, 12, 14], [2, 4, 6, 8, 10, 12, 14, 16]]) == [2, 4, 6, 8, 10]\n assert candidate(nums = [[1, 2, 3], [3, 2, 1], [2, 1, 3], [1, 3, 2], [3, 1, 2]]) == [1, 2, 3]\n assert candidate(nums = [[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]\n assert candidate(nums = [[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], [9, 10, 11, 12, 1], [1, 3, 5, 7, 9]]) == []\n assert candidate(nums = [[5, 10, 15, 20, 25], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40], [25, 30, 35, 40, 45], [30, 35, 40, 45, 50]]) == []\n assert candidate(nums = [[7, 14, 21, 28, 35], [14, 21, 28, 42, 56], [21, 28, 35, 42, 56, 70]]) == [21, 28]\n assert candidate(nums = [[1, 3, 5, 7, 9], [3, 5, 7, 9, 11], [5, 7, 9, 11, 13], [7, 9, 11, 13, 15]]) == [7, 9]\n assert candidate(nums = [[10, 20, 30], [30, 40, 50], [20, 30, 40], [30, 50, 60]]) == [30]\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [30, 50, 60]]) == [30]\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60], [50, 60, 70], [60, 70, 80], [70, 80, 90], [80, 90, 100], [90, 100, 110]]) == []\n assert candidate(nums = [[10, 20, 30, 40, 50], [10, 30, 50, 70], [10, 30, 50, 90]]) == [10, 30, 50]\n assert candidate(nums = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 10]]) == []\n assert candidate(nums = [[100, 200, 300], [300, 400, 500], [500, 600, 700], [700, 800, 900], [900, 1000, 100]]) == []\n assert candidate(nums = [[5, 10, 15, 20], [10, 15, 25, 30], [15, 20, 30, 35], [20, 25, 30, 35]]) == []\n assert candidate(nums = [[500, 501, 502, 503, 504, 505], [503, 504, 505, 506, 507, 508], [505, 506, 507, 508, 509, 510], [507, 508, 509, 510, 511, 512], [509, 510, 511, 512, 513, 514]]) == []\n assert candidate(nums = [[7, 11, 13], [11, 13, 15], [11, 13, 17], [11, 13, 19]]) == [11, 13]\n assert candidate(nums = [[5, 10, 15, 20], [5, 20, 25, 30], [5, 10, 20, 35], [5, 10, 15, 20, 40]]) == [5, 20]\n assert candidate(nums = [[999], [999, 998], [999, 998, 997], [999, 998, 997, 996]]) == [999]\n assert candidate(nums = [[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]]) == [3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [[5, 10, 15], [10, 15, 20], [15, 20, 25], [20, 25, 30], [25, 30, 35]]) == []\n assert candidate(nums = [[1, 3, 5, 7, 9], [3, 5, 7, 9, 11], [5, 7, 9, 11, 13], [7, 9, 11, 13, 15], [9, 11, 13, 15, 17]]) == [9]\n assert candidate(nums = [[5, 15, 25], [5, 25, 35], [25, 35, 45], [15, 25, 35], [5, 15, 25, 35]]) == [25]\n assert candidate(nums = [[100, 200, 300], [100, 400, 500], [100, 600, 700], [100, 800, 900]]) == [100]\n assert candidate(nums = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 3, 5, 7, 9], [9, 7, 5, 3, 1], [1, 5, 9, 13, 17]]) == [1, 5]\n assert candidate(nums = [[100, 200, 300, 400, 500], [100, 200, 300, 400, 600], [100, 200, 300, 500, 600], [100, 200, 400, 500, 600]]) == [100, 200]\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 3, 5, 8, 9], [3, 4, 5, 7, 9], [3, 5, 6, 7, 9]]) == [3, 5, 9]\n assert candidate(nums = [[10, 20, 30], [30, 40, 50], [10, 30, 50, 70], [30, 80, 90, 100]]) == [30]\n assert candidate(nums = [[100, 200, 300], [200, 300, 400], [300, 400, 500], [400, 500, 600]]) == []\n assert candidate(nums = [[100, 200, 300], [200, 300, 400], [300, 400, 500], [400, 500, 600], [500, 600, 700]]) == []\n assert candidate(nums = [[10, 20, 30, 40], [20, 30, 40, 50], [30, 40, 50, 60], [40, 50, 60, 70]]) == [40]\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]]) == [9, 10]\n assert candidate(nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == []\n assert candidate(nums = [[5, 10, 15, 20, 25], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40], [25, 30, 35, 40, 45]]) == [25]\n assert candidate(nums = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 3, 5, 7, 11, 13, 17, 19, 23, 29], [3, 5, 7, 11, 13, 17, 19, 23, 29, 31]]) == [3, 5, 7, 11, 13, 17, 19]\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8, 10], [3, 6, 9, 12], [6, 12, 18]]) == [6]\n assert candidate(nums = [[10, 20, 30], [10, 20, 30, 40], [10, 20, 30, 40, 50], [10, 20, 30, 40, 50, 60]]) == [10, 20, 30]\n assert candidate(nums = [[50, 100, 150, 200], [100, 150, 200, 250], [150, 200, 250, 300], [200, 250, 300, 350], [250, 300, 350, 400]]) == []\n assert candidate(nums = [[100, 200, 300], [101, 201, 301], [102, 202, 302], [103, 203, 303], [104, 204, 304], [105, 205, 305]]) == []\n assert candidate(nums = [[100, 200, 300], [200, 300, 400], [300, 400, 500], [300, 600, 900]]) == [300]\n assert candidate(nums = [[7, 14, 21, 28], [14, 21, 28, 35], [21, 28, 35, 42], [28, 35, 42, 49]]) == [28]\n assert candidate(nums = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]) == []\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]]) == [4, 8]\n assert candidate(nums = [[300, 301, 302, 303, 304, 305], [300, 301, 302, 303, 304, 305, 306], [300, 301, 302, 303, 304, 305, 307, 308]]) == [300, 301, 302, 303, 304, 305]\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 2, 3, 4, 5]]) == []\n assert candidate(nums = [[999, 1000], [1000, 999], [999, 1000, 998], [1000, 999, 998], [998, 999, 1000], [998, 1000, 999]]) == [999, 1000]\n assert candidate(nums = [[1, 1000], [1, 999], [1, 998], [1, 997], [1, 996]]) == [1]\n assert candidate(nums = [[999, 1000], [999], [999, 1000, 998], [998, 999, 997], [999, 998, 997, 1000]]) == [999]\n assert candidate(nums = [[2, 4, 6, 8, 10, 12], [4, 8, 12, 16, 20], [6, 12, 18, 24, 30], [8, 16, 24, 32, 40], [10, 20, 30, 40, 50]]) == []\n assert candidate(nums = [[5, 15, 25, 35, 45], [15, 25, 35, 45, 55], [5, 15, 25, 35, 45, 65], [15, 25, 35, 45, 75]]) == [15, 25, 35, 45]\n assert candidate(nums = [[11, 22, 33, 44, 55], [22, 33, 44, 55, 66], [33, 44, 55, 66, 77], [44, 55, 66, 77, 88], [55, 66, 77, 88, 99]]) == [55]\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 5, 9], [2, 6, 10]]) == []\n assert candidate(nums = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [20, 30, 40, 50, 60, 70, 80, 90, 100, 110], [30, 40, 50, 60, 70, 80, 90, 100, 110, 120]]) == [30, 40, 50, 60, 70, 80, 90, 100]\n assert candidate(nums = [[10, 20, 30, 40], [10, 20, 50], [10, 30, 40, 50]]) == [10]\n assert candidate(nums = [[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]]) == [50]\n assert candidate(nums = [[7, 14, 21, 28], [14, 21, 28, 35], [21, 28, 35, 42], [28, 35, 42, 49], [35, 42, 49, 56], [42, 49, 56, 63]]) == []\n assert candidate(nums = [[1], [2], [3], [4], [5]]) == []\n assert candidate(nums = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [2, 4, 6, 8, 10, 12, 14], [1, 3, 5, 7, 9, 11, 13, 15]]) == []\n assert candidate(nums = [[10, 20, 30], [20, 30, 40], [30, 40, 50], [40, 50, 60]]) == []\n assert candidate(nums = [[100], [100, 200], [100, 200, 300], [100, 200, 300, 400], [100, 200, 300, 400, 500]]) == [100]\n assert candidate(nums = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]]) == [1]\n assert candidate(nums = [[1, 3, 5, 7, 9], [2, 3, 5, 8, 9], [3, 5, 9, 11, 13], [3, 9, 15, 18, 21]]) == [3, 9]\n assert candidate(nums = [[5, 10, 15, 20, 25, 30, 35, 40, 45, 50], [10, 15, 20, 25, 30, 35, 40, 45, 50, 55], [15, 20, 25, 30, 35, 40, 45, 50, 55, 60], [20, 25, 30, 35, 40, 45, 50, 55, 60, 65]]) == [20, 25, 30, 35, 40, 45, 50]\n assert candidate(nums = [[500, 501, 502, 503, 504], [501, 502, 503, 504, 505], [502, 503, 504, 505, 506], [503, 504, 505, 506, 507]]) == [503, 504]\n assert candidate(nums = [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [9, 10, 1], [1, 11, 12], [12, 2, 13], [13, 14, 3]]) == []\n assert candidate(nums = [[1, 10, 100, 1000], [10, 100, 1000, 200], [100, 1000, 200, 300], [1000, 200, 300, 400]]) == [1000]\n assert candidate(nums = [[7, 14, 21, 28, 35], [14, 28, 42, 56, 70], [21, 42, 63, 84, 105], [14, 21, 28, 35, 42]]) == []\n assert candidate(nums = [[7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11, 12], [11, 12, 13]]) == []\n assert candidate(nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9]]) == []\n assert candidate(nums = [[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]]) == [3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [[5, 10, 15, 20, 25], [10, 15, 20, 25, 30], [15, 20, 25, 30, 35], [20, 25, 30, 35, 40]]) == [20, 25]\n assert candidate(nums = [[100, 200, 300, 400], [400, 500, 600, 700], [300, 400, 500, 600], [400, 600, 800, 900]]) == [400]\n assert candidate(nums = [[500], [500, 501, 502], [500, 502, 503], [500, 501, 503]]) == [500]\n assert candidate(nums = [[101, 202, 303], [202, 303, 404], [303, 404, 505], [404, 505, 606], [505, 606, 707], [606, 707, 808], [707, 808, 909]]) == []\n assert candidate(nums = [[7, 14, 21], [14, 21, 28], [21, 28, 35], [7, 14, 21, 28, 35]]) == [21]\n", "comparison": "exact"}, "public_tests": ["[[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]", "[[1,2,3],[4,5,6]]"], "hints": ["Keep a count of the number of times each integer occurs in nums.", "Since all integers of nums[i] are distinct, if an integer is present in each array, its count will be equal to the total number of arrays."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().intersection", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:18+00:00", "tests_total": 93, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "counting"]}, "language": "php", "interface": {"raw_signature": "function intersection($nums) {", "container": "Solution", "callable": "intersection", "parameters": [{"name": "nums", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2249, "task_id": "count-lattice-points-inside-a-circle", "difficulty": "Medium", "problem_description": "Given a 2D integer array circles where circles[i] = [x_i, y_i, r_i] represents the center (x_i, y_i) and radius r_i of the i^th circle drawn on a grid, return the number of lattice points that are present inside at least one circle.\n\nNote:\n\n- A lattice point is a point with integer coordinates.\n- Points that lie on the circumference of a circle are also considered to be inside it.\n\nExample 1:\n\nInput: circles = [[2,2,1]]\nOutput: 5\nExplanation:\nThe figure above shows the given circle.\nThe lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.\nOther points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.\nHence, the number of lattice points present inside at least one circle is 5.\n\nExample 2:\n\nInput: circles = [[2,2,2],[3,4,1]]\nOutput: 16\nExplanation:\nThe figure above shows the given circles.\nThere are exactly 16 lattice points which are present inside at least one circle.\nSome of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).\n\nConstraints:\n\n- 1 <= circles.length <= 200\n- circles[i].length == 3\n- 1 <= x_i, y_i <= 100\n- 1 <= r_i <= min(x_i, y_i)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(circles = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 33\n assert candidate(circles = [[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5]]) == 276\n assert candidate(circles = [[2, 2, 1]]) == 5\n assert candidate(circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5]]) == 243\n assert candidate(circles = [[2, 2, 2], [3, 4, 1]]) == 16\n assert candidate(circles = [[100, 100, 1]]) == 5\n assert candidate(circles = [[100, 100, 50]]) == 7845\n assert candidate(circles = [[50, 50, 50]]) == 7845\n assert candidate(circles = [[50, 50, 40], [60, 60, 10]]) == 5025\n assert candidate(circles = [[100, 100, 100]]) == 31417\n assert candidate(circles = [[1, 1, 1]]) == 5\n assert candidate(circles = [[5, 5, 1], [5, 5, 2], [5, 5, 3]]) == 29\n assert candidate(circles = [[10, 10, 5]]) == 81\n assert candidate(circles = [[50, 50, 10], [40, 40, 10], [30, 30, 10]]) == 833\n assert candidate(circles = [[1, 1, 1], [3, 3, 1]]) == 10\n assert candidate(circles = [[1, 1, 1], [2, 2, 1], [3, 3, 1]]) == 11\n assert candidate(circles = [[50, 50, 20], [60, 60, 10]]) == 1314\n assert candidate(circles = [[10, 10, 1], [20, 20, 1], [30, 30, 1]]) == 15\n assert candidate(circles = [[10, 10, 5], [20, 20, 10], [30, 30, 15]]) == 950\n assert candidate(circles = [[50, 50, 50], [50, 50, 30]]) == 7845\n assert candidate(circles = [[50, 50, 10], [50, 60, 10], [50, 70, 10], [50, 80, 10], [50, 90, 10], [50, 100, 10], [50, 40, 10], [50, 30, 10], [50, 20, 10], [50, 10, 10]]) == 2027\n assert candidate(circles = [[100, 100, 10], [90, 90, 15], [80, 80, 20], [70, 70, 25]]) == 2685\n assert candidate(circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5], [50, 50, 5], [60, 60, 5], [70, 70, 5], [80, 80, 5], [90, 90, 5]]) == 729\n assert candidate(circles = [[30, 30, 5], [40, 40, 5], [50, 50, 5], [60, 60, 5], [70, 70, 5], [80, 80, 5], [90, 90, 5]]) == 567\n assert candidate(circles = [[50, 50, 20], [50, 50, 15], [50, 50, 10], [50, 50, 5]]) == 1257\n assert candidate(circles = [[10, 10, 10], [10, 20, 10], [10, 30, 10], [10, 40, 10], [10, 50, 10], [10, 60, 10]]) == 1267\n assert candidate(circles = [[1, 1, 1], [99, 1, 1], [1, 99, 1], [99, 99, 1], [50, 50, 5]]) == 101\n assert candidate(circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5], [50, 50, 5], [60, 60, 5], [70, 70, 5], [80, 80, 5], [90, 90, 5], [100, 100, 5]]) == 810\n assert candidate(circles = [[50, 50, 20], [60, 50, 20], [70, 50, 20], [80, 50, 20]]) == 2433\n assert candidate(circles = [[25, 25, 10], [25, 75, 10], [75, 25, 10], [75, 75, 10]]) == 1268\n assert candidate(circles = [[50, 50, 1], [50, 50, 2], [50, 50, 3], [50, 50, 4], [50, 50, 5]]) == 81\n assert candidate(circles = [[10, 10, 5], [10, 20, 5], [10, 30, 5], [10, 40, 5], [10, 50, 5], [10, 60, 5]]) == 481\n assert candidate(circles = [[30, 30, 10], [60, 30, 10], [30, 60, 10], [60, 60, 10], [45, 45, 15]]) == 1837\n assert candidate(circles = [[50, 50, 20], [50, 70, 20], [50, 30, 20], [30, 50, 20], [70, 50, 20]]) == 4113\n assert candidate(circles = [[1, 50, 1], [50, 1, 1], [50, 99, 1], [99, 50, 1]]) == 20\n assert candidate(circles = [[10, 10, 10], [20, 10, 10], [30, 10, 10], [40, 10, 10], [50, 10, 10], [60, 10, 10]]) == 1267\n assert candidate(circles = [[10, 10, 5], [15, 15, 10], [20, 20, 15], [25, 25, 20]]) == 1329\n assert candidate(circles = [[25, 25, 15], [50, 25, 15], [75, 25, 15], [25, 50, 15], [50, 50, 15], [75, 50, 15], [25, 75, 15], [50, 75, 15], [75, 75, 15]]) == 5733\n assert candidate(circles = [[25, 25, 10], [25, 75, 10], [75, 25, 10], [75, 75, 10], [50, 50, 20]]) == 2525\n assert candidate(circles = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) == 56\n assert candidate(circles = [[50, 50, 50], [30, 30, 30], [70, 70, 30], [20, 20, 20], [80, 80, 20]]) == 8687\n assert candidate(circles = [[90, 90, 5], [80, 80, 5], [70, 70, 5], [60, 60, 5]]) == 324\n assert candidate(circles = [[1, 99, 1], [99, 1, 1], [50, 50, 45], [25, 25, 25], [75, 75, 25]]) == 7605\n assert candidate(circles = [[20, 20, 5], [20, 30, 5], [30, 20, 5], [30, 30, 5], [40, 40, 5], [40, 50, 5], [50, 40, 5], [50, 50, 5]]) == 640\n assert candidate(circles = [[10, 10, 1], [20, 20, 1], [30, 30, 1], [40, 40, 1], [50, 50, 1], [60, 60, 1], [70, 70, 1], [80, 80, 1], [90, 90, 1], [10, 90, 1], [90, 10, 1]]) == 55\n assert candidate(circles = [[50, 50, 20], [70, 50, 20], [50, 70, 20], [50, 30, 20]]) == 3447\n assert candidate(circles = [[10, 10, 1], [11, 11, 2], [12, 12, 3], [13, 13, 4], [14, 14, 5], [15, 15, 6], [16, 16, 7], [17, 17, 8], [18, 18, 9], [19, 19, 10]]) == 347\n assert candidate(circles = [[10, 10, 10], [20, 10, 10], [10, 20, 10], [20, 20, 10], [15, 15, 10]]) == 797\n assert candidate(circles = [[90, 90, 10], [80, 80, 15], [70, 70, 5], [60, 60, 20]]) == 2036\n assert candidate(circles = [[50, 50, 50], [60, 60, 20], [70, 70, 10], [80, 80, 5], [90, 90, 2], [100, 100, 1]]) == 7863\n assert candidate(circles = [[50, 50, 1], [50, 51, 1], [51, 50, 1], [51, 51, 1], [1, 1, 1], [99, 99, 1], [1, 99, 1], [99, 1, 1]]) == 32\n assert candidate(circles = [[50, 50, 50], [40, 40, 40], [30, 30, 30], [20, 20, 20], [10, 10, 10], [60, 60, 10], [70, 70, 10], [80, 80, 10], [90, 90, 10]]) == 8613\n assert candidate(circles = [[50, 50, 25], [25, 25, 25], [75, 75, 25]]) == 5171\n assert candidate(circles = [[10, 10, 5], [20, 10, 5], [30, 10, 5], [40, 10, 5], [50, 10, 5], [60, 10, 5]]) == 481\n assert candidate(circles = [[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]]) == 35\n assert candidate(circles = [[50, 50, 5], [50, 60, 5], [50, 70, 5], [50, 80, 5], [50, 90, 5]]) == 401\n assert candidate(circles = [[10, 10, 5], [20, 20, 5], [30, 30, 5], [40, 40, 5]]) == 324\n assert candidate(circles = [[100, 100, 10], [90, 90, 20], [80, 80, 15], [70, 70, 25]]) == 2875\n assert candidate(circles = [[25, 25, 15], [75, 75, 15], [25, 75, 15], [75, 25, 15], [50, 50, 10]]) == 3153\n assert candidate(circles = [[10, 10, 5], [20, 20, 15], [30, 30, 10], [40, 40, 20]]) == 1904\n assert candidate(circles = [[25, 25, 5], [25, 30, 5], [25, 35, 5], [25, 40, 5], [25, 45, 5]]) == 269\n assert candidate(circles = [[25, 25, 15], [45, 25, 15], [25, 45, 15], [45, 45, 15]]) == 2213\n assert candidate(circles = [[10, 90, 10], [90, 10, 10], [50, 50, 20], [60, 40, 15]]) == 2133\n assert candidate(circles = [[10, 50, 10], [20, 50, 10], [30, 50, 10], [40, 50, 10], [50, 50, 10], [60, 50, 10]]) == 1267\n assert candidate(circles = [[30, 30, 20], [40, 40, 20], [50, 50, 20], [60, 60, 20]]) == 2925\n assert candidate(circles = [[10, 10, 5], [30, 30, 5], [50, 50, 5], [70, 70, 5], [90, 90, 5]]) == 405\n assert candidate(circles = [[10, 10, 5], [15, 15, 3], [20, 20, 7]]) == 244\n assert candidate(circles = [[50, 50, 20], [60, 60, 20], [70, 70, 20], [80, 80, 20], [90, 90, 20]]) == 3481\n assert candidate(circles = [[50, 50, 50], [60, 60, 50], [70, 70, 50], [80, 80, 50]]) == 12075\n assert candidate(circles = [[10, 10, 5], [15, 15, 10], [20, 20, 15], [25, 25, 20], [30, 30, 25], [35, 35, 30], [40, 40, 35], [45, 45, 40], [50, 50, 45], [55, 55, 50]]) == 8352\n assert candidate(circles = [[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]]) == 32\n assert candidate(circles = [[75, 75, 30], [25, 25, 15], [50, 50, 10]]) == 3795\n assert candidate(circles = [[10, 10, 5], [20, 20, 10], [30, 30, 15], [40, 40, 20], [50, 50, 25]]) == 2761\n assert candidate(circles = [[30, 30, 20], [30, 70, 20], [70, 30, 20], [70, 70, 20], [50, 50, 20]]) == 5369\n assert candidate(circles = [[50, 50, 10], [51, 51, 5], [52, 52, 15], [53, 53, 20]]) == 1257\n assert candidate(circles = [[1, 1, 1], [99, 99, 1], [50, 50, 40]]) == 5035\n assert candidate(circles = [[1, 1, 1], [99, 99, 1], [50, 50, 50]]) == 7855\n assert candidate(circles = [[1, 1, 1], [1, 100, 1], [100, 1, 1], [100, 100, 1], [50, 50, 45]]) == 6381\n assert candidate(circles = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]) == 90\n assert candidate(circles = [[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]]) == 347\n assert candidate(circles = [[100, 100, 100], [1, 1, 1], [99, 99, 1]]) == 31422\n assert candidate(circles = [[50, 50, 10], [50, 60, 10], [50, 70, 10], [50, 80, 10]]) == 887\n", "comparison": "exact"}, "public_tests": ["[[2,2,1]]", "[[2,2,2],[3,4,1]]"], "hints": ["For each circle, how can you check whether or not a lattice point lies inside it?", "Since you need to reduce the search space, consider the minimum and maximum possible values of the coordinates of a lattice point contained in any circle."], "metadata": {"canonical_parameter_names": ["circles"], "leetcode_dataset_entry_point": "Solution().countLatticePoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:21+00:00", "tests_total": 114, "tests_dropped": 32, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "math", "geometry", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countLatticePoints($circles) {", "container": "Solution", "callable": "countLatticePoints", "parameters": [{"name": "circles", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2250, "task_id": "count-number-of-rectangles-containing-each-point", "difficulty": "Medium", "problem_description": "You are given a 2D integer array rectangles where rectangles[i] = [l_i, h_i] indicates that i^th rectangle has a length of l_i and a height of h_i. You are also given a 2D integer array points where points[j] = [x_j, y_j] is a point with coordinates (x_j, y_j).\n\nThe i^th rectangle has its bottom-left corner point at the coordinates (0, 0) and its top-right corner point at (l_i, h_i).\n\nReturn an integer array count of length points.length where count[j] is the number of rectangles that contain the j^th point.\n\nThe i^th rectangle contains the j^th point if 0 <= x_j <= l_i and 0 <= y_j <= h_i. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.\n\nExample 1:\n\nInput: rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]\nOutput: [2,1]\nExplanation:\nThe first rectangle contains no points.\nThe second rectangle contains only the point (2, 1).\nThe third rectangle contains the points (2, 1) and (1, 4).\nThe number of rectangles that contain the point (2, 1) is 2.\nThe number of rectangles that contain the point (1, 4) is 1.\nTherefore, we return [2, 1].\n\nExample 2:\n\nInput: rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]\nOutput: [1,3]\nExplanation:\nThe first rectangle contains only the point (1, 1).\nThe second rectangle contains only the point (1, 1).\nThe third rectangle contains the points (1, 3) and (1, 1).\nThe number of rectangles that contain the point (1, 3) is 1.\nThe number of rectangles that contain the point (1, 1) is 3.\nTherefore, we return [1, 3].\n\nConstraints:\n\n- 1 <= rectangles.length, points.length <= 5 * 10^4\n- rectangles[i].length == points[j].length == 2\n- 1 <= l_i, x_j <= 10^9\n- 1 <= h_i, y_j <= 100\n- All the rectangles are unique.\n- All the points are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rectangles = [[1, 2], [2, 3], [2, 5]],points = [[2, 1], [1, 4]]) == [2, 1]\n assert candidate(rectangles = [[10, 100], [9, 99], [8, 98], [7, 97]],points = [[10, 100], [9, 99], [8, 98], [7, 97]]) == [1, 2, 3, 4]\n assert candidate(rectangles = [[10, 1], [9, 10], [10, 10], [1, 1]],points = [[5, 5], [6, 6], [7, 7]]) == [2, 2, 2]\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3]],points = [[1, 3], [1, 1]]) == [1, 3]\n assert candidate(rectangles = [[5, 100], [10, 99], [15, 98], [20, 97], [25, 96], [30, 95]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [6, 6, 6, 6, 6, 5, 5, 5, 5, 5]\n assert candidate(rectangles = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [9, 7, 5, 3, 1, 0, 0, 0, 0]\n assert candidate(rectangles = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[10, 100], [20, 99], [30, 98], [40, 97], [50, 96], [60, 95], [70, 94], [80, 93], [90, 92], [100, 91]],points = [[5, 95], [15, 90], [25, 85], [35, 80], [45, 75], [55, 70], [65, 65], [75, 60], [85, 55], [95, 50]]) == [6, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[500000000, 100], [600000000, 100], [700000000, 100], [800000000, 100]],points = [[400000000, 50], [550000000, 55], [650000000, 65], [750000000, 75]]) == [4, 3, 2, 1]\n assert candidate(rectangles = [[100, 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], [1400, 100], [1500, 100], [1600, 100], [1700, 100], [1800, 100], [1900, 100], [2000, 100]],points = [[50, 50], [250, 50], [450, 50], [650, 50], [850, 50], [1050, 50], [1250, 50], [1450, 50], [1650, 50], [1850, 50]]) == [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]\n assert candidate(rectangles = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96], [1, 95], [1, 94], [1, 93], [1, 92], [1, 91]],points = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96], [1, 95], [1, 94], [1, 93], [1, 92], [1, 91]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(rectangles = [[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]],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]]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[300000000, 100], [600000000, 90], [900000000, 80], [1200000000, 70], [1500000000, 60]],points = [[150000000, 65], [450000000, 75], [750000000, 85], [1050000000, 95], [1350000000, 100]]) == [4, 2, 0, 0, 0]\n assert candidate(rectangles = [[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], [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, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [1, 75], [1, 76], [1, 77], [1, 78], [1, 79], [1, 80], [1, 81], [1, 82], [1, 83], [1, 84], [1, 85], [1, 86], [1, 87], [1, 88], [1, 89], [1, 90], [1, 91], [1, 92], [1, 93], [1, 94], [1, 95], [1, 96], [1, 97], [1, 98], [1, 99], [1, 100]],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], [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, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [1, 75], [1, 76], [1, 77], [1, 78], [1, 79], [1, 80], [1, 81], [1, 82], [1, 83], [1, 84], [1, 85], [1, 86], [1, 87], [1, 88], [1, 89], [1, 90], [1, 91], [1, 92], [1, 93], [1, 94], [1, 95], [1, 96], [1, 97], [1, 98], [1, 99], [1, 100]]) == [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(rectangles = [[500, 90], [1000, 80], [1500, 70], [2000, 60], [2500, 50]],points = [[250, 55], [750, 75], [1250, 85], [1750, 95], [2250, 100]]) == [4, 1, 0, 0, 0]\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[5, 100], [10, 99], [15, 98], [20, 97], [25, 96], [30, 95], [35, 94], [40, 93], [45, 92], [50, 91]],points = [[1, 95], [6, 90], [11, 85], [16, 80], [21, 75], [26, 70], [31, 65], [36, 60], [41, 55], [46, 50]]) == [6, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],points = [[50, 1], [150, 2], [250, 3], [350, 4], [450, 5]]) == [5, 4, 3, 2, 1]\n assert candidate(rectangles = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]],points = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]]) == [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[500000000, 100], [499999999, 99], [500000000, 98], [1, 97]],points = [[250000000, 50], [300000000, 60], [350000000, 70]]) == [3, 3, 3]\n assert candidate(rectangles = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],points = [[50, 10], [150, 20], [250, 30], [350, 40], [450, 50]]) == [0, 0, 0, 0, 0]\n assert candidate(rectangles = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [10, 8, 6, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(rectangles = [[100, 100], [99, 100], [98, 100], [97, 100], [96, 100], [95, 100], [94, 100], [93, 100], [92, 100], [91, 100], [90, 100]],points = [[50, 50], [60, 60], [70, 70], [80, 80], [90, 90]]) == [11, 11, 11, 11, 11]\n assert candidate(rectangles = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 100]],points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 100]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9], [1000, 10]],points = [[50, 1], [150, 2], [250, 3], [350, 4], [450, 5], [550, 6], [650, 7], [750, 8], [850, 9], [950, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[1000000000, 100], [500000000, 100], [250000000, 100], [125000000, 100], [62500000, 100]],points = [[500000000, 50], [250000000, 50], [125000000, 50], [62500000, 50], [31250000, 50]]) == [2, 3, 4, 5, 5]\n assert candidate(rectangles = [[1000000000, 100], [999999999, 99], [999999998, 98], [999999997, 97], [999999996, 96], [999999995, 95], [999999994, 94], [999999993, 93], [999999992, 92], [999999991, 91]],points = [[500000000, 50], [500000001, 50], [500000002, 50], [500000003, 50], [500000004, 50], [500000005, 50], [500000006, 50], [500000007, 50], [500000008, 50], [500000009, 50]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(rectangles = [[500000000, 50], [600000000, 60], [700000000, 70], [800000000, 80], [900000000, 90]],points = [[250000000, 25], [350000000, 35], [450000000, 45], [550000000, 55]]) == [5, 5, 5, 4]\n assert candidate(rectangles = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [5, 5, 5, 5, 5]\n assert candidate(rectangles = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],points = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500]],points = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450]]) == [1, 0, 0, 0, 0]\n assert candidate(rectangles = [[1000000000, 100], [999999999, 99], [1000000000, 98], [1, 97]],points = [[500000000, 50], [600000000, 51], [700000000, 52], [800000000, 53]]) == [3, 3, 3, 3]\n assert candidate(rectangles = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]],points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [10, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],points = [[1, 1], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90]]) == [10, 10, 9, 8, 7, 6, 5, 4, 3, 2]\n assert candidate(rectangles = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],points = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],points = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],points = [[1, 90], [2, 89], [3, 88], [4, 87], [5, 86], [6, 85], [7, 84], [8, 83], [9, 82], [10, 81]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96]],points = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96]]) == [1, 2, 3, 4, 5]\n assert candidate(rectangles = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]],points = [[3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[5, 100], [10, 99], [15, 98], [20, 97], [25, 96], [30, 95]],points = [[5, 95], [10, 90], [15, 85], [20, 80], [25, 75], [30, 70]]) == [6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900], [1000, 1000]],points = [[50, 50], [150, 150], [250, 250], [350, 350], [450, 450], [550, 550], [650, 650], [750, 750], [850, 850], [950, 950]]) == [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[100, 1], [100, 2], [100, 3], [100, 4], [100, 5], [100, 6], [100, 7], [100, 8], [100, 9], [100, 10]],points = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[500000000, 100], [500000001, 99], [500000002, 98], [500000003, 97], [500000004, 96]],points = [[500000000, 99], [500000001, 98], [500000002, 97]]) == [2, 2, 2]\n assert candidate(rectangles = [[100, 100], [200, 95], [300, 90], [400, 85], [500, 80], [600, 75], [700, 70], [800, 65], [900, 60], [1000, 55]],points = [[50, 50], [150, 55], [250, 60], [350, 65], [450, 70], [550, 75], [650, 80], [750, 85], [850, 90], [950, 95]]) == [10, 9, 7, 5, 3, 1, 0, 0, 0, 0]\n assert candidate(rectangles = [[500000000, 50], [600000000, 60], [700000000, 70], [800000000, 80]],points = [[100000000, 10], [200000000, 20], [300000000, 30], [400000000, 40], [500000000, 50], [600000000, 60], [700000000, 70], [800000000, 80]]) == [4, 4, 4, 4, 4, 3, 2, 1]\n assert candidate(rectangles = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[1000000000, 100], [1000000000, 99], [1000000000, 98], [1000000000, 97], [1000000000, 96]],points = [[500000000, 50], [500000000, 49], [500000000, 48], [500000000, 47], [500000000, 46]]) == [5, 5, 5, 5, 5]\n assert candidate(rectangles = [[500000000, 100], [500000001, 100], [500000002, 100], [500000003, 100], [500000004, 100]],points = [[499999999, 50], [500000000, 50], [500000001, 50], [500000002, 50], [500000003, 50]]) == [5, 5, 4, 3, 2]\n assert candidate(rectangles = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]],points = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(rectangles = [[50, 50], [75, 75], [100, 100], [25, 25]],points = [[30, 30], [40, 40], [60, 60], [80, 80], [90, 90]]) == [3, 3, 2, 1, 1]\n assert candidate(rectangles = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]],points = [[1, 1], [10, 10], [2, 2], [20, 20], [3, 3], [30, 30], [4, 4], [40, 40], [5, 5], [50, 50]]) == [10, 1, 9, 0, 8, 0, 7, 0, 6, 0]\n assert candidate(rectangles = [[10, 100], [20, 100], [30, 100], [40, 100], [50, 100]],points = [[5, 50], [15, 50], [25, 50], [35, 50], [45, 50]]) == [5, 4, 3, 2, 1]\n assert candidate(rectangles = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1]],points = [[15, 1], [25, 1], [35, 1], [45, 1], [55, 1]]) == [4, 3, 2, 1, 0]\n assert candidate(rectangles = [[100, 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, 21], [100, 22], [100, 23], [100, 24], [100, 25], [100, 26], [100, 27], [100, 28], [100, 29], [100, 30], [100, 31], [100, 32], [100, 33], [100, 34], [100, 35], [100, 36], [100, 37], [100, 38], [100, 39], [100, 40], [100, 41], [100, 42], [100, 43], [100, 44], [100, 45], [100, 46], [100, 47], [100, 48], [100, 49], [100, 50], [100, 51], [100, 52], [100, 53], [100, 54], [100, 55], [100, 56], [100, 57], [100, 58], [100, 59], [100, 60], [100, 61], [100, 62], [100, 63], [100, 64], [100, 65], [100, 66], [100, 67], [100, 68], [100, 69], [100, 70], [100, 71], [100, 72], [100, 73], [100, 74], [100, 75], [100, 76], [100, 77], [100, 78], [100, 79], [100, 80], [100, 81], [100, 82], [100, 83], [100, 84], [100, 85], [100, 86], [100, 87], [100, 88], [100, 89], [100, 90], [100, 91], [100, 92], [100, 93], [100, 94], [100, 95], [100, 96], [100, 97], [100, 98], [100, 99]],points = [[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], [50, 16], [50, 17], [50, 18], [50, 19], [50, 20], [50, 21], [50, 22], [50, 23], [50, 24], [50, 25], [50, 26], [50, 27], [50, 28], [50, 29], [50, 30], [50, 31], [50, 32], [50, 33], [50, 34], [50, 35], [50, 36], [50, 37], [50, 38], [50, 39], [50, 40], [50, 41], [50, 42], [50, 43], [50, 44], [50, 45], [50, 46], [50, 47], [50, 48], [50, 49], [50, 50], [50, 51], [50, 52], [50, 53], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 59], [50, 60], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [50, 73], [50, 74], [50, 75], [50, 76], [50, 77], [50, 78], [50, 79], [50, 80], [50, 81], [50, 82], [50, 83], [50, 84], [50, 85], [50, 86], [50, 87], [50, 88], [50, 89], [50, 90], [50, 91], [50, 92], [50, 93], [50, 94], [50, 95], [50, 96], [50, 97], [50, 98], [50, 99]]) == [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(rectangles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],points = [[5, 100], [6, 99], [7, 98], [8, 97], [9, 96], [10, 95], [11, 94], [12, 93], [13, 92], [14, 91]]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[1000000000, 1], [999999999, 2], [999999998, 3], [999999997, 4], [999999996, 5]],points = [[1000000000, 1], [999999999, 2], [999999998, 3], [999999997, 4], [999999996, 5]]) == [1, 1, 1, 1, 1]\n assert candidate(rectangles = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96], [1, 95]],points = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(rectangles = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]],points = [[9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9], [9, 10]]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(rectangles = [[9, 90], [8, 80], [7, 70], [6, 60], [5, 50], [4, 40], [3, 30], [2, 20], [1, 10]],points = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == [9, 8, 7, 6, 5, 4, 3, 2, 1]\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,3],[2,5]]\n[[2,1],[1,4]]", "[[1,1],[2,2],[3,3]]\n[[1,3],[1,1]]"], "hints": ["The heights of the rectangles and the y-coordinates of the points are only at most 100, so for each point, we can iterate over the possible heights of the rectangles that contain a given point.", "For a given point and height, can we efficiently count how many rectangles with that height contain our point?", "Sort the rectangles at each height and use binary search."], "metadata": {"canonical_parameter_names": ["rectangles", "points"], "leetcode_dataset_entry_point": "Solution().countRectangles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:23+00:00", "tests_total": 64, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "binary-search", "binary-indexed-tree", "sorting"]}, "language": "php", "interface": {"raw_signature": "function countRectangles($rectangles, $points) {", "container": "Solution", "callable": "countRectangles", "parameters": [{"name": "rectangles", "type": "Integer[][]"}, {"name": "points", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2251, "task_id": "number-of-flowers-in-full-bloom", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array flowers, where flowers[i] = [start_i, end_i] means the i^th flower will be in full bloom from start_i to end_i (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the i^th person will arrive to see the flowers.\n\nReturn an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom when the i^th person arrives.\n\nExample 1:\n\nInput: flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11]\nOutput: [1,2,2,2]\nExplanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\nFor each person, we return the number of flowers in full bloom during their arrival.\n\nExample 2:\n\nInput: flowers = [[1,10],[3,3]], people = [3,3,2]\nOutput: [2,2,1]\nExplanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\nFor each person, we return the number of flowers in full bloom during their arrival.\n\nConstraints:\n\n- 1 <= flowers.length <= 5 * 10^4\n- flowers[i].length == 2\n- 1 <= start_i <= end_i <= 10^9\n- 1 <= people.length <= 5 * 10^4\n- 1 <= people[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(flowers = [[1, 10], [3, 3]],people = [3, 3, 2]) == [2, 2, 1]\n assert candidate(flowers = [[1, 100]],people = [50, 100, 150]) == [1, 1, 0]\n assert candidate(flowers = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4]],people = [1, 2, 3, 4]) == [1, 2, 2, 1]\n assert candidate(flowers = [[5, 10], [15, 20], [1, 5]],people = [6, 12, 4]) == [1, 0, 1]\n assert candidate(flowers = [[1, 1000000000]],people = [1, 500000000, 1000000000]) == [1, 1, 1]\n assert candidate(flowers = [[5, 10], [15, 20], [25, 30]],people = [10, 20, 30, 40]) == [1, 1, 1, 0]\n assert candidate(flowers = [[1, 6], [3, 7], [9, 12], [4, 13]],people = [2, 3, 7, 11]) == [1, 2, 2, 2]\n assert candidate(flowers = [[1, 1000000000]],people = [1, 1000000000]) == [1, 1]\n assert candidate(flowers = [[5, 11], [8, 8], [8, 9], [10, 10], [9, 11], [5, 7]],people = [6, 10, 7]) == [2, 3, 2]\n assert candidate(flowers = [[1, 1], [2, 2], [3, 3]],people = [1, 2, 3]) == [1, 1, 1]\n assert candidate(flowers = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(flowers = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],people = [3, 6, 8, 10, 15]) == [3, 5, 3, 1, 0]\n assert candidate(flowers = [[1, 10], [1, 10], [1, 10], [1, 10], [1, 10]],people = [1, 5, 10]) == [5, 5, 5]\n assert candidate(flowers = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],people = [1, 5, 10, 15]) == [1, 2, 2, 0]\n assert candidate(flowers = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23]],people = [2, 6, 10, 14, 18, 22, 24]) == [1, 1, 1, 1, 1, 1, 0]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996]],people = [1, 1000000000, 500000000, 250000000, 750000000]) == [1, 1, 5, 5, 5]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997]],people = [1, 2, 3, 4, 999999999, 1000000000]) == [1, 2, 3, 4, 2, 1]\n assert candidate(flowers = [[100000000, 200000000], [300000000, 400000000], [500000000, 600000000]],people = [150000000, 350000000, 550000000]) == [1, 1, 1]\n assert candidate(flowers = [[2, 5], [8, 10], [12, 14], [18, 22], [26, 28], [30, 34]],people = [2, 5, 8, 10, 12, 14, 18, 22, 26, 28, 30, 34]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],people = [5, 6, 7, 8, 9, 10]) == [5, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[1, 6], [3, 7], [9, 12], [4, 13], [14, 17], [18, 21], [22, 25]],people = [2, 3, 7, 11, 15, 19, 23]) == [1, 2, 2, 2, 1, 1, 1]\n assert candidate(flowers = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30]],people = [1, 2, 3, 4, 5, 6, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300]],people = [1, 50, 100, 150, 200, 250, 300]) == [1, 2, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[5, 15], [10, 20], [15, 25], [20, 30], [25, 35]],people = [10, 15, 20, 25, 30, 35]) == [2, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[5, 20], [20, 30], [10, 25], [15, 35], [25, 40]],people = [10, 15, 20, 25, 30, 35, 40]) == [2, 3, 4, 4, 3, 2, 1]\n assert candidate(flowers = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],people = [5, 15, 25, 35, 45, 55]) == [1, 1, 1, 1, 1, 0]\n assert candidate(flowers = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21], [22, 24], [25, 27], [28, 30]],people = [1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19], [19, 21]],people = [2, 6, 10, 14, 18, 22]) == [1, 1, 1, 1, 1, 0]\n assert candidate(flowers = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [100, 110]],people = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],people = [3, 8, 13, 18, 23]) == [1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 3, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 0, 0, 0, 0, 0]\n assert candidate(flowers = [[1, 6], [3, 7], [9, 12], [4, 13], [10, 15], [16, 20], [21, 25], [26, 30]],people = [2, 5, 6, 7, 10, 15, 20, 25, 30]) == [1, 3, 3, 2, 3, 1, 1, 1, 1]\n assert candidate(flowers = [[10, 15], [15, 20], [20, 25], [25, 30]],people = [12, 17, 22, 27]) == [1, 1, 1, 1]\n assert candidate(flowers = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35]],people = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33]) == [0, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 1000], [500, 1500], [1000, 2000], [1500, 2500], [2000, 3000], [2500, 3500], [3000, 4000], [3500, 4500], [4000, 5000], [4500, 5500]],people = [1, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000]) == [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2]\n assert candidate(flowers = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]\n assert candidate(flowers = [[1, 5], [2, 3], [4, 6], [7, 8], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 2, 2, 2, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50]],people = [5, 15, 25, 35, 45]) == [1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5]],people = [1, 2, 3, 4, 5]) == [5, 5, 5, 5, 5]\n assert candidate(flowers = [[1, 5], [2, 9], [6, 8], [4, 7], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 2, 3, 3, 3, 3, 2, 2, 1]\n assert candidate(flowers = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]\n assert candidate(flowers = [[2, 11], [4, 12], [8, 15], [9, 16], [10, 17]],people = [5, 10, 15, 20]) == [2, 5, 3, 0]\n assert candidate(flowers = [[1, 1000000000], [2, 500000000], [500000000, 1000000000]],people = [1, 250000000, 500000000, 750000000, 1000000000]) == [1, 2, 3, 2, 2]\n assert candidate(flowers = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]],people = [50, 55, 60, 65, 70, 75, 80, 85, 90, 95]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 6]\n assert candidate(flowers = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996], [6, 999999995]],people = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 999999995, 999999997, 1000000000]) == [1, 3, 5, 6, 6, 6, 6, 6, 6, 6, 6, 4, 1]\n assert candidate(flowers = [[1, 10], [5, 15], [10, 20], [15, 25], [20, 30]],people = [1, 6, 11, 16, 21]) == [1, 2, 2, 2, 2]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(flowers = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [9, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[10, 12], [12, 14], [14, 16], [16, 18], [18, 20], [20, 22], [22, 24], [24, 26], [26, 28]],people = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]) == [1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1]\n assert candidate(flowers = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]],people = [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, 1, 1, 0, 0, 0]\n assert candidate(flowers = [[1, 5], [2, 8], [3, 9], [10, 15], [12, 18], [16, 20]],people = [1, 3, 5, 7, 10, 12, 15, 18, 20]) == [1, 3, 3, 2, 1, 2, 2, 2, 1]\n assert candidate(flowers = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 500000000], [500000001, 1000000000]],people = [250000000, 750000000, 1000000000]) == [1, 1, 1]\n assert candidate(flowers = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],people = [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]\n assert candidate(flowers = [[1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000], [1, 1000]],people = [1, 500, 1000]) == [10, 10, 10]\n assert candidate(flowers = [[1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(flowers = [[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10, 20]],people = [5, 15, 25]) == [0, 10, 0]\n assert candidate(flowers = [[1, 6], [6, 11], [11, 16], [16, 21]],people = [1, 5, 6, 10, 11, 15, 16, 20, 21]) == [1, 1, 2, 1, 2, 1, 2, 1, 1]\n assert candidate(flowers = [[100, 110], [110, 120], [120, 130], [130, 140], [140, 150], [150, 160], [160, 170], [170, 180], [180, 190]],people = [105, 115, 125, 135, 145, 155, 165, 175, 185]) == [1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21]],people = [2, 5, 8, 11, 14, 17, 20]) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996]],people = [1, 2, 3, 4, 5, 1000000000, 999999999, 999999998, 999999997, 999999996]) == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]\n assert candidate(flowers = [[1, 10000], [10001, 20000], [20001, 30000], [30001, 40000], [40001, 50000]],people = [5000, 15000, 25000, 35000, 45000]) == [1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996]],people = [1, 500000000, 1000000000]) == [1, 5, 1]\n assert candidate(flowers = [[1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000]],people = [1, 1000000000, 500000000, 250000000, 750000000]) == [10, 10, 10, 10, 10]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(flowers = [[1, 100], [10, 90], [20, 80], [30, 70], [40, 60], [50, 50]],people = [1, 50, 100, 150]) == [1, 6, 1, 0]\n assert candidate(flowers = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350]],people = [50, 100, 150, 200, 250, 300, 350]) == [2, 3, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[100, 200], [150, 250], [200, 300], [250, 350], [300, 400]],people = [50, 100, 150, 200, 250, 300, 350, 400, 450]) == [0, 1, 2, 3, 3, 3, 2, 1, 0]\n assert candidate(flowers = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]],people = [1, 2, 3, 4, 5]) == [10, 10, 10, 10, 10]\n assert candidate(flowers = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60]],people = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996], [6, 999999995], [7, 999999994], [8, 999999993], [9, 999999992], [10, 999999991]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(flowers = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],people = [3, 8, 13, 18, 23, 28]) == [1, 1, 1, 1, 1, 0]\n assert candidate(flowers = [[1, 5], [10, 15], [20, 25], [30, 35], [40, 45]],people = [3, 8, 13, 18, 23, 28, 33, 38, 43]) == [1, 0, 1, 0, 1, 0, 1, 0, 1]\n assert candidate(flowers = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996], [6, 999999995], [7, 999999994], [8, 999999993], [9, 999999992], [10, 999999991]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 999999991, 999999992, 999999993, 999999994, 999999995, 999999996, 999999997, 999999998, 999999999, 1000000000]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60], [55, 65]],people = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65]) == [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1]\n assert candidate(flowers = [[5, 15], [10, 20], [15, 25], [20, 30], [25, 35]],people = [5, 8, 10, 12, 15, 18, 20, 23, 25, 28, 30]) == [1, 1, 2, 2, 3, 2, 3, 2, 3, 2, 2]\n assert candidate(flowers = [[1, 10], [1, 9], [1, 8], [1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],people = [1, 5, 9]) == [1, 2, 2]\n assert candidate(flowers = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50], [51, 60], [61, 70], [71, 80], [81, 90], [91, 100]],people = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 5], [10, 20], [25, 35], [40, 50], [55, 60]],people = [5, 15, 25, 35, 45, 55, 60]) == [1, 1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35]],people = [8, 13, 18, 23, 28, 33]) == [1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000]],people = [1, 1000000000]) == [10, 10]\n assert candidate(flowers = [[1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000]],people = [1, 500000000, 1000000000]) == [5, 5, 5]\n assert candidate(flowers = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3]],people = [1, 2, 3, 4, 5]) == [5, 5, 5, 0, 0]\n assert candidate(flowers = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],people = [1, 5, 9, 13, 17, 20]) == [1, 1, 1, 1, 1, 1]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],people = [1, 3, 5, 7, 9]) == [1, 2, 2, 2, 2]\n assert candidate(flowers = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],people = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 2, 2, 2, 2, 2, 2, 2, 1]\n assert candidate(flowers = [[1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000], [1, 1000000000]],people = [1, 1000000000, 500000000, 250000000, 750000000]) == [5, 5, 5, 5, 5]\n assert candidate(flowers = [[1, 10], [11, 20], [21, 30], [31, 40], [41, 50]],people = [5, 15, 25, 35, 45, 55, 1, 11, 21, 31, 41]) == [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1]\n", "comparison": "exact"}, "public_tests": ["[[1,6],[3,7],[9,12],[4,13]]\n[2,3,7,11]", "[[1,10],[3,3]]\n[3,3,2]"], "hints": ["Notice that for any given time t, the number of flowers blooming at time t is equal to the number of flowers that have started blooming minus the number of flowers that have already stopped blooming.", "We can obtain these values efficiently using binary search.", "We can store the starting times in sorted order, which then allows us to binary search to find how many flowers have started blooming for a given time t.", "We do the same for the ending times to find how many flowers have stopped blooming at time t."], "metadata": {"canonical_parameter_names": ["flowers", "people"], "leetcode_dataset_entry_point": "Solution().fullBloomFlowers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:26+00:00", "tests_total": 105, "tests_dropped": 5, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "binary-search", "sorting", "prefix-sum", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function fullBloomFlowers($flowers, $people) {", "container": "Solution", "callable": "fullBloomFlowers", "parameters": [{"name": "flowers", "type": "Integer[][]"}, {"name": "people", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2255, "task_id": "count-prefixes-of-a-given-string", "difficulty": "Easy", "problem_description": "You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters.\n\nReturn the number of strings in words that are a prefix of s.\n\nA prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: words = [\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"], s = \"abc\"\nOutput: 3\nExplanation:\nThe strings in words which are a prefix of s = \"abc\" are:\n\"a\", \"ab\", and \"abc\".\nThus the number of strings in words which are a prefix of s is 3.\n\nExample 2:\n\nInput: words = [\"a\",\"a\"], s = \"aa\"\nOutput: 2\nExplanation:\nBoth of the strings are a prefix of s.\nNote that the same string can occur multiple times in words, and it should be counted each time.\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length, s.length <= 10\n- words[i] and s consist of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['hello', 'hell', 'he', 'h'],s = \"hello\") == 4\n assert candidate(words = ['short'],s = \"shorter\") == 1\n assert candidate(words = ['same', 'same'],s = \"same\") == 2\n assert candidate(words = ['hello'],s = \"h\") == 0\n assert candidate(words = ['hello'],s = \"hello\") == 1\n assert candidate(words = ['d', 'do', 'dog', 'doge'],s = \"doge\") == 4\n assert candidate(words = ['prefix'],s = \"prefix\") == 1\n assert candidate(words = ['same', 'same', 'same'],s = \"same\") == 3\n assert candidate(words = ['world'],s = \"world\") == 1\n assert candidate(words = ['a', 'b', 'c'],s = \"abcde\") == 1\n assert candidate(words = ['a'],s = \"a\") == 1\n assert candidate(words = ['not', 'a', 'prefix'],s = \"example\") == 0\n assert candidate(words = ['test', 'testing', 't'],s = \"testing\") == 3\n assert candidate(words = ['xyz', 'xy', 'x'],s = \"xyz\") == 3\n assert candidate(words = ['abcd'],s = \"abc\") == 0\n assert candidate(words = ['a', 'b', 'c'],s = \"d\") == 0\n assert candidate(words = ['test', 'testing', 'tested'],s = \"testing\") == 2\n assert candidate(words = ['a', 'a'],s = \"aa\") == 2\n assert candidate(words = ['abc'],s = \"abc\") == 1\n assert candidate(words = ['abc', 'abcd', 'abcde'],s = \"abcdef\") == 3\n assert candidate(words = ['z', 'zz', 'zzz'],s = \"zzzz\") == 3\n assert candidate(words = ['cat', 'bat', 'rat'],s = \"car\") == 0\n assert candidate(words = ['a', 'b', 'c', 'ab', 'bc', 'abc'],s = \"abc\") == 3\n assert candidate(words = ['h'],s = \"hello\") == 1\n assert candidate(words = ['a'],s = \"b\") == 0\n assert candidate(words = ['yes', 'no'],s = \"yesman\") == 1\n assert candidate(words = ['prefix'],s = \"prefixing\") == 1\n assert candidate(words = ['hello', 'he', 'h'],s = \"hello\") == 3\n assert candidate(words = ['test'],s = \"testing\") == 1\n assert candidate(words = ['a', 'ab', 'abc', 'abcd'],s = \"abcd\") == 4\n assert candidate(words = ['ab', 'abc', 'abcd'],s = \"abcd\") == 3\n assert candidate(words = ['test', 'testing', 'tested', 'te'],s = \"testing\") == 3\n assert candidate(words = ['unique', 'uniq', 'un'],s = \"unique\") == 3\n assert candidate(words = ['different', 'dif', 'diff', 'differ'],s = \"different\") == 4\n assert candidate(words = ['prefix', 'pre', 'pred'],s = \"predicate\") == 2\n assert candidate(words = ['example', 'examp', 'exam', 'exa', 'ex', 'e'],s = \"example\") == 6\n assert candidate(words = ['prefix', 'prefi', 'pref', 'pre'],s = \"prefix\") == 4\n assert candidate(words = ['abc', 'abcd', 'ab', 'a'],s = \"abcd\") == 4\n assert candidate(words = ['complex', 'com', 'comp', 'comple', 'complexe'],s = \"complex\") == 4\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa'],s = \"aaaaa\") == 4\n assert candidate(words = ['example', 'ex', 'exa', 'exam', 'examp', 'examp'],s = \"example\") == 6\n assert candidate(words = ['complex', 'comple', 'compl', 'comp'],s = \"complexity\") == 4\n assert candidate(words = ['hello', 'hell', 'he'],s = \"hello\") == 3\n assert candidate(words = ['abcde', 'bcde', 'cde', 'de', 'e'],s = \"abcde\") == 1\n assert candidate(words = ['abc', 'def', 'ghi'],s = \"abcdefghi\") == 1\n assert candidate(words = ['not', 'no', 'n'],s = \"note\") == 3\n assert candidate(words = ['multiple', 'multip', 'multi', 'mult', 'mult'],s = \"multiple\") == 5\n assert candidate(words = ['word', 'words', 'wording'],s = \"word\") == 1\n assert candidate(words = ['prefix', 'pre', 'p'],s = \"prefix\") == 3\n assert candidate(words = ['overlap', 'over', 'ov', 'o'],s = \"overlap\") == 4\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],s = \"aaaaaaaa\") == 5\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],s = \"aaaaa\") == 5\n assert candidate(words = ['short', 'shorter', 'shortest'],s = \"short\") == 1\n assert candidate(words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg'],s = \"abcdefgh\") == 7\n assert candidate(words = ['short', 'shot', 'sh', 's'],s = \"shortstory\") == 3\n assert candidate(words = ['abcd', 'abc', 'ab', 'a'],s = \"a\") == 1\n assert candidate(words = ['longword', 'long', 'lo', 'l', 'lon', 'longw'],s = \"longword\") == 6\n assert candidate(words = ['a', 'b', 'c', 'd', 'e'],s = \"abcde\") == 1\n assert candidate(words = ['prefix', 'pre', 'p'],s = \"prefix\") == 3\n assert candidate(words = ['prefix', 'pre', 'pref', 'prefi', 'prefixe'],s = \"prefix\") == 4\n assert candidate(words = ['aaa', 'aa', 'a'],s = \"aaaaa\") == 3\n assert candidate(words = ['one', 'two', 'three', 'four'],s = \"one\") == 1\n assert candidate(words = ['different', 'diff', 'diffe', 'differen', 'differen'],s = \"different\") == 5\n assert candidate(words = ['unique', 'uniq', 'un', 'u'],s = \"unique\") == 4\n assert candidate(words = ['aaa', 'aa', 'a', 'aaaa'],s = \"aaa\") == 3\n assert candidate(words = ['abcd', 'bcde', 'cdef', 'defg'],s = \"abcd\") == 1\n assert candidate(words = ['not', 'no', 'n'],s = \"note\") == 3\n assert candidate(words = ['same', 'same', 'same', 'same'],s = \"same\") == 4\n assert candidate(words = ['test', 'testing', 'tea', 'te'],s = \"testing\") == 3\n assert candidate(words = ['begin', 'beg', 'be', 'b'],s = \"beginning\") == 4\n assert candidate(words = ['overlap', 'over', 'o'],s = \"overlap\") == 3\n assert candidate(words = ['test', 'testing', 'tes', 't'],s = \"testing\") == 4\n assert candidate(words = ['xy', 'xyz', 'xyzz'],s = \"xy\") == 1\n assert candidate(words = ['one', 'two', 'three', 'four', 'five'],s = \"fives\") == 1\n assert candidate(words = ['longword', 'long', 'lo', 'l'],s = \"longword\") == 4\n assert candidate(words = ['example', 'ex', 'exa', 'exam', 'examp'],s = \"example\") == 5\n assert candidate(words = ['abc', 'abcd', 'abcde'],s = \"abcdef\") == 3\n assert candidate(words = ['multiple', 'multi', 'mul', 'mu'],s = \"multiples\") == 4\n assert candidate(words = ['word', 'wor', 'wo', 'w'],s = \"word\") == 4\n assert candidate(words = ['banana', 'ban', 'ba', 'b'],s = \"bananarama\") == 4\n assert candidate(words = ['abcd', 'abc', 'ab', 'a'],s = \"abcd\") == 4\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa'],s = \"aaaa\") == 4\n assert candidate(words = ['prefix', 'pre', 'prefixx', 'prefixxx', 'prefixxxx'],s = \"prefixx\") == 3\n assert candidate(words = ['test', 'testing', 'tested'],s = \"testing\") == 2\n assert candidate(words = ['part', 'partial', 'partially'],s = \"partially\") == 3\n assert candidate(words = ['aaa', 'aa', 'a', 'aaaa'],s = \"aaaa\") == 4\n assert candidate(words = ['one', 'two', 'three', 'four'],s = \"one\") == 1\n assert candidate(words = ['prefix', 'pre', 'prex', 'abc'],s = \"prefix\") == 2\n assert candidate(words = ['abc', 'abcd', 'abcde'],s = \"abcdefg\") == 3\n assert candidate(words = ['repeat', 'repe', 'rep', 're', 'r'],s = \"repeat\") == 5\n assert candidate(words = ['a', 'ab', 'abc', 'abcd', 'abcde'],s = \"a\") == 1\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa'],s = \"aaaaaa\") == 5\n assert candidate(words = ['complex', 'comp', 'com', 'co', 'c'],s = \"complexity\") == 5\n assert candidate(words = ['python', 'pyth', 'py'],s = \"python\") == 3\n assert candidate(words = ['xyz', 'xy', 'x'],s = \"xy\") == 2\n assert candidate(words = ['complex', 'com', 'co', 'c'],s = \"complex\") == 4\n assert candidate(words = ['prefix', 'prefixx', 'prefixxx', 'prefixxxx'],s = \"prefix\") == 1\n assert candidate(words = ['abc', 'abcd', 'abcde'],s = \"abcdefg\") == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'abc'],s = \"abcdefghi\") == 2\n assert candidate(words = ['cat', 'cattle', 'cattleman'],s = \"cattleman\") == 3\n assert candidate(words = ['xyz', 'xy', 'x'],s = \"xyz\") == 3\n assert candidate(words = ['same', 'same', 'same'],s = \"same\") == 3\n assert candidate(words = ['prefix', 'pre', 'pref'],s = \"prefix\") == 3\n assert candidate(words = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef'],s = \"fghijkl\") == 0\n assert candidate(words = ['small', 'smaller', 'smallest', 'smallerest'],s = \"smallerest\") == 3\n assert candidate(words = ['abc', 'abcd', 'abcde', 'abcdef'],s = \"abcdefg\") == 4\n assert candidate(words = ['test', 'testing', 'testi'],s = \"test\") == 1\n assert candidate(words = ['zz', 'zzz', 'zzzz'],s = \"zzzz\") == 3\n assert candidate(words = ['hello', 'he', 'hell'],s = \"hello\") == 3\n assert candidate(words = ['prefix', 'pre', 'pref', 'prex'],s = \"prefix\") == 3\n assert candidate(words = ['z', 'zz', 'zzz', 'zzzz'],s = \"zzzzzz\") == 4\n assert candidate(words = ['unique', 'uniq', 'uni', 'un', 'u'],s = \"unique\") == 5\n assert candidate(words = ['cat', 'dog', 'car', 'catch', 'cart'],s = \"catch\") == 2\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],s = \"abcdefghij\") == 1\n assert candidate(words = ['unique', 'uniq', 'uni', 'un'],s = \"uniques\") == 4\n assert candidate(words = ['hello', 'world', 'hel', 'wo', 'wor'],s = \"helloworld\") == 2\n assert candidate(words = ['overlap', 'over', 'ov', 'overlaplap'],s = \"overlap\") == 3\n assert candidate(words = ['matching', 'match', 'mat', 'ma', 'm'],s = \"matching\") == 5\n assert candidate(words = ['hello', 'hell', 'he', 'h', 'hellohello'],s = \"hellohello\") == 5\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa'],s = \"aaaaaaaaa\") == 4\n assert candidate(words = ['match', 'mat', 'ma', 'm'],s = \"match\") == 4\n assert candidate(words = ['example', 'exa', 'ex', 'e'],s = \"example\") == 4\n assert candidate(words = ['hello', 'hell', 'he', 'h'],s = \"hello\") == 4\n assert candidate(words = ['word', 'wording', 'wordings'],s = \"word\") == 1\n assert candidate(words = ['a', 'ab', 'abc', 'abcd'],s = \"abcde\") == 4\n assert candidate(words = ['unique', 'uniqueness', 'uni', 'un'],s = \"uniqueness\") == 4\n assert candidate(words = ['one', 'on', 'o', 'ones'],s = \"one\") == 3\n assert candidate(words = ['word', 'wo', 'w'],s = \"word\") == 3\n assert candidate(words = ['prefix', 'pre', 'pr', 'p'],s = \"prefix\") == 4\n assert candidate(words = ['example', 'exam', 'ex', 'e'],s = \"examples\") == 4\n assert candidate(words = ['common', 'commo', 'comm', 'com', 'co', 'c'],s = \"common\") == 6\n", "comparison": "exact"}, "public_tests": ["[\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"]\n\"abc\"", "[\"a\",\"a\"]\n\"aa\""], "hints": ["For each string in words, check if it is a prefix of s. If true, increment the answer by 1."], "metadata": {"canonical_parameter_names": ["words", "s"], "leetcode_dataset_entry_point": "Solution().countPrefixes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:28+00:00", "tests_total": 146, "tests_dropped": 15, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function countPrefixes($words, $s) {", "container": "Solution", "callable": "countPrefixes", "parameters": [{"name": "words", "type": "String[]"}, {"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2256, "task_id": "minimum-average-difference", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of length n.\n\nThe average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer.\n\nReturn the index with the minimum average difference. If there are multiple such indices, return the smallest one.\n\nNote:\n\n- The absolute difference of two numbers is the absolute value of their difference.\n- The average of n elements is the sum of the n elements divided (integer division) by n.\n- The average of 0 elements is considered to be 0.\n\nExample 1:\n\nInput: nums = [2,5,3,9,5,3]\nOutput: 3\nExplanation:\n- The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.\n- The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.\n- The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.\n- The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.\n- The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.\n- The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.\nThe average difference of index 3 is the minimum average difference so return 3.\n\nExample 2:\n\nInput: nums = [0]\nOutput: 0\nExplanation:\nThe only index is 0 so return 0.\nThe average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0]) == 1\n assert candidate(nums = [100000, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [0, 1, 0, 1, 0]) == 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, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 9\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(nums = [1, 0, 0, 0, 0]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [2, 5, 3, 9, 5, 3]) == 3\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 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]) == 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]) == 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]) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 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, 1]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 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 = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16]) == 1\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000, 0]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 0\n assert candidate(nums = [100000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 14\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 = [1, 10, 100, 1000, 10000, 100000, 90000, 9000, 900, 90]) == 5\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == 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]) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0]) == 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]) == 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]) == 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]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 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]) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114]) == 0\n assert candidate(nums = [100000, 0, 50000, 50000, 25000, 25000, 75000, 25000, 0, 100000]) == 4\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 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, 100000]) == 20\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 = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 0\n assert candidate(nums = [5, 3, 8, 1, 4, 2, 7, 6, 9, 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, 1]) == 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]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]) == 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]) == 0\n assert candidate(nums = [0, 100000, 0, 100000, 0, 100000, 0, 100000, 0, 100000]) == 1\n assert candidate(nums = [5, 2, 9, 1, 5, 6]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 9\n assert candidate(nums = [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 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 9\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 20]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 0\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 0, 4, 5, 0, 6, 3, 7, 2, 8, 1, 9]) == 9\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\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 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 = [100000, 100000, 100000, 100000, 100000, 0, 0, 0, 0, 0]) == 9\n assert candidate(nums = [7, 3, 8, 5, 2, 6, 4, 9, 1, 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]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 0\n assert candidate(nums = [100000, 0, 100000, 0, 100000, 0]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100000]) == 14\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 9\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,5,3,9,5,3]", "[0]"], "hints": ["How can we use precalculation to efficiently calculate the average difference at an index?", "Create a prefix and/or suffix sum array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumAverageDifference", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:30+00:00", "tests_total": 94, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minimumAverageDifference($nums) {", "container": "Solution", "callable": "minimumAverageDifference", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2257, "task_id": "count-unguarded-cells-in-the-grid", "difficulty": "Medium", "problem_description": "You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [row_i, col_i] and walls[j] = [row_j, col_j] represent the positions of the i^th guard and j^th wall respectively.\n\nA guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless obstructed by a wall or another guard. A cell is guarded if there is at least one guard that can see it.\n\nReturn the number of unoccupied cells that are not guarded.\n\nExample 1:\n\nInput: m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]\nOutput: 7\nExplanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram.\nThere are a total of 7 unguarded cells, so we return 7.\n\nExample 2:\n\nInput: m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]\nOutput: 4\nExplanation: The unguarded cells are shown in green in the above diagram.\nThere are a total of 4 unguarded cells, so we return 4.\n\nConstraints:\n\n- 1 <= m, n <= 10^5\n- 2 <= m * n <= 10^5\n- 1 <= guards.length, walls.length <= 5 * 10^4\n- 2 <= guards.length + walls.length <= m * n\n- guards[i].length == walls[j].length == 2\n- 0 <= row_i, row_j < m\n- 0 <= col_i, col_j < n\n- All the positions in guards and walls are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 4,n = 6,guards = [[0, 0], [1, 1], [2, 3]],walls = [[0, 1], [2, 2], [1, 4]]) == 7\n assert candidate(m = 3,n = 3,guards = [[1, 1]],walls = [[0, 1], [1, 0], [2, 1], [1, 2]]) == 4\n assert candidate(m = 5,n = 5,guards = [[2, 2]],walls = [[0, 0], [4, 4]]) == 14\n assert candidate(m = 10,n = 10,guards = [[3, 3], [6, 6]],walls = [[1, 1], [8, 8]]) == 62\n assert candidate(m = 6,n = 6,guards = [[1, 1], [4, 4]],walls = [[2, 2], [3, 3]]) == 14\n assert candidate(m = 12,n = 12,guards = [[1, 1], [5, 5], [9, 9]],walls = [[2, 2], [6, 6], [10, 10], [3, 3], [7, 7], [11, 11]]) == 75\n assert candidate(m = 10,n = 10,guards = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 2]],walls = [[1, 1]]) == 49\n assert candidate(m = 10,n = 5,guards = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], [8, 2], [9, 2]],walls = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [6, 4], [7, 4], [8, 4], [9, 4]]) == 1\n assert candidate(m = 20,n = 10,guards = [[5, 2], [10, 7], [15, 3], [18, 8]],walls = [[0, 5], [4, 9], [9, 4], [14, 8], [19, 3], [7, 0]]) == 104\n assert candidate(m = 15,n = 20,guards = [[2, 5], [4, 8], [10, 15]],walls = [[3, 3], [6, 7], [9, 12], [11, 14]]) == 200\n assert candidate(m = 20,n = 20,guards = [[0, 0], [19, 19], [0, 19], [19, 0]],walls = [[5, 5], [15, 15], [10, 10], [14, 14], [9, 9], [11, 11]]) == 318\n assert candidate(m = 10,n = 10,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],walls = [[0, 0], [6, 6], [7, 7], [8, 8], [9, 9]]) == 20\n assert candidate(m = 15,n = 20,guards = [[2, 2], [5, 5], [8, 8]],walls = [[3, 3], [7, 7], [11, 11], [13, 13]]) == 200\n assert candidate(m = 45,n = 45,guards = [[10, 10], [20, 20], [30, 30], [40, 40]],walls = [[12, 12], [18, 18], [22, 22], [28, 28], [32, 32], [38, 38]]) == 1675\n assert candidate(m = 18,n = 18,guards = [[9, 9], [10, 10], [11, 11], [12, 12], [13, 13]],walls = [[0, 0], [17, 17], [1, 1], [16, 16], [8, 8], [9, 9]]) == 164\n assert candidate(m = 20,n = 20,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],walls = [[6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 220\n assert candidate(m = 15,n = 15,guards = [[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]],walls = [[0, 7], [7, 0], [7, 7], [7, 14], [14, 7]]) == 3\n assert candidate(m = 6,n = 9,guards = [[1, 1], [1, 8], [4, 4], [5, 5]],walls = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [5, 7], [5, 8], [4, 8], [3, 8], [2, 8], [1, 8], [0, 8]]) == 8\n assert candidate(m = 12,n = 12,guards = [[2, 2], [2, 9], [9, 2], [9, 9], [5, 5]],walls = [[3, 3], [3, 8], [8, 3], [8, 8], [6, 6]]) == 76\n assert candidate(m = 12,n = 8,guards = [[2, 1], [5, 3], [8, 5]],walls = [[1, 2], [4, 4], [7, 6], [10, 7]]) == 41\n assert candidate(m = 9,n = 9,guards = [[1, 1], [1, 7], [7, 1], [7, 7]],walls = [[2, 2], [2, 6], [6, 2], [6, 6], [3, 3], [3, 5], [5, 3], [5, 5]]) == 41\n assert candidate(m = 100,n = 100,guards = [[25, 25], [50, 50], [75, 75]],walls = [[10, 10], [20, 20], [30, 30], [40, 40], [55, 55], [60, 60], [65, 65], [70, 70], [80, 80], [90, 90]]) == 9399\n assert candidate(m = 25,n = 25,guards = [[12, 12], [13, 13], [14, 14]],walls = [[0, 0], [24, 24], [5, 5], [20, 20], [10, 10], [15, 15]]) == 478\n assert candidate(m = 11,n = 7,guards = [[3, 1], [6, 4], [8, 6]],walls = [[1, 0], [2, 3], [4, 5], [5, 6], [7, 2]]) == 32\n assert candidate(m = 10,n = 10,guards = [[3, 3], [3, 6], [6, 3], [6, 6]],walls = [[2, 2], [2, 7], [7, 2], [7, 7], [4, 4], [4, 5], [5, 4], [5, 5]]) == 56\n assert candidate(m = 8,n = 12,guards = [[1, 5], [4, 7], [6, 3]],walls = [[0, 3], [3, 5], [5, 8], [7, 10]]) == 45\n assert candidate(m = 8,n = 8,guards = [[2, 2], [3, 3], [4, 4]],walls = [[1, 1], [5, 5], [6, 6], [7, 7], [0, 0], [1, 6], [6, 1], [5, 7], [7, 5]]) == 16\n assert candidate(m = 16,n = 16,guards = [[8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13]],walls = [[0, 0], [1, 1], [15, 15], [14, 14], [7, 7], [6, 6]]) == 94\n assert candidate(m = 8,n = 8,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]],walls = [[0, 0], [7, 7], [3, 3], [5, 5], [2, 2]]) == 0\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[0, 0], [19, 19], [9, 9], [14, 14], [15, 5], [5, 15], [10, 0], [10, 19]]) == 303\n assert candidate(m = 8,n = 8,guards = [[1, 1], [1, 6], [6, 1], [6, 6]],walls = [[2, 3], [2, 5], [5, 2], [5, 5]]) == 32\n assert candidate(m = 7,n = 7,guards = [[1, 1], [1, 5], [5, 1], [5, 5]],walls = [[0, 3], [3, 0], [3, 6], [6, 3]]) == 21\n assert candidate(m = 10,n = 5,guards = [[0, 0], [0, 4], [5, 0], [5, 4]],walls = [[1, 2], [2, 2], [3, 2], [4, 2], [6, 2], [7, 2], [8, 2], [9, 2]]) == 16\n assert candidate(m = 70,n = 70,guards = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60]],walls = [[15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65]]) == 4090\n assert candidate(m = 10,n = 10,guards = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8]],walls = [[1, 1], [1, 9], [9, 1], [9, 9], [0, 0], [0, 9], [9, 0], [5, 1], [5, 9]]) == 3\n assert candidate(m = 5,n = 10,guards = [[0, 0], [0, 9], [4, 0], [4, 9]],walls = [[2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8]]) == 16\n assert candidate(m = 10,n = 10,guards = [[0, 0], [0, 9], [9, 0], [9, 9]],walls = [[2, 2], [2, 7], [7, 2], [7, 7]]) == 60\n assert candidate(m = 7,n = 7,guards = [[1, 1], [1, 5], [5, 1], [5, 5]],walls = [[2, 2], [2, 5], [5, 2], [5, 5], [3, 3]]) == 23\n assert candidate(m = 8,n = 8,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],walls = [[0, 0], [7, 7], [0, 7], [7, 0]]) == 5\n assert candidate(m = 10,n = 10,guards = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]],walls = [[1, 1], [8, 8], [9, 9], [0, 0]]) == 12\n assert candidate(m = 7,n = 7,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],walls = [[0, 0], [1, 2], [2, 4], [3, 5], [4, 6], [5, 0], [6, 1], [6, 6]]) == 11\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[2, 2], [7, 7], [12, 12], [17, 17]]) == 285\n assert candidate(m = 100,n = 100,guards = [[10, 10], [40, 50], [70, 80]],walls = [[15, 15], [30, 30], [60, 60], [85, 85]]) == 9405\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[0, 0], [19, 19], [5, 10], [10, 15], [15, 5], [5, 15], [10, 5]]) == 331\n assert candidate(m = 15,n = 15,guards = [[2, 2], [7, 7], [12, 12]],walls = [[3, 3], [4, 4], [5, 5], [6, 6], [8, 8], [9, 9], [10, 10], [11, 11], [13, 13], [14, 14]]) == 134\n assert candidate(m = 18,n = 10,guards = [[3, 3], [7, 3], [11, 3], [3, 7], [7, 7], [11, 7]],walls = [[2, 2], [2, 8], [8, 2], [8, 8], [5, 5]]) == 115\n assert candidate(m = 10,n = 5,guards = [[2, 1], [7, 3]],walls = [[1, 1], [1, 3], [3, 1], [3, 3], [5, 1], [5, 3], [8, 1], [8, 3]]) == 31\n assert candidate(m = 15,n = 15,guards = [[2, 2], [5, 5], [8, 8]],walls = [[3, 3], [6, 6], [9, 9], [4, 4], [7, 7], [10, 10]]) == 138\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[2, 2], [4, 4], [6, 6], [8, 8], [12, 12], [14, 14], [16, 16], [18, 18]]) == 281\n assert candidate(m = 7,n = 7,guards = [[0, 0], [0, 6], [6, 0], [6, 6], [3, 3]],walls = [[1, 1], [1, 5], [5, 1], [5, 5], [2, 2], [2, 4], [4, 2], [4, 4]]) == 8\n assert candidate(m = 8,n = 8,guards = [[1, 1], [1, 7], [7, 1], [7, 7], [3, 3], [3, 4], [4, 3], [4, 4]],walls = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [7, 0], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7]]) == 12\n assert candidate(m = 7,n = 7,guards = [[1, 3], [2, 4], [3, 5], [4, 1], [5, 2], [6, 3]],walls = [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [5, 6], [4, 6], [3, 6], [2, 6], [1, 6]]) == 0\n assert candidate(m = 12,n = 10,guards = [[2, 2], [2, 3], [3, 2], [3, 3], [5, 5], [6, 6], [7, 7], [8, 8]],walls = [[1, 1], [1, 2], [1, 3], [1, 4], [4, 4], [5, 4], [6, 4], [7, 4], [8, 4], [9, 9]]) == 30\n assert candidate(m = 12,n = 12,guards = [[3, 3], [6, 6], [9, 9]],walls = [[2, 2], [4, 4], [5, 5], [7, 7], [8, 8], [10, 10], [11, 11], [0, 0], [1, 1]]) == 72\n assert candidate(m = 14,n = 14,guards = [[2, 2], [2, 11], [11, 2], [11, 11]],walls = [[3, 3], [3, 10], [10, 3], [10, 10], [5, 5], [5, 8], [8, 5], [8, 8]]) == 136\n assert candidate(m = 12,n = 12,guards = [[6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]],walls = [[0, 0], [11, 11], [10, 10], [9, 9], [8, 8]]) == 31\n assert candidate(m = 10,n = 10,guards = [[1, 1], [1, 8], [8, 1], [8, 8], [4, 4]],walls = [[0, 0], [0, 9], [9, 0], [9, 9], [2, 2], [2, 7], [7, 2], [7, 7]]) == 41\n assert candidate(m = 9,n = 9,guards = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]],walls = [[4, 3], [4, 5], [5, 4], [3, 4]]) == 14\n assert candidate(m = 15,n = 15,guards = [[2, 3], [4, 5], [6, 7]],walls = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 139\n assert candidate(m = 80,n = 80,guards = [[10, 10], [30, 30], [50, 50], [70, 70]],walls = [[15, 15], [35, 35], [55, 55], [75, 75]]) == 5772\n assert candidate(m = 6,n = 6,guards = [[1, 1], [1, 4], [4, 1], [4, 4]],walls = [[0, 0], [0, 5], [5, 0], [5, 5], [2, 2], [3, 3]]) == 10\n assert candidate(m = 8,n = 8,guards = [[1, 1], [2, 2], [3, 3], [4, 4]],walls = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == 30\n assert candidate(m = 25,n = 15,guards = [[3, 4], [8, 9], [13, 14], [18, 1], [23, 6]],walls = [[2, 5], [7, 10], [12, 13], [17, 2], [22, 7]]) == 195\n assert candidate(m = 15,n = 20,guards = [[5, 5], [7, 7], [10, 10]],walls = [[3, 3], [12, 12], [8, 8], [6, 6]]) == 200\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[2, 2], [3, 3], [4, 4], [6, 6], [7, 7], [8, 8], [9, 9], [11, 11], [12, 12], [13, 13], [14, 14], [16, 16], [17, 17], [18, 18], [19, 19]]) == 274\n assert candidate(m = 50,n = 50,guards = [[10, 10], [20, 20], [30, 30], [40, 40]],walls = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45]]) == 2111\n assert candidate(m = 8,n = 5,guards = [[1, 1], [1, 3], [3, 1], [3, 3]],walls = [[0, 0], [0, 4], [4, 0], [4, 4], [2, 2]]) == 13\n assert candidate(m = 50,n = 50,guards = [[25, 25], [25, 26], [24, 25]],walls = [[24, 24], [24, 26], [26, 25], [26, 26]]) == 2421\n assert candidate(m = 15,n = 20,guards = [[2, 2], [5, 5], [7, 7], [10, 10]],walls = [[1, 1], [3, 3], [8, 8], [12, 12], [14, 19]]) == 171\n assert candidate(m = 5,n = 10,guards = [[1, 2], [3, 7]],walls = [[1, 1], [1, 3], [2, 1], [2, 3], [3, 1], [3, 3], [4, 1], [4, 3], [1, 8], [1, 9], [2, 8], [2, 9], [3, 8], [3, 9], [4, 8], [4, 9]]) == 21\n assert candidate(m = 7,n = 7,guards = [[1, 1], [5, 5]],walls = [[2, 2], [2, 3], [2, 4], [3, 2], [3, 4], [4, 2], [4, 3], [4, 4]]) == 17\n assert candidate(m = 30,n = 30,guards = [[1, 1], [2, 2], [3, 3], [4, 4]],walls = [[5, 5], [6, 6], [7, 7], [8, 8]]) == 672\n assert candidate(m = 15,n = 15,guards = [[3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13]],walls = [[1, 1], [2, 2], [4, 4], [6, 6], [8, 8], [10, 10], [12, 12], [14, 14]]) == 73\n assert candidate(m = 10,n = 10,guards = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],walls = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 28\n assert candidate(m = 12,n = 12,guards = [[3, 3], [4, 4], [5, 5], [6, 6]],walls = [[1, 1], [2, 2], [7, 7], [8, 8], [9, 9], [10, 10]]) == 58\n assert candidate(m = 6,n = 6,guards = [[0, 0], [5, 5]],walls = [[1, 1], [1, 4], [2, 2], [2, 3], [3, 2], [3, 3], [4, 1], [4, 4]]) == 8\n assert candidate(m = 9,n = 9,guards = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],walls = [[0, 0], [8, 8], [1, 1], [7, 7], [2, 2], [3, 3]]) == 12\n assert candidate(m = 15,n = 15,guards = [[2, 2], [7, 7], [12, 12]],walls = [[0, 0], [5, 5], [10, 10], [14, 14]]) == 140\n assert candidate(m = 15,n = 15,guards = [[2, 2], [5, 5], [8, 8], [11, 11]],walls = [[3, 3], [6, 6], [9, 9], [12, 12], [0, 0], [14, 14]]) == 115\n assert candidate(m = 15,n = 10,guards = [[5, 5], [10, 5], [14, 5]],walls = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [11, 5], [12, 5], [13, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 99\n assert candidate(m = 7,n = 11,guards = [[1, 3], [4, 6], [6, 8]],walls = [[0, 1], [2, 4], [3, 5], [5, 7], [6, 9]]) == 29\n assert candidate(m = 10,n = 10,guards = [[1, 2], [2, 1], [3, 3], [6, 6], [8, 8]],walls = [[0, 0], [4, 4], [5, 5], [9, 9]]) == 21\n assert candidate(m = 20,n = 20,guards = [[5, 5], [10, 10], [15, 15]],walls = [[3, 3], [4, 4], [6, 6], [7, 7], [9, 9], [11, 11], [13, 13], [14, 14], [16, 16], [17, 17], [19, 19]]) == 278\n", "comparison": "exact"}, "public_tests": ["4\n6\n[[0,0],[1,1],[2,3]]\n[[0,1],[2,2],[1,4]]", "3\n3\n[[1,1]]\n[[0,1],[1,0],[2,1],[1,2]]"], "hints": ["Create a 2D array to represent the grid. Can you mark the tiles that can be seen by a guard?", "Iterate over the guards, and for each of the 4 directions, advance the current tile and mark the tile. When should you stop advancing?"], "metadata": {"canonical_parameter_names": ["m", "n", "guards", "walls"], "leetcode_dataset_entry_point": "Solution().countUnguarded", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:33+00:00", "tests_total": 83, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function countUnguarded($m, $n, $guards, $walls) {", "container": "Solution", "callable": "countUnguarded", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "guards", "type": "Integer[][]"}, {"name": "walls", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2258, "task_id": "escape-the-spreading-fire", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values:\n\n- 0 represents grass,\n- 1 represents fire,\n- 2 represents a wall that you and fire cannot pass through.\n\nYou are situated in the top-left cell, (0, 0), and you want to travel to the safehouse at the bottom-right cell, (m - 1, n - 1). Every minute, you may move to an adjacent grass cell. After your move, every fire cell will spread to all adjacent cells that are not walls.\n\nReturn the maximum number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse. If this is impossible, return -1. If you can always reach the safehouse regardless of the minutes stayed, return 10^9.\n\nNote that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.\n\nA cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).\n\nExample 1:\n\nInput: grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]\nOutput: 3\nExplanation: The figure above shows the scenario where you stay in the initial position for 3 minutes.\nYou will still be able to safely reach the safehouse.\nStaying for more than 3 minutes will not allow you to safely reach the safehouse.\n\nExample 2:\n\nInput: grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]\nOutput: -1\nExplanation: The figure above shows the scenario where you immediately move towards the safehouse.\nFire will spread to any cell you move towards and it is impossible to safely reach the safehouse.\nThus, -1 is returned.\n\nExample 3:\n\nInput: grid = [[0,0,0],[2,2,0],[1,2,0]]\nOutput: 1000000000\nExplanation: The figure above shows the initial grid.\nNotice that the fire is contained by walls and you will always be able to safely reach the safehouse.\nThus, 10^9 is returned.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 300\n- 4 <= m * n <= 2 * 10^4\n- grid[i][j] is either 0, 1, or 2.\n- grid[0][0] == grid[m - 1][n - 1] == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 0, 0, 0], [0, 1, 2, 0], [0, 2, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 0, 0, 2, 0], [0, 2, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 2, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 2, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 2, 0, 2, 0], [0, 0, 0, 2, 0], [0, 1, 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, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 2, 1, 0], [0, 2, 0, 0, 0, 0], [0, 0, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 1], [0, 2, 2, 0], [0, 2, 2, 0], [0, 0, 0, 0]]) == -1\n assert candidate(grid = [[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]]) == 1000000000\n assert candidate(grid = [[0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 2, 2, 1, 0], [0, 2, 0, 0, 1, 2, 0], [0, 0, 2, 2, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 2, 2, 1, 0], [0, 2, 0, 0, 0, 2, 0], [0, 0, 2, 2, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 2, 2, 2, 0], [0, 2, 0, 2, 0], [0, 2, 2, 2, 0], [0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0], [2, 2, 0], [1, 2, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 2, 0, 0, 0, 0], [0, 1, 1, 1, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0], [0, 1, 1, 1, 0, 2, 0], [0, 0, 2, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 2, 0, 0], [0, 0, 0, 1, 2, 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, 2, 0, 0, 0], [0, 1, 2, 0, 1, 2, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 1, 0, 2, 0, 2, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 1, 2, 1, 0, 1, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 2, 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, 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, 0], [0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 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, 2, 0, 0, 0, 0], [0, 0, 0, 2, 1, 2, 0, 0, 0], [0, 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]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0], [0, 1, 0, 1, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2], [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, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 0, 1, 2, 1, 2, 0, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 1, 0], [2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 2, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 1, 0, 0]]) == -1\n assert candidate(grid = [[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, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 0, 1, 2, 1, 2, 1, 0, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 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, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 2, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 2, 2, 1, 0], [0, 2, 0, 0, 1, 2, 0], [0, 0, 2, 2, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 2, 0, 1, 0, 0], [0, 0, 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, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 2, 0, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 1, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 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, 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, 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\n assert candidate(grid = [[0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 2, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 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]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 2, 0, 2, 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, 0, 0, 1, 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, 0, 0, 0, 0], [0, 1, 2, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0], [0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 2, 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\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, 2, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 2, 2, 0, 0], [0, 0, 2, 2, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0], [0, 1, 0, 2, 0, 2, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 1, 2, 0, 0, 2, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 2, 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, 1, 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, 0, 0, 0, 0], [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, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 2, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 2, 0, 0], [0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 2, 0, 0, 2, 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, 2, 2, 2, 0, 0], [0, 0, 0, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 2, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 2], [0, 1, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 2, 0, 1, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 2, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 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]]) == -1\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, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 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], [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, 2, 0, 0], [0, 0, 1, 2, 0, 2, 1, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 2, 0, 0], [0, 0, 1, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0], [0, 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]]) == -1\n assert candidate(grid = [[0, 0, 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, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 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\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, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 1, 1, 1, 2, 0, 2, 1, 1, 0], [0, 0, 0, 0, 2, 2, 2, 0, 0, 0], [0, 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]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 1, 2, 2, 2, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 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, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 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, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 1, 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, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0], [0, 1, 0, 2, 0, 0, 0, 0], [0, 0, 0, 2, 2, 0, 1, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 2, 2, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 1, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 1, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 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, 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]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 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, 1, 2, 1, 2, 0], [0, 0, 1, 0, 0, 0], [0, 2, 0, 2, 1, 0], [0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 2, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 0, 2, 1, 0], [0, 1, 2, 0, 1, 0, 2, 1, 0], [0, 1, 2, 0, 0, 0, 2, 1, 0], [0, 1, 2, 2, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 1, 0], [0, 0, 0, 0, 2, 2, 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]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 1, 0, 0, 0, 1, 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]]) == -1\n assert candidate(grid = [[0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 2, 0], [0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 2, 1, 0, 2, 1, 0, 2, 0], [0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 2, 0], [0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 2, 1, 0, 2, 1, 0, 2, 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, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 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\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 0, 2, 0], [0, 0, 0, 0, 1, 0, 0], [0, 2, 0, 2, 0, 2, 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, 2, 0, 2, 0, 2, 0, 2, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 2, 0, 2, 0, 2, 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, 2, 1, 0, 0, 2, 0], [0, 0, 0, 0, 2, 0, 0], [0, 2, 0, 0, 0, 2, 0], [0, 0, 0, 2, 0, 0, 0], [0, 2, 0, 0, 0, 2, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 2, 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, 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, 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, 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, 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, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 2, 2, 2, 2, 1, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 2, 2, 0, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 1, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 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, 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, 1, 2, 2, 2, 0, 0, 1, 0], [0, 2, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 2, 0, 2, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 2, 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, 1, 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, 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, 1, 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, 0, 0, 0, 0], [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, 0], [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, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 2, 2, 2, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 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, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 2, 2, 2, 2, 1, 0], [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, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 2, 2, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 0, 1, 2, 1, 0, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 2, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0, 2, 0], [0, 2, 0, 0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 2, 0, 0], [0, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 2, 2, 2, 2, 2, 2, 1, 0], [0, 0, 0, 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, 0, 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, 2, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 1, 2, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0, 2, 0], [0, 2, 1, 0, 2, 1, 0, 2, 0, 2], [0, 0, 0, 2, 0, 0, 0, 0, 2, 0], [0, 1, 0, 0, 1, 0, 1, 2, 0, 0], [0, 0, 0, 2, 0, 0, 0, 0, 2, 0], [0, 2, 1, 0, 2, 1, 0, 2, 0, 2], [0, 0, 0, 2, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 2, 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, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 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\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, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 0, 1, 2, 0, 2, 1, 0], [0, 1, 2, 0, 0, 0, 0, 2, 1, 0], [0, 1, 2, 2, 2, 2, 2, 2, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 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, 0]]) == -1\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 0, 2, 1, 2], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == -1\n assert candidate(grid = [[0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1000000000\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2], [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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2], [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, 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", "comparison": "exact"}, "public_tests": ["[[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]", "[[0,0,0,0],[0,1,2,0],[0,2,0,0]]", "[[0,0,0],[2,2,0],[1,2,0]]"], "hints": ["For some tile (x, y), how can we determine when, if ever, the fire will reach it?", "We can use multi-source BFS to find the earliest time the fire will reach each cell.", "Then, starting with a given t minutes of staying in the initial position, we can check if there is a safe path to the safehouse using the obtained information about the fire.", "We can use binary search to efficiently find the maximum t that allows us to reach the safehouse."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maximumMinutes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:35+00:00", "tests_total": 85, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "binary-search", "breadth-first-search", "matrix"]}, "language": "php", "interface": {"raw_signature": "function maximumMinutes($grid) {", "container": "Solution", "callable": "maximumMinutes", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2259, "task_id": "remove-digit-from-number-to-maximize-result", "difficulty": "Easy", "problem_description": "You are given a string number representing a positive integer and a character digit.\n\nReturn the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.\n\nExample 1:\n\nInput: number = \"123\", digit = \"3\"\nOutput: \"12\"\nExplanation: There is only one '3' in \"123\". After removing '3', the result is \"12\".\n\nExample 2:\n\nInput: number = \"1231\", digit = \"1\"\nOutput: \"231\"\nExplanation: We can remove the first '1' to get \"231\" or remove the second '1' to get \"123\".\nSince 231 > 123, we return \"231\".\n\nExample 3:\n\nInput: number = \"551\", digit = \"5\"\nOutput: \"51\"\nExplanation: We can remove either the first or second '5' from \"551\".\nBoth result in the string \"51\".\n\nConstraints:\n\n- 2 <= number.length <= 100\n- number consists of digits from '1' to '9'.\n- digit is a digit from '1' to '9'.\n- digit occurs at least once in number.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(number = \"222333\",digit = \"2\") == \"22333\"\n assert candidate(number = \"99999\",digit = \"9\") == \"9999\"\n assert candidate(number = \"999\",digit = \"9\") == \"99\"\n assert candidate(number = \"551\",digit = \"5\") == \"51\"\n assert candidate(number = \"987654321\",digit = \"9\") == \"87654321\"\n assert candidate(number = \"123456789\",digit = \"5\") == \"12346789\"\n assert candidate(number = \"11111\",digit = \"1\") == \"1111\"\n assert candidate(number = \"123456789123456789\",digit = \"4\") == \"12356789123456789\"\n assert candidate(number = \"11211\",digit = \"1\") == \"1211\"\n assert candidate(number = \"123\",digit = \"3\") == \"12\"\n assert candidate(number = \"111111111\",digit = \"1\") == \"11111111\"\n assert candidate(number = \"1112\",digit = \"1\") == \"112\"\n assert candidate(number = \"999999999\",digit = \"9\") == \"99999999\"\n assert candidate(number = \"1231\",digit = \"1\") == \"231\"\n assert candidate(number = \"1221\",digit = \"1\") == \"221\"\n assert candidate(number = \"87654321\",digit = \"8\") == \"7654321\"\n assert candidate(number = \"3141592653589793\",digit = \"1\") == \"341592653589793\"\n assert candidate(number = \"123456789\",digit = \"8\") == \"12345679\"\n assert candidate(number = \"987654321\",digit = \"2\") == \"98765431\"\n assert candidate(number = \"1221\",digit = \"2\") == \"121\"\n assert candidate(number = \"2222222\",digit = \"2\") == \"222222\"\n assert candidate(number = \"1111\",digit = \"1\") == \"111\"\n assert candidate(number = \"123456789\",digit = \"9\") == \"12345678\"\n assert candidate(number = \"5656565656\",digit = \"6\") == \"565656565\"\n assert candidate(number = \"987654321123456789\",digit = \"4\") == \"98765432112356789\"\n assert candidate(number = \"123123123123\",digit = \"2\") == \"13123123123\"\n assert candidate(number = \"9898989898\",digit = \"8\") == \"998989898\"\n assert candidate(number = \"1122334455\",digit = \"1\") == \"122334455\"\n assert candidate(number = \"333333333\",digit = \"3\") == \"33333333\"\n assert candidate(number = \"12345654321\",digit = \"3\") == \"1245654321\"\n assert candidate(number = \"112233445566778899\",digit = \"5\") == \"11223344566778899\"\n assert candidate(number = \"987987987\",digit = \"7\") == \"98987987\"\n assert candidate(number = \"5959595959\",digit = \"9\") == \"595959595\"\n assert candidate(number = \"987654321123456789987654321\",digit = \"3\") == \"98765432112456789987654321\"\n assert candidate(number = \"122122122\",digit = \"2\") == \"12212212\"\n assert candidate(number = \"11111111111111111111111111111111111111111111111111\",digit = \"1\") == \"1111111111111111111111111111111111111111111111111\"\n assert candidate(number = \"1919191919191919\",digit = \"9\") == \"191919191919191\"\n assert candidate(number = \"543219876\",digit = \"9\") == \"54321876\"\n assert candidate(number = \"987654321987654321987654321987654321\",digit = \"8\") == \"98765432198765432198765432197654321\"\n assert candidate(number = \"123412341234\",digit = \"2\") == \"13412341234\"\n assert candidate(number = \"1919191919\",digit = \"9\") == \"191919191\"\n assert candidate(number = \"1919191919191919191919191919191919191919191919191\",digit = \"9\") == \"191919191919191919191919191919191919191919191911\"\n assert candidate(number = \"9999999999\",digit = \"9\") == \"999999999\"\n assert candidate(number = \"543219876987654321\",digit = \"9\") == \"54321987687654321\"\n assert candidate(number = \"987654321123456789\",digit = \"1\") == \"98765432123456789\"\n assert candidate(number = \"3131313131\",digit = \"1\") == \"331313131\"\n assert candidate(number = \"555555555555555555555\",digit = \"5\") == \"55555555555555555555\"\n assert candidate(number = \"9999999999999999999\",digit = \"9\") == \"999999999999999999\"\n assert candidate(number = \"1212121212\",digit = \"2\") == \"121212121\"\n assert candidate(number = \"12345123451234512345\",digit = \"4\") == \"1235123451234512345\"\n assert candidate(number = \"91827364591827364591\",digit = \"1\") == \"9827364591827364591\"\n assert candidate(number = \"567567567\",digit = \"7\") == \"56756756\"\n assert candidate(number = \"999888777666555444333222111\",digit = \"9\") == \"99888777666555444333222111\"\n assert candidate(number = \"5645645645645645645645645645645645645645645645645\",digit = \"5\") == \"645645645645645645645645645645645645645645645645\"\n assert candidate(number = \"1234321\",digit = \"3\") == \"124321\"\n assert candidate(number = \"123456789123456789123456789\",digit = \"8\") == \"12345679123456789123456789\"\n assert candidate(number = \"123123123123123\",digit = \"1\") == \"23123123123123\"\n assert candidate(number = \"5656565656\",digit = \"5\") == \"656565656\"\n assert candidate(number = \"918273645\",digit = \"9\") == \"18273645\"\n assert candidate(number = \"12233445566778899\",digit = \"9\") == \"1223344556677889\"\n assert candidate(number = \"5555555555555555555\",digit = \"5\") == \"555555555555555555\"\n assert candidate(number = \"999999999999999999999\",digit = \"9\") == \"99999999999999999999\"\n assert candidate(number = \"33333333333333333333333333333333333333333333333333\",digit = \"3\") == \"3333333333333333333333333333333333333333333333333\"\n assert candidate(number = \"3232323232323232\",digit = \"3\") == \"323232323232322\"\n assert candidate(number = \"123456789\",digit = \"2\") == \"13456789\"\n assert candidate(number = \"19191919191919191919\",digit = \"9\") == \"1919191919191919191\"\n assert candidate(number = \"123123123\",digit = \"1\") == \"23123123\"\n assert candidate(number = \"5645645645645645645645645645645645645645645645645\",digit = \"6\") == \"564564564564564564564564564564564564564564564545\"\n assert candidate(number = \"123987654321987654321987654321\",digit = \"9\") == \"12398765432198765432187654321\"\n assert candidate(number = \"1212121212121212121\",digit = \"2\") == \"121212121212121211\"\n assert candidate(number = \"123123123123123123123\",digit = \"3\") == \"12312312312312312312\"\n assert candidate(number = \"11111111111111111111\",digit = \"1\") == \"1111111111111111111\"\n assert candidate(number = \"112233445566778899\",digit = \"1\") == \"12233445566778899\"\n assert candidate(number = \"2222222222222222222222222222222\",digit = \"2\") == \"222222222222222222222222222222\"\n assert candidate(number = \"123987654321987654321987654321\",digit = \"1\") == \"23987654321987654321987654321\"\n assert candidate(number = \"987654321987654321\",digit = \"9\") == \"98765432187654321\"\n assert candidate(number = \"11111111111111111111111111111111111111111111\",digit = \"1\") == \"1111111111111111111111111111111111111111111\"\n assert candidate(number = \"9999999999999999999999999999999999999999999999999\",digit = \"9\") == \"999999999999999999999999999999999999999999999999\"\n assert candidate(number = \"111222333444555666777888999\",digit = \"3\") == \"11122233444555666777888999\"\n assert candidate(number = \"23333332\",digit = \"3\") == \"2333332\"\n assert candidate(number = \"22222222222222222222222222222222222222222222\",digit = \"2\") == \"2222222222222222222222222222222222222222222\"\n assert candidate(number = \"99999999991\",digit = \"9\") == \"9999999991\"\n assert candidate(number = \"333333\",digit = \"3\") == \"33333\"\n assert candidate(number = \"123456789123456789123456789\",digit = \"9\") == \"12345678912345678912345678\"\n assert candidate(number = \"123412341234\",digit = \"1\") == \"23412341234\"\n assert candidate(number = \"987654321123456789\",digit = \"9\") == \"98765432112345678\"\n assert candidate(number = \"543212345\",digit = \"2\") == \"54321345\"\n assert candidate(number = \"1111111111\",digit = \"1\") == \"111111111\"\n assert candidate(number = \"432143214321\",digit = \"2\") == \"43214321431\"\n assert candidate(number = \"12233445566778899\",digit = \"1\") == \"2233445566778899\"\n assert candidate(number = \"5555555555555555555555555555555555555555555555555\",digit = \"5\") == \"555555555555555555555555555555555555555555555555\"\n assert candidate(number = \"11112222\",digit = \"2\") == \"1111222\"\n assert candidate(number = \"31415926535\",digit = \"1\") == \"3415926535\"\n assert candidate(number = \"98877665544332211\",digit = \"8\") == \"9877665544332211\"\n assert candidate(number = \"2468135791113151719\",digit = \"1\") == \"246835791113151719\"\n assert candidate(number = \"12345678987654321\",digit = \"7\") == \"1234568987654321\"\n", "comparison": "exact"}, "public_tests": ["\"123\"\n\"3\"", "\"1231\"\n\"1\"", "\"551\"\n\"5\""], "hints": ["The maximum length of number is really small.", "Iterate through the digits of number and every time we see digit, try removing it.", "To remove a character at index i, concatenate the substring from index 0 to i - 1 and the substring from index i + 1 to number.length - 1."], "metadata": {"canonical_parameter_names": ["number", "digit"], "leetcode_dataset_entry_point": "Solution().removeDigit", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:37+00:00", "tests_total": 126, "tests_dropped": 30, "flags": [], "topic_tags": ["string", "greedy", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function removeDigit($number, $digit) {", "container": "Solution", "callable": "removeDigit", "parameters": [{"name": "number", "type": "String"}, {"name": "digit", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2260, "task_id": "minimum-consecutive-cards-to-pick-up", "difficulty": "Medium", "problem_description": "You are given an integer array cards where cards[i] represents the value of the i^th card. A pair of cards are matching if the cards have the same value.\n\nReturn the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching cards, return -1.\n\nExample 1:\n\nInput: cards = [3,4,2,3,4,7]\nOutput: 4\nExplanation: We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.\n\nExample 2:\n\nInput: cards = [1,0,5,3]\nOutput: -1\nExplanation: There is no way to pick up a set of consecutive cards that contain a pair of matching cards.\n\nConstraints:\n\n- 1 <= cards.length <= 10^5\n- 0 <= cards[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(cards = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 11\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) == 21\n assert candidate(cards = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 10\n assert candidate(cards = [3, 4, 2, 3, 4, 7]) == 4\n assert candidate(cards = [0, 0]) == 2\n assert candidate(cards = [1, 1]) == 2\n assert candidate(cards = [0, 0, 0, 0, 0]) == 2\n assert candidate(cards = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1]) == -1\n assert candidate(cards = [5]) == -1\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(cards = [1000000, 999999, 1000000]) == 3\n assert candidate(cards = [1, 1, 1, 1, 1]) == 2\n assert candidate(cards = [1, 0, 5, 3]) == -1\n assert candidate(cards = [1000000, 0, 1000000]) == 3\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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, 1]) == 51\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1]) == 12\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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]) == 51\n assert candidate(cards = [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, 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]) == 11\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 21\n assert candidate(cards = [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]) == 2\n assert candidate(cards = [5, 3, 8, 10, 5, 3, 8, 10, 5, 3, 8, 10, 5, 3, 8, 10, 5, 3, 8, 10]) == 5\n assert candidate(cards = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5]) == 7\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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, 1, 2, 3, 4, 5, 6, 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]) == 31\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 11\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 5, 15, 25, 35, 45, 55, 65, 75, 85]) == 12\n assert candidate(cards = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 10]) == 21\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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(cards = [1000000, 999999, 999998, 999997, 999996, 999995, 1000000]) == 7\n assert candidate(cards = [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]) == 6\n assert candidate(cards = [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]) == 11\n assert candidate(cards = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1]) == 6\n assert candidate(cards = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 2\n assert candidate(cards = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(cards = [5, 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(cards = [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, 0]) == 32\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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, 1]) == 31\n assert candidate(cards = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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(cards = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981, 999980, 999999]) == 21\n assert candidate(cards = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10]) == 11\n assert candidate(cards = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 500, 300]) == 8\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 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]) == 2\n assert candidate(cards = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 1000]) == 11\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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]) == 51\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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(cards = [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]) == 2\n assert candidate(cards = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 6\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [9, 3, 1, 3, 2, 5, 9, 8, 3, 9]) == 3\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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]) == 31\n assert candidate(cards = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 1000000]) == 11\n assert candidate(cards = [1, 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, 1]) == 2\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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]) == 2\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 11\n assert candidate(cards = [1000000, 999999, 999998, 1000000, 999997, 999996, 999995, 999994, 999993, 1000000]) == 4\n assert candidate(cards = [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]) == 11\n assert candidate(cards = [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]) == 11\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6]) == 11\n assert candidate(cards = [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, 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]) == 21\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 3\n assert candidate(cards = [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]) == 2\n assert candidate(cards = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(cards = [1000000, 999999, 999998, 999997, 1000000, 999996, 999995, 999994, 999993, 999992, 999991, 999990, 999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981, 999980]) == 5\n assert candidate(cards = [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]) == 26\n assert candidate(cards = [42, 17, 23, 34, 42, 17, 23, 34, 42, 17, 23, 34, 42]) == 5\n assert candidate(cards = [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, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]) == 26\n assert candidate(cards = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 11\n assert candidate(cards = [1, 0, 5, 3, 2, 4, 6, 7, 8, 9, 1, 0, 5, 3, 2, 4, 6, 7, 8, 9]) == 11\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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, 1]) == 2\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) == 21\n assert candidate(cards = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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(cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(cards = [1000000, 999999, 999998, 999997, 999996, 1000000]) == 6\n assert candidate(cards = [1000000, 999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 1000000]) == 11\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 11\n assert candidate(cards = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 17\n assert candidate(cards = [1, 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]) == 26\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(cards = [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]) == 11\n assert candidate(cards = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000, 100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000]) == 11\n assert candidate(cards = [1, 0, 5, 3, 2, 2, 5, 1, 0, 3, 2, 1]) == 2\n assert candidate(cards = [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]) == 2\n assert candidate(cards = [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]) == 11\n assert candidate(cards = [100000, 200000, 300000, 100000, 400000, 500000, 600000, 700000, 800000, 900000, 100000]) == 4\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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]) == 31\n assert candidate(cards = [1, 2, 3, 4, 5, 6, 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, 1]) == 101\n assert candidate(cards = [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, 1]) == 2\n assert candidate(cards = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 3\n assert candidate(cards = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 1]) == 21\n assert candidate(cards = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 11\n assert candidate(cards = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 2\n assert candidate(cards = [1, 2, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 2\n assert candidate(cards = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 1000000]) == 11\n assert candidate(cards = [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]) == 2\n assert candidate(cards = [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, 1]) == 21\n assert candidate(cards = [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]) == 21\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 11\n assert candidate(cards = [1000000, 1000000, 1000000, 1000000, 1000000]) == 2\n assert candidate(cards = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10]) == 11\n assert candidate(cards = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]) == 11\n assert candidate(cards = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == 3\n assert candidate(cards = [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]) == 12\n assert candidate(cards = [100000, 200000, 300000, 400000, 500000, 100000, 200000, 300000, 400000, 500000]) == 6\n", "comparison": "exact"}, "public_tests": ["[3,4,2,3,4,7]", "[1,0,5,3]"], "hints": ["Iterate through the cards and store the location of the last occurrence of each number.", "What data structure could you use to get the last occurrence of a number in O(1) or O(log n)?"], "metadata": {"canonical_parameter_names": ["cards"], "leetcode_dataset_entry_point": "Solution().minimumCardPickup", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:39+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function minimumCardPickup($cards) {", "container": "Solution", "callable": "minimumCardPickup", "parameters": [{"name": "cards", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2261, "task_id": "k-divisible-elements-subarrays", "difficulty": "Medium", "problem_description": "Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p.\n\nTwo arrays nums1 and nums2 are said to be distinct if:\n\n- They are of different lengths, or\n- There exists at least one index i where nums1[i] != nums2[i].\n\nA subarray is defined as a non-empty contiguous sequence of elements in an array.\n\nExample 1:\n\nInput: nums = [2,3,3,2,2], k = 2, p = 2\nOutput: 11\nExplanation:\nThe elements at indices 0, 3, and 4 are divisible by p = 2.\nThe 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:\n[2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].\nNote that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.\nThe subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4], k = 4, p = 1\nOutput: 10\nExplanation:\nAll element of nums are divisible by p = 1.\nAlso, every subarray of nums will have at most 4 elements that are divisible by 1.\nSince all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.\n\nConstraints:\n\n- 1 <= nums.length <= 200\n- 1 <= nums[i], p <= 200\n- 1 <= k <= nums.length\n\nFollow up:\n\nCan you solve this problem in O(n^2) time complexity?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 1, 2, 1],k = 1,p = 2) == 5\n assert candidate(nums = [19, 23, 29, 31, 37],k = 3,p = 5) == 15\n assert candidate(nums = [1, 2, 1, 2],k = 1,p = 2) == 5\n assert candidate(nums = [13, 26, 39, 52, 65],k = 2,p = 13) == 9\n assert candidate(nums = [5, 5, 5, 5],k = 2,p = 5) == 2\n assert candidate(nums = [5, 10, 15, 20],k = 2,p = 5) == 7\n assert candidate(nums = [5, 10, 15, 20, 25],k = 3,p = 5) == 12\n assert candidate(nums = [7, 11, 13, 17],k = 1,p = 2) == 10\n assert candidate(nums = [6, 3, 2, 8, 7, 1],k = 3,p = 3) == 21\n assert candidate(nums = [5, 5, 5, 5],k = 1,p = 5) == 1\n assert candidate(nums = [3, 9, 12, 15, 18],k = 2,p = 3) == 9\n assert candidate(nums = [11, 22, 33, 44, 55],k = 3,p = 11) == 12\n assert candidate(nums = [19, 19, 19, 19, 19],k = 3,p = 19) == 3\n assert candidate(nums = [7, 14, 21, 28, 35],k = 2,p = 7) == 9\n assert candidate(nums = [2, 4, 6, 8, 10],k = 1,p = 2) == 5\n assert candidate(nums = [3, 6, 9, 12, 15],k = 1,p = 3) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30],k = 3,p = 5) == 15\n assert candidate(nums = [7, 14, 21, 28, 35],k = 1,p = 7) == 5\n assert candidate(nums = [3, 6, 9, 12, 15],k = 2,p = 3) == 9\n assert candidate(nums = [200, 100, 50, 25, 12],k = 1,p = 25) == 6\n assert candidate(nums = [1, 1, 1, 1, 1],k = 2,p = 1) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 2,p = 10) == 9\n assert candidate(nums = [1, 1, 1, 1],k = 1,p = 1) == 1\n assert candidate(nums = [10, 5, 15, 20, 25],k = 3,p = 5) == 12\n assert candidate(nums = [6, 3, 9, 12, 15],k = 2,p = 3) == 9\n assert candidate(nums = [2, 3, 3, 2, 2],k = 2,p = 2) == 11\n assert candidate(nums = [11, 13, 17, 19, 23],k = 5,p = 2) == 15\n assert candidate(nums = [6, 12, 18, 24, 30],k = 3,p = 3) == 12\n assert candidate(nums = [11, 22, 33, 44, 55],k = 5,p = 10) == 15\n assert candidate(nums = [8, 16, 24, 32, 40],k = 2,p = 8) == 9\n assert candidate(nums = [1, 2, 3, 4],k = 4,p = 1) == 10\n assert candidate(nums = [1, 6, 3, 2, 7, 4],k = 3,p = 3) == 21\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 = 15,p = 3) == 195\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 = 8,p = 1) == 132\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],k = 5,p = 5) == 50\n assert candidate(nums = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200],k = 1,p = 20) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10,p = 1) == 55\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 2,p = 11) == 19\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],k = 15,p = 7) == 231\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 = 25,p = 2) == 325\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,p = 1) == 5\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],k = 4,p = 4) == 34\n assert candidate(nums = [200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181],k = 15,p = 200) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7,p = 3) == 120\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 2,p = 2) == 9\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 5,p = 2) == 65\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 200],k = 5,p = 5) == 210\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165],k = 6,p = 11) == 75\n assert candidate(nums = [200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181],k = 15,p = 19) == 210\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10,p = 10) == 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 = 10,p = 3) == 210\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,p = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,p = 10) == 40\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],k = 7,p = 7) == 77\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200],k = 4,p = 100) == 8\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 3,p = 15) == 27\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155],k = 7,p = 5) == 91\n assert candidate(nums = [12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126],k = 12,p = 6) == 174\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,p = 2) == 147\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 3,p = 4) == 47\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 2,p = 13) == 19\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 5,p = 4) == 55\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3,p = 2) == 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],k = 5,p = 3) == 201\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 = 15,p = 2) == 210\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 = 10,p = 7) == 155\n assert candidate(nums = [15, 18, 21, 24, 27, 30, 33, 36, 39, 42],k = 5,p = 3) == 40\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 = 15,p = 2) == 345\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,p = 5) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 4,p = 7) == 34\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3,p = 1) == 3\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 3,p = 11) == 27\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2,p = 2) == 55\n assert candidate(nums = [200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181],k = 10,p = 2) == 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 = 5,p = 2) == 160\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5,p = 5) == 5\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,p = 5) == 155\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,p = 3) == 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 = 5,p = 2) == 20\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 5,p = 2) == 19\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33],k = 5,p = 3) == 45\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 4,p = 7) == 34\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],k = 5,p = 4) == 40\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],k = 50,p = 1) == 50\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 = 10,p = 3) == 155\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,p = 1) == 90\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42],k = 5,p = 3) == 60\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,p = 2) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 4,p = 3) == 34\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 = 7,p = 3) == 119\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 2,p = 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],k = 10,p = 1) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 6,p = 2) == 75\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91],k = 7,p = 7) == 70\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 4,p = 10) == 34\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 = 10,p = 2) == 210\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],k = 15,p = 5) == 270\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,p = 5) == 155\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 6,p = 2) == 75\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,p = 1) == 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],k = 20,p = 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],k = 3,p = 1) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 10,p = 2) == 105\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 3,p = 7) == 27\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91],k = 6,p = 7) == 63\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 = 20,p = 2) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 5,p = 2) == 40\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],k = 7,p = 5) == 84\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],k = 3,p = 10) == 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, 101, 103, 107, 109, 113],k = 15,p = 2) == 465\n assert candidate(nums = [5, 10, 5, 10, 5, 10, 5, 10, 5, 10],k = 3,p = 5) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,p = 10) == 40\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 5,p = 2) == 40\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200],k = 4,p = 25) == 26\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,p = 3) == 210\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111],k = 6,p = 101) == 66\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 5,p = 3) == 65\n", "comparison": "exact"}, "public_tests": ["[2,3,3,2,2]\n2\n2", "[1,2,3,4]\n4\n1"], "hints": ["Enumerate all subarrays and find the ones that satisfy all the conditions.", "Use any suitable method to hash the subarrays to avoid duplicates."], "metadata": {"canonical_parameter_names": ["nums", "k", "p"], "leetcode_dataset_entry_point": "Solution().countDistinct", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:41+00:00", "tests_total": 135, "tests_dropped": 18, "flags": [], "topic_tags": ["array", "hash-table", "trie", "rolling-hash", "hash-function", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countDistinct($nums, $k, $p) {", "container": "Solution", "callable": "countDistinct", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "p", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2262, "task_id": "total-appeal-of-a-string", "difficulty": "Hard", "problem_description": "The appeal of a string is the number of distinct characters found in the string.\n\n- For example, the appeal of \"abbca\" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.\n\nGiven a string s, return the total appeal of all of its substrings.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"abbca\"\nOutput: 28\nExplanation: The following are the substrings of \"abbca\":\n- Substrings of length 1: \"a\", \"b\", \"b\", \"c\", \"a\" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.\n- Substrings of length 2: \"ab\", \"bb\", \"bc\", \"ca\" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.\n- Substrings of length 3: \"abb\", \"bbc\", \"bca\" have an appeal of 2, 2, and 3 respectively. The sum is 7.\n- Substrings of length 4: \"abbc\", \"bbca\" have an appeal of 3 and 3 respectively. The sum is 6.\n- Substrings of length 5: \"abbca\" has an appeal of 3. The sum is 3.\nThe total sum is 5 + 7 + 7 + 6 + 3 = 28.\n\nExample 2:\n\nInput: s = \"code\"\nOutput: 20\nExplanation: The following are the substrings of \"code\":\n- Substrings of length 1: \"c\", \"o\", \"d\", \"e\" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.\n- Substrings of length 2: \"co\", \"od\", \"de\" have an appeal of 2, 2, and 2 respectively. The sum is 6.\n- Substrings of length 3: \"cod\", \"ode\" have an appeal of 3 and 3 respectively. The sum is 6.\n- Substrings of length 4: \"code\" has an appeal of 4. The sum is 4.\nThe total sum is 4 + 6 + 6 + 4 = 20.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 3276\n assert candidate(s = \"zzzaaa\") == 30\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abacabadabacaba\") == 357\n assert candidate(s = \"abcabcabc\") == 109\n assert candidate(s = \"abbca\") == 28\n assert candidate(s = \"ababababab\") == 100\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\") == 210\n assert candidate(s = \"aaa\") == 6\n assert candidate(s = \"python\") == 56\n assert candidate(s = \"abcabc\") == 46\n assert candidate(s = \"world\") == 35\n assert candidate(s = \"zzzzzzzzzz\") == 55\n assert candidate(s = \"abcdabcdabcd\") == 244\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 1306\n assert candidate(s = \"abc\") == 10\n assert candidate(s = \"abcd\") == 20\n assert candidate(s = \"aaaa\") == 10\n assert candidate(s = \"hello\") == 29\n assert candidate(s = \"mississippi\") == 148\n assert candidate(s = \"zzzzz\") == 15\n assert candidate(s = \"z\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 13078\n assert candidate(s = \"longstringwithvariouscharacters\") == 3921\n assert candidate(s = \"code\") == 20\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 3276\n assert candidate(s = \"xyzzxyzzxyzz\") == 191\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeefffffffffgggggggggghhhhhhhhhh\") == 11380\n assert candidate(s = \"abcdefg\") == 84\n assert candidate(s = \"aabbccaaabbbccc\") == 274\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzz\") == 18730\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghij\") == 6520\n assert candidate(s = \"bbaaccddeeffgg\") == 329\n assert candidate(s = \"aabbaabbaabbccddeeefffggghhhiiijjjkkklllmnnnooopppqqqrrrsssttuuuuuuuuvvwxyz\") == 26940\n assert candidate(s = \"abracadabra\") == 210\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 1306\n assert candidate(s = \"uniquecharacters\") == 677\n assert candidate(s = \"aabbc\") == 25\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzz\") == 23011\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabb\") == 1008\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbcccccccccc\") == 865\n assert candidate(s = \"abacabadabacabadabacabadabacabad\") == 1838\n assert candidate(s = \"ababababababababababababababa\") == 841\n assert candidate(s = \"ninetyninebottlesofbeer\") == 1564\n assert candidate(s = \"abcdabcdbcadbacdbac\") == 646\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 1820\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == 46306\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 5345\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\") == 3276\n assert candidate(s = \"abcabcabcabcabcabcabcabcabc\") == 1054\n assert candidate(s = \"abababababababab\") == 256\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 21528\n assert candidate(s = \"xyxzyzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxz\") == 5105\n assert candidate(s = \"hellohellohello\") == 377\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == 46120\n assert candidate(s = \"banana\") == 40\n assert candidate(s = \"hellohellobyebye\") == 513\n assert candidate(s = \"pneumonoultramicroscopicsilicovolcanoconiosis\") == 8230\n assert candidate(s = \"abacabadaba\") == 177\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1378\n assert candidate(s = \"thisisareallylongteststringwithmanydistinctcharactersandrepeatedones\") == 25027\n assert candidate(s = \"thisisaverylongstringwithmanycopiesofthissubstringthissubstringthissubstring\") == 35609\n assert candidate(s = \"xyxzyxyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyz\") == 2363\n assert candidate(s = \"aaaaabbbbbccccc\") == 220\n assert candidate(s = \"xyzzzyxzyzyzyxzyzyxzyzyzyzyxzyzyzyzyzyzyzyzyzyzyzyzyzyz\") == 4088\n assert candidate(s = \"amazingappeal\") == 374\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1275\n assert candidate(s = \"aabbccaaaabbbccc\") == 309\n assert candidate(s = \"abacabadabacabaabacabadabacaba\") == 1555\n", "comparison": "exact"}, "public_tests": ["\"abbca\"", "\"code\""], "hints": ["Consider the set of substrings that end at a certain index i. Then, consider a specific alphabetic character. How do you count the number of substrings ending at index i that contain that character?", "The number of substrings that contain the alphabetic character is equivalent to 1 plus the index of the last occurrence of the character before index i + 1.", "The total appeal of all substrings ending at index i is the total sum of the number of substrings that contain each alphabetic character.", "To find the total appeal of all substrings, we simply sum up the total appeal for each index."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().appealSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:44+00:00", "tests_total": 69, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function appealSum($s) {", "container": "Solution", "callable": "appealSum", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2264, "task_id": "largest-3-same-digit-number-in-string", "difficulty": "Easy", "problem_description": "You are given a string num representing a large integer. An integer is good if it meets the following conditions:\n\n- It is a substring of num with length 3.\n- It consists of only one unique digit.\n\nReturn the maximum good integer as a string or an empty string \"\" if no such integer exists.\n\nNote:\n\n- A substring is a contiguous sequence of characters within a string.\n- There may be leading zeroes in num or a good integer.\n\nExample 1:\n\nInput: num = \"6777133339\"\nOutput: \"777\"\nExplanation: There are two distinct good integers: \"777\" and \"333\".\n\"777\" is the largest, so we return \"777\".\n\nExample 2:\n\nInput: num = \"2300019\"\nOutput: \"000\"\nExplanation: \"000\" is the only good integer.\n\nExample 3:\n\nInput: num = \"42352338\"\nOutput: \"\"\nExplanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.\n\nConstraints:\n\n- 3 <= num.length <= 1000\n- num only consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"999888777666555444333222111000\") == \"999\"\n assert candidate(num = \"000\") == \"000\"\n assert candidate(num = \"42352338\") == \"\"\n assert candidate(num = \"9876543210\") == \"\"\n assert candidate(num = \"555444555\") == \"555\"\n assert candidate(num = \"112233445566778899\") == \"\"\n assert candidate(num = \"888777666555444333222111000\") == \"888\"\n assert candidate(num = \"2300019\") == \"000\"\n assert candidate(num = \"10000001\") == \"000\"\n assert candidate(num = \"123\") == \"\"\n assert candidate(num = \"6777133339\") == \"777\"\n assert candidate(num = \"1222333444555666777888999000\") == \"999\"\n assert candidate(num = \"888777666555444333222111\") == \"888\"\n assert candidate(num = \"333333333\") == \"333\"\n assert candidate(num = \"999999999\") == \"999\"\n assert candidate(num = \"999999\") == \"999\"\n assert candidate(num = \"11223344556677889900\") == \"\"\n assert candidate(num = \"9999999\") == \"999\"\n assert candidate(num = \"1234567890\") == \"\"\n assert candidate(num = \"000111222333444555666777888999\") == \"999\"\n assert candidate(num = \"111222333\") == \"333\"\n assert candidate(num = \"888888888888888888888\") == \"888\"\n assert candidate(num = \"100100100\") == \"\"\n assert candidate(num = \"000000000\") == \"000\"\n assert candidate(num = \"111111111\") == \"111\"\n assert candidate(num = \"111\") == \"111\"\n assert candidate(num = \"123123123123123123123123123123123123\") == \"\"\n assert candidate(num = \"1234444321111234444321\") == \"444\"\n assert candidate(num = \"12345678987654321000000123456789\") == \"000\"\n assert candidate(num = \"555444333222111000000000000111222333444\") == \"555\"\n assert candidate(num = \"123456789123456789123456789123456789123456789\") == \"\"\n assert candidate(num = \"1233344445555566666777777\") == \"777\"\n assert candidate(num = \"555444333222111000000111222333444555\") == \"555\"\n assert candidate(num = \"1222222222222222222222222222221\") == \"222\"\n assert candidate(num = \"555444333222111000999888777666555\") == \"999\"\n assert candidate(num = \"10000001000000100000010000001000000\") == \"000\"\n assert candidate(num = \"987654321111111111111111111111987654321000000000\") == \"111\"\n assert candidate(num = \"88888888888888888888888888888888888888888888\") == \"888\"\n assert candidate(num = \"1234567890123456789012345678901234567890\") == \"\"\n assert candidate(num = \"12345678987654321012345678987654321\") == \"\"\n assert candidate(num = \"999000111222333444555666777888999\") == \"999\"\n assert candidate(num = \"000123456789\") == \"000\"\n assert candidate(num = \"111111222222333333444444555555666666777777888888999999\") == \"999\"\n assert candidate(num = \"1111111111111111111111111111111111111111111111111\") == \"111\"\n assert candidate(num = \"123123123123123123123123\") == \"\"\n assert candidate(num = \"123123123123123123123123123123\") == \"\"\n assert candidate(num = \"1000000000000000000000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"01234567890123456789012345678901234567890\") == \"\"\n assert candidate(num = \"999999999999999999999999999999\") == \"999\"\n assert candidate(num = \"987654321111111111111111111111987654321\") == \"111\"\n assert candidate(num = \"111222333444555666777888999000111222333444555666777888999\") == \"999\"\n assert candidate(num = \"1221221221221221221221221\") == \"\"\n assert candidate(num = \"000000000000000000000000000\") == \"000\"\n assert candidate(num = \"123123123123123123123123123\") == \"\"\n assert candidate(num = \"55555555555555555555555555555555555555555555555555555555\") == \"555\"\n assert candidate(num = \"123333456789000123456789\") == \"333\"\n assert candidate(num = \"00000000000000000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"99999999999999999999999999999999999999999999\") == \"999\"\n assert candidate(num = \"333333333333333333333333333333\") == \"333\"\n assert candidate(num = \"9990000000000000000000000000000000000000000000000000000000\") == \"999\"\n assert candidate(num = \"1122334455667788990011223344556677889900\") == \"\"\n assert candidate(num = \"33333333333333333333333333333333333333333333\") == \"333\"\n assert candidate(num = \"987654321000000000987654321\") == \"000\"\n assert candidate(num = \"122333444555666777888999\") == \"999\"\n assert candidate(num = \"888999777666555444333222111000\") == \"999\"\n assert candidate(num = \"111222333444555666777888999000\") == \"999\"\n assert candidate(num = \"123332111112222233333\") == \"333\"\n assert candidate(num = \"98765432109876543210987654321\") == \"\"\n assert candidate(num = \"000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"11111111111111111111111111111111111111111111\") == \"111\"\n assert candidate(num = \"98765432111111111111111111111111111111111111\") == \"111\"\n assert candidate(num = \"999111222333444555666777888\") == \"999\"\n assert candidate(num = \"123332111222222111111\") == \"333\"\n assert candidate(num = \"111222333444555666777888999111222333444555\") == \"999\"\n assert candidate(num = \"10101010101010101010101010101010101010101010\") == \"\"\n assert candidate(num = \"12345678987654321111100000000222222333333\") == \"333\"\n assert candidate(num = \"1000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"111222333444555666777888999000111222\") == \"999\"\n assert candidate(num = \"98765432111123456789000000\") == \"111\"\n assert candidate(num = \"999000999000999\") == \"999\"\n assert candidate(num = \"0000000000000000000000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"000000111111222222333333444444555555666666777777888888999999\") == \"999\"\n assert candidate(num = \"111222333444555666777888999111\") == \"999\"\n assert candidate(num = \"987654321098765432109876543210\") == \"\"\n assert candidate(num = \"888999888999888999888999888999\") == \"999\"\n assert candidate(num = \"111000111000111000111000\") == \"111\"\n assert candidate(num = \"1234555554321\") == \"555\"\n assert candidate(num = \"123456789123456789123456789\") == \"\"\n assert candidate(num = \"111000111000111000111000111000\") == \"111\"\n assert candidate(num = \"111000222333444555666777888999\") == \"999\"\n assert candidate(num = \"333222111333222111333222111\") == \"333\"\n assert candidate(num = \"101010101010101010101010101\") == \"\"\n assert candidate(num = \"1111111111111111111111111111111\") == \"111\"\n assert candidate(num = \"12345678999987654321\") == \"999\"\n assert candidate(num = \"111122223333444455556666777788889999\") == \"999\"\n assert candidate(num = \"123456789000000987654321\") == \"000\"\n assert candidate(num = \"999888777666555444333222111\") == \"999\"\n assert candidate(num = \"555555555555555555555555555555555555555555555555\") == \"555\"\n assert candidate(num = \"111222333444555666777888999\") == \"999\"\n assert candidate(num = \"999888777666555444333222111000999888777\") == \"999\"\n assert candidate(num = \"111000111222333\") == \"333\"\n assert candidate(num = \"123456789876543211222333444555666777888999\") == \"999\"\n assert candidate(num = \"123456789876543211111111111111\") == \"111\"\n assert candidate(num = \"9999999999999999999999999999999999999999999999999\") == \"999\"\n assert candidate(num = \"123456789000000000000000000\") == \"000\"\n assert candidate(num = \"987654321000000123456789\") == \"000\"\n assert candidate(num = \"111999888777666555444333222111\") == \"999\"\n assert candidate(num = \"5555555555555555555555555555555\") == \"555\"\n assert candidate(num = \"333222111000999888777666555444333222111000\") == \"999\"\n assert candidate(num = \"1233321111222223333\") == \"333\"\n assert candidate(num = \"0011223344556677889900112233445566\") == \"\"\n assert candidate(num = \"123456789012345678901234567890\") == \"\"\n assert candidate(num = \"000111222333444555666777888999000111222333\") == \"999\"\n assert candidate(num = \"1111122223333444455556666777788889999\") == \"999\"\n assert candidate(num = \"5555555555555555555555555\") == \"555\"\n assert candidate(num = \"111222333444555666777888999000111\") == \"999\"\n assert candidate(num = \"999000999000999000999000999000999000\") == \"999\"\n assert candidate(num = \"1234567890000000000000000000000000000000\") == \"000\"\n assert candidate(num = \"123456789123456789123456789123456789\") == \"\"\n assert candidate(num = \"11111111111111111111111111111100000000000000000\") == \"111\"\n assert candidate(num = \"555555444444333333222222111111\") == \"555\"\n assert candidate(num = \"333222111000777888999\") == \"999\"\n assert candidate(num = \"555555555555555555555555555555\") == \"555\"\n assert candidate(num = \"1222233333444444555555566666667\") == \"666\"\n assert candidate(num = \"123123123123123123123123123123123123123123123123123123123123\") == \"\"\n assert candidate(num = \"123456789999987654321\") == \"999\"\n assert candidate(num = \"990990990990990990\") == \"\"\n assert candidate(num = \"123455567890123456789012345678\") == \"555\"\n assert candidate(num = \"111111111111111111111111111111\") == \"111\"\n assert candidate(num = \"12345556789000987654321000000\") == \"555\"\n assert candidate(num = \"22222222222222222222222222222222222222222222\") == \"222\"\n assert candidate(num = \"10000000000000000000000000000001\") == \"000\"\n assert candidate(num = \"000111000111000111000111000111\") == \"111\"\n", "comparison": "exact"}, "public_tests": ["\"6777133339\"", "\"2300019\"", "\"42352338\""], "hints": ["We can sequentially check if “999”, “888”, “777”, … , “000” exists in num in that order. The first to be found is the maximum good integer.", "If we cannot find any of the above integers, we return an empty string “”."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().largestGoodInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:48+00:00", "tests_total": 133, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function largestGoodInteger($num) {", "container": "Solution", "callable": "largestGoodInteger", "parameters": [{"name": "num", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2266, "task_id": "count-number-of-texts", "difficulty": "Medium", "problem_description": "Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.\n\nIn order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.\n\n- For example, to add the letter 's', Alice has to press '7' four times. Similarly, to add the letter 'k', Alice has to press '5' twice.\n- Note that the digits '0' and '1' do not map to any letters, so Alice does not use them.\n\nHowever, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys instead.\n\n- For example, when Alice sent the message \"bob\", Bob received the string \"2266622\".\n\nGiven a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: pressedKeys = \"22233\"\nOutput: 8\nExplanation:\nThe possible text messages Alice could have sent are:\n\"aaadd\", \"abdd\", \"badd\", \"cdd\", \"aaae\", \"abe\", \"bae\", and \"ce\".\nSince there are 8 possible messages, we return 8.\n\nExample 2:\n\nInput: pressedKeys = \"222222222222222222222222222222222222\"\nOutput: 82876089\nExplanation:\nThere are 2082876103 possible text messages Alice could have sent.\nSince we need to return the answer modulo 10^9 + 7, we return 2082876103 % (10^9 + 7) = 82876089.\n\nConstraints:\n\n- 1 <= pressedKeys.length <= 10^5\n- pressedKeys only consists of digits from '2' - '9'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pressedKeys = \"99999999\") == 108\n assert candidate(pressedKeys = \"3333\") == 7\n assert candidate(pressedKeys = \"33\") == 2\n assert candidate(pressedKeys = \"4444\") == 7\n assert candidate(pressedKeys = \"555555\") == 24\n assert candidate(pressedKeys = \"9999999\") == 56\n assert candidate(pressedKeys = \"888888888\") == 149\n assert candidate(pressedKeys = \"888888\") == 24\n assert candidate(pressedKeys = \"7777777\") == 56\n assert candidate(pressedKeys = \"66\") == 2\n assert candidate(pressedKeys = \"55555\") == 13\n assert candidate(pressedKeys = \"888\") == 4\n assert candidate(pressedKeys = \"33344455566677778889999\") == 65536\n assert candidate(pressedKeys = \"2222\") == 7\n assert candidate(pressedKeys = \"7777\") == 8\n assert candidate(pressedKeys = \"77777777\") == 108\n assert candidate(pressedKeys = \"8888\") == 7\n assert candidate(pressedKeys = \"6666666\") == 44\n assert candidate(pressedKeys = \"23456789\") == 1\n assert candidate(pressedKeys = \"666\") == 4\n assert candidate(pressedKeys = \"22233\") == 8\n assert candidate(pressedKeys = \"555\") == 4\n assert candidate(pressedKeys = \"9999999999\") == 401\n assert candidate(pressedKeys = \"44444\") == 13\n assert candidate(pressedKeys = \"333333\") == 24\n assert candidate(pressedKeys = \"99999\") == 15\n assert candidate(pressedKeys = \"88888\") == 13\n assert candidate(pressedKeys = \"222222222222222222222222222222222222\") == 82876089\n assert candidate(pressedKeys = \"777777777777777777777777777777777777\") == 312882411\n assert candidate(pressedKeys = \"2222222222222222222222222222222222227777777777777777777777777777777\") == 168766023\n assert candidate(pressedKeys = \"2223333333333333333333333333333333334444444444444444444444444444444\") == 151530826\n assert candidate(pressedKeys = \"234567898765432345678987654323456789876543234567898765432\") == 1\n assert candidate(pressedKeys = \"7773333322225555555555444446666688888\") == 219119992\n assert candidate(pressedKeys = \"222222222222222222222222222222222222444444444444444444444444444\") == 964547839\n assert candidate(pressedKeys = \"9999999999999999999999999999999999999999999999999999999999999999999\") == 831813694\n assert candidate(pressedKeys = \"55555555555555555555555555555555555577777777777777777777777777777778888888888888888888888888888888\") == 60492310\n assert candidate(pressedKeys = \"333322225555444466668888\") == 117649\n", "comparison": "exact"}, "public_tests": ["\"22233\"", "\"222222222222222222222222222222222222\""], "hints": ["For a substring consisting of the same digit, how can we count the number of texts it could have originally represented?", "How can dynamic programming help us calculate the required answer?"], "metadata": {"canonical_parameter_names": ["pressedKeys"], "leetcode_dataset_entry_point": "Solution().countTexts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:52+00:00", "tests_total": 38, "tests_dropped": 1, "flags": ["figure_reference", "has_images"], "topic_tags": ["hash-table", "math", "string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countTexts($pressedKeys) {", "container": "Solution", "callable": "countTexts", "parameters": [{"name": "pressedKeys", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2267, "task_id": "check-if-there-is-a-valid-parentheses-string-path", "difficulty": "Hard", "problem_description": "A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n\n- It is ().\n- It can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\n- It can be written as (A), where A is a valid parentheses string.\n\nYou are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions:\n\n- The path starts from the upper left cell (0, 0).\n- The path ends at the bottom-right cell (m - 1, n - 1).\n- The path only ever moves down or right.\n- The resulting parentheses string formed by the path is valid.\n\nReturn true if there exists a valid parentheses string path in the grid. Otherwise, return false.\n\nExample 1:\n\nInput: grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]]\nOutput: true\nExplanation: The above diagram shows two possible paths that form valid parentheses strings.\nThe first path shown results in the valid parentheses string \"()(())\".\nThe second path shown results in the valid parentheses string \"((()))\".\nNote that there may be other valid parentheses string paths.\n\nExample 2:\n\nInput: grid = [[\")\",\")\"],[\"(\",\"(\"]]\nOutput: false\nExplanation: The two possible paths form the parentheses strings \"))(\" and \")((\". Since neither of them are valid parentheses strings, we return false.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 100\n- grid[i][j] is either '(' or ')'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [['(', '(', '('], [')', '(', ')'], ['(', '(', ')'], ['(', '(', ')']]) == True\n assert candidate(grid = [[')', ')'], ['(', '(']]) == False\n assert candidate(grid = [[')', '('], ['(', '(']]) == False\n assert candidate(grid = [['(', ')', '(', ')'], [')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', ')', '(', ')'], ['(', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '('], [')', '(', ')', '(', ')'], ['(', ')', '(', ')', '('], [')', '(', ')', '(', ')'], [')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '('], [')', '(', ')', '(', ')'], [')', '(', '(', ')', '('], [')', '(', ')', '(', ')'], [')', '(', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '(', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', ')', '(', '(', '(', ')', '(', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', ')', '(', '(', '(', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')']]) == True\n assert candidate(grid = [[')', '(', '(', '(', '('], ['(', ')', '(', ')', '('], [')', '(', ')', '(', ')'], ['(', ')', '(', ')', '('], [')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '('], [')', '(', '(', ')'], [')', ')', '(', ')'], [')', '(', ')', ')']]) == False\n assert candidate(grid = [['(', '(', '(', '(', '(', '('], [')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '(', ')'], ['(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', ')', '(', ')'], [')', '(', '(', ')', '('], [')', '(', ')', '(', ')'], [')', '(', '(', ')', '('], [')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', ')', '(', '(', '(', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '('], [')', '(', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '('], [')', '(', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', ')', '('], [')', '(', '(', ')'], ['(', ')', ')', '(']]) == False\n assert candidate(grid = [['(', '(', ')', '(', '(', '(', ')'], [')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', '(', '(', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', ')', '(', '(', '(', ')'], [')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')'], ['(', '(', ')', ')'], [')', ')', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '(', '('], [')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')'], [')', '(', ')', '(', ')'], [')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '('], [')', '(', ')', '('], ['(', ')', '(', ')'], [')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', ')', '(', ')', '('], [')', '(', ')', '(', ')'], ['(', ')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')']]) == False\n assert candidate(grid = [['(', '(', ')', '('], [')', '(', ')', '('], ['(', ')', ')', '('], [')', '(', '(', ')']]) == False\n assert candidate(grid = [['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], ['(', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')'], [')', '(', ')', '(', ')', '(', ')', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', '(', ')', '('], ['(', '(', ')', ')', '(']]) == False\n assert candidate(grid = [['(', '(', ')', '(', ')'], [')', '(', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', '(', '(', ')'], [')', '(', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')'], [')', '(', '(', ')', '(', ')', '('], [')', '(', ')', '(', ')', '(', ')']]) == True\n assert candidate(grid = [['(', '(', ')', '('], [')', '(', ')', '('], ['(', '(', ')', '('], [')', '(', ')', '(']]) == False\n assert candidate(grid = [['(', '(', '(', ')'], [')', '(', ')', '('], ['(', ')', ')', '(']]) == False\n", "comparison": "exact"}, "public_tests": ["[[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]]", "[[\")\",\")\"],[\"(\",\"(\"]]"], "hints": ["What observations can you make about the number of open brackets and close brackets for any prefix of a valid bracket sequence?", "The number of open brackets must always be greater than or equal to the number of close brackets.", "Could you use dynamic programming?"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().hasValidPath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:55+00:00", "tests_total": 54, "tests_dropped": 15, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix", "bracket-sequences"]}, "language": "php", "interface": {"raw_signature": "function hasValidPath($grid) {", "container": "Solution", "callable": "hasValidPath", "parameters": [{"name": "grid", "type": "String[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2269, "task_id": "find-the-k-beauty-of-a-number", "difficulty": "Easy", "problem_description": "The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions:\n\n- It has a length of k.\n- It is a divisor of num.\n\nGiven integers num and k, return the k-beauty of num.\n\nNote:\n\n- Leading zeros are allowed.\n- 0 is not a divisor of any value.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: num = 240, k = 2\nOutput: 2\nExplanation: The following are the substrings of num of length k:\n- \"24\" from \"240\": 24 is a divisor of 240.\n- \"40\" from \"240\": 40 is a divisor of 240.\nTherefore, the k-beauty is 2.\n\nExample 2:\n\nInput: num = 430043, k = 2\nOutput: 2\nExplanation: The following are the substrings of num of length k:\n- \"43\" from \"430043\": 43 is a divisor of 430043.\n- \"30\" from \"430043\": 30 is not a divisor of 430043.\n- \"00\" from \"430043\": 0 is not a divisor of 430043.\n- \"04\" from \"430043\": 4 is not a divisor of 430043.\n- \"43\" from \"430043\": 43 is a divisor of 430043.\nTherefore, the k-beauty is 2.\n\nConstraints:\n\n- 1 <= num <= 10^9\n- 1 <= k <= num.length (taking num as a string)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 100000,k = 2) == 1\n assert candidate(num = 240,k = 2) == 2\n assert candidate(num = 1111,k = 2) == 3\n assert candidate(num = 430043,k = 2) == 2\n assert candidate(num = 99999,k = 5) == 1\n assert candidate(num = 123456,k = 3) == 0\n assert candidate(num = 987654,k = 1) == 1\n assert candidate(num = 1111,k = 1) == 4\n assert candidate(num = 987654321,k = 4) == 0\n assert candidate(num = 999999999,k = 9) == 1\n assert candidate(num = 111222333,k = 5) == 0\n assert candidate(num = 100100100,k = 4) == 4\n assert candidate(num = 111111111,k = 1) == 9\n assert candidate(num = 7777777,k = 7) == 1\n assert candidate(num = 12301230,k = 4) == 3\n assert candidate(num = 1000000000,k = 9) == 1\n assert candidate(num = 333333333,k = 4) == 0\n assert candidate(num = 999999999,k = 2) == 0\n assert candidate(num = 567890123,k = 6) == 0\n assert candidate(num = 555555555,k = 6) == 0\n assert candidate(num = 100100100,k = 3) == 7\n assert candidate(num = 86420,k = 2) == 1\n assert candidate(num = 987654321,k = 9) == 1\n assert candidate(num = 222222222,k = 2) == 0\n assert candidate(num = 999999999,k = 1) == 9\n assert candidate(num = 864208642,k = 3) == 0\n assert candidate(num = 101010101,k = 3) == 0\n assert candidate(num = 987654321,k = 3) == 0\n assert candidate(num = 222222222,k = 3) == 7\n assert candidate(num = 123123123,k = 2) == 0\n assert candidate(num = 1000000,k = 4) == 1\n assert candidate(num = 777000777,k = 4) == 2\n assert candidate(num = 101010101,k = 5) == 0\n assert candidate(num = 123123123,k = 4) == 0\n assert candidate(num = 1000000000,k = 5) == 1\n assert candidate(num = 222222222,k = 1) == 9\n assert candidate(num = 101010101,k = 2) == 4\n assert candidate(num = 567890123,k = 3) == 0\n assert candidate(num = 222222222,k = 5) == 0\n assert candidate(num = 999999999,k = 7) == 0\n assert candidate(num = 999999999,k = 3) == 7\n assert candidate(num = 864197532,k = 4) == 0\n assert candidate(num = 1000000000,k = 4) == 1\n assert candidate(num = 444444444,k = 5) == 0\n assert candidate(num = 555555555,k = 5) == 0\n assert candidate(num = 7777777,k = 2) == 0\n", "comparison": "exact"}, "public_tests": ["240\n2", "430043\n2"], "hints": ["We should check all the substrings of num with a length of k and see if it is a divisor of num.", "We can more easily obtain the substrings by converting num into a string and converting back to an integer to check for divisibility."], "metadata": {"canonical_parameter_names": ["num", "k"], "leetcode_dataset_entry_point": "Solution().divisorSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:46:59+00:00", "tests_total": 90, "tests_dropped": 44, "flags": [], "topic_tags": ["math", "string", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function divisorSubstrings($num, $k) {", "container": "Solution", "callable": "divisorSubstrings", "parameters": [{"name": "num", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2270, "task_id": "number-of-ways-to-split-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of length n.\n\nnums contains a valid split at index i if the following are true:\n\n- The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.\n- There is at least one element to the right of i. That is, 0 <= i < n - 1.\n\nReturn the number of valid splits in nums.\n\nExample 1:\n\nInput: nums = [10,4,-8,7]\nOutput: 2\nExplanation:\nThere are three ways of splitting nums into two non-empty parts:\n- Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.\n- Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.\n- Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.\nThus, the number of valid splits in nums is 2.\n\nExample 2:\n\nInput: nums = [2,3,1,0]\nOutput: 2\nExplanation:\nThere are two valid splits in nums:\n- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split.\n- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- -10^5 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-100000, -100000, -100000, -100000, -100000]) == 2\n assert candidate(nums = [1, -1, 1, -1, 1]) == 2\n assert candidate(nums = [100, -50, 50, -25, 25]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1, -1, 1, -1, 1, -1]) == 5\n assert candidate(nums = [100000, -100000, 100000, -100000, 100000]) == 2\n assert candidate(nums = [100000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 19\n assert candidate(nums = [-1, -2, -3, -4, -5]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [-1, 1, -1, 1, -1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [100000, -50000, 50000, -50000, 50000]) == 4\n assert candidate(nums = [-100000, 100000, -100000, 100000, -100000]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100000]) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 6\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 7\n assert candidate(nums = [10, 4, -8, 7]) == 2\n assert candidate(nums = [2, 3, 1, 0]) == 2\n assert candidate(nums = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40, 45, -45, 50, -50]) == 19\n assert candidate(nums = [-1, -1, -1, -1, -1, 5, -1, -1, -1, -1, -1]) == 5\n assert candidate(nums = [100000, 0, -50000, 50000, -100000, 0, 50000, -50000, 100000, 0]) == 6\n assert candidate(nums = [10000, 20000, 30000, -10000, -20000, -30000, 40000]) == 4\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80, 90, -90, 100, -100]) == 19\n assert candidate(nums = [100000, -50000, 25000, -12500, 6250, -3125, 1562]) == 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]) == 6\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 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]) == 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]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [50, 25, 12, 6, 3, 1, 0, -1, -3, -6, -12, -25, -50, 100, 200]) == 0\n assert candidate(nums = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000, -1100, 1200, -1300, 1400, -1500, 1600, -1700, 1800, -1900, 2000]) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, -600, -700, -800, -900, -1000]) == 8\n assert candidate(nums = [10000, 20000, 30000, -60000, 40000, 50000, -100000, 60000, 70000, 80000]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == 19\n assert candidate(nums = [-5, -1, -4, -2, -3, -6, -7, -8, -9, -10]) == 6\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50, 60, 70, 80, 90, 100]) == 2\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]) == 20\n assert candidate(nums = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 5500]) == 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]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 9\n assert candidate(nums = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 2\n assert candidate(nums = [5, 2, -3, 1, 4, 6, -2, 8, -5, 3]) == 4\n assert candidate(nums = [-150, -140, -130, -120, -110, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == 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]) == 19\n assert candidate(nums = [100000, 0, -100000, 0, 100000, 0, -100000, 0, 100000]) == 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]) == 15\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 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]) == 15\n assert candidate(nums = [5, 2, 3, 7, 4, 1, 6, 8]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -10]) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -550]) == 10\n assert candidate(nums = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10]) == 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, 100]) == 0\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50]) == 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]) == 10\n assert candidate(nums = [10, -5, 20, -10, 30, -15, 40, -20, 50, -25, 60, -30]) == 4\n assert candidate(nums = [100, 200, 300, -600, 100, 200, 300]) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 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, 10, -10]) == 19\n assert candidate(nums = [50000, 40000, 30000, 20000, 10000, -10000, -20000, -30000, -40000, -50000]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 3\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, -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, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 55]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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]) == 6\n assert candidate(nums = [100000, 50000, -25000, -25000, 10000, -10000, 1000, -1000, 100, -100, 10, -10, 1, -1]) == 13\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]) == 21\n assert candidate(nums = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 7\n assert candidate(nums = [100000, -50000, 50000, -50000, 50000, -50000, 50000, -50000, 50000, -50000]) == 9\n assert candidate(nums = [100000, -50000, -30000, -20000, 10000, 5000, 2500, 1250, 625, 313]) == 8\n assert candidate(nums = [50000, 50000, -100000, 25000, 25000, 25000, 25000]) == 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]) == 19\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]) == 2\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, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 10]) == 0\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]) == 20\n assert candidate(nums = [99999, -99999, 99998, -99998, 99997, -99997, 99996, -99996, 99995, -99995]) == 9\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 9\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80]) == 15\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, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, -5, 1, 1, 1, 1, 1]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [-100, -200, -300, -400, -500, 600, 700, 800, 900, 1000]) == 1\n assert candidate(nums = [-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -100, -90, -80, -70, -60]) == 11\n assert candidate(nums = [-5, -2, -3, -7, -4, -1, -6, -8]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 4\n assert candidate(nums = [5, 3, -5, 2, -3, 3, 9, -10, 4]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -55]) == 10\n", "comparison": "exact"}, "public_tests": ["[10,4,-8,7]", "[2,3,1,0]"], "hints": ["For any index i, how can we find the sum of the first (i+1) elements from the sum of the first i elements?", "If the total sum of the array is known, how can we check if the sum of the first (i+1) elements greater than or equal to the remaining elements?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().waysToSplitArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:02+00:00", "tests_total": 105, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function waysToSplitArray($nums) {", "container": "Solution", "callable": "waysToSplitArray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2271, "task_id": "maximum-white-tiles-covered-by-a-carpet", "difficulty": "Medium", "problem_description": "You are given a 2D integer array tiles where tiles[i] = [l_i, r_i] represents that every tile j in the range l_i <= j <= r_i is colored white.\n\nYou are also given an integer carpetLen, the length of a single carpet that can be placed anywhere.\n\nReturn the maximum number of white tiles that can be covered by the carpet.\n\nExample 1:\n\nInput: tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10\nOutput: 9\nExplanation: Place the carpet starting on tile 10.\nIt covers 9 white tiles, so we return 9.\nNote that there may be other places where the carpet covers 9 white tiles.\nIt can be shown that the carpet cannot cover more than 9 white tiles.\n\nExample 2:\n\nInput: tiles = [[10,11],[1,1]], carpetLen = 2\nOutput: 2\nExplanation: Place the carpet starting on tile 10.\nIt covers 2 white tiles, so we return 2.\n\nConstraints:\n\n- 1 <= tiles.length <= 5 * 10^4\n- tiles[i].length == 2\n- 1 <= l_i <= r_i <= 10^9\n- 1 <= carpetLen <= 10^9\n- The tiles are non-overlapping.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tiles = [[1, 1000000000]],carpetLen = 1000000000) == 1000000000\n assert candidate(tiles = [[1, 10], [11, 20], [21, 30]],carpetLen = 15) == 15\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11]],carpetLen = 3) == 2\n assert candidate(tiles = [[5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],carpetLen = 3) == 3\n assert candidate(tiles = [[1, 100]],carpetLen = 50) == 50\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11]],carpetLen = 10) == 8\n assert candidate(tiles = [[3, 6], [8, 10], [12, 15], [18, 20]],carpetLen = 8) == 7\n assert candidate(tiles = [[3, 7], [10, 15], [18, 20]],carpetLen = 8) == 6\n assert candidate(tiles = [[1, 10], [20, 30], [40, 50]],carpetLen = 15) == 11\n assert candidate(tiles = [[3, 6], [8, 10], [12, 15]],carpetLen = 5) == 4\n assert candidate(tiles = [[1, 3], [6, 8], [9, 12]],carpetLen = 5) == 5\n assert candidate(tiles = [[1, 3], [6, 10], [12, 14], [16, 18]],carpetLen = 5) == 5\n assert candidate(tiles = [[1, 5], [10, 11], [12, 18], [20, 25], [30, 32]],carpetLen = 10) == 9\n assert candidate(tiles = [[10, 11], [1, 1]],carpetLen = 2) == 2\n assert candidate(tiles = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],carpetLen = 10) == 10\n assert candidate(tiles = [[2, 5], [8, 10], [12, 15], [18, 25], [30, 35], [40, 50]],carpetLen = 12) == 11\n assert candidate(tiles = [[1, 2], [4, 8], [10, 14], [16, 20], [22, 26], [28, 32], [34, 38], [40, 44], [46, 50]],carpetLen = 10) == 9\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23], [25, 27], [29, 31]],carpetLen = 4) == 3\n assert candidate(tiles = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70]],carpetLen = 25) == 17\n assert candidate(tiles = [[1, 5], [7, 10], [15, 20], [25, 30], [35, 40]],carpetLen = 12) == 9\n assert candidate(tiles = [[1, 2], [4, 6], [8, 10], [12, 14], [16, 18], [20, 22], [24, 26], [28, 30], [32, 34], [36, 38], [40, 42]],carpetLen = 10) == 8\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14]],carpetLen = 4) == 3\n assert candidate(tiles = [[1, 5], [10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65], [70, 75]],carpetLen = 12) == 8\n assert candidate(tiles = [[1, 100], [200, 300], [400, 500], [600, 700], [800, 900]],carpetLen = 150) == 101\n assert candidate(tiles = [[1, 1000000000]],carpetLen = 500000000) == 500000000\n assert candidate(tiles = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65], [70, 75], [80, 85], [90, 95]],carpetLen = 30) == 18\n assert candidate(tiles = [[1, 100], [200, 300], [400, 500], [600, 700], [800, 900]],carpetLen = 200) == 101\n assert candidate(tiles = [[1, 5], [10, 14], [20, 24], [30, 34], [40, 44], [50, 54]],carpetLen = 10) == 6\n assert candidate(tiles = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30], [31, 35]],carpetLen = 10) == 10\n assert candidate(tiles = [[1, 3], [6, 8], [11, 13], [16, 18], [21, 23], [26, 28], [31, 33], [36, 38], [41, 43], [46, 48]],carpetLen = 5) == 3\n assert candidate(tiles = [[5, 9], [15, 29], [35, 49], [55, 69], [75, 89], [95, 109]],carpetLen = 20) == 15\n assert candidate(tiles = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]],carpetLen = 15) == 11\n assert candidate(tiles = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65], [70, 75], [80, 85]],carpetLen = 20) == 12\n assert candidate(tiles = [[1, 10], [20, 30], [40, 50], [60, 70], [80, 90]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 20], [25, 40], [45, 60], [65, 80], [85, 100]],carpetLen = 20) == 20\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23], [25, 27], [29, 31], [33, 35], [37, 39]],carpetLen = 7) == 6\n assert candidate(tiles = [[1, 10], [21, 30], [41, 50], [61, 70], [81, 90], [101, 110]],carpetLen = 20) == 10\n assert candidate(tiles = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100], [110, 120], [130, 140], [150, 160]],carpetLen = 25) == 16\n assert candidate(tiles = [[1, 200], [400, 600], [800, 1000], [1200, 1400], [1600, 1800]],carpetLen = 350) == 201\n assert candidate(tiles = [[1, 2], [4, 6], [8, 10], [12, 14], [16, 18], [20, 22], [24, 26], [28, 30]],carpetLen = 5) == 4\n assert candidate(tiles = [[2, 6], [9, 14], [17, 22], [25, 30], [33, 38], [41, 46]],carpetLen = 20) == 16\n assert candidate(tiles = [[5, 10], [20, 25], [35, 40], [55, 60], [65, 70]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23], [25, 27]],carpetLen = 5) == 4\n assert candidate(tiles = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100]],carpetLen = 35) == 22\n assert candidate(tiles = [[1, 5], [8, 12], [15, 20], [25, 30], [35, 40]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]],carpetLen = 3) == 2\n assert candidate(tiles = [[2, 5], [8, 15], [18, 25], [30, 35], [40, 50], [55, 60]],carpetLen = 15) == 13\n assert candidate(tiles = [[1, 2], [4, 6], [8, 10], [12, 14], [16, 18], [20, 22], [24, 26], [28, 30]],carpetLen = 7) == 6\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17]],carpetLen = 3) == 2\n assert candidate(tiles = [[1, 5], [10, 14], [20, 24], [30, 34], [40, 44], [50, 54], [60, 64], [70, 74], [80, 84], [90, 94]],carpetLen = 10) == 6\n assert candidate(tiles = [[1, 20], [25, 40], [45, 60], [65, 80], [85, 100]],carpetLen = 30) == 26\n assert candidate(tiles = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],carpetLen = 4) == 7\n assert candidate(tiles = [[1, 3], [6, 8], [11, 13], [16, 18], [21, 23], [26, 28]],carpetLen = 5) == 3\n assert candidate(tiles = [[5, 10], [20, 25], [35, 40], [50, 55], [60, 65], [70, 75], [80, 85]],carpetLen = 20) == 12\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23]],carpetLen = 12) == 9\n assert candidate(tiles = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],carpetLen = 5) == 9\n assert candidate(tiles = [[1, 5], [7, 15], [20, 30], [35, 45], [50, 60], [65, 75]],carpetLen = 12) == 11\n assert candidate(tiles = [[1, 5], [10, 15], [20, 25], [30, 35], [40, 45]],carpetLen = 12) == 8\n assert candidate(tiles = [[1, 3], [10, 12], [20, 22], [30, 32], [40, 42], [50, 52], [60, 62]],carpetLen = 5) == 3\n assert candidate(tiles = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 3], [10, 12], [20, 22], [30, 32], [40, 42]],carpetLen = 4) == 3\n assert candidate(tiles = [[1, 3], [4, 6], [7, 9], [10, 12], [13, 15], [16, 18], [19, 21], [22, 24]],carpetLen = 10) == 10\n assert candidate(tiles = [[1, 3], [5, 8], [10, 14], [18, 22], [26, 30], [34, 38]],carpetLen = 6) == 5\n assert candidate(tiles = [[1, 5], [10, 14], [19, 23], [28, 32], [37, 41], [46, 50]],carpetLen = 10) == 6\n assert candidate(tiles = [[1, 500000000], [500000001, 1000000000]],carpetLen = 600000000) == 600000000\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]],carpetLen = 4) == 3\n assert candidate(tiles = [[2, 5], [8, 11], [15, 18], [22, 25], [29, 32]],carpetLen = 10) == 8\n assert candidate(tiles = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30]],carpetLen = 12) == 12\n assert candidate(tiles = [[1, 2], [5, 6], [9, 10], [13, 14], [17, 18], [21, 22], [25, 26], [29, 30]],carpetLen = 3) == 2\n assert candidate(tiles = [[1, 50], [100, 150], [200, 250], [300, 350], [400, 450], [500, 550]],carpetLen = 75) == 51\n assert candidate(tiles = [[1, 3], [6, 8], [11, 13], [16, 18], [21, 23], [26, 28], [31, 33]],carpetLen = 6) == 4\n assert candidate(tiles = [[2, 4], [8, 12], [16, 20], [24, 28], [32, 36]],carpetLen = 8) == 5\n assert candidate(tiles = [[1, 3], [6, 9], [12, 15], [18, 21], [24, 27], [30, 33]],carpetLen = 10) == 8\n assert candidate(tiles = [[5, 7], [10, 12], [15, 17], [20, 22], [25, 27], [30, 32], [35, 37]],carpetLen = 7) == 5\n assert candidate(tiles = [[1, 5], [7, 11], [13, 17], [19, 23], [25, 29], [31, 35]],carpetLen = 15) == 13\n assert candidate(tiles = [[1, 1000000], [2000000, 3000000], [4000000, 5000000], [6000000, 7000000]],carpetLen = 1500000) == 1000001\n assert candidate(tiles = [[5, 10], [20, 25], [35, 40], [55, 60], [75, 80], [95, 100]],carpetLen = 30) == 12\n assert candidate(tiles = [[1, 10], [20, 30], [40, 50], [60, 70], [80, 90]],carpetLen = 25) == 16\n assert candidate(tiles = [[100, 200], [300, 400], [500, 600], [700, 800], [900, 1000]],carpetLen = 150) == 101\n assert candidate(tiles = [[1, 50], [100, 150], [200, 250], [300, 350], [400, 450]],carpetLen = 100) == 51\n assert candidate(tiles = [[1, 5], [10, 14], [18, 22], [26, 30]],carpetLen = 7) == 5\n assert candidate(tiles = [[1, 10], [20, 30], [40, 50], [60, 70], [80, 90], [100, 110]],carpetLen = 25) == 16\n assert candidate(tiles = [[1, 3], [6, 8], [11, 13], [16, 18], [21, 23]],carpetLen = 7) == 5\n assert candidate(tiles = [[1, 2], [4, 8], [10, 14], [16, 20], [22, 26], [28, 32]],carpetLen = 8) == 7\n assert candidate(tiles = [[1, 2], [4, 6], [8, 10], [12, 14], [16, 18], [20, 22], [24, 26], [28, 30], [32, 34]],carpetLen = 10) == 8\n assert candidate(tiles = [[1, 1000000000]],carpetLen = 999999999) == 999999999\n assert candidate(tiles = [[1, 100], [200, 300], [400, 500], [600, 700], [800, 900]],carpetLen = 100) == 100\n assert candidate(tiles = [[1, 100], [200, 300], [400, 500], [600, 700], [800, 900]],carpetLen = 50) == 50\n assert candidate(tiles = [[100, 200], [300, 400], [500, 600], [700, 800], [900, 1000]],carpetLen = 500) == 302\n assert candidate(tiles = [[1, 10], [15, 20], [25, 30], [35, 40], [45, 50]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],carpetLen = 5) == 5\n assert candidate(tiles = [[1, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70]],carpetLen = 18) == 14\n assert candidate(tiles = [[1, 10], [15, 20], [25, 30], [35, 40], [45, 50]],carpetLen = 12) == 10\n assert candidate(tiles = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]],carpetLen = 15) == 15\n assert candidate(tiles = [[1, 50], [100, 150], [200, 250], [300, 350], [400, 450]],carpetLen = 150) == 101\n assert candidate(tiles = [[1, 20], [40, 60], [80, 100], [120, 140], [160, 180]],carpetLen = 35) == 21\n assert candidate(tiles = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]],carpetLen = 5) == 5\n assert candidate(tiles = [[1, 5], [10, 20], [25, 30], [35, 40], [45, 50], [55, 60]],carpetLen = 10) == 10\n assert candidate(tiles = [[100, 150], [200, 250], [300, 350], [400, 450], [500, 550], [600, 650], [700, 750]],carpetLen = 100) == 51\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19], [21, 23]],carpetLen = 5) == 4\n assert candidate(tiles = [[2, 5], [8, 15], [20, 25], [30, 40], [45, 55]],carpetLen = 12) == 11\n assert candidate(tiles = [[5, 9], [15, 19], [25, 29], [35, 39], [45, 49]],carpetLen = 10) == 5\n assert candidate(tiles = [[10, 14], [15, 19], [20, 24], [25, 29], [30, 34], [35, 39]],carpetLen = 15) == 15\n assert candidate(tiles = [[1, 3], [5, 7], [9, 11], [13, 15], [17, 19]],carpetLen = 6) == 5\n assert candidate(tiles = [[1, 2], [4, 5], [7, 8], [10, 11], [13, 14], [16, 17], [19, 20]],carpetLen = 5) == 4\n assert candidate(tiles = [[1, 10], [20, 30], [40, 50], [60, 70], [80, 90], [100, 110]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60]],carpetLen = 12) == 10\n assert candidate(tiles = [[100, 200], [300, 400], [500, 600], [700, 800], [900, 1000]],carpetLen = 250) == 151\n assert candidate(tiles = [[10, 20], [30, 40], [50, 60], [70, 80], [90, 100], [110, 120], [130, 140]],carpetLen = 25) == 16\n assert candidate(tiles = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50]],carpetLen = 15) == 11\n assert candidate(tiles = [[1, 2], [10, 11], [20, 21], [30, 31], [40, 41], [50, 51], [60, 61], [70, 71], [80, 81], [90, 91]],carpetLen = 2) == 2\n", "comparison": "exact"}, "public_tests": ["[[1,5],[10,11],[12,18],[20,25],[30,32]]\n10", "[[10,11],[1,1]]\n2"], "hints": ["Think about the potential placements of the carpet in an optimal solution.", "Can we use Prefix Sum and Binary Search to determine how many tiles are covered for a given placement?"], "metadata": {"canonical_parameter_names": ["tiles", "carpetLen"], "leetcode_dataset_entry_point": "Solution().maximumWhiteTiles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:04+00:00", "tests_total": 111, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "greedy", "sliding-window", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maximumWhiteTiles($tiles, $carpetLen) {", "container": "Solution", "callable": "maximumWhiteTiles", "parameters": [{"name": "tiles", "type": "Integer[][]"}, {"name": "carpetLen", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2272, "task_id": "substring-with-largest-variance", "difficulty": "Hard", "problem_description": "The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same.\n\nGiven a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aababbb\"\nOutput: 3\nExplanation:\nAll possible variances along with their respective substrings are listed below:\n- Variance 0 for substrings \"a\", \"aa\", \"ab\", \"abab\", \"aababb\", \"ba\", \"b\", \"bb\", and \"bbb\".\n- Variance 1 for substrings \"aab\", \"aba\", \"abb\", \"aabab\", \"ababb\", \"aababbb\", and \"bab\".\n- Variance 2 for substrings \"aaba\", \"ababbb\", \"abbb\", and \"babb\".\n- Variance 3 for substring \"babbb\".\nSince the largest possible variance is 3, we return it.\n\nExample 2:\n\nInput: s = \"abcde\"\nOutput: 0\nExplanation:\nNo letter occurs more than once in s, so the variance of every substring is 0.\n\nConstraints:\n\n- 1 <= s.length <= 10^4\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzy\") == 5\n assert candidate(s = \"zyzzyzyzy\") == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"abbaabbaabba\") == 2\n assert candidate(s = \"abababab\") == 1\n assert candidate(s = \"aaaaa\") == 0\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"abcabcabc\") == 1\n assert candidate(s = \"zzyzxzyzyzxzyzxzyzxzyzxzyzxzyzxzyz\") == 11\n assert candidate(s = \"abcabcabcabc\") == 1\n assert candidate(s = \"abcde\") == 0\n assert candidate(s = \"leetcode\") == 2\n assert candidate(s = \"xyzxyzxyz\") == 1\n assert candidate(s = \"abccccccc\") == 6\n assert candidate(s = \"zzzzzzzzzz\") == 0\n assert candidate(s = \"aabbcc\") == 1\n assert candidate(s = \"mississippi\") == 3\n assert candidate(s = \"abcdefghij\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijj\") == 1\n assert candidate(s = \"aabbaaabb\") == 3\n assert candidate(s = \"abacaba\") == 3\n assert candidate(s = \"aababbb\") == 3\n", "comparison": "exact"}, "public_tests": ["\"aababbb\"", "\"abcde\""], "hints": ["Think about how to solve the problem if the string had only two distinct characters.", "If we replace all occurrences of the first character by +1 and those of the second character by -1, can we efficiently calculate the largest possible variance of a string with only two distinct characters?", "Now, try finding the optimal answer by taking all possible pairs of characters into consideration."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().largestVariance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:07+00:00", "tests_total": 25, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function largestVariance($s) {", "container": "Solution", "callable": "largestVariance", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2273, "task_id": "find-resultant-array-after-removing-anagrams", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string array words, where words[i] consists of lowercase English letters.\n\nIn one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that satisfies the conditions.\n\nReturn words after performing all operations. It can be shown that selecting the indices for each operation in any arbitrary order will lead to the same result.\n\nAn Anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, \"dacb\" is an anagram of \"abdc\".\n\nExample 1:\n\nInput: words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]\nOutput: [\"abba\",\"cd\"]\nExplanation:\nOne of the ways we can obtain the resultant array is by using the following operations:\n- Since words[2] = \"bbaa\" and words[1] = \"baba\" are anagrams, we choose index 2 and delete words[2].\n Now words = [\"abba\",\"baba\",\"cd\",\"cd\"].\n- Since words[1] = \"baba\" and words[0] = \"abba\" are anagrams, we choose index 1 and delete words[1].\n Now words = [\"abba\",\"cd\",\"cd\"].\n- Since words[2] = \"cd\" and words[1] = \"cd\" are anagrams, we choose index 2 and delete words[2].\n Now words = [\"abba\",\"cd\"].\nWe can no longer perform any operations, so [\"abba\",\"cd\"] is the final answer.\n\nExample 2:\n\nInput: words = [\"a\",\"b\",\"c\",\"d\",\"e\"]\nOutput: [\"a\",\"b\",\"c\",\"d\",\"e\"]\nExplanation:\nNo two adjacent strings in words are anagrams of each other, so no operations are performed.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 10\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['abc', 'cab', 'bca', 'xyz', 'zyx', 'yxz']) == ['abc', 'xyz']\n assert candidate(words = ['abc', 'cba', 'bca', 'xyz', 'zyx']) == ['abc', 'xyz']\n assert candidate(words = ['unique', 'words', 'here', 'now']) == ['unique', 'words', 'here', 'now']\n assert candidate(words = ['test', 'sett', 'tset', 'ttew']) == ['test', 'ttew']\n assert candidate(words = ['same', 'same', 'same', 'same', 'same']) == ['same']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e']) == ['a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['aabbcc', 'abcabc', 'bcaacb', 'bacbac', 'cababc']) == ['aabbcc']\n assert candidate(words = ['test', 'sett', 'tset', 'stet', 'ttes']) == ['test']\n assert candidate(words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']) == ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']\n assert candidate(words = ['hello', 'billion', 'oellh', 'llheo', 'note', 'tone']) == ['hello', 'billion', 'oellh', 'note']\n assert candidate(words = ['abc', 'cab', 'bac', 'bca', 'xyz']) == ['abc', 'xyz']\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd']) == ['abcd']\n assert candidate(words = ['hello', 'olleh', 'world', 'dlrow', 'python', 'nohtyp']) == ['hello', 'world', 'python']\n assert candidate(words = ['abba', 'baba', 'bbaa', 'cd', 'cd']) == ['abba', 'cd']\n assert candidate(words = ['deed', 'deep', 'peed', 'depe', 'dpee']) == ['deed', 'deep']\n assert candidate(words = ['hello', 'world', 'dlrow', 'owrld', 'worlc']) == ['hello', 'world', 'worlc']\n assert candidate(words = ['same', 'same', 'same', 'same']) == ['same']\n assert candidate(words = ['abc', 'cba', 'bac', 'bca', 'cab', 'acb']) == ['abc']\n assert candidate(words = ['aaa', 'aa', 'a', 'aaaa', 'aaa']) == ['aaa', 'aa', 'a', 'aaaa', 'aaa']\n assert candidate(words = ['aabbcc', 'baccab', 'abcabc', 'xyz', 'zyx', 'yxz']) == ['aabbcc', 'xyz']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl']) == ['listen', 'google']\n assert candidate(words = ['abc', 'cab', 'bac', 'bca', 'acb', 'cba']) == ['abc']\n assert candidate(words = ['aaa', 'aa', 'a']) == ['aaa', 'aa', 'a']\n assert candidate(words = ['deed', 'deed', 'deed', 'deed', 'deed']) == ['deed']\n assert candidate(words = ['hello', 'world', 'dlrow', 'owrld', 'werld', 'hello', 'olleh', 'dlrow', 'world', 'rowld', 'dlrow', 'hello', 'hello', 'world', 'world', 'world', 'dlrow', 'dlrow', 'dlrow', 'dlrow']) == ['hello', 'world', 'werld', 'hello', 'dlrow', 'hello', 'world']\n assert candidate(words = ['triangle', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral']) == ['triangle']\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e']) == ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'cab', 'bac', 'xyz', 'zyx', 'yxz']) == ['listen', 'google', 'abc', 'xyz']\n assert candidate(words = ['rat', 'car', 'tar', 'arc', 'art', 'cat', 'tac', 'act', 'rat', 'car']) == ['rat', 'car', 'tar', 'arc', 'art', 'cat', 'rat', 'car']\n assert candidate(words = ['racecar', 'carrace', 'acecar', 'enlist', 'inlets', 'silent', 'google', 'gooegl', 'abc', 'bac', 'cba', 'xyz', 'zyx', 'yxz', 'zyx', 'xyz', 'listen', 'silent', 'enlist']) == ['racecar', 'acecar', 'enlist', 'google', 'abc', 'xyz', 'listen']\n assert candidate(words = ['aabbcc', 'aabbc', 'aabc', 'abc', 'ab', 'a', 'abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd', 'mnop', 'ponm', 'omnp', 'nmop', 'mpno', 'pmno']) == ['aabbcc', 'aabbc', 'aabc', 'abc', 'ab', 'a', 'abcd', 'mnop']\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba']) == ['ab']\n assert candidate(words = ['hello', 'olleh', 'loleh', 'ohell', 'ehlol', 'world', 'dlrow', 'rowld', 'owlrd', 'wrold', 'hello', 'olleh', 'loleh', 'ohell', 'ehlol']) == ['hello', 'world', 'hello']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'cab', 'bac', 'xyz', 'zyx', 'zyxw', 'wxyz']) == ['listen', 'google', 'abc', 'xyz', 'zyxw']\n assert candidate(words = ['abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd', 'abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd', 'mnop', 'ponm', 'omnp', 'nmop', 'mpno', 'pmno']) == ['abcd', 'mnop']\n assert candidate(words = ['aabbcc', 'baccab', 'abcabc', 'xyz', 'zyx', 'yxz', 'test', 'sett', 'tset', 'stet', 'ttes']) == ['aabbcc', 'xyz', 'test']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'cab', 'bac', 'bca', 'acb', 'cba', 'xyz', 'zyx', 'yxz']) == ['listen', 'google', 'abc', 'xyz']\n assert candidate(words = ['rat', 'tar', 'art', 'star', 'rats', 'tars', 'arts', 'tsar', 'chart', 'arch', 'cart', 'ract', 'track', 'krat', 'tract', 'crat', 'carr', 'rack', 'crab', 'back', 'bark', 'park', 'parking', 'arking', 'king', 'gnik', 'pink', 'kimp', 'pink', 'knip', 'kpin']) == ['rat', 'star', 'chart', 'arch', 'cart', 'track', 'krat', 'tract', 'crat', 'carr', 'rack', 'crab', 'back', 'bark', 'park', 'parking', 'arking', 'king', 'pink', 'kimp', 'pink']\n assert candidate(words = ['rat', 'tar', 'art', 'car', 'arc', 'par', 'arp', 'arc', 'rac', 'cat', 'tac', 'act', 'cta', 'atc', 'tca', 'pqr', 'qrp', 'rpq', 'prq', 'rqp', 'qpr', 'aabb', 'bbaa', 'abab', 'abba', 'aaaa', 'bbba', 'baab', 'aabb', 'baba', 'bbaa', 'cd', 'cd', 'efg', 'feg', 'gfe', 'geg', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj', 'kkk', 'lll', 'mmm', 'nnn', 'ooo', 'ppp', 'qqq', 'rrr', 'sss', 'ttt', 'uuu', 'vvv', 'www', 'xxx', 'yyy', 'zzz']) == ['rat', 'car', 'par', 'arc', 'cat', 'pqr', 'aabb', 'aaaa', 'bbba', 'baab', 'cd', 'efg', 'geg', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj', 'kkk', 'lll', 'mmm', 'nnn', 'ooo', 'ppp', 'qqq', 'rrr', 'sss', 'ttt', 'uuu', 'vvv', 'www', 'xxx', 'yyy', 'zzz']\n assert candidate(words = ['race', 'care', 'acre', 'racecar', 'carrace', 'racecar', 'carrace', 'abc', 'bca', 'cab', 'xyz', 'zyx', 'yxz', 'zyxzyx', 'xzyzyz', 'yzyzyx']) == ['race', 'racecar', 'abc', 'xyz', 'zyxzyx', 'xzyzyz', 'yzyzyx']\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == ['abcd']\n assert candidate(words = ['aaaa', 'aaab', 'aabb', 'abbb', 'bbbb', 'bbb', 'bb', 'b', 'a', 'abc', 'bac', 'cba', 'bca', 'cab', 'acb', 'xyz', 'zyx', 'yxz']) == ['aaaa', 'aaab', 'aabb', 'abbb', 'bbbb', 'bbb', 'bb', 'b', 'a', 'abc', 'xyz']\n assert candidate(words = ['rat', 'tar', 'art', 'dog', 'god', 'cat', 'act', 'tac', 'tack', 'rack', 'track', 'chart', 'cart']) == ['rat', 'dog', 'cat', 'tack', 'rack', 'track', 'chart', 'cart']\n assert candidate(words = ['abcde', 'edcba', 'decba', 'acdeb', 'badce', 'abcde', 'edcba', 'decba', 'acdeb', 'badce', 'abcde', 'edcba', 'decba', 'acdeb', 'badce', 'abcde', 'edcba', 'decba', 'acdeb', 'badce']) == ['abcde']\n assert candidate(words = ['anagram', 'nagaram', 'margana', 'anagram', 'margana', 'anagram', 'nagaram', 'margana', 'anagram', 'nagaram', 'margana', 'anagram', 'nagaram', 'margana', 'anagram', 'nagaram', 'margana', 'anagram', 'nagaram', 'margana']) == ['anagram']\n assert candidate(words = ['python', 'typhon', 'hypton', 'ypthon', 'phonto', 'opynth', 'ypthon', 'phonto', 'opynth', 'ypthon', 'phonto', 'opynth', 'ypthon', 'phonto', 'opynth']) == ['python', 'phonto', 'opynth', 'phonto', 'opynth', 'phonto', 'opynth', 'phonto', 'opynth']\n assert candidate(words = ['dormitory', 'dirtyroom', 'dirtyroom', 'dormitory', 'dirtyroom', 'dirtyroom', 'dormitory']) == ['dormitory']\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == ['abcd']\n assert candidate(words = ['aaaaa', 'aaabb', 'aabba', 'abbaa', 'baaab', 'baaba', 'bbaaa', 'abcde', 'edcba', 'decba', 'cbade', 'badec']) == ['aaaaa', 'aaabb', 'abcde']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'bca', 'cab', 'xyz', 'zyx', 'yxz']) == ['listen', 'google', 'abc', 'xyz']\n assert candidate(words = ['race', 'care', 'acre', 'barc', 'racecar', 'carrace', 'racecar', 'carecar', 'abcde', 'edcba', 'bcdea', 'deabc', 'acdeb', 'decab']) == ['race', 'barc', 'racecar', 'abcde']\n assert candidate(words = ['triangle', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral', 'integral']) == ['triangle']\n assert candidate(words = ['aabbcc', 'abcabc', 'baccab', 'abccba', 'bacabc', 'aabbcc', 'abcd', 'dcba', 'cdab', 'bcda', 'badc', 'cabd']) == ['aabbcc', 'abcd']\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == ['abcd']\n assert candidate(words = ['rat', 'tar', 'art', 'dog', 'god', 'cat', 'act', 'tac', 'abc', 'bca', 'cab', 'xyz', 'zyx', 'yxz']) == ['rat', 'dog', 'cat', 'abc', 'xyz']\n assert candidate(words = ['hello', 'olleh', 'world', 'dlrow', 'python', 'nothpy', 'java', 'avaj', 'abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd']) == ['hello', 'world', 'python', 'java', 'abcd']\n assert candidate(words = ['anagram', 'nagaram', 'margana', 'ramnaga', 'gnamar', 'gnamar', 'gnamra', 'gnamra', 'gnamra', 'gnamra', 'gnamra', 'gnamra', 'gnamra']) == ['anagram', 'gnamar']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'bca', 'cab', 'xyz', 'zyx', 'zyx', 'xyz']) == ['listen', 'google', 'abc', 'xyz']\n assert candidate(words = ['aabbcc', 'baccab', 'cbaabc', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'xyz', 'zyx', 'yxz', 'zyx', 'xyz']) == ['aabbcc', 'abc', 'xyz']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'cab', 'bac', 'xyz', 'zyx', 'yxz', 'uvw', 'vuw', 'wuv']) == ['listen', 'google', 'abc', 'xyz', 'uvw']\n assert candidate(words = ['abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd', 'abcd', 'dcba', 'bacd', 'cadb', 'abdc', 'cabd']) == ['abcd']\n assert candidate(words = ['python', 'typhon', 'nohtyp', 'ypthon', 'hypnot', 'python', 'typhon', 'nohtyp', 'ypthon', 'hypnot', 'python', 'typhon', 'nohtyp', 'ypthon', 'hypnot', 'python', 'typhon', 'nohtyp', 'ypthon', 'hypnot']) == ['python']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'inlets']) == ['listen', 'google', 'inlets']\n assert candidate(words = ['aabbcc', 'abcabc', 'baccab', 'cabcab', 'abacbc', 'bbacac', 'acbbca', 'aabbbc', 'aabbbc', 'aabbbc']) == ['aabbcc', 'aabbbc']\n assert candidate(words = ['abcd', 'dcba', 'cdab', 'bacd', 'cadb', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == ['abcd']\n assert candidate(words = ['aabbcc', 'abcabc', 'baccab', 'xyz', 'zyx', 'yxz', 'mnop', 'ponm', 'omnp', 'nmop', 'mpno', 'pmno']) == ['aabbcc', 'xyz', 'mnop']\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba', 'zzzz', 'zzz', 'zz', 'z']) == ['abc', 'abcd', 'zzzz', 'zzz', 'zz', 'z']\n assert candidate(words = ['ab', 'ba', 'aabb', 'bbaa', 'abab', 'baba', 'abba', 'baab', 'ab', 'ba']) == ['ab', 'aabb', 'ab']\n assert candidate(words = ['aabbcc', 'baccab', 'abcabc', 'abc', 'bac', 'cab', 'bac', 'abc', 'bac', 'cab', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc', 'bac', 'abc']) == ['aabbcc', 'abc']\n assert candidate(words = ['abcd', 'dcba', 'abdc', 'cbad', 'bcad', 'adbc', 'dabc', 'cdab', 'dacb', 'cadb', 'acbd', 'bdac', 'bdca', 'abcd', 'dcba', 'abdc', 'cbad', 'bcad', 'adbc', 'dabc', 'cdab', 'dacb', 'cadb', 'acbd', 'bdac', 'bdca', 'abcd', 'dcba', 'abdc', 'cbad', 'bcad', 'adbc', 'dabc', 'cdab', 'dacb', 'cadb', 'acbd', 'bdac', 'bdca', 'abcd', 'dcba', 'abdc', 'cbad', 'bcad', 'adbc', 'dabc', 'cdab', 'dacb', 'cadb', 'acbd', 'bdac', 'bdca']) == ['abcd']\n assert candidate(words = ['aabbcc', 'abcabc', 'baccab', 'ccabba', 'cabacb', 'abcabc', 'aabbcc', 'xyzxyz', 'zyxzyx', 'yxzyxz', 'zyxzyx']) == ['aabbcc', 'xyzxyz']\n assert candidate(words = ['anagram', 'nagaram', 'margana', 'gnarama', 'granama', 'aaagmnr', 'ab', 'ba', 'abc', 'cba', 'abcd', 'dcba', 'xyz', 'zyx', 'yxz', 'test', 'sett', 'tset', 'stet', 'ttes', 'deed', 'deep', 'peed', 'depe', 'dpee', 'aabbcc', 'baccab', 'abcabc', 'rat', 'tar', 'art', 'dog', 'god', 'cat', 'act', 'tac', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba', 'zzzz', 'zzz', 'zz', 'z']) == ['anagram', 'ab', 'abc', 'abcd', 'xyz', 'test', 'deed', 'deep', 'aabbcc', 'rat', 'dog', 'cat', 'abcd', 'zzzz', 'zzz', 'zz', 'z']\n assert candidate(words = ['word', 'drow', 'dwor', 'owrd', 'abcd', 'dcba', 'cadb', 'bdac', 'abcd', 'dcba', 'cabd', 'bdac']) == ['word', 'abcd']\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'abdc', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd']) == ['abcd']\n assert candidate(words = ['anagram', 'nagaram', 'margana', 'anagram', 'nagaram', 'margana', 'anagram', 'nagaram']) == ['anagram']\n assert candidate(words = ['abcd', 'dcba', 'cdab', 'bacd', 'adcb', 'cbad', 'bcda', 'abcd', 'dcba', 'cdab', 'bacd', 'adcb', 'cbad', 'bcda']) == ['abcd']\n assert candidate(words = ['rat', 'tar', 'art', 'car', 'arc', 'arc', 'rca', 'arc', 'cat', 'tac', 'act', 'dog', 'god', 'god', 'ogd']) == ['rat', 'car', 'cat', 'dog']\n assert candidate(words = ['hello', 'billion', 'nillion', 'illonbi', 'onbilin', 'nnoblli', 'olnibin', 'lobinin', 'ollinbi', 'bloninl', 'bnoloni', 'noblinl', 'llinbon', 'lobinln', 'nilonbl', 'nonlibl', 'oblinln', 'nlonbil', 'oninlb', 'nobinll', 'binlonl', 'onlibnl', 'nbinlol', 'inlboon', 'libnoln', 'onilnbl', 'inlobnl', 'lnoibnl', 'nobllin', 'oinlnbl', 'onilb', 'nlibl', 'inlbn', 'lnbol', 'onbil', 'ilnob', 'lnoib', 'nlobi', 'olnib', 'blnio', 'bnlio', 'nliob', 'libon', 'inlob', 'onilb', 'nobil', 'inobl', 'onlbi', 'nobil', 'lobin', 'linbo', 'inolb', 'nolbi', 'libno', 'inlob', 'onilb', 'nobli', 'inobl', 'onlbi', 'nobil', 'lobin', 'linbo', 'inolb', 'nolbi', 'libno']) == ['hello', 'billion', 'nillion', 'illonbi', 'onbilin', 'nnoblli', 'olnibin', 'ollinbi', 'bloninl', 'bnoloni', 'noblinl', 'oninlb', 'nobinll', 'inlboon', 'libnoln', 'onilb', 'nlibl', 'inlbn', 'lnbol', 'onbil']\n assert candidate(words = ['aabb', 'abab', 'bbaa', 'abcd', 'dcba', 'cdab', 'bcda', 'mnop', 'ponm', 'opnm', 'nmop', 'qrst', 'srqt', 'qstr', 'tqrs', 'stqr', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd']) == ['aabb', 'abcd', 'mnop', 'qrst', 'abcd']\n assert candidate(words = ['triangle', 'integral', 'integral', 'integral', 'triangle', 'integral']) == ['triangle']\n assert candidate(words = ['listen', 'silent', 'enlist', 'google', 'gooegl', 'abc', 'cab', 'bac', 'xyz', 'zyx', 'yxz', 'test', 'sett', 'tset', 'stet', 'ttes', 'deed', 'deep', 'peed', 'depe', 'dpee']) == ['listen', 'google', 'abc', 'xyz', 'test', 'deed', 'deep']\n assert candidate(words = ['deed', 'deep', 'peed', 'depe', 'dpee', 'abcd', 'dcba', 'cbad', 'adcb', 'bacd', 'cabd', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'dcba']) == ['deed', 'deep', 'abcd']\n assert candidate(words = ['aabbcc', 'bbaacc', 'abcabc', 'cccccc', 'bbbaaa', 'aabbcc', 'ccbbdd']) == ['aabbcc', 'cccccc', 'bbbaaa', 'aabbcc', 'ccbbdd']\n assert candidate(words = ['anagram', 'nagaram', 'margana', 'gnarham', 'ramnaga', 'gramana', 'amnagar', 'mangara', 'gnarama', 'ramagna', 'amnagra', 'agranam', 'mangnra', 'gnanram', 'rangnam', 'anagram', 'nagaram', 'margana', 'gnarham', 'ramnaga', 'gramana', 'amnagar', 'mangara', 'gnarama', 'ramagna', 'amnagra', 'agranam', 'mangnra', 'gnanram', 'rangnam']) == ['anagram', 'gnarham', 'ramnaga', 'mangnra', 'anagram', 'gnarham', 'ramnaga', 'mangnra']\n", "comparison": "exact"}, "public_tests": ["[\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]", "[\"a\",\"b\",\"c\",\"d\",\"e\"]"], "hints": ["Instead of removing each repeating anagram, try to find all the strings in words which will not be present in the final answer.", "For every index i, find the largest index j < i such that words[j] will be present in the final answer.", "Check if words[i] and words[j] are anagrams. If they are, then it can be confirmed that words[i] will not be present in the final answer."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().removeAnagrams", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:09+00:00", "tests_total": 86, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "string", "sorting"]}, "language": "php", "interface": {"raw_signature": "function removeAnagrams($words) {", "container": "Solution", "callable": "removeAnagrams", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2274, "task_id": "maximum-consecutive-floors-without-special-floors", "difficulty": "Medium", "problem_description": "Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.\n\nYou are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given the integer array special, where special[i] denotes a special floor that Alice has designated for relaxation.\n\nReturn the maximum number of consecutive floors without a special floor.\n\nExample 1:\n\nInput: bottom = 2, top = 9, special = [4,6]\nOutput: 3\nExplanation: The following are the ranges (inclusive) of consecutive floors without a special floor:\n- (2, 3) with a total amount of 2 floors.\n- (5, 5) with a total amount of 1 floor.\n- (7, 9) with a total amount of 3 floors.\nTherefore, we return the maximum number which is 3 floors.\n\nExample 2:\n\nInput: bottom = 6, top = 8, special = [7,6,8]\nOutput: 0\nExplanation: Every floor rented is a special floor, so we return 0.\n\nConstraints:\n\n- 1 <= special.length <= 10^5\n- 1 <= bottom <= special[i] <= top <= 10^9\n- All the values of special are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(bottom = 3,top = 7,special = [3, 4, 5, 6, 7]) == 0\n assert candidate(bottom = 1,top = 1,special = [1]) == 0\n assert candidate(bottom = 1,top = 10,special = [3, 5, 7, 9]) == 2\n assert candidate(bottom = 6,top = 8,special = [7, 6, 8]) == 0\n assert candidate(bottom = 5,top = 15,special = [10]) == 5\n assert candidate(bottom = 3,top = 15,special = [3, 5, 7, 9, 11, 15]) == 3\n assert candidate(bottom = 1,top = 10,special = [2, 5, 8]) == 2\n assert candidate(bottom = 10,top = 20,special = [12, 14, 16, 18]) == 2\n assert candidate(bottom = 6,top = 8,special = [7, 6, 8]) == 0\n assert candidate(bottom = 2,top = 9,special = [4, 6]) == 3\n assert candidate(bottom = 10,top = 20,special = [12, 15, 18]) == 2\n assert candidate(bottom = 1,top = 10,special = [5]) == 5\n assert candidate(bottom = 10,top = 10,special = [10]) == 0\n assert candidate(bottom = 1,top = 1000000000,special = [500000000]) == 500000000\n assert candidate(bottom = 3,top = 7,special = [3, 4, 5, 6, 7]) == 0\n assert candidate(bottom = 1,top = 10,special = [3, 5, 7]) == 3\n assert candidate(bottom = 2,top = 9,special = [4, 6]) == 3\n assert candidate(bottom = 1,top = 100,special = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 9\n assert candidate(bottom = 1,top = 1000000,special = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000]) == 100000\n assert candidate(bottom = 2,top = 100,special = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 10\n assert candidate(bottom = 50,top = 200,special = [60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == 10\n assert candidate(bottom = 1,top = 1000,special = [1, 500, 1000]) == 499\n assert candidate(bottom = 10,top = 20,special = [11, 13, 15, 17]) == 3\n assert candidate(bottom = 50,top = 200,special = [100, 150, 125]) == 50\n assert candidate(bottom = 5,top = 50,special = [10, 20, 30, 40]) == 10\n assert candidate(bottom = 1,top = 1000000000,special = [1000000000]) == 999999999\n assert candidate(bottom = 1,top = 1000000000,special = [1, 1000000000]) == 999999998\n assert candidate(bottom = 5,top = 25,special = [7, 13, 19]) == 6\n assert candidate(bottom = 1,top = 500,special = [250]) == 250\n assert candidate(bottom = 5,top = 20,special = [6, 8, 10, 12, 14, 16, 18]) == 2\n assert candidate(bottom = 1,top = 1000,special = [500, 750]) == 499\n assert candidate(bottom = 1,top = 1000,special = [500]) == 500\n assert candidate(bottom = 1,top = 50,special = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]) == 2\n assert candidate(bottom = 5,top = 15,special = [6, 11]) == 4\n assert candidate(bottom = 5,top = 15,special = [7, 10, 13]) == 2\n assert candidate(bottom = 10,top = 50,special = [15, 25, 35, 45]) == 9\n assert candidate(bottom = 10,top = 50,special = [15, 25, 35]) == 15\n assert candidate(bottom = 1,top = 50,special = [50]) == 49\n assert candidate(bottom = 1,top = 100,special = [2, 98]) == 95\n assert candidate(bottom = 5,top = 25,special = [10, 20]) == 9\n assert candidate(bottom = 1,top = 100,special = [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]) == 3\n assert candidate(bottom = 1,top = 100,special = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 81\n assert candidate(bottom = 1,top = 100,special = [50]) == 50\n assert candidate(bottom = 1,top = 1000,special = [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]) == 901\n assert candidate(bottom = 1,top = 100,special = [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, 100]) == 1\n assert candidate(bottom = 10,top = 20,special = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(bottom = 1,top = 1000000000,special = [100000000, 200000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000]) == 100000000\n assert candidate(bottom = 1,top = 1000,special = [10, 200, 300, 400, 500, 600, 700, 800, 900]) == 189\n assert candidate(bottom = 1,top = 50,special = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47]) == 3\n assert candidate(bottom = 100,top = 200,special = [120, 130, 140, 150, 160, 170, 180, 190]) == 20\n assert candidate(bottom = 1,top = 1000,special = [1, 1000]) == 998\n assert candidate(bottom = 1,top = 1000000000,special = [1, 500000000, 1000000000]) == 499999999\n assert candidate(bottom = 10,top = 20,special = [10, 12, 14, 16, 18, 20]) == 1\n assert candidate(bottom = 1,top = 1000,special = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 100\n assert candidate(bottom = 1,top = 1000000,special = [500000]) == 500000\n assert candidate(bottom = 5,top = 50,special = [15, 25, 35, 45]) == 10\n assert candidate(bottom = 50,top = 150,special = [51, 52, 53, 54, 55, 56, 57, 58, 59, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149]) == 40\n assert candidate(bottom = 1,top = 50,special = [25]) == 25\n assert candidate(bottom = 10,top = 100,special = [15, 35, 60, 85]) == 24\n assert candidate(bottom = 1,top = 100,special = [1, 2, 3, 4, 5, 96, 97, 98, 99, 100]) == 90\n assert candidate(bottom = 10,top = 1000,special = [150, 250, 350, 450, 550, 650, 750, 850, 950]) == 140\n assert candidate(bottom = 5,top = 50,special = [10, 15, 20, 25, 30, 35, 40, 45]) == 5\n assert candidate(bottom = 10,top = 20,special = [12, 15, 18]) == 2\n assert candidate(bottom = 1,top = 100,special = [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]) == 1\n assert candidate(bottom = 1,top = 100,special = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 10\n assert candidate(bottom = 10,top = 50,special = [12, 15, 20, 25, 30, 35, 40, 45]) == 5\n assert candidate(bottom = 10,top = 10000,special = [500, 2500, 4500, 6500, 8500]) == 1999\n assert candidate(bottom = 1,top = 100,special = [99]) == 98\n assert candidate(bottom = 1,top = 100,special = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 61\n assert candidate(bottom = 1,top = 100,special = [1, 100]) == 98\n assert candidate(bottom = 10,top = 100,special = [20, 40, 60, 80]) == 20\n assert candidate(bottom = 1,top = 1000000,special = [1, 2, 3, 4, 5, 999995, 999996, 999997, 999998, 999999]) == 999989\n assert candidate(bottom = 1,top = 20,special = [2, 4, 6, 8, 10, 12, 14, 16, 18]) == 2\n assert candidate(bottom = 1,top = 20,special = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(bottom = 1,top = 10,special = [2, 4, 6, 8]) == 2\n assert candidate(bottom = 100,top = 200,special = [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]) == 1\n assert candidate(bottom = 100,top = 500,special = [200, 300, 400]) == 100\n assert candidate(bottom = 1,top = 100,special = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 9\n assert candidate(bottom = 1,top = 20,special = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 1\n assert candidate(bottom = 10,top = 1000,special = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 100\n assert candidate(bottom = 1,top = 100,special = [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]) == 1\n assert candidate(bottom = 1,top = 50,special = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 29\n assert candidate(bottom = 20,top = 200,special = [30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190]) == 10\n assert candidate(bottom = 5,top = 50,special = [15, 25, 35, 45, 5, 40]) == 9\n assert candidate(bottom = 1,top = 100,special = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]) == 5\n assert candidate(bottom = 10,top = 50,special = [20, 30, 40]) == 10\n assert candidate(bottom = 1,top = 100,special = [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]) == 7\n assert candidate(bottom = 1,top = 10,special = [1, 3, 5, 7, 9]) == 1\n assert candidate(bottom = 1,top = 100,special = [5, 25, 45, 65, 85, 95]) == 19\n assert candidate(bottom = 10,top = 100,special = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 75\n assert candidate(bottom = 1,top = 100,special = [2, 25, 50, 75, 100]) == 24\n assert candidate(bottom = 1,top = 10,special = [2, 4, 6, 8, 10]) == 1\n", "comparison": "exact"}, "public_tests": ["2\n9\n[4,6]", "6\n8\n[7,6,8]"], "hints": ["Say we have a pair of special floors (x, y) with no other special floors in between. There are x - y - 1 consecutive floors in between them without a special floor.", "Say there are n special floors. After sorting special, we have answer = max(answer, special[i] – special[i – 1] – 1) for all 0 < i < n.", "However, there are two special cases left to consider: the floors before special[0] and after special[n-1].", "To consider these cases, we have answer = max(answer, special[0] – bottom, top – special[n-1])."], "metadata": {"canonical_parameter_names": ["bottom", "top", "special"], "leetcode_dataset_entry_point": "Solution().maxConsecutive", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:12+00:00", "tests_total": 93, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maxConsecutive($bottom, $top, $special) {", "container": "Solution", "callable": "maxConsecutive", "parameters": [{"name": "bottom", "type": "Integer"}, {"name": "top", "type": "Integer"}, {"name": "special", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2275, "task_id": "largest-combination-with-bitwise-and-greater-than-zero", "difficulty": "Medium", "problem_description": "The bitwise AND of an array nums is the bitwise AND of all integers in nums.\n\n- For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.\n- Also, for nums = [7], the bitwise AND is 7.\n\nYou are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of elements in the candidates array.\n\nReturn the size of the largest combination of candidates with a bitwise AND greater than 0.\n\nExample 1:\n\nInput: candidates = [16,17,71,62,12,24,14]\nOutput: 4\nExplanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.\nThe size of the combination is 4.\nIt can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.\nNote that more than one combination may have the largest size.\nFor example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.\n\nExample 2:\n\nInput: candidates = [8,8]\nOutput: 2\nExplanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.\nThe size of the combination is 2, so we return 2.\n\nConstraints:\n\n- 1 <= candidates.length <= 10^5\n- 1 <= candidates[i] <= 10^7\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(candidates = [16, 17, 71, 62, 12, 24, 14]) == 4\n assert candidate(candidates = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 16\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(candidates = [1, 10000000, 2, 9999999, 3, 9999998, 4, 9999997, 5, 9999996, 6, 9999995, 7, 9999994, 8, 9999993, 9, 9999992, 10, 9999991]) == 11\n assert candidate(candidates = [31, 31, 31, 31, 31, 31, 31, 31, 31, 31]) == 10\n assert candidate(candidates = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(candidates = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991]) == 10\n assert candidate(candidates = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1\n assert candidate(candidates = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(candidates = [8, 8]) == 2\n assert candidate(candidates = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(candidates = [1048575, 1048574, 1048573, 1048572, 1048571]) == 5\n assert candidate(candidates = [10000000, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144]) == 2\n assert candidate(candidates = [31, 31, 31, 31, 31]) == 5\n assert candidate(candidates = [10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000]) == 10\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 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\n assert candidate(candidates = [1048575, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == 14\n assert candidate(candidates = [9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990, 9999989, 9999988, 9999987, 9999986, 9999985, 9999984, 9999983, 9999982, 9999981, 9999980]) == 20\n assert candidate(candidates = [1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 1000007, 1000008, 1000009, 1000010, 1000011, 1000012, 1000013, 1000014, 1000015, 1000016, 1000017, 1000018, 1000019]) == 20\n assert candidate(candidates = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 1\n assert candidate(candidates = [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]) == 30\n assert candidate(candidates = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153, 162, 171, 180]) == 11\n assert candidate(candidates = [524288, 524290, 524292, 524294, 524296, 524298, 524300, 524302, 524304, 524306, 524308, 524310, 524312, 524314, 524316, 524318, 524320, 524322, 524324, 524326]) == 20\n assert candidate(candidates = [5000000, 5000001, 5000002, 5000003, 5000004, 5000005, 5000006, 5000007, 5000008, 5000009, 5000010, 5000011, 5000012, 5000013, 5000014, 5000015, 5000016, 5000017, 5000018, 5000019, 5000020, 5000021, 5000022, 5000023, 5000024, 5000025, 5000026, 5000027, 5000028, 5000029, 5000030]) == 31\n assert candidate(candidates = [5000000, 4000000, 3000000, 2000000, 1000000, 500000, 400000, 300000, 200000, 100000, 50000, 40000, 30000, 20000, 10000, 5000, 4000, 3000, 2000, 1000, 500, 400, 300, 200, 100, 50, 40, 30, 20, 10, 5]) == 16\n assert candidate(candidates = [1, 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]) == 29\n assert candidate(candidates = [8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(candidates = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 1005, 1004]) == 20\n assert candidate(candidates = [983040, 983041, 983042, 983043, 983044, 983045, 983046, 983047, 983048, 983049]) == 10\n assert candidate(candidates = [9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990, 9999989, 9999988, 9999987, 9999986, 9999985, 9999984, 9999983, 9999982, 9999981, 9999980]) == 20\n assert candidate(candidates = [5000000, 5000001, 5000002, 5000003, 5000004, 5000005, 5000006, 5000007, 5000008, 5000009]) == 10\n assert candidate(candidates = [8388607, 8388606, 8388605, 8388604, 8388603, 8388602, 8388601, 8388600, 8388599, 8388598, 8388597, 8388596, 8388595, 8388594, 8388593, 8388592, 8388591, 8388590, 8388589, 8388588]) == 20\n assert candidate(candidates = [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]) == 16\n assert candidate(candidates = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 9\n assert candidate(candidates = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2\n assert candidate(candidates = [15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607]) == 20\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(candidates = [1048575, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2\n assert candidate(candidates = [3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151]) == 20\n assert candidate(candidates = [1023, 2047, 4095, 8191, 16383, 32767, 65535]) == 7\n assert candidate(candidates = [262143, 262142, 262141, 262140, 262139, 262138, 262137, 262136, 262135, 262134, 262133, 262132, 262131, 262130, 262129, 262128, 262127, 262126, 262125, 262124, 262123, 262122, 262121, 262120, 262119, 262118, 262117, 262116, 262115, 262114, 262113]) == 31\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 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]) == 32\n assert candidate(candidates = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]) == 10\n assert candidate(candidates = [5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000, 5000000]) == 15\n assert candidate(candidates = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 20\n assert candidate(candidates = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 20\n assert candidate(candidates = [1, 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]) == 29\n assert candidate(candidates = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(candidates = [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]) == 30\n assert candidate(candidates = [10000000, 5000000, 2500000, 1250000, 625000, 312500, 156250, 78125, 39062, 19531, 9765, 4882, 2441, 1220, 610, 305, 152, 76, 38, 19]) == 8\n assert candidate(candidates = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 62\n assert candidate(candidates = [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\n assert candidate(candidates = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287]) == 10\n assert candidate(candidates = [65535, 65534, 65533, 65532, 65531, 65530, 65529, 65528, 65527, 65526, 65525, 65524, 65523, 65522, 65521, 65520, 65519, 65518, 65517, 65516, 65515, 65514, 65513, 65512, 65511, 65510, 65509, 65508, 65507, 65506, 65505]) == 31\n assert candidate(candidates = [1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576]) == 10\n assert candidate(candidates = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1\n assert candidate(candidates = [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]) == 50\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 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]) == 16\n assert candidate(candidates = [1, 2, 3, 4, 5, 6, 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\n assert candidate(candidates = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000]) == 10\n assert candidate(candidates = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 1\n assert candidate(candidates = [15, 27, 51, 85, 129, 173, 217, 261, 305, 349, 393, 437, 481, 525, 569, 613, 657, 701, 745, 789, 833, 877, 921, 965, 1009, 1053, 1097, 1141, 1185, 1229]) == 30\n assert candidate(candidates = [10000000, 9999999, 9999998, 9999997, 9999996, 9999995, 9999994, 9999993, 9999992, 9999991, 9999990, 9999989, 9999988, 9999987, 9999986, 9999985, 9999984, 9999983, 9999982, 9999981]) == 20\n", "comparison": "exact"}, "public_tests": ["[16,17,71,62,12,24,14]", "[8,8]"], "hints": ["For the bitwise AND to be greater than zero, at least one bit should be 1 for every number in the combination.", "The candidates are 24 bits long, so for every bit position, we can calculate the size of the largest combination such that the bitwise AND will have a 1 at that bit position."], "metadata": {"canonical_parameter_names": ["candidates"], "leetcode_dataset_entry_point": "Solution().largestCombination", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:14+00:00", "tests_total": 92, "tests_dropped": 29, "flags": [], "topic_tags": ["array", "hash-table", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function largestCombination($candidates) {", "container": "Solution", "callable": "largestCombination", "parameters": [{"name": "candidates", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2278, "task_id": "percentage-of-letter-in-string", "difficulty": "Easy", "problem_description": "Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.\n\nExample 1:\n\nInput: s = \"foobar\", letter = \"o\"\nOutput: 33\nExplanation:\nThe percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.\n\nExample 2:\n\nInput: s = \"jjjj\", letter = \"k\"\nOutput: 0\nExplanation:\nThe percentage of characters in s that equal the letter 'k' is 0%, so we return 0.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- s consists of lowercase English letters.\n- letter is a lowercase English letter.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"jjjj\",letter = \"k\") == 0\n assert candidate(s = \"foobar\",letter = \"o\") == 33\n assert candidate(s = \"mississippi\",letter = \"i\") == 36\n assert candidate(s = \"python\",letter = \"y\") == 16\n assert candidate(s = \"abcabcabc\",letter = \"a\") == 33\n assert candidate(s = \"hello\",letter = \"l\") == 40\n assert candidate(s = \"world\",letter = \"d\") == 20\n assert candidate(s = \"zzzz\",letter = \"z\") == 100\n assert candidate(s = \"b\",letter = \"a\") == 0\n assert candidate(s = \"solution\",letter = \"o\") == 25\n assert candidate(s = \"aaaaabbbbb\",letter = \"b\") == 50\n assert candidate(s = \"a\",letter = \"a\") == 100\n assert candidate(s = \"abcdefg\",letter = \"h\") == 0\n assert candidate(s = \"zzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"aabbcc\",letter = \"b\") == 33\n assert candidate(s = \"aabbccddeeff\",letter = \"c\") == 16\n assert candidate(s = \"abcdefg\",letter = \"a\") == 14\n assert candidate(s = \"zzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"abcdefg\",letter = \"x\") == 0\n assert candidate(s = \"characterization\",letter = \"c\") == 12\n assert candidate(s = \"examplewithrepeatedletterzzzz\",letter = \"z\") == 13\n assert candidate(s = \"qwertypoiuytrewqasdfghjklzxcvbnmasdfghjklzxcvbnm\",letter = \"q\") == 4\n assert candidate(s = \"oneletterone\",letter = \"n\") == 16\n assert candidate(s = \"parameter\",letter = \"r\") == 22\n assert candidate(s = \"alphabet\",letter = \"p\") == 12\n assert candidate(s = \"determinethepercentage\",letter = \"e\") == 31\n assert candidate(s = \"programming\",letter = \"m\") == 18\n assert candidate(s = \"supercalifragilisticexpialidocious\",letter = \"i\") == 20\n assert candidate(s = \"abracadabra\",letter = \"a\") == 45\n assert candidate(s = \"development\",letter = \"e\") == 27\n assert candidate(s = \"abcdefghij\",letter = \"a\") == 10\n assert candidate(s = \"abcdefghijk\",letter = \"a\") == 9\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"abcdefghij\",letter = \"j\") == 10\n assert candidate(s = \"visualization\",letter = \"i\") == 23\n assert candidate(s = \"programming\",letter = \"g\") == 18\n assert candidate(s = \"development\",letter = \"d\") == 9\n assert candidate(s = \"charactercounting\",letter = \"c\") == 17\n assert candidate(s = \"percentage\",letter = \"e\") == 30\n assert candidate(s = \"classification\",letter = \"f\") == 7\n assert candidate(s = \"environment\",letter = \"n\") == 27\n assert candidate(s = \"xyz\",letter = \"z\") == 33\n assert candidate(s = \"charactercountexample\",letter = \"e\") == 14\n assert candidate(s = \"testtesttesttest\",letter = \"t\") == 50\n assert candidate(s = \"computation\",letter = \"i\") == 9\n assert candidate(s = \"performance\",letter = \"n\") == 9\n assert candidate(s = \"understanding\",letter = \"d\") == 15\n assert candidate(s = \"consistencyiskey\",letter = \"i\") == 12\n assert candidate(s = \"xyxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyzxzyzyz\",letter = \"y\") == 33\n assert candidate(s = \"algorithm\",letter = \"g\") == 11\n assert candidate(s = \"representation\",letter = \"r\") == 14\n assert candidate(s = \"communication\",letter = \"m\") == 15\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",letter = \"z\") == 3\n assert candidate(s = \"mississippi\",letter = \"s\") == 36\n assert candidate(s = \"thisisaverylongstringwithrandomcharacters\",letter = \"t\") == 9\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"variable\",letter = \"b\") == 12\n assert candidate(s = \"pythonprogramming\",letter = \"p\") == 11\n assert candidate(s = \"xyzzxyzz\",letter = \"z\") == 50\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",letter = \"a\") == 3\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",letter = \"m\") == 3\n assert candidate(s = \"xylophone\",letter = \"p\") == 11\n assert candidate(s = \"characterization\",letter = \"t\") == 12\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"synchronous\",letter = \"s\") == 18\n assert candidate(s = \"congratulations\",letter = \"t\") == 13\n assert candidate(s = \"mississippi\",letter = \"x\") == 0\n assert candidate(s = \"example\",letter = \"a\") == 14\n assert candidate(s = \"development\",letter = \"l\") == 9\n assert candidate(s = \"averylongstringwithvariouscharacters\",letter = \"a\") == 11\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",letter = \"z\") == 3\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\",letter = \"e\") == 8\n assert candidate(s = \"uniquecharacters\",letter = \"u\") == 12\n assert candidate(s = \"hellotheregeneralkenobi\",letter = \"l\") == 13\n assert candidate(s = \"asynchronous\",letter = \"y\") == 8\n assert candidate(s = \"helloalibabacloud\",letter = \"a\") == 17\n assert candidate(s = \"mathematics\",letter = \"a\") == 18\n assert candidate(s = \"function\",letter = \"u\") == 12\n assert candidate(s = \"expression\",letter = \"s\") == 20\n assert candidate(s = \"thisisaverylongstringthatshouldtestthemaximumlengthoftheinputwhichisonehundredcharacters\",letter = \"s\") == 7\n assert candidate(s = \"lkjashdflkjhaskldjfhlasjdhflkajshdfjklsahjfdlkjahs\",letter = \"l\") == 14\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxyxy\",letter = \"x\") == 50\n assert candidate(s = \"programminglanguage\",letter = \"g\") == 21\n assert candidate(s = \"abcdefghij\",letter = \"m\") == 0\n assert candidate(s = \"percentageletter\",letter = \"t\") == 18\n assert candidate(s = \"encyclopedia\",letter = \"o\") == 8\n assert candidate(s = \"thisisaverylongstringindeedtoseeifitworks\",letter = \"s\") == 12\n assert candidate(s = \"alphabet\",letter = \"z\") == 0\n assert candidate(s = \"programminglanguage\",letter = \"a\") == 15\n assert candidate(s = \"statistics\",letter = \"s\") == 30\n assert candidate(s = \"xylophone\",letter = \"x\") == 11\n assert candidate(s = \"encyclopedia\",letter = \"e\") == 16\n assert candidate(s = \"nolettersmatch\",letter = \"z\") == 0\n assert candidate(s = \"elephant\",letter = \"l\") == 12\n assert candidate(s = \"character\",letter = \"c\") == 22\n assert candidate(s = \"banana\",letter = \"a\") == 50\n assert candidate(s = \"congratulations\",letter = \"o\") == 13\n assert candidate(s = \"longstringwithvariouscharacters\",letter = \"v\") == 3\n assert candidate(s = \"algorithm\",letter = \"l\") == 11\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\",letter = \"b\") == 33\n assert candidate(s = \"alabama\",letter = \"b\") == 14\n assert candidate(s = \"zzzzzzzzzz\",letter = \"z\") == 100\n assert candidate(s = \"sequence\",letter = \"q\") == 12\n assert candidate(s = \"banana\",letter = \"n\") == 33\n", "comparison": "exact"}, "public_tests": ["\"foobar\"\n\"o\"", "\"jjjj\"\n\"k\""], "hints": ["Can we count the number of occurrences of letter in s?", "Recall that the percentage is calculated as (occurrences / total) * 100."], "metadata": {"canonical_parameter_names": ["s", "letter"], "leetcode_dataset_entry_point": "Solution().percentageLetter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:19+00:00", "tests_total": 107, "tests_dropped": 2, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function percentageLetter($s, $letter) {", "container": "Solution", "callable": "percentageLetter", "parameters": [{"name": "s", "type": "String"}, {"name": "letter", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2279, "task_id": "maximum-bags-with-full-capacity-of-rocks", "difficulty": "Medium", "problem_description": "You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The i^th bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.\n\nReturn the maximum number of bags that could have full capacity after placing the additional rocks in some bags.\n\nExample 1:\n\nInput: capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2\nOutput: 3\nExplanation:\nPlace 1 rock in bag 0 and 1 rock in bag 1.\nThe number of rocks in each bag are now [2,3,4,4].\nBags 0, 1, and 2 have full capacity.\nThere are 3 bags at full capacity, so we return 3.\nIt can be shown that it is not possible to have more than 3 bags at full capacity.\nNote that there may be other ways of placing the rocks that result in an answer of 3.\n\nExample 2:\n\nInput: capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100\nOutput: 3\nExplanation:\nPlace 8 rocks in bag 0 and 2 rocks in bag 2.\nThe number of rocks in each bag are now [10,2,2].\nBags 0, 1, and 2 have full capacity.\nThere are 3 bags at full capacity, so we return 3.\nIt can be shown that it is not possible to have more than 3 bags at full capacity.\nNote that we did not use all of the additional rocks.\n\nConstraints:\n\n- n == capacity.length == rocks.length\n- 1 <= n <= 5 * 10^4\n- 1 <= capacity[i] <= 10^9\n- 0 <= rocks[i] <= capacity[i]\n- 1 <= additionalRocks <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(capacity = [2, 3, 4, 5],rocks = [1, 2, 4, 4],additionalRocks = 2) == 3\n assert candidate(capacity = [1, 2, 3],rocks = [0, 0, 0],additionalRocks = 5) == 2\n assert candidate(capacity = [3, 2, 1],rocks = [0, 0, 0],additionalRocks = 5) == 2\n assert candidate(capacity = [1, 1, 1],rocks = [0, 0, 0],additionalRocks = 3) == 3\n assert candidate(capacity = [3, 9, 8],rocks = [0, 2, 5],additionalRocks = 6) == 2\n assert candidate(capacity = [5, 5, 5, 5],rocks = [0, 0, 0, 0],additionalRocks = 10) == 2\n assert candidate(capacity = [1, 1, 1, 1],rocks = [1, 1, 1, 1],additionalRocks = 1) == 4\n assert candidate(capacity = [3, 3, 3],rocks = [3, 0, 0],additionalRocks = 3) == 2\n assert candidate(capacity = [10, 2, 2],rocks = [2, 2, 0],additionalRocks = 100) == 3\n assert candidate(capacity = [5, 5, 5],rocks = [0, 0, 0],additionalRocks = 10) == 2\n assert candidate(capacity = [1, 1, 1, 1],rocks = [1, 1, 1, 1],additionalRocks = 4) == 4\n assert candidate(capacity = [5, 5, 5],rocks = [0, 0, 0],additionalRocks = 15) == 3\n assert candidate(capacity = [3, 3, 3],rocks = [1, 2, 3],additionalRocks = 2) == 2\n assert candidate(capacity = [1, 3, 5, 7, 9],rocks = [0, 1, 2, 3, 4],additionalRocks = 10) == 4\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [0, 0, 0, 0, 0],additionalRocks = 1500) == 5\n assert candidate(capacity = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 2500) == 9\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 5) == 5\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 5) == 5\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [0, 0, 0, 0, 0],additionalRocks = 45) == 4\n assert candidate(capacity = [5, 8, 10, 15, 20],rocks = [0, 4, 7, 10, 15],additionalRocks = 20) == 4\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 55) == 10\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [50, 150, 250, 350, 450],additionalRocks = 500) == 5\n assert candidate(capacity = [1, 2, 3, 4, 5, 6],rocks = [0, 0, 0, 0, 0, 0],additionalRocks = 20) == 5\n assert candidate(capacity = [500000000, 500000000, 500000000],rocks = [0, 0, 0],additionalRocks = 1000000000) == 2\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [10, 20, 30, 40, 0],additionalRocks = 50) == 5\n assert candidate(capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],rocks = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4],additionalRocks = 15) == 6\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [1, 2, 3, 4, 5],additionalRocks = 90) == 4\n assert candidate(capacity = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],rocks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],additionalRocks = 5) == 5\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [0, 0, 0, 0, 0],additionalRocks = 30) == 3\n assert candidate(capacity = [5, 5, 5, 5, 5],rocks = [1, 2, 3, 4, 5],additionalRocks = 10) == 5\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 5) == 5\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [90, 180, 270, 360, 450],additionalRocks = 100) == 4\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [5, 5, 5, 5, 5],additionalRocks = 25) == 5\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],additionalRocks = 10) == 10\n assert candidate(capacity = [2, 4, 6, 8, 10],rocks = [0, 1, 2, 3, 4],additionalRocks = 10) == 3\n assert candidate(capacity = [50, 50, 50, 50, 50],rocks = [0, 0, 0, 0, 0],additionalRocks = 100) == 2\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 10) == 10\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [0, 0, 0, 0, 0],additionalRocks = 150) == 5\n assert candidate(capacity = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 10) == 4\n assert candidate(capacity = [999999999, 1],rocks = [0, 0],additionalRocks = 1000000000) == 2\n assert candidate(capacity = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 550) == 10\n assert candidate(capacity = [100, 100, 100, 100],rocks = [100, 100, 100, 100],additionalRocks = 100) == 4\n assert candidate(capacity = [2, 4, 6, 8, 10],rocks = [1, 1, 1, 1, 1],additionalRocks = 15) == 3\n assert candidate(capacity = [50, 50, 50, 50, 50],rocks = [10, 20, 30, 40, 50],additionalRocks = 100) == 5\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 10) == 10\n assert candidate(capacity = [5, 15, 25, 35, 45],rocks = [2, 8, 14, 20, 26],additionalRocks = 120) == 5\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [0, 100, 200, 300, 400],additionalRocks = 500) == 5\n assert candidate(capacity = [5, 10, 15, 20, 25, 30, 35],rocks = [0, 0, 0, 0, 0, 0, 0],additionalRocks = 105) == 6\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],additionalRocks = 45) == 10\n assert candidate(capacity = [1, 3, 5, 7, 9],rocks = [0, 0, 0, 0, 0],additionalRocks = 25) == 5\n assert candidate(capacity = [1, 2, 4, 8, 16, 32, 64, 128],rocks = [0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 255) == 8\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [0, 0, 0, 0, 0],additionalRocks = 100) == 4\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],additionalRocks = 1) == 10\n assert candidate(capacity = [25, 25, 25, 25, 25, 25, 25, 25, 25, 25],rocks = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20],additionalRocks = 50) == 10\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],additionalRocks = 15) == 10\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [50, 100, 150, 200, 250],additionalRocks = 500) == 4\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [5, 5, 5, 5, 5],additionalRocks = 15) == 3\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [50, 100, 150, 200, 250],additionalRocks = 1000) == 5\n assert candidate(capacity = [1, 2, 4, 8, 16, 32],rocks = [0, 1, 3, 7, 15, 31],additionalRocks = 63) == 6\n assert candidate(capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 50) == 5\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [9, 8, 7, 6, 5],additionalRocks = 5) == 2\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [0, 2, 4, 6, 8],additionalRocks = 15) == 3\n assert candidate(capacity = [1000, 2000, 3000, 4000, 5000],rocks = [500, 1000, 1500, 2000, 2500],additionalRocks = 5000) == 4\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [50, 100, 150, 200, 250],additionalRocks = 100) == 1\n assert candidate(capacity = [100, 200, 300],rocks = [50, 100, 150],additionalRocks = 200) == 2\n assert candidate(capacity = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],rocks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],additionalRocks = 100) == 19\n assert candidate(capacity = [3, 6, 9, 12, 15],rocks = [0, 3, 6, 9, 12],additionalRocks = 20) == 5\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [1, 2, 3, 4, 5],additionalRocks = 80) == 3\n assert candidate(capacity = [10, 15, 20, 25, 30],rocks = [0, 5, 10, 20, 25],additionalRocks = 50) == 5\n assert candidate(capacity = [1000000, 2000000, 3000000, 4000000, 5000000],rocks = [100000, 200000, 300000, 400000, 500000],additionalRocks = 5000000) == 2\n assert candidate(capacity = [100, 100, 100, 100],rocks = [99, 98, 97, 96],additionalRocks = 4) == 2\n assert candidate(capacity = [1, 2, 3, 4, 5],rocks = [0, 1, 2, 3, 4],additionalRocks = 10) == 5\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [10, 20, 30, 40, 50],additionalRocks = 100) == 5\n assert candidate(capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],rocks = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],additionalRocks = 5) == 5\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [90, 190, 290, 390, 490],additionalRocks = 50) == 5\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [0, 0, 0, 0, 0],additionalRocks = 25) == 2\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 5) == 2\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 55) == 10\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [9, 19, 29, 39, 49],additionalRocks = 5) == 5\n assert candidate(capacity = [7, 7, 7, 7, 7, 7, 7],rocks = [1, 2, 3, 4, 5, 6, 0],additionalRocks = 14) == 4\n assert candidate(capacity = [5, 5, 5, 5, 5],rocks = [0, 1, 2, 3, 4],additionalRocks = 10) == 4\n assert candidate(capacity = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 55) == 10\n assert candidate(capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],rocks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],additionalRocks = 5) == 1\n assert candidate(capacity = [10, 10, 10, 10, 10],rocks = [1, 2, 3, 4, 5],additionalRocks = 15) == 2\n assert candidate(capacity = [100, 200, 300, 400, 500],rocks = [10, 20, 30, 40, 50],additionalRocks = 1000) == 4\n assert candidate(capacity = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],rocks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],additionalRocks = 55) == 10\n assert candidate(capacity = [10, 20, 30, 40, 50],rocks = [0, 5, 10, 15, 20],additionalRocks = 100) == 5\n assert candidate(capacity = [100000000, 100000000, 100000000],rocks = [50000000, 50000000, 50000000],additionalRocks = 100000000) == 2\n assert candidate(capacity = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],rocks = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4],additionalRocks = 25) == 12\n assert candidate(capacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],rocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],additionalRocks = 10) == 10\n", "comparison": "exact"}, "public_tests": ["[2,3,4,5]\n[1,2,4,4]\n2", "[10,2,2]\n[2,2,0]\n100"], "hints": ["Which bag should you fill completely first?", "Can you think of a greedy solution?"], "metadata": {"canonical_parameter_names": ["capacity", "rocks", "additionalRocks"], "leetcode_dataset_entry_point": "Solution().maximumBags", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:21+00:00", "tests_total": 103, "tests_dropped": 13, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function maximumBags($capacity, $rocks, $additionalRocks) {", "container": "Solution", "callable": "maximumBags", "parameters": [{"name": "capacity", "type": "Integer[]"}, {"name": "rocks", "type": "Integer[]"}, {"name": "additionalRocks", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2280, "task_id": "minimum-lines-to-represent-a-line-chart", "difficulty": "Medium", "problem_description": "You are given a 2D integer array stockPrices where stockPrices[i] = [day_i, price_i] indicates the price of the stock on day day_i is price_i. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:\n\nReturn the minimum number of lines needed to represent the line chart.\n\nExample 1:\n\nInput: stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]\nOutput: 3\nExplanation:\nThe diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.\nThe following 3 lines can be drawn to represent the line chart:\n- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).\n- Line 2 (in blue) from (4,4) to (5,4).\n- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).\nIt can be shown that it is not possible to represent the line chart using less than 3 lines.\n\nExample 2:\n\nInput: stockPrices = [[3,4],[1,2],[7,8],[2,3]]\nOutput: 1\nExplanation:\nAs shown in the diagram above, the line chart can be represented with a single line.\n\nConstraints:\n\n- 1 <= stockPrices.length <= 10^5\n- stockPrices[i].length == 2\n- 1 <= day_i, price_i <= 10^9\n- All day_i are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stockPrices = [[3, 4], [1, 2], [7, 8], [2, 3]]) == 1\n assert candidate(stockPrices = [[1, 7], [2, 6], [3, 5], [4, 4], [5, 4], [6, 3], [7, 2], [8, 1]]) == 3\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 10], [3, 3], [4, 14], [5, 5], [6, 18], [7, 7], [8, 22], [9, 9], [10, 26]]) == 9\n assert candidate(stockPrices = [[1, 1], [10, 10], [100, 100], [1000, 1000], [10000, 10000], [100000, 100000], [1000000, 1000000], [10000000, 10000000], [100000000, 100000000]]) == 1\n assert candidate(stockPrices = [[1, 2], [2, 4], [3, 6], [5, 8], [10, 14], [20, 22], [30, 30], [40, 40]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 5], [8, 7], [16, 9], [32, 11], [64, 13], [128, 15]]) == 7\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [6, 21], [7, 28], [8, 36], [9, 45], [10, 55]]) == 9\n assert candidate(stockPrices = [[1, 2], [2, 3], [4, 5], [5, 7], [6, 11], [7, 13], [8, 17], [9, 19]]) == 6\n assert candidate(stockPrices = [[1, 2], [2, 2], [3, 3], [4, 3], [5, 4], [6, 5], [7, 6], [8, 6], [9, 7]]) == 6\n assert candidate(stockPrices = [[1, 1], [3, 3], [6, 6], [10, 10], [15, 15], [21, 21], [28, 28]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 5], [8, 9], [16, 17], [32, 33], [64, 65], [128, 129]]) == 2\n assert candidate(stockPrices = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 11], [6, 13], [7, 17]]) == 4\n assert candidate(stockPrices = [[1, 1], [3, 5], [6, 10], [10, 17], [15, 26], [21, 37], [28, 50], [36, 65], [45, 82]]) == 8\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [5, 5], [6, 6], [8, 8], [9, 9], [11, 11], [12, 12]]) == 1\n assert candidate(stockPrices = [[1, 5], [2, 5], [3, 5], [4, 6], [5, 6], [6, 6], [7, 7], [8, 7], [9, 7], [10, 8]]) == 6\n assert candidate(stockPrices = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19], [21, 21], [23, 23]]) == 1\n assert candidate(stockPrices = [[1, 10], [2, 20], [3, 30], [4, 25], [5, 20], [6, 15], [7, 10]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 5], [3, 10], [4, 17], [5, 26], [6, 37], [7, 50], [8, 65], [9, 82], [10, 101]]) == 9\n assert candidate(stockPrices = [[1, 2], [2, 3], [3, 2], [4, 3], [5, 2], [6, 3], [7, 2], [8, 3]]) == 7\n assert candidate(stockPrices = [[1, 5], [2, 7], [3, 9], [4, 11], [5, 13], [6, 15], [7, 17], [8, 19], [9, 21], [10, 23]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64]]) == 7\n assert candidate(stockPrices = [[1, 1], [3, 2], [5, 3], [7, 4], [9, 5], [11, 6], [13, 7], [15, 8], [17, 9], [19, 10]]) == 1\n assert candidate(stockPrices = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 2], [7, 3], [8, 4], [9, 5], [10, 6]]) == 2\n assert candidate(stockPrices = [[1, 2], [2, 3], [4, 5], [7, 8], [11, 12], [16, 14], [22, 15], [29, 16], [37, 17]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 5], [5, 8], [6, 12], [7, 17], [8, 23], [9, 30], [10, 38]]) == 8\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 4], [4, 6], [5, 8], [6, 10], [7, 12], [8, 14], [9, 16], [10, 18]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [6, 21], [7, 28]]) == 6\n assert candidate(stockPrices = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 10], [3, 20], [4, 30], [5, 40], [6, 50], [7, 60], [8, 70], [9, 80], [10, 90]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]) == 1\n assert candidate(stockPrices = [[1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]) == 2\n assert candidate(stockPrices = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [11, 20], [12, 21], [13, 22], [14, 23], [15, 24]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 7], [7, 15], [11, 26], [16, 40], [22, 58], [29, 79]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 5], [4, 9], [8, 13], [16, 17], [32, 21], [64, 25], [128, 29]]) == 7\n assert candidate(stockPrices = [[1, 1], [10, 2], [100, 3], [1000, 4], [10000, 5], [100000, 6], [1000000, 7]]) == 6\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 5], [3, 14], [4, 30], [5, 50], [6, 75], [7, 105], [8, 140], [9, 182], [10, 230]]) == 9\n assert candidate(stockPrices = [[1, 2], [2, 1], [3, 2], [4, 1], [5, 2], [6, 1], [7, 2], [8, 1], [9, 2], [10, 1]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [5, 5], [8, 8], [13, 13], [21, 21], [34, 34], [55, 55]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 2], [5, 3], [6, 4], [7, 4], [8, 4], [9, 5], [10, 6]]) == 4\n assert candidate(stockPrices = [[1, 5], [2, 10], [3, 15], [5, 20], [10, 25], [20, 30], [40, 35], [80, 40]]) == 6\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 2], [4, 3], [5, 3], [6, 4], [7, 4], [8, 5]]) == 7\n assert candidate(stockPrices = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == 1\n assert candidate(stockPrices = [[1, 3], [2, 5], [3, 7], [4, 9], [5, 11], [6, 13], [7, 15], [8, 17], [9, 19], [10, 21], [11, 23], [12, 25]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 2], [4, 5], [5, 4], [6, 7], [7, 6], [8, 9], [9, 8], [10, 11]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 2], [7, 3], [8, 2], [9, 1], [10, 1], [11, 1], [12, 1], [13, 1], [14, 1], [15, 1]]) == 4\n assert candidate(stockPrices = [[1, 1], [2, 4], [4, 9], [7, 16], [11, 25], [16, 36], [22, 49], [29, 64]]) == 7\n assert candidate(stockPrices = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500], [60, 600], [70, 700]]) == 1\n assert candidate(stockPrices = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [6, 5], [7, 5], [8, 5], [9, 5], [10, 5]]) == 1\n assert candidate(stockPrices = [[1, 1], [3, 3], [6, 6], [9, 9], [12, 12], [15, 15], [18, 18], [21, 21]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == 1\n assert candidate(stockPrices = [[1, 1], [3, 2], [6, 3], [10, 4], [15, 5], [21, 6], [28, 7], [36, 8], [45, 9]]) == 8\n assert candidate(stockPrices = [[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\n assert candidate(stockPrices = [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]) == 8\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 3], [5, 3], [6, 3], [7, 4], [8, 5], [9, 6], [10, 7]]) == 3\n assert candidate(stockPrices = [[1, 2], [2, 3], [3, 5], [5, 8], [8, 13], [13, 21], [21, 34], [34, 55], [55, 89], [89, 144]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 9], [6, 11], [7, 13], [8, 15], [9, 17], [10, 19], [11, 21], [12, 23], [13, 25]]) == 1\n assert candidate(stockPrices = [[1, 2], [2, 2], [3, 2], [4, 3], [5, 4], [6, 5], [7, 5], [8, 5], [9, 6], [10, 7]]) == 4\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 1\n assert candidate(stockPrices = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16], [9, 18], [10, 20]]) == 1\n assert candidate(stockPrices = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17], [19, 19]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 1], [4, 2], [5, 1], [6, 2], [7, 1], [8, 2], [9, 1], [10, 2]]) == 9\n assert candidate(stockPrices = [[1, 1], [3, 5], [6, 10], [10, 15], [15, 20], [21, 25], [28, 30]]) == 6\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 5], [5, 7], [6, 9], [7, 11]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 4], [4, 8], [5, 16], [6, 32], [7, 64], [8, 128], [9, 256], [10, 512]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 3], [4, 9], [8, 27], [16, 81], [32, 243], [64, 729], [128, 2187]]) == 7\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3], [7, 4], [8, 4], [9, 5], [10, 5]]) == 9\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 5], [5, 7], [6, 10], [7, 15], [8, 21], [9, 28], [10, 36]]) == 7\n assert candidate(stockPrices = [[10, 20], [20, 10], [30, 30], [40, 40], [50, 50], [60, 60]]) == 3\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 4], [5, 8], [9, 16], [17, 32], [33, 64], [65, 128], [129, 256]]) == 2\n assert candidate(stockPrices = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [6, 8], [7, 6], [8, 4], [9, 2]]) == 2\n assert candidate(stockPrices = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [8, 3], [9, 3], [10, 3]]) == 1\n assert candidate(stockPrices = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 1\n assert candidate(stockPrices = [[1, 2], [2, 2], [3, 3], [4, 3], [5, 4], [6, 4], [7, 5], [8, 5]]) == 7\n assert candidate(stockPrices = [[1, 2], [2, 2], [3, 2], [4, 2], [5, 3], [6, 4], [7, 5], [8, 6], [9, 7], [10, 8]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 11]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 2], [4, 2], [5, 3], [6, 3], [7, 4], [8, 4], [9, 5]]) == 7\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 3], [4, 4], [5, 5], [6, 6], [7, 8], [8, 8], [9, 9], [10, 10]]) == 6\n assert candidate(stockPrices = [[1, 1], [2, 2], [4, 4], [5, 5], [7, 7], [8, 8], [10, 10], [11, 11]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [4, 5], [5, 8], [6, 13], [7, 21], [8, 31], [9, 43], [10, 57]]) == 8\n assert candidate(stockPrices = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 2]]) == 2\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1]]) == 1\n assert candidate(stockPrices = [[1, 10], [2, 15], [3, 25], [4, 40], [5, 60], [6, 85], [7, 115], [8, 150], [9, 190], [10, 235]]) == 9\n assert candidate(stockPrices = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 6], [6, 6], [7, 6], [8, 6], [9, 7], [10, 7]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 5], [3, 9], [4, 14], [5, 19], [6, 25], [7, 31], [8, 38], [9, 45], [10, 53]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 3], [3, 5], [4, 7], [5, 5], [6, 3], [7, 1], [8, 3], [9, 5], [10, 7]]) == 3\n assert candidate(stockPrices = [[1, 1], [3, 4], [6, 7], [8, 10], [9, 11], [11, 13], [13, 15], [14, 16]]) == 4\n assert candidate(stockPrices = [[5, 3], [10, 6], [15, 9], [20, 12], [25, 15], [30, 18], [35, 21], [40, 24]]) == 1\n assert candidate(stockPrices = [[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], [20, 5]]) == 1\n assert candidate(stockPrices = [[1, 1000000000], [2, 999999999], [3, 999999998], [4, 999999997], [5, 999999996], [6, 999999995], [7, 999999994], [8, 999999993], [9, 999999992], [10, 999999991]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 2], [6, 2], [7, 2], [8, 2], [9, 3], [10, 3]]) == 5\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 3], [5, 5], [6, 6], [8, 8], [9, 9], [10, 10]]) == 1\n assert candidate(stockPrices = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9], [11, 11], [13, 13], [15, 15], [17, 17]]) == 1\n assert candidate(stockPrices = [[1, 1], [2, 2], [3, 5], [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(stockPrices = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 40], [7, 30], [8, 20], [9, 10]]) == 2\n", "comparison": "exact"}, "public_tests": ["[[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]", "[[3,4],[1,2],[7,8],[2,3]]"], "hints": ["When will three adjacent points lie on the same line? How can we generalize this for all points?", "Will calculating the slope of lines connecting adjacent points help us find the answer?"], "metadata": {"canonical_parameter_names": ["stockPrices"], "leetcode_dataset_entry_point": "Solution().minimumLines", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:23+00:00", "tests_total": 107, "tests_dropped": 7, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "math", "geometry", "sorting", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function minimumLines($stockPrices) {", "container": "Solution", "callable": "minimumLines", "parameters": [{"name": "stockPrices", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2281, "task_id": "sum-of-total-strength-of-wizards", "difficulty": "Hard", "problem_description": "As the ruler of a kingdom, you have an army of wizards at your command.\n\nYou are given a 0-indexed integer array strength, where strength[i] denotes the strength of the i^th wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the product of the following two values:\n\n- The strength of the weakest wizard in the group.\n- The total of all the individual strengths of the wizards in the group.\n\nReturn the sum of the total strengths of all contiguous groups of wizards. Since 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: strength = [1,3,1,2]\nOutput: 44\nExplanation: The following are all the contiguous groups of wizards:\n- [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [3] from [1,3,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9\n- [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [2] from [1,3,1,2] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4\n- [1,3] from [1,3,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4\n- [3,1] from [1,3,1,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4\n- [1,2] from [1,3,1,2] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3\n- [1,3,1] from [1,3,1,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5\n- [3,1,2] from [1,3,1,2] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6\n- [1,3,1,2] from [1,3,1,2] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7\nThe sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.\n\nExample 2:\n\nInput: strength = [5,4,6]\nOutput: 213\nExplanation: The following are all the contiguous groups of wizards:\n- [5] from [5,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25\n- [4] from [5,4,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16\n- [6] from [5,4,6] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36\n- [5,4] from [5,4,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36\n- [4,6] from [5,4,6] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40\n- [5,4,6] from [5,4,6] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60\nThe sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.\n\nConstraints:\n\n- 1 <= strength.length <= 10^5\n- 1 <= strength[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(strength = [1]) == 1\n assert candidate(strength = [1, 1, 1, 1, 1]) == 35\n assert candidate(strength = [10, 9, 8, 7, 6]) == 1988\n assert candidate(strength = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4576\n assert candidate(strength = [5]) == 25\n assert candidate(strength = [1000000000, 1000000000, 1000000000]) == 490\n assert candidate(strength = [5, 3, 1, 2, 4]) == 156\n assert candidate(strength = [1, 2, 3, 4, 5]) == 238\n assert candidate(strength = [5, 6, 7, 8, 9, 10]) == 2688\n assert candidate(strength = [5, 4, 6]) == 213\n assert candidate(strength = [1, 10, 1, 10, 1, 10]) == 578\n assert candidate(strength = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 731\n assert candidate(strength = [10, 9, 8, 7, 6, 5]) == 2688\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4576\n assert candidate(strength = [1, 3, 1, 2]) == 44\n assert candidate(strength = [1000000000, 1000000000]) == 196\n assert candidate(strength = [1, 3, 5, 7, 9, 7, 5, 3, 1]) == 2577\n assert candidate(strength = [100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100, 50, 100]) == 2600000\n assert candidate(strength = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 21824\n assert candidate(strength = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2330\n assert candidate(strength = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 4144\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 315315\n assert candidate(strength = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 22000\n assert candidate(strength = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 108290\n assert candidate(strength = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 760\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1540\n assert candidate(strength = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1]) == 4820\n assert candidate(strength = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 8712\n assert candidate(strength = [1, 5, 2, 5, 3, 5, 4, 5, 5, 5]) == 2232\n assert candidate(strength = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 13042\n assert candidate(strength = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 457600\n assert candidate(strength = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 370373883\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 109802\n assert candidate(strength = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 98736\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2871\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 2871\n assert candidate(strength = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 1660\n assert candidate(strength = [10, 20, 30, 40, 50]) == 23800\n assert candidate(strength = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 38768\n assert candidate(strength = [1000000000, 1000000000, 1000000000, 1000000000]) == 980\n assert candidate(strength = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4576\n assert candidate(strength = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == 370373883\n assert candidate(strength = [5, 3, 8, 6, 2, 7, 4, 9, 1]) == 1914\n assert candidate(strength = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 14312\n assert candidate(strength = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 2684\n assert candidate(strength = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 2439\n assert candidate(strength = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10]) == 4200\n assert candidate(strength = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 109802\n assert candidate(strength = [2, 1, 3, 4, 2, 1, 3, 4, 2, 1]) == 638\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 165\n assert candidate(strength = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 268328687\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 457600\n assert candidate(strength = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 13552\n assert candidate(strength = [2, 1, 3, 4, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 1, 2]) == 3672\n assert candidate(strength = [3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 3193\n assert candidate(strength = [5, 3, 8, 6, 2, 7, 4, 1, 9]) == 1590\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2767600\n assert candidate(strength = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5]) == 619372\n assert candidate(strength = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 30778\n assert candidate(strength = [5, 1, 4, 2, 3, 6, 7, 8, 9, 10]) == 3448\n assert candidate(strength = [2, 1, 2, 1, 2, 1, 2, 1, 2]) == 260\n assert candidate(strength = [35, 30, 25, 20, 15, 10, 5, 10, 15, 20, 25, 30, 35]) == 72275\n assert candidate(strength = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 3178\n assert candidate(strength = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 268328687\n assert candidate(strength = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1715\n assert candidate(strength = [1000000000, 1000000000, 1000000000, 1000000000]) == 980\n assert candidate(strength = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1414\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 2767600\n assert candidate(strength = [10, 15, 10, 20, 15, 25, 20, 30, 25, 35]) == 61475\n assert candidate(strength = [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]) == 301120400\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 457600\n assert candidate(strength = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 1013\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1540\n assert candidate(strength = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 3150\n assert candidate(strength = [10, 20, 30, 20, 10, 10, 20, 30, 20, 10]) == 46200\n assert candidate(strength = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2871\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4576\n assert candidate(strength = [3, 1, 2, 5, 4]) == 186\n assert candidate(strength = [5, 1, 3, 2, 4, 6, 8, 7, 9]) == 2155\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 220\n assert candidate(strength = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10780\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2876356\n assert candidate(strength = [1, 1000000000, 1, 1000000000, 1, 1000000000]) == 0\n assert candidate(strength = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 3676\n assert candidate(strength = [100, 1, 200, 2, 300, 3, 400, 4, 500]) == 596592\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 109802\n assert candidate(strength = [50, 20, 30, 10, 40, 60, 70, 5, 80, 90]) == 115850\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 220\n assert candidate(strength = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 30778\n assert candidate(strength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 28764\n assert candidate(strength = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 926\n assert candidate(strength = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 28764\n assert candidate(strength = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 826\n assert candidate(strength = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 369\n assert candidate(strength = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 340\n assert candidate(strength = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 6, 7, 8, 9, 10]) == 3083588\n assert candidate(strength = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2871\n assert candidate(strength = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5500\n assert candidate(strength = [1, 3, 2, 4, 1, 5, 2, 6, 1, 7, 2, 8, 1, 9, 2, 10]) == 3648\n assert candidate(strength = [3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == 1864\n assert candidate(strength = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3]) == 639\n assert candidate(strength = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 165\n assert candidate(strength = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 1980\n", "comparison": "exact"}, "public_tests": ["[1,3,1,2]", "[5,4,6]"], "hints": ["Consider the contribution of each wizard to the answer.", "Can you efficiently calculate the total contribution to the answer for all subarrays that end at each index?", "Denote the total contribution of all subarrays ending at index i as solve[i]. Can you express solve[i] in terms of solve[m] for some m < i?"], "metadata": {"canonical_parameter_names": ["strength"], "leetcode_dataset_entry_point": "Solution().totalStrength", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:26+00:00", "tests_total": 104, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "stack", "monotonic-stack", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function totalStrength($strength) {", "container": "Solution", "callable": "totalStrength", "parameters": [{"name": "strength", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2283, "task_id": "check-if-number-has-equal-digit-count-and-digit-value", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string num of length n consisting of digits.\n\nReturn true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.\n\nExample 1:\n\nInput: num = \"1210\"\nOutput: true\nExplanation:\nnum[0] = '1'. The digit 0 occurs once in num.\nnum[1] = '2'. The digit 1 occurs twice in num.\nnum[2] = '1'. The digit 2 occurs once in num.\nnum[3] = '0'. The digit 3 occurs zero times in num.\nThe condition holds true for every index in \"1210\", so return true.\n\nExample 2:\n\nInput: num = \"030\"\nOutput: false\nExplanation:\nnum[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.\nnum[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.\nnum[2] = '0'. The digit 2 occurs zero times in num.\nThe indices 0 and 1 both violate the condition, so return false.\n\nConstraints:\n\n- n == num.length\n- 1 <= n <= 10\n- num consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"1111\") == False\n assert candidate(num = \"00000\") == False\n assert candidate(num = \"10\") == False\n assert candidate(num = \"1111111111\") == False\n assert candidate(num = \"000\") == False\n assert candidate(num = \"6200000000\") == False\n assert candidate(num = \"0100100010\") == False\n assert candidate(num = \"6210001000\") == True\n assert candidate(num = \"030\") == False\n assert candidate(num = \"9876543210\") == False\n assert candidate(num = \"2020202020\") == False\n assert candidate(num = \"0\") == False\n assert candidate(num = \"5000000000\") == False\n assert candidate(num = \"21200\") == True\n assert candidate(num = \"0987654321\") == False\n assert candidate(num = \"2020\") == True\n assert candidate(num = \"11200\") == False\n assert candidate(num = \"1010101010\") == False\n assert candidate(num = \"1210\") == True\n assert candidate(num = \"6543210\") == False\n assert candidate(num = \"50000\") == False\n assert candidate(num = \"5000001000\") == False\n assert candidate(num = \"1234567890\") == False\n assert candidate(num = \"1221111111\") == False\n assert candidate(num = \"1001\") == False\n assert candidate(num = \"0000\") == False\n assert candidate(num = \"2120000000\") == False\n assert candidate(num = \"4000400040\") == False\n assert candidate(num = \"101010101\") == False\n assert candidate(num = \"0000100000\") == False\n assert candidate(num = \"1112212100\") == False\n assert candidate(num = \"0000000000\") == False\n assert candidate(num = \"0000000100\") == False\n assert candidate(num = \"0101010101\") == False\n assert candidate(num = \"9000000000\") == False\n assert candidate(num = \"3110001000\") == False\n assert candidate(num = \"0100101010\") == False\n assert candidate(num = \"100010000\") == False\n assert candidate(num = \"000020000\") == False\n assert candidate(num = \"100201000\") == False\n assert candidate(num = \"30003\") == False\n assert candidate(num = \"1221\") == False\n assert candidate(num = \"12101000\") == False\n assert candidate(num = \"000010001\") == False\n assert candidate(num = \"3000000000\") == False\n assert candidate(num = \"0010000000\") == False\n assert candidate(num = \"0000101000\") == False\n assert candidate(num = \"3100000\") == False\n assert candidate(num = \"3000000010\") == False\n assert candidate(num = \"0100000001\") == False\n assert candidate(num = \"121010000\") == False\n assert candidate(num = \"0123400000\") == False\n assert candidate(num = \"2010000000\") == False\n assert candidate(num = \"0010000010\") == False\n assert candidate(num = \"102020100\") == False\n assert candidate(num = \"000300003\") == False\n assert candidate(num = \"500000000\") == False\n assert candidate(num = \"40000000\") == False\n assert candidate(num = \"5000011000\") == False\n assert candidate(num = \"1001001001\") == False\n assert candidate(num = \"1221100000\") == False\n assert candidate(num = \"1212121212\") == False\n assert candidate(num = \"0001000100\") == False\n assert candidate(num = \"0000000010\") == False\n assert candidate(num = \"3000100002\") == False\n assert candidate(num = \"100002000\") == False\n assert candidate(num = \"200000010\") == False\n assert candidate(num = \"0012002001\") == False\n assert candidate(num = \"13010003\") == False\n assert candidate(num = \"42101000\") == True\n assert candidate(num = \"7000000000\") == False\n assert candidate(num = \"6543210000\") == False\n assert candidate(num = \"5000001400\") == False\n assert candidate(num = \"210010010\") == False\n assert candidate(num = \"012020200\") == False\n assert candidate(num = \"0000000004\") == False\n assert candidate(num = \"000030000\") == False\n assert candidate(num = \"12101\") == False\n assert candidate(num = \"4000010000\") == False\n assert candidate(num = \"2220000000\") == False\n assert candidate(num = \"1210101010\") == False\n assert candidate(num = \"000000003\") == False\n assert candidate(num = \"0210000110\") == False\n assert candidate(num = \"1000100010\") == False\n assert candidate(num = \"100000002\") == False\n assert candidate(num = \"3000300000\") == False\n assert candidate(num = \"400001000\") == False\n assert candidate(num = \"0123456789\") == False\n assert candidate(num = \"0000001001\") == False\n assert candidate(num = \"2100100000\") == False\n assert candidate(num = \"3110000\") == False\n assert candidate(num = \"0000000020\") == False\n assert candidate(num = \"200100100\") == False\n assert candidate(num = \"1210100\") == False\n assert candidate(num = \"1020304050\") == False\n assert candidate(num = \"6000000000\") == False\n assert candidate(num = \"001010101\") == False\n assert candidate(num = \"0000000002\") == False\n assert candidate(num = \"000001011\") == False\n assert candidate(num = \"20200\") == False\n assert candidate(num = \"1111111110\") == False\n assert candidate(num = \"1300102000\") == False\n assert candidate(num = \"2020200\") == False\n assert candidate(num = \"41210000\") == False\n assert candidate(num = \"0000000009\") == False\n assert candidate(num = \"0020200\") == False\n assert candidate(num = \"200001\") == False\n assert candidate(num = \"100000101\") == False\n assert candidate(num = \"010200200\") == False\n assert candidate(num = \"1000000001\") == False\n assert candidate(num = \"0123210\") == False\n assert candidate(num = \"3000100000\") == False\n assert candidate(num = \"200000000\") == False\n assert candidate(num = \"021001001\") == False\n assert candidate(num = \"30000003\") == False\n assert candidate(num = \"300020000\") == False\n assert candidate(num = \"0000000001\") == False\n assert candidate(num = \"300000000\") == False\n assert candidate(num = \"0000000110\") == False\n assert candidate(num = \"5000000005\") == False\n assert candidate(num = \"4000000000\") == False\n assert candidate(num = \"2010011000\") == False\n assert candidate(num = \"201010101\") == False\n assert candidate(num = \"001100110\") == False\n assert candidate(num = \"1000000010\") == False\n assert candidate(num = \"0112233445\") == False\n assert candidate(num = \"5000000100\") == False\n assert candidate(num = \"0110001000\") == False\n assert candidate(num = \"3110000000\") == False\n assert candidate(num = \"100010001\") == False\n assert candidate(num = \"0000010010\") == False\n assert candidate(num = \"8000000000\") == False\n assert candidate(num = \"00001111\") == False\n assert candidate(num = \"1200100000\") == False\n assert candidate(num = \"3330000000\") == False\n assert candidate(num = \"011110000\") == False\n assert candidate(num = \"2120001000\") == False\n", "comparison": "exact"}, "public_tests": ["\"1210\"", "\"030\""], "hints": ["Count the frequency of each digit in num."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().digitCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:30+00:00", "tests_total": 150, "tests_dropped": 13, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function digitCount($num) {", "container": "Solution", "callable": "digitCount", "parameters": [{"name": "num", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2284, "task_id": "sender-with-largest-word-count", "difficulty": "Medium", "problem_description": "You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].\n\nA message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.\n\nReturn the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.\n\nNote:\n\n- Uppercase letters come before lowercase letters in lexicographical order.\n- \"Alice\" and \"alice\" are distinct.\n\nExample 1:\n\nInput: messages = [\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"], senders = [\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]\nOutput: \"Alice\"\nExplanation: Alice sends a total of 2 + 3 = 5 words.\nuserTwo sends a total of 2 words.\nuserThree sends a total of 3 words.\nSince Alice has the largest word count, we return \"Alice\".\n\nExample 2:\n\nInput: messages = [\"How is leetcode for everyone\",\"Leetcode is useful for practice\"], senders = [\"Bob\",\"Charlie\"]\nOutput: \"Charlie\"\nExplanation: Bob sends a total of 5 words.\nCharlie sends a total of 5 words.\nSince there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.\n\nConstraints:\n\n- n == messages.length == senders.length\n- 1 <= n <= 10^4\n- 1 <= messages[i].length <= 100\n- 1 <= senders[i].length <= 10\n- messages[i] consists of uppercase and lowercase English letters and ' '.\n- All the words in messages[i] are separated by a single space.\n- messages[i] does not have leading or trailing spaces.\n- senders[i] consists of uppercase and lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(messages = ['This is a test', 'Another test', 'Final test'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Hi'],senders = ['Bob']) == \"Bob\"\n assert candidate(messages = ['Short', 'Longer message indeed'],senders = ['Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['How is leetcode for everyone', 'Leetcode is useful for practice'],senders = ['Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Hi', 'Hello', 'Hey'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Hello userTwooo', 'Hi userThree', 'Wonderful day Alice', 'Nice day userThree'],senders = ['Alice', 'userTwo', 'userThree', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Short', 'Longer message indeed'],senders = ['Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['This is a test', 'Another test', 'Final test'],senders = ['Alice', 'Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Short', 'Longer message indeed'],senders = ['Charlie', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Short', 'Longer message here', 'Even longer message here'],senders = ['Zoe', 'Zoe', 'Zoe']) == \"Zoe\"\n assert candidate(messages = ['a', 'b', 'c', 'd'],senders = ['Anna', 'Bob', 'Charlie', 'David']) == \"David\"\n assert candidate(messages = ['Hello', 'Hi'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Hello World', 'Foo Bar'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Hi', 'Hello'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Equal length messages here', 'Equal length messages here', 'Equal length messages here'],senders = ['Alice', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['a a a a a a a a a a', 'b b b b b b b b b', 'c c c c c c c c', 'd d d d d d d'],senders = ['Alice', 'Bob', 'Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Hello Alice', 'Hello Bob', 'Hello Charlie', 'Hello Dave', 'Hello Eve'],senders = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']) == \"Eve\"\n assert candidate(messages = ['Short', 'Longer message with multiple words', 'Another long message that is quite lengthy'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['abc def ghi', 'jkl mno pqr', 'stu vwx yz'],senders = ['Alice', 'Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Word', 'Word Word', 'Word Word Word', 'Word Word Word Word', 'Word Word Word Word Word'],senders = ['Yankee', 'yankee', 'YANKEE', 'Yankee', 'yankee']) == \"yankee\"\n assert candidate(messages = ['a', 'b c', 'd e f', 'g h i j'],senders = ['Z', 'Y', 'X', 'W']) == \"W\"\n assert candidate(messages = ['First message', 'Second message', 'Third message', 'Fourth message'],senders = ['Dave', 'Dave', 'Eve', 'Dave']) == \"Dave\"\n assert candidate(messages = ['This is a longer message with multiple words', 'Short message', 'Another long message with several words in it'],senders = ['Charlie', 'Alice', 'Bob']) == \"Charlie\"\n assert candidate(messages = ['a', 'b', 'c', 'd', 'e', 'f'],senders = ['Z', 'Y', 'X', 'W', 'V', 'U']) == \"Z\"\n assert candidate(messages = ['Hi', 'Hello', 'Hey', 'Goodbye', 'See you later'],senders = ['Alice', 'Bob', 'Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Hello world', 'How are you doing', 'I am fine thank you', 'And you'],senders = ['Bob', 'Charlie', 'Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Many many words in this message to test the function', 'Few words'],senders = ['Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['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', 'a b c d e f g h i j k l m n o p q r s t u v w x'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Short message', 'Another short one'],senders = ['charlie', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['One two three four five', 'Six seven eight nine ten', 'Eleven twelve'],senders = ['George', 'Hannah', 'George']) == \"George\"\n assert candidate(messages = ['Hello userTwooo', 'Hi userThree', 'Wonderful day Alice', 'Nice day userThree', 'Great to see you Alice'],senders = ['Alice', 'userTwo', 'userThree', 'Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],senders = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']) == \"A\"\n assert candidate(messages = ['Short msg', 'Medium length message indeed', 'A very long message with lots of words to count accurately'],senders = ['Carol', 'Carol', 'Carol']) == \"Carol\"\n assert candidate(messages = ['Hello world', 'Python programming is fun', 'Hello again', 'Data structures and algorithms'],senders = ['Alice', 'Bob', 'Alice', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Long message to test', 'Another long message to test', 'Short'],senders = ['Charlie', 'Alice', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['One', 'Two', 'Three', 'Four', 'Five'],senders = ['Zebra', 'Zebra', 'Zebra', 'Zebra', 'Zebra']) == \"Zebra\"\n assert candidate(messages = ['One', 'Two words here', 'Three words in this message', 'Four words make a sentence'],senders = ['Anna', 'Anna', 'Anna', 'Anna']) == \"Anna\"\n assert candidate(messages = ['Quick brown fox jumps over lazy dog', 'Hello', 'Goodbye'],senders = ['Alice', 'Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Quick brown fox', 'Lazy dog', 'Uppercase LOWERCASE', 'Mixed CASE Words'],senders = ['Alex', 'Bob', 'Charlie', 'David']) == \"David\"\n assert candidate(messages = ['One', 'Two words here', 'Three words in this one', 'Four words make this message'],senders = ['Eve', 'eve', 'EVE', 'Eve']) == \"Eve\"\n assert candidate(messages = ['This is a longer message', 'Even longer message here', 'Short'],senders = ['Charlie', 'Charlie', 'Alice']) == \"Charlie\"\n assert candidate(messages = ['Short', 'Longer message to test', 'Even longer message to check the word count', 'Short again'],senders = ['Bob', 'Charlie', 'Alice', 'Charlie']) == \"Alice\"\n assert candidate(messages = ['This is a test message', 'Another test', 'Yet another message here'],senders = ['Charlie', 'Alice', 'Bob']) == \"Charlie\"\n assert candidate(messages = ['A quick brown fox jumps over the lazy dog', 'Foo bar baz'],senders = ['Dave', 'Eve']) == \"Dave\"\n assert candidate(messages = ['Equal words here', 'Equal words here'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Many words in this message to test the word count functionality', 'Another message to ensure the solution works correctly'],senders = ['Anna', 'Anna']) == \"Anna\"\n assert candidate(messages = ['Multiple words', 'Multiple words', 'Multiple words', 'Multiple words'],senders = ['Alice', 'Bob', 'Charlie', 'David']) == \"David\"\n assert candidate(messages = ['Equal words', 'Equal words'],senders = ['Anna', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Equal length message', 'Another equal length message'],senders = ['Dave', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Word', 'Word word', 'Word word word', 'Word word word word', 'Word word word word word'],senders = ['Alex', 'Alex', 'Alex', 'Brian', 'Brian']) == \"Brian\"\n assert candidate(messages = ['One', 'Two words', 'Three words here', 'Four words in this message'],senders = ['Bob', 'Charlie', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Multiple words in this message', 'Single', 'Two words'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Equal length', 'Equal length'],senders = ['Tom', 'Jerry']) == \"Tom\"\n assert candidate(messages = ['Message one', 'Message two', 'Message three', 'Message four'],senders = ['Zebra', 'Zebra', 'Zebra', 'Zebra']) == \"Zebra\"\n assert candidate(messages = ['Unique message each time', 'Another unique one'],senders = ['Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Same sender many times', 'Same sender many times', 'Same sender many times'],senders = ['Alice', 'Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Message one', 'Another message', 'Yet another message to test', 'Final message'],senders = ['Zara', 'Alice', 'Bob', 'Charlie']) == \"Bob\"\n assert candidate(messages = ['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'],senders = ['Alice', 'Bob', 'Charlie']) == \"Bob\"\n assert candidate(messages = ['Hello world', 'Foo bar baz', 'This is a test message'],senders = ['alice', 'Bob', 'alice']) == \"alice\"\n assert candidate(messages = ['Message one', 'Message two', 'Message three'],senders = ['Zach', 'Yvonne', 'Xander']) == \"Zach\"\n assert candidate(messages = ['Different sender', 'Different sender', 'Different sender', 'Different sender'],senders = ['Mike', 'Mike', 'Mike', 'Mike']) == \"Mike\"\n assert candidate(messages = ['Short', 'Medium length message', 'A very very very long message that spans several words indeed'],senders = ['Alice', 'Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['This is a longer message', 'Short', 'Another long message here'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['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'],senders = ['Alice']) == \"Alice\"\n assert candidate(messages = ['a', 'b', 'c', 'd', 'e'],senders = ['Eve', 'Eve', 'Eve', 'Eve', 'Eve']) == \"Eve\"\n assert candidate(messages = ['Equal words', 'Equal words'],senders = ['Frank', 'frank']) == \"frank\"\n assert candidate(messages = ['This is a test message', 'Another test', 'Short one'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['A quick brown fox jumps over the lazy dog', 'Lorem ipsum dolor sit amet', 'Consectetur adipiscing elit', 'Sed do eiusmod tempor incididunt'],senders = ['Sam', 'Sam', 'Sam', 'Sam']) == \"Sam\"\n assert candidate(messages = ['Equal', 'Equal Equal', 'Equal Equal Equal'],senders = ['Mickey', 'mickey', 'MICKEY']) == \"MICKEY\"\n assert candidate(messages = ['Hi Alice', 'Hello Bob', 'How are you Charlie'],senders = ['Bob', 'Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Hello world', 'Good morning', 'How are you doing'],senders = ['Charlie', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Hello world', 'How are you today', 'Hope you are well'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['abc def ghi', 'jkl mno pqr', 'stu vwx yz', 'abc def', 'ghi jkl'],senders = ['Charlie', 'Bob', 'Alice', 'Charlie', 'Alice']) == \"Charlie\"\n assert candidate(messages = ['Word', 'Word Word', 'Word Word Word', 'Word Word Word Word'],senders = ['Zeta', 'Zeta', 'zeta', 'ZETA']) == \"ZETA\"\n assert candidate(messages = ['This is a very long message to test the word count functionality', 'Short msg'],senders = ['Delta', 'delta']) == \"Delta\"\n assert candidate(messages = ['Hi there', 'Hello there', 'Hi there', 'Hello there'],senders = ['Alice', 'Bob', 'Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['A', 'B', 'C', 'D'],senders = ['Anna', 'Bob', 'Charlie', 'David']) == \"David\"\n assert candidate(messages = ['One', 'Two words', 'Three words here', 'Four words message test'],senders = ['David', 'David', 'Eve', 'Eve']) == \"Eve\"\n assert candidate(messages = ['Same length', 'Same length', 'Same length', 'Same length'],senders = ['Alice', 'Bob', 'Charlie', 'David']) == \"David\"\n assert candidate(messages = ['Quick brown fox jumps over the lazy dog', 'Lazy dog sleeps', 'Quick fox runs away'],senders = ['Dog', 'Dog', 'Fox']) == \"Dog\"\n assert candidate(messages = ['Equal words here', 'Equal words here', 'Equal words here'],senders = ['Anna', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Multiple messages here', 'Even more messages', 'And yet another message'],senders = ['Kate', 'Kate', 'Laura']) == \"Kate\"\n assert candidate(messages = ['Multiple words in this message', 'Another message with several words', 'Just a few words'],senders = ['SenderX', 'SenderX', 'SenderY']) == \"SenderX\"\n assert candidate(messages = ['Message from Alice', 'Another message from Alice', 'Yet another message from Alice', 'Final message from Alice'],senders = ['Alice', 'Alice', 'Alice', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Message one', 'Message two', 'Message three', 'Message four', 'Message five'],senders = ['Neil', 'Neil', 'Neil', 'Neil', 'Neil']) == \"Neil\"\n assert candidate(messages = ['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'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Multiple words in this message', 'Few words', 'One'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n assert candidate(messages = ['Equal length message', 'Equal length message'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['word'],senders = ['Z']) == \"Z\"\n assert candidate(messages = ['Single', 'Double words', 'Triple words here'],senders = ['Eve', 'Eve', 'Frank']) == \"Frank\"\n assert candidate(messages = ['Many words in this message to test the word count', 'Few words'],senders = ['Charlie', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Same sender multiple times', 'Same sender multiple times', 'Same sender multiple times'],senders = ['Zoe', 'Zoe', 'Zoe']) == \"Zoe\"\n assert candidate(messages = ['A B C D E', 'F G H', 'I J K L M N O'],senders = ['Dave', 'Eve', 'Frank']) == \"Frank\"\n assert candidate(messages = ['Long message with multiple words indeed', 'Another long message with multiple words indeed'],senders = ['Anna', 'Anna']) == \"Anna\"\n assert candidate(messages = ['A quick brown fox jumps over the lazy dog', 'Lorem ipsum dolor sit amet', 'Python programming'],senders = ['Alice', 'Bob', 'Charlie']) == \"Alice\"\n assert candidate(messages = ['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'],senders = ['Zachary']) == \"Zachary\"\n assert candidate(messages = ['This is a test message', 'Another message here', 'Short one'],senders = ['Alice', 'Bob', 'Charlie']) == \"Alice\"\n assert candidate(messages = ['A quick brown fox jumps over the lazy dog', 'The quick brown fox jumps over the lazy dog'],senders = ['Grace', 'grace']) == \"grace\"\n assert candidate(messages = ['Single', 'Double double', 'Triple triple triple'],senders = ['Alice', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Short message', 'Longer message here', 'Even longer message to check', 'Short again'],senders = ['Bob', 'Charlie', 'Alice', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Short one', 'Another short one'],senders = ['Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['One', 'Two words', 'Three words here'],senders = ['Zara', 'Zara', 'Zara']) == \"Zara\"\n assert candidate(messages = ['Unique words in each message', 'Unique words here too', 'More unique words'],senders = ['Zoe', 'Yasmin', 'Xander']) == \"Zoe\"\n assert candidate(messages = ['One', 'Two words', 'Three words here', 'Four words in a sentence'],senders = ['Charlie', 'Alice', 'Bob', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Hello world', 'This is a longer message', 'Another message'],senders = ['Charlie', 'Bob', 'Charlie']) == \"Bob\"\n assert candidate(messages = ['Test message', 'Test message', 'Test message', 'Test message'],senders = ['Jack', 'Jack', 'Jack', 'Jack']) == \"Jack\"\n assert candidate(messages = ['One more message', 'Yet another message', 'Final message'],senders = ['Charlie', 'Charlie', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['Hello world', 'How are you doing today', 'Fine thank you'],senders = ['Charlie', 'Alice', 'Bob']) == \"Alice\"\n assert candidate(messages = ['Hello world', 'This is a test', 'Python programming'],senders = ['Alice', 'Bob', 'Charlie']) == \"Bob\"\n assert candidate(messages = ['Single', 'Two words', 'Three word phrase', 'Four word sentence structure'],senders = ['Zebra', 'Zebra', 'Zebra', 'Zebra']) == \"Zebra\"\n assert candidate(messages = ['Hello world', 'Hello Alice', 'Hello Bob'],senders = ['Bob', 'Alice', 'Bob']) == \"Bob\"\n assert candidate(messages = ['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'],senders = ['SenderA', 'SenderB', 'SenderC']) == \"SenderC\"\n assert candidate(messages = ['Unique message', 'Unique message', 'Unique message'],senders = ['Ian', 'Ian', 'Ian']) == \"Ian\"\n assert candidate(messages = ['Message one', 'Message two', 'Message three', 'Message four'],senders = ['Anna', 'Bob', 'Charlie', 'Bob']) == \"Bob\"\n assert candidate(messages = ['Long message to increase word count significantly', 'Short'],senders = ['Charlie', 'Charlie']) == \"Charlie\"\n assert candidate(messages = ['A quick brown fox jumps over the lazy dog', 'The quick brown fox jumps over the lazy dog', 'Lazy dog'],senders = ['Alice', 'Bob', 'Alice']) == \"Alice\"\n", "comparison": "exact"}, "public_tests": ["[\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"]\n[\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]", "[\"How is leetcode for everyone\",\"Leetcode is useful for practice\"]\n[\"Bob\",\"Charlie\"]"], "hints": ["The number of words in a message is equal to the number of spaces + 1.", "Use a hash map to count the total number of words from each sender."], "metadata": {"canonical_parameter_names": ["messages", "senders"], "leetcode_dataset_entry_point": "Solution().largestWordCount", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:33+00:00", "tests_total": 117, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function largestWordCount($messages, $senders) {", "container": "Solution", "callable": "largestWordCount", "parameters": [{"name": "messages", "type": "String[]"}, {"name": "senders", "type": "String[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2285, "task_id": "maximum-total-importance-of-roads", "difficulty": "Medium", "problem_description": "You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.\n\nYou are also given a 2D integer array roads where roads[i] = [a_i, b_i] denotes that there exists a bidirectional road connecting cities a_i and b_i.\n\nYou need to assign each city with an integer value from 1 to n, where each value can only be used once. The importance of a road is then defined as the sum of the values of the two cities it connects.\n\nReturn the maximum total importance of all roads possible after assigning the values optimally.\n\nExample 1:\n\nInput: n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]\nOutput: 43\nExplanation: The figure above shows the country and the assigned values of [2,4,5,3,1].\n- The road (0,1) has an importance of 2 + 4 = 6.\n- The road (1,2) has an importance of 4 + 5 = 9.\n- The road (2,3) has an importance of 5 + 3 = 8.\n- The road (0,2) has an importance of 2 + 5 = 7.\n- The road (1,3) has an importance of 4 + 3 = 7.\n- The road (2,4) has an importance of 5 + 1 = 6.\nThe total importance of all roads is 6 + 9 + 8 + 7 + 7 + 6 = 43.\nIt can be shown that we cannot obtain a greater total importance than 43.\n\nExample 2:\n\nInput: n = 5, roads = [[0,3],[2,4],[1,3]]\nOutput: 20\nExplanation: The figure above shows the country and the assigned values of [4,3,2,5,1].\n- The road (0,3) has an importance of 4 + 5 = 9.\n- The road (2,4) has an importance of 2 + 1 = 3.\n- The road (1,3) has an importance of 3 + 5 = 8.\nThe total importance of all roads is 9 + 3 + 8 = 20.\nIt can be shown that we cannot obtain a greater total importance than 20.\n\nConstraints:\n\n- 2 <= n <= 5 * 10^4\n- 1 <= roads.length <= 5 * 10^4\n- roads[i].length == 2\n- 0 <= a_i, b_i <= n - 1\n- a_i != b_i\n- There are no duplicate roads.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,roads = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3], [2, 4]]) == 43\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]]) == 45\n assert candidate(n = 3,roads = [[0, 1], [1, 2]]) == 9\n assert candidate(n = 4,roads = [[0, 1], [0, 3], [1, 2], [2, 3]]) == 20\n assert candidate(n = 4,roads = [[0, 1], [1, 2], [2, 3]]) == 17\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [1, 2], [1, 3], [1, 4], [2, 5]]) == 53\n assert candidate(n = 5,roads = [[0, 3], [2, 4], [1, 3]]) == 20\n assert candidate(n = 20,roads = [[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], [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]]) == 947\n assert candidate(n = 7,roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 59\n assert candidate(n = 9,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 0], [6, 1], [7, 2], [8, 3]]) == 180\n assert candidate(n = 8,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0]]) == 72\n assert candidate(n = 10,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) == 165\n assert candidate(n = 12,roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 11]]) == 188\n assert candidate(n = 16,roads = [[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, 8], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14], [7, 15], [0, 4], [1, 5], [2, 6], [3, 7], [8, 12], [9, 13], [10, 14], [11, 15]]) == 541\n assert candidate(n = 10,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]]) == 123\n assert candidate(n = 10,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 8], [1, 7], [2, 6], [3, 5], [4, 0], [5, 1], [6, 2], [7, 3], [8, 4]]) == 218\n assert candidate(n = 14,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 6], [1, 7], [2, 8], [2, 9], [3, 10], [3, 11], [4, 12], [4, 13], [5, 6], [5, 7], [6, 8], [6, 9], [7, 10], [7, 11], [8, 12], [8, 13], [9, 10], [9, 11], [10, 12], [10, 13], [11, 12], [11, 13]]) == 444\n assert candidate(n = 14,roads = [[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, 6], [1, 7], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 1], [9, 2], [10, 3], [11, 4], [12, 5], [13, 6]]) == 433\n assert candidate(n = 9,roads = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4], [3, 5], [4, 6], [5, 6], [5, 7], [6, 8], [7, 8]]) == 129\n assert candidate(n = 10,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [5, 6], [6, 7], [7, 8], [8, 9]]) == 164\n assert candidate(n = 20,roads = [[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], [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, 1]]) == 950\n assert candidate(n = 12,roads = [[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]]) == 234\n assert candidate(n = 8,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 4], [1, 5], [2, 6], [3, 7]]) == 108\n assert candidate(n = 8,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 4], [3, 5], [4, 6], [5, 7]]) == 105\n assert candidate(n = 15,roads = [[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], [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]]) == 525\n assert candidate(n = 10,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]) == 160\n assert candidate(n = 9,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [4, 5], [6, 7], [7, 8]]) == 120\n assert candidate(n = 15,roads = [[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]]) == 315\n assert candidate(n = 10,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]) == 135\n assert candidate(n = 12,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 10], [6, 11], [7, 11], [8, 11], [9, 11]]) == 218\n assert candidate(n = 10,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]]) == 110\n assert candidate(n = 15,roads = [[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], [10, 14], [11, 14], [12, 14], [13, 14]]) == 425\n assert candidate(n = 7,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 4], [3, 5], [4, 6], [5, 6]]) == 83\n assert candidate(n = 10,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 222\n assert candidate(n = 15,roads = [[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], [1, 8], [2, 9], [3, 10], [4, 11], [5, 12], [6, 13], [7, 14], [8, 1], [9, 2], [10, 3], [11, 4], [12, 5], [13, 6], [14, 0]]) == 480\n assert candidate(n = 8,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 0], [6, 1], [7, 2]]) == 144\n assert candidate(n = 20,roads = [[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]]) == 420\n assert candidate(n = 7,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == 105\n assert candidate(n = 12,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9], [4, 10], [5, 10], [6, 11], [7, 11], [8, 11], [9, 11], [10, 11]]) == 237\n assert candidate(n = 15,roads = [[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]]) == 279\n assert candidate(n = 20,roads = [[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], [10, 19]]) == 516\n assert candidate(n = 9,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 7], [7, 8]]) == 107\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5]]) == 105\n assert candidate(n = 12,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [0, 11]]) == 156\n assert candidate(n = 8,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 2], [2, 4], [4, 6], [6, 0]]) == 124\n assert candidate(n = 20,roads = [[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], [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], [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, 16], [2, 17], [2, 18], [2, 19]]) == 1542\n assert candidate(n = 6,roads = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [0, 4], [1, 4], [2, 4], [3, 4], [0, 5], [1, 5], [2, 5], [3, 5], [4, 5]]) == 105\n assert candidate(n = 15,roads = [[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, 14]]) == 240\n assert candidate(n = 7,roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 6], [4, 5], [5, 6]]) == 78\n assert candidate(n = 15,roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [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]]) == 428\n assert candidate(n = 8,roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 7], [5, 7], [6, 7]]) == 101\n assert candidate(n = 15,roads = [[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, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9]]) == 345\n assert candidate(n = 8,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 0], [7, 1]]) == 144\n assert candidate(n = 9,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [0, 8], [1, 7], [2, 5], [3, 6], [4, 0]]) == 134\n assert candidate(n = 13,roads = [[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, 11], [6, 12], [7, 8], [8, 9], [9, 10]]) == 258\n assert candidate(n = 7,roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 4], [4, 5], [5, 6]]) == 78\n assert candidate(n = 20,roads = [[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, 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, 0], [19, 1]]) == 840\n assert candidate(n = 8,roads = [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7]]) == 69\n assert candidate(n = 15,roads = [[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], [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], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14]]) == 822\n assert candidate(n = 12,roads = [[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], [6, 2], [7, 3], [8, 4], [9, 5], [10, 1], [11, 0]]) == 312\n assert candidate(n = 11,roads = [[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]]) == 197\n assert candidate(n = 12,roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [0, 11], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 231\n assert candidate(n = 9,roads = [[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3], [6, 7], [7, 8], [8, 6], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8]]) == 159\n assert candidate(n = 50000,roads = [[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]]) == 1999620\n assert candidate(n = 15,roads = [[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]]) == 284\n", "comparison": "exact"}, "public_tests": ["5\n[[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]", "5\n[[0,3],[2,4],[1,3]]"], "hints": ["Consider what each city contributes to the total importance of all roads.", "Based on that, how can you sort the cities such that assigning them values in that order will yield the maximum total importance?"], "metadata": {"canonical_parameter_names": ["n", "roads"], "leetcode_dataset_entry_point": "Solution().maximumImportance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:35+00:00", "tests_total": 65, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["greedy", "graph", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maximumImportance($n, $roads) {", "container": "Solution", "callable": "maximumImportance", "parameters": [{"name": "n", "type": "Integer"}, {"name": "roads", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2287, "task_id": "rearrange-characters-to-make-target-string", "difficulty": "Easy", "problem_description": "You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.\n\nReturn the maximum number of copies of target that can be formed by taking letters from s and rearranging them.\n\nExample 1:\n\nInput: s = \"ilovecodingonleetcode\", target = \"code\"\nOutput: 2\nExplanation:\nFor the first copy of \"code\", take the letters at indices 4, 5, 6, and 7.\nFor the second copy of \"code\", take the letters at indices 17, 18, 19, and 20.\nThe strings that are formed are \"ecod\" and \"code\" which can both be rearranged into \"code\".\nWe can make at most two copies of \"code\", so we return 2.\n\nExample 2:\n\nInput: s = \"abcba\", target = \"abc\"\nOutput: 1\nExplanation:\nWe can make one copy of \"abc\" by taking the letters at indices 0, 1, and 2.\nWe can make at most one copy of \"abc\", so we return 1.\nNote that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of \"abc\".\n\nExample 3:\n\nInput: s = \"abbaccaddaeea\", target = \"aaaaa\"\nOutput: 1\nExplanation:\nWe can make one copy of \"aaaaa\" by taking the letters at indices 0, 3, 6, 9, and 12.\nWe can make at most one copy of \"aaaaa\", so we return 1.\n\nConstraints:\n\n- 1 <= s.length <= 100\n- 1 <= target.length <= 10\n- s and target consist of lowercase English letters.\n\nNote: This question is the same as 1189: Maximum Number of Balloons.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbc\",target = \"abc\") == 1\n assert candidate(s = \"aabbbccc\",target = \"abc\") == 2\n assert candidate(s = \"zzzz\",target = \"zz\") == 2\n assert candidate(s = \"abcabcabc\",target = \"abc\") == 3\n assert candidate(s = \"abcd\",target = \"abce\") == 0\n assert candidate(s = \"abbaccaddaeea\",target = \"aaaaa\") == 1\n assert candidate(s = \"aabbbcc\",target = \"abc\") == 2\n assert candidate(s = \"ilovecodingonleetcode\",target = \"code\") == 2\n assert candidate(s = \"aabbccddeeffgghh\",target = \"abcdefgh\") == 2\n assert candidate(s = \"aabbcc\",target = \"abc\") == 2\n assert candidate(s = \"zzzz\",target = \"zzz\") == 1\n assert candidate(s = \"a\",target = \"a\") == 1\n assert candidate(s = \"abcccccc\",target = \"cat\") == 0\n assert candidate(s = \"aaabbbccc\",target = \"abc\") == 3\n assert candidate(s = \"abcd\",target = \"e\") == 0\n assert candidate(s = \"abcd\",target = \"abcd\") == 1\n assert candidate(s = \"aaaaa\",target = \"a\") == 5\n assert candidate(s = \"abababab\",target = \"abab\") == 2\n assert candidate(s = \"aaa\",target = \"a\") == 3\n assert candidate(s = \"aaaaaaaaaa\",target = \"aa\") == 5\n assert candidate(s = \"pqr\",target = \"ppp\") == 0\n assert candidate(s = \"aaaabbbbcccc\",target = \"abc\") == 4\n assert candidate(s = \"leetcode\",target = \"leet\") == 1\n assert candidate(s = \"abcba\",target = \"abc\") == 1\n assert candidate(s = \"xyz\",target = \"xyzy\") == 0\n assert candidate(s = \"xyz\",target = \"zyx\") == 1\n assert candidate(s = \"programming\",target = \"gram\") == 1\n assert candidate(s = \"ababababababababababab\",target = \"baba\") == 5\n assert candidate(s = \"bbbaaaccdddeefff\",target = \"abcde\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",target = \"zzzz\") == 10\n assert candidate(s = \"elevenletters\",target = \"eleven\") == 1\n assert candidate(s = \"ppppppppppppppp\",target = \"pppp\") == 3\n assert candidate(s = \"programmingproblems\",target = \"problem\") == 1\n assert candidate(s = \"characterscharacters\",target = \"characters\") == 2\n assert candidate(s = \"hellokitty\",target = \"hello\") == 1\n assert candidate(s = \"repeatedcharacters\",target = \"repeat\") == 1\n assert candidate(s = \"abcdabcdabcdabcdabcd\",target = \"abcdabcd\") == 2\n assert candidate(s = \"ppppqqqqrrrsssss\",target = \"pqrs\") == 3\n assert candidate(s = \"xyzxyzxyz\",target = \"xyz\") == 3\n assert candidate(s = \"thisisjustaword\",target = \"word\") == 1\n assert candidate(s = \"bananaananan\",target = \"ana\") == 3\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",target = \"zzzz\") == 8\n assert candidate(s = \"xxxxxyyyyyzzzzzwwwwwvvvvv\",target = \"xyzzwv\") == 2\n assert candidate(s = \"ppqpqqppqppqqqqqqq\",target = \"ppqq\") == 3\n assert candidate(s = \"aabcccccaaa\",target = \"abc\") == 1\n assert candidate(s = \"xyzzyxzyzyzxzyxzy\",target = \"zyx\") == 4\n assert candidate(s = \"pppppppppppppppppppppppppppppppppppppppppppppppppppp\",target = \"p\") == 52\n assert candidate(s = \"quickbrownfox\",target = \"quick\") == 1\n assert candidate(s = \"abracadabra\",target = \"abrac\") == 1\n assert candidate(s = \"aaabbbcccddd\",target = \"abcd\") == 3\n assert candidate(s = \"jumpoverthelazydog\",target = \"dogjump\") == 1\n assert candidate(s = \"xyxxyxyxyxyx\",target = \"xyx\") == 3\n assert candidate(s = \"bananana\",target = \"banana\") == 1\n assert candidate(s = \"supercalifragilisticexpialidocious\",target = \"super\") == 2\n assert candidate(s = \"programmingisfun\",target = \"fun\") == 1\n assert candidate(s = \"rearrangerearrangerearrange\",target = \"range\") == 3\n assert candidate(s = \"aaabbbccc\",target = \"abcabc\") == 1\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",target = \"a\") == 91\n assert candidate(s = \"aabbbcccdddeeefff\",target = \"abcdef\") == 2\n assert candidate(s = \"abacabadabacaba\",target = \"abc\") == 2\n assert candidate(s = \"mississippi\",target = \"issi\") == 2\n assert candidate(s = \"babbbababbaba\",target = \"bab\") == 4\n assert candidate(s = \"abacabadabacaba\",target = \"abac\") == 2\n assert candidate(s = \"aabbaabbaabb\",target = \"aabb\") == 3\n assert candidate(s = \"nfaivnfainfainfainfainfafinainfnainfaianfaianfaianfaianfaianfaianfaianfaianfaianfaianfai\",target = \"nfa\") == 19\n assert candidate(s = \"abcdefgabcdefgabcdefg\",target = \"abcdefg\") == 3\n assert candidate(s = \"qpwoeirutyalskdjfhgmznxbcv\",target = \"qwerty\") == 1\n assert candidate(s = \"everygoodboydoesfine\",target = \"every\") == 1\n assert candidate(s = \"aabbcc\",target = \"abcabc\") == 1\n assert candidate(s = \"aabbbccddeeefff\",target = \"abcdef\") == 2\n assert candidate(s = \"xyxxyxyxyx\",target = \"xyx\") == 3\n assert candidate(s = \"aabbcc\",target = \"aab\") == 1\n assert candidate(s = \"xzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzy\",target = \"zyx\") == 23\n assert candidate(s = \"aabbcdeffgghhiijk\",target = \"abcdefghij\") == 1\n assert candidate(s = \"wassupwassupwassup\",target = \"wassup\") == 3\n assert candidate(s = \"abracadabra\",target = \"abra\") == 2\n assert candidate(s = \"xyzxyzxyzxyzxyz\",target = \"xyzxyz\") == 2\n assert candidate(s = \"testtesttesttest\",target = \"test\") == 4\n assert candidate(s = \"rearrangerearrange\",target = \"rearrange\") == 2\n assert candidate(s = \"optimization\",target = \"on\") == 1\n assert candidate(s = \"aaaaaaaaaaa\",target = \"aaaaa\") == 2\n assert candidate(s = \"qqwweerrttyyuuiiooppllaa\",target = \"typewriter\") == 1\n assert candidate(s = \"balloonballoonballoon\",target = \"balloon\") == 3\n assert candidate(s = \"nnnoooiii\",target = \"noon\") == 1\n assert candidate(s = \"abracadabra\",target = \"cab\") == 1\n assert candidate(s = \"xyzxyzxyzxyzxyzxyz\",target = \"xyz\") == 6\n assert candidate(s = \"xylophonephonexylo\",target = \"xylo\") == 2\n assert candidate(s = \"abcabcabcabcabc\",target = \"abcabc\") == 2\n assert candidate(s = \"babababababababab\",target = \"abba\") == 4\n assert candidate(s = \"abcabcabcabcabc\",target = \"ab\") == 5\n assert candidate(s = \"aaaabbbbccccdddd\",target = \"abcd\") == 4\n assert candidate(s = \"rearrangecharacters\",target = \"char\") == 1\n assert candidate(s = \"elephantelephant\",target = \"elephant\") == 2\n assert candidate(s = \"fifteenlettersfifteenletters\",target = \"fifteen\") == 2\n assert candidate(s = \"thisthisthisthisthisthisisthisthisthisthisthis\",target = \"this\") == 11\n assert candidate(s = \"supercalifragilisticexpialidocious\",target = \"supercali\") == 2\n assert candidate(s = \"mississippi\",target = \"issip\") == 2\n assert candidate(s = \"aabbccddeeff\",target = \"abcdef\") == 2\n assert candidate(s = \"babababa\",target = \"ba\") == 4\n assert candidate(s = \"abcdabcdabcdabcdabcd\",target = \"abcd\") == 5\n assert candidate(s = \"xylophone\",target = \"xyl\") == 1\n assert candidate(s = \"abcdabcdabcd\",target = \"abcd\") == 3\n assert candidate(s = \"thisisaverylongstringwithmanylettersinittomakeitmorechallengingtotest\",target = \"thisis\") == 2\n assert candidate(s = \"balloonballoon\",target = \"balloon\") == 2\n assert candidate(s = \"packmyboxwithfivedozenliquorjugs\",target = \"boxwith\") == 1\n assert candidate(s = \"bananaapple\",target = \"ana\") == 2\n assert candidate(s = \"qwerqwerqwerqwer\",target = \"qwerqwer\") == 2\n assert candidate(s = \"thefiveboxingwizardsjumpquickly\",target = \"jump\") == 1\n assert candidate(s = \"algorithmsarecool\",target = \"cool\") == 1\n assert candidate(s = \"exampleexampleexampleexampleexampleexample\",target = \"example\") == 6\n assert candidate(s = \"xylophone\",target = \"phonex\") == 1\n assert candidate(s = \"thisisaverylongstringthatyoumightfindchallengingtorearrange\",target = \"string\") == 3\n assert candidate(s = \"bananaananabanananana\",target = \"nana\") == 4\n assert candidate(s = \"hellohellohellohello\",target = \"hello\") == 4\n assert candidate(s = \"abracadabra\",target = \"abraca\") == 1\n assert candidate(s = \"hellohellohello\",target = \"hello\") == 3\n", "comparison": "exact"}, "public_tests": ["\"ilovecodingonleetcode\"\n\"code\"", "\"abcba\"\n\"abc\"", "\"abbaccaddaeea\"\n\"aaaaa\""], "hints": ["Count the frequency of each character in s and target.", "Consider each letter one at a time. If there are x occurrences of a letter in s and y occurrences of the same letter in target, how many copies of this letter can we make?", "We can make floor(x / y) copies of the letter."], "metadata": {"canonical_parameter_names": ["s", "target"], "leetcode_dataset_entry_point": "Solution().rearrangeCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:37+00:00", "tests_total": 129, "tests_dropped": 13, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function rearrangeCharacters($s, $target) {", "container": "Solution", "callable": "rearrangeCharacters", "parameters": [{"name": "s", "type": "String"}, {"name": "target", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2288, "task_id": "apply-discount-to-prices", "difficulty": "Medium", "problem_description": "A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign.\n\n- For example, \"$100\", \"$23\", and \"$6\" represent prices while \"100\", \"$\", and \"$1e5\" do not.\n\nYou are given a string sentence representing a sentence and an integer discount. For each word representing a price, apply a discount of discount% on the price and update the word in the sentence. All updated prices should be represented with exactly two decimal places.\n\nReturn a string representing the modified sentence.\n\nNote that all prices will contain at most 10 digits.\n\nExample 1:\n\nInput: sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50\nOutput: \"there are $0.50 $1.00 and 5$ candies in the shop\"\nExplanation:\nThe words which represent prices are \"$1\" and \"$2\".\n- A 50% discount on \"$1\" yields \"$0.50\", so \"$1\" is replaced by \"$0.50\".\n- A 50% discount on \"$2\" yields \"$1\". Since we need to have exactly 2 decimal places after a price, we replace \"$2\" with \"$1.00\".\n\nExample 2:\n\nInput: sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100\nOutput: \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\"\nExplanation:\nApplying a 100% discount on any price will result in 0.\nThe words representing prices are \"$3\", \"$5\", \"$6\", and \"$9\".\nEach of them is replaced by \"$0.00\".\n\nConstraints:\n\n- 1 <= sentence.length <= 10^5\n- sentence consists of lowercase English letters, digits, ' ', and '$'.\n- sentence does not have leading or trailing spaces.\n- All words in sentence are separated by a single space.\n- All prices will be positive numbers without leading zeros.\n- All prices will have at most 10 digits.\n- 0 <= discount <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentence = \"$10 $20 $30 $40 $50\",discount = 0) == \"$10.00 $20.00 $30.00 $40.00 $50.00\"\n assert candidate(sentence = \"$100 $200 $300\",discount = 25) == \"$75.00 $150.00 $225.00\"\n assert candidate(sentence = \"no prices here\",discount = 20) == \"no prices here\"\n assert candidate(sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\",discount = 100) == \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\"\n assert candidate(sentence = \"there are $1 $2 and 5$ candies in the shop\",discount = 50) == \"there are $0.50 $1.00 and 5$ candies in the shop\"\n assert candidate(sentence = \"no prices here\",discount = 10) == \"no prices here\"\n assert candidate(sentence = \"$9999999999 $1\",discount = 99) == \"$99999999.99 $0.01\"\n assert candidate(sentence = \"$9999999999 $10000000000 $11111111111\",discount = 10) == \"$8999999999.10 $9000000000.00 $9999999999.90\"\n assert candidate(sentence = \"$999 $888 $777 $666 $555 $444 $333 $222 $111 $000\",discount = 90) == \"$99.90 $88.80 $77.70 $66.60 $55.50 $44.40 $33.30 $22.20 $11.10 $0.00\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000\",discount = 15) == \"$85.00 $170.00 $255.00 $340.00 $425.00 $510.00 $595.00 $680.00 $765.00 $850.00\"\n assert candidate(sentence = \"$0 $00 $000 $0000 $00000\",discount = 100) == \"$0.00 $0.00 $0.00 $0.00 $0.00\"\n assert candidate(sentence = \"$1000000000 $999999999 $1111111111 $2222222222 $3333333333\",discount = 75) == \"$250000000.00 $249999999.75 $277777777.75 $555555555.50 $833333333.25\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $0\",discount = 75) == \"$0.25 $0.50 $0.75 $1.00 $1.25 $1.50 $1.75 $2.00 $2.25 $0.00\"\n assert candidate(sentence = \"$123456 $654321 $111111 $222222\",discount = 75) == \"$30864.00 $163580.25 $27777.75 $55555.50\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10\",discount = 20) == \"$0.80 $1.60 $2.40 $3.20 $4.00 $4.80 $5.60 $6.40 $7.20 $8.00\"\n assert candidate(sentence = \"$0 $1 $2 $3 $4 $5 $6 $7 $8 $9\",discount = 10) == \"$0.00 $0.90 $1.80 $2.70 $3.60 $4.50 $5.40 $6.30 $7.20 $8.10\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000 $1100 $1200 $1300 $1400 $1500\",discount = 10) == \"$90.00 $180.00 $270.00 $360.00 $450.00 $540.00 $630.00 $720.00 $810.00 $900.00 $990.00 $1080.00 $1170.00 $1260.00 $1350.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100\",discount = 100) == \"$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00\"\n assert candidate(sentence = \"$999999999 $111111111 $222222222 $333333333 $444444444\",discount = 90) == \"$99999999.90 $11111111.10 $22222222.20 $33333333.30 $44444444.40\"\n assert candidate(sentence = \"$1000000000 $999999999 $888888888 $777777777 $666666666 $555555555 $444444444 $333333333 $222222222 $111111111\",discount = 1) == \"$990000000.00 $989999999.01 $879999999.12 $769999999.23 $659999999.34 $549999999.45 $439999999.56 $329999999.67 $219999999.78 $109999999.89\"\n assert candidate(sentence = \"$12345678901234567890 $98765432109876543210 $10000000001000000000\",discount = 50) == \"$6172839450617283584.00 $49382716054938271744.00 $5000000000499999744.00\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000\",discount = 99) == \"$1.00 $2.00 $3.00 $4.00 $5.00 $6.00 $7.00 $8.00 $9.00 $10.00\"\n assert candidate(sentence = \"$9999999999 this is a very long sentence with many $100 prices $500 and $1000\",discount = 20) == \"$7999999999.20 this is a very long sentence with many $80.00 prices $400.00 and $800.00\"\n assert candidate(sentence = \"$1million $1billion $1trillion\",discount = 50) == \"$1million $1billion $1trillion\"\n assert candidate(sentence = \"$1000000 $2000000 $3000000 $4000000\",discount = 30) == \"$700000.00 $1400000.00 $2100000.00 $2800000.00\"\n assert candidate(sentence = \"$500 $1000 $1500 $2000\",discount = 20) == \"$400.00 $800.00 $1200.00 $1600.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 10) == \"$0.90 $1.80 $2.70 $3.60 $4.50 $5.40 $6.30 $7.20 $8.10 $9.00 $9.90 $10.80 $11.70 $12.60 $13.50 $14.40 $15.30 $16.20 $17.10 $18.00\"\n assert candidate(sentence = \"$9999999999 $1000000000 $123456789\",discount = 5) == \"$9499999999.05 $950000000.00 $117283949.55\"\n assert candidate(sentence = \"$999999999 $888888888 $777777777 $666666666 $555555555\",discount = 20) == \"$799999999.20 $711111110.40 $622222221.60 $533333332.80 $444444444.00\"\n assert candidate(sentence = \"$1234567890 $123456789 $12345678 $1234567 $123456 $12345 $1234 $123 $12 $1\",discount = 10) == \"$1111111101.00 $111111110.10 $11111110.20 $1111110.30 $111110.40 $11110.50 $1110.60 $110.70 $10.80 $0.90\"\n assert candidate(sentence = \"$1 $10 $100 $1000 $10000 $100000 $1000000 $10000000 $100000000 $1000000000\",discount = 99) == \"$0.01 $0.10 $1.00 $10.00 $100.00 $1000.00 $10000.00 $100000.00 $1000000.00 $10000000.00\"\n assert candidate(sentence = \"$12345 $67890 $54321 $98760 $13579 $24680\",discount = 30) == \"$8641.50 $47523.00 $38024.70 $69132.00 $9505.30 $17276.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 95) == \"$0.05 $0.10 $0.15 $0.20 $0.25 $0.30 $0.35 $0.40 $0.45 $0.50 $0.55 $0.60 $0.65 $0.70 $0.75 $0.80 $0.85 $0.90 $0.95 $1.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100\",discount = 5) == \"$9.50 $19.00 $28.50 $38.00 $47.50 $57.00 $66.50 $76.00 $85.50 $95.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100\",discount = 20) == \"$8.00 $16.00 $24.00 $32.00 $40.00 $48.00 $56.00 $64.00 $72.00 $80.00\"\n assert candidate(sentence = \"$9999999999\",discount = 1) == \"$9899999999.01\"\n assert candidate(sentence = \"$100abc $abc100 $100$ $100 $200\",discount = 10) == \"$100abc $abc100 $100$ $90.00 $180.00\"\n assert candidate(sentence = \"$9999999999 is the max price and $1 is the min price in this sentence\",discount = 5) == \"$9499999999.05 is the max price and $0.95 is the min price in this sentence\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $0\",discount = 50) == \"$0.50 $1.00 $1.50 $2.00 $2.50 $3.00 $3.50 $4.00 $4.50 $0.00 $0.50 $1.00 $1.50 $2.00 $2.50 $3.00 $3.50 $4.00 $4.50 $0.00\"\n assert candidate(sentence = \"$10000000000 $20000000000 $30000000000\",discount = 50) == \"$5000000000.00 $10000000000.00 $15000000000.00\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000 $1100 $1200 $1300 $1400 $1500 $1600 $1700 $1800 $1900 $2000\",discount = 75) == \"$25.00 $50.00 $75.00 $100.00 $125.00 $150.00 $175.00 $200.00 $225.00 $250.00 $275.00 $300.00 $325.00 $350.00 $375.00 $400.00 $425.00 $450.00 $475.00 $500.00\"\n assert candidate(sentence = \"$12345 $67890 $54321 $98765 $13579 $24680\",discount = 30) == \"$8641.50 $47523.00 $38024.70 $69135.50 $9505.30 $17276.00\"\n assert candidate(sentence = \"$0\",discount = 100) == \"$0.00\"\n assert candidate(sentence = \"$1234567890 $987654321 $1000000000\",discount = 10) == \"$1111111101.00 $888888888.90 $900000000.00\"\n assert candidate(sentence = \"$9 $99 $999 $9999 $99999 $999999 $9999999 $99999999 $999999999 $9999999999\",discount = 90) == \"$0.90 $9.90 $99.90 $999.90 $9999.90 $99999.90 $999999.90 $9999999.90 $99999999.90 $999999999.90\"\n assert candidate(sentence = \"$1234567890 $9876543210 $1111111111 $2222222222 $3333333333 $4444444444 $5555555555 $6666666666 $7777777777 $8888888888\",discount = 10) == \"$1111111101.00 $8888888889.00 $999999999.90 $1999999999.80 $2999999999.70 $3999999999.60 $4999999999.50 $5999999999.40 $6999999999.30 $7999999999.20\"\n assert candidate(sentence = \"$9999999999 $1000000000 $123456789\",discount = 10) == \"$8999999999.10 $900000000.00 $111111110.10\"\n assert candidate(sentence = \"$1000000 $2000000 $3000000 $4000000 $5000000\",discount = 0) == \"$1000000.00 $2000000.00 $3000000.00 $4000000.00 $5000000.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100\",discount = 0) == \"$10.00 $20.00 $30.00 $40.00 $50.00 $60.00 $70.00 $80.00 $90.00 $100.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100 $110 $120 $130 $140 $150\",discount = 30) == \"$7.00 $14.00 $21.00 $28.00 $35.00 $42.00 $49.00 $56.00 $63.00 $70.00 $77.00 $84.00 $91.00 $98.00 $105.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 99) == \"$0.01 $0.02 $0.03 $0.04 $0.05 $0.06 $0.07 $0.08 $0.09 $0.10 $0.11 $0.12 $0.13 $0.14 $0.15 $0.16 $0.17 $0.18 $0.19 $0.20\"\n assert candidate(sentence = \"$1000 $2000 $3000\",discount = 95) == \"$50.00 $100.00 $150.00\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777 $6666666666 $5555555555\",discount = 0) == \"$9999999999.00 $8888888888.00 $7777777777.00 $6666666666.00 $5555555555.00\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000\",discount = 0) == \"$100.00 $200.00 $300.00 $400.00 $500.00 $600.00 $700.00 $800.00 $900.00 $1000.00\"\n assert candidate(sentence = \"$1000000000 $999999999 $888888888 $777777777 $666666666 $555555555 $444444444 $333333333 $222222222 $111111111\",discount = 15) == \"$850000000.00 $849999999.15 $755555554.80 $661111110.45 $566666666.10 $472222221.75 $377777777.40 $283333333.05 $188888888.70 $94444444.35\"\n assert candidate(sentence = \"$100000 $200000 $300000 $400000 $500000\",discount = 20) == \"$80000.00 $160000.00 $240000.00 $320000.00 $400000.00\"\n assert candidate(sentence = \"$123abc $456def $789ghi $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 15) == \"$123abc $456def $789ghi $0.00 $0.85 $1.70 $2.55 $3.40 $4.25 $5.10 $5.95 $6.80 $7.65 $8.50 $9.35 $10.20 $11.05 $11.90 $12.75 $13.60 $14.45 $15.30 $16.15 $17.00\"\n assert candidate(sentence = \"$9999999999 $1000000000 $100000000 $10000000 $1000000 $100000 $10000 $1000 $100 $10 $1\",discount = 5) == \"$9499999999.05 $950000000.00 $95000000.00 $9500000.00 $950000.00 $95000.00 $9500.00 $950.00 $95.00 $9.50 $0.95\"\n assert candidate(sentence = \"$123 $456 $789 $012 $345 $678 $901 $234 $567 $890 $123456789 $987654321 $111111111 $222222222 $333333333 $444444444 $555555555 $666666666 $777777777 $888888888 $999999999 $1000000000 $2000000000 $3000000000\",discount = 30) == \"$86.10 $319.20 $552.30 $8.40 $241.50 $474.60 $630.70 $163.80 $396.90 $623.00 $86419752.30 $691358024.70 $77777777.70 $155555555.40 $233333333.10 $311111110.80 $388888888.50 $466666666.20 $544444443.90 $622222221.60 $699999999.30 $700000000.00 $1400000000.00 $2100000000.00\"\n assert candidate(sentence = \"$5 $15 $25 $35 $45 $55 $65 $75 $85 $95\",discount = 75) == \"$1.25 $3.75 $6.25 $8.75 $11.25 $13.75 $16.25 $18.75 $21.25 $23.75\"\n assert candidate(sentence = \"$50 apples $20 oranges $30 bananas $10 grapes\",discount = 30) == \"$35.00 apples $14.00 oranges $21.00 bananas $7.00 grapes\"\n assert candidate(sentence = \"$9999999999 $123456789 $9876543210 $1000000000 $500000000\",discount = 15) == \"$8499999999.15 $104938270.65 $8395061728.50 $850000000.00 $425000000.00\"\n assert candidate(sentence = \"$0 $00 $000 $0000 $00000\",discount = 20) == \"$0.00 $0.00 $0.00 $0.00 $0.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15\",discount = 0) == \"$1.00 $2.00 $3.00 $4.00 $5.00 $6.00 $7.00 $8.00 $9.00 $10.00 $11.00 $12.00 $13.00 $14.00 $15.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10\",discount = 5) == \"$0.95 $1.90 $2.85 $3.80 $4.75 $5.70 $6.65 $7.60 $8.55 $9.50\"\n assert candidate(sentence = \"$1234567890 $9876543210 $1000000000\",discount = 5) == \"$1172839495.50 $9382716049.50 $950000000.00\"\n assert candidate(sentence = \"$1000000000 $999999999 $888888888 $777777777\",discount = 50) == \"$500000000.00 $499999999.50 $444444444.00 $388888888.50\"\n assert candidate(sentence = \"$1234567890 $9876543210 $1000000000\",discount = 15) == \"$1049382706.50 $8395061728.50 $850000000.00\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777 $6666666666 $5555555555 $4444444444 $3333333333 $2222222222 $1111111111 $1\",discount = 99) == \"$99999999.99 $88888888.88 $77777777.77 $66666666.66 $55555555.55 $44444444.44 $33333333.33 $22222222.22 $11111111.11 $0.01\"\n assert candidate(sentence = \"$123 $456 $789 $101112 $131415 $161718 $192021 $222324 $252627 $282930\",discount = 25) == \"$92.25 $342.00 $591.75 $75834.00 $98561.25 $121288.50 $144015.75 $166743.00 $189470.25 $212197.50\"\n assert candidate(sentence = \"$1000 $2000 $3000 $4000 $5000 $6000 $7000 $8000 $9000 $10000\",discount = 75) == \"$250.00 $500.00 $750.00 $1000.00 $1250.00 $1500.00 $1750.00 $2000.00 $2250.00 $2500.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 50) == \"$0.50 $1.00 $1.50 $2.00 $2.50 $3.00 $3.50 $4.00 $4.50 $5.00 $5.50 $6.00 $6.50 $7.00 $7.50 $8.00 $8.50 $9.00 $9.50 $10.00\"\n assert candidate(sentence = \"$100 $200 $300 $400 $500 $600 $700 $800 $900 $1000\",discount = 20) == \"$80.00 $160.00 $240.00 $320.00 $400.00 $480.00 $560.00 $640.00 $720.00 $800.00\"\n assert candidate(sentence = \"$999999999 $888888888 $777777777 $666666666 $555555555\",discount = 30) == \"$699999999.30 $622222221.60 $544444443.90 $466666666.20 $388888888.50\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777\",discount = 5) == \"$9499999999.05 $8444444443.60 $7388888888.15\"\n assert candidate(sentence = \"$1000000000 $100000000 $10000000 $1000000 $100000 $10000 $1000 $100 $10 $1\",discount = 5) == \"$950000000.00 $95000000.00 $9500000.00 $950000.00 $95000.00 $9500.00 $950.00 $95.00 $9.50 $0.95\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 15) == \"$0.85 $1.70 $2.55 $3.40 $4.25 $5.10 $5.95 $6.80 $7.65 $8.50 $9.35 $10.20 $11.05 $11.90 $12.75 $13.60 $14.45 $15.30 $16.15 $17.00\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777 $6666666666 $5555555555 $4444444444 $3333333333 $2222222222 $1111111111 $1000000000 $999999999 $888888888 $777777777 $666666666 $555555555 $444444444 $333333333 $222222222 $111111111 $100000000 $99999999 $88888888 $77777777 $66666666 $55555555 $44444444 $33333333 $22222222 $11111111 $10000000 $9999999 $8888888 $7777777 $6666666 $5555555 $4444444 $3333333 $2222222 $1111111 $1000000 $999999 $888888 $777777 $666666 $555555 $444444 $333333 $222222 $111111 $100000 $99999 $88888 $77777 $66666 $55555 $44444 $33333 $22222 $11111 $10000 $9999 $8888 $7777 $6666 $5555 $4444 $3333 $2222 $1111 $1000 $999 $888 $777 $666 $555 $444 $333 $222 $111 $100 $99 $88 $77 $66 $55 $44 $33 $22 $11 $1\",discount = 10) == \"$8999999999.10 $7999999999.20 $6999999999.30 $5999999999.40 $4999999999.50 $3999999999.60 $2999999999.70 $1999999999.80 $999999999.90 $900000000.00 $899999999.10 $799999999.20 $699999999.30 $599999999.40 $499999999.50 $399999999.60 $299999999.70 $199999999.80 $99999999.90 $90000000.00 $89999999.10 $79999999.20 $69999999.30 $59999999.40 $49999999.50 $39999999.60 $29999999.70 $19999999.80 $9999999.90 $9000000.00 $8999999.10 $7999999.20 $6999999.30 $5999999.40 $4999999.50 $3999999.60 $2999999.70 $1999999.80 $999999.90 $900000.00 $899999.10 $799999.20 $699999.30 $599999.40 $499999.50 $399999.60 $299999.70 $199999.80 $99999.90 $90000.00 $89999.10 $79999.20 $69999.30 $59999.40 $49999.50 $39999.60 $29999.70 $19999.80 $9999.90 $9000.00 $8999.10 $7999.20 $6999.30 $5999.40 $4999.50 $3999.60 $2999.70 $1999.80 $999.90 $900.00 $899.10 $799.20 $699.30 $599.40 $499.50 $399.60 $299.70 $199.80 $99.90 $90.00 $89.10 $79.20 $69.30 $59.40 $49.50 $39.60 $29.70 $19.80 $9.90 $0.90\"\n assert candidate(sentence = \"$100 abc $200 def $300 ghi $400 jkl $500 mno\",discount = 75) == \"$25.00 abc $50.00 def $75.00 ghi $100.00 jkl $125.00 mno\"\n assert candidate(sentence = \"$1234 $5678 $91011 $121314 $151617 $181920 $212223 $242526 $272829 $303132\",discount = 20) == \"$987.20 $4542.40 $72808.80 $97051.20 $121293.60 $145536.00 $169778.40 $194020.80 $218263.20 $242505.60\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20 $21 $22 $23 $24 $25 $26 $27 $28 $29 $30\",discount = 100) == \"$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00\"\n assert candidate(sentence = \"$1234567890 $987654321 $1000000000 $500000000 $250000000 $125000000 $62500000 $31250000 $15625000 $7812500 $3906250 $1953125 $976562 $488281 $244140 $122070 $61035 $30517 $15258 $7629 $3814 $1907 $953 $476 $238 $119 $59 $29 $14 $7 $3 $1\",discount = 10) == \"$1111111101.00 $888888888.90 $900000000.00 $450000000.00 $225000000.00 $112500000.00 $56250000.00 $28125000.00 $14062500.00 $7031250.00 $3515625.00 $1757812.50 $878905.80 $439452.90 $219726.00 $109863.00 $54931.50 $27465.30 $13732.20 $6866.10 $3432.60 $1716.30 $857.70 $428.40 $214.20 $107.10 $53.10 $26.10 $12.60 $6.30 $2.70 $0.90\"\n assert candidate(sentence = \"$123 $456 $789 $1011 $1213 $1415 $1617 $1819 $2021 $2223 $2425 $2627 $2829 $3031 $3233\",discount = 25) == \"$92.25 $342.00 $591.75 $758.25 $909.75 $1061.25 $1212.75 $1364.25 $1515.75 $1667.25 $1818.75 $1970.25 $2121.75 $2273.25 $2424.75\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10\",discount = 90) == \"$0.10 $0.20 $0.30 $0.40 $0.50 $0.60 $0.70 $0.80 $0.90 $1.00\"\n assert candidate(sentence = \"$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15\",discount = 5) == \"$0.95 $1.90 $2.85 $3.80 $4.75 $5.70 $6.65 $7.60 $8.55 $9.50 $10.45 $11.40 $12.35 $13.30 $14.25\"\n assert candidate(sentence = \"$9 $8 $7 $6 $5 $4 $3 $2 $1 $0\",discount = 100) == \"$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00\"\n assert candidate(sentence = \"$123 $456 $789 $101112 $131415 $161718\",discount = 75) == \"$30.75 $114.00 $197.25 $25278.00 $32853.75 $40429.50\"\n assert candidate(sentence = \"$1 $10 $100 $1000 $10000 $100000 $1000000 $10000000 $100000000 $1000000000\",discount = 50) == \"$0.50 $5.00 $50.00 $500.00 $5000.00 $50000.00 $500000.00 $5000000.00 $50000000.00 $500000000.00\"\n assert candidate(sentence = \"$10 $20 $30 $40 $50 $60 $70 $80 $90 $100 $110 $120 $130 $140 $150\",discount = 75) == \"$2.50 $5.00 $7.50 $10.00 $12.50 $15.00 $17.50 $20.00 $22.50 $25.00 $27.50 $30.00 $32.50 $35.00 $37.50\"\n assert candidate(sentence = \"$1000000000 this is a test with one big $9999999999 price and a small $1\",discount = 1) == \"$990000000.00 this is a test with one big $9899999999.01 price and a small $0.99\"\n assert candidate(sentence = \"$0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10\",discount = 50) == \"$0.00 $0.50 $1.00 $1.50 $2.00 $2.50 $3.00 $3.50 $4.00 $4.50 $5.00\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777 $6666666666 $5555555555\",discount = 1) == \"$9899999999.01 $8799999999.12 $7699999999.23 $6599999999.34 $5499999999.45\"\n assert candidate(sentence = \"$1 $10 $100 $1000 $10000 $100000 $1000000 $10000000 $100000000 $1000000000 $10000000000\",discount = 5) == \"$0.95 $9.50 $95.00 $950.00 $9500.00 $95000.00 $950000.00 $9500000.00 $95000000.00 $950000000.00 $9500000000.00\"\n assert candidate(sentence = \"$9999999999 $8888888888 $7777777777 $6666666666 $5555555555 $4444444444 $3333333333 $2222222222 $1111111111 $1000000000\",discount = 50) == \"$4999999999.50 $4444444444.00 $3888888888.50 $3333333333.00 $2777777777.50 $2222222222.00 $1666666666.50 $1111111111.00 $555555555.50 $500000000.00\"\n assert candidate(sentence = \"$9999999999 $999999999 $99999999 $9999999 $999999 $99999 $9999 $999 $99 $9\",discount = 0) == \"$9999999999.00 $999999999.00 $99999999.00 $9999999.00 $999999.00 $99999.00 $9999.00 $999.00 $99.00 $9.00\"\n assert candidate(sentence = \"$999999999 $888888888 $777777777 $666666666 $555555555 $444444444 $333333333 $222222222 $111111111 $1\",discount = 50) == \"$499999999.50 $444444444.00 $388888888.50 $333333333.00 $277777777.50 $222222222.00 $166666666.50 $111111111.00 $55555555.50 $0.50\"\n assert candidate(sentence = \"$0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20\",discount = 10) == \"$0.00 $0.90 $1.80 $2.70 $3.60 $4.50 $5.40 $6.30 $7.20 $8.10 $9.00 $9.90 $10.80 $11.70 $12.60 $13.50 $14.40 $15.30 $16.20 $17.10 $18.00\"\n assert candidate(sentence = \"$999 $888 $777 $666 $555 $444 $333 $222 $111 $10\",discount = 99) == \"$9.99 $8.88 $7.77 $6.66 $5.55 $4.44 $3.33 $2.22 $1.11 $0.10\"\n", "comparison": "exact"}, "public_tests": ["\"there are $1 $2 and 5$ candies in the shop\"\n50", "\"1 2 $3 4 $5 $6 7 8$ $9 $10$\"\n100"], "hints": ["Extract each word from the sentence and check if it represents a price.", "For each price, apply the given discount to it and update it."], "metadata": {"canonical_parameter_names": ["sentence", "discount"], "leetcode_dataset_entry_point": "Solution().discountPrices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:40+00:00", "tests_total": 108, "tests_dropped": 10, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function discountPrices($sentence, $discount) {", "container": "Solution", "callable": "discountPrices", "parameters": [{"name": "sentence", "type": "String"}, {"name": "discount", "type": "Integer"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2289, "task_id": "steps-to-make-array-non-decreasing", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.\n\nReturn the number of steps performed until nums becomes a non-decreasing array.\n\nExample 1:\n\nInput: nums = [5,3,4,4,7,3,6,11,8,5,11]\nOutput: 3\nExplanation: The following are the steps performed:\n- Step 1: [5,3,4,4,7,3,6,11,8,5,11] becomes [5,4,4,7,6,11,11]\n- Step 2: [5,4,4,7,6,11,11] becomes [5,4,7,11,11]\n- Step 3: [5,4,7,11,11] becomes [5,7,11,11]\n[5,7,11,11] is a non-decreasing array. Therefore, we return 3.\n\nExample 2:\n\nInput: nums = [4,5,7,7,13]\nOutput: 0\nExplanation: nums is already a non-decreasing array. Therefore, we return 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 = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == 1\n assert candidate(nums = [3, 2, 1, 2, 1, 2, 3, 2, 1]) == 3\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 1\n assert candidate(nums = [2, 1]) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 5, 4, 6]) == 1\n assert candidate(nums = [3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 2\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 6, 7, 8, 9]) == 4\n assert candidate(nums = [4, 5, 7, 7, 13]) == 0\n assert candidate(nums = [1, 3, 2]) == 1\n assert candidate(nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [7, 14, 4, 14, 13, 2, 6, 13, 10, 16]) == 3\n assert candidate(nums = [3, 2, 1, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == 0\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 0\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 0\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [2, 1, 3, 2, 1, 4, 3, 2, 1, 5]) == 1\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4, 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, 2]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 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]) == 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]) == 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]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3]) == 6\n assert candidate(nums = [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]) == 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]) == 2\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995]) == 1\n assert candidate(nums = [100, 10, 90, 20, 80, 30, 70, 40, 60, 50, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [10, 20, 30, 25, 40, 50, 45, 60, 70, 55, 80, 90, 85, 100, 95, 110, 120, 115]) == 1\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 1\n assert candidate(nums = [10, 20, 15, 25, 30, 5, 35, 40, 45, 10, 50]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 9\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 = [10, 20, 30, 25, 20, 15, 10, 5, 15, 25, 35, 45, 55, 50, 45, 40, 35, 30, 25, 20]) == 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]) == 1\n assert candidate(nums = [1, 9, 2, 8, 3, 7, 4, 6, 5, 10]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 9\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 5, 9, 6, 10, 5, 11, 5, 12]) == 1\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21]) == 1\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 1\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110]) == 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\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 2\n assert candidate(nums = [10, 20, 30, 25, 35, 40, 38, 45, 50, 48]) == 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]) == 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]) == 0\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == 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, 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, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 5, 6]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 1, 2, 3, 4, 5, 10, 9, 8, 7, 6]) == 5\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == 3\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5]) == 1\n assert candidate(nums = [10, 1, 20, 2, 30, 3, 40, 4, 50, 5, 60, 6, 70, 7, 80, 8, 90, 9, 100, 10]) == 1\n assert candidate(nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11, 20, 15, 25, 22, 30, 27, 35, 32, 40, 37, 45, 42, 50]) == 3\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 1\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 5, 9, 6]) == 1\n assert candidate(nums = [3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 3, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 9, 8, 7, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [100, 200, 150, 250, 200, 300, 250, 350, 300, 400]) == 1\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, 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]) == 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]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 20, 19, 18, 17, 16]) == 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, 1]) == 2\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 1\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 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]) == 0\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5, 600, 6, 700, 7, 800, 8, 900, 9, 1000, 10]) == 1\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\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 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]) == 4\n assert candidate(nums = [3, 2, 1, 4, 6, 5, 7, 9, 8, 10]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1, 10]) == 2\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [3, 2, 1, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12]) == 1\n assert candidate(nums = [5, 3, 8, 6, 7, 2, 4, 9, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 2\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, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 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, 11, 90, 12, 89]) == 2\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]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11, 10, 9, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 2\n assert candidate(nums = [100, 200, 100, 300, 200, 400, 300, 500, 400, 600]) == 1\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 2\n assert candidate(nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11, 3, 2, 1, 9, 8, 7, 6, 5, 4]) == 3\n assert candidate(nums = [8, 3, 2, 1, 4, 5, 6, 7, 9, 10]) == 5\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 = [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]) == 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 = [3, 2, 1, 6, 5, 4, 9, 8, 7, 10]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 10, 9, 8, 7, 6]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 10\n assert candidate(nums = [1, 3, 2, 4, 6, 5, 7, 9, 8, 10, 12, 11, 13, 15, 14, 16, 18, 17, 19, 20]) == 1\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, 10, 2, 9, 3, 8, 4, 7, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 9\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 7\n assert candidate(nums = [10, 9, 8, 10, 9, 8, 10, 9, 8, 10, 9, 8, 10, 9, 8]) == 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]) == 9\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]) == 1\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 1\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 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, 1, 2, 3, 4, 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]) == 4\n", "comparison": "exact"}, "public_tests": ["[5,3,4,4,7,3,6,11,8,5,11]", "[4,5,7,7,13]"], "hints": ["Notice that an element will be removed if and only if there exists a strictly greater element to the left of it in the array.", "For each element, we need to find the number of rounds it will take for it to be removed. The answer is the maximum number of rounds for all elements. Build an array dp to hold this information where the answer is the maximum value of dp.", "Use a stack of the indices. While processing element nums[i], remove from the stack all the indices of elements that are smaller than nums[i]. dp[i] should be set to the maximum of dp[i] + 1 and dp[removed index]."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().totalSteps", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:42+00:00", "tests_total": 129, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "linked-list", "dynamic-programming", "stack", "monotonic-stack", "simulation"]}, "language": "php", "interface": {"raw_signature": "function totalSteps($nums) {", "container": "Solution", "callable": "totalSteps", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2290, "task_id": "minimum-obstacle-removal-to-reach-corner", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values:\n\n- 0 represents an empty cell,\n- 1 represents an obstacle that may be removed.\n\nYou can move up, down, left, or right from and to an empty cell.\n\nReturn the minimum number of obstacles to remove so you can move from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1).\n\nExample 1:\n\nInput: grid = [[0,1,1],[1,1,0],[1,1,0]]\nOutput: 2\nExplanation: We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2).\nIt can be shown that we need to remove at least 2 obstacles, so we return 2.\nNote that there may be other ways to remove 2 obstacles to create a path.\n\nExample 2:\n\nInput: grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]\nOutput: 0\nExplanation: We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 10^5\n- 2 <= m * n <= 10^5\n- grid[i][j] is either 0 or 1.\n- grid[0][0] == grid[m - 1][n - 1] == 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[0, 1], [1, 0]]) == 1\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 0]]) == 4\n assert candidate(grid = [[0, 1, 1, 0], [1, 1, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0]]) == 0\n assert candidate(grid = [[0, 1, 1], [1, 1, 0], [1, 1, 0]]) == 2\n assert candidate(grid = [[0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 1, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 1, 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]]) == 3\n assert candidate(grid = [[0, 1, 1, 0, 1, 1, 1, 1, 0, 0], [1, 0, 1, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0, 0, 1, 0], [1, 1, 0, 1, 1, 1, 1, 0, 1, 1], [1, 1, 0, 0, 0, 0, 1, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 1, 0], [1, 1, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 1, 1, 1, 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]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0], [1, 1, 1, 0, 1, 0], [0, 0, 0, 1, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 0], [1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1], [0, 1, 1, 1, 1, 0, 0]]) == 2\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]]) == 4\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, 0]]) == 6\n assert candidate(grid = [[0, 1, 1, 1, 1, 0], [1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1], [0, 1, 1, 1, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0], [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], [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, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 0, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 0], [0, 1, 0, 0, 0, 1], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 2\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, 0, 0, 0, 0, 1, 0, 0, 1, 0], [1, 1, 1, 1, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 0, 0, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 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\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1], [1, 0, 1, 1, 1, 1, 1], [1, 1, 1, 1, 0, 1, 1], [0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0]]) == 4\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, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 1, 0, 0, 0, 0], [0, 1, 0, 1, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0], [1, 1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 0], [1, 0, 1, 0, 1], [1, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 0, 1, 1, 0]]) == 3\n assert candidate(grid = [[0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 0]]) == 2\n assert candidate(grid = [[0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 0, 1, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 1, 0, 0], [1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 0, 0, 0]]) == 1\n assert candidate(grid = [[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, 0, 0, 0, 0, 1, 0, 0, 1, 0], [1, 1, 1, 1, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0], [1, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 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\n assert candidate(grid = [[0, 1, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 0, 1, 1, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 0, 0, 0, 1, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 0, 1, 0, 0, 1], [1, 1, 1, 0, 1, 1, 0, 1], [1, 0, 0, 0, 1, 1, 0, 1], [0, 1, 1, 0, 0, 1, 0, 0], [0, 1, 1, 1, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 0], [1, 1, 0, 0, 1, 0, 1], [0, 1, 0, 0, 0, 1, 0], [1, 0, 1, 1, 1, 0, 0], [0, 0, 0, 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, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]]) == 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, 1, 0, 1, 0, 1, 0]]) == 7\n assert candidate(grid = [[0, 1, 1, 0, 0, 1, 0], [1, 1, 1, 1, 1, 0, 1], [0, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 1, 1, 0], [0, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 1, 1, 0]]) == 3\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 0, 1], [0, 1, 1, 1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 1, 1, 1, 1, 0, 1], [0, 1, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1, 0]]) == 3\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0, 1, 0], [1, 1, 1, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 0, 1], [0, 1, 1, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0]]) == 4\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) == 2\n assert candidate(grid = [[0, 1, 1, 1, 0, 0, 0], [1, 1, 0, 1, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 0]]) == 2\n assert candidate(grid = [[0, 1, 1, 1, 0], [1, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 1, 0]]) == 1\n assert candidate(grid = [[0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 0, 0, 1, 1], [1, 1, 1, 0, 1], [0, 0, 0, 0, 0]]) == 3\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 0], [1, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 0, 1, 0, 1, 1], [0, 1, 1, 1, 1, 1, 0]]) == 4\n assert candidate(grid = [[0, 1, 1, 1, 0, 1, 1, 0, 1, 1], [1, 0, 0, 1, 0, 1, 1, 1, 0, 1], [1, 1, 0, 1, 0, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 0, 1, 1, 0, 0, 0, 0]]) == 3\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, 0, 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]]) == 0\n assert candidate(grid = [[0, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 1, 1, 0, 1], [0, 1, 0, 0, 0, 1, 0, 0], [0, 1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 1, 1, 1, 0, 1, 0], [0, 0, 0, 0, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 0, 1, 0, 0, 0], [1, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 1, 0], [0, 1, 1, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0]]) == 1\n assert candidate(grid = [[0, 1, 1, 1, 1, 1], [1, 1, 1, 0, 1, 1], [1, 0, 1, 1, 1, 1], [1, 1, 1, 1, 0, 1], [1, 1, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0]]) == 4\n assert candidate(grid = [[0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[0,1,1],[1,1,0],[1,1,0]]", "[[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]"], "hints": ["Model the grid as a graph where cells are nodes and edges are between adjacent cells. Edges to cells with obstacles have a cost of 1 and all other edges have a cost of 0.", "Could you use 0-1 Breadth-First Search or Dijkstra’s algorithm?"], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().minimumObstacles", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:45+00:00", "tests_total": 59, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["array", "breadth-first-search", "graph", "heap-priority-queue", "matrix", "shortest-path", "0-1-bfs", "dijkstra"]}, "language": "php", "interface": {"raw_signature": "function minimumObstacles($grid) {", "container": "Solution", "callable": "minimumObstacles", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2293, "task_id": "min-max-game", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums whose length is a power of 2.\n\nApply the following algorithm on nums:\n\n1. Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2.\n2. For every even index i where 0 <= i < n / 2, assign the value of newNums[i] as min(nums[2 * i], nums[2 * i + 1]).\n3. For every odd index i where 0 <= i < n / 2, assign the value of newNums[i] as max(nums[2 * i], nums[2 * i + 1]).\n4. Replace the array nums with newNums.\n5. Repeat the entire process starting from step 1.\n\nReturn the last number that remains in nums after applying the algorithm.\n\nExample 1:\n\nInput: nums = [1,3,5,2,4,8,2,2]\nOutput: 1\nExplanation: The following arrays are the results of applying the algorithm repeatedly.\nFirst: nums = [1,5,4,2]\nSecond: nums = [1,4]\nThird: nums = [1]\n1 is the last remaining number, so we return 1.\n\nExample 2:\n\nInput: nums = [3]\nOutput: 3\nExplanation: 3 is already the last remaining number, so we return 3.\n\nConstraints:\n\n- 1 <= nums.length <= 1024\n- 1 <= nums[i] <= 10^9\n- nums.length is a power of 2.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 2, 4, 8, 2, 2]) == 1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [5, 1, 4, 2, 7, 6, 3, 8]) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993]) == 999999995\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 = [2, 7, 4, 1, 8, 1, 5, 6]) == 2\n assert candidate(nums = [7, 5, 3, 1, 9, 11, 13, 15]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [9, 11, 8, 7, 6, 5, 4, 3]) == 5\n assert candidate(nums = [3]) == 3\n assert candidate(nums = [7, 3, 2, 4, 9, 8, 5, 1]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80]) == 10\n assert candidate(nums = [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, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == 1\n assert candidate(nums = [1024]) == 1024\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993]) == 1\n assert candidate(nums = [23, 45, 12, 67, 34, 89, 10, 20, 33, 56, 78, 90, 11, 22, 35, 46]) == 23\n assert candidate(nums = [128, 256, 512, 1024, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 8\n assert candidate(nums = [16, 8, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55]) == 4\n assert candidate(nums = [5, 3, 8, 1, 6, 7, 2, 4, 9, 11, 10, 13, 15, 12, 14, 16]) == 3\n assert candidate(nums = [9, 1, 7, 5, 3, 6, 4, 8, 2, 10, 11, 13, 12, 14, 15, 16]) == 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, 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 = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55]) == 50\n assert candidate(nums = [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 3, 5, 7, 9, 11]) == 11\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462, 504, 546, 588, 630, 672]) == 42\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 3, 5, 7, 9, 11]) == 11\n assert candidate(nums = [13, 21, 7, 15, 2, 18, 10, 20, 23, 5, 3, 9, 22, 4, 8, 16, 19, 1, 17, 14, 12, 6, 11, 24, 111]) == 13\n assert candidate(nums = [9, 3, 5, 7, 2, 8, 6, 4, 1, 10, 11, 12, 13, 14, 15, 16]) == 3\n assert candidate(nums = [1000000000, 1, 1000000000, 2, 1000000000, 3, 1000000000, 4]) == 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, 52, 54, 56, 58, 60, 62, 64]) == 2\n assert candidate(nums = [100, 200, 150, 50, 250, 125, 300, 75, 275, 62, 175, 87, 325, 43, 187, 91]) == 100\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 = [5, 15, 10, 20, 25, 35, 30, 40, 45, 55, 50, 60, 65, 75, 70, 80]) == 5\n assert candidate(nums = [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 11\n assert candidate(nums = [987654321, 123456789, 198765432, 212345678, 398765432, 312345678, 498765432, 412345678]) == 123456789\n assert candidate(nums = [9, 1, 8, 2, 7, 3, 6, 4, 5, 10, 15, 20, 25, 30, 35, 40]) == 1\n assert candidate(nums = [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]) == 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]) == 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 = [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]) == 2\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]) == 5\n assert candidate(nums = [1000000000, 999999999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600]) == 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, 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]) == 10\n assert candidate(nums = [8, 3, 9, 2, 10, 7, 6, 5, 12, 11, 14, 13, 16, 15, 18, 17]) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 2\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431]) == 1023\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 1\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, 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]) == 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, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]) == 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\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 17, 18, 19, 20, 21]) == 21\n assert candidate(nums = [9, 7, 5, 11, 13, 2, 8, 6, 4, 10, 12, 3, 1, 14, 15, 16]) == 7\n assert candidate(nums = [33, 11, 44, 22, 55, 33, 66, 44, 77, 55, 88, 66, 99, 77, 110, 88]) == 11\n assert candidate(nums = [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]) == 11\n assert candidate(nums = [2, 1, 3, 4, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]) == 1\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, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == 2\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990, 999999989, 999999988, 999999987, 999999986, 999999985]) == 999999990\n assert candidate(nums = [23, 45, 12, 67, 34, 89, 21, 56, 78, 90, 34, 23, 67, 89, 45, 12]) == 23\n assert candidate(nums = [5, 8, 3, 9, 1, 7, 4, 2, 6, 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]) == 4\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16]) == 4\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 90\n assert candidate(nums = [1, 3, 2, 4, 7, 5, 9, 6, 11, 8, 10, 12, 15, 13, 14, 16, 19, 17, 18, 20, 23, 21, 22, 24, 27, 25, 26, 28, 31, 29, 30, 32]) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985]) == 990\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 1\n assert candidate(nums = [100, 200, 150, 50, 300, 250, 400, 10, 600, 550, 700, 20, 800, 750, 900, 30]) == 100\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == 5\n assert candidate(nums = [17, 23, 15, 29, 11, 31, 13, 37, 19, 41, 21, 43, 25, 47, 27, 49]) == 17\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\n assert candidate(nums = [5, 2, 9, 1, 7, 3, 8, 4, 6, 10, 12, 11, 14, 13, 16, 15]) == 2\n assert candidate(nums = [2, 1, 3, 4, 5, 6, 8, 7, 9, 10, 12, 11, 14, 13, 15, 16]) == 1\n assert candidate(nums = [100, 50, 25, 75, 60, 30, 90, 40, 80, 10, 110, 120, 130, 140, 150, 160]) == 50\n assert candidate(nums = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930, 313233, 343536, 373839, 404142, 434445, 464748]) == 123\n assert candidate(nums = [9, 7, 5, 3, 2, 8, 6, 4, 1, 10, 12, 14, 16, 18, 20, 19]) == 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\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]) == 21\n assert candidate(nums = [17, 13, 21, 7, 11, 19, 23, 5, 15, 9, 25, 3, 27, 1, 29, 12]) == 13\n assert candidate(nums = [100, 200, 150, 300, 50, 250, 20, 400, 10, 15, 30, 25, 60, 70, 80, 90]) == 90\n assert candidate(nums = [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]) == 43\n assert candidate(nums = [1000000000, 1, 1000000000, 1, 1000000000, 1, 1000000000, 1]) == 1\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 = [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]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 17, 18, 19, 20, 21, 22, 23]) == 4\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]) == 5\n", "comparison": "exact"}, "public_tests": ["[1,3,5,2,4,8,2,2]", "[3]"], "hints": ["Simply simulate the algorithm.", "Note that the size of the array decreases exponentially, so the process will terminate after just O(log n) steps."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minMaxGame", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:49+00:00", "tests_total": 93, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function minMaxGame($nums) {", "container": "Solution", "callable": "minMaxGame", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2294, "task_id": "partition-array-such-that-maximum-difference-is-k", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences.\n\nReturn the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k.\n\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [3,6,1,2,5], k = 2\nOutput: 2\nExplanation:\nWe can partition nums into the two subsequences [3,1,2] and [6,5].\nThe difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.\nThe difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.\nSince two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed.\n\nExample 2:\n\nInput: nums = [1,2,3], k = 1\nOutput: 2\nExplanation:\nWe can partition nums into the two subsequences [1,2] and [3].\nThe difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.\nThe difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.\nSince two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3].\n\nExample 3:\n\nInput: nums = [2,2,4,5], k = 0\nOutput: 3\nExplanation:\nWe can partition nums into the three subsequences [2,2], [4], and [5].\nThe difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.\nThe difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.\nThe difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.\nSince three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^5\n- 0 <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 100000],k = 99999) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],k = 0) == 1\n assert candidate(nums = [1, 2, 3],k = 1) == 2\n assert candidate(nums = [1, 3, 5, 7, 9],k = 1) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 5\n assert candidate(nums = [3, 6, 1, 2, 5],k = 2) == 2\n assert candidate(nums = [5, 5, 5, 5, 5],k = 1) == 1\n assert candidate(nums = [2, 2, 4, 5],k = 0) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 4) == 1\n assert candidate(nums = [5, 4, 3, 2, 1],k = 3) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 5\n assert candidate(nums = [1, 100, 101, 200, 201, 300, 301],k = 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],k = 2) == 9\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61],k = 4) == 8\n assert candidate(nums = [5, 5, 5, 10, 10, 10, 15, 15, 15, 20, 20, 20, 25, 25, 25, 30, 30, 30, 35, 35, 35, 40, 40, 40, 45, 45, 45],k = 5) == 5\n assert candidate(nums = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901],k = 100) == 5\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 20) == 4\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],k = 150) == 6\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],k = 5) == 11\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) == 7\n assert candidate(nums = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009],k = 1) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 99) == 10\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6],k = 1) == 5\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 15) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 1000) == 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],k = 2) == 9\n assert candidate(nums = [3, 1, 2, 6, 5, 4, 9, 7, 8, 12, 10, 11, 15, 13, 14, 18, 16, 17, 21, 19, 20],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, 10, 10],k = 1) == 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 = 1) == 20\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998],k = 99998) == 2\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 6\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) == 5\n assert candidate(nums = [8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84],k = 4) == 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 = 1) == 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 = 2) == 10\n assert candidate(nums = [100, 105, 110, 115, 120, 125, 130, 135, 140, 145],k = 10) == 4\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 20) == 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 = 24) == 1\n assert candidate(nums = [5, 8, 12, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6],k = 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],k = 1) == 10\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 200) == 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 = 4) == 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) == 1\n assert candidate(nums = [1, 3, 6, 8, 10, 15, 18, 20, 22, 25],k = 4) == 5\n assert candidate(nums = [10, 21, 32, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 153, 164],k = 11) == 8\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 1) == 5\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28],k = 3) == 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],k = 0) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 4) == 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 = 2) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 2) == 8\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, 85, 89, 93, 97, 101],k = 4) == 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) == 4\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 1) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 21, 22, 23, 24, 25],k = 10) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 150) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],k = 2) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],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],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, 21, 22, 23, 24, 25],k = 0) == 25\n assert candidate(nums = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30],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, 10, 10],k = 1) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 2) == 8\n assert candidate(nums = [1, 5, 9, 14, 18, 22, 26, 30],k = 4) == 5\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) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],k = 0) == 1\n assert candidate(nums = [1, 3, 6, 8, 10, 15, 18, 20, 25, 28],k = 3) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 25) == 5\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50) == 10\n assert candidate(nums = [5, 8, 3, 9, 1, 4, 7, 6, 2, 10],k = 3) == 3\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 = 5) == 4\n assert candidate(nums = [5, 1, 9, 3, 7, 11, 6, 4, 8, 2, 10, 12],k = 3) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 5\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 = 4) == 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],k = 10) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 15) == 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 = 2) == 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],k = 3) == 7\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994],k = 3) == 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, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197],k = 4) == 25\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 = 2) == 13\n assert candidate(nums = [1, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 3) == 8\n assert candidate(nums = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 10000) == 5\n assert candidate(nums = [4, 8, 15, 16, 23, 42, 50, 55, 60, 65],k = 10) == 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 = 3) == 10\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == 11\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 8, 9, 10, 10, 10, 10, 10],k = 1) == 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, 42, 44, 46, 48, 50],k = 5) == 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],k = 1) == 3\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 5\n assert candidate(nums = [5, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48],k = 5) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 0) == 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],k = 10) == 10\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120],k = 15) == 6\n assert candidate(nums = [30, 40, 20, 50, 60, 10, 70, 80, 90, 100],k = 10) == 5\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 = [5, 2, 9, 1, 5, 6],k = 4) == 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],k = 10) == 7\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100],k = 9) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40],k = 1) == 20\n assert candidate(nums = [15, 8, 20, 12, 18, 25, 5, 10, 30, 22],k = 5) == 4\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 = 4) == 7\n assert candidate(nums = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 10) == 8\n", "comparison": "exact"}, "public_tests": ["[3,6,1,2,5]\n2", "[1,2,3]\n1", "[2,2,4,5]\n0"], "hints": ["Which values in each subsequence matter? The only values that matter are the maximum and minimum values.", "Let the maximum and minimum values of a subsequence be Max and Min. It is optimal to place all values in between Max and Min in the original array in the same subsequence as Max and Min.", "Sort the array."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().partitionArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:52+00:00", "tests_total": 112, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function partitionArray($nums, $k) {", "container": "Solution", "callable": "partitionArray", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2295, "task_id": "replace-elements-in-an-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the i^th operation you replace the number operations[i][0] with operations[i][1].\n\nIt is guaranteed that in the i^th operation:\n\n- operations[i][0] exists in nums.\n- operations[i][1] does not exist in nums.\n\nReturn the array obtained after applying all the operations.\n\nExample 1:\n\nInput: nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]]\nOutput: [3,2,7,1]\nExplanation: We perform the following operations on nums:\n- Replace the number 1 with 3. nums becomes [3,2,4,6].\n- Replace the number 4 with 7. nums becomes [3,2,7,6].\n- Replace the number 6 with 1. nums becomes [3,2,7,1].\nWe return the final array [3,2,7,1].\n\nExample 2:\n\nInput: nums = [1,2], operations = [[1,3],[2,1],[3,2]]\nOutput: [2,1]\nExplanation: We perform the following operations to nums:\n- Replace the number 1 with 3. nums becomes [3,2].\n- Replace the number 2 with 1. nums becomes [3,1].\n- Replace the number 3 with 2. nums becomes [2,1].\nWe return the array [2,1].\n\nConstraints:\n\n- n == nums.length\n- m == operations.length\n- 1 <= n, m <= 10^5\n- All the values of nums are distinct.\n- operations[i].length == 2\n- 1 <= nums[i], operations[i][0], operations[i][1] <= 10^6\n- operations[i][0] will exist in nums when applying the i^th operation.\n- operations[i][1] will not exist in nums when applying the i^th operation.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2],operations = [[1, 3], [2, 1], [3, 2]]) == [2, 1]\n assert candidate(nums = [5, 3, 7, 8],operations = [[5, 10], [3, 15], [7, 20], [8, 25]]) == [10, 15, 20, 25]\n assert candidate(nums = [1, 2, 3, 4, 5],operations = [[1, 5], [2, 4], [3, 3]]) == [5, 4, 3, 4, 5]\n assert candidate(nums = [1, 2, 4, 6],operations = [[1, 3], [4, 7], [6, 1]]) == [3, 2, 7, 1]\n assert candidate(nums = [100, 200, 300],operations = [[100, 150], [200, 250], [300, 350]]) == [150, 250, 350]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65],operations = [[5, 1], [15, 2], [25, 3], [35, 4], [45, 5], [55, 6], [65, 7]]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],operations = [[10, 110], [20, 220], [30, 330], [40, 440], [50, 550], [60, 660], [70, 770], [80, 880], [90, 990], [100, 1010]]) == [110, 220, 330, 440, 550, 660, 770, 880, 990, 1010]\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120],operations = [[8, 1], [16, 2], [24, 3], [32, 4], [40, 5], [48, 6], [56, 7], [64, 8], [72, 9], [80, 10], [88, 11], [96, 12], [104, 13], [112, 14], [120, 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, 11, 12, 13, 14, 15],operations = [[1, 15], [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15]\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65],operations = [[5, 1], [15, 2], [25, 3], [35, 4], [45, 5], [55, 6], [65, 7]]) == [1, 2, 3, 4, 5, 6, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],operations = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45], [60, 55], [70, 65], [80, 75], [90, 85], [100, 95]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(nums = [1, 3, 5, 7, 9],operations = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [2, 4, 6, 8, 10]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],operations = [[7, 1], [14, 2], [21, 3], [28, 4], [35, 5], [42, 6], [49, 7], [56, 8], [63, 9], [70, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],operations = [[1000, 500], [2000, 1500], [3000, 2500], [4000, 3500], [5000, 4500]]) == [500, 1500, 2500, 3500, 4500]\n assert candidate(nums = [1234, 5678, 91011, 121314, 151617],operations = [[1234, 1], [5678, 2], [91011, 3], [121314, 4], [151617, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],operations = [[7, 1], [14, 2], [21, 3], [28, 4], [35, 5], [42, 6], [49, 7], [56, 8], [63, 9], [70, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [7, 14, 21, 28, 35, 42],operations = [[7, 1], [14, 2], [21, 3], [28, 4], [35, 5], [42, 6]]) == [1, 2, 3, 4, 5, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],operations = [[1, 16], [2, 17], [3, 18], [4, 19], [5, 20], [6, 21], [7, 22], [8, 23], [9, 24], [10, 25], [11, 26], [12, 27], [13, 28], [14, 29], [15, 30]]) == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],operations = [[100000, 1], [50000, 2], [25000, 3], [12500, 4], [6250, 5], [3125, 6], [1562, 7], [781, 8], [390, 9], [195, 10]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],operations = [[1000000, 1], [999999, 2], [999998, 3], [999997, 4], [999996, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],operations = [[1000, 1001], [2000, 2002], [3000, 3003], [4000, 4004], [5000, 5005]]) == [1001, 2002, 3003, 4004, 5005]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],operations = [[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]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]\n assert candidate(nums = [999, 998, 997, 996, 995],operations = [[999, 994], [998, 993], [997, 992], [996, 991], [995, 990]]) == [994, 993, 992, 991, 990]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],operations = [[1, 21], [2, 22], [3, 23], [4, 24], [5, 25], [6, 26], [7, 27], [8, 28], [9, 29], [10, 30], [11, 31], [12, 32], [13, 33], [14, 34], [15, 35], [16, 36], [17, 37], [18, 38], [19, 39], [20, 40]]) == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]\n assert candidate(nums = [5, 10, 15, 20, 25],operations = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000],operations = [[1000, 1001], [2000, 2001], [3000, 3001], [4000, 4001], [5000, 5001], [6000, 6001]]) == [1001, 2001, 3001, 4001, 5001, 6001]\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],operations = [[1000000, 999999], [500000, 499999], [250000, 249999], [125000, 124999], [62500, 62499], [31250, 31249], [15625, 15624], [7812, 7811], [3906, 3905], [1953, 1952]]) == [999999, 499999, 249999, 124999, 62499, 31249, 15624, 7811, 3905, 1952]\n assert candidate(nums = [1, 3, 5, 7, 9],operations = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [2, 4, 6, 8, 10]\n assert candidate(nums = [5, 3, 8, 9, 10],operations = [[5, 6], [3, 4], [8, 5], [9, 8], [10, 9]]) == [6, 4, 5, 8, 9]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],operations = [[10, 11], [20, 21], [30, 31], [40, 41], [50, 51], [60, 61], [70, 71], [80, 81], [90, 91], [100, 101]]) == [11, 21, 31, 41, 51, 61, 71, 81, 91, 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],operations = [[1, 21], [2, 22], [3, 23], [4, 24], [5, 25], [6, 26], [7, 27], [8, 28], [9, 29], [10, 30], [11, 31], [12, 32], [13, 33], [14, 34], [15, 35], [16, 36], [17, 37], [18, 38], [19, 39], [20, 40]]) == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],operations = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 11]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11]\n assert candidate(nums = [9999, 8888, 7777, 6666, 5555],operations = [[9999, 10000], [8888, 11111], [7777, 12222], [6666, 13333], [5555, 14444]]) == [10000, 11111, 12222, 13333, 14444]\n assert candidate(nums = [500000, 1, 500001, 2, 500002],operations = [[500000, 3], [1, 4], [500001, 5], [2, 6], [500002, 7]]) == [3, 4, 5, 6, 7]\n assert candidate(nums = [10, 20, 30, 40, 50, 60],operations = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65]]) == [15, 25, 35, 45, 55, 65]\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121],operations = [[11, 12], [22, 14], [33, 16], [44, 18], [55, 20], [66, 22], [77, 24], [88, 26], [99, 28], [110, 30], [121, 32]]) == [12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]\n assert candidate(nums = [7, 14, 21, 28, 35, 42],operations = [[7, 1], [14, 2], [21, 3], [28, 4], [35, 5], [42, 6]]) == [1, 2, 3, 4, 5, 6]\n assert candidate(nums = [12, 34, 56, 78, 90, 123, 456],operations = [[12, 11], [34, 33], [56, 55], [78, 77], [90, 89], [123, 122], [456, 455]]) == [11, 33, 55, 77, 89, 122, 455]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56],operations = [[7, 15], [14, 7], [21, 14], [28, 21], [35, 28], [42, 35], [49, 42], [56, 49]]) == [15, 7, 14, 21, 28, 35, 42, 49]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],operations = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45], [60, 55], [70, 65], [80, 75], [90, 85], [100, 95]]) == [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],operations = [[9, 18], [8, 16], [7, 14], [6, 12], [5, 10], [4, 8], [3, 6], [2, 4], [1, 2]]) == [18, 16, 14, 12, 10, 8, 6, 4, 2]\n assert candidate(nums = [5, 3, 8, 9, 2],operations = [[5, 15], [3, 10], [8, 18], [9, 19], [2, 12]]) == [15, 10, 18, 19, 12]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],operations = [[2, 1], [4, 3], [6, 5], [8, 7], [10, 9], [12, 11], [14, 13], [16, 15], [18, 17], [20, 19]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [5, 3, 8, 9, 2, 6],operations = [[5, 10], [3, 5], [8, 3], [9, 8], [2, 9], [6, 2]]) == [10, 5, 3, 8, 9, 2]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],operations = [[100, 110], [200, 120], [300, 130], [400, 140], [500, 150], [600, 160], [700, 170], [800, 180], [900, 190], [1000, 200], [1100, 210], [1200, 220], [1300, 230], [1400, 240], [1500, 250]]) == [110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250]\n assert candidate(nums = [1, 100000],operations = [[1, 50000], [100000, 99999]]) == [50000, 99999]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],operations = [[1000, 1100], [2000, 2200], [3000, 3300], [4000, 4400], [5000, 5500]]) == [1100, 2200, 3300, 4400, 5500]\n assert candidate(nums = [5, 15, 25, 35, 45, 55],operations = [[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60]]) == [10, 20, 30, 40, 50, 60]\n assert candidate(nums = [10, 20, 30, 40, 50],operations = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45]]) == [5, 15, 25, 35, 45]\n assert candidate(nums = [1, 1000000],operations = [[1, 2], [1000000, 1]]) == [2, 1]\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390, 195],operations = [[100000, 200000], [50000, 100000], [25000, 50000], [12500, 25000], [6250, 12500], [3125, 6250], [1562, 3125], [781, 1562], [390, 781], [195, 390]]) == [200000, 100000, 50000, 25000, 12500, 6250, 3125, 1562, 781, 390]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],operations = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n assert candidate(nums = [5, 10, 15, 20, 25, 30],operations = [[5, 4], [10, 9], [15, 8], [20, 7], [25, 6], [30, 5]]) == [4, 9, 8, 7, 6, 5]\n assert candidate(nums = [7, 11, 13, 17, 19],operations = [[7, 10], [11, 12], [13, 14], [17, 15], [19, 16]]) == [10, 12, 14, 15, 16]\n assert candidate(nums = [10, 20, 30, 40, 50],operations = [[10, 15], [30, 35], [50, 55], [20, 25], [40, 45]]) == [15, 25, 35, 45, 55]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],operations = [[1, 20], [3, 21], [5, 22], [7, 23], [9, 24], [11, 25], [13, 26], [15, 27], [17, 28], [19, 29]]) == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996],operations = [[1000000, 1], [999999, 2], [999998, 3], [999997, 4], [999996, 5]]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30, 40, 50],operations = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55]]) == [15, 25, 35, 45, 55]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],operations = [[2, 1], [4, 3], [6, 5], [8, 7], [10, 9], [12, 11], [14, 13], [16, 15], [18, 17], [20, 19]]) == [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n assert candidate(nums = [5, 3, 9, 11, 13],operations = [[3, 4], [9, 10], [11, 12], [13, 14], [5, 6]]) == [6, 4, 10, 12, 14]\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],operations = [[99, 100], [98, 101], [97, 102], [96, 103], [95, 104], [94, 105], [93, 106], [92, 107], [91, 108], [90, 109]]) == [100, 101, 102, 103, 104, 105, 106, 107, 108, 109]\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222, 333, 444, 555, 666, 777, 888, 999],operations = [[11, 1], [22, 2], [33, 3], [44, 4], [55, 5], [66, 6], [77, 7], [88, 8], [99, 9], [111, 10], [222, 11], [333, 12], [444, 13], [555, 14], [666, 15], [777, 16], [888, 17], [999, 18]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]\n assert candidate(nums = [7, 17, 27, 37, 47, 57],operations = [[7, 8], [17, 18], [27, 28], [37, 38], [47, 48], [57, 58]]) == [8, 18, 28, 38, 48, 58]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000],operations = [[1000, 1001], [2000, 2002], [3000, 3003], [4000, 4004], [5000, 5005], [6000, 6006]]) == [1001, 2002, 3003, 4004, 5005, 6006]\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000],operations = [[1000, 500], [2000, 1000], [3000, 1500], [4000, 2000], [5000, 2500], [6000, 3000], [7000, 3500], [8000, 4000], [9000, 4500]]) == [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],operations = [[2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19], [20, 21]]) == [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]\n assert candidate(nums = [29, 13, 11, 14, 23, 25, 9, 22, 19, 30, 28, 21, 17, 26, 18, 24, 27, 16, 12, 31, 10, 15, 8, 20, 7, 6, 5, 4, 3, 2, 1],operations = [[29, 32], [13, 33], [11, 34], [14, 35], [23, 36], [25, 37], [9, 38], [22, 39], [19, 40], [30, 41], [28, 42], [21, 43], [17, 44], [26, 45], [18, 46], [24, 47], [27, 48], [16, 49], [12, 50], [31, 51], [10, 52], [15, 53], [8, 54], [20, 55], [7, 56], [6, 57], [5, 58], [4, 59], [3, 60], [2, 61], [1, 62]]) == [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]\n assert candidate(nums = [99, 199, 299, 399, 499, 599],operations = [[99, 100], [199, 200], [299, 300], [399, 400], [499, 500], [599, 600]]) == [100, 200, 300, 400, 500, 600]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 1],operations = [[5, 10], [3, 11], [8, 12], [6, 13], [2, 14], [7, 15], [4, 16], [1, 17]]) == [10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],operations = [[1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20]]) == [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500],operations = [[1000000, 999999], [500000, 1000000], [250000, 500000], [125000, 250000], [62500, 125000]]) == [999999, 1000000, 500000, 250000, 125000]\n assert candidate(nums = [9, 7, 5, 3, 1],operations = [[9, 10], [7, 8], [5, 6], [3, 4], [1, 2]]) == [10, 8, 6, 4, 2]\n assert candidate(nums = [10, 20, 30, 40, 50, 60],operations = [[10, 15], [20, 25], [30, 35], [40, 45], [50, 55], [60, 65]]) == [15, 25, 35, 45, 55, 65]\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],operations = [[999999, 999989], [999998, 999988], [999997, 999987], [999996, 999986], [999995, 999985], [999994, 999984], [999993, 999983], [999992, 999982], [999991, 999981], [999990, 999980]]) == [999989, 999988, 999987, 999986, 999985, 999984, 999983, 999982, 999981, 999980]\n assert candidate(nums = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],operations = [[10000, 5000], [20000, 10000], [30000, 15000], [40000, 20000], [50000, 25000], [60000, 30000], [70000, 35000], [80000, 40000], [90000, 45000], [100000, 50000]]) == [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000]\n", "comparison": "exact"}, "public_tests": ["[1,2,4,6]\n[[1,3],[4,7],[6,1]]", "[1,2]\n[[1,3],[2,1],[3,2]]"], "hints": ["Can you think of a data structure that will allow you to store the position of each number?", "Use that data structure to instantly replace a number with its new value."], "metadata": {"canonical_parameter_names": ["nums", "operations"], "leetcode_dataset_entry_point": "Solution().arrayChange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:47:54+00:00", "tests_total": 76, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "simulation"]}, "language": "php", "interface": {"raw_signature": "function arrayChange($nums, $operations) {", "container": "Solution", "callable": "arrayChange", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "operations", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2300, "task_id": "successful-pairs-of-spells-and-potions", "difficulty": "Medium", "problem_description": "You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the i^th spell and potions[j] represents the strength of the j^th potion.\n\nYou are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.\n\nReturn an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the i^th spell.\n\nExample 1:\n\nInput: spells = [5,1,3], potions = [1,2,3,4,5], success = 7\nOutput: [4,0,3]\nExplanation:\n- 0^th spell: 5 * [1,2,3,4,5] = [5,10,15,20,25]. 4 pairs are successful.\n- 1^st spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.\n- 2^nd spell: 3 * [1,2,3,4,5] = [3,6,9,12,15]. 3 pairs are successful.\nThus, [4,0,3] is returned.\n\nExample 2:\n\nInput: spells = [3,1,2], potions = [8,5,8], success = 16\nOutput: [2,0,2]\nExplanation:\n- 0^th spell: 3 * [8,5,8] = [24,15,24]. 2 pairs are successful.\n- 1^st spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.\n- 2^nd spell: 2 * [8,5,8] = [16,10,16]. 2 pairs are successful.\nThus, [2,0,2] is returned.\n\nConstraints:\n\n- n == spells.length\n- m == potions.length\n- 1 <= n, m <= 10^5\n- 1 <= spells[i], potions[i] <= 10^5\n- 1 <= success <= 10^10\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(spells = [3, 1, 2],potions = [8, 5, 8],success = 16) == [2, 0, 2]\n assert candidate(spells = [1, 1, 1],potions = [1, 1, 1],success = 2) == [0, 0, 0]\n assert candidate(spells = [5, 1, 3],potions = [1, 2, 3, 4, 5],success = 7) == [4, 0, 3]\n assert candidate(spells = [1, 2, 3, 4, 5],potions = [5, 4, 3, 2, 1],success = 10) == [0, 1, 2, 3, 4]\n assert candidate(spells = [10, 20, 30],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 50) == [6, 8, 9]\n assert candidate(spells = [100000, 100000, 100000],potions = [100000, 100000, 100000],success = 10000000000) == [3, 3, 3]\n assert candidate(spells = [10, 20, 30],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 100) == [1, 6, 7]\n assert candidate(spells = [1, 1, 1],potions = [1, 1, 1, 1],success = 1) == [4, 4, 4]\n assert candidate(spells = [10, 10, 10],potions = [1, 1, 1, 1, 1],success = 100) == [0, 0, 0]\n assert candidate(spells = [1, 1, 1, 1],potions = [1, 1, 1, 1],success = 1) == [4, 4, 4, 4]\n assert candidate(spells = [1, 2, 3, 4, 5],potions = [5, 4, 3, 2, 1],success = 6) == [0, 3, 4, 4, 4]\n assert candidate(spells = [10, 20, 30],potions = [5, 10, 15, 20],success = 100) == [3, 4, 4]\n assert candidate(spells = [100000],potions = [100000],success = 10000000000) == [1]\n assert candidate(spells = [100, 200, 300, 400, 500],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],success = 500) == [11, 13, 14, 14, 15]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [50000, 49999, 49998, 49997, 49996, 49995, 49994, 49993, 49992, 49991],success = 4999750005) == [2, 2, 1, 1, 0]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],success = 100000) == [1, 6, 7, 8, 9, 9, 9, 9, 9, 10]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 10000000000) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [100000, 99999, 99998, 99997, 99996, 99995],success = 9999900000) == [1, 0, 0, 0, 0]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],success = 2) == [0, 0, 0, 0, 0]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],success = 1) == [10, 10, 10, 10, 10]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],success = 50) == [6, 8, 9, 9, 10, 10, 10, 10, 10, 10]\n assert candidate(spells = [1, 10, 100, 1000, 10000],potions = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000],success = 10000) == [0, 1, 4, 7, 10]\n assert candidate(spells = [1, 3, 5, 7, 9],potions = [11, 13, 15, 17, 19, 21, 23, 25, 27, 29],success = 50) == [0, 7, 10, 10, 10]\n assert candidate(spells = [2, 4, 6, 8, 10],potions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],success = 100) == [1, 6, 7, 8, 9]\n assert candidate(spells = [100, 200, 300, 400, 500],potions = [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],success = 5000) == [10, 16, 19, 20, 21]\n assert candidate(spells = [5, 10, 15, 20, 25],potions = [20, 25, 30, 35, 40, 45, 50, 55, 60],success = 500) == [0, 3, 6, 8, 9]\n assert candidate(spells = [1000, 2000, 3000, 4000, 5000],potions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],success = 10000) == [9, 10, 10, 10, 10]\n assert candidate(spells = [5, 10, 15, 20, 25],potions = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],success = 50) == [5, 8, 8, 9, 9]\n assert candidate(spells = [1, 2, 3, 4, 5],potions = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],success = 100000) == [0, 10, 10, 10, 10]\n assert candidate(spells = [9, 8, 7, 6, 5],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9],success = 20) == [7, 7, 7, 6, 6]\n assert candidate(spells = [100, 200, 300, 400, 500],potions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],success = 100) == [10, 10, 10, 10, 10]\n assert candidate(spells = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],potions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],success = 250) == [1, 6, 7, 8, 9, 9, 9, 9, 9, 10]\n assert candidate(spells = [50000, 50000, 50000, 50000],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 100000) == [10, 10, 10, 10]\n assert candidate(spells = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],potions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],success = 2500) == [0, 0, 2, 4, 6, 6, 7, 7, 8, 8]\n assert candidate(spells = [50000, 25000, 12500],potions = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000],success = 625000000) == [9, 8, 6]\n assert candidate(spells = [1, 2, 3, 4, 5],potions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],success = 25) == [6, 8, 9, 9, 10]\n assert candidate(spells = [100000, 90000, 80000],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 500000) == [6, 5, 4]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [100000, 100000, 100000, 100000, 100000],success = 100000) == [5, 5, 5, 5, 5]\n assert candidate(spells = [10000, 20000, 30000, 40000, 50000],potions = [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000],success = 200000000) == [7, 9, 9, 10, 10]\n assert candidate(spells = [10000, 5000, 2500],potions = [5000, 10000, 15000, 20000, 25000],success = 100000000) == [4, 2, 0]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],success = 1000000) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(spells = [5, 15, 25, 35, 45],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 100) == [1, 7, 9, 9, 9]\n assert candidate(spells = [100000, 100000, 100000, 100000],potions = [100000, 100000, 100000, 100000, 100000],success = 10000000000) == [5, 5, 5, 5]\n assert candidate(spells = [5, 5, 5, 5, 5],potions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],success = 6) == [0, 0, 0, 0, 0]\n assert candidate(spells = [1, 3, 5, 7, 9],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 18) == [2, 8, 9, 9, 10]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],success = 1) == [21, 21, 21, 21, 21]\n assert candidate(spells = [3, 3, 3, 3, 3],potions = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],success = 10) == [0, 0, 0, 0, 0]\n assert candidate(spells = [1, 3, 5, 7, 9],potions = [9, 7, 5, 3, 1],success = 15) == [0, 3, 4, 4, 4]\n assert candidate(spells = [9, 7, 5, 3, 1],potions = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2],success = 50) == [8, 7, 6, 2, 0]\n assert candidate(spells = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 20) == [1, 7, 9, 9, 9, 10, 10, 10, 10, 10]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11],success = 9999500000) == [0, 0, 0, 0, 0]\n assert candidate(spells = [50, 25, 10, 2],potions = [1000, 500, 250, 125, 62, 31, 15, 7, 3, 1],success = 5000) == [4, 3, 2, 0]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],success = 10) == [1, 6, 7, 8, 9, 9, 9, 9, 9, 10]\n assert candidate(spells = [1000, 2000, 3000, 4000, 5000],potions = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],success = 5000000) == [0, 0, 0, 0, 10]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],success = 9999500000) == [0, 0, 0, 0, 0]\n assert candidate(spells = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],potions = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],success = 100000) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(spells = [5, 5, 5, 5, 5],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 25) == [6, 6, 6, 6, 6]\n assert candidate(spells = [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],potions = [100, 200, 300, 400, 500],success = 5000) == [0, 0, 0, 0, 1, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(spells = [100, 200, 300, 400, 500],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],success = 1000) == [11, 16, 17, 18, 19]\n assert candidate(spells = [100000, 90000, 80000],potions = [100000, 90000, 80000, 70000, 60000],success = 8100000000) == [2, 2, 0]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [100000, 100000, 100000, 100000, 100000],success = 50000) == [5, 5, 5, 5, 5]\n assert candidate(spells = [1, 3, 5, 7, 9],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 15) == [3, 8, 9, 9, 10]\n assert candidate(spells = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],potions = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],success = 1000000) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]\n assert candidate(spells = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],success = 1000) == [1, 11, 14, 16, 17, 17, 18, 18, 18, 19]\n assert candidate(spells = [100000, 1, 50000, 10000],potions = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],success = 10000000000) == [1, 0, 0, 0]\n assert candidate(spells = [1, 1, 1, 1, 1],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 10) == [1, 1, 1, 1, 1]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [1, 10, 100, 1000, 10000, 100000],success = 9999500000) == [1, 1, 1, 1, 1]\n assert candidate(spells = [9, 8, 7, 6, 5, 4, 3, 2, 1],potions = [9, 8, 7, 6, 5, 4, 3, 2, 1],success = 36) == [6, 5, 4, 4, 2, 1, 0, 0, 0]\n assert candidate(spells = [99999, 99998, 99997, 99996, 99995],potions = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],success = 9999800001) == [1, 0, 0, 0, 0]\n assert candidate(spells = [50, 25, 100, 1],potions = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],success = 1000) == [6, 5, 7, 1]\n assert candidate(spells = [10, 20, 30, 40, 50],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 150) == [3, 7, 8, 9, 9]\n assert candidate(spells = [100000, 90000, 80000, 70000, 60000],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 54000000) == [0, 0, 0, 0, 0]\n assert candidate(spells = [100000, 1, 99999],potions = [1, 100000, 99999, 50000, 25000],success = 9999999999) == [1, 0, 0]\n assert candidate(spells = [100000, 100000, 100000],potions = [100000, 100000, 100000, 100000, 100000],success = 10000000000) == [5, 5, 5]\n assert candidate(spells = [5, 10, 15, 20, 25],potions = [20, 25, 30, 35, 40, 45, 50, 55, 60, 65],success = 800) == [0, 0, 3, 6, 7]\n assert candidate(spells = [50, 40, 30, 20, 10],potions = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],success = 200) == [10, 10, 9, 9, 7]\n assert candidate(spells = [100000, 50000, 25000],potions = [1, 10, 100, 1000, 10000, 100000],success = 10000000000) == [1, 0, 0]\n assert candidate(spells = [100, 200, 300, 400, 500],potions = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],success = 1500) == [3, 7, 8, 9, 9]\n assert candidate(spells = [50, 50, 50, 50, 50],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],success = 250) == [16, 16, 16, 16, 16]\n assert candidate(spells = [99999, 99998, 99997],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 9999800000) == [0, 0, 0]\n assert candidate(spells = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],potions = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],success = 1024) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(spells = [100000, 50000, 25000, 12500],potions = [1, 10, 100, 1000, 10000, 100000],success = 10000000000) == [1, 0, 0, 0]\n assert candidate(spells = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 50) == [0, 0, 0, 0, 1, 2, 3, 4, 5, 6]\n assert candidate(spells = [10, 20, 30, 40, 50],potions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],success = 50) == [6, 8, 9, 9, 10]\n", "comparison": "exact"}, "public_tests": ["[5,1,3]\n[1,2,3,4,5]\n7", "[3,1,2]\n[8,5,8]\n16"], "hints": ["Notice that if a spell and potion pair is successful, then the spell and all stronger potions will be successful too.", "Thus, for each spell, we need to find the potion with the least strength that will form a successful pair.", "We can efficiently do this by sorting the potions based on strength and using binary search."], "metadata": {"canonical_parameter_names": ["spells", "potions", "success"], "leetcode_dataset_entry_point": "Solution().successfulPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:01+00:00", "tests_total": 96, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "sorting"]}, "language": "php", "interface": {"raw_signature": "function successfulPairs($spells, $potions, $success) {", "container": "Solution", "callable": "successfulPairs", "parameters": [{"name": "spells", "type": "Integer[]"}, {"name": "potions", "type": "Integer[]"}, {"name": "success", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2301, "task_id": "match-substring-after-replacement", "difficulty": "Hard", "problem_description": "You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [old_i, new_i] indicates that you may perform the following operation any number of times:\n\n- Replace a character old_i of sub with new_i.\n\nEach character in sub cannot be replaced more than once.\n\nReturn true if it is possible to make sub a substring of s by replacing zero or more characters according to mappings. Otherwise, return false.\n\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]\nOutput: true\nExplanation: Replace the first 'e' in sub with '3' and 't' in sub with '7'.\nNow sub = \"l3e7\" is a substring of s, so we return true.\n\nExample 2:\n\nInput: s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]]\nOutput: false\nExplanation: The string \"f00l\" is not a substring of s and no replacements can be made.\nNote that we cannot replace '0' with 'o'.\n\nExample 3:\n\nInput: s = \"Fool33tbaR\", sub = \"leetd\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]]\nOutput: true\nExplanation: Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.\nNow sub = \"l33tb\" is a substring of s, so we return true.\n\nConstraints:\n\n- 1 <= sub.length <= s.length <= 5000\n- 0 <= mappings.length <= 1000\n- mappings[i].length == 2\n- old_i != new_i\n- s and sub consist of uppercase and lowercase English letters and digits.\n- old_i and new_i are either uppercase or lowercase English letters or digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"fooleetbar\",sub = \"f00l\",mappings = [['o', '0']]) == False\n assert candidate(s = \"fool3e7bar\",sub = \"leet\",mappings = [['e', '3'], ['t', '7'], ['t', '8']]) == True\n assert candidate(s = \"Fool33tbaR\",sub = \"leetd\",mappings = [['e', '3'], ['t', '7'], ['t', '8'], ['d', 'b'], ['p', 'b']]) == True\n assert candidate(s = \"1234567890\",sub = \"120\",mappings = [['3', '4'], ['5', '6'], ['7', '8'], ['9', '0']]) == False\n assert candidate(s = \"thisisaverylongstringwithmanycharacters\",sub = \"thisisaverylongstringwithmanychar1\",mappings = [['a', '1']]) == False\n assert candidate(s = \"abcABC123\",sub = \"aBc12\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C'], ['1', '2'], ['2', '3']]) == True\n assert candidate(s = \"A1B2C3D4E5F6G7H8I9J0\",sub = \"abcdefghij\",mappings = [['1', 'a'], ['2', 'b'], ['3', 'c'], ['4', 'd'], ['5', 'e'], ['6', 'f'], ['7', 'g'], ['8', 'h'], ['9', 'i'], ['0', 'j']]) == False\n assert candidate(s = \"AaBbCc\",sub = \"abc\",mappings = [['A', 'a'], ['B', 'b'], ['C', 'c']]) == False\n assert candidate(s = \"UPPERlower\",sub = \"lower\",mappings = [['U', 'l'], ['P', 'o'], ['E', 'w'], ['R', 'r']]) == True\n assert candidate(s = \"12345678901234567890\",sub = \"13579\",mappings = [['1', '2'], ['3', '4'], ['5', '6'], ['7', '8'], ['9', '0']]) == False\n assert candidate(s = \"xyzuvw\",sub = \"xyzz\",mappings = [['z', 'w'], ['z', 'u']]) == True\n assert candidate(s = \"aaaaaaa\",sub = \"aaab\",mappings = [['a', 'b']]) == False\n assert candidate(s = \"aaaaabbbbcccc\",sub = \"abc\",mappings = [['a', 'b'], ['b', 'c'], ['c', 'a']]) == True\n assert candidate(s = \"1234567890qwertyuiopasdfghjklzxcvbnm\",sub = \"QWERTYUIOPASDFGHJKLZXCVBNM\",mappings = [['q', 'Q'], ['w', 'W'], ['e', 'E'], ['r', 'R'], ['t', 'T'], ['y', 'Y'], ['u', 'U'], ['i', 'I'], ['o', 'O'], ['p', 'P'], ['a', 'A'], ['s', 'S'], ['d', 'D'], ['f', 'F'], ['g', 'G'], ['h', 'H'], ['j', 'J'], ['k', 'K'], ['l', 'L'], ['z', 'Z'], ['x', 'X'], ['c', 'C'], ['v', 'V'], ['b', 'B'], ['n', 'N'], ['m', 'M']]) == False\n assert candidate(s = \"1234567890abcdefghijklmnopqrstuvwxyz\",sub = \"123abc\",mappings = [['1', 'a'], ['2', 'b'], ['3', 'c'], ['a', '1'], ['b', '2'], ['c', '3']]) == False\n assert candidate(s = \"mississippi\",sub = \"misp\",mappings = [['i', 's'], ['s', 'i']]) == False\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789\",sub = \"abcdef\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D'], ['e', 'E'], ['f', 'F'], ['0', 'a'], ['1', 'b']]) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",sub = \"zzzzzzzzzzzzzzzz\",mappings = []) == True\n assert candidate(s = \"PythonProgrammingIsFun\",sub = \"PythnPrgrammngIsFn\",mappings = [['o', '0'], ['r', '4'], ['g', '9'], ['m', 'n'], ['n', 'm'], ['u', '1']]) == False\n assert candidate(s = \"abcXYZabcXYZabc\",sub = \"XYZ\",mappings = [['X', 'a'], ['Y', 'b'], ['Z', 'c']]) == True\n assert candidate(s = \"abcXYZ123defGHI456\",sub = \"xyz\",mappings = [['x', 'X'], ['y', 'Y'], ['z', 'Z']]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",sub = \"mnoPQR\",mappings = [['m', 'M'], ['n', 'N'], ['o', 'O'], ['p', 'P'], ['q', 'Q'], ['r', 'R'], ['s', 'S'], ['t', 'T']]) == False\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\",sub = \"qwertyuiopasdfghjklzxcvbnm\",mappings = [['Q', 'q'], ['W', 'w'], ['E', 'e'], ['R', 'r'], ['T', 't'], ['Y', 'y'], ['U', 'u'], ['I', 'i'], ['O', 'o'], ['P', 'p'], ['A', 'a'], ['S', 's'], ['D', 'd'], ['F', 'f'], ['G', 'g'], ['H', 'h'], ['J', 'j'], ['K', 'k'], ['L', 'l'], ['Z', 'z'], ['X', 'x'], ['C', 'c'], ['V', 'v'], ['B', 'b'], ['N', 'n'], ['M', 'm']]) == False\n assert candidate(s = \"xyzabcxyz\",sub = \"zyx\",mappings = [['x', 'y'], ['y', 'z'], ['z', 'x']]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz0123456789\",sub = \"zyxwvutsrqp\",mappings = [['z', '9'], ['y', '8'], ['x', '7'], ['w', '6'], ['v', '5'], ['u', '4'], ['t', '3'], ['s', '2'], ['r', '1'], ['q', '0']]) == False\n assert candidate(s = \"aabbccddeeff\",sub = \"abc\",mappings = [['a', 'b'], ['b', 'c'], ['c', 'd']]) == True\n assert candidate(s = \"9876543210\",sub = \"123\",mappings = [['1', '9'], ['2', '8'], ['3', '7']]) == True\n assert candidate(s = \"mississippi\",sub = \"miss\",mappings = [['m', 'i'], ['i', 's'], ['s', 'p']]) == True\n assert candidate(s = \"mississippi\",sub = \"MISS\",mappings = [['m', 'M'], ['i', 'I'], ['s', 'S']]) == False\n assert candidate(s = \"ababababababab\",sub = \"AB\",mappings = [['a', 'A'], ['b', 'B']]) == False\n assert candidate(s = \"nestedparentheses\",sub = \"nest1dpar3ntheses\",mappings = [['e', '1'], ['o', '3']]) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",sub = \"aaaaaaaaaa\",mappings = [['z', 'a']]) == False\n assert candidate(s = \"abcabcabcabcabcabc\",sub = \"abababa\",mappings = [['a', 'b'], ['b', 'a']]) == False\n assert candidate(s = \"MULTIPLEMAPPINGS\",sub = \"MAPPING\",mappings = [['M', 'N'], ['A', 'B'], ['P', 'Q'], ['I', 'J'], ['G', 'H']]) == True\n assert candidate(s = \"12345678901234567890\",sub = \"111111\",mappings = [['1', '2'], ['2', '3'], ['3', '4'], ['4', '5'], ['5', '6'], ['6', '7']]) == False\n assert candidate(s = \"abracadabra123\",sub = \"acad\",mappings = [['a', '1'], ['d', '3'], ['a', 'b']]) == True\n assert candidate(s = \"TheQuickBrownFox\",sub = \"TheQucikBrwnFks\",mappings = [['u', 'i'], ['i', 'k'], ['B', 'r'], ['r', 'n'], ['F', 'k'], ['o', 'u']]) == False\n assert candidate(s = \"MAPPINGmappings\",sub = \"mapping\",mappings = [['M', 'm'], ['A', 'a'], ['P', 'p'], ['P', 'p'], ['I', 'i'], ['N', 'n'], ['G', 'g']]) == True\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",sub = \"fedcba\",mappings = [['f', 'Z'], ['e', 'Y'], ['d', 'X'], ['c', 'W'], ['b', 'V'], ['a', 'U']]) == False\n assert candidate(s = \"mississippi\",sub = \"missi5\",mappings = [['i', '5']]) == False\n assert candidate(s = \"ababababab\",sub = \"abab\",mappings = [['a', 'b'], ['b', 'a']]) == True\n assert candidate(s = \"xyz123xyz123xyz123\",sub = \"abc\",mappings = [['a', 'x'], ['b', 'y'], ['c', 'z'], ['1', 'a'], ['2', 'b'], ['3', 'c']]) == True\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",sub = \"ABCD123\",mappings = [['E', '1'], ['F', '2'], ['G', '3']]) == False\n assert candidate(s = \"00000000000000000000\",sub = \"1111111111\",mappings = [['0', '1']]) == False\n assert candidate(s = \"abcabcabcabcabcabc\",sub = \"aBc\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C']]) == False\n assert candidate(s = \"HELLOworld\",sub = \"H3LL0\",mappings = [['E', '3'], ['O', '0']]) == False\n assert candidate(s = \"1234567890\",sub = \"123\",mappings = [['1', '9'], ['2', '8'], ['3', '7']]) == True\n assert candidate(s = \"a1b2c3d4e5f6g7h8i9j0\",sub = \"abcdefghij\",mappings = [['a', '1'], ['b', '2'], ['c', '3'], ['d', '4'], ['e', '5'], ['f', '6'], ['g', '7'], ['h', '8'], ['i', '9'], ['j', '0']]) == False\n assert candidate(s = \"abcXYZdefUVW\",sub = \"xyzuvw\",mappings = [['a', 'x'], ['b', 'y'], ['c', 'z'], ['d', 'u'], ['e', 'v'], ['f', 'w']]) == False\n assert candidate(s = \"xyxyxyxyxy\",sub = \"xyz\",mappings = [['x', 'y'], ['y', 'x']]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",sub = \"xyz\",mappings = [['x', 'v'], ['y', 'w'], ['z', 'x']]) == True\n assert candidate(s = \"A1B2C3D4E5F6G7H8I9J0\",sub = \"abcd\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D']]) == False\n assert candidate(s = \"1234567890\",sub = \"abcdefghij\",mappings = [['1', 'a'], ['2', 'b'], ['3', 'c'], ['4', 'd'], ['5', 'e'], ['6', 'f'], ['7', 'g'], ['8', 'h'], ['9', 'i']]) == False\n assert candidate(s = \"abcdefabcdefabcdef\",sub = \"xyz\",mappings = [['a', 'x'], ['b', 'y'], ['c', 'z']]) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",sub = \"zzzz\",mappings = [['z', 'Z'], ['Z', 'z']]) == True\n assert candidate(s = \"aaaaaa\",sub = \"bbbbb\",mappings = [['a', 'b']]) == False\n assert candidate(s = \"abcabcabcabc\",sub = \"abca\",mappings = [['a', 'b'], ['b', 'c'], ['c', 'a']]) == True\n assert candidate(s = \"111222333444555666777888999\",sub = \"123456789\",mappings = [['1', '2'], ['2', '3'], ['3', '4'], ['4', '5'], ['5', '6'], ['6', '7'], ['7', '8'], ['8', '9']]) == False\n assert candidate(s = \"1234567890\",sub = \"123abc\",mappings = [['4', 'a'], ['5', 'b'], ['6', 'c']]) == False\n assert candidate(s = \"abcabcabcabcabc\",sub = \"abdc\",mappings = [['a', 'd'], ['b', 'c']]) == False\n assert candidate(s = \"AAABBBCCCDDD\",sub = \"abc\",mappings = [['A', 'a'], ['B', 'b'], ['C', 'c']]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",sub = \"zyxwvutsrqponmlkjihgfedcba\",mappings = [['a', 'z'], ['b', 'y'], ['c', 'x'], ['d', 'w'], ['e', 'v'], ['f', 'u'], ['g', 't'], ['h', 's'], ['i', 'r'], ['j', 'q'], ['k', 'p'], ['l', 'o'], ['m', 'n']]) == False\n assert candidate(s = \"abcdefghij\",sub = \"abcd12\",mappings = [['e', '1'], ['f', '2'], ['g', '3']]) == False\n assert candidate(s = \"HelloWorld123\",sub = \"hello123\",mappings = [['H', 'h'], ['W', 'w'], ['o', '0'], ['r', '4'], ['l', '1']]) == False\n assert candidate(s = \"aabbccddeeffgg\",sub = \"abc\",mappings = [['a', 'b'], ['b', 'c'], ['c', 'd']]) == True\n assert candidate(s = \"abcdeABCDEabcdeABCDE\",sub = \"abcde\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D'], ['e', 'E']]) == True\n assert candidate(s = \"patternmatching\",sub = \"patt3rn\",mappings = [['a', '3']]) == False\n assert candidate(s = \"abcdefgABCDEFG\",sub = \"aBcDeFg\",mappings = [['a', 'A'], ['b', 'B'], ['c', 'C'], ['d', 'D'], ['e', 'E'], ['f', 'F'], ['g', 'G']]) == True\n assert candidate(s = \"abcdefghijk\",sub = \"abc123\",mappings = [['d', '1'], ['e', '2'], ['f', '3']]) == False\n assert candidate(s = \"zzzzzzzzzz\",sub = \"aaa\",mappings = [['z', 'a']]) == False\n assert candidate(s = \"hello123world456\",sub = \"hell12\",mappings = [['l', '1'], ['o', '2']]) == False\n assert candidate(s = \"helloWorld123\",sub = \"he1oW3ld\",mappings = [['l', '1'], ['o', '0'], ['W', '3'], ['r', '2']]) == False\n assert candidate(s = \"12345678901234567890\",sub = \"12345\",mappings = [['1', '2'], ['2', '3'], ['3', '4'], ['4', '5'], ['5', '6']]) == True\n", "comparison": "exact"}, "public_tests": ["\"fool3e7bar\"\n\"leet\"\n[[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]", "\"fooleetbar\"\n\"f00l\"\n[[\"o\",\"0\"]]", "\"Fool33tbaR\"\n\"leetd\"\n[[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]]"], "hints": ["Enumerate all substrings of s with the same length as sub, and compare each substring to sub for equality.", "How can you quickly tell if a character of s can result from replacing the corresponding character in sub?"], "metadata": {"canonical_parameter_names": ["s", "sub", "mappings"], "leetcode_dataset_entry_point": "Solution().matchReplacement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:03+00:00", "tests_total": 79, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "string", "string-matching"]}, "language": "php", "interface": {"raw_signature": "function matchReplacement($s, $sub, $mappings) {", "container": "Solution", "callable": "matchReplacement", "parameters": [{"name": "s", "type": "String"}, {"name": "sub", "type": "String"}, {"name": "mappings", "type": "String[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2302, "task_id": "count-subarrays-with-score-less-than-k", "difficulty": "Hard", "problem_description": "The score of an array is defined as the product of its sum and its length.\n\n- For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.\n\nGiven a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.\n\nA subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,1,4,3,5], k = 10\nOutput: 6\nExplanation:\nThe 6 subarrays having scores less than 10 are:\n- [2] with score 2 * 1 = 2.\n- [1] with score 1 * 1 = 1.\n- [4] with score 4 * 1 = 4.\n- [3] with score 3 * 1 = 3.\n- [5] with score 5 * 1 = 5.\n- [2,1] with score (2 + 1) * 2 = 6.\nNote that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.\n\nExample 2:\n\nInput: nums = [1,1,1], k = 5\nOutput: 5\nExplanation:\nEvery subarray except [1,1,1] has a score less than 5.\n[1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.\nThus, there are 5 subarrays having scores less than 5.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^5\n- 1 <= k <= 10^15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],k = 100) == 15\n assert candidate(nums = [10, 10, 10],k = 100) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 24\n assert candidate(nums = [1, 1, 1],k = 5) == 5\n assert candidate(nums = [1],k = 2) == 1\n assert candidate(nums = [5, 5, 5, 5],k = 20) == 4\n assert candidate(nums = [10, 20, 30],k = 100) == 4\n assert candidate(nums = [5, 5, 5, 5],k = 25) == 7\n assert candidate(nums = [2, 1, 4, 3, 5],k = 10) == 6\n assert candidate(nums = [10, 5, 2, 6],k = 100) == 10\n assert candidate(nums = [5, 5, 5, 5, 5],k = 25) == 9\n assert candidate(nums = [1, 2, 3, 4, 5],k = 75) == 14\n assert candidate(nums = [10, 20, 30, 40, 50],k = 200) == 10\n assert candidate(nums = [5, 5, 5, 5],k = 15) == 4\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 10) == 19\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000) == 32\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 50) == 19\n assert candidate(nums = [3, 5, 2, 8, 6, 1],k = 25) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 30) == 24\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 30) == 19\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 = 50) == 74\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) == 74\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3],k = 20) == 23\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 100) == 26\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 100) == 34\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 10000) == 54\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 200) == 32\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 100) == 29\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 100) == 34\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 30) == 18\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 100) == 23\n assert candidate(nums = [100, 200, 300, 400, 500],k = 100000) == 15\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],k = 500000000000) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 50) == 24\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 500000) == 55\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 400) == 37\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995],k = 100000000000) == 21\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9],k = 50) == 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],k = 200) == 101\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55],k = 500) == 37\n assert candidate(nums = [3, 5, 7, 2, 8, 10],k = 100) == 17\n assert candidate(nums = [100, 200, 300, 400, 500],k = 10000) == 15\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100000) == 55\n assert candidate(nums = [5, 1, 3, 2, 5, 1, 2],k = 20) == 14\n assert candidate(nums = [9, 7, 5, 3, 1, 9, 7, 5, 3, 1],k = 100) == 34\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 300) == 32\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10000) == 55\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 = 30) == 57\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],k = 999990000000) == 55\n assert candidate(nums = [7, 3, 2, 8, 1, 2, 4],k = 20) == 11\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 20) == 20\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 81) == 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],k = 10) == 57\n assert candidate(nums = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 25) == 22\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 50) == 54\n assert candidate(nums = [3, 2, 1, 4, 5],k = 20) == 10\n assert candidate(nums = [5, 4, 3, 2, 1],k = 15) == 8\n assert candidate(nums = [10, 1, 2, 3, 10, 2, 3, 10, 2, 3],k = 50) == 27\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 150) == 30\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 50000) == 54\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 150) == 38\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 100) == 27\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 11) == 27\n assert candidate(nums = [50, 40, 30, 20, 10],k = 1000) == 15\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 50) == 22\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],k = 100) == 203\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 150) == 29\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 50) == 34\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5000) == 55\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10) == 27\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 500) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 150) == 53\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) == 54\n assert candidate(nums = [10, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 150) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100) == 32\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5000) == 54\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 200) == 61\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 100) == 44\n", "comparison": "exact"}, "public_tests": ["[2,1,4,3,5]\n10", "[1,1,1]\n5"], "hints": ["If we add an element to a list of elements, how will the score change?", "How can we use this to determine the number of subarrays with score less than k in a given range?", "How can we use “Two Pointers” to generalize the solution, and thus count all possible subarrays?"], "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-30T20:48:06+00:00", "tests_total": 79, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "binary-search", "sliding-window", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function countSubarrays($nums, $k) {", "container": "Solution", "callable": "countSubarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2303, "task_id": "calculate-amount-paid-in-taxes", "difficulty": "Easy", "problem_description": "You are given a 0-indexed 2D integer array brackets where brackets[i] = [upper_i, percent_i] means that the i^th tax bracket has an upper bound of upper_i and is taxed at a rate of percent_i. The brackets are sorted by upper bound (i.e. upper_{i-1} < upper_i for 0 < i < brackets.length).\n\nTax is calculated as follows:\n\n- The first upper_0 dollars earned are taxed at a rate of percent_0.\n- The next upper_1 - upper_0 dollars earned are taxed at a rate of percent_1.\n- The next upper_2 - upper_1 dollars earned are taxed at a rate of percent_2.\n- And so on.\n\nYou are given an integer income representing the amount of money you earned. Return the amount of money that you have to pay in taxes. Answers within 10^-5 of the actual answer will be accepted.\n\nExample 1:\n\nInput: brackets = [[3,50],[7,10],[12,25]], income = 10\nOutput: 2.65000\nExplanation:\nBased on your income, you have 3 dollars in the 1^st tax bracket, 4 dollars in the 2^nd tax bracket, and 3 dollars in the 3^rd tax bracket.\nThe tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.\nIn total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.\n\nExample 2:\n\nInput: brackets = [[1,0],[4,25],[5,50]], income = 2\nOutput: 0.25000\nExplanation:\nBased on your income, you have 1 dollar in the 1^st tax bracket and 1 dollar in the 2^nd tax bracket.\nThe tax rate for the two tax brackets is 0% and 25%, respectively.\nIn total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.\n\nExample 3:\n\nInput: brackets = [[2,50]], income = 0\nOutput: 0.00000\nExplanation:\nYou have no income to tax, so you have to pay a total of $0 in taxes.\n\nConstraints:\n\n- 1 <= brackets.length <= 100\n- 1 <= upper_i <= 1000\n- 0 <= percent_i <= 100\n- 0 <= income <= 1000\n- upper_i is sorted in ascending order.\n- All the values of upper_i are unique.\n- The upper bound of the last tax bracket is greater than or equal to income.\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(brackets=[[3, 50], [7, 10], [12, 25]], income=10), 2.65)\n assert answers_match(candidate(brackets=[[5, 10], [10, 20], [15, 30], [20, 40]], income=25), 5.0)\n assert answers_match(candidate(brackets=[[100, 20]], income=50), 10.0)\n assert answers_match(candidate(brackets=[[50, 0], [100, 20], [150, 25]], income=175), 22.5)\n assert answers_match(candidate(brackets=[[1, 100], [2, 50]], income=1), 1.0)\n assert answers_match(candidate(brackets=[[5, 5], [10, 15], [15, 25]], income=15), 2.25)\n assert answers_match(candidate(brackets=[[1, 100]], income=1), 1.0)\n assert answers_match(candidate(brackets=[[2, 50]], income=0), 0.0)\n assert answers_match(candidate(brackets=[[1, 100], [2, 0], [3, 50]], income=1), 1.0)\n assert answers_match(candidate(brackets=[[1, 0], [4, 25], [5, 50]], income=2), 0.25)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30], [40, 40]], income=35), 8.0)\n assert answers_match(candidate(brackets=[[1, 1], [2, 2], [3, 3]], income=3), 0.06)\n assert answers_match(candidate(brackets=[[1, 100], [2, 50], [3, 25]], income=1), 1.0)\n assert answers_match(candidate(brackets=[[10, 20], [20, 30], [30, 40]], income=15), 3.5)\n assert answers_match(candidate(brackets=[[5, 50], [10, 30], [15, 20]], income=12), 4.4)\n assert answers_match(candidate(brackets=[[500, 10], [1000, 20]], income=750), 100.0)\n assert answers_match(candidate(brackets=[[10, 50]], income=10), 5.0)\n assert answers_match(candidate(brackets=[[50, 10], [100, 20], [150, 30]], income=75), 10.0)\n assert answers_match(candidate(brackets=[[10, 20], [20, 30], [30, 25]], income=25), 6.25)\n assert answers_match(candidate(brackets=[[100, 5]], income=100), 5.0)\n assert answers_match(candidate(brackets=[[100, 10]], income=100), 10.0)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30]], income=15), 2.0)\n assert answers_match(candidate(brackets=[[1, 1], [2, 2], [3, 3], [4, 4]], income=4), 0.1)\n assert answers_match(candidate(brackets=[[100, 10]], income=50), 5.0)\n assert answers_match(candidate(brackets=[[500, 10], [750, 20], [1000, 30]], income=1000), 175.0)\n assert answers_match(candidate(brackets=[[5, 100]], income=5), 5.0)\n assert answers_match(candidate(brackets=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], income=5), 0.15)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30]], income=25), 4.5)\n assert answers_match(candidate(brackets=[[3, 0], [6, 10], [9, 20]], income=9), 0.9)\n assert answers_match(candidate(brackets=[[1, 100], [2, 100], [3, 100]], income=3), 3.0)\n assert answers_match(candidate(brackets=[[50, 10], [100, 20], [200, 30], [500, 40]], income=400), 125.0)\n assert answers_match(candidate(brackets=[[100, 10], [200, 20], [300, 30], [400, 40]], income=350), 80.0)\n assert answers_match(candidate(brackets=[[10, 0], [20, 10], [30, 20], [40, 30], [50, 40], [60, 50]], income=60), 15.0)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]], income=45), 12.5)\n assert answers_match(candidate(brackets=[[500, 25], [1000, 30]], income=800), 215.0)\n assert answers_match(candidate(brackets=[[5, 0], [10, 5], [15, 10], [20, 15], [25, 20]], income=18), 1.2)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20]], income=25), 2.25)\n assert answers_match(candidate(brackets=[[50, 1], [100, 2], [150, 3], [200, 4], [250, 5]], income=100), 1.5)\n assert answers_match(candidate(brackets=[[5, 25], [15, 50], [25, 75], [35, 100]], income=35), 23.75)\n assert answers_match(candidate(brackets=[[100, 25], [200, 30], [300, 35]], income=250), 72.5)\n assert answers_match(candidate(brackets=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]], income=10), 5.5)\n assert answers_match(candidate(brackets=[[10, 0], [20, 5], [30, 10], [40, 15], [50, 20], [60, 25]], income=55), 6.25)\n assert answers_match(candidate(brackets=[[100, 5], [200, 10], [300, 15], [400, 20], [500, 25]], income=500), 75.0)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30], [40, 40]], income=25), 4.5)\n assert answers_match(candidate(brackets=[[100, 10], [200, 20], [300, 30], [400, 40], [500, 50], [600, 60], [700, 70], [800, 80], [900, 90], [1000, 100]], income=1000), 550.0)\n assert answers_match(candidate(brackets=[[150, 5], [250, 10], [350, 15], [450, 20], [550, 25]], income=600), 77.5)\n assert answers_match(candidate(brackets=[[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]], income=45), 1.25)\n assert answers_match(candidate(brackets=[[100, 5], [150, 10], [200, 15], [250, 20], [300, 25], [350, 30], [400, 35], [450, 40], [500, 45]], income=499), 114.55)\n assert answers_match(candidate(brackets=[[100, 15], [200, 25], [300, 35], [400, 45]], income=350), 97.5)\n assert answers_match(candidate(brackets=[[500, 1], [1000, 2]], income=750), 10.0)\n assert answers_match(candidate(brackets=[[50, 5], [150, 15], [300, 25]], income=200), 30.0)\n assert answers_match(candidate(brackets=[[50, 15], [100, 20], [150, 25], [200, 30]], income=175), 37.5)\n assert answers_match(candidate(brackets=[[10, 50], [20, 75], [30, 100]], income=10), 5.0)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35]], income=65), 12.25)\n assert answers_match(candidate(brackets=[[1, 100]], income=1000), 1.0)\n assert answers_match(candidate(brackets=[[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60], [65, 70], [75, 80], [85, 90], [95, 100]], income=100), 54.5)\n assert answers_match(candidate(brackets=[[200, 10], [400, 20], [600, 30], [800, 40], [1000, 50]], income=750), 180.0)\n assert answers_match(candidate(brackets=[[100, 0], [200, 5], [300, 10], [400, 15], [500, 20]], income=0), 0.0)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]], income=30), 3.0)\n assert answers_match(candidate(brackets=[[100, 10], [200, 20], [300, 30], [400, 40], [500, 50]], income=450), 125.0)\n assert answers_match(candidate(brackets=[[100, 5], [200, 10], [300, 15], [400, 20], [500, 25], [600, 30], [700, 35], [800, 40], [900, 45], [1000, 50]], income=800), 180.0)\n assert answers_match(candidate(brackets=[[10, 25], [20, 25], [30, 25], [40, 25], [50, 25]], income=40), 10.0)\n assert answers_match(candidate(brackets=[[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]], income=25), 0.45)\n assert answers_match(candidate(brackets=[[10, 100], [20, 100], [30, 100], [40, 100], [50, 100]], income=45), 45.0)\n assert answers_match(candidate(brackets=[[50, 0], [100, 10], [150, 20], [200, 30], [250, 40]], income=250), 50.0)\n assert answers_match(candidate(brackets=[[1, 2], [2, 4], [3, 6], [4, 8], [5, 10]], income=5), 0.3)\n assert answers_match(candidate(brackets=[[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]], income=400), 10.0)\n assert answers_match(candidate(brackets=[[10, 10], [50, 20], [100, 30], [200, 40], [500, 50]], income=600), 214.0)\n assert answers_match(candidate(brackets=[[50, 1], [100, 2], [150, 3], [200, 4], [250, 5], [300, 6]], income=175), 4.0)\n assert answers_match(candidate(brackets=[[15, 0], [30, 10], [45, 20], [60, 30], [75, 40]], income=70), 13.0)\n assert answers_match(candidate(brackets=[[10, 50], [20, 40], [30, 30], [40, 20], [50, 10]], income=50), 15.0)\n assert answers_match(candidate(brackets=[[10, 50], [20, 40], [30, 30], [40, 20], [50, 10]], income=45), 14.5)\n assert answers_match(candidate(brackets=[[50, 0], [100, 5], [150, 10], [200, 15], [250, 20], [300, 25]], income=120), 4.5)\n assert answers_match(candidate(brackets=[[10, 25], [20, 25], [30, 25], [40, 25], [50, 25], [60, 25], [70, 25], [80, 25], [90, 25], [100, 25]], income=95), 23.75)\n assert answers_match(candidate(brackets=[[10, 50], [20, 50], [30, 50], [40, 50], [50, 50], [60, 50], [70, 50], [80, 50], [90, 50], [100, 50]], income=55), 27.5)\n assert answers_match(candidate(brackets=[[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]], income=100), 5.5)\n assert answers_match(candidate(brackets=[[1000, 100]], income=1000), 1000.0)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]], income=85), 20.25)\n assert answers_match(candidate(brackets=[[10, 0], [20, 0], [30, 0], [40, 0], [50, 0]], income=50), 0.0)\n assert answers_match(candidate(brackets=[[5, 10], [15, 15], [25, 20], [35, 25], [45, 30]], income=30), 5.25)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15]], income=5), 0.25)\n assert answers_match(candidate(brackets=[[50, 10], [100, 20], [150, 30], [200, 40], [250, 50]], income=300), 75.0)\n assert answers_match(candidate(brackets=[[50, 10], [100, 20], [150, 30], [200, 40], [250, 50]], income=220), 60.0)\n assert answers_match(candidate(brackets=[[2, 5], [5, 10], [10, 20], [20, 30], [50, 40]], income=30), 8.4)\n assert answers_match(candidate(brackets=[[10, 0], [20, 10], [30, 20], [40, 30], [50, 40], [60, 50], [70, 60], [80, 70], [90, 80], [100, 90]], income=95), 40.5)\n assert answers_match(candidate(brackets=[[300, 5], [600, 10], [900, 15]], income=900), 90.0)\n assert answers_match(candidate(brackets=[[100, 10], [200, 20], [300, 30], [400, 40], [500, 50], [600, 60]], income=650), 210.0)\n assert answers_match(candidate(brackets=[[5, 0], [10, 10], [15, 20], [20, 30], [25, 40]], income=25), 5.0)\n assert answers_match(candidate(brackets=[[100, 15], [200, 25], [300, 35], [400, 45], [500, 55]], income=600), 175.0)\n assert answers_match(candidate(brackets=[[10, 100], [20, 90], [30, 80], [40, 70], [50, 60]], income=15), 14.5)\n assert answers_match(candidate(brackets=[[200, 15], [400, 25], [600, 30]], income=550), 125.0)\n assert answers_match(candidate(brackets=[[10, 25], [20, 35], [30, 45], [40, 55], [50, 65]], income=35), 13.25)\n assert answers_match(candidate(brackets=[[10, 15], [20, 25], [30, 35], [40, 45], [50, 55]], income=50), 17.5)\n assert answers_match(candidate(brackets=[[1, 100], [2, 90], [3, 80], [4, 70], [5, 60]], income=5), 4.0)\n assert answers_match(candidate(brackets=[[10, 0], [20, 5], [30, 10], [40, 15], [50, 20], [60, 25], [70, 30], [80, 35], [90, 40], [100, 45]], income=50), 5.0)\n assert answers_match(candidate(brackets=[[30, 5], [60, 10], [90, 15], [120, 20], [150, 25]], income=150), 22.5)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]], income=100), 55.0)\n assert answers_match(candidate(brackets=[[10, 0], [20, 5], [30, 10], [40, 15], [50, 20]], income=40), 3.0)\n assert answers_match(candidate(brackets=[[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]], income=10), 0.55)\n assert answers_match(candidate(brackets=[[50, 5], [150, 10], [250, 15], [350, 20], [450, 25], [550, 30]], income=300), 37.5)\n assert answers_match(candidate(brackets=[[10, 100], [20, 0], [30, 100], [40, 0]], income=35), 20.0)\n assert answers_match(candidate(brackets=[[5, 10], [15, 20], [25, 30], [35, 40], [45, 50], [55, 60]], income=55), 20.5)\n assert answers_match(candidate(brackets=[[100, 10], [200, 20], [300, 30], [400, 40], [500, 50]], income=500), 150.0)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30], [70, 35], [80, 40], [90, 45], [100, 50]], income=100), 27.5)\n assert answers_match(candidate(brackets=[[50, 5], [150, 15], [250, 25], [350, 35], [450, 45]], income=450), 122.5)\n assert answers_match(candidate(brackets=[[200, 10], [500, 20], [800, 30], [1000, 40]], income=750), 155.0)\n assert answers_match(candidate(brackets=[[100, 0], [200, 0], [300, 0], [400, 0], [500, 0]], income=500), 0.0)\n assert answers_match(candidate(brackets=[[100, 5], [200, 10], [300, 15], [400, 20], [500, 25], [600, 30]], income=600), 105.0)\n assert answers_match(candidate(brackets=[[100, 0], [200, 5], [300, 10], [400, 15], [500, 20], [600, 25]], income=150), 2.5)\n assert answers_match(candidate(brackets=[[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60]], income=6), 2.1)\n assert answers_match(candidate(brackets=[[10, 5], [20, 10], [30, 15], [40, 20], [50, 25]], income=45), 6.25)\n assert answers_match(candidate(brackets=[[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]], income=35), 8.0)\n assert answers_match(candidate(brackets=[[1, 100], [10, 90], [100, 80], [1000, 70]], income=500), 361.1)\n assert answers_match(candidate(brackets=[[100, 5], [200, 10], [300, 15], [400, 20], [500, 25], [600, 30], [700, 35], [800, 40], [900, 45], [1000, 50]], income=950), 250.0)\n assert answers_match(candidate(brackets=[[50, 5], [100, 15], [200, 25], [300, 35]], income=250), 52.5)\n assert answers_match(candidate(brackets=[[100, 5], [200, 10], [300, 15], [400, 20], [500, 25], [600, 30], [700, 35], [800, 40], [900, 45], [1000, 50]], income=999), 274.5)\n assert answers_match(candidate(brackets=[[5, 10], [10, 20], [15, 30], [20, 40], [25, 50]], income=18), 4.2)\n", "comparison": "float"}, "public_tests": ["[[3,50],[7,10],[12,25]]\n10", "[[1,0],[4,25],[5,50]]\n2", "[[2,50]]\n0"], "hints": ["As you iterate through the tax brackets, keep track of the previous tax bracket’s upper bound in a variable called prev. If there is no previous tax bracket, use 0 instead.", "The amount of money in the ith tax bracket is min(income, upperi) - prev."], "metadata": {"canonical_parameter_names": ["brackets", "income"], "leetcode_dataset_entry_point": "Solution().calculateTax", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:08+00:00", "tests_total": 122, "tests_dropped": 5, "flags": ["decimal_answer"], "topic_tags": ["array", "simulation"]}, "language": "php", "interface": {"raw_signature": "function calculateTax($brackets, $income) {", "container": "Solution", "callable": "calculateTax", "parameters": [{"name": "brackets", "type": "Integer[][]"}, {"name": "income", "type": "Integer"}], "return_type": "Float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2304, "task_id": "minimum-path-cost-in-a-grid", "difficulty": "Medium", "problem_description": "You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1, you can move to any of the cells (x + 1, 0), (x + 1, 1), ..., (x + 1, n - 1). Note that it is not possible to move from cells in the last row.\n\nEach possible move has a cost given by a 0-indexed 2D array moveCost of size (m * n) x n, where moveCost[i][j] is the cost of moving from a cell with value i to a cell in column j of the next row. The cost of moving from cells in the last row of grid can be ignored.\n\nThe cost of a path in grid is the sum of all values of cells visited plus the sum of costs of all the moves made. Return the minimum cost of a path that starts from any cell in the first row and ends at any cell in the last row.\n\nExample 1:\n\nInput: grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]\nOutput: 17\nExplanation: The path with the minimum possible cost is the path 5 -> 0 -> 1.\n- The sum of the values of cells visited is 5 + 0 + 1 = 6.\n- The cost of moving from 5 to 0 is 3.\n- The cost of moving from 0 to 1 is 8.\nSo the total cost of the path is 6 + 3 + 8 = 17.\n\nExample 2:\n\nInput: grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]\nOutput: 6\nExplanation: The path with the minimum possible cost is the path 2 -> 3.\n- The sum of the values of cells visited is 2 + 3 = 5.\n- The cost of moving from 2 to 3 is 1.\nSo the total cost of this path is 5 + 1 = 6.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 50\n- grid consists of distinct integers from 0 to m * n - 1.\n- moveCost.length == m * n\n- moveCost[i].length == n\n- 1 <= moveCost[i][j] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],moveCost = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 26, 27]]) == 29\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],moveCost = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) == 9\n assert candidate(grid = [[0, 1], [2, 3]],moveCost = [[9, 8], [1, 5], [10, 12], [18, 6]]) == 4\n assert candidate(grid = [[5, 3], [4, 0], [2, 1]],moveCost = [[9, 8], [1, 5], [10, 12], [18, 6], [2, 4], [14, 3]]) == 17\n assert candidate(grid = [[5, 1, 2], [4, 0, 3]],moveCost = [[12, 10, 15], [20, 23, 8], [21, 7, 1], [8, 1, 13], [9, 10, 25], [5, 3, 2]]) == 6\n assert candidate(grid = [[1, 3, 5], [2, 8, 4], [6, 7, 9], [10, 12, 11]],moveCost = [[2, 3, 4], [1, 6, 5], [8, 9, 7], [3, 2, 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]]) == 38\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],moveCost = [[1, 2, 3, 4, 5], [6, 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]]) == 55\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]],moveCost = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 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 = [[1, 10, 3, 4], [2, 5, 6, 7], [8, 9, 2, 11], [12, 13, 14, 15]],moveCost = [[1, 2, 3, 4], [5, 6, 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]]) == 42\n assert candidate(grid = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20]],moveCost = [[1, 2, 3, 4, 5], [6, 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]]) == 43\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],moveCost = [[1, 2, 3], [4, 5, 6], [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]]) == 61\n assert candidate(grid = [[1, 3, 2, 4], [2, 4, 3, 1], [3, 1, 4, 2], [4, 2, 1, 3]],moveCost = [[1, 2, 3, 4], [5, 6, 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]]) == 25\n assert candidate(grid = [[1, 3, 5], [2, 4, 6], [7, 8, 9]],moveCost = [[3, 5, 2], [1, 3, 4], [6, 2, 5], [4, 1, 3], [2, 5, 1], [7, 2, 4], [3, 6, 2], [5, 1, 4], [2, 3, 1]]) == 14\n", "comparison": "exact"}, "public_tests": ["[[5,3],[4,0],[2,1]]\n[[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]", "[[5,1,2],[4,0,3]]\n[[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]"], "hints": ["What is the optimal cost to get to each of the cells in the second row? What about the third row?", "Use dynamic programming to compute the optimal cost to get to each cell."], "metadata": {"canonical_parameter_names": ["grid", "moveCost"], "leetcode_dataset_entry_point": "Solution().minPathCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:10+00:00", "tests_total": 28, "tests_dropped": 15, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "php", "interface": {"raw_signature": "function minPathCost($grid, $moveCost) {", "container": "Solution", "callable": "minPathCost", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "moveCost", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2305, "task_id": "fair-distribution-of-cookies", "difficulty": "Medium", "problem_description": "You are given an integer array cookies, where cookies[i] denotes the number of cookies in the i^th bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.\n\nThe unfairness of a distribution is defined as the maximum total cookies obtained by a single child in the distribution.\n\nReturn the minimum unfairness of all distributions.\n\nExample 1:\n\nInput: cookies = [8,15,10,20,8], k = 2\nOutput: 31\nExplanation: One optimal distribution is [8,15,8] and [10,20]\n- The 1^st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.\n- The 2^nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.\nThe unfairness of the distribution is max(31,30) = 31.\nIt can be shown that there is no distribution with an unfairness less than 31.\n\nExample 2:\n\nInput: cookies = [6,1,3,2,2,4,1,2], k = 3\nOutput: 7\nExplanation: One optimal distribution is [6,1], [3,2,2], and [4,1,2]\n- The 1^st child receives [6,1] which has a total of 6 + 1 = 7 cookies.\n- The 2^nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.\n- The 3^rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.\nThe unfairness of the distribution is max(7,7,7) = 7.\nIt can be shown that there is no distribution with an unfairness less than 7.\n\nConstraints:\n\n- 2 <= cookies.length <= 8\n- 1 <= cookies[i] <= 10^5\n- 2 <= k <= cookies.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 100000],k = 7) == 100000\n assert candidate(cookies = [8, 15, 10, 20, 8],k = 2) == 31\n assert candidate(cookies = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 8) == 100000\n assert candidate(cookies = [1, 100000, 1, 1, 1, 1, 1, 1],k = 3) == 100000\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 2) == 180\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 8) == 80\n assert candidate(cookies = [1, 3, 2, 4, 5, 6, 7, 8],k = 2) == 18\n assert candidate(cookies = [100000, 1, 1, 1, 1, 1, 1, 1],k = 2) == 100000\n assert candidate(cookies = [5, 5, 5, 5, 5, 5, 5, 5],k = 8) == 5\n assert candidate(cookies = [2, 2, 2, 2, 2, 2, 2, 2],k = 2) == 8\n assert candidate(cookies = [6, 1, 3, 2, 2, 4, 1, 2],k = 3) == 7\n assert candidate(cookies = [8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 9\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == 9\n assert candidate(cookies = [100000, 1, 1, 1, 1, 1, 1, 1],k = 7) == 100000\n assert candidate(cookies = [5, 5, 5, 5, 5, 5, 5, 5],k = 2) == 20\n assert candidate(cookies = [8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 18\n assert candidate(cookies = [15, 20, 25, 30, 35, 40, 45, 50],k = 7) == 50\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 7) == 8\n assert candidate(cookies = [9, 8, 7, 6, 5, 4, 3, 2],k = 5) == 9\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 5) == 800\n assert candidate(cookies = [1, 1, 2, 2, 3, 3, 4, 4],k = 5) == 4\n assert candidate(cookies = [7, 14, 21, 28, 35, 42, 49, 56],k = 2) == 126\n assert candidate(cookies = [80, 70, 60, 50, 40, 30, 20, 10],k = 4) == 90\n assert candidate(cookies = [1, 1, 2, 2, 3, 3, 4, 4],k = 2) == 10\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 4) == 90\n assert candidate(cookies = [12, 11, 10, 9, 8, 7, 6, 5],k = 3) == 23\n assert candidate(cookies = [100, 200, 300, 150, 50, 25, 25, 50],k = 4) == 300\n assert candidate(cookies = [30, 20, 10, 40, 60, 50, 70, 80],k = 5) == 80\n assert candidate(cookies = [30, 20, 10, 20, 30, 20, 10, 20],k = 5) == 40\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 5) == 80\n assert candidate(cookies = [100000, 1, 2, 3, 4, 5, 6, 7],k = 2) == 100000\n assert candidate(cookies = [1, 10, 100, 1000, 10000, 100000, 5, 50],k = 5) == 100000\n assert candidate(cookies = [9, 6, 12, 4, 7, 11, 5, 3],k = 4) == 15\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 1],k = 4) == 2\n assert candidate(cookies = [9, 9, 9, 9, 9, 9, 9, 9],k = 4) == 18\n assert candidate(cookies = [1, 2, 4, 8, 16, 32, 64, 128],k = 5) == 128\n assert candidate(cookies = [10, 10, 10, 10, 10, 10, 10, 10],k = 7) == 20\n assert candidate(cookies = [18, 23, 45, 12, 34, 56, 78, 90],k = 3) == 123\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 6) == 800\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 4) == 900\n assert candidate(cookies = [8, 1, 5, 7, 3, 6, 4, 2],k = 3) == 12\n assert candidate(cookies = [9, 8, 7, 6, 5, 4, 3, 2],k = 6) == 9\n assert candidate(cookies = [16, 14, 12, 10, 8, 6, 4, 2],k = 4) == 18\n assert candidate(cookies = [5, 10, 15, 20, 25, 30, 35, 40],k = 5) == 40\n assert candidate(cookies = [5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 15\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 7) == 8\n assert candidate(cookies = [9, 18, 27, 36, 45, 54, 63, 72],k = 4) == 81\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 1],k = 8) == 1\n assert candidate(cookies = [15, 14, 13, 12, 11, 10, 9, 8],k = 4) == 23\n assert candidate(cookies = [15, 25, 35, 45, 55, 65, 75, 85],k = 5) == 85\n assert candidate(cookies = [12, 11, 10, 9, 8, 7, 6, 5],k = 2) == 34\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 1],k = 3) == 3\n assert candidate(cookies = [30, 20, 10, 10, 20, 30, 40, 50],k = 5) == 50\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 3) == 120\n assert candidate(cookies = [15, 15, 15, 15, 15, 15, 15, 15],k = 7) == 30\n assert candidate(cookies = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],k = 8) == 8000\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 1],k = 8) == 1\n assert candidate(cookies = [8, 16, 32, 64, 128, 256, 512, 1024],k = 2) == 1024\n assert candidate(cookies = [30, 20, 10, 60, 50, 40, 70, 80],k = 5) == 80\n assert candidate(cookies = [5, 10, 15, 20, 25, 30, 35, 40],k = 6) == 40\n assert candidate(cookies = [9, 3, 10, 12, 8, 15, 5, 7],k = 3) == 24\n assert candidate(cookies = [3, 1, 2, 4, 5, 6, 7, 8],k = 4) == 9\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 4) == 9\n assert candidate(cookies = [12, 17, 22, 14, 29, 18, 15, 20],k = 4) == 41\n assert candidate(cookies = [1, 2, 4, 8, 16, 32, 64, 128],k = 3) == 128\n assert candidate(cookies = [100, 100, 100, 100, 100, 100, 100, 100],k = 5) == 200\n assert candidate(cookies = [12, 23, 34, 45, 56, 67, 78, 89],k = 3) == 135\n assert candidate(cookies = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k = 4) == 200000\n assert candidate(cookies = [10, 20, 30, 40, 50, 60, 70, 80],k = 6) == 80\n assert candidate(cookies = [7, 8, 9, 10, 11, 12, 13, 14],k = 6) == 17\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 3) == 1200\n assert candidate(cookies = [8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 8\n assert candidate(cookies = [8, 15, 10, 20, 8, 5, 3, 7],k = 3) == 26\n assert candidate(cookies = [5, 15, 25, 35, 45, 55, 65, 75],k = 3) == 110\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 8\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 4) == 900\n assert candidate(cookies = [15, 15, 15, 15, 15, 15, 15, 15],k = 6) == 30\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 5) == 800\n assert candidate(cookies = [2, 4, 6, 8, 10, 12, 14, 16],k = 3) == 24\n assert candidate(cookies = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000],k = 2) == 18000\n assert candidate(cookies = [50, 40, 30, 20, 10, 5, 3, 1],k = 4) == 50\n assert candidate(cookies = [5, 5, 15, 15, 25, 25, 35, 35],k = 4) == 40\n assert candidate(cookies = [15, 15, 15, 15, 15, 15, 15, 15],k = 2) == 60\n assert candidate(cookies = [2, 2, 2, 2, 2, 2, 2, 2],k = 7) == 4\n assert candidate(cookies = [25, 25, 25, 25, 25, 25, 25, 25],k = 8) == 25\n assert candidate(cookies = [8, 15, 10, 20, 8, 12, 15, 10],k = 3) == 33\n assert candidate(cookies = [8, 1, 2, 3, 4, 5, 6, 7],k = 2) == 18\n assert candidate(cookies = [10, 20, 10, 20, 10, 20, 10, 20],k = 4) == 30\n assert candidate(cookies = [50, 40, 30, 20, 10, 1, 2, 3],k = 3) == 53\n assert candidate(cookies = [1, 1, 2, 2, 3, 3, 4, 4],k = 4) == 5\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 8) == 8\n assert candidate(cookies = [1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 4\n assert candidate(cookies = [1, 2, 3, 4, 5, 6, 7, 8],k = 3) == 12\n assert candidate(cookies = [10, 10, 20, 20, 30, 30, 40, 40],k = 4) == 50\n assert candidate(cookies = [9, 18, 27, 36, 45, 54, 63, 72],k = 4) == 81\n assert candidate(cookies = [8, 1, 2, 3, 4, 5, 6, 7],k = 8) == 8\n assert candidate(cookies = [100, 200, 300, 400, 500, 600, 700, 800],k = 7) == 800\n", "comparison": "exact"}, "public_tests": ["[8,15,10,20,8]\n2", "[6,1,3,2,2,4,1,2]\n3"], "hints": ["We have to give each bag to one of the children. How can we enumerate all of the possibilities?", "Use recursion and keep track of the current number of cookies each child has. Once all the bags have been distributed, find the child with the most cookies."], "metadata": {"canonical_parameter_names": ["cookies", "k"], "leetcode_dataset_entry_point": "Solution().distributeCookies", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:13+00:00", "tests_total": 104, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "dynamic-programming", "backtracking", "bit-manipulation", "bitmask"]}, "language": "php", "interface": {"raw_signature": "function distributeCookies($cookies, $k) {", "container": "Solution", "callable": "distributeCookies", "parameters": [{"name": "cookies", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2306, "task_id": "naming-a-company", "difficulty": "Hard", "problem_description": "You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:\n\n1. Choose 2 distinct names from ideas, call them idea_A and idea_B.\n2. Swap the first letters of idea_A and idea_B with each other.\n3. If both of the new names are not found in the original ideas, then the name idea_A idea_B (the concatenation of idea_A and idea_B, separated by a space) is a valid company name.\n4. Otherwise, it is not a valid name.\n\nReturn the number of distinct valid names for the company.\n\nExample 1:\n\nInput: ideas = [\"coffee\",\"donuts\",\"time\",\"toffee\"]\nOutput: 6\nExplanation: The following selections are valid:\n- (\"coffee\", \"donuts\"): The company name created is \"doffee conuts\".\n- (\"donuts\", \"coffee\"): The company name created is \"conuts doffee\".\n- (\"donuts\", \"time\"): The company name created is \"tonuts dime\".\n- (\"donuts\", \"toffee\"): The company name created is \"tonuts doffee\".\n- (\"time\", \"donuts\"): The company name created is \"dime tonuts\".\n- (\"toffee\", \"donuts\"): The company name created is \"doffee tonuts\".\nTherefore, there are a total of 6 distinct company names.\n\nThe following are some examples of invalid selections:\n- (\"coffee\", \"time\"): The name \"toffee\" formed after swapping already exists in the original array.\n- (\"time\", \"toffee\"): Both names are still the same after swapping and exist in the original array.\n- (\"coffee\", \"toffee\"): Both names formed after swapping already exist in the original array.\n\nExample 2:\n\nInput: ideas = [\"lack\",\"back\"]\nOutput: 0\nExplanation: There are no valid selections. Therefore, 0 is returned.\n\nConstraints:\n\n- 2 <= ideas.length <= 5 * 10^4\n- 1 <= ideas[i].length <= 10\n- ideas[i] consists of lowercase English letters.\n- All the strings in ideas are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(ideas = ['coffee', 'donuts', 'time', 'toffee']) == 6\n assert candidate(ideas = ['aaa', 'bbb', 'ccc']) == 6\n assert candidate(ideas = ['abc', 'bcd', 'cde', 'dec']) == 12\n assert candidate(ideas = ['abcd', 'dcba', 'ddda', 'dccd']) == 6\n assert candidate(ideas = ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc']) == 0\n assert candidate(ideas = ['aaa', 'bbb', 'ccc', 'ddd']) == 12\n assert candidate(ideas = ['lack', 'back']) == 0\n assert candidate(ideas = ['aaa', 'bbb', 'ccc', 'aab', 'abb', 'abc']) == 10\n assert candidate(ideas = ['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(ideas = ['ana', 'anna', 'nana', 'ann', 'nan']) == 12\n assert candidate(ideas = ['aaa', 'baa', 'caa']) == 0\n assert candidate(ideas = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 0\n assert candidate(ideas = ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc']) == 0\n assert candidate(ideas = ['aa', 'bb', 'cc', 'ac', 'ba', 'ab', 'ad', 'da', 'bd', 'db']) == 10\n assert candidate(ideas = ['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', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', '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']) == 5552\n assert candidate(ideas = ['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', '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', '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', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 10002\n assert candidate(ideas = ['axx', 'bxx', 'cxx', 'dxx', 'exx', 'fxx', 'gxx', 'hxx', 'ixx', 'jxx', 'kxx', 'lxx', 'mxx', 'nxx', 'oxx', 'pxx', 'qxx', 'rxx', 'sxx', 'txx', 'uxx', 'vxx', 'wxx', 'xxx', 'yxx', 'zxx']) == 0\n assert candidate(ideas = ['abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'axa', 'bxb', 'cxc', 'dxd', 'eye', 'fzf', 'gag', 'hah', 'ibi', 'jij', 'kjk', 'lll', 'mmm', 'nnn', 'ooo', 'ppp', 'qqq', 'rrr', 'sss', 'ttt', 'uuu', 'vvv', 'www', 'xxx', 'yyy', 'zzz']) == 2390\n assert candidate(ideas = ['aabb', 'abbb', 'acbb', 'adbb', 'aebb', 'afbb', 'agbb', 'ahbb', 'aibb', 'ajbb', 'akbb', 'albb', 'ambb', 'anbb', 'aobb', 'apbb', 'aqbb', 'arbb', 'asbb', 'atbb', 'aubb', 'avbb', 'awbb', 'axbb', 'aybb', 'azbb', 'baab', 'bbab', 'bcab', 'bdab', 'beab', 'bfab', 'bgab', 'bhab', 'biab', 'bjab', 'bkab', 'blab', 'bmba', 'bnab', 'boab', 'bpab', 'bqab', 'brab', 'bsab', 'btab', 'buab', 'bvab', 'bwab', 'bxab', 'byab', 'bzab', 'caab', 'cbab', 'ccab', 'cdba', 'ceab', 'cfab', 'cgab', 'chab', 'ciab', 'cjab', 'ckab', 'clab', 'cmba', 'cnab', 'coab', 'cpab', 'cqab', 'crab', 'csab', 'ctab', 'cuab', 'cvab', 'cwab', 'cxab', 'cyab', 'czab', 'daab', 'dbab', 'dcab', 'ddab', 'deab', 'dfab', 'dgab', 'dhab', 'diab', 'djab', 'dkab', 'dlab', 'dmab', 'dnab', 'doab', 'dpab', 'dqab', 'drab', 'dsab', 'dtab', 'duab', 'dvab', 'dwab', 'dxab', 'dyab', 'dzab', 'eaab', 'ebab', 'ecab', 'edab', 'eeab', 'efab', 'egab', 'ehab', 'eiab', 'ejab', 'ekab', 'elab', 'emab', 'enab', 'eoab', 'epab', 'eqab', 'erab', 'esab', 'etab', 'euab', 'evab', 'ewab', 'exab', 'eyab', 'ezab', 'faab', 'fbab', 'fcab', 'fdab', 'feab', 'ffab', 'fgab', 'fhab', 'fiab', 'fjab', 'fkab', 'flab', 'fmab', 'fnab', 'foab', 'fpab', 'fqab', 'frab', 'fsab', 'ftab', 'fuab', 'fvab', 'fwab', 'fxab', 'fyab', 'fzab']) == 6792\n assert candidate(ideas = ['aabb', 'abba', 'bbaa', 'baab', 'abab', 'baba', 'abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba', 'aaaa', 'bbbb', 'cccc', 'dddd', 'aabbcc', 'bbccaa', 'ccaabb', 'aabbaa', 'bbccbb', 'ccaaca']) == 1182\n assert candidate(ideas = ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc', 'ddd', 'dee', 'def', 'deg', 'dih', 'dii', 'dij', 'dka', 'dkb', 'dkc', 'dla', 'dlb', 'dlc', 'dma', 'dmb', 'dmc', 'dna', 'dnb', 'dnc', 'doa', 'dob', 'doc', 'doea', 'doeb', 'doec', 'dofa', 'dobf', 'docf']) == 1512\n assert candidate(ideas = ['aabc', 'abac', 'abbc', 'acbc', 'adbc', 'aebc', 'afbc', 'agbc', 'ahbc', 'aibc', 'ajbc', 'akbc', 'albc', 'ambc', 'anbc', 'aobc', 'apbc', 'aqbc', 'arbc', 'asbc', 'atbc', 'aubc', 'avbc', 'awbc', 'axbc', 'aybc', 'azbc', 'baaa', 'baab', 'baac', 'baad', 'baae', 'baaf', 'baag', 'baah', 'baai', 'baaj', 'baak', 'baal', 'baam', 'baan', 'baao', 'baap', 'baaq', 'baar', 'baas', 'baat', 'baau', 'baav', 'baaw', 'baax', 'baay', 'baaz']) == 1404\n assert candidate(ideas = ['apple', 'apricot', 'banana', 'blueberry', 'cherry', 'cranberry', 'grape', 'guava', 'kiwi', 'lemon', 'lime', 'mango', 'melon', 'orange', 'papaya', 'peach', 'pear', 'plum', 'raspberry', 'strawberry', 'tangerine', 'watermelon']) == 438\n assert candidate(ideas = ['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', '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', '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', 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'fffff', 'ggggg', 'hhhhh', 'iiiii', 'jjjjj', 'kkkkk', 'lllll', 'mmmmm', 'nnnnn', 'ooooo', 'ppppp', 'qqqqq', 'rrrrr', 'sssss', 'ttttt', 'uuuuu', 'vvvvv', 'wwwww', 'xxxxx', 'yyyyy', 'zzzzz']) == 10400\n", "comparison": "exact"}, "public_tests": ["[\"coffee\",\"donuts\",\"time\",\"toffee\"]", "[\"lack\",\"back\"]"], "hints": ["How can we divide the ideas into groups to make it easier to find valid pairs?", "Group ideas that share the same suffix (all characters except the first) together and notice that a pair of ideas from the same group is invalid. What about pairs of ideas from different groups?", "The first letter of the idea in the first group must not be the first letter of an idea in the second group and vice versa.", "We can efficiently count the valid pairings for an idea if we already know how many ideas starting with a letter x are within a group that does not contain any ideas with starting letter y for all letters x and y."], "metadata": {"canonical_parameter_names": ["ideas"], "leetcode_dataset_entry_point": "Solution().distinctNames", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:15+00:00", "tests_total": 45, "tests_dropped": 21, "flags": [], "topic_tags": ["array", "hash-table", "string", "bit-manipulation", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function distinctNames($ideas) {", "container": "Solution", "callable": "distinctNames", "parameters": [{"name": "ideas", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2309, "task_id": "greatest-english-letter-in-upper-and-lower-case", "difficulty": "Easy", "problem_description": "Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.\n\nAn English letter b is greater than another letter a if b appears after a in the English alphabet.\n\nExample 1:\n\nInput: s = \"lEeTcOdE\"\nOutput: \"E\"\nExplanation:\nThe letter 'E' is the only letter to appear in both lower and upper case.\n\nExample 2:\n\nInput: s = \"arRAzFif\"\nOutput: \"R\"\nExplanation:\nThe letter 'R' is the greatest letter to appear in both lower and upper case.\nNote that 'A' and 'F' also appear in both lower and upper case, but 'R' is greater than 'F' or 'A'.\n\nExample 3:\n\nInput: s = \"AbCdEfGhIjK\"\nOutput: \"\"\nExplanation:\nThere is no letter that appears in both lower and upper case.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s consists of lowercase and uppercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"mMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"zZyYxXwWeE\") == \"Z\"\n assert candidate(s = \"zZyYxXwWvVuUtTrRsSqQpPoOnNmMlLkKiIjJhHgGfFeEdDcCbBaA\") == \"Z\"\n assert candidate(s = \"bBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\") == \"Y\"\n assert candidate(s = \"alluppercase\") == \"\"\n assert candidate(s = \"ALLLOWERCASE\") == \"\"\n assert candidate(s = \"aBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"AbCdEfGhIjK\") == \"\"\n assert candidate(s = \"a\") == \"\"\n assert candidate(s = \"NoUpperCaseHere\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"Z\"\n assert candidate(s = \"bA\") == \"\"\n assert candidate(s = \"AbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"NnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"lEeTcOdE\") == \"E\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"arRAzFif\") == \"R\"\n assert candidate(s = \"abcdefgHIJKLMnoPQRSTuVwxyz\") == \"\"\n assert candidate(s = \"QwErTyUiOpAsDfGhJkLzXcVbNm\") == \"\"\n assert candidate(s = \"aA\") == \"A\"\n assert candidate(s = \"A\") == \"\"\n assert candidate(s = \"AaBbCc\") == \"C\"\n assert candidate(s = \"zZ\") == \"Z\"\n assert candidate(s = \"MmQqEe\") == \"Q\"\n assert candidate(s = \"aB\") == \"\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYz\") == \"\"\n assert candidate(s = \"qUICkBrOwNBROWNfOX\") == \"W\"\n assert candidate(s = \"pUrPLe\") == \"P\"\n assert candidate(s = \"ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa\") == \"Z\"\n assert candidate(s = \"aBcD\") == \"\"\n assert candidate(s = \"bLuE\") == \"\"\n assert candidate(s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\") == \"\"\n assert candidate(s = \"xYzZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwW\") == \"Z\"\n assert candidate(s = \"bBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"bAcBdCeCdFdEgFhG\") == \"G\"\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"Z\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZzZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaAaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"hYsS\") == \"S\"\n assert candidate(s = \"thisIsAtEsTString\") == \"T\"\n assert candidate(s = \"xyzXYZuvwUVWtTqsSRpqPRonmNMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"Z\"\n assert candidate(s = \"AaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAa\") == \"A\"\n assert candidate(s = \"aAaaAAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"A\"\n assert candidate(s = \"noUpperLower\") == \"\"\n assert candidate(s = \"UnIqUe\") == \"\"\n assert candidate(s = \"mAgEnTa\") == \"A\"\n assert candidate(s = \"aAaAaAaAaAaA\") == \"A\"\n assert candidate(s = \"AaaaBBbbbCCCCDDDdeeeFFGHHHIIIJJJ\") == \"D\"\n assert candidate(s = \"xyzABCxyzABC\") == \"\"\n assert candidate(s = \"aNdSoMeSpEcIaLChArAcTeRs\") == \"S\"\n assert candidate(s = \"withSomeDuPpLicaTeS\") == \"T\"\n assert candidate(s = \"bBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBbBb\") == \"B\"\n assert candidate(s = \"mNnOoPpQqRrSsTtUuVvWwXxYyZzLlKkJjIiHhGgFfEeDdCcBbAa\") == \"Z\"\n assert candidate(s = \"abcdefghiJklmnopqrStuvWxyzZ\") == \"Z\"\n assert candidate(s = \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"abcdefGHIJKLmnopQRStuvWXYZ\") == \"\"\n assert candidate(s = \"mMnNoOpPqQrRsStTuUvVwWxXyYzZaAbBcCdDeEfFgGhHiIjJkKlL\") == \"Z\"\n assert candidate(s = \"aBcDdEfGgHiJjKlMmNoPpQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"gRaY\") == \"\"\n assert candidate(s = \"butNoVaLiDgReaTtEsT\") == \"T\"\n assert candidate(s = \"mIXeDuPpLeTeXt\") == \"T\"\n assert candidate(s = \"nNoOlLkKiIjJhHgGfFeEdDcCbBaA\") == \"O\"\n assert candidate(s = \"cYaN\") == \"\"\n assert candidate(s = \"sUpErCoMpLeXtExT\") == \"X\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzZ\") == \"Z\"\n assert candidate(s = \"mIxEdCaSeStRiNg\") == \"I\"\n assert candidate(s = \"MmLlKkJjIiHhGgFfEeDdCcBbAa\") == \"M\"\n assert candidate(s = \"abcdefgHIJKLmnopqRSTUVWxyz\") == \"\"\n assert candidate(s = \"mM\") == \"M\"\n assert candidate(s = \"AbcDefGhIjKlMnopQRStuvWXYZ\") == \"\"\n assert candidate(s = \"ZZZaaaBBBcccDDDeeeFFFgggHHHiiiJJJkkkLLLmmmNNNoooPPPqqqRRRsssTTTuuuVVVwwwXXXyyyzzz\") == \"Z\"\n assert candidate(s = \"tEsTiNgUpPeRaNdLoWeRcAsE\") == \"T\"\n assert candidate(s = \"sUnShInESoNnY\") == \"S\"\n assert candidate(s = \"xYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxYxY\") == \"\"\n assert candidate(s = \"mNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"Z\"\n assert candidate(s = \"zZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\") == \"Z\"\n assert candidate(s = \"aNkLmNpQrStUvWxYzZ\") == \"Z\"\n assert candidate(s = \"sTrInGtEsTcAsE\") == \"T\"\n assert candidate(s = \"aAaAaAbBbBcCcCdDdDeEeEfFfFgGgGhHhHiIiIjJjJkKkKlLlLmMmMnNnNoOpPqQrRsStTuUvVwWxXyYzZzZyYxXwWvVuUtTsSrRpPqQoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"Z\"\n assert candidate(s = \"gReEn\") == \"E\"\n assert candidate(s = \"mnopQRstUVwXYZ\") == \"\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") == \"Z\"\n assert candidate(s = \"mnopqrStuvWxyzZ\") == \"Z\"\n assert candidate(s = \"aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA\") == \"Z\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"A\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaA\") == \"A\"\n assert candidate(s = \"abcdefghijkLmnopqrstUvwxyz\") == \"\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"aNnBmMlLkKiIjJhHgGfFeEdDcCbBaA\") == \"N\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmooppqqrrssttuuvvwwxxyyzz\") == \"\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"\"\n assert candidate(s = \"aBcDxyzXYZaBcD\") == \"Z\"\n assert candidate(s = \"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz\") == \"Z\"\n assert candidate(s = \"fUnNyCaSe\") == \"N\"\n assert candidate(s = \"oRaNgE\") == \"\"\n assert candidate(s = \"aBcDfEgHiJkLmNoPqRsTuVwXyZ\") == \"\"\n assert candidate(s = \"xyZzXyZzXyZzXyZzXyZzXyZzXyZzXyZzXyZz\") == \"Z\"\n assert candidate(s = \"bAcAdAeAfAgAhAiAjAkAlAmAnAoApAqArAsAtAuAvAwAxAyAz\") == \"\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"A\"\n assert candidate(s = \"qQwWeErRtTyYuUiIoOpPlLkKjJhHgGfFdDsSaAzZ\") == \"Z\"\n assert candidate(s = \"xyzXYZabcABCdefDEFghiGHIjklJKLmnopMNOpqrQRstSTuvwUVWxyzXYZ\") == \"Z\"\n assert candidate(s = \"MiXeDcAsEnOnCaSeTeStStRiNg\") == \"T\"\n assert candidate(s = \"jUmBlEdTeXt\") == \"T\"\n assert candidate(s = \"aBcDefGHiJkLmNoPqRsTuVwXyZZzz\") == \"Z\"\n assert candidate(s = \"aAeEiIoOuUaAeEiIoOuUaAeEiIoOuU\") == \"U\"\n assert candidate(s = \"abCDxyzXYZ\") == \"Z\"\n assert candidate(s = \"oNeTwOThReEfOuRfIvEsIxTEnElEvEnTiGoNeVeNtWeNtYtHrEe\") == \"W\"\n assert candidate(s = \"mAgIc\") == \"\"\n assert candidate(s = \"aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA\") == \"Z\"\n assert candidate(s = \"ABCDEFGhijklmNopqrStuvWxyz\") == \"\"\n assert candidate(s = \"AbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQrStUvWxYz\") == \"\"\n", "comparison": "exact"}, "public_tests": ["\"lEeTcOdE\"", "\"arRAzFif\"", "\"AbCdEfGhIjK\""], "hints": ["Consider iterating through the string and storing each unique character that occurs in a set.", "From Z to A, check whether both the uppercase and lowercase version occur in the set."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().greatestLetter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:20+00:00", "tests_total": 117, "tests_dropped": 2, "flags": [], "topic_tags": ["hash-table", "string", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function greatestLetter($s) {", "container": "Solution", "callable": "greatestLetter", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2310, "task_id": "sum-of-numbers-with-units-digit-k", "difficulty": "Medium", "problem_description": "Given two integers num and k, consider a set of positive integers with the following properties:\n\n- The units digit of each integer is k.\n- The sum of the integers is num.\n\nReturn the minimum possible size of such a set, or -1 if no such set exists.\n\nNote:\n\n- The set can contain multiple instances of the same integer, and the sum of an empty set is considered 0.\n- The units digit of a number is the rightmost digit of the number.\n\nExample 1:\n\nInput: num = 58, k = 9\nOutput: 2\nExplanation:\nOne valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.\nAnother valid set is [19,39].\nIt can be shown that 2 is the minimum possible size of a valid set.\n\nExample 2:\n\nInput: num = 37, k = 2\nOutput: -1\nExplanation: It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.\n\nExample 3:\n\nInput: num = 0, k = 7\nOutput: 0\nExplanation: The sum of an empty set is considered 0.\n\nConstraints:\n\n- 0 <= num <= 3000\n- 0 <= k <= 9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 25,k = 5) == 1\n assert candidate(num = 2023,k = 3) == 1\n assert candidate(num = 37,k = 2) == -1\n assert candidate(num = 100,k = 0) == 1\n assert candidate(num = 58,k = 9) == 2\n assert candidate(num = 99,k = 9) == 1\n assert candidate(num = 15,k = 3) == 5\n assert candidate(num = 27,k = 9) == 3\n assert candidate(num = 888,k = 8) == 1\n assert candidate(num = 0,k = 7) == 0\n assert candidate(num = 100,k = 1) == 10\n assert candidate(num = 88,k = 8) == 1\n assert candidate(num = 20,k = 5) == 2\n assert candidate(num = 45,k = 5) == 1\n assert candidate(num = 1,k = 1) == 1\n assert candidate(num = 999,k = 9) == 1\n assert candidate(num = 100,k = 3) == 10\n assert candidate(num = 9,k = 9) == 1\n assert candidate(num = 10,k = 0) == 1\n assert candidate(num = 100,k = 9) == 10\n assert candidate(num = 666,k = 6) == 1\n assert candidate(num = 345,k = 4) == -1\n assert candidate(num = 1000,k = 5) == 2\n assert candidate(num = 123,k = 3) == 1\n assert candidate(num = 2997,k = 7) == 1\n assert candidate(num = 2999,k = 9) == 1\n assert candidate(num = 275,k = 5) == 1\n assert candidate(num = 3000,k = 1) == 10\n assert candidate(num = 222,k = 2) == 1\n assert candidate(num = 210,k = 1) == 10\n assert candidate(num = 256,k = 7) == 8\n assert candidate(num = 1995,k = 5) == 1\n assert candidate(num = 900,k = 0) == 1\n assert candidate(num = 456,k = 4) == 4\n assert candidate(num = 256,k = 8) == 2\n assert candidate(num = 789,k = 9) == 1\n assert candidate(num = 21,k = 1) == 1\n assert candidate(num = 202,k = 2) == 1\n assert candidate(num = 333,k = 3) == 1\n assert candidate(num = 150,k = 5) == 2\n assert candidate(num = 123,k = 8) == -1\n assert candidate(num = 2500,k = 5) == 2\n assert candidate(num = 400,k = 6) == 5\n assert candidate(num = 1234,k = 8) == 3\n assert candidate(num = 777,k = 1) == 7\n assert candidate(num = 234,k = 5) == -1\n assert candidate(num = 3000,k = 9) == 10\n assert candidate(num = 2345,k = 4) == -1\n assert candidate(num = 678,k = 8) == 1\n assert candidate(num = 999,k = 3) == 3\n assert candidate(num = 145,k = 6) == -1\n assert candidate(num = 56,k = 0) == -1\n assert candidate(num = 777,k = 7) == 1\n assert candidate(num = 2999,k = 3) == 3\n assert candidate(num = 1200,k = 0) == 1\n assert candidate(num = 567,k = 2) == -1\n assert candidate(num = 444,k = 4) == 1\n assert candidate(num = 50,k = 5) == 2\n assert candidate(num = 999,k = 1) == 9\n assert candidate(num = 256,k = 6) == 1\n assert candidate(num = 189,k = 9) == 1\n assert candidate(num = 555,k = 5) == 1\n assert candidate(num = 111,k = 1) == 1\n assert candidate(num = 450,k = 5) == 2\n assert candidate(num = 0,k = 0) == 0\n assert candidate(num = 299,k = 9) == 1\n assert candidate(num = 250,k = 7) == 10\n assert candidate(num = 768,k = 4) == 2\n assert candidate(num = 1985,k = 5) == 1\n assert candidate(num = 1500,k = 0) == 1\n assert candidate(num = 3000,k = 5) == 2\n assert candidate(num = 2875,k = 7) == 5\n assert candidate(num = 158,k = 8) == 1\n assert candidate(num = 99,k = 2) == -1\n assert candidate(num = 1234,k = 4) == 1\n assert candidate(num = 234,k = 4) == 1\n assert candidate(num = 111,k = 2) == -1\n assert candidate(num = 101,k = 1) == 1\n assert candidate(num = 3000,k = 0) == 1\n assert candidate(num = 143,k = 3) == 1\n assert candidate(num = 800,k = 2) == 5\n assert candidate(num = 1024,k = 3) == 8\n assert candidate(num = 303,k = 3) == 1\n assert candidate(num = 888,k = 2) == 4\n assert candidate(num = 500,k = 5) == 2\n assert candidate(num = 123,k = 4) == -1\n assert candidate(num = 1234,k = 7) == 2\n assert candidate(num = 1000,k = 1) == 10\n assert candidate(num = 75,k = 5) == 1\n assert candidate(num = 1999,k = 9) == 1\n assert candidate(num = 243,k = 7) == 9\n assert candidate(num = 1998,k = 8) == 1\n assert candidate(num = 246,k = 7) == 8\n assert candidate(num = 135,k = 5) == 1\n assert candidate(num = 676,k = 6) == 1\n assert candidate(num = 123,k = 1) == 3\n assert candidate(num = 150,k = 1) == 10\n assert candidate(num = 2500,k = 0) == 1\n assert candidate(num = 2345,k = 9) == 5\n assert candidate(num = 5,k = 0) == -1\n assert candidate(num = 999,k = 5) == -1\n assert candidate(num = 250,k = 5) == 2\n assert candidate(num = 147,k = 6) == -1\n assert candidate(num = 199,k = 9) == 1\n assert candidate(num = 1000,k = 0) == 1\n assert candidate(num = 2468,k = 8) == 1\n assert candidate(num = 2024,k = 4) == 1\n assert candidate(num = 234,k = 3) == 8\n assert candidate(num = 1111,k = 1) == 1\n", "comparison": "exact"}, "public_tests": ["58\n9", "37\n2", "0\n7"], "hints": ["Try solving this recursively.", "Create a method that takes an integer x as a parameter. This method returns the minimum possible size of a set where each number has units digit k and the sum of the numbers in the set is x."], "metadata": {"canonical_parameter_names": ["num", "k"], "leetcode_dataset_entry_point": "Solution().minimumNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:22+00:00", "tests_total": 114, "tests_dropped": 5, "flags": [], "topic_tags": ["math", "dynamic-programming", "greedy", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function minimumNumbers($num, $k) {", "container": "Solution", "callable": "minimumNumbers", "parameters": [{"name": "num", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2311, "task_id": "longest-binary-subsequence-less-than-or-equal-to-k", "difficulty": "Medium", "problem_description": "You are given a binary string s and a positive integer k.\n\nReturn the length of the longest subsequence of s that makes up a binary number less than or equal to k.\n\nNote:\n\n- The subsequence can contain leading zeroes.\n- The empty string is considered to be equal to 0.\n- A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nExample 1:\n\nInput: s = \"1001010\", k = 5\nOutput: 5\nExplanation: The longest subsequence of s that makes up a binary number less than or equal to 5 is \"00010\", as this number is equal to 2 in decimal.\nNote that \"00100\" and \"00101\" are also possible, which are equal to 4 and 5 in decimal, respectively.\nThe length of this subsequence is 5, so 5 is returned.\n\nExample 2:\n\nInput: s = \"00101001\", k = 1\nOutput: 6\nExplanation: \"000001\" is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.\nThe length of this subsequence is 6, so 6 is returned.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s[i] is either '0' or '1'.\n- 1 <= k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"111000111\",k = 127) == 7\n assert candidate(s = \"1111111\",k = 127) == 7\n assert candidate(s = \"1111000011\",k = 255) == 8\n assert candidate(s = \"1100110011\",k = 10) == 6\n assert candidate(s = \"1010101010\",k = 512) == 9\n assert candidate(s = \"10101010\",k = 10) == 6\n assert candidate(s = \"111000111\",k = 50) == 6\n assert candidate(s = \"1101001\",k = 4) == 4\n assert candidate(s = \"11111111\",k = 15) == 4\n assert candidate(s = \"0101010101\",k = 512) == 10\n assert candidate(s = \"1101101\",k = 7) == 4\n assert candidate(s = \"1100110011\",k = 500) == 9\n assert candidate(s = \"0000000\",k = 10) == 7\n assert candidate(s = \"1001010\",k = 5) == 5\n assert candidate(s = \"00000\",k = 1000) == 5\n assert candidate(s = \"0101010101\",k = 255) == 9\n assert candidate(s = \"1\",k = 1) == 1\n assert candidate(s = \"11111111\",k = 255) == 8\n assert candidate(s = \"0000111100\",k = 31) == 9\n assert candidate(s = \"101010\",k = 3) == 4\n assert candidate(s = \"1111000011110000\",k = 100000) == 16\n assert candidate(s = \"1100110011\",k = 100) == 8\n assert candidate(s = \"1010101010\",k = 10) == 7\n assert candidate(s = \"100110011001100110\",k = 1000) == 14\n assert candidate(s = \"11001100\",k = 20) == 6\n assert candidate(s = \"00000000\",k = 8) == 8\n assert candidate(s = \"00101001\",k = 1) == 6\n assert candidate(s = \"010101010101010101\",k = 10000) == 16\n assert candidate(s = \"100101010010101010101010\",k = 1024) == 18\n assert candidate(s = \"1010101010101010101010101\",k = 1048575) == 22\n assert candidate(s = \"11001100110011001100110011001100110011001100110011001100\",k = 1000000) == 38\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010101010101010\",k = 10) == 36\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010\",k = 1023) == 33\n assert candidate(s = \"110011001100110011001100110011001100110011001100\",k = 65535) == 32\n assert candidate(s = \"001100110011001100110011001100110011001100110011001100110011\",k = 4096) == 36\n assert candidate(s = \"1101101101101101101101101\",k = 1000) == 15\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111111111111111\",k = 2047) == 11\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000\",k = 1000) == 56\n assert candidate(s = \"0101010101010101010101010101010101010101\",k = 1023) == 25\n assert candidate(s = \"00001111000011110000111100001111000011110000111100001111\",k = 32767) == 36\n assert candidate(s = \"1001001001001001001001001001001001001001\",k = 10000) == 31\n assert candidate(s = \"11010110101101011010110101101011010110101101011010110101\",k = 1048575) == 34\n assert candidate(s = \"1001001001001001001001001001001001001001001001001001001001\",k = 5000) == 43\n assert candidate(s = \"1100110011001100110011001100110011001100110011001100110011001100110011001100110011001100\",k = 128) == 47\n assert candidate(s = \"10010101010101010101\",k = 30000) == 18\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000111000111000\",k = 50000) == 43\n assert candidate(s = \"11010101010101010101\",k = 16383) == 16\n assert candidate(s = \"1101001101001101001101001101001\",k = 1024) == 20\n assert candidate(s = \"1111111111111111111111111111111111111111\",k = 1024) == 10\n assert candidate(s = \"0101010101010101010101010101010101010101\",k = 10) == 22\n assert candidate(s = \"1001100110011001100110011001100110011001\",k = 2000) == 25\n assert candidate(s = \"1100110011001100\",k = 1000) == 12\n assert candidate(s = \"10101010101010101010101010101010101010101010\",k = 1000000) == 32\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101010101010101\",k = 1000) == 39\n assert candidate(s = \"11111111111111111111111111111111111111111111\",k = 1048575) == 20\n assert candidate(s = \"1111111111111111111111111\",k = 1048575) == 20\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\",k = 500) == 48\n assert candidate(s = \"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\",k = 1000000000) == 29\n assert candidate(s = \"00000000000000000000000000000000000000000000000000000000000000000\",k = 1) == 65\n assert candidate(s = \"0011001100110011001100110011001100110011\",k = 5000) == 27\n assert candidate(s = \"111111111100000000111111111000000011111111100000001111111110000000111111111000000011111111\",k = 10000000) == 52\n assert candidate(s = \"1101101101101101101101101101101101101101\",k = 500) == 19\n assert candidate(s = \"100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000100010001000\",k = 500000000) == 115\n assert candidate(s = \"11110000111100001111000011110000111100001111000011110000\",k = 65535) == 36\n assert candidate(s = \"100000000000000000000000000000000000000000000000\",k = 1000000000) == 47\n assert candidate(s = \"11001100110011001100110011001100\",k = 2048) == 21\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101\",k = 2048) == 34\n assert candidate(s = \"0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\",k = 100) == 48\n assert candidate(s = \"111000111000111000111000111000111000111000111000111000111000111000111\",k = 500) == 39\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101\",k = 511) == 33\n assert candidate(s = \"01110111011101110111011101110111011101110111011101110111\",k = 524287) == 29\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010101010101010101\",k = 1048575) == 53\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010\",k = 65535) == 44\n assert candidate(s = \"1111000011110000111100001111000011110000\",k = 10000) == 25\n assert candidate(s = \"0000000000000000000000000\",k = 1) == 25\n assert candidate(s = \"000111000111000111000111000111000111000111000111000111000111000111000111\",k = 25000) == 44\n assert candidate(s = \"1110000011100000111000001110000011100000111000001110000011100000111000001110000011100000\",k = 255) == 58\n assert candidate(s = \"010101010101010101010101010101010101010101010101\",k = 524287) == 34\n assert candidate(s = \"1110001110001110001110001\",k = 2048) == 17\n assert candidate(s = \"1111000011110000111100001111000011110000111100001111000011110000\",k = 10000) == 37\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111\",k = 1000000000) == 29\n assert candidate(s = \"000100010001000100010001000100010001000100010001000100010001000100010\",k = 1023) == 55\n assert candidate(s = \"0000111111111111111111111\",k = 1048575) == 24\n assert candidate(s = \"0011001100110011001100110011001100110011001100110011001100110011001100110011001100110011\",k = 50) == 47\n assert candidate(s = \"10000000000000000000000000000000000000000000000000000000000000000000\",k = 1) == 67\n assert candidate(s = \"1010101010101010101010101010101010101010\",k = 1023) == 25\n assert candidate(s = \"110010011001001100100110010011001001100100110011001001\",k = 1023) == 34\n assert candidate(s = \"00000000000000000000\",k = 1000) == 20\n assert candidate(s = \"11111111111111111111111111111111111111111111111111111111\",k = 2047) == 11\n assert candidate(s = \"1111111111111111111111111111111111111111111111111111111111111111\",k = 1000000000) == 29\n assert candidate(s = \"001010101010101010101010101010101010101010101010\",k = 1024) == 30\n assert candidate(s = \"10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\",k = 999999999) == 94\n", "comparison": "exact"}, "public_tests": ["\"1001010\"\n5", "\"00101001\"\n1"], "hints": ["Choosing a subsequence from the string is equivalent to deleting all the other digits.", "If you were to remove a digit, which one should you remove to reduce the value of the string?"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().longestSubsequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:24+00:00", "tests_total": 101, "tests_dropped": 9, "flags": [], "topic_tags": ["string", "dynamic-programming", "greedy", "memoization"]}, "language": "php", "interface": {"raw_signature": "function longestSubsequence($s, $k) {", "container": "Solution", "callable": "longestSubsequence", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2312, "task_id": "selling-pieces-of-wood", "difficulty": "Hard", "problem_description": "You are given two integers m and n that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array prices, where prices[i] = [h_i, w_i, price_i] indicates you can sell a rectangular piece of wood of height h_i and width w_i for price_i dollars.\n\nTo cut a piece of wood, you must make a vertical or horizontal cut across the entire height or width of the piece to split it into two smaller pieces. After cutting a piece of wood into some number of smaller pieces, you can sell pieces according to prices. You may sell multiple pieces of the same shape, and you do not have to sell all the shapes. The grain of the wood makes a difference, so you cannot rotate a piece to swap its height and width.\n\nReturn the maximum money you can earn after cutting an m x n piece of wood.\n\nNote that you can cut the piece of wood as many times as you want.\n\nExample 1:\n\nInput: m = 3, n = 5, prices = [[1,4,2],[2,2,7],[2,1,3]]\nOutput: 19\nExplanation: The diagram above shows a possible scenario. It consists of:\n- 2 pieces of wood shaped 2 x 2, selling for a price of 2 * 7 = 14.\n- 1 piece of wood shaped 2 x 1, selling for a price of 1 * 3 = 3.\n- 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\nThis obtains a total of 14 + 3 + 2 = 19 money earned.\nIt can be shown that 19 is the maximum amount of money that can be earned.\n\nExample 2:\n\nInput: m = 4, n = 6, prices = [[3,2,10],[1,4,2],[4,1,3]]\nOutput: 32\nExplanation: The diagram above shows a possible scenario. It consists of:\n- 3 pieces of wood shaped 3 x 2, selling for a price of 3 * 10 = 30.\n- 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\nThis obtains a total of 30 + 2 = 32 money earned.\nIt can be shown that 32 is the maximum amount of money that can be earned.\nNotice that we cannot rotate the 1 x 4 piece of wood to obtain a 4 x 1 piece of wood.\n\nConstraints:\n\n- 1 <= m, n <= 200\n- 1 <= prices.length <= 2 * 10^4\n- prices[i].length == 3\n- 1 <= h_i <= m\n- 1 <= w_i <= n\n- 1 <= price_i <= 10^6\n- All the shapes of wood (h_i, w_i) are pairwise distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(m = 4,n = 6,prices = [[3, 2, 10], [1, 4, 2], [4, 1, 3]]) == 32\n assert candidate(m = 2,n = 2,prices = [[1, 1, 1], [2, 2, 5]]) == 5\n assert candidate(m = 3,n = 5,prices = [[1, 4, 2], [2, 2, 7], [2, 1, 3]]) == 19\n assert candidate(m = 200,n = 200,prices = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 40000\n assert candidate(m = 2,n = 2,prices = [[2, 2, 5]]) == 5\n assert candidate(m = 1,n = 1,prices = [[1, 1, 100]]) == 100\n assert candidate(m = 5,n = 5,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20]]) == 29\n assert candidate(m = 5,n = 5,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 20], [5, 5, 50]]) == 50\n assert candidate(m = 10,n = 10,prices = [[1, 1, 1], [1, 2, 3], [2, 1, 3], [2, 2, 5], [3, 3, 10], [5, 5, 20]]) == 150\n assert candidate(m = 15,n = 15,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [6, 6, 36], [7, 7, 49], [8, 8, 64], [9, 9, 81], [10, 10, 100], [11, 11, 121], [12, 12, 144], [13, 13, 169], [14, 14, 196], [15, 15, 225]]) == 225\n assert candidate(m = 90,n = 60,prices = [[5, 5, 25], [10, 10, 100], [15, 15, 225], [20, 20, 400], [25, 25, 625]]) == 5400\n assert candidate(m = 10,n = 5,prices = [[1, 1, 2], [1, 2, 4], [1, 3, 6], [1, 4, 8], [1, 5, 10], [2, 1, 4], [2, 2, 8], [2, 3, 12], [2, 4, 16], [2, 5, 20], [3, 1, 6], [3, 2, 12], [3, 3, 18], [3, 4, 24], [3, 5, 30], [4, 1, 8], [4, 2, 16], [4, 3, 24], [4, 4, 32], [4, 5, 40], [5, 1, 10], [5, 2, 20], [5, 3, 30], [5, 4, 40], [5, 5, 50]]) == 100\n assert candidate(m = 100,n = 100,prices = [[50, 50, 2500], [25, 25, 625], [75, 75, 4500], [10, 10, 25], [1, 1, 1]]) == 10000\n assert candidate(m = 50,n = 50,prices = [[5, 5, 25], [10, 10, 100], [25, 25, 625], [45, 45, 2025], [1, 1, 1]]) == 2500\n assert candidate(m = 150,n = 100,prices = [[10, 20, 100], [15, 10, 200], [20, 15, 250], [50, 50, 1500], [75, 75, 5000]]) == 20000\n assert candidate(m = 5,n = 5,prices = [[1, 1, 10], [2, 2, 20], [3, 3, 30], [4, 4, 40], [5, 5, 50]]) == 250\n assert candidate(m = 150,n = 100,prices = [[1, 1, 1], [5, 5, 10], [10, 10, 20], [15, 15, 30], [25, 25, 40], [50, 50, 100]]) == 15000\n assert candidate(m = 180,n = 90,prices = [[1, 1, 2], [2, 2, 8], [3, 3, 18], [4, 4, 32], [5, 5, 50], [6, 6, 72], [7, 7, 98], [8, 8, 128], [9, 9, 162], [10, 10, 200], [15, 15, 750], [30, 30, 3000], [45, 45, 6750], [90, 90, 20250]]) == 54000\n assert candidate(m = 50,n = 50,prices = [[1, 1, 2], [2, 2, 6], [3, 3, 18], [4, 4, 40], [5, 5, 75], [10, 10, 300], [15, 15, 800], [25, 25, 1200]]) == 8625\n assert candidate(m = 160,n = 140,prices = [[1, 2, 1], [2, 1, 2], [3, 4, 3], [4, 3, 4], [5, 6, 5], [6, 5, 6], [7, 8, 7], [8, 7, 8], [9, 10, 9], [10, 9, 10]]) == 22400\n assert candidate(m = 150,n = 120,prices = [[50, 40, 2000], [75, 60, 3600], [25, 30, 600], [10, 15, 150], [1, 1, 1]]) == 18000\n assert candidate(m = 100,n = 100,prices = [[10, 10, 50], [20, 20, 100], [30, 30, 150], [50, 50, 300]]) == 5000\n assert candidate(m = 20,n = 30,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [10, 10, 100], [15, 15, 225]]) == 600\n assert candidate(m = 120,n = 80,prices = [[20, 10, 200], [10, 20, 150], [30, 30, 900], [60, 40, 2400], [40, 60, 3000]]) == 11400\n assert candidate(m = 80,n = 60,prices = [[20, 15, 300], [10, 10, 100], [40, 30, 1200], [60, 40, 2400], [50, 50, 3000], [1, 1, 1]]) == 5300\n assert candidate(m = 110,n = 90,prices = [[30, 20, 600], [60, 40, 2400], [15, 10, 150], [50, 30, 1500], [1, 1, 1]]) == 9900\n assert candidate(m = 100,n = 100,prices = [[10, 10, 50], [20, 20, 200], [30, 30, 500], [40, 40, 1000], [50, 50, 2000]]) == 8000\n assert candidate(m = 180,n = 160,prices = [[10, 10, 50], [20, 20, 200], [30, 30, 500], [40, 40, 1000], [50, 50, 2000], [60, 60, 3000]]) == 22650\n assert candidate(m = 50,n = 50,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [5, 5, 50], [10, 10, 100], [25, 25, 5000], [50, 50, 100000]]) == 100000\n assert candidate(m = 200,n = 100,prices = [[1, 1, 1], [1, 2, 2], [2, 1, 3], [2, 2, 5], [10, 10, 100], [20, 20, 500], [30, 30, 1200], [50, 50, 2500], [100, 100, 10000]]) == 30000\n assert candidate(m = 80,n = 120,prices = [[1, 2, 2], [2, 1, 3], [2, 3, 5], [3, 2, 6], [4, 6, 12], [6, 4, 15], [8, 12, 24], [12, 8, 30]]) == 14400\n assert candidate(m = 150,n = 100,prices = [[10, 10, 100], [20, 20, 500], [30, 30, 1200], [15, 15, 300]]) == 19500\n assert candidate(m = 200,n = 100,prices = [[1, 1, 1], [2, 2, 2], [4, 4, 4], [8, 8, 8], [16, 16, 16], [32, 32, 32]]) == 20000\n assert candidate(m = 10,n = 20,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [6, 6, 36], [7, 7, 49], [8, 8, 64], [9, 9, 81], [10, 10, 100]]) == 200\n assert candidate(m = 200,n = 200,prices = [[10, 20, 100], [20, 30, 250], [30, 40, 500], [40, 50, 750], [50, 60, 1000]]) == 20000\n assert candidate(m = 190,n = 190,prices = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [2, 1, 2], [2, 2, 5], [2, 3, 6], [3, 1, 3], [3, 2, 6], [3, 3, 10]]) == 45125\n assert candidate(m = 100,n = 100,prices = [[10, 10, 100], [20, 20, 300], [30, 30, 600], [40, 40, 1000], [50, 50, 1500]]) == 10000\n assert candidate(m = 120,n = 80,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 35], [8, 8, 45], [9, 9, 55], [10, 10, 65], [11, 11, 75], [12, 12, 85], [13, 13, 95], [14, 14, 105], [15, 15, 115], [16, 16, 125], [17, 17, 135], [18, 18, 145], [19, 19, 155], [20, 20, 165], [21, 21, 175], [22, 22, 185], [23, 23, 195], [24, 24, 205], [25, 25, 215], [26, 26, 225], [27, 27, 235], [28, 28, 245], [29, 29, 255], [30, 30, 265], [31, 31, 275], [32, 32, 285], [33, 33, 295], [34, 34, 305], [35, 35, 315], [36, 36, 325], [37, 37, 335], [38, 38, 345], [39, 39, 355], [40, 40, 365], [41, 41, 375], [42, 42, 385], [43, 43, 395], [44, 44, 405], [45, 45, 415], [46, 46, 425], [47, 47, 435], [48, 48, 445], [49, 49, 455], [50, 50, 465], [51, 51, 475], [52, 52, 485], [53, 53, 495], [54, 54, 505], [55, 55, 515], [56, 56, 525], [57, 57, 535], [58, 58, 545], [59, 59, 555], [60, 60, 565], [61, 61, 575], [62, 62, 585], [63, 63, 595], [64, 64, 605], [65, 65, 615], [66, 66, 625], [67, 67, 635], [68, 68, 645], [69, 69, 655], [70, 70, 665], [71, 71, 675], [72, 72, 685], [73, 73, 695], [74, 74, 705], [75, 75, 715], [76, 76, 725], [77, 77, 735], [78, 78, 745], [79, 79, 755], [80, 80, 765]]) == 12000\n assert candidate(m = 80,n = 60,prices = [[10, 20, 500], [20, 30, 1500], [30, 40, 2700], [40, 50, 4000]]) == 12000\n assert candidate(m = 120,n = 80,prices = [[1, 1, 1], [2, 2, 5], [4, 4, 20], [8, 8, 100], [16, 16, 500], [32, 32, 2000], [64, 64, 5000], [120, 80, 10000]]) == 18500\n assert candidate(m = 200,n = 200,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 35], [8, 8, 45], [9, 9, 55], [10, 10, 65], [11, 11, 75], [12, 12, 85], [13, 13, 95], [14, 14, 105], [15, 15, 115], [16, 16, 125], [17, 17, 135], [18, 18, 145], [19, 19, 155], [20, 20, 165], [21, 21, 175], [22, 22, 185], [23, 23, 195], [24, 24, 205], [25, 25, 215], [26, 26, 225], [27, 27, 235], [28, 28, 245], [29, 29, 255], [30, 30, 265]]) == 50000\n assert candidate(m = 200,n = 100,prices = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [5, 5, 5], [10, 10, 10], [20, 20, 20], [50, 50, 50], [100, 100, 100]]) == 20000\n assert candidate(m = 15,n = 12,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25]]) == 222\n assert candidate(m = 200,n = 150,prices = [[50, 50, 1000], [75, 75, 3000], [100, 100, 5000], [150, 150, 8000]]) == 15000\n assert candidate(m = 180,n = 180,prices = [[1, 1, 3], [2, 2, 6], [3, 3, 9], [4, 4, 12], [5, 5, 15], [6, 6, 18], [7, 7, 21], [8, 8, 24], [9, 9, 27]]) == 97200\n assert candidate(m = 175,n = 110,prices = [[10, 5, 50], [5, 10, 75], [20, 10, 150], [10, 20, 200], [15, 15, 300], [25, 25, 500], [50, 50, 1000]]) == 28875\n assert candidate(m = 120,n = 80,prices = [[1, 1, 1], [2, 2, 5], [4, 4, 15], [8, 8, 30], [16, 16, 60], [32, 32, 120], [64, 64, 240]]) == 12000\n assert candidate(m = 180,n = 120,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 20], [5, 5, 50], [6, 6, 100], [10, 10, 500], [20, 20, 2000], [30, 30, 5000], [40, 40, 10000], [50, 50, 20000], [60, 60, 50000], [120, 120, 100000], [180, 120, 150000]]) == 300000\n assert candidate(m = 120,n = 120,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]]) == 14400\n assert candidate(m = 6,n = 4,prices = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [2, 1, 2], [2, 2, 5], [2, 3, 6], [2, 4, 8], [3, 1, 3], [3, 2, 6], [3, 3, 9], [3, 4, 12], [4, 1, 4], [4, 2, 8], [4, 3, 12], [4, 4, 16], [5, 1, 5], [5, 2, 10], [5, 3, 15], [5, 4, 20], [6, 1, 6], [6, 2, 12], [6, 3, 18], [6, 4, 24]]) == 30\n assert candidate(m = 190,n = 190,prices = [[1, 1, 1], [10, 10, 50], [20, 20, 200], [30, 30, 500], [40, 40, 1000], [50, 50, 2000], [60, 60, 3000], [70, 70, 4000], [80, 80, 5000], [90, 90, 6000], [100, 100, 7000], [110, 110, 8000], [120, 120, 9000], [130, 130, 10000], [140, 140, 11000], [150, 150, 12000], [160, 160, 13000], [170, 170, 14000], [180, 180, 15000], [190, 190, 16000]]) == 36100\n assert candidate(m = 80,n = 60,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 20], [5, 5, 50], [10, 10, 100], [20, 20, 500], [30, 30, 1500], [40, 40, 5000], [50, 50, 10000], [60, 60, 20000], [80, 60, 30000]]) == 30000\n assert candidate(m = 150,n = 150,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [150, 150, 100000], [75, 75, 25000]]) == 100000\n assert candidate(m = 150,n = 150,prices = [[1, 1, 5], [2, 2, 10], [3, 3, 15], [5, 5, 25], [10, 10, 50], [15, 15, 75]]) == 112500\n assert candidate(m = 100,n = 100,prices = [[1, 1, 10], [10, 10, 500], [50, 50, 20000], [25, 25, 5000], [100, 100, 50000]]) == 100000\n assert candidate(m = 120,n = 150,prices = [[1, 1, 5], [2, 2, 15], [3, 3, 45], [4, 4, 100], [5, 5, 175], [6, 6, 270], [7, 7, 392], [8, 8, 540], [9, 9, 717], [10, 10, 920], [11, 11, 1155], [12, 12, 1420], [13, 13, 1725], [14, 14, 2070], [15, 15, 2450], [16, 16, 2870], [17, 17, 3332], [18, 18, 3837], [19, 19, 4385], [20, 20, 4980]]) == 220200\n assert candidate(m = 7,n = 3,prices = [[1, 1, 3], [1, 2, 5], [1, 3, 7], [2, 1, 6], [2, 2, 12], [2, 3, 15], [3, 1, 9], [3, 2, 18], [3, 3, 20]]) == 63\n assert candidate(m = 100,n = 150,prices = [[5, 5, 25], [10, 10, 100], [15, 15, 250], [20, 20, 500], [25, 25, 750]]) == 18500\n assert candidate(m = 100,n = 200,prices = [[1, 1, 1], [2, 2, 2], [3, 3, 3], [5, 5, 5], [10, 10, 10], [20, 20, 20], [50, 50, 50], [100, 100, 100]]) == 20000\n assert candidate(m = 100,n = 50,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 35], [8, 8, 45], [9, 9, 55], [10, 10, 65], [11, 11, 75], [12, 12, 85], [13, 13, 95], [14, 14, 105], [15, 15, 115], [16, 16, 125], [17, 17, 135], [18, 18, 145], [19, 19, 155], [20, 20, 165], [21, 21, 175], [22, 22, 185], [23, 23, 195], [24, 24, 205], [25, 25, 215], [26, 26, 225], [27, 27, 235], [28, 28, 245], [29, 29, 255], [30, 30, 265], [31, 31, 275], [32, 32, 285], [33, 33, 295], [34, 34, 305], [35, 35, 315], [36, 36, 325], [37, 37, 335], [38, 38, 345], [39, 39, 355], [40, 40, 365], [41, 41, 375], [42, 42, 385], [43, 43, 395], [44, 44, 405], [45, 45, 415], [46, 46, 425], [47, 47, 435], [48, 48, 445], [49, 49, 455], [50, 50, 465]]) == 6250\n assert candidate(m = 100,n = 100,prices = [[1, 1, 10], [5, 5, 100], [10, 10, 500], [20, 20, 2000], [50, 50, 10000]]) == 100000\n assert candidate(m = 120,n = 120,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [6, 6, 36], [7, 7, 49], [8, 8, 64], [9, 9, 81], [10, 10, 100], [11, 11, 121], [12, 12, 144], [13, 13, 169], [14, 14, 196], [15, 15, 225]]) == 14400\n assert candidate(m = 120,n = 80,prices = [[1, 1, 1], [2, 2, 5], [4, 4, 20], [8, 8, 100], [16, 16, 500]]) == 18500\n assert candidate(m = 180,n = 120,prices = [[1, 2, 1], [2, 3, 4], [3, 4, 7], [4, 5, 11], [5, 6, 16]]) == 14400\n assert candidate(m = 180,n = 160,prices = [[90, 80, 14400], [60, 70, 8400], [30, 40, 1200], [20, 30, 600], [10, 20, 200], [1, 1, 1]]) == 57600\n assert candidate(m = 75,n = 75,prices = [[1, 1, 2], [3, 3, 10], [5, 5, 30], [7, 7, 60], [10, 10, 120], [15, 15, 300], [20, 20, 500], [25, 25, 800], [30, 30, 1200], [35, 35, 1600], [40, 40, 2000], [45, 45, 2400], [50, 50, 2800], [55, 55, 3200], [60, 60, 3600], [65, 65, 4000], [70, 70, 4400], [75, 75, 4800]]) == 11250\n assert candidate(m = 160,n = 100,prices = [[10, 10, 100], [20, 20, 400], [30, 30, 900], [40, 40, 1600], [50, 50, 2500]]) == 16000\n assert candidate(m = 120,n = 80,prices = [[10, 5, 10], [5, 10, 20], [15, 5, 30], [5, 15, 40], [20, 10, 50], [10, 20, 60], [25, 5, 70], [5, 25, 80], [30, 10, 90], [10, 30, 100]]) == 6070\n assert candidate(m = 160,n = 160,prices = [[1, 1, 1], [2, 2, 5], [4, 4, 15], [8, 8, 30], [16, 16, 60], [32, 32, 120], [64, 64, 240], [128, 128, 480]]) == 32000\n assert candidate(m = 8,n = 6,prices = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [2, 1, 2], [2, 2, 5], [2, 3, 6], [2, 4, 8], [2, 5, 10], [2, 6, 12], [3, 1, 3], [3, 2, 6], [3, 3, 9], [3, 4, 12], [3, 5, 15], [3, 6, 18], [4, 1, 4], [4, 2, 8], [4, 3, 12], [4, 4, 16], [4, 5, 20], [4, 6, 24], [5, 1, 5], [5, 2, 10], [5, 3, 15], [5, 4, 20], [5, 5, 25], [5, 6, 30], [6, 1, 6], [6, 2, 12], [6, 3, 18], [6, 4, 24], [6, 5, 30], [6, 6, 36], [7, 1, 7], [7, 2, 14], [7, 3, 21], [7, 4, 28], [7, 5, 35], [7, 6, 42], [8, 1, 8], [8, 2, 16], [8, 3, 24], [8, 4, 32], [8, 5, 40], [8, 6, 48]]) == 60\n assert candidate(m = 190,n = 140,prices = [[10, 10, 100], [20, 20, 400], [30, 30, 900], [40, 40, 1600], [50, 50, 2500]]) == 26600\n assert candidate(m = 150,n = 100,prices = [[1, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 35], [8, 8, 45], [9, 9, 55], [10, 10, 65], [11, 11, 75], [12, 12, 85], [13, 13, 95], [14, 14, 105], [15, 15, 115], [16, 16, 125], [17, 17, 135], [18, 18, 145], [19, 19, 155], [20, 20, 165], [21, 21, 175], [22, 22, 185], [23, 23, 195], [24, 24, 205], [25, 25, 215], [26, 26, 225], [27, 27, 235], [28, 28, 245], [29, 29, 255], [30, 30, 265], [31, 31, 275], [32, 32, 285], [33, 33, 295], [34, 34, 305], [35, 35, 315], [36, 36, 325], [37, 37, 335], [38, 38, 345], [39, 39, 355], [40, 40, 365], [41, 41, 375], [42, 42, 385], [43, 43, 395], [44, 44, 405], [45, 45, 415], [46, 46, 425], [47, 47, 435], [48, 48, 445], [49, 49, 455], [50, 50, 465], [51, 51, 475], [52, 52, 485], [53, 53, 495], [54, 54, 505], [55, 55, 515], [56, 56, 525], [57, 57, 535], [58, 58, 545], [59, 59, 555], [60, 60, 565], [61, 61, 575], [62, 62, 585], [63, 63, 595], [64, 64, 605], [65, 65, 615], [66, 66, 625], [67, 67, 635], [68, 68, 645], [69, 69, 655], [70, 70, 665], [71, 71, 675], [72, 72, 685], [73, 73, 695], [74, 74, 705], [75, 75, 715]]) == 18750\n assert candidate(m = 100,n = 100,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [6, 6, 36], [7, 7, 49], [8, 8, 64], [9, 9, 81], [10, 10, 100], [20, 20, 400], [30, 30, 900], [40, 40, 1600], [50, 50, 2500], [60, 60, 3600], [70, 70, 4900], [80, 80, 6400], [90, 90, 8100], [100, 100, 10000]]) == 10000\n assert candidate(m = 180,n = 120,prices = [[10, 20, 50], [20, 10, 40], [30, 40, 120], [40, 30, 100], [60, 60, 200]]) == 5400\n assert candidate(m = 200,n = 100,prices = [[1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [2, 2, 5], [2, 3, 6], [2, 4, 7], [2, 5, 8], [3, 3, 9], [3, 4, 10], [3, 5, 11], [4, 4, 13], [4, 5, 14], [5, 5, 16]]) == 25000\n assert candidate(m = 18,n = 18,prices = [[1, 1, 1], [1, 2, 3], [2, 1, 3], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 35], [8, 8, 45], [9, 9, 55], [10, 10, 65], [11, 11, 75], [12, 12, 85], [13, 13, 95], [14, 14, 105], [15, 15, 115], [16, 16, 125], [17, 17, 135], [18, 18, 145]]) == 486\n assert candidate(m = 150,n = 100,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 20], [5, 5, 50], [6, 6, 100], [7, 7, 200], [8, 8, 500]]) == 110350\n assert candidate(m = 150,n = 100,prices = [[10, 10, 100], [20, 20, 500], [30, 30, 1200], [5, 5, 20], [15, 15, 300]]) == 19500\n assert candidate(m = 190,n = 130,prices = [[1, 1, 1], [2, 2, 4], [3, 3, 9], [4, 4, 16], [5, 5, 25], [10, 10, 100], [15, 15, 225], [20, 20, 400], [25, 25, 625]]) == 24700\n assert candidate(m = 10,n = 10,prices = [[1, 1, 5], [2, 2, 10], [3, 3, 15], [4, 4, 20], [5, 5, 25], [6, 6, 30], [7, 7, 35], [8, 8, 40], [9, 9, 45], [10, 10, 50]]) == 500\n assert candidate(m = 50,n = 50,prices = [[5, 5, 100], [10, 10, 500], [15, 15, 1200], [20, 20, 2000], [25, 25, 3000], [30, 30, 4000], [35, 35, 5000], [40, 40, 6000], [45, 45, 7000], [50, 50, 8000]]) == 12800\n assert candidate(m = 100,n = 100,prices = [[50, 50, 10000], [25, 25, 2500], [75, 75, 15000], [10, 10, 100], [1, 1, 1]]) == 40000\n assert candidate(m = 10,n = 10,prices = [[1, 1, 1], [2, 2, 5], [3, 3, 10], [4, 4, 15], [5, 5, 20], [6, 6, 25], [7, 7, 30], [8, 8, 35], [9, 9, 40], [10, 10, 50]]) == 125\n assert candidate(m = 150,n = 100,prices = [[1, 1, 1], [2, 2, 5], [5, 5, 10], [10, 10, 20], [15, 15, 30]]) == 18750\n", "comparison": "exact"}, "public_tests": ["3\n5\n[[1,4,2],[2,2,7],[2,1,3]]", "4\n6\n[[3,2,10],[1,4,2],[4,1,3]]"], "hints": ["Note down the different actions that can be done on a piece of wood with dimensions m x n. What do you notice?", "If possible, we could sell the m x n piece. We could also cut the piece vertically creating two pieces of size m x n1 and m x n2 where n1 + n2 = n, or horizontally creating two pieces of size m1 x n and m2 x n where m1 + m2 = m.", "Notice that cutting a piece breaks the problem down into smaller subproblems, and selling the piece when available is also a case that terminates the process. Thus, we can use DP to efficiently solve this."], "metadata": {"canonical_parameter_names": ["m", "n", "prices"], "leetcode_dataset_entry_point": "Solution().sellingWood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:27+00:00", "tests_total": 88, "tests_dropped": 4, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "memoization"]}, "language": "php", "interface": {"raw_signature": "function sellingWood($m, $n, $prices) {", "container": "Solution", "callable": "sellingWood", "parameters": [{"name": "m", "type": "Integer"}, {"name": "n", "type": "Integer"}, {"name": "prices", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2315, "task_id": "count-asterisks", "difficulty": "Easy", "problem_description": "You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1^st and 2^nd '|' make a pair, the 3^rd and 4^th '|' make a pair, and so forth.\n\nReturn the number of '*' in s, excluding the '*' between each pair of '|'.\n\nNote that each '|' will belong to exactly one pair.\n\nExample 1:\n\nInput: s = \"l|*e*et|c**o|*de|\"\nOutput: 2\nExplanation: The considered characters are underlined: \"l|*e*et|c**o|*de|\".\nThe characters between the first and second '|' are excluded from the answer.\nAlso, the characters between the third and fourth '|' are excluded from the answer.\nThere are 2 asterisks considered. Therefore, we return 2.\n\nExample 2:\n\nInput: s = \"iamprogrammer\"\nOutput: 0\nExplanation: In this example, there are no asterisks in s. Therefore, we return 0.\n\nExample 3:\n\nInput: s = \"yo|uar|e**|b|e***au|tifu|l\"\nOutput: 5\nExplanation: The considered characters are underlined: \"yo|uar|e**|b|e***au|tifu|l\". There are 5 asterisks considered. Therefore, we return 5.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s consists of lowercase English letters, vertical bars '|', and asterisks '*'.\n- s contains an even number of vertical bars '|'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"iamprogrammer\") == 0\n assert candidate(s = \"|*|*|*|*|\") == 2\n assert candidate(s = \"||||||||||\") == 0\n assert candidate(s = \"yo|uar|e**|b|e***au|tifu|l\") == 5\n assert candidate(s = \"l|*e*et|c**o|*de|\") == 2\n assert candidate(s = \"abc|def|ghi|jkl|\") == 0\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|\") == 11\n assert candidate(s = \"*|*|*|*|*|*|\") == 3\n assert candidate(s = \"no|asterisks|here|\") == 0\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|\") == 5\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*|\") == 2\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*|\") == 13\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|\") == 13\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*|*\") == 19\n assert candidate(s = \"this|is|a|test|string|with|multiple|pipes|and|asterisks|*|*|*|*|*|*|*|*|*|*|*|\") == 6\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*|\") == 31\n assert candidate(s = \"multiple|pairs|of|bars|and*no*asterisks*between|them|\") == 3\n assert candidate(s = \"*a*|b*c|d*e*f|g*h*i*j|\") == 4\n assert candidate(s = \"abc*def|ghi*jkl|*mnop|qrstu|vwxyz*\") == 3\n assert candidate(s = \"|*a*|b|c*|d*e*|f*g*h|*i*j*k*|l*m*n*o*|\") == 6\n assert candidate(s = \"this|is|a|test|string|with|multiple|pipes|and|asterisks|*|*|*|\") == 2\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|\") == 26\n assert candidate(s = \"|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\") == 0\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*|\") == 0\n assert candidate(s = \"interleaved*characters|with|pipes*and*asterisks|and|more|pipes*and*asterisks*at|the*end*of*the|string*\") == 6\n assert candidate(s = \"|*||||*||||*||||*||||*|\") == 0\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|\") == 0\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*|\") == 1\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*|\") == 27\n assert candidate(s = \"nested||pipes|should|not|affect|the|count|of|*|in|between|pipes|\") == 0\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*|\") == 13\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*|\") == 26\n assert candidate(s = \"long|*sequence*|of|*characters*|to|test|the|*algorithm*|efficiency|\") == 0\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*|*\") == 2\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*|\") == 13\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*|\") == 13\n assert candidate(s = \"nested|*pipes*|and|*asterisks*|inside|*and*|outside|*pipes*|\") == 0\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|\") == 9\n assert candidate(s = \"multiple*asterisks*here|and*here*too|and*here|\") == 3\n assert candidate(s = \"this|is*a*test|to*see*if*the*function*works*correctly*with*many*bars|and*asterisks*in*various*places*|\") == 9\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*|\") == 12\n assert candidate(s = \"*at|the|start*|and|at|the|end*|pipes|should|not|affect|the|count*|\") == 4\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*|\") == 0\n assert candidate(s = \"|pipes|without|*asterisks*|in|between|pipes|should|return|zero|\") == 0\n assert candidate(s = \"*only*|*pipes*|*and*|*asterisks*|*in*|*the*|*string*|\") == 8\n assert candidate(s = \"no*bars*in*string\") == 3\n assert candidate(s = \"no|pipes|here|just|plain|text|and|some|asterisks*at*the*end\") == 3\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*|\") == 6\n assert candidate(s = \"nested*bars*are|not|possible|but|this|is*a*test*case*with*many*bars|and*some*stars*in*the*end*|\") == 8\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 20\n assert candidate(s = \"*at*the*start*and*no*pipes*in*the*middle*or*end\") == 11\n assert candidate(s = \"|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 19\n assert candidate(s = \"noasterisks|here|but|many|pipes|to|confuse|you|\") == 0\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*\") == 1\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|*\") == 1\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*|\") == 14\n assert candidate(s = \"hello*world|this|is*a*test|string|with*many*asterisks|\") == 5\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|*|\") == 14\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|\") == 17\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*|\") == 3\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 18\n assert candidate(s = \"||||||||**||||||||\") == 2\n assert candidate(s = \"*single*|*pair*|of|*pipes*|with|*multiple*|asterisks*|inside*|\") == 3\n assert candidate(s = \"no|pipes|here|just|asterisks|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 11\n assert candidate(s = \"a*|b*c|d*e*f|g*h|i*j*k|l*m*n|\") == 5\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|\") == 18\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 8\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\") == 25\n assert candidate(s = \"this|is*a*test|with*many*asterisks|and*no*exclusions*at*the*end*\") == 2\n assert candidate(s = \"multiple||pipes||in||a||row||with||asterisks*in||between\") == 1\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*|\") == 24\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*|\") == 13\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*|\") == 5\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|*\") == 18\n assert candidate(s = \"hello|world|*python*|programming|*|code*|\") == 3\n assert candidate(s = \"hello|world*is*great|but*this*is*not|\") == 3\n assert candidate(s = \"*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 20\n assert candidate(s = \"*|**|***|****|*****|******|*******|********|*********|**********|\") == 25\n assert candidate(s = \"no|*pipes|or|*asterisks*|here|\") == 0\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|\") == 25\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|\") == 13\n assert candidate(s = \"*middle*|pipes|*middle*|pipes|*middle*|pipes|*middle*|pipes|*middle*|pipes|\") == 10\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*|\") == 18\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*|\") == 1\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|*\") == 1\n assert candidate(s = \"nested|pipes|are|not|possible||but|this|is|how|it|could|look|if|they|were|*|*|*|*|*|*|\") == 3\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*|\") == 13\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*|*|\") == 27\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\") == 25\n assert candidate(s = \"|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 21\n assert candidate(s = \"longer|string|with|many|characters|and|some|pipes|and|asterisks*in*various*places|and*more|pipes|and|asterisks*at*the*end*\") == 1\n assert candidate(s = \"complex|test*case*with*mixed*characters*and*bars*and*asterisks|throughout*the*string|\") == 2\n assert candidate(s = \"single*asterisk*outside*pipes|double**asterisks*inside*pipes|triple***asterisks*outside*pipes\") == 8\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|\") == 8\n assert candidate(s = \"multiple|*pipes*|in|*one*|segment|*of*|the|*string*|should|be|handled|correctly|\") == 0\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|\") == 6\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||\") == 0\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|\") == 12\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|*|*|*|*|\") == 2\n assert candidate(s = \"|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 16\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|\") == 0\n assert candidate(s = \"|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|\") == 20\n assert candidate(s = \"||||||||||||||||||||||||||||||||||||||||||||||||||||\") == 0\n assert candidate(s = \"nested|*p*|ai|*n*|e*d|*|t*e*s*t|case|\") == 4\n", "comparison": "exact"}, "public_tests": ["\"l|*e*et|c**o|*de|\"", "\"iamprogrammer\"", "\"yo|uar|e**|b|e***au|tifu|l\""], "hints": ["Iterate through each character, while maintaining whether we are currently between a pair of ‘|’ or not.", "If we are not in between a pair of ‘|’ and there is a ‘*’, increment the answer by 1."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countAsterisks", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:29+00:00", "tests_total": 106, "tests_dropped": 2, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function countAsterisks($s) {", "container": "Solution", "callable": "countAsterisks", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2316, "task_id": "count-unreachable-pairs-of-nodes-in-an-undirected-graph", "difficulty": "Medium", "problem_description": "You are given an integer n. There is an undirected graph with n nodes, 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 nodes a_i and b_i.\n\nReturn the number of pairs of different nodes that are unreachable from each other.\n\nExample 1:\n\nInput: n = 3, edges = [[0,1],[0,2],[1,2]]\nOutput: 0\nExplanation: There are no pairs of nodes that are unreachable from each other. Therefore, we return 0.\n\nExample 2:\n\nInput: n = 7, edges = [[0,2],[0,5],[2,4],[1,6],[5,4]]\nOutput: 14\nExplanation: There are 14 pairs of nodes that are unreachable from each other:\n[[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]].\nTherefore, we return 14.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- 0 <= edges.length <= 2 * 10^5\n- edges[i].length == 2\n- 0 <= a_i, b_i < n\n- a_i != b_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], [3, 4]]) == 11\n assert candidate(n = 6,edges = []) == 15\n assert candidate(n = 3,edges = [[0, 1], [0, 2], [1, 2]]) == 0\n assert candidate(n = 5,edges = [[0, 1], [2, 3]]) == 8\n assert candidate(n = 10,edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) == 40\n assert candidate(n = 5,edges = [[0, 1], [1, 2], [3, 4]]) == 6\n assert candidate(n = 4,edges = []) == 6\n assert candidate(n = 1,edges = []) == 0\n assert candidate(n = 10,edges = []) == 45\n assert candidate(n = 7,edges = [[0, 2], [0, 5], [2, 4], [1, 6], [5, 4]]) == 14\n assert candidate(n = 6,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9]]) == 25\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, 12], [12, 13], [13, 14], [14, 6], [15, 16], [16, 17], [17, 18], [18, 19], [19, 15]]) == 129\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [4, 5], [6, 7], [7, 8], [8, 9]]) == 33\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], [15, 0]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]]) == 96\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [3, 4], [4, 5], [6, 7], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22], [23, 24]]) == 283\n assert candidate(n = 10,edges = [[0, 1], [2, 3], [3, 4], [4, 5], [6, 7], [7, 8], [8, 9]]) == 32\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]]) == 83\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9], [10, 11], [11, 12], [12, 13], [13, 14]]) == 75\n assert candidate(n = 15,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7], [8, 9], [9, 10], [11, 12], [13, 14]]) == 93\n assert candidate(n = 20,edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19]]) == 180\n assert candidate(n = 15,edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 0]]) == 96\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, 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]]) == 250\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\n assert candidate(n = 50,edges = [[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]]) == 1200\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [8, 9], [9, 10], [11, 12], [13, 14]]) == 87\n assert candidate(n = 100,edges = []) == 4950\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [6, 7], [8, 9]]) == 31\n assert candidate(n = 8,edges = [[0, 1], [1, 2], [2, 3], [4, 5], [5, 6], [7, 4]]) == 16\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]]) == 100\n assert candidate(n = 25,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 12], [12, 9], [13, 14], [14, 15], [15, 16], [16, 13], [17, 18], [18, 19], [19, 20], [20, 17], [21, 22], [22, 23], [23, 24], [24, 21]]) == 260\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [3, 6], [7, 8], [7, 9]]) == 33\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 = 30,edges = [[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]]) == 420\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 2], [3, 4]]) == 6\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]]) == 1035\n assert candidate(n = 100,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], [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]]) == 0\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [3, 4], [4, 5], [5, 6], [7, 8], [8, 9], [9, 10], [11, 12], [12, 13], [13, 14], [14, 7]]) == 68\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [0, 3], [4, 5], [6, 7], [6, 8], [6, 9]]) == 32\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [3, 4], [4, 5], [6, 7], [8, 9]]) == 37\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [11, 12], [12, 13], [13, 14]]) == 74\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 0], [7, 8], [8, 9], [9, 10], [10, 11], [11, 7]]) == 35\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]]) == 0\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, 12], [12, 9], [13, 14], [14, 15], [15, 16], [16, 13], [17, 18], [18, 19], [19, 17]]) == 159\n assert candidate(n = 12,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 36\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [4, 5], [5, 6], [7, 8]]) == 35\n assert candidate(n = 15,edges = [[0, 1], [1, 2], [3, 4], [4, 5], [5, 6], [7, 8], [8, 9], [10, 11], [12, 13], [13, 14]]) == 89\n assert candidate(n = 20,edges = [[0, 1], [0, 2], [1, 3], [2, 4], [5, 6], [5, 7], [6, 8], [7, 9], [10, 11], [11, 12], [12, 13], [13, 14], [15, 16], [16, 17], [17, 18], [18, 19]]) == 150\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 = 25,edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [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]]) == 150\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [4, 5], [5, 6], [7, 8], [8, 9]]) == 33\n assert candidate(n = 10,edges = [[0, 1], [1, 2], [2, 3], [3, 4], [5, 6], [7, 8], [8, 9]]) == 31\n", "comparison": "exact"}, "public_tests": ["3\n[[0,1],[0,2],[1,2]]", "7\n[[0,2],[0,5],[2,4],[1,6],[5,4]]"], "hints": ["Find the connected components of the graph. To find connected components, you can use Union Find (Disjoint Sets), BFS, or DFS.", "For a node u, the number of nodes that are unreachable from u is the number of nodes that are not in the same connected component as u.", "The number of unreachable nodes from node u will be the same for the number of nodes that are unreachable from node v if nodes u and v belong to the same connected component."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().countPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:31+00:00", "tests_total": 55, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "union-find", "graph"]}, "language": "php", "interface": {"raw_signature": "function countPairs($n, $edges) {", "container": "Solution", "callable": "countPairs", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2317, "task_id": "maximum-xor-after-operations", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).\n\nNote that AND is the bitwise AND operation and XOR is the bitwise XOR operation.\n\nReturn the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.\n\nExample 1:\n\nInput: nums = [3,2,4,6]\nOutput: 7\nExplanation: Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.\nNow, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.\nIt can be shown that 7 is the maximum possible bitwise XOR.\nNote that other operations may be used to achieve a bitwise XOR of 7.\n\nExample 2:\n\nInput: nums = [1,2,3,9,2]\nOutput: 11\nExplanation: Apply the operation zero times.\nThe bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.\nIt can be shown that 11 is the maximum possible bitwise XOR.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 0 <= nums[i] <= 10^8\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [8, 1, 4, 2, 15]) == 15\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == 15\n assert candidate(nums = [1, 0, 3, 2]) == 3\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1]) == 1\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]) == 8184\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1]) == 255\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == 7\n assert candidate(nums = [3, 2, 4, 6]) == 7\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000]) == 134217712\n assert candidate(nums = [1, 2, 3, 9, 2]) == 11\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312, 97656, 48828, 24414, 12207, 6103, 3051, 1525, 762, 381, 190, 95, 47, 23, 11, 5, 2, 1]) == 134217727\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 31\n assert candidate(nums = [7, 7, 7, 7, 7]) == 7\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024]) == 2040\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]) == 15\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312, 97656, 48828, 24414, 12207, 6103, 3051, 1525, 762, 381, 190, 95, 47, 23, 11, 5, 2, 1]) == 134217727\n assert candidate(nums = [2, 4, 8, 16, 32]) == 62\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25]) == 31\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1]) == 255\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 1023\n assert candidate(nums = [10, 20, 30, 40]) == 62\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047]) == 2047\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 127\n assert candidate(nums = [1919810, 909405, 454702, 227351, 113675, 56837, 28418, 14209, 7104, 3552, 1776, 888, 444, 222, 111, 55, 27, 13, 6, 3, 1]) == 2097151\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]) == 2097151\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1020\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 = [1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2097151\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 255, 127, 63, 31, 15, 7, 3]) == 255\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575]) == 1048575\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, 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]) == 63\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\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]) == 63\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312, 97656, 48828, 24414, 12207, 6103, 3051, 1525, 762, 381, 190, 95]) == 134217727\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]) == 1048575\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 5, 5, 7, 7, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 29, 29, 31, 31, 37, 37, 41, 41, 43, 43]) == 63\n assert candidate(nums = [23456789, 87654321, 12345678, 45678901, 56789012, 67890123, 78901234, 34567890, 43210987, 76543210, 98765432, 21098765, 32109876, 65432109, 54321098, 43210987, 32109876, 21098765, 10987654, 98765432, 87654321, 76543210, 65432109, 54321098, 43210987, 32109876, 21098765, 10987654, 9876543, 8765432]) == 134217727\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84]) == 127\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 2047\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 65535\n assert candidate(nums = [131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 262143\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 2044\n assert candidate(nums = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 65535\n assert candidate(nums = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240]) == 255\n assert candidate(nums = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 31\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\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 = [16777215, 8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535, 32767]) == 16777215\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]) == 100661247\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1048575\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == 1023\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1023\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]) == 63\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996, 99999995, 99999994, 99999993, 99999992, 99999991]) == 100000255\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\n assert candidate(nums = [1048575, 1048574, 1048573, 1048572, 1048571, 1048570]) == 1048575\n assert candidate(nums = [99999999, 88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111, 100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000, 5000000, 1000000, 500000, 100000, 50000, 10000, 5000, 1000, 500, 100, 50, 10]) == 134217727\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312]) == 134217727\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]) == 13\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 31\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1023\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate(nums = [100000000, 90000000, 80000000, 70000000, 60000000]) == 134217600\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\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, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2097151\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 = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1023\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255]) == 255\n assert candidate(nums = [1048575, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1048575\n assert candidate(nums = [8388607, 4194303, 2097151, 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]) == 8388607\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535]) == 65535\n assert candidate(nums = [100000000, 99999999, 99999998, 99999997, 99999996]) == 100000255\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2047\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 9000, 8000]) == 1048575\n assert candidate(nums = [8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0]) == 16777215\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 = [23, 45, 67, 89, 111, 133, 155, 177]) == 255\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]) == 1048575\n assert candidate(nums = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14]) == 15\n", "comparison": "exact"}, "public_tests": ["[3,2,4,6]", "[1,2,3,9,2]"], "hints": ["Consider what it means to be able to choose any x for the operation and which integers could be obtained from a given nums[i].", "The given operation can unset any bit in nums[i].", "The nth bit of the XOR of all the elements is 1 if the nth bit is 1 for an odd number of elements. When can we ensure it is odd?", "Try to set every bit of the result to 1 if possible."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().maximumXOR", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:34+00:00", "tests_total": 117, "tests_dropped": 34, "flags": [], "topic_tags": ["array", "math", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function maximumXOR($nums) {", "container": "Solution", "callable": "maximumXOR", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2318, "task_id": "number-of-distinct-roll-sequences", "difficulty": "Hard", "problem_description": "You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:\n\n1. The greatest common divisor of any adjacent values in the sequence is equal to 1.\n2. There is at least a gap of 2 rolls between equal valued rolls. More formally, if the value of the i^th roll is equal to the value of the j^th roll, then abs(i - j) > 2.\n\nReturn the total number of distinct sequences possible. Since the answer may be very large, return it modulo 10^9 + 7.\n\nTwo sequences are considered distinct if at least one element is different.\n\nExample 1:\n\nInput: n = 4\nOutput: 184\nExplanation: Some of the possible sequences are (1, 2, 3, 4), (6, 1, 2, 3), (1, 2, 3, 1), etc.\nSome invalid sequences are (1, 2, 1, 3), (1, 2, 3, 6).\n(1, 2, 1, 3) is invalid since the first and third roll have an equal value and abs(1 - 3) = 2 (i and j are 1-indexed).\n(1, 2, 3, 6) is invalid since the greatest common divisor of 3 and 6 = 3.\nThere are a total of 184 distinct sequences possible, so we return 184.\n\nExample 2:\n\nInput: n = 2\nOutput: 22\nExplanation: Some of the possible sequences are (1, 2), (2, 1), (3, 2).\nSome invalid sequences are (3, 6), (2, 4) since the greatest common divisor is not equal to 1.\nThere are a total of 22 distinct sequences possible, so we return 22.\n\nConstraints:\n\n- 1 <= n <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 66\n assert candidate(n = 100) == 534856607\n assert candidate(n = 4) == 184\n assert candidate(n = 10000) == 874574246\n assert candidate(n = 2) == 22\n assert candidate(n = 1) == 6\n assert candidate(n = 1000) == 497171723\n assert candidate(n = 10) == 93120\n assert candidate(n = 2000) == 784558903\n assert candidate(n = 104) == 920649565\n assert candidate(n = 5) == 516\n assert candidate(n = 8000) == 366597434\n assert candidate(n = 5000) == 798977852\n assert candidate(n = 9999) == 455330915\n assert candidate(n = 20) == 996985946\n assert candidate(n = 15) == 16706688\n assert candidate(n = 6) == 1472\n assert candidate(n = 750) == 498714087\n assert candidate(n = 500) == 353640467\n assert candidate(n = 7) == 4136\n", "comparison": "exact"}, "public_tests": ["4", "2"], "hints": ["Can you think of a DP solution?", "Consider a state that remembers the last 1 or 2 rolls.", "Do you need to consider the last 3 rolls?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().distinctSequences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:36+00:00", "tests_total": 21, "tests_dropped": 1, "flags": [], "topic_tags": ["dynamic-programming", "memoization"]}, "language": "php", "interface": {"raw_signature": "function distinctSequences($n) {", "container": "Solution", "callable": "distinctSequences", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2319, "task_id": "check-if-matrix-is-x-matrix", "difficulty": "Easy", "problem_description": "A square matrix is said to be an X-Matrix if both of the following conditions hold:\n\n1. All the elements in the diagonals of the matrix are non-zero.\n2. All other elements are 0.\n\nGiven a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false.\n\nExample 1:\n\nInput: grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]\nOutput: true\nExplanation: Refer to the diagram above.\nAn X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\nThus, grid is an X-Matrix.\n\nExample 2:\n\nInput: grid = [[5,7,0],[0,3,1],[0,5,0]]\nOutput: false\nExplanation: Refer to the diagram above.\nAn X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\nThus, grid is not an X-Matrix.\n\nConstraints:\n\n- n == grid.length == grid[i].length\n- 3 <= n <= 100\n- 0 <= grid[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 2, 0, 0], [0, 0, 0, 3], [0, 0, 4, 0], [0, 5, 0, 0]]) == False\n assert candidate(grid = [[1, 2, 0, 0], [0, 3, 1, 0], [0, 5, 2, 0], [0, 0, 0, 4]]) == False\n assert candidate(grid = [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 5]]) == False\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1]]) == False\n assert candidate(grid = [[5, 7, 0], [0, 3, 1], [0, 5, 0]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 1], [0, 2, 0, 2, 0], [0, 0, 3, 0, 0], [0, 2, 0, 2, 0], [1, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[2, 0, 0, 1], [0, 3, 1, 0], [0, 5, 2, 0], [4, 0, 0, 2]]) == True\n assert candidate(grid = [[6, 0, 0, 0, 6], [0, 7, 0, 7, 0], [0, 0, 8, 0, 0], [0, 7, 0, 7, 0], [6, 0, 0, 0, 6]]) == True\n assert candidate(grid = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]) == False\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == False\n assert candidate(grid = [[0, 1, 0], [1, 2, 1], [0, 1, 0]]) == False\n assert candidate(grid = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]) == False\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) == True\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]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 2, 0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 3, 0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 4, 0, 0, 4, 0, 0, 0], [0, 0, 0, 0, 5, 5, 0, 0, 0, 0], [0, 0, 0, 0, 5, 5, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 4, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 3, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 2, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 2], [0, 3, 0, 0, 0, 0, 5, 0], [0, 0, 6, 0, 0, 8, 0, 0], [0, 0, 0, 9, 10, 0, 0, 0], [0, 0, 0, 11, 12, 0, 0, 0], [0, 0, 13, 0, 0, 14, 0, 0], [0, 15, 0, 0, 0, 0, 16, 0], [17, 0, 0, 0, 0, 0, 0, 18]]) == True\n assert candidate(grid = [[5, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 5]]) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 4, 0, 0, 0], [0, 0, 5, 0, 0, 0, 0], [0, 6, 0, 0, 0, 0, 0], [7, 0, 0, 0, 0, 0, 0]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 1, 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], [0, 0, 0, 0, 0, 6]]) == False\n assert candidate(grid = [[1, 2, 3, 4, 5], [0, 6, 0, 7, 0], [0, 0, 8, 0, 0], [0, 9, 0, 10, 0], [11, 0, 0, 0, 12]]) == False\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7], [0, 8, 0, 0, 0, 9, 0], [0, 0, 10, 0, 11, 0, 0], [0, 0, 0, 12, 0, 0, 0], [0, 0, 13, 0, 14, 0, 0], [0, 15, 0, 0, 0, 16, 0], [17, 0, 0, 0, 0, 0, 18]]) == False\n assert candidate(grid = [[2, 0, 0, 0, 3], [0, 5, 0, 6, 0], [0, 0, 7, 0, 0], [0, 8, 0, 9, 0], [4, 0, 0, 0, 1]]) == True\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]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 3], [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, 0, 0, 2]]) == False\n assert candidate(grid = [[7, 0, 0, 0, 0, 1], [0, 4, 0, 0, 4, 0], [0, 0, 9, 0, 0, 0], [0, 0, 0, 6, 0, 0], [0, 8, 0, 0, 7, 0], [2, 0, 0, 0, 0, 9]]) == False\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]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 1], [0, 2, 0, 0, 0, 2, 0], [0, 0, 3, 0, 3, 0, 0], [0, 0, 0, 4, 0, 0, 0], [0, 0, 5, 0, 5, 0, 0], [0, 6, 0, 0, 0, 6, 0], [7, 0, 0, 0, 0, 0, 7]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 1], [0, 0, 3, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 5, 0], [1, 0, 0, 0, 0, 1]]) == False\n assert candidate(grid = [[7, 0, 0, 0, 0, 0], [0, 6, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 2]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 2, 0, 0, 0, 0, 0, 2, 0], [0, 0, 3, 0, 0, 0, 3, 0, 0], [0, 0, 0, 4, 0, 4, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 4, 0, 4, 0, 0, 0], [0, 0, 3, 0, 0, 0, 3, 0, 0], [0, 2, 0, 0, 0, 0, 0, 2, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0, 1], [0, 1, 0, 1, 0]]) == False\n assert candidate(grid = [[6, 0, 0, 0, 0], [0, 7, 0, 0, 0], [0, 0, 8, 0, 0], [0, 0, 0, 9, 0], [0, 0, 0, 0, 10]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 7], [0, 2, 0, 0, 0, 8, 0], [0, 0, 3, 0, 9, 0, 0], [0, 0, 0, 4, 0, 0, 0], [0, 0, 10, 0, 5, 0, 0], [0, 11, 0, 0, 0, 6, 0], [12, 0, 0, 0, 0, 0, 13]]) == True\n assert candidate(grid = [[6, 0, 0, 0, 1], [0, 7, 0, 3, 0], [0, 0, 8, 0, 0], [0, 9, 0, 5, 0], [2, 0, 0, 0, 4]]) == True\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, 4, 0, 0], [0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 1]]) == False\n assert candidate(grid = [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]]) == False\n assert candidate(grid = [[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], [0, 0, 0, 0, 0, 6]]) == False\n assert candidate(grid = [[9, 0, 0, 0, 0, 0, 0, 0], [0, 8, 0, 0, 0, 0, 0, 0], [0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0, 2]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]) == False\n assert candidate(grid = [[1, 2, 0, 0, 4], [3, 0, 5, 0, 6], [0, 7, 0, 8, 0], [9, 0, 10, 0, 11], [12, 0, 0, 13, 14]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 2], [0, 3, 0, 5, 0], [0, 0, 4, 0, 0], [0, 6, 0, 7, 0], [8, 0, 0, 0, 9]]) == True\n assert candidate(grid = [[10, 0, 0, 0, 0, 0, 0, 0, 0], [0, 9, 0, 0, 0, 0, 0, 0, 0], [0, 0, 8, 0, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2]]) == False\n assert candidate(grid = [[5, 0, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 9]]) == False\n assert candidate(grid = [[5, 0, 0, 0, 0], [0, 6, 0, 0, 0], [0, 0, 7, 0, 0], [0, 0, 0, 8, 0], [0, 0, 0, 0, 9]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 2, 0, 0, 1], [0, 0, 3, 0, 0], [0, 0, 0, 2, 0], [1, 0, 0, 0, 1]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 9, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 2], [0, 2, 0, 3, 0], [0, 0, 4, 0, 0], [0, 5, 0, 6, 0], [7, 0, 0, 0, 8]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 14], [0, 2, 0, 0, 0, 0, 15, 0], [0, 0, 3, 0, 0, 16, 0, 0], [0, 0, 0, 4, 17, 0, 0, 0], [0, 0, 0, 18, 5, 0, 0, 0], [0, 0, 19, 0, 0, 6, 0, 0], [0, 20, 0, 0, 0, 0, 7, 0], [21, 0, 0, 0, 0, 0, 0, 8]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 5], [0, 2, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 5, 0], [6, 0, 0, 0, 0, 7]]) == False\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]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 2], [0, 2, 0, 0, 0, 0, 3, 0], [0, 0, 3, 0, 0, 4, 0, 0], [0, 0, 0, 4, 5, 0, 0, 0], [0, 0, 0, 5, 4, 0, 0, 0], [0, 0, 4, 0, 0, 3, 0, 0], [0, 3, 0, 0, 0, 0, 2, 0], [2, 0, 0, 0, 0, 0, 0, 1]]) == True\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, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 1], [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], [1, 0, 0, 0, 0, 0, 1]]) == False\n assert candidate(grid = [[12, 0, 0, 0, 0, 0], [0, 13, 0, 0, 0, 0], [0, 0, 14, 0, 0, 0], [0, 0, 0, 15, 0, 0], [0, 0, 0, 0, 16, 0], [0, 0, 0, 0, 0, 17]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 9], [0, 2, 0, 0, 0, 0, 8, 0], [0, 0, 3, 0, 0, 7, 0, 0], [0, 0, 0, 4, 6, 0, 0, 0], [0, 0, 0, 6, 4, 0, 0, 0], [0, 0, 7, 0, 0, 3, 0, 0], [0, 8, 0, 0, 0, 0, 2, 0], [9, 0, 0, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]) == False\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]]) == False\n assert candidate(grid = [[5, 0, 0, 0, 0, 0, 7], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [9, 0, 0, 0, 0, 0, 10]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0], [0, 2, 0, 0, 1], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 1, 0, 0, 5]]) == False\n assert candidate(grid = [[0, 1, 0, 0, 0, 0, 0], [1, 0, 2, 0, 0, 0, 0], [0, 2, 0, 3, 0, 0, 0], [0, 0, 3, 0, 4, 0, 0], [0, 0, 0, 4, 0, 5, 0], [0, 0, 0, 0, 5, 0, 6], [0, 0, 0, 0, 0, 6, 0]]) == False\n assert candidate(grid = [[5, 0, 0, 0, 0, 0, 0, 0, 0, 2], [0, 4, 0, 0, 0, 0, 0, 0, 3, 0], [0, 0, 3, 0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 2, 0, 0, 5, 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, 5, 0, 0, 2, 0, 0, 0], [0, 0, 4, 0, 0, 0, 0, 3, 0, 0], [0, 3, 0, 0, 0, 0, 0, 0, 4, 0], [2, 0, 0, 0, 0, 0, 0, 0, 0, 5]]) == False\n assert candidate(grid = [[7, 0, 0, 0, 0], [0, 8, 0, 0, 0], [0, 0, 9, 0, 0], [0, 0, 0, 10, 0], [0, 0, 0, 0, 11]]) == False\n assert candidate(grid = [[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 2, 0], [0, 0, 0, 3, 0, 0], [0, 0, 4, 0, 0, 0], [0, 5, 0, 0, 0, 0], [6, 0, 0, 0, 0, 0]]) == False\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]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 1, 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]]) == False\n assert candidate(grid = [[0, 0, 0, 0, 1], [0, 0, 0, 2, 0], [0, 0, 3, 0, 0], [0, 4, 0, 0, 0], [5, 0, 0, 0, 0]]) == False\n assert candidate(grid = [[1, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0, 0, 1]]) == True\n assert candidate(grid = [[1, 0, 0, 0, 5], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [6, 0, 0, 0, 1]]) == False\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]]) == False\n", "comparison": "exact"}, "public_tests": ["[[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]", "[[5,7,0],[0,3,1],[0,5,0]]"], "hints": ["Assuming a 0-indexed matrix, for a given cell on row i and column j, it is in a diagonal if and only if i == j or i == n - 1 - j.", "We can then iterate through the elements in the matrix to check if all the elements in the diagonals are non-zero and all other elements are zero."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().checkXMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:38+00:00", "tests_total": 70, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix"]}, "language": "php", "interface": {"raw_signature": "function checkXMatrix($grid) {", "container": "Solution", "callable": "checkXMatrix", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2320, "task_id": "count-number-of-ways-to-place-houses", "difficulty": "Medium", "problem_description": "There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed.\n\nReturn the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo 10^9 + 7.\n\nNote that if a house is placed on the i^th plot on one side of the street, a house can also be placed on the i^th plot on the other side of the street.\n\nExample 1:\n\nInput: n = 1\nOutput: 4\nExplanation:\nPossible arrangements:\n1. All plots are empty.\n2. A house is placed on one side of the street.\n3. A house is placed on the other side of the street.\n4. Two houses are placed, one on each side of the street.\n\nExample 2:\n\nInput: n = 2\nOutput: 9\nExplanation: The 9 possible arrangements are shown in the diagram above.\n\nConstraints:\n\n- 1 <= n <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 25\n assert candidate(n = 100) == 20522904\n assert candidate(n = 10000) == 402613600\n assert candidate(n = 2) == 9\n assert candidate(n = 1) == 4\n assert candidate(n = 1000) == 500478595\n assert candidate(n = 10) == 20736\n assert candidate(n = 4000) == 984988507\n assert candidate(n = 7000) == 750848153\n assert candidate(n = 2000) == 329423452\n assert candidate(n = 7500) == 39764836\n assert candidate(n = 50) == 245481867\n assert candidate(n = 5) == 169\n assert candidate(n = 3000) == 511358621\n assert candidate(n = 30) == 30066266\n assert candidate(n = 4) == 64\n assert candidate(n = 1001) == 307206160\n assert candidate(n = 8) == 3025\n assert candidate(n = 250) == 172820552\n assert candidate(n = 8000) == 823868594\n assert candidate(n = 5000) == 851109891\n assert candidate(n = 9999) == 459963766\n assert candidate(n = 20) == 313679521\n assert candidate(n = 15) == 2550409\n assert candidate(n = 2500) == 968650195\n assert candidate(n = 9000) == 641644802\n assert candidate(n = 200) == 450435314\n assert candidate(n = 9) == 7921\n assert candidate(n = 6) == 441\n assert candidate(n = 6000) == 337759600\n assert candidate(n = 500) == 164765197\n assert candidate(n = 7) == 1156\n assert candidate(n = 25) == 580030458\n", "comparison": "exact"}, "public_tests": ["1", "2"], "hints": ["Try coming up with a DP solution for one side of the street.", "The DP for one side of the street will bear resemblance to the Fibonacci sequence.", "The number of different arrangements on both side of the street is the same."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().countHousePlacements", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:41+00:00", "tests_total": 33, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countHousePlacements($n) {", "container": "Solution", "callable": "countHousePlacements", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2321, "task_id": "maximum-score-of-spliced-array", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2, both of length n.\n\nYou can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right].\n\n- For example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left = 1 and right = 2, nums1 becomes [1,12,13,4,5] and nums2 becomes [11,2,3,14,15].\n\nYou may choose to apply the mentioned operation once or not do anything.\n\nThe score of the arrays is the maximum of sum(nums1) and sum(nums2), where sum(arr) is the sum of all the elements in the array arr.\n\nReturn the maximum possible score.\n\nA subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).\n\nExample 1:\n\nInput: nums1 = [60,60,60], nums2 = [10,90,10]\nOutput: 210\nExplanation: Choosing left = 1 and right = 1, we have nums1 = [60,90,60] and nums2 = [10,60,10].\nThe score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.\n\nExample 2:\n\nInput: nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]\nOutput: 220\nExplanation: Choosing left = 3, right = 4, we have nums1 = [20,40,20,40,20] and nums2 = [50,20,50,70,30].\nThe score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.\n\nExample 3:\n\nInput: nums1 = [7,11,13], nums2 = [1,1,1]\nOutput: 31\nExplanation: We choose not to swap any subarray.\nThe score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 1 <= n <= 10^5\n- 1 <= nums1[i], nums2[i] <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [20, 40, 20, 70, 30],nums2 = [50, 20, 50, 40, 20]) == 220\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45]) == 150\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10000, 10000, 10000, 10000, 10000]) == 50000\n assert candidate(nums1 = [100, 200, 300],nums2 = [300, 200, 100]) == 800\n assert candidate(nums1 = [1, 2, 3],nums2 = [4, 5, 6]) == 15\n assert candidate(nums1 = [5000, 5000, 5000],nums2 = [5000, 5000, 5000]) == 15000\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1]) == 8\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 30\n assert candidate(nums1 = [5000, 5000, 5000, 5000, 5000],nums2 = [6000, 6000, 6000, 6000, 6000]) == 30000\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 21\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5]) == 25\n assert candidate(nums1 = [10000, 10000, 10000],nums2 = [1, 1, 1]) == 30000\n assert candidate(nums1 = [60, 60, 60],nums2 = [10, 90, 10]) == 210\n assert candidate(nums1 = [1, 1, 1],nums2 = [10000, 10000, 10000]) == 30000\n assert candidate(nums1 = [7, 11, 13],nums2 = [1, 1, 1]) == 31\n assert candidate(nums1 = [9, 8, 7],nums2 = [1, 2, 3]) == 24\n assert candidate(nums1 = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],nums2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 120\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [1, 2, 3, 4, 5]) == 25\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]) == 310\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000],nums2 = [5000, 5000, 5000, 5000, 5000]) == 50000\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 2, 30, 4, 50, 6, 70, 8, 90, 10]) == 280\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]) == 5500\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5]) == 15\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]) == 550\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]) == 800\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],nums2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 55000\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]) == 50\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]) == 30\n assert candidate(nums1 = [10000, 1, 10000, 1, 10000],nums2 = [1, 10000, 1, 10000, 1]) == 40001\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 = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 200000\n assert candidate(nums1 = [5, 1, 3, 7, 9, 11, 13, 15, 17, 19],nums2 = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 104\n assert candidate(nums1 = [5000, 3000, 1000, 500, 250],nums2 = [250, 500, 1000, 3000, 5000]) == 17000\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]) == 176\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [1, 6, 11, 16, 21]) == 75\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]) == 42\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000],nums2 = [9999, 9999, 9999, 9999, 9999]) == 50000\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]) == 55\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 45\n assert candidate(nums1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],nums2 = [200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 3100\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999]) == 99990\n assert candidate(nums1 = [5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5]) == 41\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 150000\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 58\n assert candidate(nums1 = [10000, 1, 10000, 1, 10000, 1, 10000, 1, 10000, 1],nums2 = [1, 10000, 1, 10000, 1, 10000, 1, 10000, 1, 10000]) == 60004\n assert candidate(nums1 = [10000, 9000, 8000, 7000, 6000],nums2 = [100, 200, 300, 400, 500]) == 40000\n assert candidate(nums1 = [5000, 2000, 3000, 4000, 1000],nums2 = [1000, 4000, 3000, 2000, 5000]) == 19000\n assert candidate(nums1 = [9999, 9998, 9997, 9996, 9995],nums2 = [1, 2, 3, 4, 5]) == 49985\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]) == 36\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]) == 80\n assert candidate(nums1 = [5000, 5000, 5000, 5000, 5000],nums2 = [10000, 10000, 10000, 10000, 10000]) == 50000\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]) == 55\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]) == 550\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],nums2 = [9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000, 9000]) == 100000\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]) == 400\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000]) == 100000\n assert candidate(nums1 = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 50000\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]) == 550\n assert candidate(nums1 = [100, 100, 100, 100, 100],nums2 = [200, 200, 200, 200, 200]) == 1000\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [5000, 4000, 3000, 2000, 1000]) == 21000\n assert candidate(nums1 = [5000, 5000, 5000, 5000, 5000],nums2 = [5000, 5000, 5000, 5000, 5000]) == 25000\n assert candidate(nums1 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000\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]) == 40\n assert candidate(nums1 = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100],nums2 = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 604\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]) == 100\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]) == 20\n assert candidate(nums1 = [1, 2, 3, 4, 5, 100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100, 5, 4, 3, 2, 1]) == 3000\n assert candidate(nums1 = [1, 10, 100, 1000, 10000],nums2 = [10000, 1000, 100, 10, 1]) == 22100\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]) == 5500\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]) == 50\n assert candidate(nums1 = [100, 50, 30, 20, 10],nums2 = [10, 20, 30, 50, 100]) == 330\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]) == 110\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [100, 90, 80, 70, 60]) == 400\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]) == 55\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]) == 210\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]) == 8000\n assert candidate(nums1 = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],nums2 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == 80000\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [10, 8, 6, 4, 2]) == 40\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 60\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]) == 120\n assert candidate(nums1 = [10000, 1, 1, 1, 10000],nums2 = [1, 10000, 10000, 1, 1]) == 40001\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100]) == 2100\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]) == 1760\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000],nums2 = [1, 1, 1, 1, 1]) == 50000\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [1, 2, 3, 4, 5]) == 15000\n assert candidate(nums1 = [1, 1, 1, 1, 1, 10000],nums2 = [10000, 1, 1, 1, 1, 1]) == 20004\n", "comparison": "exact"}, "public_tests": ["[60,60,60]\n[10,90,10]", "[20,40,20,70,30]\n[50,20,50,40,20]", "[7,11,13]\n[1,1,1]"], "hints": ["Think on Dynamic Programming.", "First assume you will be taking the array a and choose some subarray from b", "Suppose the DP is DP(pos, state). pos is the current position you are in. state is one of {0,1,2}, where 0 means taking the array a, 1 means we are taking the subarray b, and 2 means we are again taking the array a. We need to handle the transitions carefully."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().maximumsSplicedArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:43+00:00", "tests_total": 87, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function maximumsSplicedArray($nums1, $nums2) {", "container": "Solution", "callable": "maximumsSplicedArray", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2322, "task_id": "minimum-score-after-removals-on-a-tree", "difficulty": "Hard", "problem_description": "There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\n\nYou are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also 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\nRemove two distinct edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:\n\n1. Get the XOR of all the values of the nodes for each of the three components respectively.\n2. The difference between the largest XOR value and the smallest XOR value is the score of the pair.\n\n- For example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.\n\nReturn the minimum score of any possible pair of edge removals on the given tree.\n\nExample 1:\n\nInput: nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]\nOutput: 9\nExplanation: The diagram above shows a way to make a pair of removals.\n- The 1^st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.\n- The 2^nd component has node [0] with value [1]. Its XOR value is 1 = 1.\n- The 3^rd component has node [2] with value [5]. Its XOR value is 5 = 5.\nThe score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.\nIt can be shown that no other pair of removals will obtain a smaller score than 9.\n\nExample 2:\n\nInput: nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]\nOutput: 0\nExplanation: The diagram above shows a way to make a pair of removals.\n- The 1^st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.\n- The 2^nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.\n- The 3^rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.\nThe score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.\nWe cannot obtain a smaller score than 0.\n\nConstraints:\n\n- n == nums.length\n- 3 <= n <= 1000\n- 1 <= nums[i] <= 10^8\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(nums = [1, 5, 5, 4, 11],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 9\n assert candidate(nums = [10, 20, 30, 40, 50],edges = [[0, 1], [0, 2], [0, 3], [3, 4]]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(nums = [5, 5, 2, 4, 4, 2],edges = [[0, 1], [1, 2], [5, 2], [4, 3], [1, 3]]) == 0\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [3, 6]]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 4\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300],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]]) == 336\n assert candidate(nums = [100000000, 50000000, 25000000, 12500000, 6250000, 3125000, 1562500, 781250, 390625, 195312, 97656, 48828, 24414, 12207],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]]) == 67079550\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 36\n assert candidate(nums = [100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000, 100000000],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]]) == 3\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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]]) == 2\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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]]) == 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],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]]) == 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],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(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 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]]) == 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],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]]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9]]) == 1\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 36\n assert candidate(nums = [9, 3, 5, 2, 7, 1, 8, 6, 4],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8]]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8]]) == 16\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135],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]]) == 75\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 7, 9, 8, 10, 12, 11, 13, 15, 14, 17, 16, 19, 18, 20],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [2, 6], [6, 7], [4, 8], [8, 9], [8, 10], [5, 11], [11, 12], [11, 13], [10, 14], [14, 15], [14, 16], [7, 17], [17, 18], [18, 19]]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11]]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130],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]]) == 20\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11]]) == 11\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],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]]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 36\n assert candidate(nums = [100000000, 99999999, 88888888, 77777777, 66666666, 55555555, 44444444, 33333333, 22222222, 11111111],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 9915534\n assert candidate(nums = [1, 5, 3, 7, 9, 11, 13, 15, 17, 19, 21, 23, 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]]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],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(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],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]]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]]) == 552\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 4\n", "comparison": "exact"}, "public_tests": ["[1,5,5,4,11]\n[[0,1],[1,2],[1,3],[3,4]]", "[5,5,2,4,4,2]\n[[0,1],[1,2],[5,2],[4,3],[1,3]]"], "hints": ["Consider iterating over the first edge to remove, and then doing some precalculations on the 2 resulting connected components.", "Will calculating the XOR of each subtree help?"], "metadata": {"canonical_parameter_names": ["nums", "edges"], "leetcode_dataset_entry_point": "Solution().minimumScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:45+00:00", "tests_total": 55, "tests_dropped": 1, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "bit-manipulation", "tree", "depth-first-search"]}, "language": "php", "interface": {"raw_signature": "function minimumScore($nums, $edges) {", "container": "Solution", "callable": "minimumScore", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2325, "task_id": "decode-the-message", "difficulty": "Easy", "problem_description": "You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:\n\n1. Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table.\n2. Align the substitution table with the regular English alphabet.\n3. Each letter in message is then substituted using the table.\n4. Spaces ' ' are transformed to themselves.\n\n- For example, given key = \"happy boy\" (actual key would have at least one instance of each letter in the alphabet), we have the partial substitution table of ('h' -> 'a', 'a' -> 'b', 'p' -> 'c', 'y' -> 'd', 'b' -> 'e', 'o' -> 'f').\n\nReturn the decoded message.\n\nExample 1:\n\nInput: key = \"the quick brown fox jumps over the lazy dog\", message = \"vkbs bs t suepuv\"\nOutput: \"this is a secret\"\nExplanation: The diagram above shows the substitution table.\nIt is obtained by taking the first appearance of each letter in \"the quick brown fox jumps over the lazy dog\".\n\nExample 2:\n\nInput: key = \"eljuxhpwnyrdgtqkviszcfmabo\", message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\"\nOutput: \"the five boxing wizards jump quickly\"\nExplanation: The diagram above shows the substitution table.\nIt is obtained by taking the first appearance of each letter in \"eljuxhpwnyrdgtqkviszcfmabo\".\n\nConstraints:\n\n- 26 <= key.length <= 2000\n- key consists of lowercase English letters and ' '.\n- key contains every letter in the English alphabet ('a' to 'z') at least once.\n- 1 <= message.length <= 2000\n- message consists of lowercase English letters and ' '.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"cba zyx\") == \"xyz abc\"\n assert candidate(key = \"a quick movement of the enemy will jeopardize five gunboats\",message = \"yfcj myj pyjl ufcj myj pyjl ufcj myj pyjl\") == \"omer gor sorq cmer gor sorq cmer gor sorq\"\n assert candidate(key = \"the five boxing wizards jump quickly on this yellow pig\",message = \"jhxuh lqdj efxgh lpuaz fxdyjzjw\") == \"rbisb yvpr cdikb yusnm dipzrmrl\"\n assert candidate(key = \"dvhfujngcpqxlwokzriebastmy\",message = \"mwtiaz azr\") == \"ynxsvq vqr\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"xyz abc\") == \"xyz abc\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"vkbs bs t suepuv\") == \"this is a secret\"\n assert candidate(key = \"byvzkgxfnqmpalwodjtrshceui\",message = \"xsm wv zmz\") == \"guk oc dkd\"\n assert candidate(key = \"wmtresuavhigdcbfykjqploxzn\",message = \"lfnlccyvmdg\") == \"vpzvnnqibml\"\n assert candidate(key = \"zabcdefghijklmnopqrstuvwxy\",message = \"sl rfc zdf\") == \"tm sgd aeg\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"mlkjhgfedcbazyxwvutsrqpon\") == \"nopqstuvwxyzabcdefghijklm\"\n assert candidate(key = \"eljuxhpwnyrdgtqkviszcfmabo\",message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\") == \"the five boxing wizards jump quickly\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"z x c v\") == \"z x c v\"\n assert candidate(key = \"gysrnhxvaofcedwmltukipjbqz\",message = \"gigv symykgl igxvxjxg\") == \"auah cbpbtaq uaghgwga\"\n assert candidate(key = \"phinxajsgkrzcwvltqbdemoufy\",message = \"xvo wv pmj\") == \"eow no avg\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"zaoymnbxcqrljtheifkgdvspwu\") == \"zaoymnbxcqrljtheifkgdvspwu\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"gsv jfrxp yildm ulc\") == \"olw qnduj fhsmz gsv\"\n assert candidate(key = \"the five boxing wizards jump quickly on this june day\",message = \"ymj lvfx sflhzymhs vxlw wjymjlvfx sflhzymhs\") == \"ztr yfdi qdybmztbq fiyl lrztryfdi qdybmztbq\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt\") == \"thequ ickbr ownfo xjump sover thela zydog\"\n assert candidate(key = \"dfghjklwcvxziomnpqrustyabe\",message = \"kckd ykky\") == \"fifa wffw\"\n assert candidate(key = \"mnychdpbxofl wgviakjuzterqs\",message = \"irhvmvccsjb\") == \"pxeoaoddzsh\"\n assert candidate(key = \"pack my box with five dozen liquor jugs\",message = \"xujf qv zgy jxpx qne nfgqj sraju\") == \"ivxn uo ryf xiai usp snyux zwbxv\"\n assert candidate(key = \"mwp dhxjzvcqrkbyanflstguoei\",message = \"di vccvmr wv czebwqha wv iv lvyrj\") == \"dz ijjial bi jhynbkep bi zi siolg\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"a b c d\") == \"z y x w\"\n assert candidate(key = \"the five boxing wizards jump quickly\",message = \"fmwp vifd ttp xosmead\") == \"dtlu fedp aau ihqtcnp\"\n assert candidate(key = \"vuqangfkswjpryxtdmzobhcile\",message = \"wfn yv yfcv\") == \"jge na ngwa\"\n assert candidate(key = \"abcdefghijk lmnopqrstuvwxyz\",message = \"eiqhw fjq hwdq\") == \"eiqhw fjq hwdq\"\n assert candidate(key = \"a quick movement of the enemy will jeopardize five gunboats\",message = \"zruog glhvg frp fvdw zl glcgv\") == \"vtchw wqniw mts miup vq wqewi\"\n assert candidate(key = \"thejumpsquickbrownfoxoverlazydog\",message = \"svhjyjsiqphsjudprvcbgijz\") == \"htbdxdhjigbhdeygntkmzjdw\"\n assert candidate(key = \"ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az\",message = \"qz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz\") == \"qz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz vz\"\n assert candidate(key = \"swzybfrxlnaoumdgtqivhjkpce\",message = \"flgxswdliefyirukyoaqmpjc\") == \"fiphaboiszfdsgmwdlkrnxvy\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"qruqz efn nhr htyq\") == \"djedw cnm mbj baxd\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"xibohu uvp xibohu\") == \"ofikbe etr ofikbe\"\n assert candidate(key = \"abcd efgh ijkl mnop qrst uvwx yz\",message = \"vuwx yz abcd ef\") == \"vuwx yz abcd ef\"\n assert candidate(key = \"gymnopqrstuvwxzabcdefhiljk\",message = \"xqmgq zm zmjy\") == \"ngcag oc ocyb\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"yxe xe xe\") == \"bcv cv cv\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",message = \"abc def abc\") == \"abc def abc\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"vxp qpy o\") == \"vxp qpy o\"\n assert candidate(key = \"jumps over the lazy dog quick brown fox\",message = \"pvuzr cgviy ojizv bxz cfiwz nqzsx vgrb\") == \"dgbni tqgso fasng vzn tyswn xrnez gqiv\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"xqf\") == \"odn\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"gfn\") == \"znm\"\n assert candidate(key = \"pzucfelxwyabqomtjirdnsvhgk\",message = \"kwj kwi kwv wkv\") == \"ziq zir ziw izw\"\n assert candidate(key = \"fmwtkujhpnobxigcsqrzydalve\",message = \"fyh fyt fyv yfj\") == \"auh aud auy uag\"\n assert candidate(key = \"abcdefghij klmnopqrstuvwxyz\",message = \"qzcfj nx ud qzcfj\") == \"qzcfj nx ud qzcfj\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx x\") == \"xpo o\"\n assert candidate(key = \"jumps over lazy dogs quick brown fox the this\",message = \"yjiwxtw vqzj spwq ovbxc yoz qjxv\") == \"maquxyu gpla edup fgtxr mfl paxg\"\n assert candidate(key = \"jklmnopqrstuvwxyzabcdefghi\",message = \"frg fmh gfn\") == \"wix wdy xwe\"\n assert candidate(key = \"zabcdefghijklmnopqrstuvwxy\",message = \"qxy xyx yxq\") == \"ryz yzy zyr\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog and the quick brown fox jumps over the lazy dog\",message = \"vkbs bs t suepuv\") == \"this is a secret\"\n assert candidate(key = \"ekmflgdqvzntowyhxuspaibrcj\",message = \"jbs xut hig\") == \"zws qrl pvf\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"iyh uhy l\") == \"rbs fsb o\"\n assert candidate(key = \"vwxymnbcdfghjklqropstuzaike\",message = \"vcp o cv vcp\") == \"ahs r ha ahs\"\n assert candidate(key = \"ajfzldkgotmhrvwsypnqicxebu\",message = \"oxt oxi oxd xot\") == \"iwj iwu iwf wij\"\n assert candidate(key = \"jklmnopqrstuvwxyzabcdefghi\",message = \"wfn yv yfcv\") == \"nwe pm pwtm\"\n assert candidate(key = \"tevosjhbnyxrgqkfaumzilwpcd\",message = \"npu gpm gpy lgg\") == \"ixr mxs mxj vmm\"\n assert candidate(key = \"mnbvcxzlkjhgfdsapoiuytrewq\",message = \"hfu q jhu\") == \"kmt z jkt\"\n assert candidate(key = \"asdfghjklqwertyuiopzxcvbnm\",message = \"yqz dpy o\") == \"ojt cso r\"\n assert candidate(key = \"qbnvgjlftscxkouwamdphzreiy\",message = \"umr urv urm pyz\") == \"orw owd owr tzv\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"zqj dpy o\") == \"taq mjf i\"\n assert candidate(key = \"five boxing wizards jump quickly on this lazy dog\",message = \"qzyc yvzctv yxqjvzq yjiwxtw on qjxv yoj\") == \"tkxu xckuyc xgtpckt xpbjgyj fh tpgc xfp\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"c e\") == \"g c\"\n assert candidate(key = \"abcdefghizjklmnopqrstuvwxy\",message = \"lii eil eil\") == \"mii eim eim\"\n assert candidate(key = \"vxznpqjwoefkytlimrdhaguscb\",message = \"tyf iy tf\") == \"nmk pm nk\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"sw uqz\") == \"sl edw\"\n assert candidate(key = \"jxwtrklivnpmhudsfgcayzbeoq\",message = \"kcfizgv zr ocfv\") == \"fsqhvri ve ysqi\"\n assert candidate(key = \"lazy dogs quick brown fox jumps over the this\",message = \"vqzj spwq ovbxc yjiwxtw vqzj qjxv\") == \"wict hvpi fwnsl dtkpsyp wict itsw\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx z\") == \"xpo w\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"mlml qmf lml gmgg\") == \"mlml qmf lml gmgg\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"vz\") == \"tw\"\n assert candidate(key = \"dbrujxfgzvcotwiympnslakqhe\",message = \"kmqs ks u kqsebs\") == \"wqxt wt d wxtzbt\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"wqiv xi sqin sqin\") == \"ldft of sdfm sdfm\"\n assert candidate(key = \"dtjgsvyzxpkbfqwulcmohraeni\",message = \"obr obn oti atn\") == \"tlv tly tbz wby\"\n assert candidate(key = \"abcdefghijk lmnopqrstuvwxyz\",message = \"svil km ybgu bg ujr krkhi yjr cvvux\") == \"svil km ybgu bg ujr krkhi yjr cvvux\"\n assert candidate(key = \"the quick brown fox jumps over lazy dogs\",message = \"mht zrs xqf ovkqvoq ngyu kgxqj bpxc\") == \"qba wjs odn kthdtkd mzxe hzodp irog\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"jyq zq o\") == \"qfa ta i\"\n assert candidate(key = \"gibrfqotdhewakjyzlxmvncpus\",message = \"yxh lo loxhy\") == \"psj rg rgsjp\"\n assert candidate(key = \"mnopqrstuvwxyzabcdefghijkl\",message = \"aov eovm eovm\") == \"ocj scja scja\"\n assert candidate(key = \"gfedcbauioplkjhzyxwvtsrqmn\",message = \"ixv yxv oxv\") == \"irt qrt jrt\"\n assert candidate(key = \"xyzabcdefghijklmnopqrstuvw\",message = \"wvf v fv\") == \"zyi y iy\"\n assert candidate(key = \"abc def ghijk lmnop qrst uvwxyz\",message = \"nvmjy nbsytw\") == \"nvmjy nbsytw\"\n assert candidate(key = \"eljuxhpwnyrdgtqkviszcfmabo\",message = \"ihd hsih xihw gh hsi\") == \"rfl fsrf erfh mf fsr\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"zqv qv q\") == \"mdi di d\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"qytz nwt zwt\") == \"dxaw mla wla\"\n assert candidate(key = \"quick brown fox jumps over the lazy dog and the quick brown fox jumps\",message = \"vxw aov g pufa ohq\") == \"qli vhq z obkv hta\"\n assert candidate(key = \"vbnmxczasdfghjklpoiuytrewq\",message = \"vkbs bs t suepuv\") == \"aobi bi v itxqta\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"yvc zc yz\") == \"bex ax ba\"\n assert candidate(key = \"azbycxdwevfugthrskjqplomni\",message = \"tqppf ptd je\") == \"ntuuk ung si\"\n assert candidate(key = \"xylophone qwertyuiop asdfghjklz cvbnm\",message = \"cvmu cvxqv\") == \"wxzm wxaix\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"lqtfw xtg twkxq\") == \"saenb ueo ebrua\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx v\") == \"xpo t\"\n assert candidate(key = \"nmqpviwedklxzfgrctuhyjasob\",message = \"ohc oha ohu voh\") == \"ytq ytw yts eyt\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"izk zkh bva jnfrdq\") == \"vmx mxu oin waseqd\"\n assert candidate(key = \"quick brown fox jumps over the lazy dog\",message = \"rwjsi exmti gsrhri zv wimtix egzewy\") == \"gimpc rlnsc zpgtgc wq icnscl rzwrix\"\n assert candidate(key = \"lazy dogs jumps over the quick brown fox the\",message = \"vqzj yjiwxtw spwq yoj spwq ovbxc yoz\") == \"mrci diswzpw hlwr dfi hlwr fmvzt dfc\"\n assert candidate(key = \"mnopqrstuvwxyzabcdefghijkl\",message = \"mud gct gct\") == \"air uqh uqh\"\n assert candidate(key = \"lazy dogs jumps quickly over the brown fox and\",message = \"vqzj yjiwxtw spwq yoj ovbxc yoz\") == \"qmci dinwztw hlwm dfi fqvzo dfc\"\n assert candidate(key = \"vzhofucmlnjqbdspartexwiykg\",message = \"dpy ld o yv\") == \"npx in d xa\"\n assert candidate(key = \"mnbvcxzlkjhgfdsapoiuytrewq\",message = \"cv lpcv\") == \"ed hqed\"\n assert candidate(key = \"the lazy dog jumps over the quick brown fox\",message = \"qjxv yoj vqzj spwq yjiwxtw ovbxc yvoqzgkxq\") == \"rkzp gik prfk onwr gkswzaw ipvzt gpirfjuzr\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx yjx\") == \"xpo xpo\"\n assert candidate(key = \"cvzkgbxquihmpnytjrsdawolef\",message = \"cfr cfd cfl mfl\") == \"azr azt azx lzx\"\n assert candidate(key = \"lazy dogs jumps quickly over the brown fox the\",message = \"vqzj yjiwxtw spwq yoj ovbxc yoj\") == \"qmci dinwztw hlwm dfi fqvzo dfi\"\n assert candidate(key = \"thezyxwvutsrqponmlkjihgfedcba\",message = \"zqv eovm ztqkofv ztqkofv\") == \"dlh cnhp dalrnvh dalrnvh\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"evh vhe yhe\") == \"ves esv bsv\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"zqf ykq fqu fqo ykt nqtk\") == \"wdn xhd nde ndk xha mdah\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"hqv v yhqf\") == \"hqv v yhqf\"\n assert candidate(key = \"ponmlkjihgfedcbazyxwvutsrq\",message = \"jxqy xtgy efn nhr\") == \"gszr swjr lkc ciy\"\n assert candidate(key = \"gymbztfkwjxehalnqosrudvpci\",message = \"nqzv nq p azdvmn\") == \"pqew pq x nevwcp\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"zcf bvg jnfrdq\") == \"zcf bvg jnfrdq\"\n assert candidate(key = \"brown fox the quick jumps over lazy dogs and\",message = \"ovbxc yoz spwq yvoqzgkxq vqzj qjxv ovgx\") == \"ctagn xcw srdk xtckwzogk tkwp kpgt ctzg\"\n assert candidate(key = \"qpwoeirutyalskdjfhgczxmvbn\",message = \"vcp o cv ocv\") == \"xtb d tx dtx\"\n assert candidate(key = \"ijklmnopqrstuvwxyzabcdefgh\",message = \"wqv qv q\") == \"oin in i\"\n assert candidate(key = \"cijqxfyvolnmtzgdwsaehrkpbu\",message = \"fnw uvf uft nwg\") == \"fkq zhf zfm kqo\"\n assert candidate(key = \"lazy dogs jump quickly over the brown fox\",message = \"jxqy xtgy efn nhr\") == \"izmd ztgd ryx xus\"\n assert candidate(key = \"phinxqbcdgjkamlstvrewyzouf\",message = \"thx thg lv xkqhs\") == \"qbe qbj or elfbp\"\n assert candidate(key = \"jklmnopqrstuvwxyzabcdefghi\",message = \"dru gct gct\") == \"uil xtk xtk\"\n assert candidate(key = \"jxqtvknpsmuhbdrgzlcewfoaiy\",message = \"dgy gch dgy\") == \"npz psl npz\"\n assert candidate(key = \"abcdefghijklnmopqrstuvwxyz\",message = \"opq qpo qpo\") == \"opq qpo qpo\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"gsv htk gdv jgd\") == \"olw per omw qom\"\n assert candidate(key = \"wsgczxfltkbqpndohjuaevrmiy\",message = \"vmx gpm mvg maq\") == \"vxf cmx xvc xtl\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"xol mlu w yjx\") == \"xol mlu w yjx\"\n assert candidate(key = \"dogs quick brown fox jumps over lazy the this\",message = \"vqzj spwq ovbxc yjiwxtw vqzj qjxv\") == \"sewp drle bsjoh xpgloyl sewp epos\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx y\") == \"xpo x\"\n assert candidate(key = \"lmnopqrstuvwxyzabcdefghijk\",message = \"vqj qjv z\") == \"kfy fyk o\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"qiy oiq z\") == \"qiy oiq z\"\n assert candidate(key = \"and the quick brown fox jumps over lazy dogs\",message = \"ovgx yoj spwq yvoqzgkxq ovbxc yjiwxtw vqzj\") == \"nvzq ynr utog yvngxzkqg nvlqj yrioqdo vgxr\"\n assert candidate(key = \"qwertyuioplkjhgfdsazxcvbnm\",message = \"gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt\") == \"orwmp dujfh kqzgk vapyl nkcwh orwit sxbke\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"zqv qv z\") == \"mdi di m\"\n assert candidate(key = \"quick brown fox jumps over lazy dogs the this\",message = \"yvoqzgkxq ovbxc yjiwxtw vqzj qjxv spwq qjxv\") == \"vqhauxela hqfld vmcilyi qaum amlq poia amlq\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"oxj o j\") == \"iuq i q\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"sw yjx\") == \"sl xpo\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"v zifw ilxqfs\") == \"t wfnl fuodns\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"qzcf bfgs jgcd yqcf\") == \"qzcf bfgs jgcd yqcf\"\n assert candidate(key = \"abcdefghizjklmnopqrstuvwxy\",message = \"ulc cul cul\") == \"vmc cvm cvm\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"tsr rst rst\") == \"ghi ihg ihg\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"qz cf\") == \"dw gn\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"mfir kkfr ifxk\") == \"znhd rrnd hnur\"\n assert candidate(key = \"fnex wpviqkdmtlugybhcarzsoj\",message = \"hcv uxl\") == \"stg odn\"\n assert candidate(key = \"zebra quick brown fox jumps over the lazy dog\",message = \"gqjty efn nhr htyq\") == \"zfpux bnm mvd vuxf\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"vqz zqv z\") == \"idm mdi m\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"vgj ov sa jhygjmt oh rjw\") == \"tzp kt sv pbxzpqa kb jpl\"\n assert candidate(key = \"bcadefghijklmnopqrstuvwxzy\",message = \"bdc bva jnfrdq\") == \"adb avc jnfrdq\"\n assert candidate(key = \"asdfghjklqwertyuiopzxcvbnm\",message = \"wqv qv q\") == \"kjw jw j\"\n assert candidate(key = \"zebra tiger quick brown fox jumps over the lazy dog\",message = \"uybvf ojizv cfiwz nqzsx vgrb cgviy ojizv bxz\") == \"jycvp mrgav kpgna oiauq vhdc khvgy mrgav cqa\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"dkv v yvk\") == \"yht t xth\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"zqv qv zc\") == \"mdi di mp\"\n assert candidate(key = \"the brown fox jumps quickly over a lazy dog\",message = \"pjoj qvw xqt jqtqi yjiwxtw spwq jx gsvk yoj\") == \"nkfk pvg jpa kpapq ukqgjag ongp kj zovs ufk\"\n assert candidate(key = \"this quick brown fox jumps over lazy dogs\",message = \"qjxv yvoqzgkxq ovbxc yjiwxtw spwq yoj vqzj\") == \"epos xskewzhoe ksiog xpcloal drle xkp sewp\"\n assert candidate(key = \"jklmnopqrstuvwxyzabcdefghi\",message = \"sgtw xjxw xjxw\") == \"jxkn oaon oaon\"\n assert candidate(key = \"a bc df egh ijkl mno pq rs tuvwxyz\",message = \"v lqyq w lwv yjx\") == \"v lqyq w lwv yjx\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"qzcfb qmgox ypgmt gsv fiu\") == \"qzcfb qmgox ypgmt gsv fiu\"\n assert candidate(key = \"pqrkxlcdemosvahzwfygtnujib\",message = \"izv zfc yfcv\") == \"ypm prg srgm\"\n assert candidate(key = \"lazy dogs jump over quick brown fox the\",message = \"bxz bpxc wxqgc ebcjg fcivw zqzsx ojizv\") == \"txc tlxr uxpgr ntrig wrqmu cpchx fiqcm\"\n assert candidate(key = \"okyftdazhsxngijwumrcvqlpeb\",message = \"kqv mhg a lv vjx\") == \"bvu rim g wu uok\"\n assert candidate(key = \"the brown fox jumps quickly over a lazy dog\",message = \"mht zrs xqf ovkqvoq ngyu a qzfe nax\") == \"mba xeo jpi fvspvfp hzul w pxic hwj\"\n assert candidate(key = \"over lazy dogs quick brown fox jumps the this\",message = \"spwq vqzj spwq ovbxc yjiwxtw qjxv qjxv\") == \"kxrl blgv kxrl abquo hvnruyr lvub lvub\"\n assert candidate(key = \"the brown quick fox jumps over lazy dogs\",message = \"zqft gqf vxt xec ohq oizd\") == \"wina zin toa ocl fbi fkwy\"\n assert candidate(key = \"jumped over the lazy brown fox quick\",message = \"ujxqyc efn nhr htyq\") == \"batuow esr rki kjou\"\n assert candidate(key = \"fghijklmnopqrstuvwxyzabcde\",message = \"vrc vja vrc vja\") == \"qmx qev qmx qev\"\n assert candidate(key = \"the quick brown fox jumps over lazy dogs and\",message = \"spwq yvoqzgkxq ovbxc yjiwxtw vqzj ovgx\") == \"srld xtkdwzhod ktiog xpfloal tdwp ktzo\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"qjvux xfgf q px\") == \"dpteo onzn d ro\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dog\",message = \"dkv v ydv\") == \"yht t xyt\"\n assert candidate(key = \"xlsnmveizhptfjugobcdkqrway\",message = \"wcr vcv wcv xwv\") == \"xsw fsf xsf axf\"\n assert candidate(key = \"quick brown fox jumps over lazy dog the\",message = \"fxfsr jxqfk wtf pvuzr bcgy jxqfk dvo\") == \"klkpg mlake iyk oqbug fdxv mlake wqh\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx w\") == \"xpo l\"\n assert candidate(key = \"bdfhjlnprtvxzcgikmoqsuwyae\",message = \"hc vjg cji cgy\") == \"dn keo nep nox\"\n assert candidate(key = \"onmlkjihgfedcbazyxwvutsrqp\",message = \"ixkz znxoz kx yq\") == \"grep pbrap er qy\"\n assert candidate(key = \"phqgiumeaylnofdxjkrcvstzwb\",message = \"ixw ikg ikg ikg\") == \"epy erd erd erd\"\n assert candidate(key = \"five boxing wizards jump quickly on this lazy dog\",message = \"wfkq xqfnk uveogvj pvuzr cfiwz rjgt jxqfk bxz\") == \"javt gtahv qcdficp scqkm uabjk mpiy pgtav egk\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"vqj qjv cv\") == \"waq aqw vw\"\n assert candidate(key = \"abcdefghjklmnopqrstuvwxyzti\",message = \"ghw gct gct\") == \"ghv gcs gcs\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"fnbv wvxm\") == \"nmit ltoq\"\n assert candidate(key = \"the quick brown fox jumps over the lazy dogs\",message = \"yjx\") == \"xpo\"\n assert candidate(key = \"mnbvcxzlkjhgfdsapoiuytrewq\",message = \"qnb wql fhw fql\") == \"zbc yzh mky mzh\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz\",message = \"anxanq azoz anu\") == \"anxanq azoz anu\"\n assert candidate(key = \"thequickbrownfoxjumpsoverthelazydogs\",message = \"qjvux xfgf q px\") == \"dpteo onzn d ro\"\n assert candidate(key = \"abcdefghjklmnopqrstuvwxyzti\",message = \"jkq xjxw xjxw\") == \"ijp wiwv wiwv\"\n assert candidate(key = \"bujgtfayrxohqzplmwdinckevs\",message = \"yzq d pyq o\") == \"hnm s ohm k\"\n assert candidate(key = \"rjkylmfdqogavwunhixpctzesb\",message = \"tzm tmz tmh tmi\") == \"vwf vfw vfq vfr\"\n assert candidate(key = \"the quick brown fox jumps over lazy dogs this\",message = \"spwq yvoqzgkxq ovbxc yjiwxtw vqzj qjxv\") == \"srld xtkdwzhod ktiog xpfloal tdwp dpot\"\n assert candidate(key = \"brown fox jumps over lazy dogs the quick this\",message = \"ovbxc yjiwxtw vqzj qjxv spwq yvoqzgkxq\") == \"cmagy rhxdgud mwqh whgm lkdw rmcwqtzgw\"\n assert candidate(key = \"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\",message = \"z k u o c g t w\") == \"z k u o c g t w\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"gtgt nvo gtg mpgg\") == \"tgtg mel tgt nktt\"\n assert candidate(key = \"ijklmnopqrstuvwxyzabcdefgh\",message = \"wqv qv qv\") == \"oin in in\"\n assert candidate(key = \"mjw qzlnf hw uo kcf jehrv dpo osxgt cyqak\",message = \"jnjfdh frl df\") == \"bgbhqi hof qh\"\n assert candidate(key = \"abcdefghizjklmnopqrstuvwxy\",message = \"vuvw xw yx za\") == \"wvwx yx zy ja\"\n assert candidate(key = \"abcdefghijklnmopqrstuvwxyz\",message = \"ehu zcv i\") == \"ehu zcv i\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"ehu zcv i\") == \"ehu zcv i\"\n assert candidate(key = \"wvutsrqponmlkjihgfedcba zyx\",message = \"zyxwvutsrqpnmolkjihgfedcba\") == \"xyzabcdefghjkilmnopqrstuvw\"\n assert candidate(key = \"mnbvcxzlkjhgfdsapoiuytrewq\",message = \"vcp o cv v\") == \"deq r ed d\"\n assert candidate(key = \"qwertyuiopasdfghjklzxcvbnm\",message = \"jyq zq j\") == \"qfa ta q\"\n assert candidate(key = \"the brown fox jumps over the lazy dog quickly\",message = \"tqpp d dswcp gygij\") == \"awnn u uogyn vtvxk\"\n assert candidate(key = \"zyxwvutsrqponmlkjihgfedcba\",message = \"ixq kivk eiqb\") == \"rcj prep vrjy\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"wklv lv dq xvh hqw phvvdjh\") == \"wklv lv dq xvh hqw phvvdjh\"\n assert candidate(key = \"nopqrstuvwxyzabcdefghijklm\",message = \"zcf jopcnboe wj jop\") == \"mps wbcpaobr jw wbc\"\n assert candidate(key = \"xyzabcdefghijklmnopqrstuvw\",message = \"xpu xh z\") == \"asx ak c\"\n assert candidate(key = \"quick brown fox jumps over the lazy dog\",message = \"kxvzn hqomj jxq zpsvx wbvs hq tkgx\") == \"elqwj tahnm mla wopql ifqp ta sezl\"\n assert candidate(key = \"abcdefghijklmnopqrstuvwxyz\",message = \"ehu zcv z\") == \"ehu zcv z\"\n assert candidate(key = \"this quick brown fox jumps over lazy dogs and\",message = \"qjxv spwq yvoqzgkxq ovbxc yjiwxtw vqzj ovgx\") == \"epos drle xskewzhoe ksiog xpcloal sewp kszo\"\n assert candidate(key = \"abcdef ghijklmnopqrstuvwxyz\",message = \"zcf bvg jnfrdq\") == \"zcf bvg jnfrdq\"\n assert candidate(key = \"abcdefghijklnmopqrstuvwxyz\",message = \"qzdv lqaf qv yzxq\") == \"qzdv lqaf qv yzxq\"\n assert candidate(key = \"abcdefghikjlmnopqrstuvwxyz\",message = \"hij iji iij\") == \"hik iki iik\"\n", "comparison": "exact"}, "public_tests": ["\"the quick brown fox jumps over the lazy dog\"\n\"vkbs bs t suepuv\"", "\"eljuxhpwnyrdgtqkviszcfmabo\"\n\"zwx hnfx lqantp mnoeius ycgk vcnjrdb\""], "hints": ["Iterate through the characters in the key to construct a mapping to the English alphabet.", "Make sure to check that the current character is not already in the mapping (only the first appearance is considered).", "Map the characters in the message according to the constructed mapping."], "metadata": {"canonical_parameter_names": ["key", "message"], "leetcode_dataset_entry_point": "Solution().decodeMessage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:50+00:00", "tests_total": 204, "tests_dropped": 3, "flags": ["figure_reference", "has_images"], "topic_tags": ["hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function decodeMessage($key, $message) {", "container": "Solution", "callable": "decodeMessage", "parameters": [{"name": "key", "type": "String"}, {"name": "message", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2327, "task_id": "number-of-people-aware-of-a-secret", "difficulty": "Medium", "problem_description": "On day 1, one person discovers a secret.\n\nYou are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after discovering it. A person cannot share the secret on the same day they forgot it, or on any day afterwards.\n\nGiven an integer n, return the number of people who know the secret at the end of day n. Since the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 6, delay = 2, forget = 4\nOutput: 5\nExplanation:\nDay 1: Suppose the first person is named A. (1 person)\nDay 2: A is the only person who knows the secret. (1 person)\nDay 3: A shares the secret with a new person, B. (2 people)\nDay 4: A shares the secret with a new person, C. (3 people)\nDay 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)\nDay 6: B shares the secret with E, and C shares the secret with F. (5 people)\n\nExample 2:\n\nInput: n = 4, delay = 1, forget = 3\nOutput: 6\nExplanation:\nDay 1: The first person is named A. (1 person)\nDay 2: A shares the secret with B. (2 people)\nDay 3: A and B share the secret with 2 new people, C and D. (4 people)\nDay 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people)\n\nConstraints:\n\n- 2 <= n <= 1000\n- 1 <= delay < forget <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8,delay = 3,forget = 6) == 6\n assert candidate(n = 500,delay = 100,forget = 400) == 5820125\n assert candidate(n = 4,delay = 1,forget = 3) == 6\n assert candidate(n = 1000,delay = 5,forget = 10) == 743819361\n assert candidate(n = 1000,delay = 1,forget = 999) == 344211603\n assert candidate(n = 10,delay = 2,forget = 5) == 30\n assert candidate(n = 10,delay = 3,forget = 5) == 5\n assert candidate(n = 15,delay = 4,forget = 7) == 19\n assert candidate(n = 6,delay = 2,forget = 4) == 5\n assert candidate(n = 5,delay = 1,forget = 4) == 14\n assert candidate(n = 7,delay = 2,forget = 3) == 2\n assert candidate(n = 100,delay = 10,forget = 50) == 22517820\n assert candidate(n = 200,delay = 50,forget = 150) == 27250\n assert candidate(n = 900,delay = 300,forget = 650) == 45500\n assert candidate(n = 550,delay = 150,forget = 450) == 203375\n assert candidate(n = 950,delay = 400,forget = 700) == 11625\n assert candidate(n = 800,delay = 150,forget = 600) == 79177860\n assert candidate(n = 900,delay = 150,forget = 300) == 935294905\n assert candidate(n = 1000,delay = 1,forget = 10) == 694661098\n assert candidate(n = 700,delay = 110,forget = 550) == 887595495\n assert candidate(n = 600,delay = 250,forget = 550) == 5350\n assert candidate(n = 500,delay = 100,forget = 200) == 5264525\n assert candidate(n = 200,delay = 2,forget = 199) == 349361643\n assert candidate(n = 1000,delay = 1,forget = 500) == 28219034\n assert candidate(n = 1000,delay = 1,forget = 2) == 2\n assert candidate(n = 750,delay = 250,forget = 500) == 31625\n assert candidate(n = 999,delay = 50,forget = 400) == 112339611\n assert candidate(n = 950,delay = 300,forget = 600) == 81225\n assert candidate(n = 750,delay = 200,forget = 600) == 635625\n assert candidate(n = 900,delay = 200,forget = 500) == 9051525\n assert candidate(n = 600,delay = 125,forget = 500) == 6406900\n assert candidate(n = 800,delay = 200,forget = 300) == 843250\n assert candidate(n = 550,delay = 110,forget = 440) == 8292625\n assert candidate(n = 700,delay = 150,forget = 450) == 7127075\n assert candidate(n = 500,delay = 5,forget = 100) == 121345145\n assert candidate(n = 750,delay = 120,forget = 450) == 913950185\n assert candidate(n = 300,delay = 60,forget = 280) == 907415\n assert candidate(n = 500,delay = 150,forget = 400) == 42450\n assert candidate(n = 600,delay = 50,forget = 550) == 979826832\n assert candidate(n = 750,delay = 125,forget = 550) == 450909175\n assert candidate(n = 550,delay = 70,forget = 400) == 326052608\n assert candidate(n = 800,delay = 400,forget = 750) == 350\n assert candidate(n = 120,delay = 20,forget = 100) == 207054\n assert candidate(n = 400,delay = 30,forget = 150) == 689207212\n assert candidate(n = 800,delay = 100,forget = 600) == 153808266\n assert candidate(n = 600,delay = 200,forget = 300) == 10000\n assert candidate(n = 900,delay = 300,forget = 600) == 45450\n assert candidate(n = 950,delay = 150,forget = 850) == 488545869\n assert candidate(n = 600,delay = 250,forget = 400) == 5200\n assert candidate(n = 650,delay = 130,forget = 520) == 15497300\n assert candidate(n = 700,delay = 350,forget = 560) == 210\n assert candidate(n = 950,delay = 140,forget = 650) == 285835661\n assert candidate(n = 850,delay = 300,forget = 500) == 28975\n assert candidate(n = 650,delay = 90,forget = 500) == 926898505\n assert candidate(n = 550,delay = 250,forget = 450) == 1475\n assert candidate(n = 800,delay = 200,forget = 500) == 1423700\n assert candidate(n = 750,delay = 250,forget = 550) == 31675\n assert candidate(n = 550,delay = 80,forget = 450) == 2109288\n assert candidate(n = 500,delay = 200,forget = 400) == 5250\n assert candidate(n = 1000,delay = 50,forget = 900) == 770071855\n assert candidate(n = 750,delay = 120,forget = 500) == 914080410\n assert candidate(n = 600,delay = 150,forget = 450) == 619250\n assert candidate(n = 999,delay = 300,forget = 750) == 246900\n assert candidate(n = 1000,delay = 50,forget = 950) == 770074505\n assert candidate(n = 950,delay = 190,forget = 760) == 65412725\n assert candidate(n = 1000,delay = 10,forget = 500) == 104566774\n assert candidate(n = 600,delay = 120,forget = 480) == 11476850\n assert candidate(n = 1000,delay = 400,forget = 700) == 20400\n assert candidate(n = 900,delay = 100,forget = 800) == 892948851\n assert candidate(n = 500,delay = 50,forget = 450) == 344465040\n assert candidate(n = 200,delay = 40,forget = 150) == 219220\n assert candidate(n = 300,delay = 50,forget = 250) == 8177885\n assert candidate(n = 1000,delay = 500,forget = 900) == 400\n assert candidate(n = 600,delay = 100,forget = 500) == 165273270\n assert candidate(n = 750,delay = 200,forget = 500) == 632925\n assert candidate(n = 850,delay = 130,forget = 550) == 523316449\n assert candidate(n = 450,delay = 90,forget = 360) == 3944850\n assert candidate(n = 1000,delay = 150,forget = 700) == 188312873\n assert candidate(n = 1000,delay = 999,forget = 1000) == 2\n assert candidate(n = 400,delay = 10,forget = 350) == 610381426\n assert candidate(n = 800,delay = 150,forget = 350) == 77362035\n assert candidate(n = 700,delay = 190,forget = 560) == 426390\n assert candidate(n = 550,delay = 220,forget = 330) == 6215\n assert candidate(n = 900,delay = 250,forget = 600) == 651750\n assert candidate(n = 700,delay = 70,forget = 630) == 66046770\n assert candidate(n = 950,delay = 400,forget = 850) == 11775\n assert candidate(n = 750,delay = 150,forget = 600) == 26594875\n assert candidate(n = 400,delay = 100,forget = 350) == 192050\n assert candidate(n = 300,delay = 10,forget = 299) == 236977941\n assert candidate(n = 800,delay = 200,forget = 600) == 1434000\n assert candidate(n = 900,delay = 200,forget = 700) == 9092125\n assert candidate(n = 700,delay = 100,forget = 500) == 766847687\n assert candidate(n = 650,delay = 175,forget = 525) == 378875\n assert candidate(n = 600,delay = 80,forget = 400) == 816019201\n assert candidate(n = 1000,delay = 500,forget = 999) == 499\n assert candidate(n = 300,delay = 100,forget = 200) == 5150\n", "comparison": "exact"}, "public_tests": ["6\n2\n4", "4\n1\n3"], "hints": ["Let dp[i][j] be the number of people who have known the secret for exactly j + 1 days, at day i.", "If j > 0, dp[i][j] = dp[i – 1][j – 1].", "dp[i][0] = sum(dp[i – 1][j]) for j in [delay – 1, forget – 2]."], "metadata": {"canonical_parameter_names": ["n", "delay", "forget"], "leetcode_dataset_entry_point": "Solution().peopleAwareOfSecret", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:55+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["dynamic-programming", "queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function peopleAwareOfSecret($n, $delay, $forget) {", "container": "Solution", "callable": "peopleAwareOfSecret", "parameters": [{"name": "n", "type": "Integer"}, {"name": "delay", "type": "Integer"}, {"name": "forget", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2328, "task_id": "number-of-increasing-paths-in-a-grid", "difficulty": "Hard", "problem_description": "You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.\n\nReturn the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10^9 + 7.\n\nTwo paths are considered different if they do not have exactly the same sequence of visited cells.\n\nExample 1:\n\nInput: grid = [[1,1],[3,4]]\nOutput: 8\nExplanation: The strictly increasing paths are:\n- Paths with length 1: [1], [1], [3], [4].\n- Paths with length 2: [1 -> 3], [1 -> 4], [3 -> 4].\n- Paths with length 3: [1 -> 3 -> 4].\nThe total number of paths is 4 + 3 + 1 = 8.\n\nExample 2:\n\nInput: grid = [[1],[2]]\nOutput: 3\nExplanation: The strictly increasing paths are:\n- Paths with length 1: [1], [2].\n- Paths with length 2: [1 -> 2].\nThe total number of paths is 2 + 1 = 3.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 1000\n- 1 <= 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, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[4, 3, 2, 1], [3, 2, 1, 4], [2, 1, 4, 3], [1, 4, 3, 2]]) == 64\n assert candidate(grid = [[4, 3, 2, 1], [5, 6, 7, 8]]) == 50\n assert candidate(grid = [[1]]) == 1\n assert candidate(grid = [[1], [2]]) == 3\n assert candidate(grid = [[9, 9, 4], [6, 6, 8], [2, 1, 1]]) == 23\n assert candidate(grid = [[9, 9, 9], [9, 9, 9], [9, 9, 9]]) == 9\n assert candidate(grid = [[10]]) == 1\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 53\n assert candidate(grid = [[10, 20, 30], [15, 25, 35], [12, 22, 32]]) == 38\n assert candidate(grid = [[1, 1], [3, 4]]) == 8\n assert candidate(grid = [[3, 1, 4, 2], [1, 6, 5, 3], [2, 7, 4, 8]]) == 49\n assert candidate(grid = [[10, 10, 10, 10], [10, 1, 2, 10], [10, 3, 4, 10], [10, 10, 10, 10]]) == 42\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 185\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]]) == 4312\n assert candidate(grid = [[1, 3, 1], [1, 5, 1], [4, 2, 4]]) == 21\n assert candidate(grid = [[1, 1, 1], [1, 2, 1], [1, 1, 1]]) == 13\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9]]) == 77\n assert candidate(grid = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 192\n assert candidate(grid = [[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, 5, 4, 3, 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]]) == 363\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [10, 11, 12]]) == 172\n assert candidate(grid = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [3, 2, 3, 8, 6], [3, 7, 4, 9, 8]]) == 117\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]]) == 887\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]]) == 1673\n assert candidate(grid = [[1, 10, 9, 14, 13], [2, 3, 8, 12, 15], [5, 6, 7, 11, 16], [17, 18, 19, 20, 21]]) == 328\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 65\n assert candidate(grid = [[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]]) == 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]]) == 431\n assert candidate(grid = [[10, 9, 8, 7, 6], [11, 10, 9, 8, 7], [12, 11, 10, 9, 8], [13, 12, 11, 10, 9], [14, 13, 12, 11, 10]]) == 887\n assert candidate(grid = [[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]]) == 65\n assert candidate(grid = [[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], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]) == 12309\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, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == 880\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) == 105\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], [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], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 1540\n assert candidate(grid = [[1, 2, 3, 2, 1], [2, 3, 4, 3, 2], [3, 4, 5, 4, 3], [2, 3, 4, 3, 2], [1, 2, 3, 2, 1]]) == 189\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]]) == 550\n assert candidate(grid = [[1, 10, 100], [10, 100, 1000], [100, 1000, 10000]]) == 53\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]]) == 45\n assert candidate(grid = [[5, 3, 2], [1, 4, 6], [7, 8, 9]]) == 41\n assert candidate(grid = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [3, 2, 3, 8, 4], [2, 7, 1, 8, 2]]) == 112\n assert candidate(grid = [[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]]) == 465\n assert candidate(grid = [[10, 10, 10, 10], [10, 1, 1, 10], [10, 1, 1, 10], [10, 10, 10, 10]]) == 24\n assert candidate(grid = [[5, 5, 5, 5, 5], [5, 1, 2, 1, 5], [5, 3, 4, 3, 5], [5, 5, 5, 5, 5]]) == 54\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) == 55\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]]) == 887\n assert candidate(grid = [[1, 3, 2, 1], [1, 3, 2, 1], [1, 3, 2, 1]]) == 24\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [12, 11, 10], [13, 14, 15]]) == 476\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, 1]]) == 887\n assert candidate(grid = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16]]) == 1276\n assert candidate(grid = [[5, 5, 5, 5], [5, 1, 2, 5], [5, 4, 3, 5], [5, 5, 5, 5]]) == 45\n assert candidate(grid = [[1, 2, 3], [6, 5, 4], [7, 8, 9], [4, 5, 6]]) == 93\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]]) == 887\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == 226\n assert candidate(grid = [[1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]) == 330\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]]) == 25\n assert candidate(grid = [[1, 2], [4, 3], [2, 1], [3, 4]]) == 26\n assert candidate(grid = [[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]]) == 65\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]]) == 149\n assert candidate(grid = [[10, 9, 8, 7], [9, 8, 7, 6], [8, 7, 6, 5], [7, 6, 5, 4]]) == 226\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]]) == 887\n assert candidate(grid = [[9, 8, 7, 6], [8, 7, 6, 5], [7, 6, 5, 4], [6, 5, 4, 3], [5, 4, 3, 2], [4, 3, 2, 1]]) == 756\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]]) == 385\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]]) == 133\n assert candidate(grid = [[1, 10, 100, 1000, 10000], [1, 10, 100, 1000, 10000], [1, 10, 100, 1000, 10000], [1, 10, 100, 1000, 10000]]) == 60\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]]) == 887\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]]) == 65\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, 5]]) == 50\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]]) == 12309\n assert candidate(grid = [[10, 11, 16, 15, 4, 1, 5], [7, 6, 3, 16, 15, 10, 11], [14, 13, 12, 5, 18, 19, 20], [1, 2, 3, 4, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30]]) == 508\n assert candidate(grid = [[1, 2, 3, 4], [4, 3, 2, 1], [5, 6, 7, 8], [8, 7, 6, 5]]) == 139\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]]) == 24\n assert candidate(grid = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41]]) == 481\n assert candidate(grid = [[5, 1, 4], [1, 5, 5], [4, 5, 5]]) == 19\n assert candidate(grid = [[1, 3, 1], [1, 5, 1], [1, 3, 1]]) == 21\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], [2, 1, 2, 1, 2, 1, 2, 1, 2, 1], [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]]) == 135\n assert candidate(grid = [[10], [9], [8], [7], [6], [5], [4], [3], [2], [1]]) == 55\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2], [1, 2, 3, 4, 5]]) == 133\n assert candidate(grid = [[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]]) == 283\n assert candidate(grid = [[3, 2, 1], [6, 5, 4], [9, 8, 7]]) == 53\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]]) == 4560\n assert candidate(grid = [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == 495\n", "comparison": "exact"}, "public_tests": ["[[1,1],[3,4]]", "[[1],[2]]"], "hints": ["How can you calculate the number of increasing paths that start from a cell (i, j)? Think about dynamic programming.", "Define f(i, j) as the number of increasing paths starting from cell (i, j). Try to find how f(i, j) is related to each of f(i, j+1), f(i, j-1), f(i+1, j) and f(i-1, j)."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().countPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:48:57+00:00", "tests_total": 88, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "depth-first-search", "breadth-first-search", "graph", "topological-sort", "memoization", "matrix"]}, "language": "php", "interface": {"raw_signature": "function countPaths($grid) {", "container": "Solution", "callable": "countPaths", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2332, "task_id": "the-latest-time-to-catch-a-bus", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the i^th bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represents the arrival time of the j^th passenger. All bus departure times are unique. All passenger arrival times are unique.\n\nYou are given an integer capacity, which represents the maximum number of passengers that can get on each bus.\n\nWhen a passenger arrives, they will wait in line for the next available bus. You can get on a bus that departs at x minutes if you arrive at y minutes where y <= x, and the bus is not full. Passengers with the earliest arrival times get on the bus first.\n\nMore formally when a bus arrives, either:\n\n- If capacity or fewer passengers are waiting for a bus, they will all get on the bus, or\n- The capacity passengers with the earliest arrival times will get on the bus.\n\nReturn the latest time you may arrive at the bus station to catch a bus. You cannot arrive at the same time as another passenger.\n\nNote: The arrays buses and passengers are not necessarily sorted.\n\nExample 1:\n\nInput: buses = [10,20], passengers = [2,17,18,19], capacity = 2\nOutput: 16\nExplanation: Suppose you arrive at time 16.\nAt time 10, the first bus departs with the 0^th passenger.\nAt time 20, the second bus departs with you and the 1^st passenger.\nNote that you may not arrive at the same time as another passenger, which is why you must arrive before the 1^st passenger to catch the bus.\n\nExample 2:\n\nInput: buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2\nOutput: 20\nExplanation: Suppose you arrive at time 20.\nAt time 10, the first bus departs with the 3^rd passenger.\nAt time 20, the second bus departs with the 5^th and 1^st passengers.\nAt time 30, the third bus departs with the 0^th passenger and you.\nNotice if you had arrived any later, then the 6^th passenger would have taken your seat on the third bus.\n\nConstraints:\n\n- n == buses.length\n- m == passengers.length\n- 1 <= n, m, capacity <= 10^5\n- 2 <= buses[i], passengers[i] <= 10^9\n- Each element in buses is unique.\n- Each element in passengers is unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(buses = [50, 60, 70],passengers = [5, 10, 20, 30, 40],capacity = 5) == 70\n assert candidate(buses = [3, 5, 7],passengers = [2, 4, 6, 8],capacity = 1) == 5\n assert candidate(buses = [10, 20],passengers = [2, 17, 18, 19],capacity = 2) == 16\n assert candidate(buses = [10, 20, 30, 40],passengers = [5, 10, 15, 20, 25, 30, 35, 40],capacity = 1) == 19\n assert candidate(buses = [100, 200],passengers = [99, 101, 102, 103],capacity = 2) == 100\n assert candidate(buses = [100],passengers = [99],capacity = 1) == 98\n assert candidate(buses = [30],passengers = [19, 13, 26, 4, 25, 11, 21],capacity = 3) == 12\n assert candidate(buses = [100],passengers = [10],capacity = 1) == 9\n assert candidate(buses = [20, 30, 10],passengers = [19, 13, 26, 4, 25, 11, 21],capacity = 2) == 20\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [10, 20, 30, 40, 50],capacity = 1) == 49\n assert candidate(buses = [100, 200, 300, 400, 500],passengers = [50, 150, 250, 350, 450, 50, 150, 250, 350, 450, 50, 150, 250, 350, 450, 50, 150, 250, 350, 450, 50, 150, 250, 350, 450, 50, 150, 250, 350, 450, 50, 150, 250, 350, 450],capacity = 5) == 349\n assert candidate(buses = [5, 15, 25, 35, 45],passengers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44],capacity = 4) == 35\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],capacity = 2) == 50\n assert candidate(buses = [15, 25, 35, 45, 55],passengers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],capacity = 5) == 55\n assert candidate(buses = [5, 12, 19, 26, 33],passengers = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],capacity = 2) == 26\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [9, 19, 29, 39, 49],capacity = 1) == 48\n assert candidate(buses = [100, 200, 300, 400, 500],passengers = [50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500],capacity = 3) == 399\n assert candidate(buses = [15, 30, 45, 60, 75],passengers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],capacity = 3) == 75\n assert candidate(buses = [5, 10, 20, 30, 40],passengers = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],capacity = 2) == 26\n assert candidate(buses = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],passengers = [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],capacity = 1) == 19\n assert candidate(buses = [5, 15, 25, 35, 45],passengers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44],capacity = 5) == 43\n assert candidate(buses = [100, 200, 300],passengers = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],capacity = 5) == 189\n assert candidate(buses = [100, 200, 300],passengers = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500],capacity = 2) == 299\n assert candidate(buses = [12, 24, 36, 48, 60],passengers = [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],capacity = 5) == 49\n assert candidate(buses = [30, 60, 90, 120, 150],passengers = [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],capacity = 4) == 99\n assert candidate(buses = [100, 200, 300, 400, 500],passengers = [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],capacity = 10) == 500\n assert candidate(buses = [20, 30, 40, 50, 60],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],capacity = 2) == 49\n assert candidate(buses = [15, 30, 45, 60, 75],passengers = [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],capacity = 5) == 74\n assert candidate(buses = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],passengers = [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],capacity = 1) == 49\n assert candidate(buses = [5, 15, 25, 35, 45, 55],passengers = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54],capacity = 1) == 28\n assert candidate(buses = [100, 200, 300],passengers = [50, 99, 101, 149, 151, 299, 301],capacity = 2) == 298\n assert candidate(buses = [20, 50, 70, 100],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],capacity = 5) == 94\n assert candidate(buses = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],passengers = [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],capacity = 3) == 63\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],capacity = 2) == 49\n assert candidate(buses = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],passengers = [9, 19, 29, 39, 49, 59, 69, 79, 89, 99],capacity = 1) == 98\n assert candidate(buses = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],passengers = [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],capacity = 3) == 134\n assert candidate(buses = [100, 200, 300, 400, 500],passengers = [50, 150, 250, 350, 450],capacity = 1) == 449\n assert candidate(buses = [100, 200, 300, 400, 500],passengers = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310],capacity = 10) == 500\n assert candidate(buses = [100, 120, 140, 160, 180],passengers = [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],capacity = 10) == 179\n assert candidate(buses = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],passengers = [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],capacity = 3) == 99\n assert candidate(buses = [5, 10, 20, 25],passengers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],capacity = 3) == 1\n assert candidate(buses = [100, 200, 300],passengers = [50, 150, 250, 350],capacity = 3) == 300\n assert candidate(buses = [5, 15, 25, 35, 45],passengers = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60],capacity = 2) == 35\n assert candidate(buses = [20, 30, 40, 50, 60],passengers = [5, 15, 25, 35, 45, 55, 65],capacity = 2) == 60\n assert candidate(buses = [15, 30, 45, 60],passengers = [3, 4, 6, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 47, 49, 51, 53, 57, 59],capacity = 5) == 38\n assert candidate(buses = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],capacity = 2) == 99\n assert candidate(buses = [5, 15, 25, 35, 45],passengers = [2, 5, 7, 10, 15, 18, 20, 22, 25, 30, 32, 35, 40, 42, 45],capacity = 3) == 41\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [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],capacity = 3) == 29\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [5, 15, 25, 35, 45, 55],capacity = 1) == 44\n assert candidate(buses = [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],passengers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],capacity = 1) == 21\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],capacity = 1) == 44\n assert candidate(buses = [1000, 2000, 3000],passengers = [500, 1500, 2500, 3500, 4500],capacity = 2) == 3000\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacity = 2) == 49\n assert candidate(buses = [10, 20, 30, 40, 50],passengers = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],capacity = 1) == 24\n", "comparison": "exact"}, "public_tests": ["[10,20]\n[2,17,18,19]\n2", "[20,30,10]\n[19,13,26,4,25,11,21]\n2"], "hints": ["Sort the buses and passengers arrays.", "Use 2 pointers to traverse buses and passengers with a simulation of passengers getting on a particular bus."], "metadata": {"canonical_parameter_names": ["buses", "passengers", "capacity"], "leetcode_dataset_entry_point": "Solution().latestTimeCatchTheBus", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:04+00:00", "tests_total": 93, "tests_dropped": 39, "flags": [], "topic_tags": ["array", "two-pointers", "binary-search", "sorting"]}, "language": "php", "interface": {"raw_signature": "function latestTimeCatchTheBus($buses, $passengers, $capacity) {", "container": "Solution", "callable": "latestTimeCatchTheBus", "parameters": [{"name": "buses", "type": "Integer[]"}, {"name": "passengers", "type": "Integer[]"}, {"name": "capacity", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2333, "task_id": "minimum-sum-of-squared-difference", "difficulty": "Medium", "problem_description": "You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n.\n\nThe sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])^2 for each 0 <= i < n.\n\nYou are also given two positive integers k1 and k2. You can modify any of the elements of nums1 by +1 or -1 at most k1 times. Similarly, you can modify any of the elements of nums2 by +1 or -1 at most k2 times.\n\nReturn the minimum sum of squared difference after modifying array nums1 at most k1 times and modifying array nums2 at most k2 times.\n\nNote: You are allowed to modify the array elements to become negative integers.\n\nExample 1:\n\nInput: nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0\nOutput: 579\nExplanation: The elements in nums1 and nums2 cannot be modified because k1 = 0 and k2 = 0.\nThe sum of square difference will be: (1 - 2)^2+ (2 - 10)^2+ (3 - 20)^2+ (4 - 19)^2 = 579.\n\nExample 2:\n\nInput: nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1\nOutput: 43\nExplanation: One way to obtain the minimum sum of square difference is:\n- Increase nums1[0] once.\n- Increase nums2[2] once.\nThe minimum of the sum of square difference will be:\n(2 - 5)^2+ (4 - 8)^2+ (10 - 7)^2+ (12 - 9)^2 = 43.\nNote that, there are other ways to obtain the minimum of the sum of square difference, but there is no way to obtain a sum smaller than 43.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 1 <= n <= 10^5\n- 0 <= nums1[i], nums2[i] <= 10^5\n- 0 <= k1, k2 <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [5, 5, 5, 5],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100000, 100000],nums2 = [0, 0],k1 = 100000,k2 = 100000) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],k1 = 1,k2 = 1) == 3\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1],k1 = 3,k2 = 3) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [100, 100, 100, 100],k1 = 200,k2 = 200) == 0\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1],k1 = 10,k2 = 10) == 0\n assert candidate(nums1 = [1, 2, 3, 4],nums2 = [2, 10, 20, 19],k1 = 0,k2 = 0) == 579\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1],k1 = 2,k2 = 2) == 0\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1],k1 = 4,k2 = 4) == 16\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [5, 5, 5, 5, 5],k1 = 5,k2 = 5) == 20\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0],k1 = 5,k2 = 5) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k1 = 5,k2 = 5) == 2\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],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [10, 10, 10, 10],k1 = 20,k2 = 20) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k1 = 3,k2 = 3) == 10\n assert candidate(nums1 = [0, 0, 0],nums2 = [100, 100, 100],k1 = 150,k2 = 150) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [1, 2, 3],k1 = 25,k2 = 25) == 6\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1],k1 = 5,k2 = 5) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 1, 1, 1],k1 = 2,k2 = 2) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [10, 10, 10, 10],k1 = 10,k2 = 10) == 64\n assert candidate(nums1 = [3, 5, 7, 9],nums2 = [4, 6, 8, 10],k1 = 3,k2 = 3) == 0\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [0, 0, 0],k1 = 300000,k2 = 300000) == 0\n assert candidate(nums1 = [1, 4, 10, 12],nums2 = [5, 8, 6, 9],k1 = 1,k2 = 1) == 43\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [0, 0, 0],k1 = 100000,k2 = 100000) == 3333333334\n assert candidate(nums1 = [5, 5, 5, 5],nums2 = [1, 1, 1, 1],k1 = 10,k2 = 10) == 0\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [0, 0, 0],k1 = 100000,k2 = 100000) == 3333333334\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [5000, 4000, 3000, 2000, 1000],k1 = 2000,k2 = 2000) == 16000000\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [100000, 90000, 80000, 70000],nums2 = [60000, 50000, 40000, 30000],k1 = 500000,k2 = 500000) == 0\n assert candidate(nums1 = [100000, 50000, 25000, 10000],nums2 = [90000, 60000, 35000, 15000],k1 = 50000,k2 = 50000) == 0\n assert candidate(nums1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],nums2 = [99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999],k1 = 1000000,k2 = 1000000) == 0\n assert candidate(nums1 = [100000, 50000, 25000],nums2 = [0, 0, 0],k1 = 500000,k2 = 500000) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],k1 = 50,k2 = 50) == 245\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],k1 = 1000,k2 = 1000) == 1298535\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [100, 100, 100, 100, 100],k1 = 300,k2 = 300) == 0\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],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],k1 = 1000000000,k2 = 1000000000) == 0\n assert candidate(nums1 = [9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9],k1 = 10,k2 = 10) == 52\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k1 = 50,k2 = 50) == 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],k1 = 0,k2 = 0) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [50000, 50000, 50000],nums2 = [0, 0, 0],k1 = 150000,k2 = 150000) == 0\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [500, 1000, 1500, 2000, 2500],k1 = 1000,k2 = 1000) == 6583334\n assert candidate(nums1 = [100, 200, 300],nums2 = [300, 200, 100],k1 = 150,k2 = 150) == 5000\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [500, 1500, 2500, 3500, 4500],k1 = 100000,k2 = 100000) == 0\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],k1 = 150,k2 = 150) == 4252\n assert candidate(nums1 = [5, 10, 15, 20, 25, 30],nums2 = [3, 6, 9, 12, 15, 18],k1 = 20,k2 = 25) == 0\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],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k1 = 10,k2 = 10) == 5\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [150, 250, 350, 450],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k1 = 10,k2 = 10) == 0\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],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [105, 205, 305, 405],k1 = 10,k2 = 10) == 0\n assert candidate(nums1 = [50, 50, 50, 50, 50],nums2 = [1, 2, 3, 4, 5],k1 = 200,k2 = 200) == 0\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],k1 = 5,k2 = 5) == 810\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],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [100000, 0, 50000],nums2 = [0, 100000, 50000],k1 = 100000,k2 = 100000) == 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],k1 = 100,k2 = 100) == 12728\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [1, 2, 3, 4, 5],k1 = 20,k2 = 20) == 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],k1 = 0,k2 = 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],k1 = 0,k2 = 0) == 330\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],k1 = 500,k2 = 500) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],k1 = 10,k2 = 10) == 0\n assert candidate(nums1 = [50, 50, 50, 50, 50],nums2 = [0, 0, 0, 0, 0],k1 = 50,k2 = 50) == 4500\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],k1 = 100,k2 = 100) == 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],k1 = 20,k2 = 20) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k1 = 100,k2 = 100) == 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],k1 = 1000,k2 = 1000) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [100, 100, 100, 100, 100],k1 = 100,k2 = 100) == 175000\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000],nums2 = [50000, 40000, 30000, 20000, 10000],k1 = 1000000,k2 = 1000000) == 0\n assert candidate(nums1 = [100, 100, 100, 100, 100, 100],nums2 = [1, 1, 1, 1, 1, 1],k1 = 300,k2 = 300) == 0\n assert candidate(nums1 = [1000, 2000, 3000, 4000, 5000],nums2 = [500, 1500, 2500, 3500, 4500],k1 = 2000,k2 = 2000) == 0\n assert candidate(nums1 = [10, 20, 30],nums2 = [30, 20, 10],k1 = 20,k2 = 20) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k1 = 50,k2 = 50) == 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, 10],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 1, 1, 1, 1],k1 = 10,k2 = 10) == 0\n assert candidate(nums1 = [50000, 40000, 30000, 20000, 10000],nums2 = [50000, 40000, 30000, 20000, 10000],k1 = 0,k2 = 0) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 2, 3, 4, 5],k1 = 1000,k2 = 1000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [100000, 100000, 100000, 100000, 100000],k1 = 50000,k2 = 50000) == 31999200005\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [15, 25, 35, 45, 55],k1 = 15,k2 = 20) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [10, 20, 30, 40, 50],k1 = 10000,k2 = 10000) == 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],k1 = 10,k2 = 10) == 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],k1 = 0,k2 = 0) == 330\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],k1 = 500,k2 = 500) == 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],k1 = 20,k2 = 20) == 10\n assert candidate(nums1 = [50, 50, 50, 50, 50],nums2 = [100, 100, 100, 100, 100],k1 = 150,k2 = 150) == 0\n assert candidate(nums1 = [100000, 90000, 80000, 70000],nums2 = [60000, 50000, 40000, 30000],k1 = 1000000,k2 = 1000000) == 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],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k1 = 1000,k2 = 1000) == 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],k1 = 5,k2 = 5) == 160\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [90, 190, 290, 390, 490],k1 = 5,k2 = 5) == 320\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],k1 = 500,k2 = 500) == 0\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [1, 2, 3, 4, 5],k1 = 1000000,k2 = 1000000) == 0\n assert candidate(nums1 = [100000, 90000, 80000, 70000, 60000],nums2 = [50000, 40000, 30000, 20000, 10000],k1 = 1000000,k2 = 1000000) == 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],k1 = 20,k2 = 20) == 10\n assert candidate(nums1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k1 = 100,k2 = 100) == 0\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],k1 = 100,k2 = 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],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [1, 1, 1],k1 = 500,k2 = 500) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 150, 250, 350, 450],k1 = 1000,k2 = 1000) == 0\n assert candidate(nums1 = [100000, 100000, 100000],nums2 = [0, 0, 0],k1 = 150000,k2 = 150000) == 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],k1 = 50,k2 = 50) == 0\n assert candidate(nums1 = [100000, 100000, 100000, 100000, 100000],nums2 = [0, 0, 0, 0, 0],k1 = 1000000,k2 = 1000000) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [5, 15, 25, 35, 45],k1 = 25,k2 = 25) == 0\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [100, 90, 80, 70, 60],k1 = 500,k2 = 500) == 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],k1 = 500,k2 = 500) == 0\n assert candidate(nums1 = [5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5],k1 = 100,k2 = 100) == 0\n assert candidate(nums1 = [5, 10, 15, 20, 25],nums2 = [3, 8, 13, 18, 23],k1 = 25,k2 = 25) == 0\n assert candidate(nums1 = [10000, 20000, 30000, 40000, 50000],nums2 = [1, 2, 3, 4, 5],k1 = 1000000,k2 = 1000000) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100],k1 = 1000,k2 = 1000) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 2, 3, 4, 5],k1 = 1000,k2 = 1000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],k1 = 1500000,k2 = 1500000) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [10, 20, 30, 40, 50],k1 = 250,k2 = 250) == 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],k1 = 1000,k2 = 1000) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4]\n[2,10,20,19]\n0\n0", "[1,4,10,12]\n[5,8,6,9]\n1\n1"], "hints": ["There is no difference between the purpose of k1 and k2. Adding +1 to one element in nums1 is same as performing -1 to one element in nums2, and vice versa.", "Reduce the sum of squared difference greedily. One operation of k should use the index that has the current maximum difference.", "Binary search the maximum difference for the final result."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "k1", "k2"], "leetcode_dataset_entry_point": "Solution().minSumSquareDiff", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:07+00:00", "tests_total": 116, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function minSumSquareDiff($nums1, $nums2, $k1, $k2) {", "container": "Solution", "callable": "minSumSquareDiff", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "k1", "type": "Integer"}, {"name": "k2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2334, "task_id": "subarray-with-elements-greater-than-varying-threshold", "difficulty": "Hard", "problem_description": "You are given an integer array nums and an integer threshold.\n\nFind any subarray of nums of length k such that every element in the subarray is greater than threshold / k.\n\nReturn the size of any such subarray. If there is no such subarray, return -1.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,4,3,1], threshold = 6\nOutput: 3\nExplanation: The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.\nNote that this is the only valid subarray.\n\nExample 2:\n\nInput: nums = [6,5,6,5,8], threshold = 7\nOutput: 1\nExplanation: The subarray [8] has a size of 1, and 8 > 7 / 1 = 7. So 1 is returned.\nNote that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5.\nSimilarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.\nTherefore, 2, 3, 4, or 5 may also be returned.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i], threshold <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 15) == 1\n assert candidate(nums = [10, 10, 10, 10, 10],threshold = 1) == 1\n assert candidate(nums = [5, 5, 5, 5, 5],threshold = 25) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 55) == -1\n assert candidate(nums = [10, 20, 30, 40, 50],threshold = 100) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],threshold = 5) == 2\n assert candidate(nums = [2, 2, 2, 2, 2],threshold = 10) == -1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],threshold = 1) == 2\n assert candidate(nums = [1, 2, 3, 4, 5],threshold = 15) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 45) == -1\n assert candidate(nums = [5, 4, 3, 2, 1],threshold = 10) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 50) == -1\n assert candidate(nums = [6, 5, 6, 5, 8],threshold = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 30) == -1\n assert candidate(nums = [1, 3, 4, 3, 1],threshold = 6) == 3\n assert candidate(nums = [100, 200, 300, 400, 500],threshold = 1000) == -1\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],threshold = 20) == 21\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],threshold = 10) == 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],threshold = 10) == 11\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],threshold = 500) == -1\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],threshold = 50) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 5) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],threshold = 225) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],threshold = 45) == 1\n assert candidate(nums = [1, 9, 1, 9, 1, 9, 1, 9, 1, 9],threshold = 8) == 1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10],threshold = 45) == -1\n assert candidate(nums = [5, 10, 15, 20, 25],threshold = 100) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],threshold = 1000) == -1\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],threshold = 1285) == -1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],threshold = 100) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 95) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],threshold = 1000) == -1\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],threshold = 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],threshold = 1) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 1) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 20) == 3\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],threshold = 1000000000) == 2\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],threshold = 100) == -1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],threshold = 15) == 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],threshold = 1) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 55) == -1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 50) == -1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],threshold = 20) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],threshold = 20) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],threshold = 120) == -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],threshold = 1000) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],threshold = 450) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 25) == -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 = 190) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 25) == 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],threshold = 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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) == 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],threshold = 1950) == -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],threshold = 1000000000) == -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],threshold = 200) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],threshold = 100) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 45) == -1\n assert candidate(nums = [1, 1000000000, 1, 1, 1, 1, 1, 1, 1, 1],threshold = 1000000000) == -1\n assert candidate(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1],threshold = 400) == -1\n assert candidate(nums = [100, 200, 300, 400, 500],threshold = 1000) == -1\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],threshold = 18) == -1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],threshold = 20) == 5\n assert candidate(nums = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100],threshold = 250) == 4\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],threshold = 1000000000) == 2\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],threshold = 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],threshold = 10) == 4\n assert candidate(nums = [5, 8, 7, 3, 9, 10, 2, 1, 6],threshold = 20) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],threshold = 500000000) == 1\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9],threshold = 50) == -1\n assert candidate(nums = [5, 1, 4, 3, 9, 8, 10],threshold = 30) == -1\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 100) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 20) == 3\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 20) == 3\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],threshold = 450) == -1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],threshold = 25) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 45) == -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],threshold = 50) == -1\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2],threshold = 100) == -1\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 7, 9, 8, 10],threshold = 15) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],threshold = 25) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],threshold = 100) == -1\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1],threshold = 10) == -1\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],threshold = 210) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],threshold = 20) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],threshold = 900) == -1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],threshold = 5000) == -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 = 90) == 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],threshold = 100) == -1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],threshold = 500) == 6\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],threshold = 10) == -1\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 20) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],threshold = 495) == -1\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 2, 1, 3, 4],threshold = 10) == 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],threshold = 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],threshold = 200) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],threshold = 100) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],threshold = 50) == 4\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7],threshold = 49) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],threshold = 1285) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],threshold = 550) == -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],threshold = 240) == -1\n assert candidate(nums = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],threshold = 900) == -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],threshold = 5) == 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],threshold = 90) == 7\n assert candidate(nums = [10, 1, 10, 1, 10, 1, 10, 1, 10, 1],threshold = 9) == 1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],threshold = 45) == -1\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],threshold = 15) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],threshold = 100) == -1\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],threshold = 550) == -1\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],threshold = 1000000000) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],threshold = 275) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],threshold = 25) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],threshold = 45) == -1\n", "comparison": "exact"}, "public_tests": ["[1,3,4,3,1]\n6", "[6,5,6,5,8]\n7"], "hints": ["For all elements to be greater than the threshold/length, the minimum element in the subarray must be greater than the threshold/length.", "For a given index, could you find the largest subarray such that the given index is the minimum element?", "Could you use a monotonic stack to get the next and previous smallest element for every index?"], "metadata": {"canonical_parameter_names": ["nums", "threshold"], "leetcode_dataset_entry_point": "Solution().validSubarraySize", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:10+00:00", "tests_total": 116, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "stack", "union-find", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function validSubarraySize($nums, $threshold) {", "container": "Solution", "callable": "validSubarraySize", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "threshold", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2335, "task_id": "minimum-amount-of-time-to-fill-cups", "difficulty": "Easy", "problem_description": "You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water.\n\nYou are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot water cups you need to fill respectively. Return the minimum number of seconds needed to fill up all the cups.\n\nExample 1:\n\nInput: amount = [1,4,2]\nOutput: 4\nExplanation: One way to fill up the cups is:\nSecond 1: Fill up a cold cup and a warm cup.\nSecond 2: Fill up a warm cup and a hot cup.\nSecond 3: Fill up a warm cup and a hot cup.\nSecond 4: Fill up a warm cup.\nIt can be proven that 4 is the minimum number of seconds needed.\n\nExample 2:\n\nInput: amount = [5,4,4]\nOutput: 7\nExplanation: One way to fill up the cups is:\nSecond 1: Fill up a cold cup, and a hot cup.\nSecond 2: Fill up a cold cup, and a warm cup.\nSecond 3: Fill up a cold cup, and a warm cup.\nSecond 4: Fill up a warm cup, and a hot cup.\nSecond 5: Fill up a cold cup, and a hot cup.\nSecond 6: Fill up a cold cup, and a warm cup.\nSecond 7: Fill up a hot cup.\n\nExample 3:\n\nInput: amount = [5,0,0]\nOutput: 5\nExplanation: Every second, we fill up a cold cup.\n\nConstraints:\n\n- amount.length == 3\n- 0 <= amount[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(amount = [33, 33, 34]) == 50\n assert candidate(amount = [0, 0, 0]) == 0\n assert candidate(amount = [99, 1, 1]) == 99\n assert candidate(amount = [7, 7, 7]) == 11\n assert candidate(amount = [10, 10, 10]) == 15\n assert candidate(amount = [1, 2, 3]) == 3\n assert candidate(amount = [100, 0, 0]) == 100\n assert candidate(amount = [100, 100, 100]) == 150\n assert candidate(amount = [0, 1, 2]) == 2\n assert candidate(amount = [1, 4, 2]) == 4\n assert candidate(amount = [5, 0, 0]) == 5\n assert candidate(amount = [99, 99, 1]) == 100\n assert candidate(amount = [0, 50, 50]) == 50\n assert candidate(amount = [5, 4, 4]) == 7\n assert candidate(amount = [98, 1, 1]) == 98\n assert candidate(amount = [25, 0, 75]) == 75\n assert candidate(amount = [42, 42, 41]) == 63\n assert candidate(amount = [60, 20, 20]) == 60\n assert candidate(amount = [10, 50, 25]) == 50\n assert candidate(amount = [49, 49, 49]) == 74\n assert candidate(amount = [1, 1, 0]) == 1\n assert candidate(amount = [80, 10, 10]) == 80\n assert candidate(amount = [1, 10, 10]) == 11\n assert candidate(amount = [1, 1, 100]) == 100\n assert candidate(amount = [10, 90, 0]) == 90\n assert candidate(amount = [10, 80, 10]) == 80\n assert candidate(amount = [0, 0, 100]) == 100\n assert candidate(amount = [80, 10, 10]) == 80\n assert candidate(amount = [33, 33, 34]) == 50\n assert candidate(amount = [70, 70, 60]) == 100\n assert candidate(amount = [50, 25, 25]) == 50\n assert candidate(amount = [29, 29, 42]) == 50\n assert candidate(amount = [50, 50, 49]) == 75\n assert candidate(amount = [99, 2, 99]) == 100\n assert candidate(amount = [50, 49, 51]) == 75\n assert candidate(amount = [100, 1, 1]) == 100\n assert candidate(amount = [80, 70, 60]) == 105\n assert candidate(amount = [100, 50, 25]) == 100\n assert candidate(amount = [1, 0, 1]) == 1\n assert candidate(amount = [40, 30, 20]) == 45\n assert candidate(amount = [1, 2, 97]) == 97\n assert candidate(amount = [1, 1, 1]) == 2\n assert candidate(amount = [49, 50, 1]) == 50\n assert candidate(amount = [30, 20, 10]) == 30\n assert candidate(amount = [100, 10, 10]) == 100\n assert candidate(amount = [2, 99, 99]) == 100\n assert candidate(amount = [1, 98, 1]) == 98\n assert candidate(amount = [1, 0, 99]) == 99\n assert candidate(amount = [80, 15, 5]) == 80\n assert candidate(amount = [45, 55, 0]) == 55\n assert candidate(amount = [100, 1, 1]) == 100\n assert candidate(amount = [50, 50, 1]) == 51\n assert candidate(amount = [25, 25, 25]) == 38\n assert candidate(amount = [42, 29, 29]) == 50\n assert candidate(amount = [100, 50, 1]) == 100\n assert candidate(amount = [1, 90, 10]) == 90\n assert candidate(amount = [1, 1, 1]) == 2\n assert candidate(amount = [0, 75, 25]) == 75\n assert candidate(amount = [55, 45, 5]) == 55\n assert candidate(amount = [10, 1, 90]) == 90\n assert candidate(amount = [100, 10, 0]) == 100\n assert candidate(amount = [80, 10, 1]) == 80\n assert candidate(amount = [48, 48, 48]) == 72\n assert candidate(amount = [80, 50, 30]) == 80\n assert candidate(amount = [90, 90, 1]) == 91\n assert candidate(amount = [1, 50, 50]) == 51\n assert candidate(amount = [55, 0, 45]) == 55\n assert candidate(amount = [49, 2, 49]) == 50\n assert candidate(amount = [45, 67, 23]) == 68\n assert candidate(amount = [20, 20, 60]) == 60\n assert candidate(amount = [100, 100, 99]) == 150\n assert candidate(amount = [10, 10, 100]) == 100\n assert candidate(amount = [50, 100, 50]) == 100\n assert candidate(amount = [10, 15, 20]) == 23\n assert candidate(amount = [0, 100, 100]) == 100\n assert candidate(amount = [60, 40, 20]) == 60\n assert candidate(amount = [0, 100, 0]) == 100\n assert candidate(amount = [50, 51, 50]) == 76\n assert candidate(amount = [33, 33, 33]) == 50\n assert candidate(amount = [23, 47, 29]) == 50\n assert candidate(amount = [51, 51, 51]) == 77\n assert candidate(amount = [50, 1, 50]) == 51\n assert candidate(amount = [25, 10, 50]) == 50\n assert candidate(amount = [55, 55, 45]) == 78\n assert candidate(amount = [0, 100, 10]) == 100\n assert candidate(amount = [90, 10, 1]) == 90\n assert candidate(amount = [33, 66, 0]) == 66\n assert candidate(amount = [99, 1, 0]) == 99\n assert candidate(amount = [50, 25, 10]) == 50\n assert candidate(amount = [49, 50, 51]) == 75\n assert candidate(amount = [60, 60, 61]) == 91\n assert candidate(amount = [29, 42, 29]) == 50\n assert candidate(amount = [50, 50, 50]) == 75\n assert candidate(amount = [25, 25, 26]) == 38\n assert candidate(amount = [34, 33, 34]) == 51\n assert candidate(amount = [2, 49, 49]) == 50\n assert candidate(amount = [25, 25, 25]) == 38\n assert candidate(amount = [1, 1, 2]) == 2\n assert candidate(amount = [1, 1, 99]) == 99\n assert candidate(amount = [60, 40, 20]) == 60\n assert candidate(amount = [60, 60, 60]) == 90\n assert candidate(amount = [33, 33, 67]) == 67\n assert candidate(amount = [10, 100, 10]) == 100\n assert candidate(amount = [5, 0, 5]) == 5\n assert candidate(amount = [1, 100, 1]) == 100\n assert candidate(amount = [80, 15, 5]) == 80\n assert candidate(amount = [99, 99, 99]) == 149\n assert candidate(amount = [66, 33, 0]) == 66\n assert candidate(amount = [2, 3, 4]) == 5\n assert candidate(amount = [5, 15, 80]) == 80\n assert candidate(amount = [30, 0, 20]) == 30\n assert candidate(amount = [50, 25, 25]) == 50\n assert candidate(amount = [47, 23, 29]) == 50\n assert candidate(amount = [100, 99, 98]) == 149\n assert candidate(amount = [90, 85, 80]) == 128\n assert candidate(amount = [67, 33, 33]) == 67\n assert candidate(amount = [98, 99, 1]) == 99\n assert candidate(amount = [15, 80, 5]) == 80\n assert candidate(amount = [10, 10, 80]) == 80\n assert candidate(amount = [3, 2, 1]) == 3\n assert candidate(amount = [23, 45, 67]) == 68\n assert candidate(amount = [50, 50, 100]) == 100\n assert candidate(amount = [90, 10, 90]) == 95\n assert candidate(amount = [99, 98, 97]) == 147\n assert candidate(amount = [1, 99, 1]) == 99\n assert candidate(amount = [45, 55, 55]) == 78\n assert candidate(amount = [75, 25, 0]) == 75\n assert candidate(amount = [0, 0, 100]) == 100\n assert candidate(amount = [1, 100, 1]) == 100\n assert candidate(amount = [1, 2, 1]) == 2\n assert candidate(amount = [70, 20, 10]) == 70\n assert candidate(amount = [2, 2, 1]) == 3\n assert candidate(amount = [95, 3, 2]) == 95\n assert candidate(amount = [1, 2, 3]) == 3\n assert candidate(amount = [0, 99, 0]) == 99\n assert candidate(amount = [60, 40, 0]) == 60\n assert candidate(amount = [10, 10, 10]) == 15\n assert candidate(amount = [33, 34, 33]) == 50\n assert candidate(amount = [50, 50, 5]) == 53\n assert candidate(amount = [2, 1, 1]) == 2\n assert candidate(amount = [2, 1, 2]) == 3\n assert candidate(amount = [10, 90, 0]) == 90\n assert candidate(amount = [66, 33, 3]) == 66\n assert candidate(amount = [49, 49, 2]) == 50\n assert candidate(amount = [67, 23, 45]) == 68\n assert candidate(amount = [50, 49, 48]) == 74\n assert candidate(amount = [55, 45, 55]) == 78\n assert candidate(amount = [0, 55, 45]) == 55\n assert candidate(amount = [100, 0, 0]) == 100\n assert candidate(amount = [0, 1, 1]) == 1\n assert candidate(amount = [1, 1, 100]) == 100\n assert candidate(amount = [1, 2, 2]) == 3\n assert candidate(amount = [50, 50, 0]) == 50\n assert candidate(amount = [34, 33, 33]) == 50\n assert candidate(amount = [0, 100, 0]) == 100\n assert candidate(amount = [42, 41, 42]) == 63\n assert candidate(amount = [100, 50, 50]) == 100\n assert candidate(amount = [100, 50, 50]) == 100\n assert candidate(amount = [10, 0, 100]) == 100\n assert candidate(amount = [0, 99, 1]) == 99\n assert candidate(amount = [99, 99, 2]) == 100\n assert candidate(amount = [50, 0, 50]) == 50\n assert candidate(amount = [41, 42, 42]) == 63\n assert candidate(amount = [0, 5, 5]) == 5\n assert candidate(amount = [1, 99, 98]) == 99\n assert candidate(amount = [2, 2, 98]) == 98\n assert candidate(amount = [1, 1, 98]) == 98\n assert candidate(amount = [10, 10, 1]) == 11\n assert candidate(amount = [1, 99, 99]) == 100\n assert candidate(amount = [29, 47, 23]) == 50\n assert candidate(amount = [33, 67, 33]) == 67\n assert candidate(amount = [99, 98, 97]) == 147\n assert candidate(amount = [10, 20, 30]) == 30\n assert candidate(amount = [0, 50, 50]) == 50\n assert candidate(amount = [99, 1, 0]) == 99\n assert candidate(amount = [99, 1, 99]) == 100\n assert candidate(amount = [10, 90, 10]) == 90\n", "comparison": "exact"}, "public_tests": ["[1,4,2]", "[5,4,4]", "[5,0,0]"], "hints": ["To minimize the amount of time needed, you want to fill up as many cups as possible in each second. This means that you want to maximize the number of seconds where you are filling up two cups.", "You always want to fill up the two types of water with the most unfilled cups."], "metadata": {"canonical_parameter_names": ["amount"], "leetcode_dataset_entry_point": "Solution().fillCups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:12+00:00", "tests_total": 178, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "greedy", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function fillCups($amount) {", "container": "Solution", "callable": "fillCups", "parameters": [{"name": "amount", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2337, "task_id": "move-pieces-to-obtain-a-string", "difficulty": "Medium", "problem_description": "You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where:\n\n- The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.\n- The character '_' represents a blank space that can be occupied by any of the 'L' or 'R' pieces.\n\nReturn true if it is possible to obtain the string target by moving the pieces of the string start any number of times. Otherwise, return false.\n\nExample 1:\n\nInput: start = \"_L__R__R_\", target = \"L______RR\"\nOutput: true\nExplanation: We can obtain the string target from start by doing the following moves:\n- Move the first piece one step to the left, start becomes equal to \"L___R__R_\".\n- Move the last piece one step to the right, start becomes equal to \"L___R___R\".\n- Move the second piece three steps to the right, start becomes equal to \"L______RR\".\nSince it is possible to get the string target from start, we return true.\n\nExample 2:\n\nInput: start = \"R_L_\", target = \"__LR\"\nOutput: false\nExplanation: The 'R' piece in the string start can move one step to the right to obtain \"_RL_\".\nAfter that, no pieces can move anymore, so it is impossible to obtain the string target from start.\n\nExample 3:\n\nInput: start = \"_R\", target = \"R_\"\nOutput: false\nExplanation: The piece in the string start can move only to the right, so it is impossible to obtain the string target from start.\n\nConstraints:\n\n- n == start.length == target.length\n- 1 <= n <= 10^5\n- start and target consist of the characters 'L', 'R', and '_'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(start = \"_R\",target = \"R_\") == False\n assert candidate(start = \"___\",target = \"___\") == True\n assert candidate(start = \"LR\",target = \"LR\") == True\n assert candidate(start = \"_LL_R\",target = \"LL__R\") == True\n assert candidate(start = \"____\",target = \"____\") == True\n assert candidate(start = \"L_R\",target = \"_LR\") == False\n assert candidate(start = \"R__L\",target = \"L__R\") == False\n assert candidate(start = \"L_L_R\",target = \"LL_R_\") == False\n assert candidate(start = \"R_R\",target = \"_RR\") == True\n assert candidate(start = \"_L__R__R_\",target = \"L______RR\") == True\n assert candidate(start = \"L___R\",target = \"_L__R\") == False\n assert candidate(start = \"LL_R\",target = \"R_L_\") == False\n assert candidate(start = \"__L___\",target = \"L_____\") == True\n assert candidate(start = \"LRRL\",target = \"LRRL\") == True\n assert candidate(start = \"RL\",target = \"LR\") == False\n assert candidate(start = \"R__L\",target = \"__LR\") == False\n assert candidate(start = \"LRLR\",target = \"LRLR\") == True\n assert candidate(start = \"LL_RR\",target = \"L_RLR\") == False\n assert candidate(start = \"L_L\",target = \"LL_\") == True\n assert candidate(start = \"RLRL\",target = \"LRLR\") == False\n assert candidate(start = \"L___R\",target = \"L___R\") == True\n assert candidate(start = \"R___L\",target = \"L___R\") == False\n assert candidate(start = \"R_L_\",target = \"__LR\") == False\n assert candidate(start = \"R_LRL\",target = \"RLR_L\") == False\n assert candidate(start = \"RRLL____\",target = \"____RRLL\") == False\n assert candidate(start = \"R__L__R\",target = \"__LR___\") == False\n assert candidate(start = \"LR___LR___LR____\",target = \"_L__L___R___R___\") == False\n assert candidate(start = \"L___R_L__\",target = \"L______LR\") == False\n assert candidate(start = \"R____L_____\",target = \"_____R____L\") == False\n assert candidate(start = \"R______L\",target = \"_____LR_\") == False\n assert candidate(start = \"R___L__R_L\",target = \"_____LR__L\") == False\n assert candidate(start = \"L______R______L\",target = \"_______LR______\") == False\n assert candidate(start = \"R__L___L_\",target = \"___LR___L\") == False\n assert candidate(start = \"L____R____L___\",target = \"________LR____\") == False\n assert candidate(start = \"L_R____R\",target = \"_LR_____\") == False\n assert candidate(start = \"R_R_R_R_\",target = \"____RRRR\") == True\n assert candidate(start = \"R_L_R_L_R\",target = \"_L__L__RR\") == False\n assert candidate(start = \"R__LR_R__\",target = \"__LR___R_\") == False\n assert candidate(start = \"LR_L_R_L_R\",target = \"L_R_L_R_L_\") == False\n assert candidate(start = \"L_R_L_R\",target = \"_L__L_R\") == False\n assert candidate(start = \"R__L___R_L\",target = \"____LR__RL\") == False\n assert candidate(start = \"__LR__R\",target = \"____LRR\") == False\n assert candidate(start = \"L___R___L\",target = \"____L__LR\") == False\n assert candidate(start = \"_L_R__L_R\",target = \"L______LR\") == False\n assert candidate(start = \"L_L_L_L_L\",target = \"_____LLLL\") == False\n assert candidate(start = \"R_L_R_L_R_L\",target = \"_LR_L_L_R_L\") == False\n assert candidate(start = \"R_L_R_L_R\",target = \"___R_L_RL\") == False\n assert candidate(start = \"R_L_R_L_R\",target = \"_LR_L__RR\") == False\n assert candidate(start = \"R___L___R___L\",target = \"_____R___L___\") == False\n assert candidate(start = \"LR_LRL__\",target = \"LRL_L___\") == False\n assert candidate(start = \"L___R____L\",target = \"______LR_L\") == False\n assert candidate(start = \"L____R____\",target = \"____LR____\") == False\n assert candidate(start = \"RRR___LLL\",target = \"___LLLRRR\") == False\n assert candidate(start = \"L_R_L___R\",target = \"L___L_R__\") == False\n assert candidate(start = \"L_R_L_R_L_R\",target = \"LL______RRR\") == False\n assert candidate(start = \"_L__R_L_R\",target = \"L_____RLR\") == False\n assert candidate(start = \"R_L_R_L_R_L_R___\",target = \"_L_R_L_R_L_R____\") == False\n assert candidate(start = \"R___L___R\",target = \"__LR___R_\") == False\n assert candidate(start = \"______L_R\",target = \"L______R_\") == False\n assert candidate(start = \"R__L_L___R\",target = \"___LR____R\") == False\n assert candidate(start = \"_L_L_L_L\",target = \"LLLL____\") == True\n assert candidate(start = \"_L_R_L_R_\",target = \"L_____R_R\") == False\n assert candidate(start = \"L_R_L_R_L_R\",target = \"_LR_L_R_L_R\") == False\n assert candidate(start = \"L_R_L_R_L_R\",target = \"_L_L_L_RLR_\") == False\n assert candidate(start = \"L_____R_L____\",target = \"________L_R__\") == False\n assert candidate(start = \"R_L_R___L_R___\",target = \"_L_R_L___R____\") == False\n assert candidate(start = \"_L_R__L__R\",target = \"____L___LR\") == False\n assert candidate(start = \"R_L_R___L\",target = \"_LR______\") == False\n assert candidate(start = \"L_R_L___R\",target = \"L___LR___\") == False\n assert candidate(start = \"R_L_R_L_R\",target = \"_LR_L_R_L\") == False\n assert candidate(start = \"LRLR_LRL\",target = \"LRLR_LRL\") == True\n assert candidate(start = \"R_____L__\",target = \"_____LR__\") == False\n assert candidate(start = \"R_L_R_L\",target = \"__LR__L\") == False\n assert candidate(start = \"R_L_R_L_R_L\",target = \"LR_L_R_L_R_\") == False\n assert candidate(start = \"L_____R___L\",target = \"________LRL\") == False\n assert candidate(start = \"_L____R_____\",target = \"L_____R_____\") == True\n assert candidate(start = \"___LR___R\",target = \"L_____RR_\") == False\n assert candidate(start = \"_L___R_L_R\",target = \"L_____RR__\") == False\n assert candidate(start = \"L___R__L_R\",target = \"LL______RR\") == False\n assert candidate(start = \"______\",target = \"______\") == True\n assert candidate(start = \"R_L_R___L_R\",target = \"_L_R_L___RR\") == False\n assert candidate(start = \"R________L\",target = \"________LR\") == False\n assert candidate(start = \"R_L___L_R\",target = \"__LR__L_R\") == False\n assert candidate(start = \"L___R___L\",target = \"__L___R_L\") == False\n assert candidate(start = \"_______L_L_R_R\",target = \"L______L___R_R\") == True\n assert candidate(start = \"RRRLLL___\",target = \"___RRRLLL\") == False\n assert candidate(start = \"L__R__L___R____\",target = \"L___L__R__R____\") == False\n assert candidate(start = \"L___R__L___\",target = \"_L_____RL__\") == False\n assert candidate(start = \"L___R___L___R\",target = \"L___L___R___R\") == False\n assert candidate(start = \"____L___R__\",target = \"L_____R____\") == False\n assert candidate(start = \"L_R__L_R\",target = \"_LR__LR_\") == False\n assert candidate(start = \"R_L___LR__L____\",target = \"__LR__LR__L____\") == False\n assert candidate(start = \"L___R___R\",target = \"___L____R\") == False\n assert candidate(start = \"L___R___L_R\",target = \"L_____RL___\") == False\n assert candidate(start = \"__L_R__R_L\",target = \"L_____R__L\") == False\n assert candidate(start = \"_L___R__L\",target = \"L_____R__\") == False\n assert candidate(start = \"_L_R_L_R_R\",target = \"L______RRR\") == False\n assert candidate(start = \"_R_L_R_L____\",target = \"____LR____LR\") == False\n assert candidate(start = \"R_L__R\",target = \"__LR__\") == False\n", "comparison": "exact"}, "public_tests": ["\"_L__R__R_\"\n\"L______RR\"", "\"R_L_\"\n\"__LR\"", "\"_R\"\n\"R_\""], "hints": ["After some sequence of moves, can the order of the pieces change?", "Try to match each piece in s with a piece in e."], "metadata": {"canonical_parameter_names": ["start", "target"], "leetcode_dataset_entry_point": "Solution().canChange", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:14+00:00", "tests_total": 136, "tests_dropped": 37, "flags": [], "topic_tags": ["two-pointers", "string"]}, "language": "php", "interface": {"raw_signature": "function canChange($start, $target) {", "container": "Solution", "callable": "canChange", "parameters": [{"name": "start", "type": "String"}, {"name": "target", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2338, "task_id": "count-the-number-of-ideal-arrays", "difficulty": "Hard", "problem_description": "You are given two integers n and maxValue, which are used to describe an ideal array.\n\nA 0-indexed integer array arr of length n is considered ideal if the following conditions hold:\n\n- Every arr[i] is a value from 1 to maxValue, for 0 <= i < n.\n- Every arr[i] is divisible by arr[i - 1], for 0 < i < n.\n\nReturn the number of distinct ideal arrays of length n. Since the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 2, maxValue = 5\nOutput: 10\nExplanation: The following are the possible ideal arrays:\n- Arrays starting with the value 1 (5 arrays): [1,1], [1,2], [1,3], [1,4], [1,5]\n- Arrays starting with the value 2 (2 arrays): [2,2], [2,4]\n- Arrays starting with the value 3 (1 array): [3,3]\n- Arrays starting with the value 4 (1 array): [4,4]\n- Arrays starting with the value 5 (1 array): [5,5]\nThere are a total of 5 + 2 + 1 + 1 + 1 = 10 distinct ideal arrays.\n\nExample 2:\n\nInput: n = 5, maxValue = 3\nOutput: 11\nExplanation: The following are the possible ideal arrays:\n- Arrays starting with the value 1 (9 arrays):\n - With no other distinct values (1 array): [1,1,1,1,1]\n - With 2^nd distinct value 2 (4 arrays): [1,1,1,1,2], [1,1,1,2,2], [1,1,2,2,2], [1,2,2,2,2]\n - With 2^nd distinct value 3 (4 arrays): [1,1,1,1,3], [1,1,1,3,3], [1,1,3,3,3], [1,3,3,3,3]\n- Arrays starting with the value 2 (1 array): [2,2,2,2,2]\n- Arrays starting with the value 3 (1 array): [3,3,3,3,3]\nThere are a total of 9 + 1 + 1 = 11 distinct ideal arrays.\n\nConstraints:\n\n- 2 <= n <= 10^4\n- 1 <= maxValue <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 7,maxValue = 7) == 106\n assert candidate(n = 2,maxValue = 5) == 10\n assert candidate(n = 3,maxValue = 7) == 28\n assert candidate(n = 3,maxValue = 6) == 25\n assert candidate(n = 6,maxValue = 12) == 327\n assert candidate(n = 10,maxValue = 5) == 86\n assert candidate(n = 4,maxValue = 4) == 19\n assert candidate(n = 10,maxValue = 10) == 571\n assert candidate(n = 4,maxValue = 7) == 43\n assert candidate(n = 3,maxValue = 2) == 4\n assert candidate(n = 10000,maxValue = 10000) == 22940607\n assert candidate(n = 4,maxValue = 10) == 89\n assert candidate(n = 5,maxValue = 3) == 11\n assert candidate(n = 2000,maxValue = 10) == 347343994\n assert candidate(n = 15,maxValue = 10) == 1431\n assert candidate(n = 7,maxValue = 20) == 1191\n assert candidate(n = 8000,maxValue = 8000) == 106406983\n assert candidate(n = 8,maxValue = 16) == 1115\n assert candidate(n = 6000,maxValue = 6000) == 883250062\n assert candidate(n = 2000,maxValue = 5000) == 716352377\n assert candidate(n = 10000,maxValue = 1) == 1\n assert candidate(n = 100,maxValue = 50) == 604383896\n assert candidate(n = 1000,maxValue = 4) == 502501\n assert candidate(n = 9,maxValue = 5) == 73\n assert candidate(n = 7,maxValue = 15) == 575\n assert candidate(n = 10,maxValue = 20) == 3176\n assert candidate(n = 2000,maxValue = 1000) == 534638579\n assert candidate(n = 10,maxValue = 15) == 1341\n assert candidate(n = 50,maxValue = 20) == 519126\n assert candidate(n = 8,maxValue = 3) == 17\n assert candidate(n = 20,maxValue = 2) == 21\n assert candidate(n = 6,maxValue = 3) == 13\n assert candidate(n = 100,maxValue = 3) == 201\n assert candidate(n = 10000,maxValue = 5000) == 22892639\n assert candidate(n = 9999,maxValue = 10000) == 667133522\n assert candidate(n = 6000,maxValue = 3000) == 80648523\n assert candidate(n = 3000,maxValue = 3000) == 806624302\n assert candidate(n = 2000,maxValue = 2000) == 585712681\n assert candidate(n = 3,maxValue = 1) == 1\n assert candidate(n = 5000,maxValue = 5) == 12517501\n assert candidate(n = 5000,maxValue = 2000) == 802769368\n assert candidate(n = 1000,maxValue = 2000) == 228299266\n assert candidate(n = 8,maxValue = 20) == 1707\n assert candidate(n = 50,maxValue = 25) == 1630451\n assert candidate(n = 100,maxValue = 2) == 101\n assert candidate(n = 5,maxValue = 1) == 1\n assert candidate(n = 6,maxValue = 8) == 138\n assert candidate(n = 5,maxValue = 9999) == 6309016\n assert candidate(n = 100,maxValue = 5) == 5351\n assert candidate(n = 500,maxValue = 3) == 1001\n assert candidate(n = 2000,maxValue = 50) == 74895101\n assert candidate(n = 100,maxValue = 100) == 959337187\n assert candidate(n = 5,maxValue = 100) == 7537\n assert candidate(n = 100,maxValue = 10) == 202201\n assert candidate(n = 9,maxValue = 9) == 373\n assert candidate(n = 5000,maxValue = 20) == 436322284\n assert candidate(n = 2000,maxValue = 10000) == 239341549\n assert candidate(n = 20,maxValue = 50) == 388980\n assert candidate(n = 10000,maxValue = 500) == 397370814\n assert candidate(n = 1000,maxValue = 1000) == 91997497\n assert candidate(n = 7500,maxValue = 7500) == 143340271\n assert candidate(n = 25,maxValue = 30) == 153176\n assert candidate(n = 500,maxValue = 500) == 652553975\n assert candidate(n = 5000,maxValue = 100) == 853200627\n assert candidate(n = 5000,maxValue = 5000) == 144035088\n assert candidate(n = 1000,maxValue = 100) == 607180637\n assert candidate(n = 50,maxValue = 100) == 268368886\n assert candidate(n = 10000,maxValue = 100) == 200548806\n assert candidate(n = 10,maxValue = 100) == 105568\n assert candidate(n = 2,maxValue = 10000) == 93668\n assert candidate(n = 10,maxValue = 10000) == 466423769\n assert candidate(n = 1000,maxValue = 10000) == 888200964\n assert candidate(n = 15,maxValue = 15) == 3711\n assert candidate(n = 3000,maxValue = 6000) == 321990518\n assert candidate(n = 8,maxValue = 2) == 9\n assert candidate(n = 30,maxValue = 30) == 290436\n assert candidate(n = 1000,maxValue = 10) == 170172001\n assert candidate(n = 7500,maxValue = 10000) == 430119293\n assert candidate(n = 8000,maxValue = 9000) == 358648747\n assert candidate(n = 7500,maxValue = 5000) == 777616479\n", "comparison": "exact"}, "public_tests": ["2\n5", "5\n3"], "hints": ["Notice that an ideal array is non-decreasing.", "Consider an alternative problem: where an ideal array must also be strictly increasing. Can you use DP to solve it?", "Will combinatorics help to get an answer from the alternative problem to the actual problem?"], "metadata": {"canonical_parameter_names": ["n", "maxValue"], "leetcode_dataset_entry_point": "Solution().idealArrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:17+00:00", "tests_total": 80, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "dynamic-programming", "combinatorics", "number-theory", "prime-factorization", "fermats-little-theorem"]}, "language": "php", "interface": {"raw_signature": "function idealArrays($n, $maxValue) {", "container": "Solution", "callable": "idealArrays", "parameters": [{"name": "n", "type": "Integer"}, {"name": "maxValue", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2341, "task_id": "maximum-number-of-pairs-in-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums. In one operation, you may do the following:\n\n- Choose two integers in nums that are equal.\n- Remove both integers from nums, forming a pair.\n\nThe operation is done on nums as many times as possible.\n\nReturn a 0-indexed integer array answer of size 2 where answer[0] is the number of pairs that are formed and answer[1] is the number of leftover integers in nums after doing the operation as many times as possible.\n\nExample 1:\n\nInput: nums = [1,3,2,1,3,2,2]\nOutput: [3,1]\nExplanation:\nForm a pair with nums[0] and nums[3] and remove them from nums. Now, nums = [3,2,3,2,2].\nForm a pair with nums[0] and nums[2] and remove them from nums. Now, nums = [2,2,2].\nForm a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [2].\nNo more pairs can be formed. A total of 3 pairs have been formed, and there is 1 number leftover in nums.\n\nExample 2:\n\nInput: nums = [1,1]\nOutput: [1,0]\nExplanation: Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [].\nNo more pairs can be formed. A total of 1 pair has been formed, and there are 0 numbers leftover in nums.\n\nExample 3:\n\nInput: nums = [0]\nOutput: [0,1]\nExplanation: No pairs can be formed, and there is 1 number leftover in nums.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 0 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [5, 0]\n assert candidate(nums = [100, 0, 50, 50, 0, 100]) == [3, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 10]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [5, 1]\n assert candidate(nums = [42]) == [0, 1]\n assert candidate(nums = [1]) == [0, 1]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 2]) == [3, 1]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1]) == [4, 1]\n assert candidate(nums = [6, 6, 6, 7, 7, 7, 8, 8, 8, 8]) == [4, 2]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [5, 0]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [5, 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]) == [10, 0]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == [6, 0]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [0, 5]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == [3, 3]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == [5, 0]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == [5, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [5, 0]\n assert candidate(nums = [0]) == [0, 1]\n assert candidate(nums = [100, 100, 100, 99, 99, 98]) == [2, 2]\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == [3, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [4, 2]\n assert candidate(nums = [100, 100, 99, 99, 98, 98, 97, 97, 96, 96]) == [5, 0]\n assert candidate(nums = [1, 1]) == [1, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [5, 0]\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2]) == [3, 1]\n assert candidate(nums = [100, 100, 100]) == [1, 1]\n assert candidate(nums = [30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34]) == [8, 3]\n assert candidate(nums = [1, 2, 1, 2, 3, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6]) == [7, 1]\n assert candidate(nums = [10, 10, 10, 10, 10, 20, 20, 20, 20, 30, 30, 30, 40, 40, 40, 40, 40]) == [7, 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]) == [14, 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]) == [15, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == [10, 0]\n assert candidate(nums = [65, 65, 65, 65, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68]) == [11, 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]) == [18, 0]\n assert candidate(nums = [34, 34, 34, 35, 35, 35, 35, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38]) == [13, 2]\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]) == [11, 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]) == [8, 4]\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]) == [12, 1]\n assert candidate(nums = [7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12]) == [9, 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, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == [16, 5]\n assert candidate(nums = [30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33]) == [12, 3]\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [10, 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]) == [15, 0]\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]) == [13, 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, 5, 5, 5, 5, 5, 5, 5, 5]) == [14, 2]\n assert candidate(nums = [1, 1, 1, 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]) == [3, 23]\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, 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]) == [10, 5]\n assert candidate(nums = [35, 35, 35, 35, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38]) == [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]) == [0, 30]\n assert candidate(nums = [10, 20, 10, 20, 30, 30, 30, 40, 40, 40, 40]) == [5, 1]\n assert candidate(nums = [21, 22, 22, 21, 23, 24, 24, 23, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29]) == [9, 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, 6, 6, 6, 6, 6, 6, 6]) == [12, 3]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6]) == [15, 0]\n assert candidate(nums = [6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8]) == [8, 1]\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]) == [11, 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]) == [9, 2]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [6, 2]\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40, 40]) == [6, 1]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4]) == [7, 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]) == [12, 1]\n assert candidate(nums = [21, 21, 21, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25]) == [9, 2]\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]) == [13, 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]) == [15, 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]) == [10, 0]\n assert candidate(nums = [45, 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49]) == [14, 2]\n assert candidate(nums = [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [8, 4]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == [7, 1]\n assert candidate(nums = [16, 17, 18, 19, 20, 16, 17, 18, 19, 20, 16, 17, 18, 19, 20, 16, 17, 18, 19, 20, 16, 17, 18, 19, 20]) == [10, 5]\n assert candidate(nums = [10, 10, 10, 20, 20, 30, 30, 40, 40, 40, 50, 50, 50, 50]) == [6, 2]\n assert candidate(nums = [10, 20, 10, 30, 20, 30, 40, 40, 40, 50, 50, 50, 50, 60, 60, 60, 60, 60]) == [8, 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, 2, 2, 2, 2, 2, 2]) == [18, 1]\n assert candidate(nums = [10, 20, 10, 30, 20, 30, 40, 50, 60, 40, 50, 60, 70, 80, 90, 100, 70, 80, 90, 100]) == [10, 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, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == [20, 0]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]) == [10, 0]\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, 1]\n assert candidate(nums = [39, 39, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44]) == [12, 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]) == [0, 20]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 2, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6]) == [11, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 10]\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == [8, 4]\n assert candidate(nums = [99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92, 91, 91, 90, 90]) == [10, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [6, 3]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 10, 10]) == [14, 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]) == [14, 0]\n assert candidate(nums = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99]) == [10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [15, 0]\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [9, 5]\n assert candidate(nums = [7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10]) == [9, 2]\n assert candidate(nums = [10, 10, 20, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40, 40]) == [6, 2]\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == [0, 20]\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]) == [0, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == [15, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == [20, 0]\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10]) == [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]) == [0, 20]\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10]) == [13, 1]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == [6, 2]\n assert candidate(nums = [11, 12, 11, 12, 13, 14, 15, 14, 13, 15, 15, 14, 13, 12, 11]) == [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, 1, 2, 3, 4, 5]) == [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]) == [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, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == [10, 2]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]) == [16, 0]\n assert candidate(nums = [16, 16, 17, 17, 17, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 20]) == [7, 2]\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == [15, 2]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10]) == [16, 0]\n assert candidate(nums = [52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52]) == [19, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 6, 7, 8, 9, 10]) == [10, 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]) == [12, 2]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [4, 2]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8]) == [15, 1]\n assert candidate(nums = [60, 60, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64]) == [9, 2]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 6, 7, 8, 9, 10]) == [6, 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, 12, 12, 12]) == [12, 12]\n assert candidate(nums = [26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29]) == [11, 2]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == [12, 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]) == [14, 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]) == [12, 2]\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9]) == [8, 1]\n assert candidate(nums = [0, 1, 1, 0, 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]) == [12, 5]\n assert candidate(nums = [2, 3, 3, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6]) == [7, 4]\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]) == [11, 3]\n assert candidate(nums = [7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]) == [7, 1]\n assert candidate(nums = [39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) == [0, 21]\n", "comparison": "exact"}, "public_tests": ["[1,3,2,1,3,2,2]", "[1,1]", "[0]"], "hints": ["What do we need to know to find how many pairs we can make? We need to know the frequency of each integer.", "When will there be a leftover number? When the frequency of an integer is an odd number."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:21+00:00", "tests_total": 126, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function numberOfPairs($nums) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2342, "task_id": "max-sum-of-a-pair-with-equal-sum-of-digits", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j].\n\nReturn the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions. If no such pair of indices exists, return -1.\n\nExample 1:\n\nInput: nums = [18,43,36,13,7]\nOutput: 54\nExplanation: The pairs (i, j) that satisfy the conditions are:\n- (0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.\n- (1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.\nSo the maximum sum that we can obtain is 54.\n\nExample 2:\n\nInput: nums = [10,12,19,14]\nOutput: -1\nExplanation: There are no two numbers that satisfy the conditions, so 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 = [99, 18, 81, 27]) == 108\n assert candidate(nums = [55, 23, 45, 55, 23]) == 110\n assert candidate(nums = [55, 23, 45, 55]) == 110\n assert candidate(nums = [111, 222, 333, 444]) == -1\n assert candidate(nums = [1000000000]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [999999999, 999999999]) == 1999999998\n assert candidate(nums = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [999999999, 111111111, 222222222]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == -1\n assert candidate(nums = [99, 18, 81, 27, 72]) == 153\n assert candidate(nums = [9, 99, 999, 9999]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500]) == -1\n assert candidate(nums = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 1100000000\n assert candidate(nums = [89, 98, 76, 67, 54, 45, 32, 23, 10, 1]) == 187\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(nums = [55, 23, 32, 44, 55]) == 110\n assert candidate(nums = [55, 23, 45, 67, 89, 90, 11]) == 135\n assert candidate(nums = [123, 321, 213, 132, 231, 312]) == 633\n assert candidate(nums = [10, 12, 19, 14]) == -1\n assert candidate(nums = [18, 43, 36, 13, 7]) == 54\n assert candidate(nums = [123, 321, 213]) == 534\n assert candidate(nums = [55, 23, 45, 67, 89, 90]) == 135\n assert candidate(nums = [123, 321, 213, 132, 312, 231]) == 633\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == -1\n assert candidate(nums = [123456789, 987654321, 234567891, 123456789, 987654321]) == 1975308642\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888]) == 1543209876\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 1100\n assert candidate(nums = [55555, 44444, 33333, 22222, 11111, 66666, 77777, 88888, 99999]) == -1\n assert candidate(nums = [12345, 54321, 13452, 21435, 23541, 32145, 42315, 52314, 34512, 54123]) == 108444\n assert candidate(nums = [12345, 54321, 23451, 45123, 34512, 123456, 654321, 234516, 165432, 321654, 654123, 412365, 564321, 123654, 654312]) == 1308633\n assert candidate(nums = [123, 321, 231, 312, 132, 213, 456, 654, 564, 546, 465, 645, 789, 987, 897, 879, 798, 978]) == 1965\n assert candidate(nums = [1001, 1100, 1010, 1001, 2002, 2020, 2200, 3003, 3030, 3300]) == 6330\n assert candidate(nums = [123456789, 987654321, 234567891, 345678912, 456789123, 567891234, 678912345, 789123456, 891234567]) == 1878888888\n assert candidate(nums = [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 10000]) == -1\n assert candidate(nums = [123, 132, 213, 231, 312, 321, 456, 465, 546, 564, 645, 654, 789, 798, 879, 897, 978, 987, 101, 110, 1001, 1010, 1100]) == 2110\n assert candidate(nums = [555555555, 222222222, 333333333, 444444444, 55555555, 22222222, 33333333, 44444444, 5555555, 2222222, 3333333, 4444444]) == -1\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111]) == -1\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999]) == 1100000000\n assert candidate(nums = [123, 321, 213, 132, 312, 231, 111, 222, 333]) == 633\n assert candidate(nums = [999, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 1998\n assert candidate(nums = [1001, 1100, 1010, 10001, 9999, 8888, 7777, 6666, 5555, 4444, 3333, 2222, 1111]) == 11101\n assert candidate(nums = [99, 999, 9999, 99999, 999999]) == -1\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789, 987654321]) == 1543209876\n assert candidate(nums = [1234, 4321, 2341, 1432, 1243, 2413, 3412, 4123, 1342, 3241]) == 8444\n assert candidate(nums = [999999999, 111111111, 222222222, 333333333, 444444444]) == -1\n assert candidate(nums = [987654321, 123456789, 98765432, 12345678, 9876543, 1234567]) == 1111111110\n assert candidate(nums = [1001, 1010, 1100, 2002, 2020, 2200, 3003, 3030, 3300]) == 6330\n assert candidate(nums = [11112, 22223, 33334, 44445, 55556, 66667, 77778, 88889, 99990]) == 177768\n assert candidate(nums = [123, 321, 111, 456, 654, 789, 987]) == 1776\n assert candidate(nums = [987654321, 123456789, 111222333, 333222111, 444444444, 555555555]) == 1543209876\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 100, 200, 300, 400, 500, 600, 700, 800, 900]) == 1233\n assert candidate(nums = [876, 768, 687, 867, 678, 786, 543, 456, 345, 435, 543, 534]) == 1743\n assert candidate(nums = [12345, 54321, 11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999]) == 87654\n assert candidate(nums = [54321, 21345, 32145, 45321, 14523, 51423, 23451, 34512, 45123, 12354]) == 105744\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 1875\n assert candidate(nums = [500000000, 499999999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 999999999]) == 500000005\n assert candidate(nums = [12, 21, 30, 13, 31, 40, 24, 42, 33, 50]) == 75\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999]) == -1\n assert candidate(nums = [123, 321, 213, 111, 222, 333]) == 543\n assert candidate(nums = [999, 111, 222, 333, 444, 555, 666, 777, 888]) == -1\n assert candidate(nums = [9, 90, 900, 9000, 90000, 900000, 9000000, 90000000, 900000000]) == 990000000\n assert candidate(nums = [123456789, 987654321, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888]) == 1543209876\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999]) == -1\n assert candidate(nums = [199, 288, 377, 466, 555, 644, 733, 822, 911, 1000]) == -1\n assert candidate(nums = [123, 321, 213, 132, 312, 231]) == 633\n assert candidate(nums = [12345, 54321, 23451, 15432, 67890, 98760, 89076, 76980, 32145, 54312]) == 187836\n assert candidate(nums = [999999999, 111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888]) == -1\n assert candidate(nums = [123456789, 12345678, 1234567, 123456, 12345, 1234, 123, 12, 1]) == -1\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 456, 654, 546, 465, 564, 645, 789, 987, 897, 798, 879, 978]) == 1965\n assert candidate(nums = [987654321, 123456789, 234567891, 345678912, 456789123]) == 1444443444\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 18, 81, 123, 321, 132, 213, 231, 312]) == 633\n assert candidate(nums = [123456789, 987654321, 123456789, 987654321]) == 1975308642\n assert candidate(nums = [100, 101, 110, 111, 200, 201, 210, 211, 300, 301, 310, 311]) == 611\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 1100000000\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 171\n assert candidate(nums = [123, 321, 213, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 543\n assert candidate(nums = [99999999, 9999999, 999999, 99999, 9999, 999, 99, 9, 88888888, 8888888, 888888, 88888, 8888, 888, 88, 8]) == -1\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 9675\n assert candidate(nums = [12, 21, 13, 31, 14, 41, 15, 51, 16, 61, 17, 71, 18, 81, 19, 91]) == 110\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999, 9999999]) == -1\n assert candidate(nums = [1001, 110, 1110, 1011, 11100, 11110, 10111]) == 21221\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 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]) == 31\n assert candidate(nums = [123, 234, 345, 456, 567, 678, 789, 890, 901, 102]) == -1\n assert candidate(nums = [100000000, 100000001, 100000002, 100000003, 100000004, 100000005]) == -1\n assert candidate(nums = [1001, 1010, 1100, 2002, 2020, 2200, 3003, 3030, 3300]) == 6330\n assert candidate(nums = [123456789, 987654321, 111222333, 444555666, 777888999]) == 1432209987\n assert candidate(nums = [123456789, 987654321, 234567891, 123456782, 111111111]) == 1222222212\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == -1\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 234, 432, 567, 765, 890, 980]) == 1870\n assert candidate(nums = [100000000, 200000000, 300000000, 111111111, 222222222, 333333333]) == -1\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 1100000000\n assert candidate(nums = [98765, 56789, 12345, 54321, 67890, 9876, 6789, 1234, 5678, 2345]) == 155554\n assert candidate(nums = [56, 65, 74, 47, 83, 38, 92, 29, 101, 110]) == 211\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990]) == -1\n assert candidate(nums = [1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 1100000000\n assert candidate(nums = [876543210, 123456789, 111222333, 444555666, 777888999, 555555555, 666666666]) == 1000111221\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 100000000]) == -1\n assert candidate(nums = [999999999, 111111111, 222222222, 333333333, 444444444, 555555555]) == -1\n assert candidate(nums = [123, 1230, 1203, 1023, 10023, 100023, 1000023, 10000023, 100000023]) == 110000046\n assert candidate(nums = [112, 121, 211, 221, 212, 122, 333, 444, 555, 666, 777, 888, 999, 1001, 1010, 1100]) == 2110\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 111, 222, 333, 444]) == 633\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999]) == -1\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 1101, 2202, 3303, 4404, 5505]) == 10410\n assert candidate(nums = [101, 110, 202, 220, 303, 330, 404, 440, 505, 550]) == 1055\n assert candidate(nums = [1234, 4321, 2134, 1324, 2341, 3412, 3421, 4231, 4123, 2431]) == 8552\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909]) == -1\n assert candidate(nums = [123, 321, 213, 132, 231, 312, 12, 21, 111, 222, 333, 444, 555, 666, 777, 888, 999]) == 633\n assert candidate(nums = [11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999]) == -1\n assert candidate(nums = [987654321, 98765432, 9876543, 987654, 98765, 9876, 987, 98, 9]) == -1\n assert candidate(nums = [123, 321, 213, 456, 654, 564, 999, 888, 777, 111]) == 1218\n assert candidate(nums = [987, 654, 321, 432, 789, 123]) == 1776\n assert candidate(nums = [88, 88, 88, 88, 88, 88, 88, 88, 88, 88]) == 176\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1]) == 1100000000\n", "comparison": "exact"}, "public_tests": ["[18,43,36,13,7]", "[10,12,19,14]"], "hints": ["What is the largest possible sum of digits a number can have?", "Group the array elements by the sum of their digits, and find the largest two elements of each group."], "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-30T20:49:24+00:00", "tests_total": 121, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maximumSum($nums) {", "container": "Solution", "callable": "maximumSum", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2343, "task_id": "query-kth-smallest-trimmed-number", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits.\n\nYou are also given a 0-indexed 2D integer array queries where queries[i] = [k_i, trim_i]. For each queries[i], you need to:\n\n- Trim each number in nums to its rightmost trim_i digits.\n- Determine the index of the k_i^th smallest trimmed number in nums. If two trimmed numbers are equal, the number with the lower index is considered to be smaller.\n- Reset each number in nums to its original length.\n\nReturn an array answer of the same length as queries, where answer[i] is the answer to the i^th query.\n\nNote:\n\n- To trim to the rightmost x digits means to keep removing the leftmost digit, until only x digits remain.\n- Strings in nums may contain leading zeros.\n\nExample 1:\n\nInput: nums = [\"102\",\"473\",\"251\",\"814\"], queries = [[1,1],[2,3],[4,2],[1,2]]\nOutput: [2,2,1,0]\nExplanation:\n1. After trimming to the last digit, nums = [\"2\",\"3\",\"1\",\"4\"]. The smallest number is 1 at index 2.\n2. Trimmed to the last 3 digits, nums is unchanged. The 2^nd smallest number is 251 at index 2.\n3. Trimmed to the last 2 digits, nums = [\"02\",\"73\",\"51\",\"14\"]. The 4^th smallest number is 73.\n4. Trimmed to the last 2 digits, the smallest number is 2 at index 0.\n Note that the trimmed number \"02\" is evaluated as 2.\n\nExample 2:\n\nInput: nums = [\"24\",\"37\",\"96\",\"04\"], queries = [[2,1],[2,2]]\nOutput: [3,0]\nExplanation:\n1. Trimmed to the last digit, nums = [\"4\",\"7\",\"6\",\"4\"]. The 2^nd smallest number is 4 at index 3.\n There are two occurrences of 4, but the one at index 0 is considered smaller than the one at index 3.\n2. Trimmed to the last 2 digits, nums is unchanged. The 2^nd smallest number is 24.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i].length <= 100\n- nums[i] consists of only digits.\n- All nums[i].length are equal.\n- 1 <= queries.length <= 100\n- queries[i].length == 2\n- 1 <= k_i <= nums.length\n- 1 <= trim_i <= nums[i].length\n\nFollow up: Could you use the Radix Sort Algorithm to solve this problem? What will be the complexity of that solution?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = ['111', '222', '333', '444'],queries = [[1, 1], [2, 2], [3, 3], [4, 3]]) == [0, 1, 2, 3]\n assert candidate(nums = ['123', '456', '789', '012'],queries = [[1, 2], [3, 3], [2, 1]]) == [3, 1, 0]\n assert candidate(nums = ['001', '002', '003'],queries = [[1, 1], [2, 1], [3, 1]]) == [0, 1, 2]\n assert candidate(nums = ['001', '012', '123', '234'],queries = [[1, 2], [2, 3], [3, 1]]) == [0, 1, 2]\n assert candidate(nums = ['001', '002', '003', '004'],queries = [[1, 3], [4, 1], [2, 2]]) == [0, 3, 1]\n assert candidate(nums = ['24', '37', '96', '04'],queries = [[2, 1], [2, 2]]) == [3, 0]\n assert candidate(nums = ['111', '222', '333', '444'],queries = [[1, 1], [2, 2], [3, 3], [4, 4]]) == [0, 1, 2, 3]\n assert candidate(nums = ['56', '78', '90'],queries = [[1, 1], [2, 2]]) == [2, 1]\n assert candidate(nums = ['12', '12', '12'],queries = [[1, 1], [2, 1], [3, 1]]) == [0, 1, 2]\n assert candidate(nums = ['567', '890', '123'],queries = [[1, 3], [2, 2], [3, 1]]) == [2, 0, 0]\n assert candidate(nums = ['123', '456', '789'],queries = [[1, 2], [3, 3], [2, 1]]) == [0, 2, 1]\n assert candidate(nums = ['123', '456', '789'],queries = [[1, 2], [3, 1], [2, 3]]) == [0, 2, 1]\n assert candidate(nums = ['102', '473', '251', '814'],queries = [[1, 1], [2, 3], [4, 2], [1, 2]]) == [2, 2, 1, 0]\n assert candidate(nums = ['001', '010', '100'],queries = [[1, 1], [2, 2], [3, 3]]) == [1, 0, 2]\n assert candidate(nums = ['987', '654', '321'],queries = [[1, 3], [2, 2], [3, 1]]) == [2, 1, 0]\n assert candidate(nums = ['00123', '01234', '12345', '23456', '34567'],queries = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['1234567890', '9876543210', '0000000000', '1111111111', '2222222222'],queries = [[1, 5], [3, 10], [2, 3], [5, 2]]) == [2, 0, 3, 0]\n assert candidate(nums = ['9999', '8888', '7777', '6666'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [1, 4]]) == [3, 2, 1, 0, 3]\n assert candidate(nums = ['111111111', '222222222', '333333333', '444444444', '555555555', '666666666', '777777777', '888888888', '999999999'],queries = [[9, 1], [1, 9], [5, 5], [3, 7], [7, 3], [2, 8], [8, 2], [4, 6], [6, 4]]) == [8, 0, 4, 2, 6, 1, 7, 3, 5]\n assert candidate(nums = ['1001', '10001', '100001', '1000001', '10000001'],queries = [[1, 4], [2, 6], [3, 3], [4, 5], [5, 1]]) == [1, 4, 2, 1, 4]\n assert candidate(nums = ['123456', '654321', '135799', '975311', '246800'],queries = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2]]) == [0, 2, 3, 2, 2]\n assert candidate(nums = ['12345', '67890', '54321', '09876', '43210'],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [3, 4, 0, 3, 3]\n assert candidate(nums = ['123456789', '987654321', '135792468', '246801357', '579135791'],queries = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [1, 4], [2, 3], [3, 2], [4, 1]]) == [0, 2, 3, 2, 2, 3, 3, 2, 2]\n assert candidate(nums = ['10001', '01001', '00101', '00011', '11001'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [2, 3]]) == [0, 1, 4, 1, 4, 1]\n assert candidate(nums = ['00001', '00002', '00003', '00004', '00005', '00006', '00007', '00008', '00009'],queries = [[1, 1], [9, 1], [2, 1], [3, 1], [8, 1], [4, 1], [7, 1], [5, 1], [6, 1]]) == [0, 8, 1, 2, 7, 3, 6, 4, 5]\n assert candidate(nums = ['1234', '2345', '3456', '4567', '5678', '6789', '7890'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7]]) == [6, 1, 2, 3, 4, 5, 6]\n assert candidate(nums = ['00000', '00001', '00002', '00003', '00004'],queries = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 5]]) == [0, 1, 2, 3, 4, 0]\n assert candidate(nums = ['00001', '00010', '00100', '01000', '10000'],queries = [[1, 1], [5, 5], [3, 3], [2, 2], [4, 4]]) == [1, 4, 0, 3, 2]\n assert candidate(nums = ['987', '876', '765', '654', '543', '432', '321', '210', '109'],queries = [[1, 1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3], [7, 2], [8, 3], [9, 1]]) == [7, 6, 6, 5, 4, 3, 2, 1, 8]\n assert candidate(nums = ['1010', '0101', '0011', '1100'],queries = [[1, 2], [2, 1], [3, 4], [4, 3]]) == [3, 3, 0, 1]\n assert candidate(nums = ['1111', '2222', '3333', '4444', '5555'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 5]]) == [0, 1, 2, 3, 4, 0]\n assert candidate(nums = ['000001', '000010', '000100', '001000', '010000', '100000'],queries = [[1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6]]) == [0, 1, 2, 3, 4, 5]\n assert candidate(nums = ['11111', '11112', '11122', '11222', '12222'],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['100100', '100010', '101000', '010100', '001100', '001010', '010010', '000101', '000011', '110000'],queries = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1], [7, 6], [8, 5], [9, 4], [10, 3]]) == [8, 8, 6, 5, 9, 5, 1, 9, 5, 7]\n assert candidate(nums = ['11111', '22222', '33333', '44444', '55555'],queries = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['999', '888', '777', '666', '555'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 3]]) == [4, 3, 2, 1, 0]\n assert candidate(nums = ['00123', '00234', '00345', '00456'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [2, 3]]) == [0, 1, 2, 3, 1]\n assert candidate(nums = ['123', '234', '345', '456', '567', '678', '789', '890', '901', '012'],queries = [[1, 1], [10, 3], [5, 2], [3, 3], [8, 1], [2, 2], [7, 3], [4, 3], [6, 3], [9, 1]]) == [7, 8, 2, 1, 4, 9, 5, 2, 4, 5]\n assert candidate(nums = ['00000', '11111', '22222', '33333', '44444', '55555'],queries = [[1, 1], [6, 5], [3, 3], [4, 2], [2, 4], [5, 5]]) == [0, 5, 2, 3, 1, 4]\n assert candidate(nums = ['123', '456', '789', '101', '111'],queries = [[1, 1], [2, 2], [3, 3], [4, 1], [5, 2]]) == [3, 4, 0, 1, 2]\n assert candidate(nums = ['123456', '654321', '111111', '222222', '333333'],queries = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2]]) == [2, 3, 4, 4, 0]\n assert candidate(nums = ['999', '111', '222', '888', '333', '444', '555', '666', '777', '000'],queries = [[1, 1], [10, 3], [5, 2], [3, 3], [8, 1], [2, 2], [4, 4], [7, 5], [6, 6], [9, 9]]) == [9, 0, 5, 2, 8, 1, 4, 7, 6, 3]\n assert candidate(nums = ['09876', '54321', '01234', '98765', '43210'],queries = [[1, 3], [2, 2], [3, 1], [4, 5], [5, 4]]) == [4, 1, 2, 1, 0]\n assert candidate(nums = ['0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'],queries = [[1, 1], [5, 4], [10, 1], [3, 2], [7, 3]]) == [0, 4, 9, 2, 6]\n assert candidate(nums = ['00011', '00101', '01001', '10001', '00110', '01100', '11000', '10100', '01010', '10010'],queries = [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [8, 3], [9, 3], [10, 3]]) == [6, 2, 3, 8, 9, 0, 5, 7, 1, 4]\n assert candidate(nums = ['123', '456', '789', '123', '456'],queries = [[1, 3], [2, 3], [3, 3], [4, 2], [5, 1]]) == [0, 3, 1, 4, 2]\n assert candidate(nums = ['00001', '00002', '00003', '00004', '00005', '00006', '00007', '00008', '00009', '00010'],queries = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == [9, 0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = ['112233', '223344', '334455', '445566', '556677'],queries = [[1, 3], [2, 6], [3, 2], [4, 4], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['123456789', '234567890', '345678901', '456789012', '567890123'],queries = [[1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [1, 1]]) == [0, 1, 2, 3, 4, 1]\n assert candidate(nums = ['11111', '22222', '33333', '44444', '55555'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['98765', '87654', '76543', '65432', '54321'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [4, 3, 2, 1, 0]\n assert candidate(nums = ['11111', '21111', '31111', '41111', '51111'],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['9999999999', '1234567890', '1111111111', '2222222222', '3333333333'],queries = [[1, 10], [2, 5], [3, 7], [4, 2], [5, 9]]) == [2, 3, 4, 1, 0]\n assert candidate(nums = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'],queries = [[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]]) == [0, 2, 8, 12, 2, 10, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = ['111111111', '222222222', '333333333', '444444444', '555555555'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [3, 9], [5, 9]]) == [0, 1, 2, 3, 4, 2, 4]\n assert candidate(nums = ['0000', '0001', '0010', '0100', '1000'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [0, 3, 1, 3, 4]\n assert candidate(nums = ['00011', '00101', '01001', '10001', '00110', '01100', '11000', '10100', '10010', '01010'],queries = [[1, 2], [3, 3], [5, 1], [7, 4], [9, 5], [2, 5], [4, 2], [6, 3], [8, 1], [10, 2]]) == [5, 3, 8, 6, 7, 1, 1, 0, 1, 0]\n assert candidate(nums = ['99999', '88888', '77777', '66666', '55555', '44444', '33333'],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [3, 5], [4, 4]]) == [6, 5, 4, 3, 2, 4, 3]\n assert candidate(nums = ['0011', '0101', '1001', '1100'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [1, 2]]) == [3, 1, 3, 3, 3]\n assert candidate(nums = ['0123456789', '1234567890', '2345678901', '3456789012', '4567890123'],queries = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['00001', '00011', '00111', '01111', '11111', '22222', '33333', '44444', '55555'],queries = [[1, 1], [5, 2], [9, 3], [4, 4], [3, 5], [8, 1], [2, 2]]) == [0, 4, 8, 3, 2, 7, 1]\n assert candidate(nums = ['12', '21', '11', '22', '12', '21'],queries = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [1, 2]]) == [1, 2, 5, 0, 3, 4, 2]\n assert candidate(nums = ['9990', '9909', '9099', '0999', '9999'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 1], [5, 2], [5, 3]]) == [0, 0, 0, 0, 4, 4, 4]\n assert candidate(nums = ['001100', '010101', '100100', '110011'],queries = [[1, 2], [2, 3], [3, 4], [4, 5], [1, 3], [2, 4], [3, 5], [4, 6]]) == [0, 0, 1, 1, 3, 2, 3, 3]\n assert candidate(nums = ['00111', '01010', '10001', '11100', '10110'],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == [0, 1, 2, 4, 3]\n assert candidate(nums = ['00123', '01234', '12345', '23456', '34567'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [2, 3], [3, 2]]) == [0, 1, 2, 3, 4, 1, 2]\n assert candidate(nums = ['12345', '23456', '34567', '45678', '56789'],queries = [[1, 1], [3, 2], [5, 3], [2, 4], [4, 5]]) == [0, 2, 4, 1, 3]\n assert candidate(nums = ['12345', '67890', '13579', '24680', '97531'],queries = [[1, 2], [3, 4], [5, 1], [2, 5], [4, 3]]) == [4, 3, 2, 2, 3]\n assert candidate(nums = ['1111111111', '2222222222', '3333333333', '4444444444', '5555555555', '6666666666', '7777777777', '8888888888', '9999999999'],queries = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]\n assert candidate(nums = ['50000', '05000', '00500', '00050'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [3, 5], [4, 5]]) == [0, 1, 3, 1, 1, 0]\n assert candidate(nums = ['9876543210', '0123456789', '1029384756', '2918074653', '3827165430'],queries = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [1, 1, 4, 3, 0]\n assert candidate(nums = ['123', '234', '345', '456', '567', '678', '789'],queries = [[1, 1], [2, 3], [4, 2], [5, 3], [7, 1]]) == [0, 1, 3, 4, 6]\n assert candidate(nums = ['999999', '888888', '777777', '666666', '555555'],queries = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2]]) == [4, 3, 2, 1, 0]\n assert candidate(nums = ['12345', '23456', '34567', '45678', '56789'],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5], [1, 1]]) == [0, 1, 2, 3, 4, 0]\n assert candidate(nums = ['00001', '00010', '00100', '01000', '10000'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [1, 3, 0, 2, 4]\n assert candidate(nums = ['0000000000', '0000000001', '0000000010', '0000000100', '0000001000', '0000010000', '0000100000', '0001000000', '0010000000', '0100000000'],queries = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [6, 5], [7, 4], [8, 3], [9, 2], [10, 1]]) == [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = ['110011001', '101010101', '010101010', '001100110', '100110011'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 3], [2, 3], [3, 5], [4, 5], [5, 1]]) == [2, 1, 4, 0, 0, 0, 2, 4, 1, 4]\n assert candidate(nums = ['98765', '87654', '76543', '65432'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [1, 2], [2, 3]]) == [3, 2, 1, 0, 3, 2]\n assert candidate(nums = ['0001', '0010', '0100', '1000'],queries = [[1, 1], [2, 2], [3, 3], [4, 4]]) == [1, 3, 1, 3]\n assert candidate(nums = ['99999', '99998', '99997', '99996', '99995'],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == [4, 3, 2, 1, 0]\n assert candidate(nums = ['1234', '5678', '9012', '3456'],queries = [[1, 1], [2, 4], [3, 3], [4, 2]]) == [2, 3, 3, 1]\n assert candidate(nums = ['001', '010', '100', '011', '101', '110'],queries = [[1, 1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3]]) == [1, 2, 4, 1, 4, 5]\n assert candidate(nums = ['11111', '22222', '33333', '44444'],queries = [[4, 5], [3, 4], [2, 3], [1, 2]]) == [3, 2, 1, 0]\n assert candidate(nums = ['9876543210', '8765432109', '7654321098', '6543210987', '5432109876'],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [4, 2, 0, 3, 1]\n assert candidate(nums = ['12345', '23456', '34567', '45678', '56789'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['9876543210', '0123456789', '1098765432', '2987654321', '3876543210'],queries = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]]) == [1, 2, 3, 4, 0]\n assert candidate(nums = ['0011', '0101', '0110', '1001', '1010', '1100'],queries = [[1, 1], [3, 2], [2, 2], [4, 3], [5, 1], [6, 3]]) == [2, 3, 1, 5, 1, 2]\n assert candidate(nums = ['00100', '01010', '10001', '01110', '11001'],queries = [[1, 5], [2, 3], [3, 2], [4, 4], [5, 1]]) == [0, 4, 4, 1, 4]\n assert candidate(nums = ['987654321', '876543219', '765432198', '654321987', '543219876'],queries = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [3, 9]]) == [0, 0, 0, 0, 0, 2]\n assert candidate(nums = ['11111', '22222', '33333', '44444', '55555'],queries = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == [0, 1, 2, 3, 4]\n assert candidate(nums = ['00111', '01110', '11100', '11001', '10011'],queries = [[1, 3], [2, 2], [3, 1], [4, 4], [5, 5]]) == [3, 3, 0, 2, 2]\n assert candidate(nums = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001'],queries = [[1, 4], [2, 3], [3, 2], [4, 1], [5, 4], [6, 3], [7, 2], [8, 1], [9, 4], [10, 3]]) == [0, 8, 8, 6, 4, 3, 2, 5, 8, 7]\n assert candidate(nums = ['00001', '00010', '00100', '01000', '10000'],queries = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [0, 0, 0, 0, 0]\n assert candidate(nums = ['00001', '00002', '00003', '00004', '00005'],queries = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2]]) == [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]\n", "comparison": "exact"}, "public_tests": ["[\"102\",\"473\",\"251\",\"814\"]\n[[1,1],[2,3],[4,2],[1,2]]", "[\"24\",\"37\",\"96\",\"04\"]\n[[2,1],[2,2]]"], "hints": ["Run a simulation to follow the requirement of each query."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().smallestTrimmedNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:26+00:00", "tests_total": 94, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "divide-and-conquer", "sorting", "heap-priority-queue", "radix-sort", "quickselect"]}, "language": "php", "interface": {"raw_signature": "function smallestTrimmedNumbers($nums, $queries) {", "container": "Solution", "callable": "smallestTrimmedNumbers", "parameters": [{"name": "nums", "type": "String[]"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2344, "task_id": "minimum-deletions-to-make-array-divisible", "difficulty": "Hard", "problem_description": "You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.\n\nReturn the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1.\n\nNote that an integer x divides y if y % x == 0.\n\nExample 1:\n\nInput: nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]\nOutput: 2\nExplanation:\nThe smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.\nWe use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].\nThe smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.\nIt can be shown that 2 is the minimum number of deletions needed.\n\nExample 2:\n\nInput: nums = [4,3,6], numsDivide = [8,2,6,10]\nOutput: -1\nExplanation:\nWe want the smallest element in nums to divide all the elements of numsDivide.\nThere is no way to delete elements from nums to allow this.\n\nConstraints:\n\n- 1 <= nums.length, numsDivide.length <= 10^5\n- 1 <= nums[i], numsDivide[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],numsDivide = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 10, 15, 20],numsDivide = [5, 15, 25, 35]) == 0\n assert candidate(nums = [1, 3, 5, 7],numsDivide = [2, 4, 6, 8]) == 0\n assert candidate(nums = [10, 20, 30],numsDivide = [5, 10, 15]) == -1\n assert candidate(nums = [5, 5, 5, 5],numsDivide = [5, 5, 5, 5]) == 0\n assert candidate(nums = [3, 5, 7, 9],numsDivide = [15, 30, 45, 60]) == 0\n assert candidate(nums = [2, 4, 6, 8],numsDivide = [2, 4, 6, 8]) == 0\n assert candidate(nums = [5, 10, 15, 20],numsDivide = [10, 20, 30, 40]) == 0\n assert candidate(nums = [5, 7, 10],numsDivide = [14, 35, 70]) == 1\n assert candidate(nums = [2, 4, 8, 16],numsDivide = [1, 2, 3, 4]) == -1\n assert candidate(nums = [3, 5, 6, 8, 9],numsDivide = [30, 45, 60]) == 0\n assert candidate(nums = [1, 2, 3, 4],numsDivide = [2, 4, 6, 8]) == 0\n assert candidate(nums = [4, 3, 6],numsDivide = [8, 2, 6, 10]) == -1\n assert candidate(nums = [3, 9, 7, 3],numsDivide = [9, 18, 90, 72]) == 0\n assert candidate(nums = [2, 3, 2, 4, 3],numsDivide = [9, 6, 9, 3, 15]) == 2\n assert candidate(nums = [1],numsDivide = [1]) == 0\n assert candidate(nums = [3, 6, 9, 12],numsDivide = [3, 6, 9, 12]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15],numsDivide = [27, 54, 81, 108]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],numsDivide = [20, 40, 60, 80, 100]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81],numsDivide = [162, 324, 486, 648]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84],numsDivide = [84, 168, 252]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [100, 200, 300]) == 0\n assert candidate(nums = [17, 34, 51, 68],numsDivide = [34, 68, 102, 136, 170]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],numsDivide = [15, 30, 45, 60, 75]) == 0\n assert candidate(nums = [8, 16, 32, 64, 128],numsDivide = [256, 512, 1024, 2048]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35],numsDivide = [49, 98, 147, 196]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19],numsDivide = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == -1\n assert candidate(nums = [4, 8, 12, 16, 20],numsDivide = [8, 16, 24, 32, 40, 48, 56]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45],numsDivide = [18, 36, 54, 72]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],numsDivide = [18, 36, 54, 72, 90]) == 0\n assert candidate(nums = [21, 42, 63, 84],numsDivide = [42, 84, 126, 168, 210]) == 0\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128],numsDivide = [256, 512, 1024, 2048]) == 0\n assert candidate(nums = [3, 9, 27, 81, 243],numsDivide = [81, 243, 729, 2187]) == 0\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40],numsDivide = [4, 8, 12, 16, 20]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12],numsDivide = [24, 48, 72, 96]) == 0\n assert candidate(nums = [3, 6, 9, 12],numsDivide = [18, 24, 30, 36, 42]) == 0\n assert candidate(nums = [13, 26, 39, 52],numsDivide = [260, 390, 520]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],numsDivide = [30, 45, 60, 75]) == -1\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64],numsDivide = [192, 384, 576, 768]) == 0\n assert candidate(nums = [12, 15, 18, 21],numsDivide = [36, 54, 72, 90]) == 2\n assert candidate(nums = [7, 11, 13, 17],numsDivide = [14, 22, 26, 34]) == -1\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13],numsDivide = [2, 3, 5, 7, 11, 13]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65],numsDivide = [260, 390, 520, 650]) == 0\n assert candidate(nums = [31, 37, 41, 43, 47],numsDivide = [93, 121, 143, 187]) == -1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],numsDivide = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35],numsDivide = [14, 28, 42, 56]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [66, 132, 198, 264]) == 0\n assert candidate(nums = [2, 5, 7, 10, 14],numsDivide = [4, 10, 14, 20]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65],numsDivide = [78, 156, 234, 312]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [100, 50, 25, 20]) == 0\n assert candidate(nums = [31, 62, 93, 124, 155],numsDivide = [186, 372, 558, 744]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],numsDivide = [1, 2, 3, 4, 5, 6, 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 = [101, 202, 303, 404],numsDivide = [202, 404, 606, 808, 1010]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [100, 200, 300, 400]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [220, 330, 440, 550]) == 0\n assert candidate(nums = [47, 94, 141, 188, 235],numsDivide = [282, 564, 846, 1128]) == 0\n assert candidate(nums = [29, 58, 87, 116, 145],numsDivide = [174, 348, 522, 696]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],numsDivide = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 0\n assert candidate(nums = [9, 18, 27, 36],numsDivide = [27, 54, 81, 108, 135]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15],numsDivide = [27, 54, 81, 108]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [22, 44, 66, 88]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65],numsDivide = [78, 156, 234, 312]) == 0\n assert candidate(nums = [3, 5, 7, 11, 13],numsDivide = [15, 21, 35, 77]) == -1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],numsDivide = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [18, 27, 36, 45, 54],numsDivide = [54, 108, 162, 216]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15],numsDivide = [18, 36, 54, 72]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],numsDivide = [60, 105, 140, 231]) == -1\n assert candidate(nums = [100, 200, 300, 400, 500],numsDivide = [1000, 2000, 3000, 4000]) == 0\n assert candidate(nums = [7, 14, 28, 35],numsDivide = [28, 56, 84, 112]) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000],numsDivide = [1000000000, 500000000, 250000000, 125000000]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],numsDivide = [12, 18, 24, 30, 36]) == 0\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909],numsDivide = [1010, 2020, 3030]) == 0\n assert candidate(nums = [17, 34, 51, 68, 85],numsDivide = [102, 204, 306, 408]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [50, 75, 100]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],numsDivide = [100, 200, 300, 400, 500]) == 0\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21],numsDivide = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == -1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104],numsDivide = [104, 208, 312]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],numsDivide = [12, 18, 24, 30]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11],numsDivide = [2310, 4620, 6930, 9240]) == 0\n assert candidate(nums = [7, 14, 21, 28],numsDivide = [42, 56, 70, 84]) == 0\n assert candidate(nums = [30, 40, 50, 60, 70],numsDivide = [300, 600, 900, 1200]) == 0\n assert candidate(nums = [18, 27, 36, 45],numsDivide = [162, 243, 324]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],numsDivide = [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 = [11, 22, 33, 44, 55, 66],numsDivide = [132, 264, 396]) == 0\n assert candidate(nums = [10, 15, 20, 25, 30],numsDivide = [100, 150, 200]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],numsDivide = [50, 100, 150, 200]) == 0\n assert candidate(nums = [12, 15, 20, 25, 30],numsDivide = [60, 90, 120, 150]) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42],numsDivide = [420, 840, 1260, 1680]) == 0\n assert candidate(nums = [7, 14, 28, 35, 42],numsDivide = [84, 168, 252, 336]) == 0\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31],numsDivide = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == -1\n assert candidate(nums = [23, 46, 69, 92, 115],numsDivide = [138, 207, 276, 345, 414]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],numsDivide = [25, 50, 75, 100]) == -1\n assert candidate(nums = [2, 3, 5, 7, 11, 13],numsDivide = [30030, 60060, 90090, 120120]) == 0\n assert candidate(nums = [12, 24, 36, 48],numsDivide = [60, 120, 180]) == 0\n assert candidate(nums = [43, 86, 129, 172, 215],numsDivide = [258, 387, 516, 645, 774]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35],numsDivide = [42, 56, 70, 84]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [220, 330, 440, 550, 660]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],numsDivide = [3, 5, 7, 9, 11]) == -1\n assert candidate(nums = [2, 2, 2, 2, 2],numsDivide = [4, 6, 8, 10]) == 0\n assert candidate(nums = [8, 16, 24, 32, 40],numsDivide = [40, 80, 120, 160]) == 0\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65],numsDivide = [165, 330, 495]) == 0\n assert candidate(nums = [43, 86, 129, 172, 215],numsDivide = [258, 516, 774, 1032]) == 0\n assert candidate(nums = [10, 15, 20, 25, 30],numsDivide = [150, 300, 450, 600, 750]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18],numsDivide = [180, 360, 540, 720, 900]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],numsDivide = [100, 200, 300, 400, 500]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19],numsDivide = [13, 17, 19, 29, 31]) == -1\n assert candidate(nums = [1001, 2002, 3003, 4004],numsDivide = [2002, 4004, 6006, 8008, 10010]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45],numsDivide = [108, 162, 216, 270, 324]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],numsDivide = [20, 40, 60, 80, 100]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65],numsDivide = [78, 130, 195, 260, 325]) == 0\n assert candidate(nums = [3, 6, 9, 12],numsDivide = [36, 72, 108]) == 0\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23],numsDivide = [2310, 4620, 6930, 9240]) == 0\n assert candidate(nums = [3, 9, 12, 18],numsDivide = [27, 54, 81, 108]) == 0\n assert candidate(nums = [5, 15, 25, 35, 45],numsDivide = [75, 150, 225, 300]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [50, 100, 150, 200]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [110, 220, 330, 440, 550]) == 0\n assert candidate(nums = [37, 74, 111, 148, 185],numsDivide = [238, 357, 476, 595, 714]) == -1\n assert candidate(nums = [31, 62, 93, 124, 155],numsDivide = [186, 279, 372, 465, 558]) == 0\n assert candidate(nums = [41, 82, 123, 164, 205],numsDivide = [246, 369, 492, 615, 738]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65, 78],numsDivide = [156, 195, 260, 390]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35],numsDivide = [49, 98, 147, 196]) == 0\n assert candidate(nums = [7, 14, 21, 28],numsDivide = [42, 56, 70]) == 0\n assert candidate(nums = [30, 60, 90, 120, 150, 180],numsDivide = [300, 600, 900, 1200]) == 0\n assert candidate(nums = [5, 15, 25, 35],numsDivide = [25, 50, 75, 100, 125]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],numsDivide = [150, 300, 450, 600]) == -1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],numsDivide = [14, 28, 42, 56, 70]) == 0\n assert candidate(nums = [13, 26, 39, 52],numsDivide = [26, 52, 78, 104, 130]) == 0\n assert candidate(nums = [17, 34, 51, 68, 85],numsDivide = [340, 680, 1020, 1360]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [50, 100, 150, 200]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42],numsDivide = [14, 28, 42, 56, 70]) == 0\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999],numsDivide = [1110, 2220, 3330]) == 0\n assert candidate(nums = [1, 2, 3, 5, 7, 11],numsDivide = [105, 165, 231]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63],numsDivide = [108, 162, 216, 270]) == 0\n assert candidate(nums = [13, 26, 39, 52, 65],numsDivide = [26, 52, 78, 104]) == 0\n assert candidate(nums = [11, 22, 33, 44, 55],numsDivide = [66, 77, 88, 99]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30],numsDivide = [60, 120, 180, 240]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25],numsDivide = [50, 100, 150, 200, 250]) == 0\n assert candidate(nums = [100, 200, 300, 400],numsDivide = [500, 1000, 1500]) == 0\n assert candidate(nums = [37, 74, 111, 148, 185],numsDivide = [222, 444, 666, 888]) == 0\n assert candidate(nums = [29, 58, 87, 116, 145],numsDivide = [174, 261, 348, 435, 522]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],numsDivide = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [8, 16, 24, 32, 40],numsDivide = [100, 200, 300, 400]) == -1\n assert candidate(nums = [23, 46, 69, 92, 115],numsDivide = [138, 276, 414, 552]) == 0\n assert candidate(nums = [19, 38, 57, 76, 95],numsDivide = [114, 190, 285, 380, 475]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],numsDivide = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == -1\n assert candidate(nums = [19, 38, 57, 76, 95],numsDivide = [114, 228, 342, 456]) == 0\n assert candidate(nums = [10, 15, 20, 25],numsDivide = [100, 200, 300]) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],numsDivide = [12, 24, 36, 48, 60]) == 0\n assert candidate(nums = [11, 22, 33, 44],numsDivide = [22, 44, 66, 88, 110]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],numsDivide = [24, 36, 48, 60]) == 0\n assert candidate(nums = [17, 23, 31, 37, 41, 43],numsDivide = [51, 68, 85]) == 0\n assert candidate(nums = [8, 16, 24, 32, 40],numsDivide = [16, 32, 48, 64, 80, 96]) == 0\n assert candidate(nums = [19, 38, 57, 76],numsDivide = [38, 76, 114, 152, 190]) == 0\n assert candidate(nums = [41, 82, 123, 164, 205],numsDivide = [246, 492, 738, 984]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1],numsDivide = [1]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35],numsDivide = [42, 56, 84, 98, 140]) == 0\n assert candidate(nums = [6, 12, 18, 24, 30],numsDivide = [12, 24, 36, 48, 60, 72]) == 0\n", "comparison": "exact"}, "public_tests": ["[2,3,2,4,3]\n[9,6,9,3,15]", "[4,3,6]\n[8,2,6,10]"], "hints": ["How can we find an integer x that divides all the elements of numsDivide?", "Will finding GCD (Greatest Common Divisor) help here?"], "metadata": {"canonical_parameter_names": ["nums", "numsDivide"], "leetcode_dataset_entry_point": "Solution().minOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:29+00:00", "tests_total": 158, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "sorting", "heap-priority-queue", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function minOperations($nums, $numsDivide) {", "container": "Solution", "callable": "minOperations", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "numsDivide", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2347, "task_id": "best-poker-hand", "difficulty": "Easy", "problem_description": "You are given an integer array ranks and a character array suits. You have 5 cards where the i^th card has a rank of ranks[i] and a suit of suits[i].\n\nThe following are the types of poker hands you can make from best to worst:\n\n1. \"Flush\": Five cards of the same suit.\n2. \"Three of a Kind\": Three cards of the same rank.\n3. \"Pair\": Two cards of the same rank.\n4. \"High Card\": Any single card.\n\nReturn a string representing the best type of poker hand you can make with the given cards.\n\nNote that the return values are case-sensitive.\n\nExample 1:\n\nInput: ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"]\nOutput: \"Flush\"\nExplanation: The hand with all the cards consists of 5 cards with the same suit, so we have a \"Flush\".\n\nExample 2:\n\nInput: ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"]\nOutput: \"Three of a Kind\"\nExplanation: The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a \"Three of a Kind\".\nNote that we could also make a \"Pair\" hand but \"Three of a Kind\" is a better hand.\nAlso note that other cards could be used to make the \"Three of a Kind\" hand.\n\nExample 3:\n\nInput: ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"]\nOutput: \"Pair\"\nExplanation: The hand with the first and second card consists of 2 cards with the same rank, so we have a \"Pair\".\nNote that we cannot make a \"Flush\" or a \"Three of a Kind\".\n\nConstraints:\n\n- ranks.length == suits.length == 5\n- 1 <= ranks[i] <= 13\n- 'a' <= suits[i] <= 'd'\n- No two cards have the same rank and suit.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(ranks = [7, 7, 7, 8, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Three of a Kind\"\n assert candidate(ranks = [10, 10, 2, 12, 9],suits = ['a', 'b', 'c', 'a', 'd']) == \"Pair\"\n assert candidate(ranks = [7, 7, 7, 7, 7],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'b', 'c', 'd', 'a']) == \"High Card\"\n assert candidate(ranks = [13, 2, 3, 1, 9],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [2, 3, 4, 5, 6],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [11, 11, 12, 12, 13],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [4, 4, 2, 4, 4],suits = ['d', 'a', 'a', 'b', 'c']) == \"Three of a Kind\"\n assert candidate(ranks = [10, 10, 11, 11, 12],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [6, 6, 6, 7, 7],suits = ['d', 'd', 'd', 'c', 'c']) == \"Three of a Kind\"\n assert candidate(ranks = [8, 8, 8, 9, 10],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [5, 6, 7, 8, 9],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [5, 5, 6, 6, 7],suits = ['a', 'b', 'a', 'b', 'a']) == \"Pair\"\n assert candidate(ranks = [6, 6, 7, 7, 8],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [1, 2, 3, 3, 3],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [4, 4, 5, 5, 6],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [9, 9, 9, 9, 9],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [1, 2, 3, 4, 4],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [8, 8, 9, 9, 10],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [10, 11, 12, 13, 13],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [6, 6, 6, 7, 8],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [10, 10, 10, 12, 13],suits = ['a', 'b', 'c', 'a', 'b']) == \"Three of a Kind\"\n assert candidate(ranks = [8, 8, 9, 9, 10],suits = ['a', 'a', 'b', 'b', 'c']) == \"Pair\"\n assert candidate(ranks = [3, 3, 3, 8, 8],suits = ['a', 'b', 'c', 'a', 'b']) == \"Three of a Kind\"\n assert candidate(ranks = [13, 13, 13, 13, 1],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [6, 6, 6, 7, 8],suits = ['a', 'a', 'a', 'b', 'c']) == \"Three of a Kind\"\n assert candidate(ranks = [1, 1, 2, 3, 4],suits = ['a', 'a', 'b', 'c', 'd']) == \"Pair\"\n assert candidate(ranks = [13, 13, 13, 13, 13],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [9, 9, 10, 11, 12],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [8, 8, 10, 10, 10],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [3, 3, 3, 4, 4],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [6, 6, 6, 6, 6],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [8, 8, 8, 9, 9],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [5, 5, 5, 5, 10],suits = ['a', 'a', 'a', 'a', 'b']) == \"Three of a Kind\"\n assert candidate(ranks = [7, 8, 9, 10, 11],suits = ['a', 'b', 'c', 'd', 'a']) == \"High Card\"\n assert candidate(ranks = [13, 12, 11, 10, 9],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [5, 5, 5, 6, 7],suits = ['a', 'b', 'c', 'a', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [6, 6, 6, 7, 8],suits = ['b', 'b', 'b', 'c', 'd']) == \"Three of a Kind\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'a', 'b', 'b', 'c']) == \"High Card\"\n assert candidate(ranks = [6, 6, 7, 7, 8],suits = ['a', 'a', 'b', 'b', 'c']) == \"Pair\"\n assert candidate(ranks = [2, 2, 2, 2, 2],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [13, 13, 2, 3, 4],suits = ['a', 'b', 'a', 'b', 'a']) == \"Pair\"\n assert candidate(ranks = [6, 6, 6, 6, 7],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [11, 11, 12, 12, 13],suits = ['a', 'a', 'b', 'b', 'c']) == \"Pair\"\n assert candidate(ranks = [10, 10, 11, 11, 12],suits = ['a', 'b', 'a', 'b', 'a']) == \"Pair\"\n assert candidate(ranks = [5, 6, 7, 8, 9],suits = ['a', 'b', 'c', 'd', 'a']) == \"High Card\"\n assert candidate(ranks = [8, 8, 8, 8, 2],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [1, 1, 2, 3, 4],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [2, 3, 4, 5, 6],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [5, 5, 5, 6, 7],suits = ['a', 'a', 'a', 'b', 'c']) == \"Three of a Kind\"\n assert candidate(ranks = [2, 2, 3, 4, 5],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [7, 8, 9, 10, 11],suits = ['a', 'b', 'c', 'd', 'a']) == \"High Card\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'b', 'c', 'd', 'a']) == \"High Card\"\n assert candidate(ranks = [9, 9, 10, 10, 11],suits = ['a', 'b', 'a', 'b', 'c']) == \"Pair\"\n assert candidate(ranks = [3, 3, 4, 4, 5],suits = ['a', 'a', 'b', 'b', 'c']) == \"Pair\"\n assert candidate(ranks = [9, 9, 9, 9, 10],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [7, 8, 9, 10, 11],suits = ['a', 'a', 'a', 'a', 'a']) == \"Flush\"\n assert candidate(ranks = [1, 1, 2, 2, 3],suits = ['a', 'b', 'c', 'd', 'a']) == \"Pair\"\n assert candidate(ranks = [9, 9, 9, 9, 9],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [2, 2, 2, 2, 3],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [13, 13, 13, 1, 1],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [5, 5, 10, 10, 10],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [3, 3, 5, 5, 7],suits = ['a', 'b', 'a', 'b', 'a']) == \"Pair\"\n assert candidate(ranks = [12, 12, 13, 13, 13],suits = ['a', 'b', 'c', 'd', 'a']) == \"Three of a Kind\"\n assert candidate(ranks = [1, 2, 3, 4, 5],suits = ['a', 'a', 'a', 'a', 'd']) == \"High Card\"\n", "comparison": "exact"}, "public_tests": ["[13,2,3,1,9]\n[\"a\",\"a\",\"a\",\"a\",\"a\"]", "[4,4,2,4,4]\n[\"d\",\"a\",\"a\",\"b\",\"c\"]", "[10,10,2,12,9]\n[\"a\",\"b\",\"c\",\"a\",\"d\"]"], "hints": ["Sequentially check the conditions 1 through 4, and return the outcome corresponding to the first met condition."], "metadata": {"canonical_parameter_names": ["ranks", "suits"], "leetcode_dataset_entry_point": "Solution().bestHand", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:33+00:00", "tests_total": 100, "tests_dropped": 33, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function bestHand($ranks, $suits) {", "container": "Solution", "callable": "bestHand", "parameters": [{"name": "ranks", "type": "Integer[]"}, {"name": "suits", "type": "String[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2348, "task_id": "number-of-zero-filled-subarrays", "difficulty": "Medium", "problem_description": "Given an integer array nums, return the number of subarrays filled with 0.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,0,0,2,0,0,4]\nOutput: 6\nExplanation:\nThere are 4 occurrences of [0] as a subarray.\nThere are 2 occurrences of [0,0] as a subarray.\nThere is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.\n\nExample 2:\n\nInput: nums = [0,0,0,2,0,0]\nOutput: 9\nExplanation:\nThere are 5 occurrences of [0] as a subarray.\nThere are 3 occurrences of [0,0] as a subarray.\nThere is 1 occurrence of [0,0,0] as a subarray.\nThere is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9.\n\nExample 3:\n\nInput: nums = [2,10,2019]\nOutput: 0\nExplanation: There is no subarray filled with 0. Therefore, we return 0.\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 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 45\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 2\n assert candidate(nums = [1, 0, 1, 0, 1]) == 2\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]) == 30\n assert candidate(nums = [1, 3, 0, 0, 2, 0, 0, 4]) == 6\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 1\n assert candidate(nums = [5, 0, 0, 0, 0, 0, 0, 5]) == 21\n assert candidate(nums = [5, 6, 7, 8, 9]) == 0\n assert candidate(nums = [0, 0, 0, 2, 0, 0]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 45\n assert candidate(nums = [2, 10, 2019]) == 0\n assert candidate(nums = [0]) == 1\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 3\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0]) == 4\n assert candidate(nums = [0, 0, 0, 0]) == 10\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0]) == 9\n assert candidate(nums = [5, 4, 3, 2, 1, 0]) == 1\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0]) == 4\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1]) == 3\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 0, 0]) == 8\n assert candidate(nums = [10, 20, 30, 0, 0, 0, 40, 50, 60, 0, 0, 70]) == 9\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0]) == 18\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7]) == 52\n assert candidate(nums = [1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0]) == 37\n assert candidate(nums = [999999999, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 190\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, 1]) == 300\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 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]) == 210\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0]) == 63\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]) == 175\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == 30\n assert candidate(nums = [1000000000, 0, 0, 0, -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]) == 502\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0]) == 45\n assert candidate(nums = [0, 0, 0, 1, 1, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0]) == 37\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 0, 0, 0]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14]) == 45\n assert candidate(nums = [100, 0, 0, 0, 0, 0, 200, 0, 0, 0, 300, 0, 0, 0, 400, 0, 0, 0, 500]) == 33\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, 0, 0, 1, 0, 0, 1]) == 39\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0]) == 50\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]) == 45\n assert candidate(nums = [10, 0, 0, 10, 0, 10, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0]) == 38\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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 2850\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 8\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == 6\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]) == 54\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]) == 1596\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 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, 0, 0]) == 1891\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]) == 22\n assert candidate(nums = [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]) == 780\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10, 0, 0, 0, 0]) == 76\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]) == 990\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, 1000000000]) == 325\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10]) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1275\n assert candidate(nums = [9, 0, 0, 8, 0, 0, 7, 0, 0, 6, 0, 0, 5, 0, 0, 4, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0]) == 25\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]) == 5\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]) == 13\n assert candidate(nums = [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]) == 171\n assert candidate(nums = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 4753\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 0, 4, 0, 0, 0, 5]) == 11\n assert candidate(nums = [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]) == 34\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == 5\n assert candidate(nums = [999999999, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -999999999]) == 190\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 10]) == 42\n assert candidate(nums = [1, 2, 3, 0, 0, 0, 4, 5, 0, 0, 6, 7, 0, 0, 0, 0, 8]) == 19\n assert candidate(nums = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5]) == 25\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 = [0, 1, 0, 1, 0, 1, 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 = [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]) == 300\n assert candidate(nums = [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0]) == 54\n assert candidate(nums = [0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0]) == 22\n assert candidate(nums = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 55\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 5]) == 60\n assert candidate(nums = [1, 2, 3, 4, 5, 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 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0]) == 84\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]) == 325\n assert candidate(nums = [9, 0, 0, 0, 0, 8, 0, 0, 7, 0, 0, 0, 6, 0, 5, 0, 0, 4, 0, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0]) == 36\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 106\n assert candidate(nums = [0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0]) == 12\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == 21\n assert candidate(nums = [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]) == 34\n assert candidate(nums = [1, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]) == 34\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0]) == 9\n assert candidate(nums = [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]) == 62\n assert candidate(nums = [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]) == 496\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000, 1000000000, 1000000000]) == 153\n assert candidate(nums = [1, 0, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 0, 5, 0, 0, 6, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9]) == 67\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 0, 0, 0, 0]) == 38\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]) == 595\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == 9\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 0, 0, 0, 2, 2, 2, 0, 0, 0, 3, 3, 3, 0, 0, 0]) == 24\n", "comparison": "exact"}, "public_tests": ["[1,3,0,0,2,0,0,4]", "[0,0,0,2,0,0]", "[2,10,2019]"], "hints": ["For each zero, you can calculate the number of zero-filled subarrays that end on that index, which is the number of consecutive zeros behind the current element + 1.", "Maintain the number of consecutive zeros behind the current element, count the number of zero-filled subarrays that end on each index, sum it up to get the answer."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().zeroFilledSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:36+00:00", "tests_total": 99, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math"]}, "language": "php", "interface": {"raw_signature": "function zeroFilledSubarray($nums) {", "container": "Solution", "callable": "zeroFilledSubarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2350, "task_id": "shortest-impossible-sequence-of-rolls", "difficulty": "Hard", "problem_description": "You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the i^th roll is rolls[i].\n\nReturn the length of the shortest sequence of rolls so that there's no such subsequence in rolls.\n\nA sequence of rolls of length len is the result of rolling a k sided dice len times.\n\nExample 1:\n\nInput: rolls = [4,2,1,2,3,3,2,4,1], k = 4\nOutput: 3\nExplanation: Every sequence of rolls of length 1, [1], [2], [3], [4], can be taken from rolls.\nEvery sequence of rolls of length 2, [1, 1], [1, 2], ..., [4, 4], can be taken from rolls.\nThe sequence [1, 4, 2] cannot be taken from rolls, so we return 3.\nNote that there are other sequences that cannot be taken from rolls.\n\nExample 2:\n\nInput: rolls = [1,1,2,2], k = 2\nOutput: 2\nExplanation: Every sequence of rolls of length 1, [1], [2], can be taken from rolls.\nThe sequence [2, 1] cannot be taken from rolls, so we return 2.\nNote that there are other sequences that cannot be taken from rolls but [2, 1] is the shortest.\n\nExample 3:\n\nInput: rolls = [1,1,3,2,2,2,3,3], k = 4\nOutput: 1\nExplanation: The sequence [4] cannot be taken from rolls, so we return 1.\nNote that there are other sequences that cannot be taken from rolls but [4] is the shortest.\n\nConstraints:\n\n- n == rolls.length\n- 1 <= n <= 10^5\n- 1 <= rolls[i] <= k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 2\n assert candidate(rolls = [1, 1, 1, 1, 1],k = 1) == 6\n assert candidate(rolls = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 4\n assert candidate(rolls = [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1],k = 6) == 3\n assert candidate(rolls = [1, 1, 3, 2, 2, 2, 3, 3],k = 4) == 1\n assert candidate(rolls = [1, 1, 2, 2],k = 2) == 2\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 11\n assert candidate(rolls = [1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 3\n assert candidate(rolls = [4, 2, 1, 2, 3, 3, 2, 4, 1],k = 4) == 3\n assert candidate(rolls = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 4\n assert candidate(rolls = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10) == 1\n assert candidate(rolls = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 1\n assert candidate(rolls = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 3\n assert candidate(rolls = [1],k = 1) == 2\n assert candidate(rolls = [5, 5, 5, 5, 5],k = 5) == 1\n assert candidate(rolls = [5, 4, 3, 2, 1],k = 5) == 2\n assert candidate(rolls = [1, 2, 3, 4, 5],k = 5) == 2\n assert candidate(rolls = [1, 3, 2, 3, 2, 1],k = 3) == 3\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 9\n assert candidate(rolls = [5, 1, 3, 4, 2, 5, 1, 3, 4, 2, 5, 1, 3, 4, 2],k = 5) == 4\n assert candidate(rolls = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 3, 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(rolls = [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 = 10) == 5\n assert candidate(rolls = [1, 2, 3, 4, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],k = 6) == 3\n assert candidate(rolls = [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 = 3) == 18\n assert candidate(rolls = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 100000) == 1\n assert candidate(rolls = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 2\n assert candidate(rolls = [1, 2, 3, 4, 4, 3, 2, 1, 1, 2, 3, 4, 4, 3, 2, 1],k = 4) == 5\n assert candidate(rolls = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 8\n assert candidate(rolls = [1, 2, 1, 3, 2, 1, 4, 2, 1, 3, 4, 2, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 1, 4, 2, 1, 3, 4, 2, 1, 3, 2, 4, 1, 3, 2, 4, 1, 3, 2, 1, 4, 2, 1, 3, 4, 2, 1, 3, 2, 4],k = 4) == 12\n assert candidate(rolls = [3, 1, 2, 1, 3, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 10\n assert candidate(rolls = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 5) == 5\n assert candidate(rolls = [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],k = 5) == 10\n assert candidate(rolls = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 3\n assert candidate(rolls = [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],k = 10) == 6\n assert candidate(rolls = [1, 2, 2, 1, 3, 1, 2, 3, 4, 2, 1, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],k = 6) == 3\n assert candidate(rolls = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],k = 4) == 2\n assert candidate(rolls = [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 = 10) == 5\n assert candidate(rolls = [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 = 10) == 3\n assert candidate(rolls = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 2\n assert candidate(rolls = [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) == 2\n assert candidate(rolls = [5, 5, 5, 5, 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(rolls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 3\n assert candidate(rolls = [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],k = 5) == 12\n assert candidate(rolls = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],k = 5) == 2\n assert candidate(rolls = [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],k = 10) == 8\n assert candidate(rolls = [1, 2, 3, 4, 5, 6, 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],k = 30) == 3\n assert candidate(rolls = [5, 3, 1, 4, 2, 5, 3, 1, 4, 2, 5, 3, 1, 4, 2],k = 5) == 4\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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) == 35\n assert candidate(rolls = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 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 = 5) == 5\n assert candidate(rolls = [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, 1],k = 15) == 3\n assert candidate(rolls = [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 = 10) == 4\n assert candidate(rolls = [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],k = 7) == 2\n assert candidate(rolls = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 6\n assert candidate(rolls = [1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4],k = 4) == 6\n assert candidate(rolls = [1],k = 100000) == 1\n assert candidate(rolls = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15) == 4\n assert candidate(rolls = [2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4],k = 4) == 11\n assert candidate(rolls = [5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4],k = 5) == 4\n assert candidate(rolls = [1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 3\n assert candidate(rolls = [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],k = 5) == 13\n assert candidate(rolls = [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 = 3) == 16\n assert candidate(rolls = [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, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],k = 10) == 4\n assert candidate(rolls = [1, 3, 2, 4, 2, 1, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],k = 4) == 6\n assert candidate(rolls = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == 11\n assert candidate(rolls = [7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1],k = 7) == 6\n assert candidate(rolls = [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 = 5) == 7\n assert candidate(rolls = [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) == 2\n assert candidate(rolls = [1, 3, 3, 1, 2, 4, 4, 2, 3, 1, 4, 2, 3, 1, 2, 4, 4, 2, 3, 1, 4, 2, 3, 1, 2, 4, 4, 2, 3, 1, 4, 2, 3, 1, 2, 4, 4, 2, 3, 1, 4, 2, 3, 1, 2, 4],k = 4) == 10\n assert candidate(rolls = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 1, 2, 2, 3, 3],k = 6) == 2\n assert candidate(rolls = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 5) == 5\n assert candidate(rolls = [1, 2, 2, 1, 3, 3, 1, 2, 3, 4, 4, 1, 2, 3, 4, 5, 5, 1, 2, 3, 4, 5, 6, 6, 1, 2, 3, 4, 5, 6, 7, 7],k = 7) == 2\n assert candidate(rolls = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 3\n assert candidate(rolls = [3, 1, 2, 4, 3, 1, 2, 4, 3, 1, 2, 4, 3, 1, 2, 4, 3, 1, 2, 4],k = 4) == 6\n assert candidate(rolls = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],k = 5) == 2\n assert candidate(rolls = [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, 6],k = 6) == 2\n assert candidate(rolls = [1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2],k = 5) == 4\n assert candidate(rolls = [7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7],k = 7) == 5\n assert candidate(rolls = [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) == 4\n assert candidate(rolls = [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(rolls = [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 = 20) == 3\n assert candidate(rolls = [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],k = 4) == 2\n assert candidate(rolls = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 16\n assert candidate(rolls = [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, 5, 4, 3, 2, 1],k = 5) == 12\n assert candidate(rolls = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6],k = 6) == 3\n assert candidate(rolls = [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 = 5) == 4\n assert candidate(rolls = [1, 2, 2, 1, 3, 3, 3, 1, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 6\n assert candidate(rolls = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],k = 5) == 4\n assert candidate(rolls = [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, 3, 2, 1, 3, 2, 1],k = 3) == 16\n assert candidate(rolls = [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],k = 4) == 9\n assert candidate(rolls = [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, 3, 4],k = 4) == 12\n assert candidate(rolls = [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 = 3) == 11\n assert candidate(rolls = [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) == 4\n assert candidate(rolls = [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],k = 4) == 2\n assert candidate(rolls = [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) == 10\n assert candidate(rolls = [5, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4],k = 5) == 5\n assert candidate(rolls = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],k = 5) == 4\n assert candidate(rolls = [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, 10],k = 20) == 2\n", "comparison": "exact"}, "public_tests": ["[4,2,1,2,3,3,2,4,1]\n4", "[1,1,2,2]\n2", "[1,1,3,2,2,2,3,3]\n4"], "hints": ["How can you find the minimum index such that all sequences of length 1 can be formed from the start until that index?", "Starting from the previous minimum index, what is the next index such that all sequences of length 2 can be formed?", "Can you extend the idea to sequences of length 3 and more?"], "metadata": {"canonical_parameter_names": ["rolls", "k"], "leetcode_dataset_entry_point": "Solution().shortestSequence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:38+00:00", "tests_total": 97, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "greedy"]}, "language": "php", "interface": {"raw_signature": "function shortestSequence($rolls, $k) {", "container": "Solution", "callable": "shortestSequence", "parameters": [{"name": "rolls", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2351, "task_id": "first-letter-to-appear-twice", "difficulty": "Easy", "problem_description": "Given a string s consisting of lowercase English letters, return the first letter to appear twice.\n\nNote:\n\n- A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.\n- s will contain at least one letter that appears twice.\n\nExample 1:\n\nInput: s = \"abccbaacz\"\nOutput: \"c\"\nExplanation:\nThe letter 'a' appears on the indexes 0, 5 and 6.\nThe letter 'b' appears on the indexes 1 and 4.\nThe letter 'c' appears on the indexes 2, 3 and 7.\nThe letter 'z' appears on the index 8.\nThe letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.\n\nExample 2:\n\nInput: s = \"abcdd\"\nOutput: \"d\"\nExplanation:\nThe only letter that appears twice is 'd' so we return 'd'.\n\nConstraints:\n\n- 2 <= s.length <= 100\n- s consists of lowercase English letters.\n- s has at least one repeated letter.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"alphabet\") == \"a\"\n assert candidate(s = \"finding\") == \"i\"\n assert candidate(s = \"xyzxyz\") == \"x\"\n assert candidate(s = \"zabcdefghijkkl\") == \"k\"\n assert candidate(s = \"first\") == None\n assert candidate(s = \"second\") == None\n assert candidate(s = \"abcdefghijkk\") == \"k\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaa\") == \"a\"\n assert candidate(s = \"abcdefggh\") == \"g\"\n assert candidate(s = \"mnopqrsstuvwxzyz\") == \"s\"\n assert candidate(s = \"abccbaacz\") == \"c\"\n assert candidate(s = \"interview\") == \"i\"\n assert candidate(s = \"abcdefgah\") == \"a\"\n assert candidate(s = \"abcdd\") == \"d\"\n assert candidate(s = \"aabb\") == \"a\"\n assert candidate(s = \"xyzabczy\") == \"z\"\n assert candidate(s = \"xyzxyzxyz\") == \"x\"\n assert candidate(s = \"example\") == \"e\"\n assert candidate(s = \"repeated\") == \"e\"\n assert candidate(s = \"occurrence\") == \"c\"\n assert candidate(s = \"aabbccddeeff\") == \"a\"\n assert candidate(s = \"aab\") == \"a\"\n assert candidate(s = \"hello\") == \"l\"\n assert candidate(s = \"aabbcc\") == \"a\"\n assert candidate(s = \"abcdabc\") == \"a\"\n assert candidate(s = \"characters\") == \"a\"\n assert candidate(s = \"programming\") == \"r\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabc\") == \"a\"\n assert candidate(s = \"abcdefghia\") == \"a\"\n assert candidate(s = \"abcdefghijkklmno\") == \"k\"\n assert candidate(s = \"onetimeonetimethisisaverylongstringwithsomerepeatedcharacters\") == \"e\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmq\") == \"q\"\n assert candidate(s = \"abcdefghijkabcdefghijklmnopqrstuvwxyz\") == \"a\"\n assert candidate(s = \"findingthebestsolution\") == \"i\"\n assert candidate(s = \"hellothereitisme\") == \"l\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"a\"\n assert candidate(s = \"thisisareallylongstringtofindtherepeatedcharacter\") == \"i\"\n assert candidate(s = \"abracadabra\") == \"a\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzz\") == \"z\"\n assert candidate(s = \"ababababababababababababababababab\") == \"a\"\n assert candidate(s = \"fasterthanlighttravels\") == \"t\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\") == \"a\"\n assert candidate(s = \"zzzzzzzzzz\") == \"z\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwxyzz\") == \"a\"\n assert candidate(s = \"xyzzzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxzyxzyzyxz\") == \"z\"\n assert candidate(s = \"characterscharacterscharacterszzzzzzz\") == \"a\"\n assert candidate(s = \"abababababababababababababababab\") == \"a\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\") == \"a\"\n assert candidate(s = \"thisisareallylongstringwithsomerepeatedcharacters\") == \"i\"\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydoggg\") == \"o\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab\") == \"a\"\n assert candidate(s = \"repeatedcharacters\") == \"e\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydogzzzzzzzzzzzzz\") == \"o\"\n assert candidate(s = \"abcdefghijklmnopqrstuuvwxyzz\") == \"u\"\n assert candidate(s = \"everyletterappearsatleasttwicemanytimes\") == \"e\"\n assert candidate(s = \"abcabcabcabcabcabcabc\") == \"a\"\n assert candidate(s = \"abcdefghijzabcdefghijzabcdefghijzabcdefghijzabcdefghijzabcdefghijz\") == \"a\"\n assert candidate(s = \"uniqueabcunique\") == \"u\"\n assert candidate(s = \"abcdefghijkmnopqrstuvwxyzabcde\") == \"a\"\n assert candidate(s = \"mnopqrstuzyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == \"u\"\n assert candidate(s = \"almostuniqueexceptfortheendzz\") == \"u\"\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == \"a\"\n assert candidate(s = \"alohafromhawaii\") == \"a\"\n assert candidate(s = \"supercalifragilisticexpialidociouszzzz\") == \"r\"\n assert candidate(s = \"vovelsaeiouaeiouaeiou\") == \"v\"\n assert candidate(s = \"abcdefghijkabcdefghijk\") == \"a\"\n assert candidate(s = \"manymanycharactersandcharacters\") == \"m\"\n assert candidate(s = \"thisisthesentencewithrepeatedwords\") == \"i\"\n assert candidate(s = \"charactersrepeatedoften\") == \"a\"\n assert candidate(s = \"sometextwithrepeatedlettersss\") == \"e\"\n assert candidate(s = \"abcdefghijklmnoab\") == \"a\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz\") == \"a\"\n assert candidate(s = \"abcdefghijkabcdefghijkabcdefghijk\") == \"a\"\n assert candidate(s = \"encyclopedia\") == \"c\"\n assert candidate(s = \"abcdefghijkllmnopqrstuvwxyz\") == \"l\"\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzzxyzzxyzz\") == \"z\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijklmno\") == \"m\"\n assert candidate(s = \"repeatedcharacterintheendzz\") == \"e\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"thelongestsubstringwithoutrepeatingcharactersxx\") == \"e\"\n assert candidate(s = \"abcdefghijabcdefghijabcdefghijabcde\") == \"a\"\n assert candidate(s = \"abababababababababab\") == \"a\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"abcxyzabcxyzabcxyzabcxyzabcxyzabcxyzabcxyza\") == \"a\"\n assert candidate(s = \"mnopqrswxyzaabcdefgijkhl\") == \"a\"\n assert candidate(s = \"mnopqrstuvwxyzaabcdefghijklmnopqrstuvwxyz\") == \"a\"\n assert candidate(s = \"abacabadabacaba\") == \"a\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"a\"\n assert candidate(s = \"overlappingcharactersababababababababa\") == \"p\"\n assert candidate(s = \"abcdexyzzyxwvutsrqponmlkjihgfe\") == \"z\"\n assert candidate(s = \"abcdefghijklaaabbbccc\") == \"a\"\n assert candidate(s = \"testingtestingtesting\") == \"t\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaz\") == \"z\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\") == \"q\"\n assert candidate(s = \"abcdefghijkllmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == \"l\"\n assert candidate(s = \"nestedcharactersandcharacters\") == \"e\"\n assert candidate(s = \"elevenletters\") == \"e\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"a\"\n assert candidate(s = \"tenletterstensletters\") == \"e\"\n assert candidate(s = \"uniquecharacterherea\") == \"u\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydogz\") == \"o\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n assert candidate(s = \"thequickbrownfoxjumpsoverthelazydog\") == \"o\"\n assert candidate(s = \"aaaabbbbccccdddd\") == \"a\"\n assert candidate(s = \"abcdexyzabc\") == \"a\"\n assert candidate(s = \"abcdefghef\") == \"e\"\n assert candidate(s = \"abcdefghijjklmnopqrstuvwxyz\") == \"j\"\n assert candidate(s = \"thisisaverylongstringwithseveralrepeatedcharacters\") == \"i\"\n assert candidate(s = \"singleletterrepeatedmanytimesaaaaaaaaaaa\") == \"l\"\n assert candidate(s = \"abcdefghijkla\") == \"a\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzba\") == \"b\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyx\") == \"z\"\n assert candidate(s = \"aabccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"a\"\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydog\") == \"o\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"a\"\n assert candidate(s = \"verylongstringwithrepeatedcharactersqrs\") == \"r\"\n assert candidate(s = \"repeatedcharacharactercharacter\") == \"e\"\n assert candidate(s = \"programmingproblemsarefun\") == \"r\"\n assert candidate(s = \"charactersrepeatedinrandomorderzzzzzzzzzz\") == \"a\"\n assert candidate(s = \"thisproblemhasmanylettersrepeated\") == \"h\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzabcdefghijklmnopqrstuvwxyz\") == \"z\"\n assert candidate(s = \"characterscharacterscharacterscharacters\") == \"a\"\n assert candidate(s = \"mississippi\") == \"s\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbac\") == \"c\"\n assert candidate(s = \"aaaaaaaaaaabbbbbbbbbbbccccccccccdddddddddd\") == \"a\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\") == \"z\"\n assert candidate(s = \"aaaaabbbbbccccc\") == \"a\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"z\"\n", "comparison": "exact"}, "public_tests": ["\"abccbaacz\"", "\"abcdd\""], "hints": ["Iterate through the string from left to right. Keep track of the elements you have already seen in a set.", "If the current element is already in the set, return that element."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().repeatedCharacter", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:40+00:00", "tests_total": 132, "tests_dropped": 3, "flags": [], "topic_tags": ["hash-table", "string", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function repeatedCharacter($s) {", "container": "Solution", "callable": "repeatedCharacter", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2352, "task_id": "equal-row-and-column-pairs", "difficulty": "Medium", "problem_description": "Given a 0-indexed n x n integer matrix grid, return the number of pairs (r_i, c_j) such that row r_i and column c_j are equal.\n\nA row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array).\n\nExample 1:\n\nInput: grid = [[3,2,1],[1,7,6],[2,7,7]]\nOutput: 1\nExplanation: There is 1 equal row and column pair:\n- (Row 2, Column 1): [2,7,7]\n\nExample 2:\n\nInput: grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]\nOutput: 3\nExplanation: There are 3 equal row and column pairs:\n- (Row 0, Column 0): [3,1,2,2]\n- (Row 2, Column 2): [2,4,2,2]\n- (Row 3, Column 2): [2,4,2,2]\n\nConstraints:\n\n- n == grid.length == grid[i].length\n- 1 <= n <= 200\n- 1 <= grid[i][j] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 9\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]]) == 9\n assert candidate(grid = [[5]]) == 1\n assert candidate(grid = [[3, 2, 1], [1, 7, 6], [2, 7, 7]]) == 1\n assert candidate(grid = [[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]) == 16\n assert candidate(grid = [[1, 2, 3], [3, 2, 1], [2, 1, 3]]) == 0\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 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 0\n assert candidate(grid = [[3, 1, 2, 2], [1, 4, 4, 5], [2, 4, 2, 2], [2, 4, 2, 2]]) == 3\n assert candidate(grid = [[10, 20, 30], [30, 20, 10], [20, 10, 30]]) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 1, 1, 1, 1, 1], [2, 3, 4, 5, 6, 7], [7, 6, 5, 4, 3, 2], [2, 2, 2, 2, 2, 2]]) == 0\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]]) == 36\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]]) == 49\n assert candidate(grid = [[10, 20, 30, 40], [40, 30, 20, 10], [10, 30, 50, 70], [70, 50, 30, 10]]) == 0\n assert candidate(grid = [[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]]) == 5\n assert candidate(grid = [[100000, 1, 2, 3], [1, 100000, 2, 3], [2, 1, 100000, 3], [3, 2, 1, 100000]]) == 1\n assert candidate(grid = [[7, 8, 9, 10], [10, 9, 8, 7], [7, 7, 7, 7], [1, 2, 3, 4]]) == 0\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]]) == 5\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]]) == 4\n assert candidate(grid = [[5, 1, 9, 1, 5], [1, 5, 1, 5, 1], [9, 1, 5, 1, 9], [1, 5, 1, 5, 1], [5, 1, 9, 1, 5]]) == 9\n assert candidate(grid = [[1, 2, 3, 4], [2, 1, 4, 3], [3, 4, 1, 2], [4, 3, 2, 1]]) == 4\n assert candidate(grid = [[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]) == 4\n assert candidate(grid = [[5, 6, 7, 8, 9], [9, 8, 7, 6, 5], [5, 5, 5, 5, 5], [1, 2, 3, 4, 5], [9, 7, 5, 3, 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, 1]]) == 25\n assert candidate(grid = [[7, 8, 9, 10], [8, 9, 10, 7], [9, 10, 7, 8], [10, 7, 8, 9]]) == 4\n assert candidate(grid = [[100, 101, 102, 103, 104, 105], [105, 104, 103, 102, 101, 100], [100, 102, 104, 106, 108, 110], [110, 108, 106, 104, 102, 100], [101, 103, 105, 107, 109, 111], [111, 109, 107, 105, 103, 101]]) == 0\n assert candidate(grid = [[1, 2, 1], [2, 1, 2], [1, 2, 1]]) == 5\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 1, 1, 1, 1], [2, 3, 4, 5, 6], [6, 5, 4, 3, 2]]) == 0\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], [1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4, 4, 4, 4], [5, 5, 5, 5, 5, 5, 5, 5, 5]]) == 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], [19, 17, 15, 13, 11, 9, 7, 5, 3, 1], [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]]) == 0\n assert candidate(grid = [[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]]) == 36\n assert candidate(grid = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]]) == 5\n assert candidate(grid = [[7, 8, 9], [9, 7, 8], [8, 9, 7]]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 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], [12, 11, 10, 9, 8, 7, 6, 5, 4, 3], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [13, 12, 11, 10, 9, 8, 7, 6, 5, 4], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]]) == 0\n assert candidate(grid = [[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]]) == 0\n assert candidate(grid = [[1, 1, 2, 2], [2, 2, 1, 1], [1, 2, 1, 2], [2, 1, 2, 1]]) == 2\n assert candidate(grid = [[1, 2, 1, 2], [2, 1, 2, 1], [1, 2, 1, 2], [2, 1, 2, 1]]) == 8\n assert candidate(grid = [[12345, 67890, 54321], [67890, 54321, 12345], [54321, 12345, 67890]]) == 3\n assert candidate(grid = [[11, 12, 13, 14], [15, 16, 17, 18], [19, 20, 21, 22], [14, 18, 22, 26]]) == 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]]) == 5\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]]) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 2, 1, 2, 1], [1, 3, 1, 3, 1], [1, 4, 1, 4, 1], [1, 5, 1, 5, 1]]) == 3\n assert candidate(grid = [[100, 200, 300, 400], [200, 300, 400, 500], [300, 400, 500, 600], [400, 500, 600, 700]]) == 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, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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\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]]) == 36\n assert candidate(grid = [[9, 8, 7, 6], [8, 7, 6, 5], [7, 6, 5, 4], [6, 5, 4, 3]]) == 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], [1, 2, 3, 4, 5]]) == 0\n assert candidate(grid = [[11, 22, 33, 44, 55, 66], [66, 55, 44, 33, 22, 11], [11, 11, 11, 11, 11, 11], [22, 33, 44, 55, 66, 77], [77, 66, 55, 44, 33, 22], [22, 22, 22, 22, 22, 22]]) == 0\n assert candidate(grid = [[5, 6, 7, 8, 9], [6, 7, 8, 9, 5], [7, 8, 9, 5, 6], [8, 9, 5, 6, 7], [9, 5, 6, 7, 8]]) == 5\n assert candidate(grid = [[11, 22, 33, 44, 55], [55, 44, 33, 22, 11], [11, 33, 55, 77, 99], [99, 77, 55, 33, 11], [22, 44, 66, 88, 100]]) == 0\n assert candidate(grid = [[4, 3, 2, 1], [1, 4, 3, 2], [2, 1, 4, 3], [3, 2, 1, 4]]) == 0\n assert candidate(grid = [[100, 200, 300, 400, 500], [500, 400, 300, 200, 100], [100, 300, 500, 700, 900], [900, 700, 500, 300, 100], [100, 100, 100, 100, 100]]) == 0\n assert candidate(grid = [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]]) == 8\n assert candidate(grid = [[1, 1, 2, 1], [1, 2, 1, 1], [2, 1, 1, 1], [1, 1, 1, 2]]) == 4\n assert candidate(grid = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == 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, 1, 1, 1, 1]]) == 0\n assert candidate(grid = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 3, 4, 1], [3, 4, 1, 2]]) == 0\n", "comparison": "exact"}, "public_tests": ["[[3,2,1],[1,7,6],[2,7,7]]", "[[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]"], "hints": ["We can use nested loops to compare every row against every column.", "Another loop is necessary to compare the row and column element by element.", "It is also possible to hash the arrays and compare the hashed values instead."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().equalPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:43+00:00", "tests_total": 64, "tests_dropped": 7, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function equalPairs($grid) {", "container": "Solution", "callable": "equalPairs", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2354, "task_id": "number-of-excellent-pairs", "difficulty": "Hard", "problem_description": "You are given a 0-indexed positive integer array nums and a positive integer k.\n\nA pair of numbers (num1, num2) is called excellent if the following conditions are satisfied:\n\n- Both the numbers num1 and num2 exist in the array nums.\n- The sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than or equal to k, where OR is the bitwise OR operation and AND is the bitwise AND operation.\n\nReturn the number of distinct excellent pairs.\n\nTwo pairs (a, b) and (c, d) are considered distinct if either a != c or b != d. For example, (1, 2) and (2, 1) are distinct.\n\nNote that a pair (num1, num2) such that num1 == num2 can also be excellent if you have at least one occurrence of num1 in the array.\n\nExample 1:\n\nInput: nums = [1,2,3,1], k = 3\nOutput: 5\nExplanation: The excellent pairs are the following:\n- (3, 3). (3 AND 3) and (3 OR 3) are both equal to (11) in binary. The total number of set bits is 2 + 2 = 4, which is greater than or equal to k = 3.\n- (2, 3) and (3, 2). (2 AND 3) is equal to (10) in binary, and (2 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\n- (1, 3) and (3, 1). (1 AND 3) is equal to (01) in binary, and (1 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\nSo the number of excellent pairs is 5.\n\nExample 2:\n\nInput: nums = [5,1,1], k = 10\nOutput: 0\nExplanation: There are no excellent pairs for this array.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= k <= 60\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [2, 4, 8, 16],k = 3) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 4) == 93\n assert candidate(nums = [1, 2, 4, 8, 16, 32],k = 3) == 0\n assert candidate(nums = [9, 10, 11, 12, 13, 14, 15],k = 7) == 7\n assert candidate(nums = [1, 1, 2, 3, 4],k = 2) == 16\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 9) == 72\n assert candidate(nums = [5, 1, 1],k = 10) == 0\n assert candidate(nums = [31, 14, 7, 3],k = 6) == 11\n assert candidate(nums = [1, 3, 5, 7],k = 4) == 11\n assert candidate(nums = [3, 1, 2, 5, 3, 4],k = 4) == 4\n assert candidate(nums = [7, 8, 9],k = 5) == 3\n assert candidate(nums = [1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [31, 14, 7, 1],k = 8) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 1],k = 3) == 5\n assert candidate(nums = [6, 5, 3, 1, 8, 7, 2, 4],k = 6) == 1\n assert candidate(nums = [7, 7, 7, 7],k = 5) == 1\n assert candidate(nums = [1023, 511, 255, 127],k = 10) == 16\n assert candidate(nums = [8, 8, 8, 8],k = 4) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1],k = 3) == 0\n assert candidate(nums = [7, 10, 4, 3, 15],k = 5) == 14\n assert candidate(nums = [31, 15, 7, 3, 1],k = 8) == 6\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 6) == 76\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 10) == 64\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 15) == 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],k = 5) == 348\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 10) == 25\n assert candidate(nums = [15, 8, 7, 3, 1, 1, 2, 2],k = 4) == 21\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],k = 10) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],k = 4) == 22\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 1) == 100\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 3) == 209\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5) == 200\n assert candidate(nums = [123456789, 987654321, 234567891, 198765432, 345678912, 456789123, 567891234, 678912345, 789123456, 891234567],k = 25) == 88\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383],k = 15) == 25\n assert candidate(nums = [1, 5, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385, 32769, 65537, 131073, 262145, 524289, 1048577, 2097153],k = 18) == 0\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023],k = 9) == 72\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 = 25) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907],k = 25) == 140\n assert candidate(nums = [5, 13, 15, 31, 7, 63],k = 8) == 19\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000],k = 10) == 36\n assert candidate(nums = [128, 256, 512, 1024, 2048, 4096],k = 7) == 0\n assert candidate(nums = [31, 14, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128],k = 7) == 7\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 20) == 100\n assert candidate(nums = [1023, 511, 255, 127, 63, 31],k = 10) == 36\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == 1\n assert candidate(nums = [29, 15, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 12\n assert candidate(nums = [5, 7, 15, 31, 63, 127, 255, 511, 1023, 2047],k = 15) == 36\n assert candidate(nums = [7, 11, 13, 17, 19, 23, 29, 31],k = 6) == 55\n assert candidate(nums = [100, 200, 300, 400, 500],k = 8) == 10\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 7) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 15) == 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 = 20) == 229\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 6) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],k = 10) == 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 = 4) == 44\n assert candidate(nums = [3, 7, 15, 31, 63],k = 5) == 24\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 9) == 72\n assert candidate(nums = [5, 7, 13, 17, 23, 29, 31, 37, 41, 43, 47, 53, 59],k = 8) == 73\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535],k = 18) == 120\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],k = 10) == 67\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8],k = 3) == 48\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 10) == 64\n assert candidate(nums = [3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047],k = 12) == 64\n assert candidate(nums = [7, 11, 13, 14, 15],k = 5) == 25\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191],k = 14) == 91\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],k = 8) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 5) == 219\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 1],k = 10) == 28\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 16\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 5) == 209\n assert candidate(nums = [29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29],k = 5) == 1\n assert candidate(nums = [999999937, 999999938, 999999939, 999999940, 999999941, 999999942, 999999943, 999999944, 999999945, 999999946],k = 40) == 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],k = 14) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64],k = 7) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517],k = 20) == 256\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64],k = 10) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 44\n assert candidate(nums = [2, 4, 8, 16, 32],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],k = 4) == 285\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 = 12) == 345\n assert candidate(nums = [29, 17, 23, 30, 14, 11, 13, 19, 21, 22],k = 6) == 87\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 10) == 0\n assert candidate(nums = [3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 25, 27, 30, 33, 34, 36, 40, 41, 42, 45, 48, 50, 51, 54, 57, 60, 62, 65, 66, 68, 72, 73, 74, 77, 80, 81, 82, 85, 88, 90, 93, 96, 98, 101, 102, 104, 105, 106, 108, 112, 113, 114, 117, 120, 122, 125, 126, 129, 130, 132, 135, 136, 138, 140, 141, 142, 144, 145, 146, 148, 150, 153, 154, 156, 159, 160, 162, 165, 168, 170, 171, 172, 174, 177, 180, 182, 185, 186, 188, 190, 192, 193, 194, 195, 196, 198, 200, 201, 204, 205, 208, 210, 213, 216, 218, 219, 220, 222, 224, 225, 226, 228, 230, 231, 232, 234, 237, 240, 242, 243, 244, 246, 248, 249, 250, 252, 255],k = 6) == 13945\n assert candidate(nums = [3, 5, 9, 17, 33, 65, 129, 257, 513],k = 7) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 7) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12],k = 5) == 24\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 12) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3],k = 1) == 1\n assert candidate(nums = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023],k = 15) == 1\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 2) == 100\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],k = 12) == 45\n assert candidate(nums = [3, 3, 3, 5, 5, 5, 7, 7, 7],k = 4) == 9\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 25) == 100\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767],k = 12) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],k = 5) == 636\n assert candidate(nums = [5, 3, 9, 7, 11],k = 4) == 25\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 16\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 = 22) == 0\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255],k = 10) == 28\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],k = 4) == 247\n assert candidate(nums = [98304, 49152, 24576, 12288, 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1, 1, 1, 1],k = 12) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 12) == 100\n assert candidate(nums = [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],k = 15) == 0\n assert candidate(nums = [8, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180],k = 4) == 239\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 = 8) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,3,1]\n3", "[5,1,1]\n10"], "hints": ["Can you find a different way to describe the second condition?", "The sum of the number of set bits in (num1 OR num2) and (num1 AND num2) is equal to the sum of the number of set bits in num1 and num2."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().countExcellentPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:45+00:00", "tests_total": 111, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function countExcellentPairs($nums, $k) {", "container": "Solution", "callable": "countExcellentPairs", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2357, "task_id": "make-array-zero-by-subtracting-equal-amounts", "difficulty": "Easy", "problem_description": "You are given a non-negative integer array nums. In one operation, you must:\n\n- Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.\n- Subtract x from every positive element in nums.\n\nReturn the minimum number of operations to make every element in nums equal to 0.\n\nExample 1:\n\nInput: nums = [1,5,0,3,5]\nOutput: 3\nExplanation:\nIn the first operation, choose x = 1. Now, nums = [0,4,0,2,4].\nIn the second operation, choose x = 2. Now, nums = [0,2,0,0,2].\nIn the third operation, choose x = 2. Now, nums = [0,0,0,0,0].\n\nExample 2:\n\nInput: nums = [0]\nOutput: 0\nExplanation: Each element in nums is already 0 so no operations are needed.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 0 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 0, 1, 0, 1]) == 1\n assert candidate(nums = [1, 5, 0, 3, 5]) == 3\n assert candidate(nums = [0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4]) == 4\n assert candidate(nums = [100, 0, 50, 50]) == 2\n assert candidate(nums = [100, 0, 50, 50, 0]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [99, 99, 99, 99, 99]) == 1\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == 1\n assert candidate(nums = [100, 100, 100, 100, 100]) == 1\n assert candidate(nums = [100, 0, 50, 25, 75]) == 4\n assert candidate(nums = [0, 0, 0, 0]) == 0\n assert candidate(nums = [2, 2, 2, 2]) == 1\n assert candidate(nums = [5, 5, 5, 0, 0, 5, 0]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [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]) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]) == 10\n assert candidate(nums = [50, 25, 12, 6, 3, 1, 0, 0, 0, 0]) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [7, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 7\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0]) == 10\n assert candidate(nums = [5, 0, 3, 3, 5, 0, 2]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 10, 20, 30, 40, 50, 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\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 = [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\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 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]) == 9\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 10\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, 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, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 15\n assert candidate(nums = [5, 10, 15, 20, 25]) == 5\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5]) == 10\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [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]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 5\n assert candidate(nums = [5, 3, 8, 6, 2, 0, 7]) == 6\n assert candidate(nums = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 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]) == 10\n assert candidate(nums = [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]) == 5\n assert candidate(nums = [5, 3, 2, 1, 4, 0, 2, 3]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0]) == 10\n assert candidate(nums = [42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0]) == 1\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 2\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93]) == 7\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 5\n assert candidate(nums = [5, 3, 2, 1, 4, 3, 5, 0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == 5\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 1\n assert candidate(nums = [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 5\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 1\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]) == 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 = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 3\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == 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\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == 5\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 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]) == 25\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]) == 10\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 15\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 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]) == 20\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 20\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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, 10, 10, 10]) == 10\n assert candidate(nums = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0, 10, 20, 30, 40, 50, 60, 70, 80]) == 10\n assert candidate(nums = [50, 25, 75, 50, 25, 75, 50, 25, 75, 50, 25, 75, 50, 25, 75]) == 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]) == 20\n assert candidate(nums = [0, 2, 3, 2, 1, 3, 4, 3, 2, 1]) == 4\n assert candidate(nums = [5, 1, 4, 2, 3, 1, 0, 2, 4, 3]) == 5\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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 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\n assert candidate(nums = [7, 14, 21, 28, 35, 42]) == 6\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 10, 20, 30]) == 5\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 4\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 0, 0]) == 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]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 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]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 3\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80]) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 0, 10, 20, 30, 40]) == 5\n", "comparison": "exact"}, "public_tests": ["[1,5,0,3,5]", "[0]"], "hints": ["It is always best to set x as the smallest non-zero element in nums.", "Elements with the same value will always take the same number of operations to become 0. Contrarily, elements with different values will always take a different number of operations to become 0.", "The answer is the number of unique non-zero numbers in nums."], "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-30T20:49:50+00:00", "tests_total": 116, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "sorting", "heap-priority-queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function minimumOperations($nums) {", "container": "Solution", "callable": "minimumOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2358, "task_id": "maximum-number-of-groups-entering-a-competition", "difficulty": "Medium", "problem_description": "You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions:\n\n- The sum of the grades of students in the i^th group is less than the sum of the grades of students in the (i + 1)^th group, for all groups (except the last).\n- The total number of students in the i^th group is less than the total number of students in the (i + 1)^th group, for all groups (except the last).\n\nReturn the maximum number of groups that can be formed.\n\nExample 1:\n\nInput: grades = [10,6,12,7,3,5]\nOutput: 3\nExplanation: The following is a possible way to form 3 groups of students:\n- 1^st group has the students with grades = [12]. Sum of grades: 12. Student count: 1\n- 2^nd group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2\n- 3^rd group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3\nIt can be shown that it is not possible to form more than 3 groups.\n\nExample 2:\n\nInput: grades = [8,8]\nOutput: 1\nExplanation: We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups.\n\nConstraints:\n\n- 1 <= grades.length <= 10^5\n- 1 <= grades[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grades = [10, 6, 12, 7, 3, 5]) == 3\n assert candidate(grades = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 4\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 4\n assert candidate(grades = [1]) == 1\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(grades = [100, 200, 300, 400, 500]) == 2\n assert candidate(grades = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 4\n assert candidate(grades = [1, 2]) == 1\n assert candidate(grades = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 4\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 5\n assert candidate(grades = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(grades = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 4\n assert candidate(grades = [8, 8]) == 1\n assert candidate(grades = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 4\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 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]) == 13\n assert candidate(grades = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 4\n assert candidate(grades = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 4\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 5\n assert candidate(grades = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 4\n assert candidate(grades = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 4\n assert candidate(grades = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 5\n assert candidate(grades = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 4\n assert candidate(grades = [9, 5, 1, 3, 7, 4, 2, 8, 6, 10]) == 4\n assert candidate(grades = [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]) == 6\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(grades = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(grades = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 6\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 4\n assert candidate(grades = [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, 99975, 99974, 99973, 99972, 99971, 99970, 99969, 99968, 99967, 99966, 99965, 99964, 99963, 99962, 99961, 99960, 99959, 99958, 99957, 99956, 99955, 99954, 99953, 99952, 99951, 99950, 99949, 99948, 99947, 99946, 99945, 99944, 99943, 99942, 99941, 99940, 99939, 99938, 99937, 99936, 99935, 99934, 99933, 99932, 99931, 99930, 99929, 99928, 99927, 99926, 99925, 99924, 99923, 99922, 99921, 99920, 99919, 99918, 99917, 99916, 99915, 99914, 99913, 99912, 99911, 99910, 99909, 99908, 99907, 99906, 99905, 99904, 99903, 99902, 99901]) == 13\n assert candidate(grades = [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\n assert candidate(grades = [1, 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(grades = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]) == 4\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 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]) == 8\n assert candidate(grades = [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]) == 8\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 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]) == 8\n assert candidate(grades = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 5\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(grades = [100000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(grades = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 5\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 5\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(grades = [5, 1, 4, 3, 2, 6, 7, 8, 9, 10]) == 4\n assert candidate(grades = [2, 1, 3, 1, 2, 3, 4, 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]) == 7\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(grades = [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]) == 9\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(grades = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 8\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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(grades = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]) == 5\n assert candidate(grades = [1, 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(grades = [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]) == 6\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 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(grades = [9, 3, 5, 7, 2, 8, 6, 4, 1, 10]) == 4\n assert candidate(grades = [30, 25, 20, 15, 10, 5, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 5\n assert candidate(grades = [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]) == 13\n assert candidate(grades = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(grades = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == 5\n assert candidate(grades = [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]) == 6\n assert candidate(grades = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 5\n assert candidate(grades = [1, 2, 3, 4, 5, 6, 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(grades = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 4\n assert candidate(grades = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215]) == 6\n assert candidate(grades = [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\n assert candidate(grades = [1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019]) == 5\n assert candidate(grades = [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]) == 8\n assert candidate(grades = [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]) == 9\n assert candidate(grades = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985, 99984, 99983, 99982, 99981]) == 5\n assert candidate(grades = [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]) == 7\n assert candidate(grades = [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]) == 6\n assert candidate(grades = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 5\n assert candidate(grades = [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]) == 9\n assert candidate(grades = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16, 21, 30, 22, 29, 23, 28, 24, 27, 25, 26]) == 7\n", "comparison": "exact"}, "public_tests": ["[10,6,12,7,3,5]", "[8,8]"], "hints": ["Would it be easier to place the students into valid groups after sorting them based on their grades in ascending order?", "Notice that, after sorting, we can separate them into groups of sizes 1, 2, 3, and so on.", "If the last group is invalid, we can merge it with the previous group.", "This creates the maximum number of groups because we always greedily form the smallest possible group."], "metadata": {"canonical_parameter_names": ["grades"], "leetcode_dataset_entry_point": "Solution().maximumGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:52+00:00", "tests_total": 84, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "binary-search", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maximumGroups($grades) {", "container": "Solution", "callable": "maximumGroups", "parameters": [{"name": "grades", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2359, "task_id": "find-closest-node-to-given-two-nodes", "difficulty": "Medium", "problem_description": "You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\n\nThe graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1.\n\nYou are also given two integers node1 and node2.\n\nReturn the index of the node that can be reached from both node1 and node2, such that the maximum between the distance from node1 to that node, and from node2 to that node is minimized. If there are multiple answers, return the node with the smallest index, and if no possible answer exists, return -1.\n\nNote that edges may contain cycles.\n\nExample 1:\n\nInput: edges = [2,2,3,-1], node1 = 0, node2 = 1\nOutput: 2\nExplanation: The distance from node 0 to node 2 is 1, and the distance from node 1 to node 2 is 1.\nThe maximum of those two distances is 1. It can be proven that we cannot get a node with a smaller maximum distance than 1, so we return node 2.\n\nExample 2:\n\nInput: edges = [1,2,-1], node1 = 0, node2 = 2\nOutput: 2\nExplanation: The distance from node 0 to node 2 is 2, and the distance from node 2 to itself is 0.\nThe maximum of those two distances is 2. It can be proven that we cannot get a node with a smaller maximum distance than 2, so we return node 2.\n\nConstraints:\n\n- n == edges.length\n- 2 <= n <= 10^5\n- -1 <= edges[i] < n\n- edges[i] != i\n- 0 <= node1, node2 < n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [5, -1, 3, 4, 5, 6, -1, -1, 4, 3],node1 = 0,node2 = 0) == 0\n assert candidate(edges = [4, 3, 0, 5, 3, -1],node1 = 4,node2 = 0) == 4\n assert candidate(edges = [1, 2, 0, -1],node1 = 0,node2 = 2) == 0\n assert candidate(edges = [4, 4, 4, 5, 1, 2, 2],node1 = 1,node2 = 1) == 1\n assert candidate(edges = [4, 4, 4, 5, 1, 2],node1 = 0,node2 = 1) == 4\n assert candidate(edges = [4, 4, 8, -1, 9, 8, 4, 4, 1, 1],node1 = 5,node2 = 6) == 1\n assert candidate(edges = [1, 2, 0, -1],node1 = 1,node2 = 2) == 2\n assert candidate(edges = [1, 2, 3, 4, -1],node1 = 0,node2 = 4) == 4\n assert candidate(edges = [2, 2, 3, -1],node1 = 0,node2 = 1) == 2\n assert candidate(edges = [1, 2, -1],node1 = 0,node2 = 2) == 2\n assert candidate(edges = [4, 3, 0, 5, 3, 9, 8, 5, 4, 6],node1 = 0,node2 = 8) == 4\n assert candidate(edges = [4, 4, 8, 5, 9, 8, 4, 4, 1, 1],node1 = 5,node2 = 6) == 1\n assert candidate(edges = [3, 0, 5, 5, 5, 3, 2, 0],node1 = 1,node2 = 7) == 0\n assert candidate(edges = [9, 8, 7, 6, 5, 4, 3, 2, 1, -1],node1 = 0,node2 = 8) == -1\n assert candidate(edges = [1, 2, 0, -1, -1, -1],node1 = 2,node2 = 3) == -1\n assert candidate(edges = [1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],node1 = 0,node2 = 10) == -1\n assert candidate(edges = [5, 3, 1, 5, 2, 3],node1 = 1,node2 = 0) == 3\n assert candidate(edges = [5, 5, 5, 5, 5, -1, -1, -1, -1, -1],node1 = 0,node2 = 5) == 5\n assert candidate(edges = [2, 2, 3, 4, 2, -1, -1, 1],node1 = 0,node2 = 6) == -1\n assert candidate(edges = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],node1 = 0,node2 = 9) == 0\n assert candidate(edges = [2, 0, 0, 2, 5, 4, 4],node1 = 3,node2 = 4) == -1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],node1 = 0,node2 = 5) == 0\n assert candidate(edges = [4, 3, 0, 5, 3, -1],node1 = 0,node2 = 4) == 4\n assert candidate(edges = [3, 3, 3, 4, 3, -1, -1, -1, -1, -1, 5, 6, 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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],node1 = 0,node2 = 40) == -1\n assert candidate(edges = [9, 8, 7, 6, 5, 4, 3, 2, 1, -1, 0],node1 = 5,node2 = 0) == -1\n assert candidate(edges = [4, 4, 8, -1, 9, 8, 4, 4, 1, 11, 4, 4, 4, 8, 11, 2, 10, 4, 10, 1],node1 = 0,node2 = 13) == 4\n assert candidate(edges = [6, 3, 4, 5, 5, 6, 7, 1, 0, -1],node1 = 0,node2 = 5) == 6\n assert candidate(edges = [1, 2, 0, 1, 3, 4, 2],node1 = 2,node2 = 5) == 1\n assert candidate(edges = [2, 0, 0, 2, 1, 4],node1 = 3,node2 = 5) == 0\n assert candidate(edges = [1, 2, 3, 4, 0, -1],node1 = 0,node2 = 5) == -1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1],node1 = 18,node2 = 19) == -1\n assert candidate(edges = [4, 4, 8, 5, 9, 8, 4, 4, 1, 4],node1 = 0,node2 = 7) == 4\n assert candidate(edges = [1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0],node1 = 0,node2 = 5) == 0\n assert candidate(edges = [3, 3, 0, -1, -1, 0],node1 = 1,node2 = 5) == 3\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10],node1 = 0,node2 = 19) == -1\n assert candidate(edges = [1, 2, 0, 5, 2, 1, 3, 4, 6, 7, -1],node1 = 8,node2 = 9) == 1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, -1],node1 = 19,node2 = 20) == -1\n assert candidate(edges = [4, 4, 4, 5, 1, 2, 2],node1 = 1,node2 = 0) == 4\n assert candidate(edges = [3, 4, 4, 5, 1, 6, 5, 5, 6, 8, 8, 1, 7, 9, 8, 8, 8, 8, 8, 8],node1 = 0,node2 = 10) == 5\n assert candidate(edges = [1, 2, 3, 4, 0],node1 = 1,node2 = 4) == 1\n assert candidate(edges = [3, 0, 5, 1, 3, 2, 4, 2, 2, -1],node1 = 1,node2 = 8) == -1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0],node1 = 0,node2 = 19) == 0\n assert candidate(edges = [2, -1, 3, 5, -1, 2],node1 = 0,node2 = 5) == 2\n assert candidate(edges = [4, 4, 4, 5, 1, 2],node1 = 0,node2 = 3) == 4\n assert candidate(edges = [2, 2, 0, 4, 1, 0, -1, -1, 0, 3],node1 = 6,node2 = 7) == -1\n assert candidate(edges = [4, 4, 4, 5, 1, 2, 2],node1 = 0,node2 = 3) == 4\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0],node1 = 0,node2 = 19) == 0\n assert candidate(edges = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],node1 = 0,node2 = 18) == -1\n assert candidate(edges = [1, 2, 3, 4, -1, -1, -1, -1, -1, -1],node1 = 0,node2 = 7) == -1\n assert candidate(edges = [5, 3, 4, 5, 3, 2, -1],node1 = 1,node2 = 4) == 3\n assert candidate(edges = [4, 4, 4, 5, 1, 2, 2],node1 = 1,node2 = 5) == 4\n assert candidate(edges = [1, 0, 0, 4, 1],node1 = 0,node2 = 3) == 1\n assert candidate(edges = [2, -1, 3, 1],node1 = 0,node2 = 2) == 2\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],node1 = 0,node2 = 9) == 0\n assert candidate(edges = [10, 15, 11, 14, 13, 12, 5, 15, 9, 12, 15, 9, 10, 11, 13, -1, 12, 14, 15, 8, 5],node1 = 0,node2 = 14) == 10\n assert candidate(edges = [5, 4, 0, 2, 3, 0, 2, 4, 0, 3, 2, 3, 2, 2, 3, 0, 2, 1, 0, 1],node1 = 0,node2 = 1) == 0\n assert candidate(edges = [3, 0, 5, 5, 2, 4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],node1 = 0,node2 = 18) == -1\n assert candidate(edges = [1, 0, 3, 2, 1, 4, 5, -1, -1, -1, 8, 9, 7, 10, 11, 12, 13, -1],node1 = 1,node2 = 7) == -1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1],node1 = 0,node2 = 10) == 10\n assert candidate(edges = [2, 2, 3, 4, 5, -1, 2, 6, 7, -1, -1],node1 = 0,node2 = 1) == 2\n assert candidate(edges = [2, 3, 3, 2],node1 = 0,node2 = 1) == 2\n assert candidate(edges = [5, 4, 0, 2, 3, 0, 2, 4, 0, 3, 2, 3, 2, 2, 3, -1, 2],node1 = 0,node2 = 2) == 0\n assert candidate(edges = [5, 3, 1, 4, 2, 6, 3, 2],node1 = 0,node2 = 5) == 5\n assert candidate(edges = [5, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, 13, -1, 14, -1, 15],node1 = 0,node2 = 15) == -1\n assert candidate(edges = [2, 2, 3, 4, 5, -1, -1, 5, 5, 5],node1 = 0,node2 = 9) == 5\n assert candidate(edges = [1, 2, 0, 1, 3, -1, -1, -1],node1 = 0,node2 = 1) == 1\n assert candidate(edges = [3, 3, 0, 5, -1, 2, 0, -1, -1, 3, 1],node1 = 3,node2 = 10) == 3\n", "comparison": "exact"}, "public_tests": ["[2,2,3,-1]\n0\n1", "[1,2,-1]\n0\n2"], "hints": ["How can you find the shortest distance from one node to all nodes in the graph?", "Use BFS to find the shortest distance from both node1 and node2 to all nodes in the graph. Then iterate over all nodes, and find the node with the minimum max distance."], "metadata": {"canonical_parameter_names": ["edges", "node1", "node2"], "leetcode_dataset_entry_point": "Solution().closestMeetingNode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:55+00:00", "tests_total": 101, "tests_dropped": 34, "flags": ["multiple_answers", "has_images"], "topic_tags": ["depth-first-search", "graph"]}, "language": "php", "interface": {"raw_signature": "function closestMeetingNode($edges, $node1, $node2) {", "container": "Solution", "callable": "closestMeetingNode", "parameters": [{"name": "edges", "type": "Integer[]"}, {"name": "node1", "type": "Integer"}, {"name": "node2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2360, "task_id": "longest-cycle-in-a-graph", "difficulty": "Hard", "problem_description": "You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\n\nThe graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1.\n\nReturn the length of the longest cycle in the graph. If no cycle exists, return -1.\n\nA cycle is a path that starts and ends at the same node.\n\nExample 1:\n\nInput: edges = [3,3,4,2,3]\nOutput: 3\nExplanation: The longest cycle in the graph is the cycle: 2 -> 4 -> 3 -> 2.\nThe length of this cycle is 3, so 3 is returned.\n\nExample 2:\n\nInput: edges = [2,-1,3,1]\nOutput: -1\nExplanation: There are no cycles in this graph.\n\nConstraints:\n\n- n == edges.length\n- 2 <= n <= 10^5\n- -1 <= edges[i] < n\n- edges[i] != i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [-1, 2, 0, 1, -1]) == -1\n assert candidate(edges = [1, 2, 0, 4, -1]) == 3\n assert candidate(edges = [5, 4, 5, 4, 5, 4]) == 2\n assert candidate(edges = [1, 0, -1, -1]) == 2\n assert candidate(edges = [1, 0, 0, 0, 1]) == 2\n assert candidate(edges = [1, 0, -1, -1, -1]) == 2\n assert candidate(edges = [2, -1, 1, -1, -1, -1, -1, -1, -1, -1]) == -1\n assert candidate(edges = [5, 4, 3, 2, 1, 0]) == 2\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 10\n assert candidate(edges = [1, 2, 0, 1, 3, -1]) == 3\n assert candidate(edges = [1, 2, 0, -1]) == 3\n assert candidate(edges = [1, 2, 3, 4, 0]) == 5\n assert candidate(edges = [3, 0, 1, 4, 2]) == 5\n assert candidate(edges = [-1, -1, -1, -1, -1]) == -1\n assert candidate(edges = [5, 4, 3, 2, 1, 0, -1, -1, -1, -1]) == 2\n assert candidate(edges = [3, 3, 4, 2, 3]) == 3\n assert candidate(edges = [2, -1, 3, 1]) == -1\n assert candidate(edges = [1, 0, 0, 0, 0]) == 2\n assert candidate(edges = [1, 2, 3, 4, 5, 0]) == 6\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11]) == 10\n assert candidate(edges = [1, 2, 0, 5, 6, 7, 8, 9, 3, 4]) == 7\n assert candidate(edges = [2, 3, 4, -1, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -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 = [5, 4, 0, 2, 0, 1, -1, 3]) == 4\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 10\n assert candidate(edges = [1, 2, 0, -1, 1, -1, -1, -1, -1, -1]) == 3\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 10]) == 10\n assert candidate(edges = [2, 2, 3, 2, 2]) == 2\n assert candidate(edges = [1, 0, 3, 2, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(edges = [3, 3, 3, 1, 2]) == 2\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 21, 22, 23, 24, 20]) == 10\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1]) == -1\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\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, 0]) == 41\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, 30]) == 10\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 0]) == 8\n assert candidate(edges = [7, 4, 5, 6, 3, 1, 2, 0]) == 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, 0]) == 31\n assert candidate(edges = [5, 4, 0, 2, 0, 1, 2, -1, -1, 10, 9]) == 4\n assert candidate(edges = [2, 3, 4, 5, 0, -1, -1, -1, -1, -1]) == 3\n assert candidate(edges = [3, 3, 4, 2, 3, -1, 5, 5, 6, 7, -1, 8, 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, 31, 32, -1, 33, 34, -1, 35, 36, -1, 37, 38, -1, 39, 40, -1, 41, 42, -1, 43, 44, -1, 45, 46, -1, 47, 48, -1, 49, 50, -1, 51, 52, -1, 53, 54, -1, 55, 56, -1, 57, 58, -1, 59, 60, -1, 61, 62, -1, 63, 64, -1, 65, 66, -1, 67, 68, -1, 69, 70, -1, 71, 72, -1, 73, 74, -1, 75, 76, -1, 77, 78, -1, 79, 80, -1, 81, 82, -1, 83, 84, -1, 85, 86, -1, 87, 88, -1, 89, 90, -1, 91, 92, -1, 93, 94, -1, 95, 96, -1, 97, 98, -1, 99, 100, -1]) == 3\n assert candidate(edges = [2, 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\n assert candidate(edges = [1, 2, 0, 4, 3]) == 3\n assert candidate(edges = [1, 3, 4, 2, 1, -1, -1, -1]) == 4\n assert candidate(edges = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, 1]) == 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, 0]) == 100\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0]) == 20\n assert candidate(edges = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == -1\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == 11\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]) == 16\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 1, 2, 3, 4]) == 21\n assert candidate(edges = [4, 4, 4, 4, 0]) == 2\n assert candidate(edges = [5, 4, 3, 2, 1, -1, -1, -1, -1, -1]) == 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, 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, 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, 0]) == 201\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\n assert candidate(edges = [9, 9, 9, 9, 9, 9, 9, 9, 9, 0]) == 2\n assert candidate(edges = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -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(edges = [3, 3, 4, 2, 3, 3, 4, 2, 3, 3]) == 3\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10]) == 10\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0]) == 15\n assert candidate(edges = [3, 2, 1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == 2\n assert candidate(edges = [5, 5, 5, 5, 5, -1, 5, 5, 5, 5]) == -1\n assert candidate(edges = [1, 2, 3, 4, 0, 6, 7, 8, 9, 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, 0]) == 30\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\n assert candidate(edges = [1, 2, 3, 4, 0, 6, 7, 8, 9, 5]) == 5\n assert candidate(edges = [5, 4, 0, 2, 0, 4, 2, 2, 0, 4]) == 3\n assert candidate(edges = [5, 4, 3, 2, 1, 0, 5, 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]) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0]) == 40\n assert candidate(edges = [-1, 3, -1, -1, 5, -1, 7, -1, 9, -1, 11, -1, 13, -1, 15, -1, 17, -1, 19, -1, 21, -1, 23, -1, 25, -1]) == -1\n assert candidate(edges = [4, 3, 0, 5, 3, -1, 2]) == -1\n", "comparison": "exact"}, "public_tests": ["[3,3,4,2,3]", "[2,-1,3,1]"], "hints": ["How many cycles can each node at most be part of?", "Each node can be part of at most one cycle. Start from each node and find the cycle that it is part of if there is any. Save the already visited nodes to not repeat visiting the same cycle multiple times."], "metadata": {"canonical_parameter_names": ["edges"], "leetcode_dataset_entry_point": "Solution().longestCycle", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:49:58+00:00", "tests_total": 109, "tests_dropped": 39, "flags": ["has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "graph", "topological-sort", "kosarajus-algorithm", "tarjans-scc-algorithm"]}, "language": "php", "interface": {"raw_signature": "function longestCycle($edges) {", "container": "Solution", "callable": "longestCycle", "parameters": [{"name": "edges", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2363, "task_id": "merge-similar-items", "difficulty": "Easy", "problem_description": "You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties:\n\n- items[i] = [value_i, weight_i] where value_i represents the value and weight_i represents the weight of the i^th item.\n- The value of each item in items is unique.\n\nReturn a 2D integer array ret where ret[i] = [value_i, weight_i], with weight_i being the sum of weights of all items with value value_i.\n\nNote: ret should be returned in ascending order by value.\n\nExample 1:\n\nInput: items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]\nOutput: [[1,6],[3,9],[4,5]]\nExplanation:\nThe item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6.\nThe item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9.\nThe item with value = 4 occurs in items1 with weight = 5, total weight = 5.\nTherefore, we return [[1,6],[3,9],[4,5]].\n\nExample 2:\n\nInput: items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]\nOutput: [[1,4],[2,4],[3,4]]\nExplanation:\nThe item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4.\nThe item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4.\nThe item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.\nTherefore, we return [[1,4],[2,4],[3,4]].\n\nExample 3:\n\nInput: items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]\nOutput: [[1,7],[2,4],[7,1]]\nExplanation:\nThe item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7.\nThe item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.\nThe item with value = 7 occurs in items2 with weight = 1, total weight = 1.\nTherefore, we return [[1,7],[2,4],[7,1]].\n\nConstraints:\n\n- 1 <= items1.length, items2.length <= 1000\n- items1[i].length == items2[i].length == 2\n- 1 <= value_i, weight_i <= 1000\n- Each value_i in items1 is unique.\n- Each value_i in items2 is unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(items1 = [[1, 3], [2, 2]],items2 = [[7, 1], [2, 2], [1, 4]]) == [(1, 7), (2, 4), (7, 1)]\n assert candidate(items1 = [[1, 1000]],items2 = [[2, 1000]]) == [(1, 1000), (2, 1000)]\n assert candidate(items1 = [[1, 1], [4, 5], [3, 8]],items2 = [[3, 1], [1, 5]]) == [(1, 6), (3, 9), (4, 5)]\n assert candidate(items1 = [[1000, 1]],items2 = [[999, 1000]]) == [(999, 1000), (1000, 1)]\n assert candidate(items1 = [[100, 100], [200, 200]],items2 = [[150, 150], [250, 250]]) == [(100, 100), (150, 150), (200, 200), (250, 250)]\n assert candidate(items1 = [[10, 10]],items2 = [[20, 20]]) == [(10, 10), (20, 20)]\n assert candidate(items1 = [[5, 5], [10, 10]],items2 = [[5, 5], [15, 15]]) == [(5, 10), (10, 10), (15, 15)]\n assert candidate(items1 = [[5, 5]],items2 = [[5, 5]]) == [(5, 10)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3]],items2 = [[4, 4], [5, 5], [6, 6]]) == [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]\n assert candidate(items1 = [[1, 1], [3, 2], [2, 3]],items2 = [[2, 1], [3, 2], [1, 3]]) == [(1, 4), (2, 4), (3, 4)]\n assert candidate(items1 = [[1, 100], [2, 200], [3, 300]],items2 = [[1, 100], [2, 200], [3, 300]]) == [(1, 200), (2, 400), (3, 600)]\n assert candidate(items1 = [[1, 500], [2, 400], [3, 300], [4, 200], [5, 100]],items2 = [[6, 100], [7, 200], [8, 300], [9, 400], [10, 500]]) == [(1, 500), (2, 400), (3, 300), (4, 200), (5, 100), (6, 100), (7, 200), (8, 300), (9, 400), (10, 500)]\n assert candidate(items1 = [[500, 500], [1, 1], [100, 100]],items2 = [[500, 500], [1, 1], [100, 100], [200, 200], [300, 300], [400, 400]]) == [(1, 2), (100, 200), (200, 200), (300, 300), (400, 400), (500, 1000)]\n assert candidate(items1 = [[1, 999], [2, 998], [3, 997], [4, 996], [5, 995]],items2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 1000), (5, 1000)]\n assert candidate(items1 = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],items2 = [[50, 5], [150, 4], [250, 3], [350, 2], [450, 1]]) == [(50, 5), (100, 1), (150, 4), (200, 2), (250, 3), (300, 3), (350, 2), (400, 4), (450, 1), (500, 5)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4]],items2 = [[2, 4], [3, 6], [5, 8], [6, 10]]) == [(1, 1), (2, 6), (3, 9), (4, 4), (5, 8), (6, 10)]\n assert candidate(items1 = [[999, 1], [998, 2], [997, 3]],items2 = [[996, 4], [995, 5], [994, 6], [993, 7], [992, 8], [991, 9], [990, 10]]) == [(990, 10), (991, 9), (992, 8), (993, 7), (994, 6), (995, 5), (996, 4), (997, 3), (998, 2), (999, 1)]\n assert candidate(items1 = [[10, 1], [20, 1], [30, 1], [40, 1], [50, 1]],items2 = [[10, 99], [20, 98], [30, 97], [40, 96], [50, 95]]) == [(10, 100), (20, 99), (30, 98), (40, 97), (50, 96)]\n assert candidate(items1 = [[1, 10], [2, 20], [5, 50], [10, 100]],items2 = [[1, 5], [3, 30], [4, 40], [6, 60], [7, 70]]) == [(1, 15), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60), (7, 70), (10, 100)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4]],items2 = [[2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 1), (2, 4), (3, 6), (4, 8), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]\n assert candidate(items1 = [[1, 1], [10, 10], [100, 100]],items2 = [[1, 99], [10, 90], [100, 900], [1000, 1000]]) == [(1, 100), (10, 100), (100, 1000), (1000, 1000)]\n assert candidate(items1 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],items2 = [[3, 30], [4, 40], [5, 50], [6, 60], [7, 70]]) == [(1, 10), (2, 20), (3, 60), (4, 80), (5, 100), (6, 60), (7, 70)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],items2 = [[10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19]]) == [(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(items1 = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45]],items2 = [[5, 45], [15, 35], [25, 25], [35, 15], [45, 5]]) == [(5, 50), (15, 50), (25, 50), (35, 50), (45, 50)]\n assert candidate(items1 = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],items2 = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55]]) == [(5, 5), (10, 1), (15, 15), (20, 2), (25, 25), (30, 3), (35, 35), (40, 4), (45, 45), (50, 5), (55, 55)]\n assert candidate(items1 = [[500, 100], [300, 200]],items2 = [[200, 300], [100, 400], [500, 600]]) == [(100, 400), (200, 300), (300, 200), (500, 700)]\n assert candidate(items1 = [[5, 1], [15, 2], [25, 3], [35, 4], [45, 5]],items2 = [[5, 5], [15, 4], [25, 3], [35, 2], [45, 1]]) == [(5, 6), (15, 6), (25, 6), (35, 6), (45, 6)]\n assert candidate(items1 = [[1, 10], [2, 20], [3, 30]],items2 = [[4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90]]) == [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60), (7, 70), (8, 80), (9, 90)]\n assert candidate(items1 = [[100, 100], [200, 200], [300, 300]],items2 = [[150, 150], [250, 250], [350, 350], [450, 450]]) == [(100, 100), (150, 150), (200, 200), (250, 250), (300, 300), (350, 350), (450, 450)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],items2 = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10)]\n assert candidate(items1 = [[1, 1000], [2, 1000], [3, 1000]],items2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1001), (2, 1002), (3, 1003), (4, 4), (5, 5)]\n assert candidate(items1 = [[1, 1000], [2, 999], [3, 998], [4, 997]],items2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == [(1, 1001), (2, 1001), (3, 1001), (4, 1001), (5, 5)]\n assert candidate(items1 = [[5, 5], [10, 10], [15, 15], [20, 20]],items2 = [[5, 5], [10, 10], [25, 25], [30, 30]]) == [(5, 10), (10, 20), (15, 15), (20, 20), (25, 25), (30, 30)]\n assert candidate(items1 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],items2 = [[6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60), (7, 70), (8, 80), (9, 90), (10, 100)]\n assert candidate(items1 = [[500, 5000], [1000, 10000]],items2 = [[250, 2500], [750, 7500]]) == [(250, 2500), (500, 5000), (750, 7500), (1000, 10000)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],items2 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == [(1, 11), (2, 22), (3, 33), (4, 44), (5, 55), (6, 66), (7, 77), (8, 88), (9, 99), (10, 110)]\n assert candidate(items1 = [[100, 1], [200, 2], [300, 3], [400, 4]],items2 = [[50, 5], [150, 15], [250, 25], [350, 35], [450, 45]]) == [(50, 5), (100, 1), (150, 15), (200, 2), (250, 25), (300, 3), (350, 35), (400, 4), (450, 45)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],items2 = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]]) == [(10, 11), (20, 22), (30, 33), (40, 44), (50, 55), (60, 66), (70, 77), (80, 88), (90, 99), (100, 110)]\n assert candidate(items1 = [[10, 15], [20, 25], [30, 35], [40, 45]],items2 = [[10, 5], [20, 15], [50, 55]]) == [(10, 20), (20, 40), (30, 35), (40, 45), (50, 55)]\n assert candidate(items1 = [[1, 10], [2, 20], [3, 30]],items2 = [[4, 40], [5, 50], [6, 60], [7, 70], [8, 80]]) == [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60), (7, 70), (8, 80)]\n assert candidate(items1 = [[5, 10], [15, 20], [25, 30], [35, 40]],items2 = [[10, 5], [15, 15], [25, 25], [40, 45]]) == [(5, 10), (10, 5), (15, 35), (25, 55), (35, 40), (40, 45)]\n assert candidate(items1 = [[1000, 1]],items2 = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992]]) == [(1, 1000), (2, 999), (3, 998), (4, 997), (5, 996), (6, 995), (7, 994), (8, 993), (9, 992), (1000, 1)]\n assert candidate(items1 = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5]],items2 = [[100, 5], [200, 4], [300, 3], [400, 2], [500, 1]]) == [(100, 6), (200, 6), (300, 6), (400, 6), (500, 6)]\n assert candidate(items1 = [[999, 1], [998, 2], [997, 3], [996, 4], [995, 5]],items2 = [[994, 6], [993, 7], [992, 8], [991, 9], [990, 10]]) == [(990, 10), (991, 9), (992, 8), (993, 7), (994, 6), (995, 5), (996, 4), (997, 3), (998, 2), (999, 1)]\n assert candidate(items1 = [[999, 1], [998, 2], [997, 3]],items2 = [[996, 4], [995, 5], [994, 6], [993, 7], [992, 8]]) == [(992, 8), (993, 7), (994, 6), (995, 5), (996, 4), (997, 3), (998, 2), (999, 1)]\n assert candidate(items1 = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]],items2 = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5]]) == [(5, 6), (10, 12), (15, 18), (20, 24), (25, 30)]\n assert candidate(items1 = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5]],items2 = [[10, 5], [20, 4], [30, 3], [40, 2], [50, 1]]) == [(10, 6), (20, 6), (30, 6), (40, 6), (50, 6)]\n assert candidate(items1 = [[100, 1000], [200, 2000]],items2 = [[101, 1001], [201, 2001], [100, 1000]]) == [(100, 2000), (101, 1001), (200, 2000), (201, 2001)]\n assert candidate(items1 = [[1, 1000], [2, 999], [3, 998]],items2 = [[2, 1], [3, 2], [4, 3], [5, 4], [6, 5]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 3), (5, 4), (6, 5)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60]],items2 = [[15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65]]) == [(10, 10), (15, 15), (20, 20), (25, 25), (30, 30), (35, 35), (40, 40), (45, 45), (50, 50), (55, 55), (60, 60), (65, 65)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],items2 = [[5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]],items2 = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1]]) == [(1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100]],items2 = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]]) == [(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)]\n assert candidate(items1 = [[10, 50], [20, 100], [30, 150], [40, 200]],items2 = [[10, 50], [20, 50], [30, 50], [50, 250]]) == [(10, 100), (20, 150), (30, 200), (40, 200), (50, 250)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],items2 = [[15, 15], [25, 25], [35, 35], [45, 45], [55, 55]]) == [(10, 10), (15, 15), (20, 20), (25, 25), (30, 30), (35, 35), (40, 40), (45, 45), (50, 50), (55, 55)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],items2 = [[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(items1 = [[2, 200], [4, 400], [6, 600], [8, 800]],items2 = [[1, 100], [3, 300], [5, 500], [7, 700], [9, 900]]) == [(1, 100), (2, 200), (3, 300), (4, 400), (5, 500), (6, 600), (7, 700), (8, 800), (9, 900)]\n assert candidate(items1 = [[1, 1000], [3, 1000], [5, 1000], [7, 1000], [9, 1000]],items2 = [[2, 1000], [4, 1000], [6, 1000], [8, 1000], [10, 1000]]) == [(1, 1000), (2, 1000), (3, 1000), (4, 1000), (5, 1000), (6, 1000), (7, 1000), (8, 1000), (9, 1000), (10, 1000)]\n assert candidate(items1 = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],items2 = [[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(items1 = [[1, 999]],items2 = [[1, 1]]) == [(1, 1000)]\n assert candidate(items1 = [[100, 1000], [200, 2000], [300, 3000]],items2 = [[50, 500], [150, 1500], [250, 2500], [350, 3500]]) == [(50, 500), (100, 1000), (150, 1500), (200, 2000), (250, 2500), (300, 3000), (350, 3500)]\n assert candidate(items1 = [[10, 5], [20, 15], [30, 25]],items2 = [[5, 5], [15, 10], [25, 15], [35, 20]]) == [(5, 5), (10, 5), (15, 10), (20, 15), (25, 15), (30, 25), (35, 20)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70]],items2 = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75]]) == [(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)]\n assert candidate(items1 = [[100, 100], [200, 200], [300, 300]],items2 = [[100, 50], [200, 150], [300, 250], [400, 350], [500, 450]]) == [(100, 150), (200, 350), (300, 550), (400, 350), (500, 450)]\n assert candidate(items1 = [[1, 100], [2, 200], [3, 300], [4, 400]],items2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 101), (2, 202), (3, 303), (4, 404), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]\n assert candidate(items1 = [[1, 1000], [500, 1], [1000, 1000]],items2 = [[1, 1], [500, 1000], [1000, 1]]) == [(1, 1001), (500, 1001), (1000, 1001)]\n assert candidate(items1 = [[10, 50], [20, 100], [30, 150]],items2 = [[5, 25], [10, 75], [40, 200]]) == [(5, 25), (10, 125), (20, 100), (30, 150), (40, 200)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30]],items2 = [[11, 11], [21, 21], [31, 31], [10, 9], [20, 18], [30, 27]]) == [(10, 19), (11, 11), (20, 38), (21, 21), (30, 57), (31, 31)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]],items2 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == [(1, 11), (2, 22), (3, 33), (4, 44), (5, 55), (6, 66), (7, 77), (8, 88), (9, 99), (10, 110)]\n assert candidate(items1 = [[10, 100], [20, 200], [30, 300], [40, 400]],items2 = [[5, 50], [10, 150], [25, 250], [30, 350]]) == [(5, 50), (10, 250), (20, 200), (25, 250), (30, 650), (40, 400)]\n assert candidate(items1 = [[100, 10], [200, 20], [300, 30], [400, 40], [500, 50]],items2 = [[50, 5], [150, 15], [250, 25], [350, 35], [450, 45], [550, 55]]) == [(50, 5), (100, 10), (150, 15), (200, 20), (250, 25), (300, 30), (350, 35), (400, 40), (450, 45), (500, 50), (550, 55)]\n assert candidate(items1 = [[100, 100], [200, 200], [300, 300], [400, 400], [500, 500], [600, 600], [700, 700], [800, 800], [900, 900]],items2 = [[100, 1], [200, 2], [300, 3], [400, 4], [500, 5], [600, 6], [700, 7], [800, 8], [900, 9]]) == [(100, 101), (200, 202), (300, 303), (400, 404), (500, 505), (600, 606), (700, 707), (800, 808), (900, 909)]\n assert candidate(items1 = [[10, 100], [20, 200], [30, 300]],items2 = [[15, 150], [25, 250], [35, 350], [45, 450], [55, 550]]) == [(10, 100), (15, 150), (20, 200), (25, 250), (30, 300), (35, 350), (45, 450), (55, 550)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]],items2 = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]) == [(1, 6), (2, 6), (3, 6), (4, 6), (5, 6)]\n assert candidate(items1 = [[1, 100], [10, 100], [100, 100], [1000, 100]],items2 = [[2, 200], [20, 200], [200, 200], [2000, 200]]) == [(1, 100), (2, 200), (10, 100), (20, 200), (100, 100), (200, 200), (1000, 100), (2000, 200)]\n assert candidate(items1 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],items2 = [[1, 5], [2, 10], [3, 15], [4, 20], [5, 25]]) == [(1, 15), (2, 30), (3, 45), (4, 60), (5, 75)]\n assert candidate(items1 = [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]],items2 = [[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(items1 = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]],items2 = [[1, 5], [2, 10], [3, 15], [4, 20], [5, 25]]) == [(1, 15), (2, 30), (3, 45), (4, 60), (5, 75)]\n assert candidate(items1 = [[1, 1000], [2, 999], [3, 998], [4, 997]],items2 = [[5, 996], [6, 995], [7, 994], [8, 993]]) == [(1, 1000), (2, 999), (3, 998), (4, 997), (5, 996), (6, 995), (7, 994), (8, 993)]\n assert candidate(items1 = [[999, 1], [998, 2], [997, 3]],items2 = [[996, 4], [995, 5], [997, 6]]) == [(995, 5), (996, 4), (997, 9), (998, 2), (999, 1)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30]],items2 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]]) == [(10, 20), (20, 40), (30, 60), (40, 40), (50, 50)]\n assert candidate(items1 = [[100, 1], [200, 2], [300, 3], [400, 4]],items2 = [[50, 5], [150, 6], [250, 7], [350, 8], [450, 9]]) == [(50, 5), (100, 1), (150, 6), (200, 2), (250, 7), (300, 3), (350, 8), (400, 4), (450, 9)]\n assert candidate(items1 = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50]],items2 = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45]]) == [(5, 5), (10, 10), (15, 15), (20, 20), (25, 25), (30, 30), (35, 35), (40, 40), (45, 45), (50, 50)]\n assert candidate(items1 = [[100, 1], [200, 1], [300, 1], [400, 1], [500, 1]],items2 = [[100, 1000], [200, 2000], [300, 3000], [400, 4000], [500, 5000]]) == [(100, 1001), (200, 2001), (300, 3001), (400, 4001), (500, 5001)]\n assert candidate(items1 = [[5, 50], [15, 150], [25, 250], [35, 350], [45, 450]],items2 = [[5, 50], [15, 150], [25, 250], [35, 350], [45, 450]]) == [(5, 100), (15, 300), (25, 500), (35, 700), (45, 900)]\n assert candidate(items1 = [[10, 1], [20, 2], [30, 3]],items2 = [[10, 9], [20, 8], [30, 7]]) == [(10, 10), (20, 10), (30, 10)]\n assert candidate(items1 = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5]],items2 = [[5, 5], [10, 4], [15, 3], [20, 2], [25, 1]]) == [(5, 6), (10, 6), (15, 6), (20, 6), (25, 6)]\n assert candidate(items1 = [[500, 50], [1000, 100]],items2 = [[250, 25], [750, 75], [1000, 50]]) == [(250, 25), (500, 50), (750, 75), (1000, 150)]\n assert candidate(items1 = [[1, 1], [10, 10], [100, 100], [1000, 1000]],items2 = [[1, 1000], [10, 100], [100, 10], [1000, 1]]) == [(1, 1001), (10, 110), (100, 110), (1000, 1001)]\n assert candidate(items1 = [[500, 1], [501, 2], [502, 3], [503, 4], [504, 5]],items2 = [[500, 5], [501, 4], [502, 3], [503, 2], [504, 1]]) == [(500, 6), (501, 6), (502, 6), (503, 6), (504, 6)]\n assert candidate(items1 = [[10, 100], [20, 200], [30, 300], [40, 400], [50, 500]],items2 = [[5, 50], [15, 150], [25, 250], [35, 350], [45, 450], [55, 550]]) == [(5, 50), (10, 100), (15, 150), (20, 200), (25, 250), (30, 300), (35, 350), (40, 400), (45, 450), (50, 500), (55, 550)]\n assert candidate(items1 = [[1, 100], [3, 300], [5, 500], [7, 700]],items2 = [[2, 200], [4, 400], [6, 600], [8, 800]]) == [(1, 100), (2, 200), (3, 300), (4, 400), (5, 500), (6, 600), (7, 700), (8, 800)]\n assert candidate(items1 = [[999, 1], [998, 2], [997, 3]],items2 = [[999, 4], [998, 5], [997, 6], [996, 7]]) == [(996, 7), (997, 9), (998, 7), (999, 5)]\n assert candidate(items1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]],items2 = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]) == [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)]\n assert candidate(items1 = [[10, 5], [20, 10], [30, 15], [40, 20]],items2 = [[10, 15], [20, 20], [50, 25], [60, 30]]) == [(10, 20), (20, 30), (30, 15), (40, 20), (50, 25), (60, 30)]\n assert candidate(items1 = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25], [30, 30], [35, 35], [40, 40]],items2 = [[3, 3], [6, 6], [9, 9], [12, 12], [18, 18], [21, 21], [24, 24], [27, 27], [33, 33], [36, 36], [39, 39], [42, 42]]) == [(3, 3), (5, 5), (6, 6), (9, 9), (10, 10), (12, 12), (15, 15), (18, 18), (20, 20), (21, 21), (24, 24), (25, 25), (27, 27), (30, 30), (33, 33), (35, 35), (36, 36), (39, 39), (40, 40), (42, 42)]\n assert candidate(items1 = [[5, 100], [15, 200], [25, 300], [35, 400]],items2 = [[5, 150], [25, 250], [35, 350], [45, 450]]) == [(5, 250), (15, 200), (25, 550), (35, 750), (45, 450)]\n assert candidate(items1 = [[1, 1000], [500, 500], [1000, 1]],items2 = [[1, 1000], [500, 500], [1000, 1]]) == [(1, 2000), (500, 1000), (1000, 2)]\n assert candidate(items1 = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]],items2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == [(1, 101), (2, 202), (3, 303), (4, 404), (5, 505), (6, 606), (7, 707), (8, 808), (9, 909), (10, 1010)]\n assert candidate(items1 = [[5, 1], [10, 2], [15, 3], [20, 4], [25, 5]],items2 = [[5, 5], [10, 10], [15, 15], [20, 20], [25, 25]]) == [(5, 6), (10, 12), (15, 18), (20, 24), (25, 30)]\n", "comparison": "exact"}, "public_tests": ["[[1,1],[4,5],[3,8]]\n[[3,1],[1,5]]", "[[1,1],[3,2],[2,3]]\n[[2,1],[3,2],[1,3]]", "[[1,3],[2,2]]\n[[7,1],[2,2],[1,4]]"], "hints": ["Map the weights using the corresponding values as keys.", "Make sure your output is sorted in ascending order by value."], "metadata": {"canonical_parameter_names": ["items1", "items2"], "leetcode_dataset_entry_point": "Solution().mergeSimilarItems", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:03+00:00", "tests_total": 100, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function mergeSimilarItems($items1, $items2) {", "container": "Solution", "callable": "mergeSimilarItems", "parameters": [{"name": "items1", "type": "Integer[][]"}, {"name": "items2", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2364, "task_id": "count-number-of-bad-pairs", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i].\n\nReturn the total number of bad pairs in nums.\n\nExample 1:\n\nInput: nums = [4,1,3,3]\nOutput: 5\nExplanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.\nThe pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.\nThe pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.\nThe pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.\nThe pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.\nThere are a total of 5 bad pairs, so we return 5.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: 0\nExplanation: There are no bad pairs.\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]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 15\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == 25\n assert candidate(nums = [9, 7, 5, 3, 1]) == 10\n assert candidate(nums = [1, 1, 1, 1]) == 6\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1, 3, 5, 7, 9]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 41\n assert candidate(nums = [10, 20, 30, 40, 50]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 3]) == 13\n assert candidate(nums = [4, 1, 3, 3]) == 5\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5]) == 16\n assert candidate(nums = [1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 42\n assert candidate(nums = [5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 45\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 21\n assert candidate(nums = [5, 3, 1, 4, 2]) == 10\n assert candidate(nums = [50, 40, 30, 20, 10]) == 10\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == 25\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 190\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 25\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 44\n assert candidate(nums = [1, 1000000000, 2, 999999999, 3, 999999998, 4, 999999997, 5, 999999996, 6, 999999995, 7, 999999994, 8, 999999993, 9, 999999992, 10, 999999991]) == 190\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]) == 189\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\n assert candidate(nums = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106]) == 104\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\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]) == 982\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 105\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]) == 465\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 10\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == 45\n assert candidate(nums = [10, 20, 30, 20, 10, 20, 30, 20, 10, 20]) == 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]) == 186\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 105\n assert candidate(nums = [4, 7, 10, 13, 16, 19, 22, 25]) == 28\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]) == 105\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\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 9, 8, 10, 11, 13, 12, 14, 15, 17, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 272\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 = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [3, 8, 3, 8, 3, 8, 3, 8, 3, 8]) == 42\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 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, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 241\n assert candidate(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 6]) == 32\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]) == 300\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]) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 185\n assert candidate(nums = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46]) == 44\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]) == 63\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]) == 496\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1]) == 42\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 50\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8]) == 99\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12, 13, 15, 14, 16, 17, 19, 18, 20, 21, 23, 22, 24, 25, 27, 26, 28, 29, 31, 30, 32, 33, 35, 34, 36, 37, 39, 38, 40]) == 500\n assert candidate(nums = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 45\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == 175\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 35\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 245\n assert candidate(nums = [10, 11, 13, 16, 20, 25, 31, 38, 46, 55, 65, 76, 88, 101, 115, 130, 146, 163, 181, 200, 220, 241, 263, 286, 310, 335, 361, 388, 416, 445]) == 434\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]) == 299\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]) == 44\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 189\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 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]) == 435\n assert candidate(nums = [100, 200, 150, 300, 250, 400, 350, 500, 450, 600]) == 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]) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 200\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 45\n assert candidate(nums = [1, 2, 3, 5, 4, 6, 7, 9, 8, 10, 11, 13, 12, 14, 15, 17, 16, 18, 19, 20]) == 112\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 2, 1]) == 25\n assert candidate(nums = [1, 5, 14, 30, 55, 91, 140, 204, 285, 385, 506, 650, 819, 1015, 1240, 1496, 1785, 2109, 2470, 2870, 3311, 3795, 4324, 4890, 5495, 6131, 6798, 7490, 8210, 8951]) == 435\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 66\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]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 45\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 65\n assert candidate(nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 190\n assert candidate(nums = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 190\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 37\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 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]) == 190\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517]) == 120\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 119\n assert candidate(nums = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19]) == 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]) == 426\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == 43\n assert candidate(nums = [7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16]) == 48\n assert candidate(nums = [5, 1, 9, 3, 7, 11, 15, 2, 6, 10, 14, 18, 22, 26, 30]) == 103\n assert candidate(nums = [1, 6, 3, 8, 5, 10, 7, 12, 9, 14, 11, 16, 13, 18, 15]) == 56\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 105\n assert candidate(nums = [1, 2, 5, 10, 17, 26, 37, 50, 65, 82, 101, 122, 145, 170, 197, 226, 257, 290, 325, 362, 401, 442, 485, 530, 577, 626, 677, 730, 785, 842]) == 434\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 = [100, 101, 102, 99, 98, 97, 96, 95, 94, 93]) == 42\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]) == 102\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995]) == 15\n assert candidate(nums = [5, 3, 1, 4, 2, 6, 8, 7, 10, 9]) == 40\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 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]) == 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, 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]) == 1741\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 190\n assert candidate(nums = [1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56]) == 54\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]) == 385\n assert candidate(nums = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [1, 2, 3, 6, 11, 20, 37, 68, 129, 246, 473, 910]) == 63\n assert candidate(nums = [1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231, 276, 325, 378, 435]) == 105\n assert candidate(nums = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3]) == 180\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 105\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]) == 269\n assert candidate(nums = [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, 52, 51, 54, 53, 56, 55]) == 784\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\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 190\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100]) == 66\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 105\n", "comparison": "exact"}, "public_tests": ["[4,1,3,3]", "[1,2,3,4,5]"], "hints": ["Would it be easier to count the number of pairs that are not bad pairs?", "Notice that (j - i != nums[j] - nums[i]) is the same as (nums[i] - i != nums[j] - j).", "Keep a counter of nums[i] - i. To be efficient, use a HashMap."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countBadPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:05+00:00", "tests_total": 132, "tests_dropped": 9, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting"]}, "language": "php", "interface": {"raw_signature": "function countBadPairs($nums) {", "container": "Solution", "callable": "countBadPairs", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2365, "task_id": "task-scheduler-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task.\n\nYou are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task of the same type can be performed.\n\nEach day, until all tasks have been completed, you must either:\n\n- Complete the next task from tasks, or\n- Take a break.\n\nReturn the minimum number of days needed to complete all tasks.\n\nExample 1:\n\nInput: tasks = [1,2,1,2,3,1], space = 3\nOutput: 9\nExplanation:\nOne way to complete all tasks in 9 days is as follows:\nDay 1: Complete the 0th task.\nDay 2: Complete the 1st task.\nDay 3: Take a break.\nDay 4: Take a break.\nDay 5: Complete the 2nd task.\nDay 6: Complete the 3rd task.\nDay 7: Take a break.\nDay 8: Complete the 4th task.\nDay 9: Complete the 5th task.\nIt can be shown that the tasks cannot be completed in less than 9 days.\n\nExample 2:\n\nInput: tasks = [5,8,8,5], space = 2\nOutput: 6\nExplanation:\nOne way to complete all tasks in 6 days is as follows:\nDay 1: Complete the 0th task.\nDay 2: Complete the 1st task.\nDay 3: Take a break.\nDay 4: Take a break.\nDay 5: Complete the 2nd task.\nDay 6: Complete the 3rd task.\nIt can be shown that the tasks cannot be completed in less than 6 days.\n\nConstraints:\n\n- 1 <= tasks.length <= 10^5\n- 1 <= tasks[i] <= 10^9\n- 1 <= space <= tasks.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 10) == 10\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 1) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5],space = 5) == 5\n assert candidate(tasks = [1, 1, 1, 1, 1],space = 1) == 9\n assert candidate(tasks = [1, 1, 1, 1],space = 2) == 10\n assert candidate(tasks = [1, 1, 1, 1, 1],space = 5) == 25\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 5) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5],space = 1) == 5\n assert candidate(tasks = [1, 1, 1, 1],space = 1) == 7\n assert candidate(tasks = [1, 2, 1, 2, 3, 1],space = 3) == 9\n assert candidate(tasks = [5, 8, 8, 5],space = 2) == 6\n assert candidate(tasks = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 10) == 10\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 1) == 10\n assert candidate(tasks = [1000000000, 999999999, 1000000000, 999999999, 1000000000],space = 3) == 9\n assert candidate(tasks = [1, 3, 2, 3, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],space = 4) == 34\n assert candidate(tasks = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],space = 1) == 36\n assert candidate(tasks = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],space = 2) == 12\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 10) == 21\n assert candidate(tasks = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10],space = 3) == 34\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],space = 20) == 191\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],space = 1) == 39\n assert candidate(tasks = [1, 2, 2, 1, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9, 10, 9, 10],space = 5) == 41\n assert candidate(tasks = [1000000000, 1, 2, 1000000000, 3, 4, 1000000000, 5],space = 2) == 8\n assert candidate(tasks = [5, 1, 2, 5, 1, 2, 5, 1, 2],space = 3) == 11\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],space = 3) == 38\n assert candidate(tasks = [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],space = 5) == 29\n assert candidate(tasks = [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],space = 2) == 64\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],space = 1) == 19\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 15) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 4) == 20\n assert candidate(tasks = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],space = 9) == 91\n assert candidate(tasks = [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],space = 15) == 30\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],space = 1) == 20\n assert candidate(tasks = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6],space = 3) == 66\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],space = 10) == 188\n assert candidate(tasks = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],space = 5) == 17\n assert candidate(tasks = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],space = 2) == 10\n assert candidate(tasks = [5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],space = 5) == 25\n assert candidate(tasks = [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],space = 4) == 25\n assert candidate(tasks = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],space = 1) == 20\n assert candidate(tasks = [1000000000, 999999999, 1000000000, 999999999, 1000000000],space = 2) == 7\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 10) == 100\n assert candidate(tasks = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1],space = 2) == 20\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 10) == 210\n assert candidate(tasks = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 1000000000],space = 5) == 11\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],space = 1) == 20\n assert candidate(tasks = [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],space = 20) == 52\n assert candidate(tasks = [999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991, 999999990, 999999989, 999999988, 999999987, 999999986, 999999985],space = 10) == 15\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],space = 5) == 70\n assert candidate(tasks = [1, 2, 3, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1],space = 2) == 20\n assert candidate(tasks = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],space = 3) == 18\n assert candidate(tasks = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3],space = 3) == 38\n assert candidate(tasks = [1, 3, 5, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9],space = 5) == 20\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],space = 3) == 77\n assert candidate(tasks = [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],space = 10) == 113\n assert candidate(tasks = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50],space = 15) == 53\n assert candidate(tasks = [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],space = 10) == 32\n assert candidate(tasks = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],space = 1) == 12\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 19) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 5) == 20\n assert candidate(tasks = [1, 2, 2, 1, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],space = 2) == 34\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 5) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 2) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 5) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],space = 3) == 18\n assert candidate(tasks = [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],space = 5) == 140\n assert candidate(tasks = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],space = 9) == 91\n assert candidate(tasks = [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],space = 3) == 31\n assert candidate(tasks = [1000000000, 999999999, 1000000000, 999999999, 1000000000, 999999999],space = 5) == 14\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],space = 2) == 40\n assert candidate(tasks = [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],space = 3) == 75\n assert candidate(tasks = [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],space = 3) == 35\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 3) == 20\n assert candidate(tasks = [1, 2, 3, 2, 1, 2, 1, 2, 1],space = 2) == 12\n assert candidate(tasks = [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],space = 4) == 105\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],space = 2) == 40\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],space = 3) == 74\n assert candidate(tasks = [1, 3, 2, 3, 1, 4, 2, 3, 1, 2, 4, 3, 1, 2, 3, 4, 1, 2, 3, 4],space = 4) == 28\n assert candidate(tasks = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],space = 4) == 15\n assert candidate(tasks = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8],space = 2) == 20\n assert candidate(tasks = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],space = 3) == 18\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 1) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5],space = 4) == 14\n assert candidate(tasks = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 5) == 265\n assert candidate(tasks = [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],space = 10) == 30\n assert candidate(tasks = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],space = 1) == 21\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],space = 4) == 18\n assert candidate(tasks = [1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3],space = 2) == 36\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 1) == 20\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 20) == 20\n assert candidate(tasks = [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],space = 1) == 30\n assert candidate(tasks = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 15) == 46\n assert candidate(tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],space = 1) == 20\n assert candidate(tasks = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],space = 4) == 47\n", "comparison": "exact"}, "public_tests": ["[1,2,1,2,3,1]\n3", "[5,8,8,5]\n2"], "hints": ["Try taking breaks as late as possible, such that tasks are still spaced appropriately.", "Whenever considering whether to complete the next task, if it is not the first task of its type, check how many days ago the previous task was completed and add an appropriate number of breaks."], "metadata": {"canonical_parameter_names": ["tasks", "space"], "leetcode_dataset_entry_point": "Solution().taskSchedulerII", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:07+00:00", "tests_total": 102, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "hash-table", "simulation"]}, "language": "php", "interface": {"raw_signature": "function taskSchedulerII($tasks, $space) {", "container": "Solution", "callable": "taskSchedulerII", "parameters": [{"name": "tasks", "type": "Integer[]"}, {"name": "space", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2366, "task_id": "minimum-replacements-to-sort-the-array", "difficulty": "Hard", "problem_description": "You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it.\n\n- For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7].\n\nReturn the minimum number of operations to make an array that is sorted in non-decreasing order.\n\nExample 1:\n\nInput: nums = [3,9,3]\nOutput: 2\nExplanation: Here are the steps to sort the array in non-decreasing order:\n- From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3]\n- From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3]\nThere are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: 0\nExplanation: The array is already in non-decreasing order. Therefore, we return 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 = [1, 1000000000]) == 0\n assert candidate(nums = [9, 7, 5, 3, 1]) == 20\n assert candidate(nums = [10, 5, 3]) == 5\n assert candidate(nums = [100, 75, 50]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [1000000000, 1000000000]) == 0\n assert candidate(nums = [1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [3, 9, 3]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == 0\n assert candidate(nums = [9, 4, 2, 1]) == 12\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [7, 8, 9, 10]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [5, 3, 2, 4, 1]) == 10\n assert candidate(nums = [10, 3, 3, 3, 3]) == 3\n assert candidate(nums = [1, 2, 5, 5, 5]) == 0\n assert candidate(nums = [10, 5, 2]) == 11\n assert candidate(nums = [100, 75, 50, 25]) == 6\n assert candidate(nums = [10, 10, 10, 10, 10]) == 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]) == 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]) == 190\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1, 1000000000]) == 1999999998\n assert candidate(nums = [1, 100, 1, 100, 1, 100, 1, 100]) == 297\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 56\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99]) == 0\n assert candidate(nums = [999999999, 100000000, 10000000, 1000000, 100000]) == 11106\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, 1]) == 4950\n assert candidate(nums = [99, 90, 81, 72, 63, 54, 45, 36, 27, 18, 9]) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 0\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 105\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1, 1, 1, 1]) == 190\n assert candidate(nums = [8, 12, 18, 24, 30, 36, 42, 48, 54, 60]) == 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 = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000]) == 45\n assert candidate(nums = [1000, 999, 998, 997, 996]) == 10\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 7, 8, 9, 10]) == 4\n assert candidate(nums = [8, 22, 9, 11, 2]) == 41\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1]) == 3999999996\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1]) == 36\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 100]) == 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]) == 81\n assert candidate(nums = [10, 15, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 125\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000]) == 57\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 45\n assert candidate(nums = [7, 14, 7, 28, 14, 35, 21, 49, 28, 56]) == 4\n assert candidate(nums = [20, 10, 20, 10, 20, 10, 20]) == 3\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000]) == 26\n assert candidate(nums = [2, 6, 5, 4, 3, 2, 1]) == 16\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 45\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10]) == 20\n assert candidate(nums = [10, 5, 25, 15, 20, 50, 30, 100, 40, 60]) == 5\n assert candidate(nums = [10, 20, 30, 25, 20, 15, 10]) == 16\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 1013\n assert candidate(nums = [5, 20, 15, 10, 25, 30, 5, 40, 35, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 16\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]) == 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]) == 90\n assert candidate(nums = [3, 12, 15, 9, 6, 3]) == 10\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 45\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 45\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [3, 10, 5, 15, 20, 25, 30, 5]) == 15\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 3, 1]) == 151\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]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [8, 12, 9, 6, 3, 1]) == 33\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 0\n assert candidate(nums = [34, 34, 21, 21, 13, 13, 8, 8, 5, 5, 3, 3, 2, 2]) == 155\n assert candidate(nums = [45, 36, 30, 24, 18, 15, 10, 5]) == 43\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 50]) == 9\n assert candidate(nums = [8, 12, 8, 16, 8]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 5]) == 100\n assert candidate(nums = [9, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 52\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == 10\n assert candidate(nums = [3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9]) == 44\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 81\n assert candidate(nums = [10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 35]) == 0\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 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, 1]) == 120\n assert candidate(nums = [15, 10, 5, 10, 15, 20, 25, 30, 35, 40]) == 3\n assert candidate(nums = [1000000000, 999999999, 999999998]) == 3\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 10]) == 168\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]) == 4950\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 0\n assert candidate(nums = [2, 2, 3, 3, 5, 5, 8, 8, 13, 13, 21, 21, 34, 34, 55, 55]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1]) == 9\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 0\n assert candidate(nums = [50, 40, 30, 20, 10, 5, 1, 1, 1, 1]) == 149\n assert candidate(nums = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 0\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 2036\n assert candidate(nums = [1, 10, 100, 1000, 10000]) == 0\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000]) == 57\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]) == 0\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 0\n", "comparison": "exact"}, "public_tests": ["[3,9,3]", "[1,2,3,4,5]"], "hints": ["It is optimal to never make an operation to the last element of the array.", "You can iterate from the second last element to the first. If the current value is greater than the previous bound, we want to break it into pieces so that the smaller one is as large as possible but not larger than the previous one."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumReplacement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:10+00:00", "tests_total": 107, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "math", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minimumReplacement($nums) {", "container": "Solution", "callable": "minimumReplacement", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2367, "task_id": "number-of-arithmetic-triplets", "difficulty": "Easy", "problem_description": "You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:\n\n- i < j < k,\n- nums[j] - nums[i] == diff, and\n- nums[k] - nums[j] == diff.\n\nReturn the number of unique arithmetic triplets.\n\nExample 1:\n\nInput: nums = [0,1,4,6,7,10], diff = 3\nOutput: 2\nExplanation:\n(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.\n(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.\n\nExample 2:\n\nInput: nums = [4,5,6,7,8,9], diff = 2\nOutput: 2\nExplanation:\n(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.\n(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.\n\nConstraints:\n\n- 3 <= nums.length <= 200\n- 0 <= nums[i] <= 200\n- 1 <= diff <= 50\n- nums is strictly increasing.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],diff = 2) == 5\n assert candidate(nums = [5, 10, 15, 20, 25, 30],diff = 5) == 4\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],diff = 4) == 6\n assert candidate(nums = [4, 5, 6, 7, 8, 9],diff = 2) == 2\n assert candidate(nums = [1, 3, 5, 7, 9],diff = 2) == 3\n assert candidate(nums = [0, 3, 6, 9, 12],diff = 3) == 3\n assert candidate(nums = [0, 1, 4, 6, 7, 10],diff = 3) == 2\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41],diff = 4) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],diff = 1) == 8\n assert candidate(nums = [0, 2, 4, 6, 8, 10],diff = 2) == 4\n assert candidate(nums = [10, 20, 30, 40, 50],diff = 10) == 3\n assert candidate(nums = [2, 5, 8, 11, 14, 17, 20],diff = 3) == 5\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],diff = 3) == 8\n assert candidate(nums = [10, 15, 20, 25, 30, 35],diff = 5) == 4\n assert candidate(nums = [5, 10, 15, 20, 25],diff = 5) == 3\n assert candidate(nums = [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42],diff = 3) == 13\n assert candidate(nums = [10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122],diff = 8) == 13\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, 85, 89, 93, 97],diff = 4) == 23\n assert candidate(nums = [1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109],diff = 6) == 17\n assert candidate(nums = [2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98, 104, 110, 116, 122],diff = 6) == 19\n assert candidate(nums = [1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85],diff = 6) == 13\n assert candidate(nums = [3, 12, 21, 30, 39, 48, 57, 66, 75, 84, 93],diff = 9) == 9\n assert candidate(nums = [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72],diff = 6) == 11\n assert candidate(nums = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50],diff = 5) == 9\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160],diff = 8) == 18\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],diff = 5) == 18\n assert candidate(nums = [5, 12, 19, 26, 33, 40, 47, 54, 61, 68],diff = 7) == 8\n assert candidate(nums = [2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68],diff = 6) == 10\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133],diff = 7) == 17\n assert candidate(nums = [1, 8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 120, 127, 134, 141, 148, 155, 162, 169, 176, 183, 190, 197],diff = 7) == 27\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155],diff = 10) == 14\n assert candidate(nums = [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80],diff = 4) == 19\n assert candidate(nums = [1, 5, 9, 14, 19, 24, 29, 34, 39, 44, 49],diff = 4) == 1\n assert candidate(nums = [2, 9, 16, 23, 30, 37, 44, 51, 58, 65, 72],diff = 7) == 9\n assert candidate(nums = [0, 2, 6, 8, 10, 14, 18, 20, 24, 28, 32, 34, 38, 40],diff = 2) == 1\n assert candidate(nums = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191],diff = 10) == 18\n assert candidate(nums = [3, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115],diff = 4) == 0\n assert candidate(nums = [1, 8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99],diff = 7) == 13\n assert candidate(nums = [1, 6, 9, 11, 15, 18, 21, 24, 27, 30],diff = 3) == 4\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187, 198],diff = 11) == 16\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117, 123, 129, 135, 141, 147, 153, 159, 165, 171, 177, 183, 189, 195],diff = 6) == 31\n assert candidate(nums = [2, 9, 16, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93],diff = 7) == 12\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38],diff = 4) == 8\n assert candidate(nums = [3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123, 131, 139, 147, 155, 163, 171, 179],diff = 8) == 21\n assert candidate(nums = [2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62],diff = 5) == 11\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117, 123],diff = 6) == 19\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96, 101, 106, 111],diff = 5) == 21\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40],diff = 3) == 12\n assert candidate(nums = [0, 5, 11, 17, 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, 191, 197],diff = 7) == 0\n assert candidate(nums = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45],diff = 5) == 8\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51],diff = 5) == 9\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39],diff = 3) == 11\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28],diff = 3) == 8\n assert candidate(nums = [2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102],diff = 5) == 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],diff = 1) == 18\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41],diff = 5) == 7\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71],diff = 6) == 10\n assert candidate(nums = [7, 17, 27, 37, 47, 57, 67, 77, 87, 97],diff = 10) == 8\n assert candidate(nums = [2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97],diff = 5) == 18\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],diff = 4) == 23\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],diff = 10) == 8\n assert candidate(nums = [2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98],diff = 6) == 15\n assert candidate(nums = [0, 5, 11, 16, 22, 27, 33, 38, 44, 49],diff = 7) == 0\n assert candidate(nums = [0, 3, 7, 12, 15, 19, 24, 27, 31, 36, 39, 43, 48, 51, 55, 60, 63, 67, 72],diff = 3) == 0\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59],diff = 6) == 8\n assert candidate(nums = [5, 12, 19, 26, 33, 40, 47, 54, 61, 68, 75, 82, 89],diff = 7) == 11\n assert candidate(nums = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48],diff = 5) == 8\n assert candidate(nums = [5, 20, 35, 50, 65, 80, 95, 110, 125, 140, 155, 170, 185],diff = 15) == 11\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34],diff = 3) == 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],diff = 10) == 18\n assert candidate(nums = [3, 12, 21, 30, 39, 48, 57, 66, 75, 84, 93, 102, 111, 120, 129, 138, 147, 156, 165, 174],diff = 9) == 18\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25],diff = 3) == 7\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81],diff = 5) == 15\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95],diff = 6) == 14\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99],diff = 6) == 15\n assert candidate(nums = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],diff = 2) == 9\n assert candidate(nums = [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20],diff = 1) == 0\n assert candidate(nums = [1, 5, 8, 11, 14, 17, 20, 23, 26],diff = 3) == 6\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],diff = 1) == 19\n assert candidate(nums = [0, 5, 10, 15, 20, 25, 30, 35, 40],diff = 5) == 7\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43],diff = 4) == 9\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195],diff = 10) == 18\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61],diff = 3) == 19\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, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 138, 140, 141, 143, 144, 146, 147, 149, 150, 152, 153, 155, 156, 158, 159, 161, 162, 164, 165, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, 183, 185, 186, 188, 189, 191, 192, 194, 195, 197, 198],diff = 2) == 1\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22],diff = 3) == 6\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96, 101, 106, 111, 116, 121, 126, 131, 136, 141, 146, 151, 156, 161, 166, 171, 176, 181, 186, 191, 196, 200],diff = 5) == 38\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61],diff = 5) == 11\n assert candidate(nums = [2, 9, 16, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 100],diff = 7) == 13\n assert candidate(nums = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],diff = 2) == 2\n assert candidate(nums = [3, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],diff = 3) == 8\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, 85, 89, 93, 97, 101],diff = 4) == 24\n assert candidate(nums = [1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97],diff = 6) == 15\n assert candidate(nums = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100],diff = 15) == 0\n assert candidate(nums = [7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67],diff = 5) == 11\n assert candidate(nums = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98],diff = 5) == 18\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, 118, 127],diff = 9) == 13\n assert candidate(nums = [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44],diff = 4) == 10\n assert candidate(nums = [2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114],diff = 8) == 13\n assert candidate(nums = [7, 17, 27, 37, 47, 57, 67, 77, 87, 97, 107, 117, 127, 137, 147, 157, 167, 177, 187, 197],diff = 10) == 18\n assert candidate(nums = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53],diff = 5) == 9\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49],diff = 4) == 11\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99],diff = 6) == 15\n assert candidate(nums = [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99],diff = 9) == 10\n assert candidate(nums = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73],diff = 5) == 13\n", "comparison": "exact"}, "public_tests": ["[0,1,4,6,7,10]\n3", "[4,5,6,7,8,9]\n2"], "hints": ["Are the constraints small enough for brute force?", "We can use three loops, each iterating through the array to go through every possible triplet. Be sure to not count duplicates."], "metadata": {"canonical_parameter_names": ["nums", "diff"], "leetcode_dataset_entry_point": "Solution().arithmeticTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:12+00:00", "tests_total": 104, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function arithmeticTriplets($nums, $diff) {", "container": "Solution", "callable": "arithmeticTriplets", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "diff", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2368, "task_id": "reachable-nodes-with-restrictions", "difficulty": "Medium", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\n\nYou 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 an integer array restricted which represents restricted nodes.\n\nReturn the maximum number of nodes you can reach from node 0 without visiting a restricted node.\n\nNote that node 0 will not be a restricted node.\n\nExample 1:\n\nInput: n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]\nOutput: 4\nExplanation: The diagram above shows the tree.\nWe have that [0,1,2,3] are the only nodes that can be reached from node 0 without visiting a restricted node.\n\nExample 2:\n\nInput: n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]\nOutput: 3\nExplanation: The diagram above shows the tree.\nWe have that [0,5,6] are the only nodes that can be reached from node 0 without visiting a restricted node.\n\nConstraints:\n\n- 2 <= n <= 10^5\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- 1 <= restricted.length < n\n- 1 <= restricted[i] < n\n- All the values of restricted are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5]],restricted = [1, 4]) == 3\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]],restricted = [5, 7]) == 6\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7]],restricted = [2, 4]) == 5\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],restricted = [7, 8]) == 8\n assert candidate(n = 8,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [6, 7]],restricted = [3, 5]) == 6\n assert candidate(n = 7,edges = [[0, 1], [1, 2], [3, 1], [4, 0], [0, 5], [5, 6]],restricted = [4, 5]) == 4\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],restricted = [1, 2]) == 1\n assert candidate(n = 6,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],restricted = [1, 5]) == 2\n assert candidate(n = 7,edges = [[0, 1], [0, 2], [0, 5], [0, 4], [3, 2], [6, 5]],restricted = [4, 2, 1]) == 3\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [1, 3], [1, 4]],restricted = [2, 3]) == 3\n assert candidate(n = 5,edges = [[0, 1], [0, 2], [2, 3], [2, 4]],restricted = [3]) == 4\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]],restricted = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 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]],restricted = [1, 5, 9]) == 5\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]],restricted = [12, 14, 16, 18, 20, 22, 24, 26, 28]) == 19\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]],restricted = [2, 5, 8, 10]) == 6\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]],restricted = [3, 7, 12, 16]) == 11\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]],restricted = [9, 10, 11]) == 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]],restricted = [3, 5, 7, 9, 11]) == 8\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],restricted = [1, 5]) == 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]],restricted = [2, 4]) == 5\n assert candidate(n = 25,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]],restricted = [3, 5, 8, 12, 15]) == 9\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],restricted = [1, 4, 6]) == 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]],restricted = [8, 9, 10, 11]) == 11\n assert candidate(n = 21,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], [10, 20]],restricted = [2, 6, 10, 15, 18, 20]) == 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]],restricted = [2, 3, 5, 7, 9]) == 3\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]],restricted = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == 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]],restricted = [5, 11, 17, 23]) == 19\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]],restricted = [1, 2, 3, 5, 6, 7, 10]) == 1\n assert candidate(n = 15,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]],restricted = [3, 5, 8]) == 8\n assert candidate(n = 20,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]],restricted = [2, 4, 7, 12]) == 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]],restricted = [1, 3, 5]) == 3\n assert candidate(n = 9,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8]],restricted = [1, 3, 5, 7]) == 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]],restricted = [1, 4, 7]) == 4\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]],restricted = [1, 4, 6, 7, 11]) == 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]],restricted = [1, 5, 8, 12, 15]) == 5\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]],restricted = [1, 2, 3, 4]) == 1\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], [7, 19], [7, 20], [8, 21], [8, 22], [9, 23], [9, 24], [10, 25], [10, 26], [10, 27], [11, 28], [11, 29]],restricted = [1, 2, 3, 4, 5, 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\n assert candidate(n = 15,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]],restricted = [2, 4, 6, 8]) == 5\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]],restricted = [1, 3, 5, 8, 11, 15]) == 5\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]],restricted = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 5\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]],restricted = [1, 5, 9, 13, 17, 21]) == 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]],restricted = [2, 6, 10]) == 7\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],restricted = [3, 5, 7]) == 6\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]],restricted = [2, 6, 10, 14, 18, 22, 26]) == 12\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]],restricted = [2, 4, 6, 8]) == 6\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]],restricted = [3, 5, 7, 10]) == 8\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],restricted = [2, 4, 7]) == 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]],restricted = [1, 5, 10]) == 5\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]],restricted = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(n = 15,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]],restricted = [1, 4, 6, 9]) == 5\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]],restricted = [1, 3, 5, 8, 11, 15, 21]) == 5\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], [8, 16], [9, 17], [10, 18], [11, 19]],restricted = [1, 3, 5, 7, 9]) == 5\n assert candidate(n = 30,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]],restricted = [2, 4, 7, 12, 15, 20]) == 6\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]],restricted = [1, 4, 6, 9, 11]) == 3\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]],restricted = [1, 3, 5, 8, 11]) == 5\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]],restricted = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 6\n assert candidate(n = 12,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]],restricted = [2, 7, 9]) == 5\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]],restricted = [3, 6, 9, 12, 15]) == 7\n assert candidate(n = 10,edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]],restricted = [3, 6, 8]) == 6\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]],restricted = [3, 10, 15, 19]) == 13\n", "comparison": "exact"}, "public_tests": ["7\n[[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]]\n[4,5]", "7\n[[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]]\n[4,2,1]"], "hints": ["Can we find all the reachable nodes in a single traversal?", "Traverse the graph from node 0 while avoiding the nodes in restricted and do not revisit nodes that have been visited.", "Keep count of how many nodes are visited in total."], "metadata": {"canonical_parameter_names": ["n", "edges", "restricted"], "leetcode_dataset_entry_point": "Solution().reachableNodes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:15+00:00", "tests_total": 71, "tests_dropped": 11, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "hash-table", "tree", "depth-first-search", "breadth-first-search", "union-find", "graph"]}, "language": "php", "interface": {"raw_signature": "function reachableNodes($n, $edges, $restricted) {", "container": "Solution", "callable": "reachableNodes", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}, {"name": "restricted", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2369, "task_id": "check-if-there-is-a-valid-partition-for-the-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.\n\nWe call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:\n\n1. The subarray consists of exactly 2, equal elements. For example, the subarray [2,2] is good.\n2. The subarray consists of exactly 3, equal elements. For example, the subarray [4,4,4] is good.\n3. The subarray consists of exactly 3 consecutive increasing elements, that is, the difference between adjacent elements is 1. For example, the subarray [3,4,5] is good, but the subarray [1,3,5] is not.\n\nReturn true if the array has at least one valid partition. Otherwise, return false.\n\nExample 1:\n\nInput: nums = [4,4,4,5,6]\nOutput: true\nExplanation: The array can be partitioned into the subarrays [4,4] and [4,5,6].\nThis partition is valid, so we return true.\n\nExample 2:\n\nInput: nums = [1,1,1,2]\nOutput: false\nExplanation: There is no valid partition for this array.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 4, 5]) == False\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 2, 3, 3, 3, 4, 5, 5]) == False\n assert candidate(nums = [1, 1, 2, 3, 4, 4, 5, 6]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4]) == True\n assert candidate(nums = [1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 3, 3, 3]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [1, 3, 5, 7, 9]) == False\n assert candidate(nums = [1, 1, 2, 2, 3, 3]) == True\n assert candidate(nums = [1000000, 1000000]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == True\n assert candidate(nums = [1, 1, 1, 2]) == False\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 5, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 5]) == False\n assert candidate(nums = [4, 4, 4, 5, 6]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 3]) == False\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == True\n assert candidate(nums = [1, 2, 3, 2, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3]) == True\n assert candidate(nums = [1, 2, 3]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == True\n assert candidate(nums = [2, 2, 3, 4, 5, 5, 5]) == True\n assert candidate(nums = [2, 2]) == True\n assert candidate(nums = [4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == True\n assert candidate(nums = [1, 1, 1, 2, 3, 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]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10]) == False\n assert candidate(nums = [1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15, 15, 15, 16, 17, 18, 19, 20, 20, 20, 21, 22, 23]) == False\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]) == True\n assert candidate(nums = [5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15]) == True\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8, 9]) == True\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == True\n assert candidate(nums = [3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 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]) == 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]) == True\n assert candidate(nums = [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 = [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]) == 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]) == True\n assert candidate(nums = [9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8, 8, 8, 9, 9, 10, 10]) == True\n assert candidate(nums = [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]) == 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, 10, 10, 11, 12, 13, 14, 15, 15, 15]) == True\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]) == True\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]) == True\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13]) == True\n assert candidate(nums = [9, 9, 10, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16]) == False\n assert candidate(nums = [3, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 10, 10]) == True\n assert candidate(nums = [10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 17, 18, 19, 19, 20]) == 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]) == True\n assert candidate(nums = [5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 13]) == True\n assert candidate(nums = [5, 6, 7, 8, 8, 9, 10, 10, 11, 11]) == False\n assert candidate(nums = [10, 10, 10, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15, 15, 15, 16, 17, 18, 19, 20, 20, 20, 21, 22, 23]) == False\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]) == True\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]) == True\n assert candidate(nums = [1, 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]) == True\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]) == 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, 2, 3, 1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 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 = [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, 24, 25, 26]) == False\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 2, 3, 2, 2, 3, 4, 5, 6, 6, 6]) == True\n assert candidate(nums = [1, 1, 2, 3, 4, 4, 4, 5, 6, 7, 8, 9, 10, 10, 10]) == True\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == True\n assert candidate(nums = [5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == True\n assert candidate(nums = [5, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == False\n assert candidate(nums = [1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == False\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]) == False\n assert candidate(nums = [4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]) == False\n assert candidate(nums = [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, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 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, 21, 22, 22]) == False\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == True\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, 11, 11, 11, 12, 12, 12]) == True\n assert candidate(nums = [3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20]) == True\n assert candidate(nums = [1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15, 15, 15, 16, 16, 16]) == True\n assert candidate(nums = [2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == True\n assert candidate(nums = [3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8]) == True\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7, 8, 8, 8]) == 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]) == True\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16]) == True\n assert candidate(nums = [1, 1, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 10, 10, 10, 11, 12]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11, 12, 13, 13, 13, 14, 14]) == True\n assert candidate(nums = [1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 19]) == False\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8]) == True\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8]) == 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, 25, 25, 26, 27, 28, 29, 30, 30, 30]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23]) == 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, 12, 12, 13, 13]) == False\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18]) == False\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == True\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, 11, 11, 12, 12, 13, 13]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17]) == True\n assert candidate(nums = [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, 14, 14]) == False\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == True\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]) == True\n assert candidate(nums = [1, 2, 3, 3, 4, 5, 5, 5, 6, 7, 8, 8, 9, 10, 10, 10, 11, 12, 13, 14, 15, 15, 15, 16, 17, 18, 19, 20, 20, 20, 21, 22, 23, 24, 25]) == False\n assert candidate(nums = [9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13]) == True\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10]) == False\n assert candidate(nums = [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]) == True\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19]) == True\n assert candidate(nums = [2, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15]) == True\n assert candidate(nums = [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]) == True\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17]) == False\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8]) == True\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == False\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]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9]) == False\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == True\n assert candidate(nums = [2, 2, 3, 3, 4, 5, 5, 6, 6, 7]) == False\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]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == True\n", "comparison": "exact"}, "public_tests": ["[4,4,4,5,6]", "[1,1,1,2]"], "hints": ["How can you reduce the problem to checking if there is a valid partition for a smaller array?", "Use dynamic programming to reduce the problem until you have an empty array."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().validPartition", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:18+00:00", "tests_total": 134, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function validPartition($nums) {", "container": "Solution", "callable": "validPartition", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2370, "task_id": "longest-ideal-subsequence", "difficulty": "Medium", "problem_description": "You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:\n\n- t is a subsequence of the string s.\n- The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.\n\nReturn the length of the longest ideal string.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nNote that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.\n\nExample 1:\n\nInput: s = \"acfgbd\", k = 2\nOutput: 4\nExplanation: The longest ideal string is \"acbd\". The length of this string is 4, so 4 is returned.\nNote that \"acfgbd\" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.\n\nExample 2:\n\nInput: s = \"abcd\", k = 3\nOutput: 4\nExplanation: The longest ideal string is \"abcd\". The length of this string is 4, so 4 is returned.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- 0 <= k <= 25\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 25) == 20\n assert candidate(s = \"a\",k = 0) == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 0) == 1\n assert candidate(s = \"abcd\",k = 3) == 4\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 1) == 26\n assert candidate(s = \"a\",k = 5) == 1\n assert candidate(s = \"abacabadabacaba\",k = 1) == 12\n assert candidate(s = \"pqrspqrstuv\",k = 2) == 10\n assert candidate(s = \"abcabcabcabc\",k = 2) == 12\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",k = 25) == 27\n assert candidate(s = \"acfgbd\",k = 2) == 4\n assert candidate(s = \"aaaabbbbcccc\",k = 25) == 12\n assert candidate(s = \"zzzzzzzzz\",k = 25) == 9\n assert candidate(s = \"leetcode\",k = 2) == 5\n assert candidate(s = \"abcabcabc\",k = 2) == 9\n assert candidate(s = \"zyzyzyzyzyzyzyzyzyzy\",k = 1) == 20\n assert candidate(s = \"triplebyte\",k = 2) == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\",k = 1) == 52\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabb\",k = 1) == 32\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggg\",k = 2) == 28\n assert candidate(s = \"aabcdefghijklmnopqrstuvwxyz\",k = 24) == 27\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",k = 2) == 16\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 1) == 26\n assert candidate(s = \"abacabadabacaba\",k = 0) == 8\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 0) == 50\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 25) == 26\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 5) == 26\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhh\",k = 3) == 32\n assert candidate(s = \"aabcdefghijklmnopqrstuvwxyz\",k = 1) == 27\n assert candidate(s = \"abababababababababababababababab\",k = 0) == 16\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcd\",k = 3) == 32\n assert candidate(s = \"ababababababababababababababababab\",k = 0) == 17\n assert candidate(s = \"abcdxyzabcdxyzabcdxyz\",k = 4) == 12\n assert candidate(s = \"z\",k = 25) == 1\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 0) == 1\n assert candidate(s = \"mississippiissipi\",k = 4) == 9\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 0) == 60\n assert candidate(s = \"thisisaverylongstringthatneedstobechecked\",k = 3) == 17\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",k = 25) == 51\n assert candidate(s = \"zzzzyyyyxxxwwvvuttsrrqqppoonnmmllkkjjiihhggffeeddccbbbaaa\",k = 3) == 57\n assert candidate(s = \"qpwoeirutyalskdjfhgzmxncbv\",k = 4) == 11\n assert candidate(s = \"aaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaabaaaab\",k = 0) == 40\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcd\",k = 3) == 28\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 2) == 29\n assert candidate(s = \"abcdabcdabcdabcdabcdabcd\",k = 3) == 24\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\",k = 5) == 21\n assert candidate(s = \"abacabacabacaba\",k = 1) == 12\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 25) == 52\n assert candidate(s = \"zzzyyyxxxwwwwvvvuutttsssrqqppoonnmlkkjjiihhggffeeddccbbaaa\",k = 2) == 58\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 1) == 52\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxyz\",k = 24) == 26\n assert candidate(s = \"bdfhjlnprtvxz\",k = 2) == 13\n assert candidate(s = \"mnopqrsmnopqrsmnopqrsmnopqrs\",k = 2) == 16\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",k = 0) == 120\n assert candidate(s = \"qwertypoiuytrewqazxcvbnmnbvcxz\",k = 5) == 15\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",k = 5) == 22\n assert candidate(s = \"qpqprqqpqrqpqrqpqrqpq\",k = 1) == 20\n assert candidate(s = \"abcdxyzabcdxyzabcdxyz\",k = 3) == 12\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijkl\",k = 10) == 14\n assert candidate(s = \"mmppqqrrssttuuvvwwxxyyzz\",k = 1) == 22\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 0) == 20\n assert candidate(s = \"abababababababababababababababab\",k = 1) == 32\n assert candidate(s = \"abcdefgabcdefgabcdefg\",k = 5) == 19\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",k = 24) == 26\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 0) == 2\n assert candidate(s = \"abacabadabacabadabacabad\",k = 1) == 18\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 2) == 26\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 3) == 30\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz\",k = 12) == 52\n assert candidate(s = \"aeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",k = 0) == 63\n assert candidate(s = \"qpwoeirutyalskdjfhgxcvbnm\",k = 5) == 11\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\",k = 2) == 97\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",k = 10) == 37\n assert candidate(s = \"abcdefghijkalmnopqrstuvwxyz\",k = 2) == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 25) == 84\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 2) == 52\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab\",k = 1) == 128\n assert candidate(s = \"abcdabcdabcdabcd\",k = 3) == 16\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\",k = 5) == 17\n assert candidate(s = \"a\",k = 25) == 1\n assert candidate(s = \"aquickbrownfoxjumpsoverthelazydog\",k = 5) == 14\n assert candidate(s = \"mjmnjmmnjmnmjmmnj\",k = 0) == 8\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",k = 24) == 26\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 24) == 52\n", "comparison": "exact"}, "public_tests": ["\"acfgbd\"\n2", "\"abcd\"\n3"], "hints": ["How can you calculate the longest ideal subsequence that ends at a specific index i?", "Can you calculate it for all positions i? How can you use previously calculated answers to calculate the answer for the next position?"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().longestIdealString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:20+00:00", "tests_total": 85, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function longestIdealString($s, $k) {", "container": "Solution", "callable": "longestIdealString", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2373, "task_id": "largest-local-values-in-a-matrix", "difficulty": "Easy", "problem_description": "You are given an n x n integer matrix grid.\n\nGenerate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:\n\n- maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.\n\nIn other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.\n\nReturn the generated matrix.\n\nExample 1:\n\nInput: grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]\nOutput: [[9,9],[8,6]]\nExplanation: The diagram above shows the original matrix and the generated matrix.\nNotice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.\n\nExample 2:\n\nInput: grid = [[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]]\nOutput: [[2,2,2],[2,2,2],[2,2,2]]\nExplanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.\n\nConstraints:\n\n- n == grid.length == grid[i].length\n- 3 <= n <= 100\n- 1 <= grid[i][j] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[5, 8, 4, 3], [3, 5, 9, 5], [7, 6, 7, 9], [4, 8, 5, 3]]) == [[9, 9], [9, 9]]\n assert candidate(grid = [[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, 2, 2], [2, 2, 2], [2, 2, 2]]\n assert candidate(grid = [[100, 100, 100], [100, 100, 100], [100, 100, 100]]) == [[100]]\n assert candidate(grid = [[9, 9, 8, 1], [5, 6, 2, 6], [8, 2, 6, 4], [6, 2, 2, 2]]) == [[9, 9], [8, 6]]\n assert candidate(grid = [[1, 9, 2, 8, 3, 7, 4, 6, 5, 10], [11, 19, 12, 18, 13, 17, 14, 16, 15, 20], [21, 29, 22, 28, 23, 27, 24, 26, 25, 30], [31, 39, 32, 38, 33, 37, 34, 36, 35, 40], [41, 49, 42, 48, 43, 47, 44, 46, 45, 50], [51, 59, 52, 58, 53, 57, 54, 56, 55, 60], [61, 69, 62, 68, 63, 67, 64, 66, 65, 70], [71, 79, 72, 78, 73, 77, 74, 76, 75, 80], [81, 89, 82, 88, 83, 87, 84, 86, 85, 90], [91, 99, 92, 98, 93, 97, 94, 96, 95, 100]]) == [[29, 29, 28, 28, 27, 27, 26, 30], [39, 39, 38, 38, 37, 37, 36, 40], [49, 49, 48, 48, 47, 47, 46, 50], [59, 59, 58, 58, 57, 57, 56, 60], [69, 69, 68, 68, 67, 67, 66, 70], [79, 79, 78, 78, 77, 77, 76, 80], [89, 89, 88, 88, 87, 87, 86, 90], [99, 99, 98, 98, 97, 97, 96, 100]]\n assert candidate(grid = [[9, 9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9], [9, 9, 9, 9]]) == [[9, 9], [9, 9]]\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]]) == [[100, 99, 98], [95, 94, 93], [90, 89, 88]]\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]]) == [[15, 16, 17, 18], [21, 22, 23, 24], [27, 28, 29, 30], [33, 34, 35, 36]]\n assert candidate(grid = [[100, 1, 100, 1, 100, 1], [1, 100, 1, 100, 1, 100], [100, 1, 100, 1, 100, 1], [1, 100, 1, 100, 1, 100], [100, 1, 100, 1, 100, 1], [1, 100, 1, 100, 1, 100]]) == [[100, 100, 100, 100], [100, 100, 100, 100], [100, 100, 100, 100], [100, 100, 100, 100]]\n assert candidate(grid = [[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]]) == [[50, 60, 70], [60, 70, 80], [70, 80, 90]]\n assert candidate(grid = [[50, 20, 30, 10, 60, 70, 80], [40, 10, 50, 30, 20, 60, 90], [60, 50, 40, 30, 20, 10, 70], [30, 40, 50, 60, 70, 80, 90], [20, 30, 40, 50, 60, 70, 80], [10, 20, 30, 40, 50, 60, 70], [5, 15, 25, 35, 45, 55, 65]]) == [[60, 50, 60, 70, 90], [60, 60, 70, 80, 90], [60, 60, 70, 80, 90], [50, 60, 70, 80, 90], [40, 50, 60, 70, 80]]\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, 7, 5, 3, 1], [2, 4, 6, 8, 10, 8, 6, 4, 2], [3, 6, 9, 12, 15, 12, 9, 6, 3], [4, 8, 12, 16, 20, 16, 12, 8, 4], [5, 10, 15, 20, 25, 20, 15, 10, 5], [6, 12, 18, 24, 30, 24, 18, 12, 6], [7, 14, 21, 28, 35, 28, 21, 14, 7]]) == [[9, 8, 9, 9, 9, 8, 9], [9, 8, 10, 10, 10, 8, 6], [9, 12, 15, 15, 15, 12, 9], [12, 16, 20, 20, 20, 16, 12], [15, 20, 25, 25, 25, 20, 15], [18, 24, 30, 30, 30, 24, 18], [21, 28, 35, 35, 35, 28, 21]]\n assert candidate(grid = [[70, 23, 16, 35, 40, 97, 89], [22, 28, 48, 39, 78, 49, 21], [72, 84, 43, 26, 14, 62, 54], [92, 25, 15, 61, 32, 86, 19], [11, 98, 85, 29, 53, 77, 94], [59, 34, 82, 76, 83, 36, 93], [50, 60, 51, 44, 46, 63, 79]]) == [[84, 84, 78, 97, 97], [92, 84, 78, 86, 86], [98, 98, 85, 86, 94], [98, 98, 85, 86, 94], [98, 98, 85, 83, 94]]\n assert candidate(grid = [[100, 1, 1, 1, 1, 1, 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], [100, 1, 1, 1, 1, 1, 100]]) == [[100, 1, 1, 1, 100], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [100, 1, 1, 1, 100]]\n assert candidate(grid = [[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]]) == [[66, 67, 68, 69, 70], [73, 74, 75, 76, 77], [80, 81, 82, 83, 84], [87, 88, 89, 90, 91], [94, 95, 96, 97, 98]]\n assert candidate(grid = [[100, 99, 98, 97], [96, 95, 94, 93], [92, 91, 90, 89], [88, 87, 86, 85]]) == [[100, 99], [96, 95]]\n assert candidate(grid = [[50, 50, 50, 50, 50, 50], [50, 1, 2, 3, 4, 50], [50, 6, 7, 8, 9, 50], [50, 10, 11, 12, 13, 50], [50, 14, 15, 16, 17, 50], [50, 50, 50, 50, 50, 50]]) == [[50, 50, 50, 50], [50, 12, 13, 50], [50, 16, 17, 50], [50, 50, 50, 50]]\n assert candidate(grid = [[1, 10, 15, 20, 25, 30], [5, 6, 7, 8, 9, 10], [15, 20, 25, 30, 35, 40], [25, 30, 35, 40, 45, 50], [35, 40, 45, 50, 55, 60], [45, 50, 55, 60, 65, 70]]) == [[25, 30, 35, 40], [35, 40, 45, 50], [45, 50, 55, 60], [55, 60, 65, 70]]\n assert candidate(grid = [[100, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7], [4, 5, 6, 7, 8]]) == [[100, 5, 6], [5, 6, 7], [6, 7, 8]]\n assert candidate(grid = [[99, 1, 2, 3, 4, 5, 6, 7, 8], [8, 99, 1, 2, 3, 4, 5, 6, 7], [7, 8, 99, 1, 2, 3, 4, 5, 6], [6, 7, 8, 99, 1, 2, 3, 4, 5], [5, 6, 7, 8, 99, 1, 2, 3, 4], [4, 5, 6, 7, 8, 99, 1, 2, 3], [3, 4, 5, 6, 7, 8, 99, 1, 2], [2, 3, 4, 5, 6, 7, 8, 99, 1], [1, 2, 3, 4, 5, 6, 7, 8, 99]]) == [[99, 99, 99, 5, 6, 7, 8], [99, 99, 99, 99, 5, 6, 7], [99, 99, 99, 99, 99, 5, 6], [8, 99, 99, 99, 99, 99, 5], [7, 8, 99, 99, 99, 99, 99], [6, 7, 8, 99, 99, 99, 99], [5, 6, 7, 8, 99, 99, 99]]\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [7, 8, 9, 10, 11, 12], [12, 11, 10, 9, 8, 7], [13, 14, 15, 16, 17, 18], [18, 17, 16, 15, 14, 13]]) == [[9, 10, 11, 12], [12, 11, 11, 12], [15, 16, 17, 18], [18, 17, 17, 18]]\n assert candidate(grid = [[1, 3, 2, 1, 5], [4, 1, 5, 3, 2], [2, 5, 3, 4, 1], [3, 2, 4, 5, 3], [5, 4, 1, 2, 3]]) == [[5, 5, 5], [5, 5, 5], [5, 5, 5]]\n assert candidate(grid = [[90, 91, 92, 93, 94, 95], [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]]) == [[92, 93, 94, 95], [89, 88, 87, 86], [83, 82, 81, 80], [77, 76, 75, 74]]\n assert candidate(grid = [[9, 1, 3, 5, 7, 9], [5, 3, 1, 7, 9, 5], [3, 5, 7, 1, 3, 7], [7, 9, 5, 3, 1, 9], [9, 7, 3, 5, 7, 1], [1, 9, 7, 5, 3, 5]]) == [[9, 7, 9, 9], [9, 9, 9, 9], [9, 9, 7, 9], [9, 9, 7, 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, 7, 5, 3, 1], [2, 4, 6, 8, 10, 8, 6, 4, 2], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 7, 5, 3, 1], [2, 4, 6, 8, 10, 8, 6, 4, 2], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == [[9, 8, 9, 9, 9, 8, 9], [9, 8, 10, 10, 10, 8, 6], [6, 8, 10, 10, 10, 8, 9], [9, 8, 10, 10, 10, 8, 9], [9, 8, 9, 9, 9, 8, 9], [9, 8, 10, 10, 10, 8, 6], [6, 8, 10, 10, 10, 8, 9]]\n assert candidate(grid = [[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], [40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30], [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60], [60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50], [70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70], [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100], [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]) == [[32, 33, 34, 35, 36, 37, 38, 39, 40], [40, 39, 38, 37, 36, 37, 38, 39, 40], [52, 53, 54, 55, 56, 57, 58, 59, 60], [60, 59, 58, 57, 56, 57, 58, 59, 60], [72, 73, 74, 75, 76, 77, 78, 79, 80], [80, 79, 78, 77, 76, 77, 78, 79, 80], [92, 93, 94, 95, 96, 97, 98, 99, 100], [100, 99, 98, 97, 96, 97, 98, 99, 100], [100, 99, 98, 97, 96, 97, 98, 99, 100]]\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]]) == [[17, 18, 19, 20, 21], [24, 25, 26, 27, 28], [31, 32, 33, 34, 35], [38, 39, 40, 41, 42], [45, 46, 47, 48, 49]]\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]]) == [[6, 5, 6, 7], [7, 6, 6, 7], [7, 6, 7, 8], [8, 7, 7, 8]]\n assert candidate(grid = [[5, 3, 1, 2, 7, 8, 4, 9, 6], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 1, 3, 4, 5, 6, 7, 8, 9], [8, 9, 1, 2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8, 9, 1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5, 6, 7, 8], [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, 6, 7, 8, 9], [9, 9, 7, 8, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 7, 8, 9]]\n assert candidate(grid = [[1, 100, 2, 99, 3, 98], [100, 99, 2, 1, 3, 98], [99, 98, 1, 2, 100, 3], [3, 2, 100, 1, 99, 2], [2, 1, 99, 3, 100, 98], [100, 98, 3, 99, 2, 1]]) == [[100, 100, 100, 100], [100, 100, 100, 100], [100, 100, 100, 100], [100, 100, 100, 100]]\n assert candidate(grid = [[48, 12, 24, 87, 55, 96], [17, 94, 31, 76, 67, 33], [58, 28, 72, 57, 86, 52], [27, 74, 95, 65, 89, 60], [41, 62, 84, 43, 88, 9], [13, 77, 42, 82, 36, 70]]) == [[94, 94, 87, 96], [95, 95, 95, 89], [95, 95, 95, 89], [95, 95, 95, 89]]\n assert candidate(grid = [[1, 1, 1, 100, 1, 1, 1, 1, 1], [1, 1, 1, 1, 100, 1, 1, 1, 1], [1, 1, 1, 1, 1, 100, 1, 1, 1], [1, 1, 1, 1, 1, 1, 100, 1, 1], [1, 1, 1, 1, 1, 1, 1, 100, 1], [1, 1, 1, 1, 1, 1, 1, 1, 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, 100, 100, 100, 100, 100, 1], [1, 1, 100, 100, 100, 100, 100], [1, 1, 1, 100, 100, 100, 100], [1, 1, 1, 1, 100, 100, 100], [1, 1, 1, 1, 1, 100, 100], [1, 1, 1, 1, 1, 1, 100], [1, 1, 1, 1, 1, 1, 1]]\n assert candidate(grid = [[83, 11, 52, 93, 48, 37, 29, 71, 88], [6, 13, 39, 96, 54, 15, 79, 38, 40], [87, 75, 99, 64, 49, 91, 27, 67, 56], [95, 70, 43, 25, 12, 81, 41, 69, 82], [9, 58, 66, 20, 33, 47, 80, 90, 65], [31, 55, 86, 46, 68, 74, 3, 16, 57], [4, 51, 73, 60, 85, 100, 5, 78, 18], [26, 32, 59, 45, 97, 7, 62, 53, 24], [63, 14, 98, 44, 35, 72, 8, 42, 17]]) == [[99, 99, 99, 96, 91, 91, 88], [99, 99, 99, 96, 91, 91, 82], [99, 99, 99, 91, 91, 91, 90], [95, 86, 86, 81, 81, 90, 90], [86, 86, 86, 100, 100, 100, 90], [86, 86, 97, 100, 100, 100, 78], [98, 98, 98, 100, 100, 100, 78]]\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 7, 5, 3, 1, 2, 4, 6, 8], [8, 6, 4, 2, 1, 3, 5, 7, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 7, 5, 3, 1, 2, 4, 6, 8], [8, 6, 4, 2, 1, 3, 5, 7, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1]]) == [[9, 8, 7, 6, 7, 8, 9], [9, 7, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 7, 9], [9, 8, 7, 6, 7, 8, 9], [9, 8, 7, 6, 7, 8, 9], [9, 7, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 7, 9]]\n assert candidate(grid = [[10, 10, 10, 10, 10, 10, 10, 10, 10], [10, 9, 9, 9, 9, 9, 9, 9, 10], [10, 9, 8, 8, 8, 8, 8, 9, 10], [10, 9, 8, 7, 7, 7, 8, 9, 10], [10, 9, 8, 7, 6, 7, 8, 9, 10], [10, 9, 8, 7, 7, 7, 8, 9, 10], [10, 9, 8, 8, 8, 8, 8, 9, 10], [10, 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, 9, 9, 9, 9, 9, 10], [10, 9, 8, 8, 8, 9, 10], [10, 9, 8, 7, 8, 9, 10], [10, 9, 8, 8, 8, 9, 10], [10, 9, 9, 9, 9, 9, 10], [10, 10, 10, 10, 10, 10, 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, 9, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 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, 9, 9, 1, 1], [1, 1, 9, 9, 9, 1, 1], [1, 1, 9, 9, 9, 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], [9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 2, 4, 6, 8], [8, 6, 4, 2, 1, 9, 7, 5, 3], [5, 1, 9, 7, 3, 6, 2, 8, 4], [2, 8, 6, 4, 7, 1, 3, 9, 5], [4, 9, 1, 3, 2, 8, 5, 7, 6], [3, 5, 2, 8, 4, 7, 6, 9, 1], [6, 7, 8, 9, 1, 2, 3, 4, 5]]) == [[9, 8, 9, 9, 9, 8, 9], [9, 8, 9, 9, 9, 9, 8], [9, 9, 9, 9, 9, 9, 8], [9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 8, 8, 9, 9], [9, 9, 8, 8, 8, 9, 9], [9, 9, 9, 9, 8, 9, 9]]\n assert candidate(grid = [[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]]) == [[48, 49, 50, 51, 52], [55, 56, 57, 58, 59], [62, 63, 64, 65, 66], [69, 70, 71, 72, 73], [76, 77, 78, 79, 80]]\n assert candidate(grid = [[1, 15, 3, 17, 7], [16, 18, 5, 14, 6], [12, 19, 9, 13, 11], [4, 8, 20, 1, 10], [15, 2, 16, 3, 18]]) == [[19, 19, 17], [20, 20, 20], [20, 20, 20]]\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, 75, 74, 73, 72, 71], [70, 69, 68, 67, 66, 65]]) == [[100, 99, 98, 97], [94, 93, 92, 91], [88, 87, 86, 85], [82, 81, 80, 79]]\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], [2, 4, 6, 8, 10, 12, 14, 16, 18], [18, 16, 14, 12, 10, 8, 6, 4, 2], [17, 15, 13, 11, 9, 7, 5, 3, 1], [9, 7, 5, 3, 1, 2, 4, 6, 8], [8, 6, 4, 2, 1, 3, 5, 7, 9], [7, 8, 9, 1, 2, 3, 4, 5, 6]]) == [[9, 8, 9, 11, 13, 15, 17], [9, 8, 10, 12, 14, 16, 18], [18, 16, 14, 12, 14, 16, 18], [18, 16, 14, 12, 14, 16, 18], [18, 16, 14, 12, 10, 8, 8], [17, 15, 13, 11, 9, 7, 9], [9, 9, 9, 3, 5, 7, 9]]\n assert candidate(grid = [[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]]\n assert candidate(grid = [[30, 1, 2, 3, 4, 5, 6], [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], [6, 7, 8, 9, 10, 11, 12]]) == [[30, 5, 6, 7, 8], [5, 6, 7, 8, 9], [6, 7, 8, 9, 10], [7, 8, 9, 10, 11], [8, 9, 10, 11, 12]]\n assert candidate(grid = [[10, 9, 8, 7, 6], [7, 6, 5, 4, 3], [8, 7, 6, 5, 4], [9, 8, 7, 6, 5], [10, 9, 8, 7, 6]]) == [[10, 9, 8], [9, 8, 7], [10, 9, 8]]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 3, 2, 1, 1], [1, 3, 5, 3, 1, 1], [1, 2, 3, 2, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == [[5, 5, 5, 3], [5, 5, 5, 3], [5, 5, 5, 3], [3, 3, 3, 2]]\n assert candidate(grid = [[81, 82, 83, 84, 85, 86, 87], [88, 89, 90, 91, 92, 93, 94], [95, 96, 97, 98, 99, 100, 95], [94, 93, 92, 91, 90, 89, 88], [87, 86, 85, 84, 83, 82, 81], [82, 83, 84, 85, 86, 87, 88], [89, 90, 91, 92, 93, 94, 95]]) == [[97, 98, 99, 100, 100], [97, 98, 99, 100, 100], [97, 98, 99, 100, 100], [94, 93, 92, 91, 90], [91, 92, 93, 94, 95]]\n assert candidate(grid = [[3, 3, 3, 3, 3, 3, 3], [3, 1, 2, 3, 4, 5, 3], [3, 4, 5, 6, 7, 8, 3], [3, 5, 6, 7, 8, 9, 3], [3, 6, 7, 8, 9, 8, 3], [3, 5, 6, 7, 8, 7, 3], [3, 3, 3, 3, 3, 3, 3]]) == [[5, 6, 7, 8, 8], [6, 7, 8, 9, 9], [7, 8, 9, 9, 9], [7, 8, 9, 9, 9], [7, 8, 9, 9, 9]]\n assert candidate(grid = [[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]]\n assert candidate(grid = [[1, 50, 2, 51, 3, 52, 4, 53, 5], [5, 54, 6, 55, 7, 56, 8, 57, 9], [10, 59, 11, 60, 12, 61, 13, 62, 14], [15, 63, 16, 64, 17, 65, 18, 66, 19], [20, 67, 21, 68, 22, 69, 23, 70, 24], [25, 71, 26, 72, 27, 73, 28, 74, 29], [30, 75, 31, 76, 32, 77, 33, 78, 34], [35, 79, 36, 80, 37, 81, 38, 82, 39], [40, 83, 41, 84, 42, 85, 43, 86, 44]]) == [[59, 60, 60, 61, 61, 62, 62], [63, 64, 64, 65, 65, 66, 66], [67, 68, 68, 69, 69, 70, 70], [71, 72, 72, 73, 73, 74, 74], [75, 76, 76, 77, 77, 78, 78], [79, 80, 80, 81, 81, 82, 82], [83, 84, 84, 85, 85, 86, 86]]\n assert candidate(grid = [[5, 1, 9, 3, 5, 7, 8, 2, 9, 10], [6, 2, 8, 4, 7, 5, 3, 8, 10, 7], [9, 3, 5, 8, 2, 10, 4, 7, 6, 5], [1, 4, 7, 9, 8, 6, 2, 10, 3, 9], [8, 6, 2, 7, 5, 9, 10, 4, 8, 6], [4, 7, 8, 6, 10, 2, 9, 5, 7, 4], [7, 5, 3, 9, 4, 8, 6, 10, 2, 8], [2, 8, 10, 5, 7, 3, 9, 6, 4, 7], [9, 6, 4, 7, 8, 10, 5, 2, 3, 1], [10, 7, 6, 5, 9, 4, 8, 7, 6, 5]]) == [[9, 9, 9, 10, 10, 10, 10, 10], [9, 9, 9, 10, 10, 10, 10, 10], [9, 9, 9, 10, 10, 10, 10, 10], [8, 9, 10, 10, 10, 10, 10, 10], [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, 9, 7]]\n", "comparison": "exact"}, "public_tests": ["[[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]", "[[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]]"], "hints": ["Use nested loops to run through all possible 3 x 3 windows in the matrix.", "For each 3 x 3 window, iterate through the values to get the maximum value within the window."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().largestLocal", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:25+00:00", "tests_total": 56, "tests_dropped": 6, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix"]}, "language": "php", "interface": {"raw_signature": "function largestLocal($grid) {", "container": "Solution", "callable": "largestLocal", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2374, "task_id": "node-with-highest-edge-score", "difficulty": "Medium", "problem_description": "You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge.\n\nThe graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i].\n\nThe edge score of a node i is defined as the sum of the labels of all the nodes that have an edge pointing to i.\n\nReturn the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.\n\nExample 1:\n\nInput: edges = [1,0,0,0,0,7,7,5]\nOutput: 7\nExplanation:\n- The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.\n- The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.\n- The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.\n- The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.\nNode 7 has the highest edge score so return 7.\n\nExample 2:\n\nInput: edges = [2,0,0,2]\nOutput: 0\nExplanation:\n- The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.\n- The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.\nNodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0.\n\nConstraints:\n\n- n == edges.length\n- 2 <= n <= 10^5\n- 0 <= edges[i] < n\n- edges[i] != i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(edges = [2, 0, 0, 2]) == 0\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(edges = [1, 0, 0, 0, 0, 7, 7, 5]) == 7\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 0]) == 0\n assert candidate(edges = [5, 3, 0, 5, 1, 6, 2]) == 2\n assert candidate(edges = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == 6\n assert candidate(edges = [1, 2, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]) == 0\n assert candidate(edges = [1, 2, 0, 0, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(edges = [8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7]) == 7\n assert candidate(edges = [1, 2, 3, 4, 5, 6, 7, 0, 1, 2]) == 2\n assert candidate(edges = [2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,0,0,0,0,7,7,5]", "[2,0,0,2]"], "hints": ["Create an array arr where arr[i] is the edge score for node i.", "How does the edge score for node edges[i] change? It increases by i.", "The edge score may not fit within a standard 32-bit integer."], "metadata": {"canonical_parameter_names": ["edges"], "leetcode_dataset_entry_point": "Solution().edgeScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:27+00:00", "tests_total": 26, "tests_dropped": 15, "flags": ["has_images"], "topic_tags": ["hash-table", "graph"]}, "language": "php", "interface": {"raw_signature": "function edgeScore($edges) {", "container": "Solution", "callable": "edgeScore", "parameters": [{"name": "edges", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2375, "task_id": "construct-smallest-number-from-di-string", "difficulty": "Medium", "problem_description": "You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.\n\nA 0-indexed string num of length n + 1 is created using the following conditions:\n\n- num consists of the digits '1' to '9', where each digit is used at most once.\n- If pattern[i] == 'I', then num[i] < num[i + 1].\n- If pattern[i] == 'D', then num[i] > num[i + 1].\n\nReturn the lexicographically smallest possible string num that meets the conditions.\n\nExample 1:\n\nInput: pattern = \"IIIDIDDD\"\nOutput: \"123549876\"\nExplanation:\nAt indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].\nAt indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].\nSome possible values of num are \"245639871\", \"135749862\", and \"123849765\".\nIt can be proven that \"123549876\" is the smallest possible num that meets the conditions.\nNote that \"123414321\" is not possible because the digit '1' is used more than once.\n\nExample 2:\n\nInput: pattern = \"DDD\"\nOutput: \"4321\"\nExplanation:\nSome possible values of num are \"9876\", \"7321\", and \"8742\".\nIt can be proven that \"4321\" is the smallest possible num that meets the conditions.\n\nConstraints:\n\n- 1 <= pattern.length <= 8\n- pattern consists of only the letters 'I' and 'D'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pattern = \"DDD\") == \"4321\"\n assert candidate(pattern = \"IIIDIDDD\") == \"123549876\"\n assert candidate(pattern = \"ID\") == \"132\"\n assert candidate(pattern = \"IIDDD\") == \"126543\"\n assert candidate(pattern = \"DDIII\") == \"321456\"\n assert candidate(pattern = \"IDID\") == \"13254\"\n assert candidate(pattern = \"IIII\") == \"12345\"\n assert candidate(pattern = \"DI\") == \"213\"\n assert candidate(pattern = \"IID\") == \"1243\"\n assert candidate(pattern = \"DDIDDIID\") == \"321654798\"\n assert candidate(pattern = \"IDIDIDID\") == \"132547698\"\n assert candidate(pattern = \"I\") == \"12\"\n assert candidate(pattern = \"DID\") == \"2143\"\n assert candidate(pattern = \"IIIII\") == \"123456\"\n assert candidate(pattern = \"DDDDD\") == \"654321\"\n assert candidate(pattern = \"D\") == \"21\"\n assert candidate(pattern = \"DDDD\") == \"54321\"\n assert candidate(pattern = \"DDDIDIII\") == \"432165789\"\n assert candidate(pattern = \"DDDIIIII\") == \"432156789\"\n assert candidate(pattern = \"IDDDDDID\") == \"176543298\"\n assert candidate(pattern = \"IIDID\") == \"124365\"\n assert candidate(pattern = \"DIIIDDDI\") == \"213487659\"\n assert candidate(pattern = \"DDDDDDD\") == \"87654321\"\n assert candidate(pattern = \"DIDIDIDI\") == \"214365879\"\n assert candidate(pattern = \"DDDDDDDD\") == \"987654321\"\n assert candidate(pattern = \"DDDDIIII\") == \"543216789\"\n assert candidate(pattern = \"IIIDIDID\") == \"123547698\"\n assert candidate(pattern = \"IDDDIIDI\") == \"154326879\"\n assert candidate(pattern = \"IIDIDDDI\") == \"124387659\"\n assert candidate(pattern = \"DIDIDID\") == \"21436587\"\n assert candidate(pattern = \"DDDDIII\") == \"54321678\"\n assert candidate(pattern = \"IDIDID\") == \"1325476\"\n assert candidate(pattern = \"IIDIDIDI\") == \"124365879\"\n assert candidate(pattern = \"DDDDDDI\") == \"76543218\"\n assert candidate(pattern = \"DDIDDDID\") == \"321765498\"\n assert candidate(pattern = \"DIIIIIII\") == \"213456789\"\n assert candidate(pattern = \"IDDDIDII\") == \"154327689\"\n assert candidate(pattern = \"DDIDIDID\") == \"321547698\"\n assert candidate(pattern = \"IIIDDDDD\") == \"123987654\"\n assert candidate(pattern = \"IIIIIID\") == \"12345687\"\n assert candidate(pattern = \"IDIDDDID\") == \"132765498\"\n assert candidate(pattern = \"IIIIIII\") == \"12345678\"\n assert candidate(pattern = \"DDIIDDDD\") == \"321498765\"\n assert candidate(pattern = \"IIIIIIID\") == \"123456798\"\n assert candidate(pattern = \"DIIDIDID\") == \"213547698\"\n assert candidate(pattern = \"DDIIDIDI\") == \"321465879\"\n assert candidate(pattern = \"IIDDDIID\") == \"126543798\"\n assert candidate(pattern = \"IIDDDIII\") == \"126543789\"\n assert candidate(pattern = \"DIDID\") == \"214365\"\n assert candidate(pattern = \"DDDDDIII\") == \"654321789\"\n assert candidate(pattern = \"DDII\") == \"32145\"\n assert candidate(pattern = \"DDDIDDDD\") == \"432198765\"\n assert candidate(pattern = \"IDDDDDD\") == \"18765432\"\n assert candidate(pattern = \"IDII\") == \"13245\"\n assert candidate(pattern = \"DDDDDDII\") == \"765432189\"\n assert candidate(pattern = \"IIIDDDDI\") == \"123876549\"\n assert candidate(pattern = \"IDDDIDID\") == \"154327698\"\n assert candidate(pattern = \"IIIIIDDI\") == \"123458769\"\n assert candidate(pattern = \"DDDDDD\") == \"7654321\"\n assert candidate(pattern = \"IIIIIDDD\") == \"123459876\"\n assert candidate(pattern = \"DDDDIID\") == \"54321687\"\n assert candidate(pattern = \"DDIIDDID\") == \"321476598\"\n assert candidate(pattern = \"IIDDDDDD\") == \"129876543\"\n assert candidate(pattern = \"IIDDDII\") == \"12654378\"\n assert candidate(pattern = \"DDIIDIDD\") == \"321465987\"\n assert candidate(pattern = \"IIDDIIDD\") == \"125436987\"\n assert candidate(pattern = \"IIIIIIII\") == \"123456789\"\n assert candidate(pattern = \"IIIDDDD\") == \"12387654\"\n assert candidate(pattern = \"DDIID\") == \"321465\"\n", "comparison": "exact"}, "public_tests": ["\"IIIDIDDD\"", "\"DDD\""], "hints": ["With the constraints, could we generate every possible string?", "Yes we can. Now we just need to check if the string meets all the conditions."], "metadata": {"canonical_parameter_names": ["pattern"], "leetcode_dataset_entry_point": "Solution().smallestNumber", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:30+00:00", "tests_total": 116, "tests_dropped": 47, "flags": [], "topic_tags": ["string", "backtracking", "stack", "greedy"]}, "language": "php", "interface": {"raw_signature": "function smallestNumber($pattern) {", "container": "Solution", "callable": "smallestNumber", "parameters": [{"name": "pattern", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2376, "task_id": "count-special-integers", "difficulty": "Hard", "problem_description": "We call a positive integer special if all of its digits are distinct.\n\nGiven a positive integer n, return the number of special integers that belong to the interval [1, n].\n\nExample 1:\n\nInput: n = 20\nOutput: 19\nExplanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers.\n\nExample 2:\n\nInput: n = 5\nOutput: 5\nExplanation: All the integers from 1 to 5 are special.\n\nExample 3:\n\nInput: n = 135\nOutput: 110\nExplanation: There are 110 integers from 1 to 135 that are special.\nSome of the integers that are not special are: 22, 114, and 131.\n\nConstraints:\n\n- 1 <= n <= 2 * 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 135) == 110\n assert candidate(n = 999) == 738\n assert candidate(n = 200) == 162\n assert candidate(n = 10000) == 5274\n assert candidate(n = 1234) == 803\n assert candidate(n = 2000) == 1242\n assert candidate(n = 9876) == 5274\n assert candidate(n = 123456789) == 2392084\n assert candidate(n = 20) == 19\n assert candidate(n = 2000000) == 229050\n assert candidate(n = 2000000000) == 5974650\n assert candidate(n = 300) == 234\n assert candidate(n = 100) == 90\n assert candidate(n = 1999999999) == 5974650\n assert candidate(n = 1000) == 738\n assert candidate(n = 1) == 1\n assert candidate(n = 5) == 5\n assert candidate(n = 222222222) == 2789370\n assert candidate(n = 210) == 171\n assert candidate(n = 999999999) == 5611770\n assert candidate(n = 12345) == 5660\n assert candidate(n = 9999999) == 712890\n assert candidate(n = 111111) == 34170\n assert candidate(n = 111222333) == 2386170\n assert candidate(n = 111) == 98\n assert candidate(n = 213456789) == 2754964\n assert candidate(n = 987654) == 168570\n assert candidate(n = 876543210) == 5202657\n assert candidate(n = 200000) == 47610\n assert candidate(n = 101010101) == 2345850\n assert candidate(n = 200000000) == 2708730\n assert candidate(n = 12344321) == 735990\n assert candidate(n = 543210987) == 3975354\n assert candidate(n = 1122334455) == 5652090\n assert candidate(n = 9999) == 5274\n assert candidate(n = 555555555) == 3998970\n assert candidate(n = 1111111) == 175290\n assert candidate(n = 1000000000) == 5611770\n assert candidate(n = 88888) == 29130\n assert candidate(n = 1000000001) == 5611770\n assert candidate(n = 111111111) == 2386170\n assert candidate(n = 987654321) == 5611770\n assert candidate(n = 888888888) == 5208570\n assert candidate(n = 1234567890) == 5658004\n assert candidate(n = 567890123) == 4028371\n assert candidate(n = 101010) == 32490\n assert candidate(n = 987654320) == 5611769\n assert candidate(n = 98765) == 32490\n assert candidate(n = 1000000) == 168570\n assert candidate(n = 999999) == 168570\n assert candidate(n = 123456) == 34417\n assert candidate(n = 87654321) == 2141294\n assert candidate(n = 1111111111) == 5652090\n", "comparison": "exact"}, "public_tests": ["20", "5", "135"], "hints": ["Try to think of dynamic programming.", "Use the idea of digit dynamic programming to build the numbers, in addition to a bitmask that will tell which digits you have used so far on the number that you are building."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().countSpecialNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:32+00:00", "tests_total": 57, "tests_dropped": 4, "flags": [], "topic_tags": ["math", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countSpecialNumbers($n) {", "container": "Solution", "callable": "countSpecialNumbers", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2379, "task_id": "minimum-recolors-to-get-k-consecutive-black-blocks", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. The characters 'W' and 'B' denote the colors white and black, respectively.\n\nYou are also given an integer k, which is the desired number of consecutive black blocks.\n\nIn one operation, you can recolor a white block such that it becomes a black block.\n\nReturn the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.\n\nExample 1:\n\nInput: blocks = \"WBBWWBBWBW\", k = 7\nOutput: 3\nExplanation:\nOne way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks\nso that blocks = \"BBBBBBBWBW\".\nIt can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.\nTherefore, we return 3.\n\nExample 2:\n\nInput: blocks = \"WBWBBBW\", k = 2\nOutput: 0\nExplanation:\nNo changes need to be made, since 2 consecutive black blocks already exist.\nTherefore, we return 0.\n\nConstraints:\n\n- n == blocks.length\n- 1 <= n <= 100\n- blocks[i] is either 'W' or 'B'.\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(blocks = \"WWWW\",k = 2) == 2\n assert candidate(blocks = \"WBBBWWBBBW\",k = 3) == 0\n assert candidate(blocks = \"WBBWWBBWBW\",k = 7) == 3\n assert candidate(blocks = \"BBBBB\",k = 3) == 0\n assert candidate(blocks = \"BWBWBWBWBW\",k = 6) == 3\n assert candidate(blocks = \"WWWWWW\",k = 4) == 4\n assert candidate(blocks = \"WWWWWW\",k = 3) == 3\n assert candidate(blocks = \"BBBB\",k = 4) == 0\n assert candidate(blocks = \"BBBBBB\",k = 4) == 0\n assert candidate(blocks = \"WBWBBBW\",k = 2) == 0\n assert candidate(blocks = \"WBWBWBWBWB\",k = 5) == 2\n assert candidate(blocks = \"BBBBBB\",k = 3) == 0\n assert candidate(blocks = \"BBBBBBBBBBBBBBBBBBBB\",k = 20) == 0\n assert candidate(blocks = \"BBWBBWBBWBBWBBWBBWBBWBBWBBWBBWBBW\",k = 14) == 4\n assert candidate(blocks = \"WBBBWWWWWWBBBWWBB\",k = 7) == 2\n assert candidate(blocks = \"WBWBWBWBWBWBWBWBWB\",k = 10) == 5\n assert candidate(blocks = \"WBBWWBBWWBBWWBBWWBBW\",k = 8) == 4\n assert candidate(blocks = \"WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB\",k = 10) == 5\n assert candidate(blocks = \"WBWBWBWBWBWBWB\",k = 5) == 2\n assert candidate(blocks = \"WWBBWWBBWWBBWWBBWWBB\",k = 6) == 2\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBWBWBWBWBW\",k = 7) == 3\n assert candidate(blocks = \"BBWWBBWWBBW\",k = 5) == 2\n assert candidate(blocks = \"BWBWBWBWBWBWBW\",k = 7) == 3\n assert candidate(blocks = \"WBBBWWBBBWBBBWWBBB\",k = 7) == 1\n assert candidate(blocks = \"BBBBBBBBBBBBBBBB\",k = 16) == 0\n assert candidate(blocks = \"BBBBBBWWBBWWBBWWBBWW\",k = 6) == 0\n assert candidate(blocks = \"WWBWWBBWWB\",k = 6) == 3\n assert candidate(blocks = \"WWWWBBWWWBBWWBBWWB\",k = 5) == 2\n assert candidate(blocks = \"WBBWWWWBBBWBWWBBB\",k = 8) == 3\n assert candidate(blocks = \"BBWWBBWWBBWWBBWW\",k = 4) == 2\n assert candidate(blocks = \"BWWBWWBWWBWWBWWBWWBW\",k = 7) == 4\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBWBW\",k = 15) == 7\n assert candidate(blocks = \"WWWWWWWWWW\",k = 10) == 10\n assert candidate(blocks = \"WWBWWBWWBWWBWWBWWBWWBWWBWWB\",k = 3) == 2\n assert candidate(blocks = \"WBBBBBBWBBBBBBW\",k = 10) == 1\n assert candidate(blocks = \"BBBWBBWWWWBBBWWBBB\",k = 6) == 1\n assert candidate(blocks = \"BBBBBBBWWWWWWWBBBBBB\",k = 8) == 1\n assert candidate(blocks = \"WWWWBWWWWBWWWWBWWWWB\",k = 4) == 3\n assert candidate(blocks = \"WBBWBBWBBWBBWBBW\",k = 7) == 2\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBW\",k = 10) == 5\n assert candidate(blocks = \"BWBWBWBWBW\",k = 4) == 2\n assert candidate(blocks = \"WBBBWWBBBWWBBB\",k = 6) == 2\n assert candidate(blocks = \"WWWWWBBBWBBBWWWW\",k = 7) == 1\n assert candidate(blocks = \"BBBWWWBBBWWWBBB\",k = 9) == 3\n assert candidate(blocks = \"WBBWBWBWBWBWBWBWBW\",k = 8) == 3\n assert candidate(blocks = \"WWWWWWWW\",k = 4) == 4\n assert candidate(blocks = \"BBWWBBWWBBWW\",k = 4) == 2\n assert candidate(blocks = \"WWBBBWWBBBWWBBBWW\",k = 5) == 2\n assert candidate(blocks = \"WWWWWWWWWW\",k = 5) == 5\n assert candidate(blocks = \"WWWWWWWWWWWWWWWWWWWW\",k = 15) == 15\n assert candidate(blocks = \"BBBBBBBBBWWWWWWWWW\",k = 9) == 0\n assert candidate(blocks = \"BBBBBB\",k = 6) == 0\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBWBW\",k = 9) == 4\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBWBWBW\",k = 11) == 5\n assert candidate(blocks = \"BBBBBBBBBB\",k = 5) == 0\n assert candidate(blocks = \"BBBBWWBBBWBWB\",k = 6) == 2\n assert candidate(blocks = \"BBBBWBWBWBWBWBWBWB\",k = 11) == 4\n assert candidate(blocks = \"WBBBBBBBBBBBBBBBBBBBBBBBBBBW\",k = 25) == 0\n assert candidate(blocks = \"BBBBBBWWWWWW\",k = 4) == 0\n assert candidate(blocks = \"BBBWWBWBWBWBWBW\",k = 6) == 2\n assert candidate(blocks = \"BWBWBWBWBWBWBWBW\",k = 8) == 4\n assert candidate(blocks = \"WBBWWBBWBWWBBWBBWBWBWBWB\",k = 12) == 5\n assert candidate(blocks = \"BBBWWWBBBWWWBBBWWWBB\",k = 5) == 2\n assert candidate(blocks = \"WWBBWWBBWWBBWWBBWW\",k = 5) == 2\n assert candidate(blocks = \"BBBBBBBWBBB\",k = 8) == 1\n assert candidate(blocks = \"WBBBWWBBBWWBBB\",k = 8) == 2\n assert candidate(blocks = \"BBBWBBBWWBBBWWBBBWWB\",k = 7) == 1\n assert candidate(blocks = \"BBWWWWWWWWWW\",k = 3) == 1\n assert candidate(blocks = \"BWBWBWBWBW\",k = 8) == 4\n assert candidate(blocks = \"WBBBWBWBWBWBBB\",k = 5) == 1\n assert candidate(blocks = \"WWBWBWBWBW\",k = 5) == 2\n assert candidate(blocks = \"WBBWWBBWBBWWBBWBBWBBWWBBWB\",k = 8) == 2\n assert candidate(blocks = \"BBWWBBWWBBWWBBWWBBWWBBWW\",k = 5) == 2\n assert candidate(blocks = \"WBBBWWBBBWBBBWWBBB\",k = 6) == 1\n assert candidate(blocks = \"WBWBWBWBWBWBWBWBWBWB\",k = 10) == 5\n assert candidate(blocks = \"BWBWBWBWBWBWBWBW\",k = 6) == 3\n assert candidate(blocks = \"WBBWBBWWBBWWBBWBBWBBW\",k = 8) == 2\n assert candidate(blocks = \"WBBWWBBWBWWBBWBBW\",k = 10) == 4\n assert candidate(blocks = \"BWWWWBBWWWWBBWWWW\",k = 7) == 4\n assert candidate(blocks = \"BBBWBWBBBBBBBWB\",k = 9) == 1\n assert candidate(blocks = \"WWWWWWWWWWWW\",k = 5) == 5\n assert candidate(blocks = \"WBBWWWWBWBWWB\",k = 6) == 3\n assert candidate(blocks = \"WWBBWWBBWWBBWWBBWWBB\",k = 4) == 2\n assert candidate(blocks = \"WBBWBBWBBWBBWBBWBBWB\",k = 10) == 3\n assert candidate(blocks = \"BBWWBBWWBBWWBBWWBB\",k = 4) == 2\n assert candidate(blocks = \"BWWBWWBWWBWWBWWBWW\",k = 6) == 4\n assert candidate(blocks = \"WWWBWWWWBWBWWB\",k = 4) == 2\n assert candidate(blocks = \"WBWBWBWBWBWBWBWBWBWB\",k = 5) == 2\n assert candidate(blocks = \"WBBWBBWBBWBBWBBWBBWB\",k = 9) == 3\n assert candidate(blocks = \"BBBBBBBWWWWWWWWWW\",k = 7) == 0\n assert candidate(blocks = \"WWWWWWWWWWWWWWWWWWWW\",k = 1) == 1\n assert candidate(blocks = \"WBBWWBBWWBBWWBBWWBBWWBBW\",k = 7) == 3\n assert candidate(blocks = \"WWWWBBWWWWBBWWWWBBWWWWBB\",k = 4) == 2\n assert candidate(blocks = \"WWBBWWBBWWBBWW\",k = 5) == 2\n assert candidate(blocks = \"WWWWBWWWWBWWWWB\",k = 4) == 3\n assert candidate(blocks = \"BBBBBBBBBB\",k = 10) == 0\n assert candidate(blocks = \"BBBBBBBBBBBBBBBBBBBB\",k = 10) == 0\n assert candidate(blocks = \"WWWWWWWWWWWWWW\",k = 5) == 5\n assert candidate(blocks = \"WWBBWWBBWWBBWW\",k = 6) == 2\n assert candidate(blocks = \"BBBBBWWBBBWWBBBWWBBBWWBBB\",k = 5) == 0\n assert candidate(blocks = \"BWBWBWBWBWBWBWBWBWBWBWBWBWBWBW\",k = 15) == 7\n", "comparison": "exact"}, "public_tests": ["\"WBBWWBBWBW\"\n7", "\"WBWBBBW\"\n2"], "hints": ["Iterate through all possible consecutive substrings of k characters.", "Find the number of changes for each substring to make all blocks black, and return the minimum of these."], "metadata": {"canonical_parameter_names": ["blocks", "k"], "leetcode_dataset_entry_point": "Solution().minimumRecolors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:37+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function minimumRecolors($blocks, $k) {", "container": "Solution", "callable": "minimumRecolors", "parameters": [{"name": "blocks", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2380, "task_id": "time-needed-to-rearrange-a-binary-string", "difficulty": "Medium", "problem_description": "You are given a binary string s. In one second, all occurrences of \"01\" are simultaneously replaced with \"10\". This process repeats until no occurrences of \"01\" exist.\n\nReturn the number of seconds needed to complete this process.\n\nExample 1:\n\nInput: s = \"0110101\"\nOutput: 4\nExplanation:\nAfter one second, s becomes \"1011010\".\nAfter another second, s becomes \"1101100\".\nAfter the third second, s becomes \"1110100\".\nAfter the fourth second, s becomes \"1111000\".\nNo occurrence of \"01\" exists any longer, and the process needed 4 seconds to complete,\nso we return 4.\n\nExample 2:\n\nInput: s = \"11100\"\nOutput: 0\nExplanation:\nNo occurrence of \"01\" exists in s, and the processes needed 0 seconds to complete,\nso we return 0.\n\nConstraints:\n\n- 1 <= s.length <= 1000\n- s[i] is either '0' or '1'.\n\nFollow up:\n\nCan you solve this problem in O(n) time complexity?\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"1111\") == 0\n assert candidate(s = \"00110011\") == 5\n assert candidate(s = \"0000\") == 0\n assert candidate(s = \"111000\") == 0\n assert candidate(s = \"0010110\") == 4\n assert candidate(s = \"1001001\") == 4\n assert candidate(s = \"000011110000\") == 7\n assert candidate(s = \"000111\") == 5\n assert candidate(s = \"1001001001\") == 6\n assert candidate(s = \"11111\") == 0\n assert candidate(s = \"01010101\") == 4\n assert candidate(s = \"10101010\") == 3\n assert candidate(s = \"110100110\") == 4\n assert candidate(s = \"1010101010\") == 4\n assert candidate(s = \"101010\") == 2\n assert candidate(s = \"1000000\") == 0\n assert candidate(s = \"11001100\") == 3\n assert candidate(s = \"11100\") == 0\n assert candidate(s = \"0101010101\") == 5\n assert candidate(s = \"0110101\") == 4\n assert candidate(s = \"0110011001\") == 5\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"0010010010\") == 6\n assert candidate(s = \"101010101010101010\") == 8\n assert candidate(s = \"011010101010101010100110\") == 12\n assert candidate(s = \"0010101010101010\") == 8\n assert candidate(s = \"000000000000000000000000000111111111111111111111111111111111111111111111111\") == 74\n assert candidate(s = \"01001010100101010010\") == 11\n assert candidate(s = \"11101110111011101110111011101110111011101110\") == 30\n assert candidate(s = \"00000000111111111111\") == 19\n assert candidate(s = \"1100110011001100\") == 7\n assert candidate(s = \"111011101110111011101110111011101110111011101110\") == 33\n assert candidate(s = \"000111000111000111000111000111000111\") == 20\n assert candidate(s = \"10101010101010101010101010\") == 12\n assert candidate(s = \"00000000000000001111111111111111\") == 31\n assert candidate(s = \"111000111000111\") == 8\n assert candidate(s = \"10110011001100110011\") == 10\n assert candidate(s = \"010101010101010101\") == 9\n assert candidate(s = \"0000000000000000000011111111111111111111\") == 39\n assert candidate(s = \"1100110011001100110011001100110011001100\") == 19\n assert candidate(s = \"1010101010101010\") == 7\n assert candidate(s = \"111111000000111111000000\") == 11\n assert candidate(s = \"11110000011110000111\") == 11\n assert candidate(s = \"111100001111000011110000\") == 11\n assert candidate(s = \"111111111111111111110000000000000000\") == 0\n assert candidate(s = \"0011001100110011\") == 9\n assert candidate(s = \"00000111111111\") == 13\n assert candidate(s = \"11111000001111100000\") == 9\n assert candidate(s = \"111111100000000\") == 0\n assert candidate(s = \"0000111100001111000011110000\") == 15\n assert candidate(s = \"01001000100001000001\") == 15\n assert candidate(s = \"00000101010111111\") == 13\n assert candidate(s = \"0110110110110110\") == 10\n assert candidate(s = \"01010101010101010101010101\") == 13\n assert candidate(s = \"11110000111100001111\") == 11\n assert candidate(s = \"01101101101101\") == 9\n assert candidate(s = \"000000001111111100000000\") == 15\n assert candidate(s = \"101010101010\") == 5\n assert candidate(s = \"000000011111111\") == 14\n assert candidate(s = \"110000000000001111\") == 15\n assert candidate(s = \"01001000100000001001\") == 15\n assert candidate(s = \"01010101010101010101010101010101010101010101010101\") == 25\n assert candidate(s = \"001001001001001001001001\") == 16\n assert candidate(s = \"000101010101\") == 7\n assert candidate(s = \"10010010010010\") == 8\n assert candidate(s = \"0000001111111111\") == 15\n assert candidate(s = \"00000000001111111111\") == 19\n assert candidate(s = \"000000001111111111111111\") == 23\n assert candidate(s = \"00000111110000011111\") == 14\n assert candidate(s = \"01010010101101\") == 8\n assert candidate(s = \"11101110000111000011\") == 10\n assert candidate(s = \"1001001001001001\") == 10\n assert candidate(s = \"11001100110011001100\") == 9\n assert candidate(s = \"00111100001111000011\") == 11\n assert candidate(s = \"01010101010101010101010101010101\") == 16\n assert candidate(s = \"10010010010010010010\") == 12\n assert candidate(s = \"1010101010101010101010101010\") == 13\n assert candidate(s = \"01001100110011001100\") == 10\n assert candidate(s = \"1000000000000000000000000000000000000000\") == 0\n assert candidate(s = \"111000111000\") == 5\n assert candidate(s = \"11000011110000\") == 7\n assert candidate(s = \"11111000000000\") == 0\n assert candidate(s = \"10101101010010\") == 6\n assert candidate(s = \"000000001111111111\") == 17\n assert candidate(s = \"10010101010101010101\") == 10\n assert candidate(s = \"0101010101010101\") == 8\n assert candidate(s = \"11111111111111111110\") == 0\n assert candidate(s = \"0000000000000000001\") == 18\n assert candidate(s = \"111111110000000011111111\") == 15\n assert candidate(s = \"00000111111111111111100000\") == 20\n assert candidate(s = \"0101010101010101010101010101\") == 14\n assert candidate(s = \"00010001000100010001\") == 15\n assert candidate(s = \"1111111111111111111111111111111111111111\") == 0\n assert candidate(s = \"11111100000011111100\") == 11\n assert candidate(s = \"00110011001100110011\") == 11\n assert candidate(s = \"11111111000000000000\") == 0\n assert candidate(s = \"00010010010010010010010010010010010010010010\") == 29\n assert candidate(s = \"00000111100001111000\") == 12\n assert candidate(s = \"1001001001001001001001001\") == 16\n assert candidate(s = \"01010101010101010101010101010101010101010101010101010101\") == 28\n assert candidate(s = \"00100100100100100100100100100100100100100100\") == 28\n assert candidate(s = \"01010101010101\") == 7\n assert candidate(s = \"10101010100101010101\") == 10\n assert candidate(s = \"00101010101010101010101010\") == 13\n assert candidate(s = \"000001000001000001000001000001000001\") == 30\n assert candidate(s = \"1010101010101010101010101010101010101010\") == 19\n assert candidate(s = \"1001001001001001001001001001001001001001001001001\") == 32\n assert candidate(s = \"1111000011110000111100001111\") == 15\n assert candidate(s = \"111110000011111\") == 9\n assert candidate(s = \"11111010101000000\") == 3\n assert candidate(s = \"01010101010101010101010101010101010101010101\") == 22\n assert candidate(s = \"01010101010101010101\") == 10\n assert candidate(s = \"111111110000000011111111000000001111\") == 19\n assert candidate(s = \"00011111100000111110\") == 13\n assert candidate(s = \"0000000000000000000000000000000000000001\") == 39\n assert candidate(s = \"11000011110000111100\") == 11\n assert candidate(s = \"01101101101101101101\") == 13\n assert candidate(s = \"10101010101010101010\") == 9\n assert candidate(s = \"11111111111111110000000000000000\") == 0\n assert candidate(s = \"100110011001100110011001\") == 12\n assert candidate(s = \"110110110110110110\") == 10\n assert candidate(s = \"00101010101000\") == 6\n assert candidate(s = \"11111111111111110000000000\") == 0\n assert candidate(s = \"000111000111000\") == 8\n assert candidate(s = \"001001001001001001\") == 12\n assert candidate(s = \"1000000000000001\") == 14\n assert candidate(s = \"0000111100001111\") == 11\n", "comparison": "exact"}, "public_tests": ["\"0110101\"", "\"11100\""], "hints": ["Try replicating the steps from the problem statement.", "Perform the replacements simultaneously, and return the number of times the process repeats."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().secondsToRemoveOccurrences", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:39+00:00", "tests_total": 127, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "simulation"]}, "language": "php", "interface": {"raw_signature": "function secondsToRemoveOccurrences($s) {", "container": "Solution", "callable": "secondsToRemoveOccurrences", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2381, "task_id": "shifting-letters-ii", "difficulty": "Medium", "problem_description": "You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [start_i, end_i, direction_i]. For every i, shift the characters in s from the index start_i to the index end_i (inclusive) forward if direction_i = 1, or shift the characters backward if direction_i = 0.\n\nShifting a character forward means replacing it with the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Similarly, shifting a character backward means replacing it with the previous letter in the alphabet (wrapping around so that 'a' becomes 'z').\n\nReturn the final string after all such shifts to s are applied.\n\nExample 1:\n\nInput: s = \"abc\", shifts = [[0,1,0],[1,2,1],[0,2,1]]\nOutput: \"ace\"\nExplanation: Firstly, shift the characters from index 0 to index 1 backward. Now s = \"zac\".\nSecondly, shift the characters from index 1 to index 2 forward. Now s = \"zbd\".\nFinally, shift the characters from index 0 to index 2 forward. Now s = \"ace\".\n\nExample 2:\n\nInput: s = \"dztz\", shifts = [[0,0,0],[1,1,1]]\nOutput: \"catz\"\nExplanation: Firstly, shift the characters from index 0 to index 0 backward. Now s = \"cztz\".\nFinally, shift the characters from index 1 to index 1 forward. Now s = \"catz\".\n\nConstraints:\n\n- 1 <= s.length, shifts.length <= 5 * 10^4\n- shifts[i].length == 3\n- 0 <= start_i <= end_i < s.length\n- 0 <= direction_i <= 1\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"world\",shifts = [[0, 4, 0], [0, 4, 0], [0, 4, 0], [0, 4, 0]]) == \"sknhz\"\n assert candidate(s = \"abc\",shifts = [[0, 1, 0], [1, 2, 1], [0, 2, 1]]) == \"ace\"\n assert candidate(s = \"xyz\",shifts = [[0, 2, 0]]) == \"wxy\"\n assert candidate(s = \"abcdef\",shifts = [[1, 4, 1], [2, 3, 0]]) == \"accdff\"\n assert candidate(s = \"aaa\",shifts = [[0, 2, 1], [0, 2, 1], [0, 2, 1]]) == \"ddd\"\n assert candidate(s = \"hello\",shifts = [[0, 4, 1], [1, 3, 0]]) == \"iellp\"\n assert candidate(s = \"hello\",shifts = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1]]) == \"ignnp\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1]]) == \"bcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"dztz\",shifts = [[0, 0, 0], [1, 1, 1]]) == \"catz\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",shifts = [[0, 25, 0]]) == \"yxwvutsrqponmlkjihgfedcbaz\"\n assert candidate(s = \"a\",shifts = [[0, 0, 1], [0, 0, 0]]) == \"a\"\n assert candidate(s = \"abcd\",shifts = [[0, 3, 1], [1, 2, 0], [2, 3, 1]]) == \"bbdf\"\n assert candidate(s = \"zzz\",shifts = [[0, 2, 0], [0, 2, 0], [0, 2, 0]]) == \"www\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 0]]) == \"zabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"hello\",shifts = [[0, 4, 1]]) == \"ifmmp\"\n assert candidate(s = \"zzzzzzzzzz\",shifts = [[0, 4, 0], [5, 9, 1], [0, 9, 1], [3, 6, 0]]) == \"zzzyyaabbb\"\n assert candidate(s = \"alphabet\",shifts = [[0, 0, 1], [1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0], [5, 5, 1]]) == \"bkqgbbet\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [5, 10, 0], [15, 20, 1]]) == \"bcdeffghijkmnoprstuvwwxyza\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",shifts = [[0, 51, 1], [10, 40, 0], [20, 30, 1], [30, 40, 0]]) == \"bbccddeeffffgghhiijjllmmnnoopppoppqqrrsstvwwxxyyzzaa\"\n assert candidate(s = \"abacax\",shifts = [[0, 5, 1], [1, 4, 0], [2, 3, 1], [0, 5, 0]]) == \"aaaczx\"\n assert candidate(s = \"programming\",shifts = [[0, 9, 1], [1, 8, 0], [2, 7, 1], [3, 6, 0], [4, 5, 1], [5, 5, 0], [6, 6, 1], [7, 7, 0], [8, 8, 1], [9, 9, 0]]) == \"qrpgsanmjng\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 9, 0], [1, 8, 1], [2, 7, 0], [3, 6, 1], [4, 5, 0]]) == \"zbbddeggii\"\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijkl\",shifts = [[0, 25, 1], [5, 15, 0], [10, 20, 1], [15, 25, 0]]) == \"nopqrrstuvxyzabbdefghhijkl\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [0, 25, 1], [0, 25, 1], [0, 25, 0]]) == \"cdefghijklmnopqrstuvwxyzab\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [0, 25, 0], [0, 25, 1], [0, 25, 0]]) == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abababab\",shifts = [[0, 7, 1], [1, 6, 0], [2, 5, 1], [3, 4, 0]]) == \"bbbbacac\"\n assert candidate(s = \"zzzzzzzzzz\",shifts = [[0, 9, 1], [2, 8, 0], [4, 6, 1]]) == \"aazzaaazza\"\n assert candidate(s = \"algorithm\",shifts = [[0, 2, 1], [3, 5, 0], [6, 8, 1], [1, 4, 0], [2, 3, 1], [5, 7, 0], [7, 8, 1]]) == \"blhnpgtio\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 9, 1], [0, 9, 0], [0, 9, 1], [0, 9, 0], [0, 9, 1], [0, 9, 0], [0, 9, 1], [0, 9, 0], [0, 9, 1], [0, 9, 0]]) == \"abcdefghij\"\n assert candidate(s = \"codingame\",shifts = [[0, 1, 1], [2, 3, 0], [4, 5, 1], [6, 7, 0], [8, 8, 1], [0, 8, 0], [0, 8, 1], [0, 8, 0], [0, 8, 1]]) == \"dpchohzlf\"\n assert candidate(s = \"abacabadabacaba\",shifts = [[0, 14, 1], [1, 13, 0], [2, 12, 1], [3, 11, 0], [4, 10, 1], [5, 9, 0]]) == \"bbbcbbadabbcbbb\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 4, 1], [5, 9, 0], [0, 4, 0], [5, 9, 1], [0, 9, 1]]) == \"bcdefghijk\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [1, 24, 0], [2, 23, 1], [3, 22, 0], [4, 21, 1]]) == \"bbddfghijklmnopqrstuvwwyya\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",shifts = [[0, 25, 0], [5, 10, 1], [15, 20, 0]]) == \"yxwvuutsrqpnmlkihgfeddcbaz\"\n assert candidate(s = \"zzzzz\",shifts = [[0, 4, 0], [0, 4, 0], [0, 4, 0], [0, 4, 0], [0, 4, 1]]) == \"wwwww\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 9, 1], [1, 8, 0], [2, 7, 1], [3, 6, 0], [4, 5, 1]]) == \"bbddfggiik\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 9, 1], [0, 9, 0], [0, 9, 1], [0, 9, 0], [0, 9, 1]]) == \"bcdefghijk\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzz\",shifts = [[0, 25, 1], [5, 15, 0], [10, 20, 1]]) == \"aaaaazzzzzaaaaaabbbbbaaaaa\"\n assert candidate(s = \"abcdefghijklmnop\",shifts = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1], [11, 11, 1], [12, 12, 1], [13, 13, 1], [14, 14, 1], [15, 15, 1]]) == \"bcdefghijklmnopq\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 12, 1], [13, 25, 0], [0, 25, 1], [0, 25, 0], [0, 25, 1]]) == \"cdefghijklmnonopqrstuvwxyz\"\n assert candidate(s = \"alibabacloud\",shifts = [[0, 9, 1], [2, 4, 0], [5, 7, 1], [8, 11, 0], [0, 3, 1], [6, 9, 0], [1, 8, 1], [2, 7, 0]]) == \"cojcadbdlntc\"\n assert candidate(s = \"xyz\",shifts = [[0, 2, 1], [0, 2, 1], [0, 2, 0], [0, 2, 0]]) == \"xyz\"\n assert candidate(s = \"abcdefg\",shifts = [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1]]) == \"bdefghh\"\n assert candidate(s = \"abacabadabacaba\",shifts = [[0, 4, 1], [5, 9, 0], [10, 14, 1], [0, 14, 0], [0, 14, 1]]) == \"bcbdbazczabdbcb\"\n assert candidate(s = \"example\",shifts = [[0, 6, 1], [1, 5, 0], [2, 4, 1], [3, 6, 0]]) == \"fxbmpke\"\n assert candidate(s = \"abcdefg\",shifts = [[0, 6, 1], [1, 5, 0], [2, 4, 1], [3, 3, 0]]) == \"bbddffh\"\n assert candidate(s = \"hellozworld\",shifts = [[0, 4, 1], [5, 9, 0], [6, 10, 1], [7, 8, 0], [9, 10, 1], [10, 10, 0]]) == \"ifmmpywnqme\"\n assert candidate(s = \"abcde\",shifts = [[0, 2, 1], [3, 4, 0], [1, 3, 1], [0, 1, 0], [4, 4, 1], [2, 2, 0]]) == \"acdde\"\n assert candidate(s = \"xylophone\",shifts = [[0, 8, 1], [1, 7, 0], [2, 6, 1], [3, 5, 0], [4, 4, 1]]) == \"yymoqhpnf\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [0, 25, 0], [0, 25, 1], [0, 25, 0], [0, 25, 1]]) == \"bcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"programming\",shifts = [[0, 9, 1], [4, 8, 0], [2, 6, 1], [1, 7, 0], [0, 8, 1]]) == \"rsqisbnmjog\"\n assert candidate(s = \"shiftmeplease\",shifts = [[0, 1, 1], [2, 3, 0], [4, 5, 1], [6, 7, 0], [8, 9, 1], [10, 11, 0], [12, 12, 1]]) == \"tiheundomfzrf\"\n assert candidate(s = \"quickbrownfox\",shifts = [[0, 12, 1], [1, 11, 0], [2, 10, 1], [3, 9, 0], [4, 8, 1], [5, 7, 0]]) == \"rujclbroxngoy\"\n assert candidate(s = \"mnopqr\",shifts = [[0, 2, 1], [3, 5, 0], [0, 5, 1], [1, 4, 0]]) == \"oopopr\"\n assert candidate(s = \"abcdefghijklmnop\",shifts = [[0, 15, 1], [1, 14, 0], [2, 13, 1], [3, 12, 0], [4, 11, 1], [5, 10, 0], [6, 9, 1], [7, 8, 0]]) == \"bbddffhhikkmmooq\"\n assert candidate(s = \"zzzzzzzzzz\",shifts = [[0, 9, 1], [1, 8, 0], [2, 7, 1], [3, 6, 0], [4, 5, 1]]) == \"azazaazaza\"\n assert candidate(s = \"mississippi\",shifts = [[0, 4, 0], [1, 3, 1], [2, 2, 0], [3, 5, 1], [6, 8, 0], [7, 7, 1], [8, 10, 0], [9, 9, 1], [10, 10, 0]]) == \"lirtitrinpg\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 0, 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, 0], [10, 10, 0], [11, 11, 0], [12, 12, 0], [13, 13, 0], [14, 14, 0], [15, 15, 0], [16, 16, 0], [17, 17, 0], [18, 18, 0], [19, 19, 0], [20, 20, 0], [21, 21, 0], [22, 22, 0], [23, 23, 0], [24, 24, 1], [25, 25, 1]]) == \"zabcdefghijklmnopqrstuvwza\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [5, 15, 0], [10, 20, 1]]) == \"bcdeffghijlmnopqstuvwwxyza\"\n assert candidate(s = \"programming\",shifts = [[0, 8, 1], [3, 7, 0], [2, 5, 1], [4, 10, 0], [1, 9, 1]]) == \"qtrisbmmjnf\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1], [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]]) == \"bcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"abcdefgh\",shifts = [[0, 0, 0], [7, 7, 1], [2, 2, 1], [5, 5, 0], [3, 3, 1]]) == \"zbdeeegi\"\n assert candidate(s = \"a\",shifts = [[0, 0, 1], [0, 0, 0], [0, 0, 1], [0, 0, 0]]) == \"a\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 25, 1], [0, 25, 1], [0, 25, 1], [0, 25, 1], [0, 25, 1]]) == \"fghijklmnopqrstuvwxyzabcde\"\n assert candidate(s = \"abcdefg\",shifts = [[0, 1, 0], [1, 2, 0], [2, 3, 0], [3, 4, 0], [4, 5, 0], [5, 6, 0]]) == \"zzabcdf\"\n assert candidate(s = \"mnopqr\",shifts = [[0, 0, 1], [1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0]]) == \"nmporq\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 4, 0], [5, 9, 1], [0, 9, 1], [1, 8, 0], [2, 7, 1], [3, 6, 0], [4, 5, 1]]) == \"aaccehhjjl\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 1, 1], [2, 3, 0], [4, 5, 1], [6, 7, 0], [8, 9, 1]]) == \"bcbcfgfgjk\"\n assert candidate(s = \"mississippi\",shifts = [[0, 2, 1], [2, 4, 0], [4, 6, 1], [6, 8, 0], [8, 10, 1]]) == \"njsritshpqj\"\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",shifts = [[0, 9, 1], [10, 19, 0], [20, 25, 1], [0, 19, 0], [10, 25, 1], [0, 25, 0], [0, 25, 1]]) == \"qwertyuiopzrcefgijkyzexdpo\"\n assert candidate(s = \"aaaabbbbcccc\",shifts = [[0, 3, 1], [4, 7, 0], [8, 11, 1], [0, 11, 1]]) == \"ccccbbbbeeee\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",shifts = [[0, 51, 1], [0, 51, 0], [0, 51, 1], [0, 51, 0], [0, 51, 1]]) == \"bbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaa\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",shifts = [[0, 13, 0], [13, 25, 1], [0, 25, 0], [0, 25, 1]]) == \"yxwvutsrqponmmmlkjihgfedcb\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",shifts = [[0, 25, 0], [0, 25, 0], [0, 25, 0], [0, 25, 0], [0, 25, 0]]) == \"utsrqponmlkjihgfedcbazyxwv\"\n assert candidate(s = \"shiftthis\",shifts = [[0, 0, 1], [1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0], [6, 6, 1], [7, 7, 0], [8, 8, 1]]) == \"tgjeusiht\"\n assert candidate(s = \"abcd\",shifts = [[0, 3, 1], [0, 2, 0], [1, 3, 1], [1, 2, 0], [2, 3, 1]]) == \"abdg\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\",shifts = [[0, 25, 1], [1, 24, 0], [2, 23, 1], [3, 22, 0]]) == \"bbddefghijklmnopqrstuvwyyaa\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1], [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, 0], [25, 25, 0]]) == \"bcdefghijklmnopqrstuvwxyxy\"\n assert candidate(s = \"python\",shifts = [[0, 5, 1], [1, 4, 0], [2, 3, 1], [0, 5, 0], [1, 4, 1]]) == \"pyuion\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 0, 1], [1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0], [6, 6, 1], [7, 7, 0], [8, 8, 1], [9, 9, 0]]) == \"badcfehgji\"\n assert candidate(s = \"zzzzzzzzzz\",shifts = [[0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1], [0, 9, 1]]) == \"jjjjjjjjjj\"\n assert candidate(s = \"xyzxyzxyz\",shifts = [[0, 2, 1], [3, 5, 0], [6, 8, 1], [0, 5, 1], [3, 8, 0], [0, 8, 1]]) == \"abcxyzyza\"\n assert candidate(s = \"aaaabbbb\",shifts = [[0, 3, 1], [4, 7, 0], [2, 5, 1], [1, 6, 0]]) == \"babbaaza\"\n assert candidate(s = \"zzzzzzzz\",shifts = [[0, 7, 1], [1, 6, 0], [2, 5, 1], [3, 4, 0]]) == \"azazzaza\"\n assert candidate(s = \"abcdefghij\",shifts = [[0, 4, 1], [1, 8, 0], [2, 7, 1], [3, 6, 0], [4, 5, 1]]) == \"bbddfffhhj\"\n assert candidate(s = \"abcdabcdabcd\",shifts = [[0, 3, 1], [4, 7, 0], [8, 11, 1], [0, 11, 0], [0, 11, 1]]) == \"bcdezabcbcde\"\n assert candidate(s = \"zzzzzzzzzz\",shifts = [[0, 9, 1], [0, 9, 0], [1, 8, 1], [1, 8, 0], [2, 7, 1], [2, 7, 0], [3, 6, 1], [3, 6, 0], [4, 5, 1], [4, 5, 0]]) == \"zzzzzzzzzz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",shifts = [[0, 0, 1], [1, 1, 0], [2, 2, 1], [3, 3, 0], [4, 4, 1], [5, 5, 0], [6, 6, 1], [7, 7, 0], [8, 8, 1], [9, 9, 0], [10, 10, 1], [11, 11, 0], [12, 12, 1], [13, 13, 0], [14, 14, 1], [15, 15, 0], [16, 16, 1], [17, 17, 0], [18, 18, 1], [19, 19, 0], [20, 20, 1], [21, 21, 0], [22, 22, 1], [23, 23, 0], [24, 24, 1], [25, 25, 0]]) == \"badcfehgjilknmporqtsvuxwzy\"\n assert candidate(s = \"xyzabc\",shifts = [[0, 2, 1], [3, 5, 0], [1, 4, 1], [2, 5, 0], [0, 5, 1]]) == \"zbbabb\"\n assert candidate(s = \"programming\",shifts = [[0, 3, 1], [4, 8, 0], [6, 10, 1], [7, 9, 0], [1, 5, 1]]) == \"qtqiramlhnh\"\n", "comparison": "exact"}, "public_tests": ["\"abc\"\n[[0,1,0],[1,2,1],[0,2,1]]", "\"dztz\"\n[[0,0,0],[1,1,1]]"], "hints": ["Instead of shifting every character in each shift, could you keep track of which characters are shifted and by how much across all shifts?", "Try marking the start and ends of each shift, then perform a prefix sum of the shifts."], "metadata": {"canonical_parameter_names": ["s", "shifts"], "leetcode_dataset_entry_point": "Solution().shiftingLetters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:41+00:00", "tests_total": 94, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "string", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function shiftingLetters($s, $shifts) {", "container": "Solution", "callable": "shiftingLetters", "parameters": [{"name": "s", "type": "String"}, {"name": "shifts", "type": "Integer[][]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2382, "task_id": "maximum-segment-sum-after-removals", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the i^th query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments.\n\nA segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a segment.\n\nReturn an integer array answer, of length n, where answer[i] is the maximum segment sum after applying the i^th removal.\n\nNote: The same index will not be removed more than once.\n\nExample 1:\n\nInput: nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]\nOutput: [14,7,2,2,0]\nExplanation: Using 0 to indicate a removed element, the answer is as follows:\nQuery 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].\nQuery 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].\nQuery 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2].\nQuery 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2].\nQuery 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.\nFinally, we return [14,7,2,2,0].\n\nExample 2:\n\nInput: nums = [3,2,11,1], removeQueries = [3,2,1,0]\nOutput: [16,5,3,0]\nExplanation: Using 0 to indicate a removed element, the answer is as follows:\nQuery 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].\nQuery 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].\nQuery 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].\nQuery 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.\nFinally, we return [16,5,3,0].\n\nConstraints:\n\n- n == nums.length == removeQueries.length\n- 1 <= n <= 10^5\n- 1 <= nums[i] <= 10^9\n- 0 <= removeQueries[i] < n\n- All the values of removeQueries are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 5, 6, 1],removeQueries = [0, 3, 2, 4, 1]) == [14, 7, 2, 2, 0]\n assert candidate(nums = [5, 1, 4, 3, 2],removeQueries = [2, 0, 4, 1, 3]) == [6, 5, 3, 3, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000],removeQueries = [0, 1, 2]) == [2000000000, 1000000000, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],removeQueries = [4, 3, 2, 1, 0]) == [100, 60, 30, 10, 0]\n assert candidate(nums = [5, 1, 4, 3],removeQueries = [1, 2, 0, 3]) == [7, 5, 3, 0]\n assert candidate(nums = [3, 2, 11, 1],removeQueries = [3, 2, 1, 0]) == [16, 5, 3, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],removeQueries = [0, 1, 2, 3, 4]) == [140, 120, 90, 50, 0]\n assert candidate(nums = [10, 20, 30, 40, 50],removeQueries = [2, 4, 0, 1, 3]) == [90, 40, 40, 40, 0]\n assert candidate(nums = [5, 2, 3, 1, 4],removeQueries = [2, 0, 4, 3, 1]) == [7, 5, 2, 2, 0]\n assert candidate(nums = [1, 1, 1, 1, 1],removeQueries = [0, 1, 2, 3, 4]) == [4, 3, 2, 1, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000],removeQueries = [0, 1, 2]) == [2000000000, 1000000000, 0]\n assert candidate(nums = [5, 1, 3, 2, 4],removeQueries = [2, 0, 1, 3, 4]) == [6, 6, 6, 4, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],removeQueries = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [5, 2, 3, 1, 4],removeQueries = [2, 0, 3, 4, 1]) == [7, 5, 4, 2, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [9000000000, 8000000000, 7000000000, 6000000000, 5000000000, 4000000000, 3000000000, 2000000000, 1000000000, 0]\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000],removeQueries = [5, 4, 3, 2, 1, 0]) == [111110, 11110, 1110, 110, 10, 0]\n assert candidate(nums = [9, 1, 5, 3, 2, 4, 8, 6, 7, 10],removeQueries = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == [46, 36, 35, 28, 23, 17, 14, 6, 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],removeQueries = [0, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [324, 299, 275, 252, 230, 209, 189, 170, 152, 135, 119, 104, 90, 77, 65, 54, 44, 35, 27, 20, 14, 9, 5, 2, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],removeQueries = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == [5400, 4900, 4000, 2700, 1000, 1000, 1000, 1000, 1000, 0]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],removeQueries = [3, 6, 0, 5, 1, 7, 2, 4]) == [130, 55, 55, 40, 40, 25, 25, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],removeQueries = [14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == [105, 104, 102, 99, 95, 90, 84, 77, 69, 60, 50, 39, 27, 14, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [4, 2, 6, 8, 0, 1, 3, 5, 7, 9]) == [400, 400, 270, 100, 100, 100, 100, 100, 100, 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],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [380, 342, 306, 272, 240, 210, 182, 156, 132, 110, 90, 72, 56, 42, 30, 20, 12, 6, 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],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],removeQueries = [14, 0, 7, 2, 9, 4, 12, 6, 11, 3, 8, 13, 5, 10, 1]) == [196, 195, 132, 132, 96, 96, 44, 44, 27, 27, 27, 21, 21, 3, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],removeQueries = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 3, 4, 0, 1]) == [65, 61, 58, 56, 55, 54, 52, 49, 45, 40, 40, 40, 40, 40, 40, 19, 19, 19, 9, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000],removeQueries = [2, 0, 1, 3]) == [2000000000, 1000000000, 1000000000, 0]\n assert candidate(nums = [100, 200, 300, 400, 500],removeQueries = [4, 3, 2, 1, 0]) == [1000, 600, 300, 100, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [5, 2, 8, 0, 4, 7, 1, 9, 6, 3]) == [340, 340, 150, 150, 150, 100, 100, 70, 40, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [5, 2, 8, 1, 7, 4, 3, 9, 6, 0]) == [340, 340, 150, 150, 100, 100, 100, 70, 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],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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],removeQueries = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [190, 153, 120, 91, 66, 45, 28, 19, 19, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],removeQueries = [14, 1, 2, 12, 0, 3, 4, 13, 5, 6, 11, 7, 8, 9, 10]) == [10500, 10200, 9900, 7200, 7200, 6800, 6300, 6300, 5700, 5000, 3800, 3000, 2100, 1100, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],removeQueries = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 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],removeQueries = [19, 9, 18, 8, 17, 7, 16, 6, 15, 5, 14, 4, 13, 3, 12, 2, 11, 1, 10, 0]) == [1900, 1350, 1160, 1160, 980, 980, 810, 810, 650, 650, 500, 500, 360, 360, 230, 230, 110, 110, 10, 0]\n assert candidate(nums = [31, 41, 59, 26, 53, 58, 97, 93, 23, 84, 62, 64, 33, 83, 27, 95, 28, 84, 19, 71],removeQueries = [10, 18, 8, 12, 17, 19, 16, 7, 5, 0, 14, 2, 15, 9, 6, 13, 3, 4, 11, 1]) == [565, 565, 458, 458, 458, 458, 458, 365, 210, 205, 179, 97, 97, 97, 83, 79, 64, 64, 41, 0]\n assert candidate(nums = [2, 1, 3, 4, 2, 3, 4, 1, 5, 6, 7, 8, 9, 10],removeQueries = [1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12]) == [62, 55, 50, 45, 34, 19, 9, 9, 9, 9, 9, 9, 9, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]) == [540, 490, 400, 270, 100, 100, 100, 100, 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],removeQueries = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == [190, 153, 120, 91, 66, 45, 28, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [5, 3, 7, 1, 9, 4, 0, 6, 8, 2]) == [340, 340, 190, 190, 90, 90, 90, 90, 30, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],removeQueries = [4, 2, 6, 8, 0, 3, 5, 7, 9, 1]) == [4000, 4000, 2700, 1000, 1000, 1000, 1000, 1000, 200, 0]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [89, 85, 77, 74, 72, 69, 60, 53, 44, 39, 36, 31, 25, 23, 14, 9, 8, 4, 3, 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],removeQueries = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]) == [190, 153, 120, 91, 66, 45, 28, 19, 19, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],removeQueries = [2, 4, 6, 8, 10, 12, 14, 0, 1, 3, 5, 7, 9, 11, 13]) == [11400, 10500, 9200, 7500, 5400, 2900, 1400, 1400, 1400, 1400, 1400, 1400, 1400, 1400, 0]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],removeQueries = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [1996093750, 1992187500, 1984375000, 1968750000, 1937500000, 1875000000, 1750000000, 1500000000, 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],removeQueries = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == [19, 17, 15, 13, 11, 9, 7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [46, 39, 34, 31, 30, 28, 24, 18, 10, 0]\n assert candidate(nums = [5, 1, 4, 3, 9, 8, 7, 2, 6],removeQueries = [2, 5, 0, 3, 4, 8, 6, 7, 1]) == [35, 15, 15, 15, 15, 9, 2, 1, 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],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [4, 8, 3, 7, 2, 6, 1, 5, 0]) == [30, 30, 24, 24, 17, 17, 9, 9, 0]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [45, 36, 28, 21, 15, 10, 6, 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],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [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],removeQueries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 132, 119, 105, 90, 74, 57, 39, 20, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [5, 7, 3, 1, 9, 0, 8, 6, 2, 4]) == [340, 190, 190, 190, 90, 90, 70, 50, 50, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],removeQueries = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [9000000000, 8000000000, 7000000000, 6000000000, 5000000000, 4000000000, 3000000000, 2000000000, 1000000000, 0]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6],removeQueries = [5, 0, 4, 9, 2, 8, 6, 3, 7, 1]) == [25, 24, 22, 21, 16, 11, 10, 10, 10, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],removeQueries = [14, 1, 2, 12, 0, 3, 4, 13, 5, 6, 11, 7, 8, 9, 10]) == [105, 102, 99, 72, 72, 68, 63, 63, 57, 50, 38, 30, 21, 11, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],removeQueries = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [9000000000, 8000000000, 7000000000, 6000000000, 5000000000, 4000000000, 3000000000, 2000000000, 1000000000, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],removeQueries = [7, 14, 0, 13, 1, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6]) == [840, 690, 690, 550, 550, 420, 420, 300, 300, 190, 190, 130, 90, 70, 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],removeQueries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]) == [90, 80, 70, 60, 50, 40, 30, 20, 10, 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],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [1999996181, 1999992367, 1999984738, 1999969480, 1999938963, 1999877928, 1999755858, 1999511718, 1999023437, 1998046875, 1996093750, 1992187500, 1984375000, 1968750000, 1937500000, 1875000000, 1750000000, 1500000000, 1000000000, 0]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200],removeQueries = [11, 5, 3, 7, 9, 1, 8, 10, 4, 2, 6, 0]) == [6600, 4500, 4500, 3000, 1100, 1100, 1100, 700, 700, 700, 100, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8]) == [36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [0, 8, 1, 7, 2, 6, 3, 5, 4]) == [36, 35, 27, 25, 18, 15, 9, 5, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],removeQueries = [0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13]) == [54, 50, 44, 37, 29, 20, 10, 5, 5, 5, 5, 5, 5, 5, 0]\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115],removeQueries = [7, 15, 3, 11, 13, 5, 9, 1, 12, 14, 8, 10, 6, 2, 4, 0]) == [892, 777, 777, 339, 327, 327, 303, 114, 114, 110, 110, 106, 104, 104, 100, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [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],removeQueries = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],removeQueries = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [0, 8, 1, 7, 2, 6, 3, 5, 4]) == [36, 35, 27, 25, 18, 15, 9, 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],removeQueries = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],removeQueries = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == [209, 206, 204, 199, 195, 189, 182, 174, 165, 155, 144, 132, 119, 105, 90, 74, 57, 39, 20, 0]\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],removeQueries = [15, 10, 5, 0, 19, 14, 9, 4, 18, 13, 8, 3, 17, 12, 7, 2, 16, 11, 6, 1]) == [120, 74, 74, 74, 54, 54, 54, 54, 39, 35, 35, 35, 25, 17, 17, 17, 12, 7, 4, 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],removeQueries = [10, 5, 15, 2, 18, 8, 0, 17, 3, 14, 9, 11, 7, 1, 12, 6, 13, 4, 16, 19]) == [10, 9, 5, 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6],removeQueries = [10, 2, 16, 14, 18, 6, 8, 12, 4, 1, 13, 7, 15, 3, 9, 19, 11, 5, 17, 0]) == [47, 47, 31, 31, 31, 17, 17, 15, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 3, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [5, 7, 9, 1, 3, 8, 2, 6, 4, 0]) == [340, 190, 150, 120, 90, 70, 70, 50, 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],removeQueries = [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]) == [435, 406, 378, 351, 325, 300, 276, 253, 231, 210, 190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],removeQueries = [7, 3, 9, 13, 5, 11, 1, 6, 2, 14, 8, 0, 12, 10, 4]) == [840, 840, 650, 360, 360, 150, 150, 150, 150, 130, 130, 130, 110, 50, 0]\n assert candidate(nums = [5, 2, 3, 1, 4, 6, 8, 7, 9, 10],removeQueries = [4, 0, 3, 2, 5, 1, 8, 9, 7, 6]) == [40, 40, 40, 40, 34, 34, 15, 15, 8, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],removeQueries = [0, 2, 4, 6, 8, 1, 3, 5, 7]) == [36, 21, 10, 8, 8, 6, 4, 2, 0]\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],removeQueries = [0, 1, 2, 3, 4]) == [4000000000, 3000000000, 2000000000, 1000000000, 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, 45, 46, 47, 48, 49, 50],removeQueries = [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]) == [1225, 1176, 1128, 1081, 1035, 990, 946, 903, 861, 820, 780, 741, 703, 666, 630, 595, 561, 528, 496, 465, 435, 406, 378, 351, 325, 300, 276, 253, 231, 210, 190, 171, 153, 136, 120, 105, 91, 78, 66, 55, 45, 36, 28, 21, 15, 10, 6, 3, 1, 0]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],removeQueries = [4, 2, 7, 5, 8, 1, 0, 9, 3, 6]) == [400, 400, 190, 190, 100, 100, 100, 70, 70, 0]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],removeQueries = [5, 7, 3, 9, 1, 6, 0, 8, 2, 4]) == [64, 36, 36, 17, 17, 17, 17, 9, 9, 0]\n", "comparison": "exact"}, "public_tests": ["[1,2,5,6,1]\n[0,3,2,4,1]", "[3,2,11,1]\n[3,2,1,0]"], "hints": ["Use a sorted data structure to collect removal points and store the segments.", "Use a heap or priority queue to store segment sums and their corresponding boundaries.", "Make sure to remove invalid segments from the heap."], "metadata": {"canonical_parameter_names": ["nums", "removeQueries"], "leetcode_dataset_entry_point": "Solution().maximumSegmentSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:44+00:00", "tests_total": 90, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "union-find", "prefix-sum", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function maximumSegmentSum($nums, $removeQueries) {", "container": "Solution", "callable": "maximumSegmentSum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "removeQueries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2383, "task_id": "minimum-hours-of-training-to-win-a-competition", "difficulty": "Easy", "problem_description": "You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.\n\nYou are also given two 0-indexed integer arrays energy and experience, both of length n.\n\nYou will face n opponents in order. The energy and experience of the i^th opponent is denoted by energy[i] and experience[i] respectively. When you face an opponent, you need to have both strictly greater experience and energy to defeat them and move to the next opponent if available.\n\nDefeating the i^th opponent increases your experience by experience[i], but decreases your energy by energy[i].\n\nBefore starting the competition, you can train for some number of hours. After each hour of training, you can either choose to increase your initial experience by one, or increase your initial energy by one.\n\nReturn the minimum number of training hours required to defeat all n opponents.\n\nExample 1:\n\nInput: initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]\nOutput: 8\nExplanation: You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.\nYou face the opponents in the following order:\n- You have more energy and experience than the 0^th opponent so you win.\n Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.\n- You have more energy and experience than the 1^st opponent so you win.\n Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.\n- You have more energy and experience than the 2^nd opponent so you win.\n Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.\n- You have more energy and experience than the 3^rd opponent so you win.\n Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.\nYou did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.\nIt can be proven that no smaller answer exists.\n\nExample 2:\n\nInput: initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]\nOutput: 0\nExplanation: You do not need any additional energy or experience to win the competition, so we return 0.\n\nConstraints:\n\n- n == energy.length == experience.length\n- 1 <= n <= 100\n- 1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 50],experience = [50, 50]) == 52\n assert candidate(initialEnergy = 5,initialExperience = 3,energy = [1, 4, 3, 2],experience = [2, 6, 3, 1]) == 8\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [100],experience = [100]) == 200\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 25, 25],experience = [50, 25, 25]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30],experience = [10, 20, 30]) == 11\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [100],experience = [100]) == 2\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 50],experience = [50, 50]) == 1\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 0\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(initialEnergy = 2,initialExperience = 4,energy = [1],experience = [3]) == 0\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 5\n assert candidate(initialEnergy = 99,initialExperience = 99,energy = [100],experience = [100]) == 4\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],experience = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 71\n assert candidate(initialEnergy = 50,initialExperience = 25,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(initialEnergy = 30,initialExperience = 25,energy = [10, 15, 20, 5, 10],experience = [20, 15, 10, 25, 15]) == 31\n assert candidate(initialEnergy = 40,initialExperience = 40,energy = [20, 20, 20, 20],experience = [20, 20, 20, 20]) == 41\n assert candidate(initialEnergy = 30,initialExperience = 20,energy = [10, 20, 30, 40, 50],experience = [1, 2, 3, 4, 5]) == 121\n assert candidate(initialEnergy = 15,initialExperience = 8,energy = [7, 7, 7, 7, 7, 7],experience = [6, 6, 6, 6, 6, 6]) == 28\n assert candidate(initialEnergy = 70,initialExperience = 40,energy = [5, 15, 25, 35, 45],experience = [45, 35, 25, 15, 5]) == 62\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],experience = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 135\n assert candidate(initialEnergy = 2,initialExperience = 2,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(initialEnergy = 20,initialExperience = 25,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 36\n assert candidate(initialEnergy = 10,initialExperience = 5,energy = [5, 6, 7, 8],experience = [1, 2, 3, 4]) == 17\n assert candidate(initialEnergy = 20,initialExperience = 5,energy = [10, 15, 5, 20],experience = [3, 7, 10, 2]) == 31\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30, 40],experience = [5, 15, 25, 35]) == 51\n assert candidate(initialEnergy = 40,initialExperience = 25,energy = [10, 15, 10, 20, 15, 25],experience = [25, 20, 15, 10, 25, 20]) == 57\n assert candidate(initialEnergy = 30,initialExperience = 30,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],experience = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 181\n assert candidate(initialEnergy = 10,initialExperience = 20,energy = [1, 3, 5, 7, 9],experience = [9, 7, 5, 3, 1]) == 16\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 51\n assert candidate(initialEnergy = 50,initialExperience = 30,energy = [40, 35, 20, 10, 5],experience = [25, 20, 15, 10, 5]) == 61\n assert candidate(initialEnergy = 70,initialExperience = 30,energy = [20, 10, 30, 5, 20],experience = [15, 25, 10, 20, 5]) == 16\n assert candidate(initialEnergy = 20,initialExperience = 15,energy = [10, 20, 30],experience = [5, 15, 25]) == 41\n assert candidate(initialEnergy = 1,initialExperience = 10,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9],experience = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 45\n assert candidate(initialEnergy = 20,initialExperience = 15,energy = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14],experience = [14, 13, 12, 11, 10, 9, 8, 7, 6, 5]) == 76\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [25, 25, 25, 25],experience = [20, 20, 20, 20]) == 51\n assert candidate(initialEnergy = 15,initialExperience = 10,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 42\n assert candidate(initialEnergy = 25,initialExperience = 15,energy = [8, 7, 6, 5, 4, 3, 2, 1],experience = [1, 2, 3, 4, 5, 6, 7, 8]) == 12\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],experience = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 26\n assert candidate(initialEnergy = 10,initialExperience = 15,energy = [3, 2, 6, 1],experience = [8, 4, 2, 7]) == 3\n assert candidate(initialEnergy = 20,initialExperience = 25,energy = [10, 10, 10, 10],experience = [25, 26, 27, 28]) == 22\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 15, 25, 35],experience = [30, 20, 10, 5]) == 92\n assert candidate(initialEnergy = 30,initialExperience = 30,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 0\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 47\n assert candidate(initialEnergy = 30,initialExperience = 50,energy = [10, 20, 30],experience = [25, 20, 15]) == 31\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],experience = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 91\n assert candidate(initialEnergy = 15,initialExperience = 20,energy = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2]) == 46\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [20, 30, 40, 50, 60, 70, 80, 90, 100],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 441\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [10, 20, 30, 40, 50],experience = [1, 2, 3, 4, 5]) == 141\n assert candidate(initialEnergy = 25,initialExperience = 25,energy = [20, 15, 10, 5],experience = [5, 10, 15, 20]) == 26\n assert candidate(initialEnergy = 30,initialExperience = 20,energy = [15, 25, 10],experience = [10, 15, 25]) == 21\n assert candidate(initialEnergy = 50,initialExperience = 30,energy = [10, 20, 15, 25],experience = [5, 25, 20, 30]) == 21\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [99, 98, 97, 96, 95],experience = [95, 96, 97, 98, 99]) == 580\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [10, 20, 30, 40],experience = [40, 30, 20, 10]) == 140\n assert candidate(initialEnergy = 10,initialExperience = 5,energy = [3, 2, 6, 1],experience = [5, 4, 3, 2]) == 4\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],experience = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 26\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [1, 2, 3, 4, 5],experience = [5, 4, 3, 2, 1]) == 12\n assert candidate(initialEnergy = 60,initialExperience = 30,energy = [20, 20, 20, 20, 20],experience = [20, 20, 20, 20, 20]) == 41\n assert candidate(initialEnergy = 75,initialExperience = 40,energy = [40, 30, 20, 10, 5],experience = [50, 40, 30, 20, 10]) == 42\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [25, 10, 10, 5],experience = [20, 25, 30, 10]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41],experience = [51, 49, 48, 47, 46, 45, 44, 43, 42, 41]) == 408\n assert candidate(initialEnergy = 10,initialExperience = 5,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 52\n assert candidate(initialEnergy = 20,initialExperience = 10,energy = [25, 15, 5, 10, 20],experience = [30, 20, 10, 5, 15]) == 77\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90],experience = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 947\n assert candidate(initialEnergy = 30,initialExperience = 30,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 26\n assert candidate(initialEnergy = 5,initialExperience = 3,energy = [1, 2, 3, 4, 5],experience = [5, 4, 3, 2, 1]) == 14\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 6, 7, 8],experience = [15, 14, 13, 12]) == 23\n assert candidate(initialEnergy = 80,initialExperience = 60,energy = [15, 20, 25, 30, 35],experience = [65, 70, 75, 80, 85]) == 52\n assert candidate(initialEnergy = 40,initialExperience = 30,energy = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],experience = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 61\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 30, 20],experience = [20, 30, 50]) == 1\n assert candidate(initialEnergy = 25,initialExperience = 25,energy = [13, 14, 15, 16, 17],experience = [17, 16, 15, 14, 13]) == 51\n assert candidate(initialEnergy = 30,initialExperience = 30,energy = [29, 28, 27, 26, 25],experience = [25, 26, 27, 28, 29]) == 106\n assert candidate(initialEnergy = 20,initialExperience = 20,energy = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 31\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 25, 12, 6, 3, 1],experience = [1, 3, 6, 12, 25, 50]) == 0\n assert candidate(initialEnergy = 80,initialExperience = 70,energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 471\n assert candidate(initialEnergy = 100,initialExperience = 1,energy = [99, 99, 99],experience = [98, 97, 96]) == 296\n assert candidate(initialEnergy = 10,initialExperience = 15,energy = [3, 4, 5, 6, 7],experience = [5, 6, 7, 8, 9]) == 16\n assert candidate(initialEnergy = 20,initialExperience = 10,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 37\n assert candidate(initialEnergy = 50,initialExperience = 20,energy = [25, 25, 25, 25],experience = [15, 15, 15, 15]) == 51\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30, 40],experience = [40, 30, 20, 10]) == 51\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],experience = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 212\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 40, 30, 20, 10],experience = [10, 20, 30, 40, 50]) == 51\n assert candidate(initialEnergy = 60,initialExperience = 25,energy = [20, 20, 20, 20],experience = [15, 25, 35, 45]) == 21\n assert candidate(initialEnergy = 60,initialExperience = 40,energy = [10, 20, 30, 40],experience = [40, 30, 20, 10]) == 42\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30, 40],experience = [45, 35, 25, 15]) == 51\n assert candidate(initialEnergy = 3,initialExperience = 4,energy = [2, 5, 7, 8],experience = [5, 3, 6, 10]) == 22\n assert candidate(initialEnergy = 50,initialExperience = 10,energy = [30, 20, 10, 5, 25],experience = [15, 25, 5, 10, 30]) == 47\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [99, 1, 1],experience = [1, 99, 1]) == 199\n assert candidate(initialEnergy = 20,initialExperience = 20,energy = [10, 20, 30, 40],experience = [15, 15, 15, 15]) == 81\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [99, 99, 99, 99],experience = [99, 99, 99, 99]) == 297\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [90, 80, 70, 60, 50, 40, 30, 20, 10],experience = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 459\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [25, 25, 25, 25],experience = [20, 30, 20, 30]) == 51\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [10, 10, 10, 10],experience = [11, 12, 13, 14]) == 33\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [10, 20, 30, 40, 50],experience = [50, 40, 30, 20, 10]) == 200\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 3, 2, 4, 5, 3, 2, 1],experience = [2, 1, 3, 2, 1, 4, 3, 2]) == 23\n assert candidate(initialEnergy = 30,initialExperience = 25,energy = [5, 15, 25, 35, 45],experience = [40, 35, 30, 25, 20]) == 112\n assert candidate(initialEnergy = 20,initialExperience = 10,energy = [5, 10, 15, 20],experience = [8, 6, 4, 2]) == 31\n assert candidate(initialEnergy = 50,initialExperience = 30,energy = [10, 20, 30, 40],experience = [20, 30, 40, 50]) == 51\n assert candidate(initialEnergy = 15,initialExperience = 20,energy = [3, 3, 3, 3, 3],experience = [1, 2, 3, 4, 5]) == 1\n assert candidate(initialEnergy = 10,initialExperience = 50,energy = [25, 25, 25, 25],experience = [51, 52, 53, 54]) == 93\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [10, 20, 30],experience = [30, 20, 10]) == 90\n assert candidate(initialEnergy = 50,initialExperience = 100,energy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],experience = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 6\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 2, 3, 4, 5],experience = [1, 2, 3, 4, 5]) == 16\n assert candidate(initialEnergy = 30,initialExperience = 15,energy = [5, 10, 15, 20, 25],experience = [10, 15, 20, 25, 30]) == 46\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [25, 25, 25, 25],experience = [25, 25, 25, 25]) == 51\n assert candidate(initialEnergy = 60,initialExperience = 60,energy = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],experience = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 532\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 5, 5, 5],experience = [5, 5, 5, 5]) == 11\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 56\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30],experience = [15, 25, 35]) == 11\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 5, 5, 5, 5],experience = [1, 2, 3, 4, 5]) == 16\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 1, 1],experience = [1, 1, 1]) == 4\n assert candidate(initialEnergy = 1,initialExperience = 100,energy = [1, 1, 1],experience = [1, 1, 1]) == 3\n assert candidate(initialEnergy = 1,initialExperience = 50,energy = [50, 50, 50, 50],experience = [1, 1, 1, 1]) == 200\n assert candidate(initialEnergy = 100,initialExperience = 1,energy = [100],experience = [1]) == 2\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 25, 25],experience = [50, 25, 25]) == 1\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [2, 3, 4],experience = [4, 3, 2]) == 5\n assert candidate(initialEnergy = 30,initialExperience = 30,energy = [10, 20, 10],experience = [5, 15, 10]) == 11\n assert candidate(initialEnergy = 15,initialExperience = 15,energy = [5, 5, 5],experience = [5, 5, 5]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30, 40],experience = [10, 20, 30, 40]) == 51\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 50],experience = [50, 50]) == 52\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 5\n assert candidate(initialEnergy = 20,initialExperience = 20,energy = [5, 5, 5, 5, 5],experience = [5, 5, 5, 5, 5]) == 6\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 40, 30],experience = [30, 40, 50]) == 71\n assert candidate(initialEnergy = 50,initialExperience = 1,energy = [25, 25, 25],experience = [25, 25, 25]) == 51\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [5, 4, 3, 2, 1],experience = [1, 2, 3, 4, 5]) == 16\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [10, 10, 10],experience = [10, 10, 10]) == 22\n assert candidate(initialEnergy = 50,initialExperience = 1,energy = [1, 1, 1, 1],experience = [50, 50, 50, 50]) == 50\n assert candidate(initialEnergy = 1,initialExperience = 100,energy = [1],experience = [100]) == 2\n assert candidate(initialEnergy = 20,initialExperience = 20,energy = [10, 10, 10],experience = [10, 10, 10]) == 11\n assert candidate(initialEnergy = 100,initialExperience = 1,energy = [99, 98, 97],experience = [97, 98, 99]) == 292\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 10, 10, 10, 10],experience = [10, 10, 10, 10, 10]) == 1\n assert candidate(initialEnergy = 1,initialExperience = 100,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 4\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [3, 2, 1],experience = [1, 2, 3]) == 2\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(initialEnergy = 5,initialExperience = 5,energy = [10, 10, 10],experience = [10, 10, 10]) == 32\n assert candidate(initialEnergy = 30,initialExperience = 10,energy = [10, 10, 10],experience = [5, 5, 5]) == 1\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 2, 3, 4, 5],experience = [5, 4, 3, 2, 1]) == 6\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [25, 25, 25, 25],experience = [25, 25, 25, 25]) == 51\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 2, 3, 4, 5],experience = [5, 4, 3, 2, 1]) == 6\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],experience = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30],experience = [15, 25, 35]) == 11\n assert candidate(initialEnergy = 10,initialExperience = 1,energy = [2, 3, 4, 5],experience = [3, 4, 5, 6]) == 8\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [10, 20, 30],experience = [30, 20, 10]) == 0\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 30],experience = [40, 60]) == 0\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 5, 5, 5],experience = [5, 5, 5, 5]) == 11\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 2, 3],experience = [1, 2, 3]) == 7\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 0\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [10, 9, 8, 7],experience = [7, 8, 9, 10]) == 25\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 25, 25],experience = [50, 25, 25]) == 52\n assert candidate(initialEnergy = 3,initialExperience = 3,energy = [1, 1, 1, 1],experience = [1, 1, 1, 1]) == 2\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50, 50, 50],experience = [50, 50, 50]) == 102\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 50, 50],experience = [30, 30, 30]) == 51\n assert candidate(initialEnergy = 20,initialExperience = 20,energy = [10, 10],experience = [10, 10]) == 1\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [10, 10, 10],experience = [10, 10, 10]) == 22\n assert candidate(initialEnergy = 10,initialExperience = 1,energy = [10, 10, 10],experience = [1, 1, 1]) == 22\n assert candidate(initialEnergy = 30,initialExperience = 10,energy = [15, 15, 15],experience = [5, 5, 5]) == 16\n assert candidate(initialEnergy = 60,initialExperience = 50,energy = [30, 20, 10],experience = [10, 20, 30]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30],experience = [5, 15, 25]) == 11\n assert candidate(initialEnergy = 1,initialExperience = 1,energy = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],experience = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 11\n assert candidate(initialEnergy = 100,initialExperience = 100,energy = [50, 40, 30],experience = [10, 20, 30]) == 21\n assert candidate(initialEnergy = 3,initialExperience = 3,energy = [1, 1, 3, 3],experience = [3, 3, 1, 1]) == 7\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [10, 20, 30],experience = [5, 15, 25]) == 11\n assert candidate(initialEnergy = 1,initialExperience = 50,energy = [25, 25, 25],experience = [25, 25, 25]) == 75\n assert candidate(initialEnergy = 100,initialExperience = 1,energy = [1, 1, 1],experience = [1, 1, 1]) == 1\n assert candidate(initialEnergy = 50,initialExperience = 50,energy = [50],experience = [50]) == 2\n assert candidate(initialEnergy = 10,initialExperience = 10,energy = [5, 5, 5],experience = [5, 5, 5]) == 6\n", "comparison": "exact"}, "public_tests": ["5\n3\n[1,4,3,2]\n[2,6,3,1]", "2\n4\n[1]\n[3]"], "hints": ["Find the minimum number of training hours needed for the energy and experience separately, and sum the results.", "Try to increase the energy and experience until you find how much is enough to win the competition."], "metadata": {"canonical_parameter_names": ["initialEnergy", "initialExperience", "energy", "experience"], "leetcode_dataset_entry_point": "Solution().minNumberOfHours", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:46+00:00", "tests_total": 169, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "greedy"]}, "language": "php", "interface": {"raw_signature": "function minNumberOfHours($initialEnergy, $initialExperience, $energy, $experience) {", "container": "Solution", "callable": "minNumberOfHours", "parameters": [{"name": "initialEnergy", "type": "Integer"}, {"name": "initialExperience", "type": "Integer"}, {"name": "energy", "type": "Integer[]"}, {"name": "experience", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2384, "task_id": "largest-palindromic-number", "difficulty": "Medium", "problem_description": "You are given a string num consisting of digits only.\n\nReturn the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.\n\nNotes:\n\n- You do not need to use all the digits of num, but you must use at least one digit.\n- The digits can be reordered.\n\nExample 1:\n\nInput: num = \"444947137\"\nOutput: \"7449447\"\nExplanation:\nUse the digits \"4449477\" from \"444947137\" to form the palindromic integer \"7449447\".\nIt can be shown that \"7449447\" is the largest palindromic integer that can be formed.\n\nExample 2:\n\nInput: num = \"00009\"\nOutput: \"9\"\nExplanation:\nIt can be shown that \"9\" is the largest palindromic integer that can be formed.\nNote that the integer returned should not contain leading zeroes.\n\nConstraints:\n\n- 1 <= num.length <= 10^5\n- num consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = \"1111\") == \"1111\"\n assert candidate(num = \"00000\") == \"0\"\n assert candidate(num = \"10\") == \"1\"\n assert candidate(num = \"9\") == \"9\"\n assert candidate(num = \"1111111111\") == \"1111111111\"\n assert candidate(num = \"00009\") == \"9\"\n assert candidate(num = \"000\") == \"0\"\n assert candidate(num = \"220022\") == \"220022\"\n assert candidate(num = \"1\") == \"1\"\n assert candidate(num = \"55555\") == \"55555\"\n assert candidate(num = \"12345678987654321\") == \"87654321912345678\"\n assert candidate(num = \"9876543210\") == \"9\"\n assert candidate(num = \"0\") == \"0\"\n assert candidate(num = \"444947137\") == \"7449447\"\n assert candidate(num = \"22\") == \"22\"\n assert candidate(num = \"123321\") == \"321123\"\n assert candidate(num = \"1234567890\") == \"9\"\n assert candidate(num = \"9876543210000000000\") == \"9\"\n assert candidate(num = \"1001\") == \"1001\"\n assert candidate(num = \"987654321111111111111111111111111111111111111111111987654321\") == \"987654321111111111111111111111111111111111111111111123456789\"\n assert candidate(num = \"1001001001001001\") == \"1110000000000111\"\n assert candidate(num = \"123456789987654321123456789987654321\") == \"998877665544332211112233445566778899\"\n assert candidate(num = \"12345543211234554321\") == \"55443322111122334455\"\n assert candidate(num = \"98765432109876543210\") == \"98765432100123456789\"\n assert candidate(num = \"1000000000000000000000001\") == \"1000000000000000000000001\"\n assert candidate(num = \"900000000000000000000000000000009\") == \"900000000000000000000000000000009\"\n assert candidate(num = \"33330000000000000000000\") == \"33000000000000000000033\"\n assert candidate(num = \"0987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210\") == \"99998888777766665555444433332222111100000900000111122223333444455556666777788889999\"\n assert candidate(num = \"5555555555555555555\") == \"5555555555555555555\"\n assert candidate(num = \"101010101010101010101010101010101010101010101010101010101010101010101010101010101\") == \"111111111111111111110000000000000000000010000000000000000000011111111111111111111\"\n assert candidate(num = \"1111100000111110000011111\") == \"1111111000001000001111111\"\n assert candidate(num = \"11000011\") == \"11000011\"\n assert candidate(num = \"123455432109876567890\") == \"987654321050123456789\"\n assert candidate(num = \"999999999999999999999999999\") == \"999999999999999999999999999\"\n assert candidate(num = \"10000000000000000000000000000000000000000000000000000000000000000000000000001\") == \"10000000000000000000000000000000000000000000000000000000000000000000000000001\"\n assert candidate(num = \"090090090\") == \"900090009\"\n assert candidate(num = \"111122223333444455556666777788889999\") == \"998877665544332211112233445566778899\"\n assert candidate(num = \"1234567898765432100000000000000000000000000000000000000000000000000000000000000000\") == \"876543210000000000000000000000000000000090000000000000000000000000000000012345678\"\n assert candidate(num = \"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009\") == \"9\"\n assert candidate(num = \"123321456654123321\") == \"654332211112233456\"\n assert candidate(num = \"543210987654321098765432109876543210\") == \"987655443322110090011223344556789\"\n assert candidate(num = \"00000000000000000000000000000000000000000000000000000000000000000000000000009\") == \"9\"\n assert candidate(num = \"101010101010101010101010101010101\") == \"111111110000000010000000011111111\"\n assert candidate(num = \"1234567890987654321\") == \"9876543210123456789\"\n assert candidate(num = \"0000000001000000000\") == \"1\"\n assert candidate(num = \"111222333444555666777888999\") == \"9876543219123456789\"\n assert candidate(num = \"987654321234567890000000\") == \"98765432000100023456789\"\n assert candidate(num = \"987654321234567890\") == \"98765432123456789\"\n assert candidate(num = \"122111221\") == \"221111122\"\n assert candidate(num = \"908070605040302010\") == \"9\"\n", "comparison": "exact"}, "public_tests": ["\"444947137\"", "\"00009\""], "hints": ["In order to form a valid palindrome, other than the middle digit in an odd-length palindrome, every digit needs to exist on both sides.", "A longer palindrome implies a larger valued palindrome. For palindromes of the same length, the larger digits should occur first.", "We can count the occurrences of each digit and build the palindrome starting from the ends. Starting from the larger digits, if there are still at least 2 occurrences of a digit, we can place these digits on each side.", "Make sure to consider the special case for the center digit (if any) and zeroes. There should not be leading zeroes."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().largestPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:48+00:00", "tests_total": 50, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function largestPalindromic($num) {", "container": "Solution", "callable": "largestPalindromic", "parameters": [{"name": "num", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2386, "task_id": "find-the-k-sum-of-an-array", "difficulty": "Hard", "problem_description": "You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together.\n\nWe define the K-Sum of the array as the k^th largest subsequence sum that can be obtained (not necessarily distinct).\n\nReturn the K-Sum of the array.\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\nNote that the empty subsequence is considered to have a sum of 0.\n\nExample 1:\n\nInput: nums = [2,4,-2], k = 5\nOutput: 2\nExplanation: All the possible subsequence sums that we can obtain are the following sorted in decreasing order:\n6, 4, 4, 2, 2, 0, 0, -2.\nThe 5-Sum of the array is 2.\n\nExample 2:\n\nInput: nums = [1,-2,3,4,-10,12], k = 16\nOutput: 10\nExplanation: The 16-Sum of the array is 10.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- -10^9 <= nums[i] <= 10^9\n- 1 <= k <= min(2000, 2^n)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 100\n assert candidate(nums = [1000000000, -1000000000, 500000000, -500000000],k = 7) == 0\n assert candidate(nums = [1000000000, -1000000000, 1000000000],k = 3) == 1000000000\n assert candidate(nums = [1, 2, 3],k = 1) == 6\n assert candidate(nums = [5, 8, 3, 1],k = 8) == 9\n assert candidate(nums = [0, 0, 0, 0],k = 10) == 0\n assert candidate(nums = [0, 0, 0, 0],k = 1) == 0\n assert candidate(nums = [-1, -2, -3],k = 4) == -3\n assert candidate(nums = [-1, -2, -3, -4],k = 4) == -3\n assert candidate(nums = [5, 10, -3, 7, 2, -8],k = 3) == 21\n assert candidate(nums = [1, 2, 3],k = 2) == 5\n assert candidate(nums = [2, 4, -2],k = 5) == 2\n assert candidate(nums = [1, -2, 3, 4, -10, 12],k = 16) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 1000) == 80\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 = 1000) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 512) == 27\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 500) == 0\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15],k = 100) == -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],k = 1000) == 17\n assert candidate(nums = [5, 7, -3, 9, -6, 2, 8, -4],k = 20) == 21\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 20) == 8000000000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1024) == 0\n assert candidate(nums = [-1, 2, -3, 4, -5, 6, -7, 8],k = 20) == 12\n assert candidate(nums = [100, 200, 300, -100, -200, -300, 400, 500, -400, -500],k = 50) == 900\n assert candidate(nums = [100, 200, -150, 250, -300, 400, -50, -500, 600, 700, -1000, 800, 900],k = 1000) == 2150\n assert candidate(nums = [0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6],k = 25) == 17\n assert candidate(nums = [5, -3, 7, 1, -2, 4],k = 15) == 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 = 200) == 193\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 = 750) == 76\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45],k = 100) == 60\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],k = 100) == 70\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],k = 100) == 7\n assert candidate(nums = [1, 3, -2, 5, -4, 2, 6],k = 10) == 13\n assert candidate(nums = [5, -3, 7, 9, -2, 10],k = 15) == 19\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 1000) == 2000000000\n assert candidate(nums = [1000000000, -999999999, 999999998, -999999997, 999999996, -999999995, 999999994, -999999993, 999999992, -999999991],k = 200) == 1000000004\n assert candidate(nums = [5, -3, 2, 1, -2, 4, -1, 3, -5, 6],k = 150) == 11\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125],k = 50) == 1902343750\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 500) == 280\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 500) == 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, -5, -10, -15, -20, -25, -30, -35, -40, -45, -50, -55, -60, -65, -70, -75, -80, -85, -90, -95, -100],k = 1500) == 975\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 512) == 280\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) == 840\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 1000) == 93\n assert candidate(nums = [-1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000],k = 1000) == -8000000000\n assert candidate(nums = [10, 20, 30, -10, -20, -30, 40, 50, 60, -40, -50, -60],k = 150) == 120\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 2000) == 31\n assert candidate(nums = [100, 200, 300, -100, -200, -300, 400, 500, 600, -400, -500, -600, 700, 800, 900],k = 500) == 3300\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],k = 256) == -210\n assert candidate(nums = [5, 3, -1, 4, -6, 2, -2, 3],k = 10) == 13\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000],k = 2000) == 3800\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000],k = 30) == 1000000000\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 = 1024) == 17\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 = 2000) == 6\n assert candidate(nums = [1000000, -500000, 2000000, -1000000, 3000000, -1500000],k = 20) == 2500000\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 100) == 40\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 = 500) == 172\n assert candidate(nums = [5, -1, 3, -4, 2, -6, 7, -8, 9, -10],k = 128) == 10\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 50) == -11\n assert candidate(nums = [5, 4, 3, 2, 1],k = 20) == 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 = 500) == 188\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 = 500) == 17\n assert candidate(nums = [10, -5, 3, -2, 1, -1, 0],k = 15) == 11\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -100, -200, -300, -400, -500],k = 300) == 4400\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],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],k = 1500) == 181\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 20) == -9\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 400\n assert candidate(nums = [-1, -2, -3, -4, -5],k = 7) == -4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1024) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9],k = 1000) == 33\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 = 2000) == 343\n assert candidate(nums = [999999999, -999999999, 999999998, -999999998, 999999997, -999999997, 999999996, -999999996, 999999995, -999999995],k = 500) == 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 = 2000) == 179\n assert candidate(nums = [-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 1000) == 33\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 = 1024) == 351\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 = 200) == 8\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 1000) == 4100\n assert candidate(nums = [5, -3, 2, 7, -8, 10, -2, 3, 4, -1],k = 15) == 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],k = 2000) == 16\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 1024) == -55\n assert candidate(nums = [500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1],k = 1000) == 999998131\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 = 1000) == 17\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 15) == -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],k = 500) == 88\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 = 1024) == 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 = 1000) == 184\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],k = 1500) == 3900\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 = 750) == 420\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10],k = 1500) == 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],k = 500) == 43\n assert candidate(nums = [100, 200, 300, -100, -200, -300, 400, 500, -400, -500, 600, 700, -600, -700, 800, 900, -800, -900, 1000, -1000],k = 1000) == 4100\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],k = 15) == 7\n assert candidate(nums = [-10, -20, -30, -40, -50],k = 5) == -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],k = 100) == 28\n assert candidate(nums = [1000000000, -500000000, 500000000, -250000000, 250000000, -125000000, 125000000],k = 100) == 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 = 1200) == 167\n", "comparison": "exact"}, "public_tests": ["[2,4,-2]\n5", "[1,-2,3,4,-10,12]\n16"], "hints": ["Start from the largest sum possible, and keep finding the next largest sum until you reach the kth sum.", "Starting from a sum, what are the two next largest sums that you can obtain from it?"], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().kSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:53+00:00", "tests_total": 105, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function kSum($nums, $k) {", "container": "Solution", "callable": "kSum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2389, "task_id": "longest-subsequence-with-limited-sum", "difficulty": "Easy", "problem_description": "You are given an integer array nums of length n, and an integer array queries of length m.\n\nReturn an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i].\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 = [4,5,2,1], queries = [3,10,21]\nOutput: [2,3,4]\nExplanation: We answer the queries as follows:\n- The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.\n- The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.\n- The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4.\n\nExample 2:\n\nInput: nums = [2,3,4,5], queries = [1]\nOutput: [0]\nExplanation: The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0.\n\nConstraints:\n\n- n == nums.length\n- m == queries.length\n- 1 <= n, m <= 1000\n- 1 <= nums[i], queries[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [1, 2, 3, 4, 5]) == [1, 1, 2, 2, 2]\n assert candidate(nums = [10, 20, 30],queries = [10, 25, 50, 70]) == [1, 1, 2, 3]\n assert candidate(nums = [10, 20, 30],queries = [5, 15, 25, 35]) == [0, 1, 1, 2]\n assert candidate(nums = [10, 20, 30],queries = [10, 25, 50, 60]) == [1, 1, 2, 3]\n assert candidate(nums = [5, 4, 3, 2, 1],queries = [1, 2, 3, 4, 5]) == [1, 1, 2, 2, 2]\n assert candidate(nums = [4, 5, 2, 1],queries = [3, 10, 21]) == [2, 3, 4]\n assert candidate(nums = [10, 20, 30, 40, 50],queries = [100, 200, 300, 400, 500]) == [4, 5, 5, 5, 5]\n assert candidate(nums = [5, 5, 5, 5, 5],queries = [1, 5, 10, 15, 25]) == [0, 1, 2, 3, 5]\n assert candidate(nums = [2, 3, 4, 5],queries = [1]) == [0]\n assert candidate(nums = [1, 1, 1, 1, 1],queries = [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [10, 20, 30],queries = [5, 15, 25, 35, 45]) == [0, 1, 1, 2, 2]\n assert candidate(nums = [10, 20, 30],queries = [15, 25, 35, 45]) == [1, 1, 2, 2]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [15, 10, 5]) == [5, 4, 2]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [15, 10, 5, 3, 1]) == [5, 4, 2, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5],queries = [15, 10, 5, 3]) == [5, 4, 2, 2]\n assert candidate(nums = [5, 4, 3, 2, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [55]) == [10]\n assert candidate(nums = [1000000],queries = [1000000]) == [1]\n assert candidate(nums = [5, 5, 5, 5, 5],queries = [5, 10, 15, 20, 25]) == [1, 2, 3, 4, 5]\n assert candidate(nums = [1, 1000000],queries = [1000000]) == [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 = [5, 10, 15, 20, 25, 30]) == [5, 10, 15, 20, 20, 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],queries = [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 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 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],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],queries = [55, 165, 275, 385, 495, 605, 715, 825, 935, 1045, 1155, 1265, 1375, 1485, 1595]) == [2, 5, 6, 8, 9, 10, 11, 12, 13, 13, 14, 15, 15, 15, 15]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],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, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == [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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [3, 4, 5, 6, 7, 7, 8, 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],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210]) == [4, 5, 7, 8, 9, 10, 11, 12, 12, 13, 14, 15, 15, 16, 16, 17, 17, 18, 19, 19, 20]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [2, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == [1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6]\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 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [1, 5, 15, 30, 50, 75, 105, 140, 180, 225, 275, 330, 385, 440, 500]) == [1, 2, 5, 7, 9, 11, 14, 15, 15, 15, 15, 15, 15, 15, 15]\n assert candidate(nums = [100, 10, 1, 50, 20, 60],queries = [50, 150, 200, 300, 400]) == [3, 5, 5, 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],queries = [1, 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]) == [1, 2, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [10, 30, 60, 100, 150, 210, 280, 360, 450, 550]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],queries = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],queries = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500]) == [2, 5, 6, 7, 9, 10, 10, 10, 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],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [4, 5, 7, 8, 9, 10, 11, 12, 12, 13]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],queries = [10, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500]) == [1, 2, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 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],queries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [5, 8, 10, 12, 13, 15, 16, 17, 18, 19]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],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]) == [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, 2, 3]\n assert candidate(nums = [7, 3, 10, 1, 5, 2, 8, 6, 4, 9],queries = [15, 25, 30, 35, 40, 45, 50]) == [5, 6, 7, 7, 8, 9, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [9, 7, 5, 3, 1],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == [3, 4, 5, 5, 5, 5, 5, 5, 5, 5]\n assert candidate(nums = [5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 4, 3, 2, 1, 3, 2, 1, 2, 1, 1],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, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 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]\n assert candidate(nums = [7, 3, 4, 9, 1],queries = [10, 15, 20, 25, 30, 35, 40]) == [3, 4, 4, 5, 5, 5, 5]\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],queries = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87]) == [1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 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],queries = [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 = [100, 200, 300, 400, 500],queries = [150, 300, 450, 600, 750, 900, 1050]) == [1, 2, 2, 3, 3, 3, 4]\n assert candidate(nums = [7, 1, 3, 2, 8, 5, 6, 4],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 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],queries = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]) == [10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]\n assert candidate(nums = [300, 200, 100, 400, 500],queries = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 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],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 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, 73, 79, 83, 89, 97],queries = [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]) == [2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 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],queries = [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, 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],queries = [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]) == [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7]\n assert candidate(nums = [50, 40, 30, 20, 10],queries = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7]\n assert candidate(nums = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996, 6, 995, 7, 994, 8, 993, 9, 992, 10, 991],queries = [500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500]) == [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [2, 4, 5, 5, 6, 7, 7, 8, 9, 9]\n assert candidate(nums = [999999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],queries = [1000000, 500000, 100000, 50000]) == [19, 19, 19, 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 = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]) == [2, 5, 6, 7, 9, 10, 10, 11, 12, 13, 14, 14, 15, 15, 16, 17, 17, 18, 18, 19]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],queries = [10, 30, 60, 100, 150, 210, 280, 360, 450, 550, 660, 780, 910, 1050, 1200, 1360, 1530, 1710, 1900, 2100]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1],queries = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [1, 2, 3, 4, 5, 6, 7, 7, 7, 7]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3]\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500],queries = [100000, 250000, 500000, 750000, 1000000]) == [1, 2, 3, 3, 4]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == [1, 2, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],queries = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140]) == [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]\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]) == [1, 2, 2, 3, 3, 4, 4, 4, 5, 5]\n assert candidate(nums = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711],queries = [10, 100, 1000, 10000, 100000, 1000000]) == [3, 7, 12, 16, 20, 20]\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 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],queries = [90, 180, 270, 360, 450, 540, 630, 720, 810, 900, 990]) == [3, 5, 6, 8, 9, 9, 10, 10, 10, 10, 10]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == [1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14]\n assert candidate(nums = [9, 7, 5, 3, 1],queries = [5, 10, 15, 20, 25, 30]) == [2, 3, 3, 4, 5, 5]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 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]) == [1, 2, 2, 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, 9, 9]\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],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, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == [0, 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == [1, 50, 100, 145, 145, 145, 145, 145, 145, 145, 145]\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],queries = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],queries = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 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, 1, 1, 1],queries = [1, 5, 10, 20, 50, 100, 200, 500, 1000]) == [1, 5, 10, 20, 50, 91, 91, 91, 91]\n assert candidate(nums = [33, 21, 47, 55, 17, 82, 38, 67, 25, 12, 99, 78, 63, 44, 5, 85, 93, 4, 52, 36, 73, 29, 31, 88, 57, 90, 19, 15, 81, 77, 7, 48, 53, 18, 11, 34, 86, 59, 97, 40, 30, 92, 68, 49, 61, 50, 54, 91, 74, 75, 70, 60, 83, 64, 41, 87, 62, 24, 22, 27, 66, 35, 23, 58, 79, 98, 94, 39, 28, 20, 65, 43, 51, 46, 6, 95, 71, 1, 96, 3, 8, 9, 10, 13, 14, 16, 26, 32, 37, 42, 45, 56, 72, 80, 84, 89, 91],queries = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500]) == [12, 18, 23, 26, 30, 33, 35, 38, 40, 43, 45, 47, 49, 51, 53]\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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 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],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, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == [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, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [10, 30, 60, 100, 150, 210, 280, 360, 450, 550]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],queries = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250, 1350, 1450, 1550]) == [0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5]\n assert candidate(nums = [500, 400, 300, 200, 100],queries = [150, 250, 350, 450, 550, 650, 750, 850, 950]) == [1, 1, 2, 2, 2, 3, 3, 3, 3]\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200],queries = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250, 1350, 1450, 1550]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],queries = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],queries = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]) == [5, 6, 7, 9, 10, 10, 10, 10, 10, 10]\n", "comparison": "exact"}, "public_tests": ["[4,5,2,1]\n[3,10,21]", "[2,3,4,5]\n[1]"], "hints": ["Solve each query independently.", "When solving a query, which elements of nums should you choose to make the subsequence as long as possible?", "Choose the smallest elements in nums that add up to a sum less than the query."], "metadata": {"canonical_parameter_names": ["nums", "queries"], "leetcode_dataset_entry_point": "Solution().answerQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:50:58+00:00", "tests_total": 108, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function answerQueries($nums, $queries) {", "container": "Solution", "callable": "answerQueries", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2390, "task_id": "removing-stars-from-a-string", "difficulty": "Medium", "problem_description": "You are given a string s, which contains stars *.\n\nIn one operation, you can:\n\n- Choose a star in s.\n- Remove the closest non-star character to its left, as well as remove the star itself.\n\nReturn the string after all stars have been removed.\n\nNote:\n\n- The input will be generated such that the operation is always possible.\n- It can be shown that the resulting string will always be unique.\n\nExample 1:\n\nInput: s = \"leet**cod*e\"\nOutput: \"lecoe\"\nExplanation: Performing the removals from left to right:\n- The closest character to the 1^st star is 't' in \"leet**cod*e\". s becomes \"lee*cod*e\".\n- The closest character to the 2^nd star is 'e' in \"lee*cod*e\". s becomes \"lecod*e\".\n- The closest character to the 3^rd star is 'd' in \"lecod*e\". s becomes \"lecoe\".\nThere are no more stars, so we return \"lecoe\".\n\nExample 2:\n\nInput: s = \"erase*****\"\nOutput: \"\"\nExplanation: The entire string is removed, so we return an empty string.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of lowercase English letters and stars *.\n- The operation above can be performed on s.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*y*z\") == \"abdeghjkmnpqstvwz\"\n assert candidate(s = \"leet**cod*e\") == \"lecoe\"\n assert candidate(s = \"a*b*c*d*e*\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"ab*cd*ef*gh*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*\") == \"aceg\"\n assert candidate(s = \"a*ab*abc*abcd*abcde*abcdef*abcdefg*abcdefgh*abcdefghi*abcdefghij*abcdefghijk*abcdefghijkl*abcdefghijklm*abcdefghijklmn*abcdefghijklmno*abcdefghijklmnop*abcdefghijklmnopq*abcdefghijklmnopqr*abcdefghijklmnopqrs*abcdefghijklmnopqrst*abcdefghijklmnopqrstu*abcdefghijklmnopqrstuv*abcdefghijklmnopqrstuvw*abcdefghijklmnopqrstuvwx*abcdefghijklmnopqrstuvwxy*abcdefghijklmnopqrstuvwxyza\") == \"aababcabcdabcdeabcdefabcdefgabcdefghabcdefghiabcdefghijabcdefghijkabcdefghijklabcdefghijklmabcdefghijklmnabcdefghijklmnoabcdefghijklmnopabcdefghijklmnopqabcdefghijklmnopqrabcdefghijklmnopqrsabcdefghijklmnopqrstabcdefghijklmnopqrstuabcdefghijklmnopqrstuvabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwxabcdefghijklmnopqrstuvwxyza\"\n assert candidate(s = \"abcdef\") == \"abcdef\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a\") == \"a\"\n assert candidate(s = \"ab*cd*ef*gh*ij*kl*mn*op*qr*st*uv*wx*yz\") == \"acegikmoqsuwyz\"\n assert candidate(s = \"abcde\") == \"abcde\"\n assert candidate(s = \"abc***\") == \"\"\n assert candidate(s = \"ab*cd*ef*g*hi*j*\") == \"aceh\"\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 = \"erase*****\") == \"\"\n assert candidate(s = \"abcd**efgh**ijkl**mnop**qrst**uvw**x**y**z\") == \"abefijmnqz\"\n assert candidate(s = \"aaabbbcccddd***eee***fffgggggghhhhiiiiijkkkkkllllmmmmnnnnoooo***pppppqqqqrrrrsssss\") == \"aaabbbcccfffgggggghhhhiiiiijkkkkkllllmmmmnnnnopppppqqqqrrrrsssss\"\n assert candidate(s = \"abcde**fghij**klmno**pqrst**uvwxy**z\") == \"abcfghklmpqruvwz\"\n assert candidate(s = \"abcdefghijklmnopqrstuv*xyzwvutsrponmlkjihgfedcba*\") == \"abcdefghijklmnopqrstuxyzwvutsrponmlkjihgfedcb\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*zyxwvutsrqponmlkjihgfedcba*\") == \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcb\"\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 = \"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*\") == \"aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrssssstttttuuuuuvvvvvwwwwwxxxxxyyyyyzzzzz\"\n assert candidate(s = \"abcde*fghij*klmno*pqrst*uvwxy*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*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\") == \"abcdfghiklmnpqrsuvwxz\"\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*yz*\") == \"abdeghjkmnpqstvwy\"\n assert candidate(s = \"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*\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*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\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"abcde*fg*hi*jkl*mno*pqr*stu*vwx*y*z*\") == \"abcdfhjkmnpqstvw\"\n assert candidate(s = \"aabbccddeeefffggg***hhiijjkkllmmnn***oo***ppqqrrssttttuuuuuuuuuuvvvvvvvvwxyz\") == \"aabbccddeeefffhhiijjkkllppqqrrssttttuuuuuuuuuuvvvvvvvvwxyz\"\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*zyxwvutsrqponmlkjihgfedcba\") == \"zyxwvutsrqponmlkjihgfedcba\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz*****\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwx\"\n assert candidate(s = \"z*yz*zyxw*vyxwv*u*vwxy*ts*rq*ponm*ln*kj*i*hg*fed*cb*a*\") == \"yzyxvyxwvwxtrponlkhfec\"\n assert candidate(s = \"abc***def**ghij***klmno**pqrstuv***wxyz\") == \"dgklmpqrswxyz\"\n assert candidate(s = \"abcdefghij*klmnopqrst*uvwxyz*zyxwvutsr*qp*on*m*l*k*j*i*h*g*f*e*d*c*b*a\") == \"abcdefghiklmnopqrsuvwxyzyxwvutsqoa\"\n assert candidate(s = \"a*ab*abc*abcd*abcde*abcdef*abcdefg*abcdefgh*abcdefghi*abcdefghij*abcdefghijk*abcdefghijkl*abcdefghijklm*abcdefghijklmn*abcdefghijklmno*abcdefghijklmnop*abcdefghijklmnopq*abcdefghijklmnopqr*abcdefghijklmnopqrs*abcdefghijklmnopqrst*abcdefghijklmnopqrstu*abcdefghijklmnopqrstuv*abcdefghijklmnopqrstuvw*abcdefghijklmnopqrstuvwx*abcdefghijklmnopqrstuvwxy*abcdefghijklmnopqrstuvwxyz*\") == \"aababcabcdabcdeabcdefabcdefgabcdefghabcdefghiabcdefghijabcdefghijkabcdefghijklabcdefghijklmabcdefghijklmnabcdefghijklmnoabcdefghijklmnopabcdefghijklmnopqabcdefghijklmnopqrabcdefghijklmnopqrsabcdefghijklmnopqrstabcdefghijklmnopqrstuabcdefghijklmnopqrstuvabcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvwxabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz****\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxx\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy**z\") == \"abcdefghijklmnopqrstuvwz\"\n assert candidate(s = \"xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz***xyz\") == \"xyz\"\n assert candidate(s = \"abcde*****fghij*****klmno*****pqrst*****uvwxy*****z\") == \"z\"\n assert candidate(s = \"abcdefghij***klmnopqrst***uvwxyz***abcd***efghij***klmno***pqrst***uvwxy***z\") == \"abcdefgklmnopquvwaefgklpquvz\"\n assert candidate(s = \"abcdefghijk***lmnopqrstuvwxyz**aaaaaaaaaabbbbbbbbbbccccccccccddddeeeeee****\") == \"abcdefghlmnopqrstuvwxaaaaaaaaaabbbbbbbbbbccccccccccddddee\"\n assert candidate(s = \"abcd*efgh*ijkl*mnop*qrst*uvw*x*y*z*\") == \"abcefgijkmnoqrsuv\"\n assert candidate(s = \"nested*stars*****in*string*example***\") == \"nesteistrinexam\"\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 = \"a*bb*ccc*dddd*eeeee*ffffff*gggggg*hhhhhhh*iiiiiiii*jjjjjjjjj*kkkkkkkkk*llllllllll*mmmmmmmmmm*nnnnnnnnnnn*ooooooooooo*pppppppppppp*qqqqqqqqqqqqq*rrrrrrrrrrrrrr*sssssssssssssss*ttttttttttttttttt*uuuuuuuuuuuuuuuuuu*vvvvvvvvvvvvvvvvvvv*wwwwwwwwwwwwwwwwwwww*xxyyz**\") == \"bccdddeeeefffffggggghhhhhhiiiiiiijjjjjjjjkkkkkkkklllllllllmmmmmmmmmnnnnnnnnnnoooooooooopppppppppppqqqqqqqqqqqqrrrrrrrrrrrrrssssssssssssssttttttttttttttttuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwxxy\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*abcdefghijklmnopqrstuvwxyz*\") == \"abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy\"\n assert candidate(s = \"abcde*fg*hij*k*lmnop*qrs*tuvw*x*y*z*\") == \"abcdfhilmnoqrtuv\"\n assert candidate(s = \"abcdefghi*jk*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z**\") == \"abcdefgh\"\n assert candidate(s = \"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*x*x*x*x*x*x*x*x*x*x*x\") == \"x\"\n assert candidate(s = \"aabbaa*bbcc*ddcc*eeff*ffgg*hhiijj*kkll*mmnn*oopp*qqrr*sttuu*vwwxxyyzz*****\") == \"aabbabbcddceefffghhiijkklmmnoopqqrsttuvwwx\"\n assert candidate(s = \"abc**def**ghi**jkl**mno**pqr**stu**vwx**yz**\") == \"adgjmpsv\"\n assert candidate(s = \"mississippi***ipp*ss*m*i**\") == \"mississiip\"\n assert candidate(s = \"a*bc*def*ghij*klmno*pqrst*uvwxy*z\") == \"bdeghiklmnpqrsuvwxz\"\n assert candidate(s = \"mnopqrstu*****vwxyz*****abcdefghi*****jklmno*****pqrst*****uvw*****xy*****z\") == \"mnopz\"\n assert candidate(s = \"abcde*fgh*i*jklmno*pqrstu*v*wxyz*\") == \"abcdfgjklmnpqrstwxy\"\n assert candidate(s = \"abc*def*ghi*jkl*mno*pqr*stu*vwx*y*z**\") == \"abdeghjkmnpqstv\"\n assert candidate(s = \"a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*\") == \"\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxy**z*\") == \"abcdefghijklmnopqrstuvw\"\n assert candidate(s = \"xy*z*ab*cd*ef*gh*ij*kl*mn*op*qr*st*uv*wx*yz*\") == \"xacegikmoqsuwy\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz*\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyz\"\n assert candidate(s = \"python*is*awesome***so**is**java**\") == \"pythoiawesja\"\n assert candidate(s = \"longstringwith*various*characters*and*stars*through*out***\") == \"longstringwitvarioucharacteranstarthroug\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz*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*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 = \"a*ab*abc*abcd*abcde*abcdef*abcdefg*abcdefgh*abcdefghi*abcdefghij*abcdefghijk\") == \"aababcabcdabcdeabcdefabcdefgabcdefghabcdefghiabcdefghijk\"\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*abcdefghijklmnopqrstuvwxyz*zyxwvutsrqponmlkjihgfedcba*\") == \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcb\"\n", "comparison": "exact"}, "public_tests": ["\"leet**cod*e\"", "\"erase*****\""], "hints": ["What data structure could we use to efficiently perform these removals?", "Use a stack to store the characters. Pop one character off the stack at each star. Otherwise, we push the character onto the stack."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().removeStars", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:01+00:00", "tests_total": 65, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "stack", "simulation"]}, "language": "php", "interface": {"raw_signature": "function removeStars($s) {", "container": "Solution", "callable": "removeStars", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2391, "task_id": "minimum-amount-of-time-to-collect-garbage", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the i^th house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.\n\nYou are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.\n\nThere are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.\n\nOnly one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.\n\nReturn the minimum number of minutes needed to pick up all the garbage.\n\nExample 1:\n\nInput: garbage = [\"G\",\"P\",\"GP\",\"GG\"], travel = [2,4,3]\nOutput: 21\nExplanation:\nThe paper garbage truck:\n1. Travels from house 0 to house 1\n2. Collects the paper garbage at house 1\n3. Travels from house 1 to house 2\n4. Collects the paper garbage at house 2\nAltogether, it takes 8 minutes to pick up all the paper garbage.\nThe glass garbage truck:\n1. Collects the glass garbage at house 0\n2. Travels from house 0 to house 1\n3. Travels from house 1 to house 2\n4. Collects the glass garbage at house 2\n5. Travels from house 2 to house 3\n6. Collects the glass garbage at house 3\nAltogether, it takes 13 minutes to pick up all the glass garbage.\nSince there is no metal garbage, we do not need to consider the metal garbage truck.\nTherefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.\n\nExample 2:\n\nInput: garbage = [\"MMM\",\"PGM\",\"GP\"], travel = [3,10]\nOutput: 37\nExplanation:\nThe metal garbage truck takes 7 minutes to pick up all the metal garbage.\nThe paper garbage truck takes 15 minutes to pick up all the paper garbage.\nThe glass garbage truck takes 15 minutes to pick up all the glass garbage.\nIt takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.\n\nConstraints:\n\n- 2 <= garbage.length <= 10^5\n- garbage[i] consists of only the letters 'M', 'P', and 'G'.\n- 1 <= garbage[i].length <= 10\n- travel.length == garbage.length - 1\n- 1 <= travel[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(garbage = ['M', 'P', 'G', 'M', 'P', 'G'],travel = [1, 2, 3, 4, 5]) == 37\n assert candidate(garbage = ['P', 'G', 'M', 'P'],travel = [1, 1, 1]) == 10\n assert candidate(garbage = ['GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [10, 10, 10, 10, 10]) == 138\n assert candidate(garbage = ['G', 'P', 'M'],travel = [1, 1]) == 6\n assert candidate(garbage = ['M', 'P', 'G'],travel = [1, 1]) == 6\n assert candidate(garbage = ['GGGG', 'MM', 'PP', 'GG'],travel = [5, 5, 5]) == 40\n assert candidate(garbage = ['GGP', 'GGP', 'GGP', 'GGP'],travel = [2, 2, 2]) == 24\n assert candidate(garbage = ['M', 'M', 'M', 'M', 'M'],travel = [1, 1, 1, 1]) == 9\n assert candidate(garbage = ['G', 'P', 'GP', 'GG'],travel = [2, 4, 3]) == 21\n assert candidate(garbage = ['MMM', 'PGM', 'GP'],travel = [3, 10]) == 37\n assert candidate(garbage = ['GMP', 'GMP', 'GMP'],travel = [10, 10]) == 69\n assert candidate(garbage = ['MG', 'GP', 'PM', 'MG'],travel = [3, 4, 2]) == 33\n assert candidate(garbage = ['MG', 'GP', 'MM', 'PG', 'GG'],travel = [2, 3, 1, 5]) == 32\n assert candidate(garbage = ['MGP', 'MGP', 'MGP', 'MGP'],travel = [5, 5, 5]) == 57\n assert candidate(garbage = ['GGG', 'MMM', 'PPP'],travel = [5, 5]) == 24\n assert candidate(garbage = ['GP', 'GP', 'GP', 'GP'],travel = [1, 1, 1]) == 14\n assert candidate(garbage = ['GP', 'MM', 'GG', 'PP', 'GG'],travel = [5, 2, 4, 3]) == 40\n assert candidate(garbage = ['P', 'G', 'M'],travel = [1, 2]) == 7\n assert candidate(garbage = ['G', 'P', 'M', 'GP', 'MG', 'PG', 'GMP', 'MGP', 'PMG', 'G'],travel = [2, 3, 1, 5, 4, 2, 3, 1, 4]) == 86\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [2, 2, 2, 2, 2, 2, 2, 2]) == 51\n assert candidate(garbage = ['G', 'P', 'M', 'GP', 'GM', 'MP', 'PGM', 'MGP', 'GMP', 'PGMG', 'GMPG', 'MPGM'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) == 228\n assert candidate(garbage = ['MPG', 'G', 'M', 'P', 'G', 'M', 'P', 'G'],travel = [10, 20, 30, 40, 50, 60, 70]) == 650\n assert candidate(garbage = ['GGG', 'PPP', 'MMM', 'GPM', 'GPM', 'GPM', 'GPM'],travel = [2, 2, 2, 2, 2, 2]) == 57\n assert candidate(garbage = ['GGP', 'PGM', 'MG', 'PG', 'GM', 'MP', 'GG', 'PP', 'MM'],travel = [3, 3, 3, 3, 3, 3, 3, 3]) == 83\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 2, 1, 2, 1, 2, 1, 2]) == 40\n assert candidate(garbage = ['GGGPPPMMM', 'GGGPPPMMM', 'GGGPPPMMM', 'GGGPPPMMM'],travel = [10, 10, 10]) == 126\n assert candidate(garbage = ['M', 'G', 'P', 'MG', 'PG', 'GM', 'GMP', 'P', 'M'],travel = [2, 3, 1, 4, 2, 3, 1, 2]) == 63\n assert candidate(garbage = ['G', 'M', 'P', 'G', 'M', 'P', 'G', 'M', 'P', 'G', 'M', 'P', 'G', 'M', 'P'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 289\n assert candidate(garbage = ['M', 'P', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 146\n assert candidate(garbage = ['GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [10, 20, 30, 10, 20, 30, 10, 20]) == 427\n assert candidate(garbage = ['MP', 'GP', 'MG', 'PG', 'GM', 'PM', 'MG', 'PG', 'GM', 'PM'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 150\n assert candidate(garbage = ['MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP'],travel = [2, 2, 2, 2, 2, 2, 2]) == 66\n assert candidate(garbage = ['MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 39\n assert candidate(garbage = ['GMPGMP', 'PMPMPM', 'MGMGMG', 'PGPGPG', 'GMPGMP', 'PMPMPM', 'MGMGMG', 'PGPGPG'],travel = [15, 15, 15, 15, 15, 15, 15]) == 348\n assert candidate(garbage = ['G', 'M', 'P', 'G', 'M', 'P', 'G', 'M', 'P'],travel = [1, 2, 3, 4, 5, 6, 7, 8]) == 94\n assert candidate(garbage = ['PG', 'G', 'P', 'G', 'P', 'G', 'P', 'G', 'P', 'G', 'P'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 112\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 66\n assert candidate(garbage = ['GMM', 'GGP', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [7, 8, 9, 10, 11, 12]) == 157\n assert candidate(garbage = ['GMM', 'GGP', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM', 'GPP', 'MG', 'PGM', 'PG', 'GM', 'MP', 'PGM', 'GMP'],travel = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 608\n assert candidate(garbage = ['GGGG', 'PPPP', 'MMMM', 'PPPP', 'GGGG', 'MMMM'],travel = [3, 4, 5, 6, 7]) == 79\n assert candidate(garbage = ['G', 'P', 'M', 'GP', 'MG', 'PG', 'GMP', 'MGP', 'PMG', 'G', 'P', 'M', 'GP', 'MG', 'PG', 'GMP', 'MGP', 'PMG', 'G'],travel = [2, 3, 1, 5, 4, 2, 3, 1, 4, 2, 3, 1, 5, 4, 2, 3, 1, 4]) == 179\n assert candidate(garbage = ['GP', 'MG', 'PM', 'MG', 'PM', 'MG', 'PM', 'MG', 'PM', 'MG'],travel = [5, 10, 5, 10, 5, 10, 5, 10, 5]) == 210\n assert candidate(garbage = ['P', 'M', 'G', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 130\n assert candidate(garbage = ['GMP', 'P', 'G', 'M', 'P', 'G', 'M', 'P', 'G', 'M'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 121\n assert candidate(garbage = ['MPG', 'PGM', 'GMP', 'MGP', 'GPM', 'PGM', 'GMP', 'MGP', 'GPM', 'PGM'],travel = [5, 10, 15, 20, 25, 30, 35, 40, 45]) == 705\n assert candidate(garbage = ['G', 'M', 'P', 'G', 'M', 'P', 'G', 'M', 'P', 'G'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 130\n assert candidate(garbage = ['MGP', 'G', 'P', 'M', 'GP', 'MG', 'PG', 'GM', 'PM'],travel = [10, 5, 7, 6, 8, 9, 2, 3]) == 163\n assert candidate(garbage = ['MMM', 'GGG', 'PPP', 'MMM', 'GGG', 'PPP', 'MMM'],travel = [5, 5, 5, 5, 5, 5]) == 96\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 42\n assert candidate(garbage = ['GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 513\n assert candidate(garbage = ['MMG', 'PG', 'MM', 'GGG', 'PP', 'G'],travel = [3, 5, 2, 6, 4]) == 57\n assert candidate(garbage = ['GGGG', 'PPPP', 'MMMM', 'GGGG', 'PPPP', 'MMMM'],travel = [1, 2, 3, 4, 5]) == 55\n assert candidate(garbage = ['G', 'M', 'P', 'GM', 'PG', 'MG', 'GPM', 'PMG', 'MPG', 'GMP'],travel = [2, 3, 4, 5, 6, 7, 8, 9, 10]) == 183\n assert candidate(garbage = ['MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 165\n assert candidate(garbage = ['MGP', 'GP', 'MGG', 'PGG', 'MMM', 'GGP', 'PGM'],travel = [3, 5, 2, 4, 6, 7]) == 101\n assert candidate(garbage = ['MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP'],travel = [10, 10, 10, 10, 10, 10, 10, 10, 10]) == 300\n assert candidate(garbage = ['MMMGGGPPP', 'MMMGGGPPP', 'MMMGGGPPP', 'MMMGGGPPP'],travel = [15, 15, 15]) == 171\n assert candidate(garbage = ['MGPG', 'GPMP', 'PGMG', 'P', 'M', 'G', 'MGP', 'P', 'G', 'MP'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 148\n assert candidate(garbage = ['MPG', 'G', 'P', 'M', 'PG', 'GM', 'PGM'],travel = [7, 3, 8, 2, 5, 6]) == 106\n assert candidate(garbage = ['MMM', 'MMM', 'MMM', 'MMM', 'MMM'],travel = [10, 10, 10, 10]) == 55\n assert candidate(garbage = ['G', 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 21\n assert candidate(garbage = ['GMP', 'P', 'M', 'G', 'MPG', 'MG', 'PG', 'GMP', 'GMP', 'P'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 145\n assert candidate(garbage = ['GP', 'GP', 'GP', 'GP', 'GP', 'GP', 'GP'],travel = [1, 1, 1, 1, 1, 1]) == 26\n assert candidate(garbage = ['MMM', 'PPP', 'GGG', 'MMM', 'PPP', 'GGG', 'MMM', 'PPP', 'GGG'],travel = [10, 10, 10, 10, 10, 10, 10, 10]) == 237\n assert candidate(garbage = ['MG', 'PGP', 'GGM', 'PPG', 'MMG'],travel = [3, 5, 2, 7]) == 58\n assert candidate(garbage = ['MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM', 'MMM'],travel = [10, 10, 10, 10, 10, 10, 10, 10]) == 107\n assert candidate(garbage = ['GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP', 'GMP'],travel = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 165\n assert candidate(garbage = ['G', 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 2, 3, 4, 5, 6, 7, 8]) == 94\n assert candidate(garbage = ['MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG'],travel = [5, 5, 5, 5, 5, 5, 5]) == 129\n assert candidate(garbage = ['MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG', 'MPG'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 57\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) == 427\n assert candidate(garbage = ['MMMM', 'PPPP', 'GGGG', 'MMMM', 'PPPP', 'GGGG'],travel = [10, 10, 10, 10, 10]) == 144\n assert candidate(garbage = ['MMM', 'PPP', 'GGG', 'MMM', 'PPP', 'GGG', 'MMM'],travel = [10, 10, 10, 10, 10, 10]) == 171\n assert candidate(garbage = ['MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP', 'MGP'],travel = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 69\n assert candidate(garbage = ['MMM', 'GGG', 'PPP', 'MGP', 'GMP', 'PMM', 'GGP', 'PPG', 'MPM', 'MGP'],travel = [10, 20, 15, 10, 5, 12, 8, 18, 7]) == 345\n assert candidate(garbage = ['M', 'P', 'G', 'MPG', 'GMP', 'PGM'],travel = [1, 3, 2, 4, 5]) == 57\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 115\n assert candidate(garbage = ['MGP', 'MG', 'P', 'G', 'MP', 'GM', 'PG', 'MG', 'PGM'],travel = [5, 5, 5, 5, 5, 5, 5, 5]) == 138\n assert candidate(garbage = ['G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M', 'G', 'P', 'M'],travel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 289\n assert candidate(garbage = ['G', 'P', 'M', 'PG', 'GM', 'MP', 'PGM'],travel = [1, 2, 3, 4, 5, 6]) == 75\n", "comparison": "exact"}, "public_tests": ["[\"G\",\"P\",\"GP\",\"GG\"]\n[2,4,3]", "[\"MMM\",\"PGM\",\"GP\"]\n[3,10]"], "hints": ["Where can we save time? By not visiting all the houses.", "For each type of garbage, find the house with the highest index that has at least 1 unit of this type of garbage."], "metadata": {"canonical_parameter_names": ["garbage", "travel"], "leetcode_dataset_entry_point": "Solution().garbageCollection", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:03+00:00", "tests_total": 107, "tests_dropped": 26, "flags": [], "topic_tags": ["array", "string", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function garbageCollection($garbage, $travel) {", "container": "Solution", "callable": "garbageCollection", "parameters": [{"name": "garbage", "type": "String[]"}, {"name": "travel", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2392, "task_id": "build-a-matrix-with-conditions", "difficulty": "Hard", "problem_description": "You are given a positive integer k. You are also given:\n\n- a 2D integer array rowConditions of size n where rowConditions[i] = [above_i, below_i], and\n- a 2D integer array colConditions of size m where colConditions[i] = [left_i, right_i].\n\nThe two arrays contain integers from 1 to k.\n\nYou have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.\n\nThe matrix should also satisfy the following conditions:\n\n- The number above_i should appear in a row that is strictly above the row at which the number below_i appears for all i from 0 to n - 1.\n- The number left_i should appear in a column that is strictly left of the column at which the number right_i appears for all i from 0 to m - 1.\n\nReturn any matrix that satisfies the conditions. If no answer exists, return an empty matrix.\n\nExample 1:\n\nInput: k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]]\nOutput: [[3,0,0],[0,0,1],[0,2,0]]\nExplanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.\nThe row conditions are the following:\n- Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.\n- Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.\nThe column conditions are the following:\n- Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.\n- Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.\nNote that there may be multiple correct answers.\n\nExample 2:\n\nInput: k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]]\nOutput: []\nExplanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.\nNo matrix can satisfy all the conditions, so we return the empty matrix.\n\nConstraints:\n\n- 2 <= k <= 400\n- 1 <= rowConditions.length, colConditions.length <= 10^4\n- rowConditions[i].length == colConditions[i].length == 2\n- 1 <= above_i, below_i, left_i, right_i <= k\n- above_i != below_i\n- left_i != right_i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(k = 5,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == [[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 5]]\n assert candidate(k = 3,rowConditions = [[1, 2], [3, 2]],colConditions = [[2, 1], [3, 2]]) == [[0, 0, 1], [3, 0, 0], [0, 2, 0]]\n assert candidate(k = 4,rowConditions = [[4, 3], [3, 2], [2, 1]],colConditions = [[4, 3], [3, 2], [2, 1]]) == [[4, 0, 0, 0], [0, 3, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]\n assert candidate(k = 4,rowConditions = [[1, 2], [2, 3], [3, 4]],colConditions = [[1, 2], [2, 3], [3, 4]]) == [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]\n assert candidate(k = 6,rowConditions = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [4, 6]],colConditions = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5], [4, 6]]) == [[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], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 4,rowConditions = [[1, 2], [3, 4]],colConditions = [[1, 3], [2, 4]]) == [[1, 0, 0, 0], [0, 0, 3, 0], [0, 2, 0, 0], [0, 0, 0, 4]]\n assert candidate(k = 3,rowConditions = [[1, 2], [2, 3], [3, 1], [2, 3]],colConditions = [[2, 1]]) == []\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]]) == []\n assert candidate(k = 15,rowConditions = [[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], [1, 15]],colConditions = [[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], [1, 15]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 7,rowConditions = [[7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [[0, 0, 0, 0, 0, 0, 7], [0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 15,rowConditions = [[1, 15], [2, 14], [3, 13], [4, 12], [5, 11], [6, 10], [7, 9]],colConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 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, 0, 0, 9]]\n assert candidate(k = 8,rowConditions = [[8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [[0, 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, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 15,rowConditions = [[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]],colConditions = [[1, 8], [2, 9], [3, 10], [4, 11], [5, 12], [6, 13], [7, 14], [8, 15]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 15,rowConditions = [[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], [1, 15]],colConditions = [[1, 15], [2, 15], [3, 15], [4, 15], [5, 15], [6, 15], [7, 15], [8, 15], [9, 15], [10, 15], [11, 15], [12, 15], [13, 15], [14, 15], [1, 15]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 10,rowConditions = [[1, 5], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10]],colConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 9], [0, 0, 10, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 9,rowConditions = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 6]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0]]\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 6], [2, 5], [3, 6], [4, 6]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 6], [2, 5], [3, 6], [4, 6]]) == [[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], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 7,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],colConditions = [[1, 7], [2, 6], [3, 5], [4, 5], [5, 6], [6, 7]]) == [[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]]\n assert candidate(k = 8,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[1, 8], [2, 7], [3, 6], [4, 5]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 0, 0, 0, 5], [0, 0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 8, 0, 0, 0]]\n assert candidate(k = 10,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],colConditions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 6], [0, 0, 0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0]]\n assert candidate(k = 7,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],colConditions = [[1, 4], [4, 7], [2, 5], [5, 7], [3, 6], [6, 7]]) == [[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]]\n assert candidate(k = 8,rowConditions = [[1, 8], [2, 7], [3, 6], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 9,rowConditions = [[1, 3], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],colConditions = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 10,rowConditions = [[1, 3], [2, 4], [5, 8], [6, 9], [3, 7], [4, 10]],colConditions = [[1, 5], [2, 6], [3, 9], [4, 10], [7, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 8], [0, 0, 0, 0, 0, 0, 0, 9, 0, 0], [0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 10, 0]]\n assert candidate(k = 6,rowConditions = [[1, 3], [2, 3], [4, 5], [4, 6], [5, 6]],colConditions = [[1, 4], [2, 5], [3, 6]]) == [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 12,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],colConditions = [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 13,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]],colConditions = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 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, 2], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0], [0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0], [0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 12,rowConditions = [[1, 6], [6, 11], [2, 7], [7, 12], [3, 8], [4, 9], [5, 10]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 8,rowConditions = [[1, 3], [3, 5], [5, 7], [2, 4], [4, 6], [6, 8]],colConditions = [[1, 2], [3, 4], [5, 6], [7, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 0, 0, 0], [0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 4, 0, 0], [0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 7, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == [[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], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 12,rowConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11]],colConditions = [[1, 4], [4, 8], [2, 5], [5, 9], [3, 6], [6, 10], [7, 11], [8, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0], [0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0]]\n assert candidate(k = 11,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11]]\n assert candidate(k = 10,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],colConditions = [[1, 3], [3, 5], [5, 7], [7, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 3, 0, 0, 0], [0, 0, 4, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 5, 0, 0], [0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 8, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 9], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0]]\n assert candidate(k = 7,rowConditions = [[1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7]],colConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7]]) == [[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]]\n assert candidate(k = 9,rowConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9]],colConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 12,rowConditions = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12]],colConditions = [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 10,rowConditions = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],colConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n assert candidate(k = 8,rowConditions = [[1, 4], [4, 7], [7, 8], [2, 5], [5, 8], [3, 6], [6, 8]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 6,rowConditions = [[1, 4], [2, 4], [3, 4], [5, 6]],colConditions = [[1, 3], [2, 3], [5, 6]]) == [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 3, 0], [0, 0, 0, 5, 0, 0], [0, 0, 4, 0, 0, 0], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 9,rowConditions = [[1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 0, 8], [0, 9, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 7,rowConditions = [[1, 7], [2, 6], [3, 5], [4, 5], [5, 6], [6, 7]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [[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]]\n assert candidate(k = 15,rowConditions = [[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]],colConditions = [[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]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 11,rowConditions = [[1, 11], [2, 10], [3, 9], [4, 8], [5, 7]],colConditions = [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0]]\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1]],colConditions = [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2], [6, 1]]) == []\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [1, 6]]) == [[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], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 9,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [1, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 8,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 10,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],colConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [2, 4], [4, 6], [6, 8], [8, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n assert candidate(k = 20,rowConditions = [[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]],colConditions = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [11, 20]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20]]\n assert candidate(k = 7,rowConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 6], [3, 7], [4, 7], [5, 7]],colConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 6], [3, 7], [4, 7], [5, 7]]) == [[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]]\n assert candidate(k = 10,rowConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [2, 4], [4, 6], [6, 8], [8, 10]],colConditions = [[1, 4], [4, 7], [7, 10], [2, 5], [5, 8], [3, 6], [6, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n assert candidate(k = 7,rowConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == [[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]]\n assert candidate(k = 12,rowConditions = [[1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 12], [7, 12], [8, 12], [9, 12], [10, 12], [11, 12]],colConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11]]) == [[1, 0, 0, 0, 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, 0, 3, 0, 0, 0, 0], [0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11], [0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0]]\n assert candidate(k = 7,rowConditions = [[1, 2], [2, 3], [4, 5], [5, 6], [6, 7]],colConditions = [[1, 2], [3, 4], [5, 6], [6, 7]]) == [[1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 2, 0, 0, 0], [0, 0, 5, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 0, 7]]\n assert candidate(k = 8,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[1, 3], [3, 5], [5, 7], [2, 4], [4, 6], [6, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 12,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 5,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5]],colConditions = [[1, 3], [2, 3], [3, 4], [4, 5]]) == [[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 3, 0, 0], [0, 0, 0, 4, 0], [0, 0, 0, 0, 5]]\n assert candidate(k = 6,rowConditions = [[1, 4], [2, 5], [3, 6], [4, 6]],colConditions = [[1, 3], [2, 4], [3, 5], [4, 6]]) == [[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], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 9,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 8,rowConditions = [[1, 8], [2, 7], [3, 6], [4, 5]],colConditions = [[1, 8], [2, 7], [3, 6], [4, 5]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 0, 0, 5]]\n assert candidate(k = 7,rowConditions = [[1, 3], [2, 5], [3, 6], [4, 7], [5, 7], [6, 7]],colConditions = [[1, 4], [2, 5], [3, 6], [4, 7], [5, 7], [6, 7]]) == [[1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0], [0, 0, 0, 0, 0, 6, 0], [0, 0, 0, 0, 0, 0, 7]]\n assert candidate(k = 12,rowConditions = [[1, 6], [6, 11], [11, 3], [3, 9], [9, 5], [5, 2], [2, 8], [8, 4], [4, 12], [12, 7], [7, 10]],colConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 2], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12], [0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0]]\n assert candidate(k = 15,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15]],colConditions = [[1, 3], [2, 4], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14], [12, 15]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 6,rowConditions = [[1, 6], [2, 5], [3, 4], [4, 6], [5, 6]],colConditions = [[1, 5], [2, 6], [3, 5], [4, 6]]) == [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 5, 0], [0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 12,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],colConditions = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 8,rowConditions = [[1, 3], [3, 5], [2, 4], [4, 6], [5, 7], [6, 8]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 8]]\n assert candidate(k = 20,rowConditions = [[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11]],colConditions = [[1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 8,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1]]) == [[0, 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, 0, 0, 0], [0, 0, 6, 0, 0, 0, 0, 0], [0, 7, 0, 0, 0, 0, 0, 0], [8, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 15,rowConditions = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14], [11, 15]],colConditions = [[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]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 10,rowConditions = [[1, 3], [2, 3], [3, 5], [3, 6], [4, 7], [7, 8], [9, 10]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0]]\n assert candidate(k = 20,rowConditions = [[1, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 11]],colConditions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6], [11, 19], [12, 18], [13, 17], [14, 16], [15, 20]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 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, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 20], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]\n assert candidate(k = 10,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n assert candidate(k = 10,rowConditions = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],colConditions = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, 0, 0], [0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 7, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 9, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n assert candidate(k = 12,rowConditions = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12]]\n assert candidate(k = 9,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],colConditions = [[1, 9], [2, 8], [3, 7], [4, 6], [5, 7], [6, 8], [7, 9], [8, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 6,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],colConditions = [[1, 3], [3, 5], [5, 6]]) == [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 4, 0, 0, 0], [0, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 6]]\n assert candidate(k = 10,rowConditions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]],colConditions = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 9, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 7, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 6]]\n assert candidate(k = 8,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],colConditions = [[1, 3], [3, 5], [5, 7]]) == [[1, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 3, 0, 0], [0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 5, 0], [0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 7], [0, 0, 0, 0, 8, 0, 0, 0]]\n assert candidate(k = 9,rowConditions = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 9], [6, 9], [7, 9], [8, 9]],colConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9]]\n assert candidate(k = 12,rowConditions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]],colConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11]]) == [[1, 0, 0, 0, 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, 0, 3, 0, 0, 0, 0], [0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0], [0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11], [0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0]]\n assert candidate(k = 6,rowConditions = [[1, 3], [2, 3], [1, 4], [2, 4], [1, 5], [3, 5], [1, 6], [2, 6]],colConditions = [[1, 2], [1, 3], [2, 4], [3, 4], [1, 5], [3, 5]]) == [[1, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 0, 0, 4, 0], [0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 5]]\n assert candidate(k = 15,rowConditions = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [2, 4], [4, 6], [6, 8], [8, 10], [10, 12], [12, 14]],colConditions = [[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]]) == [[1, 0, 0, 0, 0, 0, 0, 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, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15]]\n assert candidate(k = 10,rowConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]],colConditions = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 7, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 9, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]]\n", "comparison": "exact"}, "public_tests": ["3\n[[1,2],[3,2]]\n[[2,1],[3,2]]", "3\n[[1,2],[2,3],[3,1],[2,3]]\n[[2,1]]"], "hints": ["Can you think of the problem in terms of graphs?", "What algorithm allows you to find the order of nodes in a graph?"], "metadata": {"canonical_parameter_names": ["k", "rowConditions", "colConditions"], "leetcode_dataset_entry_point": "Solution().buildMatrix", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:06+00:00", "tests_total": 85, "tests_dropped": 2, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "graph", "topological-sort", "matrix", "directed-acyclic-graph"]}, "language": "php", "interface": {"raw_signature": "function buildMatrix($k, $rowConditions, $colConditions) {", "container": "Solution", "callable": "buildMatrix", "parameters": [{"name": "k", "type": "Integer"}, {"name": "rowConditions", "type": "Integer[][]"}, {"name": "colConditions", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2395, "task_id": "find-subarrays-with-equal-sum", "difficulty": "Easy", "problem_description": "Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.\n\nReturn true if these subarrays exist, and false otherwise.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [4,2,4]\nOutput: true\nExplanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: false\nExplanation: No two subarrays of size 2 have the same sum.\n\nExample 3:\n\nInput: nums = [0,0,0]\nOutput: true\nExplanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.\nNote that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.\n\nConstraints:\n\n- 2 <= nums.length <= 1000\n- -10^9 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [-1, 0, 1, -1, 0]) == True\n assert candidate(nums = [1, 1, 1, 1]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == False\n assert candidate(nums = [5, -1, 5, -1]) == True\n assert candidate(nums = [1, 2, 3, 3, 2, 1]) == True\n assert candidate(nums = [-1, 0, 1, 0, -1]) == True\n assert candidate(nums = [1000000000, 1000000000]) == False\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == False\n assert candidate(nums = [-1, -2, -3, -4, -5]) == False\n assert candidate(nums = [1, 2, 3, 4, 5]) == False\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(nums = [0, 0, 0]) == True\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000]) == True\n assert candidate(nums = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) == True\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1]) == True\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == False\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [1, 2, 1, 2]) == True\n assert candidate(nums = [1, 1, 2, 3, 3, 4]) == False\n assert candidate(nums = [-1, 0, 1, -1, 0, 1]) == True\n assert candidate(nums = [-1000000000, 1000000000, -1000000000, 1000000000]) == True\n assert candidate(nums = [4, 2, 4]) == True\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1]) == True\n assert candidate(nums = [-1, -2, -3, -1, -2, -3, -1, -2, -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, 1]) == True\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30]) == True\n assert candidate(nums = [7, 3, 5, 7, 9, 5, 3, 1, 5, 7, 9, 3, 5, 7, 1]) == 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]) == True\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200]) == True\n assert candidate(nums = [-1, -2, -3, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) == 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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]) == 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]) == True\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == True\n assert candidate(nums = [500000000, -500000000, 500000000, -500000000, 500000000, -500000000]) == True\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 = [1000000000, -1000000000, 500000000, -500000000, 250000000, -250000000, 125000000, -125000000]) == True\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110]) == True\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]) == False\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == False\n assert candidate(nums = [999999999, -999999999, 999999999, -999999999, 999999999, -999999999, 999999999, -999999999]) == True\n assert candidate(nums = [1000000000, -1000000000, 1000000000, -1000000000, 1000000000]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 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]) == 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]) == True\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == True\n assert candidate(nums = [5, 5, 10, 15, 5, 5]) == True\n assert candidate(nums = [-1, -2, -3, -4, -5, -1, -2, -3, -4, -5]) == True\n assert candidate(nums = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 10, 11]) == True\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, 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, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, 4, 3, 2, 1, 0]) == True\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == False\n assert candidate(nums = [5, -5, 5, -5, 5, -5]) == True\n assert candidate(nums = [5, 3, 5, 3, 5, 3]) == True\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == True\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 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, 21, 22, 23, 24, 25]) == False\n assert candidate(nums = [0, 1, 2, 3, 4, 3, 2, 1, 0]) == 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]) == True\n assert candidate(nums = [-1, 0, 1, -1, 0, 1, -1]) == True\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]) == 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]) == False\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3]) == True\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == True\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == True\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]) == False\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -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]) == False\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == True\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 0, -1, -2, -3, -4]) == True\n assert candidate(nums = [-1, 1, -1, 1, -1, 1, -1, 1]) == True\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == True\n assert candidate(nums = [999999999, 999999999, -999999999, -999999999, 1, -1, 1, -1]) == True\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == True\n assert candidate(nums = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) == False\n assert candidate(nums = [10, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == True\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3]) == True\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == True\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60, 50, 70, 60, 80, 70, 90, 80, 100, 90, 110, 100, 120, 110, 130, 120, 140, 130, 150, 140, 160]) == True\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, -2, -3, -4, -5]) == True\n assert candidate(nums = [5, -5, 5, -5, 5]) == True\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == True\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5]) == True\n assert candidate(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) == False\n assert candidate(nums = [-1, 2, -1, 2, -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]) == False\n assert candidate(nums = [5, 15, -10, 5, 10, 0, -5, 15, 5]) == True\n assert candidate(nums = [100, -100, 100, -100, 100, -100]) == True\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -1, -2]) == 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 = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9]) == 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 = [100, 200, 300, 400, 500, 100, 200, 300, 400, 500, 600]) == True\n assert candidate(nums = [5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3]) == True\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == True\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == True\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == True\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50]) == True\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 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]) == True\n assert candidate(nums = [1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == True\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300]) == 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, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1]) == True\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == True\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3]) == 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]) == True\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == True\n", "comparison": "exact"}, "public_tests": ["[4,2,4]", "[1,2,3,4,5]", "[0,0,0]"], "hints": ["Use a counter to keep track of the subarray sums.", "Use a hashset to check if any two sums are equal."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:10+00:00", "tests_total": 119, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "php", "interface": {"raw_signature": "function findSubarrays($nums) {", "container": "Solution", "callable": "findSubarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2396, "task_id": "strictly-palindromic-number", "difficulty": "Medium", "problem_description": "An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.\n\nGiven an integer n, return true if n is strictly palindromic and false otherwise.\n\nA string is palindromic if it reads the same forward and backward.\n\nExample 1:\n\nInput: n = 9\nOutput: false\nExplanation: In base 2: 9 = 1001 (base 2), which is palindromic.\nIn base 3: 9 = 100 (base 3), which is not palindromic.\nTherefore, 9 is not strictly palindromic so we return false.\nNote that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.\n\nExample 2:\n\nInput: n = 4\nOutput: false\nExplanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.\nTherefore, we return false.\n\nConstraints:\n\n- 4 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 15) == False\n assert candidate(n = 4) == False\n assert candidate(n = 9) == False\n assert candidate(n = 6) == False\n assert candidate(n = 20) == False\n assert candidate(n = 100) == False\n assert candidate(n = 10) == False\n assert candidate(n = 5) == False\n assert candidate(n = 99999) == False\n assert candidate(n = 4096) == False\n assert candidate(n = 21) == False\n assert candidate(n = 50000) == False\n assert candidate(n = 1000) == False\n assert candidate(n = 50) == False\n assert candidate(n = 10001) == False\n assert candidate(n = 300) == False\n assert candidate(n = 30) == False\n assert candidate(n = 99) == False\n assert candidate(n = 16) == False\n assert candidate(n = 33) == False\n assert candidate(n = 10000) == False\n assert candidate(n = 17) == False\n assert candidate(n = 1001) == False\n assert candidate(n = 23) == False\n assert candidate(n = 42) == False\n assert candidate(n = 360) == False\n assert candidate(n = 1024) == False\n assert candidate(n = 101) == False\n assert candidate(n = 100000) == False\n assert candidate(n = 2048) == False\n assert candidate(n = 255) == False\n assert candidate(n = 999) == False\n assert candidate(n = 75) == False\n assert candidate(n = 256) == False\n assert candidate(n = 32) == False\n assert candidate(n = 5000) == False\n assert candidate(n = 18) == False\n assert candidate(n = 75000) == False\n assert candidate(n = 9999) == False\n assert candidate(n = 65535) == False\n assert candidate(n = 88888) == False\n assert candidate(n = 81) == False\n assert candidate(n = 4321) == False\n assert candidate(n = 150) == False\n assert candidate(n = 200) == False\n assert candidate(n = 400) == False\n assert candidate(n = 31) == False\n assert candidate(n = 1234) == False\n assert candidate(n = 750) == False\n assert candidate(n = 121) == False\n assert candidate(n = 199) == False\n assert candidate(n = 700) == False\n assert candidate(n = 500) == False\n assert candidate(n = 54321) == False\n assert candidate(n = 25) == False\n assert candidate(n = 25000) == False\n", "comparison": "exact"}, "public_tests": ["9", "4"], "hints": ["Consider the representation of the given number in the base n - 2.", "The number n in base (n - 2) is always 12, which is not palindromic."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().isStrictlyPalindromic", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:13+00:00", "tests_total": 57, "tests_dropped": 1, "flags": [], "topic_tags": ["math", "two-pointers", "brainteaser"]}, "language": "php", "interface": {"raw_signature": "function isStrictlyPalindromic($n) {", "container": "Solution", "callable": "isStrictlyPalindromic", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2397, "task_id": "maximum-rows-covered-by-columns", "difficulty": "Medium", "problem_description": "You are given an m x n binary matrix matrix and an integer numSelect.\n\nYour goal is to select exactly numSelect distinct columns from matrix such that you cover as many rows as possible.\n\nA row is considered covered if all the 1's in that row are also part of a column that you have selected. If a row does not have any 1s, it is also considered covered.\n\nMore formally, let us consider selected = {c_1, c_2, ...., c_numSelect} as the set of columns selected by you. A row i is covered by selected if:\n\n- For each cell where matrix[i][j] == 1, the column j is in selected.\n- Or, no cell in row i has a value of 1.\n\nReturn the maximum number of rows that can be covered by a set of numSelect columns.\n\nExample 1:\n\nInput: matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2\nOutput: 3\nExplanation:\nOne possible way to cover 3 rows is shown in the diagram above.\nWe choose s = {0, 2}.\n- Row 0 is covered because it has no occurrences of 1.\n- Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.\n- Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.\n- Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.\nThus, we can cover three rows.\nNote that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.\n\nExample 2:\n\nInput: matrix = [[1],[0]], numSelect = 1\nOutput: 2\nExplanation:\nSelecting the only column will result in both rows being covered since the entire matrix is selected.\n\nConstraints:\n\n- m == matrix.length\n- n == matrix[i].length\n- 1 <= m, n <= 12\n- matrix[i][j] is either 0 or 1.\n- 1 <= numSelect <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1], [0, 0], [1, 0], [0, 1]],numSelect = 1) == 2\n assert candidate(matrix = [[1, 1, 1], [0, 1, 1], [1, 0, 1]],numSelect = 1) == 0\n assert candidate(matrix = [[0, 0], [0, 0]],numSelect = 1) == 2\n assert candidate(matrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],numSelect = 4) == 4\n assert candidate(matrix = [[0, 1, 0], [1, 0, 1], [0, 1, 0]],numSelect = 1) == 2\n assert candidate(matrix = [[0, 0, 1, 1], [1, 0, 1, 0], [1, 1, 0, 0]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],numSelect = 1) == 0\n assert candidate(matrix = [[1], [0]],numSelect = 1) == 2\n assert candidate(matrix = [[1, 1, 0, 0], [0, 1, 1, 0], [1, 0, 1, 1], [0, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]],numSelect = 2) == 2\n assert candidate(matrix = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],numSelect = 4) == 4\n assert candidate(matrix = [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1]],numSelect = 2) == 1\n assert candidate(matrix = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0, 0]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1], [1, 0, 1], [0, 0, 0], [1, 1, 1]],numSelect = 2) == 2\n assert candidate(matrix = [[0, 0], [0, 0], [1, 1]],numSelect = 2) == 3\n assert candidate(matrix = [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [0, 1, 0, 1]],numSelect = 2) == 1\n assert candidate(matrix = [[0, 0, 0], [1, 0, 1], [0, 1, 1], [0, 0, 1]],numSelect = 2) == 3\n assert candidate(matrix = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 1, 1]],numSelect = 3) == 1\n assert candidate(matrix = [[0, 1, 1, 0], [0, 1, 1, 0], [0, 1, 0, 1], [1, 0, 0, 0]],numSelect = 3) == 3\n assert candidate(matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],numSelect = 1) == 3\n assert candidate(matrix = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 1, 1], [0, 0, 1, 0]],numSelect = 2) == 2\n assert candidate(matrix = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]],numSelect = 2) == 1\n assert candidate(matrix = [[1, 0, 0, 1, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],numSelect = 2) == 0\n assert candidate(matrix = [[1, 0, 0, 0, 0, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 1, 0, 0, 1, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[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], [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, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0]],numSelect = 8) == 7\n assert candidate(matrix = [[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]],numSelect = 2) == 0\n assert candidate(matrix = [[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]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1]],numSelect = 4) == 1\n assert candidate(matrix = [[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], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1], [1, 0, 1, 0, 1], [0, 0, 1, 1, 0], [1, 0, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[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]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0]],numSelect = 7) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]],numSelect = 5) == 3\n assert candidate(matrix = [[0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1], [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]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1, 0, 0, 1], [1, 0, 1, 0, 0], [1, 1, 0, 1, 0], [0, 0, 0, 0, 1], [1, 0, 1, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 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, 1, 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, 1, 0]],numSelect = 4) == 4\n assert candidate(matrix = [[0, 1, 1, 1, 0], [1, 1, 1, 0, 1], [1, 0, 1, 1, 0], [0, 0, 0, 0, 0], [1, 1, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 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]],numSelect = 5) == 3\n assert candidate(matrix = [[1, 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, 1, 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, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1]],numSelect = 4) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 1]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 1], [1, 1, 0, 0, 1, 0]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 0, 1, 1, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0]],numSelect = 6) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 1, 0, 1], [1, 0, 1, 1, 0], [0, 0, 0, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 1, 1, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[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]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0, 1, 1]],numSelect = 6) == 2\n assert candidate(matrix = [[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], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]],numSelect = 6) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 1], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 1, 0], [0, 0, 1, 1, 0, 0, 1]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 0, 1, 0]],numSelect = 3) == 2\n assert candidate(matrix = [[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]],numSelect = 2) == 2\n assert candidate(matrix = [[0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 1, 0, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 1, 0, 0]],numSelect = 2) == 0\n assert candidate(matrix = [[1, 1, 0, 0, 1], [1, 0, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1]],numSelect = 3) == 1\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 1, 0, 0, 1], [1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1], [1, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]],numSelect = 5) == 3\n assert candidate(matrix = [[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]],numSelect = 6) == 6\n assert candidate(matrix = [[1, 0, 0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 0, 0, 0, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0, 0, 1]],numSelect = 5) == 1\n assert candidate(matrix = [[1, 1, 1, 0, 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, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]],numSelect = 3) == 1\n assert candidate(matrix = [[1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0], [1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1], [1, 1, 1, 0, 0, 0]],numSelect = 4) == 2\n assert candidate(matrix = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 1], [1, 1, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1]],numSelect = 5) == 3\n assert candidate(matrix = [[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, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]],numSelect = 3) == 1\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]],numSelect = 8) == 3\n assert candidate(matrix = [[0, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 1], [0, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 0], [0, 0, 1, 0, 1, 1]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 0, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0], [1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0]],numSelect = 5) == 3\n assert candidate(matrix = [[1, 1, 0, 1, 1, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0, 0, 1], [1, 0, 1, 0, 1, 1, 0, 0]],numSelect = 4) == 1\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0]],numSelect = 4) == 3\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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], [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]],numSelect = 6) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 1], [0, 1, 0, 1, 1, 0], [0, 0, 1, 0, 1, 1], [1, 1, 0, 1, 0, 0]],numSelect = 4) == 2\n assert candidate(matrix = [[0, 1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 1, 0], [0, 1, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 1, 1], [0, 0, 1, 0, 0, 1, 0]],numSelect = 5) == 2\n assert candidate(matrix = [[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]],numSelect = 5) == 1\n assert candidate(matrix = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]],numSelect = 2) == 2\n assert candidate(matrix = [[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]],numSelect = 5) == 3\n assert candidate(matrix = [[1, 1, 1, 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, 0, 0, 0, 0, 1, 0, 0]],numSelect = 4) == 4\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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]],numSelect = 6) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1], [1, 1, 0, 0, 1, 0]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 0, 1, 0, 1], [1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1], [1, 0, 1, 1, 0, 0]],numSelect = 2) == 0\n assert candidate(matrix = [[1, 1, 1, 0, 1], [1, 0, 1, 1, 0], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 0, 0, 0], [1, 1, 0, 1, 0], [0, 0, 1, 0, 1], [1, 0, 0, 1, 1], [0, 0, 0, 1, 1], [1, 1, 0, 0, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]],numSelect = 7) == 3\n assert candidate(matrix = [[0, 1, 0, 1, 1], [1, 1, 0, 1, 0], [0, 0, 1, 1, 1], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1]],numSelect = 3) == 2\n assert candidate(matrix = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [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]],numSelect = 5) == 3\n assert candidate(matrix = [[1, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 0, 0, 1, 1], [1, 1, 1, 0, 1]],numSelect = 3) == 1\n assert candidate(matrix = [[0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]],numSelect = 5) == 2\n assert candidate(matrix = [[1, 1, 0, 1, 1, 0, 1, 1], [0, 0, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 0, 0]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 1, 1, 1, 0, 0, 1], [0, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0, 1, 0]],numSelect = 5) == 2\n assert candidate(matrix = [[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], [1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1]],numSelect = 6) == 3\n assert candidate(matrix = [[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]],numSelect = 2) == 0\n assert candidate(matrix = [[0, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 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], [0, 1, 1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 0, 1, 0]],numSelect = 5) == 3\n assert candidate(matrix = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 1, 0, 1], [1, 0, 0, 1, 0]],numSelect = 2) == 2\n assert candidate(matrix = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 0]],numSelect = 4) == 2\n assert candidate(matrix = [[1, 1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 0], [1, 1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 0, 1, 1]],numSelect = 4) == 1\n", "comparison": "exact"}, "public_tests": ["[[0,0,0],[1,0,1],[0,1,1],[0,0,1]]\n2", "[[1],[0]]\n1"], "hints": ["Try a brute-force approach.", "Iterate through all possible sets of exactly cols columns.", "For each valid set, check how many rows are covered, and return the maximum."], "metadata": {"canonical_parameter_names": ["matrix", "numSelect"], "leetcode_dataset_entry_point": "Solution().maximumRows", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:15+00:00", "tests_total": 99, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "backtracking", "bit-manipulation", "matrix", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function maximumRows($matrix, $numSelect) {", "container": "Solution", "callable": "maximumRows", "parameters": [{"name": "matrix", "type": "Integer[][]"}, {"name": "numSelect", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2398, "task_id": "maximum-number-of-robots-within-budget", "difficulty": "Hard", "problem_description": "You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The i^th robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.\n\nThe total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.\n\nReturn the maximum number of consecutive robots you can run such that the total cost does not exceed budget.\n\nExample 1:\n\nInput: chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25\nOutput: 3\nExplanation:\nIt is possible to run all individual and consecutive pairs of robots within budget.\nTo obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.\nIt can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.\n\nExample 2:\n\nInput: chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19\nOutput: 0\nExplanation: No robot can be run that does not exceed the budget, so we return 0.\n\nConstraints:\n\n- chargeTimes.length == runningCosts.length == n\n- 1 <= n <= 5 * 10^4\n- 1 <= chargeTimes[i], runningCosts[i] <= 10^5\n- 1 <= budget <= 10^15\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(chargeTimes = [1, 1, 1, 1, 1],runningCosts = [100000, 100000, 100000, 100000, 100000],budget = 500000) == 2\n assert candidate(chargeTimes = [7, 7, 7, 7],runningCosts = [1, 1, 1, 1],budget = 20) == 3\n assert candidate(chargeTimes = [100000, 100000, 100000, 100000, 100000],runningCosts = [100000, 100000, 100000, 100000, 100000],budget = 1000000000000) == 5\n assert candidate(chargeTimes = [1, 2, 3, 4, 5],runningCosts = [1, 2, 3, 4, 5],budget = 20) == 2\n assert candidate(chargeTimes = [100000, 100000, 100000],runningCosts = [1, 1, 1],budget = 300001) == 3\n assert candidate(chargeTimes = [5, 11, 2, 7],runningCosts = [3, 9, 1, 10],budget = 30) == 2\n assert candidate(chargeTimes = [11, 12, 19],runningCosts = [10, 8, 7],budget = 19) == 0\n assert candidate(chargeTimes = [1, 2, 3],runningCosts = [10, 20, 30],budget = 100) == 2\n assert candidate(chargeTimes = [1, 2, 3, 4, 5],runningCosts = [5, 4, 3, 2, 1],budget = 20) == 2\n assert candidate(chargeTimes = [5, 5, 5, 5, 5],runningCosts = [1, 1, 1, 1, 1],budget = 15) == 3\n assert candidate(chargeTimes = [3, 6, 1, 3, 4],runningCosts = [2, 1, 3, 4, 5],budget = 25) == 3\n assert candidate(chargeTimes = [100000, 100000, 100000],runningCosts = [100000, 100000, 100000],budget = 100000000000) == 3\n assert candidate(chargeTimes = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 500) == 4\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 50) == 4\n assert candidate(chargeTimes = [1, 3, 2, 4, 5, 3, 2, 1, 4, 5],runningCosts = [5, 1, 4, 2, 3, 5, 1, 4, 2, 3],budget = 25) == 3\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 20) == 4\n assert candidate(chargeTimes = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 30) == 4\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],runningCosts = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],budget = 100) == 4\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 10) == 2\n assert candidate(chargeTimes = [20, 10, 15, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],budget = 300) == 7\n assert candidate(chargeTimes = [3, 6, 1, 3, 4, 5, 7, 8, 9, 10, 2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],runningCosts = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],budget = 100) == 5\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9],budget = 40) == 3\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 20) == 4\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 300) == 10\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 1000) == 10\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],runningCosts = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 500) == 9\n assert candidate(chargeTimes = [3, 7, 9, 8, 5, 6, 2, 4],runningCosts = [10, 8, 5, 3, 9, 6, 7, 2],budget = 50) == 2\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 100) == 5\n assert candidate(chargeTimes = [10, 20, 30, 40, 50],runningCosts = [5, 15, 25, 35, 45],budget = 500) == 4\n assert candidate(chargeTimes = [10, 15, 20, 25, 30],runningCosts = [1, 2, 3, 4, 5],budget = 50) == 3\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],budget = 500005) == 2\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],runningCosts = [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],budget = 500) == 9\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 50) == 4\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60],budget = 250) == 3\n assert candidate(chargeTimes = [100, 200, 300, 400, 500],runningCosts = [5, 5, 5, 5, 5],budget = 1500) == 5\n assert candidate(chargeTimes = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 30) == 5\n assert candidate(chargeTimes = [3, 6, 1, 3, 4, 9, 12, 8, 10, 5],runningCosts = [2, 1, 3, 4, 5, 1, 2, 3, 4, 5],budget = 100) == 5\n assert candidate(chargeTimes = [1, 2, 3, 4, 5],runningCosts = [10000, 10000, 10000, 10000, 10000],budget = 50000) == 2\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 500) == 9\n assert candidate(chargeTimes = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],runningCosts = [5, 9, 2, 6, 5, 3, 5, 9, 1, 4, 1],budget = 150) == 6\n assert candidate(chargeTimes = [10000, 20000, 30000, 40000, 50000],runningCosts = [1000, 2000, 3000, 4000, 5000],budget = 100000) == 4\n assert candidate(chargeTimes = [100000, 100000, 100000, 100000, 100000],runningCosts = [1, 1, 1, 1, 1],budget = 500005) == 5\n assert candidate(chargeTimes = [10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],runningCosts = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],budget = 1000) == 6\n assert candidate(chargeTimes = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 10000) == 10\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 100) == 5\n assert candidate(chargeTimes = [1, 10, 100, 1000, 10000],runningCosts = [1, 10, 100, 1000, 10000],budget = 111111) == 5\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9],budget = 50) == 4\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],runningCosts = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],budget = 1000) == 9\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 55) == 4\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 5) == 2\n assert candidate(chargeTimes = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],runningCosts = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5],budget = 100) == 3\n assert candidate(chargeTimes = [100, 200, 300, 400, 500],runningCosts = [5, 10, 15, 20, 25],budget = 1000) == 5\n assert candidate(chargeTimes = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 25) == 4\n assert candidate(chargeTimes = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 45) == 3\n assert candidate(chargeTimes = [50, 25, 75, 100, 125, 200, 150, 225, 300, 350],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 1000) == 5\n assert candidate(chargeTimes = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 10) == 2\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 5) == 2\n assert candidate(chargeTimes = [1, 5, 1, 5, 1, 5],runningCosts = [1, 1, 1, 1, 1, 1],budget = 12) == 2\n assert candidate(chargeTimes = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 1000000) == 10\n assert candidate(chargeTimes = [5, 15, 10, 20, 25, 30, 35, 40, 45, 50],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 100) == 5\n assert candidate(chargeTimes = [50, 40, 30, 20, 10],runningCosts = [1, 2, 3, 4, 5],budget = 100) == 4\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9],budget = 45) == 3\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 10) == 3\n assert candidate(chargeTimes = [50, 40, 30, 20, 10],runningCosts = [1, 2, 3, 4, 5],budget = 200) == 5\n assert candidate(chargeTimes = [100000, 100000, 100000, 100000, 100000],runningCosts = [100000, 100000, 100000, 100000, 100000],budget = 500000) == 2\n assert candidate(chargeTimes = [100, 200, 300, 400, 500],runningCosts = [50, 40, 30, 20, 10],budget = 1000) == 4\n assert candidate(chargeTimes = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 100) == 5\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],runningCosts = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],budget = 500) == 4\n assert candidate(chargeTimes = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 5000010) == 10\n assert candidate(chargeTimes = [10, 20, 30, 40, 50],runningCosts = [1, 2, 3, 4, 5],budget = 100) == 4\n assert candidate(chargeTimes = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],runningCosts = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6],budget = 300) == 2\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],runningCosts = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],budget = 50) == 3\n assert candidate(chargeTimes = [100, 200, 300, 400, 500, 600],runningCosts = [1, 2, 3, 4, 5, 6],budget = 1500) == 6\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 100) == 5\n assert candidate(chargeTimes = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],budget = 100) == 5\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 15) == 3\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 500) == 4\n assert candidate(chargeTimes = [9, 7, 5, 11, 13, 2, 8],runningCosts = [4, 8, 12, 16, 20, 24, 28],budget = 100) == 3\n assert candidate(chargeTimes = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 1500) == 13\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],runningCosts = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 50) == 3\n assert candidate(chargeTimes = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 50) == 4\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],runningCosts = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 100) == 5\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 10) == 3\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 20) == 4\n assert candidate(chargeTimes = [1, 3, 2, 5, 4],runningCosts = [5, 3, 6, 2, 4],budget = 20) == 2\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9],budget = 100) == 5\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 200) == 6\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70],runningCosts = [1, 2, 3, 4, 5, 6, 7],budget = 200) == 6\n assert candidate(chargeTimes = [50, 40, 30, 20, 10],runningCosts = [1, 2, 3, 4, 5],budget = 300) == 5\n assert candidate(chargeTimes = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],runningCosts = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],budget = 150) == 6\n assert candidate(chargeTimes = [9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9],budget = 30) == 3\n assert candidate(chargeTimes = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 1000000) == 10\n assert candidate(chargeTimes = [100000, 90000, 80000, 70000, 60000],runningCosts = [10000, 9000, 8000, 7000, 6000],budget = 10000000) == 5\n assert candidate(chargeTimes = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 250) == 3\n assert candidate(chargeTimes = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 200) == 10\n assert candidate(chargeTimes = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],runningCosts = [25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3],budget = 200) == 5\n assert candidate(chargeTimes = [20, 18, 15, 12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],runningCosts = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],budget = 100) == 4\n assert candidate(chargeTimes = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 100) == 7\n assert candidate(chargeTimes = [100000, 100000, 100000, 100000, 100000],runningCosts = [1, 1, 1, 1, 1],budget = 500000) == 5\n assert candidate(chargeTimes = [1000, 2000, 3000, 4000, 5000],runningCosts = [5, 5, 5, 5, 5],budget = 10000) == 5\n assert candidate(chargeTimes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 300) == 16\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],runningCosts = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],budget = 500) == 10\n assert candidate(chargeTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],runningCosts = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],budget = 500) == 4\n assert candidate(chargeTimes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 150) == 5\n assert candidate(chargeTimes = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],runningCosts = [9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3],budget = 200) == 6\n assert candidate(chargeTimes = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],budget = 250) == 7\n assert candidate(chargeTimes = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],runningCosts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],budget = 50) == 4\n", "comparison": "exact"}, "public_tests": ["[3,6,1,3,4]\n[2,1,3,4,5]\n25", "[11,12,19]\n[10,8,7]\n19"], "hints": ["Use binary search to convert the problem into checking if we can find a specific number of consecutive robots within the budget.", "Maintain a sliding window of the consecutive robots being considered.", "Use either a map, deque, or heap to find the maximum charge times in the window efficiently."], "metadata": {"canonical_parameter_names": ["chargeTimes", "runningCosts", "budget"], "leetcode_dataset_entry_point": "Solution().maximumRobots", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:17+00:00", "tests_total": 108, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "binary-search", "queue", "sliding-window", "heap-priority-queue", "prefix-sum", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function maximumRobots($chargeTimes, $runningCosts, $budget) {", "container": "Solution", "callable": "maximumRobots", "parameters": [{"name": "chargeTimes", "type": "Integer[]"}, {"name": "runningCosts", "type": "Integer[]"}, {"name": "budget", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2399, "task_id": "check-distances-between-same-letters", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.\n\nEach letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).\n\nIn a well-spaced string, the number of letters between the two occurrences of the i^th letter is distance[i]. If the i^th letter does not appear in s, then distance[i] can be ignored.\n\nReturn true if s is a well-spaced string, otherwise return false.\n\nExample 1:\n\nInput: s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: true\nExplanation:\n- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.\n- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.\n- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.\nNote that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.\nReturn true because s is a well-spaced string.\n\nExample 2:\n\nInput: s = \"aa\", distance = [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]\nOutput: false\nExplanation:\n- 'a' appears at indices 0 and 1 so there are zero letters between them.\nBecause distance[0] = 1, s is not a well-spaced string.\n\nConstraints:\n\n- 2 <= s.length <= 52\n- s consists only of lowercase English letters.\n- Each letter appears in s exactly twice.\n- distance.length == 26\n- 0 <= distance[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefghijklmnopqrztuvwxyz\",distance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(s = \"zz\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"abcdcba\",distance = [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]) == False\n assert candidate(s = \"bbcaac\",distance = [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]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvwxyz\",distance = [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, 0]) == False\n assert candidate(s = \"abcabc\",distance = [2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abba\",distance = [2, 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]) == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",distance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(s = \"aa\",distance = [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]) == False\n assert candidate(s = \"abaccb\",distance = [1, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",distance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\",distance = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcde\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"zazbzczdzdzczbza\",distance = [2, 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]) == False\n assert candidate(s = \"abcdefghijkllkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"zxyxzyxzyx\",distance = [0, 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]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"aabbaa\",distance = [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]) == False\n assert candidate(s = \"zyxzyxzyxzyx\",distance = [0, 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]) == False\n assert candidate(s = \"acbacbacbacbacbacb\",distance = [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]) == False\n assert candidate(s = \"abcdefghijabcdefghij\",distance = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"zamnzamn\",distance = [0, 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]) == False\n assert candidate(s = \"abcdefghijzyxwvutsrqponmlk\",distance = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"mnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"abcdefggfedcba\",distance = [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]) == False\n assert candidate(s = \"abcdefgabcdefg\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"lkjihglkjh\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 1, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiii\",distance = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abababababababab\",distance = [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]) == True\n assert candidate(s = \"abababababababababababab\",distance = [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]) == True\n assert candidate(s = \"pqrstuvwxyzzzyxwvutsrqp\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == False\n assert candidate(s = \"abacabadabacabad\",distance = [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]) == False\n assert candidate(s = \"abcdefghijklmabcdefghijklm\",distance = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"qponmlkjihgfedcbazyxwvutsr\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"zzzyyxxwwvvuuttssrrqqppoonnmmlkkjjiihhggffeeddccbaa\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]) == False\n assert candidate(s = \"acbacbacbacb\",distance = [2, 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]) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzz\",distance = [25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"zyxzyxzyxzyxzyxzyx\",distance = [0, 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]) == False\n assert candidate(s = \"qrstuvwxzyabcdefghijklmnop\",distance = [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]) == True\n assert candidate(s = \"mnopqrstuvwxzzyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbazyxw\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 7, 6, 5]) == False\n assert candidate(s = \"abcdabcd\",distance = [3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefgihgfedcba\",distance = [0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdefgabcdefg\",distance = [5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"qrstuvqr\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"mnopqrsmnopqr\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"mnopmnop\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"qrstuvqrstuv\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdefgabcdefg\",distance = [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]) == False\n assert candidate(s = \"zebrazebra\",distance = [23, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdefghijhgfedcba\",distance = [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]) == False\n assert candidate(s = \"ababababababababababababababababababababab\",distance = [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]) == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"lmnopqrstuvw\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefgihgfedcba\",distance = [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"mnopqrstuvwxyzz\",distance = [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]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",distance = [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]) == False\n assert candidate(s = \"pqrsrqpq\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"zabyxwvutsrqponmlkjihgfedcba\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdabcdabcdabcdabcdabcd\",distance = [3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"qrstuvrstu\",distance = [0, 0, 0, 0, 0, 0, 0, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"acbacbacbacbacbacb\",distance = [1, 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]) == False\n assert candidate(s = \"lkjhlkjhlkjh\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"mnopqrsmnopqr\",distance = [0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdeffedcba\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]) == False\n assert candidate(s = \"zabzyabzyabzyabz\",distance = [0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]) == False\n assert candidate(s = \"abcdefghigfedcba\",distance = [7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"aabbaaccddaaff\",distance = [2, 2, 2, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",distance = [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]) == False\n assert candidate(s = \"abcdabcdeff\",distance = [1, 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"mnopqrstuvtwxzyabcdeffedcba\",distance = [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]) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",distance = [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]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzza\",distance = [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]) == False\n assert candidate(s = \"mnopqrstuv\",distance = [0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"mnopqrmpqr\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2, 1, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"lmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba\",distance = [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]) == False\n assert candidate(s = \"mnopmnop\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"acbacbacba\",distance = [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]) == False\n assert candidate(s = \"mnopqrsmnopqrsmnopqrs\",distance = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == False\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdefabcdef\",distance = [5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n assert candidate(s = \"abcdefghijklmnopqrstuvwxzy\",distance = [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]) == True\n assert candidate(s = \"qrstuvqponmlkjihgfedcbazyxw\",distance = [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]) == False\n assert candidate(s = \"abcdabcdabcd\",distance = [3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == True\n", "comparison": "exact"}, "public_tests": ["\"abaccb\"\n[1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", "\"aa\"\n[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]"], "hints": ["Create an integer array of size 26 to keep track of the first occurrence of each letter.", "The number of letters between indices i and j is j - i - 1."], "metadata": {"canonical_parameter_names": ["s", "distance"], "leetcode_dataset_entry_point": "Solution().checkDistances", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:19+00:00", "tests_total": 93, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function checkDistances($s, $distance) {", "container": "Solution", "callable": "checkDistances", "parameters": [{"name": "s", "type": "String"}, {"name": "distance", "type": "Integer[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2400, "task_id": "number-of-ways-to-reach-a-position-after-exactly-k-steps", "difficulty": "Medium", "problem_description": "You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.\n\nGiven a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 10^9 + 7.\n\nTwo ways are considered different if the order of the steps made is not exactly the same.\n\nNote that the number line includes negative integers.\n\nExample 1:\n\nInput: startPos = 1, endPos = 2, k = 3\nOutput: 3\nExplanation: We can reach position 2 from 1 in exactly 3 steps in three ways:\n- 1 -> 2 -> 3 -> 2.\n- 1 -> 2 -> 1 -> 2.\n- 1 -> 0 -> 1 -> 2.\nIt can be proven that no other way is possible, so we return 3.\n\nExample 2:\n\nInput: startPos = 2, endPos = 5, k = 10\nOutput: 0\nExplanation: It is impossible to reach position 5 from position 2 in exactly 10 steps.\n\nConstraints:\n\n- 1 <= startPos, endPos, k <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(startPos = 1,endPos = 2,k = 3) == 3\n assert candidate(startPos = 10,endPos = 1,k = 15) == 455\n assert candidate(startPos = 5,endPos = 5,k = 10) == 252\n assert candidate(startPos = 10,endPos = 1,k = 9) == 1\n assert candidate(startPos = 2,endPos = 5,k = 10) == 0\n assert candidate(startPos = 1,endPos = 2,k = 100) == 0\n assert candidate(startPos = 100,endPos = 50,k = 150) == 713790273\n assert candidate(startPos = 500,endPos = 450,k = 100) == 244856590\n assert candidate(startPos = 2,endPos = 1,k = 4) == 0\n assert candidate(startPos = 500,endPos = 400,k = 100) == 1\n assert candidate(startPos = 5,endPos = 5,k = 1) == 0\n assert candidate(startPos = 1000,endPos = 990,k = 20) == 15504\n assert candidate(startPos = 100,endPos = 50,k = 200) == 489348363\n assert candidate(startPos = 5,endPos = 15,k = 12) == 12\n assert candidate(startPos = 1,endPos = 2,k = 5) == 10\n assert candidate(startPos = 100,endPos = 100,k = 200) == 407336795\n assert candidate(startPos = 500,endPos = 400,k = 199) == 0\n assert candidate(startPos = 3,endPos = 3,k = 6) == 20\n assert candidate(startPos = 100,endPos = 100,k = 1) == 0\n assert candidate(startPos = 50,endPos = 50,k = 50) == 605552882\n assert candidate(startPos = 100,endPos = 200,k = 150) == 297103639\n", "comparison": "exact"}, "public_tests": ["1\n2\n3", "2\n5\n10"], "hints": ["How many steps to the left and to the right do you need to make exactly?", "Does the order of the steps matter?", "Use combinatorics to find the number of ways to order the steps."], "metadata": {"canonical_parameter_names": ["startPos", "endPos", "k"], "leetcode_dataset_entry_point": "Solution().numberOfWays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:21+00:00", "tests_total": 39, "tests_dropped": 18, "flags": [], "topic_tags": ["math", "dynamic-programming", "combinatorics"]}, "language": "php", "interface": {"raw_signature": "function numberOfWays($startPos, $endPos, $k) {", "container": "Solution", "callable": "numberOfWays", "parameters": [{"name": "startPos", "type": "Integer"}, {"name": "endPos", "type": "Integer"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2401, "task_id": "longest-nice-subarray", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers.\n\nWe call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.\n\nReturn the length of the longest nice subarray.\n\nA subarray is a contiguous part of an array.\n\nNote that subarrays of length 1 are always considered nice.\n\nExample 1:\n\nInput: nums = [1,3,8,48,10]\nOutput: 3\nExplanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:\n- 3 AND 8 = 0.\n- 3 AND 48 = 0.\n- 8 AND 48 = 0.\nIt can be proven that no longer nice subarray can be obtained, so we return 3.\n\nExample 2:\n\nInput: nums = [3,1,5,11,13]\nOutput: 1\nExplanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.\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, 1, 5, 11, 13]) == 1\n assert candidate(nums = [31, 1, 4, 32, 16]) == 4\n assert candidate(nums = [7, 11, 13, 14, 2, 5, 3]) == 2\n assert candidate(nums = [1, 2, 4, 8, 16]) == 5\n assert candidate(nums = [16, 17, 71, 62, 12, 24, 14]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [7, 14, 28, 56, 112]) == 1\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 2\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\n assert candidate(nums = [2, 1, 5, 6, 7, 4, 10]) == 2\n assert candidate(nums = [30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [31, 15, 7, 3, 1]) == 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]) == 20\n assert candidate(nums = [1, 3, 8, 48, 10]) == 3\n assert candidate(nums = [7, 11, 14, 18, 21, 23, 26, 28, 31, 33, 34, 38, 39, 42, 43, 46, 47, 50, 51, 54]) == 1\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == 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\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]) == 21\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, 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]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 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]) == 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]) == 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\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, 122, 126, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170]) == 1\n assert candidate(nums = [1, 2, 3, 5, 6, 10, 12, 15, 17, 20, 24, 28, 30, 31, 35, 40, 42, 48, 56, 60]) == 2\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576]) == 20\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 = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1023, 511, 255, 127, 63, 31, 15, 7, 3]) == 11\n assert candidate(nums = [2, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432]) == 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]) == 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]) == 1\n assert candidate(nums = [128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864]) == 20\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, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125]) == 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]) == 2\n assert candidate(nums = [255, 256, 257, 258, 259, 260, 261, 262, 263, 264]) == 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, 2097152]) == 22\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, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048]) == 21\n assert candidate(nums = [3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864, 3145728, 6291456, 12582912, 25165824, 50331648]) == 1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 20\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048]) == 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]) == 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]) == 2\n assert candidate(nums = [1, 2, 3, 5, 6, 10, 12, 15, 20, 21, 30, 60, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608]) == 23\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [2, 3, 6, 7, 14, 21, 23, 26, 31, 35, 38, 39, 42, 43, 46, 47, 51, 53, 54, 55, 58, 59, 62, 63, 66, 67, 70, 71, 75, 77, 78, 79, 82, 83, 86, 87, 91, 93, 94, 95, 98, 99, 102, 103, 106, 107, 111, 113, 114, 115, 118, 119, 122, 123, 127]) == 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]) == 25\n assert candidate(nums = [1, 2, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385, 32769, 65537, 131073, 262145, 524289]) == 2\n assert candidate(nums = [31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383]) == 1\n assert candidate(nums = [31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == 16\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]) == 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, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200]) == 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]) == 2\n assert candidate(nums = [1048575, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048]) == 9\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]) == 30\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]) == 2\n assert candidate(nums = [1, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == 2\n assert candidate(nums = [1, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152, 98304, 196608, 393216, 786432, 1572864]) == 2\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]) == 21\n assert candidate(nums = [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]) == 2\n assert candidate(nums = [1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911]) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [3, 5, 6, 9, 10, 12, 17, 18, 20, 24, 25, 30, 33, 34, 40, 41, 48, 50, 60, 64]) == 2\n assert candidate(nums = [1023, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 2\n assert candidate(nums = [1, 5, 3, 9, 7, 11, 13, 17, 15, 23, 21, 29, 27, 33, 31, 37, 35, 41, 39, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63]) == 1\n assert candidate(nums = [1, 6, 10, 18, 33, 66, 132, 264, 528, 1056, 2112, 4224, 8448, 16896, 33792, 67584, 135168, 270336, 540672, 1081344]) == 5\n assert candidate(nums = [8388607, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384]) == 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]) == 2\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]) == 2\n assert candidate(nums = [1, 2, 3, 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480, 40960, 81920, 163840, 327680]) == 2\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1]) == 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]) == 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]) == 1\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168, 14336, 28672, 57344, 114688, 229376, 458752, 917504, 1835008, 3670016]) == 1\n assert candidate(nums = [3, 5, 1, 2, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]) == 19\n assert candidate(nums = [31, 62, 124, 248, 496, 992, 1984, 3968, 7936, 15872, 31744, 63488, 126976, 253952, 507904, 1015808, 2031616, 4063232, 8126464, 16252928]) == 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]) == 1\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == 1\n assert candidate(nums = [511, 255, 127, 63, 31, 15, 7, 3, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]) == 12\n assert candidate(nums = [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]) == 30\n assert candidate(nums = [999999999, 536870911, 268435455, 134217727, 67108863, 33554431, 16777215, 8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023]) == 1\n", "comparison": "exact"}, "public_tests": ["[1,3,8,48,10]", "[3,1,5,11,13]"], "hints": ["What is the maximum possible length of a nice subarray?", "If two numbers have bitwise AND equal to zero, they do not have any common set bit. A number x <= 10^9 only has 30 bits, hence the length of the longest nice subarray cannot exceed 30."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().longestNiceSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:24+00:00", "tests_total": 115, "tests_dropped": 32, "flags": [], "topic_tags": ["array", "bit-manipulation", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function longestNiceSubarray($nums) {", "container": "Solution", "callable": "longestNiceSubarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2402, "task_id": "meeting-rooms-iii", "difficulty": "Hard", "problem_description": "You are given an integer n. There are n rooms numbered from 0 to n - 1.\n\nYou are given a 2D integer array meetings where meetings[i] = [start_i, end_i] means that a meeting will be held during the half-closed time interval [start_i, end_i). All the values of start_i are unique.\n\nMeetings are allocated to rooms in the following manner:\n\n1. Each meeting will take place in the unused room with the lowest number.\n2. If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.\n3. When a room becomes unused, meetings that have an earlier original start time should be given the room.\n\nReturn the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.\n\nA half-closed interval [a, b) is the interval between a and b including a and not including b.\n\nExample 1:\n\nInput: n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]\nOutput: 0\nExplanation:\n- At time 0, both rooms are not being used. The first meeting starts in room 0.\n- At time 1, only room 1 is not being used. The second meeting starts in room 1.\n- At time 2, both rooms are being used. The third meeting is delayed.\n- At time 3, both rooms are being used. The fourth meeting is delayed.\n- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).\n- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).\nBoth rooms 0 and 1 held 2 meetings, so we return 0.\n\nExample 2:\n\nInput: n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]\nOutput: 1\nExplanation:\n- At time 1, all three rooms are not being used. The first meeting starts in room 0.\n- At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.\n- At time 3, only room 2 is not being used. The third meeting starts in room 2.\n- At time 4, all three rooms are being used. The fourth meeting is delayed.\n- At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).\n- At time 6, all three rooms are being used. The fifth meeting is delayed.\n- At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).\nRoom 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.\n\nConstraints:\n\n- 1 <= n <= 100\n- 1 <= meetings.length <= 10^5\n- meetings[i].length == 2\n- 0 <= start_i < end_i <= 5 * 10^5\n- All the values of start_i are unique.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,meetings = [[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\n assert candidate(n = 5,meetings = [[0, 2], [1, 3], [2, 4], [3, 5], [4, 6]]) == 0\n assert candidate(n = 10,meetings = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]]) == 0\n assert candidate(n = 5,meetings = [[0, 30], [5, 10], [15, 20], [5, 10]]) == 1\n assert candidate(n = 2,meetings = [[0, 10], [1, 5], [2, 7], [3, 4]]) == 0\n assert candidate(n = 4,meetings = [[0, 2], [0, 3], [1, 2], [2, 4], [3, 5]]) == 0\n assert candidate(n = 1,meetings = [[1, 2], [3, 4], [5, 6]]) == 0\n assert candidate(n = 5,meetings = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 1,meetings = [[0, 1], [2, 3], [4, 5]]) == 0\n assert candidate(n = 10,meetings = [[0, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == 0\n assert candidate(n = 4,meetings = [[0, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 0\n assert candidate(n = 2,meetings = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 3,meetings = [[1, 20], [2, 10], [3, 5], [4, 9], [6, 8]]) == 1\n assert candidate(n = 3,meetings = [[0, 100], [101, 200], [201, 300], [301, 400]]) == 0\n assert candidate(n = 1,meetings = [[0, 100], [100, 200], [200, 300]]) == 0\n assert candidate(n = 4,meetings = [[1, 10], [2, 15], [3, 20], [4, 25], [5, 30]]) == 0\n assert candidate(n = 10,meetings = [[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]]) == 0\n assert candidate(n = 7,meetings = [[1, 5], [1, 10], [1, 15], [1, 20], [2, 6], [2, 11], [2, 16], [2, 21], [3, 7], [3, 12], [3, 17], [3, 22], [4, 8], [4, 13], [4, 18], [4, 23], [5, 9], [5, 14], [5, 19], [5, 24]]) == 4\n assert candidate(n = 6,meetings = [[0, 100], [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], [31, 69], [32, 68], [33, 67], [34, 66], [35, 65], [36, 64], [37, 63], [38, 62], [39, 61], [40, 60], [41, 59], [42, 58], [43, 57], [44, 56], [45, 55], [46, 54], [47, 53], [48, 52], [49, 51]]) == 0\n assert candidate(n = 10,meetings = [[1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20], [11, 21], [12, 22], [13, 23], [14, 24], [15, 25], [16, 26], [17, 27], [18, 28], [19, 29], [20, 30]]) == 0\n assert candidate(n = 6,meetings = [[1, 3], [2, 5], [4, 7], [6, 9], [8, 11], [10, 13], [12, 15], [14, 17], [16, 19], [18, 21]]) == 0\n assert candidate(n = 4,meetings = [[1, 10], [2, 8], [3, 6], [4, 5], [5, 15], [6, 12], [7, 10], [8, 20], [9, 11], [10, 13]]) == 1\n assert candidate(n = 5,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]]) == 0\n assert candidate(n = 7,meetings = [[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]]) == 0\n assert candidate(n = 8,meetings = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19], [11, 20], [12, 21], [13, 22], [14, 23], [15, 24], [16, 25], [17, 26], [18, 27], [19, 28], [20, 29], [21, 30]]) == 0\n assert candidate(n = 3,meetings = [[10, 15], [20, 25], [30, 35], [5, 10], [15, 20], [25, 30], [35, 40], [5, 15], [10, 20], [20, 30]]) == 0\n assert candidate(n = 10,meetings = [[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(n = 3,meetings = [[0, 10], [1, 5], [2, 7], [3, 4], [4, 6], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12]]) == 1\n assert candidate(n = 10,meetings = [[0, 1000], [500, 1500], [1000, 2000], [1500, 2500], [2000, 3000], [2500, 3500], [3000, 4000], [3500, 4500], [4000, 5000], [4500, 5500]]) == 0\n assert candidate(n = 2,meetings = [[0, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400], [350, 450], [400, 500], [450, 550]]) == 0\n assert candidate(n = 2,meetings = [[0, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100], [0, 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]]) == 0\n assert candidate(n = 5,meetings = [[0, 2], [0, 4], [0, 6], [0, 8], [0, 10], [1, 3], [1, 5], [1, 7], [1, 9], [2, 4], [2, 6], [2, 8], [3, 5], [3, 7], [4, 6], [4, 8], [5, 7], [6, 8], [7, 9], [8, 10]]) == 0\n assert candidate(n = 7,meetings = [[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\n assert candidate(n = 3,meetings = [[0, 3], [1, 2], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13]]) == 0\n assert candidate(n = 4,meetings = [[0, 10], [1, 5], [2, 7], [3, 4], [8, 12], [10, 15], [13, 18]]) == 1\n assert candidate(n = 6,meetings = [[0, 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]]) == 0\n assert candidate(n = 2,meetings = [[100, 105], [101, 106], [102, 107], [103, 108], [104, 109], [105, 110], [106, 111], [107, 112], [108, 113], [109, 114]]) == 0\n assert candidate(n = 5,meetings = [[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]]) == 0\n assert candidate(n = 3,meetings = [[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]]) == 0\n assert candidate(n = 4,meetings = [[0, 50], [10, 60], [20, 70], [30, 80], [40, 90], [50, 100], [60, 110], [70, 120], [80, 130], [90, 140]]) == 0\n assert candidate(n = 6,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]]) == 0\n assert candidate(n = 2,meetings = [[0, 10], [10, 20], [20, 30], [30, 40], [40, 50], [0, 15], [15, 25], [25, 35], [35, 45], [45, 55]]) == 0\n assert candidate(n = 7,meetings = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]]) == 1\n assert candidate(n = 7,meetings = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [0, 11], [1, 12], [2, 13], [3, 14], [4, 15]]) == 0\n assert candidate(n = 5,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]]) == 0\n assert candidate(n = 10,meetings = [[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]]) == 0\n assert candidate(n = 4,meetings = [[0, 30], [5, 10], [15, 20], [25, 35], [10, 25], [20, 30], [30, 40]]) == 1\n assert candidate(n = 7,meetings = [[1, 5], [2, 8], [3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [9, 15], [10, 16], [11, 17], [12, 18], [13, 19], [14, 20], [15, 21], [16, 22], [17, 23], [18, 24], [19, 25], [20, 26], [21, 27], [22, 28], [23, 29], [24, 30], [25, 31], [26, 32], [27, 33], [28, 34], [29, 35], [30, 36], [31, 37], [32, 38], [33, 39], [34, 40], [35, 41], [36, 42], [37, 43], [38, 44], [39, 45], [40, 46], [41, 47], [42, 48], [43, 49], [44, 50], [45, 51], [46, 52], [47, 53], [48, 54], [49, 55]]) == 0\n assert candidate(n = 6,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]]) == 0\n assert candidate(n = 7,meetings = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]]) == 0\n assert candidate(n = 3,meetings = [[0, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400]]) == 0\n assert candidate(n = 4,meetings = [[0, 3], [1, 5], [2, 6], [3, 9], [4, 10], [5, 12], [6, 13], [7, 15], [8, 17], [9, 18]]) == 0\n assert candidate(n = 8,meetings = [[0, 15], [15, 30], [30, 45], [45, 60], [60, 75], [75, 90], [90, 105], [105, 120], [120, 135], [135, 150], [150, 165], [165, 180], [180, 195], [195, 210], [210, 225]]) == 0\n assert candidate(n = 3,meetings = [[0, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [0, 30], [10, 40], [20, 50]]) == 0\n assert candidate(n = 8,meetings = [[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(n = 5,meetings = [[10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [15, 25], [25, 35], [35, 45], [45, 55], [55, 65]]) == 0\n assert candidate(n = 5,meetings = [[0, 2], [2, 4], [4, 6], [6, 8], [8, 10], [1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [12, 14], [14, 16], [16, 18], [18, 20]]) == 0\n assert candidate(n = 5,meetings = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20], [11, 21], [12, 22], [13, 23], [14, 24], [15, 25], [16, 26], [17, 27], [18, 28], [19, 29]]) == 0\n assert candidate(n = 3,meetings = [[1, 100], [101, 200], [201, 300], [10, 110], [110, 210], [210, 310], [20, 120], [120, 220], [220, 320], [30, 130], [130, 230], [230, 330]]) == 0\n assert candidate(n = 6,meetings = [[0, 2], [1, 4], [2, 6], [3, 8], [4, 10], [5, 12], [6, 14], [7, 16], [8, 18], [9, 20], [10, 22], [11, 24], [12, 26], [13, 28], [14, 30], [15, 32], [16, 34], [17, 36], [18, 38], [19, 40]]) == 0\n assert candidate(n = 2,meetings = [[0, 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]]) == 0\n assert candidate(n = 4,meetings = [[1, 15], [2, 3], [5, 12], [8, 10], [6, 14], [16, 20], [17, 19], [21, 25], [22, 24], [23, 26]]) == 1\n assert candidate(n = 6,meetings = [[0, 5], [1, 6], [2, 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], [17, 22], [18, 23], [19, 24], [20, 25], [21, 26], [22, 27], [23, 28], [24, 29], [25, 30]]) == 0\n assert candidate(n = 5,meetings = [[0, 10], [10, 20], [20, 30], [30, 40], [40, 50], [1, 11], [11, 21], [21, 31], [31, 41], [41, 51]]) == 0\n assert candidate(n = 6,meetings = [[1, 1000], [2, 2000], [3, 3000], [4, 4000], [5, 5000], [6, 6000], [7, 7000], [8, 8000], [9, 9000], [10, 10000]]) == 0\n assert candidate(n = 3,meetings = [[0, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400], [350, 450], [400, 500], [450, 550], [500, 600], [550, 650], [600, 700], [650, 750], [700, 800]]) == 0\n assert candidate(n = 3,meetings = [[0, 2], [0, 5], [0, 10], [5, 10], [10, 15], [5, 15], [10, 20], [15, 25], [20, 30], [25, 35]]) == 0\n assert candidate(n = 7,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]]) == 0\n assert candidate(n = 4,meetings = [[1, 10], [2, 15], [3, 12], [4, 11], [5, 14], [6, 13], [7, 16], [8, 17], [9, 18], [10, 19]]) == 0\n assert candidate(n = 3,meetings = [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]]) == 0\n assert candidate(n = 5,meetings = [[0, 2], [1, 4], [2, 6], [3, 8], [4, 10], [5, 12], [6, 14], [7, 16], [8, 18], [9, 20], [10, 22], [11, 24], [12, 26], [13, 28], [14, 30]]) == 0\n assert candidate(n = 5,meetings = [[0, 10], [10, 20], [20, 30], [30, 40], [40, 50], [5, 15], [15, 25], [25, 35], [35, 45], [45, 55]]) == 0\n assert candidate(n = 3,meetings = [[0, 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]]) == 0\n assert candidate(n = 2,meetings = [[0, 100], [50, 60], [20, 30], [10, 20], [30, 40], [70, 80], [110, 120], [90, 100], [130, 140], [150, 160]]) == 1\n assert candidate(n = 4,meetings = [[1, 18], [2, 15], [3, 12], [4, 9], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18]]) == 3\n assert candidate(n = 10,meetings = [[0, 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, 21]]) == 0\n assert candidate(n = 7,meetings = [[0, 100], [100, 200], [200, 300], [300, 400], [400, 500], [500, 600], [600, 700], [700, 800], [800, 900], [900, 1000], [100, 500], [200, 600], [300, 700], [400, 800], [500, 900], [600, 1000]]) == 0\n assert candidate(n = 4,meetings = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50]]) == 0\n assert candidate(n = 8,meetings = [[0, 2], [0, 4], [0, 6], [0, 8], [0, 10], [0, 12], [0, 14], [0, 16], [0, 18], [0, 20], [1, 3], [1, 5], [1, 7], [1, 9], [1, 11], [1, 13], [1, 15], [1, 17], [1, 19], [1, 21]]) == 2\n assert candidate(n = 4,meetings = [[0, 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, 21]]) == 0\n assert candidate(n = 5,meetings = [[0, 50], [10, 60], [20, 70], [30, 80], [40, 90], [50, 100], [60, 110], [70, 120], [80, 130], [90, 140]]) == 0\n assert candidate(n = 5,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]]) == 0\n assert candidate(n = 4,meetings = [[1, 10], [10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60], [55, 65], [60, 70]]) == 0\n assert candidate(n = 3,meetings = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [3, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12]]) == 0\n assert candidate(n = 7,meetings = [[0, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400], [350, 450], [400, 500], [450, 550], [500, 600], [550, 650], [600, 700], [650, 750], [700, 800]]) == 0\n assert candidate(n = 6,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]]) == 0\n assert candidate(n = 1,meetings = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110], [11, 120], [12, 130], [13, 140], [14, 150], [15, 160], [16, 170], [17, 180], [18, 190], [19, 200], [20, 210], [21, 220], [22, 230], [23, 240], [24, 250], [25, 260], [26, 270], [27, 280], [28, 290], [29, 300]]) == 0\n assert candidate(n = 6,meetings = [[1, 6], [2, 5], [3, 4], [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]]) == 0\n assert candidate(n = 10,meetings = [[0, 10], [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, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == 0\n assert candidate(n = 4,meetings = [[0, 15], [5, 20], [10, 25], [15, 30], [20, 35], [25, 40]]) == 0\n", "comparison": "exact"}, "public_tests": ["2\n[[0,10],[1,5],[2,7],[3,4]]", "3\n[[1,20],[2,10],[3,5],[4,9],[6,8]]"], "hints": ["Sort meetings based on start times.", "Use two min heaps, the first one keeps track of the numbers of all the rooms that are free. The second heap keeps track of the end times of all the meetings that are happening and the room that they are in.", "Keep track of the number of times each room is used in an array.", "With each meeting, check if there are any free rooms. If there are, then use the room with the smallest number. Otherwise, assign the meeting to the room whose meeting will end the soonest."], "metadata": {"canonical_parameter_names": ["n", "meetings"], "leetcode_dataset_entry_point": "Solution().mostBooked", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:27+00:00", "tests_total": 92, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "sorting", "heap-priority-queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function mostBooked($n, $meetings) {", "container": "Solution", "callable": "mostBooked", "parameters": [{"name": "n", "type": "Integer"}, {"name": "meetings", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2404, "task_id": "most-frequent-even-element", "difficulty": "Easy", "problem_description": "Given an integer array nums, return the most frequent even element.\n\nIf there is a tie, return the smallest one. If there is no such element, return -1.\n\nExample 1:\n\nInput: nums = [0,1,2,2,4,4,1]\nOutput: 2\nExplanation:\nThe even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.\nWe return the smallest one, which is 2.\n\nExample 2:\n\nInput: nums = [4,4,4,9,2,4]\nOutput: 4\nExplanation: 4 is the even element appears the most.\n\nExample 3:\n\nInput: nums = [29,47,21,41,13,37,25,7]\nOutput: -1\nExplanation: There is no even element.\n\nConstraints:\n\n- 1 <= nums.length <= 2000\n- 0 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [29, 47, 21, 41, 13, 37, 25, 7]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15]) == -1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4]) == 4\n assert candidate(nums = [8, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6]) == 8\n assert candidate(nums = [10, 20, 20, 10, 10, 20, 20, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [1, 3, 5, 7, 9]) == -1\n assert candidate(nums = [10, 20, 20, 10, 30, 30, 30, 20, 20]) == 20\n assert candidate(nums = [10, 20, 20, 10, 10, 20, 20]) == 20\n assert candidate(nums = [6, 6, 6, 6, 8, 8, 8, 8, 10, 10]) == 6\n assert candidate(nums = [6, 6, 6, 8, 8, 8, 10, 10, 10]) == 6\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 4, 4, 4]) == 2\n assert candidate(nums = [0, 1, 2, 2, 4, 4, 1]) == 2\n assert candidate(nums = [2]) == 2\n assert candidate(nums = [6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11]) == -1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13]) == -1\n assert candidate(nums = [6, 6, 6, 8, 8, 8, 10, 10]) == 6\n assert candidate(nums = [6, 6, 8, 8, 8, 10, 10, 10, 10]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\n assert candidate(nums = [0]) == 0\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate(nums = [100000, 100000, 99998, 99998, 99996]) == 99998\n assert candidate(nums = [10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30]) == 10\n assert candidate(nums = [4, 4, 4, 9, 2, 4]) == 4\n assert candidate(nums = [100000, 100000, 99998, 99998, 99998]) == 99998\n assert candidate(nums = [0, 0, 0, 1, 1, 1, 2, 2, 2]) == 0\n assert candidate(nums = [2, 2, 2, 2, 2]) == 2\n assert candidate(nums = [2, 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, 22, 24, 26, 28, 30]) == 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]) == 10\n assert candidate(nums = [99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131]) == -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, 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, 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]) == 2\n assert candidate(nums = [0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8]) == 8\n assert candidate(nums = [6, 6, 8, 8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 12]) == 12\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 10000, 10000, 10000]) == 10000\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 100, 200, 200, 300, 300, 300, 300]) == 300\n assert candidate(nums = [0, 0, 0, 2, 2, 2, 4, 4, 4, 6, 6, 8, 8, 8, 8]) == 8\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 = [100000, 100000, 100000, 99998, 99998, 99996, 99996, 99996, 99994, 99994]) == 99996\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\n assert candidate(nums = [1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]) == 1500\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 4\n assert candidate(nums = [99998, 99998, 99998, 99996, 99996, 99994, 99994, 99994, 99992, 99992, 99992, 99992]) == 99992\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 50000\n assert candidate(nums = [12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 12\n assert candidate(nums = [5, 3, 1, 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, 8, 8, 8, 10, 10, 10, 12, 12, 14, 14, 14, 16, 16, 16, 16]) == 8\n assert candidate(nums = [100000, 99998, 99998, 99996, 99996, 99996, 99994, 99994]) == 99996\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 100, 100]) == 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, 2, 4, 6, 8, 10]) == 2\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\n assert candidate(nums = [0, 0, 2, 2, 2, 4, 4, 4, 4, 6, 6]) == 4\n assert candidate(nums = [2, 2, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(nums = [100000, 100000, 100000, 99998, 99998, 99998, 99996, 99996, 99994]) == 99998\n assert candidate(nums = [18, 18, 18, 18, 20, 20, 20, 20, 22, 22, 22, 22, 24, 24, 24, 24]) == 18\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]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10]) == 2\n assert candidate(nums = [2, 2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, 18, 20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28, 28, 30, 30, 30, 32, 32, 32, 34, 34, 34, 36, 36, 36, 38, 38, 38, 40, 40, 40, 42, 42, 42, 44, 44, 44, 46, 46, 46, 48, 48, 48, 50, 50, 50, 52, 52, 52, 54, 54, 54, 56, 56, 56, 58, 58, 58, 60, 60, 60, 62, 62, 62, 64, 64, 64, 66, 66, 66, 68, 68, 68, 70, 70, 70, 72, 72, 72, 74, 74, 74, 76, 76, 76, 78, 78, 78, 80, 80, 80, 82, 82, 82, 84, 84, 84, 86, 86, 86, 88, 88, 88, 90, 90, 90, 92, 92, 92, 94, 94, 94, 96, 96, 96, 98, 98, 98]) == 2\n assert candidate(nums = [6, 8, 10, 8, 6, 6, 8, 10, 10, 10, 10, 8]) == 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, 22, 24, 26, 28, 30, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 2\n assert candidate(nums = [1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19]) == -1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 4\n assert candidate(nums = [10, 10, 10, 20, 20, 30, 30, 40, 40, 40, 50, 50, 50, 50]) == 50\n assert candidate(nums = [100000, 100000, 99998, 99998, 99998, 99996, 99996, 99996, 99996]) == 99996\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\n assert candidate(nums = [100000, 50000, 100000, 50000, 20000, 20000, 20000, 20000]) == 20000\n assert candidate(nums = [2, 4, 6, 8, 10, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10]) == 2\n assert candidate(nums = [8, 6, 8, 8, 6, 6, 8, 8, 6, 6, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6]) == 6\n assert candidate(nums = [10, 20, 10, 30, 20, 20, 40, 40, 40, 40, 60, 60]) == 40\n assert candidate(nums = [18, 18, 18, 20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28, 28, 30, 30, 30]) == 18\n assert candidate(nums = [8, 3, 8, 6, 8, 5, 6, 6, 2, 2, 2, 10, 10, 10, 10]) == 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, 52, 54, 56, 58, 60]) == 2\n assert candidate(nums = [0, 2, 2, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8]) == 8\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, 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]) == 4\n assert candidate(nums = [10, 10, 10, 12, 12, 14, 14, 14, 16, 16, 16, 16, 18, 18, 18, 18, 18, 20, 20, 20, 20, 20]) == 18\n assert candidate(nums = [20000, 20000, 19998, 19998, 19996, 19996, 19994, 19994, 19992, 19992]) == 19992\n assert candidate(nums = [2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8, 8, 10, 10, 10, 10, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 12, 12, 14, 16, 18, 20]) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 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, 8, 10]) == 2\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, 20, 30, 30, 30, 40, 40, 40, 40]) == 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]) == 2\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18]) == 8\n assert candidate(nums = [20000, 19998, 19998, 19996, 19996, 19996, 19994, 19994, 19992, 19992, 19992, 19992]) == 19992\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 = [2, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10, 10]) == 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, 10, 10, 10, 10, 10]) == 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, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [2, 4, 4, 6, 6, 6, 8, 8, 8, 8, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12]) == 12\n assert candidate(nums = [100000, 100000, 99998, 99998, 99998, 99996, 99996, 99996, 99994, 99994, 99994, 99994]) == 99994\n assert candidate(nums = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 46, 48, 48, 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 76, 78, 78, 80, 80, 82, 82, 84, 84, 86, 86, 88, 88, 90, 90, 92, 92, 94, 94, 96, 96, 98, 98, 100, 100]) == 2\n assert candidate(nums = [1000, 2000, 1000, 3000, 4000, 4000, 5000, 5000, 5000, 5000, 6000, 6000, 6000, 6000, 6000]) == 6000\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 6]) == 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, 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, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]) == 2\n assert candidate(nums = [100000, 100000, 100000, 50000, 50000, 50000, 50000, 25000, 25000]) == 50000\n assert candidate(nums = [42, 42, 42, 42, 44, 44, 44, 44, 46, 46, 46, 46]) == 42\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\n assert candidate(nums = [8, 8, 8, 6, 6, 6, 4, 4, 4, 4]) == 4\n assert candidate(nums = [5000, 4000, 3000, 2000, 1000, 1000, 2000, 3000, 4000, 5000, 5000, 4000, 3000, 2000, 1000]) == 1000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 200, 200, 300, 300, 300, 400, 400, 400, 400, 500, 500, 500, 500, 500, 600, 600, 600, 600, 600, 600, 700, 700, 700, 700, 700, 700, 700, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 900, 900, 900, 900, 900, 900, 900, 900, 900, 900, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 1000\n", "comparison": "exact"}, "public_tests": ["[0,1,2,2,4,4,1]", "[4,4,4,9,2,4]", "[29,47,21,41,13,37,25,7]"], "hints": ["Could you count the frequency of each even element in the array?", "Would a hashmap help?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().mostFrequentEven", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:31+00:00", "tests_total": 110, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function mostFrequentEven($nums) {", "container": "Solution", "callable": "mostFrequentEven", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2405, "task_id": "optimal-partition-of-string", "difficulty": "Medium", "problem_description": "Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.\n\nReturn the minimum number of substrings in such a partition.\n\nNote that each character should belong to exactly one substring in a partition.\n\nExample 1:\n\nInput: s = \"abacaba\"\nOutput: 4\nExplanation:\nTwo possible partitions are (\"a\",\"ba\",\"cab\",\"a\") and (\"ab\",\"a\",\"ca\",\"ba\").\nIt can be shown that 4 is the minimum number of substrings needed.\n\nExample 2:\n\nInput: s = \"ssssss\"\nOutput: 6\nExplanation:\nThe only valid partition is (\"s\",\"s\",\"s\",\"s\",\"s\",\"s\").\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of only English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\") == 1\n assert candidate(s = \"abac\") == 2\n assert candidate(s = \"abcdabcdeabcdefabcdefg\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 44\n assert candidate(s = \"abababab\") == 4\n assert candidate(s = \"aaaaa\") == 5\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"optimal\") == 1\n assert candidate(s = \"abcabcabc\") == 3\n assert candidate(s = \"ssssss\") == 6\n assert candidate(s = \"abcabcabcabc\") == 4\n assert candidate(s = \"ab\") == 1\n assert candidate(s = \"partition\") == 2\n assert candidate(s = \"racecar\") == 2\n assert candidate(s = \"xyzxyzxyz\") == 3\n assert candidate(s = \"abcadef\") == 2\n assert candidate(s = \"banana\") == 3\n assert candidate(s = \"abc\") == 1\n assert candidate(s = \"pqrspqrspqrs\") == 3\n assert candidate(s = \"aabbccddeeff\") == 7\n assert candidate(s = \"abcdeabcde\") == 2\n assert candidate(s = \"aabbcc\") == 4\n assert candidate(s = \"unique\") == 2\n assert candidate(s = \"characters\") == 2\n assert candidate(s = \"aaaaaaaaa\") == 9\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 27\n assert candidate(s = \"abacaba\") == 4\n assert candidate(s = \"abca\") == 2\n assert candidate(s = \"zxyxzyxz\") == 3\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzxy\") == 40\n assert candidate(s = \"abcdeabcdeabcdeabcdeabcde\") == 5\n assert candidate(s = \"xyxxyxyxyxxyxyxyxyxyx\") == 12\n assert candidate(s = \"repeatrepeatrepeatrepeatrepeat\") == 10\n assert candidate(s = \"uniquecharacterswithoutrepeating\") == 6\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 23\n assert candidate(s = \"abacabadabacabaeabacabafabacabadabacabaeabacabaf\") == 24\n assert candidate(s = \"abacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabaf\") == 72\n assert candidate(s = \"abacabadabacabad\") == 8\n assert candidate(s = \"aaaaabbbbbccccdddd\") == 15\n assert candidate(s = \"abcdabcdeabcdabcdef\") == 4\n assert candidate(s = \"aaaabbbbccccddddeeeeffffgggghhhhiiiiiiijjjjjjkkkkkkklllllllmmmmmmmnnnnnnnooooooooppppppppqqqqqqqqrrrrrrrrssssssssttttttttuuuuuuuuvvvvvvvvwwwwwwwwxxxxxxxxxyyyyyyyyzzzzzzzz\") == 145\n assert candidate(s = \"longerstringwithoutrepeats\") == 5\n assert candidate(s = \"abcba\") == 2\n assert candidate(s = \"mississippimississippimississippi\") == 15\n assert candidate(s = \"aaaaabbbbbcccccdddddeeeeeeaaaaabbbbbcccccdddddeeeeeeaaaaabbbbbcccccdddddeeeeeeaaaaabbbbbcccccdddddeeeeee\") == 85\n assert candidate(s = \"aaaaabbbbbcccccdddddeeeee\") == 21\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 30\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 16\n assert candidate(s = \"abracadabraabracadabraabracadabra\") == 15\n assert candidate(s = \"aaaaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh\") == 59\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzz\") == 29\n assert candidate(s = \"noon\") == 2\n assert candidate(s = \"abcabcabcabcabcabc\") == 6\n assert candidate(s = \"thisisaverylongstringthatwilltestthealgorithm\") == 9\n assert candidate(s = \"hellohellohellohellohellohello\") == 12\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzz\") == 24\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 4\n assert candidate(s = \"abcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcbaabcdedcba\") == 20\n assert candidate(s = \"abacdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 3\n assert candidate(s = \"abacaxbabax\") == 5\n assert candidate(s = \"aaaaaaaabbbbbbbbccccccccddddddddeeeeeeee\") == 36\n assert candidate(s = \"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\") == 40\n assert candidate(s = \"abababababababababab\") == 10\n assert candidate(s = \"abacabadabacaba\") == 8\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 36\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 3\n assert candidate(s = \"thecuriouscaseofjeffersonraisethetrapdoor\") == 8\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdefghijklmnopqrstuvwxyz\") == 28\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 70\n assert candidate(s = \"aaaaabbbbbccccddddeeeeffffgggg\") == 24\n assert candidate(s = \"xyzzysabcabcabcabcabcabcabcabc\") == 9\n assert candidate(s = \"abcdefghijklaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 38\n assert candidate(s = \"abracadabraabracadabra\") == 10\n assert candidate(s = \"ababcbabcab\") == 5\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 28\n assert candidate(s = \"mnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 61\n assert candidate(s = \"abacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabaf\") == 36\n assert candidate(s = \"aabbccddeeffaabbccddeeff\") == 13\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 40\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 9\n assert candidate(s = \"thisisanexamplestringthatneedstobepartitionedproperly\") == 9\n assert candidate(s = \"abacabadabacabaeabacabaf\") == 12\n assert candidate(s = \"abacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabaf\") == 60\n assert candidate(s = \"aabcbcbcbaabcabcbcbcba\") == 10\n assert candidate(s = \"mnopqrsmnopqrsmnopqrsmnopqrs\") == 4\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm\") == 2\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcd\") == 8\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 5\n assert candidate(s = \"aaaaaabbcccddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooo\") == 43\n assert candidate(s = \"abcabcabcabcabcabcabcabc\") == 8\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 2\n assert candidate(s = \"abcdabcdaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 29\n assert candidate(s = \"abacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabafabacabadabacabaeabacabaf\") == 48\n assert candidate(s = \"ppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxxyyyyzzzz\") == 35\n assert candidate(s = \"aabbaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 29\n assert candidate(s = \"xyzzxyzzxyzzxyzzxyzzxyzz\") == 12\n assert candidate(s = \"mississippi\") == 5\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzz\") == 43\n assert candidate(s = \"abcabcabcabcabc\") == 5\n assert candidate(s = \"aaaaabbbbbbbaaaabbbbbbbaaaabbbbbbbaaaabbbbb\") == 36\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 50\n", "comparison": "exact"}, "public_tests": ["\"abacaba\"", "\"ssssss\""], "hints": ["Try to come up with a greedy approach.", "From left to right, extend every substring in the partition as much as possible."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().partitionString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:34+00:00", "tests_total": 103, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function partitionString($s) {", "container": "Solution", "callable": "partitionString", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2406, "task_id": "divide-intervals-into-minimum-number-of-groups", "difficulty": "Medium", "problem_description": "You are given a 2D integer array intervals where intervals[i] = [left_i, right_i] represents the inclusive interval [left_i, right_i].\n\nYou have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.\n\nReturn the minimum number of groups you need to make.\n\nTwo intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.\n\nExample 1:\n\nInput: intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]\nOutput: 3\nExplanation: We can divide the intervals into the following groups:\n- Group 1: [1, 5], [6, 8].\n- Group 2: [2, 3], [5, 10].\n- Group 3: [1, 10].\nIt can be proven that it is not possible to divide the intervals into fewer than 3 groups.\n\nExample 2:\n\nInput: intervals = [[1,3],[5,6],[8,10],[11,13]]\nOutput: 1\nExplanation: None of the intervals overlap, so we can put all of them in one group.\n\nConstraints:\n\n- 1 <= intervals.length <= 10^5\n- intervals[i].length == 2\n- 1 <= left_i <= right_i <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8]]) == 1\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 2\n assert candidate(intervals = [[1, 1000000]]) == 1\n assert candidate(intervals = [[5, 10], [6, 8], [1, 5], [2, 3], [1, 10]]) == 3\n assert candidate(intervals = [[1, 3], [5, 6], [8, 10], [11, 13]]) == 1\n assert candidate(intervals = [[1, 100], [50, 60], [60, 90]]) == 3\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30]]) == 2\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 1\n assert candidate(intervals = [[1, 2], [1, 3], [1, 4], [1, 5]]) == 4\n assert candidate(intervals = [[1, 5], [2, 9], [3, 7], [4, 10]]) == 4\n assert candidate(intervals = [[1, 100], [2, 99], [3, 98], [4, 97]]) == 4\n assert candidate(intervals = [[5, 10], [11, 15], [16, 20], [21, 25], [1, 5], [6, 10], [11, 15], [16, 20], [21, 25]]) == 2\n assert candidate(intervals = [[5, 15], [10, 20], [25, 30], [5, 10], [15, 25], [20, 25]]) == 3\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8]]) == 3\n assert candidate(intervals = [[1, 10], [2, 5], [3, 8], [4, 9], [5, 10], [6, 11]]) == 5\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30], [5, 15], [15, 25]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 2\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 2\n assert candidate(intervals = [[1000, 2000], [1500, 2500], [2000, 3000], [2500, 3500], [3000, 4000], [3500, 4500]]) == 3\n assert candidate(intervals = [[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], [15, 36], [16, 35], [17, 34], [18, 33], [19, 32], [20, 31], [21, 30], [22, 29], [23, 28], [24, 27], [25, 26]]) == 25\n assert candidate(intervals = [[1, 5], [2, 5], [3, 5], [4, 5], [5, 5]]) == 5\n assert candidate(intervals = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6]]) == 5\n assert candidate(intervals = [[1, 1000], [2, 999], [3, 998], [4, 997], [5, 996], [6, 995], [7, 994], [8, 993], [9, 992], [10, 991]]) == 10\n assert candidate(intervals = [[1, 3], [2, 5], [3, 7], [4, 9], [5, 11], [6, 13], [7, 15]]) == 5\n assert candidate(intervals = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50]]) == 3\n assert candidate(intervals = [[1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 5\n assert candidate(intervals = [[10, 20], [15, 25], [20, 30], [25, 35], [30, 40], [35, 45], [40, 50], [45, 55], [50, 60], [55, 65]]) == 3\n assert candidate(intervals = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100], [1, 50], [51, 100]]) == 11\n assert candidate(intervals = [[1, 500000], [500001, 1000000], [2, 499999], [500002, 999998], [3, 499998], [500003, 999997]]) == 3\n assert candidate(intervals = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11], [8, 12], [9, 13], [10, 14]]) == 5\n assert candidate(intervals = [[1, 500000], [500001, 1000000], [1, 500000], [500001, 1000000]]) == 2\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 1\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == 3\n assert candidate(intervals = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96], [6, 95], [7, 94], [8, 93], [9, 92], [10, 91]]) == 10\n assert candidate(intervals = [[1, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50]]) == 2\n assert candidate(intervals = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]]) == 5\n assert candidate(intervals = [[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]) == 10\n assert candidate(intervals = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996], [6, 99995], [7, 99994], [8, 99993], [9, 99992], [10, 99991]]) == 10\n assert candidate(intervals = [[5, 10], [15, 20], [25, 30], [10, 15], [20, 25], [30, 35], [15, 20], [25, 30], [35, 40], [20, 25]]) == 4\n assert candidate(intervals = [[1, 10], [11, 20], [1, 10], [11, 20], [1, 10], [11, 20]]) == 3\n assert candidate(intervals = [[1, 3], [2, 6], [3, 9], [4, 12], [5, 15]]) == 4\n assert candidate(intervals = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 9\n assert candidate(intervals = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25], [26, 30], [1, 10], [6, 15], [11, 20], [16, 25]]) == 3\n assert candidate(intervals = [[1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10], [1, 10]]) == 10\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 2\n assert candidate(intervals = [[1, 3], [3, 5], [5, 7], [7, 9], [9, 11], [11, 13], [13, 15], [15, 17], [17, 19]]) == 2\n assert candidate(intervals = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997]]) == 4\n assert candidate(intervals = [[1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 5\n assert candidate(intervals = [[1, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 2\n assert candidate(intervals = [[5, 10], [15, 20], [25, 30], [5, 20], [10, 25], [15, 30], [5, 30]]) == 5\n assert candidate(intervals = [[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7, 16], [8, 17], [9, 18], [10, 19]]) == 10\n assert candidate(intervals = [[1, 100000], [100000, 200000], [200000, 300000], [300000, 400000], [400000, 500000]]) == 2\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [50, 60], [60, 70], [70, 80], [80, 90], [90, 100]]) == 2\n assert candidate(intervals = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7]]) == 6\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350], [300, 400]]) == 3\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [1, 5], [5, 9], [9, 13]]) == 3\n assert candidate(intervals = [[1, 3], [2, 5], [4, 7], [6, 9], [8, 11], [10, 13], [12, 15]]) == 2\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300], [250, 350]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == 3\n assert candidate(intervals = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]]) == 9\n assert candidate(intervals = [[1, 10], [1, 20], [1, 30], [1, 40], [1, 50], [1, 60], [1, 70], [1, 80], [1, 90], [1, 100]]) == 10\n assert candidate(intervals = [[1, 10], [11, 20], [1, 10], [11, 20], [1, 10], [11, 20], [1, 10], [11, 20]]) == 4\n assert candidate(intervals = [[1, 2], [2, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30]]) == 2\n assert candidate(intervals = [[1, 5], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 3\n assert candidate(intervals = [[1, 1000000], [1, 1000000], [1, 1000000]]) == 3\n assert candidate(intervals = [[1, 5], [1, 5], [1, 5], [1, 5], [1, 5], [1, 5]]) == 6\n assert candidate(intervals = [[1, 3], [1, 3], [1, 3], [2, 4], [2, 4], [2, 4], [3, 5], [3, 5], [3, 5], [4, 6], [4, 6], [4, 6], [5, 7], [5, 7], [5, 7]]) == 9\n assert candidate(intervals = [[1, 1000000], [2, 999999], [3, 999998], [4, 999997], [5, 999996]]) == 5\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == 2\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50]]) == 2\n assert candidate(intervals = [[1, 100000], [2, 99999], [3, 99998], [4, 99997], [5, 99996]]) == 5\n assert candidate(intervals = [[1, 1000], [500, 1500], [1000, 2000], [1500, 2500], [2000, 3000], [2500, 3500], [3000, 4000]]) == 3\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 6\n assert candidate(intervals = [[1, 3], [2, 6], [8, 10], [15, 18], [3, 5], [6, 9], [12, 14]]) == 3\n assert candidate(intervals = [[1, 10], [11, 20], [21, 30], [31, 40], [1, 10], [11, 20], [21, 30], [31, 40], [1, 10]]) == 3\n assert candidate(intervals = [[10, 20], [20, 30], [30, 40], [10, 20], [20, 30], [30, 40], [10, 30], [20, 40], [30, 50]]) == 7\n assert candidate(intervals = [[1, 5], [5, 10], [10, 15], [15, 20], [20, 25], [25, 30], [30, 35]]) == 2\n assert candidate(intervals = [[1, 10], [1, 10], [1, 10], [10, 20], [10, 20], [10, 20]]) == 6\n assert candidate(intervals = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == 6\n assert candidate(intervals = [[1, 3], [2, 4], [3, 5], [4, 6], [5, 7]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9]]) == 5\n assert candidate(intervals = [[1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3]]) == 10\n assert candidate(intervals = [[1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [4, 9], [5, 10], [6, 11], [7, 12], [8, 13], [9, 14], [10, 15]]) == 6\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [200, 300]]) == 3\n assert candidate(intervals = [[5, 10], [15, 20], [25, 30], [35, 40], [10, 15], [20, 25], [30, 35]]) == 2\n assert candidate(intervals = [[1, 10], [10, 20], [20, 30], [30, 40], [40, 50], [1, 50]]) == 3\n assert candidate(intervals = [[1, 100], [50, 150], [100, 200], [150, 250], [200, 300]]) == 3\n assert candidate(intervals = [[1, 20], [5, 15], [10, 25], [15, 30], [20, 35]]) == 4\n assert candidate(intervals = [[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]]) == 1\n assert candidate(intervals = [[1, 3], [4, 7], [8, 10], [2, 5], [6, 9], [11, 13], [1, 4], [5, 8], [9, 12]]) == 3\n assert candidate(intervals = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13]]) == 2\n assert candidate(intervals = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 10], [2, 9]]) == 3\n", "comparison": "exact"}, "public_tests": ["[[5,10],[6,8],[1,5],[2,3],[1,10]]", "[[1,3],[5,6],[8,10],[11,13]]"], "hints": ["Can you find a different way to describe the question?", "The minimum number of groups we need is equivalent to the maximum number of intervals that overlap at some point. How can you find that?"], "metadata": {"canonical_parameter_names": ["intervals"], "leetcode_dataset_entry_point": "Solution().minGroups", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:36+00:00", "tests_total": 97, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "two-pointers", "greedy", "sorting", "heap-priority-queue", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minGroups($intervals) {", "container": "Solution", "callable": "minGroups", "parameters": [{"name": "intervals", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2407, "task_id": "longest-increasing-subsequence-ii", "difficulty": "Hard", "problem_description": "You are given an integer array nums and an integer k.\n\nFind the longest subsequence of nums that meets the following requirements:\n\n- The subsequence is strictly increasing and\n- The difference between adjacent elements in the subsequence is at most k.\n\nReturn the length of the longest subsequence that meets the requirements.\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 = [4,2,1,4,3,4,5,8,15], k = 3\nOutput: 5\nExplanation:\nThe longest subsequence that meets the requirements is [1,3,4,5,8].\nThe subsequence has a length of 5, so we return 5.\nNote that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3.\n\nExample 2:\n\nInput: nums = [7,4,5,1,8,12,4,7], k = 5\nOutput: 4\nExplanation:\nThe longest subsequence that meets the requirements is [4,5,8,12].\nThe subsequence has a length of 4, so we return 4.\n\nExample 3:\n\nInput: nums = [1,5], k = 1\nOutput: 1\nExplanation:\nThe longest subsequence that meets the requirements is [1].\nThe subsequence has a length of 1, so we return 1.\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i], k <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 10) == 3\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 1\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 5) == 3\n assert candidate(nums = [7, 4, 5, 1, 8, 12, 4, 7],k = 5) == 4\n assert candidate(nums = [5, 4, 3, 2, 1],k = 1) == 1\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 2) == 2\n assert candidate(nums = [10, 9, 2, 5, 3, 7, 101, 18],k = 4) == 3\n assert candidate(nums = [9, 7, 5, 3, 1],k = 2) == 1\n assert candidate(nums = [1, 3, 5, 7, 9],k = 2) == 5\n assert candidate(nums = [4, 2, 1, 4, 3, 4, 5, 8, 15],k = 3) == 5\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 5\n assert candidate(nums = [1, 5],k = 1) == 1\n assert candidate(nums = [5, 8, 7, 1, 9, 1, 5, 10, 4, 3, 2, 1],k = 2) == 4\n assert candidate(nums = [3, 1, 2, 4, 6, 5, 9, 7, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20],k = 3) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 4) == 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 = 19) == 20\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, 1, 10],k = 9) == 2\n assert candidate(nums = [3, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 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],k = 5) == 10\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 9) == 1\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 2) == 11\n assert candidate(nums = [100, 200, 300, 400, 500, 401, 402, 403, 501, 502, 503, 504],k = 10) == 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],k = 1) == 2\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 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],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 15) == 10\n assert candidate(nums = [5, 8, 7, 1, 9, 12, 10, 13, 14, 15],k = 4) == 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 = 2) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4],k = 4) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 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],k = 50) == 10\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9],k = 2) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 10) == 10\n assert candidate(nums = [1, 4, 3, 5, 6, 2, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, 17, 20, 19],k = 4) == 11\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 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],k = 1) == 20\n assert candidate(nums = [9, 1, 4, 7, 3, 2, 5, 8, 6],k = 3) == 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],k = 1) == 1\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 = 1) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 9) == 1\n assert candidate(nums = [20, 10, 30, 40, 50, 60, 70, 80, 90, 100, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 10\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 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],k = 3) == 30\n assert candidate(nums = [1, 6, 7, 8, 4, 5, 6, 7, 8, 9, 10, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 10\n assert candidate(nums = [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 7, 8],k = 2) == 8\n assert candidate(nums = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996],k = 99999) == 6\n assert candidate(nums = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],k = 1) == 3\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],k = 9) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],k = 2) == 15\n assert candidate(nums = [2, 3, 1, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 3) == 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) == 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],k = 5) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 14) == 15\n assert candidate(nums = [3, 1, 5, 2, 6, 4, 7],k = 3) == 4\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 9) == 16\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6],k = 3) == 6\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 10) == 1\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1],k = 4) == 2\n assert candidate(nums = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 10\n assert candidate(nums = [3, 1, 2, 5, 4, 8, 7, 6, 10, 9],k = 3) == 5\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 10) == 1\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 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],k = 19) == 20\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 100) == 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],k = 1) == 1\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],k = 10) == 1\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985],k = 5) == 1\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 92, 83, 74, 65, 56, 47, 38, 29],k = 9) == 12\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 2) == 10\n assert candidate(nums = [3, 1, 5, 4, 7, 6, 9, 8, 11, 10],k = 2) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 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 = 2) == 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 = 1) == 2\n assert candidate(nums = [3, 10, 2, 1, 20, 15, 25, 28, 30, 100],k = 10) == 6\n assert candidate(nums = [10, 20, 30, 40, 50, 1, 2, 3, 4, 5],k = 10) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10],k = 5) == 1\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1],k = 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],k = 2) == 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) == 20\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],k = 3) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 90) == 10\n assert candidate(nums = [5, 4, 3, 2, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 16\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93],k = 90) == 9\n assert candidate(nums = [5, 3, 4, 8, 9, 10, 20, 30, 15, 25, 35, 45, 55, 65, 75],k = 20) == 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 = 2) == 10\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6],k = 2) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10],k = 3) == 10\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58],k = 2) == 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],k = 2) == 20\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5],k = 3) == 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],k = 1) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 5) == 10\n assert candidate(nums = [4, 3, 5, 4, 7, 6, 8, 9, 10, 11, 12],k = 3) == 8\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 1) == 1\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 100) == 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],k = 5) == 1\n assert candidate(nums = [4, 3, 2, 1, 100, 101, 102, 103, 104],k = 3) == 5\n assert candidate(nums = [3, 10, 2, 1, 20, 1, 15, 5, 17, 6, 8, 9, 11, 13, 14],k = 4) == 8\n assert candidate(nums = [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, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5],k = 5) == 20\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11],k = 3) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 50) == 15\n", "comparison": "exact"}, "public_tests": ["[4,2,1,4,3,4,5,8,15]\n3", "[7,4,5,1,8,12,4,7]\n5", "[1,5]\n1"], "hints": ["We can use dynamic programming. Let dp[i][val] be the answer using only the first i + 1 elements, and the last element in the subsequence is equal to val.", "The only value that might change between dp[i - 1] and dp[i] are dp[i - 1][val] and dp[i][val].", "Try using dp[i - 1] and the fact that the second last element in the subsequence has to fall within a range to calculate dp[i][val].", "We can use a segment tree to find the maximum value in dp[i - 1] within a certain range."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().lengthOfLIS", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:38+00:00", "tests_total": 110, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "divide-and-conquer", "dynamic-programming", "binary-indexed-tree", "segment-tree", "queue", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function lengthOfLIS($nums, $k) {", "container": "Solution", "callable": "lengthOfLIS", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2409, "task_id": "count-days-spent-together", "difficulty": "Easy", "problem_description": "Alice and Bob are traveling to Rome for separate business meetings.\n\nYou are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format \"MM-DD\", corresponding to the month and day of the date.\n\nReturn the total number of days that Alice and Bob are in Rome together.\n\nYou can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].\n\nExample 1:\n\nInput: arriveAlice = \"08-15\", leaveAlice = \"08-18\", arriveBob = \"08-16\", leaveBob = \"08-19\"\nOutput: 3\nExplanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.\n\nExample 2:\n\nInput: arriveAlice = \"10-01\", leaveAlice = \"10-31\", arriveBob = \"11-01\", leaveBob = \"12-31\"\nOutput: 0\nExplanation: There is no day when Alice and Bob are in Rome together, so we return 0.\n\nConstraints:\n\n- All dates are provided in the format \"MM-DD\".\n- Alice and Bob's arrival dates are earlier than or equal to their leaving dates.\n- The given dates are valid dates of a non-leap year.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(arriveAlice = \"03-10\",leaveAlice = \"05-20\",arriveBob = \"04-01\",leaveBob = \"04-30\") == 30\n assert candidate(arriveAlice = \"06-15\",leaveAlice = \"06-20\",arriveBob = \"06-18\",leaveBob = \"06-25\") == 3\n assert candidate(arriveAlice = \"10-01\",leaveAlice = \"10-31\",arriveBob = \"11-01\",leaveBob = \"12-31\") == 0\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"12-31\",arriveBob = \"01-01\",leaveBob = \"12-31\") == 365\n assert candidate(arriveAlice = \"08-15\",leaveAlice = \"08-18\",arriveBob = \"08-16\",leaveBob = \"08-19\") == 3\n assert candidate(arriveAlice = \"12-20\",leaveAlice = \"12-31\",arriveBob = \"12-25\",leaveBob = \"12-30\") == 6\n assert candidate(arriveAlice = \"05-24\",leaveAlice = \"07-24\",arriveBob = \"07-25\",leaveBob = \"08-25\") == 0\n assert candidate(arriveAlice = \"07-20\",leaveAlice = \"08-15\",arriveBob = \"07-25\",leaveBob = \"08-10\") == 17\n assert candidate(arriveAlice = \"07-01\",leaveAlice = \"08-01\",arriveBob = \"07-15\",leaveBob = \"07-30\") == 16\n assert candidate(arriveAlice = \"07-10\",leaveAlice = \"07-20\",arriveBob = \"07-15\",leaveBob = \"07-25\") == 6\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"01-31\",arriveBob = \"01-01\",leaveBob = \"01-31\") == 31\n assert candidate(arriveAlice = \"03-10\",leaveAlice = \"03-10\",arriveBob = \"03-10\",leaveBob = \"03-10\") == 1\n assert candidate(arriveAlice = \"06-15\",leaveAlice = \"06-15\",arriveBob = \"06-15\",leaveBob = \"06-15\") == 1\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"01-31\",arriveBob = \"01-15\",leaveBob = \"01-20\") == 6\n assert candidate(arriveAlice = \"03-14\",leaveAlice = \"03-14\",arriveBob = \"03-14\",leaveBob = \"03-14\") == 1\n assert candidate(arriveAlice = \"06-01\",leaveAlice = \"06-30\",arriveBob = \"05-25\",leaveBob = \"06-10\") == 10\n assert candidate(arriveAlice = \"10-01\",leaveAlice = \"10-20\",arriveBob = \"09-25\",leaveBob = \"10-25\") == 20\n assert candidate(arriveAlice = \"11-15\",leaveAlice = \"12-31\",arriveBob = \"12-01\",leaveBob = \"12-31\") == 31\n assert candidate(arriveAlice = \"04-10\",leaveAlice = \"06-10\",arriveBob = \"05-01\",leaveBob = \"06-30\") == 41\n assert candidate(arriveAlice = \"01-10\",leaveAlice = \"02-20\",arriveBob = \"02-15\",leaveBob = \"03-25\") == 6\n assert candidate(arriveAlice = \"09-15\",leaveAlice = \"09-15\",arriveBob = \"09-15\",leaveBob = \"09-15\") == 1\n assert candidate(arriveAlice = \"12-20\",leaveAlice = \"12-31\",arriveBob = \"12-15\",leaveBob = \"01-10\") == 0\n assert candidate(arriveAlice = \"05-05\",leaveAlice = \"07-05\",arriveBob = \"05-05\",leaveBob = \"05-05\") == 1\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-15\",arriveBob = \"03-01\",leaveBob = \"03-31\") == 15\n assert candidate(arriveAlice = \"08-15\",leaveAlice = \"09-15\",arriveBob = \"09-15\",leaveBob = \"10-15\") == 1\n assert candidate(arriveAlice = \"03-05\",leaveAlice = \"03-20\",arriveBob = \"03-15\",leaveBob = \"03-25\") == 6\n assert candidate(arriveAlice = \"03-15\",leaveAlice = \"03-20\",arriveBob = \"03-10\",leaveBob = \"03-14\") == 0\n assert candidate(arriveAlice = \"06-01\",leaveAlice = \"06-30\",arriveBob = \"06-15\",leaveBob = \"06-25\") == 11\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-10\",arriveBob = \"03-01\",leaveBob = \"03-15\") == 10\n assert candidate(arriveAlice = \"01-15\",leaveAlice = \"01-15\",arriveBob = \"01-15\",leaveBob = \"01-15\") == 1\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"01-31\",arriveBob = \"01-15\",leaveBob = \"02-14\") == 17\n assert candidate(arriveAlice = \"12-15\",leaveAlice = \"12-15\",arriveBob = \"12-16\",leaveBob = \"12-16\") == 0\n assert candidate(arriveAlice = \"11-11\",leaveAlice = \"11-11\",arriveBob = \"11-11\",leaveBob = \"11-11\") == 1\n assert candidate(arriveAlice = \"11-20\",leaveAlice = \"12-15\",arriveBob = \"11-25\",leaveBob = \"12-25\") == 21\n assert candidate(arriveAlice = \"11-11\",leaveAlice = \"11-25\",arriveBob = \"11-20\",leaveBob = \"12-10\") == 6\n assert candidate(arriveAlice = \"04-30\",leaveAlice = \"05-30\",arriveBob = \"04-15\",leaveBob = \"05-15\") == 16\n assert candidate(arriveAlice = \"07-20\",leaveAlice = \"08-10\",arriveBob = \"07-25\",leaveBob = \"08-05\") == 12\n assert candidate(arriveAlice = \"08-05\",leaveAlice = \"10-10\",arriveBob = \"09-01\",leaveBob = \"10-05\") == 35\n assert candidate(arriveAlice = \"08-15\",leaveAlice = \"09-20\",arriveBob = \"09-05\",leaveBob = \"10-05\") == 16\n assert candidate(arriveAlice = \"01-15\",leaveAlice = \"03-20\",arriveBob = \"02-10\",leaveBob = \"04-15\") == 39\n assert candidate(arriveAlice = \"10-20\",leaveAlice = \"11-10\",arriveBob = \"11-05\",leaveBob = \"12-15\") == 6\n assert candidate(arriveAlice = \"06-30\",leaveAlice = \"07-01\",arriveBob = \"06-29\",leaveBob = \"07-02\") == 2\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-01\",arriveBob = \"03-01\",leaveBob = \"03-02\") == 1\n assert candidate(arriveAlice = \"04-01\",leaveAlice = \"04-30\",arriveBob = \"03-20\",leaveBob = \"04-25\") == 25\n assert candidate(arriveAlice = \"09-10\",leaveAlice = \"10-10\",arriveBob = \"09-15\",leaveBob = \"09-20\") == 6\n assert candidate(arriveAlice = \"05-10\",leaveAlice = \"05-10\",arriveBob = \"05-10\",leaveBob = \"05-10\") == 1\n assert candidate(arriveAlice = \"07-20\",leaveAlice = \"07-25\",arriveBob = \"07-20\",leaveBob = \"07-25\") == 6\n assert candidate(arriveAlice = \"08-01\",leaveAlice = \"08-31\",arriveBob = \"07-20\",leaveBob = \"08-10\") == 10\n assert candidate(arriveAlice = \"06-15\",leaveAlice = \"06-20\",arriveBob = \"06-21\",leaveBob = \"06-25\") == 0\n assert candidate(arriveAlice = \"12-15\",leaveAlice = \"12-20\",arriveBob = \"12-15\",leaveBob = \"12-20\") == 6\n assert candidate(arriveAlice = \"11-01\",leaveAlice = \"11-30\",arriveBob = \"10-25\",leaveBob = \"11-25\") == 25\n assert candidate(arriveAlice = \"07-31\",leaveAlice = \"07-31\",arriveBob = \"08-01\",leaveBob = \"08-01\") == 0\n assert candidate(arriveAlice = \"08-01\",leaveAlice = \"08-31\",arriveBob = \"07-25\",leaveBob = \"08-15\") == 15\n assert candidate(arriveAlice = \"02-14\",leaveAlice = \"03-14\",arriveBob = \"03-01\",leaveBob = \"04-01\") == 14\n assert candidate(arriveAlice = \"08-10\",leaveAlice = \"09-10\",arriveBob = \"09-05\",leaveBob = \"09-20\") == 6\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"01-31\",arriveBob = \"02-01\",leaveBob = \"02-28\") == 0\n assert candidate(arriveAlice = \"03-15\",leaveAlice = \"03-31\",arriveBob = \"04-01\",leaveBob = \"04-10\") == 0\n assert candidate(arriveAlice = \"01-01\",leaveAlice = \"12-31\",arriveBob = \"06-15\",leaveBob = \"06-15\") == 1\n assert candidate(arriveAlice = \"11-15\",leaveAlice = \"11-30\",arriveBob = \"12-01\",leaveBob = \"12-31\") == 0\n assert candidate(arriveAlice = \"09-01\",leaveAlice = \"11-15\",arriveBob = \"10-01\",leaveBob = \"10-31\") == 31\n assert candidate(arriveAlice = \"04-15\",leaveAlice = \"06-20\",arriveBob = \"05-01\",leaveBob = \"07-15\") == 51\n assert candidate(arriveAlice = \"08-20\",leaveAlice = \"09-20\",arriveBob = \"09-10\",leaveBob = \"10-10\") == 11\n assert candidate(arriveAlice = \"07-10\",leaveAlice = \"08-10\",arriveBob = \"07-20\",leaveBob = \"08-20\") == 22\n assert candidate(arriveAlice = \"05-10\",leaveAlice = \"06-10\",arriveBob = \"05-20\",leaveBob = \"06-20\") == 22\n assert candidate(arriveAlice = \"06-01\",leaveAlice = \"06-10\",arriveBob = \"06-05\",leaveBob = \"06-05\") == 1\n assert candidate(arriveAlice = \"11-10\",leaveAlice = \"11-10\",arriveBob = \"11-11\",leaveBob = \"11-11\") == 0\n assert candidate(arriveAlice = \"09-01\",leaveAlice = \"10-31\",arriveBob = \"08-01\",leaveBob = \"09-15\") == 15\n assert candidate(arriveAlice = \"12-15\",leaveAlice = \"12-31\",arriveBob = \"12-10\",leaveBob = \"12-15\") == 1\n assert candidate(arriveAlice = \"07-01\",leaveAlice = \"07-31\",arriveBob = \"06-25\",leaveBob = \"07-25\") == 25\n assert candidate(arriveAlice = \"03-10\",leaveAlice = \"04-10\",arriveBob = \"04-05\",leaveBob = \"05-10\") == 6\n assert candidate(arriveAlice = \"03-31\",leaveAlice = \"03-31\",arriveBob = \"04-01\",leaveBob = \"04-01\") == 0\n assert candidate(arriveAlice = \"09-10\",leaveAlice = \"10-10\",arriveBob = \"09-15\",leaveBob = \"10-15\") == 26\n assert candidate(arriveAlice = \"05-25\",leaveAlice = \"06-05\",arriveBob = \"05-26\",leaveBob = \"06-04\") == 10\n assert candidate(arriveAlice = \"10-15\",leaveAlice = \"10-20\",arriveBob = \"09-25\",leaveBob = \"10-16\") == 2\n assert candidate(arriveAlice = \"09-01\",leaveAlice = \"10-31\",arriveBob = \"08-15\",leaveBob = \"09-15\") == 15\n assert candidate(arriveAlice = \"03-01\",leaveAlice = \"03-31\",arriveBob = \"02-28\",leaveBob = \"03-10\") == 10\n assert candidate(arriveAlice = \"06-01\",leaveAlice = \"08-31\",arriveBob = \"07-01\",leaveBob = \"07-31\") == 31\n assert candidate(arriveAlice = \"07-25\",leaveAlice = \"08-25\",arriveBob = \"07-26\",leaveBob = \"07-27\") == 2\n assert candidate(arriveAlice = \"06-01\",leaveAlice = \"08-31\",arriveBob = \"07-01\",leaveBob = \"09-30\") == 62\n assert candidate(arriveAlice = \"02-15\",leaveAlice = \"03-15\",arriveBob = \"03-10\",leaveBob = \"04-10\") == 6\n assert candidate(arriveAlice = \"04-30\",leaveAlice = \"05-01\",arriveBob = \"04-29\",leaveBob = \"05-02\") == 2\n assert candidate(arriveAlice = \"09-01\",leaveAlice = \"09-15\",arriveBob = \"08-20\",leaveBob = \"09-10\") == 10\n assert candidate(arriveAlice = \"03-15\",leaveAlice = \"03-15\",arriveBob = \"03-15\",leaveBob = \"03-15\") == 1\n assert candidate(arriveAlice = \"05-05\",leaveAlice = \"05-05\",arriveBob = \"05-04\",leaveBob = \"05-06\") == 1\n assert candidate(arriveAlice = \"08-25\",leaveAlice = \"09-05\",arriveBob = \"09-01\",leaveBob = \"09-10\") == 5\n assert candidate(arriveAlice = \"07-05\",leaveAlice = \"08-10\",arriveBob = \"08-05\",leaveBob = \"09-15\") == 6\n assert candidate(arriveAlice = \"09-10\",leaveAlice = \"11-20\",arriveBob = \"10-01\",leaveBob = \"10-31\") == 31\n assert candidate(arriveAlice = \"09-15\",leaveAlice = \"10-15\",arriveBob = \"10-01\",leaveBob = \"11-01\") == 15\n assert candidate(arriveAlice = \"12-15\",leaveAlice = \"12-31\",arriveBob = \"12-20\",leaveBob = \"01-15\") == 0\n assert candidate(arriveAlice = \"05-05\",leaveAlice = \"07-10\",arriveBob = \"06-01\",leaveBob = \"06-30\") == 30\n assert candidate(arriveAlice = \"03-15\",leaveAlice = \"05-15\",arriveBob = \"04-01\",leaveBob = \"04-30\") == 30\n assert candidate(arriveAlice = \"11-10\",leaveAlice = \"11-20\",arriveBob = \"11-21\",leaveBob = \"11-30\") == 0\n assert candidate(arriveAlice = \"02-20\",leaveAlice = \"03-10\",arriveBob = \"03-05\",leaveBob = \"04-01\") == 6\n assert candidate(arriveAlice = \"01-05\",leaveAlice = \"01-10\",arriveBob = \"01-08\",leaveBob = \"01-15\") == 3\n assert candidate(arriveAlice = \"01-29\",leaveAlice = \"02-02\",arriveBob = \"02-01\",leaveBob = \"02-28\") == 2\n assert candidate(arriveAlice = \"10-10\",leaveAlice = \"10-20\",arriveBob = \"09-30\",leaveBob = \"10-10\") == 1\n assert candidate(arriveAlice = \"04-01\",leaveAlice = \"04-30\",arriveBob = \"04-10\",leaveBob = \"04-20\") == 11\n assert candidate(arriveAlice = \"05-15\",leaveAlice = \"06-15\",arriveBob = \"06-10\",leaveBob = \"07-10\") == 6\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-01\",arriveBob = \"02-28\",leaveBob = \"03-01\") == 2\n assert candidate(arriveAlice = \"01-10\",leaveAlice = \"02-10\",arriveBob = \"02-01\",leaveBob = \"03-10\") == 10\n assert candidate(arriveAlice = \"11-01\",leaveAlice = \"11-30\",arriveBob = \"11-15\",leaveBob = \"12-15\") == 16\n assert candidate(arriveAlice = \"05-01\",leaveAlice = \"05-31\",arriveBob = \"04-30\",leaveBob = \"05-10\") == 10\n assert candidate(arriveAlice = \"12-10\",leaveAlice = \"12-31\",arriveBob = \"12-20\",leaveBob = \"01-10\") == 0\n assert candidate(arriveAlice = \"07-20\",leaveAlice = \"08-20\",arriveBob = \"08-01\",leaveBob = \"08-19\") == 19\n assert candidate(arriveAlice = \"01-10\",leaveAlice = \"02-10\",arriveBob = \"01-15\",leaveBob = \"03-15\") == 27\n assert candidate(arriveAlice = \"05-10\",leaveAlice = \"05-15\",arriveBob = \"05-12\",leaveBob = \"05-20\") == 4\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-05\",arriveBob = \"03-01\",leaveBob = \"03-10\") == 5\n assert candidate(arriveAlice = \"02-28\",leaveAlice = \"03-01\",arriveBob = \"02-29\",leaveBob = \"03-02\") == 1\n assert candidate(arriveAlice = \"11-25\",leaveAlice = \"12-10\",arriveBob = \"12-01\",leaveBob = \"12-15\") == 10\n assert candidate(arriveAlice = \"04-10\",leaveAlice = \"04-30\",arriveBob = \"04-15\",leaveBob = \"05-15\") == 16\n assert candidate(arriveAlice = \"07-10\",leaveAlice = \"07-20\",arriveBob = \"07-20\",leaveBob = \"07-30\") == 1\n assert candidate(arriveAlice = \"11-11\",leaveAlice = \"11-30\",arriveBob = \"11-15\",leaveBob = \"11-25\") == 11\n assert candidate(arriveAlice = \"03-20\",leaveAlice = \"03-31\",arriveBob = \"04-01\",leaveBob = \"04-10\") == 0\n assert candidate(arriveAlice = \"09-15\",leaveAlice = \"10-15\",arriveBob = \"10-10\",leaveBob = \"11-10\") == 6\n assert candidate(arriveAlice = \"11-01\",leaveAlice = \"11-15\",arriveBob = \"10-25\",leaveBob = \"11-10\") == 10\n assert candidate(arriveAlice = \"07-20\",leaveAlice = \"08-20\",arriveBob = \"07-15\",leaveBob = \"07-25\") == 6\n", "comparison": "exact"}, "public_tests": ["\"08-15\"\n\"08-18\"\n\"08-16\"\n\"08-19\"", "\"10-01\"\n\"10-31\"\n\"11-01\"\n\"12-31\""], "hints": ["For a given day, determine if Alice or Bob or both are in Rome.", "Brute force all 365 days for both Alice and Bob."], "metadata": {"canonical_parameter_names": ["arriveAlice", "leaveAlice", "arriveBob", "leaveBob"], "leetcode_dataset_entry_point": "Solution().countDaysTogether", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:40+00:00", "tests_total": 116, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "string"]}, "language": "php", "interface": {"raw_signature": "function countDaysTogether($arriveAlice, $leaveAlice, $arriveBob, $leaveBob) {", "container": "Solution", "callable": "countDaysTogether", "parameters": [{"name": "arriveAlice", "type": "String"}, {"name": "leaveAlice", "type": "String"}, {"name": "arriveBob", "type": "String"}, {"name": "leaveBob", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2410, "task_id": "maximum-matching-of-players-with-trainers", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array players, where players[i] represents the ability of the i^th player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the j^th trainer.\n\nThe i^th player can match with the j^th trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the i^th player can be matched with at most one trainer, and the j^th trainer can be matched with at most one player.\n\nReturn the maximum number of matchings between players and trainers that satisfy these conditions.\n\nExample 1:\n\nInput: players = [4,7,9], trainers = [8,2,5,8]\nOutput: 2\nExplanation:\nOne of the ways we can form two matchings is as follows:\n- players[0] can be matched with trainers[0] since 4 <= 8.\n- players[1] can be matched with trainers[3] since 7 <= 8.\nIt can be proven that 2 is the maximum number of matchings that can be formed.\n\nExample 2:\n\nInput: players = [1,1,1], trainers = [10]\nOutput: 1\nExplanation:\nThe trainer can be matched with any of the 3 players.\nEach player can only be matched with one trainer, so the maximum answer is 1.\n\nConstraints:\n\n- 1 <= players.length, trainers.length <= 10^5\n- 1 <= players[i], trainers[j] <= 10^9\n\nNote: This question is the same as 445: Assign Cookies.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(players = [1, 2, 3],trainers = [10, 11, 12]) == 3\n assert candidate(players = [10, 20, 30],trainers = [1, 2, 3]) == 0\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [5, 4, 3, 2, 1]) == 5\n assert candidate(players = [1000000000],trainers = [1000000000]) == 1\n assert candidate(players = [1, 2, 3],trainers = [4, 5, 6, 7, 8]) == 3\n assert candidate(players = [1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1]) == 5\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10]) == 1\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(players = [1],trainers = [1]) == 1\n assert candidate(players = [1, 10, 100],trainers = [10, 100, 1000]) == 3\n assert candidate(players = [5, 6, 7],trainers = [8, 9, 10]) == 3\n assert candidate(players = [1, 3, 5, 7, 9],trainers = [2, 4, 6, 8, 10]) == 5\n assert candidate(players = [5, 5, 5],trainers = [5, 5, 5]) == 3\n assert candidate(players = [9, 7, 5, 3, 1],trainers = [10, 8, 6, 4, 2]) == 5\n assert candidate(players = [1, 2, 3],trainers = [10, 20, 30]) == 3\n assert candidate(players = [10, 20, 30, 40],trainers = [5, 15, 25, 35, 45]) == 4\n assert candidate(players = [10, 20, 30],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(players = [1, 1000000000],trainers = [1000000000, 1]) == 2\n assert candidate(players = [5, 5, 5, 5],trainers = [5, 5, 5, 5]) == 4\n assert candidate(players = [1, 3, 5, 7],trainers = [2, 4, 6, 8]) == 4\n assert candidate(players = [1, 1, 1],trainers = [10]) == 1\n assert candidate(players = [4, 7, 9],trainers = [8, 2, 5, 8]) == 2\n assert candidate(players = [100, 200, 300],trainers = [150, 250, 350]) == 3\n assert candidate(players = [3, 7, 11, 15, 19],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(players = [4, 7, 9, 11, 13, 15],trainers = [10, 8, 12, 6, 14, 16]) == 6\n assert candidate(players = [100, 200, 300, 400, 500],trainers = [50, 150, 250, 350, 450, 550]) == 5\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(players = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [5, 5, 5, 5, 5]) == 5\n assert candidate(players = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 20\n assert candidate(players = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],trainers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(players = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],trainers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],trainers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 10\n assert candidate(players = [3, 3, 3, 4, 4, 4, 5, 5, 5],trainers = [3, 4, 5]) == 3\n assert candidate(players = [1, 5, 8, 9, 11, 13, 15, 17, 19],trainers = [2, 3, 6, 7, 10, 12, 14, 16, 18, 20]) == 8\n assert candidate(players = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],trainers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 4\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(players = [50, 40, 30, 20, 10],trainers = [15, 25, 35, 45, 55]) == 5\n assert candidate(players = [1, 1, 1, 1, 1],trainers = [1, 2, 3, 4, 5]) == 5\n assert candidate(players = [1, 3, 6, 7, 8],trainers = [2, 4, 5, 8, 9]) == 4\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 20\n assert candidate(players = [1, 100, 1000, 10000, 100000],trainers = [1, 100, 1000, 10000, 100000]) == 5\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 10\n assert candidate(players = [5, 10, 15, 20, 25, 30],trainers = [25, 10, 5, 30, 20, 15]) == 6\n assert candidate(players = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],trainers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4],trainers = [1, 2, 2, 3, 3, 4, 4, 5]) == 8\n assert candidate(players = [10, 20, 30, 40, 50],trainers = [15, 25, 35, 45, 55]) == 5\n assert candidate(players = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],trainers = [500, 600, 700, 800, 900, 1000, 100, 200, 300, 400]) == 10\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],trainers = [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\n assert candidate(players = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],trainers = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]) == 10\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],trainers = [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]) == 25\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trainers = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 5\n assert candidate(players = [1, 5, 9, 13, 17],trainers = [3, 7, 11, 15, 19]) == 5\n assert candidate(players = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],trainers = [5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]) == 15\n assert candidate(players = [3, 6, 7, 8, 10, 11, 15],trainers = [4, 5, 8, 9, 12, 16, 20]) == 6\n assert candidate(players = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],trainers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == 10\n assert candidate(players = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],trainers = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 20\n assert candidate(players = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1]) == 5\n assert candidate(players = [5, 10, 15, 20, 25, 30],trainers = [3, 6, 9, 12, 18, 21, 24, 27]) == 5\n assert candidate(players = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500],trainers = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 10\n assert candidate(players = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],trainers = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 15\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(players = [10, 20, 30, 40, 50],trainers = [1, 2, 3, 4, 5]) == 0\n assert candidate(players = [1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],trainers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 20\n assert candidate(players = [1, 10, 100, 1000, 10000, 100000],trainers = [100000, 10000, 1000, 100, 10, 1]) == 6\n assert candidate(players = [100, 200, 300, 400, 500],trainers = [250, 350, 150, 450, 550]) == 5\n assert candidate(players = [10, 10, 10, 10, 10],trainers = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(players = [100, 200, 300, 400, 500],trainers = [150, 250, 350, 450, 550]) == 5\n assert candidate(players = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],trainers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 9\n assert candidate(players = [1000000000, 1000000000, 1000000000],trainers = [1000000000, 1000000000]) == 2\n assert candidate(players = [1, 100, 200, 300, 400, 500],trainers = [500, 400, 300, 200, 100, 1]) == 6\n assert candidate(players = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],trainers = [99, 199, 299, 399, 499, 599, 699, 799, 899, 999, 1099, 1199, 1299, 1399, 1499]) == 14\n assert candidate(players = [1000000000, 999999999, 999999998, 999999997, 999999996],trainers = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 5\n assert candidate(players = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],trainers = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10]) == 10\n assert candidate(players = [10, 20, 30, 40, 50],trainers = [5, 15, 25, 35, 45, 55]) == 5\n assert candidate(players = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],trainers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],trainers = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155]) == 15\n assert candidate(players = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],trainers = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950]) == 9\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10\n assert candidate(players = [1, 1, 1, 1, 1],trainers = [1]) == 1\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 20\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(players = [5, 5, 5, 5, 5],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 5\n assert candidate(players = [5, 5, 5, 5, 5],trainers = [5, 5, 5, 5, 5]) == 5\n assert candidate(players = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],trainers = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]) == 10\n assert candidate(players = [2, 5, 8, 12, 15],trainers = [3, 5, 7, 9, 11, 15]) == 4\n assert candidate(players = [1, 2, 3, 4, 5],trainers = [1, 1, 1, 1, 1]) == 1\n assert candidate(players = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],trainers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 9\n assert candidate(players = [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],trainers = [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]) == 25\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trainers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(players = [10, 20, 30, 40, 50],trainers = [15, 25, 35, 45, 55]) == 5\n assert candidate(players = [3, 6, 9, 12, 15, 18, 21],trainers = [10, 12, 14, 16, 18, 20, 22]) == 7\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(players = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],trainers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trainers = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 10\n assert candidate(players = [5, 5, 5, 5, 5],trainers = [1, 2, 3, 4, 5]) == 1\n assert candidate(players = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],trainers = [150, 250, 350, 450, 550, 650, 750, 850, 950, 1050]) == 10\n assert candidate(players = [5, 10, 15, 20, 25],trainers = [1, 5, 10, 15, 20, 25, 30]) == 5\n assert candidate(players = [100, 100, 100, 100, 100],trainers = [100, 100, 100, 100, 100, 100]) == 5\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],trainers = [3, 6, 9, 12, 15]) == 5\n assert candidate(players = [5, 5, 5, 5, 5],trainers = [1, 2, 3, 4, 5]) == 1\n assert candidate(players = [100, 200, 300],trainers = [150, 100, 250, 300]) == 3\n assert candidate(players = [50, 40, 30, 20, 10],trainers = [10, 20, 30, 40, 50]) == 5\n assert candidate(players = [10, 20, 30, 40, 50],trainers = [9, 19, 29, 39, 49]) == 4\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],trainers = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 15\n assert candidate(players = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],trainers = [1, 1, 1, 1, 1, 1, 1, 1, 1, 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(players = [90, 80, 70, 60, 50, 40, 30, 20, 10],trainers = [85, 95, 90, 75, 65, 55, 45, 35, 25, 15]) == 9\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 10\n assert candidate(players = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],trainers = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 10\n assert candidate(players = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],trainers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 10\n assert candidate(players = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],trainers = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 10\n", "comparison": "exact"}, "public_tests": ["[4,7,9]\n[8,2,5,8]", "[1,1,1]\n[10]"], "hints": ["Sort both the arrays.", "Construct the matching greedily."], "metadata": {"canonical_parameter_names": ["players", "trainers"], "leetcode_dataset_entry_point": "Solution().matchPlayersAndTrainers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:43+00:00", "tests_total": 120, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "two-pointers", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function matchPlayersAndTrainers($players, $trainers) {", "container": "Solution", "callable": "matchPlayersAndTrainers", "parameters": [{"name": "players", "type": "Integer[]"}, {"name": "trainers", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2411, "task_id": "smallest-subarrays-with-maximum-bitwise-or", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR.\n\n- In other words, let B_ij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(B_ik) where i <= k <= n - 1.\n\nThe bitwise OR of an array is the bitwise OR of all the numbers in it.\n\nReturn an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,0,2,1,3]\nOutput: [3,3,2,2,1]\nExplanation:\nThe maximum possible bitwise OR starting at any index is 3.\n- Starting at index 0, the shortest subarray that yields it is [1,0,2].\n- Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].\n- Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].\n- Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].\n- Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].\nTherefore, we return [3,3,2,2,1].\n\nExample 2:\n\nInput: nums = [1,2]\nOutput: [2,1]\nExplanation:\nStarting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.\nStarting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.\nTherefore, we return [2,1].\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- 0 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1]) == [10, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1]\n assert candidate(nums = [8, 16, 32, 64, 128]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [1, 0, 1, 0, 1]) == [1, 2, 1, 2, 1]\n assert candidate(nums = [3, 1, 5, 7, 9]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [8, 4, 2, 1]) == [4, 3, 2, 1]\n assert candidate(nums = [1, 3, 5, 7, 9]) == [5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [8, 7, 6, 5, 4, 3, 2, 3, 2, 1]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 2, 1, 2, 1]\n assert candidate(nums = [1, 0, 2, 1, 3]) == [3, 3, 2, 2, 1]\n assert candidate(nums = [8, 4, 2, 1, 0]) == [4, 3, 2, 1, 1]\n assert candidate(nums = [5, 5, 5, 5, 5]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [0, 0, 0, 0, 0]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 3, 2, 1, 4, 7, 8, 5, 6, 9]) == [7, 6, 5, 4, 3, 2, 3, 3, 2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [0, 0, 0, 0]) == [1, 1, 1, 1]\n assert candidate(nums = [1023, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 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, 1023]) == [10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [31, 15, 7, 3, 1]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2]) == [2, 1]\n assert candidate(nums = [3, 3, 3, 3, 3]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125]) == [10, 9, 8, 7, 6, 5, 4, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 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 = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == [1, 1, 1, 1, 1]\n assert candidate(nums = [8, 4, 2, 1, 16, 8, 4, 2, 1, 32, 16, 8, 4, 2, 1, 64, 32, 16, 8, 4, 2, 1]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 7, 7, 7, 7, 7, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [33554431, 16777215, 8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 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]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\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]) == [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 = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 1005, 1004]) == [1, 2, 3, 2, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 1, 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]) == [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, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1]) == [1, 1, 1, 4, 3, 2, 1, 1, 1, 4, 3, 2, 1, 1, 1, 4, 3, 2, 1, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [31, 15, 7, 3, 1, 0, 1, 3, 7, 15, 31, 63, 127, 255, 511]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [128, 64, 32, 16, 8, 4, 2, 1, 255, 127, 63, 31, 15, 7, 3, 1, 511, 255, 127, 63]) == [17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 5, 4, 3, 2, 3, 2, 1]\n assert candidate(nums = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014]) == [1, 2, 3, 2, 5, 4, 3, 2, 1, 1]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [7, 6, 5, 4, 3, 2, 4, 3, 2, 1]\n assert candidate(nums = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]) == [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]) == [8, 7, 6, 5, 4, 3, 2, 5, 4, 3, 2, 3, 2, 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, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 5, 4, 3, 2, 3, 2, 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]\n assert candidate(nums = [8, 6, 2, 3, 7, 5, 1, 4, 9, 10]) == [4, 8, 7, 6, 5, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1]\n assert candidate(nums = [8388607, 4194303, 2097151, 1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 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]\n assert candidate(nums = [1023, 0, 2047, 0, 4095, 0, 8191, 0, 16383, 0]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 1]\n assert candidate(nums = [8, 15, 3, 12, 7, 9, 1, 5, 11, 6, 4, 10, 2, 14, 0, 13]) == [2, 1, 2, 2, 2, 4, 3, 2, 2, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [2, 3, 1, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]) == [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, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111, 0]) == [4, 5, 4, 4, 4, 3, 3, 2, 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, 31]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 5, 4, 3, 2, 3, 2, 2, 1]\n assert candidate(nums = [31, 15, 7, 3, 1, 1, 3, 7, 15, 31, 1, 1, 3, 7, 15, 31, 1, 1, 3, 7, 15, 31, 1, 1, 3, 7, 15, 31]) == [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 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, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == [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 = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [16, 8, 4, 2, 1, 32, 64, 128, 256, 512]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 0]) == [1, 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, 0]) == [2, 3, 2, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 2, 5, 4, 3, 2, 1, 2, 3, 2, 1, 2, 1, 1]\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [1, 1, 1, 1, 1, 1, 1, 1, 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]) == [17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 3, 2, 2, 1]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035]) == [10, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 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]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 5, 4, 3, 2, 1]\n assert candidate(nums = [3, 1, 2, 7, 4, 6, 5, 0, 8, 9]) == [9, 8, 7, 6, 5, 4, 3, 3, 2, 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]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [31, 15, 7, 3, 1, 1, 3, 7, 15, 31]) == [1, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [9, 3, 1, 7, 5, 11, 13, 15, 8, 12, 14, 6, 10, 2, 4, 0]) == [4, 5, 4, 3, 2, 2, 2, 1, 3, 2, 1, 2, 3, 2, 1, 1]\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == [8, 7, 6, 5, 4, 3, 2, 3, 2, 1]\n assert candidate(nums = [15, 7, 3, 1, 14, 6, 2, 0, 13, 5, 1, 0, 9, 3, 1, 0, 8, 2, 0, 7]) == [1, 4, 3, 2, 5, 4, 3, 7, 6, 5, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1]\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 1]\n assert candidate(nums = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 0, 0, 0, 0]) == [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, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [3, 2, 9, 8, 7, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 2, 1, 2, 1, 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]) == [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]) == [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 3, 2, 1]\n assert candidate(nums = [268435455, 134217727, 67108863, 33554431, 16777215, 8388607, 4194303, 2097151, 1048575, 524287]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [5, 3, 1, 7, 9, 11, 13, 15, 17, 19]) == [9, 8, 7, 6, 5, 4, 3, 2, 2, 1]\n assert candidate(nums = [255, 127, 63, 31, 15, 7, 3, 1, 128, 64, 32, 16, 8, 4, 2, 1, 256, 512, 1024, 2048, 4096]) == [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 = [31, 14, 7, 3, 1, 0, 1, 3, 7, 14, 31, 0, 1, 3, 7, 14, 31, 0, 1, 3, 7, 14, 31]) == [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0]) == [1, 1, 1, 4, 3, 2, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 0, 2, 1, 3, 1, 0, 2, 1, 3, 1, 0, 2, 1, 3, 1, 0, 2, 1, 3]) == [3, 3, 2, 2, 1, 3, 3, 2, 2, 1, 3, 3, 2, 2, 1, 3, 3, 2, 2, 1]\n assert candidate(nums = [5, 8, 14, 23, 42, 67, 98, 132, 175, 220, 270, 325, 385, 450, 520]) == [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1048575, 524287, 262143, 131071, 65535, 32767, 16383, 8191, 4095, 2047]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(nums = [255, 128, 64, 32, 16, 8, 4, 2, 1, 255, 128, 64, 32, 16, 8, 4, 2, 1, 255, 128, 64, 32, 16, 8, 4, 2, 1]) == [1, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000, 7812500, 3906250, 1953125, 976562, 488281, 244140, 122070, 61035, 30517, 15258, 7629, 3814, 1907, 953, 476, 238, 119, 59, 29, 14, 7, 3, 1, 0]) == [10, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1]\n assert candidate(nums = [1, 0, 3, 2, 1, 2, 3, 0, 1, 2]) == [3, 2, 1, 2, 2, 2, 1, 3, 2, 1]\n assert candidate(nums = [524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 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 = [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]\n assert candidate(nums = [31, 15, 7, 3, 1, 63, 31, 15, 7, 3, 1, 127, 63, 31, 15, 7, 3, 1, 255, 127, 63, 31, 15, 7, 3, 1]) == [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 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]\n assert candidate(nums = [987654321, 987654320, 987654319, 987654318, 987654317, 987654316, 987654315, 987654314, 987654313, 987654312]) == [3, 2, 1, 2, 3, 2, 1, 2, 1, 1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 0, 3, 2, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]) == [3, 2, 1, 2, 2, 2, 1, 3, 2, 2, 1, 3, 2, 2, 1, 3, 2, 2, 1, 1]\n assert candidate(nums = [1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016, 1015, 1014, 1013, 1012, 1011, 1010, 1009, 1008, 1007, 1006, 1005, 1004]) == [1, 2, 3, 2, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 1, 1]\n assert candidate(nums = [31, 15, 7, 3, 1, 0, 1, 3, 5, 7, 9]) == [1, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n", "comparison": "exact"}, "public_tests": ["[1,0,2,1,3]", "[1,2]"], "hints": ["Consider trying to solve the problem for each bit position separately.", "For each bit position, find the position of the next number that has a 1 in that position, if any.", "Take the maximum distance to such a number, including the current number.", "Iterate backwards to achieve a linear complexity."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().smallestSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:45+00:00", "tests_total": 102, "tests_dropped": 7, "flags": [], "topic_tags": ["array", "binary-search", "bit-manipulation", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function smallestSubarrays($nums) {", "container": "Solution", "callable": "smallestSubarrays", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2412, "task_id": "minimum-money-required-before-transactions", "difficulty": "Hard", "problem_description": "You are given a 0-indexed 2D integer array transactions, where transactions[i] = [cost_i, cashback_i].\n\nThe array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= cost_i must hold true. After performing a transaction, money becomes money - cost_i + cashback_i.\n\nReturn the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.\n\nExample 1:\n\nInput: transactions = [[2,1],[5,0],[4,2]]\nOutput: 10\nExplanation:\nStarting with money = 10, the transactions can be performed in any order.\nIt can be shown that starting with money < 10 will fail to complete all transactions in some order.\n\nExample 2:\n\nInput: transactions = [[3,0],[0,3]]\nOutput: 3\nExplanation:\n- If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.\n- If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.\nThus, starting with money = 3, the transactions can be performed in any order.\n\nConstraints:\n\n- 1 <= transactions.length <= 10^5\n- transactions[i].length == 2\n- 0 <= cost_i, cashback_i <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(transactions = [[1, 2], [3, 4], [5, 6]]) == 5\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0]]) == 6\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 4\n assert candidate(transactions = [[0, 0], [0, 0], [0, 0]]) == 0\n assert candidate(transactions = [[7, 3], [2, 1], [4, 4]]) == 9\n assert candidate(transactions = [[2, 1], [5, 0], [4, 2]]) == 10\n assert candidate(transactions = [[0, 0], [1, 1], [2, 2]]) == 2\n assert candidate(transactions = [[10, 5], [2, 2], [8, 3]]) == 15\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000]]) == 1000000000\n assert candidate(transactions = [[10, 5], [5, 10], [20, 10]]) == 25\n assert candidate(transactions = [[100, 0], [0, 100], [50, 50]]) == 150\n assert candidate(transactions = [[10, 5], [2, 2], [1, 1]]) == 10\n assert candidate(transactions = [[3, 0], [0, 3]]) == 3\n assert candidate(transactions = [[1000000000, 500000000], [500000000, 250000000]]) == 1250000000\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000], [500000000, 500000000]]) == 1500000000\n assert candidate(transactions = [[5, 5], [5, 5], [5, 5]]) == 5\n assert candidate(transactions = [[100, 50], [50, 100], [25, 25]]) == 100\n assert candidate(transactions = [[0, 1], [0, 2], [0, 3]]) == 0\n assert candidate(transactions = [[10, 0], [0, 10], [5, 5]]) == 15\n assert candidate(transactions = [[5, 10], [3, 6], [7, 8]]) == 7\n assert candidate(transactions = [[100, 99], [99, 98], [98, 97], [97, 96], [96, 95], [95, 94], [94, 93], [93, 92], [92, 91], [91, 90]]) == 109\n assert candidate(transactions = [[100, 50], [50, 100], [25, 75], [75, 25]]) == 150\n assert candidate(transactions = [[1, 100], [1, 99], [1, 98], [1, 97], [1, 96]]) == 1\n assert candidate(transactions = [[1000000000, 500000000], [500000000, 1000000000], [250000000, 750000000], [750000000, 250000000]]) == 1500000000\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000], [500000000, 500000000], [250000000, 250000000], [750000000, 750000000]]) == 1750000000\n assert candidate(transactions = [[1, 999999999], [2, 999999998], [3, 999999997], [4, 999999996], [5, 999999995]]) == 5\n assert candidate(transactions = [[5, 10], [10, 5], [3, 15], [15, 3], [8, 8]]) == 25\n assert candidate(transactions = [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1], [10, 1]]) == 46\n assert candidate(transactions = [[1000000000, 500000000], [500000000, 250000000], [250000000, 125000000], [125000000, 62500000], [62500000, 31250000]]) == 1468750000\n assert candidate(transactions = [[5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [5, 0], [4, 5], [3, 5], [2, 5], [1, 5]]) == 20\n assert candidate(transactions = [[1, 1000000000], [2, 1000000000], [3, 1000000000], [4, 1000000000], [5, 1000000000], [6, 1000000000], [7, 1000000000], [8, 1000000000], [9, 1000000000], [10, 1000000000]]) == 10\n assert candidate(transactions = [[1000000000, 500000000], [500000000, 250000000], [250000000, 125000000], [125000000, 62500000], [62500000, 31250000], [31250000, 15625000], [15625000, 7812500], [7812500, 3906250], [3906250, 1953125], [1953125, 976562], [976562, 488281], [488281, 244140], [244140, 122070], [122070, 61035], [61035, 30517], [30517, 15258], [15258, 7629], [7629, 3814], [3814, 1907], [1907, 953], [953, 476], [476, 238], [238, 119], [119, 59], [59, 29], [29, 14], [14, 7], [7, 3], [3, 1]]) == 1499999999\n assert candidate(transactions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25], [60, 30]]) == 135\n assert candidate(transactions = [[1, 1], [1, 2], [2, 1], [2, 2], [1, 3], [3, 1], [3, 3]]) == 6\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000], [500000000, 500000000], [500000001, 499999999]]) == 1500000002\n assert candidate(transactions = [[10, 5], [9, 4], [8, 3], [7, 2], [6, 1], [5, 0], [4, 6], [3, 7], [2, 8], [1, 9]]) == 35\n assert candidate(transactions = [[100, 50], [200, 150], [300, 100], [400, 50], [500, 0]]) == 1300\n assert candidate(transactions = [[10, 10], [20, 10], [30, 10], [40, 10], [50, 10], [60, 10], [70, 10], [80, 10], [90, 10], [100, 10]]) == 460\n assert candidate(transactions = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]) == 45\n assert candidate(transactions = [[5, 0], [0, 5], [5, 5], [0, 0], [10, 10]]) == 15\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [10, 0]]) == 55\n assert candidate(transactions = [[10, 5], [20, 15], [30, 25], [40, 35], [50, 45]]) == 70\n assert candidate(transactions = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6], [6, 5], [7, 8], [8, 7], [9, 10], [10, 9]]) == 14\n assert candidate(transactions = [[100, 90], [90, 80], [80, 70], [70, 60], [60, 50]]) == 140\n assert candidate(transactions = [[9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 0]]) == 17\n assert candidate(transactions = [[1000, 500], [1500, 1000], [2000, 1500], [2500, 2000], [3000, 2500]]) == 5000\n assert candidate(transactions = [[1000000000, 900000000], [500000000, 400000000], [300000000, 200000000], [100000000, 90000000]]) == 1210000000\n assert candidate(transactions = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10]]) == 55\n assert candidate(transactions = [[500, 500], [500, 500], [500, 500], [500, 500], [500, 500]]) == 500\n assert candidate(transactions = [[10, 1], [5, 5], [15, 10], [20, 15], [25, 20], [30, 25], [35, 30], [40, 35], [45, 40]]) == 84\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 9\n assert candidate(transactions = [[10, 15], [15, 20], [20, 25], [25, 30], [30, 35], [35, 40], [40, 45], [45, 50], [50, 55]]) == 50\n assert candidate(transactions = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [2, 1], [1, 2]]) == 4\n assert candidate(transactions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10]]) == 505\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 5\n assert candidate(transactions = [[5, 2], [10, 3], [15, 5], [20, 10]]) == 40\n assert candidate(transactions = [[100, 0], [0, 100], [50, 50], [25, 25], [75, 75]]) == 175\n assert candidate(transactions = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == 10\n assert candidate(transactions = [[10, 1], [9, 2], [8, 3], [7, 4], [6, 5], [5, 6], [4, 7], [3, 8], [2, 9], [1, 10]]) == 30\n assert candidate(transactions = [[10, 0], [20, 10], [30, 20], [40, 30], [50, 40], [60, 50], [70, 60], [80, 70], [90, 80]]) == 170\n assert candidate(transactions = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 19\n assert candidate(transactions = [[100, 1], [101, 1], [102, 1], [103, 1], [104, 1]]) == 506\n assert candidate(transactions = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 6\n assert candidate(transactions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 10\n assert candidate(transactions = [[9, 8], [7, 6], [5, 4], [3, 2], [1, 0]]) == 13\n assert candidate(transactions = [[10, 15], [20, 10], [30, 5], [40, 0], [50, 25], [60, 30], [70, 20]]) == 210\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 8\n assert candidate(transactions = [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]]) == 25\n assert candidate(transactions = [[100, 50], [200, 150], [50, 100], [300, 200]]) == 400\n assert candidate(transactions = [[100, 50], [200, 100], [300, 150], [50, 25]]) == 475\n assert candidate(transactions = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]) == 0\n assert candidate(transactions = [[50, 0], [25, 0], [0, 50], [0, 25], [75, 0], [0, 75]]) == 150\n assert candidate(transactions = [[20, 10], [25, 15], [30, 20], [35, 25], [40, 30], [45, 35], [50, 40], [55, 45], [60, 50], [65, 55]]) == 155\n assert candidate(transactions = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]) == 6\n assert candidate(transactions = [[1, 100], [2, 99], [3, 98], [4, 97], [5, 96]]) == 5\n assert candidate(transactions = [[9, 8], [7, 6], [5, 4], [3, 2], [1, 0]]) == 13\n assert candidate(transactions = [[100, 10], [90, 20], [80, 30], [70, 40], [60, 50], [50, 60], [40, 70], [30, 80], [20, 90], [10, 100]]) == 300\n assert candidate(transactions = [[500, 250], [250, 125], [125, 62], [62, 31], [31, 15], [15, 7], [7, 3], [3, 1], [1, 0]]) == 750\n assert candidate(transactions = [[10, 100], [20, 90], [30, 80], [40, 70], [50, 60], [60, 50], [70, 40], [80, 30], [90, 20], [100, 10]]) == 300\n assert candidate(transactions = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100]]) == 100\n assert candidate(transactions = [[5, 0], [5, 5], [5, 10], [5, 15], [5, 20], [5, 25], [5, 30], [5, 35], [5, 40], [5, 45]]) == 10\n assert candidate(transactions = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]) == 4\n assert candidate(transactions = [[100, 50], [50, 100], [200, 150], [150, 200]]) == 250\n assert candidate(transactions = [[10, 5], [5, 10], [15, 20], [20, 15], [25, 30], [30, 25]]) == 40\n assert candidate(transactions = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 5]]) == 7\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000], [500000000, 500000000]]) == 1500000000\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0]]) == 15\n assert candidate(transactions = [[100, 0], [50, 100], [25, 50], [10, 25], [5, 10], [1, 5]]) == 150\n assert candidate(transactions = [[10, 9], [9, 8], [8, 7], [7, 6], [6, 5], [5, 4], [4, 3], [3, 2], [2, 1], [1, 0]]) == 19\n assert candidate(transactions = [[5, 10], [15, 5], [25, 20], [35, 30], [45, 40], [55, 50], [65, 60], [75, 70], [85, 80]]) == 125\n assert candidate(transactions = [[10, 5], [20, 10], [30, 15], [40, 20], [50, 25]]) == 100\n assert candidate(transactions = [[5, 10], [10, 5], [0, 0], [7, 7], [3, 3]]) == 12\n assert candidate(transactions = [[1000, 1000], [2000, 1000], [3000, 1000], [4000, 1000], [5000, 1000], [6000, 1000], [7000, 1000], [8000, 1000], [9000, 1000], [10000, 1000]]) == 46000\n assert candidate(transactions = [[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]]) == 150\n assert candidate(transactions = [[10, 1], [20, 2], [30, 3], [40, 4], [50, 5], [60, 6], [70, 7], [80, 8], [90, 9], [100, 10], [1, 100], [2, 90], [3, 80], [4, 70], [5, 60], [6, 50], [7, 40], [8, 30], [9, 20], [10, 10]]) == 505\n assert candidate(transactions = [[1, 0], [0, 1], [1, 1], [0, 0], [1, 0], [0, 1]]) == 3\n assert candidate(transactions = [[1000000000, 0], [0, 1000000000]]) == 1000000000\n assert candidate(transactions = [[100000, 50000], [50000, 25000], [25000, 12500], [12500, 6250], [6250, 3125], [3125, 1562], [1562, 781], [781, 390], [390, 195]]) == 149805\n assert candidate(transactions = [[100, 0], [90, 10], [80, 20], [70, 30], [60, 40], [50, 50], [40, 60], [30, 70], [20, 80], [10, 90]]) == 350\n assert candidate(transactions = [[500, 400], [400, 300], [300, 200], [200, 100]]) == 800\n assert candidate(transactions = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10]]) == 0\n assert candidate(transactions = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 7\n assert candidate(transactions = [[0, 100], [100, 200], [200, 300], [300, 400], [400, 500]]) == 400\n assert candidate(transactions = [[10, 0], [0, 10], [5, 5], [5, 0], [0, 5], [7, 7], [3, 3], [2, 2], [1, 1]]) == 22\n assert candidate(transactions = [[10, 10], [9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1]]) == 10\n assert candidate(transactions = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 8\n assert candidate(transactions = [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0], [10, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 65\n assert candidate(transactions = [[10, 1], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9]]) == 54\n assert candidate(transactions = [[10, 5], [15, 10], [20, 15], [25, 20], [30, 25], [35, 30], [40, 35], [45, 40], [50, 45], [55, 50]]) == 100\n", "comparison": "exact"}, "public_tests": ["[[2,1],[5,0],[4,2]]", "[[3,0],[0,3]]"], "hints": ["Split transactions that have cashback greater or equal to cost apart from transactions that have cashback less than cost. You will always earn money in the first scenario.", "For transactions that have cashback greater or equal to cost, sort them by cost in descending order.", "For transactions that have cashback less than cost, sort them by cashback in ascending order."], "metadata": {"canonical_parameter_names": ["transactions"], "leetcode_dataset_entry_point": "Solution().minimumMoney", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:48+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumMoney($transactions) {", "container": "Solution", "callable": "minimumMoney", "parameters": [{"name": "transactions", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2413, "task_id": "smallest-even-multiple", "difficulty": "Easy", "problem_description": "Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.\n\nExample 1:\n\nInput: n = 5\nOutput: 10\nExplanation: The smallest multiple of both 5 and 2 is 10.\n\nExample 2:\n\nInput: n = 6\nOutput: 6\nExplanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.\n\nConstraints:\n\n- 1 <= n <= 150\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 6\n assert candidate(n = 100) == 100\n assert candidate(n = 33) == 66\n assert candidate(n = 75) == 150\n assert candidate(n = 6) == 6\n assert candidate(n = 2) == 2\n assert candidate(n = 1) == 2\n assert candidate(n = 7) == 14\n assert candidate(n = 5) == 10\n assert candidate(n = 150) == 150\n assert candidate(n = 45) == 90\n assert candidate(n = 119) == 238\n assert candidate(n = 53) == 106\n assert candidate(n = 43) == 86\n assert candidate(n = 103) == 206\n assert candidate(n = 145) == 290\n assert candidate(n = 37) == 74\n assert candidate(n = 23) == 46\n assert candidate(n = 73) == 146\n assert candidate(n = 133) == 266\n assert candidate(n = 8) == 8\n assert candidate(n = 147) == 294\n assert candidate(n = 131) == 262\n assert candidate(n = 27) == 54\n assert candidate(n = 35) == 70\n assert candidate(n = 77) == 154\n assert candidate(n = 11) == 22\n assert candidate(n = 142) == 142\n assert candidate(n = 55) == 110\n assert candidate(n = 65) == 130\n assert candidate(n = 97) == 194\n assert candidate(n = 88) == 88\n assert candidate(n = 29) == 58\n assert candidate(n = 135) == 270\n assert candidate(n = 144) == 144\n assert candidate(n = 107) == 214\n assert candidate(n = 21) == 42\n assert candidate(n = 115) == 230\n assert candidate(n = 87) == 174\n assert candidate(n = 137) == 274\n assert candidate(n = 17) == 34\n assert candidate(n = 42) == 42\n assert candidate(n = 101) == 202\n assert candidate(n = 89) == 178\n assert candidate(n = 112) == 112\n assert candidate(n = 71) == 142\n assert candidate(n = 81) == 162\n assert candidate(n = 41) == 82\n assert candidate(n = 9) == 18\n assert candidate(n = 83) == 166\n assert candidate(n = 121) == 242\n assert candidate(n = 105) == 210\n assert candidate(n = 79) == 158\n assert candidate(n = 84) == 84\n assert candidate(n = 63) == 126\n assert candidate(n = 61) == 122\n assert candidate(n = 130) == 130\n assert candidate(n = 49) == 98\n assert candidate(n = 47) == 94\n assert candidate(n = 113) == 226\n assert candidate(n = 93) == 186\n assert candidate(n = 57) == 114\n assert candidate(n = 111) == 222\n assert candidate(n = 123) == 246\n assert candidate(n = 95) == 190\n assert candidate(n = 141) == 282\n assert candidate(n = 51) == 102\n assert candidate(n = 127) == 254\n assert candidate(n = 15) == 30\n assert candidate(n = 13) == 26\n assert candidate(n = 69) == 138\n assert candidate(n = 125) == 250\n assert candidate(n = 12) == 12\n assert candidate(n = 117) == 234\n assert candidate(n = 59) == 118\n assert candidate(n = 67) == 134\n assert candidate(n = 99) == 198\n assert candidate(n = 64) == 64\n assert candidate(n = 143) == 286\n assert candidate(n = 128) == 128\n assert candidate(n = 129) == 258\n assert candidate(n = 140) == 140\n assert candidate(n = 149) == 298\n assert candidate(n = 19) == 38\n assert candidate(n = 39) == 78\n assert candidate(n = 91) == 182\n assert candidate(n = 139) == 278\n assert candidate(n = 85) == 170\n assert candidate(n = 109) == 218\n assert candidate(n = 31) == 62\n assert candidate(n = 25) == 50\n", "comparison": "exact"}, "public_tests": ["5", "6"], "hints": ["A guaranteed way to find a multiple of 2 and n is to multiply them together. When is this the answer, and when is there a smaller answer?", "There is a smaller answer when n is even."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().smallestEvenMultiple", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:50+00:00", "tests_total": 91, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function smallestEvenMultiple($n) {", "container": "Solution", "callable": "smallestEvenMultiple", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2414, "task_id": "length-of-the-longest-alphabetical-continuous-substring", "difficulty": "Medium", "problem_description": "An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string \"abcdefghijklmnopqrstuvwxyz\".\n\n- For example, \"abc\" is an alphabetical continuous string, while \"acb\" and \"za\" are not.\n\nGiven a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.\n\nExample 1:\n\nInput: s = \"abacaba\"\nOutput: 2\nExplanation: There are 4 distinct continuous substrings: \"a\", \"b\", \"c\" and \"ab\".\n\"ab\" is the longest continuous substring.\n\nExample 2:\n\nInput: s = \"abcde\"\nOutput: 5\nExplanation: \"abcde\" is the longest continuous substring.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of only English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"zzzzzzzzz\") == 1\n assert candidate(s = \"abxyz\") == 3\n assert candidate(s = \"qrstuvwpqrstu\") == 7\n assert candidate(s = \"mnopqrstuvwxyzz\") == 14\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"mnopqrstuvwxyza\") == 14\n assert candidate(s = \"abababab\") == 2\n assert candidate(s = \"qrstuvwxyza\") == 10\n assert candidate(s = \"bcdfghij\") == 5\n assert candidate(s = \"a\") == 1\n assert candidate(s = \"abcdabcde\") == 5\n assert candidate(s = \"pqrstuvwxyzabc\") == 11\n assert candidate(s = \"ababababab\") == 2\n assert candidate(s = \"mnopqr\") == 6\n assert candidate(s = \"abcde\") == 5\n assert candidate(s = \"xyz\") == 3\n assert candidate(s = \"mnopqrstu\") == 9\n assert candidate(s = \"qrstuvwpqr\") == 7\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 1\n assert candidate(s = \"abccba\") == 3\n assert candidate(s = \"acdfg\") == 2\n assert candidate(s = \"defghijklmno\") == 12\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 2\n assert candidate(s = \"zab\") == 2\n assert candidate(s = \"abxyzab\") == 3\n assert candidate(s = \"bcdfghjkl\") == 3\n assert candidate(s = \"abacaba\") == 2\n assert candidate(s = \"xyzabc\") == 3\n assert candidate(s = \"abcabcvwxyz\") == 5\n assert candidate(s = \"abcdefgxyzabcdefghijlmnopqrstuvwxyz\") == 15\n assert candidate(s = \"abcdefghijlmnopqrstuvwxyzmnopqrstuvwxy\") == 15\n assert candidate(s = \"mnopqrstuabcdefghijklmnopqrstuvwxyzaabcdeefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"defghijklmnopqrstuvwxyz\") == 23\n assert candidate(s = \"mnopqrstuvmnopqrstu\") == 10\n assert candidate(s = \"mnopqrstuuvwxyzaaaa\") == 9\n assert candidate(s = \"abcabcdabcdeabcdeabcd\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzab\") == 26\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzz\") == 26\n assert candidate(s = \"pqrsabcdewxyz\") == 5\n assert candidate(s = \"xyzabcd\") == 4\n assert candidate(s = \"aaaabbbbcccc\") == 2\n assert candidate(s = \"zzzzzzzzzz\") == 1\n assert candidate(s = \"abxyzabxyz\") == 3\n assert candidate(s = \"abdefgxyz\") == 4\n assert candidate(s = \"defghijklmnopqrstuvw\") == 20\n assert candidate(s = \"mnopqrstuvxyzab\") == 10\n assert candidate(s = \"pqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 11\n assert candidate(s = \"mnopqrstuabcde\") == 9\n assert candidate(s = \"abcxyzab\") == 3\n assert candidate(s = \"abcdefgxyzabcde\") == 7\n assert candidate(s = \"abcabcabcabcabcabcabc\") == 3\n assert candidate(s = \"pqrstuvwxyza\") == 11\n assert candidate(s = \"mnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 14\n assert candidate(s = \"mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz\") == 14\n assert candidate(s = \"lmnopqrstuvwxyzabc\") == 15\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijkl\") == 14\n assert candidate(s = \"qrsabcdabcdxyz\") == 4\n assert candidate(s = \"defghijklmnopqrstuvwxyza\") == 23\n assert candidate(s = \"mnopqrstuvwxyzmnopqrstuvwxyza\") == 14\n assert candidate(s = \"abcdeabfghicdef\") == 5\n assert candidate(s = \"xyzabxyzuvwxyza\") == 6\n assert candidate(s = \"abxyzabcxyz\") == 3\n assert candidate(s = \"qrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 10\n assert candidate(s = \"abcdefabcdeabcde\") == 6\n assert candidate(s = \"pqrsabcd\") == 4\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == 26\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyza\") == 26\n assert candidate(s = \"klmnopqrstuvxyz\") == 12\n assert candidate(s = \"abababababab\") == 2\n assert candidate(s = \"mnopqrstuabcdefghijklmnopqrstuvwxyzaabcde\") == 26\n assert candidate(s = \"mnopqrstuvwxyzabcde\") == 14\n assert candidate(s = \"xyzabcde\") == 5\n assert candidate(s = \"mnopqrstuzyxwvutsrqponmlkjihgfedcba\") == 9\n assert candidate(s = \"qrsabcdabcdabcd\") == 4\n assert candidate(s = \"mnopqrstuvwxyzabcdefghijklmno\") == 15\n assert candidate(s = \"abcdeabcdabcdabcdabcde\") == 5\n assert candidate(s = \"mnopqrstuabcdefghijklmnopqrstuvwxyza\") == 26\n assert candidate(s = \"aaaaa\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"xyzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxz\") == 3\n assert candidate(s = \"mnopqrstuuvwxyza\") == 9\n assert candidate(s = \"abcdefgabcdefgabcdefgabcdefg\") == 7\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"qrstuvwxyzabcdefghijklmnop\") == 16\n assert candidate(s = \"abcdxyzuvwxyza\") == 6\n assert candidate(s = \"mnopqrstuvwxyzmnopqrstu\") == 14\n assert candidate(s = \"xyzzyxwvutsrqponmlkjihgfedcba\") == 3\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxy\") == 25\n assert candidate(s = \"zabcvwxyz\") == 5\n assert candidate(s = \"abxyzabcd\") == 4\n assert candidate(s = \"mnopqrlmnopqr\") == 7\n assert candidate(s = \"aabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"abxyzabc\") == 3\n assert candidate(s = \"qrstuvwpqrstuzyxwvutsrqponmlkjihgfedcba\") == 7\n assert candidate(s = \"zabcdefghijklmnopqrstuvwxyza\") == 26\n assert candidate(s = \"xyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 3\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbcc\") == 2\n assert candidate(s = \"abcdefghijlmnopqrstuvwxyz\") == 15\n assert candidate(s = \"abcddefghijklmnopqrstuvwxyz\") == 23\n assert candidate(s = \"abcdeabcdeabcde\") == 5\n assert candidate(s = \"qrstuvwxyz\") == 10\n assert candidate(s = \"abcdefghijkabcde\") == 11\n assert candidate(s = \"abcdefgabcdefgabcdefg\") == 7\n assert candidate(s = \"abcdefghijlkjihgfedcba\") == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcbaedcba\") == 1\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzaabcdefghijklmnopqrstuvwxyza\") == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 1\n assert candidate(s = \"xyzzyxwvutsrqpomnlkjihgfedcba\") == 3\n assert candidate(s = \"pqrstuvwxyzabcde\") == 11\n assert candidate(s = \"lmnopqrsabcd\") == 8\n", "comparison": "exact"}, "public_tests": ["\"abacaba\"", "\"abcde\""], "hints": ["What is the longest possible continuous substring?", "The size of the longest possible continuous substring is at most 26, so we can just brute force the answer."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().longestContinuousSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:53+00:00", "tests_total": 115, "tests_dropped": 1, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function longestContinuousSubstring($s) {", "container": "Solution", "callable": "longestContinuousSubstring", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2416, "task_id": "sum-of-prefix-scores-of-strings", "difficulty": "Hard", "problem_description": "You are given an array words of size n consisting of non-empty strings.\n\nWe define the score of a string term as the number of strings words[i] such that term is a prefix of words[i].\n\n- For example, if words = [\"a\", \"ab\", \"abc\", \"cab\"], then the score of \"ab\" is 2, since \"ab\" is a prefix of both \"ab\" and \"abc\".\n\nReturn an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].\n\nNote that a string is considered as a prefix of itself.\n\nExample 1:\n\nInput: words = [\"abc\",\"ab\",\"bc\",\"b\"]\nOutput: [5,4,3,2]\nExplanation: The answer for each string is the following:\n- \"abc\" has 3 prefixes: \"a\", \"ab\", and \"abc\".\n- There are 2 strings with the prefix \"a\", 2 strings with the prefix \"ab\", and 1 string with the prefix \"abc\".\nThe total is answer[0] = 2 + 2 + 1 = 5.\n- \"ab\" has 2 prefixes: \"a\" and \"ab\".\n- There are 2 strings with the prefix \"a\", and 2 strings with the prefix \"ab\".\nThe total is answer[1] = 2 + 2 = 4.\n- \"bc\" has 2 prefixes: \"b\" and \"bc\".\n- There are 2 strings with the prefix \"b\", and 1 string with the prefix \"bc\".\nThe total is answer[2] = 2 + 1 = 3.\n- \"b\" has 1 prefix: \"b\".\n- There are 2 strings with the prefix \"b\".\nThe total is answer[3] = 2.\n\nExample 2:\n\nInput: words = [\"abcd\"]\nOutput: [4]\nExplanation:\n\"abcd\" has 4 prefixes: \"a\", \"ab\", \"abc\", and \"abcd\".\nEach prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4.\n\nConstraints:\n\n- 1 <= words.length <= 1000\n- 1 <= words[i].length <= 1000\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['hello', 'hell', 'he', 'h']) == [12, 11, 7, 4]\n assert candidate(words = ['abc', 'ab', 'bc', 'b']) == [5, 4, 3, 2]\n assert candidate(words = ['a', 'b', 'c', 'd']) == [1, 1, 1, 1]\n assert candidate(words = ['aa', 'aaa', 'aaaa', 'aaaaa']) == [8, 11, 13, 14]\n assert candidate(words = ['a', 'ab', 'abc', 'abcd']) == [4, 7, 9, 10]\n assert candidate(words = ['abcde', 'abcd', 'abc', 'ab', 'a']) == [15, 14, 12, 9, 5]\n assert candidate(words = ['b', 'bb', 'bbb', 'bbbb']) == [4, 7, 9, 10]\n assert candidate(words = ['xyz', 'xy', 'x']) == [6, 5, 3]\n assert candidate(words = ['abcd']) == [4]\n assert candidate(words = ['xyz', 'xy', 'x', 'xyzabc']) == [9, 7, 4, 12]\n assert candidate(words = ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']) == [4, 4, 4, 4, 4, 4, 4, 4, 4]\n assert candidate(words = ['aaaa', 'aa', 'a']) == [7, 5, 3]\n assert candidate(words = ['dynamic', 'dyn', 'dynam', 'dynamicp', 'dynamicpr', 'dynamicpro', 'dynamicprogra', 'dynamicprogram', 'dynamicprogramming']) == [57, 27, 43, 63, 68, 72, 81, 83, 87]\n assert candidate(words = ['optimization', 'optimize', 'opt', 'opti', 'optim', 'optimi']) == [37, 33, 18, 23, 27, 30]\n assert candidate(words = ['xylophone', 'xylo', 'xylophon', 'xy', 'xyl', 'xylophonist', 'xylophoneplayer', 'xylophoneplayerperformance']) == [52, 29, 49, 16, 23, 52, 64, 75]\n assert candidate(words = ['xylophone', 'xylography', 'xylo', 'xylophoneography', 'xyl', 'xylonate']) == [33, 29, 23, 40, 18, 27]\n assert candidate(words = ['aabbcc', 'aabbc', 'aabb', 'aa', 'a', 'aabbbccc', 'aabbbbcccc', 'aabbbbccccd']) == [30, 29, 27, 15, 8, 33, 40, 41]\n assert candidate(words = ['aaaa', 'aaab', 'aaac', 'aabb', 'aabc', 'abaa', 'abab', 'abac', 'abba', 'abbb', 'abbc', 'abca', 'abcb', 'abcc', 'acaa', 'acab', 'acac', 'acba', 'acbb', 'acbc', 'acca', 'accc']) == [31, 31, 31, 30, 30, 35, 35, 35, 35, 35, 35, 35, 35, 35, 34, 34, 34, 34, 34, 34, 33, 33]\n assert candidate(words = ['abacax', 'abaca', 'bacax', 'abac', 'ab']) == [17, 16, 5, 14, 8]\n assert candidate(words = ['apple', 'app', 'application', 'applesauce', 'appetizer']) == [20, 15, 25, 25, 21]\n assert candidate(words = ['pneumonoultramicroscopicsilicovolcanoconiosis', 'pneumo', 'pneumonoultra', 'pneumonoultramicro', 'pneumonoultramicroscopicsilico', 'pneumonoultramicroscopicsilicovolcano', 'pneumo']) == [155, 42, 77, 97, 133, 147, 42]\n assert candidate(words = ['programming', 'program', 'pro', 'prog', 'progr']) == [30, 26, 15, 19, 22]\n assert candidate(words = ['algorithm', 'algo', 'al', 'alex', 'ale', 'all']) == [21, 16, 12, 15, 14, 13]\n assert candidate(words = ['abcdabcd', 'abcabc', 'ababab', 'aaaaaa', 'bbbbbb', 'cccccc', 'dddddd']) == [14, 12, 11, 9, 6, 6, 6]\n assert candidate(words = ['algorithm', 'algo', 'alg', 'algor', 'algorith', 'algori']) == [35, 23, 18, 27, 34, 30]\n assert candidate(words = ['aabbcc', 'aabbc', 'aabb', 'aab', 'aa', 'a', 'aabbbcc', 'aabbb', 'aabbbb']) == [33, 32, 30, 24, 17, 9, 35, 33, 34]\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa']) == [9, 17, 24, 30, 35, 39, 42, 44, 45]\n assert candidate(words = ['prefix', 'pre', 'prefer', 'preference', 'presentation', 'president', 'presidency']) == [26, 21, 28, 32, 32, 33, 34]\n assert candidate(words = ['hello', 'hell', 'he', 'h', 'hero', 'helium', 'helper']) == [20, 19, 13, 7, 15, 20, 20]\n assert candidate(words = ['unique', 'un', 'uni', 'unic', 'uniqu', 'uniquee', 'uniqueee', 'uniqueeee']) == [37, 16, 23, 24, 33, 40, 42, 43]\n assert candidate(words = ['prefix', 'pre', 'pref', 'prefi', 'prefin', 'prefixation', 'prefixes', 'prefixing', 'prefixes', 'preference', 'prefer']) == [55, 33, 43, 50, 51, 60, 59, 58, 59, 51, 47]\n assert candidate(words = ['apple', 'app', 'ap', 'application', 'appetite']) == [17, 14, 10, 23, 19]\n assert candidate(words = ['aabbcc', 'aab', 'abc', 'aac', 'acc', 'aaa', 'bbb', 'ccc', 'aabbc', 'aabbbc', 'aabbbcc', 'aabbbccc']) == [32, 24, 12, 19, 12, 19, 3, 3, 31, 35, 37, 38]\n assert candidate(words = ['complex', 'com', 'compl', 'complexity', 'composite']) == [26, 15, 22, 29, 24]\n assert candidate(words = ['cat', 'cater', 'caterpillar', 'catering', 'caterer', 'caterers', 'catered', 'catering']) == [24, 38, 44, 44, 43, 44, 42, 44]\n assert candidate(words = ['a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa', 'aaaaaaaaaa']) == [10, 19, 27, 34, 40, 45, 49, 52, 54, 55]\n assert candidate(words = ['optimization', 'opt', 'opti', 'optim', 'optimiz', 'optimise', 'optimized']) == [44, 21, 27, 32, 39, 38, 41]\n assert candidate(words = ['data', 'dat', 'database', 'datascience', 'datastructure']) == [19, 15, 23, 27, 29]\n assert candidate(words = ['car', 'cat', 'catch', 'cart', 'card', 'carpet']) == [16, 14, 16, 17, 17, 19]\n assert candidate(words = ['banana', 'band', 'ball', 'bat', 'basketball']) == [15, 13, 12, 11, 18]\n assert candidate(words = ['programming', 'program', 'pro', 'pr', 'p', 'prefix', 'pre', 'preprocessing']) == [30, 26, 18, 15, 8, 21, 18, 28]\n assert candidate(words = ['longword', 'longworder', 'longworderer', 'longwordererest', 'longwordereresterest']) == [40, 48, 54, 60, 65]\n assert candidate(words = ['algorithm', 'algo', 'al', 'alex', 'algorithmic', 'algorithms']) == [35, 20, 12, 14, 37, 36]\n assert candidate(words = ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc']) == [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]\n assert candidate(words = ['backtracking', 'back', 'backt', 'backtr', 'backtra', 'backtrac', 'backtrack', 'backtracki', 'backtrackin', 'backtrackin', 'backtrackinga', 'backtrackingal', 'backtrackingalg', 'backtrackingalgo']) == [131, 56, 69, 81, 92, 102, 111, 119, 126, 126, 135, 138, 140, 141]\n assert candidate(words = ['prefix', 'pre', 'pres', 'presum', 'pressure']) == [18, 15, 18, 20, 22]\n assert candidate(words = ['interview', 'inter', 'inte', 'interw', 'interv', 'intervi', 'interviewe']) == [45, 34, 28, 35, 38, 41, 46]\n assert candidate(words = ['zebra', 'zoo', 'zookeeper', 'zoozoo', 'ze', 'zee', 'z']) == [13, 13, 19, 16, 10, 11, 7]\n assert candidate(words = ['repeated', 'repeat', 'rep', 're', 'r', 'peated', 'eat', 'e', 't', 'ted', 'tedious', 'tediousness']) == [20, 18, 12, 9, 5, 6, 4, 2, 4, 10, 18, 22]\n assert candidate(words = ['banana', 'ban', 'bananas', 'band', 'bandana', 'bandwidth']) == [24, 18, 25, 21, 24, 26]\n assert candidate(words = ['repeated', 'repeats', 'repeat', 'repeating', 'repeatedly', 'repeatability']) == [40, 37, 36, 39, 42, 43]\n assert candidate(words = ['algorithm', 'al', 'algo', 'all', 'algorithms', 'application', 'app']) == [28, 12, 18, 13, 29, 19, 11]\n assert candidate(words = ['flower', 'flow', 'flight', 'flour', 'flourish', 'flourishingly']) == [21, 19, 16, 23, 29, 34]\n assert candidate(words = ['banana', 'ban', 'band', 'bandana', 'bandanna', 'banda']) == [21, 18, 22, 28, 29, 25]\n assert candidate(words = ['hello', 'hell', 'he', 'h', 'helicopter', 'helium', 'help', 'hero', 'her', 'hemoglobin']) == [27, 26, 19, 10, 32, 28, 25, 22, 21, 27]\n assert candidate(words = ['unique', 'uniques', 'unicorn', 'unicycle', 'universality']) == [21, 22, 20, 21, 24]\n assert candidate(words = ['optimization', 'optimizer', 'optimize', 'optimal', 'optimism', 'optimist', 'optimistic', 'optimum', 'opt', 'optional']) == [61, 59, 58, 49, 57, 58, 60, 49, 30, 43]\n assert candidate(words = ['complex', 'complicated', 'complicate', 'complexity', 'complexion', 'complexing', 'complexified', 'complexify', 'complexifies', 'complexing']) == [66, 61, 60, 75, 75, 77, 81, 77, 81, 77]\n assert candidate(words = ['abracadabra', 'abra', 'bracadabra', 'bracada', 'braca', 'bracad', 'bracadab', 'bracadabr', 'bracadabra', 'bracadabram', 'bracadabramm']) == [15, 8, 75, 60, 45, 53, 66, 71, 75, 77, 78]\n assert candidate(words = ['hello', 'hell', 'help', 'hero', 'her', 'hers', 'he', 'hem', 'hemoglobin']) == [24, 23, 22, 22, 21, 22, 18, 20, 27]\n assert candidate(words = ['trie', 'tr', 'tree', 'tries', 'trigger', 'trig']) == [18, 12, 14, 19, 21, 18]\n assert candidate(words = ['aabbcc', 'aabbc', 'aabb', 'aab', 'aa', 'a']) == [21, 20, 18, 15, 11, 6]\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcde', 'abcdef', 'abcdefghij', 'a']) == [48, 21, 24, 32, 5]\n assert candidate(words = ['algorithm', 'algo', 'algor', 'algorit', 'algorith', 'algorithme', 'algori', 'algorithmically']) == [57, 32, 39, 50, 54, 58, 45, 63]\n assert candidate(words = ['banana', 'ban', 'band', 'bandana', 'bandwidth']) == [18, 15, 18, 21, 23]\n assert candidate(words = ['algorithm', 'algebra', 'alien', 'alliance', 'alibi', 'allocate', 'allot', 'allow', 'allude', 'allure', 'alloy', 'ally']) == [32, 30, 28, 37, 28, 40, 37, 37, 36, 36, 37, 33]\n assert candidate(words = ['prefix', 'pre', 'pref', 'prefer', 'preference', 'preferred', 'preferring']) == [29, 21, 27, 35, 39, 39, 40]\n assert candidate(words = ['data', 'database', 'datastructure', 'datamining', 'dataviz', 'datascience', 'datamodel']) == [28, 32, 38, 35, 31, 36, 34]\n assert candidate(words = ['programming', 'program', 'pro', 'progress', 'profound', 'process', 'progressive']) == [37, 33, 21, 35, 26, 25, 38]\n assert candidate(words = ['programming', 'program', 'pro', 'programminglanguage', 'prolog', 'protocol']) == [38, 30, 18, 46, 21, 23]\n assert candidate(words = ['abacaxi', 'abacax', 'abac', 'aba', 'ab', 'a', 'abc', 'abcd', 'abcde']) == [29, 28, 24, 21, 17, 9, 20, 22, 23]\n assert candidate(words = ['zebra', 'ze', 'zoo', 'zookeeper', 'zest', 'zippy', 'zeta', 'zone']) == [15, 12, 13, 19, 14, 12, 14, 13]\n assert candidate(words = ['complexity', 'comp', 'compl', 'comple', 'complex', 'complexe', 'complexit']) == [48, 28, 34, 39, 43, 44, 47]\n assert candidate(words = ['algorithm', 'algebra', 'al', 'algorithmically', 'algo']) == [27, 18, 10, 33, 17]\n assert candidate(words = ['unique', 'un', 'uni', 'unic', 'uniqu', 'uniqueness', 'uniquely', 'uniques']) == [37, 16, 23, 24, 33, 41, 39, 38]\n assert candidate(words = ['datastructure', 'data', 'datas', 'datast', 'datastr', 'datastru', 'datastruc']) == [52, 28, 34, 39, 43, 46, 48]\n assert candidate(words = ['prefix', 'prefixes', 'pref', 'prefer', 'prefixing']) == [26, 28, 20, 22, 29]\n assert candidate(words = ['apple', 'app', 'ap', 'a', 'application']) == [15, 12, 9, 5, 21]\n assert candidate(words = ['banana', 'bandana', 'band', 'bandwidth', 'bandage']) == [18, 23, 19, 24, 23]\n assert candidate(words = ['abacaxi', 'abac', 'aba', 'ab', 'a', 'abacax', 'abacaxs', 'abacaxus']) == [35, 26, 21, 15, 8, 34, 35, 36]\n assert candidate(words = ['interview', 'inter', 'interac', 'interactive', 'interact', 'interactivity']) == [34, 30, 38, 46, 41, 48]\n assert candidate(words = ['prefix', 'prefixing', 'prefixation', 'prefixer', 'pref', 'pre', 'p']) == [32, 35, 37, 34, 24, 19, 7]\n assert candidate(words = ['zebra', 'zebr', 'zeb', 'ze', 'z', 'zebraa', 'zebrab', 'zebrac', 'zebrad']) == [35, 30, 24, 17, 9, 36, 36, 36, 36]\n assert candidate(words = ['cat', 'cater', 'category', 'categories', 'caterpillar', 'catering', 'catered', 'caterer', 'caterers', 'catering']) == [30, 46, 46, 48, 52, 52, 50, 51, 52, 52]\n assert candidate(words = ['abacaxi', 'abacax', 'abac', 'aba', 'ab', 'a', 'bacaxi', 'bacax', 'bac', 'ba', 'b']) == [23, 22, 18, 15, 11, 6, 17, 16, 12, 9, 5]\n assert candidate(words = ['abacax', 'abaca', 'ab', 'abc', 'abcd', 'abcde', 'abcdef']) == [21, 20, 14, 18, 21, 23, 24]\n assert candidate(words = ['xylophone', 'xylo', 'xylophon', 'xylophone', 'xylophones', 'xylophonist', 'xylophonists', 'xylophonistic', 'xylophonistically', 'xylophonists', 'xylophonist']) == [87, 44, 84, 87, 88, 102, 104, 106, 110, 104, 102]\n assert candidate(words = ['algorithm', 'algo', 'al', 'alex', 'alert']) == [19, 14, 10, 13, 14]\n assert candidate(words = ['banana', 'ban', 'band', 'bandana', 'bandwidth', 'bandage']) == [21, 18, 22, 26, 27, 26]\n assert candidate(words = ['test', 'testing', 'tested', 'testify', 'testimony', 'testimonial', 'testament', 'testamentary', 'testator', 'testatrix']) == [40, 46, 42, 46, 51, 53, 52, 55, 48, 49]\n assert candidate(words = ['banana', 'band', 'bandana', 'bandanna', 'bandage', 'bandaid']) == [21, 23, 30, 31, 29, 29]\n assert candidate(words = ['abcd', 'abc', 'ab', 'a', 'zyx', 'zy', 'z', 'mnop', 'mno', 'mn', 'm']) == [10, 9, 7, 4, 6, 5, 3, 10, 9, 7, 4]\n assert candidate(words = ['optimization', 'optimizer', 'optimize', 'optimal', 'optimism', 'optimist', 'optimum', 'option', 'optional', 'opt', 'optic', 'optics']) == [67, 65, 64, 56, 62, 62, 56, 51, 53, 36, 49, 50]\n assert candidate(words = ['banana', 'ban', 'band', 'bandana', 'bandanna', 'banda', 'bandanaaa']) == [24, 21, 26, 35, 35, 30, 37]\n assert candidate(words = ['supercalifragilisticexpialidocious', 'super', 'supercal', 'supercalifrag', 'supercalifragilistic', 'supercalifragilisticex', 'supercalifragilisticexp', 'supercalifragilisticexpia', 'supercalifragilisticexpiali', 'supercalifragilisticexpialidoc', 'supercalifragilisticexpialidociou', 'supercalifragilisticexpialidociousness']) == [274, 60, 93, 143, 206, 222, 229, 241, 251, 263, 272, 278]\n assert candidate(words = ['interspecies', 'inter', 'interstellar', 'interact', 'interaction', 'interference', 'internet', 'interim']) == [48, 40, 48, 46, 49, 47, 43, 42]\n", "comparison": "exact"}, "public_tests": ["[\"abc\",\"ab\",\"bc\",\"b\"]", "[\"abcd\"]"], "hints": ["What data structure will allow you to efficiently keep track of the score of each prefix?", "Use a Trie. Insert all the words into it, and keep a counter at each node that will tell you how many times we have visited each prefix."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().sumPrefixScores", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:51:57+00:00", "tests_total": 96, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string", "trie", "counting"]}, "language": "php", "interface": {"raw_signature": "function sumPrefixScores($words) {", "container": "Solution", "callable": "sumPrefixScores", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2418, "task_id": "sort-the-people", "difficulty": "Easy", "problem_description": "You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.\n\nFor each index i, names[i] and heights[i] denote the name and height of the i^th person.\n\nReturn names sorted in descending order by the people's heights.\n\nExample 1:\n\nInput: names = [\"Mary\",\"John\",\"Emma\"], heights = [180,165,170]\nOutput: [\"Mary\",\"Emma\",\"John\"]\nExplanation: Mary is the tallest, followed by Emma and John.\n\nExample 2:\n\nInput: names = [\"Alice\",\"Bob\",\"Bob\"], heights = [155,185,150]\nOutput: [\"Bob\",\"Alice\",\"Bob\"]\nExplanation: The first Bob is the tallest, followed by Alice and the second Bob.\n\nConstraints:\n\n- n == names.length == heights.length\n- 1 <= n <= 10^3\n- 1 <= names[i].length <= 20\n- 1 <= heights[i] <= 10^5\n- names[i] consists of lower and upper case English letters.\n- All the values of heights are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(names = ['Zoe', 'Lily', 'Rose'],heights = [150, 145, 155]) == ['Rose', 'Zoe', 'Lily']\n assert candidate(names = ['Qwen', 'Alibaba', 'Cloud'],heights = [200, 190, 180]) == ['Qwen', 'Alibaba', 'Cloud']\n assert candidate(names = ['Ava', 'Sophia', 'Isabella'],heights = [160, 165, 170]) == ['Isabella', 'Sophia', 'Ava']\n assert candidate(names = ['Mary', 'John', 'Emma'],heights = [180, 165, 170]) == ['Mary', 'Emma', 'John']\n assert candidate(names = ['A', 'B', 'C', 'D'],heights = [150, 160, 170, 180]) == ['D', 'C', 'B', 'A']\n assert candidate(names = ['Ava', 'Ella', 'Olivia'],heights = [168, 162, 170]) == ['Olivia', 'Ava', 'Ella']\n assert candidate(names = ['Alice', 'Bob', 'Bob'],heights = [155, 185, 150]) == ['Bob', 'Alice', 'Bob']\n assert candidate(names = ['Zoe', 'Liam', 'Noah'],heights = [165, 175, 185]) == ['Noah', 'Liam', 'Zoe']\n assert candidate(names = ['Noah', 'Liam', 'Mason'],heights = [185, 180, 175]) == ['Noah', 'Liam', 'Mason']\n assert candidate(names = ['Mia', 'Ella', 'Olivia'],heights = [168, 162, 170]) == ['Olivia', 'Mia', 'Ella']\n assert candidate(names = ['Tom', 'Jerry', 'Spike'],heights = [190, 160, 175]) == ['Tom', 'Spike', 'Jerry']\n assert candidate(names = ['Zoe', 'Liam', 'Noah'],heights = [175, 180, 165]) == ['Liam', 'Zoe', 'Noah']\n assert candidate(names = ['Z', 'Y', 'X'],heights = [165, 175, 185]) == ['X', 'Y', 'Z']\n assert candidate(names = ['Anna', 'Elsa', 'Olaf'],heights = [170, 180, 160]) == ['Elsa', 'Anna', 'Olaf']\n assert candidate(names = ['Liam', 'Noah', 'Oliver', 'Elijah', 'James', 'William', 'Benjamin'],heights = [179, 178, 177, 176, 175, 174, 173]) == ['Liam', 'Noah', 'Oliver', 'Elijah', 'James', 'William', 'Benjamin']\n assert candidate(names = ['William', 'James', 'Benjamin', 'Henry'],heights = [190, 170, 180, 160]) == ['William', 'Benjamin', 'James', 'Henry']\n assert candidate(names = ['Jackson', 'Aiden', 'Mason', 'Lucas'],heights = [182, 188, 178, 180]) == ['Aiden', 'Jackson', 'Lucas', 'Mason']\n assert candidate(names = ['Dominic', 'Penelope', 'Victor', 'Emilia', 'Mason'],heights = [178, 173, 189, 169, 174]) == ['Victor', 'Dominic', 'Mason', 'Penelope', 'Emilia']\n assert candidate(names = ['Ezra', 'Isabella', 'Oliver', 'Sophia', 'Noah', 'Emma', 'James', 'Amelia', 'Benjamin', 'Ava', 'Elijah', 'Liam'],heights = [177, 165, 183, 170, 185, 171, 179, 172, 180, 167, 182, 184]) == ['Noah', 'Liam', 'Oliver', 'Elijah', 'Benjamin', 'James', 'Ezra', 'Amelia', 'Emma', 'Sophia', 'Ava', 'Isabella']\n assert candidate(names = ['Daniel', 'Matthew', 'Ethan', 'Logan', 'Jackson'],heights = [175, 170, 165, 160, 155]) == ['Daniel', 'Matthew', 'Ethan', 'Logan', 'Jackson']\n assert candidate(names = ['William', 'James', 'George', 'Charles'],heights = [188, 192, 178, 180]) == ['James', 'William', 'Charles', 'George']\n assert candidate(names = ['Liam', 'Noah', 'Oliver', 'Elijah', 'William'],heights = [180, 178, 175, 173, 170]) == ['Liam', 'Noah', 'Oliver', 'Elijah', 'William']\n assert candidate(names = ['Sophia', 'Jackson', 'Mia', 'Logan'],heights = [160, 200, 180, 170]) == ['Jackson', 'Mia', 'Logan', 'Sophia']\n assert candidate(names = ['Amelia', 'Olivia', 'Emma', 'Sophia'],heights = [155, 165, 175, 185]) == ['Sophia', 'Emma', 'Olivia', 'Amelia']\n assert candidate(names = ['Emma', 'Noah', 'Olivia', 'Elijah', 'Ava', 'Sophia'],heights = [173, 186, 168, 183, 170, 165]) == ['Noah', 'Elijah', 'Emma', 'Ava', 'Olivia', 'Sophia']\n assert candidate(names = ['Levi', 'Carter', 'Aria', 'Sebastian', 'Avery'],heights = [175, 184, 168, 189, 176]) == ['Sebastian', 'Carter', 'Avery', 'Levi', 'Aria']\n assert candidate(names = ['Sophia', 'Olivia', 'Isabella', 'Ava', 'Emma'],heights = [162, 178, 168, 173, 175]) == ['Olivia', 'Emma', 'Ava', 'Isabella', 'Sophia']\n assert candidate(names = ['William', 'James', 'Oliver', 'Noah', 'Elijah', 'Lucas'],heights = [195, 194, 193, 192, 191, 190]) == ['William', 'James', 'Oliver', 'Noah', 'Elijah', 'Lucas']\n assert candidate(names = ['Zachary', 'Christopher', 'Jonathan', 'Matthew'],heights = [195, 190, 180, 185]) == ['Zachary', 'Christopher', 'Matthew', 'Jonathan']\n assert candidate(names = ['Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf'],heights = [160, 165, 170, 175, 180]) == ['Golf', 'Foxtrot', 'Echo', 'Delta', 'Charlie']\n assert candidate(names = ['Ava', 'Isabella', 'Sophia', 'Emma', 'Olivia', 'Mia'],heights = [155, 157, 158, 160, 159, 156]) == ['Emma', 'Olivia', 'Sophia', 'Isabella', 'Mia', 'Ava']\n assert candidate(names = ['Grace', 'Heidi', 'Ivy', 'Judy', 'Kara'],heights = [158, 168, 178, 188, 198]) == ['Kara', 'Judy', 'Ivy', 'Heidi', 'Grace']\n assert candidate(names = ['Mila', 'Aaron', 'Jasper', 'Sophie'],heights = [170, 160, 200, 180]) == ['Jasper', 'Sophie', 'Mila', 'Aaron']\n assert candidate(names = ['Finn', 'Jake', 'BMO', 'Marceline', 'LSP'],heights = [160, 170, 155, 180, 150]) == ['Marceline', 'Jake', 'Finn', 'BMO', 'LSP']\n assert candidate(names = ['Zoe', 'Chris', 'Ava', 'Ian'],heights = [165, 190, 175, 180]) == ['Chris', 'Ian', 'Ava', 'Zoe']\n assert candidate(names = ['Grace', 'Katherine', 'Ava', 'Sophie', 'Liam'],heights = [165, 172, 160, 170, 180]) == ['Liam', 'Katherine', 'Sophie', 'Grace', 'Ava']\n assert candidate(names = ['Olivia', 'Emma', 'Ava', 'Sophia'],heights = [158, 159, 160, 157]) == ['Ava', 'Emma', 'Olivia', 'Sophia']\n assert candidate(names = ['Evelyn', 'Arthur', 'Sophie', 'Miles'],heights = [160, 190, 180, 175]) == ['Arthur', 'Sophie', 'Miles', 'Evelyn']\n assert candidate(names = ['Ethan', 'Abigail', 'Daniel', 'Ella'],heights = [185, 168, 195, 175]) == ['Daniel', 'Ethan', 'Ella', 'Abigail']\n assert candidate(names = ['Ava', 'Ella', 'Scarlett', 'Grace'],heights = [185, 175, 165, 155]) == ['Ava', 'Ella', 'Scarlett', 'Grace']\n assert candidate(names = ['Amelia', 'Olivia', 'Ava', 'Isla'],heights = [168, 169, 170, 171]) == ['Isla', 'Ava', 'Olivia', 'Amelia']\n assert candidate(names = ['Noah', 'Sophia', 'Mia', 'Ethan'],heights = [195, 180, 175, 170]) == ['Noah', 'Sophia', 'Mia', 'Ethan']\n assert candidate(names = ['Alex', 'Brian', 'Carter', 'David', 'Ethan'],heights = [155, 165, 175, 185, 195]) == ['Ethan', 'David', 'Carter', 'Brian', 'Alex']\n assert candidate(names = ['Jonathan', 'Katherine', 'Lucas', 'Mia', 'Nina'],heights = [175, 165, 180, 170, 160]) == ['Lucas', 'Jonathan', 'Mia', 'Katherine', 'Nina']\n assert candidate(names = ['Lucas', 'Hannah', 'Olivia', 'Avery'],heights = [185, 168, 190, 175]) == ['Olivia', 'Lucas', 'Avery', 'Hannah']\n assert candidate(names = ['Nina', 'Nora', 'Nina', 'Nora'],heights = [160, 162, 158, 159]) == ['Nora', 'Nina', 'Nora', 'Nina']\n assert candidate(names = ['Daniel', 'Matilda', 'Samuel', 'Lucas', 'Mia', 'Emily', 'Oliver', 'Ava'],heights = [182, 165, 178, 184, 170, 167, 190, 173]) == ['Oliver', 'Lucas', 'Daniel', 'Samuel', 'Ava', 'Mia', 'Emily', 'Matilda']\n assert candidate(names = ['Sophia', 'Olivia', 'Ava', 'Isabella', 'Mia'],heights = [160, 165, 170, 175, 180]) == ['Mia', 'Isabella', 'Ava', 'Olivia', 'Sophia']\n assert candidate(names = ['Sophia', 'Oliver', 'Isabella', 'Noah'],heights = [172, 180, 168, 182]) == ['Noah', 'Oliver', 'Sophia', 'Isabella']\n assert candidate(names = ['Zoe', 'Sophia', 'Ava', 'Isabella'],heights = [163, 164, 165, 162]) == ['Ava', 'Sophia', 'Zoe', 'Isabella']\n assert candidate(names = ['Oliver', 'Amelia', 'Evelyn', 'Jasper'],heights = [185, 170, 180, 190]) == ['Jasper', 'Oliver', 'Evelyn', 'Amelia']\n assert candidate(names = ['Emily', 'Emma', 'Mia', 'Sophia', 'Isabella', 'Ava', 'Olivia'],heights = [163, 164, 162, 165, 166, 161, 160]) == ['Isabella', 'Sophia', 'Emma', 'Emily', 'Mia', 'Ava', 'Olivia']\n assert candidate(names = ['Isabella', 'Sophia', 'Olivia', 'Ava', 'Emma'],heights = [162, 172, 182, 192, 202]) == ['Emma', 'Ava', 'Olivia', 'Sophia', 'Isabella']\n assert candidate(names = ['Liam', 'Noah', 'Oliver', 'Lucas', 'Ethan'],heights = [200, 199, 198, 197, 196]) == ['Liam', 'Noah', 'Oliver', 'Lucas', 'Ethan']\n assert candidate(names = ['Scarlett', 'Ava', 'Emma', 'Olivia', 'Sophia'],heights = [175, 180, 170, 165, 185]) == ['Sophia', 'Ava', 'Scarlett', 'Emma', 'Olivia']\n assert candidate(names = ['Sophia', 'Emma', 'Ava', 'Olivia', 'Isabella', 'Mia'],heights = [169, 168, 167, 166, 165, 164]) == ['Sophia', 'Emma', 'Ava', 'Olivia', 'Isabella', 'Mia']\n assert candidate(names = ['Benjamin', 'Logan', 'Jackson', 'David', 'Aiden'],heights = [150, 160, 170, 180, 190]) == ['Aiden', 'David', 'Jackson', 'Logan', 'Benjamin']\n assert candidate(names = ['Mia', 'Evelyn', 'Abigail', 'Scarlett', 'Amelia'],heights = [180, 175, 170, 165, 160]) == ['Mia', 'Evelyn', 'Abigail', 'Scarlett', 'Amelia']\n assert candidate(names = ['Camila', 'Lincoln', 'Madison', 'Isaac', 'Scarlett'],heights = [167, 187, 170, 182, 163]) == ['Lincoln', 'Isaac', 'Madison', 'Camila', 'Scarlett']\n assert candidate(names = ['Sophia', 'Isabella', 'Olivia', 'Ava', 'Mia'],heights = [162, 171, 168, 165, 169]) == ['Isabella', 'Mia', 'Olivia', 'Ava', 'Sophia']\n assert candidate(names = ['Theodore', 'George', 'Thomas', 'James'],heights = [175, 185, 180, 170]) == ['George', 'Thomas', 'Theodore', 'James']\n assert candidate(names = ['Sam', 'Max', 'Leo', 'Sam'],heights = [185, 182, 179, 184]) == ['Sam', 'Sam', 'Max', 'Leo']\n assert candidate(names = ['Charlotte', 'Sophia', 'Ava', 'Isabella'],heights = [165, 170, 175, 180]) == ['Isabella', 'Ava', 'Sophia', 'Charlotte']\n assert candidate(names = ['Charlotte', 'Amelia', 'Evelyn', 'Abigail', 'Sofia'],heights = [150, 155, 160, 165, 170]) == ['Sofia', 'Abigail', 'Evelyn', 'Amelia', 'Charlotte']\n assert candidate(names = ['Lily', 'Aaron', 'Emma', 'Nolan'],heights = [165, 185, 175, 195]) == ['Nolan', 'Aaron', 'Emma', 'Lily']\n assert candidate(names = ['Sophia', 'Isabella', 'Olivia', 'Ava'],heights = [165, 172, 168, 170]) == ['Isabella', 'Ava', 'Olivia', 'Sophia']\n assert candidate(names = ['Ethan', 'Noah', 'Liam', 'Mason'],heights = [180, 185, 170, 175]) == ['Noah', 'Ethan', 'Mason', 'Liam']\n assert candidate(names = ['Alexander', 'Sophia', 'Benjamin', 'Charlotte', 'Elijah', 'Mia', 'James', 'Amelia'],heights = [180, 166, 175, 168, 183, 172, 178, 171]) == ['Elijah', 'Alexander', 'James', 'Benjamin', 'Mia', 'Amelia', 'Charlotte', 'Sophia']\n assert candidate(names = ['William', 'James', 'Oliver', 'Benjamin', 'Elijah', 'Lucas'],heights = [187, 186, 185, 184, 183, 182]) == ['William', 'James', 'Oliver', 'Benjamin', 'Elijah', 'Lucas']\n assert candidate(names = ['Eva', 'Nathan', 'Ella', 'Samuel', 'Sophia'],heights = [169, 179, 171, 186, 174]) == ['Samuel', 'Nathan', 'Sophia', 'Ella', 'Eva']\n assert candidate(names = ['Zoe', 'Addison', 'Mia', 'Hannah', 'Abigail'],heights = [168, 167, 166, 165, 164]) == ['Zoe', 'Addison', 'Mia', 'Hannah', 'Abigail']\n assert candidate(names = ['Benjamin', 'Olivia', 'Daniel', 'Zachary'],heights = [170, 180, 160, 190]) == ['Zachary', 'Olivia', 'Benjamin', 'Daniel']\n assert candidate(names = ['Carter', 'Jackson', 'Lucas', 'Logan', 'Benjamin'],heights = [190, 185, 180, 175, 170]) == ['Carter', 'Jackson', 'Lucas', 'Logan', 'Benjamin']\n assert candidate(names = ['Amelia', 'Oliver', 'Ava', 'Noah', 'Sophia', 'Ethan', 'Isabella', 'Elijah'],heights = [172, 188, 169, 185, 171, 182, 168, 184]) == ['Oliver', 'Noah', 'Elijah', 'Ethan', 'Amelia', 'Sophia', 'Ava', 'Isabella']\n assert candidate(names = ['Michael', 'Christopher', 'Jessica', 'Matthew', 'Ashley'],heights = [182, 178, 165, 180, 170]) == ['Michael', 'Matthew', 'Christopher', 'Ashley', 'Jessica']\n assert candidate(names = ['Amelia', 'Sophia', 'Isabella', 'Olivia', 'Ava', 'Emma'],heights = [150, 151, 152, 153, 154, 155]) == ['Emma', 'Ava', 'Olivia', 'Isabella', 'Sophia', 'Amelia']\n assert candidate(names = ['Catherine', 'Margaret', 'Joan', 'Eleanor'],heights = [167, 173, 170, 169]) == ['Margaret', 'Joan', 'Eleanor', 'Catherine']\n assert candidate(names = ['Mason', 'Jacob', 'William', 'Ethan', 'Alexander'],heights = [155, 165, 175, 185, 195]) == ['Alexander', 'Ethan', 'William', 'Jacob', 'Mason']\n assert candidate(names = ['Sophia', 'Ava', 'Emma', 'Isabella', 'Olivia', 'Mia', 'Charlotte'],heights = [169, 168, 167, 166, 165, 164, 163]) == ['Sophia', 'Ava', 'Emma', 'Isabella', 'Olivia', 'Mia', 'Charlotte']\n assert candidate(names = ['Scarlett', 'Avery', 'James', 'Michael', 'Evelyn'],heights = [162, 177, 181, 180, 166]) == ['James', 'Michael', 'Avery', 'Evelyn', 'Scarlett']\n assert candidate(names = ['Sophia', 'Jackson', 'Ava', 'Lucas', 'Mia', 'Ethan'],heights = [160, 195, 168, 180, 170, 185]) == ['Jackson', 'Ethan', 'Lucas', 'Mia', 'Ava', 'Sophia']\n assert candidate(names = ['Sophia', 'Isabella', 'Olivia', 'Ava', 'Emma'],heights = [160, 165, 170, 175, 180]) == ['Emma', 'Ava', 'Olivia', 'Isabella', 'Sophia']\n assert candidate(names = ['Alexander', 'Michael', 'Benjamin', 'Daniel'],heights = [190, 188, 185, 187]) == ['Alexander', 'Michael', 'Daniel', 'Benjamin']\n assert candidate(names = ['Mia', 'Ethan', 'Amelia', 'Liam', 'Olivia'],heights = [168, 180, 169, 182, 165]) == ['Liam', 'Ethan', 'Amelia', 'Mia', 'Olivia']\n assert candidate(names = ['Sophia', 'Olivia', 'Ava', 'Isabella'],heights = [165, 170, 175, 180]) == ['Isabella', 'Ava', 'Olivia', 'Sophia']\n assert candidate(names = ['Alexander', 'Michael', 'William', 'James', 'Benjamin'],heights = [155, 190, 165, 185, 170]) == ['Michael', 'James', 'Benjamin', 'William', 'Alexander']\n assert candidate(names = ['Emily', 'Emma', 'Sophia', 'Olivia', 'Isabella', 'Ava'],heights = [161, 160, 159, 158, 157, 156]) == ['Emily', 'Emma', 'Sophia', 'Olivia', 'Isabella', 'Ava']\n assert candidate(names = ['Zoe', 'Lily', 'Rosie', 'Lena'],heights = [160, 162, 158, 159]) == ['Lily', 'Zoe', 'Lena', 'Rosie']\n assert candidate(names = ['Zoe', 'Abigail', 'Daniel', 'Jackson', 'Harper'],heights = [165, 172, 179, 183, 170]) == ['Jackson', 'Daniel', 'Abigail', 'Harper', 'Zoe']\n assert candidate(names = ['Jackson', 'Aiden', 'Lucas', 'Caleb', 'Noah'],heights = [151, 161, 171, 181, 191]) == ['Noah', 'Caleb', 'Lucas', 'Aiden', 'Jackson']\n assert candidate(names = ['Alexander', 'Noah', 'Daniel', 'Matthew', 'Logan'],heights = [182, 181, 183, 180, 179]) == ['Daniel', 'Alexander', 'Noah', 'Matthew', 'Logan']\n assert candidate(names = ['Liam', 'Noah', 'Oliver', 'Elijah', 'James'],heights = [170, 180, 190, 200, 210]) == ['James', 'Elijah', 'Oliver', 'Noah', 'Liam']\n assert candidate(names = ['Lucas', 'Mason', 'Logan', 'Ethan'],heights = [178, 177, 179, 176]) == ['Logan', 'Lucas', 'Mason', 'Ethan']\n assert candidate(names = ['Peter', 'Paul', 'Mary', 'John', 'Jane'],heights = [175, 180, 165, 170, 160]) == ['Paul', 'Peter', 'John', 'Mary', 'Jane']\n assert candidate(names = ['William', 'James', 'Benjamin', 'Henry', 'Noah', 'Liam'],heights = [185, 180, 175, 170, 190, 195]) == ['Liam', 'Noah', 'William', 'James', 'Benjamin', 'Henry']\n assert candidate(names = ['Zoe', 'Lily', 'Ella', 'Amelia'],heights = [160, 165, 170, 175]) == ['Amelia', 'Ella', 'Lily', 'Zoe']\n assert candidate(names = ['Amelia', 'Connor', 'Sophia', 'Ethan'],heights = [175, 195, 180, 185]) == ['Connor', 'Ethan', 'Sophia', 'Amelia']\n assert candidate(names = ['William', 'James', 'Oliver', 'Benjamin', 'Elijah'],heights = [190, 185, 180, 175, 170]) == ['William', 'James', 'Oliver', 'Benjamin', 'Elijah']\n assert candidate(names = ['Emily', 'Ava', 'Sophia', 'Charlotte', 'Isabella'],heights = [160, 170, 165, 155, 175]) == ['Isabella', 'Ava', 'Sophia', 'Emily', 'Charlotte']\n assert candidate(names = ['Liam', 'Noah', 'Oliver', 'Elijah', 'William', 'James'],heights = [179, 178, 177, 176, 175, 174]) == ['Liam', 'Noah', 'Oliver', 'Elijah', 'William', 'James']\n assert candidate(names = ['Jonathan', 'Jordan', 'Jack', 'Jared', 'James', 'Jackson'],heights = [198, 197, 196, 195, 194, 193]) == ['Jonathan', 'Jordan', 'Jack', 'Jared', 'James', 'Jackson']\n assert candidate(names = ['Zoe', 'Yasmin', 'Xander', 'Will', 'Vera'],heights = [150, 160, 170, 180, 190]) == ['Vera', 'Will', 'Xander', 'Yasmin', 'Zoe']\n assert candidate(names = ['Ava', 'Isabella', 'Sophia', 'Mia'],heights = [165, 175, 185, 155]) == ['Sophia', 'Isabella', 'Ava', 'Mia']\n assert candidate(names = ['Zara', 'Oliver', 'Isabella', 'Charlie'],heights = [175, 190, 165, 180]) == ['Oliver', 'Charlie', 'Zara', 'Isabella']\n assert candidate(names = ['Alex', 'Brian', 'Craig', 'David', 'Evan'],heights = [173, 171, 175, 169, 172]) == ['Craig', 'Alex', 'Evan', 'Brian', 'David']\n assert candidate(names = ['Alexander', 'Michael', 'James', 'John', 'Daniel', 'David'],heights = [172, 171, 173, 174, 175, 176]) == ['David', 'Daniel', 'John', 'James', 'Alexander', 'Michael']\n assert candidate(names = ['Scarlett', 'William', 'Lily', 'James', 'Ava', 'Thomas', 'Ella', 'Noah', 'Ethan', 'Mia', 'Olivia'],heights = [174, 185, 167, 180, 168, 182, 170, 183, 181, 169, 165]) == ['William', 'Noah', 'Thomas', 'Ethan', 'James', 'Scarlett', 'Ella', 'Mia', 'Ava', 'Lily', 'Olivia']\n assert candidate(names = ['Emma', 'Charlotte', 'Ava', 'Logan', 'Benjamin'],heights = [163, 170, 167, 178, 185]) == ['Benjamin', 'Logan', 'Charlotte', 'Ava', 'Emma']\n assert candidate(names = ['Sophie', 'Grayson', 'Hannah', 'Isaac', 'Layla'],heights = [170, 185, 165, 188, 172]) == ['Isaac', 'Grayson', 'Layla', 'Sophie', 'Hannah']\n assert candidate(names = ['Evelyn', 'Sophie', 'Isabella', 'Mia', 'Emma'],heights = [168, 170, 166, 165, 172]) == ['Emma', 'Sophie', 'Evelyn', 'Isabella', 'Mia']\n assert candidate(names = ['Zara', 'Xander', 'Yasmin', 'Will'],heights = [160, 175, 170, 165]) == ['Xander', 'Yasmin', 'Will', 'Zara']\n assert candidate(names = ['Liam', 'Hannah', 'Sophie', 'Lucas'],heights = [195, 170, 180, 175]) == ['Liam', 'Sophie', 'Lucas', 'Hannah']\n assert candidate(names = ['Liam', 'Olivia', 'Noah', 'Emma', 'Oliver', 'Ava', 'Sophia', 'Elijah', 'Amelia'],heights = [181, 168, 185, 171, 183, 167, 170, 182, 173]) == ['Noah', 'Oliver', 'Elijah', 'Liam', 'Amelia', 'Emma', 'Sophia', 'Olivia', 'Ava']\n assert candidate(names = ['Sophia', 'Ava', 'Isabella', 'Mia'],heights = [160, 170, 175, 180]) == ['Mia', 'Isabella', 'Ava', 'Sophia']\n assert candidate(names = ['Avery', 'Grayson', 'Evan', 'Nathan'],heights = [172, 182, 175, 180]) == ['Grayson', 'Nathan', 'Evan', 'Avery']\n assert candidate(names = ['Willow', 'Tara', 'Xander', 'Alyson', 'Reese'],heights = [175, 160, 170, 165, 180]) == ['Reese', 'Willow', 'Xander', 'Alyson', 'Tara']\n assert candidate(names = ['Eli', 'Ella', 'Ezra', 'Emilia', 'Evan'],heights = [170, 175, 160, 180, 165]) == ['Emilia', 'Ella', 'Eli', 'Evan', 'Ezra']\n assert candidate(names = ['James', 'Benjamin', 'Mason', 'Noah', 'Lucas'],heights = [170, 175, 180, 185, 190]) == ['Lucas', 'Noah', 'Mason', 'Benjamin', 'James']\n assert candidate(names = ['Jack', 'Rose', 'Cal', 'Fabian', 'Molly'],heights = [170, 175, 165, 180, 160]) == ['Fabian', 'Rose', 'Jack', 'Cal', 'Molly']\n", "comparison": "exact"}, "public_tests": ["[\"Mary\",\"John\",\"Emma\"]\n[180,165,170]", "[\"Alice\",\"Bob\",\"Bob\"]\n[155,185,150]"], "hints": ["Find the tallest person and swap with the first person, then find the second tallest person and swap with the second person, etc. Repeat until you fix all n people."], "metadata": {"canonical_parameter_names": ["names", "heights"], "leetcode_dataset_entry_point": "Solution().sortPeople", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:02+00:00", "tests_total": 120, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "sorting"]}, "language": "php", "interface": {"raw_signature": "function sortPeople($names, $heights) {", "container": "Solution", "callable": "sortPeople", "parameters": [{"name": "names", "type": "String[]"}, {"name": "heights", "type": "Integer[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2419, "task_id": "longest-subarray-with-maximum-bitwise-and", "difficulty": "Medium", "problem_description": "You are given an integer array nums of size n.\n\nConsider a non-empty subarray from nums that has the maximum possible bitwise AND.\n\n- In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.\n\nReturn the length of the longest such subarray.\n\nThe bitwise AND of an array is the bitwise AND of all the numbers in it.\n\nA subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,3,2,2]\nOutput: 2\nExplanation:\nThe maximum possible bitwise AND of a subarray is 3.\nThe longest subarray with that value is [3,3], so we return 2.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation:\nThe maximum possible bitwise AND of a subarray is 4.\nThe longest subarray with that value is [4], so we return 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 = [8, 9, 10, 11, 12, 13, 14, 15, 16]) == 1\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953]) == 1\n assert candidate(nums = [8, 9, 10, 10, 10, 8]) == 3\n assert candidate(nums = [2, 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 1\n assert candidate(nums = [8, 1, 2, 3, 7, 8, 8]) == 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]) == 20\n assert candidate(nums = [8, 9, 7, 6, 8, 9, 9, 8]) == 2\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [1, 2, 3, 4]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [1000000, 1, 2, 3, 1000000, 1000000]) == 2\n assert candidate(nums = [3, 1, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [1, 2, 3, 3, 2, 2]) == 2\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995]) == 1\n assert candidate(nums = [2, 2, 2, 3, 3, 3, 2, 2, 2, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2]) == 6\n assert candidate(nums = [32, 32, 32, 32, 31, 30, 29, 28, 27, 26]) == 4\n assert candidate(nums = [2, 3, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8]) == 1\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 10, 10, 2, 10, 10, 10, 5, 5, 5, 5, 10, 10, 10, 10, 1, 1, 1, 1]) == 4\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]) == 30\n assert candidate(nums = [17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 19, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]) == 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]) == 1\n assert candidate(nums = [13, 13, 13, 14, 14, 14, 14, 13, 13, 14, 14, 14, 14, 14, 13, 13, 13, 14, 14, 14]) == 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, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 55\n assert candidate(nums = [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]) == 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, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 16\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == 22\n assert candidate(nums = [1000000, 1000000, 500000, 500000, 250000, 250000, 125000, 125000, 62500, 62500, 31250, 31250, 15625, 15625, 7812, 7812, 3906, 3906, 1953, 1953]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, 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, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1000000, 1000000, 1000000, 1000000]) == 4\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, 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]) == 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, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 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]) == 51\n assert candidate(nums = [128, 255, 255, 128, 255, 255, 255, 128, 128, 255, 255, 255, 255, 255, 128]) == 5\n assert candidate(nums = [5, 5, 6, 6, 6, 5, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 5, 5, 6, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6]) == 8\n assert candidate(nums = [999999, 999998, 999999, 999997, 999999, 999999, 999996, 999999, 999999, 999999]) == 3\n", "comparison": "exact"}, "public_tests": ["[1,2,3,3,2,2]", "[1,2,3,4]"], "hints": ["Notice that the bitwise AND of two different numbers will always be strictly less than the maximum of those two numbers.", "What does that tell us about the nature of the subarray that we should choose?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().longestSubarray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:04+00:00", "tests_total": 42, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "bit-manipulation", "brainteaser"]}, "language": "php", "interface": {"raw_signature": "function longestSubarray($nums) {", "container": "Solution", "callable": "longestSubarray", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2420, "task_id": "find-all-good-indices", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array nums of size n and a positive integer k.\n\nWe call an index i in the range k <= i < n - k good if the following conditions are satisfied:\n\n- The k elements that are just before the index i are in non-increasing order.\n- The k elements that are just after the index i are in non-decreasing order.\n\nReturn an array of all good indices sorted in increasing order.\n\nExample 1:\n\nInput: nums = [2,1,1,1,3,4,1], k = 2\nOutput: [2,3]\nExplanation: There are two good indices in the array:\n- Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.\n- Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.\nNote that the index 4 is not good because [4,1] is not non-decreasing.\n\nExample 2:\n\nInput: nums = [2,1,1,2], k = 2\nOutput: []\nExplanation: There are no good indices in this array.\n\nConstraints:\n\n- n == nums.length\n- 3 <= n <= 10^5\n- 1 <= nums[i] <= 10^6\n- 1 <= k <= n / 2\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5],k = 3) == [7, 8, 9]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1],k = 2) == []\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 5, 4, 3, 2, 1],k = 3) == []\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == []\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992],k = 3) == []\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5],k = 2) == [3, 4, 5]\n assert candidate(nums = [5, 4, 5, 3, 4, 5, 6, 7, 8],k = 2) == [2, 4]\n assert candidate(nums = [2, 1, 1, 2],k = 2) == []\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 3) == []\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1],k = 2) == []\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 3) == [7, 8, 9]\n assert candidate(nums = [5, 4, 3, 4, 5],k = 1) == [1, 2, 3]\n assert candidate(nums = [2, 1, 1, 1, 3, 4, 1],k = 2) == [2, 3]\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1],k = 3) == [4, 7, 15, 18]\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],k = 3) == [3, 4, 5, 6, 7, 8, 9]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == [7, 8, 9]\n assert candidate(nums = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1],k = 2) == []\n assert candidate(nums = [100, 99, 98, 97, 96, 97, 98, 99, 100, 101, 102, 103, 104, 103, 102, 101, 100],k = 4) == [4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3, 4, 5, 4, 3],k = 2) == [6, 10, 14]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5],k = 5) == [5]\n assert candidate(nums = [10, 20, 30, 20, 10, 20, 30, 20, 10, 20, 30, 20, 10, 20, 30, 20, 10, 20, 30],k = 4) == []\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == []\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == [7, 8, 9, 10]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == [5, 6, 7]\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 2, 1, 2, 3],k = 2) == [3, 7]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 1, 1, 20, 30, 40],k = 3) == [9, 10, 11, 12]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6],k = 3) == [4, 5, 6]\n assert candidate(nums = [10, 9, 8, 7, 7, 6, 5, 4, 4, 3, 2, 1],k = 3) == []\n assert candidate(nums = [1, 3, 2, 3, 2, 3, 2, 3, 2, 1],k = 2) == [3, 5]\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],k = 2) == [3, 4, 5, 6, 13, 14, 15, 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, 1],k = 5) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1],k = 2) == [5, 6, 10, 11, 15, 16]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 1) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]\n assert candidate(nums = [10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11],k = 2) == [3, 5, 7, 9, 11, 13]\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],k = 5) == [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 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, 2],k = 3) == []\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999997, 999998, 999999, 1000000],k = 3) == [3, 4, 5]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3],k = 3) == [7, 8, 9, 10]\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 = 5) == [14]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == [8, 9, 10, 11]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == [3, 4, 5, 6]\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],k = 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 = 5) == []\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],k = 3) == [6]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == [5, 6]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == []\n assert candidate(nums = [1, 3, 2, 3, 4, 5, 4, 3, 2, 1],k = 2) == [3]\n assert candidate(nums = [8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == []\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6],k = 3) == [8, 9, 10]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],k = 2) == [3, 5, 7, 9, 11]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1],k = 4) == []\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1],k = 4) == [5, 6, 7, 11, 12, 13, 14]\n assert candidate(nums = [5, 3, 2, 1, 1, 1, 2, 3, 4, 5],k = 2) == [2, 3, 4, 5, 6]\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2],k = 3) == []\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 3) == [3, 4, 5, 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],k = 3) == [3, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 18]\n assert candidate(nums = [5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7],k = 3) == [7, 8, 9, 15]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10],k = 2) == [3, 5, 7, 9, 11, 13, 15]\n assert candidate(nums = [1, 3, 2, 2, 2, 1, 3, 4, 3, 2, 1, 2, 3, 4, 5],k = 2) == [4, 5, 9, 10, 11]\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1],k = 2) == [3, 4, 5, 10]\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 4) == [4, 5, 6, 7, 8, 9]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 11, 12, 13, 14, 15],k = 5) == [8, 9]\n assert candidate(nums = [9, 8, 7, 6, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == [3, 4, 5]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4],k = 3) == [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],k = 5) == []\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],k = 4) == []\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1],k = 3) == []\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 4) == [4, 5, 6, 7]\n assert candidate(nums = [5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5],k = 2) == [5, 6, 7]\n assert candidate(nums = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == [9, 10, 11]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 5) == [7, 8, 9]\n assert candidate(nums = [5, 4, 4, 3, 2, 2, 3, 4, 5],k = 2) == [3, 4, 5, 6]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1],k = 3) == []\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 7) == [7, 8, 9]\n assert candidate(nums = [5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],k = 3) == [5, 6, 7]\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],k = 3) == [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 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],k = 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],k = 3) == []\n assert candidate(nums = [1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 2, 1],k = 2) == [5, 7, 11, 13]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 3) == [7, 8, 9, 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, 3, 2, 1],k = 5) == []\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],k = 5) == [10]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3],k = 2) == [4, 8, 12]\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2],k = 2) == [3, 4, 7, 8]\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5) == [8, 9, 10]\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5) == [6, 7, 8, 9, 10, 11, 12, 13, 14]\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) == []\n assert candidate(nums = [3, 2, 1, 1, 1, 2, 3, 4, 5, 6],k = 2) == [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],k = 5) == []\n assert candidate(nums = [1, 2, 3, 4, 3, 3, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1],k = 3) == [6, 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, 1],k = 2) == [4, 8, 12, 16]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == []\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9],k = 3) == [4, 5, 6]\n assert candidate(nums = [1, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5],k = 3) == [9, 10]\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) == []\n assert candidate(nums = [5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5],k = 2) == [2, 4, 6, 8, 10, 12, 14, 16]\n assert candidate(nums = [6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],k = 5) == [5]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 4) == [8, 9, 10]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 2) == [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n", "comparison": "exact"}, "public_tests": ["[2,1,1,1,3,4,1]\n2", "[2,1,1,2]\n2"], "hints": ["Iterate over all indices i. How do you quickly check the two conditions?", "Precompute for each index whether the conditions are satisfied on the left and the right of the index. You can do that with two iterations, from left to right and right to left."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().goodIndices", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:07+00:00", "tests_total": 101, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function goodIndices($nums, $k) {", "container": "Solution", "callable": "goodIndices", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2421, "task_id": "number-of-good-paths", "difficulty": "Hard", "problem_description": "There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\n\nYou are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node. You are also given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i.\n\nA good path is a simple path that satisfies the following conditions:\n\n1. The starting node and the ending node have the same value.\n2. All nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node's value should be the maximum value along the path).\n\nReturn the number of distinct good paths.\n\nNote that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.\n\nExample 1:\n\nInput: vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]]\nOutput: 6\nExplanation: There are 5 good paths consisting of a single node.\nThere is 1 additional good path: 1 -> 0 -> 2 -> 4.\n(The reverse path 4 -> 2 -> 0 -> 1 is treated as the same as 1 -> 0 -> 2 -> 4.)\nNote that 0 -> 2 -> 3 is not a good path because vals[2] > vals[0].\n\nExample 2:\n\nInput: vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]]\nOutput: 7\nExplanation: There are 5 good paths consisting of a single node.\nThere are 2 additional good paths: 0 -> 1 and 2 -> 3.\n\nExample 3:\n\nInput: vals = [1], edges = []\nOutput: 1\nExplanation: The tree consists of only one node, so there is one good path.\n\nConstraints:\n\n- n == vals.length\n- 1 <= n <= 3 * 10^4\n- 0 <= vals[i] <= 10^5\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(vals = [2, 2, 2, 2, 2],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 15\n assert candidate(vals = [1],edges = []) == 1\n assert candidate(vals = [1, 2, 3, 4, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 5\n assert candidate(vals = [1, 2, 2, 3, 3, 4, 4],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 10\n assert candidate(vals = [2, 2, 2, 2],edges = [[0, 1], [1, 2], [2, 3]]) == 10\n assert candidate(vals = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(vals = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(vals = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3]]) == 10\n assert candidate(vals = [1, 1, 2, 2, 3],edges = [[0, 1], [1, 2], [2, 3], [2, 4]]) == 7\n assert candidate(vals = [5, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 5\n assert candidate(vals = [1, 3, 2, 1, 3],edges = [[0, 1], [0, 2], [2, 3], [2, 4]]) == 6\n assert candidate(vals = [1, 3, 3, 3, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 8\n assert candidate(vals = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 12\n assert candidate(vals = [3, 1, 4, 4, 3],edges = [[0, 1], [1, 2], [2, 3], [2, 4]]) == 6\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 55\n assert candidate(vals = [1, 2, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [2, 4]]) == 5\n assert candidate(vals = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6],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]]) == 56\n assert candidate(vals = [1, 3, 2, 3, 1, 4, 2, 3, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [4, 7], [6, 8]]) == 13\n assert candidate(vals = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 24\n assert candidate(vals = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 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]]) == 20\n assert candidate(vals = [1, 2, 2, 3, 3, 3, 4],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 11\n assert candidate(vals = [2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 10]]) == 28\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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]]) == 15\n assert candidate(vals = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 15\n assert candidate(vals = [1, 3, 2, 3, 1, 3, 3, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7]]) == 14\n assert candidate(vals = [5, 5, 4, 4, 3, 3, 2, 2, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 15\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],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]]) == 120\n assert candidate(vals = [1, 2, 1, 2, 1, 2, 1, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 15\n assert candidate(vals = [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]]) == 37\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(vals = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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]]) == 15\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 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]]) == 20\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],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]]) == 19\n assert candidate(vals = [5, 4, 5, 3, 4, 5, 2, 1, 5, 5, 5],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == 26\n assert candidate(vals = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],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]]) == 91\n assert candidate(vals = [10, 5, 10, 10, 3, 5, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [3, 5], [4, 6]]) == 13\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == 66\n assert candidate(vals = [7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7],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]]) == 43\n assert candidate(vals = [5, 4, 3, 2, 1, 5, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [6, 8], [6, 9]]) == 11\n assert candidate(vals = [4, 2, 5, 3, 1, 6, 1, 2, 4, 5],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [0, 5], [5, 6], [5, 7], [7, 8], [7, 9]]) == 10\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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]]) == 16\n assert candidate(vals = [1, 2, 3, 4, 5, 4, 3, 2, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [3, 5], [5, 6], [6, 7], [7, 8]]) == 10\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8]]) == 45\n assert candidate(vals = [1, 3, 2, 3, 1, 3, 1, 3, 1, 3],edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == 23\n assert candidate(vals = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 55\n assert candidate(vals = [6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],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]]) == 19\n assert candidate(vals = [4, 2, 3, 4, 3, 4, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == 10\n assert candidate(vals = [4, 2, 3, 4, 4, 3, 2, 4],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]]) == 15\n assert candidate(vals = [1, 3, 1, 2, 3, 1, 1, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7]]) == 12\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 28\n assert candidate(vals = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9], [6, 10]]) == 32\n assert candidate(vals = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 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]]) == 23\n assert candidate(vals = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5],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]]) == 33\n assert candidate(vals = [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 16\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]]) == 210\n assert candidate(vals = [1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == 19\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29]]) == 465\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 36\n assert candidate(vals = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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], [10, 18], [11, 19]]) == 210\n assert candidate(vals = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9]]) == 55\n assert candidate(vals = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 10\n assert candidate(vals = [5, 3, 5, 3, 3, 5, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 13\n assert candidate(vals = [1, 2, 2, 1, 3, 3, 1, 1, 2, 2],edges = [[0, 1], [0, 3], [1, 2], [3, 4], [3, 7], [4, 5], [5, 6], [7, 8], [8, 9]]) == 20\n assert candidate(vals = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 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], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]]) == 73\n assert candidate(vals = [5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 36\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 10\n assert candidate(vals = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3],edges = [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [3, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == 31\n assert candidate(vals = [5, 3, 5, 5, 2, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8]]) == 30\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3, 3],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8]]) == 45\n assert candidate(vals = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 16\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 9\n assert candidate(vals = [3, 1, 2, 3, 1, 3, 2, 1, 3, 2, 1],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]]) == 19\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]]) == 210\n assert candidate(vals = [2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 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], [7, 15], [7, 16], [8, 17], [8, 18], [9, 19]]) == 49\n assert candidate(vals = [3, 1, 2, 3, 3, 2, 3],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 14\n assert candidate(vals = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [7, 8], [7, 9], [9, 10], [9, 11], [11, 12], [11, 13], [13, 14], [13, 15], [15, 16], [15, 17], [17, 18], [17, 19], [19, 20]]) == 21\n assert candidate(vals = [5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == 45\n assert candidate(vals = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]) == 210\n assert candidate(vals = [4, 3, 3, 4, 4, 4, 3, 4],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]]) == 19\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 10\n", "comparison": "exact"}, "public_tests": ["[1,3,2,1,3]\n[[0,1],[0,2],[2,3],[2,4]]", "[1,1,2,2,3]\n[[0,1],[1,2],[2,3],[2,4]]", "[1]\n[]"], "hints": ["Can you process nodes from smallest to largest value?", "Try to build the graph from nodes with the smallest value to the largest value.", "May union find help?"], "metadata": {"canonical_parameter_names": ["vals", "edges"], "leetcode_dataset_entry_point": "Solution().numberOfGoodPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:10+00:00", "tests_total": 82, "tests_dropped": 2, "flags": ["has_images"], "topic_tags": ["array", "hash-table", "tree", "union-find", "graph", "sorting"]}, "language": "php", "interface": {"raw_signature": "function numberOfGoodPaths($vals, $edges) {", "container": "Solution", "callable": "numberOfGoodPaths", "parameters": [{"name": "vals", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2423, "task_id": "remove-letter-to-equalize-frequency", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.\n\nReturn true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.\n\nNote:\n\n- The frequency of a letter x is the number of times it occurs in the string.\n- You must remove exactly one letter and cannot choose to do nothing.\n\nExample 1:\n\nInput: word = \"abcc\"\nOutput: true\nExplanation: Select index 3 and delete it: word becomes \"abc\" and each character has a frequency of 1.\n\nExample 2:\n\nInput: word = \"aazz\"\nOutput: false\nExplanation: We must delete a character, so either the frequency of \"a\" is 1 and the frequency of \"z\" is 2, or vice versa. It is impossible to make all present letters have equal frequency.\n\nConstraints:\n\n- 2 <= word.length <= 100\n- word consists of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(word = \"aabbccd\") == True\n assert candidate(word = \"aaabbbccc\") == False\n assert candidate(word = \"zazaza\") == False\n assert candidate(word = \"aaaaabbbbbcccc\") == False\n assert candidate(word = \"zzzzzzzz\") == True\n assert candidate(word = \"aabbccddeff\") == True\n assert candidate(word = \"aabbbbcccc\") == False\n assert candidate(word = \"aazz\") == False\n assert candidate(word = \"aabbbccccc\") == False\n assert candidate(word = \"aaa\") == True\n assert candidate(word = \"aabbbccddd\") == False\n assert candidate(word = \"abcdef\") == True\n assert candidate(word = \"aabbcccddd\") == False\n assert candidate(word = \"aabbc\") == True\n assert candidate(word = \"aabbccddeee\") == True\n assert candidate(word = \"abacabad\") == False\n assert candidate(word = \"abcdabcd\") == False\n assert candidate(word = \"aabbbccc\") == False\n assert candidate(word = \"aabbccdde\") == True\n assert candidate(word = \"aabbbcccc\") == False\n assert candidate(word = \"aabbbcccccc\") == False\n assert candidate(word = \"zzzz\") == True\n assert candidate(word = \"abcc\") == True\n assert candidate(word = \"xyyz\") == True\n assert candidate(word = \"aab\") == True\n assert candidate(word = \"aabbcc\") == False\n assert candidate(word = \"abcde\") == True\n assert candidate(word = \"aaabbbb\") == True\n assert candidate(word = \"aabbbb\") == False\n assert candidate(word = \"abcd\") == True\n assert candidate(word = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == False\n assert candidate(word = \"abbbccddde\") == False\n assert candidate(word = \"abcabcabc\") == False\n assert candidate(word = \"qwerty\") == True\n assert candidate(word = \"aabbbcccd\") == False\n assert candidate(word = \"aabbccddd\") == True\n assert candidate(word = \"abc\") == True\n assert candidate(word = \"abcddd\") == False\n assert candidate(word = \"abcdefghijklmnopqrstuvwxzy\") == True\n assert candidate(word = \"aaaabbbb\") == False\n assert candidate(word = \"aabbccc\") == True\n assert candidate(word = \"abcdabcdabcd\") == False\n assert candidate(word = \"abcdefghi\") == True\n assert candidate(word = \"aabbcccd\") == False\n assert candidate(word = \"abcdefghijj\") == True\n assert candidate(word = \"aabbbcccdddde\") == False\n assert candidate(word = \"aabbcccc\") == False\n assert candidate(word = \"aabbccddeeefffg\") == False\n assert candidate(word = \"aabbccddeeeffffgggg\") == False\n assert candidate(word = \"aabbbccccddddeeeeeffffffggggg\") == False\n assert candidate(word = \"aabbccddeeffg\") == True\n assert candidate(word = \"zzzzzzzzzz\") == True\n assert candidate(word = \"aabbbccccdddde\") == False\n assert candidate(word = \"aabbccddeeffgg\") == False\n assert candidate(word = \"abcdefghij\") == True\n assert candidate(word = \"aabbccddeeffgggh\") == False\n assert candidate(word = \"aabbccddeeff\") == False\n assert candidate(word = \"abcabcabcabcabcabcabcabc\") == False\n assert candidate(word = \"zzzzzyyyyy\") == False\n assert candidate(word = \"aaaabbbbccccdddd\") == False\n assert candidate(word = \"aabbbccccdddd\") == False\n assert candidate(word = \"aabbbcccddd\") == False\n assert candidate(word = \"abcdefg\") == True\n assert candidate(word = \"aabbbccccddddeeeeeffffff\") == False\n assert candidate(word = \"abcdefghijjk\") == True\n assert candidate(word = \"aabbbcccde\") == False\n assert candidate(word = \"abbbbcccccdddddeeeeee\") == False\n assert candidate(word = \"aabbccddeeeffff\") == False\n assert candidate(word = \"aabbbccccddddeeeee\") == False\n assert candidate(word = \"aabbccddeeffggghhhh\") == False\n assert candidate(word = \"abcabcabcabc\") == False\n assert candidate(word = \"aabbbcccdddd\") == False\n assert candidate(word = \"aabbcddd\") == False\n", "comparison": "exact"}, "public_tests": ["\"abcc\"", "\"aazz\""], "hints": ["Brute force all letters that could be removed.", "Use a frequency array of size 26."], "metadata": {"canonical_parameter_names": ["word"], "leetcode_dataset_entry_point": "Solution().equalFrequency", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:14+00:00", "tests_total": 74, "tests_dropped": 1, "flags": [], "topic_tags": ["hash-table", "string", "counting"]}, "language": "php", "interface": {"raw_signature": "function equalFrequency($word) {", "container": "Solution", "callable": "equalFrequency", "parameters": [{"name": "word", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2425, "task_id": "bitwise-xor-of-all-pairings", "difficulty": "Medium", "problem_description": "You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. Let there be another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once).\n\nReturn the bitwise XOR of all integers in nums3.\n\nExample 1:\n\nInput: nums1 = [2,1,3], nums2 = [10,2,5,0]\nOutput: 13\nExplanation:\nA possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].\nThe bitwise XOR of all these numbers is 13, so we return 13.\n\nExample 2:\n\nInput: nums1 = [1,2], nums2 = [3,4]\nOutput: 0\nExplanation:\nAll possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],\nand nums1[1] ^ nums2[1].\nThus, one possible nums3 array is [2,5,1,6].\n2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.\n\nConstraints:\n\n- 1 <= nums1.length, nums2.length <= 10^5\n- 0 <= nums1[i], nums2[j] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [8, 16, 24, 32],nums2 = [4, 8, 12, 16, 20]) == 32\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1]) == 11\n assert candidate(nums1 = [2, 1, 3],nums2 = [10, 2, 5, 0]) == 13\n assert candidate(nums1 = [7, 8, 9],nums2 = [10, 11, 12, 13]) == 0\n assert candidate(nums1 = [14, 15, 16],nums2 = [17, 18]) == 3\n assert candidate(nums1 = [5],nums2 = [5]) == 0\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 0\n assert candidate(nums1 = [1, 1, 1],nums2 = [1, 1, 1]) == 0\n assert candidate(nums1 = [1, 3, 5, 7],nums2 = [2, 4, 6, 8]) == 0\n assert candidate(nums1 = [1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 11\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 0\n assert candidate(nums1 = [1000000000],nums2 = [1000000000]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [9, 8, 7, 6],nums2 = [5, 4, 3, 2, 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]) == 0\n assert candidate(nums1 = [9, 8, 7],nums2 = [6, 5, 4, 3, 2, 1]) == 7\n assert candidate(nums1 = [1, 2],nums2 = [3, 4]) == 0\n assert candidate(nums1 = [1],nums2 = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [1, 2, 3],nums2 = [6, 5, 4, 3, 2, 1]) == 7\n assert candidate(nums1 = [0, 0, 0],nums2 = [0, 0, 0]) == 0\n assert candidate(nums1 = [5],nums2 = [5, 5, 5, 5, 5]) == 0\n assert candidate(nums1 = [7, 14, 21],nums2 = [3, 6, 9, 12]) == 0\n assert candidate(nums1 = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],nums2 = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]) == 0\n assert candidate(nums1 = [13, 29, 37, 41, 53],nums2 = [67, 71, 73, 79, 83, 89, 97, 101]) == 12\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]) == 0\n assert candidate(nums1 = [7, 11, 13, 14],nums2 = [18, 19, 20, 21, 22]) == 15\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums1 = [1023, 511, 255, 127, 63, 31, 15, 7, 3, 1],nums2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 682\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == 0\n assert candidate(nums1 = [15, 30, 45, 60, 75],nums2 = [1, 3, 5, 7, 9, 11, 13]) == 68\n assert candidate(nums1 = [255, 127, 63, 31],nums2 = [1, 2, 4, 8, 16, 32]) == 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]) == 0\n assert candidate(nums1 = [7, 8, 9, 10],nums2 = [11, 12, 13, 14, 15]) == 12\n assert candidate(nums1 = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195],nums2 = [199, 299, 399, 499, 599, 699]) == 380\n assert candidate(nums1 = [1000000000],nums2 = [1000000000, 1000000000, 1000000000, 1000000000]) == 0\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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 31\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],nums2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 0\n assert candidate(nums1 = [7, 8, 9, 10],nums2 = [3, 1, 4, 1, 5, 9]) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [1, 3, 5, 7, 9]) == 1\n assert candidate(nums1 = [100, 200, 300],nums2 = [101, 202, 303, 404]) == 20\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [1, 2, 3, 4, 5]) == 1\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 0\n assert candidate(nums1 = [1000000000],nums2 = [500000000, 600000000, 700000000, 800000000, 900000000]) == 908472064\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]) == 0\n assert candidate(nums1 = [100, 200, 300],nums2 = [101, 202, 303, 404, 505]) == 109\n assert candidate(nums1 = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90],nums2 = [96, 102, 108, 114, 120, 126]) == 30\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]) == 0\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],nums2 = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]) == 0\n assert candidate(nums1 = [255, 254, 253, 252, 251],nums2 = [127, 63, 31, 15, 7]) == 172\n assert candidate(nums1 = [0, 255, 511, 1023, 2047],nums2 = [1, 128, 256, 512, 1024]) == 641\n assert candidate(nums1 = [1, 1000000000],nums2 = [1, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000001\n assert candidate(nums1 = [7, 15, 21],nums2 = [9, 3, 12, 8]) == 14\n assert candidate(nums1 = [255, 128, 64, 32, 16],nums2 = [1, 2, 4, 8, 16, 32]) == 63\n assert candidate(nums1 = [999999999, 888888888, 777777777],nums2 = [666666666, 555555555, 444444444, 333333333, 222222222]) == 587645496\n assert candidate(nums1 = [123456789, 987654321, 456789123],nums2 = [321654987, 789123456, 654987321, 123456789]) == 477404263\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]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024],nums2 = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2046\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13],nums2 = [2, 4, 6, 8, 10, 12, 14, 16]) == 16\n assert candidate(nums1 = [13, 17, 19, 23, 29, 31],nums2 = [37, 41, 43, 47, 53, 59, 61, 67, 71]) == 26\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]) == 0\n assert candidate(nums1 = [1000000000],nums2 = [1000000000, 1000000000]) == 0\n assert candidate(nums1 = [13, 29, 31, 47, 53, 59, 61, 67, 71, 73],nums2 = [79, 83, 89, 97, 101, 103, 107, 109, 113, 127]) == 0\n assert candidate(nums1 = [255, 128, 64, 32, 16, 8, 4, 2, 1],nums2 = [1, 3, 7, 15, 31, 63, 127, 255]) == 170\n assert candidate(nums1 = [255, 511, 765, 1023, 1279],nums2 = [15, 31, 47, 63, 79]) == 1202\n assert candidate(nums1 = [255, 128, 64, 32, 16, 8, 4, 2, 1],nums2 = [1, 3, 5, 7, 9, 11, 13, 15, 17]) == 17\n assert candidate(nums1 = [7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums1 = [999999999, 888888888, 777777777, 666666666],nums2 = [555555555, 444444444, 333333333, 222222222]) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10]) == 11\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [666],nums2 = [666, 666, 666, 666, 666, 666]) == 0\n assert candidate(nums1 = [1],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [500, 400, 300, 200, 100]) == 0\n assert candidate(nums1 = [1024, 2048, 4096, 8192, 16384],nums2 = [1, 2, 4, 8, 16]) == 31775\n assert candidate(nums1 = [7, 11, 13, 17, 19],nums2 = [3, 6, 9, 12, 15]) == 12\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],nums2 = [1024, 2048, 4096, 8192, 16384]) == 1023\n assert candidate(nums1 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],nums2 = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683]) == 0\n assert candidate(nums1 = [100, 200, 300, 400],nums2 = [50, 60, 70]) == 16\n assert candidate(nums1 = [255, 128, 64, 32],nums2 = [16, 8, 4, 2, 1]) == 31\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0]) == 0\n assert candidate(nums1 = [111, 222, 333, 444, 555, 666, 777, 888, 999],nums2 = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 707\n assert candidate(nums1 = [123456789, 987654321, 111111111, 222222222],nums2 = [333333333, 444444444, 555555555]) == 908335597\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6],nums2 = [7, 8, 9, 10, 11, 12, 13]) == 1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 3\n assert candidate(nums1 = [1000000, 2000000, 3000000, 4000000],nums2 = [500000, 600000, 700000]) == 67840\n assert candidate(nums1 = [100, 200, 300],nums2 = [50, 150, 250, 350, 450]) == 322\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11],nums2 = [2, 4, 6, 8, 10]) == 2\n assert candidate(nums1 = [13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113],nums2 = [11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111]) == 42\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [13, 14, 15, 16, 17, 18, 19, 20],nums2 = [21, 22, 23, 24, 25, 26, 27, 28]) == 0\n assert candidate(nums1 = [15, 23, 42, 8, 16],nums2 = [32, 19, 10, 7, 11]) == 31\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10, 12, 14]) == 9\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [1024, 512, 256, 128],nums2 = [64, 32, 16, 8, 4, 2, 1]) == 1920\n", "comparison": "exact"}, "public_tests": ["[2,1,3]\n[10,2,5,0]", "[1,2]\n[3,4]"], "hints": ["Think how the count of each individual integer affects the final answer.", "If the length of nums1 is m and the length of nums2 is n, then each number in nums1 is repeated n times and each number in nums2 is repeated m times."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().xorAllNums", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:17+00:00", "tests_total": 102, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "bit-manipulation", "brainteaser"]}, "language": "php", "interface": {"raw_signature": "function xorAllNums($nums1, $nums2) {", "container": "Solution", "callable": "xorAllNums", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2426, "task_id": "number-of-pairs-satisfying-inequality", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:\n\n- 0 <= i < j <= n - 1 and\n- nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.\n\nReturn the number of pairs that satisfy the conditions.\n\nExample 1:\n\nInput: nums1 = [3,2,5], nums2 = [2,2,1], diff = 1\nOutput: 3\nExplanation:\nThere are 3 pairs that satisfy the conditions:\n1. i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.\n2. i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.\n3. i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.\nTherefore, we return 3.\n\nExample 2:\n\nInput: nums1 = [3,-1], nums2 = [-2,2], diff = -1\nOutput: 0\nExplanation:\nSince there does not exist any pair that satisfies the conditions, we return 0.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 2 <= n <= 10^5\n- -10^4 <= nums1[i], nums2[i] <= 10^4\n- -10^4 <= diff <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [3, -1],nums2 = [-2, 2],diff = -1) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1],diff = 0) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],diff = 50) == 10\n assert candidate(nums1 = [-10, -20, -30, -40, -50],nums2 = [-1, -2, -3, -4, -5],diff = -10) == 0\n assert candidate(nums1 = [-10, -20, -30],nums2 = [-1, -2, -3],diff = -5) == 0\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0],diff = 10) == 6\n assert candidate(nums1 = [-1, -2, -3, -4, -5],nums2 = [-5, -4, -3, -2, -1],diff = -10) == 0\n assert candidate(nums1 = [9, 7, 5, 3, 1],nums2 = [10, 8, 6, 4, 2],diff = -1) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9],nums2 = [2, 4, 6, 8, 10],diff = 1) == 10\n assert candidate(nums1 = [10, 20, 30, 40, 50],nums2 = [1, 2, 3, 4, 5],diff = 10) == 10\n assert candidate(nums1 = [10, 20, 30],nums2 = [1, 2, 3],diff = 5) == 3\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [0, 0, 0, 0, 0],diff = 0) == 10\n assert candidate(nums1 = [3, 2, 5],nums2 = [2, 2, 1],diff = 1) == 3\n assert candidate(nums1 = [0, 0, 0, 0],nums2 = [0, 0, 0, 0],diff = 10000) == 6\n assert candidate(nums1 = [10000, -10000, 5000, -5000, 0],nums2 = [-10000, 10000, -5000, 5000, 0],diff = 0) == 4\n assert candidate(nums1 = [10000, -5000, 3000, -1000, 2000],nums2 = [5000, -2500, 1500, -500, 1000],diff = 2000) == 6\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],diff = -1) == 45\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],diff = 5) == 45\n assert candidate(nums1 = [10000, 10000, 10000, 10000, 10000],nums2 = [1, 2, 3, 4, 5],diff = 10000) == 10\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1],diff = 0) == 10\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],diff = -100) == 45\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],diff = -1) == 0\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [50, 150, 250, 350, 450],diff = 0) == 10\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],diff = 1) == 45\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [0, 0, 0, 0, 0],diff = 0) == 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],diff = 10000) == 45\n assert candidate(nums1 = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],nums2 = [-100, -200, -300, -400, -500, -600, -700, -800, -900, -1000],diff = 500) == 45\n assert candidate(nums1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],diff = 1) == 55\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 = [39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1],diff = 10) == 190\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],diff = 1000) == 45\n assert candidate(nums1 = [-500, -1000, -1500, -2000, -2500, -3000],nums2 = [500, 1000, 1500, 2000, 2500, 3000],diff = -1000) == 0\n assert candidate(nums1 = [-9999, -8888, -7777, -6666, -5555],nums2 = [-10000, -8889, -7778, -6667, -5556],diff = 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],diff = 0) == 45\n assert candidate(nums1 = [10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],diff = 10) == 45\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],diff = 100) == 45\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],diff = 20) == 17\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],diff = -1000) == 0\n assert candidate(nums1 = [5000, 5000, 5000, 5000, 5000],nums2 = [-5000, -5000, -5000, -5000, -5000],diff = 10000) == 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 = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],diff = 1) == 190\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],diff = -2) == 0\n assert candidate(nums1 = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],nums2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],diff = 0) == 20\n assert candidate(nums1 = [500, 400, 300, 200, 100, 0, -100, -200, -300, -400],nums2 = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],diff = 500) == 45\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],diff = 0) == 45\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],diff = 0) == 45\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],diff = 100) == 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],diff = 500) == 45\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],diff = -15) == 0\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],diff = 100) == 45\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],diff = 10) == 45\n assert candidate(nums1 = [5, 15, 25, 35, 45, 55],nums2 = [0, 10, 20, 30, 40, 50],diff = 5) == 15\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],diff = 100) == 45\n assert candidate(nums1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],nums2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],diff = 0) == 0\n assert candidate(nums1 = [0, -10, -20, -30, -40],nums2 = [0, 10, 20, 30, 40],diff = 10) == 0\n assert candidate(nums1 = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000],nums2 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],diff = -1000) == 0\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],diff = 1) == 30\n assert candidate(nums1 = [100, -50, 25, -25, 75, -100],nums2 = [0, 10, 20, -10, 30, -20],diff = 50) == 7\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],diff = 0) == 45\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],diff = 1) == 45\n assert candidate(nums1 = [-5, -10, -15, -20, -25],nums2 = [5, 10, 15, 20, 25],diff = 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],diff = 5) == 45\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],diff = 0) == 45\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [10, 20, 30, 40, 50],diff = 50) == 10\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],diff = -4) == 45\n assert candidate(nums1 = [0, 0, 0, 0, 0],nums2 = [1, -1, 2, -2, 3],diff = 3) == 8\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],diff = 25) == 45\n assert candidate(nums1 = [10000, -10000, 10000, -10000, 10000],nums2 = [0, 0, 0, 0, 0],diff = 0) == 7\n assert candidate(nums1 = [0, -1, 1, -2, 2, -3, 3, -4, 4, -5],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],diff = 0) == 20\n assert candidate(nums1 = [5000, -5000, 3000, -3000, 1000],nums2 = [1, -1, 2, -2, 3],diff = 10000) == 10\n assert candidate(nums1 = [-5000, 5000, -2500, 2500, 0],nums2 = [5000, -5000, 2500, -2500, 0],diff = 0) == 6\n assert candidate(nums1 = [10000, -10000, 10000, -10000, 10000],nums2 = [-10000, 10000, -10000, 10000, -10000],diff = 0) == 7\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],diff = -50) == 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, 10],diff = -2) == 0\n assert candidate(nums1 = [1, 3, 5, 7, 9, 11, 13, 15],nums2 = [0, 2, 4, 6, 8, 10, 12, 14],diff = 0) == 28\n assert candidate(nums1 = [1, -1, 2, -2, 3, -3, 4, -4],nums2 = [0, 0, 0, 0, 0, 0, 0, 0],diff = 0) == 12\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],diff = 999) == 45\n assert candidate(nums1 = [5000, 4000, 3000, 2000, 1000, 0, -1000, -2000, -3000, -4000, -5000],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],diff = 2000) == 19\n assert candidate(nums1 = [1, -1, 1, -1, 1],nums2 = [-1, 1, -1, 1, -1],diff = 2) == 7\n assert candidate(nums1 = [100, 200, 300, 400, 500],nums2 = [1, 1, 1, 1, 1],diff = 99) == 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],diff = 10) == 35\n assert candidate(nums1 = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],nums2 = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],diff = 0) == 35\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],diff = 0) == 190\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],diff = -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],diff = 1) == 45\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],diff = 0) == 45\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],diff = 1) == 45\n assert candidate(nums1 = [-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000],nums2 = [10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000],diff = 0) == 35\n assert candidate(nums1 = [5, 3, 8, 6, 2],nums2 = [1, 4, 3, 2, 5],diff = 1) == 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],diff = -5) == 0\n assert candidate(nums1 = [-10000, -9999, -9998, -9997, -9996, -9995, -9994, -9993, -9992, -9991],nums2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],diff = -10) == 0\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],diff = -5) == 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],diff = 10) == 105\n", "comparison": "exact"}, "public_tests": ["[3,2,5]\n[2,2,1]\n1", "[3,-1]\n[-2,2]\n-1"], "hints": ["Try rearranging the equation.", "Once the equation is rearranged properly, think how a segment tree or a Fenwick tree can be used to solve the rearranged equation.", "Iterate through the array backwards."], "metadata": {"canonical_parameter_names": ["nums1", "nums2", "diff"], "leetcode_dataset_entry_point": "Solution().numberOfPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:20+00:00", "tests_total": 99, "tests_dropped": 8, "flags": [], "topic_tags": ["array", "binary-search", "divide-and-conquer", "binary-indexed-tree", "segment-tree", "merge-sort", "ordered-set"]}, "language": "php", "interface": {"raw_signature": "function numberOfPairs($nums1, $nums2, $diff) {", "container": "Solution", "callable": "numberOfPairs", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}, {"name": "diff", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2427, "task_id": "number-of-common-factors", "difficulty": "Easy", "problem_description": "Given two positive integers a and b, return the number of common factors of a and b.\n\nAn integer x is a common factor of a and b if x divides both a and b.\n\nExample 1:\n\nInput: a = 12, b = 6\nOutput: 4\nExplanation: The common factors of 12 and 6 are 1, 2, 3, 6.\n\nExample 2:\n\nInput: a = 25, b = 30\nOutput: 2\nExplanation: The common factors of 25 and 30 are 1, 5.\n\nConstraints:\n\n- 1 <= a, b <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(a = 7,b = 13) == 1\n assert candidate(a = 500,b = 500) == 12\n assert candidate(a = 42,b = 56) == 4\n assert candidate(a = 999,b = 1000) == 1\n assert candidate(a = 77,b = 14) == 2\n assert candidate(a = 98,b = 42) == 4\n assert candidate(a = 77,b = 143) == 2\n assert candidate(a = 12,b = 6) == 4\n assert candidate(a = 500,b = 250) == 8\n assert candidate(a = 25,b = 30) == 2\n assert candidate(a = 500,b = 200) == 9\n assert candidate(a = 100,b = 10) == 4\n assert candidate(a = 1,b = 1) == 1\n assert candidate(a = 60,b = 120) == 12\n assert candidate(a = 7,b = 14) == 2\n assert candidate(a = 49,b = 7) == 2\n assert candidate(a = 1000,b = 1000) == 16\n assert candidate(a = 81,b = 27) == 4\n assert candidate(a = 999,b = 333) == 6\n assert candidate(a = 2,b = 3) == 1\n assert candidate(a = 987,b = 651) == 4\n assert candidate(a = 315,b = 105) == 8\n assert candidate(a = 600,b = 400) == 12\n assert candidate(a = 675,b = 900) == 9\n assert candidate(a = 675,b = 375) == 6\n assert candidate(a = 777,b = 111) == 4\n assert candidate(a = 789,b = 321) == 2\n assert candidate(a = 456,b = 123) == 2\n assert candidate(a = 360,b = 180) == 18\n assert candidate(a = 221,b = 143) == 2\n assert candidate(a = 840,b = 420) == 24\n assert candidate(a = 495,b = 135) == 6\n assert candidate(a = 999,b = 111) == 4\n assert candidate(a = 999,b = 891) == 4\n assert candidate(a = 543,b = 234) == 2\n assert candidate(a = 960,b = 720) == 20\n assert candidate(a = 777,b = 222) == 4\n assert candidate(a = 500,b = 1000) == 12\n assert candidate(a = 987,b = 654) == 2\n assert candidate(a = 450,b = 150) == 12\n assert candidate(a = 560,b = 315) == 4\n assert candidate(a = 420,b = 560) == 12\n assert candidate(a = 432,b = 504) == 12\n assert candidate(a = 100,b = 150) == 6\n assert candidate(a = 420,b = 168) == 12\n assert candidate(a = 729,b = 243) == 6\n assert candidate(a = 400,b = 500) == 9\n assert candidate(a = 504,b = 252) == 18\n assert candidate(a = 500,b = 100) == 9\n assert candidate(a = 495,b = 363) == 4\n assert candidate(a = 84,b = 105) == 4\n assert candidate(a = 315,b = 135) == 6\n assert candidate(a = 48,b = 180) == 6\n assert candidate(a = 333,b = 111) == 4\n assert candidate(a = 121,b = 220) == 2\n assert candidate(a = 560,b = 240) == 10\n assert candidate(a = 143,b = 169) == 2\n assert candidate(a = 440,b = 88) == 8\n assert candidate(a = 441,b = 147) == 6\n assert candidate(a = 675,b = 225) == 9\n assert candidate(a = 560,b = 840) == 16\n assert candidate(a = 729,b = 81) == 5\n assert candidate(a = 500,b = 400) == 9\n assert candidate(a = 210,b = 140) == 8\n assert candidate(a = 576,b = 288) == 18\n assert candidate(a = 777,b = 555) == 4\n assert candidate(a = 220,b = 88) == 6\n assert candidate(a = 720,b = 540) == 18\n assert candidate(a = 882,b = 147) == 6\n assert candidate(a = 210,b = 420) == 16\n assert candidate(a = 987,b = 329) == 4\n assert candidate(a = 882,b = 630) == 12\n assert candidate(a = 890,b = 345) == 2\n assert candidate(a = 462,b = 231) == 8\n assert candidate(a = 84,b = 28) == 6\n assert candidate(a = 450,b = 180) == 12\n assert candidate(a = 504,b = 168) == 16\n assert candidate(a = 100,b = 200) == 9\n assert candidate(a = 400,b = 160) == 10\n assert candidate(a = 1000,b = 750) == 8\n assert candidate(a = 840,b = 700) == 12\n assert candidate(a = 456,b = 342) == 8\n assert candidate(a = 650,b = 260) == 8\n assert candidate(a = 101,b = 103) == 1\n assert candidate(a = 128,b = 256) == 8\n assert candidate(a = 987,b = 323) == 1\n assert candidate(a = 729,b = 486) == 6\n assert candidate(a = 987,b = 567) == 4\n assert candidate(a = 600,b = 750) == 12\n assert candidate(a = 987,b = 399) == 4\n assert candidate(a = 360,b = 720) == 24\n assert candidate(a = 882,b = 98) == 6\n assert candidate(a = 612,b = 468) == 9\n assert candidate(a = 360,b = 240) == 16\n assert candidate(a = 900,b = 450) == 18\n assert candidate(a = 960,b = 480) == 24\n assert candidate(a = 504,b = 756) == 18\n assert candidate(a = 1000,b = 900) == 9\n assert candidate(a = 678,b = 456) == 4\n", "comparison": "exact"}, "public_tests": ["12\n6", "25\n30"], "hints": ["For each integer in range [1,1000], check if it’s divisible by both A and B."], "metadata": {"canonical_parameter_names": ["a", "b"], "leetcode_dataset_entry_point": "Solution().commonFactors", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:22+00:00", "tests_total": 107, "tests_dropped": 8, "flags": [], "topic_tags": ["math", "enumeration", "number-theory", "euclidean-algorithm", "greatest-common-divisor"]}, "language": "php", "interface": {"raw_signature": "function commonFactors($a, $b) {", "container": "Solution", "callable": "commonFactors", "parameters": [{"name": "a", "type": "Integer"}, {"name": "b", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2428, "task_id": "maximum-sum-of-an-hourglass", "difficulty": "Medium", "problem_description": "You are given an m x n integer matrix grid.\n\nWe define an hourglass as a part of the matrix with the following form:\n\nReturn the maximum sum of the elements of an hourglass.\n\nNote that an hourglass cannot be rotated and must be entirely contained within the matrix.\n\nExample 1:\n\nInput: grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]\nOutput: 30\nExplanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.\n\nExample 2:\n\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: 35\nExplanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 3 <= m, n <= 150\n- 0 <= grid[i][j] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\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]]) == 133\n assert candidate(grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]) == 1\n assert candidate(grid = [[1000000, 1000000, 1000000], [1000000, 1000000, 1000000], [1000000, 1000000, 1000000]]) == 7000000\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]]) == 7\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == 7\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 35\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0\n assert candidate(grid = [[6, 2, 1, 3], [4, 2, 1, 5], [9, 2, 8, 7], [4, 1, 2, 9]]) == 30\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, 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]]) == 3\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]]) == 5\n assert candidate(grid = [[100, 200, 300], [400, 500, 600], [700, 800, 900], [1000, 1100, 1200], [1300, 1400, 1500]]) == 7700\n assert candidate(grid = [[9, 8, 7, 6, 5, 4], [3, 2, 1, 0, 1, 2], [4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7]]) == 47\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 1], [1, 2, 3, 3, 2, 1], [1, 2, 3, 4, 3, 1], [1, 2, 3, 3, 2, 1], [1, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1]]) == 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]]) == 203\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]]) == 35\n assert candidate(grid = [[1000000, 0, 1000000, 0, 1000000], [0, 0, 0, 0, 0], [1000000, 0, 1000000, 0, 1000000], [0, 0, 0, 0, 0], [1000000, 0, 1000000, 0, 1000000]]) == 4000000\n assert candidate(grid = [[1000000, 999999, 999998, 999997, 999996], [999995, 999994, 999993, 999992, 999991], [999990, 999989, 999988, 999987, 999986], [999985, 999984, 999983, 999982, 999981], [999980, 999979, 999978, 999977, 999976]]) == 6999958\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]]) == 35\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]) == 63\n assert candidate(grid = [[999999, 999998, 999997], [999996, 999995, 999994], [999993, 999992, 999991], [999990, 999989, 999988], [999987, 999986, 999985], [999984, 999983, 999982]]) == 6999965\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, 7, 5, 3, 1], [2, 4, 6, 8, 10, 8, 6, 4, 2], [1, 5, 9, 13, 17, 13, 9, 5, 1], [2, 6, 10, 14, 18, 14, 10, 6, 2]]) == 89\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]]) == 203\n assert candidate(grid = [[9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9, 9]]) == 63\n assert candidate(grid = [[9, 8, 7, 6], [6, 5, 4, 3], [3, 2, 1, 0], [0, 1, 2, 3]]) == 35\n assert candidate(grid = [[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, 32, 33, 34], [35, 36, 37, 38, 39, 40, 41], [42, 43, 44, 45, 46, 47, 48]]) == 280\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]]) == 5\n assert candidate(grid = [[0, 1, 0, 2, 0, 3, 0, 4, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 2, 0, 3, 0, 4, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 2, 0, 3, 0, 4, 0]]) == 15\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]]) == 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]]) == 168\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]]) == 119\n assert candidate(grid = [[1, 5, 1, 3, 7], [4, 3, 2, 6, 8], [9, 5, 6, 1, 2], [7, 8, 9, 4, 5], [3, 4, 2, 7, 1]]) == 38\n assert candidate(grid = [[1, 3, 1, 1, 1, 3, 1], [1, 9, 1, 1, 1, 9, 1], [1, 3, 1, 1, 1, 3, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 3, 1, 1, 1, 3, 1]]) == 19\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]]) == 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, 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(grid = [[1, 5, 0, 2, 1], [6, 9, 2, 4, 3], [5, 6, 8, 1, 1], [2, 3, 4, 7, 9], [1, 2, 3, 4, 5]]) == 37\n assert candidate(grid = [[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]]) == 105\n assert candidate(grid = [[1000000, 1000000, 1000000, 1000000, 1000000], [1000000, 0, 0, 0, 1000000], [1000000, 0, 1000000, 0, 1000000], [1000000, 0, 0, 0, 1000000], [1000000, 1000000, 1000000, 1000000, 1000000]]) == 5000000\n assert candidate(grid = [[9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9, 9, 9, 9, 9]]) == 63\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]]) == 35\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 150], [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, 128, 129, 130, 131, 132, 133, 134, 135], [136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150]]) == 938\n assert candidate(grid = [[1, 0, 0, 1, 1], [0, 1, 1, 0, 0], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 0, 1, 1]]) == 4\n assert candidate(grid = [[1000000, 999999, 999998, 999997, 999996], [999995, 999994, 999993, 999992, 999991], [999990, 999989, 999988, 999987, 999986], [999985, 999984, 999983, 999982, 999981], [999980, 999979, 999978, 999977, 999976]]) == 6999958\n assert candidate(grid = [[100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 100000, 100000, 100000]]) == 700000\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]]) == 217\n assert candidate(grid = [[5, 1, 3, 9, 4], [2, 6, 7, 3, 8], [1, 5, 4, 7, 2], [6, 8, 2, 9, 5], [3, 7, 5, 1, 4]]) == 41\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]]) == 371\n assert candidate(grid = [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0], [5, 4, 3, 2, 1], [0, 1, 2, 3, 4], [9, 8, 7, 6, 5]]) == 39\n assert candidate(grid = [[9, 1, 8, 5, 6], [4, 7, 3, 2, 9], [10, 5, 1, 8, 2], [6, 3, 2, 7, 4], [5, 8, 9, 2, 1]]) == 41\n assert candidate(grid = [[5, 8, 4, 6], [9, 2, 3, 4], [1, 6, 7, 8], [4, 5, 6, 7], [8, 9, 0, 1], [2, 3, 4, 5]]) == 42\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]]) == 413\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, 50, 51, 52, 53, 54]]) == 294\n assert candidate(grid = [[1, 0, 7, 0, 8, 4], [4, 9, 3, 2, 5, 10], [0, 2, 8, 5, 3, 9], [3, 1, 6, 7, 4, 8], [8, 5, 2, 9, 0, 3], [1, 4, 7, 6, 9, 5]]) == 48\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]]) == 7\n assert candidate(grid = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160], [170, 180, 190, 200]]) == 1050\n assert candidate(grid = [[1000000, 1000000, 1000000], [1000000, 1000000, 1000000], [1000000, 1000000, 1000000], [1000000, 1000000, 1000000], [1000000, 1000000, 1000000]]) == 7000000\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]]) == 49\n assert candidate(grid = [[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]]) == 1680\n assert candidate(grid = [[9, 1, 2, 3, 4], [8, 7, 6, 5, 4], [3, 5, 7, 9, 1], [2, 4, 6, 8, 0], [5, 5, 5, 5, 5]]) == 43\n assert candidate(grid = [[100000, 100000, 100000], [100000, 100000, 100000], [100000, 100000, 100000]]) == 700000\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, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 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(grid = [[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], [6, 7, 8, 9, 10, 11, 12], [7, 8, 9, 10, 11, 12, 13]]) == 77\n assert candidate(grid = [[10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [1, 11, 21, 31, 41], [0, 10, 20, 30, 40], [9, 19, 29, 39, 49]]) == 248\n assert candidate(grid = [[1000000, 500000, 300000, 200000], [100000, 50000, 30000, 20000], [10000, 5000, 3000, 2000], [1000, 500, 300, 200]]) == 1868000\n", "comparison": "exact"}, "public_tests": ["[[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]", "[[1,2,3],[4,5,6],[7,8,9]]"], "hints": ["Each 3x3 submatrix has exactly one hourglass.", "Find the sum of each hourglass in the matrix and return the largest of these values."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().maxSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:24+00:00", "tests_total": 65, "tests_dropped": 2, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "matrix", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function maxSum($grid) {", "container": "Solution", "callable": "maxSum", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2429, "task_id": "minimize-xor", "difficulty": "Medium", "problem_description": "Given two positive integers num1 and num2, find the positive integer x such that:\n\n- x has the same number of set bits as num2, and\n- The value x XOR num1 is minimal.\n\nNote that XOR is the bitwise XOR operation.\n\nReturn the integer x. The test cases are generated such that x is uniquely determined.\n\nThe number of set bits of an integer is the number of 1's in its binary representation.\n\nExample 1:\n\nInput: num1 = 3, num2 = 5\nOutput: 3\nExplanation:\nThe binary representations of num1 and num2 are 0011 and 0101, respectively.\nThe integer 3 has the same number of set bits as num2, and the value 3 XOR 3 = 0 is minimal.\n\nExample 2:\n\nInput: num1 = 1, num2 = 12\nOutput: 3\nExplanation:\nThe binary representations of num1 and num2 are 0001 and 1100, respectively.\nThe integer 3 has the same number of set bits as num2, and the value 3 XOR 1 = 2 is minimal.\n\nConstraints:\n\n- 1 <= num1, num2 <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num1 = 1,num2 = 12) == 3\n assert candidate(num1 = 8,num2 = 3) == 9\n assert candidate(num1 = 29,num2 = 15) == 29\n assert candidate(num1 = 3,num2 = 5) == 3\n assert candidate(num1 = 7,num2 = 10) == 6\n assert candidate(num1 = 1000000000,num2 = 1) == 536870912\n assert candidate(num1 = 987654321,num2 = 1000000000) == 987654144\n assert candidate(num1 = 8,num2 = 31) == 31\n assert candidate(num1 = 134217728,num2 = 671088640) == 134217729\n assert candidate(num1 = 1023,num2 = 511) == 1022\n assert candidate(num1 = 8388607,num2 = 16777215) == 16777215\n assert candidate(num1 = 123456789,num2 = 31) == 122683392\n assert candidate(num1 = 1,num2 = 1023) == 1023\n assert candidate(num1 = 32768,num2 = 65535) == 65535\n assert candidate(num1 = 1023,num2 = 1) == 512\n assert candidate(num1 = 123456789,num2 = 987654321) == 123456791\n assert candidate(num1 = 1000000000,num2 = 100000000) == 999999488\n assert candidate(num1 = 123,num2 = 987654321) == 131071\n assert candidate(num1 = 500000000,num2 = 750000000) == 499999744\n assert candidate(num1 = 134217728,num2 = 32767) == 134234111\n assert candidate(num1 = 858993459,num2 = 12) == 805306368\n assert candidate(num1 = 123456,num2 = 32) == 65536\n assert candidate(num1 = 512,num2 = 256) == 512\n assert candidate(num1 = 894567321,num2 = 987654321) == 894567423\n assert candidate(num1 = 65535,num2 = 8) == 32768\n assert candidate(num1 = 111111111,num2 = 222222222) == 111111111\n assert candidate(num1 = 512,num2 = 255) == 639\n assert candidate(num1 = 834567,num2 = 987654) == 834564\n assert candidate(num1 = 999999999,num2 = 1) == 536870912\n assert candidate(num1 = 54321,num2 = 98765) == 54323\n assert candidate(num1 = 987654321,num2 = 16) == 536870912\n assert candidate(num1 = 1023,num2 = 10) == 768\n assert candidate(num1 = 987654,num2 = 24) == 786432\n assert candidate(num1 = 777777777,num2 = 333333333) == 777777760\n assert candidate(num1 = 1048575,num2 = 1048575) == 1048575\n assert candidate(num1 = 987654321,num2 = 123456789) == 987654320\n assert candidate(num1 = 131071,num2 = 65535) == 131070\n assert candidate(num1 = 999999999,num2 = 1000000000) == 999999744\n assert candidate(num1 = 16777215,num2 = 8388607) == 16777214\n assert candidate(num1 = 8192,num2 = 16384) == 8192\n assert candidate(num1 = 1023,num2 = 2047) == 2047\n assert candidate(num1 = 987654321,num2 = 135792468) == 987496448\n assert candidate(num1 = 134217728,num2 = 25) == 134217731\n assert candidate(num1 = 1000000000,num2 = 1000000000) == 1000000000\n assert candidate(num1 = 16,num2 = 3) == 17\n assert candidate(num1 = 1048575,num2 = 524288) == 524288\n assert candidate(num1 = 134217728,num2 = 67108864) == 134217728\n assert candidate(num1 = 888888888,num2 = 888888888) == 888888888\n assert candidate(num1 = 1000000000,num2 = 500000000) == 1000000000\n assert candidate(num1 = 67890,num2 = 13579) == 67891\n assert candidate(num1 = 999999999,num2 = 888888888) == 999999992\n assert candidate(num1 = 1,num2 = 1048575) == 1048575\n assert candidate(num1 = 123456789,num2 = 123456789) == 123456789\n assert candidate(num1 = 8388607,num2 = 4194304) == 4194304\n assert candidate(num1 = 8388607,num2 = 1048575) == 8388600\n assert candidate(num1 = 536870911,num2 = 268435456) == 268435456\n assert candidate(num1 = 135792468,num2 = 246813579) == 135794687\n assert candidate(num1 = 65535,num2 = 65535) == 65535\n assert candidate(num1 = 500000000,num2 = 800000000) == 499999744\n assert candidate(num1 = 1024,num2 = 1023) == 1535\n", "comparison": "exact"}, "public_tests": ["3\n5", "1\n12"], "hints": ["To arrive at a small xor, try to turn off some bits from num1", "If there are still left bits to set, try to set them from the least significant bit"], "metadata": {"canonical_parameter_names": ["num1", "num2"], "leetcode_dataset_entry_point": "Solution().minimizeXor", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:26+00:00", "tests_total": 85, "tests_dropped": 25, "flags": [], "topic_tags": ["greedy", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function minimizeXor($num1, $num2) {", "container": "Solution", "callable": "minimizeXor", "parameters": [{"name": "num1", "type": "Integer"}, {"name": "num2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2430, "task_id": "maximum-deletions-on-a-string", "difficulty": "Hard", "problem_description": "You are given a string s consisting of only lowercase English letters. In one operation, you can:\n\n- Delete the entire string s, or\n- Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.\n\nFor example, if s = \"ababc\", then in one operation, you could delete the first two letters of s to get \"abc\", since the first two letters of s and the following two letters of s are both equal to \"ab\".\n\nReturn the maximum number of operations needed to delete all of s.\n\nExample 1:\n\nInput: s = \"abcabcdabc\"\nOutput: 2\nExplanation:\n- Delete the first 3 letters (\"abc\") since the next 3 letters are equal. Now, s = \"abcdabc\".\n- Delete all the letters.\nWe used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed.\nNote that in the second operation we cannot delete \"abc\" again because the next occurrence of \"abc\" does not happen in the next 3 letters.\n\nExample 2:\n\nInput: s = \"aaabaab\"\nOutput: 4\nExplanation:\n- Delete the first letter (\"a\") since the next letter is equal. Now, s = \"aabaab\".\n- Delete the first 3 letters (\"aab\") since the next 3 letters are equal. Now, s = \"aab\".\n- Delete the first letter (\"a\") since the next letter is equal. Now, s = \"ab\".\n- Delete all the letters.\nWe used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed.\n\nExample 3:\n\nInput: s = \"aaaaa\"\nOutput: 5\nExplanation: In each operation, we can delete the first letter of s.\n\nConstraints:\n\n- 1 <= s.length <= 4000\n- s consists only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababababab\") == 48\n assert candidate(s = \"aaabaab\") == 4\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 90\n assert candidate(s = \"abacabadabacaba\") == 1\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 29\n assert candidate(s = \"abcabcabcabc\") == 4\n assert candidate(s = \"abcdabcdabcd\") == 3\n assert candidate(s = \"abcdefghijklmnopqrstuvsuwxyzabcdefghijklmnopqrstuvsuwxyz\") == 2\n assert candidate(s = \"abcabcdabc\") == 2\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 2\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 102\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 66\n assert candidate(s = \"abcdef\") == 1\n assert candidate(s = \"abababab\") == 4\n assert candidate(s = \"abcd\") == 1\n assert candidate(s = \"aaaaa\") == 5\n assert candidate(s = \"aabbccddeeff\") == 2\n assert candidate(s = \"abacabadabacabadabacaba\") == 2\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 32\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 26\n assert candidate(s = \"aabbccddeeffaabbccddeeffaabbccddeeff\") == 4\n assert candidate(s = \"abcababcababcababcababcababcababcababcababcababcababcab\") == 11\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 13\n assert candidate(s = \"abacabadabacabadabacabadabacabad\") == 4\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 26\n assert candidate(s = \"abcdefabcdefabcdefabcdefabcdef\") == 5\n assert candidate(s = \"abcdefghabcdefghabcdefghabcdefgh\") == 4\n assert candidate(s = \"aabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeff\") == 9\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\") == 19\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 10\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 24\n assert candidate(s = \"abababababababababababababababababababababababababababababababab\") == 32\n assert candidate(s = \"abababababababcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 20\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 27\n assert candidate(s = \"ababccababccababccababccababcc\") == 6\n assert candidate(s = \"aaaaabbbbbccccdddd\") == 5\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 28\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcab\") == 9\n assert candidate(s = \"abcdabcabcdabcabcd\") == 2\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") == 106\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 20\n assert candidate(s = \"ababababababababababababababababababababababababababababababababababababab\") == 37\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 18\n assert candidate(s = \"abababababababababababababababababababc\") == 19\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabac\") == 20\n assert candidate(s = \"abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh\") == 8\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzwwxxyyzzwwxxyyzz\") == 2\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 12\n assert candidate(s = \"aaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaabaaaaaaaaaab\") == 20\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabc\") == 10\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabb\") == 9\n assert candidate(s = \"abcdabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 94\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\") == 10\n assert candidate(s = \"abracadabraabracadabraabracadabra\") == 3\n assert candidate(s = \"aaabaaaabaaaaabaaaaaaaabaaaaaaaaabaaaaaaaaaabaaaaaaaaaaaabaaaaaaaaaaaaabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaab\") == 11\n assert candidate(s = \"aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\") == 24\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 110\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 21\n assert candidate(s = \"abababababababababababababababababababababab\") == 22\n assert candidate(s = \"ababababababababababababababababababababababababababababababababab\") == 33\n assert candidate(s = \"ababccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 2\n assert candidate(s = \"aabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccddeeaabbccdd\") == 7\n assert candidate(s = \"ababababababababababababababababa\") == 16\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 25\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 14\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 11\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 18\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 9\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 16\n assert candidate(s = \"aabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeff\") == 8\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 27\n assert candidate(s = \"abacabadabcaba\") == 1\n assert candidate(s = \"banana\") == 1\n assert candidate(s = \"abacabacabacabacabacabacabacabac\") == 8\n assert candidate(s = \"aaabbbcccdddcccbbbcccaaa\") == 3\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 30\n assert candidate(s = \"aabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeffaabbccddeeff\") == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 21\n assert candidate(s = \"abcdabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == 1\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad\") == 8\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 22\n assert candidate(s = \"ababcabcabcabcabcabc\") == 7\n assert candidate(s = \"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\") == 16\n assert candidate(s = \"abacabadabacabadabacabadabacabadabacabadabacabad\") == 6\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcd\") == 10\n assert candidate(s = \"abacabadabacabadabacabad\") == 3\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababababababababab\") == 46\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababababababab\") == 40\n assert candidate(s = \"ababccababccababccababccababccababccababccababccababccababccababccababccababccababccababcc\") == 16\n assert candidate(s = \"xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz\") == 29\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabcdabcdabcdabcdabcd\") == 2\n assert candidate(s = \"abababababababababababababababababababababababababababababababababababcabcabc\") == 37\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzwwxxyyzz\") == 2\n assert candidate(s = \"abacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabacabac\") == 21\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabc\") == 11\n assert candidate(s = \"ababccababccababccababccababccababccababccababccababccababccababccababccababcc\") == 14\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabacabadabacabadabacabadabacabad\") == 2\n assert candidate(s = \"abacabacabacabacabacabacabacabacabac\") == 9\n assert candidate(s = \"mississippi\") == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzabacabadabacabadabacabadabacabadabacabadabacabad\") == 2\n assert candidate(s = \"ababababababababababababababababababababababababababababababababababababababababab\") == 41\n", "comparison": "exact"}, "public_tests": ["\"abcabcdabc\"", "\"aaabaab\"", "\"aaaaa\""], "hints": ["We can use dynamic programming to find the answer. Create a 0-indexed dp array where dp[i] represents the maximum number of moves needed to remove the first i + 1 letters from s.", "What should we do if there is an i where it is impossible to remove the first i + 1 letters?", "Use a sentinel value such as -1 to show that it is impossible.", "How can we quickly determine if two substrings of s are equal? We can use hashing."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().deleteString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:28+00:00", "tests_total": 103, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "rolling-hash", "string-matching", "hash-function"]}, "language": "php", "interface": {"raw_signature": "function deleteString($s) {", "container": "Solution", "callable": "deleteString", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2432, "task_id": "the-employee-that-worked-on-the-longest-task", "difficulty": "Easy", "problem_description": "There are n employees, each with a unique id from 0 to n - 1.\n\nYou are given a 2D integer array logs where logs[i] = [id_i, leaveTime_i] where:\n\n- id_i is the id of the employee that worked on the i^th task, and\n- leaveTime_i is the time at which the employee finished the i^th task. All the values leaveTime_i are unique.\n\nNote that the i^th task starts the moment right after the (i - 1)^th task ends, and the 0^th task starts at time 0.\n\nReturn the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.\n\nExample 1:\n\nInput: n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]\nOutput: 1\nExplanation:\nTask 0 started at 0 and ended at 3 with 3 units of times.\nTask 1 started at 3 and ended at 5 with 2 units of times.\nTask 2 started at 5 and ended at 9 with 4 units of times.\nTask 3 started at 9 and ended at 15 with 6 units of times.\nThe task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.\n\nExample 2:\n\nInput: n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]\nOutput: 3\nExplanation:\nTask 0 started at 0 and ended at 1 with 1 unit of times.\nTask 1 started at 1 and ended at 7 with 6 units of times.\nTask 2 started at 7 and ended at 12 with 5 units of times.\nTask 3 started at 12 and ended at 17 with 5 units of times.\nThe tasks with the longest time is task 1. The employee that worked on it is 3, so we return 3.\n\nExample 3:\n\nInput: n = 2, logs = [[0,10],[1,20]]\nOutput: 0\nExplanation:\nTask 0 started at 0 and ended at 10 with 10 units of times.\nTask 1 started at 10 and ended at 20 with 10 units of times.\nThe tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.\n\nConstraints:\n\n- 2 <= n <= 500\n- 1 <= logs.length <= 500\n- logs[i].length == 2\n- 0 <= id_i <= n - 1\n- 1 <= leaveTime_i <= 500\n- id_i != id_{i+1}\n- leaveTime_i are sorted in a strictly increasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,logs = [[0, 1], [2, 2], [1, 3], [3, 4]]) == 0\n assert candidate(n = 2,logs = [[0, 10], [1, 20]]) == 0\n assert candidate(n = 6,logs = [[0, 2], [1, 6], [2, 10], [3, 14], [4, 18], [5, 22]]) == 1\n assert candidate(n = 5,logs = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 0\n assert candidate(n = 26,logs = [[1, 1], [3, 7], [2, 12], [7, 17]]) == 3\n assert candidate(n = 4,logs = [[0, 5], [1, 10], [2, 15], [3, 20]]) == 0\n assert candidate(n = 3,logs = [[0, 10], [1, 20], [2, 30]]) == 0\n assert candidate(n = 4,logs = [[3, 10], [1, 15], [2, 20], [0, 25]]) == 3\n assert candidate(n = 3,logs = [[0, 5], [1, 10], [2, 15]]) == 0\n assert candidate(n = 10,logs = [[0, 3], [2, 5], [0, 9], [1, 15]]) == 1\n assert candidate(n = 5,logs = [[0, 2], [1, 5], [0, 9]]) == 0\n assert candidate(n = 5,logs = [[0, 2], [1, 5], [0, 9], [1, 15]]) == 1\n assert candidate(n = 4,logs = [[0, 1], [1, 2], [2, 3], [3, 4]]) == 0\n assert candidate(n = 5,logs = [[0, 2], [1, 4], [2, 6], [3, 8], [4, 10]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [1, 12], [2, 18], [3, 25], [4, 32], [5, 40], [6, 48], [7, 55], [8, 60], [9, 65]]) == 5\n assert candidate(n = 8,logs = [[6, 2], [4, 5], [3, 9], [5, 14], [1, 18], [7, 23], [2, 29], [0, 34]]) == 2\n assert candidate(n = 6,logs = [[0, 10], [1, 20], [0, 30], [1, 40], [0, 50], [1, 60]]) == 0\n assert candidate(n = 20,logs = [[0, 10], [2, 20], [4, 30], [6, 40], [8, 50], [10, 60], [12, 70], [14, 80], [16, 90], [18, 100]]) == 0\n assert candidate(n = 8,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [3, 12], [2, 18], [1, 22], [0, 30]]) == 0\n assert candidate(n = 10,logs = [[0, 1], [2, 4], [4, 7], [6, 10], [8, 13], [1, 16], [3, 19], [5, 22], [7, 25], [9, 28]]) == 1\n assert candidate(n = 7,logs = [[0, 5], [1, 10], [2, 15], [0, 20], [1, 25], [2, 30], [0, 35]]) == 0\n assert candidate(n = 20,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [10, 55], [11, 60], [12, 65], [13, 70], [14, 75], [15, 80], [16, 85], [17, 90], [18, 95], [19, 100]]) == 0\n assert candidate(n = 30,logs = [[0, 2], [1, 5], [2, 9], [3, 14], [4, 20], [5, 27], [6, 35], [7, 44], [8, 54], [9, 65], [10, 77], [11, 90], [12, 104], [13, 119], [14, 135], [15, 152], [16, 170], [17, 189], [18, 209], [19, 230], [20, 252], [21, 275], [22, 300], [23, 326], [24, 353], [25, 381], [26, 410], [27, 440], [28, 471], [29, 500]]) == 28\n assert candidate(n = 3,logs = [[0, 10], [1, 20], [2, 20]]) == 0\n assert candidate(n = 5,logs = [[0, 5], [1, 10], [2, 10], [3, 15], [4, 20]]) == 0\n assert candidate(n = 11,logs = [[10, 10], [9, 20], [8, 30], [7, 40], [6, 50], [5, 60], [4, 70], [3, 80], [2, 90], [1, 100], [0, 110]]) == 0\n assert candidate(n = 10,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [0, 110], [1, 120]]) == 0\n assert candidate(n = 7,logs = [[0, 10], [1, 10], [2, 10], [3, 20], [4, 20], [5, 20], [6, 30]]) == 0\n assert candidate(n = 6,logs = [[0, 15], [1, 28], [2, 42], [3, 57], [4, 72], [5, 88]]) == 5\n assert candidate(n = 10,logs = [[0, 1], [1, 3], [2, 6], [3, 10], [4, 15], [5, 21], [6, 28], [7, 36], [8, 45], [9, 55]]) == 9\n assert candidate(n = 20,logs = [[19, 1], [18, 3], [17, 6], [16, 10], [15, 15], [14, 21], [13, 28], [12, 36], [11, 45], [10, 55], [9, 66], [8, 78], [7, 91], [6, 105], [5, 120], [4, 136], [3, 153], [2, 171], [1, 190], [0, 210]]) == 0\n assert candidate(n = 25,logs = [[0, 1], [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]]) == 1\n assert candidate(n = 9,logs = [[0, 2], [1, 5], [2, 10], [3, 17], [4, 26], [5, 37], [6, 50], [7, 65], [8, 82]]) == 8\n assert candidate(n = 10,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100]]) == 0\n assert candidate(n = 9,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90]]) == 0\n assert candidate(n = 15,logs = [[1, 5], [2, 15], [3, 25], [4, 35], [5, 45], [6, 55], [7, 65], [8, 75], [9, 85], [10, 95], [11, 105], [12, 115], [13, 125], [14, 135]]) == 2\n assert candidate(n = 12,logs = [[0, 2], [1, 4], [2, 7], [3, 11], [4, 16], [5, 22], [6, 29], [7, 37], [8, 46], [9, 56], [10, 67], [11, 78]]) == 10\n assert candidate(n = 6,logs = [[0, 10], [1, 10], [2, 20], [3, 20], [4, 30], [5, 30]]) == 0\n assert candidate(n = 7,logs = [[6, 3], [5, 9], [4, 14], [3, 20], [2, 27], [1, 35], [0, 44]]) == 0\n assert candidate(n = 12,logs = [[11, 2], [10, 5], [9, 9], [8, 14], [7, 20], [6, 27], [5, 35], [4, 44], [3, 54], [2, 65], [1, 77], [0, 90]]) == 0\n assert candidate(n = 6,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50]]) == 0\n assert candidate(n = 7,logs = [[0, 5], [1, 10], [2, 15], [0, 20], [3, 25], [1, 30], [4, 35]]) == 0\n assert candidate(n = 15,logs = [[14, 1], [13, 3], [12, 6], [11, 10], [10, 15], [9, 21], [8, 28], [7, 36], [6, 45], [5, 55], [4, 66], [3, 78], [2, 91], [1, 105], [0, 120]]) == 0\n assert candidate(n = 12,logs = [[11, 10], [10, 20], [9, 30], [8, 40], [7, 50], [6, 60], [5, 70], [4, 80], [3, 90], [2, 100], [1, 110], [0, 120]]) == 0\n assert candidate(n = 12,logs = [[0, 15], [1, 30], [2, 45], [3, 60], [4, 75], [5, 90], [6, 105], [7, 120], [8, 135], [9, 150], [10, 165], [11, 180]]) == 0\n assert candidate(n = 10,logs = [[0, 3], [2, 5], [0, 9], [1, 15], [4, 20], [6, 30], [5, 35], [3, 40]]) == 6\n assert candidate(n = 10,logs = [[0, 10], [1, 15], [2, 20], [3, 25], [4, 30], [5, 35], [6, 40], [7, 45], [8, 50], [9, 55], [0, 60], [1, 65], [2, 70], [3, 75], [4, 80], [5, 85], [6, 90], [7, 95], [8, 100], [9, 105]]) == 0\n assert candidate(n = 7,logs = [[0, 2], [1, 5], [2, 9], [3, 14], [4, 20], [5, 27], [6, 35]]) == 6\n assert candidate(n = 8,logs = [[0, 2], [1, 6], [2, 12], [3, 18], [4, 24], [5, 30], [6, 36], [7, 42]]) == 2\n assert candidate(n = 5,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [0, 60], [1, 70], [2, 80], [3, 90], [4, 100], [0, 110], [1, 120], [2, 130], [3, 140], [4, 150], [0, 160], [1, 170], [2, 180], [3, 190], [4, 200]]) == 0\n assert candidate(n = 8,logs = [[0, 20], [1, 30], [2, 40], [3, 50], [4, 60], [5, 70], [6, 80], [7, 90]]) == 0\n assert candidate(n = 7,logs = [[0, 1], [1, 3], [2, 6], [3, 10], [4, 15], [5, 21], [6, 28]]) == 6\n assert candidate(n = 12,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110], [11, 120], [0, 130], [1, 140], [2, 150], [3, 160], [4, 170], [5, 180], [6, 190], [7, 200], [8, 210], [9, 220], [10, 230], [11, 240]]) == 0\n assert candidate(n = 15,logs = [[5, 10], [7, 20], [2, 25], [3, 30], [10, 35], [6, 40], [1, 45]]) == 5\n assert candidate(n = 8,logs = [[0, 3], [1, 7], [2, 14], [3, 22], [4, 31], [5, 41], [6, 53], [7, 66]]) == 7\n assert candidate(n = 15,logs = [[0, 2], [1, 6], [2, 11], [3, 17], [4, 24], [5, 32], [6, 41], [7, 51], [8, 62], [9, 74], [10, 87], [11, 101], [12, 116], [13, 132], [14, 149]]) == 14\n assert candidate(n = 11,logs = [[0, 2], [1, 5], [2, 10], [3, 17], [4, 26], [5, 37], [6, 50], [7, 65], [8, 82], [9, 101], [10, 122]]) == 10\n assert candidate(n = 5,logs = [[0, 10], [1, 15], [2, 20], [3, 25], [4, 30], [0, 35], [1, 40]]) == 0\n assert candidate(n = 9,logs = [[0, 11], [1, 22], [2, 33], [3, 44], [4, 55], [5, 66], [6, 77], [7, 88], [8, 99]]) == 0\n assert candidate(n = 5,logs = [[4, 100], [2, 200], [3, 300], [1, 400], [0, 500]]) == 0\n assert candidate(n = 12,logs = [[0, 5], [1, 12], [2, 22], [3, 35], [4, 50], [5, 67], [6, 86], [7, 107], [8, 130], [9, 155], [10, 182], [11, 211]]) == 11\n assert candidate(n = 8,logs = [[7, 1], [1, 2], [3, 5], [2, 10], [4, 20], [6, 30], [5, 40], [0, 50]]) == 0\n assert candidate(n = 20,logs = [[0, 1], [2, 3], [4, 6], [6, 10], [8, 15], [10, 21], [12, 28], [14, 36], [16, 45], [18, 55], [1, 65], [3, 75], [5, 85], [7, 95]]) == 1\n assert candidate(n = 5,logs = [[0, 1], [1, 10], [2, 11], [3, 12], [4, 13]]) == 1\n assert candidate(n = 10,logs = [[0, 10], [1, 15], [2, 20], [3, 25], [4, 30], [5, 35], [6, 40], [7, 45], [8, 50], [9, 55]]) == 0\n assert candidate(n = 10,logs = [[9, 10], [8, 20], [7, 30], [6, 40], [5, 50], [4, 60], [3, 70], [2, 80], [1, 90], [0, 100]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [1, 15], [2, 25], [3, 35], [4, 45], [5, 55], [6, 65], [7, 75], [8, 85], [9, 95]]) == 1\n assert candidate(n = 15,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110], [11, 120], [12, 130], [13, 140], [14, 150]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 30], [5, 40], [6, 50], [7, 60], [8, 70], [9, 80]]) == 4\n assert candidate(n = 7,logs = [[0, 12], [1, 23], [2, 34], [3, 45], [4, 56], [5, 67], [6, 78]]) == 0\n assert candidate(n = 25,logs = [[0, 12], [1, 24], [2, 36], [3, 48], [4, 60], [5, 72], [6, 84], [7, 96], [8, 108], [9, 120], [10, 132], [11, 144], [12, 156], [13, 168], [14, 180], [15, 192], [16, 204], [17, 216], [18, 228], [19, 240], [20, 252], [21, 264], [22, 276], [23, 288], [24, 300]]) == 0\n assert candidate(n = 8,logs = [[7, 15], [3, 25], [5, 40], [6, 50], [2, 60], [1, 70], [4, 80], [0, 90]]) == 5\n assert candidate(n = 10,logs = [[0, 5], [1, 9], [2, 13], [3, 17], [4, 21], [5, 25], [6, 29], [7, 33], [8, 37], [9, 41]]) == 0\n assert candidate(n = 6,logs = [[5, 10], [0, 20], [2, 30], [1, 40], [3, 50], [4, 60]]) == 0\n assert candidate(n = 15,logs = [[0, 2], [1, 5], [2, 9], [3, 14], [4, 20], [5, 27], [6, 35], [7, 44], [8, 54], [9, 65], [10, 77], [11, 90], [12, 104], [13, 119], [14, 135]]) == 14\n assert candidate(n = 13,logs = [[12, 2], [11, 5], [10, 9], [9, 14], [8, 20], [7, 27], [6, 35], [5, 44], [4, 54], [3, 65], [2, 77], [1, 90], [0, 104]]) == 0\n assert candidate(n = 10,logs = [[9, 2], [3, 6], [7, 10], [2, 15], [4, 20], [1, 25], [5, 30], [8, 35], [6, 40], [0, 50]]) == 0\n assert candidate(n = 7,logs = [[0, 5], [1, 10], [0, 15], [1, 20], [0, 25], [1, 30], [0, 35]]) == 0\n assert candidate(n = 15,logs = [[14, 3], [13, 7], [12, 12], [11, 18], [10, 24], [9, 31], [8, 38], [7, 45], [6, 52], [5, 59], [4, 66], [3, 73], [2, 80], [1, 87], [0, 94]]) == 0\n assert candidate(n = 30,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [10, 55], [11, 60], [12, 65], [13, 70], [14, 75], [15, 80], [16, 85], [17, 90], [18, 95], [19, 100], [20, 105], [21, 110], [22, 115], [23, 120], [24, 125], [25, 130], [26, 135], [27, 140], [28, 145], [29, 150]]) == 0\n assert candidate(n = 10,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [0, 55], [1, 60], [2, 65], [3, 70], [4, 75], [5, 80], [6, 85], [7, 90], [8, 95], [9, 100]]) == 0\n assert candidate(n = 9,logs = [[8, 1], [7, 3], [6, 6], [5, 10], [4, 15], [3, 21], [2, 28], [1, 36], [0, 45]]) == 0\n assert candidate(n = 20,logs = [[0, 15], [1, 30], [2, 45], [3, 60], [4, 75], [5, 90], [6, 105], [7, 120], [8, 135], [9, 150], [10, 165], [11, 180], [12, 195], [13, 210], [14, 225], [15, 240], [16, 255], [17, 270], [18, 285], [19, 300]]) == 0\n assert candidate(n = 15,logs = [[0, 5], [1, 15], [2, 25], [3, 35], [4, 45], [5, 55], [6, 65], [7, 75], [8, 85], [9, 95], [10, 105], [11, 115], [12, 125], [13, 135], [14, 145]]) == 1\n assert candidate(n = 10,logs = [[0, 5], [1, 10], [2, 15], [3, 20], [4, 25], [5, 30], [6, 35], [7, 40], [8, 45], [9, 50], [0, 55], [1, 60], [2, 65], [3, 70], [4, 75], [5, 80], [6, 85], [7, 90], [8, 95], [9, 100], [0, 105], [1, 110], [2, 115], [3, 120], [4, 125], [5, 130], [6, 135], [7, 140], [8, 145], [9, 150]]) == 0\n assert candidate(n = 5,logs = [[0, 50], [1, 100], [2, 150], [3, 200], [4, 250]]) == 0\n assert candidate(n = 4,logs = [[0, 10], [1, 20], [2, 30], [3, 40]]) == 0\n assert candidate(n = 5,logs = [[4, 2], [3, 5], [2, 9], [1, 14], [0, 20]]) == 0\n assert candidate(n = 7,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [0, 80]]) == 0\n assert candidate(n = 6,logs = [[0, 5], [1, 15], [2, 25], [3, 35], [4, 45], [5, 55]]) == 1\n assert candidate(n = 7,logs = [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [0, 80], [1, 90], [2, 100], [3, 110], [4, 120], [5, 130], [6, 140], [0, 150], [1, 160], [2, 170], [3, 180], [4, 190], [5, 200], [6, 210]]) == 0\n assert candidate(n = 8,logs = [[0, 2], [1, 4], [2, 8], [3, 14], [4, 22], [5, 32], [6, 44], [7, 58]]) == 7\n assert candidate(n = 5,logs = [[0, 50], [1, 100], [2, 150], [3, 200], [4, 250], [0, 300], [1, 350], [2, 400], [3, 450], [4, 500]]) == 0\n assert candidate(n = 15,logs = [[14, 10], [3, 20], [5, 30], [7, 40], [9, 50], [11, 60], [13, 70]]) == 3\n", "comparison": "exact"}, "public_tests": ["10\n[[0,3],[2,5],[0,9],[1,15]]", "26\n[[1,1],[3,7],[2,12],[7,17]]", "2\n[[0,10],[1,20]]"], "hints": ["Find the time of the longest task", "Store each employee’s longest task time in a hash table", "For employees that have the same longest task time, we only need the employee with the smallest ID"], "metadata": {"canonical_parameter_names": ["n", "logs"], "leetcode_dataset_entry_point": "Solution().hardestWorker", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:33+00:00", "tests_total": 99, "tests_dropped": 3, "flags": [], "topic_tags": ["array"]}, "language": "php", "interface": {"raw_signature": "function hardestWorker($n, $logs) {", "container": "Solution", "callable": "hardestWorker", "parameters": [{"name": "n", "type": "Integer"}, {"name": "logs", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2433, "task_id": "find-the-original-array-of-prefix-xor", "difficulty": "Medium", "problem_description": "You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:\n\n- pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].\n\nNote that ^ denotes the bitwise-xor operation.\n\nIt can be proven that the answer is unique.\n\nExample 1:\n\nInput: pref = [5,2,0,3,1]\nOutput: [5,7,2,3,2]\nExplanation: From the array [5,7,2,3,2] we have the following:\n- pref[0] = 5.\n- pref[1] = 5 ^ 7 = 2.\n- pref[2] = 5 ^ 7 ^ 2 = 0.\n- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.\n- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.\n\nExample 2:\n\nInput: pref = [13]\nOutput: [13]\nExplanation: We have pref[0] = arr[0] = 13.\n\nConstraints:\n\n- 1 <= pref.length <= 10^5\n- 0 <= pref[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pref = [5, 2, 0, 3, 1]) == [5, 7, 2, 3, 2]\n assert candidate(pref = [0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0]\n assert candidate(pref = [0, 1, 2, 3, 4]) == [0, 1, 3, 1, 7]\n assert candidate(pref = [10, 4, 6, 3, 5]) == [10, 14, 2, 5, 6]\n assert candidate(pref = [13]) == [13]\n assert candidate(pref = [1, 1, 1, 1, 1]) == [1, 0, 0, 0, 0]\n assert candidate(pref = [2, 3, 4, 5, 6]) == [2, 1, 7, 1, 3]\n assert candidate(pref = [1, 2, 3, 4, 5]) == [1, 3, 1, 7, 1]\n assert candidate(pref = [1000000, 500000, 250000, 125000, 62500]) == [1000000, 582496, 291248, 145624, 72812]\n assert candidate(pref = [1, 3, 7, 15, 31]) == [1, 2, 4, 8, 16]\n assert candidate(pref = [10, 15, 5, 12, 9]) == [10, 5, 10, 9, 5]\n assert candidate(pref = [65535, 32767, 16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1]) == [65535, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2]\n assert candidate(pref = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 0, 111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999]) == [999999, 184839, 413193, 127515, 153097, 963135, 253449, 422427, 185865, 111111, 111111, 185865, 422427, 253449, 963135, 153097, 127515, 413193, 184839]\n assert candidate(pref = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [1, 3, 6, 12, 24, 48, 96, 192, 384, 768]\n assert candidate(pref = [123456, 234567, 345678, 456789, 567890, 678901, 789012, 890123, 901234]) == [123456, 161287, 446985, 245275, 938503, 192935, 414177, 106271, 21881]\n assert candidate(pref = [0, 1, 3, 6, 15, 31, 63, 127, 255, 511]) == [0, 1, 2, 5, 9, 16, 32, 64, 128, 256]\n assert candidate(pref = [0, 1, 3, 0, 4, 5, 1, 2, 6, 7, 1, 0]) == [0, 1, 2, 3, 4, 1, 4, 3, 4, 1, 6, 1]\n assert candidate(pref = [0, 1, 3, 6, 10, 15, 21]) == [0, 1, 2, 5, 12, 5, 26]\n assert candidate(pref = [1, 2, 4, 8, 16, 32, 64, 128, 256]) == [1, 3, 6, 12, 24, 48, 96, 192, 384]\n assert candidate(pref = [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == [1024, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1, 1, 3, 6, 12, 24, 48, 96, 192, 384, 768]\n assert candidate(pref = [0, 1, 3, 0, 4, 7, 4, 3, 1, 0]) == [0, 1, 2, 3, 4, 3, 3, 7, 2, 1]\n assert candidate(pref = [123456, 654321, 111111, 222222, 333333, 444444]) == [123456, 530865, 543222, 185865, 422427, 253449]\n assert candidate(pref = [255, 127, 63, 31, 15, 7, 3, 1, 0]) == [255, 128, 64, 32, 16, 8, 4, 2, 1]\n assert candidate(pref = [888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == [888888, 413193, 127515, 153097, 963135, 253449, 422427, 185865]\n assert candidate(pref = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [1, 3, 1, 7, 1, 3, 1, 15, 1, 3, 1, 7, 1, 3, 1]\n assert candidate(pref = [888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111, 0]) == [888888, 413193, 127515, 153097, 963135, 253449, 422427, 185865, 111111]\n assert candidate(pref = [256, 272, 258, 274, 259, 275, 260, 276, 261, 277, 262, 278, 263, 279, 264, 280, 265, 281, 266, 282, 267, 283, 268, 284, 269, 285, 270, 286, 271, 287, 272, 288]) == [256, 16, 18, 16, 17, 16, 23, 16, 17, 16, 19, 16, 17, 16, 31, 16, 17, 16, 19, 16, 17, 16, 23, 16, 17, 16, 19, 16, 17, 16, 15, 48]\n assert candidate(pref = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 3, 1, 7, 1, 3, 1, 15, 1, 3]\n assert candidate(pref = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == [100, 172, 484, 188, 100, 940, 228, 412, 164, 108]\n assert candidate(pref = [123456, 654321, 111111, 222222, 333333]) == [123456, 530865, 543222, 185865, 422427]\n assert candidate(pref = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == [100, 172, 484, 188, 100, 940, 228, 412, 164, 108, 1956, 252]\n assert candidate(pref = [15, 14, 13, 12, 11, 10, 9, 8, 7]) == [15, 1, 3, 1, 7, 1, 3, 1, 15]\n assert candidate(pref = [17, 23, 14, 31, 5, 9, 12, 7]) == [17, 6, 25, 17, 26, 12, 5, 11]\n assert candidate(pref = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023]) == [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]\n assert candidate(pref = [8, 12, 10, 15, 7, 13, 9, 14, 6, 11]) == [8, 4, 6, 5, 8, 10, 4, 7, 8, 13]\n assert candidate(pref = [13, 13, 26, 26, 52, 52, 104, 104, 208, 208]) == [13, 0, 23, 0, 46, 0, 92, 0, 184, 0]\n assert candidate(pref = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]) == [1, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576, 49152]\n assert candidate(pref = [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, 1, 1, 1, 1, 1]\n assert candidate(pref = [256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 1, 2, 4, 8, 16]) == [256, 384, 192, 96, 48, 24, 12, 6, 3, 1, 1, 3, 6, 12, 24]\n assert candidate(pref = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]) == [1, 0, 3, 1, 6, 13, 5, 24, 55, 21, 110, 201, 121, 400, 795, 441, 1510, 3109, 6733, 2616]\n assert candidate(pref = [999999, 899999, 799999, 699999, 599999, 499999, 399999, 299999, 199999, 99999]) == [999999, 194976, 102240, 432800, 231904, 951968, 113504, 166304, 499424, 166816]\n assert candidate(pref = [123456, 654321, 111222, 333444, 555666, 777888]) == [123456, 530865, 543111, 304370, 879638, 238642]\n assert candidate(pref = [7, 14, 21, 28, 35, 42, 49]) == [7, 9, 27, 9, 63, 9, 27]\n assert candidate(pref = [42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21, 42, 21]) == [42, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63]\n assert candidate(pref = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(pref = [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, 1, 1, 1, 1, 1]\n assert candidate(pref = [1024, 2048, 1024, 2048, 1024, 2048, 1024, 2048, 1024, 2048, 1024, 2048]) == [1024, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072]\n assert candidate(pref = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(pref = [1024, 2048, 4096, 8192, 16384, 32768]) == [1024, 3072, 6144, 12288, 24576, 49152]\n assert candidate(pref = [255, 0, 255, 0, 255, 0, 255, 0, 255]) == [255, 255, 255, 255, 255, 255, 255, 255, 255]\n assert candidate(pref = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) == [0, 1, 2, 5, 12, 5, 26, 9, 56, 9]\n assert candidate(pref = [123, 456, 789, 101112, 131415, 161718, 192021, 222324, 252627, 282930]) == [123, 435, 733, 100845, 232367, 30433, 39331, 100961, 48807, 494561]\n assert candidate(pref = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(pref = [1365, 1364, 1360, 1344, 1312, 1248, 1120, 896, 512, 0]) == [1365, 1, 4, 16, 96, 448, 128, 2016, 384, 512]\n assert candidate(pref = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]) == [1, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536]\n assert candidate(pref = [100, 200, 100, 300, 200, 500, 400, 700, 600, 1100, 1000, 1500, 1400, 1900, 1800]) == [100, 172, 172, 328, 484, 316, 100, 812, 228, 1556, 1956, 1588, 164, 532, 100]\n assert candidate(pref = [16, 28, 40, 52, 64, 76, 88, 100]) == [16, 12, 52, 28, 116, 12, 20, 60]\n assert candidate(pref = [16, 24, 28, 20, 26, 30, 22, 31, 27, 29, 31, 15, 7, 11, 13, 12]) == [16, 8, 4, 8, 14, 4, 8, 9, 4, 6, 2, 16, 8, 12, 6, 1]\n assert candidate(pref = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]) == [5, 15, 5, 27, 13, 7, 61, 11, 5, 31, 5, 11]\n assert candidate(pref = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n assert candidate(pref = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == [1, 3, 6, 12, 24, 48, 96, 192, 384, 768, 1536, 3072, 6144, 12288, 24576]\n assert candidate(pref = [3, 1, 2, 3, 1, 0, 1]) == [3, 2, 3, 1, 2, 1, 1]\n assert candidate(pref = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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(pref = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246]) == [255, 1, 3, 1, 7, 1, 3, 1, 15, 1]\n assert candidate(pref = [1024, 1023, 1022, 1021, 1020, 1019, 1018, 1017, 1016]) == [1024, 2047, 1, 3, 1, 7, 1, 3, 1]\n assert candidate(pref = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [15, 1, 3, 1, 7, 1, 3, 1, 15, 1, 3, 1, 7, 1, 3, 1]\n assert candidate(pref = [987654, 321456, 654321, 789012, 123456, 456789]) == [987654, 783798, 859201, 389605, 911444, 465429]\n assert candidate(pref = [8, 12, 14, 8, 10, 3, 9, 0, 1, 5, 6, 7, 1]) == [8, 4, 2, 6, 2, 9, 10, 9, 1, 4, 3, 1, 6]\n assert candidate(pref = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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(pref = [255, 254, 252, 248, 240, 224, 192, 128, 64, 0]) == [255, 1, 2, 4, 8, 16, 32, 64, 192, 64]\n assert candidate(pref = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584]) == [7, 9, 18, 36, 72, 144, 288, 576, 1152, 2304]\n assert candidate(pref = [8, 12, 10, 14, 13, 11, 15, 9, 13, 11, 15, 9]) == [8, 4, 6, 4, 3, 6, 4, 6, 4, 6, 4, 6]\n assert candidate(pref = [15, 11, 13, 9, 15, 7]) == [15, 4, 6, 4, 6, 8]\n assert candidate(pref = [8, 12, 14, 13, 9, 3, 6, 10, 11, 7]) == [8, 4, 2, 3, 4, 10, 5, 12, 1, 12]\n assert candidate(pref = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10]) == [10, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]\n assert candidate(pref = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == [1, 2, 5, 12, 5, 26, 9, 56, 9, 26]\n assert candidate(pref = [131313, 131312, 131311, 131310, 131309, 131308, 131307, 131306, 131305, 131304]) == [131313, 1, 31, 1, 3, 1, 7, 1, 3, 1]\n assert candidate(pref = [15, 30, 60, 120, 240, 480, 960, 1920, 3840, 7680]) == [15, 17, 34, 68, 136, 272, 544, 1088, 2176, 4352]\n", "comparison": "exact"}, "public_tests": ["[5,2,0,3,1]", "[13]"], "hints": ["Consider the following equation: x ^ a = b. How can you find x?", "Notice that arr[i] ^ pref[i-1] = pref[i]. This is the same as the previous equation."], "metadata": {"canonical_parameter_names": ["pref"], "leetcode_dataset_entry_point": "Solution().findArray", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:35+00:00", "tests_total": 98, "tests_dropped": 20, "flags": [], "topic_tags": ["array", "bit-manipulation"]}, "language": "php", "interface": {"raw_signature": "function findArray($pref) {", "container": "Solution", "callable": "findArray", "parameters": [{"name": "pref", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2434, "task_id": "using-a-robot-to-print-the-lexicographically-smallest-string", "difficulty": "Medium", "problem_description": "You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:\n\n- Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.\n- Remove the last character of a string t and give it to the robot. The robot will write this character on paper.\n\nReturn the lexicographically smallest string that can be written on the paper.\n\nExample 1:\n\nInput: s = \"zza\"\nOutput: \"azz\"\nExplanation: Let p denote the written string.\nInitially p=\"\", s=\"zza\", t=\"\".\nPerform first operation three times p=\"\", s=\"\", t=\"zza\".\nPerform second operation three times p=\"azz\", s=\"\", t=\"\".\n\nExample 2:\n\nInput: s = \"bac\"\nOutput: \"abc\"\nExplanation: Let p denote the written string.\nPerform first operation twice p=\"\", s=\"c\", t=\"ba\".\nPerform second operation twice p=\"ab\", s=\"c\", t=\"\".\nPerform first operation p=\"ab\", s=\"\", t=\"c\".\nPerform second operation p=\"abc\", s=\"\", t=\"\".\n\nExample 3:\n\nInput: s = \"bdda\"\nOutput: \"addb\"\nExplanation: Let p denote the written string.\nInitially p=\"\", s=\"bdda\", t=\"\".\nPerform first operation four times p=\"\", s=\"\", t=\"bdda\".\nPerform second operation four times p=\"addb\", s=\"\", t=\"\".\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of only English lowercase letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"aabbcc\") == \"aabbcc\"\n assert candidate(s = \"bdda\") == \"addb\"\n assert candidate(s = \"cba\") == \"abc\"\n assert candidate(s = \"bac\") == \"abc\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"aaa\") == \"aaa\"\n assert candidate(s = \"abcde\") == \"abcde\"\n assert candidate(s = \"zza\") == \"azz\"\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == \"abcdefghijklmnopqrstuvwxyz\"\n assert candidate(s = \"a\") == \"a\"\n assert candidate(s = \"edcba\") == \"abcde\"\n assert candidate(s = \"abacabadabacaba\") == \"aaaaaaaabcbdbcb\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"aaaabbbbccccdddd\") == \"aaaabbbbccccdddd\"\n assert candidate(s = \"fedcb\") == \"bcdef\"\n assert candidate(s = \"ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\") == \"ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\"\n assert candidate(s = \"aaabbbccc\") == \"aaabbbccc\"\n assert candidate(s = \"fedcbafedcbafedcba\") == \"aaabcdefbcdefbcdef\"\n assert candidate(s = \"fedcbaghijk\") == \"abcdefghijk\"\n assert candidate(s = \"mjwqeqpdpdwdwwvwqwdqeqpqwwqwwqwwpqwwqwpqwwqppwpqpqppwpqpqpqpqpqpqpqpqpqpqpqpqpqpqppwqqqqqqqppqqqpqpwq\") == \"ddddepppppppppppppppppppppppppppppqqqqqqqqqqqqwwqqqqqqqqqqqqqqwqqwqwwqwqwwqwwqwwqwwqqqwqwvwwwppqeqwjm\"\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooopppqqqrrrssstttuuuuvvvwwwxxxyyyzzz\") == \"aaabbbcccdddeeefffggghhhiiiijjjjkkkkllllmmmmnnnnooopppqqqrrrssstttuuuuvvvwwwxxxyyyzzz\"\n assert candidate(s = \"acbcbabcbabcba\") == \"aaaabcbbcbbcbc\"\n assert candidate(s = \"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\") == \"aaaaaaaaaaaaaaaaaaabcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc\"\n assert candidate(s = \"bbbaaa\") == \"aaabbb\"\n assert candidate(s = \"abcdcba\") == \"aabcdcb\"\n assert candidate(s = \"zazbzczdz\") == \"abcdzzzzz\"\n assert candidate(s = \"zzzaaa\") == \"aaazzz\"\n assert candidate(s = \"amazingleetcodeproblem\") == \"aabelmorpedocteelgnizm\"\n assert candidate(s = \"abcdefgzyxwvutsrqponmlkjihgfedcba\") == \"aabcdefghijklmnopqrstuvwxyzgfedcb\"\n assert candidate(s = \"fedcbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbacbac\") == \"aaaaaaaaaaaaaaaaabcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbccdef\"\n assert candidate(s = \"abracadabra\") == \"aaaaarbdcrb\"\n assert candidate(s = \"aabccccaaa\") == \"aaaaaccccb\"\n assert candidate(s = \"abcdabcda\") == \"aaadcbdcb\"\n assert candidate(s = \"bacbacbacb\") == \"aaabbccbcb\"\n assert candidate(s = \"abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\") == \"aaaaaaaaaabcdedcbedcbedcbedcbedcbedcbedcbedcbedcbe\"\n assert candidate(s = \"zzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaazzzaaaa\") == \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzz\") == \"abcdefghijklmnopqrstuvwxyzz\"\n assert candidate(s = \"zzzyyyxxxwwwwvvvuuutttsssrqqqpppoonnmmlkkjjiihhggffeedcba\") == \"abcdeeffgghhiijjkklmmnnoopppqqqrssstttuuuvvvwwwwxxxyyyzzz\"\n assert candidate(s = \"caabdbac\") == \"aaabcdbc\"\n assert candidate(s = \"aaaabbbbccccddddeeeeffff\") == \"aaaabbbbccccddddeeeeffff\"\n assert candidate(s = \"fedcba\") == \"abcdef\"\n assert candidate(s = \"abcdabcabc\") == \"aaabcbcdcb\"\n assert candidate(s = \"leetcode\") == \"cdeoteel\"\n assert candidate(s = \"racecar\") == \"aacecrr\"\n assert candidate(s = \"zzzyyxxwvwuvuttrssrqqponnmlkkjjiihhhggffeeddcbbbaaa\") == \"aaabbbcddeeffgghhhiijjkklmnnopqqrssrttuvuwvwxxyyzzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == \"aabcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcb\"\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == \"aaaabcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcbzyxwvutsrqponmlkjihgfedcbzyxwvutsrqponmlkjihgfedcbz\"\n assert candidate(s = \"banana\") == \"aaannb\"\n assert candidate(s = \"abcdeabcde\") == \"aabcdedcbe\"\n assert candidate(s = \"mississippi\") == \"iiiippssssm\"\n assert candidate(s = \"acacacacac\") == \"aaaaaccccc\"\n assert candidate(s = \"abcdabcdbacd\") == \"aaabcdcbdcbd\"\n assert candidate(s = \"bbaaccdd\") == \"aabbccdd\"\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\"\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\n assert candidate(s = \"abcdabcdabcdabcd\") == \"aaaabcdcbdcbdcbd\"\n assert candidate(s = \"aaabbbcccddd\") == \"aaabbbcccddd\"\n assert candidate(s = \"qrsnspndpsnpppdnspndpdpsnsnspdpspndpdpsnpsdpsnpspdpsndpdpsnpdpsnpsdpsnpd\") == \"ddddddddddddddpnspspnsppnsppnsppspnspspnsppnpsppsnsnsppnpsnpppnspnpsnsrq\"\n assert candidate(s = \"abababababababababababababab\") == \"aaaaaaaaaaaaaabbbbbbbbbbbbbb\"\n assert candidate(s = \"xyzzyxzyx\") == \"xxxyzyzzy\"\n", "comparison": "exact"}, "public_tests": ["\"zza\"", "\"bac\"", "\"bdda\""], "hints": ["If there are some character “a” ’ s in the string, they can be written on paper before anything else.", "Every character in the string before the last “a” should be written in reversed order.", "After the robot writes every “a” on paper, the same holds for other characters “b”, ”c”, …etc."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().robotWithString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:38+00:00", "tests_total": 61, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "stack", "greedy"]}, "language": "php", "interface": {"raw_signature": "function robotWithString($s) {", "container": "Solution", "callable": "robotWithString", "parameters": [{"name": "s", "type": "String"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2435, "task_id": "paths-in-matrix-whose-sum-is-divisible-by-k", "difficulty": "Hard", "problem_description": "You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.\n\nReturn the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3\nOutput: 2\nExplanation: There are two paths where the sum of the elements on the path is divisible by k.\nThe first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.\nThe second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.\n\nExample 2:\n\nInput: grid = [[0,0]], k = 5\nOutput: 1\nExplanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.\n\nExample 3:\n\nInput: grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1\nOutput: 10\nExplanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 5 * 10^4\n- 1 <= m * n <= 5 * 10^4\n- 0 <= grid[i][j] <= 100\n- 1 <= k <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10]],k = 5) == 6\n assert candidate(grid = [[100, 100], [100, 100]],k = 5) == 2\n assert candidate(grid = [[1, 2, 3], [4, 5, 6]],k = 2) == 3\n assert candidate(grid = [[7, 3, 4, 9], [2, 3, 6, 2], [2, 3, 7, 0]],k = 1) == 10\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 2) == 0\n assert candidate(grid = [[10, 10, 10], [10, 10, 10], [10, 10, 10]],k = 10) == 6\n assert candidate(grid = [[10, 20, 30], [40, 50, 60]],k = 10) == 3\n assert candidate(grid = [[5, 2, 4], [3, 0, 5], [0, 7, 2]],k = 3) == 2\n assert candidate(grid = [[0, 0]],k = 5) == 1\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]],k = 11) == 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], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]],k = 15) == 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]],k = 7) == 5\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 = 3) == 13\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, 1], [1, 0, 9, 8, 7, 6, 5, 4, 3, 2]],k = 10) == 44\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 = 3) == 0\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 7, 5, 3, 1, 2, 4, 6, 8]],k = 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, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 3) == 0\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]],k = 50) == 7\n assert candidate(grid = [[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]],k = 7) == 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], [21, 22, 23, 24, 25]],k = 11) == 7\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]],k = 3) == 22\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]],k = 11) == 65\n assert candidate(grid = [[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 = 29) == 41\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]],k = 19) == 9\n assert candidate(grid = [[97, 23, 14], [12, 54, 67], [11, 22, 33], [44, 55, 66]],k = 49) == 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, 1, 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(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]],k = 10) == 0\n assert candidate(grid = [[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]],k = 13) == 2\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50]],k = 13) == 6\n assert candidate(grid = [[5, 15, 25, 35, 45], [10, 20, 30, 40, 50], [5, 15, 25, 35, 45], [10, 20, 30, 40, 50]],k = 7) == 5\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]],k = 5) == 16\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]],k = 5) == 0\n assert candidate(grid = [[3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8], [9, 8, 7, 6, 5, 4, 3, 2], [1, 3, 5, 7, 9, 11, 13, 15]],k = 7) == 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]],k = 4) == 35\n assert candidate(grid = [[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]],k = 50) == 0\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]],k = 8) == 5\n assert candidate(grid = [[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]],k = 25) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [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], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]],k = 11) == 4500\n assert candidate(grid = [[42, 24, 64, 18, 81], [30, 37, 30, 26, 44], [30, 37, 30, 26, 44], [30, 37, 30, 26, 44], [30, 37, 30, 26, 44]],k = 17) == 5\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]],k = 2) == 35\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]],k = 10) == 0\n assert candidate(grid = [[10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 90, 80, 70, 60, 50, 40, 30, 20, 10], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], [100, 90, 80, 70, 60, 50, 40, 30, 20, 10], [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]],k = 11) == 119\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, 1]],k = 17) == 1\n assert candidate(grid = [[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]],k = 3) == 16568\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 = 10) == 35\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]],k = 7) == 55\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]],k = 4) == 16\n assert candidate(grid = [[42, 35, 18, 57], [61, 36, 35, 90], [61, 28, 47, 66], [84, 84, 53, 71]],k = 17) == 1\n assert candidate(grid = [[5, 8, 3, 6, 2], [7, 1, 4, 9, 10], [12, 5, 16, 3, 8], [4, 13, 11, 20, 6]],k = 7) == 4\n assert candidate(grid = [[7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2]],k = 11) == 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, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 7) == 12\n assert candidate(grid = [[34, 21, 54, 23], [12, 34, 56, 78], [90, 12, 34, 56], [78, 90, 12, 34]],k = 13) == 1\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]],k = 5) == 1\n assert candidate(grid = [[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 = 42) == 50\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]],k = 7) == 715\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],k = 3) == 0\n assert candidate(grid = [[99, 98, 97, 96], [95, 94, 93, 92], [91, 90, 89, 88]],k = 50) == 0\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, 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]],k = 50) == 0\n assert candidate(grid = [[3, 1, 4, 1, 5], [9, 2, 6, 5, 3], [5, 8, 9, 7, 9], [3, 2, 3, 8, 4], [0, 2, 1, 3, 8]],k = 13) == 4\n assert candidate(grid = [[3, 1, 2, 3, 4], [1, 3, 4, 5, 2], [2, 4, 5, 1, 3], [4, 5, 1, 3, 2], [5, 1, 3, 2, 4]],k = 13) == 39\n assert candidate(grid = [[99, 98, 97, 96, 95], [94, 93, 92, 91, 90], [89, 88, 87, 86, 85], [84, 83, 82, 81, 80]],k = 25) == 2\n assert candidate(grid = [[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]],k = 49) == 0\n assert candidate(grid = [[100, 0, 100, 0, 100], [0, 100, 0, 100, 0], [100, 0, 100, 0, 100], [0, 100, 0, 100, 0], [100, 0, 100, 0, 100]],k = 5) == 70\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]],k = 11) == 5\n assert candidate(grid = [[37, 37, 37, 37, 37, 37, 37, 37, 37, 37], [37, 37, 37, 37, 37, 37, 37, 37, 37, 37], [37, 37, 37, 37, 37, 37, 37, 37, 37, 37], [37, 37, 37, 37, 37, 37, 37, 37, 37, 37], [37, 37, 37, 37, 37, 37, 37, 37, 37, 37]],k = 47) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],k = 2) == 70\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]],k = 19) == 3\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 2, 4, 6, 8, 10], [10, 8, 6, 4, 2, 0]],k = 4) == 14\n assert candidate(grid = [[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]],k = 7) == 10\n assert candidate(grid = [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [20, 30, 40, 50, 60], [25, 35, 45, 55, 65]],k = 27) == 1\n", "comparison": "exact"}, "public_tests": ["[[5,2,4],[3,0,5],[0,7,2]]\n3", "[[0,0]]\n5", "[[7,3,4,9],[2,3,6,2],[2,3,7,0]]\n1"], "hints": ["The actual numbers in grid do not matter. What matters are the remainders you get when you divide the numbers by k.", "We can use dynamic programming to solve this problem. What can we use as states?", "Let dp[i][j][value] represent the number of paths where the sum of the elements on the path has a remainder of value when divided by k."], "metadata": {"canonical_parameter_names": ["grid", "k"], "leetcode_dataset_entry_point": "Solution().numberOfPaths", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:40+00:00", "tests_total": 74, "tests_dropped": 4, "flags": ["has_images"], "topic_tags": ["array", "dynamic-programming", "matrix"]}, "language": "php", "interface": {"raw_signature": "function numberOfPaths($grid, $k) {", "container": "Solution", "callable": "numberOfPaths", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2437, "task_id": "number-of-valid-clock-times", "difficulty": "Easy", "problem_description": "You are given a string of length 5 called time, representing the current time on a digital clock in the format \"hh:mm\". The earliest possible time is \"00:00\" and the latest possible time is \"23:59\".\n\nIn the string time, the digits represented by the ? symbol are unknown, and must be replaced with a digit from 0 to 9.\n\nReturn an integer answer, the number of valid clock times that can be created by replacing every ? with a digit from 0 to 9.\n\nExample 1:\n\nInput: time = \"?5:00\"\nOutput: 2\nExplanation: We can replace the ? with either a 0 or 1, producing \"05:00\" or \"15:00\". Note that we cannot replace it with a 2, since the time \"25:00\" is invalid. In total, we have two choices.\n\nExample 2:\n\nInput: time = \"0?:0?\"\nOutput: 100\nExplanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.\n\nExample 3:\n\nInput: time = \"??:??\"\nOutput: 1440\nExplanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.\n\nConstraints:\n\n- time is a valid string of length 5 in the format \"hh:mm\".\n- \"00\" <= hh <= \"23\"\n- \"00\" <= mm <= \"59\"\n- Some of the digits might be replaced with '?' and need to be replaced with digits from 0 to 9.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(time = \"23:?0\") == 6\n assert candidate(time = \"23:5?\") == 10\n assert candidate(time = \"09:5?\") == 10\n assert candidate(time = \"23:?9\") == 6\n assert candidate(time = \"1?:?0\") == 60\n assert candidate(time = \"00:??\") == 60\n assert candidate(time = \"1?:?5\") == 60\n assert candidate(time = \"0?:0?\") == 100\n assert candidate(time = \"?3:59\") == 3\n assert candidate(time = \"1?:2?\") == 100\n assert candidate(time = \"09:?9\") == 6\n assert candidate(time = \"??:??\") == 1440\n assert candidate(time = \"00:00\") == 1\n assert candidate(time = \"23:59\") == 1\n assert candidate(time = \"1?:30\") == 10\n assert candidate(time = \"2?:45\") == 4\n assert candidate(time = \"1?:5?\") == 100\n assert candidate(time = \"12:??\") == 60\n assert candidate(time = \"2?:4?\") == 40\n assert candidate(time = \"1??:3?\") == 0\n assert candidate(time = \"?3:21\") == 3\n assert candidate(time = \"1?:45\") == 10\n assert candidate(time = \"1?:?1\") == 60\n assert candidate(time = \"12:?5\") == 6\n assert candidate(time = \"1?:3?\") == 100\n assert candidate(time = \"09:??\") == 60\n assert candidate(time = \"12:?3\") == 6\n assert candidate(time = \"??:59\") == 24\n assert candidate(time = \"?5:00\") == 2\n assert candidate(time = \"2?:3?\") == 40\n assert candidate(time = \"??:45\") == 24\n assert candidate(time = \"?4:??\") == 120\n assert candidate(time = \"19:?5\") == 6\n assert candidate(time = \"2?:15\") == 4\n assert candidate(time = \"2?:?3\") == 24\n assert candidate(time = \"???:30\") == 0\n assert candidate(time = \"23:?5\") == 6\n assert candidate(time = \"23:?7\") == 6\n assert candidate(time = \"??:2?\") == 240\n assert candidate(time = \"0?:??:\") == 600\n assert candidate(time = \"??:00\") == 24\n assert candidate(time = \"19:?7\") == 6\n assert candidate(time = \"2?:59\") == 4\n assert candidate(time = \"2?:1?\") == 40\n assert candidate(time = \"19:?1\") == 6\n assert candidate(time = \"22:?8\") == 6\n assert candidate(time = \"?4:3?\") == 20\n assert candidate(time = \"0?:?9\") == 60\n assert candidate(time = \"?3:?1\") == 18\n assert candidate(time = \"1?:??\") == 600\n assert candidate(time = \"??:3?\") == 240\n assert candidate(time = \"??:?1\") == 144\n assert candidate(time = \"12:?7\") == 6\n assert candidate(time = \"2?:35\") == 4\n assert candidate(time = \"0??:59\") == 0\n assert candidate(time = \"2?:?0\") == 24\n assert candidate(time = \"09:?5\") == 6\n assert candidate(time = \"???:??\") == 0\n assert candidate(time = \"?0:5?\") == 30\n assert candidate(time = \"0?:3?\") == 100\n assert candidate(time = \"1?:?9\") == 60\n assert candidate(time = \"12:?9\") == 6\n assert candidate(time = \"?3:45\") == 3\n assert candidate(time = \"19:??\") == 60\n assert candidate(time = \"19:?4\") == 6\n assert candidate(time = \"23:?4\") == 6\n assert candidate(time = \"?1:??\") == 180\n assert candidate(time = \"?3:?0\") == 18\n assert candidate(time = \"0?:?5\") == 60\n assert candidate(time = \"0?:4?\") == 100\n assert candidate(time = \"2?:5?\") == 40\n assert candidate(time = \"??:10\") == 24\n assert candidate(time = \"0?:?3\") == 60\n assert candidate(time = \"19:?0\") == 6\n assert candidate(time = \"2?:?5\") == 24\n assert candidate(time = \"2?:40\") == 4\n assert candidate(time = \"19:?9\") == 6\n assert candidate(time = \"1?:0?\") == 100\n assert candidate(time = \"???:00\") == 0\n assert candidate(time = \"2?:22\") == 4\n assert candidate(time = \"0?:5?\") == 100\n assert candidate(time = \"1??:0?\") == 0\n assert candidate(time = \"0?:30\") == 10\n assert candidate(time = \"2?:?4\") == 24\n assert candidate(time = \"21:??\") == 60\n assert candidate(time = \"20:?7\") == 6\n assert candidate(time = \"?4:?3\") == 12\n assert candidate(time = \"2?:00\") == 4\n assert candidate(time = \"09:4?\") == 10\n assert candidate(time = \"?9:??\") == 120\n assert candidate(time = \"1?:?7\") == 60\n assert candidate(time = \"0?:59\") == 10\n assert candidate(time = \"0?:??\") == 600\n assert candidate(time = \"0?:?0\") == 60\n assert candidate(time = \"?4:5?\") == 20\n assert candidate(time = \"?2:??\") == 180\n assert candidate(time = \"1?:59\") == 10\n assert candidate(time = \"0?:1?\") == 100\n assert candidate(time = \"2?:??:\") == 240\n assert candidate(time = \"1??:??\") == 0\n assert candidate(time = \"?:09\") == 0\n assert candidate(time = \"?9:0?\") == 20\n assert candidate(time = \"2?:?2\") == 24\n assert candidate(time = \"?1:?2\") == 18\n assert candidate(time = \"2?:?9\") == 24\n assert candidate(time = \"0?:19\") == 10\n assert candidate(time = \"??:0?\") == 240\n assert candidate(time = \"?4:?9\") == 12\n assert candidate(time = \"20:??\") == 60\n assert candidate(time = \"??:30\") == 24\n assert candidate(time = \"1?:??:\") == 600\n assert candidate(time = \"?4:2?\") == 20\n assert candidate(time = \"1?:23\") == 10\n assert candidate(time = \"2?:2?\") == 40\n", "comparison": "exact"}, "public_tests": ["\"?5:00\"", "\"0?:0?\"", "\"??:??\""], "hints": ["Brute force all possible clock times.", "Checking if a clock time is valid can be done with Regex."], "metadata": {"canonical_parameter_names": ["time"], "leetcode_dataset_entry_point": "Solution().countTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:44+00:00", "tests_total": 114, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function countTime($time) {", "container": "Solution", "callable": "countTime", "parameters": [{"name": "time", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2438, "task_id": "range-product-queries-of-powers", "difficulty": "Medium", "problem_description": "Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.\n\nYou are also given a 0-indexed 2D integer array queries, where queries[i] = [left_i, right_i]. Each queries[i] represents a query where you have to find the product of all powers[j] with left_i <= j <= right_i.\n\nReturn an array answers, equal in length to queries, where answers[i] is the answer to the i^th query. Since the answer to the i^th query may be too large, each answers[i] should be returned modulo 10^9 + 7.\n\nExample 1:\n\nInput: n = 15, queries = [[0,1],[2,2],[0,3]]\nOutput: [2,4,64]\nExplanation:\nFor n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.\nAnswer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.\nAnswer to 2nd query: powers[2] = 4.\nAnswer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.\nEach answer modulo 10^9 + 7 yields the same answer, so [2,4,64] is returned.\n\nExample 2:\n\nInput: n = 2, queries = [[0,0]]\nOutput: [2]\nExplanation:\nFor n = 2, powers = [2].\nThe answer to the only query is powers[0] = 2. The answer modulo 10^9 + 7 is the same, so [2] is returned.\n\nConstraints:\n\n- 1 <= n <= 10^9\n- 1 <= queries.length <= 10^5\n- 0 <= start_i <= end_i < powers.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 10,queries = [[0, 0], [1, 1], [0, 2]]) == [2, 8, 16]\n assert candidate(n = 1023,queries = [[0, 9], [3, 5]]) == [371842544, 4096]\n assert candidate(n = 1023,queries = [[0, 9], [4, 5], [2, 8]]) == [371842544, 512, 359738130]\n assert candidate(n = 100,queries = [[0, 0], [1, 2], [2, 2]]) == [4, 2048, 64]\n assert candidate(n = 29,queries = [[0, 2], [1, 3]]) == [32, 512]\n assert candidate(n = 5,queries = [[0, 1], [0, 2], [1, 2]]) == [4, 4, 4]\n assert candidate(n = 1023,queries = [[0, 9], [3, 5], [6, 8]]) == [371842544, 4096, 2097152]\n assert candidate(n = 8,queries = [[0, 2], [1, 1], [0, 3]]) == [8, 1, 8]\n assert candidate(n = 1023,queries = [[0, 9], [2, 6], [0, 8]]) == [371842544, 1048576, 719476260]\n assert candidate(n = 1023,queries = [[0, 9], [1, 3], [5, 7]]) == [371842544, 64, 262144]\n assert candidate(n = 255,queries = [[0, 7], [3, 5], [1, 2]]) == [268435456, 4096, 8]\n assert candidate(n = 5,queries = [[0, 0], [0, 1], [0, 2]]) == [1, 4, 4]\n assert candidate(n = 1000000000,queries = [[0, 29]]) == [371048337]\n assert candidate(n = 15,queries = [[0, 1], [2, 2], [0, 3]]) == [2, 4, 64]\n assert candidate(n = 2,queries = [[0, 0]]) == [2]\n assert candidate(n = 134217727,queries = [[0, 26], [10, 15], [20, 25]]) == [867243987, 640520040, 792931211]\n assert candidate(n = 8388607,queries = [[0, 22], [12, 17], [20, 21], [0, 5], [18, 22]]) == [349105660, 570065479, 23240159, 32768, 976371285]\n assert candidate(n = 1024,queries = [[0, 9], [4, 4], [2, 2], [8, 8], [0, 0]]) == [1024, 1, 1, 1, 1024]\n assert candidate(n = 1048575,queries = [[0, 19], [5, 10], [15, 18]]) == [953612746, 371842544, 329376018]\n assert candidate(n = 65535,queries = [[0, 15], [4, 7], [10, 13], [0, 15]]) == [489373567, 4194304, 743685088, 489373567]\n assert candidate(n = 999999935,queries = [[0, 29], [10, 20], [15, 25], [5, 15], [0, 29]]) == [756589216, 355395742, 948232808, 711461273, 756589216]\n assert candidate(n = 999999935,queries = [[0, 29], [10, 16], [20, 26]]) == [756589216, 990388602, 1]\n assert candidate(n = 1048575,queries = [[0, 19], [10, 15], [5, 10], [18, 19]]) == [953612746, 640520040, 371842544, 438952513]\n assert candidate(n = 1000000000,queries = [[0, 29], [15, 20], [30, 30]]) == [371048337, 1, 1]\n assert candidate(n = 16777215,queries = [[0, 23], [14, 18], [6, 9], [12, 15], [0, 23]]) == [511821710, 496641140, 73741817, 383381198, 511821710]\n assert candidate(n = 524287,queries = [[0, 18], [7, 12], [3, 8], [0, 19]]) == [134084614, 67049563, 589934536, 134084614]\n assert candidate(n = 1234567,queries = [[0, 20], [7, 12], [3, 8]]) == [975523612, 329376018, 658752036]\n assert candidate(n = 67108863,queries = [[0, 25], [12, 19], [6, 11], [0, 24]]) == [217770278, 829977023, 797922655, 322050759]\n assert candidate(n = 524287,queries = [[0, 18], [5, 8], [10, 15], [17, 18], [0, 19]]) == [134084614, 67108864, 640520040, 359738130, 134084614]\n assert candidate(n = 999999935,queries = [[0, 29], [10, 20], [15, 25], [5, 15]]) == [756589216, 355395742, 948232808, 711461273]\n assert candidate(n = 65535,queries = [[0, 15], [7, 10], [3, 7], [0, 14], [12, 15]]) == [489373567, 179869065, 33554432, 243880903, 383381198]\n assert candidate(n = 1024,queries = [[0, 0], [0, 9], [1, 8]]) == [1024, 1024, 1]\n assert candidate(n = 1047552,queries = [[0, 19], [5, 12], [15, 18]]) == [961554387, 892516375, 1]\n assert candidate(n = 1048575,queries = [[0, 19], [10, 15], [5, 14], [0, 20]]) == [953612746, 640520040, 936761609, 953612746]\n assert candidate(n = 524287,queries = [[0, 18], [4, 9], [10, 15]]) == [134084614, 755810045, 640520040]\n assert candidate(n = 131071,queries = [[0, 16], [6, 10], [8, 12], [14, 16]]) == [585862415, 511620083, 898961331, 371842544]\n assert candidate(n = 536870911,queries = [[0, 28], [3, 8], [12, 17], [0, 28], [8, 13]]) == [733922348, 589934536, 570065479, 733922348, 291172004]\n assert candidate(n = 5,queries = [[0, 0], [1, 1], [0, 1]]) == [1, 4, 4]\n assert candidate(n = 4194303,queries = [[0, 21], [4, 9], [12, 16], [3, 8], [0, 21]]) == [686331837, 755810045, 270016253, 589934536, 686331837]\n assert candidate(n = 1,queries = [[0, 0]]) == [1]\n assert candidate(n = 65535,queries = [[0, 15], [3, 7], [9, 12], [0, 15], [8, 11]]) == [489373567, 33554432, 46480318, 489373567, 877905026]\n assert candidate(n = 65535,queries = [[0, 15], [5, 10], [10, 15], [0, 15]]) == [489373567, 371842544, 640520040, 489373567]\n assert candidate(n = 536870911,queries = [[0, 28], [14, 20], [22, 28]]) == [733922348, 744686787, 145353810]\n assert candidate(n = 8388607,queries = [[0, 22], [6, 12], [14, 18]]) == [349105660, 291172004, 496641140]\n assert candidate(n = 511,queries = [[0, 8], [3, 7], [1, 4], [0, 9]]) == [719476260, 33554432, 1024, 719476260]\n assert candidate(n = 3,queries = [[0, 0], [0, 1], [1, 1]]) == [1, 2, 2]\n assert candidate(n = 134217727,queries = [[0, 26], [5, 13], [18, 23], [10, 17], [0, 26]]) == [867243987, 993282280, 914988515, 951047217, 867243987]\n assert candidate(n = 16777215,queries = [[0, 23], [5, 10], [15, 18]]) == [511821710, 371842544, 329376018]\n assert candidate(n = 524287,queries = [[0, 18], [7, 12], [3, 8]]) == [134084614, 67049563, 589934536]\n assert candidate(n = 4194303,queries = [[0, 21], [13, 17], [20, 21], [5, 10], [0, 21]]) == [686331837, 640520040, 23240159, 371842544, 686331837]\n assert candidate(n = 33554431,queries = [[0, 24], [12, 19], [6, 15], [0, 25], [3, 8], [10, 13]]) == [322050759, 829977023, 243880903, 322050759, 589934536, 743685088]\n assert candidate(n = 2097151,queries = [[0, 20], [8, 12], [16, 20], [10, 15], [0, 20]]) == [431750151, 898961331, 560523804, 640520040, 431750151]\n assert candidate(n = 33554431,queries = [[0, 24], [16, 20], [8, 11], [2, 5], [0, 24]]) == [322050759, 560523804, 877905026, 16384, 322050759]\n assert candidate(n = 8388607,queries = [[0, 22], [11, 16], [4, 8], [0, 21]]) == [349105660, 993282280, 73741817, 686331837]\n assert candidate(n = 4194303,queries = [[0, 21], [10, 15], [18, 20], [5, 8], [0, 21]]) == [686331837, 640520040, 67049563, 67108864, 686331837]\n assert candidate(n = 536870911,queries = [[0, 28], [12, 18], [20, 25], [0, 29]]) == [733922348, 243880903, 792931211, 733922348]\n assert candidate(n = 33554431,queries = [[0, 24], [8, 13], [16, 20]]) == [322050759, 291172004, 560523804]\n assert candidate(n = 1000000000,queries = [[0, 29], [10, 20], [15, 25]]) == [371048337, 946258191, 1]\n assert candidate(n = 8388607,queries = [[0, 22], [7, 11], [14, 18], [2, 6], [0, 22]]) == [349105660, 371842544, 496641140, 1048576, 349105660]\n assert candidate(n = 8388607,queries = [[0, 22], [8, 13], [16, 20]]) == [349105660, 291172004, 560523804]\n assert candidate(n = 1048575,queries = [[0, 19], [10, 15], [5, 18]]) == [953612746, 640520040, 427865320]\n assert candidate(n = 511,queries = [[0, 8], [3, 6], [1, 7]]) == [719476260, 262144, 268435456]\n assert candidate(n = 33554431,queries = [[0, 24], [12, 18], [5, 10], [0, 9], [20, 24]]) == [322050759, 243880903, 371842544, 371842544, 804188847]\n assert candidate(n = 131071,queries = [[0, 16], [8, 12], [0, 0], [15, 16]]) == [585862415, 898961331, 1, 147483634]\n assert candidate(n = 8388607,queries = [[0, 22], [9, 16], [5, 11], [0, 23], [2, 7]]) == [349105660, 976371285, 533524785, 349105660, 134217728]\n assert candidate(n = 1048576,queries = [[0, 19], [5, 10], [15, 20]]) == [1048576, 1, 1]\n assert candidate(n = 255,queries = [[0, 7], [3, 6], [1, 5], [0, 0], [7, 7]]) == [268435456, 262144, 32768, 1, 128]\n assert candidate(n = 8388607,queries = [[0, 22], [11, 14], [20, 22], [15, 18], [0, 22]]) == [349105660, 898961331, 291172004, 329376018, 349105660]\n assert candidate(n = 500000000,queries = [[0, 28], [10, 20], [5, 15]]) == [885909558, 993282280, 369201595]\n assert candidate(n = 134217727,queries = [[0, 26], [10, 16], [18, 24]]) == [867243987, 121047601, 846217527]\n assert candidate(n = 524287,queries = [[0, 18], [3, 8], [12, 15], [0, 19]]) == [134084614, 589934536, 383381198, 134084614]\n assert candidate(n = 524287,queries = [[0, 18], [3, 7], [9, 14], [0, 17]]) == [134084614, 33554432, 635008130, 157921350]\n assert candidate(n = 1048575,queries = [[0, 19], [9, 15], [5, 10], [0, 18], [17, 19]]) == [953612746, 946258191, 371842544, 134084614, 383381198]\n assert candidate(n = 8388607,queries = [[0, 22], [10, 15], [5, 18]]) == [349105660, 640520040, 427865320]\n assert candidate(n = 7,queries = [[0, 0], [0, 1], [0, 2], [1, 2], [2, 2]]) == [1, 2, 8, 8, 4]\n assert candidate(n = 134217727,queries = [[0, 26], [13, 18], [8, 12], [0, 27], [4, 9]]) == [867243987, 484190404, 898961331, 867243987, 755810045]\n assert candidate(n = 67108863,queries = [[0, 25], [8, 14], [16, 22]]) == [217770278, 562080146, 948232808]\n assert candidate(n = 1000000000,queries = [[0, 29], [15, 20], [10, 14], [0, 9], [25, 29]]) == [371048337, 1, 946258191, 581415240, 1]\n assert candidate(n = 999999999,queries = [[0, 29], [10, 15], [20, 25]]) == [421709488, 951047217, 536870912]\n assert candidate(n = 268435455,queries = [[0, 27], [12, 18], [20, 26]]) == [742004924, 243880903, 427865320]\n", "comparison": "exact"}, "public_tests": ["15\n[[0,1],[2,2],[0,3]]", "2\n[[0,0]]"], "hints": ["The powers array can be created using the binary representation of n.", "Once powers is formed, the products can be taken using brute force."], "metadata": {"canonical_parameter_names": ["n", "queries"], "leetcode_dataset_entry_point": "Solution().productQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:47+00:00", "tests_total": 90, "tests_dropped": 10, "flags": [], "topic_tags": ["array", "bit-manipulation", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function productQueries($n, $queries) {", "container": "Solution", "callable": "productQueries", "parameters": [{"name": "n", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2439, "task_id": "minimize-maximum-of-array", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums comprising of n non-negative integers.\n\nIn one operation, you must:\n\n- Choose an integer i such that 1 <= i < n and nums[i] > 0.\n- Decrease nums[i] by 1.\n- Increase nums[i - 1] by 1.\n\nReturn the minimum possible value of the maximum integer of nums after performing any number of operations.\n\nExample 1:\n\nInput: nums = [3,7,1,6]\nOutput: 5\nExplanation:\nOne set of optimal operations is as follows:\n1. Choose i = 1, and nums becomes [4,6,1,6].\n2. Choose i = 3, and nums becomes [4,6,2,5].\n3. Choose i = 1, and nums becomes [5,5,2,5].\nThe maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.\nTherefore, we return 5.\n\nExample 2:\n\nInput: nums = [10,1]\nOutput: 10\nExplanation:\nIt is optimal to leave nums as is, and since 10 is the maximum value, we return 10.\n\nConstraints:\n\n- n == nums.length\n- 2 <= n <= 10^5\n- 0 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 9, 1, 9, 1]) == 5\n assert candidate(nums = [1, 1000000000]) == 500000001\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [9, 7, 5, 3, 1]) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 10\n assert candidate(nums = [1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [0, 0, 0, 0, 0]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 3\n assert candidate(nums = [1, 1000000000, 1, 1000000000, 1]) == 500000001\n assert candidate(nums = [1, 2, 1000000000, 2, 1]) == 333333335\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1\n assert candidate(nums = [1000000000, 0, 0, 0, 0]) == 1000000000\n assert candidate(nums = [5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 1000000000, 1, 1, 1]) == 500000001\n assert candidate(nums = [1, 1000000000, 1]) == 500000001\n assert candidate(nums = [10, 1]) == 10\n assert candidate(nums = [3, 7, 1, 6]) == 5\n assert candidate(nums = [1000000000, 1]) == 1000000000\n assert candidate(nums = [500, 450, 400, 350, 300, 250, 200, 150, 100, 50]) == 500\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]) == 5\n assert candidate(nums = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000000000\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 550\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 103\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 = [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 = [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 = [10, 20, 30, 40, 50]) == 30\n assert candidate(nums = [1, 999999999, 2, 999999998, 3, 999999997, 4, 999999996, 5]) == 500000000\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\n assert candidate(nums = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000]) == 47619048\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 = [1000000000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 1000000000\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\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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1000000000]) == 100000005\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 1]) == 10\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 3\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 10\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 = [1000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1000000000\n assert candidate(nums = [5, 3, 8, 2, 9, 1]) == 6\n assert candidate(nums = [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, 100, 6, 7, 8, 9, 10]) == 20\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 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, 1000000000]) == 47619049\n assert candidate(nums = [0, 0, 0, 0, 0, 1000000000]) == 166666667\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000]) == 1000000000\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 28\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 100000001\n assert candidate(nums = [999999999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 999999999\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == 1000000000\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == 20\n assert candidate(nums = [100, 50, 10, 5, 1, 0, 0, 0, 0, 0]) == 100\n assert candidate(nums = [0, 1000000000, 0, 0, 0, 0, 0, 0, 0, 0]) == 500000000\n assert candidate(nums = [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\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\n assert candidate(nums = [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 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000]) == 50000000\n assert candidate(nums = [19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 19\n assert candidate(nums = [100, 10, 1, 1, 1, 1, 1, 1, 1, 1]) == 100\n assert candidate(nums = [1000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 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\n assert candidate(nums = [0, 1000000000, 0, 1000000000, 0, 1000000000, 0]) == 500000000\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 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, 0]) == 20\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]) == 111111112\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 10\n assert candidate(nums = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000000000\n assert candidate(nums = [50, 40, 30, 20, 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, 0, 0, 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]) == 13\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000000]) == 50000001\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, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 1000\n assert candidate(nums = [1, 999999999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 500000000\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]) == 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]) == 105\n assert candidate(nums = [10, 20, 30, 40, 50]) == 30\n assert candidate(nums = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == 275\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 11\n assert candidate(nums = [1, 2, 100, 4, 5, 6, 7, 8, 9, 10]) == 35\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]) == 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]) == 11\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1]) == 1000000000\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 100\n assert candidate(nums = [100000000, 90000000, 80000000, 70000000, 60000000, 50000000, 40000000, 30000000, 20000000, 10000000]) == 100000000\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 = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 100\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 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1000000000]) == 100000000\n assert candidate(nums = [333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333, 333333333]) == 333333333\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5]) == 168\n assert candidate(nums = [1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000000000\n assert candidate(nums = [999999999, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 999999999\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]) == 55\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]) == 30\n assert candidate(nums = [1000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1000000000\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, 1000000000]) == 31250001\n assert candidate(nums = [5, 3, 8, 12, 2]) == 7\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 = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 500\n assert candidate(nums = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1000]) == 105\n assert candidate(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 6\n", "comparison": "exact"}, "public_tests": ["[3,7,1,6]", "[10,1]"], "hints": ["Try a binary search approach.", "Perform a binary search over the minimum value that can be achieved for the maximum number of the array.", "In each binary search iteration, iterate through the array backwards, greedily decreasing the current element until it is within the limit."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimizeArrayValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:49+00:00", "tests_total": 114, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "binary-search", "dynamic-programming", "greedy", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minimizeArrayValue($nums) {", "container": "Solution", "callable": "minimizeArrayValue", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2440, "task_id": "create-components-with-same-value", "difficulty": "Hard", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1.\n\nYou are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also 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 allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.\n\nReturn the maximum number of edges you can delete, such that every connected component in the tree has the same value.\n\nExample 1:\n\nInput: nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]]\nOutput: 2\nExplanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.\n\nExample 2:\n\nInput: nums = [2], edges = []\nOutput: 0\nExplanation: There are no edges to be deleted.\n\nConstraints:\n\n- 1 <= n <= 2 * 10^4\n- nums.length == n\n- 1 <= nums[i] <= 50\n- edges.length == n - 1\n- edges[i].length == 2\n- 0 <= edges[i][0], edges[i][1] <= n - 1\n- edges represents a valid tree.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [2, 3]]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]) == 5\n assert candidate(nums = [4, 4, 4, 4, 4, 4],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [4, 5]]) == 5\n assert candidate(nums = [10, 10, 10, 10],edges = [[0, 1], [1, 2], [1, 3]]) == 3\n assert candidate(nums = [3, 2, 6, 1, 3],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 0\n assert candidate(nums = [3, 3, 3, 9, 3],edges = [[0, 1], [1, 2], [1, 3], [1, 4]]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]]) == 7\n assert candidate(nums = [7, 7, 7, 7, 7, 7],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]]) == 5\n assert candidate(nums = [4, 4, 4, 4, 4, 4],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 7\n assert candidate(nums = [6, 2, 2, 2, 6],edges = [[0, 1], [1, 2], [1, 3], [3, 4]]) == 2\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 7\n assert candidate(nums = [2],edges = []) == 0\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]) == 0\n assert candidate(nums = [1, 2, 3, 6, 2, 2, 2, 6],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [3, 6], [0, 7]]) == 1\n assert candidate(nums = [15, 10, 5, 5, 10, 10, 10, 5, 10, 10],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [4, 6], [4, 7], [5, 8], [5, 9]]) == 2\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 9\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],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]]) == 19\n assert candidate(nums = [1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [0, 6], [6, 7], [6, 8], [8, 9], [9, 10], [8, 11], [7, 12], [12, 13], [12, 14], [14, 15], [14, 16], [6, 17], [17, 18], [17, 19]]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [6, 8], [6, 9]]) == 9\n assert candidate(nums = [5, 10, 5, 10, 5, 10, 5],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 1\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) == 0\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9]]) == 0\n assert candidate(nums = [10, 15, 15, 10, 20, 20, 10, 30],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7]]) == 0\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],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]]) == 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],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]]) == 19\n assert candidate(nums = [15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10],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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 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],edges = [[0, 1], [1, 2], [1, 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(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],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\n assert candidate(nums = [10, 10, 5, 5, 5, 5, 10, 5, 5, 5, 5, 10],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [0, 8], [8, 9], [8, 10], [9, 11]]) == 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],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]]) == 19\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 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\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == 0\n assert candidate(nums = [10, 5, 5, 2, 2, 2, 10, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7]]) == 0\n assert candidate(nums = [2, 4, 8, 8, 8, 16, 16, 16, 16],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8]]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9]]) == 9\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],edges = [[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(nums = [20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [1, 7], [2, 8], [2, 9], [2, 10], [3, 11], [3, 12], [3, 13], [4, 14], [4, 15], [4, 16], [5, 17], [6, 18], [7, 19]]) == 0\n assert candidate(nums = [6, 3, 3, 2, 2, 2, 6],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [0, 6]]) == 3\n", "comparison": "exact"}, "public_tests": ["[6,2,2,2,6]\n[[0,1],[1,2],[1,3],[3,4]]", "[2]\n[]"], "hints": ["Consider all divisors of the sum of values."], "metadata": {"canonical_parameter_names": ["nums", "edges"], "leetcode_dataset_entry_point": "Solution().componentValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:51+00:00", "tests_total": 49, "tests_dropped": 5, "flags": ["has_images"], "topic_tags": ["array", "math", "tree", "depth-first-search", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function componentValue($nums, $edges) {", "container": "Solution", "callable": "componentValue", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2441, "task_id": "largest-positive-integer-that-exists-with-its-negative", "difficulty": "Easy", "problem_description": "Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.\n\nReturn the positive integer k. If there is no such integer, return -1.\n\nExample 1:\n\nInput: nums = [-1,2,-3,3]\nOutput: 3\nExplanation: 3 is the only valid k we can find in the array.\n\nExample 2:\n\nInput: nums = [-1,10,6,7,-7,1]\nOutput: 7\nExplanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.\n\nExample 3:\n\nInput: nums = [-10,8,6,7,-2,-3]\nOutput: -1\nExplanation: There is no a single valid k, we return -1.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- -1000 <= nums[i] <= 1000\n- nums[i] != 0\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, -4, -3, -2]) == 4\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250, 125, -125]) == 1000\n assert candidate(nums = [5, 4, 3, 2, 1, -1]) == 1\n assert candidate(nums = [5, 4, 3, 2, 1, -5, -4, -3, -2, -1]) == 5\n assert candidate(nums = [-1]) == -1\n assert candidate(nums = [1]) == -1\n assert candidate(nums = [-5, -4, -3, -2, -1]) == -1\n assert candidate(nums = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums = [100, 200, -100, -200, 300, 400]) == 200\n assert candidate(nums = [1000, -1000]) == 1000\n assert candidate(nums = [-100, -99, -98, 98, 99, 100]) == 100\n assert candidate(nums = [-10, 8, 6, 7, -2, -3]) == -1\n assert candidate(nums = [999, -999, 500, -500, 250, -250]) == 999\n assert candidate(nums = [5, 4, 3, 2, 1]) == -1\n assert candidate(nums = [1, 1, 1, 1, -1, -1, -1, -1]) == 1\n assert candidate(nums = [1000, -1000, 500, -500, 250, -250]) == 1000\n assert candidate(nums = [1, 2, 3, -2, -1]) == 2\n assert candidate(nums = [1, 2, -2, 3, -3, 4, -4]) == 4\n assert candidate(nums = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5]) == 5\n assert candidate(nums = [-1, 10, 6, 7, -7, 1]) == 7\n assert candidate(nums = [-1, 2, -3, 3]) == 3\n assert candidate(nums = [-999, 999, -998, 998, -997, 997, -996, 996, -995, 995, -994, 994, -993, 993, -992, 992, -991, 991, -990, 990]) == 999\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, 17, 18, 19, 20]) == 5\n assert candidate(nums = [1, -1, 1000, -1000, 500, -500, 250, -250, 125, -125, 625, -625, 312, -312, 156, -156, 78, -78, 39, -39]) == 1000\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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == 9\n assert candidate(nums = [-100, -99, -98, -97, -96, -95, 95, 96, 97, 98, 99, 100]) == 100\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80, 90, -90, 100, -100]) == 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]) == -1\n assert candidate(nums = [50, -50, 23, -23, 47, -47, 38, -38, 19, -19, 11, -11, 7, -7, 3, -3, 1, -1]) == 50\n assert candidate(nums = [999, -999, 998, -998, 997, -997, 996, -996, 995, -995, 994, -994]) == 999\n assert candidate(nums = [-1, -2, -3, -4, -5, 6, 7, 8, 9, 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]) == 50\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, 170, -170, 180, -180, 190, -190, 200, -200]) == 200\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, -6, 7, -7, 8, -8, 9, -9]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -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, 11, -11, 12, -12, 13, -13, 14, -14, 15, -15]) == 15\n assert candidate(nums = [999, -999, 500, -500, 250, -250, 125, -125]) == 999\n assert candidate(nums = [100, -100, 99, -99, 98, -98, 97, -97, 96, -96, 95, -95, 94, -94, 93, -93, 92, -92, 91, -91]) == 100\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 = [-100, 100, 50, -50, 25, -25, 12, -12, 6, -6]) == 100\n assert candidate(nums = [42, -42, 24, -24, 36, -36, 48, -48, 60, -60, 72, -72, 84, -84, 96, -96, 108, -108, 120, -120]) == 120\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900]) == 900\n assert candidate(nums = [1, 2, 3, 4, 5, -6, -7, -8, -9, -10]) == -1\n assert candidate(nums = [7, -7, 14, -14, 21, -21, 28, -28, 35, -35, 42, -42, 49, -49, 56, -56, 63, -63, 70, -70, 77, -77, 84, -84]) == 84\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19]) == 19\n assert candidate(nums = [10, 20, 30, -10, -20, -30, 40, 50, -40, -50, 60, -60, 70]) == 60\n assert candidate(nums = [-500, 500, 250, -250, 125, -125, 625, -625]) == 625\n assert candidate(nums = [500, -500, 250, -250, 125, -125, 62, -62, 31, -31, 15, -15, 7, -7, 3, -3, 1, -1]) == 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]) == -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, -11, -12, -13, -14, -15]) == 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, -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 = [-1000, 1000, -999, 999, -998, 998, -1, 1]) == 1000\n assert candidate(nums = [100, 200, 300, 400, 500, -100, -200, -300, -400, -500, 150, -150, 250, -250, 350, -350]) == 500\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, -11, 12, -12, 13, -13, 14, -14, 15, -15]) == 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]) == -1\n assert candidate(nums = [999, 998, 997, 996, 995, -999, -998, -997, -996, -995, 994, 993, 992, 991, -994, -993, -992, -991]) == 999\n assert candidate(nums = [-500, 500, -499, 499, -498, 498, -1, 1, 2, -2]) == 500\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]) == 10\n assert candidate(nums = [999, -999, 998, -998, 997, -997, 996, -996, 995, -995, 994, -994, 993, -993]) == 999\n assert candidate(nums = [-500, 500, -499, 499, -200, 200, 100, -100, 50, -50, 1, -1]) == 500\n assert candidate(nums = [7, -7, 14, -14, 21, -21, 28, -28, 35, -35, 42, -42, 49, -49, 56, -56]) == 56\n assert candidate(nums = [2, -2, 4, -4, 6, -6, 8, -8, 10, -10, 12, -12, 14, -14, 16, -16, 18, -18, 20, -20, 22, -22, 24, -24, 26, -26]) == 26\n assert candidate(nums = [-333, 333, -222, 222, -111, 111, 444, -444, 555, -555, 666, -666, 777, -777, 888, -888, 999]) == 888\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, -5, -10, -15, -20, -25, -30, -35, -40, -45, -50, 60, 65, 70, 75, -60, -65, -70, -75]) == 75\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500, -600, 600, -700, 700, -800, 800, -900, 900, -1000, 1000]) == 1000\n assert candidate(nums = [5, -5, 15, -15, 25, -25, 35, -35, 45, -45, 55, -55, 65, -65, 75, -75, 85, -85, 95, -95, 105, -105, 115, -115]) == 115\n assert candidate(nums = [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]) == 15\n assert candidate(nums = [1, 2, 3, 4, 5, -1, -2, -3, -4, -5, 6, 7, 8, 9, 10, -6, -7, -8, -9, -10]) == 10\n assert candidate(nums = [-500, 500, 250, -250, 125, -125, 62, -62]) == 500\n assert candidate(nums = [100, 200, 300, 400, -100, -200, -300, -400, 500, -500]) == 500\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]) == 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, -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]) == 15\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]) == 120\n assert candidate(nums = [-500, 500, 250, -250, 125, -125, 625, -625, 312, -312]) == 625\n assert candidate(nums = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50, 60, -60, 70, -70, 80, -80, 90, -90]) == 90\n assert candidate(nums = [999, -999, 998, -998, 997, -997, 996, -996, 995, -995]) == 999\n assert candidate(nums = [101, 102, 103, 104, 105, 106, 107, 108, 109, -109, -108, -107, -106, -105, -104, -103, -102, -101]) == 109\n assert candidate(nums = [-100, 100, -50, 50, -25, 25, -10, 10]) == 100\n assert candidate(nums = [10, 20, 30, 40, 50, -10, -20, -30, -40, -50, 60, -60, 70, -70, 80, -80, 90, -90]) == 90\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\n assert candidate(nums = [-100, 100, -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]) == 100\n assert candidate(nums = [200, -200, 150, -150, 100, -100, 50, -50, 25, -25, 10, -10, 5, -5, 1, -1]) == 200\n assert candidate(nums = [-500, 500, -250, 250, -125, 125, -62, 62, -31, 31, -15, 15, -7, 7, -3, 3, -1, 1]) == 500\n assert candidate(nums = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 100\n assert candidate(nums = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000]) == 1000\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, 11, -12, 12, -13, 13, -14, 14, -15, 15]) == 15\n assert candidate(nums = [-500, 500, 250, -250, 100, -100, 50, -50, 10, -10]) == 500\n assert candidate(nums = [-500, -400, -300, -200, -100, 100, 200, 300, 400, 500, -1, 1]) == 500\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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, 11, 12, 13, 14, 15, -11, -12, -13, -14, -15, 16, 17, 18, 19, 20, -16, -17, -18, -19, -20]) == 20\n assert candidate(nums = [10, 20, 30, 40, -10, -20, -30, 50, 60, -50, -60, 70, 80, -70, -80, 90, -90, 100, -100]) == 100\n assert candidate(nums = [999, -999, 998, -998, 997, -997, 996, -996, 995, -995, 994, -994, 993, -993, 992, -992, 991, -991, 990, -990]) == 999\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]) == 12\n assert candidate(nums = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30]) == 30\n assert candidate(nums = [1, -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]) == 29\n assert candidate(nums = [-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]) == 15\n assert candidate(nums = [-999, 999, -998, 998, -997, 997, -996, 996, -995, 995]) == 999\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, 22, -22, 23, -23, 24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30]) == 30\n assert candidate(nums = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40]) == 40\n assert candidate(nums = [5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30, 35, -35, 40, -40, 45, -45]) == 45\n assert candidate(nums = [-500, 500, -499, 499, -498, 498, -497, 497, -496, 496, -495, 495]) == 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, 21, -21, 22, -22, 23, -23, 24, -24, 25, -25]) == 25\n assert candidate(nums = [-1, -2, -3, -4, -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -1\n assert candidate(nums = [77, -77, 66, -66, 55, -55, 44, -44, 33, -33, 22, -22, 11, -11, 1, -1]) == 77\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 = [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]) == 65\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1]) == 19\n assert candidate(nums = [-1000, 1000, -999, 999, -998, 998, -997, 997, -996, 996]) == 1000\n assert candidate(nums = [-100, 100, -200, 200, -300, 300, -400, 400, -500, 500, 600, -600, 700, -700, 800, -800, 900, -900]) == 900\n assert candidate(nums = [-23, 23, -45, 45, -67, 67, -89, 89, 101, -101, 123, -123, 145, -145, 167, -167, 189, -189]) == 189\n", "comparison": "exact"}, "public_tests": ["[-1,2,-3,3]", "[-1,10,6,7,-7,1]", "[-10,8,6,7,-2,-3]"], "hints": ["What data structure can help you to determine if an element exists?", "Would a hash table help?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().findMaxK", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:54+00:00", "tests_total": 116, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "sorting"]}, "language": "php", "interface": {"raw_signature": "function findMaxK($nums) {", "container": "Solution", "callable": "findMaxK", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2442, "task_id": "count-number-of-distinct-integers-after-reverse-operations", "difficulty": "Medium", "problem_description": "You are given an array nums consisting of positive integers.\n\nYou have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.\n\nReturn the number of distinct integers in the final array.\n\nExample 1:\n\nInput: nums = [1,13,10,12,31]\nOutput: 6\nExplanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].\nThe reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.\nThe number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).\n\nExample 2:\n\nInput: nums = [2,2,2]\nOutput: 1\nExplanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].\nThe number of distinct integers in this array is 1 (The number 2).\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 = [2, 2, 2]) == 1\n assert candidate(nums = [123, 321, 111, 222]) == 4\n assert candidate(nums = [100, 200, 300, 400]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 9\n assert candidate(nums = [9, 99, 999, 9999]) == 4\n assert candidate(nums = [987, 654, 321]) == 6\n assert candidate(nums = [111, 222, 333, 444, 555]) == 5\n assert candidate(nums = [123, 321, 456, 654]) == 4\n assert candidate(nums = [100, 200, 300]) == 6\n assert candidate(nums = [120, 210, 130, 310]) == 8\n assert candidate(nums = [111, 222, 333, 444]) == 4\n assert candidate(nums = [1, 13, 10, 12, 31]) == 6\n assert candidate(nums = [123, 321, 111, 456, 654]) == 5\n assert candidate(nums = [123456, 654321, 111222, 222111, 101010, 100100, 200200, 300300, 400400]) == 14\n assert candidate(nums = [123456, 654321, 112233, 332211, 445566, 665544, 778899, 998877]) == 8\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1001, 2002, 3003]) == 12\n assert candidate(nums = [10001, 20002, 30003, 40004, 50005, 111111, 222222, 333333, 444444, 555555]) == 10\n assert candidate(nums = [999, 998, 997, 996, 995, 994]) == 11\n assert candidate(nums = [987654, 456789, 876543, 345678, 765432, 234567]) == 6\n assert candidate(nums = [987654, 456789, 123, 321, 111, 222, 333]) == 7\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) == 27\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == 9\n assert candidate(nums = [101010, 202020, 303030, 404040, 505050]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 18\n assert candidate(nums = [100001, 200002, 300003, 400004, 500005, 600006, 700007, 800008, 900009]) == 9\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 111, 222, 333, 444, 555, 666]) == 12\n assert candidate(nums = [123, 321, 120, 210, 102, 201, 213, 312, 132, 321]) == 12\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007]) == 7\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210]) == 10\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005]) == 5\n assert candidate(nums = [1, 12, 123, 1234, 12345]) == 9\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000]) == 7\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]) == 24\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 9\n assert candidate(nums = [999999, 111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888]) == 9\n assert candidate(nums = [123, 231, 312, 132, 213, 321]) == 6\n assert candidate(nums = [123, 321, 456, 654, 789, 987, 101, 202, 303]) == 9\n assert candidate(nums = [123, 321, 120, 210, 102, 201, 132, 231, 312, 321, 123, 213]) == 12\n assert candidate(nums = [100000, 20000, 3000, 400, 50]) == 10\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555, 444444, 333333, 222222, 111111]) == 9\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900]) == 18\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098]) == 14\n assert candidate(nums = [123456, 234567, 345678, 456789, 567890]) == 10\n assert candidate(nums = [12345, 54321, 11223, 32211, 11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999]) == 13\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210, 432109, 321098, 210987, 109876]) == 18\n assert candidate(nums = [123, 321, 132, 213, 231, 312, 456, 654, 465, 546, 564, 645]) == 12\n assert candidate(nums = [987654, 456789, 111222, 222111, 333444]) == 6\n assert candidate(nums = [12, 21, 13, 31, 14, 41, 15, 51, 16, 61, 17, 71, 18, 81, 19, 91]) == 16\n assert candidate(nums = [100200, 200100, 101010, 110110, 202020, 220220, 303030, 330330, 404040]) == 18\n assert candidate(nums = [123, 321, 213, 132, 312, 231]) == 6\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111, 123, 321, 132, 213, 231, 312]) == 15\n assert candidate(nums = [12345, 54321, 11111, 22222, 33333]) == 5\n assert candidate(nums = [101, 110, 202, 220, 303, 330]) == 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]) == 28\n assert candidate(nums = [123456, 654321, 111111, 222222, 333333]) == 5\n assert candidate(nums = [123321, 234432, 345543, 456654, 567765]) == 5\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005]) == 5\n assert candidate(nums = [123456, 654321, 111222, 222111, 1001]) == 5\n assert candidate(nums = [123456, 654321, 112233, 332211, 987654]) == 6\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 202, 303, 404, 505, 606, 707, 808, 909, 110, 210, 310, 410, 510]) == 27\n assert candidate(nums = [1234, 4321, 1122, 2211, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]) == 13\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000]) == 10\n assert candidate(nums = [100, 101, 102, 103, 104, 105]) == 11\n assert candidate(nums = [10101, 20202, 30303, 40404, 50505, 11111, 22222, 33333, 44444, 55555]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [9, 99, 999, 9999, 99999, 999999]) == 6\n assert candidate(nums = [987654, 456789, 876543, 345678]) == 4\n assert candidate(nums = [12345, 54321, 11122, 22111, 33344, 44333, 55556, 65555, 76543, 34567]) == 10\n assert candidate(nums = [10, 100, 1000, 10000, 100000, 1000000]) == 7\n assert candidate(nums = [100000, 100001, 100010, 100100, 101000]) == 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]) == 28\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000]) == 21\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555]) == 5\n assert candidate(nums = [999999, 888888, 777777, 666666, 555555]) == 5\n assert candidate(nums = [111222, 222333, 333444, 444555, 555666]) == 10\n assert candidate(nums = [123, 321, 213, 132, 312, 231, 456, 654, 546, 465, 645, 564]) == 12\n assert candidate(nums = [1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009]) == 9\n assert candidate(nums = [999, 888, 777, 666, 555, 444, 333, 222, 111, 1001, 2002, 3003, 4004, 5005]) == 14\n assert candidate(nums = [987654, 876543, 765432, 654321, 543210]) == 10\n assert candidate(nums = [123456, 654321, 111222, 222111]) == 4\n assert candidate(nums = [100021, 123456, 789012, 321654, 210987]) == 8\n assert candidate(nums = [123456, 654321, 111111, 222222, 333333, 444444]) == 6\n assert candidate(nums = [987654, 456789, 987653, 356789, 987652, 256789, 987651, 156789, 987643]) == 10\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000]) == 10\n assert candidate(nums = [101010, 202020, 303030, 404040, 505050]) == 10\n assert candidate(nums = [100001, 200002, 300003, 400004, 500005]) == 5\n assert candidate(nums = [123456, 654321, 112233, 332211, 445566]) == 6\n assert candidate(nums = [123456, 654321, 111222, 222111, 101010]) == 6\n assert candidate(nums = [12345, 54321, 11122, 22111, 33344, 44333, 55566, 66555, 77788, 88777]) == 10\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000]) == 10\n assert candidate(nums = [10001, 10010, 10100, 11000, 10001]) == 7\n assert candidate(nums = [12, 21, 101, 110, 1001, 1010, 1100, 2002, 2020, 2200]) == 13\n assert candidate(nums = [100, 200, 300, 400, 500, 101, 202, 303, 404, 505]) == 15\n assert candidate(nums = [111111, 222222, 333333, 444444, 555555]) == 5\n assert candidate(nums = [1234, 4321, 1122, 2211, 1331, 1133, 2442, 2244, 4224, 4422]) == 11\n assert candidate(nums = [9, 98, 987, 9876, 98765]) == 9\n", "comparison": "exact"}, "public_tests": ["[1,13,10,12,31]", "[2,2,2]"], "hints": ["What data structure allows us to insert numbers and find the number of distinct numbers in it?", "Try using a set, insert all the numbers and their reverse into it, and return its size."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countDistinctIntegers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:56+00:00", "tests_total": 103, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "math", "counting"]}, "language": "php", "interface": {"raw_signature": "function countDistinctIntegers($nums) {", "container": "Solution", "callable": "countDistinctIntegers", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2443, "task_id": "sum-of-number-and-its-reverse", "difficulty": "Medium", "problem_description": "Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.\n\nExample 1:\n\nInput: num = 443\nOutput: true\nExplanation: 172 + 271 = 443 so we return true.\n\nExample 2:\n\nInput: num = 63\nOutput: false\nExplanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.\n\nExample 3:\n\nInput: num = 181\nOutput: true\nExplanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.\n\nConstraints:\n\n- 0 <= num <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(num = 443) == True\n assert candidate(num = 181) == True\n assert candidate(num = 99999) == False\n assert candidate(num = 1001) == True\n assert candidate(num = 0) == True\n assert candidate(num = 63) == False\n assert candidate(num = 1000) == False\n assert candidate(num = 121) == True\n assert candidate(num = 100) == False\n assert candidate(num = 123) == False\n assert candidate(num = 100000) == False\n assert candidate(num = 696) == False\n assert candidate(num = 1101) == False\n assert candidate(num = 999) == False\n assert candidate(num = 67876) == True\n assert candidate(num = 727) == True\n assert candidate(num = 454) == False\n assert candidate(num = 6789) == False\n assert candidate(num = 929) == True\n assert candidate(num = 1202) == False\n assert candidate(num = 767) == True\n assert candidate(num = 646) == True\n assert candidate(num = 1230) == False\n assert candidate(num = 67890) == False\n assert candidate(num = 808) == True\n assert candidate(num = 131) == False\n assert candidate(num = 303) == True\n assert candidate(num = 535) == False\n assert candidate(num = 12345) == False\n assert candidate(num = 606) == True\n assert candidate(num = 12321) == False\n assert candidate(num = 252) == False\n assert candidate(num = 474) == False\n assert candidate(num = 343) == True\n assert candidate(num = 434) == False\n assert candidate(num = 868) == True\n assert candidate(num = 56789) == False\n assert candidate(num = 171) == False\n assert candidate(num = 797) == False\n assert candidate(num = 22222) == True\n assert candidate(num = 101) == True\n assert candidate(num = 8008) == True\n assert candidate(num = 86420) == False\n assert candidate(num = 50005) == True\n assert candidate(num = 666) == True\n assert candidate(num = 939) == False\n assert candidate(num = 585) == True\n assert candidate(num = 2002) == True\n assert candidate(num = 393) == False\n assert candidate(num = 222) == True\n assert candidate(num = 98765) == False\n assert candidate(num = 151) == False\n assert candidate(num = 99009) == False\n assert candidate(num = 11) == True\n assert candidate(num = 959) == False\n assert candidate(num = 5050) == False\n assert candidate(num = 8228) == True\n assert candidate(num = 414) == False\n assert candidate(num = 67676) == True\n assert candidate(num = 898) == False\n assert candidate(num = 292) == False\n assert candidate(num = 878) == False\n assert candidate(num = 1331) == True\n assert candidate(num = 89898) == True\n assert candidate(num = 141) == True\n assert candidate(num = 80708) == False\n assert candidate(num = 191) == False\n assert candidate(num = 55555) == False\n assert candidate(num = 282) == True\n assert candidate(num = 575) == False\n assert candidate(num = 919) == False\n assert candidate(num = 848) == True\n assert candidate(num = 6006) == True\n assert candidate(num = 828) == True\n assert candidate(num = 262) == True\n assert candidate(num = 272) == False\n assert candidate(num = 353) == False\n assert candidate(num = 818) == False\n assert candidate(num = 525) == True\n assert candidate(num = 9) == False\n assert candidate(num = 979) == False\n assert candidate(num = 424) == True\n assert candidate(num = 99990) == False\n assert candidate(num = 616) == False\n assert candidate(num = 707) == True\n assert candidate(num = 66666) == True\n assert candidate(num = 595) == False\n assert candidate(num = 88888) == True\n assert candidate(num = 1221) == True\n assert candidate(num = 323) == True\n assert candidate(num = 555) == False\n assert candidate(num = 383) == True\n assert candidate(num = 888) == True\n assert candidate(num = 757) == False\n assert candidate(num = 636) == False\n assert candidate(num = 313) == False\n assert candidate(num = 464) == True\n assert candidate(num = 494) == False\n assert candidate(num = 717) == False\n assert candidate(num = 7007) == True\n assert candidate(num = 686) == True\n assert candidate(num = 9009) == True\n assert candidate(num = 60006) == True\n assert candidate(num = 20202) == True\n assert candidate(num = 24680) == False\n assert candidate(num = 737) == False\n assert candidate(num = 8888) == True\n assert candidate(num = 1) == False\n assert candidate(num = 1010) == True\n assert candidate(num = 545) == True\n assert candidate(num = 656) == False\n assert candidate(num = 909) == True\n assert candidate(num = 565) == True\n assert candidate(num = 232) == False\n assert candidate(num = 54321) == False\n assert candidate(num = 98789) == False\n assert candidate(num = 45454) == True\n assert candidate(num = 50505) == False\n assert candidate(num = 11111) == False\n assert candidate(num = 90000) == False\n assert candidate(num = 45654) == True\n assert candidate(num = 78987) == False\n assert candidate(num = 676) == False\n assert candidate(num = 505) == True\n assert candidate(num = 363) == True\n assert candidate(num = 949) == True\n assert candidate(num = 1020) == False\n assert candidate(num = 838) == False\n assert candidate(num = 161) == True\n assert candidate(num = 33333) == False\n assert candidate(num = 626) == True\n assert candidate(num = 444) == True\n assert candidate(num = 13579) == False\n assert candidate(num = 787) == True\n assert candidate(num = 202) == True\n assert candidate(num = 75309) == False\n assert candidate(num = 373) == False\n assert candidate(num = 333) == False\n assert candidate(num = 22) == True\n assert candidate(num = 50000) == False\n assert candidate(num = 404) == True\n assert candidate(num = 13531) == False\n assert candidate(num = 989) == True\n assert candidate(num = 2022) == False\n assert candidate(num = 10101) == False\n assert candidate(num = 858) == False\n assert candidate(num = 111) == False\n assert candidate(num = 484) == True\n assert candidate(num = 515) == False\n assert candidate(num = 242) == True\n assert candidate(num = 50050) == False\n assert candidate(num = 777) == False\n assert candidate(num = 54545) == False\n assert candidate(num = 969) == True\n assert candidate(num = 747) == True\n assert candidate(num = 5005) == True\n assert candidate(num = 9999) == True\n assert candidate(num = 212) == False\n assert candidate(num = 10000) == False\n", "comparison": "exact"}, "public_tests": ["443", "63", "181"], "hints": ["The constraints are small enough that we can check every number.", "To reverse a number, first convert it to a string. Then, create a new string that is the reverse of the first one. Finally, convert the new string back into a number."], "metadata": {"canonical_parameter_names": ["num"], "leetcode_dataset_entry_point": "Solution().sumOfNumberAndReverse", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:52:58+00:00", "tests_total": 177, "tests_dropped": 18, "flags": [], "topic_tags": ["math", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function sumOfNumberAndReverse($num) {", "container": "Solution", "callable": "sumOfNumberAndReverse", "parameters": [{"name": "num", "type": "Integer"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2444, "task_id": "count-subarrays-with-fixed-bounds", "difficulty": "Hard", "problem_description": "You are given an integer array nums and two integers minK and maxK.\n\nA fixed-bound subarray of nums is a subarray that satisfies the following conditions:\n\n- The minimum value in the subarray is equal to minK.\n- The maximum value in the subarray is equal to maxK.\n\nReturn the number of fixed-bound subarrays.\n\nA subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [1,3,5,2,7,5], minK = 1, maxK = 5\nOutput: 2\nExplanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].\n\nExample 2:\n\nInput: nums = [1,1,1,1], minK = 1, maxK = 1\nOutput: 10\nExplanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 1 <= nums[i], minK, maxK <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5],minK = 2,maxK = 4) == 4\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9],minK = 3,maxK = 7) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 1,maxK = 10) == 1\n assert candidate(nums = [2, 4, 3, 2, 4, 6],minK = 2,maxK = 4) == 8\n assert candidate(nums = [10, 9, 8, 7, 6],minK = 6,maxK = 10) == 1\n assert candidate(nums = [1, 2, 3, 2, 1],minK = 1,maxK = 3) == 5\n assert candidate(nums = [10, 20, 30, 40, 50],minK = 10,maxK = 50) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],minK = 2,maxK = 5) == 4\n assert candidate(nums = [1, 2, 3, 4, 5],minK = 2,maxK = 4) == 1\n assert candidate(nums = [1, 3, 5, 2, 7, 5],minK = 1,maxK = 5) == 2\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],minK = 6,maxK = 6) == 55\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],minK = 1,maxK = 5) == 4\n assert candidate(nums = [5, 5, 5, 5, 5],minK = 5,maxK = 5) == 15\n assert candidate(nums = [5, 4, 3, 2, 1],minK = 2,maxK = 4) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],minK = 5,maxK = 5) == 55\n assert candidate(nums = [1, 1, 1, 1],minK = 1,maxK = 1) == 10\n assert candidate(nums = [2, 3, 5, 1, 5, 7, 5],minK = 1,maxK = 5) == 7\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 2,maxK = 9) == 1\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 2,maxK = 8) == 1\n assert candidate(nums = [2, 1, 5, 1, 3, 5, 4, 2],minK = 1,maxK = 5) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],minK = 5,maxK = 20) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5],minK = 1,maxK = 5) == 108\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],minK = 2,maxK = 2) == 210\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],minK = 2,maxK = 9) == 3\n assert candidate(nums = [6, 2, 5, 3, 4, 2, 3, 2, 2, 3, 5, 4, 3, 2, 1],minK = 2,maxK = 5) == 47\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],minK = 2,maxK = 2) == 120\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1],minK = 1,maxK = 3) == 39\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],minK = 7,maxK = 7) == 120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10],minK = 1,maxK = 10) == 38\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],minK = 3,maxK = 12) == 1\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8],minK = 3,maxK = 5) == 3\n assert candidate(nums = [10, 7, 5, 3, 2, 2, 5, 7, 10],minK = 2,maxK = 7) == 8\n assert candidate(nums = [3, 1, 5, 4, 2, 5, 1, 3, 4],minK = 1,maxK = 5) == 26\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],minK = 3,maxK = 3) == 210\n assert candidate(nums = [7, 9, 5, 6, 3, 1, 8, 4, 2, 5],minK = 3,maxK = 7) == 0\n assert candidate(nums = [7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10],minK = 7,maxK = 10) == 246\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],minK = 1,maxK = 8) == 225\n assert candidate(nums = [5, 3, 3, 3, 1, 4, 5, 5, 2, 5],minK = 1,maxK = 5) == 22\n assert candidate(nums = [5, 3, 4, 5, 3, 5, 3, 4, 5, 3],minK = 3,maxK = 5) == 41\n assert candidate(nums = [1, 5, 3, 5, 2, 3, 5, 1, 2, 5],minK = 1,maxK = 5) == 28\n assert candidate(nums = [6, 4, 5, 1, 2, 3, 1, 5, 4, 6, 1, 2, 3, 1, 5, 4, 6, 1, 2, 3, 1, 5, 4, 6],minK = 1,maxK = 5) == 36\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 5, 3, 2, 1, 4, 5, 6, 7, 8, 9],minK = 2,maxK = 8) == 0\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],minK = 5,maxK = 10) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 2, 2, 1, 1],minK = 1,maxK = 3) == 20\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],minK = 10,maxK = 15) == 1\n assert candidate(nums = [7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 1,maxK = 7) == 9\n assert candidate(nums = [10, 20, 10, 20, 30, 10, 20, 10],minK = 10,maxK = 20) == 9\n assert candidate(nums = [1, 5, 4, 5, 1, 1, 5, 2, 1, 3, 4, 5],minK = 1,maxK = 5) == 53\n assert candidate(nums = [7, 3, 3, 5, 7, 3, 5, 7, 3, 5],minK = 3,maxK = 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],minK = 1,maxK = 1) == 210\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],minK = 4,maxK = 12) == 1\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],minK = 2,maxK = 4) == 2\n assert candidate(nums = [5, 4, 5, 3, 5, 4, 5, 2, 5, 4, 5, 3, 5, 4, 5, 1, 5, 4, 5, 3],minK = 1,maxK = 5) == 79\n assert candidate(nums = [1, 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1],minK = 1,maxK = 3) == 103\n assert candidate(nums = [5, 3, 1, 4, 5, 2, 3, 4, 5, 2, 1, 4, 5, 3, 2, 1, 5],minK = 1,maxK = 5) == 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],minK = 2,maxK = 6) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],minK = 2,maxK = 5) == 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, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 1,maxK = 10) == 303\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 5, 6, 7, 8],minK = 5,maxK = 8) == 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],minK = 1,maxK = 10) == 102\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],minK = 8,maxK = 8) == 210\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7],minK = 3,maxK = 6) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 1],minK = 1,maxK = 10) == 21\n assert candidate(nums = [1, 5, 3, 5, 2, 3, 1, 5, 2],minK = 1,maxK = 5) == 23\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],minK = 2,maxK = 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, 10],minK = 3,maxK = 7) == 2\n assert candidate(nums = [5, 5, 3, 5, 2, 3, 3, 5, 3, 3, 5, 3, 2, 5, 5, 3, 3, 5, 5, 5],minK = 2,maxK = 5) == 139\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],minK = 1,maxK = 5) == 154\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5],minK = 1,maxK = 5) == 106\n assert candidate(nums = [1, 3, 5, 3, 1, 5, 3, 1, 5, 3, 1, 5, 3, 1, 5, 3, 1, 5, 3, 1],minK = 1,maxK = 5) == 175\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32],minK = 6,maxK = 24) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160],minK = 10,maxK = 150) == 1\n assert candidate(nums = [7, 8, 9, 10, 7, 8, 9, 10, 7, 8],minK = 7,maxK = 10) == 34\n assert candidate(nums = [7, 3, 5, 1, 5, 2, 5, 5, 2, 5, 1, 5, 3, 7],minK = 1,maxK = 7) == 21\n assert candidate(nums = [2, 1, 3, 3, 2, 3, 1, 2, 3, 2, 1, 2, 3],minK = 1,maxK = 3) == 63\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],minK = 1,maxK = 5) == 312\n assert candidate(nums = [1, 3, 1, 3, 5, 1, 3, 5, 2, 5, 3, 2, 3, 1, 2, 3, 5, 1, 3, 5, 2, 5],minK = 1,maxK = 5) == 181\n assert candidate(nums = [100, 200, 100, 300, 200, 100, 300, 200, 100],minK = 100,maxK = 300) == 29\n assert candidate(nums = [9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1, 2, 4, 6, 8],minK = 3,maxK = 9) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 2, 3, 4, 5],minK = 2,maxK = 5) == 9\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 3,maxK = 8) == 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],minK = 5,maxK = 6) == 190\n assert candidate(nums = [2, 4, 2, 1, 5, 4, 2, 3, 5, 1],minK = 1,maxK = 5) == 29\n assert candidate(nums = [8, 7, 6, 7, 8, 9, 10, 9, 8, 7, 6, 7, 8, 9],minK = 6,maxK = 9) == 10\n assert candidate(nums = [3, 6, 3, 7, 3, 5, 3, 4, 3, 3],minK = 3,maxK = 7) == 27\n assert candidate(nums = [5, 1, 3, 5, 7, 5, 3, 1, 5],minK = 1,maxK = 5) == 8\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],minK = 1,maxK = 2) == 45\n assert candidate(nums = [5, 1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5],minK = 1,maxK = 5) == 110\n assert candidate(nums = [1, 5, 3, 5, 3, 5, 3, 5, 3, 1],minK = 1,maxK = 5) == 16\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],minK = 3,maxK = 7) == 1\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],minK = 6,maxK = 6) == 55\n assert candidate(nums = [2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4],minK = 2,maxK = 4) == 120\n assert candidate(nums = [1000000, 999999, 1000000, 999999, 1000000, 999999, 1000000],minK = 999999,maxK = 1000000) == 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],minK = 5,maxK = 10) == 4\n assert candidate(nums = [2, 1, 5, 3, 5, 1, 5, 2, 5, 1, 5, 3, 2, 1],minK = 1,maxK = 5) == 79\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],minK = 3,maxK = 8) == 2\n assert candidate(nums = [2, 1, 3, 4, 5, 1, 5, 2],minK = 1,maxK = 5) == 19\n assert candidate(nums = [3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 5, 5, 5, 5],minK = 1,maxK = 5) == 48\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 5, 4, 3, 2, 1, 3, 5, 2, 4, 6, 5, 4, 3, 2, 1],minK = 2,maxK = 5) == 10\n assert candidate(nums = [5, 3, 1, 3, 1, 5, 3, 1, 3, 1, 5, 3, 1, 3, 1],minK = 1,maxK = 5) == 84\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, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5],minK = 5,maxK = 10) == 3\n assert candidate(nums = [1, 2, 2, 3, 4, 3, 5, 2, 3, 4, 5, 3, 4, 5, 3, 4, 2, 3, 4, 5, 3, 4, 2, 5, 3, 4, 5],minK = 2,maxK = 5) == 256\n assert candidate(nums = [6, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1],minK = 2,maxK = 5) == 4\n assert candidate(nums = [5, 1, 2, 3, 4, 5, 6, 7, 8, 9],minK = 5,maxK = 9) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4],minK = 1,maxK = 4) == 75\n assert candidate(nums = [2, 1, 5, 3, 4, 2, 1, 5, 3, 4, 2, 1, 5, 3, 4],minK = 1,maxK = 5) == 83\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 1, 5, 2, 5, 3, 5, 4, 5, 1, 5, 2],minK = 1,maxK = 5) == 147\n assert candidate(nums = [1, 5, 3, 4, 2, 1, 5, 4, 3, 2],minK = 2,maxK = 5) == 2\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1],minK = 1,maxK = 5) == 51\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],minK = 3,maxK = 7) == 4\n assert candidate(nums = [1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000, 1, 1000000],minK = 1,maxK = 1000000) == 66\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],minK = 1,maxK = 4) == 46\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4],minK = 2,maxK = 4) == 8\n", "comparison": "exact"}, "public_tests": ["[1,3,5,2,7,5]\n1\n5", "[1,1,1,1]\n1\n1"], "hints": ["Can you solve the problem if all the numbers in the array were between minK and maxK inclusive?", "Think of the inclusion-exclusion principle.", "Divide the array into multiple subarrays such that each number in each subarray is between minK and maxK inclusive, solve the previous problem for each subarray, and sum all the answers."], "metadata": {"canonical_parameter_names": ["nums", "minK", "maxK"], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:00+00:00", "tests_total": 116, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "queue", "sliding-window", "monotonic-queue"]}, "language": "php", "interface": {"raw_signature": "function countSubarrays($nums, $minK, $maxK) {", "container": "Solution", "callable": "countSubarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "minK", "type": "Integer"}, {"name": "maxK", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2446, "task_id": "determine-if-two-events-have-conflict", "difficulty": "Easy", "problem_description": "You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:\n\n- event1 = [startTime_1, endTime_1] and\n- event2 = [startTime_2, endTime_2].\n\nEvent times are valid 24 hours format in the form of HH:MM.\n\nA conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).\n\nReturn true if there is a conflict between two events. Otherwise, return false.\n\nExample 1:\n\nInput: event1 = [\"01:15\",\"02:00\"], event2 = [\"02:00\",\"03:00\"]\nOutput: true\nExplanation: The two events intersect at time 2:00.\n\nExample 2:\n\nInput: event1 = [\"01:00\",\"02:00\"], event2 = [\"01:20\",\"03:00\"]\nOutput: true\nExplanation: The two events intersect starting from 01:20 to 02:00.\n\nExample 3:\n\nInput: event1 = [\"10:00\",\"11:00\"], event2 = [\"14:00\",\"15:00\"]\nOutput: false\nExplanation: The two events do not intersect.\n\nConstraints:\n\n- event1.length == event2.length == 2\n- event1[i].length == event2[i].length == 5\n- startTime_1 <= endTime_1\n- startTime_2 <= endTime_2\n- All the event times follow the HH:MM format.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(event1 = ['10:00', '11:00'],event2 = ['14:00', '15:00']) == False\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:01']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:00']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '12:30']) == True\n assert candidate(event1 = ['01:15', '02:00'],event2 = ['02:00', '03:00']) == True\n assert candidate(event1 = ['09:30', '10:30'],event2 = ['10:00', '11:00']) == True\n assert candidate(event1 = ['05:45', '06:45'],event2 = ['06:45', '07:45']) == True\n assert candidate(event1 = ['08:00', '09:00'],event2 = ['07:00', '08:30']) == True\n assert candidate(event1 = ['23:59', '23:59'],event2 = ['23:59', '23:59']) == True\n assert candidate(event1 = ['13:00', '15:00'],event2 = ['14:00', '16:00']) == True\n assert candidate(event1 = ['12:00', '12:30'],event2 = ['12:15', '12:45']) == True\n assert candidate(event1 = ['01:00', '02:00'],event2 = ['01:20', '03:00']) == True\n assert candidate(event1 = ['13:00', '14:00'],event2 = ['14:00', '15:00']) == True\n assert candidate(event1 = ['09:00', '09:30'],event2 = ['09:30', '10:00']) == True\n assert candidate(event1 = ['16:00', '17:00'],event2 = ['16:30', '17:30']) == True\n assert candidate(event1 = ['12:00', '13:00'],event2 = ['12:30', '13:30']) == True\n assert candidate(event1 = ['13:30', '15:30'],event2 = ['14:00', '16:00']) == True\n assert candidate(event1 = ['08:00', '09:00'],event2 = ['09:00', '10:00']) == True\n assert candidate(event1 = ['12:00', '13:00'],event2 = ['13:00', '14:00']) == True\n assert candidate(event1 = ['00:01', '23:59'],event2 = ['12:00', '12:01']) == True\n assert candidate(event1 = ['12:00', '12:00'],event2 = ['12:00', '12:00']) == True\n assert candidate(event1 = ['22:00', '23:00'],event2 = ['21:30', '22:30']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['01:00', '02:00']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:00', '13:00']) == True\n assert candidate(event1 = ['05:30', '06:00'],event2 = ['05:45', '06:15']) == True\n assert candidate(event1 = ['01:00', '02:00'],event2 = ['00:59', '01:01']) == True\n assert candidate(event1 = ['08:00', '09:00'],event2 = ['08:00', '08:30']) == True\n assert candidate(event1 = ['23:55', '00:10'],event2 = ['23:45', '00:05']) == False\n assert candidate(event1 = ['09:00', '17:00'],event2 = ['08:30', '09:30']) == True\n assert candidate(event1 = ['14:00', '16:00'],event2 = ['15:30', '17:00']) == True\n assert candidate(event1 = ['15:00', '16:00'],event2 = ['14:00', '15:30']) == True\n assert candidate(event1 = ['14:00', '15:00'],event2 = ['13:00', '14:00']) == True\n assert candidate(event1 = ['23:59', '00:01'],event2 = ['00:00', '00:01']) == False\n assert candidate(event1 = ['00:00', '11:59'],event2 = ['12:00', '23:59']) == False\n assert candidate(event1 = ['09:45', '10:45'],event2 = ['10:30', '11:30']) == True\n assert candidate(event1 = ['05:00', '07:00'],event2 = ['06:00', '06:59']) == True\n assert candidate(event1 = ['23:59', '23:59'],event2 = ['23:59', '00:00']) == False\n assert candidate(event1 = ['08:00', '09:00'],event2 = ['08:00', '08:59']) == True\n assert candidate(event1 = ['07:30', '08:00'],event2 = ['07:45', '08:15']) == True\n assert candidate(event1 = ['09:00', '18:00'],event2 = ['17:59', '18:01']) == True\n assert candidate(event1 = ['06:00', '07:00'],event2 = ['06:00', '06:59']) == True\n assert candidate(event1 = ['00:01', '00:59'],event2 = ['00:30', '01:00']) == True\n assert candidate(event1 = ['23:30', '00:30'],event2 = ['23:00', '23:59']) == False\n assert candidate(event1 = ['09:30', '10:15'],event2 = ['10:00', '10:45']) == True\n assert candidate(event1 = ['13:00', '14:00'],event2 = ['13:45', '14:45']) == True\n assert candidate(event1 = ['11:00', '13:00'],event2 = ['12:30', '14:00']) == True\n assert candidate(event1 = ['14:30', '15:30'],event2 = ['15:00', '16:00']) == True\n assert candidate(event1 = ['20:00', '21:00'],event2 = ['19:00', '20:00']) == True\n assert candidate(event1 = ['11:00', '12:00'],event2 = ['09:00', '10:59']) == False\n assert candidate(event1 = ['11:59', '23:59'],event2 = ['23:59', '00:00']) == False\n assert candidate(event1 = ['09:00', '09:00'],event2 = ['09:00', '09:00']) == True\n assert candidate(event1 = ['08:30', '09:45'],event2 = ['09:30', '10:30']) == True\n assert candidate(event1 = ['07:15', '07:45'],event2 = ['07:45', '08:15']) == True\n assert candidate(event1 = ['09:30', '10:30'],event2 = ['10:00', '10:00']) == True\n assert candidate(event1 = ['00:00', '00:01'],event2 = ['00:00', '00:02']) == True\n assert candidate(event1 = ['18:30', '19:00'],event2 = ['19:00', '19:30']) == True\n assert candidate(event1 = ['14:45', '15:15'],event2 = ['15:15', '15:45']) == True\n assert candidate(event1 = ['17:45', '18:15'],event2 = ['18:15', '18:45']) == True\n assert candidate(event1 = ['03:00', '04:00'],event2 = ['02:30', '03:30']) == True\n assert candidate(event1 = ['01:00', '02:00'],event2 = ['23:59', '01:30']) == False\n assert candidate(event1 = ['18:00', '19:00'],event2 = ['17:30', '18:00']) == True\n assert candidate(event1 = ['08:30', '09:30'],event2 = ['09:00', '09:15']) == True\n assert candidate(event1 = ['08:30', '09:30'],event2 = ['09:00', '09:30']) == True\n assert candidate(event1 = ['08:00', '09:00'],event2 = ['07:59', '08:01']) == True\n assert candidate(event1 = ['14:00', '15:00'],event2 = ['13:59', '14:01']) == True\n assert candidate(event1 = ['11:45', '12:15'],event2 = ['12:15', '12:45']) == True\n assert candidate(event1 = ['05:30', '06:30'],event2 = ['06:20', '07:20']) == True\n assert candidate(event1 = ['00:00', '24:00'],event2 = ['00:00', '24:00']) == True\n assert candidate(event1 = ['13:30', '14:30'],event2 = ['14:30', '15:30']) == True\n assert candidate(event1 = ['08:45', '09:45'],event2 = ['09:45', '10:45']) == True\n assert candidate(event1 = ['13:45', '14:45'],event2 = ['14:45', '15:45']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['12:30', '13:30']) == True\n assert candidate(event1 = ['13:15', '14:45'],event2 = ['14:00', '15:30']) == True\n assert candidate(event1 = ['09:00', '17:00'],event2 = ['10:00', '15:00']) == True\n assert candidate(event1 = ['06:00', '06:59'],event2 = ['07:00', '08:00']) == False\n assert candidate(event1 = ['22:00', '22:59'],event2 = ['22:59', '23:59']) == True\n assert candidate(event1 = ['11:00', '13:00'],event2 = ['12:00', '14:00']) == True\n assert candidate(event1 = ['17:00', '18:00'],event2 = ['16:30', '17:00']) == True\n assert candidate(event1 = ['03:00', '04:00'],event2 = ['03:59', '04:01']) == True\n assert candidate(event1 = ['06:00', '07:00'],event2 = ['05:59', '06:01']) == True\n assert candidate(event1 = ['23:55', '23:59'],event2 = ['23:56', '00:05']) == False\n assert candidate(event1 = ['23:45', '23:59'],event2 = ['23:50', '00:10']) == False\n assert candidate(event1 = ['15:30', '16:30'],event2 = ['15:00', '15:30']) == True\n assert candidate(event1 = ['09:00', '17:00'],event2 = ['17:00', '18:00']) == True\n assert candidate(event1 = ['11:00', '11:01'],event2 = ['11:00', '11:01']) == True\n assert candidate(event1 = ['09:00', '17:00'],event2 = ['12:00', '13:00']) == True\n assert candidate(event1 = ['11:00', '11:30'],event2 = ['11:30', '12:00']) == True\n assert candidate(event1 = ['05:30', '06:00'],event2 = ['06:00', '06:30']) == True\n assert candidate(event1 = ['05:30', '06:30'],event2 = ['06:29', '07:30']) == True\n assert candidate(event1 = ['09:30', '10:30'],event2 = ['10:00', '10:15']) == True\n assert candidate(event1 = ['00:00', '23:59'],event2 = ['00:00', '23:59']) == True\n assert candidate(event1 = ['11:45', '12:45'],event2 = ['11:30', '11:45']) == True\n assert candidate(event1 = ['15:30', '15:30'],event2 = ['15:30', '15:30']) == True\n assert candidate(event1 = ['12:00', '13:00'],event2 = ['11:00', '12:59']) == True\n assert candidate(event1 = ['14:00', '15:00'],event2 = ['15:00', '16:00']) == True\n assert candidate(event1 = ['21:00', '22:00'],event2 = ['20:00', '21:00']) == True\n assert candidate(event1 = ['19:00', '20:00'],event2 = ['20:00', '21:00']) == True\n assert candidate(event1 = ['08:30', '09:15'],event2 = ['09:15', '10:00']) == True\n assert candidate(event1 = ['06:00', '07:00'],event2 = ['07:00', '08:00']) == True\n assert candidate(event1 = ['18:00', '19:00'],event2 = ['17:30', '18:30']) == True\n assert candidate(event1 = ['01:00', '02:00'],event2 = ['02:01', '03:00']) == False\n assert candidate(event1 = ['09:00', '10:00'],event2 = ['10:00', '11:00']) == True\n assert candidate(event1 = ['00:00', '12:00'],event2 = ['12:00', '23:59']) == True\n assert candidate(event1 = ['23:59', '00:01'],event2 = ['23:58', '00:00']) == False\n assert candidate(event1 = ['00:01', '23:59'],event2 = ['23:59', '00:01']) == True\n assert candidate(event1 = ['10:00', '10:30'],event2 = ['09:59', '10:01']) == True\n assert candidate(event1 = ['00:00', '00:01'],event2 = ['00:01', '00:02']) == True\n assert candidate(event1 = ['11:55', '12:05'],event2 = ['12:00', '12:10']) == True\n assert candidate(event1 = ['12:34', '12:34'],event2 = ['12:34', '12:34']) == True\n", "comparison": "exact"}, "public_tests": ["[\"01:15\",\"02:00\"]\n[\"02:00\",\"03:00\"]", "[\"01:00\",\"02:00\"]\n[\"01:20\",\"03:00\"]", "[\"10:00\",\"11:00\"]\n[\"14:00\",\"15:00\"]"], "hints": ["Parse time format to some integer interval first", "How would you determine if two intervals overlap?"], "metadata": {"canonical_parameter_names": ["event1", "event2"], "leetcode_dataset_entry_point": "Solution().haveConflict", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:05+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function haveConflict($event1, $event2) {", "container": "Solution", "callable": "haveConflict", "parameters": [{"name": "event1", "type": "String[]"}, {"name": "event2", "type": "String[]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2447, "task_id": "number-of-subarrays-with-gcd-equal-to-k", "difficulty": "Medium", "problem_description": "Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nThe greatest common divisor of an array is the largest integer that evenly divides all the array elements.\n\nExample 1:\n\nInput: nums = [9,3,1,2,6,3], k = 3\nOutput: 4\nExplanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]\n\nExample 2:\n\nInput: nums = [4], k = 7\nOutput: 0\nExplanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i], k <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50],k = 10) == 11\n assert candidate(nums = [7, 14, 21, 28, 35],k = 7) == 11\n assert candidate(nums = [5, 10, 15, 20, 25],k = 5) == 11\n assert candidate(nums = [9, 3, 1, 2, 6, 3],k = 3) == 4\n assert candidate(nums = [2, 4, 6, 8, 10],k = 2) == 11\n assert candidate(nums = [3, 9, 27, 81, 243],k = 3) == 5\n assert candidate(nums = [11, 22, 33, 44, 55],k = 11) == 11\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 11\n assert candidate(nums = [4],k = 7) == 0\n assert candidate(nums = [3, 6, 9, 12, 15],k = 3) == 11\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],k = 5) == 29\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909],k = 101) == 37\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],k = 101) == 46\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45],k = 5) == 37\n assert candidate(nums = [12, 15, 18, 21, 24, 27, 30, 33, 36, 39],k = 3) == 45\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160],k = 8) == 191\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72],k = 8) == 37\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 13) == 46\n assert candidate(nums = [15, 45, 75, 105, 135, 165, 195, 225],k = 15) == 29\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310, 341, 372, 403, 434, 465, 496, 527, 558, 589, 620],k = 31) == 191\n assert candidate(nums = [15, 30, 45, 60, 75, 90],k = 15) == 16\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 13) == 46\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],k = 1) == 5151\n assert candidate(nums = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1110, 1221, 1332, 1443, 1554, 1665, 1776, 1887, 1998, 2109, 2220],k = 111) == 191\n assert candidate(nums = [60, 120, 180, 240, 300],k = 60) == 11\n assert candidate(nums = [256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072],k = 256) == 10\n assert candidate(nums = [5, 15, 25, 35, 45, 55],k = 5) == 16\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 = 2) == 301\n assert candidate(nums = [54, 108, 162, 216, 270, 324, 378, 432, 486, 540, 594, 648, 702, 756, 810, 864, 918, 972, 1026, 1080],k = 54) == 191\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 100) == 55\n assert candidate(nums = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31],k = 1) == 45\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153],k = 17) == 37\n assert candidate(nums = [101, 202, 303, 404, 505, 606],k = 101) == 16\n assert candidate(nums = [44, 88, 132, 176, 220, 264, 308, 352, 396, 440, 484, 528, 572, 616, 660, 704, 748, 792, 836, 880, 924, 968, 1012, 1056, 1100],k = 44) == 301\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104],k = 13) == 29\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 46\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096],k = 8) == 10\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) == 191\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49],k = 7) == 22\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 46\n assert candidate(nums = [60, 120, 180, 240, 300],k = 60) == 11\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 = 1) == 300\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 7) == 46\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210, 231, 252, 273, 294, 315, 336, 357, 378, 399, 420],k = 21) == 191\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) == 191\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512],k = 1) == 10\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],k = 8) == 13\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108],k = 12) == 37\n assert candidate(nums = [15, 25, 35, 45, 55, 65],k = 5) == 15\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75],k = 5) == 29\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 2) == 46\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],k = 3) == 106\n assert candidate(nums = [987, 654, 321, 987, 654, 321, 987, 654, 321],k = 3) == 36\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121],k = 11) == 56\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170],k = 17) == 46\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 2) == 106\n assert candidate(nums = [81, 54, 27, 9, 3, 1],k = 3) == 5\n assert candidate(nums = [36, 72, 108, 144, 180, 216, 252, 288, 324, 360],k = 36) == 46\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540],k = 60) == 37\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 15) == 46\n assert candidate(nums = [72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360, 384, 408],k = 24) == 105\n assert candidate(nums = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105],k = 5) == 45\n assert candidate(nums = [45, 90, 135, 180, 225, 270, 315, 360, 405, 450],k = 45) == 46\n assert candidate(nums = [7, 14, 28, 56, 112],k = 7) == 5\n assert candidate(nums = [77, 154, 231, 308, 385, 462, 539, 616, 693, 770, 847, 924, 1001, 1078, 1155, 1232, 1309, 1386, 1463, 1540],k = 77) == 191\n assert candidate(nums = [36, 72, 108, 144, 180, 216, 252, 288, 324, 360],k = 36) == 46\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 5) == 46\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 21) == 46\n assert candidate(nums = [123456789, 987654321, 111222333, 222333444, 333444555],k = 9) == 7\n assert candidate(nums = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149],k = 1) == 45\n assert candidate(nums = [6, 12, 18, 24, 30],k = 6) == 11\n assert candidate(nums = [8, 12, 16, 20, 24, 28, 32],k = 4) == 21\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],k = 1000) == 11\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 = 5) == 191\n assert candidate(nums = [48, 64, 80, 96, 112, 128, 144, 160, 176, 192],k = 16) == 45\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 21) == 46\n assert candidate(nums = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500],k = 25) == 191\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170],k = 17) == 46\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 11) == 46\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 9) == 46\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 = 100) == 191\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420],k = 42) == 46\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024],k = 8) == 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],k = 5) == 191\n assert candidate(nums = [72, 48, 12, 18, 6, 120],k = 6) == 13\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000],k = 1000000) == 11\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) == 191\n assert candidate(nums = [7, 14, 28, 56, 112, 224],k = 7) == 6\n assert candidate(nums = [7, 14, 28, 56, 112, 224, 448, 896, 1792, 3584, 7168, 14336],k = 7) == 12\n assert candidate(nums = [33, 66, 99, 132, 165, 198, 231, 264, 297, 330, 363, 396, 429, 462, 495],k = 33) == 106\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 125000000) == 4\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512, 1024],k = 8) == 8\n assert candidate(nums = [12, 15, 21, 33, 48],k = 3) == 10\n assert candidate(nums = [99, 198, 297, 396, 495, 594, 693, 792],k = 99) == 29\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 272, 289, 306, 323, 340],k = 17) == 191\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135],k = 9) == 106\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91],k = 13) == 22\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105],k = 7) == 106\n assert candidate(nums = [42, 84, 126, 168, 210, 252, 294, 336, 378, 420, 462],k = 42) == 56\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108],k = 9) == 67\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],k = 2) == 1\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48],k = 6) == 29\n assert candidate(nums = [20, 40, 60, 80, 100, 120, 140],k = 20) == 22\n assert candidate(nums = [18, 27, 36, 45, 54, 63, 72, 81, 90],k = 9) == 36\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 46\n assert candidate(nums = [100, 200, 400, 800, 1600, 3200],k = 100) == 6\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],k = 1) == 15\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],k = 15) == 46\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540, 600],k = 60) == 46\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707],k = 101) == 22\n assert candidate(nums = [48, 64, 80, 96, 112, 128, 144, 160, 176, 192],k = 16) == 45\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210, 231, 252, 273, 294, 315, 336, 357, 378, 399, 420],k = 21) == 191\n assert candidate(nums = [21, 14, 42, 84, 28, 56, 112],k = 14) == 9\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30],k = 3) == 46\n assert candidate(nums = [81, 27, 9, 3, 1],k = 1) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 2) == 46\n assert candidate(nums = [100, 150, 200, 250, 300, 350],k = 50) == 15\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60],k = 6) == 46\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255],k = 17) == 106\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000],k = 62500000) == 5\n assert candidate(nums = [123, 246, 369, 492, 615, 738, 861, 984, 1107, 1230, 1353, 1476, 1599, 1722, 1845, 1968, 2091, 2214, 2337, 2460],k = 123) == 191\n assert candidate(nums = [999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937, 999999937],k = 999999937) == 55\n assert candidate(nums = [81, 27, 9, 3, 1, 243, 729],k = 3) == 4\n", "comparison": "exact"}, "public_tests": ["[9,3,1,2,6,3]\n3", "[4]\n7"], "hints": ["The constraints on nums.length are small. It is possible to check every subarray.", "To calculate GCD, you can use a built-in function or the Euclidean Algorithm."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().subarrayGCD", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:07+00:00", "tests_total": 124, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "math", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function subarrayGCD($nums, $k) {", "container": "Solution", "callable": "subarrayGCD", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2448, "task_id": "minimum-cost-to-make-array-equal", "difficulty": "Hard", "problem_description": "You are given two 0-indexed arrays nums and cost consisting each of n positive integers.\n\nYou can do the following operation any number of times:\n\n- Increase or decrease any element of the array nums by 1.\n\nThe cost of doing one operation on the i^th element is cost[i].\n\nReturn the minimum total cost such that all the elements of the array nums become equal.\n\nExample 1:\n\nInput: nums = [1,3,5,2], cost = [2,3,1,14]\nOutput: 8\nExplanation: We can make all the elements equal to 2 in the following way:\n- Increase the 0^th element one time. The cost is 2.\n- Decrease the 1^st element one time. The cost is 3.\n- Decrease the 2^nd element three times. The cost is 1 + 1 + 1 = 3.\nThe total cost is 2 + 3 + 3 = 8.\nIt can be shown that we cannot make the array equal with a smaller cost.\n\nExample 2:\n\nInput: nums = [2,2,2,2,2], cost = [4,2,8,1,3]\nOutput: 0\nExplanation: All the elements are already equal, so no operations are needed.\n\nConstraints:\n\n- n == nums.length == cost.length\n- 1 <= n <= 10^5\n- 1 <= nums[i], cost[i] <= 10^6\n- Test cases are generated in a way that the output doesn't exceed 2^53-1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 1, 3, 9, 3],cost = [2, 1, 2, 1, 2]) == 14\n assert candidate(nums = [1, 3, 5, 2],cost = [2, 3, 1, 14]) == 8\n assert candidate(nums = [2, 2, 2, 2, 2],cost = [4, 2, 8, 1, 3]) == 0\n assert candidate(nums = [6, 1, 9],cost = [2, 5, 7]) == 46\n assert candidate(nums = [1, 2, 3],cost = [1, 2, 3]) == 4\n assert candidate(nums = [10, 1, 10],cost = [1, 100, 1]) == 18\n assert candidate(nums = [6, 1, 9, 8, 2],cost = [4, 2, 8, 1, 3]) == 48\n assert candidate(nums = [100000, 100000],cost = [1000000, 1000000]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5],cost = [10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [1, 2, 3],cost = [1, 1, 1]) == 2\n assert candidate(nums = [10, 5, 15],cost = [1, 10, 1]) == 15\n assert candidate(nums = [1, 2, 3],cost = [9, 3, 5]) == 13\n assert candidate(nums = [100000, 1000000],cost = [100, 1]) == 900000\n assert candidate(nums = [1000000, 1000000, 1000000, 1000000],cost = [1000000, 1000000, 1000000, 1000000]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],cost = [5, 4, 3, 2, 1]) == 1500\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 0\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [5, 3, 8, 6, 2, 7],cost = [100, 200, 300, 400, 500, 600]) == 3900\n assert candidate(nums = [9, 1, 4, 7, 3],cost = [100, 10, 1000, 10000, 100000]) == 41620\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 82\n assert candidate(nums = [5, 3, 8, 1, 9],cost = [10, 20, 30, 40, 50]) == 460\n assert candidate(nums = [5, 4, 3, 2, 1],cost = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [5, 5, 5, 5, 5],cost = [1000000, 1000000, 1000000, 1000000, 1000000]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 250\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995],cost = [1, 2, 3, 4, 5, 6]) == 26\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3],cost = [3, 2, 1, 1, 2, 3, 3, 2, 1]) == 12\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 112\n assert candidate(nums = [1, 5, 10, 15, 20],cost = [5, 1, 10, 1, 5]) == 105\n assert candidate(nums = [1, 2, 3, 4, 5],cost = [1, 1, 1, 1, 1000000]) == 10\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],cost = [5, 5, 5, 5, 5]) == 30000\n assert candidate(nums = [1, 5, 7, 9, 11],cost = [1, 10, 100, 1000, 10000]) == 2470\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],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]) == 29\n assert candidate(nums = [1, 1, 1, 1, 1],cost = [1000000, 1000000, 1000000, 1000000, 1000000]) == 0\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000],cost = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 25\n assert candidate(nums = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000],cost = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991]) == 49999750\n assert candidate(nums = [9, 1, 4, 6, 2],cost = [5, 3, 8, 6, 7]) == 60\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 390\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 112000\n assert candidate(nums = [500000, 500000, 500000, 500000, 500000],cost = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9],cost = [1, 2, 3, 4, 5]) == 30\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],cost = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 5600\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == 102\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 1000\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],cost = [999, 888, 777, 666, 555]) == 4662000\n assert candidate(nums = [999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991, 999990],cost = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 11200\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 50\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 12\n assert candidate(nums = [999999, 1000000, 999998],cost = [10, 1, 1]) == 2\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 112\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50],cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [100, 150, 200, 250, 300],cost = [1, 2, 3, 4, 5]) == 750\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5],cost = [1, 1, 1, 1, 1, 1, 1]) == 8\n assert candidate(nums = [50, 40, 30, 20, 10],cost = [1, 2, 3, 4, 5]) == 150\n assert candidate(nums = [10, 20, 30, 40, 50],cost = [1, 2, 3, 4, 5]) == 150\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 112\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1],cost = [1, 2, 3, 4, 5]) == 15\n assert candidate(nums = [3, 1, 2],cost = [5, 10, 15]) == 15\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 200\n assert candidate(nums = [1, 2, 2, 3, 4, 5],cost = [1, 1000, 1000, 100, 1, 1]) == 106\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 2500\n assert candidate(nums = [5, 3, 8, 6, 7],cost = [2, 5, 3, 7, 4]) == 27\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1120\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 112000\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 50\n assert candidate(nums = [1, 3, 5, 2, 4],cost = [2, 3, 1, 14, 5]) == 18\n assert candidate(nums = [9, 1, 5, 3, 7, 6],cost = [10, 1, 5, 2, 8, 3]) == 47\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],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]) == 2767\n assert candidate(nums = [1000000, 999999, 999998, 999997, 999996, 999995, 999994, 999993, 999992, 999991],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 25\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],cost = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 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],cost = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 840\n assert candidate(nums = [123456, 123456, 123456, 123456],cost = [100000, 200000, 300000, 400000]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5],cost = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5]) == 40\n assert candidate(nums = [1, 100000, 50000, 75000, 25000],cost = [1000, 1, 100, 10, 100]) == 8349789\n assert candidate(nums = [99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000000]) == 45\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 720\n assert candidate(nums = [1, 1000000, 500000],cost = [1000000, 1, 1]) == 1499998\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1120\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1120\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],cost = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 840\n assert candidate(nums = [7, 7, 7, 7, 7, 7],cost = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000],cost = [1, 10, 100, 1000, 10000, 100000, 1000000]) == 101009989899\n assert candidate(nums = [10, 10, 10, 10, 10, 10],cost = [1, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 50\n assert candidate(nums = [100, 200, 300, 400, 500],cost = [10, 20, 30, 40, 50]) == 15000\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250],cost = [1, 2, 4, 8, 16]) == 306250\n assert candidate(nums = [5, 7, 3, 10, 8],cost = [1, 5, 7, 2, 6]) == 42\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 11200\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],cost = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 50\n assert candidate(nums = [1000000, 1, 1000000, 1, 1000000],cost = [1, 1000000, 1, 1000000, 1]) == 2999997\n assert candidate(nums = [5, 3, 8, 10, 1],cost = [1, 2, 3, 4, 5]) == 53\n assert candidate(nums = [123456, 654321, 111111, 222222, 333333],cost = [1000, 2000, 3000, 4000, 5000]) == 1851852000\n assert candidate(nums = [10, 20, 30, 40, 50],cost = [10, 20, 30, 40, 50]) == 1500\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],cost = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 448\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],cost = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 112\n assert candidate(nums = [1, 5, 9, 13, 17],cost = [10, 20, 30, 40, 50]) == 600\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],cost = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000],cost = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 0\n assert candidate(nums = [1, 1000000],cost = [100000, 1]) == 999999\n assert candidate(nums = [1, 10, 100, 1000, 10000],cost = [10000, 1000, 100, 10, 1]) == 38889\n", "comparison": "exact"}, "public_tests": ["[1,3,5,2]\n[2,3,1,14]", "[2,2,2,2,2]\n[4,2,8,1,3]"], "hints": ["Changing the elements into one of the numbers already existing in the array nums is optimal.", "Try finding the cost of changing the array into each element, and return the minimum value."], "metadata": {"canonical_parameter_names": ["nums", "cost"], "leetcode_dataset_entry_point": "Solution().minCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:10+00:00", "tests_total": 109, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "greedy", "sorting", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function minCost($nums, $cost) {", "container": "Solution", "callable": "minCost", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "cost", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2449, "task_id": "minimum-number-of-operations-to-make-arrays-similar", "difficulty": "Hard", "problem_description": "You are given two positive integer arrays nums and target, of the same length.\n\nIn one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:\n\n- set nums[i] = nums[i] + 2 and\n- set nums[j] = nums[j] - 2.\n\nTwo arrays are considered to be similar if the frequency of each element is the same.\n\nReturn the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.\n\nExample 1:\n\nInput: nums = [8,12,6], target = [2,14,10]\nOutput: 2\nExplanation: It is possible to make nums similar to target in two operations:\n- Choose i = 0 and j = 2, nums = [10,12,4].\n- Choose i = 1 and j = 2, nums = [10,14,2].\nIt can be shown that 2 is the minimum number of operations needed.\n\nExample 2:\n\nInput: nums = [1,2,5], target = [4,1,3]\nOutput: 1\nExplanation: We can make nums similar to target in one operation:\n- Choose i = 1 and j = 2, nums = [1,4,3].\n\nExample 3:\n\nInput: nums = [1,1,1,1,1], target = [1,1,1,1,1]\nOutput: 0\nExplanation: The array nums is already similiar to target.\n\nConstraints:\n\n- n == nums.length == target.length\n- 1 <= n <= 10^5\n- 1 <= nums[i], target[i] <= 10^6\n- It is possible to make nums similar to target.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 3, 3, 3],target = [1, 5, 1, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1],target = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [3, 3, 3, 3],target = [5, 1, 5, 1]) == 2\n assert candidate(nums = [100000, 50000, 10000],target = [10000, 50000, 100000]) == 0\n assert candidate(nums = [1000000, 500000, 250000],target = [500000, 250000, 125000]) == 218750\n assert candidate(nums = [4, 6, 8],target = [2, 6, 10]) == 1\n assert candidate(nums = [8, 12, 6],target = [2, 14, 10]) == 2\n assert candidate(nums = [1000000, 500000, 250000],target = [125000, 375000, 875000]) == 93750\n assert candidate(nums = [4, 6, 8],target = [2, 4, 6]) == 1\n assert candidate(nums = [1, 2, 5],target = [4, 1, 3]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50],target = [5, 15, 25, 35, 45]) == 6\n assert candidate(nums = [1, 3, 5, 7, 9],target = [2, 4, 6, 8, 10]) == 1\n assert candidate(nums = [2, 4, 6, 8],target = [8, 6, 4, 2]) == 0\n assert candidate(nums = [2, 6, 10, 14, 18],target = [4, 8, 12, 16, 20]) == 2\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500],target = [62500, 125000, 250000, 500000, 1000000]) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],target = [150, 250, 350, 450, 550]) == 62\n assert candidate(nums = [10, 20, 30, 40, 50, 60],target = [5, 15, 25, 35, 45, 55]) == 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, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],target = [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]) == 12\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],target = [500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 8500, 9500]) == 1250\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]) == 0\n assert candidate(nums = [3, 7, 11, 15, 19, 23],target = [5, 9, 13, 17, 21, 25]) == 3\n assert candidate(nums = [9, 11, 13, 15, 17, 19, 21, 23],target = [7, 13, 19, 25, 31, 37, 43, 49]) == 25\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010],target = [1010, 909, 808, 707, 606, 505, 404, 303, 202, 101]) == 0\n assert candidate(nums = [11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = [9, 11, 13, 15, 17, 19, 21, 23, 25, 27]) == 5\n assert candidate(nums = [101, 202, 303, 404, 505],target = [103, 204, 305, 406, 507]) == 2\n assert candidate(nums = [1000000, 999998, 999996, 999994, 999992],target = [999999, 999997, 999995, 999993, 999991]) == 1\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]) == 12\n assert candidate(nums = [3, 7, 11, 13, 17],target = [5, 9, 15, 19, 23]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10],target = [1, 3, 5, 7, 9]) == 1\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]) == 12\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]) == 2\n assert candidate(nums = [5, 12, 18, 24, 30, 36],target = [3, 15, 21, 27, 33, 39]) == 13\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]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700],target = [50, 150, 250, 350, 450, 550, 650]) == 87\n assert candidate(nums = [9, 7, 5, 3, 1],target = [2, 4, 6, 8, 10]) == 1\n assert candidate(nums = [100000, 200000, 300000, 400000, 500000],target = [50000, 150000, 250000, 350000, 450000]) == 62500\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37]) == 20\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]) == 0\n assert candidate(nums = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38],target = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]) == 5\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],target = [1, 5, 7, 9, 11, 13, 15, 17, 19, 21]) == 2\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],target = [99, 199, 299, 399, 499, 599, 699, 799, 899, 999]) == 2\n assert candidate(nums = [1, 5, 9, 13, 17, 21],target = [3, 7, 11, 15, 19, 23]) == 3\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],target = [1, 9, 17, 25, 33, 41, 49, 57, 65, 73]) == 58\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55],target = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63]) == 45\n assert candidate(nums = [2, 4, 6, 8, 10, 12],target = [1, 5, 7, 9, 11, 13]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500],target = [98, 198, 298, 398, 498]) == 2\n assert candidate(nums = [11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = [10, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 2\n assert candidate(nums = [11, 21, 31, 41, 51, 61],target = [9, 19, 29, 39, 49, 59]) == 3\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],target = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38]) == 2\n assert candidate(nums = [2, 4, 6, 8, 10],target = [1, 3, 5, 7, 9]) == 1\n assert candidate(nums = [8, 16, 24, 32, 40, 48],target = [14, 22, 30, 38, 46, 54]) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11],target = [2, 4, 6, 8, 10, 12]) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27],target = [5, 8, 11, 14, 17, 20, 23, 26, 29]) == 4\n assert candidate(nums = [100000, 50000, 25000, 12500, 6250, 3125, 1563],target = [1562, 3125, 6250, 12500, 25000, 50000, 100000]) == 49218\n assert candidate(nums = [1, 4, 7, 10, 13, 16, 19, 22],target = [3, 6, 9, 12, 15, 18, 21, 24]) == 4\n assert candidate(nums = [2, 4, 6, 8, 10, 12],target = [1, 3, 5, 7, 9, 11]) == 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],target = [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 = [1000000, 999998, 999996, 999994, 999992, 999990, 999988, 999986, 999984, 999982],target = [999999, 999997, 999995, 999993, 999991, 999989, 999987, 999985, 999983, 999981]) == 2\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]) == 2\n assert candidate(nums = [99, 97, 95, 93, 91, 89, 87],target = [101, 99, 97, 95, 93, 91, 89]) == 3\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],target = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 12\n assert candidate(nums = [5, 5, 5, 5, 5, 10, 10, 10, 10, 10],target = [10, 10, 10, 10, 10, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],target = [2, 4, 6, 8, 10, 12, 14, 16]) == 2\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],target = [100001, 100003, 100005, 100007, 100009, 100011, 100013, 100015, 100017, 100019]) == 36\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]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13],target = [2, 4, 6, 8, 10, 12, 14]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10],target = [10, 8, 6, 4, 2]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],target = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145]) == 18\n assert candidate(nums = [2, 6, 18, 34, 50],target = [1, 5, 17, 33, 49]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],target = [50, 150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850, 1950]) == 250\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75],target = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73]) == 7\n assert candidate(nums = [1, 1, 3, 3, 5, 5, 7, 7],target = [2, 2, 4, 4, 6, 6, 8, 8]) == 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],target = [3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98]) == 10\n assert candidate(nums = [1000, 2000, 3000, 4000, 5000],target = [1500, 2500, 3500, 4500, 5500]) == 625\n assert candidate(nums = [9, 7, 5, 3, 1],target = [10, 8, 6, 4, 2]) == 1\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],target = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]) == 3\n assert candidate(nums = [11, 17, 23, 29, 31],target = [13, 19, 25, 27, 37]) == 3\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]) == 95\n assert candidate(nums = [3, 5, 7, 9, 11, 13, 15],target = [2, 4, 6, 8, 10, 12, 14]) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600],target = [150, 250, 350, 450, 550, 650]) == 75\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99],target = [10, 20, 30, 40, 50, 60, 70, 80, 90]) == 53\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99],target = [9, 19, 29, 39, 49, 59, 69, 79, 89]) == 53\n assert candidate(nums = [99, 97, 95, 93, 91, 89, 87, 85, 83, 81],target = [101, 103, 105, 107, 109, 111, 113, 115, 117, 119]) == 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],target = [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]) == 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],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15],target = [2, 4, 6, 8, 10, 12, 14, 16]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],target = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 3\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],target = [4, 9, 14, 19, 24, 29, 34, 39, 44, 49]) == 12\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]) == 2\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28],target = [2, 6, 10, 14, 18, 22, 26]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],target = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125]) == 15\n assert candidate(nums = [5, 10, 15, 20, 25, 30],target = [1, 6, 11, 16, 21, 26]) == 6\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63],target = [15, 24, 33, 42, 51, 60, 69]) == 10\n assert candidate(nums = [3, 6, 9, 12, 15, 18],target = [2, 7, 10, 13, 16, 19]) == 5\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 = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78]) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 3\n assert candidate(nums = [3, 5, 7, 9],target = [1, 7, 11, 13]) == 3\n assert candidate(nums = [100, 200, 300, 400, 500],target = [50, 150, 250, 350, 450]) == 62\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],target = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 2\n assert candidate(nums = [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953, 976, 488, 244, 122, 61, 30, 15, 7, 3, 1],target = [1, 3, 7, 15, 30, 61, 122, 244, 488, 976, 1953, 3906, 7812, 15625, 31250, 62500, 125000, 250000, 500000, 1000000]) == 0\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31],target = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 4\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]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13],target = [1, 4, 6, 8, 10, 12]) == 6\n", "comparison": "exact"}, "public_tests": ["[8,12,6]\n[2,14,10]", "[1,2,5]\n[4,1,3]", "[1,1,1,1,1]\n[1,1,1,1,1]"], "hints": ["Solve for even and odd numbers separately.", "Greedily match smallest even element from nums to smallest even element from target, then similarly next smallest element and so on.", "Similarly, match odd elements too."], "metadata": {"canonical_parameter_names": ["nums", "target"], "leetcode_dataset_entry_point": "Solution().makeSimilar", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:12+00:00", "tests_total": 107, "tests_dropped": 4, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "php", "interface": {"raw_signature": "function makeSimilar($nums, $target) {", "container": "Solution", "callable": "makeSimilar", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "target", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2451, "task_id": "odd-string-difference", "difficulty": "Easy", "problem_description": "You are given an array of equal-length strings words. Assume that the length of each string is n.\n\nEach string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e. the position of 'a' is 0, 'b' is 1, and 'z' is 25.\n\n- For example, for the string \"acb\", the difference integer array is [2 - 0, 1 - 2] = [2, -1].\n\nAll the strings in words have the same difference integer array, except one. You should find that string.\n\nReturn the string in words that has different difference integer array.\n\nExample 1:\n\nInput: words = [\"adc\",\"wzy\",\"abc\"]\nOutput: \"abc\"\nExplanation:\n- The difference integer array of \"adc\" is [3 - 0, 2 - 3] = [3, -1].\n- The difference integer array of \"wzy\" is [25 - 22, 24 - 25]= [3, -1].\n- The difference integer array of \"abc\" is [1 - 0, 2 - 1] = [1, 1].\nThe odd array out is [1, 1], so we return the corresponding string, \"abc\".\n\nExample 2:\n\nInput: words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"]\nOutput: \"bob\"\nExplanation: All the integer arrays are [0, 0] except for \"bob\", which corresponds to [13, -13].\n\nConstraints:\n\n- 3 <= words.length <= 100\n- n == words[i].length\n- 2 <= n <= 20\n- words[i] consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['adc', 'wzy', 'abc']) == \"abc\"\n assert candidate(words = ['zzz', 'zyx', 'zwy', 'zvx']) == \"zzz\"\n assert candidate(words = ['zzz', 'zyz', 'zxz', 'wyz']) == \"zzz\"\n assert candidate(words = ['aaa', 'bob', 'ccc', 'ddd']) == \"bob\"\n assert candidate(words = ['aab', 'aac', 'aad', 'abe']) == \"aab\"\n assert candidate(words = ['xyz', 'abc', 'uvw', 'aaa']) == \"aaa\"\n assert candidate(words = ['aaa', 'aaa', 'aab', 'aaa']) == \"aab\"\n assert candidate(words = ['zzz', 'aaa', 'zzz', 'aaa', 'zzz', 'aab']) == \"aab\"\n assert candidate(words = ['xyz', 'uvw', 'rst', 'qpo']) == \"qpo\"\n assert candidate(words = ['aab', 'aac', 'aba', 'aaa']) == \"aab\"\n assert candidate(words = ['qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'cba', 'bac']) == \"yza\"\n assert candidate(words = ['qrst', 'qrsu', 'rstv', 'rstw']) == \"qrst\"\n assert candidate(words = ['qrst', 'qrst', 'qrst', 'qrsu', 'qrst']) == \"qrsu\"\n assert candidate(words = ['abc', 'bcd', 'cde', 'ade']) == \"ade\"\n assert candidate(words = ['aab', 'aac', 'aba', 'aaa', 'aab', 'aac', 'aba', 'aac', 'aba', 'aab', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba', 'aac', 'aba']) == \"aaa\"\n assert candidate(words = ['abc', 'bcd', 'cde', 'bce']) == \"bce\"\n assert candidate(words = ['qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza']) == \"yza\"\n assert candidate(words = ['abc', 'bde', 'cef', 'dfg', 'efh', 'fij', 'gjk', 'hkl', 'ilm', 'jmn', 'kno', 'lop', 'mqr', 'nrs', 'ots', 'puv', 'qvw', 'rxy', 'syz', 'tza', 'uab', 'vbc', 'wcd', 'xey', 'yfz', 'zga']) == \"abc\"\n assert candidate(words = ['mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'abc', 'bcd', 'cde']) == \"yza\"\n assert candidate(words = ['uvw', 'vwx', 'wxy', 'vxz', 'wyz']) == \"vxz\"\n assert candidate(words = ['xyz', 'wxy', 'vwx', 'uvw', 'tuv', 'stu', 'rst', 'qrs', 'pqr', 'opq', 'nop', 'mno', 'lnm', 'klj', 'ijk', 'hgf', 'fed', 'edc', 'dcb', 'cba', 'bca', 'cab', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'bac']) == \"lnm\"\n assert candidate(words = ['pqr', 'qrs', 'rst', 'uvw', 'vwx', 'wxy', 'xyz', 'xya']) == \"xya\"\n assert candidate(words = ['abcdefg', 'abcdefh', 'abcdefi', 'abcdefj', 'abcdefg']) == \"abcdefh\"\n assert candidate(words = ['aaa', 'abb', 'acc', 'add', 'aee', 'aff', 'agg', 'aeh', 'aei', 'aej', 'aek', 'ael', 'aem', 'aen', 'aeo', 'aep', 'aeq', 'aer', 'aes', 'aet', 'aeu', 'aev', 'aew', 'aex', 'aey', 'aez', 'afa', 'afb', 'afc', 'afd', 'afe', 'aff', 'afg', 'afh']) == \"aaa\"\n assert candidate(words = ['xyz', 'xza', 'ywb', 'ywa']) == \"xyz\"\n assert candidate(words = ['zzz', 'zzy', 'zzx', 'zzw', 'zzv']) == \"zzz\"\n assert candidate(words = ['mnop', 'nqpo', 'opqr', 'qrst', 'rstu', 'stuv', 'tuvw', 'uvwz', 'vwxy', 'wxza', 'xyzb', 'yzca', 'zcab', 'cabc', 'abcd', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno', 'mnop', 'nopq', 'opqr', 'pqrt', 'qrst', 'rstu', 'stuv', 'tuvw', 'uvwz', 'vwxy', 'wxza', 'xyzb', 'yzca', 'zcab', 'cabc', 'abcd', 'bcde', 'cdef', 'defg', 'efgh', 'fghi', 'ghij', 'hijk', 'ijkl', 'jklm', 'klmn', 'lmno']) == \"nqpo\"\n assert candidate(words = ['abc', 'bcd', 'cde', 'def', 'geh', 'hif', 'iji', 'jik']) == \"geh\"\n assert candidate(words = ['qwert', 'wertr', 'ertty', 'rtyui', 'tyuio']) == \"qwert\"\n assert candidate(words = ['aaa', 'aab', 'aac', 'aad', 'zaa']) == \"aaa\"\n assert candidate(words = ['zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzzz', 'zzzzzzzzza']) == \"zzzzzzzzza\"\n assert candidate(words = ['zzz', 'zyz', 'xyx', 'wxw', 'vuq', 'tsr']) == \"zzz\"\n assert candidate(words = ['mnop', 'mnoq', 'mnop', 'mnoo', 'mnop']) == \"mnoq\"\n assert candidate(words = ['mno', 'nop', 'opo', 'npp', 'mqq']) == \"opo\"\n assert candidate(words = ['aaa', 'aba', 'aca', 'ada', 'aea', 'afa', 'aga', 'aha']) == \"aaa\"\n assert candidate(words = ['mnopqr', 'mnopqs', 'mnopqt', 'mnopqu', 'mnopqv']) == \"mnopqr\"\n assert candidate(words = ['qwe', 'rft', 'sgh', 'tij', 'ukl', 'vmo']) == \"qwe\"\n assert candidate(words = ['abcdef', 'abcefg', 'abcdgg', 'abcdef', 'abcdeg']) == \"abcefg\"\n assert candidate(words = ['abz', 'bca', 'cab', 'bac', 'acb', 'baa', 'aaa', 'aab']) == \"abz\"\n assert candidate(words = ['abz', 'bca', 'cab', 'abc']) == \"abz\"\n assert candidate(words = ['aaa', 'aab', 'aac', 'aad', 'aae', 'aaf', 'aag', 'aah', 'aai', 'aaj', 'aak', 'aal', 'aam', 'aan', 'aao', 'aap', 'aaq', 'aar', 'aas', 'aat', 'aau', 'aav', 'aaw', 'aax', 'aay', 'aaz', 'abb', 'abc']) == \"aaa\"\n assert candidate(words = ['aab', 'aac', 'aab', 'aac', 'aab', 'aac', 'aad', 'aac']) == \"aad\"\n assert candidate(words = ['zzz', 'zyz', 'zyx', 'zzx', 'zyw']) == \"zzz\"\n assert candidate(words = ['uvw', 'uvx', 'uwy', 'uxz']) == \"uvw\"\n assert candidate(words = ['mnop', 'nqpr', 'opqs', 'pqrt']) == \"mnop\"\n assert candidate(words = ['zzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzzz', 'zzzzzzzzzzzzzzzzzzza']) == \"zzzzzzzzzzzzzzzzzzza\"\n assert candidate(words = ['xyz', 'yza', 'zab', 'xba', 'xza']) == \"xyz\"\n assert candidate(words = ['abc', 'bcd', 'cde', 'def', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza']) == \"yza\"\n assert candidate(words = ['mnop', 'mnoq', 'mnop', 'mnop']) == \"mnoq\"\n assert candidate(words = ['pqr', 'qrs', 'rst', 'qst', 'qrt']) == \"qst\"\n assert candidate(words = ['aaa', 'aba', 'aca', 'ada', 'aea']) == \"aaa\"\n assert candidate(words = ['aaa', 'aab', 'aba', 'aca', 'baa']) == \"aaa\"\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'aefghi']) == \"aefghi\"\n assert candidate(words = ['xyz', 'yza', 'zab', 'abc']) == \"yza\"\n assert candidate(words = ['xyz', 'xwv', 'xut', 'xsr']) == \"xyz\"\n assert candidate(words = ['uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'aaa', 'aab', 'aac', 'aad', 'abe', 'acd']) == \"aaa\"\n assert candidate(words = ['abcdef', 'bcdefg', 'cdefgh', 'defghi', 'efghij', 'fghijk', 'ghijkl', 'hijklm', 'ijklmn', 'jklmno', 'klmnop', 'lmnopq', 'mnopqr', 'nopqrs', 'opqrst', 'pqrstu', 'qrstuv', 'rstuvw', 'stuvwx', 'tuvwxy', 'uvwxyx', 'vwxyxw', 'wxyxwy', 'xyxwyx', 'yxwyxy']) == \"uvwxyx\"\n assert candidate(words = ['aaaab', 'aaaba', 'aabaa', 'abaaa', 'baaaa']) == \"aaaab\"\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', 'yza', 'zab', 'aaa', 'aab', 'aac', 'aad', 'abe']) == \"yza\"\n assert candidate(words = ['zzz', 'zzy', 'zyz', 'yzz', 'zyx', 'yxz', 'xzy', 'xyz', 'yxw', 'xyw', 'xwy', 'ywx', 'wxy', 'wyz', 'xzy', 'xyz', 'xwy', 'ywx', 'wxy', 'wyz', 'xzy', 'xyz', 'xwy', 'ywx']) == \"zzz\"\n assert candidate(words = ['mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyx', 'yzy', 'zzz', 'yzy', 'xyx', 'vwx', 'uvw', 'tuv', 'stu', 'qrs', 'pqr', 'opq', 'nop', 'mno', 'zyz', 'zzz']) == \"zyz\"\n assert candidate(words = ['zzz', 'aaa', 'aab', 'aac', 'aad']) == \"aab\"\n assert candidate(words = ['xyz', 'yza', 'zab', 'cab', 'bcd']) == \"yza\"\n assert candidate(words = ['pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz', 'yza', 'zab', 'aba', 'bab', 'bba', 'aab', 'aaa', 'aab', 'aba', 'abb', 'abc']) == \"yza\"\n assert candidate(words = ['zzz', 'yyy', 'xxz', 'xxy']) == \"xxz\"\n assert candidate(words = ['xyz', 'xza', 'xya', 'xwa']) == \"xyz\"\n assert candidate(words = ['ghi', 'hij', 'ijk', 'jkl', 'gij']) == \"gij\"\n assert candidate(words = ['pqr', 'qrs', 'rst', 'str']) == \"str\"\n assert candidate(words = ['zxy', 'zyx', 'yxz', 'yzy']) == \"zxy\"\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abcd', 'abcg']) == \"abce\"\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', 'yza', 'zab', 'cab', 'bca', 'abc', 'bca', 'cab', 'bac', 'acb', 'baa', 'aaa', 'aab', 'aac', 'aad', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc']) == \"yza\"\n assert candidate(words = ['apple', 'applf', 'applg', 'applh']) == \"apple\"\n assert candidate(words = ['zzz', 'yyz', 'xxz', 'wwz', 'vvz', 'uuz', 'ttz', 'ssz', 'rrz', 'qqz', 'ppz', 'opo', 'ono', 'nnm', 'nml', 'nkl', 'nlj', 'nik', 'ihj', 'igh', 'ifh', 'ieh', 'idh', 'ich', 'ibh', 'iah', 'azg', 'azy', 'ayx', 'axw', 'avv', 'auu', 'att', 'ass', 'arr', 'aqq', 'app', 'aoo', 'ano', 'aml', 'akl', 'ajk', 'aik', 'aih', 'aig', 'aif', 'aie', 'aid', 'aic', 'abh', 'aag', 'aaf', 'aae', 'aad', 'aac', 'aab']) == \"zzz\"\n assert candidate(words = ['qwe', 'rty', 'uio', 'pas', 'qdf']) == \"qwe\"\n assert candidate(words = ['aab', 'aac', 'aad', 'abe', 'bbf', 'ccg', 'ddd']) == \"aab\"\n", "comparison": "exact"}, "public_tests": ["[\"adc\",\"wzy\",\"abc\"]", "[\"aaa\",\"bob\",\"ccc\",\"ddd\"]"], "hints": ["Find the difference integer array for each string.", "Compare them to find the odd one out."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().oddString", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:17+00:00", "tests_total": 80, "tests_dropped": 5, "flags": [], "topic_tags": ["array", "hash-table", "string"]}, "language": "php", "interface": {"raw_signature": "function oddString($words) {", "container": "Solution", "callable": "oddString", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "String", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2452, "task_id": "words-within-two-edits-of-dictionary", "difficulty": "Medium", "problem_description": "You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.\n\nIn one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.\n\nReturn a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.\n\nExample 1:\n\nInput: queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"]\nOutput: [\"word\",\"note\",\"wood\"]\nExplanation:\n- Changing the 'r' in \"word\" to 'o' allows it to equal the dictionary word \"wood\".\n- Changing the 'n' to 'j' and the 't' to 'k' in \"note\" changes it to \"joke\".\n- It would take more than 2 edits for \"ants\" to equal a dictionary word.\n- \"wood\" can remain unchanged (0 edits) and match the corresponding dictionary word.\nThus, we return [\"word\",\"note\",\"wood\"].\n\nExample 2:\n\nInput: queries = [\"yes\"], dictionary = [\"not\"]\nOutput: []\nExplanation:\nApplying any two edits to \"yes\" cannot make it equal to \"not\". Thus, we return an empty array.\n\nConstraints:\n\n- 1 <= queries.length, dictionary.length <= 100\n- n == queries[i].length == dictionary[j].length\n- 1 <= n <= 100\n- All queries[i] and dictionary[j] are composed of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(queries = ['test', 'text', 'sett'],dictionary = ['test', 'text', 'sett', 'best']) == ['test', 'text', 'sett']\n assert candidate(queries = ['abc', 'bcd', 'cde'],dictionary = ['xyz', 'zyx', 'abc']) == ['abc']\n assert candidate(queries = ['apple', 'apply'],dictionary = ['appla', 'apple', 'apply']) == ['apple', 'apply']\n assert candidate(queries = ['test', 'text', 'sett'],dictionary = ['text', 'test', 'sett', 'best']) == ['test', 'text', 'sett']\n assert candidate(queries = ['hello', 'world'],dictionary = ['hallo', 'wurld', 'holdo']) == ['hello', 'world']\n assert candidate(queries = ['word', 'note', 'ants', 'wood'],dictionary = ['wood', 'joke', 'moat']) == ['word', 'note', 'wood']\n assert candidate(queries = ['test', 'sett', 'best'],dictionary = ['rest', 'test', 'best']) == ['test', 'sett', 'best']\n assert candidate(queries = ['abcd', 'abce', 'abcf'],dictionary = ['abef', 'abcf', 'abcd']) == ['abcd', 'abce', 'abcf']\n assert candidate(queries = ['apple', 'apply', 'spoil'],dictionary = ['appla', 'appie', 'spoil']) == ['apple', 'apply', 'spoil']\n assert candidate(queries = ['hello', 'world'],dictionary = ['hallo', 'werld']) == ['hello', 'world']\n assert candidate(queries = ['apple', 'apply', 'happy'],dictionary = ['pally', 'apple', 'happy']) == ['apple', 'apply', 'happy']\n assert candidate(queries = ['test', 'text', 'sett'],dictionary = ['best', 'text', 'west']) == ['test', 'text', 'sett']\n assert candidate(queries = ['apple', 'apply'],dictionary = ['spale', 'spaly']) == ['apple', 'apply']\n assert candidate(queries = ['aabb', 'abab', 'baba'],dictionary = ['aaaa', 'bbbb', 'abab']) == ['aabb', 'abab', 'baba']\n assert candidate(queries = ['yes'],dictionary = ['not']) == []\n assert candidate(queries = ['test'],dictionary = ['tast', 'test', 'sett']) == ['test']\n assert candidate(queries = ['banana', 'bananb', 'bananc'],dictionary = ['banana', 'bananb', 'bananc', 'banand']) == ['banana', 'bananb', 'bananc']\n assert candidate(queries = ['abcdefgh', 'abcdefgh'],dictionary = ['abcdefgh', 'abcdefgh', 'abcdefgh']) == ['abcdefgh', 'abcdefgh']\n assert candidate(queries = ['abcdefghij', 'klmnopqrst'],dictionary = ['abcdeffhij', 'klmnopqrts', 'abcdefghij']) == ['abcdefghij', 'klmnopqrst']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr'],dictionary = ['abcdeg', 'ghijkm', 'mnopqs']) == ['abcdef', 'ghijkl', 'mnopqr']\n assert candidate(queries = ['abcd', 'abce', 'abcf'],dictionary = ['abcf', 'abcg', 'abcd', 'abch']) == ['abcd', 'abce', 'abcf']\n assert candidate(queries = ['abcdefghij', 'jihgfedcba'],dictionary = ['abcdefghij', 'jihgfedcba', 'abcdefghij', 'jihgfedcba', 'abcdefghij']) == ['abcdefghij', 'jihgfedcba']\n assert candidate(queries = ['abcd', 'abdc', 'acbd', 'acdb'],dictionary = ['abcd', 'abdc', 'acbd', 'acdb', 'dcba', 'bdca']) == ['abcd', 'abdc', 'acbd', 'acdb']\n assert candidate(queries = ['abcdefghij', 'abcdefghij', 'abcdefghij'],dictionary = ['abcdefghij', 'abcdefghik', 'abcdefghil', 'abcdefghim', 'abcdefghin']) == ['abcdefghij', 'abcdefghij', 'abcdefghij']\n assert candidate(queries = ['abcdef', 'ghijkl'],dictionary = ['abchef', 'ghijkl', 'abcdeg', 'ghijkl', 'abcfeg']) == ['abcdef', 'ghijkl']\n assert candidate(queries = ['abcdefghij', 'jihgfedcba'],dictionary = ['abcdefghij', 'jihgfedcba', 'abcdefghij', 'jihgfedcba']) == ['abcdefghij', 'jihgfedcba']\n assert candidate(queries = ['abcdefghij', 'jihgfedcba'],dictionary = ['abcdefghij', 'jihgfedcba', 'abcdefghij', 'abcdefghij']) == ['abcdefghij', 'jihgfedcba']\n assert candidate(queries = ['abcdefgh', 'abceghij', 'abcdefij'],dictionary = ['abcdefgh', 'abceghij', 'abcdefij', 'abcdefgj']) == ['abcdefgh', 'abceghij', 'abcdefij']\n assert candidate(queries = ['abcde', 'edcba', 'bacde'],dictionary = ['abcde', 'edcba', 'bacde', 'cabed', 'abcde', 'edcba', 'bacde', 'cabed']) == ['abcde', 'edcba', 'bacde']\n assert candidate(queries = ['abcdef', 'ghijkl'],dictionary = ['abcgef', 'ghikjl', 'abcdef']) == ['abcdef', 'ghijkl']\n assert candidate(queries = ['abcd', 'abce', 'abcf'],dictionary = ['abcf', 'abce', 'abcc']) == ['abcd', 'abce', 'abcf']\n assert candidate(queries = ['python', 'pyhton', 'pythpn'],dictionary = ['python', 'pyhton', 'pythpn', 'pythun']) == ['python', 'pyhton', 'pythpn']\n assert candidate(queries = ['cat', 'bat', 'rat'],dictionary = ['cap', 'bap', 'rap', 'tap']) == ['cat', 'bat', 'rat']\n assert candidate(queries = ['abcdefghij', 'klmnopqrst'],dictionary = ['abcdefghij', 'klmnopqrts', 'abcdefghik', 'klmnopqrst', 'abcdefghim']) == ['abcdefghij', 'klmnopqrst']\n assert candidate(queries = ['kitten', 'sitten', 'bitten'],dictionary = ['sitten', 'kitten', 'biting', 'bitten']) == ['kitten', 'sitten', 'bitten']\n assert candidate(queries = ['test', 'tast', 'rest'],dictionary = ['best', 'rest', 'tast', 'test']) == ['test', 'tast', 'rest']\n assert candidate(queries = ['transform', 'transforn', 'tranformt'],dictionary = ['transfarm', 'transform', 'transfurm']) == ['transform', 'transforn']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx'],dictionary = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx']) == ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx']\n assert candidate(queries = ['abcdefghij', 'abcdefghik', 'abcdefghil'],dictionary = ['abcdefghio', 'abcdefghij', 'abcdefghim']) == ['abcdefghij', 'abcdefghik', 'abcdefghil']\n assert candidate(queries = ['apple', 'apply', 'pally'],dictionary = ['appel', 'abble', 'appie']) == ['apple', 'apply']\n assert candidate(queries = ['zzzzzz', 'yyyyyy', 'xxxxxx'],dictionary = ['zzzzzz', 'yyyyyy', 'xxxxxx', 'wwwwww', 'vvvvvv', 'uuuuuu', 'tttttt']) == ['zzzzzz', 'yyyyyy', 'xxxxxx']\n assert candidate(queries = ['apple', 'apply', 'pally'],dictionary = ['appla', 'appli', 'apple', 'pally', 'polly']) == ['apple', 'apply', 'pally']\n assert candidate(queries = ['apple', 'apply', 'appla'],dictionary = ['apple', 'apply', 'appel', 'appla']) == ['apple', 'apply', 'appla']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],dictionary = ['abcdeg', 'ghijkm', 'mnopqs', 'stuvwx', 'yzabcd']) == ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd']\n assert candidate(queries = ['abcdefgh', 'hgfedcba', 'abcdefgh'],dictionary = ['abcdefgh', 'hgfedcba', 'zyxwvuts', 'qrstuvwx']) == ['abcdefgh', 'hgfedcba', 'abcdefgh']\n assert candidate(queries = ['abcdefghij', 'abcdefghij', 'abcdefghij'],dictionary = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij']) == ['abcdefghij', 'abcdefghij', 'abcdefghij']\n assert candidate(queries = ['abcde', 'fghij', 'klmno'],dictionary = ['abxde', 'fghij', 'klmnp']) == ['abcde', 'fghij', 'klmno']\n assert candidate(queries = ['apple', 'apply', 'appla'],dictionary = ['appel', 'apply', 'ample']) == ['apple', 'apply', 'appla']\n assert candidate(queries = ['abcdefgh', 'abcdefgh', 'abcdefgh'],dictionary = ['abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh']) == ['abcdefgh', 'abcdefgh', 'abcdefgh']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr'],dictionary = ['abcdeg', 'ghikjl', 'mnopqg']) == ['abcdef', 'ghijkl', 'mnopqr']\n assert candidate(queries = ['abcdef', 'abcdeg', 'abcdeh'],dictionary = ['abcdef', 'abcdeg', 'abcdeh', 'abcdei']) == ['abcdef', 'abcdeg', 'abcdeh']\n assert candidate(queries = ['aabbcc', 'ddeeff', 'gghhii'],dictionary = ['aabbcc', 'ddeeff', 'gghhij']) == ['aabbcc', 'ddeeff', 'gghhii']\n assert candidate(queries = ['abcdefgh', 'hgfedcba'],dictionary = ['abcdefgh', 'hgfedcba', 'abcdefgh']) == ['abcdefgh', 'hgfedcba']\n assert candidate(queries = ['cat', 'dog', 'rat'],dictionary = ['bat', 'bag', 'rat', 'tag']) == ['cat', 'dog', 'rat']\n assert candidate(queries = ['abcdef', 'ghijkl'],dictionary = ['fedcba', 'lkjihg', 'abcdeg', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd']) == ['abcdef', 'ghijkl']\n assert candidate(queries = ['aaaaaaaaaa', 'bbbbbbbbbb', 'cccccccccc'],dictionary = ['aaaaaaaaaa', 'aaaaaaaabb', 'aaaaaaabbb', 'aaaaaabbbb', 'aaaaabbbbb', 'aaaabbbbbb', 'aabbbbbbbb', 'abbbbbbbbb', 'bbbbbbbbbb']) == ['aaaaaaaaaa', 'bbbbbbbbbb']\n assert candidate(queries = ['abcdefghij', 'abcdefghik'],dictionary = ['abcdefghix', 'abcdefghiy', 'abcdefghij']) == ['abcdefghij', 'abcdefghik']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr'],dictionary = ['abcdej', 'ghijkl', 'mnopqr', 'mnopqs', 'mnopqt']) == ['abcdef', 'ghijkl', 'mnopqr']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr'],dictionary = ['abcdef', 'ghijkl', 'mnopqt']) == ['abcdef', 'ghijkl', 'mnopqr']\n assert candidate(queries = ['abcdefg', 'hijklmn', 'opqrstu'],dictionary = ['abcdefg', 'hijklmn', 'opqrsuv']) == ['abcdefg', 'hijklmn', 'opqrstu']\n assert candidate(queries = ['abcdefgh', 'abcdefgh'],dictionary = ['abcdwxyz', 'abcdefgz', 'abcdefgh']) == ['abcdefgh', 'abcdefgh']\n assert candidate(queries = ['qwerty', 'asdfgh', 'zxcvbn'],dictionary = ['qwerty', 'qwertr', 'asdwgh', 'zxcvbn', 'qwertx']) == ['qwerty', 'asdfgh', 'zxcvbn']\n assert candidate(queries = ['aaaaaa', 'bbbbbb', 'cccccc'],dictionary = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd', 'eeeeee', 'ffffff']) == ['aaaaaa', 'bbbbbb', 'cccccc']\n assert candidate(queries = ['abcdefghij', 'jihgfedcba', 'abcdefghij'],dictionary = ['abcdefghij', 'jihgfedcba', 'abcdefghji', 'jihgfedcbj', 'abcdefghii', 'jihgfedcbi']) == ['abcdefghij', 'jihgfedcba', 'abcdefghij']\n assert candidate(queries = ['abcdefgh', 'abcdefgh'],dictionary = ['abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh']) == ['abcdefgh', 'abcdefgh']\n assert candidate(queries = ['algorithm', 'alorithgm', 'alohrithm'],dictionary = ['algorithm', 'alorithgm', 'alohrithm', 'aloritrhm']) == ['algorithm', 'alorithgm', 'alohrithm']\n assert candidate(queries = ['compiler', 'comipler', 'comipler'],dictionary = ['compiler', 'comipler', 'compilir', 'comiplir']) == ['compiler', 'comipler', 'comipler']\n assert candidate(queries = ['zzzzz', 'yyyyy', 'xxxxx'],dictionary = ['zzzzz', 'xyzyx', 'zxyxz']) == ['zzzzz']\n assert candidate(queries = ['zxywvutsrqponmlkjihgfedcba'],dictionary = ['zyxwvutsrqponmlkjihgfedcba', 'zxywvutsrqponmlkjihgfedcbb']) == ['zxywvutsrqponmlkjihgfedcba']\n assert candidate(queries = ['apple', 'apply', 'ample'],dictionary = ['ample', 'appli', 'appel']) == ['apple', 'apply', 'ample']\n assert candidate(queries = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd'],dictionary = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd']) == ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yzabcd']\n assert candidate(queries = ['aaaaaa', 'bbbbbb', 'cccccc'],dictionary = ['aabbaa', 'bbccbb', 'ccddcc']) == ['aaaaaa', 'bbbbbb', 'cccccc']\n assert candidate(queries = ['abcdefghij', 'abcdefghij', 'abcdefghij'],dictionary = ['abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij', 'abcdefghij']) == ['abcdefghij', 'abcdefghij', 'abcdefghij']\n", "comparison": "exact"}, "public_tests": ["[\"word\",\"note\",\"ants\",\"wood\"]\n[\"wood\",\"joke\",\"moat\"]", "[\"yes\"]\n[\"not\"]"], "hints": ["Try brute-forcing the problem.", "For each word in queries, try comparing to each word in dictionary.", "If there is a maximum of two edit differences, the word should be present in answer."], "metadata": {"canonical_parameter_names": ["queries", "dictionary"], "leetcode_dataset_entry_point": "Solution().twoEditWords", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:19+00:00", "tests_total": 114, "tests_dropped": 41, "flags": [], "topic_tags": ["array", "string", "trie"]}, "language": "php", "interface": {"raw_signature": "function twoEditWords($queries, $dictionary) {", "container": "Solution", "callable": "twoEditWords", "parameters": [{"name": "queries", "type": "String[]"}, {"name": "dictionary", "type": "String[]"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2453, "task_id": "destroy-sequential-targets", "difficulty": "Medium", "problem_description": "You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.\n\nYou have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer. You want to destroy the maximum number of targets in nums.\n\nReturn the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.\n\nExample 1:\n\nInput: nums = [3,7,8,1,1,5], space = 2\nOutput: 1\nExplanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,...\nIn this case, we would destroy 5 total targets (all except for nums[2]).\nIt is impossible to destroy more than 5 targets, so we return nums[3].\n\nExample 2:\n\nInput: nums = [1,3,5,2,4,6], space = 2\nOutput: 1\nExplanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets.\nIt is not possible to destroy more than 3 targets.\nSince nums[0] is the minimal integer that can destroy 3 targets, we return 1.\n\nExample 3:\n\nInput: nums = [6,2,5], space = 100\nOutput: 2\nExplanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].\n\nConstraints:\n\n- 1 <= nums.length <= 10^5\n- 1 <= nums[i] <= 10^9\n- 1 <= space <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1000000000],space = 1000000000) == 1000000000\n assert candidate(nums = [1, 3, 5, 2, 4, 6],space = 2) == 1\n assert candidate(nums = [6, 2, 5],space = 100) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 1) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 1) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21],space = 3) == 3\n assert candidate(nums = [7, 14, 21, 28, 35],space = 7) == 7\n assert candidate(nums = [10, 20, 30, 40, 50],space = 10) == 10\n assert candidate(nums = [9, 19, 29, 39, 49],space = 10) == 9\n assert candidate(nums = [3, 7, 8, 1, 1, 5],space = 2) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42],space = 7) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],space = 3) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99],space = 11) == 11\n assert candidate(nums = [9, 18, 27, 36, 45],space = 9) == 9\n assert candidate(nums = [1, 1, 1, 1, 1],space = 1) == 1\n assert candidate(nums = [5, 10, 15, 20, 25, 30],space = 5) == 5\n assert candidate(nums = [1000000000, 1000000000, 1000000000],space = 1) == 1000000000\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],space = 2) == 2\n assert candidate(nums = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000],space = 1) == 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],space = 7) == 7\n assert candidate(nums = [100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190],space = 3) == 100\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77],space = 4) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147],space = 3) == 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, 147, 154, 161, 168, 175],space = 7) == 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],space = 2) == 2\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],space = 10) == 5\n assert candidate(nums = [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],space = 4) == 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],space = 4) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98],space = 7) == 7\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, 118, 127],space = 9) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],space = 100) == 100\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310, 341, 372, 403, 434, 465, 496, 527, 558, 589, 620],space = 31) == 31\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 1) == 1\n assert candidate(nums = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152, 162, 172, 182, 192],space = 10) == 2\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],space = 3) == 3\n assert candidate(nums = [2, 102, 202, 302, 402, 502, 602, 702, 802, 902, 1002, 1102, 1202, 1302, 1402, 1502, 1602, 1702, 1802, 1902],space = 100) == 2\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536],space = 1) == 1\n assert candidate(nums = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901],space = 100) == 1\n assert candidate(nums = [3, 13, 23, 33, 43, 53, 63, 73, 83, 93],space = 10) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],space = 100) == 100\n assert candidate(nums = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150],space = 15) == 15\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],space = 2) == 2\n assert candidate(nums = [5, 25, 45, 65, 85, 105, 125, 145, 165, 185, 205, 225, 245, 265, 285],space = 20) == 5\n assert candidate(nums = [99, 198, 297, 396, 495, 594, 693, 792, 891, 990, 1089, 1188, 1287, 1386, 1485, 1584, 1683, 1782, 1881, 1980],space = 99) == 99\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],space = 1) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],space = 10) == 10\n assert candidate(nums = [8, 16, 24, 32, 40, 48, 56, 64, 72, 80],space = 8) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],space = 10) == 10\n assert candidate(nums = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901, 1001, 1101, 1201, 1301, 1401],space = 100) == 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],space = 15) == 15\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],space = 2) == 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],space = 4) == 2\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],space = 2) == 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],space = 1) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],space = 2) == 2\n assert candidate(nums = [1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000],space = 1000000) == 1000000\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907],space = 3) == 3\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91],space = 9) == 1\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],space = 3) == 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],space = 7) == 7\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37],space = 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],space = 2) == 1\n assert candidate(nums = [1, 101, 201, 301, 401, 501, 601, 701, 801, 901, 1001, 1101, 1201, 1301, 1401, 1501, 1601, 1701, 1801, 1901],space = 100) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],space = 10) == 10\n assert candidate(nums = [123456789, 246913578, 370370370, 493827161, 617283952, 740740740, 864256331, 987654321],space = 123456789) == 123456789\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],space = 10) == 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],space = 1) == 1\n assert candidate(nums = [111111111, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999],space = 111111111) == 111111111\n assert candidate(nums = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91, 96],space = 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],space = 2) == 1\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994],space = 1) == 999999994\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195],space = 13) == 13\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],space = 2) == 2\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117, 123, 129, 135, 141, 147],space = 6) == 3\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],space = 100) == 100\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666, 555555555, 444444444, 333333333, 222222222, 111111111],space = 111111111) == 111111111\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],space = 7) == 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],space = 2) == 1\n assert candidate(nums = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152, 162, 172, 182, 192, 202],space = 10) == 2\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41, 47, 53, 59],space = 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],space = 5) == 1\n assert candidate(nums = [101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515],space = 101) == 101\n assert candidate(nums = [1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 100],space = 9) == 1\n assert candidate(nums = [1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115],space = 6) == 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],space = 1) == 1\n assert candidate(nums = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92],space = 10) == 2\n assert candidate(nums = [123456789, 246913578, 369270367, 492627156, 615943945],space = 123456789) == 123456789\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],space = 2) == 2\n assert candidate(nums = [10, 19, 28, 37, 46, 55, 64],space = 9) == 10\n assert candidate(nums = [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],space = 3) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],space = 3) == 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],space = 2) == 1\n assert candidate(nums = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91],space = 10) == 1\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45],space = 3) == 3\n assert candidate(nums = [12, 24, 36, 48, 60, 72, 84, 96, 108, 120],space = 12) == 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],space = 10) == 10\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],space = 2) == 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],space = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],space = 10) == 10\n assert candidate(nums = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191],space = 10) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],space = 13) == 13\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],space = 2) == 2\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],space = 10) == 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],space = 5) == 5\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288],space = 1) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],space = 100) == 100\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155],space = 10) == 5\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105],space = 10) == 5\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78, 90, 102, 114],space = 12) == 6\n assert candidate(nums = [5, 11, 17, 23, 29, 35, 41],space = 6) == 5\n assert candidate(nums = [12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50],space = 2) == 12\n assert candidate(nums = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39],space = 4) == 3\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63],space = 6) == 3\n assert candidate(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],space = 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],space = 1) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165],space = 11) == 11\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],space = 10) == 5\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],space = 10) == 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],space = 5) == 5\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996],space = 3) == 999999996\n assert candidate(nums = [5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95],space = 3) == 5\n assert candidate(nums = [1000000000, 500000000, 250000000, 125000000, 62500000, 31250000, 15625000],space = 125000000) == 125000000\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],space = 11) == 11\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],space = 7) == 7\n", "comparison": "exact"}, "public_tests": ["[3,7,8,1,1,5]\n2", "[1,3,5,2,4,6]\n2", "[6,2,5]\n100"], "hints": ["Keep track of nums[i] modulo k.", "Iterate over nums in sorted order."], "metadata": {"canonical_parameter_names": ["nums", "space"], "leetcode_dataset_entry_point": "Solution().destroyTargets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:21+00:00", "tests_total": 127, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "counting"]}, "language": "php", "interface": {"raw_signature": "function destroyTargets($nums, $space) {", "container": "Solution", "callable": "destroyTargets", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "space", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2454, "task_id": "next-greater-element-iv", "difficulty": "Hard", "problem_description": "You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer.\n\nThe second greater integer of nums[i] is nums[j] such that:\n\n- j > i\n- nums[j] > nums[i]\n- There exists exactly one index k such that nums[k] > nums[i] and i < k < j.\n\nIf there is no such nums[j], the second greater integer is considered to be -1.\n\n- For example, in the array [1, 2, 4, 3], the second greater integer of 1 is 4, 2 is 3, and that of 3 and 4 is -1.\n\nReturn an integer array answer, where answer[i] is the second greater integer of nums[i].\n\nExample 1:\n\nInput: nums = [2,4,0,9,6]\nOutput: [9,6,6,-1,-1]\nExplanation:\n0th index: 4 is the first integer greater than 2, and 9 is the second integer greater than 2, to the right of 2.\n1st index: 9 is the first, and 6 is the second integer greater than 4, to the right of 4.\n2nd index: 9 is the first, and 6 is the second integer greater than 0, to the right of 0.\n3rd index: There is no integer greater than 9 to its right, so the second greater integer is considered to be -1.\n4th index: There is no integer greater than 6 to its right, so the second greater integer is considered to be -1.\nThus, we return [9,6,6,-1,-1].\n\nExample 2:\n\nInput: nums = [3,3]\nOutput: [-1,-1]\nExplanation:\nWe return [-1,-1] since neither integer has any integer greater than it.\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, 3, 2, 4, 3, 5, 4, 6, 5, 7]) == [2, 5, 3, 6, 4, 7, 5, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5]) == [2, 5, 5, -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]\n assert candidate(nums = [1000000000, 0, 1000000000, 0, 1000000000]) == [-1, 1000000000, -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]\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 7, 8, 5]) == [2, 5, 5, 6, 7, 7, 8, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [1, 5, 2, 4, 3]) == [2, -1, 3, -1, -1]\n assert candidate(nums = [7, 1, 5, 2, 6, 3, 4, 8, 9]) == [9, 2, 8, 3, 9, 8, 9, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8]) == [2, 7, 3, 8, 4, -1, -1, -1]\n assert candidate(nums = [3, 3]) == [-1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [2, 3, 4, 5, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 0]) == [2, 5, 5, 6, 7, 8, 9, -1, -1, -1]\n assert candidate(nums = [0, 0, 0, 0, 0]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [3, 4, 5, -1, -1]\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 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]\n assert candidate(nums = [1, 2, 4, 3]) == [4, 3, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 6, 3, 2, 7, 8]) == [7, 8, 8, 8, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10]) == [2, 5, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [2, 4, 0, 9, 6]) == [9, 6, 6, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 1, 2, 4]) == [-1, -1, 4, -1, -1]\n assert candidate(nums = [10, 10, 10, 10, 10]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [2, 1, 5, 6, 2, 3, 1, 4, 2, 3]) == [6, 6, -1, -1, 4, -1, 2, -1, -1, -1]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 14, 12, 13, 15, 0]) == [2, 14, 3, 14, 4, 14, 5, 14, 11, 14, 12, -1, 15, -1, -1, -1]\n assert candidate(nums = [3, 2, 1, 0, 4, 5, 6, 7, 8, 9]) == [5, 5, 5, 5, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -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]) == [-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, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12, 9, 13, 10, 14]) == [2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12, 8, 13, 9, 14, 10, -1, -1, -1]\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, 3, 9, 3, 7, 5, 1, 8, 2, 8, 4, 8, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1]) == [5, 5, 9, 9, 6, -1, 5, 7, 7, 9, 7, -1, 8, -1, 4, 8, 4, 9, 6, 7, 4, 7, 7, 7, 7, 9, 9, 9, 8, -1, 8, 8, 8, 9, 9, 7, 7, -1, 8, 9, 7, -1, 5, 8, 8, 2, 9, 4, 9, 6, 9, 7, 4, 7, 7, 7, 7, 9, 9, 9, 8, -1, 8, 8, 8, -1, -1, 7, 7, -1, -1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1]) == [2, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1]\n assert candidate(nums = [15, 14, 13, 12, 11, 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]\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 3, 4, 5, 6, 7, 8, 9, -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, -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]) == [-1, -1, -1, -1, -1, -1, -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, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == [-1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-1, -1, 8, 8, 8, 8, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10]) == [2, 5, 3, 6, 4, 7, 5, 8, 6, 9, 7, 10, 8, -1, -1, -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]) == [-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, -1, -1, -1]\n assert candidate(nums = [1, 5, 3, 9, 2, 8, 7, 10, 6, 11]) == [3, 8, 8, 11, 7, 11, 11, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1]\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]) == [2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, -1, -1]\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60]) == [30, 40, 20, 50, 30, 60, 40, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 3, 4, 5, 6, 7, 8, 9, -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, 0, 1]) == [3, 4, 5, 6, 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]\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, -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, 5, 3, 4, 2, 7, 6, 8]) == [3, 6, 7, 6, 6, -1, -1, -1]\n assert candidate(nums = [3, 4, 2, 3, 5, 1, 6, 0, 7, 8, 9]) == [5, 6, 5, 6, 7, 7, 8, 8, 9, -1, -1]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [2, 2, 3, 3, 4, 4, 5, 5, -1, -1]\n assert candidate(nums = [5, 2, 6, 1, 3, 4, 7, 8, 0, 9]) == [7, 3, 8, 4, 7, 8, 9, -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]) == [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, -1, -1]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 12, 13, 14, 15]) == [2, 12, 3, 12, 4, 12, 5, 12, 11, 12, 13, 14, 15, -1, -1]\n assert candidate(nums = [2, 1, 3, 4, 2, 3, 4, 1, 5, 6]) == [4, 4, 4, 6, 4, 5, 6, 6, -1, -1]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 7, 8]) == [3, 3, 4, 4, 3, 4, 4, 6, 5, 4, 5, 6, 6, 8, 7, 6, 7, 8, -1, -1]\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6]) == [5, 5, 9, 9, 6, -1, 5, 7, 7, 9, 7, -1, 8, -1, 4, 8, 4, -1, -1, -1]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == [2, -1, 2, -1, 2, -1, 2, -1, -1, -1]\n assert candidate(nums = [1, 5, 3, 7, 10, 8, 6, 9, 2, 4]) == [3, 10, 10, 8, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 2, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 12, 13, 14, 15]) == [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15, -1, -1]\n assert candidate(nums = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5]) == [1, -1, 2, -1, 3, -1, 4, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 5, 4, 8, 7, 11, 10, 9, 13, 12, 6, 14, 15, 16, 17, 18, 19, 20]) == [2, 4, 4, 7, 7, 10, 10, 12, 12, 12, 15, 15, 15, 16, 17, 18, 19, 20, -1, -1]\n assert candidate(nums = [1, 5, 3, 2, 4, 7, 6, 8]) == [3, 6, 7, 7, 6, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 8, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0, 9, 8, 7, 6]) == [8, 8, 8, 8, 8, 8, -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]) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1, -1]\n assert candidate(nums = [2, 2, 1, 1, 3, 3, 4, 4, 5, 5]) == [3, 3, 3, 3, 4, 4, 5, 5, -1, -1]\n assert candidate(nums = [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]) == [1, 2, 2, 3, 3, 4, 4, -1, -1, -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]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 9, 8, 7, 10]) == [2, 5, 5, 8, 8, 8, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 5, 2, 6, 3, 7, 4, 9, 0]) == [-1, 2, 7, 3, 9, 4, -1, -1, -1, -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, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 8, -1, -1, 9, 8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) == [3, 3, -1, 3, 3, -1, 3, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [3, 4, 5, 6, 7, 8, 9, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 7, 6, 5, 9, 8, 10]) == [2, 7, 7, 6, 8, 8, 8, -1, -1, -1]\n assert candidate(nums = [8, 7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12]) == [10, 2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12, 8, -1, -1, -1]\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]) == [-1, -1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [1, 2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 6]) == [2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, -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]) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1]\n assert candidate(nums = [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == [1, 3, 3, 5, 5, 7, 7, 9, 9, -1, -1]\n assert candidate(nums = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == [-1, 2, -1, 2, -1, 2, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [2, 4, 4, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1]\n assert candidate(nums = [5, 1, 4, 3, 2, 7, 8, 6, 9, 10]) == [8, 3, 8, 8, 8, 9, 10, 10, -1, -1]\n assert candidate(nums = [3, 5, 4, 7, 6, 8, 10, 9, 11, 12, 13, 14, 15, 16, 17]) == [4, 6, 6, 10, 10, 9, 12, 12, 13, 14, 15, 16, 17, -1, -1]\n assert candidate(nums = [1, 5, 3, 2, 4, 8, 6, 7, 9, 0]) == [3, 6, 8, 8, 6, -1, 9, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1]) == [3, 4, 5, 5, 5, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]) == [2, -1, 3, -1, 4, -1, 5, -1, -1, -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, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]) == [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 38, -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, 1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == [4, 5, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, -1, -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]) == [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, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [9, 0, 9, 0, 9, 0, 9, 0, 9, 0]) == [-1, 9, -1, 9, -1, 9, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 8, 6, 2, 7, 4, 9, 1]) == [6, 6, -1, 9, 4, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 5, 3, 7, 10, 2, 6, 9, 4]) == [9, 3, 10, 10, 9, -1, 9, -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, 1, 2, 3, 4, 5]) == [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1, -1, 3, 4, 5, -1, -1]\n assert candidate(nums = [2, 1, 5, 6, 0, 3, 4, 9, 8, 7]) == [6, 6, 9, 8, 4, 9, 8, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 5, 4, 6, 7, 8, 10, 9]) == [2, 4, 4, 7, 7, 8, 10, 9, -1, -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]) == [3, 4, 5, 6, 7, 8, 9, 10, 10, -1, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 91, 82, 73, 64, 55, 46, 37, 28, 19, 10]) == [30, 40, 50, 60, 70, 80, 90, 100, 91, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]) == [30, 40, 50, 60, 70, 80, 90, 100, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [2, 1, 5, 6, 2, 3, 1, 8]) == [6, 6, 8, -1, 8, -1, -1, -1]\n assert candidate(nums = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == [-1, 3, 4, 5, 6, 7, 8, 9, -1, -1, -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, 0, 31, 32, 33, 34, 35]) == [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 35, -1, -1]\n assert candidate(nums = [3, 5, 2, 6, 1, 7, 4, 8, 0, 9]) == [6, 7, 7, 8, 4, 9, 9, -1, -1, -1]\n assert candidate(nums = [5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [-1, 3, -1, 2, -1, 6, -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, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [-1, 10, 9, 9, 9, 9, 9, 9, 9, 9, -1, -1, 9, 9, 9, 9, 9, 9, 9, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 2, 1, 3, 4, 4, 3, 5, 6, 6, 5, 7, 8, 8, 7, 9]) == [2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, -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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [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, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1]\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == [3, 4, 2, 5, 3, 6, 4, -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]\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, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, -1, -1]\n assert candidate(nums = [0, 10, 2, 9, 4, 8, 6, 7, 5, 3, 1]) == [2, -1, 4, -1, 6, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [3, 4, 5, 6, 7, 8, 9, 9, -1, 8, 8, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 200, 101, 201, 102, 202, 103, 203, 104, 204]) == [101, 202, 102, 203, 103, 204, 104, -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, -1, -1, -1, -1, -1, -1, -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, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == [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, -1, -1, -1, -1]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 2, 4, 6, 1, 7, 8, 9, 10, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == [7, 6, 6, 7, 8, 8, 9, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1, -1]\n assert candidate(nums = [50, 24, 54, 32, 54, 68, 27, 89, 10, 70, 29, 33, 63, 96, 99, 78, 76, 65, 84, 88]) == [54, 32, 89, 68, 89, 70, 70, 99, 29, 99, 63, 96, 99, -1, -1, 88, 88, 88, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4]) == [3, 4, 4, -1, -1, 4, 3, 4, -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, 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, 4, 5, 6, 7, 8, 9, 10, -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, -1, -1, -1, -1, -1, -1, -1, -1, -1]\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]) == [-1, 3, 2, -1, 3, 2, -1, 3, 2, -1, 3, 2, -1, 3, 2, -1, -1, 2, -1, -1, -1]\n assert candidate(nums = [1, 5, 2, 10, 11, 9, 3, 4, 6, 7, 8]) == [2, 11, 11, -1, -1, -1, 6, 7, 8, -1, -1]\n assert candidate(nums = [0, 11, 7, 12, 13, 14, 6, 15, 16, 17, 8, 18, 19, 9, 10, 5, 20, 21, 22, 1]) == [7, 13, 13, 14, 15, 16, 16, 17, 18, 19, 19, 20, 21, 20, 21, 21, 22, -1, -1, -1]\n assert candidate(nums = [1, 10, 8, 7, 6, 5, 4, 3, 2, 1]) == [8, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [10, 20, 30, 25, 40, 35, 50]) == [30, 25, 35, 35, -1, -1, -1]\n assert candidate(nums = [1, 2, 4, 3]) == [4, 3, -1, -1]\n assert candidate(nums = [1, 2, 3, 2, 1]) == [3, -1, -1, -1, -1]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 10, 11, 1, 2, 10, 11, 1]) == [11, 11, -1, 10, 11, -1, -1, -1]\n assert candidate(nums = [5, 3, 4, 2, 1]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [1, 100, 80, 60, 40, 20]) == [80, -1, -1, -1, -1, -1]\n assert candidate(nums = [3, 2, 1]) == [-1, -1, -1]\n assert candidate(nums = [1, 5, 2, 5, 4, 7, 3, 6]) == [2, 6, 4, 6, 6, -1, -1, -1]\n assert candidate(nums = [5, 1, 4, 3, 6, 7, 8]) == [7, 3, 7, 7, 8, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 10, 9]) == [3, 4, 5, 6, 7, 8, 10, 9, -1, -1]\n assert candidate(nums = [100, 50, 25, 12, 6, 3, 1]) == [-1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 10, 11, 12, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 10, 3, 4, 18, 5, 6]) == [3, -1, 18, 5, -1, -1, -1]\n assert candidate(nums = [5, 1, 4, 2, 3]) == [-1, 2, -1, -1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [1]) == [-1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [8, 2, 4, 6, 7, 5, 3, 9, 1]) == [-1, 6, 7, 9, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4]) == [2, 7, 3, -1, 4, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7]) == [2, 5, 5, 6, 7, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8]) == [2, 7, 3, 8, 4, -1, -1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == [2, 3, 4, 5, -1, -1]\n assert candidate(nums = [1, 5, 2, 4, 3, 6, 7, 8, 9, 10]) == [2, 7, 3, 7, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [1, 2, 0, 3, 0, 4, 0, 5, 0, 6]) == [3, 4, 4, 5, 5, 6, 6, -1, -1, -1]\n assert candidate(nums = [5, 8, 1, 2, 10, 6, 9, 7, 3, 4]) == [10, 9, 10, 6, -1, 7, -1, -1, -1, -1]\n assert candidate(nums = [2, 1]) == [-1, -1]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [100, 100, 100]) == [-1, -1, -1]\n assert candidate(nums = [1000000000, 999999999, 999999998, 999999997, 999999996]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 6, 5]) == [2, 6, 6, 5, -1, -1]\n assert candidate(nums = [1000000000, 999999999, 888888888, 777777777, 666666666]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [7, 6, 5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 2, 4, 6, 7, 1, 5]) == [-1, 4, 6, 7, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 4, 3, 5, 6, 7, 8, 9, 10]) == [4, 3, 6, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0]) == [1, -1, 1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == [3, 3, -1, 3, 3, -1, 3, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1, 0]) == [-1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5]) == [3, 4, 5, -1, -1]\n assert candidate(nums = [10, 1, 1, 6, 1, 4, 1, 2, 1, 1, 1, 9, 1, 4, 1, 1, 1, 1, 1, 1]) == [-1, 4, 4, -1, 2, -1, 9, 4, 4, 4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 3, 1, 2, 4]) == [-1, -1, 4, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12, 9, 13, 10, 14]) == [2, 7, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12, 8, 13, 9, 14, 10, -1, -1, -1]\n assert candidate(nums = [8, 5, 12, 9, 16, 15]) == [9, 9, 15, 15, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 7, 6, 8, 9, 10]) == [2, 5, 5, 7, 6, 9, 9, 10, -1, -1]\n assert candidate(nums = [3, 3]) == [-1, -1]\n assert candidate(nums = [5, 8, 4, 5, 3, 5, 10, 15]) == [10, 15, 5, 15, 10, 15, -1, -1]\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7]) == [-1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [8, 1, 5, 2, 6, 3, 7, 4]) == [-1, 2, 7, 3, -1, 4, -1, -1]\n assert candidate(nums = [7, 1, 5, 2, 6, 4, 3]) == [-1, 2, -1, 4, -1, -1, -1]\n assert candidate(nums = [10, 20, 10, 30, 20, 40]) == [30, 40, 20, -1, -1, -1]\n assert candidate(nums = [1, 2, 3]) == [3, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6]) == [2, 7, 3, 8, 4, 9, 5, -1, 6, -1, -1]\n assert candidate(nums = [10, 3, 11, 1, 15, 9]) == [15, 15, -1, 9, -1, -1]\n assert candidate(nums = [1, 10, 8, 9, 10, 11, 5, 3, 12, 0]) == [8, 12, 10, 11, 12, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5]) == [2, 5, 5, -1, -1]\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, 1, 1, 1]) == [-1, -1, -1, -1, -1, -1, -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 = [1000000000, 999999999, 999999998, 999999997, 999999996, 999999995, 999999994, 999999993, 999999992, 999999991]) == [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 5, 9]) == [2, 7, 3, 8, 4, 9, 5, -1, -1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5]) == [2, 3, 4, 5, -1, -1]\n assert candidate(nums = [5, 6, 7, 8, 9, 10]) == [7, 8, 9, 10, -1, -1]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [2, 3, 4, 5, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [0, 1, 2, 0, 3, 0, 4]) == [2, 3, 4, 4, -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]\n assert candidate(nums = [1, 2]) == [-1, -1]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2]) == [3, 3, -1, -1, 3, -1, -1, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 6, 4, 7, 8]) == [2, 5, 5, 6, 7, 4, 8, 8, -1, -1]\n assert candidate(nums = [10, 4, 3, 5, 7, 2, 8, 6, 1]) == [-1, 7, 7, 8, -1, 6, -1, -1, -1]\n assert candidate(nums = [10, 5, 1, 6, 2, 7, 3, 8, 4, 9]) == [-1, 7, 2, 8, 3, 9, 4, -1, -1, -1]\n assert candidate(nums = [10, 5, 15, 2, 18]) == [18, 18, -1, -1, -1]\n assert candidate(nums = [1, 2, 0, 3, 0, 4, 0, 5, 0]) == [3, 4, 4, 5, 5, -1, -1, -1, -1]\n assert candidate(nums = [1, 5, 2, 3, 4, 6, 7, 8, 9, 10]) == [2, 7, 4, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5]) == [3, 4, 5, 5, 5, -1, -1]\n assert candidate(nums = [5, 2, 6, 4, 7]) == [7, 4, -1, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 6, 4, 3, 2, 1, 2, 3, 4]) == [2, 5, 3, 6, 6, -1, -1, -1, -1, 4, 3, 4, -1, -1]\n assert candidate(nums = [1, 3, 2, 4, 5, 3, 2, 1]) == [2, 5, 5, -1, -1, -1, -1, -1]\n assert candidate(nums = [5, 1, 2, 3, 4, 0]) == [-1, 3, 4, -1, -1, -1]\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1]) == [1, -1, 1, -1, 1, -1, -1, -1]\n assert candidate(nums = [1, 2, 0, 3, 0, 4, 0, 5]) == [3, 4, 4, 5, 5, -1, -1, -1]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1]\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50, 45, 60]) == [15, 25, 25, 35, 35, 45, 45, -1, -1, -1]\n assert candidate(nums = [1, 2, 0, 4, 3, 5, 6, 7, 8, 9]) == [4, 3, 3, 6, 6, 7, 8, 9, -1, -1]\n assert candidate(nums = [5, 4, 3, 2, 1]) == [-1, -1, -1, -1, -1]\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == [3, 3, 4, 4, 5, 5, -1, -1, -1, -1]\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11]) == [-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]) == [3, 4, 5, 6, 7, 8, 9, 10, -1, -1]\n assert candidate(nums = [8, 1, 5, 2, 7]) == [-1, 2, -1, -1, -1]\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1]) == [2, -1, 2, -1, -1, -1, -1]\n assert candidate(nums = [2, 4, 0, 9, 6]) == [9, 6, 6, -1, -1]\n", "comparison": "exact"}, "public_tests": ["[2,4,0,9,6]", "[3,3]"], "hints": ["Move forward in nums and store the value in a non-increasing stack for the first greater value.", "Move the value in the stack to an ordered data structure for the second greater value.", "Move value from the ordered data structure for the answer."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().secondGreaterElement", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:24+00:00", "tests_total": 224, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "binary-search", "stack", "sorting", "heap-priority-queue", "monotonic-stack"]}, "language": "php", "interface": {"raw_signature": "function secondGreaterElement($nums) {", "container": "Solution", "callable": "secondGreaterElement", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2455, "task_id": "average-value-of-even-numbers-that-are-divisible-by-three", "difficulty": "Easy", "problem_description": "Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.\n\nNote that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.\n\nExample 1:\n\nInput: nums = [1,3,6,10,12,15]\nOutput: 9\nExplanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.\n\nExample 2:\n\nInput: nums = [1,2,4,7,10]\nOutput: 0\nExplanation: There is no single number that satisfies the requirement, so return 0.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 18\n assert candidate(nums = [3, 9, 15, 21, 27, 33]) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12]) == 9\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80]) == 42\n assert candidate(nums = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300]) == 165\n assert candidate(nums = [2, 6, 18, 24, 30]) == 19\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 6\n assert candidate(nums = [4, 8, 16, 20, 24, 28]) == 24\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 18\n assert candidate(nums = [30, 60, 90, 120, 150, 180]) == 105\n assert candidate(nums = [1, 5, 7, 11, 13, 17]) == 0\n assert candidate(nums = [1, 3, 6, 10, 12, 15]) == 9\n assert candidate(nums = [1, 5, 7, 11, 13, 17, 19, 23, 25, 29]) == 0\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]) == 54\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 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 12\n assert candidate(nums = [3, 9, 15, 21, 27]) == 0\n assert candidate(nums = [2, 6, 12, 18, 24, 30]) == 18\n assert candidate(nums = [36, 72, 108, 144, 180]) == 108\n assert candidate(nums = [2, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114]) == 60\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981]) == 990\n assert candidate(nums = [1, 2, 4, 7, 10]) == 0\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 0\n assert candidate(nums = [33, 66, 99, 132, 165, 198, 231, 264, 297, 330]) == 198\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]) == 33\n assert candidate(nums = [1, 5, 7, 11, 13, 17, 19, 23, 29, 31]) == 0\n assert candidate(nums = [1, 5, 7, 11, 13, 17, 19]) == 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]) == 12\n assert candidate(nums = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]) == 24\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57]) == 0\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, 949, 948, 947, 946, 945, 944, 943, 942, 941, 940, 939, 938, 937, 936, 935, 934, 933, 932, 931, 930]) == 963\n assert candidate(nums = [300, 306, 312, 318, 324, 330, 336, 342, 348, 354, 360, 366, 372, 378, 384, 390]) == 345\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 600\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78, 90, 102, 114]) == 60\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550]) == 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, 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]) == 51\n assert candidate(nums = [100, 102, 104, 105, 106, 108, 110, 111, 112, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]) == 114\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]) == 18\n assert candidate(nums = [6, 36, 72, 108, 144, 180, 216, 252, 288, 324, 360, 396, 432, 468, 504]) == 252\n assert candidate(nums = [2, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 33\n assert candidate(nums = [150, 162, 174, 186, 198, 210, 222, 234, 246, 258, 270, 282, 294, 306, 318, 330, 342, 354, 366, 378]) == 264\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]) == 84\n assert candidate(nums = [24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252]) == 138\n assert candidate(nums = [150, 210, 270, 330, 390, 450, 510, 570, 630, 690, 750, 810, 870, 930, 990]) == 570\n assert candidate(nums = [8, 14, 18, 20, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90]) == 54\n assert candidate(nums = [2, 3, 5, 6, 9, 10, 12, 15, 18, 21, 24, 27, 30]) == 18\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120]) == 63\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900, 960]) == 510\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]) == 18\n assert candidate(nums = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000]) == 525\n assert candidate(nums = [100, 102, 104, 105, 108, 110, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180]) == 141\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]) == 0\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, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]) == 33\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 9\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]) == 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, 42, 44, 46, 48, 50]) == 27\n assert candidate(nums = [102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 228, 234, 240]) == 171\n assert candidate(nums = [300, 303, 306, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 354, 357]) == 327\n assert candidate(nums = [102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198]) == 150\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117, 123, 129, 135, 141, 147, 153, 159, 165, 171, 177, 183, 189, 195, 201, 207, 213, 219, 225, 231, 237, 243, 249, 255, 261, 267, 273, 279, 285, 291, 297, 303, 309, 315, 321, 327, 333, 339, 345, 351, 357, 363, 369, 375, 381, 387, 393, 399]) == 0\n assert candidate(nums = [600, 600, 600, 600, 600, 600, 600, 600, 600, 600]) == 600\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]) == 48\n assert candidate(nums = [18, 36, 54, 72, 90, 108, 126, 144, 162, 180, 198, 216, 234, 252, 270, 288, 306, 324, 342, 360]) == 189\n assert candidate(nums = [300, 303, 306, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342, 345, 348, 351, 354, 357, 360, 363, 366, 369, 372]) == 336\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150]) == 78\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981]) == 990\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99]) == 0\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]) == 51\n assert candidate(nums = [36, 72, 108, 144, 180, 216, 252, 288, 324, 360]) == 198\n assert candidate(nums = [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]) == 0\n assert candidate(nums = [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, 198, 204, 210]) == 117\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]) == 21\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 21\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]) == 984\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 33\n assert candidate(nums = [600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638]) == 618\n assert candidate(nums = [123, 126, 129, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180]) == 153\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980]) == 990\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 18\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]) == 132\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]) == 78\n assert candidate(nums = [6, 12, 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]) == 93\n assert candidate(nums = [36, 72, 108, 144, 180, 216, 252, 288, 324, 360]) == 198\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57]) == 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, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]) == 51\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96]) == 51\n assert candidate(nums = [45, 90, 135, 180, 225, 270, 315, 360, 405, 450, 495, 540, 585, 630, 675, 720, 765, 810, 855, 900]) == 495\n assert candidate(nums = [300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338]) == 318\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78, 90, 102, 114, 126, 138, 150, 162, 174, 186, 198, 210, 222, 234, 246, 258, 270]) == 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]) == 12\n assert candidate(nums = [33, 66, 99, 132, 165, 198, 231, 264, 297, 330, 363, 396, 429, 462, 495, 528, 561, 594, 627, 660]) == 363\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, 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]) == 108\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]) == 27\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]) == 51\n assert candidate(nums = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120]) == 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, 66, 69, 72, 75, 78, 81, 84, 87, 90]) == 48\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, 100]) == 48\n assert candidate(nums = [27, 54, 81, 108, 135, 162, 189, 216, 243, 270, 297, 324, 351, 378, 405, 432, 459, 486, 513, 540]) == 297\n assert candidate(nums = [3, 5, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]) == 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]) == 60\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]) == 0\n assert candidate(nums = [996, 998, 1000, 999, 993, 990, 987, 984, 981, 978, 975, 972, 969, 966, 963, 960, 957, 954, 951, 948]) == 972\n assert candidate(nums = [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600]) == 315\n assert candidate(nums = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195]) == 0\n assert candidate(nums = [3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 87, 93, 99, 105, 111, 117, 123, 129, 135, 141, 147]) == 0\n assert candidate(nums = [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]) == 504\n assert candidate(nums = [100, 102, 104, 105, 108, 110, 112, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147, 150]) == 126\n assert candidate(nums = [6, 18, 30, 42, 54, 66, 78, 90, 102, 114, 126, 138, 150, 162, 174, 186, 198, 210, 222, 234, 246, 258, 270, 282, 294, 300, 306, 312, 318, 324, 330]) == 181\n assert candidate(nums = [200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238]) == 219\n assert candidate(nums = [999, 996, 993, 990, 987, 984, 981, 978, 975, 972, 969, 966, 963, 960, 957, 954, 951, 948, 945, 942, 939, 936, 933, 930, 927, 924, 921, 918, 915, 912, 909, 906, 903, 900, 897, 894, 891, 888, 885, 882, 879, 876, 873, 870, 867, 864, 861, 858, 855, 852, 849, 846, 843, 840, 837, 834, 831, 828, 825, 822, 819, 816, 813, 810, 807, 804, 801, 798, 795, 792, 789, 786, 783, 780, 777, 774, 771, 768, 765, 762, 759, 756, 753, 750, 747, 744, 741, 738, 735, 732, 729, 726, 723, 720, 717, 714, 711, 708, 705, 702, 699, 696, 693, 690, 687, 684, 681, 678, 675, 672, 669, 666, 663, 660, 657, 654, 651, 648, 645, 642, 639, 636, 633, 630, 627, 624, 621, 618, 615, 612, 609, 606, 603, 600]) == 798\n assert candidate(nums = [999, 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]) == 930\n", "comparison": "exact"}, "public_tests": ["[1,3,6,10,12,15]", "[1,2,4,7,10]"], "hints": ["What is the property of a number if it is divisible by both 2 and 3 at the same time?", "It is equivalent to finding all the numbers that are divisible by 6."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().averageValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:26+00:00", "tests_total": 124, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "math"]}, "language": "php", "interface": {"raw_signature": "function averageValue($nums) {", "container": "Solution", "callable": "averageValue", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2456, "task_id": "most-popular-video-creator", "difficulty": "Medium", "problem_description": "You are given two string arrays creators and ids, and an integer array views, all of length n. The i^th video on a platform was created by creators[i], has an id of ids[i], and has views[i] views.\n\nThe popularity of a creator is the sum of the number of views on all of the creator's videos. Find the creator with the highest popularity and the id of their most viewed video.\n\n- If multiple creators have the highest popularity, find all of them.\n- If multiple videos have the highest view count for a creator, find the lexicographically smallest id.\n\nNote: It is possible for different videos to have the same id, meaning that ids do not uniquely identify a video. For example, two videos with the same ID are considered as distinct videos with their own viewcount.\n\nReturn a 2D array of strings answer where answer[i] = [creators_i, id_i] means that creators_i has the highest popularity and id_i is the id of their most popular video. The answer can be returned in any order.\n\nExample 1:\n\nInput: creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4]\nOutput: [[\"alice\",\"one\"],[\"bob\",\"two\"]]\nExplanation:\nThe popularity of alice is 5 + 5 = 10.\nThe popularity of bob is 10.\nThe popularity of chris is 4.\nalice and bob are the most popular creators.\nFor bob, the video with the highest view count is \"two\".\nFor alice, the videos with the highest view count are \"one\" and \"three\". Since \"one\" is lexicographically smaller than \"three\", it is included in the answer.\n\nExample 2:\n\nInput: creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = [1,2,2]\nOutput: [[\"alice\",\"b\"]]\nExplanation:\nThe videos with id \"b\" and \"c\" have the highest view count.\nSince \"b\" is lexicographically smaller than \"c\", it is included in the answer.\n\nConstraints:\n\n- n == creators.length == ids.length == views.length\n- 1 <= n <= 10^5\n- 1 <= creators[i].length, ids[i].length <= 5\n- creators[i] and ids[i] consist only of lowercase English letters.\n- 0 <= views[i] <= 10^5\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(creators=['eve', 'eve', 'eve', 'eve'], ids=['a', 'a', 'b', 'b'], views=[10, 20, 20, 10]), [['eve', 'a']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris'], ids=['one', 'two', 'three', 'four'], views=[5, 10, 5, 4]), [['alice', 'one'], ['bob', 'two']])\n assert answers_match(candidate(creators=['john', 'john', 'john'], ids=['x', 'y', 'x'], views=[10, 10, 10]), [['john', 'x']])\n assert answers_match(candidate(creators=['alice', 'alice', 'alice'], ids=['a', 'b', 'c'], views=[1, 2, 2]), [['alice', 'b']])\n assert answers_match(candidate(creators=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], ids=['id', 'id', 'id', 'id', 'id', 'id', 'id', 'id', 'id', 'id'], views=[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [['a', 'id']])\n assert answers_match(candidate(creators=['frank', 'frank', 'frank', 'frank', 'frank', 'frank'], ids=['one', 'two', 'three', 'four', 'five', 'six'], views=[1000, 1000, 1000, 1000, 1000, 1000]), [['frank', 'five']])\n assert answers_match(candidate(creators=['alice', 'alice', 'alice', 'bob', 'bob', 'bob'], ids=['x', 'y', 'z', 'x', 'y', 'z'], views=[10, 20, 30, 30, 20, 10]), [['alice', 'z'], ['bob', 'x']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'alice'], ids=['one', 'two', 'three', 'four', 'five'], views=[5, 10, 5, 4, 15]), [['alice', 'five']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob', 'alice'], ids=['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu'], views=[10, 20, 10, 20, 30, 40, 50]), [['alice', 'stu']])\n assert answers_match(candidate(creators=['dave', 'eve', 'eve', 'eve', 'dave'], ids=['x', 'y', 'z', 'y', 'x'], views=[30, 20, 30, 40, 10]), [['eve', 'y']])\n assert answers_match(candidate(creators=['alice', 'alice', 'alice', 'alice', 'alice'], ids=['z', 'y', 'x', 'w', 'v'], views=[5, 5, 5, 5, 5]), [['alice', 'v']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob'], ids=['one', 'two', 'three', 'four', 'five', 'six'], views=[5, 15, 10, 10, 5, 5]), [['bob', 'two']])\n assert answers_match(candidate(creators=['karen', 'karen', 'karen', 'karen', 'karen', 'karen', 'karen', 'karen'], ids=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], views=[100, 200, 100, 200, 100, 200, 100, 200]), [['karen', 'b']])\n assert answers_match(candidate(creators=['mike', 'mike', 'mike', 'mike', 'mike', 'mike', 'mike'], ids=['one', 'two', 'three', 'four', 'five', 'six', 'seven'], views=[10, 20, 30, 40, 50, 60, 70]), [['mike', 'seven']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve'], ids=['a', 'b', 'c', 'd', 'e'], views=[10, 20, 10, 10, 20]), [['eve', 'b']])\n assert answers_match(candidate(creators=['a', 'b', 'a', 'b', 'a', 'b'], ids=['aaa', 'bbb', 'aaa', 'bbb', 'aaa', 'bbb'], views=[1, 2, 3, 4, 5, 6]), [['b', 'bbb']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'bob'], ids=['one', 'two', 'three', 'four', 'five'], views=[5, 15, 5, 4, 15]), [['bob', 'five']])\n assert answers_match(candidate(creators=['anna', 'anna', 'anna', 'anna', 'anna', 'anna'], ids=['x', 'y', 'z', 'x', 'y', 'z'], views=[10, 20, 30, 40, 50, 60]), [['anna', 'z']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'bob', 'alice', 'chris', 'eve', 'eve', 'eve'], ids=['one', 'two', 'three', 'four', 'two', 'six', 'seven', 'eight', 'nine', 'ten'], views=[5, 10, 5, 4, 10, 15, 1, 20, 20, 5]), [['eve', 'eight']])\n assert answers_match(candidate(creators=['frank', 'frank', 'frank', 'frank', 'frank'], ids=['a', 'b', 'a', 'c', 'b'], views=[100, 200, 300, 100, 200]), [['frank', 'a']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'bob', 'alice'], ids=['one', 'two', 'three', 'four', 'two', 'six'], views=[5, 10, 5, 4, 10, 15]), [['alice', 'six']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve', 'eve', 'eve'], ids=['a', 'b', 'c', 'd', 'e', 'f', 'g'], views=[10, 10, 10, 10, 10, 10, 10]), [['eve', 'a']])\n assert answers_match(candidate(creators=['alice', 'alice', 'alice', 'alice', 'alice'], ids=['a', 'a', 'b', 'b', 'c'], views=[10, 10, 20, 20, 30]), [['alice', 'c']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve', 'eve'], ids=['aaa', 'aab', 'aac', 'aad', 'aae', 'aaf'], views=[10, 10, 10, 10, 10, 10]), [['eve', 'aaa']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob'], ids=['a', 'b', 'a', 'b', 'a', 'b'], views=[10, 15, 10, 20, 10, 25]), [['bob', 'b']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob'], ids=['a', 'a', 'b', 'b', 'c', 'c'], views=[10, 20, 30, 40, 50, 60]), [['bob', 'c']])\n assert answers_match(candidate(creators=['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c'], ids=['m', 'n', 'o', 'p', 'q', 'r', 's', 't'], views=[100, 200, 150, 300, 400, 400, 500, 600]), [['b', 'q'], ['c', 't']])\n assert answers_match(candidate(creators=['ivan', 'ivan', 'ivan', 'ivan', 'ivan', 'ivan'], ids=['m', 'n', 'm', 'n', 'm', 'n'], views=[10, 20, 10, 20, 10, 20]), [['ivan', 'n']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'chris', 'bob'], ids=['one', 'two', 'three', 'four', 'five', 'six'], views=[5, 10, 5, 4, 3, 15]), [['bob', 'six']])\n assert answers_match(candidate(creators=['alice', 'alice', 'alice', 'alice', 'alice', 'alice'], ids=['a', 'b', 'c', 'd', 'e', 'f'], views=[100000, 99999, 99998, 99997, 99996, 99995]), [['alice', 'a']])\n assert answers_match(candidate(creators=['nina', 'nina', 'nina', 'nina', 'nina', 'nina', 'nina'], ids=['a', 'a', 'b', 'b', 'c', 'c', 'd'], views=[10, 20, 30, 20, 30, 40, 50]), [['nina', 'd']])\n assert answers_match(candidate(creators=['dave', 'eve', 'frank', 'dave', 'eve', 'frank'], ids=['alpha', 'beta', 'gamma', 'alpha', 'beta', 'gamma'], views=[10, 20, 10, 5, 25, 15]), [['eve', 'beta']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'alice'], ids=['one', 'two', 'three', 'four', 'five'], views=[5, 10, 15, 4, 10]), [['alice', 'three']])\n assert answers_match(candidate(creators=['isaac', 'jack', 'isaac', 'jack', 'isaac', 'jack'], ids=['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], views=[1, 2, 1, 2, 1, 2]), [['jack', 'bbb']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'chris', 'bob', 'alice', 'chris'], ids=['one', 'two', 'three', 'four', 'two', 'six', 'seven'], views=[5, 10, 5, 4, 10, 15, 1]), [['alice', 'six']])\n assert answers_match(candidate(creators=['tom', 'jerry', 'spike', 'tom', 'jerry', 'spike'], ids=['q', 'w', 'e', 'r', 't', 'y'], views=[100, 200, 150, 100, 200, 150]), [['jerry', 't']])\n assert answers_match(candidate(creators=['karen', 'karen', 'karen', 'karen', 'karen', 'karen'], ids=['a', 'b', 'c', 'd', 'e', 'f'], views=[1, 2, 3, 4, 5, 6]), [['karen', 'f']])\n assert answers_match(candidate(creators=['anna', 'anna', 'anna', 'anna'], ids=['aaa', 'bbb', 'aaa', 'bbb'], views=[50, 50, 50, 50]), [['anna', 'aaa']])\n assert answers_match(candidate(creators=['leo', 'leo', 'leo', 'leo', 'leo'], ids=['z', 'y', 'x', 'w', 'v'], views=[1000, 1000, 1000, 1000, 1000]), [['leo', 'v']])\n assert answers_match(candidate(creators=['nina', 'nina', 'nina', 'nina', 'nina', 'nina', 'nina', 'nina', 'nina', 'nina'], ids=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], views=[10, 20, 10, 20, 10, 20, 10, 20, 10, 20]), [['nina', 'b']])\n assert answers_match(candidate(creators=['anna', 'anna', 'anna', 'anna'], ids=['aaa', 'aab', 'aac', 'aad'], views=[5, 5, 5, 5]), [['anna', 'aaa']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob'], ids=['a', 'a', 'b', 'b', 'c', 'c'], views=[10, 20, 20, 10, 30, 30]), [['alice', 'c'], ['bob', 'c']])\n assert answers_match(candidate(creators=['alice', 'alice', 'bob', 'bob', 'alice', 'bob'], ids=['a', 'b', 'c', 'd', 'e', 'f'], views=[10, 20, 30, 30, 40, 10]), [['alice', 'e'], ['bob', 'c']])\n assert answers_match(candidate(creators=['dave', 'dave', 'dave', 'dave'], ids=['aaa', 'aab', 'aac', 'aad'], views=[1000, 1000, 1000, 1000]), [['dave', 'aaa']])\n assert answers_match(candidate(creators=['alice', 'alice', 'bob', 'bob', 'bob'], ids=['abc', 'def', 'ghi', 'jkl', 'mno'], views=[50, 50, 60, 60, 60]), [['bob', 'ghi']])\n assert answers_match(candidate(creators=['alice', 'bob', 'bob', 'alice', 'chris'], ids=['a', 'b', 'c', 'a', 'd'], views=[10, 20, 20, 30, 5]), [['alice', 'a'], ['bob', 'b']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve', 'eve'], ids=['a', 'b', 'c', 'd', 'e', 'f'], views=[5, 10, 15, 20, 25, 30]), [['eve', 'f']])\n assert answers_match(candidate(creators=['karen', 'leo', 'mike', 'leo', 'karen', 'mike'], ids=['a', 'b', 'c', 'd', 'e', 'f'], views=[30, 40, 30, 40, 30, 40]), [['leo', 'b']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve'], ids=['x', 'y', 'z', 'x', 'y'], views=[10, 20, 30, 10, 20]), [['eve', 'z']])\n assert answers_match(candidate(creators=['jane', 'jane', 'jane', 'jane', 'jane', 'jane'], ids=['one', 'two', 'three', 'four', 'five', 'six'], views=[10, 10, 10, 10, 10, 10]), [['jane', 'five']])\n assert answers_match(candidate(creators=['dave', 'eve', 'frank', 'dave', 'eve', 'frank'], ids=['m', 'n', 'o', 'p', 'q', 'r'], views=[100, 200, 150, 250, 175, 225]), [['eve', 'n'], ['frank', 'r']])\n assert answers_match(candidate(creators=['eve', 'eve', 'eve', 'eve', 'eve'], ids=['x', 'y', 'z', 'x', 'y'], views=[10, 20, 10, 20, 10]), [['eve', 'x']])\n assert answers_match(candidate(creators=['anna', 'anna', 'anna', 'bob', 'bob'], ids=['a', 'b', 'c', 'a', 'b'], views=[100, 100, 150, 200, 200]), [['bob', 'a']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice'], ids=['x', 'y', 'z', 'x', 'y'], views=[10, 20, 10, 20, 30]), [['alice', 'y']])\n assert answers_match(candidate(creators=['alice', 'bob', 'alice', 'bob', 'alice', 'bob', 'alice', 'bob'], ids=['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'], views=[1, 2, 3, 4, 5, 6, 7, 8]), [['bob', 'a']])\n assert answers_match(candidate(creators=['mike', 'mike', 'mike', 'mike', 'mike', 'mike'], ids=['same', 'same', 'same', 'same', 'same', 'same'], views=[5, 5, 5, 5, 5, 5]), [['mike', 'same']])\n assert answers_match(candidate(creators=['x', 'y', 'z', 'x', 'y', 'z'], ids=['a', 'b', 'c', 'a', 'b', 'c'], views=[10, 10, 10, 20, 20, 20]), [['x', 'a'], ['y', 'b'], ['z', 'c']])\n assert answers_match(candidate(creators=['peter', 'quinn', 'peter', 'quinn', 'peter', 'quinn'], ids=['zero', 'one', 'zero', 'one', 'zero', 'one'], views=[500, 600, 700, 800, 900, 1000]), [['quinn', 'one']])\n assert answers_match(candidate(creators=['anna', 'anna', 'anna', 'anna', 'anna'], ids=['z', 'y', 'x', 'w', 'v'], views=[5, 5, 5, 5, 5]), [['anna', 'v']])\n assert answers_match(candidate(creators=['z', 'z', 'z', 'y', 'y', 'y', 'x', 'x', 'x'], ids=['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'], views=[100, 200, 150, 300, 400, 400, 500, 600, 650]), [['x', 'c']])\n", "comparison": "unordered"}, "public_tests": ["[\"alice\",\"bob\",\"alice\",\"chris\"]\n[\"one\",\"two\",\"three\",\"four\"]\n[5,10,5,4]", "[\"alice\",\"alice\",\"alice\"]\n[\"a\",\"b\",\"c\"]\n[1,2,2]"], "hints": ["Use a hash table to store and categorize videos based on their creator.", "For each creator, iterate through all their videos and use three variables to keep track of their popularity, their most popular video, and the id of their most popular video."], "metadata": {"canonical_parameter_names": ["creators", "ids", "views"], "leetcode_dataset_entry_point": "Solution().mostPopularCreator", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:29+00:00", "tests_total": 102, "tests_dropped": 42, "flags": ["any_order"], "topic_tags": ["array", "hash-table", "string", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function mostPopularCreator($creators, $ids, $views) {", "container": "Solution", "callable": "mostPopularCreator", "parameters": [{"name": "creators", "type": "String[]"}, {"name": "ids", "type": "String[]"}, {"name": "views", "type": "Integer[]"}], "return_type": "String[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2457, "task_id": "minimum-addition-to-make-integer-beautiful", "difficulty": "Medium", "problem_description": "You are given two positive integers n and target.\n\nAn integer is considered beautiful if the sum of its digits is less than or equal to target.\n\nReturn the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.\n\nExample 1:\n\nInput: n = 16, target = 6\nOutput: 4\nExplanation: Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.\n\nExample 2:\n\nInput: n = 467, target = 6\nOutput: 33\nExplanation: Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.\n\nExample 3:\n\nInput: n = 1, target = 1\nOutput: 0\nExplanation: Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.\n\nConstraints:\n\n- 1 <= n <= 10^12\n- 1 <= target <= 150\n- The input will be generated such that it is always possible to make n beautiful.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 1000000000000,target = 1) == 0\n assert candidate(n = 1,target = 1) == 0\n assert candidate(n = 99999,target = 5) == 1\n assert candidate(n = 8888,target = 32) == 0\n assert candidate(n = 888888888,target = 24) == 1111112\n assert candidate(n = 467,target = 6) == 33\n assert candidate(n = 123456789,target = 30) == 11\n assert candidate(n = 123456789,target = 10) == 543211\n assert candidate(n = 999,target = 27) == 0\n assert candidate(n = 56789,target = 25) == 11\n assert candidate(n = 123,target = 6) == 0\n assert candidate(n = 1000000000,target = 1) == 0\n assert candidate(n = 999,target = 15) == 1\n assert candidate(n = 123456789,target = 20) == 3211\n assert candidate(n = 999999999,target = 10) == 1\n assert candidate(n = 1001,target = 1) == 8999\n assert candidate(n = 999999999999,target = 1) == 1\n assert candidate(n = 16,target = 6) == 4\n assert candidate(n = 111111111,target = 9) == 0\n assert candidate(n = 100000000000,target = 1) == 0\n assert candidate(n = 88888888888,target = 10) == 1111111112\n assert candidate(n = 987654321098,target = 50) == 2\n assert candidate(n = 100,target = 1) == 0\n assert candidate(n = 888888888888,target = 24) == 1111111112\n assert candidate(n = 101010101010,target = 15) == 0\n assert candidate(n = 234567890123,target = 30) == 109877\n assert candidate(n = 666666666666,target = 42) == 333334\n assert candidate(n = 1234567890,target = 15) == 432110\n assert candidate(n = 54321,target = 15) == 0\n assert candidate(n = 1234567890,target = 18) == 32110\n assert candidate(n = 555555555,target = 15) == 4444445\n assert candidate(n = 888888888888,target = 60) == 11112\n assert candidate(n = 1999999999,target = 10) == 1\n assert candidate(n = 567890123456,target = 75) == 0\n assert candidate(n = 9876543210,target = 30) == 3456790\n assert candidate(n = 9876543210,target = 50) == 0\n assert candidate(n = 999999999,target = 1) == 1\n assert candidate(n = 987654321098,target = 27) == 345678902\n assert candidate(n = 500000000000,target = 5) == 0\n assert candidate(n = 987654321,target = 10) == 12345679\n assert candidate(n = 999999999999,target = 10) == 1\n assert candidate(n = 888888888888,target = 35) == 11111112\n assert candidate(n = 876543210,target = 10) == 23456790\n assert candidate(n = 999,target = 2) == 1\n assert candidate(n = 99999999999,target = 9) == 1\n assert candidate(n = 999999999,target = 45) == 1\n assert candidate(n = 598765432109,target = 30) == 34567891\n assert candidate(n = 123456789012,target = 45) == 988\n assert candidate(n = 987654321,target = 20) == 2345679\n assert candidate(n = 54321,target = 8) == 5679\n assert candidate(n = 100100100100,target = 3) == 899900\n assert candidate(n = 888888888,target = 7) == 111111112\n assert candidate(n = 4321,target = 4) == 5679\n assert candidate(n = 999999999999,target = 2) == 1\n assert candidate(n = 599599599,target = 25) == 400401\n assert candidate(n = 567890123456,target = 30) == 9876544\n assert candidate(n = 54321,target = 5) == 45679\n assert candidate(n = 5000000000,target = 5) == 0\n assert candidate(n = 99998,target = 4) == 2\n assert candidate(n = 888888888,target = 15) == 11111112\n assert candidate(n = 888888888,target = 10) == 11111112\n assert candidate(n = 1,target = 2) == 0\n assert candidate(n = 111111111111,target = 12) == 0\n assert candidate(n = 222222222222,target = 24) == 0\n assert candidate(n = 987654321,target = 25) == 345679\n assert candidate(n = 333333333333,target = 30) == 667\n", "comparison": "exact"}, "public_tests": ["16\n6", "467\n6", "1\n1"], "hints": ["Think about each digit independently.", "Turn the rightmost non-zero digit to zero until the digit sum is greater than target."], "metadata": {"canonical_parameter_names": ["n", "target"], "leetcode_dataset_entry_point": "Solution().makeIntegerBeautiful", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:31+00:00", "tests_total": 103, "tests_dropped": 37, "flags": [], "topic_tags": ["math", "greedy"]}, "language": "php", "interface": {"raw_signature": "function makeIntegerBeautiful($n, $target) {", "container": "Solution", "callable": "makeIntegerBeautiful", "parameters": [{"name": "n", "type": "Integer"}, {"name": "target", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2460, "task_id": "apply-operations-to-an-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array nums of size n consisting of non-negative integers.\n\nYou need to apply n - 1 operations to this array where, in the i^th operation (0-indexed), you will apply the following on the i^th element of nums:\n\n- If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.\n\nAfter performing all the operations, shift all the 0's to the end of the array.\n\n- For example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0].\n\nReturn the resulting array.\n\nNote that the operations are applied sequentially, not all at once.\n\nExample 1:\n\nInput: nums = [1,2,2,1,1,0]\nOutput: [1,4,2,0,0,0]\nExplanation: We do the following operations:\n- i = 0: nums[0] and nums[1] are not equal, so we skip this operation.\n- i = 1: nums[1] and nums[2] are equal, we multiply nums[1] by 2 and change nums[2] to 0. The array becomes [1,4,0,1,1,0].\n- i = 2: nums[2] and nums[3] are not equal, so we skip this operation.\n- i = 3: nums[3] and nums[4] are equal, we multiply nums[3] by 2 and change nums[4] to 0. The array becomes [1,4,0,2,0,0].\n- i = 4: nums[4] and nums[5] are equal, we multiply nums[4] by 2 and change nums[5] to 0. The array becomes [1,4,0,2,0,0].\nAfter that, we shift the 0's to the end, which gives the array [1,4,2,0,0,0].\n\nExample 2:\n\nInput: nums = [0,1]\nOutput: [1,0]\nExplanation: No operation can be applied, we just shift the 0 to the end.\n\nConstraints:\n\n- 2 <= nums.length <= 2000\n- 0 <= nums[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [6, 5, 4, 3, 2, 1]) == [6, 5, 4, 3, 2, 1]\n assert candidate(nums = [1, 2, 3, 2, 3, 2]) == [1, 2, 3, 2, 3, 2]\n assert candidate(nums = [2, 2, 0, 0, 1, 1, 1]) == [4, 2, 1, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 0, 0, 10, 10, 10]) == [20, 20, 10, 0, 0, 0, 0]\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 1]) == [1, 6, 3, 4, 1, 0, 0]\n assert candidate(nums = [1, 2, 3, 2, 1, 2]) == [1, 2, 3, 2, 1, 2]\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]\n assert candidate(nums = [10, 10, 0, 0, 10, 10, 0, 0, 10, 10]) == [20, 20, 20, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 3, 3, 3, 2, 2, 1, 1, 0, 0]) == [1, 6, 3, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 1]) == [1, 0]\n assert candidate(nums = [0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0]\n assert candidate(nums = [2, 2, 2, 2, 2, 2]) == [4, 4, 4, 0, 0, 0]\n assert candidate(nums = [1, 0, 1, 0, 1, 0]) == [1, 1, 1, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == [1, 2, 3, 4, 5, 6]\n assert candidate(nums = [10, 10, 20, 20, 30, 30]) == [20, 40, 60, 0, 0, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000, 1000, 0, 0, 1000, 1000]) == [2000, 2000, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 2, 0, 0, 1]) == [1, 2, 1, 0, 0, 0]\n assert candidate(nums = [1, 1, 0, 0, 1, 1]) == [2, 2, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == [10, 10, 10, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 0, 0, 0, 0, 0, 0]) == [10, 10, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 1, 1, 0]) == [1, 4, 2, 0, 0, 0]\n assert candidate(nums = [6, 6, 5, 5, 4, 4]) == [12, 10, 8, 0, 0, 0]\n assert candidate(nums = [2, 2, 0, 0, 1, 1]) == [4, 2, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5]) == [1, 4, 6, 8, 10, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == [2, 2, 2, 0, 0, 0]\n assert candidate(nums = [0, 2, 2, 0, 0, 3, 3, 0, 0, 4, 4]) == [4, 6, 8, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [2, 2, 2, 2, 2]) == [4, 4, 2, 0, 0]\n assert candidate(nums = [2, 2, 0, 0, 2, 2]) == [4, 4, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 0, 0, 0]) == [20, 20, 20, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == [18, 16, 14, 12, 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [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(nums = [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]) == [50, 45, 40, 35, 30, 25, 20, 15, 10, 5]\n assert candidate(nums = [10, 10, 10, 10, 10, 0, 0, 0, 0, 0]) == [20, 20, 10, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == [2, 4, 4, 6, 6, 3, 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]\n assert candidate(nums = [100, 0, 100, 0, 100, 0, 100, 0, 100, 0]) == [100, 100, 100, 100, 100, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 20, 20, 10, 10, 20, 20]) == [10, 40, 20, 40, 0, 0, 0]\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]\n assert candidate(nums = [999, 999, 0, 999, 999, 999, 0, 0, 999, 999, 999]) == [1998, 1998, 999, 1998, 999, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [6, 6, 0, 6, 0, 6, 0, 6, 6, 6, 0, 6, 6, 0]) == [12, 6, 6, 12, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 1, 3, 3, 2, 2, 1, 1]) == [1, 4, 1, 6, 4, 2, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0]) == [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [500, 500, 1000, 1000, 500, 500, 0, 0, 0, 0]) == [1000, 2000, 1000, 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]) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0]) == [1, 1, 1, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 0, 5, 5, 0, 0, 5, 5, 5, 0]) == [5, 10, 10, 5, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == [20, 40, 60, 80, 100, 0, 0, 0, 0, 0]\n assert candidate(nums = [2, 2, 0, 0, 2, 2, 0, 0, 2, 2]) == [4, 4, 4, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 4, 3, 2, 1]\n assert candidate(nums = [1000, 1000, 999, 999, 888, 888, 777, 777]) == [2000, 1998, 1776, 1554, 0, 0, 0, 0]\n assert candidate(nums = [2, 2, 0, 2, 2, 0, 2, 2, 0, 2]) == [4, 4, 4, 2, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [1, 4, 6, 3, 8, 8, 0, 0, 0, 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]\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [1, 2, 6, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [3, 3, 3, 0, 3, 3, 0, 0, 3, 3, 3, 0]) == [6, 3, 6, 6, 3, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == [2, 1, 4, 2, 6, 3, 0, 0, 0]\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 2, 2, 2, 2, 2, 5, 5]) == [10, 5, 4, 4, 2, 10, 0, 0, 0, 0]\n assert candidate(nums = [6, 6, 6, 6, 0, 0, 0, 0, 6, 6]) == [12, 12, 12, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == [2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [3, 3, 3, 0, 3, 3, 0, 0, 3, 3, 3, 0, 3, 0, 3]) == [6, 3, 6, 6, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == [2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == [2000, 2000, 2000, 2000, 2000, 0, 0, 0, 0, 0]\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]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == [2, 4, 6, 8, 10, 0, 0, 0, 0, 0]\n assert candidate(nums = [9, 10, 9, 10, 9, 10, 9, 10, 9, 10]) == [9, 10, 9, 10, 9, 10, 9, 10, 9, 10]\n assert candidate(nums = [999, 0, 999, 0, 999, 0, 999, 0, 999, 0]) == [999, 999, 999, 999, 999, 0, 0, 0, 0, 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]) == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2]) == [4, 2, 4, 2, 4, 2, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 0, 10, 10, 0, 10, 0, 10, 10, 10]) == [10, 20, 10, 20, 10, 0, 0, 0, 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]\n assert candidate(nums = [1, 2, 2, 1, 1, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 1, 0, 0, 0]) == [1, 4, 2, 2, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == [1, 2, 3, 2, 1, 2, 3, 2, 1]\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == [18, 18, 18, 18, 18, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 0, 0, 5, 5, 5, 0]) == [10, 10, 5, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 0, 1, 1, 0, 1, 1]) == [2, 2, 2, 0, 0, 0, 0, 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]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == [18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0]) == [1, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 4, 4, 8, 8, 16, 16, 32]) == [1, 4, 8, 16, 32, 32, 0, 0, 0, 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]\n assert candidate(nums = [3, 0, 3, 3, 0, 0, 3, 3, 0, 3]) == [3, 6, 6, 3, 0, 0, 0, 0, 0, 0]\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0]) == [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]) == [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) == [2, 2, 1, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]) == [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]) == [2000, 2000, 2000, 2000, 0, 0, 0, 0]\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\n assert candidate(nums = [1, 0, 0, 1, 0, 1, 0, 0, 1, 0]) == [1, 1, 1, 1, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000, 1000, 0, 0, 1000, 1000, 1000, 0, 0, 1000]) == [2000, 2000, 1000, 1000, 0, 0, 0, 0, 0, 0]\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, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0]\n assert candidate(nums = [5, 5, 0, 0, 5, 5, 0, 0, 5, 5]) == [10, 10, 10, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 0, 0, 1, 1, 0, 0, 1, 1]) == [2, 2, 2, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0, 0, 0, 0]) == [1, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1, 0, 0, 0, 0]\n assert candidate(nums = [9, 9, 0, 0, 9, 0, 9, 9, 9, 0, 9, 9, 0, 9, 9, 9, 0, 9, 9, 9]) == [18, 9, 18, 9, 18, 18, 9, 18, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1]) == [1, 4, 2, 2, 1, 4, 2, 2, 4, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 0, 0, 1, 0, 0, 1, 0, 0, 1]) == [1, 1, 1, 1, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40]) == [20, 40, 60, 80, 0, 0, 0, 0]\n assert candidate(nums = [0, 1, 1, 2, 2, 0, 3, 3, 0, 4, 4, 0]) == [2, 4, 6, 8, 0, 0, 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]) == [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, 3, 3, 3, 4, 4, 4, 5, 5, 5, 0, 0, 0]) == [2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [7, 0, 7, 0, 7, 0, 7, 0, 7, 0]) == [7, 7, 7, 7, 7, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == [2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [10, 0, 10, 0, 10, 0, 10, 0, 10]) == [10, 10, 10, 10, 10, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 0, 5, 5, 0, 0, 5, 5]) == [10, 5, 10, 10, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [5, 5, 5, 5, 0, 0, 5, 5, 5, 5]) == [10, 10, 10, 10, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [8, 8, 8, 0, 8, 8, 0, 8, 8, 8]) == [16, 8, 16, 16, 8, 0, 0, 0, 0, 0]\n assert candidate(nums = [7, 7, 7, 7, 0, 0, 0, 0, 7, 7]) == [14, 14, 14, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) == [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == [2, 2, 2, 2, 2, 0, 0, 0, 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]) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]\n assert candidate(nums = [100, 200, 200, 100, 100, 200, 200, 100]) == [100, 400, 200, 400, 100, 0, 0, 0]\n assert candidate(nums = [5, 5, 0, 5, 5, 5, 0, 0, 5, 5]) == [10, 10, 5, 10, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) == [2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1000, 1000, 0, 500, 500, 0, 250, 250, 0]) == [2000, 1000, 500, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [0, 0, 1, 1, 0, 0, 1, 1, 0, 0]) == [2, 2, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4]) == [2, 4, 2, 6, 8, 8, 0, 0, 0, 0, 0]\n", "comparison": "exact"}, "public_tests": ["[1,2,2,1,1,0]", "[0,1]"], "hints": ["Iterate over the array and simulate the described process."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().applyOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:38+00:00", "tests_total": 123, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers", "simulation"]}, "language": "php", "interface": {"raw_signature": "function applyOperations($nums) {", "container": "Solution", "callable": "applyOperations", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2461, "task_id": "maximum-sum-of-distinct-subarrays-with-length-k", "difficulty": "Medium", "problem_description": "You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:\n\n- The length of the subarray is k, and\n- All the elements of the subarray are distinct.\n\nReturn the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,5,4,2,9,9,9], k = 3\nOutput: 15\nExplanation: The subarrays of nums with length 3 are:\n- [1,5,4] which meets the requirements and has a sum of 10.\n- [5,4,2] which meets the requirements and has a sum of 11.\n- [4,2,9] which meets the requirements and has a sum of 15.\n- [2,9,9] which does not meet the requirements because the element 9 is repeated.\n- [9,9,9] which does not meet the requirements because the element 9 is repeated.\nWe return 15 because it is the maximum subarray sum of all the subarrays that meet the conditions\n\nExample 2:\n\nInput: nums = [4,4,4], k = 3\nOutput: 0\nExplanation: The subarrays of nums with length 3 are:\n- [4,4,4] which does not meet the requirements because the element 4 is repeated.\nWe return 0 because no subarrays meet the conditions.\n\nConstraints:\n\n- 1 <= k <= 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, 1, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 55\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 1) == 5\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3],k = 3) == 6\n assert candidate(nums = [1, 2, 2, 1, 3, 4, 5, 6],k = 4) == 18\n assert candidate(nums = [1, 2, 2, 3, 4, 5],k = 4) == 14\n assert candidate(nums = [1, 2, 2, 1, 3, 4, 5, 6, 7, 8],k = 4) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],k = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 50\n assert candidate(nums = [1, 2, 3, 4, 5],k = 2) == 9\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1],k = 6) == 45\n assert candidate(nums = [10, 20, 30, 40, 50],k = 5) == 150\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == 30\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 40\n assert candidate(nums = [1, 5, 4, 2, 9, 9, 9],k = 3) == 15\n assert candidate(nums = [4, 4, 4],k = 3) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [100000, 100000, 100000, 100000, 100000],k = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50],k = 4) == 140\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 10) == 0\n assert candidate(nums = [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 = 4) == 34\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],k = 5) == 450\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11],k = 5) == 0\n assert candidate(nums = [5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2],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 = 5) == 0\n assert candidate(nums = [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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7],k = 8) == 44\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 = 6) == 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],k = 10) == 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],k = 7) == 0\n assert candidate(nums = [1, 2, 3, 2, 4, 5, 6, 5, 7, 8, 9],k = 4) == 29\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) == 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],k = 30) == 465\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) == 155\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991],k = 5) == 499990\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) == 0\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 15) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 5) == 0\n assert candidate(nums = [3, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10) == 155\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 15) == 1200\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],k = 5) == 40\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 4) == 22\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 = 8) == 442\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],k = 50) == 0\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],k = 3) == 0\n assert candidate(nums = [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 = 7) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5],k = 10) == 5500\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) == 345\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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 9) == 45\n assert candidate(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990],k = 5) == 499990\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 65\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 20) == 210\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8],k = 5) == 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 155\n assert candidate(nums = [1, 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],k = 10) == 55\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 = 5) == 0\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 = 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 = 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, 32, 33, 34, 35],k = 20) == 510\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],k = 10) == 155\n assert candidate(nums = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11],k = 6) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 5) == 45\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 = 5) == 35\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 = 7) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 34\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],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],k = 10) == 55\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 = 11) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 5) == 35\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500],k = 5) == 6500\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) == 0\n assert candidate(nums = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],k = 8) == 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, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 10) == 255\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10) == 105\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 7) == 84\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 = 4) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10) == 550\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 = 15) == 270\n assert candidate(nums = [5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5],k = 4) == 0\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9) == 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 = 10) == 155\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 = 3) == 0\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5) == 4000\n assert candidate(nums = [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],k = 10) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 40\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],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 = 3) == 0\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9, 9, 10],k = 5) == 35\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) == 55\n assert candidate(nums = [3, 3, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 6) == 57\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 = 10) == 55\n assert candidate(nums = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 15],k = 4) == 54\n", "comparison": "exact"}, "public_tests": ["[1,5,4,2,9,9,9]\n3", "[4,4,4]\n3"], "hints": ["Which elements change when moving from the subarray of size k that ends at index i to the subarray of size k that ends at index i + 1?", "Only two elements change, the element at i + 1 is added into the subarray, and the element at i - k + 1 gets removed from the subarray.", "Iterate through each subarray of size k and keep track of the sum of the subarray and the frequency of each element."], "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-30T20:53:41+00:00", "tests_total": 102, "tests_dropped": 3, "flags": [], "topic_tags": ["array", "hash-table", "sliding-window"]}, "language": "php", "interface": {"raw_signature": "function maximumSubarraySum($nums, $k) {", "container": "Solution", "callable": "maximumSubarraySum", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2462, "task_id": "total-cost-to-hire-k-workers", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the i^th worker.\n\nYou are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:\n\n- You will run k sessions and hire exactly one worker in each session.\n- In each hiring session, choose the worker with the lowest cost from either the first candidates workers or the last candidates workers. Break the tie by the smallest index.\n - For example, if costs = [3,2,7,7,1,2] and candidates = 2, then in the first hiring session, we will choose the 4^th worker because they have the lowest cost [3,2,7,7,1,2].\n - In the second hiring session, we will choose 1^st worker because they have the same lowest cost as 4^th worker but they have the smallest index [3,2,7,7,2]. Please note that the indexing may be changed in the process.\n- If there are fewer than candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.\n- A worker can only be chosen once.\n\nReturn the total cost to hire exactly k workers.\n\nExample 1:\n\nInput: costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4\nOutput: 11\nExplanation: We hire 3 workers in total. The total cost is initially 0.\n- In the first hiring round we choose the worker from [17,12,10,2,7,2,11,20,8]. The lowest cost is 2, and we break the tie by the smallest index, which is 3. The total cost = 0 + 2 = 2.\n- In the second hiring round we choose the worker from [17,12,10,7,2,11,20,8]. The lowest cost is 2 (index 4). The total cost = 2 + 2 = 4.\n- In the third hiring round we choose the worker from [17,12,10,7,11,20,8]. The lowest cost is 7 (index 3). The total cost = 4 + 7 = 11. Notice that the worker with index 3 was common in the first and last four workers.\nThe total hiring cost is 11.\n\nExample 2:\n\nInput: costs = [1,2,4,1], k = 3, candidates = 3\nOutput: 4\nExplanation: We hire 3 workers in total. The total cost is initially 0.\n- In the first hiring round we choose the worker from [1,2,4,1]. The lowest cost is 1, and we break the tie by the smallest index, which is 0. The total cost = 0 + 1 = 1. Notice that workers with index 1 and 2 are common in the first and last 3 workers.\n- In the second hiring round we choose the worker from [2,4,1]. The lowest cost is 1 (index 2). The total cost = 1 + 1 = 2.\n- In the third hiring round there are less than three candidates. We choose the worker from the remaining workers [2,4]. The lowest cost is 2 (index 0). The total cost = 2 + 2 = 4.\nThe total hiring cost is 4.\n\nConstraints:\n\n- 1 <= costs.length <= 10^5\n- 1 <= costs[i] <= 10^5\n- 1 <= k, candidates <= costs.length\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(costs = [10, 10, 10, 10, 10],k = 4,candidates = 2) == 40\n assert candidate(costs = [10, 10, 10, 10, 10],k = 5,candidates = 5) == 50\n assert candidate(costs = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],k = 5,candidates = 5) == 10\n assert candidate(costs = [5, 4, 3, 2, 1],k = 5,candidates = 1) == 15\n assert candidate(costs = [5, 4, 3, 2, 1],k = 3,candidates = 1) == 6\n assert candidate(costs = [5, 5, 5, 5],k = 2,candidates = 2) == 10\n assert candidate(costs = [10, 20, 30, 40, 50],k = 5,candidates = 5) == 150\n assert candidate(costs = [17, 12, 10, 2, 7, 2, 11, 20, 8],k = 3,candidates = 4) == 11\n assert candidate(costs = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9],k = 10,candidates = 10) == 90\n assert candidate(costs = [3, 2, 7, 7, 1, 2],k = 2,candidates = 2) == 3\n assert candidate(costs = [10, 20, 30, 40, 50],k = 2,candidates = 3) == 30\n assert candidate(costs = [1, 2, 4, 1],k = 3,candidates = 3) == 4\n assert candidate(costs = [10, 20, 30, 40, 50],k = 3,candidates = 1) == 60\n assert candidate(costs = [5, 4, 3, 2, 1],k = 2,candidates = 1) == 3\n assert candidate(costs = [25, 15, 30, 20, 10],k = 4,candidates = 2) == 70\n assert candidate(costs = [31, 25, 72, 79, 74],k = 3,candidates = 2) == 128\n assert candidate(costs = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5,candidates = 3) == 150\n assert candidate(costs = [150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 7,candidates = 3) == 280\n assert candidate(costs = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 9,candidates = 4) == 45\n assert candidate(costs = [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],k = 15,candidates = 15) == 300\n assert candidate(costs = [50, 20, 30, 40, 10, 60, 70, 80, 90, 100],k = 6,candidates = 4) == 210\n assert candidate(costs = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10,candidates = 4) == 55\n assert candidate(costs = [1, 3, 2, 4, 5, 7, 6, 8, 10, 9, 11, 13, 12, 14, 15],k = 8,candidates = 4) == 36\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5,candidates = 3) == 5\n assert candidate(costs = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 15,candidates = 6) == 80\n assert candidate(costs = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91],k = 10,candidates = 3) == 955\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,candidates = 6) == 55\n assert candidate(costs = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15,candidates = 8) == 120\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10,candidates = 5) == 31\n assert candidate(costs = [10, 20, 30, 15, 25, 5, 40, 35, 2, 1],k = 5,candidates = 3) == 33\n assert candidate(costs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10,candidates = 2) == 55\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10,candidates = 5) == 10\n assert candidate(costs = [9, 7, 5, 3, 1, 1, 3, 5, 7, 9, 9, 7, 5, 3, 1, 1, 3, 5, 7, 9],k = 10,candidates = 5) == 26\n assert candidate(costs = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 7,candidates = 3) == 28\n assert candidate(costs = [50, 20, 30, 10, 40, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10,candidates = 4) == 550\n assert candidate(costs = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 10,candidates = 5) == 110\n assert candidate(costs = [5, 3, 8, 6, 2, 7, 4, 1, 10, 15, 20, 25, 30],k = 8,candidates = 4) == 36\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],k = 6,candidates = 5) == 210\n assert candidate(costs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],k = 7,candidates = 8) == 2800\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 10,candidates = 5) == 55\n assert candidate(costs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,candidates = 10) == 55\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7,candidates = 4) == 280\n assert candidate(costs = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10],k = 15,candidates = 7) == 255\n assert candidate(costs = [5, 3, 8, 6, 2, 7, 4, 1],k = 4,candidates = 4) == 10\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 15,candidates = 4) == 120\n assert candidate(costs = [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],k = 15,candidates = 10) == 1200\n assert candidate(costs = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7,candidates = 5) == 280\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,candidates = 3) == 150\n assert candidate(costs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 7,candidates = 5) == 280\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 5,candidates = 3) == 150\n assert candidate(costs = [2, 1, 3, 4, 5, 6, 7, 8, 9],k = 5,candidates = 2) == 15\n assert candidate(costs = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],k = 8,candidates = 5) == 19\n assert candidate(costs = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000],k = 5,candidates = 2) == 15000\n assert candidate(costs = [50, 40, 30, 20, 10, 1, 2, 3, 4, 5],k = 5,candidates = 2) == 15\n assert candidate(costs = [30, 20, 10, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],k = 10,candidates = 6) == 550\n assert candidate(costs = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],k = 20,candidates = 10) == 400\n assert candidate(costs = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 5,candidates = 2) == 150000\n assert candidate(costs = [30, 20, 10, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165],k = 10,candidates = 5) == 305\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,candidates = 5) == 55\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10,candidates = 1) == 10\n assert candidate(costs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5,candidates = 2) == 50\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7,candidates = 6) == 280\n assert candidate(costs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 15,candidates = 7) == 205\n assert candidate(costs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 10,candidates = 5) == 100\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 10,candidates = 5) == 55\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 7,candidates = 5) == 280\n assert candidate(costs = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8,candidates = 5) == 36\n assert candidate(costs = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30],k = 10,candidates = 6) == 110\n assert candidate(costs = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 12],k = 6,candidates = 4) == 21\n assert candidate(costs = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],k = 5,candidates = 2) == 50\n assert candidate(costs = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],k = 10,candidates = 1) == 5500\n assert candidate(costs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5,candidates = 2) == 150\n assert candidate(costs = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5,candidates = 5) == 15\n assert candidate(costs = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 5,candidates = 3) == 150\n assert candidate(costs = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 5,candidates = 2) == 18\n assert candidate(costs = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000],k = 10,candidates = 5) == 550000\n assert candidate(costs = [5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5, 2],k = 10,candidates = 5) == 23\n assert candidate(costs = [5, 1, 4, 2, 3],k = 3,candidates = 1) == 9\n assert candidate(costs = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10,candidates = 5) == 55\n assert candidate(costs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 10,candidates = 5) == 55\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10,candidates = 5) == 10\n assert candidate(costs = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 15,candidates = 6) == 120\n assert candidate(costs = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 10,candidates = 10) == 1000\n assert candidate(costs = [5, 3, 8, 6, 2, 7, 4, 1],k = 4,candidates = 2) == 10\n assert candidate(costs = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],k = 7,candidates = 4) == 700\n assert candidate(costs = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6],k = 8,candidates = 4) == 19\n assert candidate(costs = [10, 5, 15, 20, 25, 30, 35, 40, 45, 50],k = 5,candidates = 3) == 75\n assert candidate(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, 27, 28, 29, 30],k = 25,candidates = 5) == 325\n assert candidate(costs = [9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3,candidates = 2) == 6\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 10,candidates = 2) == 10\n assert candidate(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],k = 15,candidates = 10) == 120\n assert candidate(costs = [50, 40, 30, 20, 10, 10, 20, 30, 40, 50],k = 5,candidates = 5) == 90\n assert candidate(costs = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 5,candidates = 3) == 1500\n assert candidate(costs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 15,candidates = 5) == 15\n assert candidate(costs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 5,candidates = 4) == 150\n assert candidate(costs = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100],k = 10,candidates = 5) == 275\n assert candidate(costs = [1, 3, 2, 4, 5, 7, 6, 9, 8, 10, 12, 11, 14, 13, 15, 17, 16, 19, 18, 20],k = 10,candidates = 5) == 55\n", "comparison": "exact"}, "public_tests": ["[17,12,10,2,7,2,11,20,8]\n3\n4", "[1,2,4,1]\n3\n3"], "hints": ["Maintain two minheaps: one for the left and one for the right.", "Compare the top element from two heaps and remove the appropriate one.", "Add a new element to the heap and maintain its size as k."], "metadata": {"canonical_parameter_names": ["costs", "k", "candidates"], "leetcode_dataset_entry_point": "Solution().totalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:43+00:00", "tests_total": 99, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "two-pointers", "heap-priority-queue", "simulation"]}, "language": "php", "interface": {"raw_signature": "function totalCost($costs, $k, $candidates) {", "container": "Solution", "callable": "totalCost", "parameters": [{"name": "costs", "type": "Integer[]"}, {"name": "k", "type": "Integer"}, {"name": "candidates", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2463, "task_id": "minimum-total-distance-traveled", "difficulty": "Hard", "problem_description": "There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the i^th robot. You are also given a 2D integer array factory where factory[j] = [position_j, limit_j] indicates that position_j is the position of the j^th factory and that the j^th factory can repair at most limit_j robots.\n\nThe positions of each robot are unique. The positions of each factory are also unique. Note that a robot can be in the same position as a factory initially.\n\nAll the robots are initially broken; they keep moving in one direction. The direction could be the negative or the positive direction of the X-axis. When a robot reaches a factory that did not reach its limit, the factory repairs the robot, and it stops moving.\n\nAt any moment, you can set the initial direction of moving for some robot. Your target is to minimize the total distance traveled by all the robots.\n\nReturn the minimum total distance traveled by all the robots. The test cases are generated such that all the robots can be repaired.\n\nNote that\n\n- All robots move at the same speed.\n- If two robots move in the same direction, they will never collide.\n- If two robots move in opposite directions and they meet at some point, they do not collide. They cross each other.\n- If a robot passes by a factory that reached its limits, it crosses it as if it does not exist.\n- If the robot moved from a position x to a position y, the distance it moved is |y - x|.\n\nExample 1:\n\nInput: robot = [0,4,6], factory = [[2,2],[6,2]]\nOutput: 4\nExplanation: As shown in the figure:\n- The first robot at position 0 moves in the positive direction. It will be repaired at the first factory.\n- The second robot at position 4 moves in the negative direction. It will be repaired at the first factory.\n- The third robot at position 6 will be repaired at the second factory. It does not need to move.\nThe limit of the first factory is 2, and it fixed 2 robots.\nThe limit of the second factory is 2, and it fixed 1 robot.\nThe total distance is |2 - 0| + |2 - 4| + |6 - 6| = 4. It can be shown that we cannot achieve a better total distance than 4.\n\nExample 2:\n\nInput: robot = [1,-1], factory = [[-2,1],[2,1]]\nOutput: 2\nExplanation: As shown in the figure:\n- The first robot at position 1 moves in the positive direction. It will be repaired at the second factory.\n- The second robot at position -1 moves in the negative direction. It will be repaired at the first factory.\nThe limit of the first factory is 1, and it fixed 1 robot.\nThe limit of the second factory is 1, and it fixed 1 robot.\nThe total distance is |2 - 1| + |(-2) - (-1)| = 2. It can be shown that we cannot achieve a better total distance than 2.\n\nConstraints:\n\n- 1 <= robot.length, factory.length <= 100\n- factory[j].length == 2\n- -10^9 <= robot[i], position_j <= 10^9\n- 0 <= limit_j <= robot.length\n- The input will be generated such that it is always possible to repair every robot.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(robot = [5, 1, 3],factory = [[2, 3]]) == 5\n assert candidate(robot = [5, 5, 5, 5],factory = [[5, 4]]) == 0\n assert candidate(robot = [-3, 0, 3],factory = [[-2, 1], [2, 1], [5, 2]]) == 5\n assert candidate(robot = [-1, -3, 2, 4, 5],factory = [[-2, 1], [2, 2], [6, 2]]) == 7\n assert candidate(robot = [-5, -2, 0, 2, 5],factory = [[-3, 2], [1, 3]]) == 9\n assert candidate(robot = [5, 8, 15],factory = [[10, 2], [16, 1]]) == 8\n assert candidate(robot = [10, 20, 30, 40],factory = [[5, 2], [15, 2], [25, 2]]) == 30\n assert candidate(robot = [-10, 0, 10],factory = [[-5, 1], [0, 2], [5, 1]]) == 10\n assert candidate(robot = [5, 2, -5],factory = [[-2, 2], [2, 2]]) == 6\n assert candidate(robot = [10, -10, 0],factory = [[0, 3]]) == 20\n assert candidate(robot = [0, 4, 6],factory = [[2, 2], [6, 2]]) == 4\n assert candidate(robot = [3, 7, 12, 15],factory = [[2, 3], [10, 2]]) == 13\n assert candidate(robot = [-3, 0, 3],factory = [[-2, 1], [2, 2]]) == 4\n assert candidate(robot = [1, -1],factory = [[-2, 1], [2, 1]]) == 2\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-15, 2], [0, 1], [15, 2]]) == 20\n assert candidate(robot = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],factory = [[-5, 2], [-15, 2], [-25, 2], [-35, 2], [-45, 2], [-55, 2], [-65, 2], [-75, 2], [-85, 2], [-95, 2]]) == 50\n assert candidate(robot = [-15, -10, -5, 0, 5, 10, 15],factory = [[-12, 2], [-7, 2], [-2, 2], [3, 2], [8, 2], [13, 2]]) == 15\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[5, 3], [10, 4], [15, 3]]) == 45\n assert candidate(robot = [-1, -2, -3, -4, -5],factory = [[-10, 3], [0, 2], [10, 1]]) == 21\n assert candidate(robot = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],factory = [[5, 3], [15, 3], [25, 3], [35, 3], [45, 3], [55, 3], [65, 3], [75, 3], [85, 3], [95, 3], [105, 3], [115, 3], [125, 3], [135, 3]]) == 75\n assert candidate(robot = [0, 2, 4, 6, 8, 10],factory = [[1, 1], [3, 1], [5, 1], [7, 1], [9, 1], [11, 1]]) == 6\n assert candidate(robot = [100, 200, 300, 400, 500],factory = [[50, 1], [150, 2], [250, 2], [350, 2], [450, 1], [550, 1]]) == 250\n assert candidate(robot = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],factory = [[0, 2], [6, 3], [12, 3], [18, 2]]) == 16\n assert candidate(robot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],factory = [[0, 5], [5, 5]]) == 20\n assert candidate(robot = [-1, 1, -2, 2, -3, 3, -4, 4, -5, 5],factory = [[-3, 3], [0, 4], [3, 3]]) == 12\n assert candidate(robot = [-5, 0, 5, 10, 15, 20, 25, 30, 35, 40],factory = [[-10, 2], [5, 3], [20, 3], [35, 2]]) == 50\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[0, 3], [5, 4], [10, 3]]) == 13\n assert candidate(robot = [-100, -50, 0, 50, 100],factory = [[-75, 2], [-25, 1], [25, 1], [75, 2]]) == 125\n assert candidate(robot = [10, 20, 30, 40, 50, 60, 70, 80, 90],factory = [[0, 3], [10, 3], [20, 3], [30, 3], [40, 3], [50, 3], [60, 3], [70, 3], [80, 3], [90, 3]]) == 0\n assert candidate(robot = [-2, -1, 0, 1, 2, 3, 4],factory = [[-3, 2], [0, 3], [3, 2]]) == 7\n assert candidate(robot = [-10, -5, 0, 5, 10, 15, 20],factory = [[-20, 1], [-10, 2], [0, 3], [10, 2], [20, 1]]) == 15\n assert candidate(robot = [-100, -50, 0, 50, 100],factory = [[-75, 2], [0, 2], [75, 2]]) == 100\n assert candidate(robot = [-100, -50, 0, 50, 100, 150],factory = [[-75, 3], [25, 2], [125, 2]]) == 150\n assert candidate(robot = [-100, -50, 0, 50, 100, 150, 200],factory = [[-75, 2], [-25, 2], [25, 2], [75, 2], [125, 2], [175, 2]]) == 175\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],factory = [[0, 5], [5, 5], [10, 5], [15, 5]]) == 60\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-15, 1], [-5, 2], [5, 3], [15, 1]]) == 25\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9],factory = [[2, 3], [5, 3], [8, 3]]) == 6\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-15, 2], [0, 3], [15, 2]]) == 20\n assert candidate(robot = [100, 200, 300, 400, 500],factory = [[50, 2], [150, 1], [250, 2], [350, 1], [450, 1]]) == 250\n assert candidate(robot = [1, 3, 5, 7, 9, 11],factory = [[2, 2], [6, 2], [10, 2]]) == 6\n assert candidate(robot = [1, 3, 5, 7, 9],factory = [[2, 2], [4, 2], [6, 2], [8, 2], [10, 1]]) == 5\n assert candidate(robot = [10, 20, 30, 40, 50, 60],factory = [[15, 2], [35, 2], [55, 2]]) == 30\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-15, 2], [-5, 3], [5, 2], [15, 1]]) == 25\n assert candidate(robot = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],factory = [[0, 10]]) == 10\n assert candidate(robot = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10],factory = [[-105, 2], [-95, 2], [-85, 2], [-75, 2], [-65, 2], [-55, 2], [-45, 2], [-35, 2], [-25, 2], [-15, 2]]) == 50\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[0, 10]]) == 55\n assert candidate(robot = [10, 20, 30, 40],factory = [[15, 2], [25, 2], [35, 2]]) == 20\n assert candidate(robot = [-10, -5, 0, 5, 10, 15, 20],factory = [[-7, 2], [-2, 2], [3, 2], [8, 2]]) == 35\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-15, 2], [0, 3], [15, 1]]) == 25\n assert candidate(robot = [-20, -15, -10, -5, 0, 5, 10, 15, 20],factory = [[-15, 2], [-10, 2], [-5, 2], [0, 2], [5, 2], [10, 2], [15, 2]]) == 10\n assert candidate(robot = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],factory = [[-6, 3], [0, 5], [6, 3]]) == 18\n assert candidate(robot = [-5, -3, -1, 1, 3, 5],factory = [[-10, 1], [-5, 2], [0, 3], [5, 2], [10, 1]]) == 6\n assert candidate(robot = [1, 3, 5, 7, 9],factory = [[0, 2], [4, 2], [8, 2]]) == 5\n assert candidate(robot = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28],factory = [[3, 3], [9, 3], [15, 3], [21, 3]]) == 25\n assert candidate(robot = [10, 10, 10, 10],factory = [[10, 1], [10, 1], [10, 1], [10, 1]]) == 0\n assert candidate(robot = [1, 4, 7, 10, 13, 16, 19, 22, 25],factory = [[3, 3], [9, 3], [15, 3], [21, 3]]) == 16\n assert candidate(robot = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],factory = [[5, 2], [15, 2], [25, 2], [35, 2], [45, 2], [55, 2], [65, 2], [75, 2], [85, 2], [95, 2]]) == 50\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[0, 2], [5, 3], [10, 5]]) == 16\n assert candidate(robot = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],factory = [[150, 3], [500, 4], [850, 3]]) == 900\n assert candidate(robot = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],factory = [[-5, 5], [0, 5], [5, 5]]) == 25\n assert candidate(robot = [-5, 0, 5, 10, 15, 20],factory = [[-10, 1], [0, 3], [10, 2], [20, 1]]) == 15\n assert candidate(robot = [-50, -25, 0, 25, 50],factory = [[-75, 3], [0, 2], [75, 1]]) == 125\n assert candidate(robot = [-10, -5, 0, 5, 10],factory = [[-15, 2], [-10, 1], [0, 3], [10, 2], [15, 1]]) == 10\n assert candidate(robot = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],factory = [[0, 5], [5, 5], [10, 5], [15, 5]]) == 40\n assert candidate(robot = [-100, -200, -300, -400, -500],factory = [[-50, 2], [-150, 1], [-250, 2], [-350, 1], [-450, 1]]) == 250\n assert candidate(robot = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10],factory = [[-95, 2], [-85, 2], [-75, 2], [-65, 2], [-55, 2], [-45, 2], [-35, 2], [-25, 2], [-15, 2], [-5, 2]]) == 50\n assert candidate(robot = [-100, -50, 0, 50, 100],factory = [[-75, 2], [-25, 2], [25, 2], [75, 1]]) == 125\n assert candidate(robot = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],factory = [[-10, 6], [0, 5]]) == 60\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[0, 5], [10, 5]]) == 25\n assert candidate(robot = [-10, -5, 0, 5, 10, 15, 20, 25],factory = [[-15, 2], [0, 3], [15, 3], [25, 1]]) == 25\n assert candidate(robot = [100, 200, 300, 400, 500],factory = [[50, 1], [150, 2], [250, 2], [350, 1], [450, 1]]) == 250\n assert candidate(robot = [-10, -5, 0, 5, 10, 15],factory = [[-8, 2], [2, 3], [12, 2]]) == 15\n assert candidate(robot = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],factory = [[-5, 5], [5, 5]]) == 50\n assert candidate(robot = [0, 10, 20, 30, 40, 50, 60],factory = [[5, 3], [15, 3], [25, 3], [35, 3], [45, 3]]) == 45\n assert candidate(robot = [-1, 0, 1],factory = [[-2, 1], [2, 1], [0, 1]]) == 2\n assert candidate(robot = [-9, -6, -3, 0, 3, 6, 9],factory = [[-8, 2], [-2, 2], [2, 2], [8, 1]]) == 12\n assert candidate(robot = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],factory = [[0, 5], [10, 5], [20, 5]]) == 26\n assert candidate(robot = [0, 10, 20, 30, 40, 50, 60],factory = [[5, 1], [15, 2], [25, 2], [35, 1], [45, 2], [55, 1]]) == 35\n assert candidate(robot = [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[-4, 3], [2, 4], [7, 3], [11, 3]]) == 22\n assert candidate(robot = [-1, -2, -3, -4, -5],factory = [[-3, 3], [0, 2]]) == 6\n assert candidate(robot = [0, 2, 4, 6, 8, 10, 12],factory = [[1, 2], [5, 2], [9, 2], [13, 1]]) == 7\n assert candidate(robot = [100, 200, 300, 400, 500],factory = [[50, 1], [150, 1], [250, 1], [350, 1], [450, 1]]) == 250\n assert candidate(robot = [-5, -3, -1, 1, 3, 5],factory = [[-10, 1], [-6, 2], [-2, 2], [2, 2], [6, 1]]) == 6\n assert candidate(robot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],factory = [[5, 5], [15, 5]]) == 45\n assert candidate(robot = [-20, -10, 0, 10, 20],factory = [[-25, 2], [-15, 3], [-5, 2], [5, 3], [15, 2], [25, 1]]) == 25\n assert candidate(robot = [-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50],factory = [[-60, 3], [-40, 4], [-20, 4], [0, 4], [20, 4], [40, 3]]) == 60\n assert candidate(robot = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],factory = [[0, 2], [4, 2], [8, 2], [12, 2], [16, 2]]) == 20\n assert candidate(robot = [1, 3, 5, 7, 9],factory = [[0, 3], [6, 2], [12, 1]]) == 9\n assert candidate(robot = [-100, -50, 0, 50, 100],factory = [[-150, 2], [-100, 2], [-50, 2], [0, 2], [50, 2], [100, 2], [150, 2]]) == 0\n assert candidate(robot = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],factory = [[0, 2], [5, 2], [10, 2], [15, 2], [20, 2]]) == 14\n", "comparison": "exact"}, "public_tests": ["[0,4,6]\n[[2,2],[6,2]]", "[1,-1]\n[[-2,1],[2,1]]"], "hints": ["Sort robots and factories by their positions.", "After sorting, notice that each factory should repair some subsegment of robots.", "Find the minimum total distance to repair first i robots with first j factories."], "metadata": {"canonical_parameter_names": ["robot", "factory"], "leetcode_dataset_entry_point": "Solution().minimumTotalDistance", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:45+00:00", "tests_total": 100, "tests_dropped": 10, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "dynamic-programming", "sorting"]}, "language": "php", "interface": {"raw_signature": "function minimumTotalDistance($robot, $factory) {", "container": "Solution", "callable": "minimumTotalDistance", "parameters": [{"name": "robot", "type": "Integer[]"}, {"name": "factory", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2465, "task_id": "number-of-distinct-averages", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array nums of even length.\n\nAs long as nums is not empty, you must repetitively:\n\n- Find the minimum number in nums and remove it.\n- Find the maximum number in nums and remove it.\n- Calculate the average of the two removed numbers.\n\nThe average of two numbers a and b is (a + b) / 2.\n\n- For example, the average of 2 and 3 is (2 + 3) / 2 = 2.5.\n\nReturn the number of distinct averages calculated using the above process.\n\nNote that when there is a tie for a minimum or maximum number, any can be removed.\n\nExample 1:\n\nInput: nums = [4,1,4,0,3,5]\nOutput: 2\nExplanation:\n1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].\n2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].\n3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.\nSince there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.\n\nExample 2:\n\nInput: nums = [1,100]\nOutput: 1\nExplanation:\nThere is only one average to be calculated after removing 1 and 100, so we return 1.\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- nums.length is even.\n- 0 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [10, 20, 30, 40, 50, 60]) == 1\n assert candidate(nums = [50, 50, 50, 50]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [1, 2, 3, 4]) == 1\n assert candidate(nums = [0, 100, 50, 50, 25, 75]) == 1\n assert candidate(nums = [1, 100]) == 1\n assert candidate(nums = [4, 1, 4, 0, 3, 5]) == 2\n assert candidate(nums = [5, 5, 5, 5]) == 1\n assert candidate(nums = [6, 6, 6, 6, 6, 6, 6, 6]) == 1\n assert candidate(nums = [99, 1, 98, 2, 97, 3]) == 1\n assert candidate(nums = [0, 0, 0, 0]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 1\n assert candidate(nums = [6, 6, 6, 6, 6, 6]) == 1\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4]) == 1\n assert candidate(nums = [1, 3, 2, 4, 6, 5]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8]) == 1\n assert candidate(nums = [100, 0, 50, 50, 25, 75, 20, 80]) == 1\n assert candidate(nums = [2, 2, 2, 2, 2, 2, 2, 2]) == 1\n assert candidate(nums = [0, 100, 50, 50]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 1\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == 1\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]) == 1\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50]) == 1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93]) == 1\n assert candidate(nums = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6]) == 6\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4, 95, 5, 94, 6]) == 1\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, 100, 2, 99, 3, 98, 4, 97]) == 1\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 1\n assert candidate(nums = [25, 75, 20, 80, 15, 85, 10, 90, 5, 95]) == 1\n assert candidate(nums = [33, 33, 33, 67, 67, 67]) == 1\n assert candidate(nums = [12, 34, 56, 78, 90, 24, 46, 68]) == 1\n assert candidate(nums = [0, 100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93]) == 1\n assert candidate(nums = [1, 1, 1, 99, 99, 99, 2, 2, 2, 98, 98, 98]) == 1\n assert candidate(nums = [0, 1, 2, 99, 98, 97, 96, 95]) == 2\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 1\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5]) == 1\n assert candidate(nums = [1, 99, 2, 98, 3, 97, 4, 96, 5, 95]) == 1\n assert candidate(nums = [1, 1, 1, 1, 100, 100, 100, 100]) == 1\n assert candidate(nums = [23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 1\n assert candidate(nums = [88, 92, 77, 65, 99, 100, 42, 33, 21, 11, 55, 66, 78, 89, 90, 91]) == 7\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 1\n assert candidate(nums = [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 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]) == 1\n assert candidate(nums = [1, 2, 3, 3, 2, 1, 4, 5, 5, 4, 6, 7, 7, 6, 8, 9, 9, 8]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 1\n assert candidate(nums = [40, 20, 60, 80, 100, 0, 50, 30, 90, 70]) == 2\n assert candidate(nums = [100, 0, 100, 0, 100, 0, 100, 0]) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10]) == 2\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 35, 55, 75]) == 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]) == 1\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) == 1\n assert candidate(nums = [100, 0, 50, 50, 25, 75, 20, 80]) == 1\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 1\n assert candidate(nums = [23, 45, 12, 67, 89, 34, 56, 78, 90, 10]) == 2\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 1\n assert candidate(nums = [99, 88, 77, 66, 55, 44, 33, 22, 11, 0]) == 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 = [2, 3, 1, 4, 6, 5, 8, 7]) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 1\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, 5, 5]) == 1\n assert candidate(nums = [8, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 1\n assert candidate(nums = [1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10, 90]) == 1\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 100, 90, 80, 70, 60, 55]) == 2\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 1\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92]) == 1\n assert candidate(nums = [50, 1, 50, 2, 50, 3, 50, 4]) == 4\n assert candidate(nums = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8]) == 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 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 1\n assert candidate(nums = [1, 99, 2, 98, 3, 97, 4, 96]) == 1\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96]) == 1\n assert candidate(nums = [99, 1, 98, 2, 97, 3, 96, 4]) == 1\n assert candidate(nums = [9, 2, 5, 7, 3, 8, 10, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 100, 100, 100, 100, 50, 50, 50, 50]) == 2\n assert candidate(nums = [49, 51, 24, 76, 38, 62, 19, 81, 9, 90]) == 2\n assert candidate(nums = [8, 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, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]) == 1\n assert candidate(nums = [0, 100, 50, 51, 49, 52, 48, 53, 47, 54]) == 2\n assert candidate(nums = [50, 40, 30, 20, 10, 0, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 3\n assert candidate(nums = [25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28]) == 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\n assert candidate(nums = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10]) == 1\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 30]) == 2\n assert candidate(nums = [50, 20, 30, 10, 40, 60, 80, 70]) == 1\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]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 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, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 1\n assert candidate(nums = [100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0, 100, 0]) == 1\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 1\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == 1\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 1\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80]) == 1\n", "comparison": "exact"}, "public_tests": ["[4,1,4,0,3,5]", "[1,100]"], "hints": ["Try sorting the array.", "Store the averages being calculated, and find the distinct ones."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().distinctAverages", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:50+00:00", "tests_total": 113, "tests_dropped": 6, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "sorting"]}, "language": "php", "interface": {"raw_signature": "function distinctAverages($nums) {", "container": "Solution", "callable": "distinctAverages", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2466, "task_id": "count-ways-to-build-good-strings", "difficulty": "Medium", "problem_description": "Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:\n\n- Append the character '0' zero times.\n- Append the character '1' one times.\n\nThis can be performed any number of times.\n\nA good string is a string constructed by the above process having a length between low and high (inclusive).\n\nReturn the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 10^9 + 7.\n\nExample 1:\n\nInput: low = 3, high = 3, zero = 1, one = 1\nOutput: 8\nExplanation:\nOne possible valid good string is \"011\".\nIt can be constructed as follows: \"\" -> \"0\" -> \"01\" -> \"011\".\nAll binary strings from \"000\" to \"111\" are good strings in this example.\n\nExample 2:\n\nInput: low = 2, high = 3, zero = 1, one = 2\nOutput: 5\nExplanation: The good strings are \"00\", \"11\", \"000\", \"110\", and \"011\".\n\nConstraints:\n\n- 1 <= low <= high <= 10^5\n- 1 <= zero, one <= low\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(low = 5,high = 7,zero = 1,one = 1) == 224\n assert candidate(low = 100,high = 200,zero = 10,one = 20) == 28513\n assert candidate(low = 5,high = 10,zero = 2,one = 4) == 16\n assert candidate(low = 10,high = 15,zero = 3,one = 2) == 93\n assert candidate(low = 5,high = 5,zero = 2,one = 3) == 2\n assert candidate(low = 5,high = 10,zero = 3,one = 4) == 8\n assert candidate(low = 1,high = 5,zero = 1,one = 1) == 62\n assert candidate(low = 5,high = 5,zero = 2,one = 2) == 0\n assert candidate(low = 4,high = 6,zero = 2,one = 2) == 12\n assert candidate(low = 4,high = 4,zero = 2,one = 2) == 4\n assert candidate(low = 2,high = 3,zero = 1,one = 2) == 5\n assert candidate(low = 3,high = 7,zero = 3,one = 3) == 6\n assert candidate(low = 50000,high = 50000,zero = 5000,one = 5000) == 1024\n assert candidate(low = 7,high = 9,zero = 3,one = 2) == 12\n assert candidate(low = 50,high = 100,zero = 5,one = 7) == 177635\n assert candidate(low = 4,high = 6,zero = 2,one = 3) == 5\n assert candidate(low = 6,high = 10,zero = 2,one = 3) == 21\n assert candidate(low = 20,high = 25,zero = 5,one = 6) == 17\n assert candidate(low = 10,high = 15,zero = 2,one = 2) == 224\n assert candidate(low = 10,high = 100,zero = 5,one = 7) == 178096\n assert candidate(low = 4,high = 8,zero = 2,one = 2) == 28\n assert candidate(low = 6,high = 10,zero = 3,one = 4) == 8\n assert candidate(low = 5,high = 10,zero = 2,one = 3) == 23\n assert candidate(low = 20,high = 30,zero = 3,one = 5) == 283\n assert candidate(low = 3,high = 9,zero = 2,one = 2) == 28\n assert candidate(low = 1,high = 10,zero = 1,one = 1) == 2046\n assert candidate(low = 10,high = 15,zero = 3,one = 4) == 23\n assert candidate(low = 10,high = 15,zero = 5,one = 6) == 5\n assert candidate(low = 10,high = 15,zero = 4,one = 5) == 9\n assert candidate(low = 5,high = 7,zero = 2,one = 3) == 7\n assert candidate(low = 10,high = 15,zero = 2,one = 3) == 93\n assert candidate(low = 10,high = 10,zero = 3,one = 4) == 3\n assert candidate(low = 10,high = 15,zero = 1,one = 1) == 64512\n assert candidate(low = 10,high = 10,zero = 5,one = 5) == 4\n assert candidate(low = 50,high = 100,zero = 10,one = 15) == 444\n assert candidate(low = 3,high = 3,zero = 1,one = 1) == 8\n assert candidate(low = 10,high = 15,zero = 5,one = 5) == 12\n assert candidate(low = 6,high = 8,zero = 4,one = 5) == 1\n assert candidate(low = 1,high = 4,zero = 1,one = 1) == 30\n assert candidate(low = 1,high = 100,zero = 1,one = 1) == 952742561\n", "comparison": "exact"}, "public_tests": ["3\n3\n1\n1", "2\n3\n1\n2"], "hints": ["Calculate the number of good strings with length less or equal to some constant x.", "Apply dynamic programming using the group size of consecutive zeros and ones."], "metadata": {"canonical_parameter_names": ["low", "high", "zero", "one"], "leetcode_dataset_entry_point": "Solution().countGoodStrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:52+00:00", "tests_total": 45, "tests_dropped": 5, "flags": [], "topic_tags": ["dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countGoodStrings($low, $high, $zero, $one) {", "container": "Solution", "callable": "countGoodStrings", "parameters": [{"name": "low", "type": "Integer"}, {"name": "high", "type": "Integer"}, {"name": "zero", "type": "Integer"}, {"name": "one", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2467, "task_id": "most-profitable-path-in-a-tree", "difficulty": "Medium", "problem_description": "There is an undirected tree with n nodes labeled from 0 to n - 1, 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\nAt every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:\n\n- the price needed to open the gate at node i, if amount[i] is negative, or,\n- the cash reward obtained on opening the gate at node i, otherwise.\n\nThe game goes on as follows:\n\n- Initially, Alice is at node 0 and Bob is at node bob.\n- At every second, Alice and Bob each move to an adjacent node. Alice moves towards some leaf node, while Bob moves towards node 0.\n- For every node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that:\n - If the gate is already open, no price will be required, nor will there be any cash reward.\n - If Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.\n- If Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node 0, he stops moving. Note that these events are independent of each other.\n\nReturn the maximum net income Alice can have if she travels towards the optimal leaf node.\n\nExample 1:\n\nInput: edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6]\nOutput: 6\nExplanation:\nThe above diagram represents the given tree. The game goes as follows:\n- Alice is initially on node 0, Bob on node 3. They open the gates of their respective nodes.\n Alice's net income is now -2.\n- Both Alice and Bob move to node 1.\n Since they reach here simultaneously, they open the gate together and share the reward.\n Alice's net income becomes -2 + (4 / 2) = 0.\n- Alice moves on to node 3. Since Bob already opened its gate, Alice's income remains unchanged.\n Bob moves on to node 0, and stops moving.\n- Alice moves on to node 4 and opens the gate there. Her net income becomes 0 + 6 = 6.\nNow, neither Alice nor Bob can make any further moves, and the game ends.\nIt is not possible for Alice to get a higher net income.\n\nExample 2:\n\nInput: edges = [[0,1]], bob = 1, amount = [-7280,2350]\nOutput: -7280\nExplanation:\nAlice follows the path 0->1 whereas Bob follows the path 1->0.\nThus, Alice opens the gate at node 0 only. Hence, her net income is -7280.\n\nConstraints:\n\n- 2 <= n <= 10^5\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- 1 <= bob < n\n- amount.length == n\n- amount[i] is an even integer in the range [-10^4, 10^4].\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]],bob = 3,amount = [10, 10, 10, 10, 10, 10, 10]) == 30\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5]],bob = 5,amount = [100, -50, -25, 200, -300, 150]) == 250\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]],bob = 7,amount = [100, 200, -300, 400, -500, 600, -700, 800]) == 400\n assert candidate(edges = [[0, 1], [1, 2], [2, 3]],bob = 2,amount = [1, 2, 3, 4]) == 6\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],bob = 5,amount = [-10, -10, -10, -10, -10, -10]) == -30\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],bob = 4,amount = [-10, 20, -30, 40, -50, 60, -70, 80, -90, 100]) == 130\n assert candidate(edges = [[0, 1], [1, 2], [2, 3], [2, 4], [4, 5]],bob = 5,amount = [1, 2, 3, 4, 5, 6]) == 8\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],bob = 4,amount = [-1, -2, -3, -4, -5, -6, -7]) == -2\n assert candidate(edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],bob = 8,amount = [-5, -5, -5, -5, -5, -5, -5, -5, -5, -5]) == -8\n assert candidate(edges = [[0, 1], [1, 2], [1, 3], [3, 4]],bob = 3,amount = [-2, 4, 2, -4, 6]) == 6\n assert candidate(edges = [[0, 1]],bob = 1,amount = [-7280, 2350]) == -7280\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],bob = 5,amount = [-5, 2, -3, 4, -1, 6, -7]) == 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]],bob = 16,amount = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000, -1100, 1200, -1300, 1400, -1500, 1600, -1700, 1800, -1900, 2000, -2100, 2200, -2300]) == 2600\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],bob = 7,amount = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]) == -3\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],bob = 7,amount = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11]) == 6\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]],bob = 5,amount = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120, 130, -140]) == -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]],bob = 7,amount = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13]) == -3\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], [4, 13], [4, 14], [5, 15], [5, 16], [5, 17], [6, 18], [6, 19], [6, 20]],bob = 18,amount = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000, 1100]) == 1100\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]],bob = 18,amount = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22]) == -5\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]],bob = 29,amount = [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]) == 380\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]],bob = 15,amount = [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]) == -1100\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]],bob = 9,amount = [-10, -20, -30, 15, 25, -5, -15, 5, 20, -35, 40, -45, 50]) == 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]],bob = 26,amount = [-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]) == 360\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]],bob = 11,amount = [-5, 3, -7, 2, 4, -10, 6, -8, -9, 12, -15, 14]) == 10\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]],bob = 18,amount = [-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000]) == -5000\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]],bob = 31,amount = [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]) == 200\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]],bob = 13,amount = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15]) == 14\n assert candidate(edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],bob = 7,amount = [100, -50, 25, -10, 20, -15, 5, -5, -2, -3, -7]) == 130\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]],bob = 12,amount = [1000, -500, 250, -100, 200, -150, 50, -50, 20, -10, 20, -15, 5, -5, 2, -1, -3, 7]) == 1302\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]],bob = 14,amount = [-50, 50, -40, 40, -30, 30, -20, 20, -10, 10, 0, -10, 10, -20, 20, -30]) == 20\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]],bob = 12,amount = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 47\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]],bob = 18,amount = [10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120, -130, -140, -150, -160, -170, -180, -190, -200]) == 150\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]],bob = 12,amount = [100, -50, 30, -20, 25, -40, 15, 60, -60, 45, -35, 20, -80, 70, 90, -100]) == 190\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]],bob = 10,amount = [-10, 15, 20, -25, 30, -35, 40, -45, 50, -55, 60, -65, 70, -75, 80]) == 130\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]],bob = 11,amount = [10, 20, -30, 40, -50, 60, -70, 80, -90, 100, -110, 120, -130]) == 150\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]],bob = 15,amount = [-10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120, 130, -140, 150, -160, 170, -180, 190, -200, 210, -220]) == 310\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]],bob = 10,amount = [10, -2, -3, -4, -5, 6, 7, -8, -9, -10, 12, -11]) == 11\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]],bob = 11,amount = [-100, 50, -25, 10, -20, 15, -5, 2, -1, -3, 7, -8, 9, -12]) == -38\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]],bob = 12,amount = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100, -110, -120, -130]) == -40\n", "comparison": "exact"}, "public_tests": ["[[0,1],[1,2],[1,3],[3,4]]\n3\n[-2,4,2,-4,6]", "[[0,1]]\n1\n[-7280,2350]"], "hints": ["Bob travels along a fixed path (from node “bob” to node 0).", "Calculate Alice’s distance to each node via DFS.", "We can calculate Alice’s score along a path ending at some node easily using Hints 1 and 2."], "metadata": {"canonical_parameter_names": ["edges", "bob", "amount"], "leetcode_dataset_entry_point": "Solution().mostProfitablePath", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:54+00:00", "tests_total": 50, "tests_dropped": 11, "flags": ["has_images"], "topic_tags": ["array", "tree", "depth-first-search", "breadth-first-search", "graph"]}, "language": "php", "interface": {"raw_signature": "function mostProfitablePath($edges, $bob, $amount) {", "container": "Solution", "callable": "mostProfitablePath", "parameters": [{"name": "edges", "type": "Integer[][]"}, {"name": "bob", "type": "Integer"}, {"name": "amount", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2468, "task_id": "split-message-based-on-limit", "difficulty": "Hard", "problem_description": "You are given a string, message, and a positive integer, limit.\n\nYou must split message into one or more parts based on limit. Each resulting part should have the suffix \"\", where \"b\" is to be replaced with the total number of parts and \"a\" is to be replaced with the index of the part, starting from 1 and going up to b. Additionally, the length of each resulting part (including its suffix) should be equal to limit, except for the last part whose length can be at most limit.\n\nThe resulting parts should be formed such that when their suffixes are removed and they are all concatenated in order, they should be equal to message. Also, the result should contain as few parts as possible.\n\nReturn the parts message would be split into as an array of strings. If it is impossible to split message as required, return an empty array.\n\nExample 1:\n\nInput: message = \"this is really a very awesome message\", limit = 9\nOutput: [\"thi<1/14>\",\"s i<2/14>\",\"s r<3/14>\",\"eal<4/14>\",\"ly <5/14>\",\"a v<6/14>\",\"ery<7/14>\",\" aw<8/14>\",\"eso<9/14>\",\"me<10/14>\",\" m<11/14>\",\"es<12/14>\",\"sa<13/14>\",\"ge<14/14>\"]\nExplanation:\nThe first 9 parts take 3 characters each from the beginning of message.\nThe next 5 parts take 2 characters each to finish splitting message.\nIn this example, each part, including the last, has length 9.\nIt can be shown it is not possible to split message into less than 14 parts.\n\nExample 2:\n\nInput: message = \"short message\", limit = 15\nOutput: [\"short mess<1/2>\",\"age<2/2>\"]\nExplanation:\nUnder the given constraints, the string can be split into two parts:\n- The first part comprises of the first 10 characters, and has a length 15.\n- The next part comprises of the last 3 characters, and has a length 8.\n\nConstraints:\n\n- 1 <= message.length <= 10^4\n- message consists only of lowercase English letters and ' '.\n- 1 <= limit <= 10^4\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(message = \"abcdefghij\",limit = 3) == []\n assert candidate(message = \"abc\",limit = 5) == []\n assert candidate(message = \"short message\",limit = 15) == ['short mess<1/2>', 'age<2/2>']\n assert candidate(message = \"hello world\",limit = 10) == ['hello<1/3>', ' worl<2/3>', 'd<3/3>']\n assert candidate(message = \"abcd efgh ijkl mnop qrst uvwx yz\",limit = 10) == ['abcd <1/7>', 'efgh <2/7>', 'ijkl <3/7>', 'mnop <4/7>', 'qrst <5/7>', 'uvwx <6/7>', 'yz<7/7>']\n assert candidate(message = \"a\",limit = 5) == []\n assert candidate(message = \"a quick brown fox jumps over the lazy dog\",limit = 10) == ['a qui<1/9>', 'ck br<2/9>', 'own f<3/9>', 'ox ju<4/9>', 'mps o<5/9>', 'ver t<6/9>', 'he la<7/9>', 'zy do<8/9>', 'g<9/9>']\n assert candidate(message = \"abcdefghij\",limit = 7) == ['ab<1/5>', 'cd<2/5>', 'ef<3/5>', 'gh<4/5>', 'ij<5/5>']\n assert candidate(message = \"python programming is fun\",limit = 20) == ['python programm<1/2>', 'ing is fun<2/2>']\n assert candidate(message = \"this is really a very awesome message\",limit = 9) == ['thi<1/14>', 's i<2/14>', 's r<3/14>', 'eal<4/14>', 'ly <5/14>', 'a v<6/14>', 'ery<7/14>', ' aw<8/14>', 'eso<9/14>', 'me<10/14>', ' m<11/14>', 'es<12/14>', 'sa<13/14>', 'ge<14/14>']\n assert candidate(message = \"ab\",limit = 5) == []\n assert candidate(message = \"a quick brown fox jumps over the lazy dog\",limit = 5) == []\n assert candidate(message = \"hello world\",limit = 20) == ['hello world<1/1>']\n assert candidate(message = \"abcdefghijabcdefghijabcdefghij\",limit = 12) == ['abcdefg<1/5>', 'hijabcd<2/5>', 'efghija<3/5>', 'bcdefgh<4/5>', 'ij<5/5>']\n assert candidate(message = \"abcdefg\",limit = 3) == []\n assert candidate(message = \"one two three four five six seven eight nine ten\",limit = 12) == ['one two<1/7>', ' three <2/7>', 'four fi<3/7>', 've six <4/7>', 'seven e<5/7>', 'ight ni<6/7>', 'ne ten<7/7>']\n assert candidate(message = \"abcdefghijabcdefghij\",limit = 10) == ['abcde<1/4>', 'fghij<2/4>', 'abcde<3/4>', 'fghij<4/4>']\n assert candidate(message = \"abcd\",limit = 5) == []\n assert candidate(message = \"anotherlongermessageforcomplextesting\",limit = 18) == ['anotherlonger<1/3>', 'messageforcom<2/3>', 'plextesting<3/3>']\n assert candidate(message = \"testing testing testing testing testing testing testing testing testing testing\",limit = 20) == ['testing testing<1/6>', ' testing testin<2/6>', 'g testing testi<3/6>', 'ng testing test<4/6>', 'ing testing tes<5/6>', 'ting<6/6>']\n assert candidate(message = \"abcd efgh ijkl mnop qrst uvwx yz\",limit = 8) == ['ab<1/23>', 'cd<2/23>', ' e<3/23>', 'fg<4/23>', 'h <5/23>', 'ij<6/23>', 'kl<7/23>', ' m<8/23>', 'no<9/23>', 'p<10/23>', ' <11/23>', 'q<12/23>', 'r<13/23>', 's<14/23>', 't<15/23>', ' <16/23>', 'u<17/23>', 'v<18/23>', 'w<19/23>', 'x<20/23>', ' <21/23>', 'y<22/23>', 'z<23/23>']\n assert candidate(message = \"one two three four five six seven eight nine ten\",limit = 5) == []\n assert candidate(message = \"shortmessage\",limit = 20) == ['shortmessage<1/1>']\n assert candidate(message = \"split this into as few parts as possible\",limit = 21) == ['split this into <1/3>', 'as few parts as <2/3>', 'possible<3/3>']\n assert candidate(message = \"repeated repeated repeated repeated repeated repeated repeated repeated\",limit = 25) == ['repeated repeated re<1/4>', 'peated repeated repe<2/4>', 'ated repeated repeat<3/4>', 'ed repeated<4/4>']\n assert candidate(message = \"this is a very long message that needs to be split into multiple parts to fit the limit\",limit = 10) == ['this<1/26>', ' is <2/26>', 'a ve<3/26>', 'ry l<4/26>', 'ong <5/26>', 'mess<6/26>', 'age <7/26>', 'that<8/26>', ' nee<9/26>', 'ds <10/26>', 'to <11/26>', 'be <12/26>', 'spl<13/26>', 'it <14/26>', 'int<15/26>', 'o m<16/26>', 'ult<17/26>', 'ipl<18/26>', 'e p<19/26>', 'art<20/26>', 's t<21/26>', 'o f<22/26>', 'it <23/26>', 'the<24/26>', ' li<25/26>', 'mit<26/26>']\n assert candidate(message = \"this is a repeated message this is a repeated message this is a repeated message\",limit = 15) == ['this is a <1/8>', 'repeated m<2/8>', 'essage thi<3/8>', 's is a rep<4/8>', 'eated mess<5/8>', 'age this i<6/8>', 's a repeat<7/8>', 'ed message<8/8>']\n assert candidate(message = \"spaces between words\",limit = 20) == ['spaces <1/3>', ' between <2/3>', ' words<3/3>']\n assert candidate(message = \"boundary boundary boundary boundary boundary boundary boundary boundary boundary boundary boundary boundary\",limit = 30) == ['boundary boundary boundar<1/5>', 'y boundary boundary bound<2/5>', 'ary boundary boundary bou<3/5>', 'ndary boundary boundary b<4/5>', 'oundary<5/5>']\n assert candidate(message = \"singleword\",limit = 12) == ['singlew<1/2>', 'ord<2/2>']\n assert candidate(message = \"a quick brown fox jumps over the lazy dog a quick brown fox jumps over the lazy dog\",limit = 15) == ['a quick br<1/9>', 'own fox ju<2/9>', 'mps over t<3/9>', 'he lazy do<4/9>', 'g a quick <5/9>', 'brown fox <6/9>', 'jumps over<7/9>', ' the lazy <8/9>', 'dog<9/9>']\n assert candidate(message = \"one two three four five six seven eight nine ten eleven twelve thirteen\",limit = 11) == ['one t<1/16>', 'wo th<2/16>', 'ree f<3/16>', 'our f<4/16>', 'ive s<5/16>', 'ix se<6/16>', 'ven e<7/16>', 'ight <8/16>', 'nine <9/16>', 'ten <10/16>', 'elev<11/16>', 'en t<12/16>', 'welv<13/16>', 'e th<14/16>', 'irte<15/16>', 'en<16/16>']\n assert candidate(message = \"a\",limit = 1) == []\n assert candidate(message = \"singlewordwithoutspaces\",limit = 25) == ['singlewordwithoutspa<1/2>', 'ces<2/2>']\n assert candidate(message = \"abcdefghijklmnopqrstuvwxyz\",limit = 5) == []\n assert candidate(message = \"one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty\",limit = 22) == ['one two three fou<1/8>', 'r five six seven <2/8>', 'eight nine ten el<3/8>', 'even twelve thirt<4/8>', 'een fourteen fift<5/8>', 'een sixteen seven<6/8>', 'teen eighteen nin<7/8>', 'eteen twenty<8/8>']\n assert candidate(message = \"a very very very very very very very very very very very long message that needs to be split into multiple parts\",limit = 18) == ['a very very v<1/9>', 'ery very very<2/9>', ' very very ve<3/9>', 'ry very very <4/9>', 'very long mes<5/9>', 'sage that nee<6/9>', 'ds to be spli<7/9>', 't into multip<8/9>', 'le parts<9/9>']\n assert candidate(message = \"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello\",limit = 5) == []\n assert candidate(message = \"veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongmessage\",limit = 25) == ['veryveryveryveryvery<1/6>', 'veryveryveryveryvery<2/6>', 'veryveryveryveryvery<3/6>', 'veryveryveryveryvery<4/6>', 'veryveryveryveryvery<5/6>', 'longmessage<6/6>']\n assert candidate(message = \"samecharssamecharssamecharssamecharssamecharssamechars\",limit = 10) == ['same<1/15>', 'char<2/15>', 'ssam<3/15>', 'echa<4/15>', 'rssa<5/15>', 'mech<6/15>', 'arss<7/15>', 'amec<8/15>', 'hars<9/15>', 'sam<10/15>', 'ech<11/15>', 'ars<12/15>', 'sam<13/15>', 'ech<14/15>', 'ars<15/15>']\n assert candidate(message = \"short\",limit = 5) == []\n assert candidate(message = \"manywordsbutnospacesmanywordsbutnospacesmanywordsbutnospacesmanywordsbutnospaces\",limit = 20) == ['manywordsbutnos<1/6>', 'pacesmanywordsb<2/6>', 'utnospacesmanyw<3/6>', 'ordsbutnospaces<4/6>', 'manywordsbutnos<5/6>', 'paces<6/6>']\n assert candidate(message = \"this message has a very specific requirement for splitting\",limit = 18) == ['this message <1/5>', 'has a very sp<2/5>', 'ecific requir<3/5>', 'ement for spl<4/5>', 'itting<5/5>']\n assert candidate(message = \"the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog\",limit = 25) == ['the quick brown fox <1/7>', 'jumps over the lazy <2/7>', 'dog the quick brown <3/7>', 'fox jumps over the l<4/7>', 'azy dog the quick br<5/7>', 'own fox jumps over t<6/7>', 'he lazy dog<7/7>']\n assert candidate(message = \"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\",limit = 4) == []\n assert candidate(message = \"short\",limit = 10) == ['short<1/1>']\n assert candidate(message = \"single\",limit = 6) == ['s<1/6>', 'i<2/6>', 'n<3/6>', 'g<4/6>', 'l<5/6>', 'e<6/6>']\n assert candidate(message = \"singlewordwithoutspaces\",limit = 10) == ['singl<1/5>', 'eword<2/5>', 'witho<3/5>', 'utspa<4/5>', 'ces<5/5>']\n assert candidate(message = \"a quick brown fox jumps over the lazy dog\",limit = 12) == ['a quick<1/6>', ' brown <2/6>', 'fox jum<3/6>', 'ps over<4/6>', ' the la<5/6>', 'zy dog<6/6>']\n assert candidate(message = \"one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty\",limit = 20) == ['one two three f<1/9>', 'our five six se<2/9>', 'ven eight nine <3/9>', 'ten eleven twel<4/9>', 've thirteen fou<5/9>', 'rteen fifteen s<6/9>', 'ixteen seventee<7/9>', 'n eighteen nine<8/9>', 'teen twenty<9/9>']\n assert candidate(message = \"boundary boundary boundary boundary boundary boundary boundary boundary boundary\",limit = 20) == ['boundary bounda<1/6>', 'ry boundary bou<2/6>', 'ndary boundary <3/6>', 'boundary bounda<4/6>', 'ry boundary bou<5/6>', 'ndary<6/6>']\n assert candidate(message = \"boundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundaryboundary\",limit = 30) == ['boundaryboundaryboundaryb<1/5>', 'oundaryboundaryboundarybo<2/5>', 'undaryboundaryboundarybou<3/5>', 'ndaryboundaryboundaryboun<4/5>', 'daryboundaryboundary<5/5>']\n assert candidate(message = \"repeated repeated repeated repeated repeated repeated repeated repeated\",limit = 12) == ['repeat<1/13>', 'ed rep<2/13>', 'eated <3/13>', 'repeat<4/13>', 'ed rep<5/13>', 'eated <6/13>', 'repeat<7/13>', 'ed rep<8/13>', 'eated <9/13>', 'repea<10/13>', 'ted r<11/13>', 'epeat<12/13>', 'ed<13/13>']\n assert candidate(message = \"this is a very long message that needs to be split into several parts to meet the limit constraint\",limit = 15) == ['this is a<1/12>', ' very lon<2/12>', 'g message<3/12>', ' that nee<4/12>', 'ds to be <5/12>', 'split int<6/12>', 'o several<7/12>', ' parts to<8/12>', ' meet the<9/12>', ' limit c<10/12>', 'onstrain<11/12>', 't<12/12>']\n assert candidate(message = \"a quick brown fox jumps over the lazy dog\",limit = 11) == ['a quic<1/7>', 'k brow<2/7>', 'n fox <3/7>', 'jumps <4/7>', 'over t<5/7>', 'he laz<6/7>', 'y dog<7/7>']\n assert candidate(message = \"a quick brown fox jumps over the lazy dog\",limit = 15) == ['a quick br<1/5>', 'own fox ju<2/5>', 'mps over t<3/5>', 'he lazy do<4/5>', 'g<5/5>']\n assert candidate(message = \"shortmsg\",limit = 12) == ['shortms<1/2>', 'g<2/2>']\n assert candidate(message = \"this is another test case with a longer message that needs to be split into multiple parts to see how the function handles it\",limit = 18) == ['this is anot<1/11>', 'her test cas<2/11>', 'e with a lon<3/11>', 'ger message <4/11>', 'that needs t<5/11>', 'o be split i<6/11>', 'nto multiple<7/11>', ' parts to se<8/11>', 'e how the fu<9/11>', 'nction hand<10/11>', 'les it<11/11>']\n assert candidate(message = \"a\",limit = 3) == []\n assert candidate(message = \"spaces in the message should be handled correctly\",limit = 15) == ['spaces <1/7>', 'in the <2/7>', ' message<3/7>', ' should<4/7>', ' be <5/7>', 'handled <6/7>', ' correctly<7/7>']\n assert candidate(message = \"splitting this message into parts is challenging\",limit = 15) == ['splitting <1/5>', 'this messa<2/5>', 'ge into pa<3/5>', 'rts is cha<4/5>', 'llenging<5/5>']\n assert candidate(message = \"another example with a bit more text to ensure the splitting algorithm works correctly\",limit = 20) == ['another example<1/6>', ' with a bit mor<2/6>', 'e text to ensur<3/6>', 'e the splitting<4/6>', ' algorithm work<5/6>', 's correctly<6/6>']\n assert candidate(message = \"this is a very very very very very very very very very very very very very very very very very very very very very very very very very very very long message indeed\",limit = 20) == ['this is a very<1/12>', ' very very ver<2/12>', 'y very very ve<3/12>', 'ry very very v<4/12>', 'ery very very <5/12>', 'very very very<6/12>', ' very very ver<7/12>', 'y very very ve<8/12>', 'ry very very v<9/12>', 'ery very very<10/12>', ' very long me<11/12>', 'ssage indeed<12/12>']\n assert candidate(message = \"edgecase\",limit = 8) == ['edg<1/3>', 'eca<2/3>', 'se<3/3>']\n assert candidate(message = \"this is a test to see if the solution can handle edge cases\",limit = 23) == ['this is a test to <1/4>', 'see if the solutio<2/4>', 'n can handle edge <3/4>', 'cases<4/4>']\n assert candidate(message = \"a very long message that needs to be split into many parts to test the solution thoroughly\",limit = 12) == ['a very<1/17>', ' long <2/17>', 'messag<3/17>', 'e that<4/17>', ' needs<5/17>', ' to be<6/17>', ' split<7/17>', ' into <8/17>', 'many p<9/17>', 'arts <10/17>', 'to te<11/17>', 'st th<12/17>', 'e sol<13/17>', 'ution<14/17>', ' thor<15/17>', 'oughl<16/17>', 'y<17/17>']\n assert candidate(message = \"this is a very very long message that needs to be split into multiple parts to fit the limit\",limit = 15) == ['this is a<1/11>', ' very ver<2/11>', 'y long me<3/11>', 'ssage tha<4/11>', 't needs t<5/11>', 'o be spli<6/11>', 't into mu<7/11>', 'ltiple pa<8/11>', 'rts to fi<9/11>', 't the li<10/11>', 'mit<11/11>']\n assert candidate(message = \"short\",limit = 100) == ['short<1/1>']\n assert candidate(message = \"this is an extremely long message that needs to be split into several parts to fit the given limit\",limit = 12) == ['this i<1/18>', 's an e<2/18>', 'xtreme<3/18>', 'ly lon<4/18>', 'g mess<5/18>', 'age th<6/18>', 'at nee<7/18>', 'ds to <8/18>', 'be spl<9/18>', 'it in<10/18>', 'to se<11/18>', 'veral<12/18>', ' part<13/18>', 's to <14/18>', 'fit t<15/18>', 'he gi<16/18>', 'ven l<17/18>', 'imit<18/18>']\n", "comparison": "exact"}, "public_tests": ["\"this is really a very awesome message\"\n9", "\"short message\"\n15"], "hints": ["Could you solve the problem if you knew how many digits the total number of parts has?", "Try all possible lengths of the total number of parts, and see if the string can be split such that the total number of parts has that length.", "Binary search can be used for each part length to find the precise number of parts needed."], "metadata": {"canonical_parameter_names": ["message", "limit"], "leetcode_dataset_entry_point": "Solution().splitMessage", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:57+00:00", "tests_total": 81, "tests_dropped": 12, "flags": [], "topic_tags": ["string", "enumeration"]}, "language": "php", "interface": {"raw_signature": "function splitMessage($message, $limit) {", "container": "Solution", "callable": "splitMessage", "parameters": [{"name": "message", "type": "String"}, {"name": "limit", "type": "Integer"}], "return_type": "String[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2469, "task_id": "convert-the-temperature", "difficulty": "Easy", "problem_description": "You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.\n\nYou should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].\n\nReturn the array ans. Answers within 10^-5 of the actual answer will be accepted.\n\nNote that:\n\n- Kelvin = Celsius + 273.15\n- Fahrenheit = Celsius * 1.80 + 32.00\n\nExample 1:\n\nInput: celsius = 36.50\nOutput: [309.65000,97.70000]\nExplanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.\n\nExample 2:\n\nInput: celsius = 122.11\nOutput: [395.26000,251.79800]\nExplanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.\n\nConstraints:\n\n- 0 <= celsius <= 1000\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(celsius=122.11), [395.26, 251.798])\n assert answers_match(candidate(celsius=1000.0), [1273.15, 1832.0])\n assert answers_match(candidate(celsius=0.0), [273.15, 32.0])\n assert answers_match(candidate(celsius=500.0), [773.15, 932.0])\n assert answers_match(candidate(celsius=100.0), [373.15, 212.0])\n assert answers_match(candidate(celsius=500.75), [773.9, 933.35])\n assert answers_match(candidate(celsius=36.5), [309.65, 97.7])\n assert answers_match(candidate(celsius=25.0), [298.15, 77.0])\n assert answers_match(candidate(celsius=273.15), [546.3, 523.67])\n assert answers_match(candidate(celsius=42.876543), [316.02654299999995, 109.1777774])\n assert answers_match(candidate(celsius=12.34), [285.48999999999995, 54.212])\n assert answers_match(candidate(celsius=37.0), [310.15, 98.60000000000001])\n assert answers_match(candidate(celsius=25.55555), [298.70554999999996, 77.99999])\n assert answers_match(candidate(celsius=150.75), [423.9, 303.35])\n assert answers_match(candidate(celsius=234.56), [507.71, 454.208])\n assert answers_match(candidate(celsius=750.5), [1023.65, 1382.9])\n assert answers_match(candidate(celsius=77.77777), [350.92777, 171.999986])\n assert answers_match(candidate(celsius=456.78), [729.93, 854.204])\n assert answers_match(candidate(celsius=750.25), [1023.4, 1382.45])\n assert answers_match(candidate(celsius=999.0), [1272.15, 1830.2])\n assert answers_match(candidate(celsius=499.99), [773.14, 931.9820000000001])\n assert answers_match(candidate(celsius=60.0), [333.15, 140.0])\n assert answers_match(candidate(celsius=23.45), [296.59999999999997, 74.21000000000001])\n assert answers_match(candidate(celsius=450.0), [723.15, 842.0])\n assert answers_match(candidate(celsius=150.67), [423.81999999999994, 303.20599999999996])\n assert answers_match(candidate(celsius=1.0), [274.15, 33.8])\n assert answers_match(candidate(celsius=500.01), [773.16, 932.018])\n assert answers_match(candidate(celsius=800.25), [1073.4, 1472.45])\n assert answers_match(candidate(celsius=550.89), [824.04, 1023.602])\n assert answers_match(candidate(celsius=999.99), [1273.1399999999999, 1831.982])\n assert answers_match(candidate(celsius=1.23456), [274.38455999999996, 34.222208])\n assert answers_match(candidate(celsius=0.99), [274.14, 33.782])\n assert answers_match(candidate(celsius=678.9), [952.05, 1254.02])\n assert answers_match(candidate(celsius=300.12), [573.27, 572.216])\n assert answers_match(candidate(celsius=0.01), [273.15999999999997, 32.018])\n assert answers_match(candidate(celsius=777.77), [1050.92, 1431.986])\n assert answers_match(candidate(celsius=89.67), [362.82, 193.406])\n assert answers_match(candidate(celsius=150.0), [423.15, 302.0])\n", "comparison": "float"}, "public_tests": ["36.50", "122.11"], "hints": ["Implement formulas that are given in the statement."], "metadata": {"canonical_parameter_names": ["celsius"], "leetcode_dataset_entry_point": "Solution().convertTemperature", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:53:59+00:00", "tests_total": 39, "tests_dropped": 1, "flags": ["decimal_answer"], "topic_tags": ["math"]}, "language": "php", "interface": {"raw_signature": "function convertTemperature($celsius) {", "container": "Solution", "callable": "convertTemperature", "parameters": [{"name": "celsius", "type": "Float"}], "return_type": "Float[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2470, "task_id": "number-of-subarrays-with-lcm-equal-to-k", "difficulty": "Medium", "problem_description": "Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nThe least common multiple of an array is the smallest positive integer that is divisible by all the array elements.\n\nExample 1:\n\nInput: nums = [3,6,2,7,1], k = 6\nOutput: 4\nExplanation: The subarrays of nums where 6 is the least common multiple of all the subarray's elements are:\n- [3,6,2,7,1]\n- [3,6,2,7,1]\n- [3,6,2,7,1]\n- [3,6,2,7,1]\n\nExample 2:\n\nInput: nums = [3], k = 2\nOutput: 0\nExplanation: There are no subarrays of nums where 2 is the least common multiple of all the subarray's elements.\n\nConstraints:\n\n- 1 <= nums.length <= 1000\n- 1 <= nums[i], k <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [7, 7, 7, 7, 7],k = 7) == 15\n assert candidate(nums = [5, 5, 5, 5, 5],k = 5) == 15\n assert candidate(nums = [7, 3, 9, 12, 15],k = 60) == 1\n assert candidate(nums = [3, 6, 2, 7, 1],k = 6) == 4\n assert candidate(nums = [100, 100, 100],k = 100) == 6\n assert candidate(nums = [7, 7, 7, 7],k = 7) == 10\n assert candidate(nums = [10, 5, 6, 20, 12],k = 60) == 7\n assert candidate(nums = [5, 10, 15, 20, 25],k = 60) == 3\n assert candidate(nums = [5, 10, 15],k = 30) == 2\n assert candidate(nums = [10, 20, 30, 40, 50],k = 100) == 0\n assert candidate(nums = [1, 1, 1, 1, 1],k = 1) == 15\n assert candidate(nums = [1, 2, 3, 4, 5],k = 60) == 3\n assert candidate(nums = [3],k = 2) == 0\n assert candidate(nums = [2, 4, 6, 8, 10],k = 20) == 0\n assert candidate(nums = [2, 4, 8, 16],k = 16) == 4\n assert candidate(nums = [6, 12, 18, 24],k = 72) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 12) == 3\n assert candidate(nums = [1, 2, 3, 4, 5],k = 1) == 1\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],k = 100) == 1\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 312) == 0\n assert candidate(nums = [8, 16, 32, 64, 128, 256, 512],k = 512) == 7\n assert candidate(nums = [5, 10, 15, 20, 25],k = 150) == 0\n assert candidate(nums = [3, 6, 9, 12, 15, 18, 21],k = 18) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 120) == 7\n assert candidate(nums = [13, 13, 13, 13, 13, 13, 13],k = 13) == 28\n assert candidate(nums = [23, 46, 69, 92, 115, 138, 161, 184, 207, 230],k = 46) == 2\n assert candidate(nums = [3, 9, 27, 81, 243],k = 243) == 5\n assert candidate(nums = [11, 22, 33, 44, 55],k = 132) == 3\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117, 130],k = 78) == 3\n assert candidate(nums = [4, 8, 16, 32, 64, 128],k = 128) == 6\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40],k = 420) == 0\n assert candidate(nums = [100, 200, 300, 400, 500],k = 200) == 2\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 540) == 7\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 420) == 0\n assert candidate(nums = [3, 9, 27, 81, 243],k = 81) == 4\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],k = 3) == 55\n assert candidate(nums = [7, 14, 21, 28, 35],k = 42) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 60) == 7\n assert candidate(nums = [6, 12, 18, 24, 30],k = 360) == 3\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 110) == 1\n assert candidate(nums = [7, 14, 28, 42, 56],k = 168) == 4\n assert candidate(nums = [30, 60, 90, 120, 150],k = 150) == 1\n assert candidate(nums = [6, 12, 3, 18, 9],k = 36) == 4\n assert candidate(nums = [10, 15, 30, 60, 120, 240],k = 120) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5],k = 5) == 21\n assert candidate(nums = [4, 6, 12, 15, 30, 60],k = 60) == 12\n assert candidate(nums = [4, 8, 12, 16, 20],k = 480) == 0\n assert candidate(nums = [5, 15, 25, 35, 45],k = 525) == 2\n assert candidate(nums = [5, 10, 20, 40, 80, 160, 320, 640],k = 640) == 8\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 42) == 2\n assert candidate(nums = [3, 5, 15, 45, 60, 90],k = 90) == 1\n assert candidate(nums = [9, 18, 27, 36, 45],k = 54) == 2\n assert candidate(nums = [7, 14, 28, 56, 112],k = 112) == 5\n assert candidate(nums = [7, 14, 21, 28, 35],k = 14) == 2\n assert candidate(nums = [2, 4, 6, 8, 12],k = 24) == 7\n assert candidate(nums = [5, 10, 15, 20, 25],k = 60) == 3\n assert candidate(nums = [29, 58, 87, 116, 145, 174, 203, 232, 261, 290],k = 29) == 1\n assert candidate(nums = [4, 8, 12, 16, 20],k = 240) == 3\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],k = 24) == 3\n assert candidate(nums = [19, 38, 57, 76, 95, 114, 133, 152, 171, 190],k = 380) == 1\n assert candidate(nums = [7, 14, 28, 49, 98],k = 196) == 6\n assert candidate(nums = [17, 34, 51, 68, 85, 102, 119, 136, 153, 170],k = 34) == 2\n assert candidate(nums = [21, 28, 35, 42, 49, 56, 63, 70],k = 42) == 1\n assert candidate(nums = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70],k = 420) == 7\n assert candidate(nums = [7, 14, 28, 56, 112],k = 56) == 4\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10],k = 20) == 1\n assert candidate(nums = [6, 9, 12, 15, 18],k = 180) == 5\n assert candidate(nums = [9, 18, 27, 36, 45, 54, 63, 72, 81, 90],k = 90) == 1\n assert candidate(nums = [11, 22, 33, 44, 55, 66, 77, 88, 99, 110],k = 660) == 7\n assert candidate(nums = [7, 14, 21, 28, 35],k = 420) == 3\n assert candidate(nums = [25, 50, 75, 100, 125],k = 250) == 0\n assert candidate(nums = [6, 12, 18, 24, 30],k = 36) == 2\n assert candidate(nums = [6, 12, 18, 24, 30],k = 360) == 3\n assert candidate(nums = [2, 4, 6, 8, 12],k = 12) == 3\n assert candidate(nums = [4, 8, 12, 16, 20],k = 240) == 3\n assert candidate(nums = [2, 4, 6, 8, 12, 24],k = 24) == 13\n assert candidate(nums = [12, 15, 20, 25, 30],k = 300) == 5\n assert candidate(nums = [100, 150, 200, 250, 300],k = 300) == 2\n assert candidate(nums = [13, 26, 39, 52, 65, 78, 91, 104, 117],k = 312) == 0\n assert candidate(nums = [2, 4, 6, 8, 10, 12],k = 12) == 3\n assert candidate(nums = [9, 18, 27, 36, 45],k = 54) == 2\n assert candidate(nums = [21, 35, 105, 210, 315, 420, 630],k = 630) == 5\n assert candidate(nums = [6, 8, 12, 24, 36],k = 24) == 7\n assert candidate(nums = [3, 9, 27, 81],k = 81) == 4\n assert candidate(nums = [13, 26, 39, 52, 65],k = 780) == 3\n assert candidate(nums = [3, 5, 15, 25, 75],k = 75) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 30) == 1\n assert candidate(nums = [17, 34, 51, 68, 85],k = 102) == 2\n assert candidate(nums = [8, 16, 24, 32, 40],k = 480) == 3\n assert candidate(nums = [8, 12, 16, 24, 32],k = 48) == 5\n assert candidate(nums = [5, 10, 15, 20, 25],k = 100) == 1\n assert candidate(nums = [3, 9, 27, 81, 243, 729],k = 729) == 6\n assert candidate(nums = [60, 120, 180, 240, 300, 360, 420, 480, 540, 600],k = 60) == 1\n assert candidate(nums = [21, 42, 63, 84, 105, 126, 147, 168, 189, 210],k = 840) == 0\n assert candidate(nums = [8, 12, 24, 36, 48, 60, 72],k = 72) == 4\n assert candidate(nums = [12, 15, 20, 25, 30],k = 600) == 0\n assert candidate(nums = [4, 8, 12, 16, 20],k = 24) == 2\n assert candidate(nums = [9, 18, 27, 36, 45, 54],k = 54) == 3\n assert candidate(nums = [100, 200, 300, 400, 500],k = 100) == 1\n assert candidate(nums = [37, 74, 111, 148, 185, 222, 259, 296, 333, 370],k = 370) == 1\n assert candidate(nums = [31, 62, 93, 124, 155, 186, 217, 248, 279, 310],k = 62) == 2\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],k = 105) == 0\n assert candidate(nums = [12, 15, 20, 25, 30],k = 60) == 3\n assert candidate(nums = [7, 14, 28, 56, 112],k = 112) == 5\n assert candidate(nums = [7, 14, 28, 35, 42],k = 42) == 1\n", "comparison": "exact"}, "public_tests": ["[3,6,2,7,1]\n6", "[3]\n2"], "hints": ["The constraints on nums.length are small. It is possible to check every subarray.", "To calculate LCM, you can use a built-in function or the formula lcm(a, b) = a * b / gcd(a, b).", "As you calculate the LCM of more numbers, it can only become greater. Once it becomes greater than k, you know that any larger subarrays containing all the current elements will not work."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().subarrayLCM", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:01+00:00", "tests_total": 128, "tests_dropped": 23, "flags": [], "topic_tags": ["array", "math", "number-theory"]}, "language": "php", "interface": {"raw_signature": "function subarrayLCM($nums, $k) {", "container": "Solution", "callable": "subarrayLCM", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2472, "task_id": "maximum-number-of-non-overlapping-palindrome-substrings", "difficulty": "Hard", "problem_description": "You are given a string s and a positive integer k.\n\nSelect a set of non-overlapping substrings from the string s that satisfy the following conditions:\n\n- The length of each substring is at least k.\n- Each substring is a palindrome.\n\nReturn the maximum number of substrings in an optimal selection.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"abaccdbbd\", k = 3\nOutput: 2\nExplanation: We can select the substrings underlined in s = \"abaccdbbd\". Both \"aba\" and \"dbbd\" are palindromes and have a length of at least k = 3.\nIt can be shown that we cannot find a selection with more than two valid substrings.\n\nExample 2:\n\nInput: s = \"adbcda\", k = 2\nOutput: 0\nExplanation: There is no palindrome substring of length at least 2 in the string.\n\nConstraints:\n\n- 1 <= k <= s.length <= 2000\n- s consists of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"racecar\",k = 2) == 1\n assert candidate(s = \"mnoonm\",k = 2) == 1\n assert candidate(s = \"zzzzzz\",k = 1) == 6\n assert candidate(s = \"abcde\",k = 3) == 0\n assert candidate(s = \"abcdeedcba\",k = 2) == 1\n assert candidate(s = \"zz\",k = 1) == 2\n assert candidate(s = \"adbcda\",k = 2) == 0\n assert candidate(s = \"abcde\",k = 1) == 5\n assert candidate(s = \"aaaaa\",k = 2) == 2\n assert candidate(s = \"racecar\",k = 3) == 1\n assert candidate(s = \"abbaeaeabba\",k = 3) == 3\n assert candidate(s = \"abbaabba\",k = 3) == 2\n assert candidate(s = \"noonhighnoon\",k = 4) == 2\n assert candidate(s = \"abacdfgdcaba\",k = 3) == 2\n assert candidate(s = \"aaaa\",k = 2) == 2\n assert candidate(s = \"a\",k = 1) == 1\n assert candidate(s = \"abcdedcba\",k = 5) == 1\n assert candidate(s = \"racecarannakayak\",k = 3) == 3\n assert candidate(s = \"abcba\",k = 5) == 1\n assert candidate(s = \"abaccdbbd\",k = 3) == 2\n assert candidate(s = \"abbaeae\",k = 2) == 2\n assert candidate(s = \"z\",k = 1) == 1\n assert candidate(s = \"aaabaaaabaaaa\",k = 5) == 2\n assert candidate(s = \"levellevellevel\",k = 5) == 3\n assert candidate(s = \"abcabcabcabc\",k = 3) == 0\n assert candidate(s = \"ababababa\",k = 3) == 3\n assert candidate(s = \"abcbaabccba\",k = 3) == 2\n assert candidate(s = \"level\",k = 5) == 1\n assert candidate(s = \"xyxxyxyxyx\",k = 1) == 10\n assert candidate(s = \"aabbaaabbbaaaa\",k = 2) == 6\n assert candidate(s = \"ababababababab\",k = 2) == 4\n assert candidate(s = \"rotorreferredder\",k = 4) == 3\n assert candidate(s = \"popopopopopop\",k = 3) == 4\n assert candidate(s = \"abaaaaba\",k = 4) == 1\n assert candidate(s = \"xyxzyzyzyxzyx\",k = 3) == 3\n assert candidate(s = \"madamimadam\",k = 2) == 3\n assert candidate(s = \"aaaaaaaaaaaaaaaaaa\",k = 10) == 1\n assert candidate(s = \"abbaabbaabba\",k = 4) == 3\n assert candidate(s = \"aabbccddeeff\",k = 2) == 6\n assert candidate(s = \"rotor\",k = 5) == 1\n assert candidate(s = \"abcddcbaabcddcba\",k = 6) == 2\n assert candidate(s = \"palindromemordnilap\",k = 6) == 1\n assert candidate(s = \"aabbccddeeefffggghhhiii\",k = 4) == 0\n assert candidate(s = \"xyxzyzyzxzyxzyx\",k = 3) == 3\n assert candidate(s = \"aaaaaaaabaaaa\",k = 5) == 2\n assert candidate(s = \"levelracecaraabba\",k = 4) == 3\n assert candidate(s = \"racecarannakayak\",k = 5) == 2\n assert candidate(s = \"abccbaabccba\",k = 3) == 2\n assert candidate(s = \"abcabcabcabcabcabcabc\",k = 3) == 0\n assert candidate(s = \"abcdedcbaedcbba\",k = 5) == 1\n assert candidate(s = \"noonnoonnoon\",k = 3) == 3\n assert candidate(s = \"abbaaccddccaaabbbcccdd\",k = 3) == 5\n assert candidate(s = \"abcbabcba\",k = 5) == 1\n assert candidate(s = \"aabbabbaaabbabba\",k = 4) == 3\n assert candidate(s = \"abbaaccddccbaabba\",k = 3) == 3\n assert candidate(s = \"abbaacccbaaabbcc\",k = 3) == 3\n assert candidate(s = \"civiccivic\",k = 4) == 2\n assert candidate(s = \"aaabaaaacaaaaaa\",k = 3) == 4\n assert candidate(s = \"abracadabra\",k = 3) == 1\n assert candidate(s = \"abcdcbaabcdcba\",k = 5) == 2\n assert candidate(s = \"xyzyzyzyzyzyzyzy\",k = 2) == 5\n assert candidate(s = \"madamracecarlevel\",k = 5) == 3\n assert candidate(s = \"xyxzyzyzyzxzyzyx\",k = 3) == 5\n assert candidate(s = \"bananaabacaxxx\",k = 3) == 3\n assert candidate(s = \"noonnoonnoon\",k = 4) == 3\n assert candidate(s = \"abcdefghij\",k = 3) == 0\n assert candidate(s = \"zzzzyyyyxxxx\",k = 4) == 3\n assert candidate(s = \"aaaabbbbccccdddd\",k = 4) == 4\n assert candidate(s = \"civicracecardeified\",k = 3) == 3\n assert candidate(s = \"aabbccddeeffgg\",k = 2) == 7\n assert candidate(s = \"madamimadam\",k = 5) == 2\n assert candidate(s = \"aaaabaaaabaaaaabaaabaaa\",k = 2) == 9\n assert candidate(s = \"racecar\",k = 6) == 1\n assert candidate(s = \"xyxxyxyxyxyx\",k = 2) == 4\n assert candidate(s = \"abcbabcba\",k = 3) == 2\n assert candidate(s = \"abcabcabcabc\",k = 1) == 12\n assert candidate(s = \"abcdefgfedcba\",k = 7) == 1\n assert candidate(s = \"mamadadadadammadam\",k = 3) == 5\n assert candidate(s = \"madamimadam\",k = 3) == 3\n assert candidate(s = \"babaddabba\",k = 3) == 2\n assert candidate(s = \"aabbabaaaabbabaab\",k = 3) == 4\n assert candidate(s = \"babbbabbbab\",k = 3) == 3\n assert candidate(s = \"aabaaaabbbaaa\",k = 3) == 4\n assert candidate(s = \"aabbaabbaaabbbaabbaab\",k = 3) == 4\n assert candidate(s = \"abccbaabc\",k = 4) == 1\n assert candidate(s = \"abracadabra\",k = 5) == 0\n assert candidate(s = \"abbaabbaabba\",k = 2) == 5\n assert candidate(s = \"aaaaaabbbbbbaaaaaabbbbb\",k = 5) == 4\n assert candidate(s = \"abcbaabababaabcba\",k = 3) == 4\n assert candidate(s = \"abcabcabc\",k = 2) == 0\n assert candidate(s = \"abccbaabcabcabcabcba\",k = 5) == 2\n assert candidate(s = \"abccbaabcba\",k = 5) == 2\n assert candidate(s = \"mississippi\",k = 3) == 2\n assert candidate(s = \"abbaabbabbaabb\",k = 2) == 6\n assert candidate(s = \"abcdefedcba\",k = 5) == 1\n assert candidate(s = \"abcdefghihgfedcba\",k = 7) == 1\n assert candidate(s = \"noonmoonnoonmoon\",k = 4) == 2\n assert candidate(s = \"abcdefedcbafedcbabcdef\",k = 5) == 2\n assert candidate(s = \"abbaabba\",k = 2) == 3\n assert candidate(s = \"deeeeinedede\",k = 4) == 2\n assert candidate(s = \"abcdedcba\",k = 4) == 1\n assert candidate(s = \"aabbccddeeeffgg\",k = 2) == 7\n assert candidate(s = \"abcdedcbaabacdfgdcaba\",k = 5) == 1\n assert candidate(s = \"zzzzyyyxxxwwvvuuttssrrqqppoonnmmlkkjjiihhggffeeddccbbaaa\",k = 4) == 1\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 2) == 26\n assert candidate(s = \"aaaaabbbaaaaa\",k = 4) == 3\n assert candidate(s = \"abacabadabacaba\",k = 4) == 2\n assert candidate(s = \"madamimadam\",k = 4) == 2\n", "comparison": "exact"}, "public_tests": ["\"abaccdbbd\"\n3", "\"adbcda\"\n2"], "hints": ["Try to use dynamic programming to solve the problem.", "let dp[i] be the answer for the prefix s[0…i].", "The final answer to the problem will be dp[n-1]. How do you compute this dp?"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().maxPalindromes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:06+00:00", "tests_total": 109, "tests_dropped": 1, "flags": [], "topic_tags": ["two-pointers", "string", "dynamic-programming", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maxPalindromes($s, $k) {", "container": "Solution", "callable": "maxPalindromes", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2475, "task_id": "number-of-unequal-triplets-in-array", "difficulty": "Easy", "problem_description": "You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:\n\n- 0 <= i < j < k < nums.length\n- nums[i], nums[j], and nums[k] are pairwise distinct.\n - In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].\n\nReturn the number of triplets that meet the conditions.\n\nExample 1:\n\nInput: nums = [4,4,2,4,3]\nOutput: 3\nExplanation: The following triplets meet the conditions:\n- (0, 2, 4) because 4 != 2 != 3\n- (1, 2, 4) because 4 != 2 != 3\n- (2, 3, 4) because 2 != 4 != 3\nSince there are 3 triplets, we return 3.\nNote that (2, 0, 4) is not a valid triplet because 2 > 0.\n\nExample 2:\n\nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: No triplets meet the conditions so we return 0.\n\nConstraints:\n\n- 3 <= 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]) == 20\n assert candidate(nums = [1, 2, 2, 3, 4]) == 7\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]) == 96\n assert candidate(nums = [1, 1, 1, 1, 1]) == 0\n assert candidate(nums = [1, 2, 3]) == 1\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 0\n assert candidate(nums = [10, 20, 30, 40, 50]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5]) == 10\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 120\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]) == 120\n assert candidate(nums = [4, 4, 2, 4, 3]) == 3\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13]) == 35\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 120\n assert candidate(nums = [999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 4495\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81]) == 1140\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 50, 40, 60]) == 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]) == 960\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, 9, 9, 9, 9]) == 3584\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]) == 19600\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, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 15000\n assert candidate(nums = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 252\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 225\n assert candidate(nums = [5, 1, 4, 1, 2, 1, 5, 2, 5, 4, 5, 2, 1, 4, 2, 1, 5, 4, 2, 1, 5, 4, 2, 1, 4, 2, 1, 5, 4, 2]) == 1680\n assert candidate(nums = [100, 200, 300, 100, 200, 300, 100, 200, 300, 100, 200, 300]) == 64\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 960\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 253\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 455\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9]) == 125\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]) == 1331\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 960\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]) == 243\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 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 = [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]) == 2912\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, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 2940\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1140\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 84\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 960\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 80\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 64\n assert candidate(nums = [7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16]) == 960\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, 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]) == 76048\n assert candidate(nums = [5, 5, 5, 1, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 118\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 455\n assert candidate(nums = [1, 2, 1, 3, 2, 4, 3, 5, 4, 6]) == 88\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 640\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 6, 7, 8, 9, 10]) == 444\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]) == 161700\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 11, 12]) == 820\n assert candidate(nums = [2, 1, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 343\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 120\n assert candidate(nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]) == 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]) == 1140\n assert candidate(nums = [10, 10, 20, 20, 30, 30, 40, 40, 50, 50]) == 80\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10]) == 2530\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]) == 0\n assert candidate(nums = [100, 200, 100, 200, 300, 400, 500, 300, 200, 100]) == 68\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 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]) == 4060\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]) == 4060\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 50\n assert candidate(nums = [100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200]) == 0\n assert candidate(nums = [50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57]) == 448\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1140\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]) == 2300\n assert candidate(nums = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 900, 800, 700, 600, 500]) == 390\n assert candidate(nums = [1, 2, 2, 3, 4, 4, 5, 6, 6, 7]) == 96\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]) == 455\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 270\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 1140\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 455\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", "comparison": "exact"}, "public_tests": ["[4,4,2,4,3]", "[1,1,1,1,1]"], "hints": ["The constraints are very small. Can we try every triplet?", "Yes, we can. Use three loops to iterate through all the possible triplets, ensuring the condition i < j < k holds."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().unequalTriplets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:10+00:00", "tests_total": 74, "tests_dropped": 2, "flags": [], "topic_tags": ["array", "hash-table", "sorting"]}, "language": "php", "interface": {"raw_signature": "function unequalTriplets($nums) {", "container": "Solution", "callable": "unequalTriplets", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2477, "task_id": "minimum-fuel-cost-to-report-to-the-capital", "difficulty": "Medium", "problem_description": "There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [a_i, b_i] denotes that there exists a bidirectional road connecting cities a_i and b_i.\n\nThere is a meeting for the representatives of each city. The meeting is in the capital city.\n\nThere is a car in each city. You are given an integer seats that indicates the number of seats in each car.\n\nA representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.\n\nReturn the minimum number of liters of fuel to reach the capital city.\n\nExample 1:\n\nInput: roads = [[0,1],[0,2],[0,3]], seats = 5\nOutput: 3\nExplanation:\n- Representative_1 goes directly to the capital with 1 liter of fuel.\n- Representative_2 goes directly to the capital with 1 liter of fuel.\n- Representative_3 goes directly to the capital with 1 liter of fuel.\nIt costs 3 liters of fuel at minimum.\nIt can be proven that 3 is the minimum number of liters of fuel needed.\n\nExample 2:\n\nInput: roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2\nOutput: 7\nExplanation:\n- Representative_2 goes directly to city 3 with 1 liter of fuel.\n- Representative_2 and representative_3 go together to city 1 with 1 liter of fuel.\n- Representative_2 and representative_3 go together to the capital with 1 liter of fuel.\n- Representative_1 goes directly to the capital with 1 liter of fuel.\n- Representative_5 goes directly to the capital with 1 liter of fuel.\n- Representative_6 goes directly to city 4 with 1 liter of fuel.\n- Representative_4 and representative_6 go together to the capital with 1 liter of fuel.\nIt costs 7 liters of fuel at minimum.\nIt can be proven that 7 is the minimum number of liters of fuel needed.\n\nExample 3:\n\nInput: roads = [], seats = 1\nOutput: 0\nExplanation: No representatives need to travel to the capital city.\n\nConstraints:\n\n- 1 <= n <= 10^5\n- roads.length == n - 1\n- roads[i].length == 2\n- 0 <= a_i, b_i < n\n- a_i != b_i\n- roads represents a valid tree.\n- 1 <= seats <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]],seats = 4) == 6\n assert candidate(roads = [[0, 1], [0, 2], [0, 3]],seats = 5) == 3\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4]],seats = 3) == 5\n assert candidate(roads = [],seats = 1) == 0\n assert candidate(roads = [[3, 1], [3, 2], [1, 0], [0, 4], [0, 5], [4, 6]],seats = 2) == 7\n assert candidate(roads = [[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]],seats = 8) == 28\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [6, 8], [6, 9]],seats = 3) == 11\n assert candidate(roads = [[0, 1], [0, 2], [2, 3], [2, 4], [4, 5], [4, 6], [6, 7], [6, 8], [8, 9], [8, 10], [10, 11]],seats = 2) == 21\n assert candidate(roads = [[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]],seats = 4) == 15\n assert candidate(roads = [[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]],seats = 6) == 31\n assert candidate(roads = [[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]],seats = 5) == 34\n assert candidate(roads = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],seats = 10) == 9\n assert candidate(roads = [[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]],seats = 5) == 53\n assert candidate(roads = [[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]],seats = 12) == 45\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]],seats = 3) == 12\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7], [6, 8], [6, 9], [7, 10], [7, 11]],seats = 4) == 16\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [4, 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], [10, 25], [11, 26], [11, 27], [11, 28], [12, 29], [12, 30], [12, 31], [13, 32], [13, 33], [13, 34], [14, 35], [14, 36], [15, 37], [15, 38], [16, 39], [16, 40]],seats = 2) == 84\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],seats = 3) == 12\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [4, 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], [10, 25], [11, 26], [11, 27], [11, 28], [12, 29], [12, 30], [12, 31]],seats = 3) == 53\n assert candidate(roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [1, 6], [2, 7], [2, 8], [2, 9], [3, 10], [3, 11], [3, 12]],seats = 7) == 12\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],seats = 5) == 13\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]],seats = 4) == 8\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],seats = 4) == 11\n assert candidate(roads = [[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]],seats = 6) == 29\n assert candidate(roads = [[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], [14, 20], [15, 21], [16, 22], [17, 23], [18, 24], [19, 25], [20, 26], [21, 27], [22, 28], [23, 29], [24, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36]],seats = 8) == 42\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [5, 7]],seats = 3) == 10\n assert candidate(roads = [[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]],seats = 5) == 16\n assert candidate(roads = [[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]],seats = 4) == 32\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],seats = 4) == 15\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]],seats = 6) == 11\n assert candidate(roads = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],seats = 2) == 12\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]],seats = 5) == 11\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [3, 9], [3, 10], [3, 11], [4, 12], [4, 13], [4, 14], [5, 15], [5, 16], [5, 17]],seats = 10) == 18\n assert candidate(roads = [[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]],seats = 9) == 44\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 10], [10, 11], [11, 12], [12, 13], [13, 14]],seats = 3) == 25\n assert candidate(roads = [[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], [14, 20], [15, 21], [16, 22], [17, 23], [18, 24], [19, 25], [20, 26], [21, 27], [22, 28], [23, 29], [24, 30]],seats = 7) == 33\n assert candidate(roads = [[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]],seats = 8) == 36\n assert candidate(roads = [[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], [10, 25], [10, 26], [11, 27], [11, 28], [12, 29], [12, 30]],seats = 8) == 33\n assert candidate(roads = [[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]],seats = 7) == 29\n assert candidate(roads = [[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]],seats = 6) == 32\n assert candidate(roads = [[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], [9, 26], [10, 27], [10, 28], [10, 29]],seats = 10) == 31\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6], [6, 7], [7, 8]],seats = 4) == 10\n assert candidate(roads = [[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]],seats = 4) == 18\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [2, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [7, 10], [7, 11], [8, 12], [8, 13], [9, 14], [9, 15]],seats = 6) == 18\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [5, 6]],seats = 3) == 8\n assert candidate(roads = [[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], [11, 25], [11, 26], [12, 27], [12, 28]],seats = 6) == 32\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],seats = 5) == 11\n assert candidate(roads = [[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], [4, 15], [5, 16], [5, 17], [5, 18], [6, 19], [6, 20], [6, 21], [7, 22], [7, 23], [7, 24], [8, 25], [8, 26], [8, 27], [9, 28], [9, 29], [9, 30]],seats = 9) == 32\n assert candidate(roads = [[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]],seats = 5) == 19\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],seats = 2) == 25\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [5, 7], [5, 8], [6, 9], [6, 10]],seats = 5) == 11\n assert candidate(roads = [[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]],seats = 9) == 35\n assert candidate(roads = [[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]],seats = 5) == 14\n assert candidate(roads = [[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]],seats = 2) == 225\n assert candidate(roads = [[0, 1], [1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 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], [10, 24], [11, 25], [11, 26]],seats = 6) == 33\n assert candidate(roads = [[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]],seats = 7) == 27\n assert candidate(roads = [[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]],seats = 7) == 36\n assert candidate(roads = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]],seats = 2) == 30\n assert candidate(roads = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [3, 9], [4, 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], [10, 25], [11, 26], [11, 27], [11, 28], [12, 29], [12, 30], [12, 31], [13, 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], [21, 50], [22, 51], [22, 52], [23, 53], [23, 54], [23, 55], [24, 56], [24, 57], [25, 58], [25, 59]],seats = 4) == 88\n assert candidate(roads = [[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]],seats = 6) == 16\n assert candidate(roads = [[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], [4, 15], [5, 16], [5, 17], [5, 18], [6, 19], [6, 20], [6, 21]],seats = 8) == 22\n assert candidate(roads = [[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]],seats = 6) == 24\n assert candidate(roads = [[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]],seats = 4) == 19\n assert candidate(roads = [[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]],seats = 5) == 26\n assert candidate(roads = [[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]],seats = 2) == 64\n", "comparison": "exact"}, "public_tests": ["[[0,1],[0,2],[0,3]]\n5", "[[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]]\n2", "[]\n1"], "hints": ["Can you record the size of each subtree?", "If n people meet on the same node, what is the minimum number of cars needed?"], "metadata": {"canonical_parameter_names": ["roads", "seats"], "leetcode_dataset_entry_point": "Solution().minimumFuelCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:16+00:00", "tests_total": 65, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["tree", "depth-first-search", "breadth-first-search", "graph"]}, "language": "php", "interface": {"raw_signature": "function minimumFuelCost($roads, $seats) {", "container": "Solution", "callable": "minimumFuelCost", "parameters": [{"name": "roads", "type": "Integer[][]"}, {"name": "seats", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2478, "task_id": "number-of-beautiful-partitions", "difficulty": "Hard", "problem_description": "You are given a string s that consists of the digits '1' to '9' and two integers k and minLength.\n\nA partition of s is called beautiful if:\n\n- s is partitioned into k non-intersecting substrings.\n- Each substring has a length of at least minLength.\n- Each substring starts with a prime digit and ends with a non-prime digit. Prime digits are '2', '3', '5', and '7', and the rest of the digits are non-prime.\n\nReturn the number of beautiful partitions of s. Since the answer may be very large, return it modulo 10^9 + 7.\n\nA substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"23542185131\", k = 3, minLength = 2\nOutput: 3\nExplanation: There exists three ways to create a beautiful partition:\n\"2354 | 218 | 5131\"\n\"2354 | 21851 | 31\"\n\"2354218 | 51 | 31\"\n\nExample 2:\n\nInput: s = \"23542185131\", k = 3, minLength = 3\nOutput: 1\nExplanation: There exists one way to create a beautiful partition: \"2354 | 218 | 5131\".\n\nExample 3:\n\nInput: s = \"3312958\", k = 3, minLength = 1\nOutput: 1\nExplanation: There exists one way to create a beautiful partition: \"331 | 29 | 58\".\n\nConstraints:\n\n- 1 <= k, minLength <= s.length <= 1000\n- s consists of the digits '1' to '9'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"52372938462673572\",k = 4,minLength = 2) == 0\n assert candidate(s = \"33333\",k = 1,minLength = 1) == 0\n assert candidate(s = \"23542185131\",k = 3,minLength = 3) == 1\n assert candidate(s = \"3312958\",k = 3,minLength = 1) == 1\n assert candidate(s = \"253179\",k = 2,minLength = 1) == 1\n assert candidate(s = \"72531\",k = 1,minLength = 5) == 1\n assert candidate(s = \"357291\",k = 2,minLength = 2) == 0\n assert candidate(s = \"22354\",k = 1,minLength = 1) == 1\n assert candidate(s = \"23542185131\",k = 3,minLength = 2) == 3\n assert candidate(s = \"77777\",k = 5,minLength = 1) == 0\n assert candidate(s = \"75319\",k = 1,minLength = 5) == 1\n assert candidate(s = \"22222\",k = 5,minLength = 1) == 0\n assert candidate(s = \"2375193\",k = 2,minLength = 2) == 0\n assert candidate(s = \"3572935729\",k = 5,minLength = 2) == 0\n assert candidate(s = \"23751\",k = 2,minLength = 1) == 0\n assert candidate(s = \"2222222222\",k = 5,minLength = 1) == 0\n assert candidate(s = \"2233445566778899\",k = 2,minLength = 4) == 2\n assert candidate(s = \"7223357\",k = 2,minLength = 1) == 0\n assert candidate(s = \"23759237592375923759\",k = 5,minLength = 4) == 0\n assert candidate(s = \"35757575757575\",k = 7,minLength = 1) == 0\n assert candidate(s = \"2354218513197531\",k = 4,minLength = 3) == 2\n assert candidate(s = \"317317317317317317317317317317\",k = 8,minLength = 2) == 0\n assert candidate(s = \"353535353535353535353535\",k = 10,minLength = 2) == 0\n assert candidate(s = \"2357235723572357235723572357\",k = 10,minLength = 2) == 0\n assert candidate(s = \"23572357235723572357235723572357235723\",k = 10,minLength = 4) == 0\n assert candidate(s = \"235423542354\",k = 3,minLength = 2) == 1\n assert candidate(s = \"373737373737373737373737\",k = 10,minLength = 2) == 0\n assert candidate(s = \"2354218513123542185131\",k = 5,minLength = 2) == 35\n assert candidate(s = \"75319284628462846284\",k = 4,minLength = 3) == 4\n assert candidate(s = \"331295833129583312958331295833129583312958\",k = 10,minLength = 3) == 110\n assert candidate(s = \"77777777777777777777777777777777777777\",k = 5,minLength = 1) == 0\n assert candidate(s = \"235711317113\",k = 3,minLength = 3) == 0\n assert candidate(s = \"23542185131\",k = 5,minLength = 1) == 0\n assert candidate(s = \"2233335555777711112222333355557777\",k = 6,minLength = 2) == 0\n assert candidate(s = \"2333353333533337333313333\",k = 7,minLength = 2) == 0\n assert candidate(s = \"23572357235723572357235723572357235723\",k = 15,minLength = 5) == 0\n assert candidate(s = \"235723572357235723572357235723572357\",k = 15,minLength = 2) == 0\n assert candidate(s = \"23547186918691869\",k = 4,minLength = 2) == 0\n assert candidate(s = \"331295897531\",k = 4,minLength = 1) == 1\n assert candidate(s = \"22222222222222222222\",k = 10,minLength = 2) == 0\n assert candidate(s = \"7777777777777777777777777777\",k = 8,minLength = 3) == 0\n assert candidate(s = \"235723572357\",k = 6,minLength = 2) == 0\n assert candidate(s = \"235235235235235235\",k = 7,minLength = 3) == 0\n assert candidate(s = \"733733733733733733733733\",k = 10,minLength = 2) == 0\n assert candidate(s = \"2375913759231\",k = 4,minLength = 2) == 0\n assert candidate(s = \"222333444555666777888999\",k = 3,minLength = 3) == 1\n assert candidate(s = \"735235235235235235\",k = 7,minLength = 2) == 0\n assert candidate(s = \"252525252525252525252525\",k = 10,minLength = 2) == 0\n assert candidate(s = \"223542185131223542185131223542185131\",k = 9,minLength = 3) == 1\n assert candidate(s = \"732519753189273189\",k = 4,minLength = 3) == 0\n assert candidate(s = \"233757537537537537537\",k = 8,minLength = 3) == 0\n assert candidate(s = \"22222222222222222222222222222222222222\",k = 15,minLength = 1) == 0\n assert candidate(s = \"222333555777111222333\",k = 7,minLength = 2) == 0\n assert candidate(s = \"735218513735218513735218513735\",k = 7,minLength = 3) == 0\n assert candidate(s = \"272727272727\",k = 6,minLength = 1) == 0\n assert candidate(s = \"23572357235723572357\",k = 5,minLength = 2) == 0\n assert candidate(s = \"222333555777111\",k = 4,minLength = 3) == 0\n assert candidate(s = \"37537537537537\",k = 6,minLength = 3) == 0\n assert candidate(s = \"22335577112233557711\",k = 6,minLength = 2) == 0\n assert candidate(s = \"2573197319731973197319\",k = 9,minLength = 2) == 0\n assert candidate(s = \"2354218513171925235729\",k = 6,minLength = 3) == 0\n assert candidate(s = \"232323232323232323232323\",k = 10,minLength = 2) == 0\n assert candidate(s = \"222333555777111222333555777111\",k = 4,minLength = 3) == 0\n assert candidate(s = \"753197531975319753\",k = 10,minLength = 2) == 0\n assert candidate(s = \"33333333333333333333333333333333333333\",k = 10,minLength = 1) == 0\n assert candidate(s = \"2323232323232323\",k = 8,minLength = 2) == 0\n assert candidate(s = \"33333333333333\",k = 5,minLength = 2) == 0\n assert candidate(s = \"33129583312958331295833129583312958331\",k = 10,minLength = 3) == 15\n assert candidate(s = \"373737373737\",k = 6,minLength = 1) == 0\n assert candidate(s = \"2233557711886644\",k = 6,minLength = 1) == 0\n assert candidate(s = \"235476918235476918235476918\",k = 6,minLength = 3) == 1\n assert candidate(s = \"333222111777555333222111\",k = 9,minLength = 2) == 0\n assert candidate(s = \"29292929292929\",k = 3,minLength = 3) == 3\n assert candidate(s = \"7235719753197532\",k = 5,minLength = 2) == 0\n assert candidate(s = \"35235235235235235235235235235\",k = 10,minLength = 3) == 0\n assert candidate(s = \"333555777222444666888999\",k = 5,minLength = 2) == 0\n assert candidate(s = \"373737373737373737\",k = 5,minLength = 3) == 0\n assert candidate(s = \"222333555777111222333555777111\",k = 6,minLength = 3) == 0\n assert candidate(s = \"23572357235723\",k = 1,minLength = 1) == 0\n assert candidate(s = \"23571113171923293137414347\",k = 10,minLength = 2) == 0\n assert candidate(s = \"22222222222222\",k = 2,minLength = 5) == 0\n assert candidate(s = \"23751937519375193\",k = 5,minLength = 2) == 0\n assert candidate(s = \"235421851312354218513123542185\",k = 6,minLength = 4) == 0\n assert candidate(s = \"22222222222222222222222222222222222222\",k = 20,minLength = 1) == 0\n assert candidate(s = \"27272727272727272727272727272\",k = 8,minLength = 2) == 0\n assert candidate(s = \"2222222222222222222222222222\",k = 12,minLength = 1) == 0\n assert candidate(s = \"753753753753753753753753753753753753753753\",k = 15,minLength = 5) == 0\n assert candidate(s = \"235421851312354218513123542185131\",k = 6,minLength = 2) == 462\n assert candidate(s = \"52373197357537325\",k = 5,minLength = 1) == 0\n assert candidate(s = \"23232323232323232323232323\",k = 10,minLength = 2) == 0\n assert candidate(s = \"222333555777222333555777222333555777\",k = 6,minLength = 4) == 0\n assert candidate(s = \"23542185131973\",k = 4,minLength = 2) == 0\n assert candidate(s = \"375375375375\",k = 5,minLength = 2) == 0\n assert candidate(s = \"75319753197531975319753197531975\",k = 8,minLength = 4) == 0\n assert candidate(s = \"3257113257113257113257\",k = 10,minLength = 2) == 0\n assert candidate(s = \"223355771199\",k = 6,minLength = 2) == 0\n assert candidate(s = \"375375375375375375375375375375\",k = 7,minLength = 4) == 0\n assert candidate(s = \"23572357235723\",k = 2,minLength = 5) == 0\n assert candidate(s = \"2354218513123542185131\",k = 6,minLength = 2) == 21\n assert candidate(s = \"23572357235723572357235723572357235723\",k = 15,minLength = 3) == 0\n assert candidate(s = \"3572535725357\",k = 5,minLength = 1) == 0\n assert candidate(s = \"2357135713571357\",k = 7,minLength = 2) == 0\n assert candidate(s = \"22223333555577772222\",k = 4,minLength = 5) == 0\n assert candidate(s = \"53725372537253725372537253725372\",k = 10,minLength = 3) == 0\n assert candidate(s = \"257357257357\",k = 4,minLength = 2) == 0\n assert candidate(s = \"2197531975319753\",k = 8,minLength = 3) == 0\n assert candidate(s = \"2357235723572357\",k = 1,minLength = 15) == 0\n assert candidate(s = \"23542185131719\",k = 5,minLength = 2) == 1\n assert candidate(s = \"57575757575757575757575757575\",k = 6,minLength = 4) == 0\n assert candidate(s = \"22335577223355772233\",k = 6,minLength = 1) == 0\n assert candidate(s = \"2357235723572357235723572357\",k = 7,minLength = 5) == 0\n assert candidate(s = \"37531975319753197537531975319753\",k = 12,minLength = 2) == 0\n assert candidate(s = \"25252525252525\",k = 5,minLength = 2) == 0\n assert candidate(s = \"21212121212121\",k = 3,minLength = 2) == 15\n assert candidate(s = \"2357198462357\",k = 4,minLength = 2) == 0\n assert candidate(s = \"235723572357235723572357\",k = 10,minLength = 2) == 0\n assert candidate(s = \"23232323232323232323232323232323\",k = 10,minLength = 2) == 0\n", "comparison": "exact"}, "public_tests": ["\"23542185131\"\n3\n2", "\"23542185131\"\n3\n3", "\"3312958\"\n3\n1"], "hints": ["Try using a greedy approach where you take as many digits as possible from the left of the string for each partition.", "You can also use a dynamic programming approach, let an array dp where dp[i] is the solution of the problem for the prefix of the string ending at index i, the answer of the problem will be dp[n-1]. What are the transitions of this dp?"], "metadata": {"canonical_parameter_names": ["s", "k", "minLength"], "leetcode_dataset_entry_point": "Solution().beautifulPartitions", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:18+00:00", "tests_total": 117, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function beautifulPartitions($s, $k, $minLength) {", "container": "Solution", "callable": "beautifulPartitions", "parameters": [{"name": "s", "type": "String"}, {"name": "k", "type": "Integer"}, {"name": "minLength", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2481, "task_id": "minimum-cuts-to-divide-a-circle", "difficulty": "Easy", "problem_description": "A valid cut in a circle can be:\n\n- A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or\n- A cut that is represented by a straight line that touches one point on the edge of the circle and its center.\n\nSome valid and invalid cuts are shown in the figures below.\n\nGiven the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.\n\nExample 1:\n\nInput: n = 4\nOutput: 2\nExplanation:\nThe above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.\n\nExample 2:\n\nInput: n = 3\nOutput: 3\nExplanation:\nAt least 3 cuts are needed to divide the circle into 3 equal slices.\nIt can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape.\nAlso note that the first cut will not divide the circle into distinct parts.\n\nConstraints:\n\n- 1 <= n <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 100) == 50\n assert candidate(n = 4) == 2\n assert candidate(n = 99) == 99\n assert candidate(n = 17) == 17\n assert candidate(n = 2) == 1\n assert candidate(n = 1) == 0\n assert candidate(n = 50) == 25\n assert candidate(n = 7) == 7\n assert candidate(n = 10) == 5\n assert candidate(n = 5) == 5\n assert candidate(n = 97) == 97\n assert candidate(n = 61) == 61\n assert candidate(n = 49) == 49\n assert candidate(n = 12) == 6\n assert candidate(n = 21) == 21\n assert candidate(n = 60) == 30\n assert candidate(n = 30) == 15\n assert candidate(n = 40) == 20\n assert candidate(n = 64) == 32\n assert candidate(n = 33) == 33\n assert candidate(n = 37) == 37\n assert candidate(n = 16) == 8\n assert candidate(n = 23) == 23\n assert candidate(n = 73) == 73\n assert candidate(n = 42) == 21\n assert candidate(n = 90) == 45\n assert candidate(n = 8) == 4\n assert candidate(n = 79) == 79\n assert candidate(n = 89) == 89\n assert candidate(n = 75) == 75\n assert candidate(n = 32) == 16\n assert candidate(n = 20) == 10\n assert candidate(n = 19) == 19\n assert candidate(n = 91) == 91\n assert candidate(n = 81) == 81\n assert candidate(n = 11) == 11\n assert candidate(n = 15) == 15\n assert candidate(n = 85) == 85\n assert candidate(n = 41) == 41\n assert candidate(n = 9) == 9\n assert candidate(n = 6) == 3\n assert candidate(n = 13) == 13\n assert candidate(n = 25) == 25\n", "comparison": "exact"}, "public_tests": ["4", "3"], "hints": ["Think about odd and even values separately.", "When will we not have to cut the circle at all?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().numberOfCuts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:23+00:00", "tests_total": 44, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["math", "geometry"]}, "language": "php", "interface": {"raw_signature": "function numberOfCuts($n) {", "container": "Solution", "callable": "numberOfCuts", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2482, "task_id": "difference-between-ones-and-zeros-in-row-and-column", "difficulty": "Medium", "problem_description": "You are given a 0-indexed m x n binary matrix grid.\n\nA 0-indexed m x n difference matrix diff is created with the following procedure:\n\n- Let the number of ones in the i^th row be onesRow_i.\n- Let the number of ones in the j^th column be onesCol_j.\n- Let the number of zeros in the i^th row be zerosRow_i.\n- Let the number of zeros in the j^th column be zerosCol_j.\n- diff[i][j] = onesRow_i + onesCol_j - zerosRow_i - zerosCol_j\n\nReturn the difference matrix diff.\n\nExample 1:\n\nInput: grid = [[0,1,1],[1,0,1],[0,0,1]]\nOutput: [[0,0,4],[0,0,4],[-2,-2,2]]\nExplanation:\n- diff[0][0] = onesRow_0 + onesCol_0 - zerosRow_0 - zerosCol_0 = 2 + 1 - 1 - 2 = 0\n- diff[0][1] = onesRow_0 + onesCol_1 - zerosRow_0 - zerosCol_1 = 2 + 1 - 1 - 2 = 0\n- diff[0][2] = onesRow_0 + onesCol_2 - zerosRow_0 - zerosCol_2 = 2 + 3 - 1 - 0 = 4\n- diff[1][0] = onesRow_1 + onesCol_0 - zerosRow_1 - zerosCol_0 = 2 + 1 - 1 - 2 = 0\n- diff[1][1] = onesRow_1 + onesCol_1 - zerosRow_1 - zerosCol_1 = 2 + 1 - 1 - 2 = 0\n- diff[1][2] = onesRow_1 + onesCol_2 - zerosRow_1 - zerosCol_2 = 2 + 3 - 1 - 0 = 4\n- diff[2][0] = onesRow_2 + onesCol_0 - zerosRow_2 - zerosCol_0 = 1 + 1 - 2 - 2 = -2\n- diff[2][1] = onesRow_2 + onesCol_1 - zerosRow_2 - zerosCol_1 = 1 + 1 - 2 - 2 = -2\n- diff[2][2] = onesRow_2 + onesCol_2 - zerosRow_2 - zerosCol_2 = 1 + 3 - 2 - 0 = 2\n\nExample 2:\n\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: [[5,5,5],[5,5,5]]\nExplanation:\n- diff[0][0] = onesRow_0 + onesCol_0 - zerosRow_0 - zerosCol_0 = 3 + 2 - 0 - 0 = 5\n- diff[0][1] = onesRow_0 + onesCol_1 - zerosRow_0 - zerosCol_1 = 3 + 2 - 0 - 0 = 5\n- diff[0][2] = onesRow_0 + onesCol_2 - zerosRow_0 - zerosCol_2 = 3 + 2 - 0 - 0 = 5\n- diff[1][0] = onesRow_1 + onesCol_0 - zerosRow_1 - zerosCol_0 = 3 + 2 - 0 - 0 = 5\n- diff[1][1] = onesRow_1 + onesCol_1 - zerosRow_1 - zerosCol_1 = 3 + 2 - 0 - 0 = 5\n- diff[1][2] = onesRow_1 + onesCol_2 - zerosRow_1 - zerosCol_2 = 3 + 2 - 0 - 0 = 5\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- grid[i][j] is either 0 or 1.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0]]) == [[1, -1, 1, -1], [1, -1, 1, -1], [1, -1, 1, -1]]\n assert candidate(grid = [[0, 1, 1], [1, 0, 1], [0, 0, 1]]) == [[0, 0, 4], [0, 0, 4], [-2, -2, 2]]\n assert candidate(grid = [[1, 0], [0, 1]]) == [[0, 0], [0, 0]]\n assert candidate(grid = [[1]]) == [[2]]\n assert candidate(grid = [[0]]) == [[-2]]\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0]]) == [[1, 1, -1, -1], [1, 1, -1, -1], [1, 1, -1, -1]]\n assert candidate(grid = [[1, 1, 1], [1, 1, 1]]) == [[5, 5, 5], [5, 5, 5]]\n assert candidate(grid = [[0, 0, 0], [0, 0, 0]]) == [[-5, -5, -5], [-5, -5, -5]]\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]]) == [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [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, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]]) == [[-2, -2, -4, -2, -2], [-2, -2, -4, -2, -2], [-4, -4, -6, -4, -4], [-2, -2, -4, -2, -2], [-2, -2, -4, -2, -2]]\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]]) == [[2, 2, 2, 0, 0], [0, 0, 0, -2, -2], [2, 2, 2, 0, 0], [0, 0, 0, -2, -2], [2, 2, 2, 0, 0]]\n assert candidate(grid = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 0], [0, 0, 0, 1, 1], [1, 1, 1, 0, 0], [0, 0, 1, 1, 1]]) == [[-2, -2, 0, 0, -2], [-2, -2, 0, 0, -2], [-2, -2, 0, 0, -2], [0, 0, 2, 2, 0], [0, 0, 2, 2, 0]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) == [[8, 4, 4, 8], [4, 0, 0, 4], [4, 0, 0, 4], [8, 4, 4, 8]]\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == [[-5, -5, -5, -5, -5], [5, 5, 5, 5, 5], [-1, -1, -1, -1, -1], [1, 1, 1, 1, 1]]\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, 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, 0, 0, 0, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == [[6, 4, 6, 4, 6], [-4, -6, -4, -6, -4], [2, 0, 2, 0, 2], [0, -2, 0, -2, 0], [2, 0, 2, 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]]) == [[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, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1], [1, 1, 1, 0, 0, 0, 1, 1, 1], [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]]) == [[-6, -6, -6, 0, 0, 0, -6, -6, -6], [-6, -6, -6, 0, 0, 0, -6, -6, -6], [-6, -6, -6, 0, 0, 0, -6, -6, -6], [0, 0, 0, 6, 6, 6, 0, 0, 0], [0, 0, 0, 6, 6, 6, 0, 0, 0], [0, 0, 0, 6, 6, 6, 0, 0, 0], [-6, -6, -6, 0, 0, 0, -6, -6, -6], [-6, -6, -6, 0, 0, 0, -6, -6, -6], [-6, -6, -6, 0, 0, 0, -6, -6, -6]]\n assert candidate(grid = [[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) == [[-5, -5, -5, -5, -5], [5, 5, 5, 5, 5], [-5, -5, -5, -5, -5], [5, 5, 5, 5, 5]]\n assert candidate(grid = [[1, 0, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1], [0, 1, 1, 0]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n assert candidate(grid = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 1, 1, 0], [0, 1, 0, 1, 1]]) == [[-1, -1, -1, 1, -1], [1, 1, 1, 3, 1], [1, 1, 1, 3, 1], [1, 1, 1, 3, 1]]\n assert candidate(grid = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 0, 0], [1, 1, 1, 1]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [-4, -4, -4, -4], [4, 4, 4, 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]]) == [[-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(grid = [[1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1]]) == [[2, 2, 2, 2, 2, 2], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [-2, -2, -2, -2, -2, -2], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]\n assert candidate(grid = [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n assert candidate(grid = [[1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1], [1, 0, 1, 0, 1, 0], [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]]\n assert candidate(grid = [[1, 0, 0, 1, 0, 1], [0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1], [0, 1, 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]]\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]]) == [[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(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 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(grid = [[1, 1, 0, 0, 0], [0, 0, 1, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 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(grid = [[1, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 1]]) == [[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, 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, -4, -8, -8, -4, -12], [-4, 4, 0, 0, 4, -4], [-8, 0, -4, -4, 0, -8], [-8, 0, -4, -4, 0, -8], [-4, 4, 0, 0, 4, -4], [-12, -4, -8, -8, -4, -12]]\n assert candidate(grid = [[1, 0, 0, 1], [0, 1, 1, 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]]\n assert candidate(grid = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]) == [[-2, 0, -2, 0, -2], [0, 2, 0, 2, 0], [-2, 0, -2, 0, -2]]\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]]) == [[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]]) == [[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(grid = [[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 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]]\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, 1, 1, 1]]) == [[2, 2, 2, 2, 2], [0, 0, 0, 0, 0], [2, 2, 2, 2, 2], [0, 0, 0, 0, 0], [6, 6, 6, 6, 6]]\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n assert candidate(grid = [[0, 1, 0, 1, 1], [1, 0, 1, 0, 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]]\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) == [[-7, -7, -7, -7], [-7, -7, -7, -7], [-7, -7, -7, -7]]\n assert candidate(grid = [[1, 1, 0, 0, 1], [1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [0, 0, 0, 1, 1], [1, 1, 1, 0, 0]]) == [[2, 2, 2, 0, 2], [2, 2, 2, 0, 2], [2, 2, 2, 0, 2], [0, 0, 0, -2, 0], [2, 2, 2, 0, 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, 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, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) == [[-9, -9, -9, -9, -9], [-9, -9, -9, -9, -9], [-9, -9, -9, -9, -9], [-9, -9, -9, -9, -9]]\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, 1, 1, 1, 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, 0, 0, 1], [1, 1, 0, 0]]) == [[1, -1, -1, 1], [1, -1, -1, 1], [1, -1, -1, 1]]\n assert candidate(grid = [[0, 1, 1, 0, 1], [1, 0, 0, 1, 0], [1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [0, 0, 0, 0, 0]]) == [[0, 0, 0, 0, 0], [-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2], [0, 0, 0, 0, 0], [-6, -6, -6, -6, -6]]\n assert candidate(grid = [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0]]) == [[5, 5, 5, 5, 5], [-5, -5, -5, -5, -5], [5, 5, 5, 5, 5], [-5, -5, -5, -5, -5]]\n assert candidate(grid = [[0, 0, 0, 1], [1, 1, 1, 0], [0, 1, 0, 1]]) == [[-3, -1, -3, -1], [1, 3, 1, 3], [-1, 1, -1, 1]]\n assert candidate(grid = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) == [[-4, -4, -4, -4], [-4, -4, -4, -4], [-4, -4, -4, -4], [-4, -4, -4, -4]]\n assert candidate(grid = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n assert candidate(grid = [[1, 0, 0, 1, 0], [0, 1, 1, 0, 1], [1, 0, 1, 0, 1], [0, 1, 0, 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(grid = [[1, 1, 0, 0, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 1, 0], [1, 0, 0, 1, 1]]) == [[2, 0, 0, 2, 2], [2, 0, 0, 2, 2], [0, -2, -2, 0, 0], [0, -2, -2, 0, 0], [2, 0, 0, 2, 2]]\n assert candidate(grid = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\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]]) == [[-3, 1, 1, -3, 1, 1, -3], [-1, 3, 3, -1, 3, 3, -1], [-1, 3, 3, -1, 3, 3, -1], [-3, 1, 1, -3, 1, 1, -3], [-1, 3, 3, -1, 3, 3, -1], [-1, 3, 3, -1, 3, 3, -1]]\n assert candidate(grid = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == [[-1, 1, -1, 1], [-1, 1, -1, 1], [-1, 1, -1, 1]]\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]]) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 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]]) == [[-1, -1, -1, -1, -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, 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]]) == [[0, 0, 0, 0, 0, 0, 0, 0], [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, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 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(grid = [[1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [1, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, 1]]) == [[-4, -4, -6, -6, -4, -4], [-4, -4, -6, -6, -4, -4], [-6, -6, -8, -8, -6, -6], [-6, -6, -8, -8, -6, -6], [-4, -4, -6, -6, -4, -4], [-4, -4, -6, -6, -4, -4]]\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) == [[8, 8, 8, 8], [8, 8, 8, 8], [8, 8, 8, 8], [8, 8, 8, 8]]\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]) == [[2, 0, 2, 0, 2], [0, -2, 0, -2, 0], [2, 0, 2, 0, 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]]) == [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]\n assert candidate(grid = [[0, 0, 1, 1, 0], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1]]) == [[-2, -2, 0, 0, -2], [-2, -2, 0, 0, -2], [0, 0, 2, 2, 0], [-2, -2, 0, 0, -2], [0, 0, 2, 2, 0]]\n assert candidate(grid = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 0, 1], [1, 1, 1, 1]]) == [[0, 0, 0, 2], [0, 0, 0, 2], [-2, -2, -2, 0], [4, 4, 4, 6]]\n assert candidate(grid = [[1, 0, 1, 1, 0], [0, 1, 0, 1, 0], [1, 1, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1]]) == [[2, 0, 2, 2, 0], [0, -2, 0, 0, -2], [2, 0, 2, 2, 0], [0, -2, 0, 0, -2], [2, 0, 2, 2, 0]]\n", "comparison": "exact"}, "public_tests": ["[[0,1,1],[1,0,1],[0,0,1]]", "[[1,1,1],[1,1,1]]"], "hints": ["You need to reuse information about a row or a column many times. Try storing it to avoid computing it multiple times.", "Use an array to store the number of 1’s in each row and another array to store the number of 1’s in each column. Once you know the number of 1’s in each row or column, you can also easily calculate the number of 0’s."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().onesMinusZeros", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:25+00:00", "tests_total": 67, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["array", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function onesMinusZeros($grid) {", "container": "Solution", "callable": "onesMinusZeros", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer[][]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2483, "task_id": "minimum-penalty-for-a-shop", "difficulty": "Medium", "problem_description": "You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':\n\n- if the i^th character is 'Y', it means that customers come at the i^th hour\n- whereas 'N' indicates that no customers come at the i^th hour.\n\nIf the shop closes at the j^th hour (0 <= j <= n), the penalty is calculated as follows:\n\n- For every hour when the shop is open and no customers come, the penalty increases by 1.\n- For every hour when the shop is closed and customers come, the penalty increases by 1.\n\nReturn the earliest hour at which the shop must be closed to incur a minimum penalty.\n\nNote that if a shop closes at the j^th hour, it means the shop is closed at the hour j.\n\nExample 1:\n\nInput: customers = \"YYNY\"\nOutput: 2\nExplanation:\n- Closing the shop at the 0^th hour incurs in 1+1+0+1 = 3 penalty.\n- Closing the shop at the 1^st hour incurs in 0+1+0+1 = 2 penalty.\n- Closing the shop at the 2^nd hour incurs in 0+0+0+1 = 1 penalty.\n- Closing the shop at the 3^rd hour incurs in 0+0+1+1 = 2 penalty.\n- Closing the shop at the 4^th hour incurs in 0+0+1+0 = 1 penalty.\nClosing the shop at 2^nd or 4^th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2.\n\nExample 2:\n\nInput: customers = \"NNNNN\"\nOutput: 0\nExplanation: It is best to close the shop at the 0^th hour as no customers arrive.\n\nExample 3:\n\nInput: customers = \"YYYY\"\nOutput: 4\nExplanation: It is best to close the shop at the 4^th hour as customers arrive at each hour.\n\nConstraints:\n\n- 1 <= customers.length <= 10^5\n- customers consists only of characters 'Y' and 'N'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(customers = \"YNYNYN\") == 1\n assert candidate(customers = \"YNNYNYYNYN\") == 1\n assert candidate(customers = \"NNYNNYNNYNNYNN\") == 0\n assert candidate(customers = \"YYYYNNYYYYNNYYYYNNYYYYNNNN\") == 22\n assert candidate(customers = \"YNYYYYYYNY\") == 8\n assert candidate(customers = \"YNYYYYNNYY\") == 6\n assert candidate(customers = \"NYYNNYNY\") == 3\n assert candidate(customers = \"YNYNNYNYYN\") == 1\n assert candidate(customers = \"NYYYYYNNNYYYYYYYYYYNNNNN\") == 19\n assert candidate(customers = \"YNYNYNYNYN\") == 1\n assert candidate(customers = \"YNYNYNYNYNYN\") == 1\n assert candidate(customers = \"NNNNN\") == 0\n assert candidate(customers = \"YYYYYYYYYY\") == 10\n assert candidate(customers = \"YYYYYYYYYYYY\") == 12\n assert candidate(customers = \"NNNNNNNNNNNN\") == 0\n assert candidate(customers = \"NNYNNYNYN\") == 0\n assert candidate(customers = \"NYNNNNNNYN\") == 0\n assert candidate(customers = \"NNNNNNNNNN\") == 0\n assert candidate(customers = \"YYNY\") == 2\n assert candidate(customers = \"YYYYNNNNYYYY\") == 4\n assert candidate(customers = \"NYYNNYNYNNY\") == 3\n assert candidate(customers = \"NYNYNYNYNYNY\") == 0\n assert candidate(customers = \"NYNYNYNYNY\") == 0\n assert candidate(customers = \"YYYY\") == 4\n assert candidate(customers = \"YNYYYYYYNYYN\") == 11\n assert candidate(customers = \"YNNYYNYY\") == 8\n assert candidate(customers = \"YYYYYNNNNNYYYYYY\") == 16\n assert candidate(customers = \"YNNYNYY\") == 1\n assert candidate(customers = \"NNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYYYNNYNNYNNYNNY\") == 4\n assert candidate(customers = \"NNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYY\") == 46\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNN\") == 48\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYYYYYYYY\") == 20\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYY\") == 0\n assert candidate(customers = \"NYNYNYNYNNYNNYNN\") == 0\n assert candidate(customers = \"YYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYY\") == 6\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNNNN\") == 94\n assert candidate(customers = \"YNYYYYYYYYNYNYYYYYYYYNYNYYYYYYYYNYNYYYYYYYYNYNYYYYYYYY\") == 54\n assert candidate(customers = \"YYNNYNYNYNYNYNYNYNYN\") == 2\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"NYNNYYNYNNYYNYNNYYNY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 94\n assert candidate(customers = \"YYYYNNYYYNYYNNYYNNYYNYNNYYNYNYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNYNYNYNNYYNNYYNNYYNNYYNYNYNYNNYYNNYYNNYYNNYYNYNYNY\") == 12\n assert candidate(customers = \"YYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNN\") == 2\n assert candidate(customers = \"YYYYYNNNNNYYYYYNNNNNYYYYYNNNNNYYYYYNNNNN\") == 5\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNN\") == 94\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 0\n assert candidate(customers = \"YNNYNYYNYYNNYNNYNYYN\") == 10\n assert candidate(customers = \"YYYYYNNYYYYNNYYY\") == 16\n assert candidate(customers = \"YYNNYYNNYYNNYY\") == 2\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 92\n assert candidate(customers = \"NYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 94\n assert candidate(customers = \"YYYYYYYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYYYY\") == 10\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYNYYNYNYYNNYY\") == 10\n assert candidate(customers = \"NYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYY\") == 16\n assert candidate(customers = \"NYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNY\") == 78\n assert candidate(customers = \"NYNYNYNYNYNYNYNY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 88\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 1\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNN\") == 94\n assert candidate(customers = \"YYYYNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNY\") == 4\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYYYNNNNYYYYNNNN\") == 4\n assert candidate(customers = \"YYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYY\") == 41\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYN\") == 1\n assert candidate(customers = \"NYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYY\") == 3\n assert candidate(customers = \"NNNNNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 94\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYY\") == 20\n assert candidate(customers = \"YYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYY\") == 2\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNN\") == 94\n assert candidate(customers = \"NYNYNNYNYNYNYNNYNYNNYNYNYNNYNYNNYNYNNYNY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 64\n assert candidate(customers = \"NYNYNYNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNY\") == 0\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNNYYYN\") == 41\n assert candidate(customers = \"NYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYN\") == 93\n assert candidate(customers = \"NYNNYNYNNYNYNNYNYNNYNYNNYNYNNYNYNNYNYNNYNYNNYNYNNYNYNNYN\") == 0\n assert candidate(customers = \"NNNNNNNNYYYYYYYY\") == 0\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"NNYNNYNNYNNYNNYY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNN\") == 52\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 44\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"NNYYNNNNYYNNYYYYNYYY\") == 20\n assert candidate(customers = \"NYNNYNYYNNYNYYNNYNYYNNYNYYNNYNYYNNYNYYNN\") == 0\n assert candidate(customers = \"NNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNN\") == 0\n assert candidate(customers = \"YNNYYNYYNNYYNYYNNYYNYYNNYYNYYNNYYNYYNNYYNYYNN\") == 43\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNN\") == 94\n assert candidate(customers = \"NNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNN\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 104\n assert candidate(customers = \"YYYYYNNNNNNNNNNN\") == 5\n assert candidate(customers = \"YYYYYNNYNYNYNYNN\") == 5\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 1\n assert candidate(customers = \"NNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNN\") == 0\n assert candidate(customers = \"YYYYYYYYYYNNNNNNNN\") == 10\n assert candidate(customers = \"YYYYYYNNNNNNYYYYYYNNNNNNYYYYYYNNNNNNYYYYYY\") == 6\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNNY\") == 2\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYYYYYYYYYYYYYY\") == 0\n assert candidate(customers = \"YYYYNNYYYNYYYYNNYYYNYYYYNNYYYNYYYYNNYYYNYYYYNNYYYNYYYY\") == 54\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNNYYNYNN\") == 2\n assert candidate(customers = \"YYYYNNNNNNNNNNNNNNNNNNNNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 108\n assert candidate(customers = \"YYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYYYYY\") == 96\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 0\n assert candidate(customers = \"YNYNYNYNYNYNYNYN\") == 1\n assert candidate(customers = \"NYNYYNNYNYNYYNNYNYNY\") == 5\n assert candidate(customers = \"NNYNYNYNYNYNYNYN\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 54\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNN\") == 94\n assert candidate(customers = \"YYNNYYYYYYNNYYYYYYNNYYYYYYNNYYYYYYNNYYYYYY\") == 42\n assert candidate(customers = \"NYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNY\") == 39\n assert candidate(customers = \"NNNNNYYYYYYYNNNN\") == 12\n assert candidate(customers = \"YYYYYNNNNYYYYYYYYYNNNNNNNYYYYYYYYYNNNNNYYY\") == 34\n assert candidate(customers = \"YYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNN\") == 10\n assert candidate(customers = \"YNNNNYNNYNYNYNYNNYNNYNNYNYNNYNNYNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNYNNY\") == 1\n assert candidate(customers = \"YYNYNYNYNYNNYNNY\") == 2\n assert candidate(customers = \"NYYYYYYYYYNNNNNNNNNN\") == 10\n assert candidate(customers = \"NNNNNNYYYYYYYYYYYYYY\") == 20\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNNNNNN\") == 94\n assert candidate(customers = \"NNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYYNNNNYYYY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 40\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNN\") == 94\n assert candidate(customers = \"YYNNYYNNYYNN\") == 2\n assert candidate(customers = \"NNYNYNYNYNYNYNNY\") == 0\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYN\") == 1\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNN\") == 94\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 1\n assert candidate(customers = \"YYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNN\") == 10\n assert candidate(customers = \"NYYYYYYYYYYYNN\") == 12\n assert candidate(customers = \"NNYYYYNNYYYYNNYYYYNNYYYYNNYYYYNNYYYYNNYYYY\") == 42\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNN\") == 94\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYN\") == 1\n assert candidate(customers = \"NNNNYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 24\n assert candidate(customers = \"YNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 1\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYY\") == 4\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNYNY\") == 0\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNN\") == 88\n assert candidate(customers = \"YYYNYYNYYYNYYNNYYYYNYYYYNYNYNYYYYYYYYYYYYNNNYNYNYYNNYNN\") == 41\n assert candidate(customers = \"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\") == 70\n assert candidate(customers = \"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\") == 0\n assert candidate(customers = \"NNNNNNNNNYYYYYYYYYYNNNNNNNNNYYYYYYYYYYNNNNNNNNNYYYYYYYYYYNNNNNNNNNYYYYYYYYYY\") == 76\n assert candidate(customers = \"YYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYYNNYY\") == 2\n assert candidate(customers = \"NYNNNYNNNYNNNY\") == 0\n assert candidate(customers = \"NYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNYYNNYY\") == 39\n assert candidate(customers = \"NNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNNYYYYYYYYYYNNNNNNNNNN\") == 0\n assert candidate(customers = \"YYYYYYYYYYNNNNNNNNNN\") == 10\n assert candidate(customers = \"NYNYNYNYNYNYNYNYNYNYNYNNNNNNNNNNNNNNNNNNNNNNNNYYYYYYYYYYYYYYYYYYYY\") == 0\n", "comparison": "exact"}, "public_tests": ["\"YYNY\"", "\"NNNNN\"", "\"YYYY\""], "hints": ["At any index, the penalty is the sum of prefix count of ‘N’ and suffix count of ‘Y’.", "Enumerate all indices and find the minimum such value."], "metadata": {"canonical_parameter_names": ["customers"], "leetcode_dataset_entry_point": "Solution().bestClosingTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:27+00:00", "tests_total": 152, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function bestClosingTime($customers) {", "container": "Solution", "callable": "bestClosingTime", "parameters": [{"name": "customers", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2484, "task_id": "count-palindromic-subsequences", "difficulty": "Hard", "problem_description": "Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 10^9 + 7.\n\nNote:\n\n- A string is palindromic if it reads the same forward and backward.\n- A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nExample 1:\n\nInput: s = \"103301\"\nOutput: 2\nExplanation:\nThere are 6 possible subsequences of length 5: \"10330\",\"10331\",\"10301\",\"10301\",\"13301\",\"03301\".\nTwo of them (both equal to \"10301\") are palindromic.\n\nExample 2:\n\nInput: s = \"0000000\"\nOutput: 21\nExplanation: All 21 subsequences are \"00000\", which is palindromic.\n\nExample 3:\n\nInput: s = \"9999900000\"\nOutput: 2\nExplanation: The only two palindromic subsequences are \"99999\" and \"00000\".\n\nConstraints:\n\n- 1 <= s.length <= 10^4\n- s consists of digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"100100100\") == 34\n assert candidate(s = \"9876543210\") == 0\n assert candidate(s = \"54321012345\") == 30\n assert candidate(s = \"12345678900987654321\") == 240\n assert candidate(s = \"00000000000000000000\") == 15504\n assert candidate(s = \"122112211\") == 33\n assert candidate(s = \"1234567890\") == 0\n assert candidate(s = \"123454321\") == 14\n assert candidate(s = \"0000000\") == 21\n assert candidate(s = \"103301\") == 2\n assert candidate(s = \"98765432100123456789\") == 240\n assert candidate(s = \"1234321234321\") == 109\n assert candidate(s = \"1111111111\") == 252\n assert candidate(s = \"0123456789\") == 0\n assert candidate(s = \"012343210\") == 14\n assert candidate(s = \"1232123212\") == 39\n assert candidate(s = \"1001001001\") == 80\n assert candidate(s = \"5555555555\") == 252\n assert candidate(s = \"1010101010\") == 68\n assert candidate(s = \"1221221221\") == 80\n assert candidate(s = \"1234567890987654321\") == 204\n assert candidate(s = \"0101010101\") == 68\n assert candidate(s = \"1212121212\") == 68\n assert candidate(s = \"9999900000\") == 2\n assert candidate(s = \"000000111111000000\") == 2868\n assert candidate(s = \"123454321123454321\") == 364\n assert candidate(s = \"1234567898765432123456789876543212345678987654321\") == 24502\n assert candidate(s = \"22233322233322233322\") == 3990\n assert candidate(s = \"54321098765432109876543210987654321054321\") == 7758\n assert candidate(s = \"1122334455667788998877665544332211\") == 5056\n assert candidate(s = \"98765432112345678998765432100\") == 672\n assert candidate(s = \"89098098098098098098\") == 1848\n assert candidate(s = \"12345678901234567890123456789012345678901234567890\") == 18100\n assert candidate(s = \"1232123212321232123212321\") == 7180\n assert candidate(s = \"12345543211234554321\") == 580\n assert candidate(s = \"12345123451234512345123451234512345\") == 12425\n assert candidate(s = \"10101010101010101010101010\") == 16588\n assert candidate(s = \"987654321012345678909876543210123456789\") == 5433\n assert candidate(s = \"90123456789012345678901234567890123456789\") == 6346\n assert candidate(s = \"010101010101010101\") == 2184\n assert candidate(s = \"098765432109876543210987654321098765432109876543210\") == 21210\n assert candidate(s = \"1234567898765432121234567898765432121\") == 5455\n assert candidate(s = \"112233445544332211\") == 576\n assert candidate(s = \"987654321000123456789\") == 285\n assert candidate(s = \"987654321000000000000000000000000000000009876543210\") == 281976\n assert candidate(s = \"987654321098765432109876543210987654321098765432109876543210\") == 49200\n assert candidate(s = \"1122334455443322112233445544332211\") == 12024\n assert candidate(s = \"0000011111222223333344444555554444433333222221111100000\") == 138761\n assert candidate(s = \"987654321123456789876543210011223344556677889987654321\") == 31546\n assert candidate(s = \"98765432101234567898\") == 253\n assert candidate(s = \"10101010101010101010101\") == 8701\n assert candidate(s = \"5555555555555555555555555555555555555555\") == 658008\n assert candidate(s = \"01020304050607080901\") == 918\n assert candidate(s = \"123456789098765432101234567890\") == 978\n assert candidate(s = \"123456789000000000987654321\") == 1374\n assert candidate(s = \"1234567890123456789012345678901234567890\") == 5040\n assert candidate(s = \"000111222333444555444333222111000\") == 9840\n assert candidate(s = \"999888777666555444333222111000\") == 0\n assert candidate(s = \"99999000001111122222333334444455555444443333322222111110000099999\") == 237888\n assert candidate(s = \"11223344556677889900998877665544332211\") == 7266\n assert candidate(s = \"111111111111111111111111111111111111111111111111111\") == 2349060\n assert candidate(s = \"00000100001000010000100000\") == 37118\n assert candidate(s = \"111000111000111000111000111000111\") == 61584\n assert candidate(s = \"99999888887777766666555554444433333222221111100000\") == 10\n assert candidate(s = \"9876543210012345678998765432100123456789\") == 5910\n assert candidate(s = \"1234567898765432112345678987654321\") == 3320\n assert candidate(s = \"12211221122112211\") == 1574\n assert candidate(s = \"543210000012345\") == 121\n assert candidate(s = \"12211221122112211221\") == 3916\n assert candidate(s = \"67890098766789009876\") == 580\n assert candidate(s = \"9876543210987654321098765432109876543210\") == 5040\n assert candidate(s = \"1111100000111110000011111000001111100000\") == 146008\n assert candidate(s = \"98765432101234567899876543210123456789\") == 4794\n assert candidate(s = \"00000111110000011111\") == 2004\n assert candidate(s = \"101010101010101010101010101010101010101010101010101010101010101010101010\") == 3501456\n assert candidate(s = \"111222333222111222333\") == 1470\n assert candidate(s = \"00000000001111111111000000000\") == 38880\n assert candidate(s = \"111110000000000000000000000000000000000000000000000\") == 1370755\n assert candidate(s = \"123456789876543210123456789\") == 624\n assert candidate(s = \"1234543216789876123454321\") == 942\n assert candidate(s = \"9876543210012345678998765432100123456789987654321\") == 17193\n assert candidate(s = \"11001100110011001100\") == 3656\n assert candidate(s = \"11100011100011100011\") == 3990\n assert candidate(s = \"99999000009999900000\") == 2004\n assert candidate(s = \"10010010010010010010\") == 4535\n assert candidate(s = \"11112222333322221111\") == 2736\n assert candidate(s = \"1232112321123211232112321123211232112321\") == 85128\n assert candidate(s = \"987654321987654321987654321\") == 576\n assert candidate(s = \"121212121212121212121212121212121212121212121212\") == 429088\n assert candidate(s = \"12345678909876543211234567890987654321\") == 4794\n assert candidate(s = \"1221122112211\") == 331\n assert candidate(s = \"99999888887777766666\") == 4\n assert candidate(s = \"123456789012345678901234567890123456789012345678901234567890\") == 49200\n assert candidate(s = \"111222333444555444333222111\") == 4974\n assert candidate(s = \"123454321123454321123454321\") == 3470\n assert candidate(s = \"0123456789876543210123456789876543210\") == 4385\n assert candidate(s = \"99999999999999999\") == 6188\n assert candidate(s = \"567899876567899876\") == 324\n assert candidate(s = \"000111222333444555666777888999888777666555444333222111000\") == 58374\n assert candidate(s = \"001122334455667788990000000000000000000000000000\") == 149310\n assert candidate(s = \"555555555555555555555555555\") == 80730\n assert candidate(s = \"1232123212321232123212321232123212321232\") == 91158\n assert candidate(s = \"543210123456789876543210\") == 399\n assert candidate(s = \"123211232112321123211232112321\") == 18456\n assert candidate(s = \"123456789098765432101234567890987654321\") == 5433\n assert candidate(s = \"90909090909090909090\") == 3936\n assert candidate(s = \"000011110000111100001111\") == 8368\n assert candidate(s = \"12345678909876543210\") == 204\n assert candidate(s = \"10101010101010101010101010101010101010101\") == 189202\n assert candidate(s = \"123456789098765432121234567890\") == 995\n assert candidate(s = \"987654321012345678987654321\") == 624\n assert candidate(s = \"10101010101010101\") == 1652\n assert candidate(s = \"0000000000111111111122222222223333333333\") == 1008\n assert candidate(s = \"11223344556677889998877665544332211\") == 5544\n assert candidate(s = \"55555555555555555555\") == 15504\n assert candidate(s = \"123456789987654321123456789\") == 672\n assert candidate(s = \"123321123321123321\") == 946\n assert candidate(s = \"10101010101010101010101010101010\") == 50624\n assert candidate(s = \"1001001001001001001001001\") == 15330\n assert candidate(s = \"01234567899876543210\") == 240\n assert candidate(s = \"123456789876543210000000000000000000\") == 11768\n assert candidate(s = \"1111222233334444555566667777888899990000\") == 0\n assert candidate(s = \"12345678987654321012345678987654321\") == 3568\n assert candidate(s = \"54321234554321234554\") == 698\n assert candidate(s = \"999999000000999999000000999999000000999999\") == 227796\n assert candidate(s = \"12345678900987654321001234567890\") == 1528\n assert candidate(s = \"90807060505060708090\") == 1254\n assert candidate(s = \"123454321123454321123454321123454321\") == 16368\n assert candidate(s = \"0123456789876543210123456789\") == 688\n assert candidate(s = \"98765432101020304050607080908070605040302010\") == 33248\n assert candidate(s = \"12345432112345432112\") == 698\n assert candidate(s = \"1001001001001001001001001001001001001001001001001\") == 564020\n assert candidate(s = \"00112233445566778899\") == 0\n assert candidate(s = \"987654321000000000000000000000000000123456789\") == 108195\n assert candidate(s = \"34554334554334554334\") == 1720\n assert candidate(s = \"100000000000000000000000000000000000000001\") == 667888\n assert candidate(s = \"1234567890098765432112345678900987654321\") == 5910\n assert candidate(s = \"01010101010101010101\") == 3936\n assert candidate(s = \"12345678900987654321000123456789\") == 1645\n assert candidate(s = \"00000111112222233333444445555566666777778888899999\") == 10\n assert candidate(s = \"010101010101010\") == 819\n assert candidate(s = \"10101010101010101010\") == 3936\n assert candidate(s = \"12345678901234567890123456789012345678901234567890123456789\") == 46090\n assert candidate(s = \"9876543210012345678909876543210\") == 1230\n assert candidate(s = \"54321098765432109876543210987654321\") == 2925\n assert candidate(s = \"000000000000000000000000000000000000000000000000001\") == 2118760\n assert candidate(s = \"111222333444555666777888999000999888777666555444333222111\") == 58374\n assert candidate(s = \"0123456789876543210\") == 204\n assert candidate(s = \"20202020202020202020\") == 3936\n", "comparison": "exact"}, "public_tests": ["\"103301\"", "\"0000000\"", "\"9999900000\""], "hints": ["There are 100 possibilities for the first two characters of the palindrome.", "Iterate over all characters, letting the current character be the center of the palindrome."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countPalindromes", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:30+00:00", "tests_total": 149, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "php", "interface": {"raw_signature": "function countPalindromes($s) {", "container": "Solution", "callable": "countPalindromes", "parameters": [{"name": "s", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2485, "task_id": "find-the-pivot-integer", "difficulty": "Easy", "problem_description": "Given a positive integer n, find the pivot integer x such that:\n\n- The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.\n\nReturn the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.\n\nExample 1:\n\nInput: n = 8\nOutput: 6\nExplanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.\n\nExample 2:\n\nInput: n = 1\nOutput: 1\nExplanation: 1 is the pivot integer since: 1 = 1.\n\nExample 3:\n\nInput: n = 4\nOutput: -1\nExplanation: It can be proved that no such integer exist.\n\nConstraints:\n\n- 1 <= n <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 3) == -1\n assert candidate(n = 4) == -1\n assert candidate(n = 1) == 1\n assert candidate(n = 1000) == -1\n assert candidate(n = 10) == -1\n assert candidate(n = 625) == -1\n assert candidate(n = 576) == -1\n assert candidate(n = 729) == -1\n assert candidate(n = 144) == -1\n assert candidate(n = 49) == 35\n assert candidate(n = 12) == -1\n assert candidate(n = 900) == -1\n assert candidate(n = 324) == -1\n assert candidate(n = 100) == -1\n assert candidate(n = 50) == -1\n assert candidate(n = 5) == -1\n assert candidate(n = 841) == -1\n assert candidate(n = 289) == -1\n assert candidate(n = 550) == -1\n assert candidate(n = 99) == -1\n assert candidate(n = 64) == -1\n assert candidate(n = 17) == -1\n assert candidate(n = 484) == -1\n assert candidate(n = 2) == -1\n assert candidate(n = 225) == -1\n assert candidate(n = 784) == -1\n assert candidate(n = 250) == -1\n assert candidate(n = 999) == -1\n assert candidate(n = 35) == -1\n assert candidate(n = 169) == -1\n assert candidate(n = 75) == -1\n assert candidate(n = 256) == -1\n assert candidate(n = 36) == -1\n assert candidate(n = 529) == -1\n assert candidate(n = 20) == -1\n assert candidate(n = 676) == -1\n assert candidate(n = 81) == -1\n assert candidate(n = 48) == -1\n assert candidate(n = 325) == -1\n assert candidate(n = 15) == -1\n assert candidate(n = 441) == -1\n assert candidate(n = 961) == -1\n assert candidate(n = 400) == -1\n assert candidate(n = 196) == -1\n assert candidate(n = 9) == -1\n assert candidate(n = 121) == -1\n assert candidate(n = 361) == -1\n assert candidate(n = 700) == -1\n assert candidate(n = 500) == -1\n assert candidate(n = 7) == -1\n assert candidate(n = 25) == -1\n", "comparison": "exact"}, "public_tests": ["8", "1", "4"], "hints": ["Can you use brute force to check every number from 1 to n if any of them is the pivot integer?", "If you know the sum of [1: pivot], how can you efficiently calculate the sum of the other parts?"], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().pivotInteger", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:32+00:00", "tests_total": 52, "tests_dropped": 0, "flags": [], "topic_tags": ["math", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function pivotInteger($n) {", "container": "Solution", "callable": "pivotInteger", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2486, "task_id": "append-characters-to-string-to-make-subsequence", "difficulty": "Medium", "problem_description": "You are given two strings s and t consisting of only lowercase English letters.\n\nReturn the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.\n\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\n\nExample 1:\n\nInput: s = \"coaching\", t = \"coding\"\nOutput: 4\nExplanation: Append the characters \"ding\" to the end of s so that s = \"coachingding\".\nNow, t is a subsequence of s (\"coachingding\").\nIt can be shown that appending any 3 characters to the end of s will never make t a subsequence.\n\nExample 2:\n\nInput: s = \"abcde\", t = \"a\"\nOutput: 0\nExplanation: t is already a subsequence of s (\"abcde\").\n\nExample 3:\n\nInput: s = \"z\", t = \"abcde\"\nOutput: 5\nExplanation: Append the characters \"abcde\" to the end of s so that s = \"zabcde\".\nNow, t is a subsequence of s (\"zabcde\").\nIt can be shown that appending any 4 characters to the end of s will never make t a subsequence.\n\nConstraints:\n\n- 1 <= s.length, t.length <= 10^5\n- s and t consist only of lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefgh\",t = \"ghijkl\") == 4\n assert candidate(s = \"ababab\",t = \"bbba\") == 1\n assert candidate(s = \"abcd\",t = \"xyz\") == 3\n assert candidate(s = \"aaaa\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"dbca\") == 3\n assert candidate(s = \"aabbcc\",t = \"abc\") == 0\n assert candidate(s = \"aaaaa\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"abcde\") == 1\n assert candidate(s = \"ababab\",t = \"bbbb\") == 1\n assert candidate(s = \"ab\",t = \"abc\") == 1\n assert candidate(s = \"abcdefgh\",t = \"efghij\") == 2\n assert candidate(s = \"hello\",t = \"oleh\") == 3\n assert candidate(s = \"abcde\",t = \"a\") == 0\n assert candidate(s = \"abcd\",t = \"abdc\") == 1\n assert candidate(s = \"abcd\",t = \"abcd\") == 0\n assert candidate(s = \"z\",t = \"abcde\") == 5\n assert candidate(s = \"abcabc\",t = \"abc\") == 0\n assert candidate(s = \"hello\",t = \"ole\") == 2\n assert candidate(s = \"abcdefgh\",t = \"efgh\") == 0\n assert candidate(s = \"a\",t = \"b\") == 1\n assert candidate(s = \"coaching\",t = \"coding\") == 4\n assert candidate(s = \"xyz\",t = \"xyza\") == 1\n assert candidate(s = \"xyz\",t = \"xyz\") == 0\n assert candidate(s = \"abcd\",t = \"efgh\") == 4\n assert candidate(s = \"aaaa\",t = \"aa\") == 0\n assert candidate(s = \"complex\",t = \"cmpx\") == 0\n assert candidate(s = \"abcabcabcabcabcabc\",t = \"abcabcabcabcabcd\") == 1\n assert candidate(s = \"thisisaverylongstring\",t = \"thisstring\") == 0\n assert candidate(s = \"hellothere\",t = \"lohere\") == 0\n assert candidate(s = \"ababababab\",t = \"bababa\") == 0\n assert candidate(s = \"xyzxyzxyzxyzxyz\",t = \"xyzyzyzyzyzyzyz\") == 4\n assert candidate(s = \"abcdabcdabcd\",t = \"dcba\") == 1\n assert candidate(s = \"abcabcabcabc\",t = \"abacaba\") == 0\n assert candidate(s = \"thefastbrownfoxjumpsoverthelazydog\",t = \"quickbrownfox\") == 13\n assert candidate(s = \"abcdefghijk\",t = \"acegik\") == 0\n assert candidate(s = \"abcde\",t = \"cbad\") == 3\n assert candidate(s = \"abracadabra\",t = \"bracadabr\") == 0\n assert candidate(s = \"longstringwithvariouscharacters\",t = \"string\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 24\n assert candidate(s = \"sequence\",t = \"subsequence\") == 9\n assert candidate(s = \"abcabcabcabc\",t = \"cccc\") == 0\n assert candidate(s = \"longerstring\",t = \"string\") == 0\n assert candidate(s = \"aaaabbbbcccc\",t = \"abcabc\") == 3\n assert candidate(s = \"abcdef\",t = \"fghijk\") == 5\n assert candidate(s = \"abcdef\",t = \"defghijk\") == 5\n assert candidate(s = \"abcdexyz\",t = \"dezy\") == 1\n assert candidate(s = \"xyzxyzxyz\",t = \"zyxzyxzyx\") == 5\n assert candidate(s = \"abababababababab\",t = \"abab\") == 0\n assert candidate(s = \"kglvkyeavnnrdq\",t = \"lky\") == 0\n assert candidate(s = \"abcabcabcabc\",t = \"abcdabcdabcd\") == 9\n assert candidate(s = \"abcdefghij\",t = \"hijjiklmn\") == 6\n assert candidate(s = \"overlaplaplap\",t = \"laplaplaplap\") == 3\n assert candidate(s = \"xyxyxyxyxy\",t = \"xyyx\") == 0\n assert candidate(s = \"hello\",t = \"heoo\") == 1\n assert candidate(s = \"abcde\",t = \"edcba\") == 4\n assert candidate(s = \"randomstring\",t = \"stringrandom\") == 6\n assert candidate(s = \"mississippi\",t = \"pis\") == 1\n assert candidate(s = \"abcdabcdabcd\",t = \"abcabcabc\") == 0\n assert candidate(s = \"sequencealignment\",t = \"seqaln\") == 0\n assert candidate(s = \"testtesttest\",t = \"testset\") == 0\n assert candidate(s = \"mississippi\",t = \"pippi\") == 3\n assert candidate(s = \"mississippi\",t = \"issip\") == 0\n assert candidate(s = \"sequencealignment\",t = \"quencal\") == 0\n assert candidate(s = \"abcdefghij\",t = \"jihgfedcba\") == 9\n assert candidate(s = \"programming\",t = \"gram\") == 0\n assert candidate(s = \"abcdef\",t = \"fedcba\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"xyzuvw\") == 3\n assert candidate(s = \"abacabadabacaba\",t = \"abcd\") == 0\n assert candidate(s = \"mississippi\",t = \"issi\") == 0\n assert candidate(s = \"aaaaabbbbbcccccdddddeeeee\",t = \"abcde\") == 0\n assert candidate(s = \"longstringwithrandomcharacters\",t = \"lgrmc\") == 0\n assert candidate(s = \"zzzzzzzzzz\",t = \"abcdefghij\") == 10\n assert candidate(s = \"patternmatching\",t = \"ternat\") == 0\n assert candidate(s = \"aabbaabbccddeeff\",t = \"abcdeff\") == 0\n assert candidate(s = \"abcde\",t = \"abcdeabcde\") == 5\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"uniquecharacters\",t = \"charactersunique\") == 6\n assert candidate(s = \"programming\",t = \"progmin\") == 0\n assert candidate(s = \"subsequence\",t = \"subs\") == 0\n assert candidate(s = \"hellothere\",t = \"othertimes\") == 5\n assert candidate(s = \"aaaaaa\",t = \"aabbcc\") == 4\n assert candidate(s = \"abcde\",t = \"efghij\") == 5\n assert candidate(s = \"mississippi\",t = \"isip\") == 0\n assert candidate(s = \"abcdefabcdef\",t = \"fedcbafedcba\") == 10\n assert candidate(s = \"longerstringwithcharacters\",t = \"stringcharacters\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"short\",t = \"longerstring\") == 12\n assert candidate(s = \"abcabcabcabcabc\",t = \"abcabcabc\") == 0\n assert candidate(s = \"abababababababab\",t = \"zzzzyyyyxxxxwwwwvvvvuuuuttttrrrrqqqqpppplllloooonnnnmmmkkkkjjjjiiiihhhhhggggggfffffeeeeeddddccccbbbbbaaaa\") == 105\n assert candidate(s = \"overlappingcharacters\",t = \"lap\") == 0\n assert candidate(s = \"sequence\",t = \"quen\") == 0\n assert candidate(s = \"abcdefghij\",t = \"zzzzzzzzzz\") == 10\n assert candidate(s = \"aaaaabbbbb\",t = \"abababab\") == 6\n assert candidate(s = \"abcdefgh\",t = \"ihgfedcba\") == 9\n assert candidate(s = \"thisisaverylongstring\",t = \"isaverylong\") == 0\n assert candidate(s = \"programming\",t = \"gramming\") == 0\n assert candidate(s = \"longeststring\",t = \"tiny\") == 1\n assert candidate(s = \"xyz\",t = \"zyxzyxzyx\") == 8\n assert candidate(s = \"abcdeabcdeabcde\",t = \"abcdee\") == 0\n assert candidate(s = \"abracadabra\",t = \"acadabra\") == 0\n assert candidate(s = \"mississippi\",t = \"ppip\") == 1\n assert candidate(s = \"onetwothreefourfive\",t = \"owhfv\") == 0\n assert candidate(s = \"aaaaaa\",t = \"bbbbb\") == 5\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",t = \"zzzyyxwwvvuutsrrqppoonnmlkkjjiihhggffeeddccbbaa\") == 45\n assert candidate(s = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",t = \"aaaaaaaaaaaaaaaaaaaaaaaaaaab\") == 1\n assert candidate(s = \"abcdefghij\",t = \"hijjiklm\") == 5\n assert candidate(s = \"example\",t = \"ample\") == 0\n assert candidate(s = \"hello\",t = \"lelo\") == 3\n assert candidate(s = \"abcabcabcabc\",t = \"abcabcabcabcabcabc\") == 6\n assert candidate(s = \"characters\",t = \"char\") == 0\n assert candidate(s = \"aaaabbbbcccc\",t = \"abc\") == 0\n assert candidate(s = \"aaaaaaaaaa\",t = \"aaaabbbbcccc\") == 8\n assert candidate(s = \"xyzuvw\",t = \"abcdefghijklmnopqrstuvwxyz\") == 26\n assert candidate(s = \"xyz\",t = \"wxyzyxwxyzyx\") == 12\n assert candidate(s = \"abcabcabcabcabc\",t = \"abcbcabcbcabcbca\") == 3\n assert candidate(s = \"randomstring\",t = \"random\") == 0\n assert candidate(s = \"abcdefghiklmnopqrstuvwxyz\",t = \"mnopqrstuvwxyz\") == 0\n assert candidate(s = \"aabacadaea\",t = \"abcde\") == 0\n assert candidate(s = \"aaaaaa\",t = \"aaaaaab\") == 1\n assert candidate(s = \"sequence\",t = \"seq\") == 0\n assert candidate(s = \"repeatedcharactersrepeatedcharacters\",t = \"characterscharacterscharacters\") == 10\n assert candidate(s = \"abcdefghij\",t = \"hijjijk\") == 4\n assert candidate(s = \"abacabadabacaba\",t = \"abcabcabc\") == 1\n assert candidate(s = \"xyzabc\",t = \"uvwabc\") == 6\n assert candidate(s = \"alibabacloud\",t = \"aliloud\") == 0\n assert candidate(s = \"aaaabbbbcccc\",t = \"bbcccaaa\") == 3\n assert candidate(s = \"aaaaabbbbbcccc\",t = \"abcabc\") == 3\n assert candidate(s = \"hello\",t = \"olelh\") == 4\n assert candidate(s = \"abcdefg\",t = \"agh\") == 1\n assert candidate(s = \"abcdefghijkllkjihgfedcba\",t = \"abcdefghijkllkjihgfedcba\") == 0\n assert candidate(s = \"overlappingoverlapping\",t = \"lapover\") == 0\n assert candidate(s = \"abcabcabcabcabc\",t = \"aabbaabbaabbaabb\") == 9\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvutsrqponmlkjihgfedcba\") == 25\n assert candidate(s = \"xyzzyxzyxzyz\",t = \"xyzxyz\") == 0\n assert candidate(s = \"hellotherehellothere\",t = \"helloothere\") == 0\n assert candidate(s = \"abcdefghij\",t = \"hijjikl\") == 4\n assert candidate(s = \"abacabadabacaba\",t = \"badaba\") == 0\n assert candidate(s = \"aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxxyyyzzz\",t = \"zzzyyxxwwvvuuuttrrssqqppoonnmmlkkjjiihhgggfffeeeddccbbaaa\") == 54\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",t = \"zyxwvut\") == 6\n assert candidate(s = \"abcdefghij\",t = \"hijjik\") == 3\n assert candidate(s = \"aabbccddeeffgg\",t = \"abcdefg\") == 0\n assert candidate(s = \"qwertyuiopasdfghjklzxcvbnm\",t = \"qwertyuiopasdfghjklzxcvbnmqwertyuiop\") == 10\n assert candidate(s = \"abcdefghij\",t = \"acegik\") == 1\n assert candidate(s = \"racecar\",t = \"racecar\") == 0\n assert candidate(s = \"abracadabra\",t = \"abcde\") == 1\n assert candidate(s = \"abcdefghij\",t = \"abcdefghij\") == 0\n", "comparison": "exact"}, "public_tests": ["\"coaching\"\n\"coding\"", "\"abcde\"\n\"a\"", "\"z\"\n\"abcde\""], "hints": ["Find the longest prefix of t that is a subsequence of s.", "Use two variables to keep track of your location in s and t. If the characters match, increment both variables. Otherwise, only increment the variable for s.", "The remaining characters in t must be appended to the end of s."], "metadata": {"canonical_parameter_names": ["s", "t"], "leetcode_dataset_entry_point": "Solution().appendCharacters", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:34+00:00", "tests_total": 153, "tests_dropped": 7, "flags": [], "topic_tags": ["two-pointers", "string", "greedy"]}, "language": "php", "interface": {"raw_signature": "function appendCharacters($s, $t) {", "container": "Solution", "callable": "appendCharacters", "parameters": [{"name": "s", "type": "String"}, {"name": "t", "type": "String"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2488, "task_id": "count-subarrays-with-median-k", "difficulty": "Hard", "problem_description": "You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.\n\nReturn the number of non-empty subarrays in nums that have a median equal to k.\n\nNote:\n\n- The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element.\n - For example, the median of [2,3,1,4] is 2, and the median of [8,4,3,5,1] is 4.\n- A subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [3,2,1,4,5], k = 4\nOutput: 3\nExplanation: The subarrays that have a median equal to 4 are: [4], [4,5] and [1,4,5].\n\nExample 2:\n\nInput: nums = [2,3,1], k = 3\nOutput: 1\nExplanation: [3] is the only subarray that has a median equal to 3.\n\nConstraints:\n\n- n == nums.length\n- 1 <= n <= 10^5\n- 1 <= nums[i], k <= n\n- The integers in nums are distinct.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 3, 1],k = 3) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 5) == 10\n assert candidate(nums = [5, 1, 4, 3, 2],k = 3) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6],k = 4) == 5\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 9\n assert candidate(nums = [3, 2, 1, 4, 5],k = 4) == 3\n assert candidate(nums = [7, 5, 3, 1, 2, 4, 6],k = 4) == 4\n assert candidate(nums = [5, 4, 3, 2, 1],k = 3) == 5\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 5) == 13\n assert candidate(nums = [5, 6, 7, 8, 9, 1, 2, 3, 4],k = 5) == 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],k = 15) == 30\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 = 15) == 21\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9],k = 5) == 6\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 10\n assert candidate(nums = [1, 5, 2, 6, 3, 7, 4, 8, 9, 10],k = 5) == 7\n assert candidate(nums = [1, 3, 2, 6, 5, 4, 8, 7, 9],k = 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, 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 = 27) == 47\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) == 30\n assert candidate(nums = [5, 2, 8, 3, 9, 4, 10, 1, 6, 7],k = 5) == 6\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 11\n assert candidate(nums = [4, 3, 2, 1, 5, 6, 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) == 50\n assert candidate(nums = [15, 20, 10, 25, 5, 1, 6, 11, 16, 21, 26, 30, 3, 8, 13, 18, 23, 28, 2, 7, 12, 17, 22, 27, 29, 4, 9, 14, 19, 24],k = 15) == 17\n assert candidate(nums = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6, 11, 20, 12, 19, 13, 18, 14, 17, 15, 16, 21, 30, 22, 29, 23, 28, 24, 27, 25, 26, 31, 40, 32, 39, 33, 38, 34, 37, 35, 36, 41, 50, 42, 49, 43, 48, 44, 47, 45, 46],k = 25) == 54\n assert candidate(nums = [5, 10, 4, 3, 8, 7, 9, 2, 6, 1],k = 5) == 7\n assert candidate(nums = [1, 5, 9, 13, 17, 21, 25, 29, 2, 6, 10, 14, 18, 22, 26, 30, 3, 7, 11, 15, 19, 23, 27, 28, 4, 8, 12, 16, 20, 24],k = 15) == 87\n assert candidate(nums = [4, 1, 5, 3, 2, 7, 6, 8, 9, 10],k = 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],k = 10) == 20\n assert candidate(nums = [2, 4, 6, 8, 10, 1, 3, 5, 7, 9],k = 5) == 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, 21, 22, 23, 24, 25],k = 13) == 25\n assert candidate(nums = [5, 1, 3, 2, 4, 6, 8, 7, 10, 9],k = 5) == 3\n assert candidate(nums = [25, 20, 15, 10, 5, 1, 6, 11, 16, 21, 26, 30, 3, 8, 13, 18, 23, 28, 2, 7, 12, 17, 22, 27, 29, 4, 9, 14, 19, 24],k = 15) == 24\n assert candidate(nums = [3, 1, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 20],k = 10) == 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],k = 11) == 19\n assert candidate(nums = [4, 1, 5, 3, 2, 6, 8, 7, 9, 10],k = 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],k = 25) == 11\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 10\n assert candidate(nums = [5, 1, 3, 2, 4, 8, 6, 7, 9, 10],k = 6) == 10\n assert candidate(nums = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10],k = 5) == 13\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) == 11\n assert candidate(nums = [1, 13, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12, 14, 15, 16, 17, 18, 19, 20, 3],k = 10) == 24\n assert candidate(nums = [5, 1, 4, 2, 3, 8, 6, 7, 10, 9],k = 5) == 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 = 11) == 19\n assert candidate(nums = [5, 3, 1, 2, 4, 6, 7, 8, 9, 10],k = 6) == 9\n assert candidate(nums = [5, 1, 9, 3, 7, 8, 2, 6, 4, 10],k = 5) == 8\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],k = 15) == 44\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) == 20\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 7\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 5) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 8) == 15\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10],k = 7) == 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],k = 12) == 17\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4],k = 5) == 3\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 15\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 6, 4, 10],k = 5) == 7\n assert candidate(nums = [1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8],k = 8) == 15\n assert candidate(nums = [12, 14, 10, 15, 13, 11, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 10) == 9\n assert candidate(nums = [1, 11, 5, 9, 7, 2, 6, 3, 8, 10, 4],k = 6) == 25\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 9\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 10\n assert candidate(nums = [3, 6, 1, 8, 5, 2, 9, 4, 7],k = 5) == 19\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 10) == 28\n assert candidate(nums = [3, 1, 4, 2, 5],k = 3) == 3\n assert candidate(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 8) == 15\n assert candidate(nums = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 11) == 25\n assert candidate(nums = [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) == 35\n assert candidate(nums = [2, 1, 5, 3, 4, 6, 7, 8, 9, 10],k = 5) == 7\n assert candidate(nums = [5, 1, 9, 3, 7, 2, 8, 4, 6, 10],k = 5) == 6\n", "comparison": "exact"}, "public_tests": ["[3,2,1,4,5]\n4", "[2,3,1]\n3"], "hints": ["Consider changing the numbers that are strictly greater than k in the array to 1, the numbers that are strictly smaller than k to -1, and k to 0.", "After the change, what property does a subarray with median k have in the new array?", "An array with median k should have a sum equal to either 0 or 1 in the new array and should contain the element k. How do you count such subarrays?"], "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-30T20:54:39+00:00", "tests_total": 79, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "hash-table", "prefix-sum"]}, "language": "php", "interface": {"raw_signature": "function countSubarrays($nums, $k) {", "container": "Solution", "callable": "countSubarrays", "parameters": [{"name": "nums", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2490, "task_id": "circular-sentence", "difficulty": "Easy", "problem_description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n\n- For example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.\n\nWords consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.\n\nA sentence is circular if:\n\n- The last character of each word in the sentence is equal to the first character of its next word.\n- The last character of the last word is equal to the first character of the first word.\n\nFor example, \"leetcode exercises sound delightful\", \"eetcode\", \"leetcode eats soul\" are all circular sentences. However, \"Leetcode is cool\", \"happy Leetcode\", \"Leetcode\" and \"I like Leetcode\" are not circular sentences.\n\nGiven a string sentence, return true if it is circular. Otherwise, return false.\n\nExample 1:\n\nInput: sentence = \"leetcode exercises sound delightful\"\nOutput: true\nExplanation: The words in sentence are [\"leetcode\", \"exercises\", \"sound\", \"delightful\"].\n- leetcode's last character is equal to exercises's first character.\n- exercises's last character is equal to sound's first character.\n- sound's last character is equal to delightful's first character.\n- delightful's last character is equal to leetcode's first character.\nThe sentence is circular.\n\nExample 2:\n\nInput: sentence = \"eetcode\"\nOutput: true\nExplanation: The words in sentence are [\"eetcode\"].\n- eetcode's last character is equal to eetcode's first character.\nThe sentence is circular.\n\nExample 3:\n\nInput: sentence = \"Leetcode is cool\"\nOutput: false\nExplanation: The words in sentence are [\"Leetcode\", \"is\", \"cool\"].\n- Leetcode's last character is not equal to is's first character.\nThe sentence is not circular.\n\nConstraints:\n\n- 1 <= sentence.length <= 500\n- sentence consist of only lowercase and uppercase English letters and spaces.\n- The words in sentence are separated by a single space.\n- There are no leading or trailing spaces.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(sentence = \"sentence ence sent\") == False\n assert candidate(sentence = \"hello olleh\") == True\n assert candidate(sentence = \"Aa Aa\") == False\n assert candidate(sentence = \"ab ba\") == True\n assert candidate(sentence = \"a\") == True\n assert candidate(sentence = \"Leetcode is cool\") == False\n assert candidate(sentence = \"b\") == True\n assert candidate(sentence = \"A aA A\") == False\n assert candidate(sentence = \"abcd dcba\") == True\n assert candidate(sentence = \"circular rular circul\") == False\n assert candidate(sentence = \"Zz zZ\") == True\n assert candidate(sentence = \"abc cba\") == True\n assert candidate(sentence = \"a a a a\") == True\n assert candidate(sentence = \"example ample exa\") == False\n assert candidate(sentence = \"A a A\") == False\n assert candidate(sentence = \"Zz\") == False\n assert candidate(sentence = \"eetcode\") == True\n assert candidate(sentence = \"abc cab bca\") == True\n assert candidate(sentence = \"abc bca cab\") == False\n assert candidate(sentence = \"B ba B\") == False\n assert candidate(sentence = \"leetcode exercises sound delightful\") == True\n assert candidate(sentence = \"b b b\") == True\n assert candidate(sentence = \"a b c a\") == False\n assert candidate(sentence = \"A a\") == False\n assert candidate(sentence = \"test tset\") == True\n assert candidate(sentence = \"aba\") == True\n assert candidate(sentence = \"mnopqr stuvwx yzab cd efgh ijklm nopqr\") == False\n assert candidate(sentence = \"world dlrow\") == True\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyz zabcdefghijklmnopqrstuvwxy\") == False\n assert candidate(sentence = \"No lemon no melon\") == False\n assert candidate(sentence = \"Anna\") == False\n assert candidate(sentence = \"Able was I ere I saw Elba Able\") == False\n assert candidate(sentence = \"Was it a car or a cat I saw saw I tac a ro rac a si taW taW\") == False\n assert candidate(sentence = \"Madam In Eden Im Adam\") == False\n assert candidate(sentence = \"Circular logic confuses brains sourcing smiles\") == False\n assert candidate(sentence = \"Rotation noitator tor\") == False\n assert candidate(sentence = \"noon moon moon\") == False\n assert candidate(sentence = \"peep peep\") == True\n assert candidate(sentence = \"b aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa b\") == False\n assert candidate(sentence = \"Noon neons number nicely\") == False\n assert candidate(sentence = \"Madam madam madam\") == False\n assert candidate(sentence = \"refer level civic civic civic level refer\") == False\n assert candidate(sentence = \"xyyx xxyy\") == False\n assert candidate(sentence = \"kayak kayak kayak kayak\") == True\n assert candidate(sentence = \"rotor racecar level deed civic\") == False\n assert candidate(sentence = \"stats tacocat stats\") == False\n assert candidate(sentence = \"racecar civic madam\") == False\n assert candidate(sentence = \"Step on no pets no step on no pets\") == False\n assert candidate(sentence = \"Able was I I saw Elba Elba saw I I was Able\") == False\n assert candidate(sentence = \"tacocat\") == True\n assert candidate(sentence = \"a quick brown fox jumps over lazy a\") == False\n assert candidate(sentence = \"zoo online one nice Easter egg\") == False\n assert candidate(sentence = \"Word dOrw\") == False\n assert candidate(sentence = \"deed deed\") == True\n assert candidate(sentence = \"daemon daemon\") == False\n assert candidate(sentence = \"Palindrome emordnilaP\") == True\n assert candidate(sentence = \"madam racecar civic\") == False\n assert candidate(sentence = \"Circular arular ci\") == False\n assert candidate(sentence = \"Madam adaM\") == False\n assert candidate(sentence = \"A Santa at NASA\") == False\n assert candidate(sentence = \"sun sets slowly on nosy wonks\") == False\n assert candidate(sentence = \"madam racecar level deed civic kayak rotor\") == False\n assert candidate(sentence = \"abcde edcba\") == True\n assert candidate(sentence = \"Nested edset n\") == False\n assert candidate(sentence = \"kayak kayak\") == True\n assert candidate(sentence = \"Nurses run Nurses\") == False\n assert candidate(sentence = \"Programming gnostic stem ngram minnow winnow now\") == False\n assert candidate(sentence = \"rotor rotor\") == True\n assert candidate(sentence = \"redivider\") == True\n assert candidate(sentence = \"racecar civic level deed\") == False\n assert candidate(sentence = \"Abba aaaa aa a\") == False\n assert candidate(sentence = \"xylophone elephant monkey keen\") == False\n assert candidate(sentence = \"xyzzyx\") == True\n assert candidate(sentence = \"circularloop loop\") == False\n assert candidate(sentence = \"Alaska Kansas suck slyly yelling nasty nasty yaks yak salty knapsack sacks sacks sky kayak kayak kayak\") == False\n assert candidate(sentence = \"x y z x\") == False\n assert candidate(sentence = \"programming is simply programming\") == False\n assert candidate(sentence = \"zoo omega meal alpha\") == False\n assert candidate(sentence = \"Loop opLo\") == False\n assert candidate(sentence = \"Startling lightning bugs ignited giants\") == False\n assert candidate(sentence = \"xylophone one love evolution nation\") == False\n assert candidate(sentence = \"deed deed deed\") == True\n assert candidate(sentence = \"Palindrome emordnilaP laP\") == False\n assert candidate(sentence = \"noon odd level civic civic civic level odd noon\") == False\n assert candidate(sentence = \"Was it a car or a cat I saw Was\") == False\n assert candidate(sentence = \"Reflection noitcifilr\") == False\n assert candidate(sentence = \"ab ba ac ca\") == True\n assert candidate(sentence = \"racecar racecar\") == True\n assert candidate(sentence = \"abracadabra arachnophobia\") == True\n assert candidate(sentence = \"repaper repaper repaper\") == True\n assert candidate(sentence = \"Complex xs w x\") == False\n assert candidate(sentence = \"abcd defg ghij jkla\") == True\n assert candidate(sentence = \"Interstellar rstellar inter\") == False\n assert candidate(sentence = \"reviled devil level deed vile derevered\") == False\n assert candidate(sentence = \"Fascinating ideas inspire amazing minds\") == False\n assert candidate(sentence = \"Alphabet tebahpla A\") == False\n assert candidate(sentence = \"Unique new weird weed nude euqinu\") == False\n assert candidate(sentence = \"Wow wow\") == False\n assert candidate(sentence = \"tortoise einstein noodles stein snot not ossetia\") == False\n assert candidate(sentence = \"rotor kayak rotor\") == False\n assert candidate(sentence = \"kayak kayak kayak kayak kayak\") == True\n assert candidate(sentence = \"zebra apple orange night eagle\") == False\n assert candidate(sentence = \"Zebra apple orange elephant\") == False\n assert candidate(sentence = \"redder redder\") == True\n assert candidate(sentence = \"No lemon no melon no lemon no melon\") == False\n assert candidate(sentence = \"xylophone elephant monkey keen noodle leet teex\") == False\n assert candidate(sentence = \"Anna civic radar level rotor\") == False\n assert candidate(sentence = \"zoo omega anna apple\") == False\n assert candidate(sentence = \"Detartrated dater dated\") == False\n assert candidate(sentence = \"xylophone excellent noodles seen\") == False\n assert candidate(sentence = \"Madam madam\") == False\n assert candidate(sentence = \"level level\") == True\n assert candidate(sentence = \"abracadabra aracnidae earthworms mammals sloths\") == False\n assert candidate(sentence = \"level level level level\") == True\n assert candidate(sentence = \"Wow wow wow\") == False\n assert candidate(sentence = \"palindrome emordnilap\") == True\n assert candidate(sentence = \"Was it a car or a cat I saw seen saw I tac a ro rac a ti saw\") == False\n assert candidate(sentence = \"a aa aaa aaaa\") == True\n assert candidate(sentence = \"xylophone objective elegant elegant not\") == False\n assert candidate(sentence = \"b b b b b\") == True\n assert candidate(sentence = \"XYlophone emotion motion nation\") == False\n assert candidate(sentence = \"Zoos own cozy zones\") == False\n assert candidate(sentence = \"deified deified deified deified\") == True\n assert candidate(sentence = \"Was it a car or a cat I saw\") == False\n assert candidate(sentence = \"Zebra apple apple orange onion nginx\") == False\n assert candidate(sentence = \"cycle ycle c\") == False\n assert candidate(sentence = \"Wow\") == False\n assert candidate(sentence = \"Programming gamifies lessons yielding successes\") == False\n assert candidate(sentence = \"Rhythms mesmerize symphonies\") == False\n assert candidate(sentence = \"Madam Ada\") == False\n assert candidate(sentence = \"Madam Arora teaches malayalam Madam\") == False\n assert candidate(sentence = \"Rotator taro Rotator\") == False\n assert candidate(sentence = \"a a a a a a a a a a a a\") == True\n assert candidate(sentence = \"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba\") == True\n assert candidate(sentence = \"Civic civic\") == False\n assert candidate(sentence = \"repaper deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed deed\") == False\n assert candidate(sentence = \"kayak civic deed level odd noon\") == False\n assert candidate(sentence = \"Madam Arora teaches malayalam\") == False\n assert candidate(sentence = \"noon odd level deed civic kayak\") == False\n assert candidate(sentence = \"giraffe elephant noodle leet teex xxyy\") == False\n assert candidate(sentence = \"Echo Charlie Hotel Hotel Echo\") == False\n assert candidate(sentence = \"racecar madam rotator\") == False\n assert candidate(sentence = \"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\") == False\n assert candidate(sentence = \"solo ollas solar lassos\") == False\n assert candidate(sentence = \"madamrefer\") == False\n assert candidate(sentence = \"civic racecar level madam deed rotator redivider\") == False\n assert candidate(sentence = \"Tactocat civic\") == False\n assert candidate(sentence = \"Xylophones yield xenial xylophiles\") == False\n assert candidate(sentence = \"civic deed level civic civic\") == False\n assert candidate(sentence = \"Underground neutergnu\") == False\n assert candidate(sentence = \"rotor\") == True\n assert candidate(sentence = \"racecar\") == True\n assert candidate(sentence = \"singleword\") == False\n assert candidate(sentence = \"zoo ooz zoo\") == False\n assert candidate(sentence = \"redder redivider redivider\") == True\n assert candidate(sentence = \"xylophone one phone nova ava axolotl talontax\") == False\n assert candidate(sentence = \"ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az\") == False\n assert candidate(sentence = \"kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak kayak\") == True\n assert candidate(sentence = \"a aa aaaa a\") == True\n assert candidate(sentence = \"Mushroom nrooms moss stamper reaper\") == False\n assert candidate(sentence = \"daemon nomad\") == True\n assert candidate(sentence = \"AbCd DeFg GhIj JkLa\") == False\n assert candidate(sentence = \"level deed deed level\") == False\n assert candidate(sentence = \"Stressed desserts\") == False\n assert candidate(sentence = \"stats stats\") == True\n assert candidate(sentence = \"A Santa at NASA A\") == False\n assert candidate(sentence = \"civic madam racecar\") == False\n assert candidate(sentence = \"repaper repaper\") == True\n assert candidate(sentence = \"Palindrome emordnilaP el\") == False\n assert candidate(sentence = \"Able was I I saw Elba\") == False\n assert candidate(sentence = \"Programming ngRams Make sense\") == False\n assert candidate(sentence = \"Mimi\") == False\n assert candidate(sentence = \"rotor rotor rotor\") == True\n assert candidate(sentence = \"rotor rotor rotor rotor\") == True\n assert candidate(sentence = \"rotator rotator\") == True\n assert candidate(sentence = \"No lemon no melon No\") == False\n assert candidate(sentence = \"Step on no pets\") == False\n assert candidate(sentence = \"A Santa at NASA at a Santa A\") == False\n assert candidate(sentence = \"Was it a car or a cat I saw saw I tac a ro rac a si taW\") == False\n assert candidate(sentence = \"a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa a\") == True\n assert candidate(sentence = \"redivider deified civic level rotator deed madam racecar\") == False\n assert candidate(sentence = \"a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa\") == True\n assert candidate(sentence = \"level level level\") == True\n assert candidate(sentence = \"deified deified\") == True\n assert candidate(sentence = \"Circular larriuC\") == False\n assert candidate(sentence = \"Symmetry try sym\") == False\n assert candidate(sentence = \"redivider redivider\") == True\n assert candidate(sentence = \"banana apple orange emitter\") == False\n assert candidate(sentence = \"reviled devil\") == False\n assert candidate(sentence = \"abracadabra arachnid did deep peeled Elba bar\") == False\n assert candidate(sentence = \"civic deed civic deed\") == False\n assert candidate(sentence = \"Wow kayak wow wow wow wow wow\") == False\n assert candidate(sentence = \"Anna annA\") == True\n assert candidate(sentence = \"Never odd or even\") == False\n assert candidate(sentence = \"Nurses run\") == False\n assert candidate(sentence = \"aaaaa aaaaa aaaaa\") == True\n assert candidate(sentence = \"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\") == False\n assert candidate(sentence = \"Zebra apple orchid night eagle\") == False\n assert candidate(sentence = \"repaid diaper\") == True\n assert candidate(sentence = \"Abc bcd def efg gfa\") == False\n assert candidate(sentence = \"Abc cba abc\") == False\n assert candidate(sentence = \"a a a a a a a a a a\") == True\n assert candidate(sentence = \"banana apple orange nice East West\") == False\n assert candidate(sentence = \"Python nohtyP\") == True\n assert candidate(sentence = \"Palindrome emordnilaP ndromePal\") == False\n assert candidate(sentence = \"a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a\") == True\n assert candidate(sentence = \"Cycle elc yc\") == False\n assert candidate(sentence = \"algorithm nom alg\") == False\n assert candidate(sentence = \"Anna annA annA\") == False\n assert candidate(sentence = \"Twisted tales weave intricate stories\") == False\n assert candidate(sentence = \"civic civic civic\") == True\n assert candidate(sentence = \"Rotor rotor\") == False\n assert candidate(sentence = \"Zoology yggdrasill lloisgoy zoo\") == False\n assert candidate(sentence = \"coding ngoding going on\") == False\n assert candidate(sentence = \"repaid repaid\") == False\n assert candidate(sentence = \"Data analytics sscientist teach harsh\") == False\n assert candidate(sentence = \"AB BA CA\") == False\n assert candidate(sentence = \"Mamad Madam Damda\") == False\n assert candidate(sentence = \"abacabadabacaba\") == True\n", "comparison": "exact"}, "public_tests": ["\"leetcode exercises sound delightful\"", "\"eetcode\"", "\"Leetcode is cool\""], "hints": ["Check the character before the empty space and the character after the empty space.", "Check the first character and the last character of the sentence."], "metadata": {"canonical_parameter_names": ["sentence"], "leetcode_dataset_entry_point": "Solution().isCircularSentence", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:44+00:00", "tests_total": 220, "tests_dropped": 1, "flags": [], "topic_tags": ["string"]}, "language": "php", "interface": {"raw_signature": "function isCircularSentence($sentence) {", "container": "Solution", "callable": "isCircularSentence", "parameters": [{"name": "sentence", "type": "String"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2491, "task_id": "divide-players-into-teams-of-equal-skill", "difficulty": "Medium", "problem_description": "You are given a positive integer array skill of even length n where skill[i] denotes the skill of the i^th player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.\n\nThe chemistry of a team is equal to the product of the skills of the players on that team.\n\nReturn the sum of the chemistry of all the teams, or return -1 if there is no way to divide the players into teams such that the total skill of each team is equal.\n\nExample 1:\n\nInput: skill = [3,2,5,1,3,4]\nOutput: 22\nExplanation:\nDivide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6.\nThe sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.\n\nExample 2:\n\nInput: skill = [3,4]\nOutput: 12\nExplanation:\nThe two players form a team with a total skill of 7.\nThe chemistry of the team is 3 * 4 = 12.\n\nExample 3:\n\nInput: skill = [1,1,2,3]\nOutput: -1\nExplanation:\nThere is no way to divide the players into teams such that the total skill of each team is equal.\n\nConstraints:\n\n- 2 <= skill.length <= 10^5\n- skill.length is even.\n- 1 <= skill[i] <= 1000\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(skill = [1, 1000, 1, 1000, 1, 1000, 1, 1000]) == 4000\n assert candidate(skill = [1, 1, 2, 2, 3, 3, 4, 4]) == 20\n assert candidate(skill = [1, 1, 2, 3]) == -1\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8]) == 60\n assert candidate(skill = [5, 5, 5, 5, 5, 5]) == 75\n assert candidate(skill = [15, 15, 15, 15, 15, 15, 15, 15]) == 900\n assert candidate(skill = [3, 4]) == 12\n assert candidate(skill = [2, 3, 3, 2, 2, 3]) == 18\n assert candidate(skill = [4, 4, 4, 4]) == 32\n assert candidate(skill = [3, 2, 5, 1, 3, 4]) == 22\n assert candidate(skill = [10, 10, 10, 10]) == 200\n assert candidate(skill = [1000, 1000, 1, 1, 2, 2]) == -1\n assert candidate(skill = [1, 2, 3, 4, 5, 6]) == 28\n assert candidate(skill = [1, 2, 3, 3, 2, 1]) == 10\n assert candidate(skill = [1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 4000\n assert candidate(skill = [10, 20, 30, 40, 50, 60]) == 2800\n assert candidate(skill = [500, 500, 500, 500, 500, 500, 500, 500]) == 1000000\n assert candidate(skill = [1, 3, 5, 7, 9, 11]) == 73\n assert candidate(skill = [1000, 1, 999, 2, 500, 501]) == 253498\n assert candidate(skill = [500, 500, 1, 999, 2, 998, 3, 997]) == 255986\n assert candidate(skill = [1, 2, 3, 6, 4, 5]) == 28\n assert candidate(skill = [250, 750, 500, 500, 750, 250, 500, 500]) == 875000\n assert candidate(skill = [1, 1, 1, 1, 1, 1, 1, 1]) == 4\n assert candidate(skill = [1, 1000, 500, 500, 250, 750, 100, 900]) == -1\n assert candidate(skill = [100, 100, 200, 200, 300, 300, 400, 400, 500, 500]) == 350000\n assert candidate(skill = [1, 999, 2, 998, 3, 997, 4, 996, 5, 995, 6, 994, 7, 993, 8, 992, 9, 991, 10, 990]) == 54615\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 182\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 18200\n assert candidate(skill = [1, 999, 3, 997, 5, 995, 7, 993, 9, 991, 11, 989, 13, 987, 15, 985]) == 63320\n assert candidate(skill = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 512\n assert candidate(skill = [200, 300, 200, 300, 200, 300, 200, 300]) == 240000\n assert candidate(skill = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) == 728\n assert candidate(skill = [333, 667, 333, 667, 333, 667, 333, 667, 333, 667, 333, 667, 333, 667, 333, 667]) == 1776888\n assert candidate(skill = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 10\n assert candidate(skill = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 252\n assert candidate(skill = [1, 1000, 2, 999, 3, 998, 4, 997, 5, 996]) == 14960\n assert candidate(skill = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6]) == 20909\n assert candidate(skill = [10, 1, 5, 15, 7, 3, 9, 11]) == -1\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 11000\n assert candidate(skill = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) == 1512\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 40800\n assert candidate(skill = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 216\n assert candidate(skill = [2, 8, 3, 7, 4, 6, 5, 5]) == 86\n assert candidate(skill = [333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348]) == 927352\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 182\n assert candidate(skill = [23, 42, 31, 57, 5, 19, 6, 49, 12, 35, 29, 10, 50, 40, 21, 33]) == -1\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80]) == 6000\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 10, 20, 30, 40, 50, 60]) == 5600\n assert candidate(skill = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 5000\n assert candidate(skill = [8, 1, 8, 1, 8, 1, 8, 1]) == 32\n assert candidate(skill = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 100, 200]) == -1\n assert candidate(skill = [250, 250, 500, 500, 750, 750, 1000, 1000]) == 1250000\n assert candidate(skill = [300, 700, 200, 800, 100, 900, 400, 600, 500, 500]) == 950000\n assert candidate(skill = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 1250000\n assert candidate(skill = [2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 200\n assert candidate(skill = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 441\n assert candidate(skill = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 20000\n assert candidate(skill = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 6000\n assert candidate(skill = [123, 321, 213, 312, 132, 231, 213, 132]) == -1\n assert candidate(skill = [6, 3, 9, 2, 8, 4, 5, 7, 1, 10, 11, 12, 13, 14, 15, 16]) == 408\n assert candidate(skill = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]) == 3080\n assert candidate(skill = [8, 6, 4, 2, 10, 12, 14, 16, 18, 20]) == 440\n assert candidate(skill = [1, 1000, 2, 999, 3, 998, 4, 997]) == 9980\n assert candidate(skill = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 84\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 18200\n assert candidate(skill = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 110\n assert candidate(skill = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) == 84\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 770\n assert candidate(skill = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 1500000\n assert candidate(skill = [499, 501, 498, 502, 497, 503, 496, 504]) == 999970\n assert candidate(skill = [1, 3, 2, 4, 5, 7, 6, 8, 9, 11, 10, 12, 13, 15, 14, 16]) == 408\n assert candidate(skill = [999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1]) == 5994\n assert candidate(skill = [999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1]) == 7992\n assert candidate(skill = [5, 1, 4, 3, 2, 6]) == 28\n assert candidate(skill = [333, 333, 333, 333, 334, 334, 334, 334]) == 444888\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 770\n assert candidate(skill = [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250]) == 500000\n assert candidate(skill = [10, 10, 10, 10, 10, 10, 10, 10]) == 400\n assert candidate(skill = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 510\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 77000\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 11000\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 408\n assert candidate(skill = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 384\n assert candidate(skill = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 335\n assert candidate(skill = [999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1, 999, 1]) == 14985\n assert candidate(skill = [999, 1, 998, 2, 997, 3, 996, 4, 995, 5, 994, 6, 993, 7, 992, 8, 991, 9, 990, 10]) == 54615\n assert candidate(skill = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 150\n assert candidate(skill = [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250]) == 375000\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 280\n assert candidate(skill = [1, 999, 2, 998, 3, 997, 4, 996, 5, 995]) == 14945\n assert candidate(skill = [100, 200, 300, 400, 100, 200, 300, 400, 500, 600, 500, 600]) == 560000\n assert candidate(skill = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 110\n assert candidate(skill = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 490\n assert candidate(skill = [500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 2000000\n assert candidate(skill = [15, 16, 15, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 1820\n assert candidate(skill = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 600\n assert candidate(skill = [100, 200, 300, 400, 500, 600, 700, 800]) == 600000\n assert candidate(skill = [999, 1, 999, 1, 999, 1, 999, 1]) == 3996\n assert candidate(skill = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 110\n assert candidate(skill = [600, 400, 600, 400, 600, 400, 600, 400, 600, 400, 600, 400]) == 1440000\n assert candidate(skill = [1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000]) == 5000\n assert candidate(skill = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 150\n assert candidate(skill = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 288\n assert candidate(skill = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1]) == 8000\n assert candidate(skill = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 220\n assert candidate(skill = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 5\n assert candidate(skill = [1, 9, 1, 9, 1, 9, 1, 9]) == 36\n assert candidate(skill = [300, 700, 200, 800, 400, 600, 100, 900, 500, 500, 400, 600]) == 1190000\n assert candidate(skill = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 335\n assert candidate(skill = [150, 250, 150, 250, 150, 250, 150, 250, 150, 250]) == 187500\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 22000\n assert candidate(skill = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 200\n assert candidate(skill = [1000, 1, 999, 2, 998, 3, 997, 4]) == 9980\n assert candidate(skill = [8, 1, 5, 3, 4, 7, 2, 6, 9, 10, 12, 11]) == 182\n assert candidate(skill = [10, 1, 10, 1, 10, 1, 10, 1]) == 40\n assert candidate(skill = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 125\n assert candidate(skill = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 40800\n assert candidate(skill = [5, 5, 5, 5, 5, 5, 5, 5]) == 100\n assert candidate(skill = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 20000\n assert candidate(skill = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]) == 40\n assert candidate(skill = [250, 750, 250, 750, 250, 750, 250, 750, 250, 750, 250, 750, 250, 750, 250, 750]) == 1500000\n", "comparison": "exact"}, "public_tests": ["[3,2,5,1,3,4]", "[3,4]", "[1,1,2,3]"], "hints": ["Try sorting the skill array.", "It is always optimal to pair the weakest available player with the strongest available player."], "metadata": {"canonical_parameter_names": ["skill"], "leetcode_dataset_entry_point": "Solution().dividePlayers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:46+00:00", "tests_total": 122, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "two-pointers", "sorting"]}, "language": "php", "interface": {"raw_signature": "function dividePlayers($skill) {", "container": "Solution", "callable": "dividePlayers", "parameters": [{"name": "skill", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2492, "task_id": "minimum-score-of-a-path-between-two-cities", "difficulty": "Medium", "problem_description": "You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [a_i, b_i, distance_i] indicates that there is a bidirectional road between cities a_i and b_i with a distance equal to distance_i. The cities graph is not necessarily connected.\n\nThe score of a path between two cities is defined as the minimum distance of a road in this path.\n\nReturn the minimum possible score of a path between cities 1 and n.\n\nNote:\n\n- A path is a sequence of roads between two cities.\n- It is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.\n- The test cases are generated such that there is at least one path between 1 and n.\n\nExample 1:\n\nInput: n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]\nOutput: 5\nExplanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5.\nIt can be shown that no other path has less score.\n\nExample 2:\n\nInput: n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]]\nOutput: 2\nExplanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2.\n\nConstraints:\n\n- 2 <= n <= 10^5\n- 1 <= roads.length <= 10^5\n- roads[i].length == 3\n- 1 <= a_i, b_i <= n\n- a_i != b_i\n- 1 <= distance_i <= 10^4\n- There are no repeated edges.\n- There is at least one path between 1 and n.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,roads = [[1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [1, 5, 30]]) == 10\n assert candidate(n = 6,roads = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5]]) == 1\n assert candidate(n = 4,roads = [[1, 2, 2], [1, 3, 4], [3, 4, 7]]) == 2\n assert candidate(n = 5,roads = [[1, 2, 10], [2, 3, 5], [3, 4, 2], [4, 5, 1]]) == 1\n assert candidate(n = 3,roads = [[1, 2, 5], [2, 3, 10], [1, 3, 7]]) == 5\n assert candidate(n = 6,roads = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [1, 6, 1]]) == 1\n assert candidate(n = 3,roads = [[1, 2, 1], [2, 3, 2], [1, 3, 3]]) == 1\n assert candidate(n = 4,roads = [[1, 2, 9], [2, 3, 6], [2, 4, 5], [1, 4, 7]]) == 5\n assert candidate(n = 3,roads = [[1, 2, 3], [2, 3, 1]]) == 1\n assert candidate(n = 5,roads = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1], [1, 5, 2]]) == 1\n assert candidate(n = 6,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [1, 6, 60]]) == 10\n assert candidate(n = 9,roads = [[1, 2, 2], [2, 3, 4], [3, 4, 6], [4, 5, 8], [5, 6, 10], [6, 7, 12], [7, 8, 14], [8, 9, 16], [1, 9, 18], [2, 8, 20], [3, 7, 22], [4, 6, 24], [5, 9, 26], [1, 5, 28], [2, 6, 30], [3, 9, 32], [1, 7, 34], [2, 9, 36], [1, 4, 38], [1, 3, 40], [1, 6, 42]]) == 2\n assert candidate(n = 7,roads = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 6], [7, 1, 7], [2, 5, 8], [3, 6, 9]]) == 1\n assert candidate(n = 9,roads = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [7, 8, 7], [8, 9, 8], [1, 3, 2], [3, 5, 3], [5, 7, 4], [7, 9, 5]]) == 1\n assert candidate(n = 15,roads = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900], [10, 11, 1000], [11, 12, 1100], [12, 13, 1200], [13, 14, 1300], [14, 15, 1400], [1, 15, 50]]) == 50\n assert candidate(n = 10,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [1, 5, 15], [5, 9, 25]]) == 10\n assert candidate(n = 7,roads = [[1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 5, 5], [5, 6, 5], [6, 7, 5], [1, 3, 5], [3, 5, 5], [5, 7, 5], [1, 4, 5], [4, 6, 5], [2, 4, 5], [3, 6, 5], [1, 6, 5], [2, 5, 5], [3, 7, 5]]) == 5\n assert candidate(n = 20,roads = [[1, 2, 20], [1, 3, 19], [2, 3, 18], [2, 4, 17], [3, 5, 16], [4, 5, 15], [5, 6, 14], [6, 7, 13], [7, 8, 12], [8, 9, 11], [9, 10, 10], [10, 11, 9], [11, 12, 8], [12, 13, 7], [13, 14, 6], [14, 15, 5], [15, 16, 4], [16, 17, 3], [17, 18, 2], [18, 19, 1], [19, 20, 20]]) == 1\n assert candidate(n = 10,roads = [[1, 2, 10], [1, 3, 5], [2, 4, 1], [2, 5, 8], [3, 6, 3], [4, 7, 2], [5, 8, 4], [6, 9, 6], [7, 10, 7], [8, 10, 9], [1, 10, 12]]) == 1\n assert candidate(n = 6,roads = [[1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 1, 1], [2, 6, 10]]) == 1\n assert candidate(n = 12,roads = [[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], [1, 12, 1], [2, 10, 2], [4, 11, 3]]) == 1\n assert candidate(n = 15,roads = [[1, 2, 2], [2, 3, 4], [3, 4, 5], [4, 5, 1], [1, 5, 2], [5, 6, 3], [6, 7, 4], [7, 8, 5], [8, 9, 6], [9, 10, 7], [10, 11, 8], [11, 12, 9], [12, 13, 10], [13, 14, 11], [14, 15, 12]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [7, 8, 8], [8, 1, 9], [1, 3, 10], [2, 4, 11], [3, 5, 12], [4, 6, 13], [5, 7, 14], [6, 8, 15], [1, 4, 16], [2, 5, 17], [3, 6, 18], [4, 7, 19], [5, 8, 20], [1, 5, 21], [2, 6, 22], [3, 7, 23], [4, 8, 24]]) == 2\n assert candidate(n = 15,roads = [[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], [1, 15, 15]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 100], [2, 3, 101], [3, 4, 102], [4, 5, 103], [5, 6, 104], [6, 7, 105], [7, 8, 106], [8, 1, 1], [2, 8, 200], [3, 7, 300]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 6], [7, 8, 7], [1, 8, 10], [2, 7, 8], [3, 6, 9], [4, 5, 11]]) == 1\n assert candidate(n = 6,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [1, 6, 5]]) == 5\n assert candidate(n = 6,roads = [[1, 3, 10], [1, 4, 20], [3, 4, 15], [4, 6, 30], [6, 5, 25], [5, 2, 5]]) == 5\n assert candidate(n = 7,roads = [[1, 2, 10], [2, 3, 10], [3, 4, 10], [4, 5, 10], [5, 6, 10], [6, 7, 10], [1, 7, 5], [1, 3, 5], [3, 5, 5], [5, 7, 5]]) == 5\n assert candidate(n = 8,roads = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 1, 800], [1, 4, 150], [2, 5, 250], [3, 6, 350], [4, 7, 450], [5, 8, 550], [6, 1, 650], [7, 2, 750], [8, 3, 850]]) == 100\n assert candidate(n = 10,roads = [[1, 2, 5], [2, 3, 3], [3, 4, 7], [4, 5, 2], [5, 6, 6], [6, 7, 8], [7, 8, 4], [8, 9, 9], [9, 10, 1], [1, 10, 11], [2, 4, 12], [3, 5, 13], [4, 6, 14], [5, 7, 15], [6, 8, 16], [7, 9, 17], [8, 10, 18], [9, 1, 19], [10, 2, 20]]) == 1\n assert candidate(n = 5,roads = [[1, 2, 1000], [2, 3, 999], [3, 4, 998], [4, 5, 997], [1, 3, 996], [2, 4, 995], [3, 5, 994], [1, 4, 993], [2, 5, 992], [1, 5, 991]]) == 991\n assert candidate(n = 7,roads = [[1, 2, 2], [2, 3, 5], [3, 4, 7], [4, 5, 3], [5, 6, 8], [6, 7, 1], [1, 7, 6], [2, 6, 4], [3, 5, 9], [1, 5, 10]]) == 1\n assert candidate(n = 15,roads = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [6, 7, 5], [7, 8, 8], [8, 9, 9], [9, 10, 10], [10, 11, 11], [11, 12, 12], [12, 13, 13], [13, 14, 14], [14, 15, 15], [1, 15, 20]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 50], [2, 3, 40], [3, 4, 30], [4, 5, 20], [5, 6, 10], [6, 7, 5], [7, 8, 1], [8, 1, 30], [2, 4, 25], [4, 6, 15], [6, 8, 5]]) == 1\n assert candidate(n = 10,roads = [[1, 2, 5], [1, 3, 2], [2, 4, 3], [3, 4, 1], [4, 5, 6], [5, 6, 4], [6, 7, 9], [7, 8, 8], [8, 9, 7], [9, 10, 10]]) == 1\n assert candidate(n = 10,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [1, 5, 15], [2, 6, 25], [3, 7, 35], [4, 8, 45]]) == 10\n assert candidate(n = 8,roads = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [7, 8, 7], [8, 1, 8], [1, 3, 9], [2, 4, 10], [3, 5, 11], [4, 6, 12], [5, 7, 13], [6, 8, 14]]) == 1\n assert candidate(n = 9,roads = [[1, 2, 15], [1, 4, 10], [2, 3, 5], [2, 5, 3], [3, 6, 7], [4, 5, 2], [4, 7, 6], [5, 8, 4], [6, 9, 8], [7, 8, 1], [8, 9, 9]]) == 1\n assert candidate(n = 6,roads = [[1, 2, 5], [2, 3, 4], [3, 4, 3], [4, 5, 2], [5, 6, 1], [1, 6, 6], [1, 3, 7], [2, 4, 8], [3, 5, 9]]) == 1\n assert candidate(n = 7,roads = [[1, 2, 7], [1, 3, 15], [2, 3, 6], [2, 4, 9], [3, 5, 12], [4, 5, 10], [4, 6, 11], [5, 6, 8], [5, 7, 3], [6, 7, 2]]) == 2\n assert candidate(n = 7,roads = [[1, 2, 1], [2, 3, 2], [3, 4, 3], [4, 5, 4], [5, 6, 5], [6, 7, 6], [1, 7, 7], [2, 4, 8], [3, 5, 9]]) == 1\n assert candidate(n = 7,roads = [[1, 2, 5], [2, 3, 4], [3, 4, 6], [4, 5, 3], [5, 6, 2], [6, 7, 8], [1, 7, 7]]) == 2\n assert candidate(n = 20,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [12, 13, 120], [13, 14, 130], [14, 15, 140], [15, 16, 150], [16, 17, 160], [17, 18, 170], [18, 19, 180], [19, 20, 190], [1, 20, 5]]) == 5\n assert candidate(n = 6,roads = [[1, 2, 5], [2, 3, 2], [3, 4, 8], [4, 5, 3], [5, 6, 1], [1, 6, 4]]) == 1\n assert candidate(n = 9,roads = [[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, 3, 10], [2, 4, 11], [3, 5, 12], [4, 6, 13], [5, 7, 14], [6, 8, 15], [7, 9, 16], [8, 1, 17], [9, 2, 18]]) == 1\n assert candidate(n = 10,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [1, 10, 5]]) == 5\n assert candidate(n = 6,roads = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [1, 6, 150], [1, 4, 250], [3, 6, 350], [2, 5, 450]]) == 100\n assert candidate(n = 8,roads = [[1, 2, 6], [2, 3, 3], [3, 4, 9], [4, 5, 4], [5, 6, 5], [6, 7, 2], [7, 8, 7], [8, 1, 8]]) == 2\n assert candidate(n = 10,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [1, 10, 1]]) == 1\n assert candidate(n = 10,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90]]) == 10\n assert candidate(n = 12,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [8, 9, 80], [9, 10, 90], [10, 11, 100], [11, 12, 110], [1, 12, 5]]) == 5\n assert candidate(n = 6,roads = [[1, 2, 5], [2, 3, 3], [3, 4, 7], [4, 5, 2], [5, 6, 4], [6, 1, 6], [1, 3, 10], [2, 4, 1], [3, 5, 8], [4, 6, 9], [5, 1, 7], [6, 2, 11]]) == 1\n assert candidate(n = 15,roads = [[1, 2, 10], [2, 3, 5], [3, 4, 6], [4, 5, 7], [5, 6, 8], [6, 7, 9], [7, 8, 1], [8, 9, 2], [9, 10, 3], [10, 11, 4], [11, 12, 11], [12, 13, 12], [13, 14, 13], [14, 15, 14], [15, 1, 15]]) == 1\n assert candidate(n = 7,roads = [[1, 2, 4], [2, 3, 3], [3, 4, 2], [4, 5, 1], [5, 6, 1], [6, 7, 2], [1, 7, 5], [2, 7, 6], [3, 7, 7]]) == 1\n assert candidate(n = 12,roads = [[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, 1, 12], [1, 3, 3], [3, 5, 5], [5, 7, 7], [7, 9, 9], [9, 11, 11], [2, 4, 4], [4, 6, 6], [6, 8, 8], [8, 10, 10], [10, 12, 12]]) == 1\n assert candidate(n = 6,roads = [[1, 2, 100], [1, 3, 200], [2, 4, 300], [3, 5, 400], [4, 5, 500], [5, 6, 600], [2, 6, 700], [1, 4, 800], [3, 6, 900]]) == 100\n assert candidate(n = 15,roads = [[1, 2, 10], [2, 3, 15], [3, 4, 20], [4, 5, 25], [5, 6, 30], [6, 7, 35], [7, 8, 40], [8, 9, 45], [9, 10, 50], [10, 11, 55], [11, 12, 60], [12, 13, 65], [13, 14, 70], [14, 15, 75], [15, 1, 80], [1, 3, 85], [3, 5, 90], [5, 7, 95], [7, 9, 100], [9, 11, 105], [11, 13, 110], [13, 15, 115], [2, 4, 120], [4, 6, 125], [6, 8, 130], [8, 10, 135], [10, 12, 140], [12, 14, 145], [14, 2, 150], [1, 4, 155], [4, 7, 160], [7, 10, 165], [10, 13, 170], [13, 1, 175], [2, 5, 180], [5, 8, 185], [8, 11, 190], [11, 14, 195], [14, 1, 200]]) == 10\n assert candidate(n = 10,roads = [[1, 2, 10], [1, 3, 9], [2, 4, 8], [2, 5, 7], [3, 5, 6], [4, 6, 5], [5, 6, 4], [6, 7, 3], [7, 8, 2], [8, 9, 1], [9, 10, 1]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 10], [2, 3, 20], [3, 4, 30], [4, 5, 40], [5, 6, 50], [6, 7, 60], [7, 8, 70], [1, 8, 80], [2, 5, 90], [3, 6, 100], [4, 7, 110]]) == 10\n assert candidate(n = 10,roads = [[1, 2, 9], [2, 3, 6], [3, 4, 5], [4, 5, 7], [5, 6, 8], [6, 7, 4], [7, 8, 2], [8, 9, 1], [9, 10, 3], [10, 1, 10]]) == 1\n assert candidate(n = 20,roads = [[1, 2, 20], [2, 3, 19], [3, 4, 18], [4, 5, 17], [5, 6, 16], [6, 7, 15], [7, 8, 14], [8, 9, 13], [9, 10, 12], [10, 11, 11], [11, 12, 10], [12, 13, 9], [13, 14, 8], [14, 15, 7], [15, 16, 6], [16, 17, 5], [17, 18, 4], [18, 19, 3], [19, 20, 2], [20, 1, 1]]) == 1\n assert candidate(n = 8,roads = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1], [5, 6, 2], [6, 7, 6], [7, 8, 5], [8, 1, 7]]) == 1\n assert candidate(n = 20,roads = [[1, 2, 100], [2, 3, 200], [3, 4, 300], [4, 5, 400], [5, 6, 500], [6, 7, 600], [7, 8, 700], [8, 9, 800], [9, 10, 900], [10, 11, 1000], [11, 12, 1100], [12, 13, 1200], [13, 14, 1300], [14, 15, 1400], [15, 16, 1500], [16, 17, 1600], [17, 18, 1700], [18, 19, 1800], [19, 20, 1900], [20, 1, 2000], [1, 3, 2100], [3, 5, 2200], [5, 7, 2300], [7, 9, 2400], [9, 11, 2500], [11, 13, 2600], [13, 15, 2700], [15, 17, 2800], [17, 19, 2900], [19, 1, 3000], [2, 4, 3100], [4, 6, 3200], [6, 8, 3300], [8, 10, 3400], [10, 12, 3500], [12, 14, 3600], [14, 16, 3700], [16, 18, 3800], [18, 20, 3900], [1, 4, 4000], [4, 7, 4100], [7, 10, 4200], [10, 13, 4300], [13, 16, 4400], [16, 19, 4500], [19, 2, 4600], [2, 5, 4700], [5, 8, 4800], [8, 11, 4900], [11, 14, 5000], [14, 17, 5100], [17, 20, 5200], [20, 1, 5300]]) == 100\n assert candidate(n = 15,roads = [[1, 2, 15], [2, 3, 14], [3, 4, 13], [4, 5, 12], [5, 6, 11], [6, 7, 10], [7, 8, 9], [8, 9, 8], [9, 10, 7], [10, 11, 6], [11, 12, 5], [12, 13, 4], [13, 14, 3], [14, 15, 2], [1, 15, 1], [2, 14, 16], [3, 13, 17], [4, 12, 18], [5, 11, 19], [6, 10, 20], [7, 9, 21]]) == 1\n", "comparison": "exact"}, "public_tests": ["4\n[[1,2,9],[2,3,6],[2,4,5],[1,4,7]]", "4\n[[1,2,2],[1,3,4],[3,4,7]]"], "hints": ["Can you solve the problem if the whole graph is connected?", "Notice that if the graph is connected, you can always use any edge of the graph in your path.", "How to solve the general problem in a similar way? Remove all the nodes that are not connected to 1 and n, then apply the previous solution in the new graph."], "metadata": {"canonical_parameter_names": ["n", "roads"], "leetcode_dataset_entry_point": "Solution().minScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:48+00:00", "tests_total": 65, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "union-find", "graph"]}, "language": "php", "interface": {"raw_signature": "function minScore($n, $roads) {", "container": "Solution", "callable": "minScore", "parameters": [{"name": "n", "type": "Integer"}, {"name": "roads", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2493, "task_id": "divide-nodes-into-the-maximum-number-of-groups", "difficulty": "Hard", "problem_description": "You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.\n\nYou are also given a 2D integer array edges, where edges[i] = [a_i,b_i] indicates that there is a bidirectional edge between nodes a_i and b_i. Notice that the given graph may be disconnected.\n\nDivide the nodes of the graph into m groups (1-indexed) such that:\n\n- Each node in the graph belongs to exactly one group.\n- For every pair of nodes in the graph that are connected by an edge [a_i,b_i], if a_i belongs to the group with index x, and b_i belongs to the group with index y, then |y - x| = 1.\n\nReturn the maximum number of groups (i.e., maximum m) into which you can divide the nodes. Return -1 if it is impossible to group the nodes with the given conditions.\n\nExample 1:\n\nInput: n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]\nOutput: 4\nExplanation: As shown in the image we:\n- Add node 5 to the first group.\n- Add node 1 to the second group.\n- Add nodes 2 and 4 to the third group.\n- Add nodes 3 and 6 to the fourth group.\nWe can see that every edge is satisfied.\nIt can be shown that that if we create a fifth group and move any node from the third or fourth group to it, at least on of the edges will not be satisfied.\n\nExample 2:\n\nInput: n = 3, edges = [[1,2],[2,3],[3,1]]\nOutput: -1\nExplanation: If we add node 1 to the first group, node 2 to the second group, and node 3 to the third group to satisfy the first two edges, we can see that the third edge will not be satisfied.\nIt can be shown that no grouping is possible.\n\nConstraints:\n\n- 1 <= n <= 500\n- 1 <= edges.length <= 10^4\n- edges[i].length == 2\n- 1 <= a_i, b_i <= n\n- a_i != b_i\n- There is at most one edge between any pair of vertices.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 1], [4, 5]]) == -1\n assert candidate(n = 4,edges = [[1, 2], [3, 4]]) == 4\n assert candidate(n = 6,edges = [[1, 2], [1, 4], [1, 5], [2, 6], [2, 3], [4, 6]]) == 4\n assert candidate(n = 3,edges = [[1, 2], [2, 3], [3, 1]]) == -1\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5]]) == 5\n assert candidate(n = 7,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == 7\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]) == -1\n assert candidate(n = 4,edges = [[1, 2]]) == 4\n assert candidate(n = 4,edges = [[1, 2], [2, 3], [3, 4], [4, 1]]) == 3\n assert candidate(n = 7,edges = [[1, 2], [2, 3], [4, 5], [5, 6], [6, 7]]) == 7\n assert candidate(n = 4,edges = [[1, 2], [2, 3]]) == 4\n assert candidate(n = 5,edges = [[1, 2], [1, 3], [1, 4], [1, 5]]) == 3\n assert candidate(n = 5,edges = [[1, 2], [3, 4]]) == 5\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10]]) == -1\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [1, 10]]) == 8\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [1, 6], [10, 11]]) == -1\n assert candidate(n = 50,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [26, 27], [27, 28], [28, 29], [29, 30], [30, 26], [31, 32], [32, 33], [33, 34], [34, 35], [35, 31], [36, 37], [37, 38], [38, 39], [39, 40], [40, 36], [41, 42], [42, 43], [43, 44], [44, 45], [45, 41], [46, 47], [47, 48], [48, 49], [49, 50], [50, 46]]) == -1\n assert candidate(n = 18,edges = [[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, 1], [1, 10], [10, 18]]) == -1\n assert candidate(n = 16,edges = [[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]]) == 16\n assert candidate(n = 25,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21]]) == -1\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 7], [13, 14], [14, 15], [15, 13]]) == -1\n assert candidate(n = 25,edges = [[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, 21], [20, 22], [21, 23], [22, 24], [23, 25]]) == 25\n assert candidate(n = 15,edges = [[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], [1, 15]]) == -1\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [26, 27], [27, 28], [28, 29], [29, 30], [30, 26], [1, 6], [11, 16], [21, 26]]) == -1\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 8], [8, 5], [1, 5], [2, 6], [3, 7], [4, 8]]) == 4\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == 10\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12]]) == 12\n assert candidate(n = 16,edges = [[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\n assert candidate(n = 20,edges = [[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]]) == 11\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 5]]) == 7\n assert candidate(n = 15,edges = [[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(n = 6,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [1, 3], [2, 4], [3, 5], [4, 6], [5, 1], [6, 2]]) == -1\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 5], [5, 6], [6, 7], [7, 8]]) == -1\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [6, 7], [7, 8], [8, 9], [9, 10]]) == 10\n assert candidate(n = 20,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16]]) == -1\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [26, 27], [27, 28], [28, 29], [29, 30], [30, 26]]) == -1\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1]]) == 6\n assert candidate(n = 30,edges = [[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\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 1], [8, 2]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == 10\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 6]]) == -1\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [1, 9], [2, 8], [3, 7], [4, 6]]) == -1\n assert candidate(n = 20,edges = [[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(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 13], [13, 10], [14, 15], [15, 14]]) == -1\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 6], [13, 14], [14, 15]]) == -1\n assert candidate(n = 10,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == 10\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 7]]) == 8\n assert candidate(n = 20,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 20\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 1]]) == 7\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [11, 12], [12, 13], [13, 14], [14, 15], [1, 11], [5, 15]]) == 11\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10], [5, 11], [6, 12]]) == 6\n assert candidate(n = 10,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [2, 3], [4, 5], [6, 7], [8, 9]]) == 10\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 11], [10, 12], [11, 12]]) == 7\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8], [6, 8], [7, 8]]) == 4\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11]]) == -1\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10]]) == 8\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7]]) == -1\n assert candidate(n = 40,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [26, 27], [27, 28], [28, 29], [29, 30], [30, 26], [31, 32], [32, 33], [33, 34], [34, 35], [35, 31], [36, 37], [37, 38], [38, 39], [39, 40], [40, 36]]) == -1\n assert candidate(n = 16,edges = [[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, 1]]) == 9\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10]]) == 6\n assert candidate(n = 18,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 13], [13, 10], [14, 15], [15, 16], [16, 17], [17, 14], [18, 1]]) == -1\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8]]) == -1\n assert candidate(n = 25,edges = [[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, 1]]) == -1\n assert candidate(n = 15,edges = [[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], [1, 15]]) == 12\n assert candidate(n = 20,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [1, 6], [11, 16]]) == -1\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15]]) == 8\n assert candidate(n = 20,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 7], [13, 14], [14, 15], [15, 16], [16, 13], [17, 18], [18, 19], [19, 20], [20, 17]]) == 14\n assert candidate(n = 25,edges = [[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, 1], [1, 11], [10, 18], [15, 25]]) == -1\n assert candidate(n = 22,edges = [[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, 1]]) == 12\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [1, 12]]) == 7\n assert candidate(n = 18,edges = [[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]]) == 18\n assert candidate(n = 20,edges = [[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, 20], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12]]) == 11\n assert candidate(n = 30,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21], [26, 27], [27, 28], [28, 29], [29, 30], [30, 26]]) == -1\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 6]]) == -1\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == 9\n assert candidate(n = 20,edges = [[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], [1, 11]]) == -1\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]]) == 5\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == 6\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 8], [8, 9], [9, 5]]) == -1\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13], [1, 4], [2, 5], [3, 6], [7, 10], [8, 11], [9, 12]]) == -1\n assert candidate(n = 30,edges = [[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, 1]]) == 16\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10], [9, 2]]) == 8\n assert candidate(n = 18,edges = [[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], [1, 18]]) == 10\n", "comparison": "exact"}, "public_tests": ["6\n[[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]", "3\n[[1,2],[2,3],[3,1]]"], "hints": ["If the graph is not bipartite, it is not possible to group the nodes.", "Notice that we can solve the problem for each connected component independently, and the final answer will be just the sum of the maximum number of groups in each component.", "Finally, to solve the problem for each connected component, we can notice that if for some node v we fix its position to be in the leftmost group, then we can also evaluate the position of every other node. That position is the depth of the node in a bfs tree after rooting at node v."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().magnificentSets", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:50+00:00", "tests_total": 83, "tests_dropped": 0, "flags": ["figure_reference", "has_images"], "topic_tags": ["depth-first-search", "breadth-first-search", "union-find", "graph"]}, "language": "php", "interface": {"raw_signature": "function magnificentSets($n, $edges) {", "container": "Solution", "callable": "magnificentSets", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2496, "task_id": "maximum-value-of-a-string-in-an-array", "difficulty": "Easy", "problem_description": "The value of an alphanumeric string can be defined as:\n\n- The numeric representation of the string in base 10, if it comprises of digits only.\n- The length of the string, otherwise.\n\nGiven an array strs of alphanumeric strings, return the maximum value of any string in strs.\n\nExample 1:\n\nInput: strs = [\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]\nOutput: 5\nExplanation:\n- \"alic3\" consists of both letters and digits, so its value is its length, i.e. 5.\n- \"bob\" consists only of letters, so its value is also its length, i.e. 3.\n- \"3\" consists only of digits, so its value is its numeric equivalent, i.e. 3.\n- \"4\" also consists only of digits, so its value is 4.\n- \"00000\" consists only of digits, so its value is 0.\nHence, the maximum value is 5, of \"alic3\".\n\nExample 2:\n\nInput: strs = [\"1\",\"01\",\"001\",\"0001\"]\nOutput: 1\nExplanation:\nEach string in the array has value 1. Hence, we return 1.\n\nConstraints:\n\n- 1 <= strs.length <= 100\n- 1 <= strs[i].length <= 9\n- strs[i] consists of only lowercase English letters and digits.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(strs = ['xyz', 'xyzz', 'xyzzz', 'xyzzzz']) == 6\n assert candidate(strs = ['a1', 'b2', 'c3', '1a', '2b', '3c']) == 2\n assert candidate(strs = ['abc', '123', 'a1b2c3', '000']) == 123\n assert candidate(strs = ['123456789', '987654321', '111111111', '222222222', '333333333']) == 987654321\n assert candidate(strs = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 1\n assert candidate(strs = ['alic3', 'bob', '3', '4', '00000']) == 5\n assert candidate(strs = ['abc', '123', 'abcd', '4567', '89']) == 4567\n assert candidate(strs = ['a', 'b', 'c', '1', '2', '3', '10', '11', '12']) == 12\n assert candidate(strs = ['987654321', 'abcdefg', 'hijklmn', '000000000']) == 987654321\n assert candidate(strs = ['987', '654', '321', '0', 'abcdefg']) == 987\n assert candidate(strs = ['1', '01', '001', '0001']) == 1\n assert candidate(strs = ['abc', '123', 'a1b2', '11111', 'zzzzz']) == 11111\n assert candidate(strs = ['hello', 'world', 'python', 'code']) == 6\n assert candidate(strs = ['111', '222', '333', '4444']) == 4444\n assert candidate(strs = ['000', '0000', '00000', '000000', '0000000']) == 0\n assert candidate(strs = ['98765', '4321', '11111', '222']) == 98765\n assert candidate(strs = ['abc', '123', 'def456', '7890']) == 7890\n assert candidate(strs = ['abc', '123', 'a1b2c3', '111111111']) == 111111111\n assert candidate(strs = ['a', 'b', 'c', 'd']) == 1\n assert candidate(strs = ['99999', '88888', '77777', '66666', '55555', '44444', '33333', '22222', '11111', '00000']) == 99999\n assert candidate(strs = ['1', '01', '001', '0001', '00001', '000001', '0000001', '00000001', '000000001']) == 1\n assert candidate(strs = ['123', '456', '789', 'abc', 'def', 'ghi', '1', '2', '3', '4', '5', '6', '7', '8', '9']) == 789\n assert candidate(strs = ['987654321', '123456789', 'abcdefghi', 'jklmnopqr', '000000000', '111111111', '222222222']) == 987654321\n assert candidate(strs = ['a1b2c3d4e', '111111111', 'fgh', '5678', 'ijklmno']) == 111111111\n assert candidate(strs = ['987', '654', '321', '000', '00', '0', 'abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yz123']) == 987\n assert candidate(strs = ['abc', 'defg', 'hijkl', 'mnopqr', 'stuvwx', 'yz123', '456789', '000000000']) == 456789\n assert candidate(strs = ['0', '00', '000', '0000', '00000', '1', '01', '001', '0001']) == 1\n assert candidate(strs = ['a1', 'b2', 'c3', 'd4', 'e5', 'f6', 'g7', 'h8', 'i9', 'j10', 'k11', 'l12', 'm13', 'n14', 'o15']) == 3\n assert candidate(strs = ['abcdefg', 'hijklmn', '0000000', '1234567', '890', 'opqrstu', 'vwxyz', '98765', '43210', '00001']) == 1234567\n assert candidate(strs = ['123abc', '456def', '789ghi', '0', '1', '2', '3', '4', '5']) == 6\n assert candidate(strs = ['a1', 'b2', 'c3', 'd4', 'e5', 'f6', 'g7', 'h8', 'i9', 'j0']) == 2\n assert candidate(strs = ['a1', 'b2', 'c3', 'd4', 'e5', 'f6', 'g7', 'h8', 'i9', 'j0', 'a1b2', 'c3d4', 'e5f6', 'g7h8', 'i9j0']) == 4\n assert candidate(strs = ['a1', 'b2', 'c3', 'd4', 'e5', 'f6', 'g7', 'h8', 'i9', 'j0']) == 2\n assert candidate(strs = ['a', '1', 'ab', '12', 'abc', '123', 'abcd', '1234', 'abcde', '12345']) == 12345\n assert candidate(strs = ['abc123', '456', 'def', '7890', 'ghi789']) == 7890\n assert candidate(strs = ['123', 'abc1', '234', 'bcd2', '345', 'cde3', '456', 'def4', '567', 'efg5']) == 567\n assert candidate(strs = ['abc123', 'def', 'ghi', '4567', '89', '0', 'abcdefg', 'hijklmn']) == 4567\n assert candidate(strs = ['abc123', '123abc', 'abc1', 'a1b2c3', '123456789']) == 123456789\n assert candidate(strs = ['123abc', '456def', '789ghi', 'abc123def', '456ghi789', '000abc123', '123456789', 'abcdef000']) == 123456789\n assert candidate(strs = ['a1', 'b2', 'c3', '1a', '2b', '3c', '10a', '20b', '30c']) == 3\n assert candidate(strs = ['abc123', 'def456', 'ghi789', 'jkl012', 'mno345', 'pqr678', 'stu901', 'vwx234', 'yz567', '0abc', '1def', '2ghi', '3jkl', '4mno', '5pqr', '6stu', '7vwx', '8yz', '9abc']) == 6\n assert candidate(strs = ['00001', '00002', '00003', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']) == 10\n assert candidate(strs = ['zzzzz', '00000', '11111', '22222', '33333', '44444']) == 44444\n assert candidate(strs = ['abcdefg', 'hijklmn', 'opqrstu', 'vwxyz', '0123456', '7890123', '4567890', '1234567', '8901234', '5678901']) == 8901234\n assert candidate(strs = ['abcdef', 'ghijkl', 'mnopqr', 'stuvwx', 'yz', '123456', '789012', '345678', '901234', '567890']) == 901234\n assert candidate(strs = ['1a', '2b', '3c', '4d', '5e', '6f', '7g', '8h', '9i', '0j']) == 2\n assert candidate(strs = ['0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '1', '2', '3', '4', '5', '6', '7', '8', '9']) == 9\n assert candidate(strs = ['00000000', '00000001', '00000010', '00000100', '00001000', '00010000', '00100000', '01000000', '10000000']) == 10000000\n assert candidate(strs = ['1234567', 'abcdefg', '7654321', 'gfedcba', '123abc', 'abc123', 'abc123abc', '123abc123', 'abc', '123', '1', 'a', '000', '999']) == 7654321\n assert candidate(strs = ['abcde123', '123abcde', 'abcd1234', '1234abcd', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '00000000']) == 99999999\n assert candidate(strs = ['00001', '00010', '00100', '01000', '10000', 'abcde', 'fghij', 'klmno', 'pqrst']) == 10000\n assert candidate(strs = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yz01', '2345', '6789', '0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999']) == 9999\n assert candidate(strs = ['abc123', 'def', 'ghi456', '789', '012345678']) == 12345678\n assert candidate(strs = ['a1b', 'b2c', 'c3d', 'd4e', 'e5f', 'f6g', 'g7h', 'h8i', 'i9j', 'j0a', '1a2', '2b3', '3c4', '4d5', '5e6', '6f7', '7g8', '8h9', '9i0', '0j1']) == 3\n assert candidate(strs = ['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']) == 1\n assert candidate(strs = ['123', 'abc', '456', 'def', '789', 'ghi', '12', 'ab', '34', 'cd', '56', 'ef', '78', 'gh', '90', 'ij']) == 789\n assert candidate(strs = ['abc123', 'def456', '789', 'ghi', '012', 'jklmno789']) == 789\n assert candidate(strs = ['abcd123', 'efgh456', 'ijkl789', 'mnop000', 'qrst111', 'uvwx222', 'yz333', '444abc', '555def', '666ghi']) == 7\n assert candidate(strs = ['zzzzz', '99999', 'abcd', '00000', '123456789']) == 123456789\n assert candidate(strs = ['a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi']) == 9\n assert candidate(strs = ['zzzz', 'aaaa', '123456789', 'abcdefghi', '000000000', '987654321']) == 987654321\n assert candidate(strs = ['987654321', 'abcdefghi', '123abc', '0', 'mnopqrstu']) == 987654321\n assert candidate(strs = ['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', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 30\n assert candidate(strs = ['999', '888', '777', '666', '555', '444', '333', '222', '111', '000']) == 999\n assert candidate(strs = ['abc1', 'def2', 'ghi3', '4', '5', '6', '7', '8', '9', '000000000', 'zzzzzzzzz', '111111111', '222222222', '333333333', '444444444', '555555555', '666666666', '777777777', '888888888', '999999999']) == 999999999\n assert candidate(strs = ['123abc456', 'abc123def', '456def123', 'abcdef', '123456', '654321', 'abcdefg', 'hijklmn', 'opqrstu', '456789', '012345', '6543210', '0000000', '9999999', 'abcdef1', '1abcdef', 'a1b2c3d', 'd3c2b1a', '123456789', '987654321']) == 987654321\n assert candidate(strs = ['abcd', '1234', 'efgh', '5678', 'ijkl', '9012', 'mnop', '3456', 'qrst', '7890']) == 9012\n assert candidate(strs = ['abc123', 'def456', 'ghi789', '123456', '123456789']) == 123456789\n assert candidate(strs = ['zzz', '999', 'zzz999', '999zzz', 'zzz99', '99zzz', 'zz99', '99zz', 'z9', '9z', 'z', '9', '000000', '111111']) == 111111\n assert candidate(strs = ['123abc', 'abc123', '12345', '54321', 'abcde']) == 54321\n assert candidate(strs = ['abcdefg', 'hijklmn', 'opqrstu', 'vwxyz01', '2345678', '000000000', '123456789']) == 123456789\n assert candidate(strs = ['0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '1', '10', '100', '1000', '10000', '100000', '1000000', '10000000', '100000000']) == 100000000\n assert candidate(strs = ['12345', '1234a', '54321', 'a1b2c3', '000000001']) == 54321\n assert candidate(strs = ['a1b2c3', '123abc', 'abc123', '007', '0x123', '999999', '123456789', 'abcdefghi']) == 123456789\n assert candidate(strs = ['abc123', '123abc', 'abc', '123', '000123', '123000']) == 123000\n assert candidate(strs = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', '11111', '22222', '33333', '44444', '55555']) == 55555\n assert candidate(strs = ['abcdef', '1', '0000001', '234567', 'ghijklm', '00000', 'nopqr', '00000000', '98765']) == 234567\n assert candidate(strs = ['xyz', '123', '456', '789', '000', '111', 'abc123', 'def456', 'ghi789']) == 789\n assert candidate(strs = ['a1b2c3', 'd4e5f6', 'g7h8i9', 'j0k1l2', 'm3n4o5', 'p6q7r8', 's9t0u1', 'v2w3x4', 'y5z6a7', 'b8c9d0']) == 6\n assert candidate(strs = ['a1b2c3', 'd4e5f6', 'g7h8i9', '01234', '56789', 'abcdefg', 'hijklmn', 'opqrstu', 'vwxyz01', '23456789']) == 23456789\n assert candidate(strs = ['a1', 'b2', 'c3', 'd4', 'e5', 'f6', 'g7', 'h8', 'i9', '10', '11', '12', '13', '14', '15']) == 15\n assert candidate(strs = ['zzz', 'yyy', 'xxx', 'www', 'vvv', 'uuu', 'ttt', 'sss', 'rrr', 'qqq', 'ppp', 'ooo', 'nnn', 'mmm', 'lll', 'kkk', 'jjj', 'iii', 'hhh', 'ggg', 'fff', 'eee', 'ddd', 'ccc', 'bbb', 'aaa', '123456789', '987654321']) == 987654321\n assert candidate(strs = ['a1b2c3', '1a2b3c', 'abc123', '123abc', 'abc', '123', 'a1b2', '1a2b', 'ab12', '12ab', 'a1', '1a', 'a', '1']) == 123\n assert candidate(strs = ['0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000']) == 0\n assert candidate(strs = ['abc', '123', '456', 'def', '789', 'ghi', '012', '345', '678', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz1']) == 789\n assert candidate(strs = ['abcdef', 'ghijkl', 'mnopqr', '123456', '789012', '321098', 'abcdefg', 'hijklmn', 'opqrstu', '456789', '012345', '654321']) == 789012\n assert candidate(strs = ['1234', '4321', '1111', '2222', '3333', '0000', '999', '8888', '77777', '666666']) == 666666\n assert candidate(strs = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', '20', '30', '40', '50']) == 50\n assert candidate(strs = ['a1b2c3', '1a2b3c', 'abc12', '12abc', 'a1b2', '1a2b', 'abc1', '1abc', 'a1', '1a', 'a', '1']) == 6\n assert candidate(strs = ['zzz', 'zzz9', 'zzz99', '9zzz', '99zzz', '999zz', 'zzz999', 'zzz9999', 'zzz99999']) == 8\n assert candidate(strs = ['zzzzzzzz', 'aaaaaaaa', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678', '87654321', 'abcd1234', '4321dcba']) == 99999999\n assert candidate(strs = ['1a', '2b', '3c', '4d', '5e', '6f', '7g', '8h', '9i', '0j', '001', '002', '003', '004', '005', '006', '007', '008', '009', '000']) == 9\n assert candidate(strs = ['abc123', '123abc', 'abc', '123', '000000000', '999999999']) == 999999999\n assert candidate(strs = ['000000001', '00000002', '00000003', 'abcde', 'fghij', 'klmno', '6789', '987654321', '000000000']) == 987654321\n assert candidate(strs = ['0000000', '0000001', '0000002', '0000003', '0000004', '0000005', '0000006', '0000007', '0000008', '0000009']) == 9\n assert candidate(strs = ['a1b2c3', 'd4e5f6', 'g7h8i9', '10', '11', '12', '13', '14', '15']) == 15\n assert candidate(strs = ['a1b2c3', 'd4e5f6', 'g7h8i9', '00000', '987654321', '111111111']) == 987654321\n assert candidate(strs = ['00123', '000045', '0000067', '123', '4567', '89012']) == 89012\n", "comparison": "exact"}, "public_tests": ["[\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]", "[\"1\",\"01\",\"001\",\"0001\"]"], "hints": ["For strings comprising only of digits, convert them into integers.", "For all other strings, calculate their length."], "metadata": {"canonical_parameter_names": ["strs"], "leetcode_dataset_entry_point": "Solution().maximumValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:55+00:00", "tests_total": 109, "tests_dropped": 11, "flags": [], "topic_tags": ["array", "string"]}, "language": "php", "interface": {"raw_signature": "function maximumValue($strs) {", "container": "Solution", "callable": "maximumValue", "parameters": [{"name": "strs", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2497, "task_id": "maximum-star-sum-of-a-graph", "difficulty": "Medium", "problem_description": "There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node.\n\nYou are also given a 2D integer array edges where edges[i] = [a_i, b_i] denotes that there exists an undirected edge connecting nodes a_i and b_i.\n\nA star graph is a subgraph of the given graph having a center node containing 0 or more neighbors. In other words, it is a subset of edges of the given graph such that there exists a common node for all edges.\n\nThe image below shows star graphs with 3 and 4 neighbors respectively, centered at the blue node.\n\nThe star sum is the sum of the values of all the nodes present in the star graph.\n\nGiven an integer k, return the maximum star sum of a star graph containing at most k edges.\n\nExample 1:\n\nInput: vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2\nOutput: 16\nExplanation: The above diagram represents the input graph.\nThe star graph with the maximum star sum is denoted by blue. It is centered at 3 and includes its neighbors 1 and 4.\nIt can be shown it is not possible to get a star graph with a sum greater than 16.\n\nExample 2:\n\nInput: vals = [-5], edges = [], k = 0\nOutput: -5\nExplanation: There is only one possible star graph, which is node 0 itself.\nHence, we return -5.\n\nConstraints:\n\n- n == vals.length\n- 1 <= n <= 10^5\n- -10^4 <= vals[i] <= 10^4\n- 0 <= edges.length <= min(n * (n - 1) / 2, 10^5)\n- edges[i].length == 2\n- 0 <= a_i, b_i <= n - 1\n- a_i != b_i\n- 0 <= k <= n - 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(vals = [5, -2, 3, 1],edges = [[0, 1], [0, 2], [0, 3]],k = 3) == 9\n assert candidate(vals = [1, 2, 3],edges = [[0, 1], [1, 2]],k = 0) == 3\n assert candidate(vals = [1, 2, 3, 4, 10, -10, -20],edges = [[0, 1], [1, 2], [1, 3], [3, 4], [3, 5], [3, 6]],k = 2) == 16\n assert candidate(vals = [100, 200, 300, 400, 500],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 4) == 1200\n assert candidate(vals = [-5],edges = [],k = 0) == -5\n assert candidate(vals = [5, 6, 7, 8, 9],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 3], [2, 4]],k = 3) == 29\n assert candidate(vals = [1, 2, 3],edges = [[0, 1], [1, 2]],k = 0) == 3\n assert candidate(vals = [1, 3, -2, 5],edges = [[0, 1], [1, 2], [2, 3]],k = 1) == 5\n assert candidate(vals = [1, -1, 1, -1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 1) == 1\n assert candidate(vals = [-1, -2, -3, -4, -5],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 2) == -1\n assert candidate(vals = [1, 2, 3],edges = [[0, 1], [1, 2]],k = 1) == 5\n assert candidate(vals = [5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3]],k = 3) == 15\n assert candidate(vals = [100, -200, 300, 400, -500],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 1) == 700\n assert candidate(vals = [10, -10, 20, -20, 30, -30],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 2) == 30\n assert candidate(vals = [5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 0]],k = 3) == 15\n assert candidate(vals = [-10, -20, -30, -40],edges = [[0, 1], [1, 2], [2, 3]],k = 1) == -10\n assert candidate(vals = [5, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [0, 3], [0, 4]],k = 3) == 20\n assert candidate(vals = [10, -1, 2, 3, -4],edges = [[0, 1], [0, 2], [0, 3], [0, 4]],k = 2) == 15\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 5) == 3\n assert candidate(vals = [10, 20, 30, -40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2]],k = 3) == 110\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [2, 4], [4, 6], [6, 8], [8, 0]],k = 5) == 350\n assert candidate(vals = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 3) == -1\n assert candidate(vals = [100, 200, 300, 400, 500, 600],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 2) == 1500\n assert candidate(vals = [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], [0, 9]],k = 4) == 0\n assert candidate(vals = [100, 200, 300, 400, 500],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [2, 3], [3, 4]],k = 4) == 1500\n assert candidate(vals = [5, -1, 3, 9, 2, -6, 7],edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 6]],k = 3) == 13\n assert candidate(vals = [100, -50, 20, -10, 5],edges = [[0, 1], [0, 2], [0, 3], [0, 4]],k = 3) == 125\n assert candidate(vals = [-5, -3, -10, -4, -1],edges = [[0, 1], [0, 2], [1, 2], [1, 3], [2, 4]],k = 2) == -1\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 5) == 3\n assert candidate(vals = [-10, 20, -30, 40, -50, 60],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]],k = 4) == 70\n assert candidate(vals = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 8], [0, 7], [0, 6], [0, 5], [0, 4], [0, 3], [0, 2]],k = 3) == 140\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 5) == 270\n assert candidate(vals = [5, -1, 3, 7, 9, -2],edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 4], [4, 5]],k = 3) == 19\n assert candidate(vals = [10, 20, 30, 40, 50],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]],k = 2) == 120\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 5) == 6\n assert candidate(vals = [-10, -20, -30, -40, -50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]],k = 2) == -10\n assert candidate(vals = [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, 0]],k = 5) == 0\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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]],k = 7) == 42\n assert candidate(vals = [5, -3, 8, 0, 2],edges = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4]],k = 3) == 13\n assert candidate(vals = [5, 1, 3, 7, 9, 2, 8, 6],edges = [[0, 1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]],k = 3) == 20\n assert candidate(vals = [10, 20, 30, 40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [1, 3], [2, 4]],k = 2) == 120\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],k = 5) == 3\n assert candidate(vals = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 3) == -10\n assert candidate(vals = [-10, -20, -30, -40, -50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]],k = 4) == -10\n assert candidate(vals = [5, 15, 25, 35, 45, 55],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]],k = 4) == 135\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 8], [3, 9]],k = 3) == 24\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]],k = 2) == 210\n assert candidate(vals = [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]],k = 2) == 0\n assert candidate(vals = [10000, -10000, 5000, -5000, 2500, -2500],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 3) == 10000\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 4) == 35\n assert candidate(vals = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 2], [1, 3], [4, 6], [5, 7], [8, 0], [9, 1], [2, 4], [3, 5], [6, 8], [7, 9]],k = 3) == 12\n assert candidate(vals = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 3) == 2700\n assert candidate(vals = [100, -50, 20, -30, 60, 10],edges = [[0, 1], [0, 2], [0, 3], [1, 4], [2, 4], [3, 5]],k = 3) == 180\n assert candidate(vals = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]],k = 3) == -10\n assert candidate(vals = [5, -5, 15, -15, 25, -25],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]],k = 4) == 25\n assert candidate(vals = [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000, 6000, -6000, 7000, -7000, 8000, -8000, 9000, -9000, 10000, -10000],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15], [16, 17], [18, 19], [0, 2], [1, 3], [4, 6], [5, 7], [8, 10], [9, 11], [12, 14], [13, 15], [16, 18], [17, 19]],k = 4) == 19000\n assert candidate(vals = [100, 200, 300, 400, 500, 600, 700, 800, 900],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]],k = 5) == 2400\n assert candidate(vals = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 9) == 50\n assert candidate(vals = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],edges = [],k = 3) == -1\n assert candidate(vals = [10, -10, 20, -20, 30, -30, 40, -40, 50, -50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 5) == 50\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 5) == 41\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [4, 9]],k = 4) == 21\n assert candidate(vals = [-10, 20, 30, -40, 50, -60],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]],k = 4) == 50\n assert candidate(vals = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [4, 5]],k = 3) == 130\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [],k = 4) == 100\n assert candidate(vals = [100, -100, 200, -200, 300, -300],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [0, 3], [1, 4], [2, 5]],k = 4) == 500\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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]],k = 10) == 3\n assert candidate(vals = [1, -1, 1, -1, 1, -1, 1, -1, 1],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0]],k = 3) == 2\n assert candidate(vals = [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]],k = 1) == 5000\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9]],k = 2) == 270\n assert candidate(vals = [-10, -20, -30, -40, -50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [1, 3], [2, 4]],k = 3) == -10\n assert candidate(vals = [5, -1, 2, 4, 6, -3],edges = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [3, 4], [4, 5]],k = 3) == 17\n assert candidate(vals = [100, 200, 300, 400, 500],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 0) == 500\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],k = 0) == 10\n assert candidate(vals = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 0], [9, 1]],k = 4) == 12\n assert candidate(vals = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 3) == -1\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 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]],k = 7) == 42\n assert candidate(vals = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]],k = 6) == 24\n assert candidate(vals = [-10, -20, -30, -40, -50, -60],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]],k = 0) == -10\n assert candidate(vals = [10000, -10000, 5000, -5000, 2500, -2500, 1250, -1250, 625, -625],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 4) == 10000\n assert candidate(vals = [-1000, -2000, -3000, -4000, -5000],edges = [[0, 1], [1, 2], [2, 3], [3, 4]],k = 3) == -1000\n assert candidate(vals = [-10, 20, 30, -40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 2], [1, 3]],k = 2) == 50\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [5, 9]],k = 2) == 21\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 3) == 270\n assert candidate(vals = [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]],k = 5) == 0\n assert candidate(vals = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]],k = 4) == 25\n assert candidate(vals = [10, 20, 30, 40, 50],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0], [0, 2], [1, 3]],k = 3) == 140\n assert candidate(vals = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]],k = 5) == 12\n assert candidate(vals = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 4) == 5\n assert candidate(vals = [10, -10, 20, -20, 30, -30, 40, -40],edges = [[0, 1], [2, 3], [4, 5], [6, 7], [0, 2], [1, 3], [4, 6], [5, 7]],k = 2) == 70\n assert candidate(vals = [10, -5, 20, 0, 15],edges = [[0, 1], [0, 2], [1, 3], [2, 3], [3, 4]],k = 3) == 35\n assert candidate(vals = [50, 30, 10, -10, -30, -50, -70, 90, 110],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 0], [1, 3], [2, 4], [5, 7]],k = 6) == 250\n assert candidate(vals = [5, 15, 25, 35, 45, 55, 65],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [0, 6], [0, 3], [1, 4], [2, 5]],k = 5) == 190\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 7], [7, 8], [8, 9]],k = 5) == 320\n assert candidate(vals = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10],edges = [],k = 2) == -1\n assert candidate(vals = [5, 10, 15, 20, 25, 30],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]],k = 2) == 75\n assert candidate(vals = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 3) == 0\n assert candidate(vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],edges = [],k = 5) == 10\n assert candidate(vals = [1000, -1000, 2000, -2000, 3000, -3000, 4000, -4000, 5000, -5000],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]],k = 5) == 5000\n assert candidate(vals = [-10000, 10000, -9000, 9000, -8000, 8000, -7000, 7000, -6000, 6000],edges = [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]],k = 2) == 10000\n assert candidate(vals = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],edges = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [0, 9], [0, 5], [1, 6], [2, 7], [3, 8], [4, 9]],k = 5) == 310\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,10,-10,-20]\n[[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]]\n2", "[-5]\n[]\n0"], "hints": ["A star graph doesn’t necessarily include all of its neighbors.", "For each node, sort its neighbors in descending order and take k max valued neighbors."], "metadata": {"canonical_parameter_names": ["vals", "edges", "k"], "leetcode_dataset_entry_point": "Solution().maxStarSum", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:54:58+00:00", "tests_total": 107, "tests_dropped": 6, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "greedy", "graph", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function maxStarSum($vals, $edges, $k) {", "container": "Solution", "callable": "maxStarSum", "parameters": [{"name": "vals", "type": "Integer[]"}, {"name": "edges", "type": "Integer[][]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2498, "task_id": "frog-jump-ii", "difficulty": "Medium", "problem_description": "You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.\n\nA frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.\n\nThe length of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.\n\n- More formally, if the frog is at stones[i] and is jumping to stones[j], the length of the jump is |stones[i] - stones[j]|.\n\nThe cost of a path is the maximum length of a jump among all jumps in the path.\n\nReturn the minimum cost of a path for the frog.\n\nExample 1:\n\nInput: stones = [0,2,5,6,7]\nOutput: 5\nExplanation: The above figure represents one of the optimal paths the frog can take.\nThe cost of this path is 5, which is the maximum length of a jump.\nSince it is not possible to achieve a cost of less than 5, we return it.\n\nExample 2:\n\nInput: stones = [0,3,9]\nOutput: 9\nExplanation:\nThe frog can jump directly to the last stone and come back to the first stone.\nIn this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.\nIt can be shown that this is the minimum achievable cost.\n\nConstraints:\n\n- 2 <= stones.length <= 10^5\n- 0 <= stones[i] <= 10^9\n- stones[0] == 0\n- stones is sorted in a strictly increasing order.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(stones = [0, 10, 15, 20, 25]) == 15\n assert candidate(stones = [0, 1, 2, 3, 4, 5]) == 2\n assert candidate(stones = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(stones = [0, 2, 5, 6, 7]) == 5\n assert candidate(stones = [0, 1, 3, 6, 10, 15]) == 9\n assert candidate(stones = [0, 5, 10, 15, 20, 25, 30]) == 10\n assert candidate(stones = [0, 3, 9]) == 9\n assert candidate(stones = [0, 10, 15, 25, 30]) == 15\n assert candidate(stones = [0, 10, 20, 30, 40]) == 20\n assert candidate(stones = [0, 1, 3, 5, 7, 9]) == 4\n assert candidate(stones = [0, 1, 3, 5, 10]) == 7\n assert candidate(stones = [0, 100, 200, 300, 400]) == 200\n assert candidate(stones = [0, 9, 20, 33, 48, 65, 84, 105, 128, 153, 180, 209, 240, 273, 308, 345, 384, 425, 468, 513, 560, 609, 660, 713, 768, 825]) == 112\n assert candidate(stones = [0, 5, 14, 27, 44, 65, 90, 121, 158, 201, 250]) == 92\n assert candidate(stones = [0, 1, 4, 10, 22, 46, 94, 190, 382, 766, 1534, 3070, 6142, 12286]) == 9216\n assert candidate(stones = [0, 11, 24, 39, 56, 75, 96, 119, 144, 171, 200, 231, 264, 300, 339, 380, 423, 468, 515, 564, 615, 668, 723, 780, 840, 903, 968, 1035, 1104, 1175]) == 140\n assert candidate(stones = [0, 3, 8, 16, 28, 44, 63, 85, 110, 138, 169, 203, 240, 279, 321]) == 81\n assert candidate(stones = [0, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106, 121, 137, 154, 172, 191, 211, 232, 254, 277, 301, 326, 352, 379]) == 53\n assert candidate(stones = [0, 100, 250, 450, 700, 1000, 1350, 1750, 2200, 2700]) == 950\n assert candidate(stones = [0, 10, 25, 45, 70, 100, 140, 185, 240, 305, 380, 470, 575, 695, 830, 980]) == 285\n assert candidate(stones = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 6144\n assert candidate(stones = [0, 5, 15, 30, 50, 75, 105, 140, 180, 225]) == 85\n assert candidate(stones = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383]) == 12288\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) == 17\n assert candidate(stones = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192]) == 6144\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600]) == 94\n assert candidate(stones = [0, 1, 4, 10, 19, 31, 46, 64, 85, 109, 136]) == 51\n assert candidate(stones = [0, 5, 12, 22, 35, 51, 70, 92, 117, 145, 176, 210, 247, 287, 330]) == 83\n assert candidate(stones = [0, 2, 4, 7, 11, 16, 22]) == 11\n assert candidate(stones = [0, 10, 15, 25, 35, 50, 75, 110, 150, 200, 260, 330, 410, 500, 600, 710, 830, 960, 1100, 1250, 1410, 1580, 1760, 1950, 2150, 2360, 2580, 2810, 3050, 3300, 3560, 3830, 4110, 4400, 4700, 5010, 5330, 5660, 6000, 6350, 6710, 7080, 7460, 7850, 8250, 8660, 9080, 9510, 9950, 10400, 10860, 11330, 11810, 12300, 12800, 13310, 13830, 14360, 14900, 15450, 16010, 16580, 17160, 17750, 18350, 18960, 19580, 20210, 20850, 21500, 22160, 22830, 23510, 24200, 24900, 25610, 26330, 27060, 27800, 28550, 29310, 30080, 30860, 31650, 32450, 33260, 34080, 34910, 35750, 36600, 37460, 38330, 39210, 40100, 41000, 41910, 42830, 43760, 44700, 45650, 46610, 47580, 48560, 49550, 50550, 51560, 52580, 53610, 54650, 55700, 56760, 57830, 58910, 60000]) == 2170\n assert candidate(stones = [0, 1, 5, 14, 29, 50, 81, 122, 173, 234, 305, 386, 477, 578, 689, 810, 941, 1082, 1233, 1394, 1565, 1746, 1937, 2148, 2379, 2620, 2871, 3132, 3403, 3684, 3975, 4276, 4587, 4908, 5239, 5580, 5931, 6292, 6663, 7044, 7435, 7836, 8247, 8668, 9099, 9540, 9991, 10452, 10923, 11404, 11895, 12406, 12937, 13488, 14059, 14640, 15231, 15832, 16443, 17064, 17695, 18336, 18987, 19648, 20320]) == 1333\n assert candidate(stones = [0, 4, 9, 16, 25, 36, 49, 64, 81, 100]) == 36\n assert candidate(stones = [0, 3, 9, 18, 30, 45, 63, 84, 108, 135, 165, 198, 234, 273, 315, 360, 408, 459, 513, 570]) == 111\n assert candidate(stones = [0, 3, 7, 12, 20, 30, 45, 65, 90]) == 45\n assert candidate(stones = [0, 2, 7, 15, 26, 39, 54, 71, 90, 111, 134, 159]) == 48\n assert candidate(stones = [0, 3, 8, 15, 24, 35, 48, 63, 80, 99, 120, 143, 168, 195, 224]) == 56\n assert candidate(stones = [0, 5, 10, 20, 35, 55, 80, 110, 145, 185, 230, 280, 335, 395, 460, 530, 605, 685, 770, 860, 955, 1055, 1160, 1270, 1385, 1505, 1630, 1760, 1895, 2035]) == 275\n assert candidate(stones = [0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, 1728, 2197, 2744, 3375, 4096]) == 1352\n assert candidate(stones = [0, 5, 14, 27, 42, 60, 81, 105]) == 45\n assert candidate(stones = [0, 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]) == 200\n assert candidate(stones = [0, 8, 18, 30, 44, 60, 78, 98, 120, 144, 170, 198, 228, 260, 294, 330, 368, 408, 450, 494, 540]) == 90\n assert candidate(stones = [0, 3, 8, 15, 25, 38, 54, 73]) == 35\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380]) == 74\n assert candidate(stones = [0, 5, 12, 20, 28, 36, 45, 55, 66, 78, 90]) == 24\n assert candidate(stones = [0, 10, 30, 60, 100, 150, 210, 280, 360, 450, 550, 660, 780, 910, 1050, 1200]) == 290\n assert candidate(stones = [0, 6, 14, 24, 36, 50, 66, 84, 104, 126, 150, 176, 204, 234, 266, 300, 336]) == 70\n assert candidate(stones = [0, 2, 5, 9, 14, 20, 27, 35, 44, 54, 65]) == 21\n assert candidate(stones = [0, 2, 8, 12, 15, 20, 25, 30]) == 10\n assert candidate(stones = [0, 1, 5, 14, 28, 47, 71, 100, 134, 173, 217, 266, 320, 379, 443, 512, 586, 665, 749, 834, 922, 1015, 1113, 1216]) == 201\n assert candidate(stones = [0, 2, 5, 8, 13, 21, 28, 35, 40]) == 15\n assert candidate(stones = [0, 2, 5, 9, 14, 20, 27, 35, 44, 54, 65, 77, 90]) == 25\n assert candidate(stones = [0, 1, 5, 11, 19, 29, 41, 55, 71, 89, 109, 131, 155, 181, 209, 239, 271, 305, 341, 379, 419, 461, 505, 551, 600, 651, 704, 759, 817, 877, 940, 1005, 1072, 1141, 1212, 1285, 1360, 1437, 1516, 1597, 1680, 1765, 1852, 1941, 2032, 2125, 2220, 2317, 2416, 2517, 2620, 2725, 2832, 2941, 3052, 3165, 3280, 3400, 3523, 3648, 3775, 3904, 4035, 4168, 4303, 4440, 4580, 4722, 4867, 5014, 5163, 5314, 5467, 5622, 5779, 5938, 6099, 6262, 6427, 6594, 6763, 6934, 7107, 7282, 7459, 7638, 7819, 8002, 8187, 8374, 8563, 8754, 8947, 9142, 9339, 9538, 9739, 9942]) == 404\n assert candidate(stones = [0, 3, 7, 13, 21, 31, 43, 57, 73, 91, 111, 133, 157, 183, 211, 241, 273, 307, 343, 381, 421, 463, 507, 553, 601]) == 94\n assert candidate(stones = [0, 2, 5, 9, 14, 20, 27, 35, 44]) == 17\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]) == 19\n assert candidate(stones = [0, 3, 8, 15, 24, 35, 48, 63, 80, 99, 120, 143, 168, 195, 224, 255, 288, 323, 360, 400]) == 77\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156]) == 46\n assert candidate(stones = [0, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106, 121, 137, 154, 172]) == 35\n assert candidate(stones = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 384\n assert candidate(stones = [0, 10, 30, 60, 100, 150, 210, 280, 360, 450, 550, 660, 780, 910, 1050]) == 270\n assert candidate(stones = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500]) == 100\n assert candidate(stones = [0, 5, 15, 30, 50, 75, 105, 140, 180, 225, 275, 330, 390, 455, 525]) == 135\n assert candidate(stones = [0, 10, 25, 40, 55, 70, 85, 100, 120, 140, 160, 180, 200]) == 40\n assert candidate(stones = [0, 10, 25, 45, 70, 100, 135, 175, 220, 270, 325]) == 105\n assert candidate(stones = [0, 5, 11, 18, 26, 35, 45, 56, 68, 81, 95, 110, 126, 143, 161, 180, 200]) == 39\n assert candidate(stones = [0, 1, 3, 7, 13, 21, 31, 43, 57, 73, 91, 111, 133, 157, 183, 211, 241, 273, 307, 343, 381]) == 74\n assert candidate(stones = [0, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106, 121, 137, 154, 172, 191, 211, 232, 254, 277, 301, 326, 352, 379, 407, 436, 466, 497, 529, 562, 596, 631, 667, 704, 742, 781, 821, 862, 904, 947, 991, 1036, 1082, 1129, 1177, 1226, 1276, 1327, 1379, 1432, 1486, 1541, 1597, 1654, 1712, 1771, 1831, 1892, 1954, 2017, 2081, 2146, 2212, 2279, 2347, 2416, 2486, 2557, 2629, 2702, 2776, 2851, 2927, 3004, 3082, 3161, 3241, 3322, 3404, 3487, 3571, 3656, 3742, 3829, 3917, 4006, 4096, 4187, 4279, 4372, 4466, 4561, 4657, 4754, 4852, 4951, 5051]) == 199\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210]) == 39\n assert candidate(stones = [0, 2, 7, 17, 32, 52, 77, 107, 142, 182, 227, 277, 332, 392]) == 115\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380]) == 74\n assert candidate(stones = [0, 2, 5, 9, 14, 20, 27, 35, 44, 54, 65, 77, 90, 104]) == 27\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) == 17\n assert candidate(stones = [0, 1, 5, 14, 29, 49, 74, 104, 139, 179, 218]) == 79\n assert candidate(stones = [0, 5, 15, 30, 50, 75, 105, 140, 180, 225, 275, 330, 390]) == 115\n assert candidate(stones = [0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330]) == 361\n assert candidate(stones = [0, 7, 16, 27, 40, 55, 72, 91, 112, 135, 160, 187, 216, 247, 280, 315, 352, 391, 432, 475]) == 84\n assert candidate(stones = [0, 10, 21, 33, 46, 60, 75, 91, 108, 126, 145, 165, 186, 208, 231, 255, 280, 306, 333, 361, 390, 420, 451, 483, 516]) == 65\n assert candidate(stones = [0, 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]) == 63\n assert candidate(stones = [0, 1, 4, 10, 19, 31, 46, 64, 85, 109, 136, 166, 200]) == 64\n assert candidate(stones = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]) == 76\n assert candidate(stones = [0, 1, 4, 10, 15, 23, 30, 35]) == 15\n assert candidate(stones = [0, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106, 121, 137, 154, 172, 191, 211, 232, 254, 277, 301, 326, 352, 379, 407, 436, 466, 497, 529, 562, 596, 631, 667, 704, 742, 781, 821, 862, 904, 947, 991]) == 87\n assert candidate(stones = [0, 10, 25, 45, 70, 100, 135, 175, 220, 270]) == 95\n assert candidate(stones = [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]) == 6\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462, 506, 552, 600]) == 94\n assert candidate(stones = [0, 3, 7, 14, 22, 31, 40, 50, 60, 70]) == 20\n assert candidate(stones = [0, 1, 4, 8, 15, 23, 36, 55, 89, 144]) == 89\n assert candidate(stones = [0, 5, 13, 24, 37, 52, 69, 88, 109, 132, 157, 184, 213, 244, 277, 312, 349, 388, 429]) == 80\n assert candidate(stones = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368]) == 28657\n assert candidate(stones = [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420]) == 78\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190]) == 37\n assert candidate(stones = [0, 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]) == 124\n assert candidate(stones = [0, 2, 6, 14, 25, 40, 58, 79, 103, 130, 160, 193, 230, 270, 315]) == 85\n assert candidate(stones = [0, 1, 4, 9, 16, 25, 36, 49, 64]) == 28\n assert candidate(stones = [0, 2, 5, 7, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 10\n assert candidate(stones = [0, 1, 3, 6, 10, 15, 21, 28]) == 13\n assert candidate(stones = [0, 1, 5, 14, 29, 49, 74, 104, 139, 179, 218, 258, 300, 344, 391, 441, 494, 550, 610, 674, 742, 815, 893, 976]) == 161\n assert candidate(stones = [0, 5, 15, 30, 50, 75, 105, 140, 180]) == 75\n assert candidate(stones = [0, 2, 5, 9, 14, 20, 27, 35, 44, 54, 65, 77, 90, 104, 119, 135, 152, 170, 189, 209, 230, 252, 275, 299, 324, 350, 377, 405, 434, 464, 495]) == 61\n assert candidate(stones = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]) == 44\n assert candidate(stones = [0, 5, 11, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 20\n assert candidate(stones = [0, 3, 8, 14, 21, 29, 38, 48, 59, 71, 84, 98]) == 27\n assert candidate(stones = [0, 10, 22, 36, 52, 70, 90, 112, 136, 162, 190, 220, 252, 286]) == 66\n", "comparison": "exact"}, "public_tests": ["[0,2,5,6,7]", "[0,3,9]"], "hints": ["One of the optimal strategies will be to jump to every stone.", "Skipping just one stone in every forward jump and jumping to those skipped stones in backward jump can minimize the maximum jump."], "metadata": {"canonical_parameter_names": ["stones"], "leetcode_dataset_entry_point": "Solution().maxJump", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:00+00:00", "tests_total": 106, "tests_dropped": 3, "flags": ["has_images"], "topic_tags": ["array", "binary-search", "greedy"]}, "language": "php", "interface": {"raw_signature": "function maxJump($stones) {", "container": "Solution", "callable": "maxJump", "parameters": [{"name": "stones", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2499, "task_id": "minimum-total-cost-to-make-arrays-unequal", "difficulty": "Hard", "problem_description": "You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.\n\nIn one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.\n\nFind the minimum total cost of performing the given operation any number of times such that nums1[i] != nums2[i] for all 0 <= i <= n - 1 after performing all the operations.\n\nReturn the minimum total cost such that nums1 and nums2 satisfy the above condition. In case it is not possible, return -1.\n\nExample 1:\n\nInput: nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]\nOutput: 10\nExplanation:\nOne of the ways we can perform the operations is:\n- Swap values at indices 0 and 3, incurring cost = 0 + 3 = 3. Now, nums1 = [4,2,3,1,5]\n- Swap values at indices 1 and 2, incurring cost = 1 + 2 = 3. Now, nums1 = [4,3,2,1,5].\n- Swap values at indices 0 and 4, incurring cost = 0 + 4 = 4. Now, nums1 =[5,3,2,1,4].\nWe can see that for each index i, nums1[i] != nums2[i]. The cost required here is 10.\nNote that there are other ways to swap values, but it can be proven that it is not possible to obtain a cost less than 10.\n\nExample 2:\n\nInput: nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]\nOutput: 10\nExplanation:\nOne of the ways we can perform the operations is:\n- Swap values at indices 2 and 3, incurring cost = 2 + 3 = 5. Now, nums1 = [2,2,1,2,3].\n- Swap values at indices 1 and 4, incurring cost = 1 + 4 = 5. Now, nums1 = [2,3,1,2,2].\nThe total cost needed here is 10, which is the minimum possible.\n\nExample 3:\n\nInput: nums1 = [1,2,2], nums2 = [1,2,2]\nOutput: -1\nExplanation:\nIt can be shown that it is not possible to satisfy the given conditions irrespective of the number of operations we perform.\nHence, we return -1.\n\nConstraints:\n\n- n == nums1.length == nums2.length\n- 1 <= n <= 10^5\n- 1 <= nums1[i], nums2[i] <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums1 = [1, 2, 2],nums2 = [1, 2, 2]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [2, 2, 2, 2, 2]) == 0\n assert candidate(nums1 = [1, 2],nums2 = [2, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5]) == -1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [1, 1, 1, 1]) == -1\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2],nums2 = [1, 1, 1, 2, 2, 2]) == 15\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3],nums2 = [1, 1, 2, 2, 3, 3]) == 15\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 2, 1]) == 1\n assert candidate(nums1 = [1, 1, 1, 1],nums2 = [2, 2, 2, 2]) == 0\n assert candidate(nums1 = [5, 1, 3, 2, 4],nums2 = [4, 2, 1, 3, 5]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [5, 4, 3, 2, 1]) == 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 = [5, 3, 2, 4, 1],nums2 = [5, 4, 1, 3, 2]) == 1\n assert candidate(nums1 = [1, 1, 2, 2],nums2 = [2, 2, 1, 1]) == 0\n assert candidate(nums1 = [1, 1, 2, 2, 3],nums2 = [1, 1, 2, 2, 3]) == 10\n assert candidate(nums1 = [1, 2, 3, 4, 5],nums2 = [1, 2, 3, 4, 5]) == 10\n assert candidate(nums1 = [5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5]) == 2\n assert candidate(nums1 = [1, 2, 3],nums2 = [3, 1, 2]) == 0\n assert candidate(nums1 = [5, 3, 3, 2, 1],nums2 = [5, 4, 4, 1, 2]) == 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]) == 0\n assert candidate(nums1 = [1],nums2 = [1]) == -1\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]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 1],nums2 = [1, 1, 1, 1, 1]) == -1\n assert candidate(nums1 = [2, 2, 2, 1, 3],nums2 = [1, 2, 2, 3, 3]) == 10\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 1, 2, 3, 4, 3, 4, 5, 6]) == 22\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]) == -1\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 10]) == 18\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],nums2 = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 4\n assert candidate(nums1 = [3, 1, 2, 3, 1, 2, 3, 1, 2, 3],nums2 = [1, 3, 2, 1, 3, 2, 1, 3, 2, 1]) == 19\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums1 = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],nums2 = [1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6]) == 15\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]) == 7\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]) == 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, 9]) == 36\n assert candidate(nums1 = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 105\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 105\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],nums2 = [2, 2, 2, 2, 1, 1, 1, 1, 3, 3, 3, 3]) == 44\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3],nums2 = [2, 2, 2, 1, 1, 1, 3, 3, 3]) == 24\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]) == -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]) == 0\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],nums2 = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5]) == 40\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 4, 4]) == 41\n assert candidate(nums1 = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums1 = [2, 3, 4, 5, 6, 1],nums2 = [6, 1, 2, 3, 4, 5]) == 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]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 9]) == 28\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],nums2 = [2, 3, 3, 4, 4, 5, 5, 6, 6, 7]) == 0\n assert candidate(nums1 = [1, 3, 2, 5, 4, 6, 7, 8, 9, 10],nums2 = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10]) == 35\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 105\n assert candidate(nums1 = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 101\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == 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]) == 0\n assert candidate(nums1 = [5, 1, 3, 2, 4, 6, 7, 8, 9, 10],nums2 = [10, 5, 4, 3, 2, 1, 8, 7, 6, 9]) == 0\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]) == -1\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],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 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 2]) == 0\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]) == 0\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6]) == 0\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]) == 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]) == 0\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4],nums2 = [1, 3, 3, 2, 2, 5, 5]) == 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]) == 45\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],nums2 = [6, 2, 1, 3, 3, 4, 4, 5, 5, 1]) == 34\n assert candidate(nums1 = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [7, 6, 5, 4, 3, 2, 1],nums2 = [1, 2, 3, 4, 5, 6, 7]) == 3\n assert candidate(nums1 = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],nums2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\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]) == 9\n assert candidate(nums1 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [1, 2, 1, 2, 3, 4, 3, 4, 5, 6]) == 22\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]) == 45\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]) == -1\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6],nums2 = [6, 2, 2, 6, 6, 2, 2, 6, 6, 2, 2]) == 6\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],nums2 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]) == 66\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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45\n assert candidate(nums1 = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\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, 2]) == -1\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]) == -1\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4],nums2 = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 12\n assert candidate(nums1 = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4],nums2 = [4, 4, 4, 3, 3, 3, 2, 2, 2, 1]) == 0\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 20\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 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],nums2 = [2, 2, 1, 1, 4, 4, 3, 3, 5, 5]) == 18\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]) == 0\n assert candidate(nums1 = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 42\n assert candidate(nums1 = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],nums2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]) == -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, 2]) == -1\n assert candidate(nums1 = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],nums2 = [2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 0\n assert candidate(nums1 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3],nums2 = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3]) == 45\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, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 190\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]) == 45\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]) == 28\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [2, 1, 4, 3, 6, 5, 8, 7, 10, 9]) == 0\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, 2, 3, 3, 4, 4, 5, 5, 6],nums2 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6]) == 45\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [1, 3, 2, 5, 4, 7, 6, 9, 8, 10]) == 9\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]) == -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, 1]) == 36\n assert candidate(nums1 = [5, 5, 5, 5, 5, 5, 5, 5, 5],nums2 = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == -1\n assert candidate(nums1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],nums2 = [5, 6, 7, 8, 9, 10, 1, 2, 3, 4]) == 0\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 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums1 = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],nums2 = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == -1\n assert candidate(nums1 = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10],nums2 = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10]) == 90\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", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5]\n[1,2,3,4,5]", "[2,2,2,1,3]\n[1,2,2,3,3]", "[1,2,2]\n[1,2,2]"], "hints": ["How can we check which indices of nums1 will be considered for swapping? How to minimize the number of such operations?", "It can be seen that greedily swapping values of indices where nums1[i] == nums2[i] is the most optimal choice. How many values cannot be swapped this way?", "Find which indices we will swap these remaining values with, and if there are enough such indices."], "metadata": {"canonical_parameter_names": ["nums1", "nums2"], "leetcode_dataset_entry_point": "Solution().minimumTotalCost", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:03+00:00", "tests_total": 118, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "hash-table", "greedy", "counting"]}, "language": "php", "interface": {"raw_signature": "function minimumTotalCost($nums1, $nums2) {", "container": "Solution", "callable": "minimumTotalCost", "parameters": [{"name": "nums1", "type": "Integer[]"}, {"name": "nums2", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2500, "task_id": "delete-greatest-value-in-each-row", "difficulty": "Easy", "problem_description": "You are given an m x n matrix grid consisting of positive integers.\n\nPerform the following operation until grid becomes empty:\n\n- Delete the element with the greatest value from each row. If multiple such elements exist, delete any of them.\n- Add the maximum of deleted elements to the answer.\n\nNote that the number of columns decreases by one after each operation.\n\nReturn the answer after performing the operations described above.\n\nExample 1:\n\nInput: grid = [[1,2,4],[3,3,1]]\nOutput: 8\nExplanation: The diagram above shows the removed values in each step.\n- In the first operation, we remove 4 from the first row and 3 from the second row (notice that, there are two cells with value 3 and we can remove any of them). We add 4 to the answer.\n- In the second operation, we remove 2 from the first row and 3 from the second row. We add 3 to the answer.\n- In the third operation, we remove 1 from the first row and 1 from the second row. We add 1 to the answer.\nThe final answer = 4 + 3 + 1 = 8.\n\nExample 2:\n\nInput: grid = [[10]]\nOutput: 10\nExplanation: The diagram above shows the removed values in each step.\n- In the first operation, we remove 10 from the first row. We add 10 to the answer.\nThe final answer = 10.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 1 <= m, n <= 50\n- 1 <= grid[i][j] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]) == 24\n assert candidate(grid = [[5, 1, 3], [4, 2, 6], [7, 8, 9]]) == 24\n assert candidate(grid = [[5, 1, 3], [9, 3, 5], [7, 6, 2]]) == 18\n assert candidate(grid = [[10]]) == 10\n assert candidate(grid = [[1, 2, 4], [3, 3, 1]]) == 8\n assert candidate(grid = [[5, 3], [9, 7], [2, 6]]) == 16\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8]]) == 20\n assert candidate(grid = [[5, 3], [9, 7]]) == 16\n assert candidate(grid = [[1, 3, 5, 7], [10, 8, 6, 4]]) == 28\n assert candidate(grid = [[1, 2], [3, 4], [5, 6]]) == 11\n assert candidate(grid = [[2, 2, 2], [2, 2, 2], [2, 2, 2]]) == 6\n assert candidate(grid = [[100, 100], [100, 100], [100, 100]]) == 200\n assert candidate(grid = [[1, 3, 5], [2, 4, 6], [3, 6, 9], [4, 8, 12]]) == 24\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) == 51\n assert candidate(grid = [[50, 49, 48, 47], [46, 45, 44, 43], [42, 41, 40, 39], [38, 37, 36, 35]]) == 194\n assert candidate(grid = [[45, 23, 67, 89, 12], [90, 34, 56, 78, 10], [11, 13, 15, 17, 19], [21, 22, 24, 25, 26]]) == 279\n assert candidate(grid = [[4, 8, 12, 16, 20], [3, 7, 11, 15, 19], [2, 6, 10, 14, 18], [1, 5, 9, 13, 17]]) == 60\n assert candidate(grid = [[23, 34, 45, 56], [12, 23, 34, 45], [56, 67, 78, 89], [90, 10, 20, 30]]) == 291\n assert candidate(grid = [[7, 8, 9], [4, 5, 6], [1, 2, 3], [7, 8, 9], [4, 5, 6], [1, 2, 3]]) == 24\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, 1, 3, 5, 7, 9], [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]]) == 165\n assert candidate(grid = [[1, 3, 5, 7, 9], [10, 8, 6, 4, 2], [11, 13, 15, 17, 19], [20, 18, 16, 14, 12]]) == 80\n assert candidate(grid = [[50, 45, 40], [35, 30, 25], [20, 15, 10], [5, 10, 15], [20, 25, 30]]) == 135\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [60, 70, 80, 90, 100], [100, 90, 80, 70, 60]]) == 400\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]) == 55\n assert candidate(grid = [[100, 99, 98, 97, 96], [95, 94, 93, 92, 91], [90, 89, 88, 87, 86]]) == 490\n assert candidate(grid = [[24, 17, 56, 38, 45], [89, 21, 37, 62, 11], [48, 93, 71, 19, 81], [25, 76, 53, 90, 32]]) == 318\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 6, 2, 5, 3, 4]]) == 21\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [25, 75, 25, 75, 25], [75, 25, 75, 25, 75]]) == 275\n assert candidate(grid = [[4, 2, 9, 1], [8, 5, 6, 7], [3, 11, 12, 10]]) == 38\n assert candidate(grid = [[20, 5, 15], [10, 10, 30], [40, 25, 5]]) == 75\n assert candidate(grid = [[23, 54, 76], [34, 56, 23], [89, 12, 45], [56, 78, 90]]) == 224\n assert candidate(grid = [[45, 12, 67, 34], [89, 23, 56, 78], [90, 45, 34, 12], [78, 90, 45, 67]]) == 280\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]) == 42\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 5, 2, 4, 3], [3, 4, 5, 1, 2]]) == 15\n assert candidate(grid = [[100, 90, 80], [70, 60, 50], [40, 30, 20], [10, 5, 1]]) == 270\n assert candidate(grid = [[7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7], [2, 1, 3, 4, 6, 5, 7], [3, 4, 5, 6, 7, 1, 2]]) == 28\n assert candidate(grid = [[3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1], [6, 6, 6, 6, 6, 6]]) == 36\n assert candidate(grid = [[9, 7, 5, 3], [8, 6, 4, 2], [7, 5, 3, 1]]) == 24\n assert candidate(grid = [[45, 55, 65], [35, 45, 55], [25, 35, 45], [15, 25, 35]]) == 165\n assert candidate(grid = [[4, 1, 7], [8, 2, 6], [3, 9, 5], [5, 3, 8]]) == 18\n assert candidate(grid = [[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]]) == 65\n assert candidate(grid = [[23, 34, 45, 56], [56, 45, 34, 23], [23, 45, 56, 34], [34, 56, 23, 45]]) == 158\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [10, 8, 6, 4, 2], [9, 7, 5, 3, 1]]) == 30\n assert candidate(grid = [[1, 5, 3], [2, 8, 7], [4, 6, 9], [11, 13, 12]]) == 36\n assert candidate(grid = [[15, 25, 35, 45, 55, 65, 75, 85, 95], [95, 85, 75, 65, 55, 45, 35, 25, 15], [10, 20, 30, 40, 50, 60, 70, 80, 90]]) == 495\n assert candidate(grid = [[1, 100, 1], [100, 1, 100], [1, 100, 1], [100, 1, 100]]) == 201\n assert candidate(grid = [[50, 49, 48], [47, 46, 45], [44, 43, 42], [41, 40, 39]]) == 147\n assert candidate(grid = [[3, 1, 2], [6, 5, 4], [9, 8, 7], [12, 11, 10]]) == 33\n assert candidate(grid = [[50, 40, 30], [40, 30, 20], [30, 20, 10], [20, 10, 5]]) == 120\n assert candidate(grid = [[10], [20], [30], [40], [50], [60]]) == 60\n assert candidate(grid = [[42, 24, 36, 18, 72], [54, 12, 60, 84, 30], [90, 45, 15, 75, 60]]) == 288\n assert candidate(grid = [[100, 99, 98, 97], [96, 95, 94, 93], [92, 91, 90, 89], [88, 87, 86, 85]]) == 394\n assert candidate(grid = [[100, 90, 80], [70, 60, 50], [40, 30, 20], [10, 20, 30]]) == 270\n assert candidate(grid = [[9, 1, 5, 3], [4, 8, 2, 7], [6, 10, 1, 12]]) == 30\n assert candidate(grid = [[25, 15, 35, 5], [10, 45, 55, 20], [50, 30, 60, 40]]) == 180\n assert candidate(grid = [[100, 99, 98, 97, 96], [95, 94, 93, 92, 91], [90, 89, 88, 87, 86]]) == 490\n assert candidate(grid = [[99, 98, 97, 96], [95, 94, 93, 92], [91, 90, 89, 88]]) == 390\n assert candidate(grid = [[10, 20, 30], [15, 25, 35], [20, 30, 40], [25, 35, 45]]) == 105\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [6, 7, 8, 9, 10], [10, 9, 8, 7, 6]]) == 40\n assert candidate(grid = [[1, 99, 2, 98], [3, 97, 4, 96], [5, 95, 6, 94], [7, 93, 8, 92]]) == 212\n assert candidate(grid = [[100, 99, 98], [97, 96, 95], [94, 93, 92], [91, 90, 89]]) == 297\n assert candidate(grid = [[5, 1, 9, 2], [8, 6, 3, 7], [4, 10, 1, 11]]) == 30\n assert candidate(grid = [[9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9]]) == 45\n assert candidate(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == 39\n assert candidate(grid = [[100, 50, 25, 10], [90, 60, 40, 30], [80, 70, 35, 15], [75, 65, 55, 45]]) == 270\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [60, 70, 80, 90, 100]]) == 400\n assert candidate(grid = [[9, 5, 1, 7], [8, 4, 2, 6], [3, 11, 10, 12]]) == 36\n assert candidate(grid = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 6]]) == 11\n assert candidate(grid = [[47, 83, 29], [91, 7, 36], [42, 54, 67], [22, 88, 15]]) == 187\n assert candidate(grid = [[99, 98, 97], [96, 95, 94], [93, 92, 91], [90, 89, 88], [87, 86, 85]]) == 294\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [2, 3, 4, 5, 1], [5, 1, 2, 3, 4]]) == 15\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, 1, 3, 5, 7, 9]]) == 55\n assert candidate(grid = [[100, 1, 2, 3], [3, 2, 1, 100], [100, 100, 1, 1], [1, 100, 100, 100]]) == 301\n assert candidate(grid = [[7, 5, 3, 1], [8, 6, 4, 2], [9, 7, 5, 3], [10, 8, 6, 4]]) == 28\n assert candidate(grid = [[15, 20, 25, 30], [10, 15, 20, 25], [5, 10, 15, 20], [1, 5, 10, 15]]) == 90\n assert candidate(grid = [[7, 3, 5, 9], [1, 4, 8, 2], [6, 10, 12, 11]]) == 39\n assert candidate(grid = [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1]]) == 65\n assert candidate(grid = [[100, 1, 2, 3, 4], [99, 5, 6, 7, 8], [98, 9, 10, 11, 12], [97, 13, 14, 15, 16]]) == 158\n assert candidate(grid = [[42, 23, 65, 12, 34], [56, 78, 90, 23, 45], [89, 12, 34, 56, 78]]) == 292\n assert candidate(grid = [[10, 15, 5, 20], [12, 18, 8, 6], [7, 11, 13, 19]]) == 53\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [7, 8, 9, 10, 11, 12], [12, 11, 10, 9, 8, 7]]) == 57\n assert candidate(grid = [[42, 42, 42, 42], [42, 42, 42, 42], [42, 42, 42, 42], [42, 42, 42, 42]]) == 168\n assert candidate(grid = [[1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1], [1, 3, 5, 2, 4, 6], [6, 4, 2, 5, 3, 1]]) == 21\n assert candidate(grid = [[100, 1, 2, 3], [4, 100, 5, 6], [7, 8, 100, 9], [10, 11, 12, 100]]) == 133\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 30, 50, 20, 40], [20, 40, 10, 50, 30]]) == 150\n assert candidate(grid = [[33, 54, 21, 45], [11, 99, 32, 16], [82, 76, 41, 53], [65, 29, 37, 44]]) == 269\n", "comparison": "exact"}, "public_tests": ["[[1,2,4],[3,3,1]]", "[[10]]"], "hints": ["Iterate from the first to the last row and if there exist some unmarked cells, take a maximum from them and mark that cell as visited.", "Add a maximum of newly marked cells to answer and repeat that operation until the whole matrix becomes marked."], "metadata": {"canonical_parameter_names": ["grid"], "leetcode_dataset_entry_point": "Solution().deleteGreatestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:05+00:00", "tests_total": 93, "tests_dropped": 6, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "sorting", "heap-priority-queue", "matrix", "simulation"]}, "language": "php", "interface": {"raw_signature": "function deleteGreatestValue($grid) {", "container": "Solution", "callable": "deleteGreatestValue", "parameters": [{"name": "grid", "type": "Integer[][]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2501, "task_id": "longest-square-streak-in-an-array", "difficulty": "Medium", "problem_description": "You are given an integer array nums. A subsequence of nums is called a square streak if:\n\n- The length of the subsequence is at least 2, and\n- after sorting the subsequence, each element (except the first element) is the square of the previous number.\n\nReturn the length of the longest square streak in nums, or return -1 if there is no square streak.\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 = [4,3,6,16,8,2]\nOutput: 3\nExplanation: Choose the subsequence [4,16,2]. After sorting it, it becomes [2,4,16].\n- 4 = 2 * 2.\n- 16 = 4 * 4.\nTherefore, [4,16,2] is a square streak.\nIt can be shown that every subsequence of length 4 is not a square streak.\n\nExample 2:\n\nInput: nums = [2,3,5,6,7]\nOutput: -1\nExplanation: There is no square streak in nums so return -1.\n\nConstraints:\n\n- 2 <= nums.length <= 10^5\n- 2 <= nums[i] <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 16, 256, 65536]) == 4\n assert candidate(nums = [6, 36, 1296, 46656]) == 3\n assert candidate(nums = [2, 3, 5, 6, 7]) == -1\n assert candidate(nums = [4, 16, 256, 65536, 2]) == 5\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n assert candidate(nums = [10, 20, 30, 40, 50]) == -1\n assert candidate(nums = [2, 4, 16, 256, 65536]) == 5\n assert candidate(nums = [4, 3, 6, 16, 8, 2]) == 3\n assert candidate(nums = [1024, 32, 2, 4, 16, 64, 256]) == 4\n assert candidate(nums = [4, 16, 64, 256, 1024, 4096]) == 3\n assert candidate(nums = [3, 9, 27, 81, 243, 729]) == 3\n assert candidate(nums = [2, 8, 16, 256, 65536]) == 3\n assert candidate(nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 25, 36, 49, 64, 81, 100]) == 3\n assert candidate(nums = [10, 100, 1000, 10000, 100000]) == 3\n assert candidate(nums = [5, 25, 125, 625, 3125, 15625, 78125]) == 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, 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 = [2, 8, 16, 32, 64, 128, 256, 512, 1024]) == 2\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]) == 4\n assert candidate(nums = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 5\n assert candidate(nums = [3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049]) == 4\n assert candidate(nums = [2, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) == 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]) == -1\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]) == 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, 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]) == -1\n", "comparison": "exact"}, "public_tests": ["[4,3,6,16,8,2]", "[2,3,5,6,7]"], "hints": ["With the constraints, the length of the longest square streak possible is 5.", "Store the elements of nums in a set to quickly check if it exists."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().longestSquareStreak", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:07+00:00", "tests_total": 132, "tests_dropped": 108, "flags": [], "topic_tags": ["array", "hash-table", "binary-search", "dynamic-programming", "sorting"]}, "language": "php", "interface": {"raw_signature": "function longestSquareStreak($nums) {", "container": "Solution", "callable": "longestSquareStreak", "parameters": [{"name": "nums", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2503, "task_id": "maximum-number-of-points-from-grid-queries", "difficulty": "Hard", "problem_description": "You are given an m x n integer matrix grid and an array queries of size k.\n\nFind an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:\n\n- If queries[i] is strictly greater than the value of the current cell that you are in, then you get one point if it is your first time visiting this cell, and you can move to any adjacent cell in all 4 directions: up, down, left, and right.\n- Otherwise, you do not get any points, and you end this process.\n\nAfter the process, answer[i] is the maximum number of points you can get. Note that for each query you are allowed to visit the same cell multiple times.\n\nReturn the resulting array answer.\n\nExample 1:\n\nInput: grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]\nOutput: [5,8,1]\nExplanation: The diagrams above show which cells we visit to get points for each query.\n\nExample 2:\n\nInput: grid = [[5,2,1],[1,1,2]], queries = [3]\nOutput: [0]\nExplanation: We can not get any points because the value of the top left cell is already greater than or equal to 3.\n\nConstraints:\n\n- m == grid.length\n- n == grid[i].length\n- 2 <= m, n <= 1000\n- 4 <= m * n <= 10^5\n- k == queries.length\n- 1 <= k <= 10^4\n- 1 <= grid[i][j], queries[i] <= 10^6\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],queries = [2, 3]) == [9, 9]\n assert candidate(grid = [[1, 2, 3], [2, 5, 7], [3, 5, 1]],queries = [5, 6, 2]) == [5, 8, 1]\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],queries = [1, 2, 3]) == [0, 9, 9]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],queries = [15, 25, 35, 45, 55, 65, 75, 85, 95]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n assert candidate(grid = [[3, 3, 3], [3, 3, 3], [3, 3, 3]],queries = [2, 4, 6]) == [0, 9, 9]\n assert candidate(grid = [[1, 10], [10, 1]],queries = [5, 15]) == [1, 4]\n assert candidate(grid = [[5, 5, 5], [5, 5, 5], [5, 5, 5]],queries = [4, 5, 6]) == [0, 0, 9]\n assert candidate(grid = [[4, 5, 6], [7, 8, 9], [10, 11, 12]],queries = [10, 15, 20]) == [6, 9, 9]\n assert candidate(grid = [[5, 2, 1], [1, 1, 2]],queries = [3]) == [0]\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],queries = [1, 2, 3]) == [0, 16, 16]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],queries = [15, 45, 75]) == [1, 4, 7]\n assert candidate(grid = [[4, 4, 4], [4, 4, 4], [4, 4, 4]],queries = [4]) == [0]\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],queries = [2, 2, 2]) == [12, 12, 12]\n assert candidate(grid = [[10, 20, 30], [40, 50, 60], [70, 80, 90]],queries = [15, 35, 65, 95]) == [1, 3, 6, 9]\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],queries = [2]) == [9]\n assert candidate(grid = [[1000000, 1000000], [1000000, 1000000]],queries = [1000000, 999999]) == [0, 0]\n assert candidate(grid = [[1, 5, 9, 13, 17], [2, 6, 10, 14, 18], [3, 7, 11, 15, 19], [4, 8, 12, 16, 20]],queries = [10, 15, 20]) == [9, 14, 19]\n assert candidate(grid = [[100000, 1, 100000, 1, 100000], [1, 100000, 1, 100000, 1], [100000, 1, 100000, 1, 100000], [1, 100000, 1, 100000, 1], [100000, 1, 100000, 1, 100000]],queries = [1, 100000, 100001]) == [0, 0, 25]\n assert candidate(grid = [[1000000, 1000000, 1000000], [1000000, 1, 1000000], [1000000, 1000000, 1000000]],queries = [1000000, 999999]) == [0, 0]\n assert candidate(grid = [[9, 8, 7, 6], [2, 1, 3, 4], [5, 10, 11, 12], [13, 14, 15, 16]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 11, 12, 13, 14, 15]\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], [5, 4, 3, 2, 1, 9, 8, 7, 6], [4, 3, 2, 1, 9, 8, 7, 6, 5], [3, 2, 1, 9, 8, 7, 6, 5, 4], [2, 1, 9, 8, 7, 6, 5, 4, 3], [1, 9, 8, 7, 6, 5, 4, 3, 2]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]) == [0, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 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]],queries = [1, 5, 10, 15, 20, 25, 30]) == [0, 4, 9, 14, 19, 24, 29]\n assert candidate(grid = [[1, 2, 3], [2, 5, 7], [3, 5, 1], [1, 2, 3], [2, 5, 7]],queries = [5, 6, 2, 8, 10]) == [10, 13, 1, 15, 15]\n assert candidate(grid = [[5, 5, 5, 5], [5, 1, 1, 5], [5, 1, 1, 5], [5, 5, 5, 5]],queries = [1, 2, 3, 4, 5, 6]) == [0, 0, 0, 0, 0, 16]\n assert candidate(grid = [[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]],queries = [2, 4, 6]) == [1, 25, 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]],queries = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == [4, 9, 14, 19, 24, 29, 34, 39, 44, 49]\n assert candidate(grid = [[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]],queries = [25, 35, 45, 55]) == [0, 0, 0, 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]],queries = [15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == [14, 24, 34, 44, 50, 50, 50, 50, 50, 50]\n assert candidate(grid = [[2, 1, 3, 1, 2], [1, 2, 1, 2, 1], [3, 1, 2, 1, 3], [1, 2, 1, 2, 1], [2, 1, 3, 1, 2]],queries = [1, 2, 3, 4]) == [0, 0, 21, 25]\n assert candidate(grid = [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [65, 70, 75, 80]],queries = [25, 50, 75, 100]) == [4, 9, 14, 16]\n assert candidate(grid = [[9, 8, 7], [6, 5, 4], [3, 2, 1]],queries = [5, 10, 15]) == [0, 9, 9]\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]],queries = [1, 5, 10, 15, 20, 25]) == [0, 4, 9, 14, 19, 24]\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]],queries = [3, 4, 5, 6]) == [2, 3, 16, 20]\n assert candidate(grid = [[2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 2], [2, 1, 2, 2, 2, 1, 2], [2, 1, 2, 1, 2, 1, 2], [2, 1, 2, 2, 2, 1, 2], [2, 1, 1, 1, 1, 1, 2], [2, 2, 2, 2, 2, 2, 2]],queries = [1, 2, 3]) == [0, 0, 49]\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 3, 6, 9, 12, 14, 15, 15, 15]\n assert candidate(grid = [[1, 3, 1, 4, 2], [3, 2, 4, 1, 3], [1, 4, 2, 3, 1], [2, 3, 1, 2, 4]],queries = [5, 3, 6, 2]) == [20, 1, 20, 1]\n assert candidate(grid = [[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]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]\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]],queries = [1, 3, 5, 7, 9]) == [0, 3, 10, 19, 24]\n assert candidate(grid = [[10, 10, 10, 10, 10], [10, 9, 9, 9, 10], [10, 9, 8, 9, 10], [10, 9, 9, 9, 10], [10, 10, 10, 10, 10]],queries = [10, 9, 8, 7]) == [0, 0, 0, 0]\n assert candidate(grid = [[5, 6, 7, 8], [4, 3, 2, 1], [12, 13, 14, 15], [9, 10, 11, 16]],queries = [3, 5, 7, 9, 11, 13, 15, 17]) == [0, 0, 6, 8, 8, 12, 14, 16]\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]],queries = [10, 20, 30, 40, 50, 60]) == [0, 8, 13, 18, 23, 25]\n assert candidate(grid = [[5, 2, 1, 4, 3, 2, 1], [4, 3, 2, 1, 4, 3, 2], [3, 2, 1, 2, 3, 2, 1], [2, 1, 2, 3, 2, 1, 2], [1, 2, 3, 2, 1, 2, 3]],queries = [3, 4, 5, 6]) == [0, 0, 0, 35]\n assert candidate(grid = [[9, 9, 9, 9, 9], [9, 1, 2, 3, 9], [9, 4, 5, 6, 9], [9, 7, 8, 9, 9], [9, 9, 9, 9, 9]],queries = [1, 5, 10]) == [0, 0, 25]\n assert candidate(grid = [[10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50], [50, 40, 30, 20, 10], [10, 20, 30, 40, 50]],queries = [25, 35, 45, 55]) == [2, 15, 20, 25]\n assert candidate(grid = [[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 = [6, 7, 8]) == [0, 0, 25]\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]],queries = [1, 2, 3, 4]) == [0, 16, 24, 25]\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]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [25, 24, 22, 19, 15, 10, 6, 3, 1, 0]\n assert candidate(grid = [[7, 7, 7, 7], [7, 7, 7, 7], [7, 7, 7, 7], [7, 7, 7, 7]],queries = [5, 6, 8]) == [0, 0, 16]\n assert candidate(grid = [[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]],queries = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [25, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n assert candidate(grid = [[1, 1, 1], [1, 10, 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]) == [0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]\n assert candidate(grid = [[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, 5, 4, 3, 1], [1, 2, 3, 4, 5, 6, 7, 6, 3, 1], [1, 2, 3, 4, 5, 6, 7, 8, 3, 1], [1, 2, 3, 4, 5, 6, 7, 6, 5, 1], [1, 2, 3, 4, 3, 2, 3, 4, 5, 1]],queries = [2, 3, 5, 7, 8, 10]) == [28, 47, 81, 96, 99, 100]\n assert candidate(grid = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [2, 3, 4, 5, 1], [6, 7, 8, 9, 10]],queries = [1, 3, 5, 7, 9, 11]) == [0, 2, 4, 12, 16, 20]\n assert candidate(grid = [[2, 3, 2], [3, 2, 3], [2, 3, 2], [3, 2, 3], [2, 3, 2]],queries = [2, 3, 4, 5, 6, 7]) == [0, 1, 15, 15, 15, 15]\n assert candidate(grid = [[3, 3, 3, 3], [3, 1, 1, 3], [3, 1, 1, 3], [3, 3, 3, 3]],queries = [1, 2, 4, 5]) == [0, 0, 16, 16]\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]],queries = [10, 5, 1, 15]) == [25, 10, 0, 25]\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7]],queries = [1, 2, 3, 4, 5, 6, 7, 8]) == [0, 1, 3, 6, 9, 12, 14, 15]\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]],queries = [10, 15, 20]) == [9, 14, 15]\n assert candidate(grid = [[1000000, 999999], [999998, 1000000], [999997, 999996]],queries = [1000000, 999999, 999998, 999997]) == [0, 0, 0, 0]\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]],queries = [5, 10, 15, 20]) == [0, 25, 25, 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]],queries = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == [25, 0, 25, 0, 25, 0, 25, 0, 25, 0, 25, 0, 25, 0, 25, 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, 1, 1, 1, 1, 1]],queries = [1, 2, 3]) == [0, 30, 30]\n assert candidate(grid = [[5, 1, 2, 3, 4], [4, 5, 6, 7, 8], [3, 4, 5, 6, 7], [2, 3, 4, 5, 6], [1, 2, 3, 4, 5]],queries = [6, 5, 4, 3, 2, 1]) == [19, 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, 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, 3, 2, 1, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2, 1, 1, 1], [1, 2, 3, 4, 5, 6, 6, 6, 5, 4, 3, 2, 1, 1, 1], [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 1, 1], [1, 2, 3, 4, 5, 6, 6, 6, 5, 4, 3, 2, 1, 1, 1], [1, 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2, 1, 1, 1], [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 1, 1], [1, 2, 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, 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]) == [0, 69, 111, 145, 170, 186, 194]\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]],queries = [5, 10, 15]) == [4, 27, 30]\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], [2, 1, 2, 1, 2, 1]],queries = [1, 2, 3]) == [0, 1, 36]\n assert candidate(grid = [[1, 3, 2, 4, 3], [2, 4, 3, 5, 4], [3, 5, 4, 6, 5], [4, 6, 5, 7, 6], [5, 7, 6, 8, 7]],queries = [2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 6, 12, 17, 21, 24, 25]\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10]],queries = [6, 10, 15, 20]) == [10, 18, 20, 20]\n assert candidate(grid = [[1, 2, 3, 4, 5], [10, 9, 8, 7, 6], [11, 12, 13, 14, 15], [20, 19, 18, 17, 16]],queries = [5, 10, 15, 20]) == [4, 9, 14, 19]\n assert candidate(grid = [[1, 3, 1, 4, 1], [2, 2, 4, 2, 4], [3, 5, 3, 5, 3], [4, 4, 5, 4, 4], [1, 1, 1, 1, 1]],queries = [2, 5, 7, 10]) == [1, 22, 25, 25]\n assert candidate(grid = [[1, 2, 3], [2, 1, 2], [3, 2, 1], [2, 1, 2], [1, 2, 3]],queries = [2, 3, 4]) == [1, 12, 15]\n assert candidate(grid = [[5, 2, 1, 2, 5], [1, 5, 2, 5, 1], [2, 1, 5, 1, 2], [5, 2, 1, 2, 5]],queries = [3, 4, 6, 7]) == [0, 0, 20, 20]\n assert candidate(grid = [[1, 5, 3, 8, 7], [2, 6, 4, 9, 8], [3, 7, 5, 10, 9], [4, 8, 6, 11, 10], [5, 9, 7, 12, 11]],queries = [1, 4, 7, 10, 13]) == [0, 3, 11, 20, 25]\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]],queries = [5, 15, 25, 30]) == [4, 14, 24, 25]\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]],queries = [6, 12, 18]) == [13, 25, 25]\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]],queries = [2, 3, 4]) == [16, 24, 25]\n assert candidate(grid = [[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]],queries = [2, 4, 6, 8, 10]) == [1, 25, 25, 25, 25]\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 2, 2, 2, 2, 1], [1, 2, 3, 3, 2, 1], [1, 2, 3, 3, 2, 1], [1, 2, 2, 2, 2, 1], [1, 1, 1, 1, 1, 1]],queries = [2, 3, 4]) == [20, 32, 36]\n assert candidate(grid = [[1, 2, 3, 4], [4, 3, 2, 1], [1, 2, 3, 4], [4, 3, 2, 1]],queries = [2, 4, 6, 8, 10]) == [1, 12, 16, 16, 16]\n assert candidate(grid = [[1, 3, 5, 7], [2, 4, 6, 8], [3, 5, 7, 9], [4, 6, 8, 10]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [0, 1, 2, 4, 6, 8, 10, 12, 14, 15]\n assert candidate(grid = [[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]],queries = [2, 4, 6, 8]) == [1, 6, 11, 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], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]],queries = [15, 25, 35]) == [14, 24, 30]\n assert candidate(grid = [[5, 3, 8, 6], [3, 4, 1, 5], [6, 1, 4, 3], [8, 5, 3, 7]],queries = [4, 6, 8, 10]) == [0, 11, 14, 16]\n assert candidate(grid = [[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]],queries = [1, 2, 3, 4]) == [0, 0, 0, 25]\n assert candidate(grid = [[1, 1, 1, 1000], [1, 1, 1000, 1], [1, 1000, 1, 1], [1000, 1, 1, 1]],queries = [500, 1001]) == [6, 16]\n assert candidate(grid = [[1, 10, 100], [10, 100, 1000], [100, 1000, 10000]],queries = [500, 50, 5]) == [6, 3, 1]\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]],queries = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == [0, 1, 2, 4, 6, 9, 11, 14, 16, 19, 21, 23, 24, 25, 25]\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]],queries = [90, 80, 70]) == [0, 0, 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]],queries = [1, 2, 3, 4, 5]) == [0, 10, 20, 30, 40]\n assert candidate(grid = [[1, 10, 3, 10, 5], [10, 9, 8, 7, 10], [6, 10, 2, 10, 4], [10, 10, 10, 10, 10], [5, 10, 7, 10, 9]],queries = [1, 5, 10, 15]) == [0, 1, 1, 25]\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]],queries = [5, 10, 15]) == [10, 23, 25]\n assert candidate(grid = [[1000000, 999999, 999998], [999997, 999996, 999995], [999994, 999993, 999992]],queries = [999999, 999998, 999997, 999996, 999995, 999994]) == [0, 0, 0, 0, 0, 0]\n assert candidate(grid = [[3, 2, 2, 3], [3, 1, 1, 3], [3, 2, 2, 3], [3, 3, 3, 3]],queries = [2, 4, 6, 8]) == [0, 16, 16, 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, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],queries = [1, 2, 3]) == [0, 40, 40]\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]],queries = [5, 15, 25, 35]) == [4, 14, 24, 34]\n assert candidate(grid = [[3, 1, 4, 1, 5, 9], [2, 6, 5, 3, 5, 9], [5, 8, 9, 7, 9, 3], [2, 8, 8, 4, 1, 9]],queries = [10, 20, 30, 40, 50]) == [24, 24, 24, 24, 24]\n", "comparison": "exact"}, "public_tests": ["[[1,2,3],[2,5,7],[3,5,1]]\n[5,6,2]", "[[5,2,1],[1,1,2]]\n[3]"], "hints": ["The queries are all given to you beforehand so you can answer them in any order you want.", "Sort the queries knowing their original order to be able to build the answer array.", "Run a BFS on the graph and answer the queries in increasing order."], "metadata": {"canonical_parameter_names": ["grid", "queries"], "leetcode_dataset_entry_point": "Solution().maxPoints", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:11+00:00", "tests_total": 103, "tests_dropped": 8, "flags": ["has_images"], "topic_tags": ["array", "two-pointers", "breadth-first-search", "union-find", "sorting", "heap-priority-queue", "matrix"]}, "language": "php", "interface": {"raw_signature": "function maxPoints($grid, $queries) {", "container": "Solution", "callable": "maxPoints", "parameters": [{"name": "grid", "type": "Integer[][]"}, {"name": "queries", "type": "Integer[]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2506, "task_id": "count-pairs-of-similar-strings", "difficulty": "Easy", "problem_description": "You are given a 0-indexed string array words.\n\nTwo strings are similar if they consist of the same characters.\n\n- For example, \"abca\" and \"cba\" are similar since both consist of characters 'a', 'b', and 'c'.\n- However, \"abacba\" and \"bcfd\" are not similar since they do not consist of the same characters.\n\nReturn the number of pairs (i, j) such that 0 <= i < j <= word.length - 1 and the two strings words[i] and words[j] are similar.\n\nExample 1:\n\nInput: words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]\nOutput: 2\nExplanation: There are 2 pairs that satisfy the conditions:\n- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.\n- i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.\n\nExample 2:\n\nInput: words = [\"aabb\",\"ab\",\"ba\"]\nOutput: 3\nExplanation: There are 3 pairs that satisfy the conditions:\n- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.\n- i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.\n- i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.\n\nExample 3:\n\nInput: words = [\"nba\",\"cba\",\"dba\"]\nOutput: 0\nExplanation: Since there does not exist any pair that satisfies the conditions, we return 0.\n\nConstraints:\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 100\n- words[i] consist of only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(words = ['aabbcc', 'abc', 'ab', 'a', 'b', 'c']) == 1\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'aab', 'aba', 'baa']) == 3\n assert candidate(words = ['aabbcc', 'abc', 'aabb', 'aaabbbcc', 'abcabc']) == 6\n assert candidate(words = ['a', 'b', 'c', 'd', 'e']) == 0\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'abc', 'abc']) == 1\n assert candidate(words = ['abcd', 'bcad', 'cabd', 'dabc']) == 6\n assert candidate(words = ['nba', 'cba', 'dba']) == 0\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']) == 15\n assert candidate(words = ['abcd', 'dcba', 'abdc', 'badc']) == 6\n assert candidate(words = ['aabb', 'ab', 'ba']) == 3\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl']) == 0\n assert candidate(words = ['aa', 'bb', 'cc', 'abc', 'cba', 'bca']) == 3\n assert candidate(words = ['a', 'b', 'c', 'd']) == 0\n assert candidate(words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']) == 0\n assert candidate(words = ['abc', 'abc', 'abc', 'abc']) == 6\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd']) == 10\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'aaa']) == 1\n assert candidate(words = ['abc', 'def', 'ghi']) == 0\n assert candidate(words = ['aba', 'aabb', 'abcd', 'bac', 'aabc']) == 2\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno']) == 0\n assert candidate(words = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba']) == 15\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'aabbcc', 'bbaacc', 'ccbaab', 'aabbbc']) == 45\n assert candidate(words = ['abcde', 'edcba', 'abc', 'bca', 'cab', 'deabc']) == 6\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba']) == 6\n assert candidate(words = ['aabbcc', 'abcabc', 'bcaabc', 'cababc', 'bcabac']) == 10\n assert candidate(words = ['aabbccddeeff', 'ffeeddccbbaa', 'abcdef', 'fedcba', 'efabcd', 'fedcba', 'abcdefg', 'gfedcba', 'hijklm', 'mlkjih']) == 17\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccaabb', 'aabbc', 'bbaac', 'ccaab', 'aaabb', 'aabbb', 'abbbb', 'bbbbb']) == 18\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']) == 0\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff', 'gggg', 'hhhh', 'iiii', 'jjjj']) == 0\n assert candidate(words = ['abcdefg', 'gfedcba', 'ghijklm', 'mlkjihg', 'nopqrst', 'tsrqpon', 'vwxyz', 'zyxwv', 'abcdabcd', 'efghijkl', 'mnopqrstuvw', 'xyzzyxwv', 'utsrqponmlkjihgfedcba']) == 6\n assert candidate(words = ['hello', 'olleh', 'world', 'dlrow', 'python', 'nohtyp', 'java', 'avaj', 'algorithm', 'mhtirogla', 'data', 'tatad', 'structure', 'erutcurts', 'example', 'elpmaxe', 'test', 'tset', 'code', 'edoc', 'challenge', 'egnellahc', 'interview', 'weivretni']) == 12\n assert candidate(words = ['xyzxyzxyz', 'zyxzyxzyx', 'yzxyzxyz', 'zyxyzxyz', 'xzyzxzyx', 'xyzzyxzyx', 'zyxzyxzyx', 'xyzzyxzyx', 'xzyzxzyx', 'xyzxyzxyz']) == 45\n assert candidate(words = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'aaaaa', 'bbbbb']) == 2\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abdg', 'abdh', 'abei', 'abdj', 'abcd', 'abcd']) == 3\n assert candidate(words = ['aabbcc', 'abc', 'ab', 'a', 'b', 'c', 'abcde', 'edcba', 'fghij', 'jihgf', 'mnopq', 'qpomn']) == 4\n assert candidate(words = ['abcd', 'dcba', 'cdab', 'bacd', 'cabd', 'abcd', 'acdb', 'bdac', 'bcda', 'dabc', 'adcb', 'cdba', 'bacd', 'abcd', 'bcad']) == 105\n assert candidate(words = ['abcd', 'dcba', 'abcd', 'dcba', 'abcd', 'abcd', 'abcd', 'dcba', 'dcba', 'abcd']) == 45\n assert candidate(words = ['xyz', 'zyx', 'abc', 'cab', 'bac', 'xyz', 'zyx']) == 9\n assert candidate(words = ['aaaa', 'aabb', 'abab', 'abba', 'baba', 'bbaa', 'baab', 'abab', 'aabb', 'abba']) == 36\n assert candidate(words = ['abc', 'bca', 'cab', 'xyz', 'zyx', 'yzx']) == 6\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'bc', 'cb', 'bd', 'db', 'cd', 'dc']) == 6\n assert candidate(words = ['abc', 'abcd', 'abcde', 'abcdef', 'abcdefg', 'abcdefgh', 'abcdefghi', 'abcdefghij']) == 0\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'xzy', 'yxz', 'zxy', 'xyzz', 'yzzx', 'zzxy', 'zzzx', 'zxzy', 'xzyz']) == 55\n assert candidate(words = ['unique', 'ueinque', 'qneuie', 'neiqueu', 'ienquue', 'enuiqueu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu', 'qieuenu', 'euniqeu', 'ueinqeu', 'neuiqeu', 'uieqneu', 'niuqueeu', 'eiunqueu', 'iuqeenu']) == 1431\n assert candidate(words = ['aaa', 'aa', 'a', 'b', 'bb', 'bbb', 'bbbb', 'bbbbb']) == 13\n assert candidate(words = ['abcd', 'abdc', 'acbd', 'acdb', 'adbc', 'adcb', 'bacd', 'badc', 'bcad', 'bcda', 'bdac', 'bdca', 'cabd', 'cadb', 'cbad', 'cbda', 'cdab', 'cdba', 'dabc', 'dacb', 'dbac', 'dbca', 'dcab', 'dcba']) == 276\n assert candidate(words = ['pqrst', 'rstqp', 'qrstp', 'srtpq', 'tsrqp', 'tspqr', 'pqrst', 'rstqp', 'qrstp', 'srtpq', 'tsrqp', 'tspqr']) == 66\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abc', 'acb', 'bac', 'bca']) == 45\n assert candidate(words = ['abc', 'abd', 'abe', 'abf', 'abg', 'abh', 'abi', 'abj', 'abk', 'abl', 'abm', 'abn', 'abo', 'abp', 'abq', 'abr', 'abs', 'abt', 'abu', 'abv', 'abw', 'abx', 'aby', 'abz']) == 0\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba']) == 15\n assert candidate(words = ['xyz', 'zyx', 'zyx', 'xyz', 'yxxz', 'zyxz', 'xzyz', 'yxzz', 'zxzy', 'zyzz', 'zzzy', 'zyyz', 'zyzx', 'xzyz', 'zzyx', 'zyxz', 'zyzx', 'zyxz', 'zyzx', 'zyxz', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx', 'zyzx']) == 744\n assert candidate(words = ['abcdefg', 'gfedcba', 'hijklmn', 'nmkljih', 'opqrstu', 'utsrqpo', 'vwxyz', 'zyxwv', 'abcdefg', 'gfedcba', 'hijklmn', 'nmkljih', 'opqrstu', 'utsrqpo', 'vwxyz', 'zyxwv']) == 24\n assert candidate(words = ['abc', 'bca', 'cab', 'xyz', 'zyx', 'yxz']) == 6\n assert candidate(words = ['abacabadabacaba', 'bacbacbacbacbac', 'cabacabacabacab', 'abcabcabcabcabc', 'bcbcbcbcbcbcb', 'cbcbcbcbcbcbc']) == 4\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'abc', 'bca', 'cab', 'abc', 'bca', 'cab']) == 15\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'abaa', 'baaa', 'bbaa', 'bbba', 'bbbb']) == 15\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba', 'mnopqrstuvwxyzabcdefghijkl']) == 3\n assert candidate(words = ['abcd', 'abce', 'abcf', 'abdg', 'abdh', 'abdi', 'abdj', 'abcd']) == 1\n assert candidate(words = ['aabbcc', 'abcabc', 'bcaabc', 'cababc', 'aabbcc', 'bbaacc', 'ccbaab']) == 21\n assert candidate(words = ['xyz', 'zyx', 'yxz', 'zxy', 'xzy', 'yzx']) == 15\n assert candidate(words = ['xyz', 'zyx', 'yxz', 'xzy', 'yzx', 'zxy', 'abc', 'bca', 'cab', 'aaa', 'bbb', 'ccc', 'aba', 'bab', 'aab', 'abb', 'baa', 'bba', 'abb', 'aab', 'abc', 'bcd', 'cde', 'def', 'efg', 'fgh', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn', 'mno', 'nop', 'opq', 'pqr', 'qrs', 'rst', 'stu', 'tuv', 'uvw', 'vwx', 'wxy', 'xyz']) == 55\n assert candidate(words = ['xyz', 'zyx', 'yzx', 'xzy', 'yxz', 'zxy', 'zyxw', 'wxyz']) == 16\n assert candidate(words = ['mnop', 'mnopqr', 'mnopqrs', 'mnopqrst', 'mnopqrstuv', 'mnopqrstuvw', 'mnopqrstuvwx', 'mnopqrstuvwxy', 'mnopqrstuvwxyz']) == 0\n assert candidate(words = ['abcabc', 'bcabc', 'cabc', 'abc', 'bca', 'cab', 'aabbcc', 'bbccaa', 'ccaabb']) == 36\n assert candidate(words = ['abcde', 'edcba', 'bcdea', 'deabc', 'cdeab']) == 10\n assert candidate(words = ['abcdef', 'fedcba', 'ghijkl', 'lkjhgf', 'mnopqr', 'rqponm', 'stuvwx', 'xwvuts', 'yz', 'zy']) == 4\n assert candidate(words = ['pqr', 'qrp', 'prq', 'rpq', 'rqp', 'pqr', 'abc', 'cab', 'bac', 'abcde', 'edcba', 'fghij', 'jihgf', 'mnopq', 'qpomn']) == 21\n assert candidate(words = ['abc', 'abcd', 'abce', 'abcf', 'abcg', 'abch', 'abci', 'abcj', 'abck', 'abcl', 'abcm', 'abcn', 'abco', 'abcp', 'abcq', 'abcr', 'abcs', 'abct', 'abcu', 'abcv', 'abcw', 'abcx', 'abcy', 'abcz']) == 0\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'bc', 'cb', 'bd', 'db', 'cd', 'dc', 'abcd', 'dcba', 'cdab', 'bacd', 'cabd', 'acbd', 'cadb', 'abcd', 'dcba', 'cdab', 'bacd', 'cabd', 'acbd', 'cadb']) == 97\n assert candidate(words = ['abcabcabc', 'bcbcbcbc', 'cacacac', 'abababab', 'babababa', 'acacacac', 'abcabcabc', 'bcbcbcbc', 'cacacac', 'abababab']) == 8\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'zyx']) == 0\n assert candidate(words = ['abcdabcdabcdabcdabcdabcdabcdabcd', 'bcadbcadbcadbcadbcadbcadbcadbcad', 'cdabcdabcdabcdabcdabcdabcdabcdabc', 'dcbadcbadcbadcbadcbadcbadcbadcba', 'abcdabcdabcdabcdabcdabcdabcdabcde']) == 6\n assert candidate(words = ['apple', 'pale', 'pplea', 'elppa', 'ppale', 'pleap']) == 15\n assert candidate(words = ['aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff', 'gggg', 'hhhh', 'iiii', 'jjjj']) == 0\n assert candidate(words = ['abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba']) == 276\n assert candidate(words = ['mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq', 'mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq', 'mnopqr', 'nopqrm', 'opqrmn', 'pqrmno', 'qrmnop', 'rmnopq']) == 153\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz']) == 0\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'uvw', 'rst', 'qpo', 'nml', 'kji', 'fed', 'cba', 'zyx', 'wvu', 'tsr', 'pon', 'mlk', 'jih', 'gf', 'de', 'abc']) == 6\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']) == 0\n assert candidate(words = ['aaa', 'bbb', 'ccc', 'abc', 'bca', 'cab', 'aab', 'aba', 'baa', 'bbc', 'bcb', 'cbb', 'acc', 'cac', 'cca']) == 12\n assert candidate(words = ['abcdef', 'fedcba', 'bcdefa', 'defabc', 'efabcd', 'fabcde', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'uvw', 'rst', 'qpo', 'nml', 'kji', 'fed', 'cba', 'zyx', 'wvu', 'tsr', 'pon', 'mlk', 'jih', 'gf', 'de', 'abc']) == 21\n assert candidate(words = ['abcde', 'edcba', 'fghij', 'jihgf', 'abcde', 'edcba']) == 7\n assert candidate(words = ['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz']) == 45\n assert candidate(words = ['aabbcc', 'abcabc', 'ababab', 'acacac', 'bcbcbc', 'bacbac', 'cabcab', 'abcabcabc', 'xyzxyzxyz', 'zyxzyxzyx']) == 11\n assert candidate(words = ['abcdefg', 'gfedcba', 'fedcbag', 'bagfedc', 'abcdefg', 'gfedcba', 'fedcbag', 'bagfedc', 'abcdefg', 'gfedcba']) == 45\n assert candidate(words = ['abcdefghij', 'jihgfedcba', 'abcdefghij', 'jihgfedcba', 'abcdefghij', 'jihgfedcba']) == 15\n assert candidate(words = ['abcdef', 'fedcba', 'defabc', 'cabfed', 'bcadef', 'fedcba', 'abcdef', 'abcdef']) == 28\n assert candidate(words = ['abcde', 'edcba', 'cdeab', 'decba', 'bacde', 'ecbad', 'abcd', 'dcba', 'abc', 'bca', 'cab', 'acb', 'bac', 'cba', 'a', 'b', 'c', 'd', 'e']) == 31\n assert candidate(words = ['aabbcc', 'aabbc', 'aabc', 'abc', 'ab', 'a', 'b', 'bb', 'bbb', 'bbbb', 'bbbbb', 'bbbbb', 'bbbb', 'bbb', 'bb', 'b']) == 51\n assert candidate(words = ['same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']) == 3403\n assert candidate(words = ['ab', 'ac', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au', 'av', 'aw', 'ax', 'ay', 'az']) == 0\n assert candidate(words = ['xyz', 'yzx', 'zxy', 'zyx', 'yxz', 'xzy', 'abc', 'cab', 'bca']) == 18\n assert candidate(words = ['abc', 'abcabc', 'abcabcabc', 'abcabcabcabc', 'abcabcabcabcabc', 'abcabcabcabcabcabc', 'abcabcabcabcabcabcabc', 'abcabcabcabcabcabcabcabc']) == 28\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']) == 26\n assert candidate(words = ['test', 'sett', 'stet', 'tset', 'ttes', 'etts', 'etst', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste', 'stte', 'ttse', 'tste']) == 3828\n assert candidate(words = ['ab', 'ba', 'ac', 'ca', 'ad', 'da', 'bc', 'cb', 'bd', 'db', 'cd', 'dc', 'abcd', 'dcba', 'cdab', 'bacd', 'cabd', 'abcd', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba', 'ab', 'ba', 'ac', 'ca', 'ad', 'da', 'bc', 'cb', 'bd', 'db', 'cd', 'dc', 'abcd', 'dcba', 'cdab', 'bacd', 'cabd', 'abcd']) == 117\n assert candidate(words = ['aaaa', 'aaab', 'aaba', 'aabb', 'abaa', 'abab', 'abba', 'abbb', 'baaa', 'baab', 'baba', 'babb', 'bbaa', 'bbab', 'bbba', 'bbbb']) == 91\n assert candidate(words = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz', 'aabbcc', 'ddeeff', 'gghhiijj', 'kkllmm', 'nnoopp', 'qqrrss', 'ttuuvv', 'wwxxyy', 'zz', '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']) == 3\n assert candidate(words = ['aabbcc', 'bbaacc', 'ccbbaa', 'aabbcc', 'bbaacc', 'ccbbaa', 'aabbbc', 'bbaacc', 'ccbbaa', 'aabbbc', 'bbaacc', 'ccbbaa']) == 66\n assert candidate(words = ['hello', 'olleh', 'ohell', 'loleh', 'ehlol', 'llohe', 'world', 'dlrow', 'owrld', 'rldwo', 'ldwor', 'dworld', 'wolrd', 'orldw', 'lrwod', 'rwdol', 'dlorw', 'lorwd', 'rowdl', 'owrld', 'dlrow', 'world', 'dlrow', 'owrld', 'rldwo', 'ldwor', 'dworld', 'wolrd', 'orldw', 'lrwod', 'rwdol', 'dlorw', 'lorwd', 'rowdl', 'owrld', 'dlrow', 'world', 'dlrow', 'owrld', 'rldwo', 'ldwor', 'dworld', 'wolrd', 'orldw', 'lrwod', 'rwdol', 'dlorw', 'lorwd', 'rowdl', 'owrld']) == 961\n", "comparison": "exact"}, "public_tests": ["[\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]", "[\"aabb\",\"ab\",\"ba\"]", "[\"nba\",\"cba\",\"dba\"]"], "hints": ["How can you check if two strings are similar?", "Use a hashSet to store the character of each string."], "metadata": {"canonical_parameter_names": ["words"], "leetcode_dataset_entry_point": "Solution().similarPairs", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:15+00:00", "tests_total": 101, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "bit-manipulation", "counting"]}, "language": "php", "interface": {"raw_signature": "function similarPairs($words) {", "container": "Solution", "callable": "similarPairs", "parameters": [{"name": "words", "type": "String[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2507, "task_id": "smallest-value-after-replacing-with-sum-of-prime-factors", "difficulty": "Medium", "problem_description": "You are given a positive integer n.\n\nContinuously replace n with the sum of its prime factors.\n\n- Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.\n\nReturn the smallest value n will take on.\n\nExample 1:\n\nInput: n = 15\nOutput: 5\nExplanation: Initially, n = 15.\n15 = 3 * 5, so replace n with 3 + 5 = 8.\n8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.\n6 = 2 * 3, so replace n with 2 + 3 = 5.\n5 is the smallest value n will take on.\n\nExample 2:\n\nInput: n = 3\nOutput: 3\nExplanation: Initially, n = 3.\n3 is the smallest value n will take on.\n\nConstraints:\n\n- 2 <= n <= 10^5\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 15) == 5\n assert candidate(n = 100) == 5\n assert candidate(n = 44) == 5\n assert candidate(n = 28) == 11\n assert candidate(n = 97) == 97\n assert candidate(n = 99999) == 31\n assert candidate(n = 729) == 5\n assert candidate(n = 12345) == 5\n assert candidate(n = 49) == 5\n assert candidate(n = 104) == 19\n assert candidate(n = 841) == 31\n assert candidate(n = 1009) == 1009\n assert candidate(n = 60) == 7\n assert candidate(n = 6857) == 6857\n assert candidate(n = 72) == 7\n assert candidate(n = 13195) == 11\n assert candidate(n = 225) == 5\n assert candidate(n = 720) == 19\n assert candidate(n = 128) == 5\n assert candidate(n = 1024) == 5\n assert candidate(n = 100000) == 7\n assert candidate(n = 789) == 11\n assert candidate(n = 2048) == 13\n assert candidate(n = 999) == 7\n assert candidate(n = 2310) == 11\n assert candidate(n = 65536) == 7\n assert candidate(n = 169) == 5\n assert candidate(n = 256) == 5\n assert candidate(n = 77) == 5\n assert candidate(n = 81) == 7\n assert candidate(n = 97531) == 67\n assert candidate(n = 99998) == 5\n assert candidate(n = 1234) == 619\n assert candidate(n = 3125) == 7\n assert candidate(n = 8898) == 7\n assert candidate(n = 121) == 13\n assert candidate(n = 500) == 19\n assert candidate(n = 54321) == 5\n assert candidate(n = 84) == 5\n", "comparison": "exact"}, "public_tests": ["15", "3"], "hints": ["Every time you replace n, it will become smaller until it is a prime number, where it will keep the same value each time you replace it.", "n decreases logarithmically, allowing you to simulate the process.", "To find the prime factors, iterate through all numbers less than n from least to greatest and find the maximum number of times each number divides n."], "metadata": {"canonical_parameter_names": ["n"], "leetcode_dataset_entry_point": "Solution().smallestValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:18+00:00", "tests_total": 45, "tests_dropped": 5, "flags": [], "topic_tags": ["math", "simulation", "number-theory", "prime-factorization", "primality-test", "sieve-theory", "prime-number-sieve"]}, "language": "php", "interface": {"raw_signature": "function smallestValue($n) {", "container": "Solution", "callable": "smallestValue", "parameters": [{"name": "n", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2508, "task_id": "add-edges-to-make-degrees-of-all-nodes-even", "difficulty": "Hard", "problem_description": "There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i. The graph can be disconnected.\n\nYou can add at most two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops.\n\nReturn true if it is possible to make the degree of each node in the graph even, otherwise return false.\n\nThe degree of a node is the number of edges connected to it.\n\nExample 1:\n\nInput: n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]\nOutput: true\nExplanation: The above diagram shows a valid way of adding an edge.\nEvery node in the resulting graph is connected to an even number of edges.\n\nExample 2:\n\nInput: n = 4, edges = [[1,2],[3,4]]\nOutput: true\nExplanation: The above diagram shows a valid way of adding two edges.\n\nExample 3:\n\nInput: n = 4, edges = [[1,2],[1,3],[1,4]]\nOutput: false\nExplanation: It is not possible to obtain a valid graph with adding at most 2 edges.\n\nConstraints:\n\n- 3 <= n <= 10^5\n- 2 <= edges.length <= 10^5\n- edges[i].length == 2\n- 1 <= a_i, b_i <= n\n- a_i != b_i\n- There are no repeated edges.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 4,edges = [[1, 2], [1, 3], [1, 4]]) == False\n assert candidate(n = 7,edges = [[1, 2], [3, 4], [5, 6], [6, 7]]) == False\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]) == True\n assert candidate(n = 4,edges = [[1, 2], [3, 4]]) == True\n assert candidate(n = 6,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) == True\n assert candidate(n = 8,edges = [[1, 2], [3, 4], [5, 6], [7, 8]]) == False\n assert candidate(n = 5,edges = [[1, 2], [2, 3], [3, 4], [4, 2], [1, 4], [2, 5]]) == True\n assert candidate(n = 7,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) == True\n assert candidate(n = 8,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [1, 3], [5, 7]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == True\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 1], [1, 3], [4, 6], [7, 9]]) == False\n assert candidate(n = 14,edges = [[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], [1, 5], [2, 6], [3, 7], [4, 8], [9, 11], [10, 12], [13, 1]]) == False\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [4, 6]]) == True\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 13], [13, 14], [14, 10], [15, 1]]) == True\n assert candidate(n = 13,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 1], [2, 13], [4, 13], [6, 13], [8, 13], [10, 13], [12, 13]]) == False\n assert candidate(n = 11,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [4, 9], [5, 10], [5, 11], [6, 7], [8, 9], [10, 11]]) == True\n assert candidate(n = 7,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 7], [7, 4], [1, 4], [2, 5], [3, 6]]) == False\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == True\n assert candidate(n = 15,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 9], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14], [7, 15], [8, 9]]) == False\n assert candidate(n = 14,edges = [[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], [6, 14], [7, 14]]) == False\n assert candidate(n = 15,edges = [[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]]) == True\n assert candidate(n = 10,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [1, 3], [2, 4], [5, 7], [6, 8], [7, 9], [8, 10]]) == True\n assert candidate(n = 14,edges = [[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]]) == True\n assert candidate(n = 25,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [21, 22], [22, 23], [23, 24], [24, 25], [25, 21]]) == True\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [7, 8], [7, 9], [8, 9], [1, 4], [2, 5], [3, 6]]) == False\n assert candidate(n = 13,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], [8, 9], [10, 11], [12, 13]]) == True\n assert candidate(n = 20,edges = [[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]]) == True\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8]]) == True\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [1, 9], [2, 4], [3, 5], [6, 8]]) == False\n assert candidate(n = 7,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [3, 7], [4, 7], [5, 6]]) == True\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1]]) == True\n assert candidate(n = 13,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [1, 3], [2, 4], [5, 7], [6, 8], [9, 11], [10, 12]]) == False\n assert candidate(n = 14,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 11], [1, 12], [2, 13], [3, 14], [4, 6], [5, 7]]) == False\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8, 10]]) == True\n assert candidate(n = 13,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8], [9, 10], [10, 11], [11, 12], [12, 13], [13, 9], [1, 9], [2, 10], [3, 11], [4, 12], [5, 13], [6, 9], [7, 10], [8, 11]]) == True\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20]]) == False\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 13], [13, 10], [14, 15], [15, 14]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10]]) == True\n assert candidate(n = 10,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) == False\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9]]) == False\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [1, 5], [2, 6], [3, 7], [4, 8], [9, 12]]) == False\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 4], [5, 8]]) == True\n assert candidate(n = 11,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]) == True\n assert candidate(n = 20,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]) == False\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 1]]) == True\n assert candidate(n = 11,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [1, 11]]) == True\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]) == True\n assert candidate(n = 14,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 6]]) == True\n assert candidate(n = 11,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 1]]) == True\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7], [4, 8], [5, 8]]) == True\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [1, 8]]) == True\n assert candidate(n = 11,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [1, 11], [2, 5], [3, 7], [4, 8]]) == False\n assert candidate(n = 18,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [17, 18]]) == False\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1], [1, 3], [5, 7]]) == True\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 1], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12]]) == True\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11]]) == True\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [3, 8], [4, 9], [4, 10]]) == False\n assert candidate(n = 16,edges = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16], [1, 3], [1, 5], [1, 7], [1, 9], [1, 11], [1, 13], [1, 15]]) == False\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6]]) == True\n assert candidate(n = 12,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10]]) == True\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [1, 4], [2, 5], [3, 6]]) == False\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [10, 11], [11, 12], [12, 10], [13, 14], [14, 15], [15, 13]]) == True\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 8]]) == True\n assert candidate(n = 16,edges = [[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, 1]]) == True\n assert candidate(n = 9,edges = [[1, 2], [3, 4], [5, 6], [7, 8]]) == False\n assert candidate(n = 14,edges = [[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]]) == True\n assert candidate(n = 20,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 4], [11, 12], [12, 13], [13, 14], [14, 15], [15, 11], [16, 17], [17, 18], [18, 19], [19, 20], [20, 16], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20]]) == False\n assert candidate(n = 7,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 5]]) == True\n assert candidate(n = 10,edges = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [9, 10]]) == False\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1], [1, 3], [2, 4], [5, 7], [6, 8]]) == False\n assert candidate(n = 8,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [7, 8]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 1], [4, 5], [5, 6], [6, 4], [7, 8], [8, 9], [9, 7], [1, 5], [2, 6], [3, 4], [7, 10]]) == False\n assert candidate(n = 8,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 1]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == True\n assert candidate(n = 9,edges = [[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9]]) == True\n assert candidate(n = 12,edges = [[1, 2], [2, 3], [3, 4], [4, 1], [5, 6], [6, 7], [7, 8], [8, 5], [9, 10], [10, 11], [11, 12], [12, 9]]) == True\n assert candidate(n = 9,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 1], [1, 3], [3, 5], [5, 7], [7, 9]]) == True\n assert candidate(n = 10,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 10], [1, 10]]) == True\n assert candidate(n = 15,edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 1], [6, 7], [7, 8], [8, 9], [9, 6], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 10]]) == True\n assert candidate(n = 6,edges = [[1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [5, 6], [1, 4], [2, 5], [3, 6]]) == False\n", "comparison": "exact"}, "public_tests": ["5\n[[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]", "4\n[[1,2],[3,4]]", "4\n[[1,2],[1,3],[1,4]]"], "hints": ["Notice that each edge that we add changes the degree of exactly 2 nodes.", "The number of nodes with an odd degree in the original graph should be either 0, 2, or 4. Try to work on each of these cases."], "metadata": {"canonical_parameter_names": ["n", "edges"], "leetcode_dataset_entry_point": "Solution().isPossible", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:20+00:00", "tests_total": 82, "tests_dropped": 0, "flags": ["has_images"], "topic_tags": ["hash-table", "graph"]}, "language": "php", "interface": {"raw_signature": "function isPossible($n, $edges) {", "container": "Solution", "callable": "isPossible", "parameters": [{"name": "n", "type": "Integer"}, {"name": "edges", "type": "Integer[][]"}], "return_type": "Boolean", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2509, "task_id": "cycle-length-queries-in-a-tree", "difficulty": "Hard", "problem_description": "You are given an integer n. There is a complete binary tree with 2^n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2^{n - 1} - 1] has two children where:\n\n- The left node has the value 2 * val, and\n- The right node has the value 2 * val + 1.\n\nYou are also given a 2D integer array queries of length m, where queries[i] = [a_i, b_i]. For each query, solve the following problem:\n\n1. Add an edge between the nodes with values a_i and b_i.\n2. Find the length of the cycle in the graph.\n3. Remove the added edge between nodes with values a_i and b_i.\n\nNote that:\n\n- A cycle is a path that starts and ends at the same node, and each edge in the path is visited only once.\n- The length of a cycle is the number of edges visited in the cycle.\n- There could be multiple edges between two nodes in the tree after adding the edge of the query.\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 = 3, queries = [[5,3],[4,7],[2,3]]\nOutput: [4,5,3]\nExplanation: The diagrams above show the tree of 2^3 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n- After adding the edge between nodes 3 and 5, the graph contains a cycle of nodes [5,2,1,3]. Thus answer to the first query is 4. We delete the added edge and process the next query.\n- After adding the edge between nodes 4 and 7, the graph contains a cycle of nodes [4,2,1,3,7]. Thus answer to the second query is 5. We delete the added edge and process the next query.\n- After adding the edge between nodes 2 and 3, the graph contains a cycle of nodes [2,1,3]. Thus answer to the third query is 3. We delete the added edge.\n\nExample 2:\n\nInput: n = 2, queries = [[1,2]]\nOutput: [2]\nExplanation: The diagram above shows the tree of 2^2 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n- After adding the edge between nodes 1 and 2, the graph contains a cycle of nodes [2,1]. Thus answer for the first query is 2. We delete the added edge.\n\nConstraints:\n\n- 2 <= n <= 30\n- m == queries.length\n- 1 <= m <= 10^5\n- queries[i].length == 2\n- 1 <= a_i, b_i <= 2^n - 1\n- a_i != b_i\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(n = 5,queries = [[31, 15], [10, 18], [9, 20]]) == [2, 6, 6]\n assert candidate(n = 3,queries = [[5, 3], [4, 7], [2, 3]]) == [4, 5, 3]\n assert candidate(n = 5,queries = [[15, 7], [10, 14], [3, 12]]) == [2, 7, 3]\n assert candidate(n = 30,queries = [[1073741823, 1], [536870912, 2], [268435456, 4]]) == [30, 29, 27]\n assert candidate(n = 4,queries = [[8, 4], [7, 3], [1, 14]]) == [2, 2, 4]\n assert candidate(n = 4,queries = [[1, 15], [14, 2], [12, 10], [6, 3]]) == [4, 5, 7, 2]\n assert candidate(n = 2,queries = [[1, 2]]) == [2]\n assert candidate(n = 5,queries = [[3, 15], [16, 7], [8, 9]]) == [3, 7, 3]\n assert candidate(n = 6,queries = [[32, 1], [16, 15], [8, 7], [4, 3], [2, 1]]) == [6, 8, 6, 4, 2]\n assert candidate(n = 4,queries = [[8, 4], [6, 10], [5, 9]]) == [2, 6, 4]\n assert candidate(n = 19,queries = [[262144, 524287], [131072, 262143], [65536, 131071], [32768, 65535], [16384, 32767], [8192, 16383], [4096, 8191], [2048, 4095], [1024, 2047], [512, 1023], [256, 511], [128, 255], [64, 127], [32, 63], [16, 31], [8, 15], [4, 7], [2, 3]]) == [37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3]\n assert candidate(n = 10,queries = [[511, 1], [256, 2], [128, 4], [64, 8], [32, 16], [16, 32], [8, 64], [4, 128], [2, 256], [1, 511], [511, 256], [256, 128], [128, 64], [64, 32], [32, 16], [16, 8], [8, 4], [4, 2], [2, 1], [511, 510], [510, 509], [509, 508], [508, 507], [507, 506], [506, 505]]) == [9, 8, 6, 4, 2, 2, 4, 6, 8, 9, 17, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 3, 7, 3, 5]\n assert candidate(n = 18,queries = [[131071, 1], [65536, 2], [32768, 4], [16384, 8], [8192, 16], [4096, 32], [2048, 64], [1024, 128], [512, 256], [256, 512], [128, 1024], [64, 2048], [32, 4096], [16, 8192], [8, 16384], [4, 32768], [2, 65536], [1, 131071]]) == [17, 16, 14, 12, 10, 8, 6, 4, 2, 2, 4, 6, 8, 10, 12, 14, 16, 17]\n assert candidate(n = 15,queries = [[32767, 16384], [8192, 4096], [2048, 1024], [512, 256], [128, 64]]) == [29, 2, 2, 2, 2]\n assert candidate(n = 22,queries = [[4194303, 2097152], [2097151, 1048576], [1048575, 524288], [524287, 262144], [262143, 131072], [131071, 65536], [65535, 32768], [32767, 16384], [16383, 8192]]) == [43, 41, 39, 37, 35, 33, 31, 29, 27]\n assert candidate(n = 25,queries = [[33554431, 16777216], [16777216, 8388608], [8388608, 4194304], [4194304, 2097152], [2097152, 1048576], [1048576, 524288], [524288, 262144], [262144, 131072], [131072, 65536], [65536, 32768], [32768, 16384], [16384, 8192], [8192, 4096], [4096, 2048], [2048, 1024], [1024, 512], [512, 256], [256, 128], [128, 64], [64, 32], [32, 16], [16, 8], [8, 4], [4, 2], [2, 1]]) == [49, 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 = 20,queries = [[1048575, 524288], [524287, 262144], [262143, 131072], [131071, 65536], [65535, 32768]]) == [39, 37, 35, 33, 31]\n assert candidate(n = 15,queries = [[16383, 1], [8192, 3], [4096, 7], [2048, 15], [1024, 31]]) == [14, 15, 15, 15, 15]\n assert candidate(n = 12,queries = [[4095, 1], [2047, 2], [1023, 4], [511, 8], [255, 16], [127, 32], [63, 64], [31, 128], [15, 256], [7, 512], [3, 1024], [1, 2048], [4094, 4095], [2046, 2047], [1022, 1023], [510, 511], [254, 255], [126, 127], [62, 63], [30, 31], [14, 15], [6, 7], [2, 3], [1, 2], [4093, 1], [2045, 2], [1021, 4], [509, 8], [253, 16], [125, 32], [61, 64], [30, 128], [14, 256], [6, 512], [2, 1024], [1, 2048]]) == [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 10, 12]\n assert candidate(n = 15,queries = [[16384, 32767], [8192, 16383], [4096, 8191], [2048, 4095], [1024, 2047], [512, 1023]]) == [29, 27, 25, 23, 21, 19]\n assert candidate(n = 10,queries = [[511, 256], [1023, 512], [768, 384], [255, 128], [127, 64]]) == [17, 19, 2, 15, 13]\n assert candidate(n = 10,queries = [[1023, 511], [511, 255], [255, 127], [127, 63], [63, 31], [31, 15], [15, 7], [7, 3], [3, 1]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 10,queries = [[512, 1], [256, 2], [128, 4], [64, 8], [32, 16], [16, 32], [8, 64], [4, 128], [2, 256], [1, 512]]) == [10, 8, 6, 4, 2, 2, 4, 6, 8, 10]\n assert candidate(n = 12,queries = [[4095, 2048], [2048, 1024], [1024, 512], [512, 256], [256, 128], [128, 64], [64, 32], [32, 16], [16, 8], [8, 4], [4, 2], [2, 1], [4095, 2047], [2047, 2046], [2046, 2045], [2045, 2044], [2044, 2043], [2043, 2042], [2042, 2041], [2041, 2040], [2040, 2039], [2039, 2038], [2038, 2037], [2037, 2036], [2036, 2035], [2035, 2034], [2034, 2033], [2033, 2032], [2032, 2031]]) == [23, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 3, 7, 3, 5, 3, 9, 3, 5, 3, 7, 3, 5, 3, 11]\n assert candidate(n = 15,queries = [[16383, 1], [8191, 2], [4095, 4], [2047, 8], [1023, 16], [511, 32], [255, 64], [127, 128], [63, 256], [31, 512], [15, 1024], [7, 2048], [3, 4096], [1, 8192], [16382, 16383], [8190, 8191], [4094, 4095], [2046, 2047], [1022, 1023], [510, 511], [254, 255], [126, 127], [62, 63], [30, 31], [14, 15], [6, 7], [2, 3], [1, 2]]) == [14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]\n assert candidate(n = 20,queries = [[1048575, 1], [524288, 2], [262144, 4], [131072, 8], [65536, 16], [32768, 32], [16384, 64], [8192, 128], [4096, 256], [2048, 512]]) == [20, 19, 17, 15, 13, 11, 9, 7, 5, 3]\n assert candidate(n = 17,queries = [[65535, 32768], [16384, 8192], [4096, 2048], [1024, 512], [256, 128], [64, 32], [16, 8], [4, 2], [2, 1], [65535, 1], [32768, 2], [16384, 4], [8192, 8], [4096, 16], [2048, 32], [1024, 64], [512, 128]]) == [31, 2, 2, 2, 2, 2, 2, 2, 2, 16, 15, 13, 11, 9, 7, 5, 3]\n assert candidate(n = 12,queries = [[4095, 1], [2048, 3], [1024, 7], [512, 15], [256, 31], [128, 63], [64, 127], [32, 255], [16, 511], [8, 1023], [4, 2047], [2, 4095]]) == [12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13]\n assert candidate(n = 27,queries = [[134217727, 67108864], [67108863, 33554432], [33554431, 16777216], [16777215, 8388608], [8388607, 4194304], [4194303, 2097152], [2097151, 1048576], [1048575, 524288], [524287, 262144], [262143, 131072], [131071, 65536], [65535, 32768], [32767, 16384], [16383, 8192], [8191, 4096], [4095, 2048], [2047, 1024], [1023, 512], [511, 256], [255, 128], [127, 64], [63, 32], [31, 16], [15, 8], [7, 4], [3, 2], [1, 2]]) == [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, 2]\n assert candidate(n = 25,queries = [[16777215, 8388608], [4194304, 2097152], [2097152, 1048576], [1048576, 524288], [524288, 262144], [262144, 131072], [131072, 65536], [65536, 32768], [32768, 16384], [16384, 8192]]) == [47, 2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 18,queries = [[131071, 65536], [32768, 16384], [8192, 4096], [2048, 1024], [512, 256], [128, 64], [32, 16], [8, 4], [2, 1], [131071, 1], [65536, 2], [32768, 4], [16384, 8]]) == [33, 2, 2, 2, 2, 2, 2, 2, 2, 17, 16, 14, 12]\n assert candidate(n = 25,queries = [[33554431, 16777216], [16777215, 8388608], [8388607, 4194304], [4194303, 2097152], [2097151, 1048576]]) == [49, 47, 45, 43, 41]\n assert candidate(n = 10,queries = [[511, 256], [128, 64], [32, 16], [8, 4], [4, 2], [2, 1], [128, 1], [256, 32], [511, 64]]) == [17, 2, 2, 2, 2, 2, 8, 4, 15]\n assert candidate(n = 25,queries = [[33554431, 16777216], [8388608, 4194304], [2097152, 1048576], [524288, 262144], [131072, 65536]]) == [49, 2, 2, 2, 2]\n assert candidate(n = 20,queries = [[524287, 262144], [131072, 65536], [32768, 16384], [8192, 4096], [2048, 1024], [512, 256], [128, 64], [32, 16], [8, 4]]) == [37, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 25,queries = [[16777216, 8388608], [8388608, 4194304], [4194304, 2097152], [2097152, 1048576], [1048576, 524288]]) == [2, 2, 2, 2, 2]\n assert candidate(n = 20,queries = [[1048575, 1], [524288, 2], [262144, 4], [131072, 8], [65536, 16]]) == [20, 19, 17, 15, 13]\n assert candidate(n = 18,queries = [[262143, 131072], [131071, 65536], [65535, 32768], [32767, 16384], [16383, 8192], [8191, 4096], [4095, 2048], [2047, 1024], [1023, 512]]) == [35, 33, 31, 29, 27, 25, 23, 21, 19]\n assert candidate(n = 18,queries = [[131072, 262143], [65536, 131071], [32768, 65535], [16384, 32767], [8192, 16383], [4096, 8191], [2048, 4095], [1024, 2047]]) == [35, 33, 31, 29, 27, 25, 23, 21]\n assert candidate(n = 25,queries = [[33554431, 16777216], [16777215, 8388608], [8388607, 4194304], [4194303, 2097152], [2097151, 1048576]]) == [49, 47, 45, 43, 41]\n assert candidate(n = 18,queries = [[262143, 1], [131072, 3], [65536, 7], [32768, 15], [16384, 31], [8192, 63], [4096, 127], [2048, 255], [1024, 511], [512, 1023], [256, 2047], [128, 4095], [64, 8191], [32, 16383], [16, 32767], [8, 65535], [4, 131071], [2, 262143]]) == [18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19]\n assert candidate(n = 15,queries = [[16383, 16384], [8192, 12287], [4096, 6143], [2048, 8192], [1024, 4096]]) == [28, 25, 23, 3, 3]\n assert candidate(n = 22,queries = [[2097152, 4194303], [1048576, 2097151], [524288, 1048575], [262144, 524287], [131072, 262143], [65536, 131071], [32768, 65535], [16384, 32767]]) == [43, 41, 39, 37, 35, 33, 31, 29]\n assert candidate(n = 25,queries = [[33554431, 1], [16777216, 2], [8388608, 4], [4194304, 8], [2097152, 16], [1048576, 32], [524288, 64], [262144, 128], [131072, 256], [65536, 512], [32768, 1024], [16384, 2048], [8192, 4096], [4096, 8192], [2048, 16384], [1024, 32768], [512, 65536], [256, 131072], [128, 262144], [64, 524288], [32, 1048576], [16, 2097152], [8, 4194304], [4, 8388608], [2, 16777216]]) == [25, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]\n assert candidate(n = 20,queries = [[524288, 1048575], [262144, 524287], [131072, 262143], [65536, 131071], [32768, 65535]]) == [39, 37, 35, 33, 31]\n assert candidate(n = 16,queries = [[65535, 32768], [32767, 16384], [16383, 8192], [8191, 4096], [4095, 2048], [2047, 1024], [1023, 512], [511, 256], [255, 128], [127, 64], [63, 32], [31, 16], [15, 8], [7, 4], [3, 2], [1, 2]]) == [31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 2]\n assert candidate(n = 15,queries = [[16383, 8192], [4096, 2048], [1024, 512], [256, 128], [64, 32], [16, 8], [4, 2], [2, 1]]) == [27, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 12,queries = [[2048, 4095], [1024, 2047], [512, 1023], [256, 511], [128, 255], [64, 127], [32, 63], [16, 31], [8, 15], [4, 7]]) == [23, 21, 19, 17, 15, 13, 11, 9, 7, 5]\n assert candidate(n = 10,queries = [[511, 256], [255, 128], [127, 64], [63, 32], [31, 16], [15, 8], [7, 4], [3, 2], [1, 2]]) == [17, 15, 13, 11, 9, 7, 5, 3, 2]\n assert candidate(n = 10,queries = [[512, 256], [256, 128], [128, 64], [64, 32], [32, 16], [16, 8], [8, 4], [4, 2], [2, 1]]) == [2, 2, 2, 2, 2, 2, 2, 2, 2]\n assert candidate(n = 20,queries = [[524288, 1048575], [262144, 524287], [131072, 262143], [65536, 131071], [32768, 65535], [16384, 32767]]) == [39, 37, 35, 33, 31, 29]\n", "comparison": "exact"}, "public_tests": ["3\n[[5,3],[4,7],[2,3]]", "2\n[[1,2]]"], "hints": ["Find the distance between nodes “a” and “b”.", "distance(a, b) = depth(a) + depth(b) - 2 * depth(LCA(a, b)). Where depth(a) denotes depth from root to node “a” and LCA(a, b) denotes the lowest common ancestor of nodes “a” and “b”.", "To find LCA(a, b), iterate over all ancestors of node “a” and check if it is the ancestor of node “b” too. If so, take the one with maximum depth."], "metadata": {"canonical_parameter_names": ["n", "queries"], "leetcode_dataset_entry_point": "Solution().cycleLengthQueries", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:23+00:00", "tests_total": 70, "tests_dropped": 19, "flags": ["figure_reference", "has_images"], "topic_tags": ["array", "tree", "binary-tree", "binary-lifting", "lowest-common-ancestor"]}, "language": "php", "interface": {"raw_signature": "function cycleLengthQueries($n, $queries) {", "container": "Solution", "callable": "cycleLengthQueries", "parameters": [{"name": "n", "type": "Integer"}, {"name": "queries", "type": "Integer[][]"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2511, "task_id": "maximum-enemy-forts-that-can-be-captured", "difficulty": "Easy", "problem_description": "You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:\n\n- -1 represents there is no fort at the i^th position.\n- 0 indicates there is an enemy fort at the i^th position.\n- 1 indicates the fort at the i^th the position is under your command.\n\nNow you have decided to move your army from one of your forts at position i to an empty position j such that:\n\n- 0 <= i, j <= n - 1\n- The army travels over enemy forts only. Formally, for all k where min(i,j) < k < max(i,j), forts[k] == 0.\n\nWhile moving the army, all the enemy forts that come in the way are captured.\n\nReturn the maximum number of enemy forts that can be captured. In case it is impossible to move your army, or you do not have any fort under your command, return 0.\n\nExample 1:\n\nInput: forts = [1,0,0,-1,0,0,0,0,1]\nOutput: 4\nExplanation:\n- Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2.\n- Moving the army from position 8 to position 3 captures 4 enemy forts.\nSince 4 is the maximum number of enemy forts that can be captured, we return 4.\n\nExample 2:\n\nInput: forts = [0,0,1,-1]\nOutput: 0\nExplanation: Since no enemy fort can be captured, 0 is returned.\n\nConstraints:\n\n- 1 <= forts.length <= 1000\n- -1 <= forts[i] <= 1\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(forts = [1, 0, 1, 0, -1, 0, 1]) == 1\n assert candidate(forts = [-1, 0, 0, 0, 0, 1]) == 4\n assert candidate(forts = [0, 0, 0, 0, 0, 0, 0]) == 0\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, -1]) == 2\n assert candidate(forts = [1, -1]) == 0\n assert candidate(forts = [0, 0, 0, 0, 0]) == 0\n assert candidate(forts = [-1]) == 0\n assert candidate(forts = [0]) == 0\n assert candidate(forts = [1, 0, -1, 0, 1, 0, -1]) == 1\n assert candidate(forts = [0, 0, 0, 0]) == 0\n assert candidate(forts = [0, 1, 0, -1, 0]) == 1\n assert candidate(forts = [1, -1, 1, -1, 1, -1]) == 0\n assert candidate(forts = [-1, 1, -1, 1, -1, 1]) == 0\n assert candidate(forts = [0, 0, 1, -1]) == 0\n assert candidate(forts = [0, 1, 0, -1, 0, 1, 0]) == 1\n assert candidate(forts = [1, 1, 1, -1, -1, -1, 1]) == 0\n assert candidate(forts = [-1, 0, -1, 0, 1, 0, 1]) == 1\n assert candidate(forts = [1, 0, 0, 0, 0, -1]) == 4\n assert candidate(forts = [1, 0, 1, 0, -1, 0, -1]) == 1\n assert candidate(forts = [-1, 0, 0, 0, 0, 0, 0, 1]) == 6\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, -1]) == 6\n assert candidate(forts = [1, 0, 0, -1, 0, 0, 0, 0, 1]) == 4\n assert candidate(forts = [1, 0, 0, 0, 0, 0, -1]) == 5\n assert candidate(forts = [-1, 0, 0, 0, 0, 0, 1]) == 5\n assert candidate(forts = [1]) == 0\n assert candidate(forts = [1, 1, -1, -1, 1, 1]) == 0\n assert candidate(forts = [-1, 0, -1, 0, 1, 0, -1]) == 1\n assert candidate(forts = [1, -1, 1, -1, 1]) == 0\n assert candidate(forts = [-1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, -1]) == 1\n assert candidate(forts = [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(forts = [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(forts = [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\n assert candidate(forts = [-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, -1]) == 0\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, -1]) == 3\n assert candidate(forts = [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\n assert candidate(forts = [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\n assert candidate(forts = [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(forts = [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, -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]) == 43\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]) == 13\n assert candidate(forts = [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, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1]) == 43\n assert candidate(forts = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1]) == 3\n assert candidate(forts = [-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]) == 4\n assert candidate(forts = [-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(forts = [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\n assert candidate(forts = [0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1]) == 5\n assert candidate(forts = [-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, 1]) == 2\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1]) == 5\n assert candidate(forts = [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]) == 0\n assert candidate(forts = [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, -1, 0, 0, 0, 0, 0, 1]) == 43\n assert candidate(forts = [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]) == 29\n assert candidate(forts = [-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\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1]) == 5\n assert candidate(forts = [-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]) == 5\n assert candidate(forts = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 1]) == 4\n assert candidate(forts = [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, -1]) == 50\n assert candidate(forts = [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, -1]) == 71\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\n assert candidate(forts = [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\n assert candidate(forts = [-1, 0, 0, 0, 0, 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]) == 7\n assert candidate(forts = [-1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1]) == 1\n assert candidate(forts = [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, -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, 1, 0, 0, 0, 0, 0, -1]) == 43\n assert candidate(forts = [-1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 1, 0]) == 4\n assert candidate(forts = [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]) == 7\n assert candidate(forts = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1]) == 8\n assert candidate(forts = [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]) == 0\n assert candidate(forts = [1, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 1, -1]) == 4\n assert candidate(forts = [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]) == 0\n assert candidate(forts = [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, 1]) == 0\n assert candidate(forts = [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(forts = [-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, 1, 0, 0, 0, 0, 0, -1]) == 43\n assert candidate(forts = [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\n assert candidate(forts = [1, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1]) == 6\n assert candidate(forts = [-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1]) == 2\n assert candidate(forts = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 8\n assert candidate(forts = [-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]) == 77\n assert candidate(forts = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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(forts = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1]) == 5\n assert candidate(forts = [-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(forts = [-1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, -1]) == 5\n assert candidate(forts = [-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]) == 0\n assert candidate(forts = [1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1]) == 3\n assert candidate(forts = [1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, -1]) == 4\n assert candidate(forts = [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\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\n assert candidate(forts = [1, 0, 0, -1, 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, -1]) == 2\n assert candidate(forts = [1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1]) == 5\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 0\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1]) == 10\n assert candidate(forts = [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, 1]) == 0\n assert candidate(forts = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) == 10\n assert candidate(forts = [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, -1]) == 56\n assert candidate(forts = [-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\n assert candidate(forts = [-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\n assert candidate(forts = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]) == 12\n assert candidate(forts = [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\n assert candidate(forts = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1]) == 2\n assert candidate(forts = [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, 1]) == 0\n assert candidate(forts = [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]) == 5\n assert candidate(forts = [0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1]) == 5\n", "comparison": "exact"}, "public_tests": ["[1,0,0,-1,0,0,0,0,1]", "[0,0,1,-1]"], "hints": ["For each fort under your command, check if you can move the army from here.", "If yes, find the closest empty positions satisfying all criteria.", "How can two-pointers be used to solve this problem optimally?"], "metadata": {"canonical_parameter_names": ["forts"], "leetcode_dataset_entry_point": "Solution().captureForts", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:27+00:00", "tests_total": 100, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "two-pointers"]}, "language": "php", "interface": {"raw_signature": "function captureForts($forts) {", "container": "Solution", "callable": "captureForts", "parameters": [{"name": "forts", "type": "Integer[]"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2512, "task_id": "reward-top-k-students", "difficulty": "Medium", "problem_description": "You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.\n\nInitially every student has 0 points. Each positive word in a feedback report increases the points of a student by 3, whereas each negative word decreases the points by 1.\n\nYou are given n feedback reports, represented by a 0-indexed string array report and a 0-indexed integer array student_id, where student_id[i] represents the ID of the student who has received the feedback report report[i]. The ID of each student is unique.\n\nGiven an integer k, return the top k students after ranking them in non-increasing order by their points. In case more than one student has the same points, the one with the lower ID ranks higher.\n\nExample 1:\n\nInput: positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is studious\",\"the student is smart\"], student_id = [1,2], k = 2\nOutput: [1,2]\nExplanation:\nBoth the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.\n\nExample 2:\n\nInput: positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is not studious\",\"the student is smart\"], student_id = [1,2], k = 2\nOutput: [2,1]\nExplanation:\n- The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points.\n- The student with ID 2 has 1 positive feedback, so he has 3 points.\nSince student 2 has more points, [2,1] is returned.\n\nConstraints:\n\n- 1 <= positive_feedback.length, negative_feedback.length <= 10^4\n- 1 <= positive_feedback[i].length, negative_feedback[j].length <= 100\n- Both positive_feedback[i] and negative_feedback[j] consists of lowercase English letters.\n- No word is present in both positive_feedback and negative_feedback.\n- n == report.length == student_id.length\n- 1 <= n <= 10^4\n- report[i] consists of lowercase English letters and spaces ' '.\n- There is a single space between consecutive words of report[i].\n- 1 <= report[i].length <= 100\n- 1 <= student_id[i] <= 10^9\n- All the values of student_id[i] are unique.\n- 1 <= k <= n\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(positive_feedback = ['smart', 'brilliant', 'studious'],negative_feedback = ['not'],report = ['this student is studious', 'the student is smart'],student_id = [1, 2],k = 2) == [1, 2]\n assert candidate(positive_feedback = ['good', 'excellent'],negative_feedback = ['bad', 'poor'],report = ['the student is good and excellent', 'the student is bad but tries'],student_id = [3, 4],k = 1) == [3]\n assert candidate(positive_feedback = ['smart', 'brilliant', 'studious'],negative_feedback = ['not'],report = ['this student is not studious', 'the student is smart'],student_id = [1, 2],k = 2) == [2, 1]\n assert candidate(positive_feedback = ['good', 'excellent'],negative_feedback = ['bad', 'poor'],report = ['the student is good', 'the student is excellent', 'the student is bad', 'the student is poor'],student_id = [101, 102, 103, 104],k = 2) == [101, 102]\n assert candidate(positive_feedback = ['good', 'excellent'],negative_feedback = ['bad', 'poor'],report = ['the student is good and excellent', 'the student is bad'],student_id = [3, 4],k = 1) == [3]\n assert candidate(positive_feedback = ['outstanding'],negative_feedback = ['poor'],report = ['the student is outstanding', 'the student is poor', 'the student is not poor'],student_id = [100, 200, 300],k = 3) == [100, 200, 300]\n assert candidate(positive_feedback = ['good', 'great'],negative_feedback = ['average', 'terrible'],report = ['average performance', 'good work but could be better', 'terrible experience'],student_id = [301, 302, 303],k = 2) == [302, 301]\n assert candidate(positive_feedback = ['kind', 'friendly'],negative_feedback = ['rude', 'mean'],report = ['the student is kind', 'the student is mean'],student_id = [7, 8],k = 2) == [7, 8]\n assert candidate(positive_feedback = ['hardworking', 'diligent'],negative_feedback = ['lazy', 'slacker'],report = ['the student is hardworking', 'the student is diligent', 'the student is lazy', 'the student is slacker'],student_id = [501, 502, 503, 504],k = 3) == [501, 502, 503]\n assert candidate(positive_feedback = ['hardworking', 'dedicated'],negative_feedback = ['lazy', 'inattentive'],report = ['the student is hardworking and dedicated', 'the student is lazy'],student_id = [10, 20],k = 1) == [10]\n assert candidate(positive_feedback = ['helpful', 'efficient'],negative_feedback = ['lazy', 'inefficient'],report = ['the student is helpful', 'the student is lazy'],student_id = [5, 6],k = 2) == [5, 6]\n assert candidate(positive_feedback = ['excellent', 'outstanding'],negative_feedback = ['poor', 'bad'],report = ['very poor performance', 'outstanding in every aspect'],student_id = [201, 202],k = 2) == [202, 201]\n assert candidate(positive_feedback = ['adept', 'proficient'],negative_feedback = ['incompetent', 'unskilled'],report = ['the student is adept', 'the student is proficient', 'the student is incompetent', 'the student is unskilled'],student_id = [701, 702, 703, 704],k = 4) == [701, 702, 703, 704]\n assert candidate(positive_feedback = ['excellent'],negative_feedback = ['terrible'],report = ['the student is excellent', 'the student is terrible', 'the student is terrible but excellent'],student_id = [5, 15, 25],k = 2) == [5, 25]\n assert candidate(positive_feedback = ['outstanding', 'great'],negative_feedback = ['average', 'poor'],report = ['the student is average', 'the student is outstanding'],student_id = [5, 6],k = 2) == [6, 5]\n assert candidate(positive_feedback = ['hardworking', 'dedicated'],negative_feedback = ['lazy', 'slacking'],report = ['the student is lazy', 'the student is dedicated and hardworking'],student_id = [7, 8],k = 2) == [8, 7]\n assert candidate(positive_feedback = ['hardworking', 'dedicated'],negative_feedback = ['lazy', 'careless'],report = ['the student is hardworking and dedicated', 'the student is lazy but smart'],student_id = [101, 102],k = 1) == [101]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'great'],negative_feedback = ['bad', 'poor', 'terrible'],report = ['the student is excellent and great', 'the student is poor', 'the student is excellent but terrible'],student_id = [5, 3, 8],k = 2) == [5, 8]\n assert candidate(positive_feedback = ['efficient', 'productive', 'organized'],negative_feedback = ['disorganized', 'inefficient', 'unproductive'],report = ['the student is efficient and organized', 'the student is disorganized and inefficient', 'the student is productive'],student_id = [3001, 3002, 3003],k = 1) == [3001]\n assert candidate(positive_feedback = ['knowledgeable', 'informed', 'learned'],negative_feedback = ['ignorant', 'uninformed', 'naive'],report = ['the student is knowledgeable', 'the student is uninformed', 'the student is ignorant and naive'],student_id = [4001, 4002, 4003],k = 2) == [4001, 4002]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'impressive'],negative_feedback = ['poor', 'mediocre', 'inadequate'],report = ['the student is excellent and impressive', 'the student is mediocre', 'the student is excellent but also poor'],student_id = [1001, 1002, 1003],k = 3) == [1001, 1003, 1002]\n assert candidate(positive_feedback = ['innovative', 'creative', 'inspiring'],negative_feedback = ['dull', 'boring', 'unoriginal'],report = ['the student is innovative and creative', 'the student is unoriginal', 'the student is inspiring but also unoriginal'],student_id = [2001, 2002, 2003],k = 2) == [2001, 2003]\n assert candidate(positive_feedback = ['innovative', 'creative', 'original'],negative_feedback = ['conventional', 'boring', 'predictable'],report = ['the student is conventional and boring', 'the student is creative and innovative', 'the student is original but not always predictable', 'the student is predictable but hardworking'],student_id = [5001, 5002, 5003, 5004],k = 2) == [5002, 5003]\n assert candidate(positive_feedback = ['knowledgeable', 'wise', 'informed'],negative_feedback = ['ignorant', 'naive', 'uninformed'],report = ['the student is knowledgeable and wise', 'the student is ignorant and naive', 'the student is informed and smart'],student_id = [4001, 4002, 4003],k = 2) == [4001, 4003]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'slow', 'inconsistent'],report = ['the student is efficient', 'the student is productive', 'the student is focused'],student_id = [9001, 9002, 9003],k = 2) == [9001, 9002]\n assert candidate(positive_feedback = ['curious', 'inquisitive', 'investigative'],negative_feedback = ['ignorant', 'uninterested', 'apathetic'],report = ['the student is curious and inquisitive', 'the student is ignorant and uninterested', 'the student is investigative but needs rest'],student_id = [999, 998, 997],k = 3) == [999, 997, 998]\n assert candidate(positive_feedback = ['leader', 'motivator', 'captain'],negative_feedback = ['follower', 'lazy', 'unmotivated'],report = ['the student is leader and motivator', 'the student is follower and lazy', 'the student is captain but tired'],student_id = [777, 778, 779],k = 1) == [777]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'remarkable'],negative_feedback = ['poor', 'mediocre', 'inadequate'],report = ['the student was excellent and outstanding', 'the student was not excellent but remarkable', 'the student was poor and mediocre'],student_id = [1001, 1002, 1003],k = 3) == [1001, 1002, 1003]\n assert candidate(positive_feedback = ['outstanding', 'excellent', 'remarkable'],negative_feedback = ['poor', 'bad', 'mediocre'],report = ['the student is outstanding and excellent', 'the student is mediocre', 'the student is poor'],student_id = [1001, 1002, 1003],k = 2) == [1001, 1002]\n assert candidate(positive_feedback = ['persevering', 'determined', 'resilient'],negative_feedback = ['quitter', 'defeated', 'weak'],report = ['the student is persevering', 'the student is determined', 'the student is resilient', 'the student is a quitter', 'the student is defeated', 'the student is weak'],student_id = [3001, 3002, 3003, 3004, 3005, 3006],k = 4) == [3001, 3002, 3003, 3004]\n assert candidate(positive_feedback = ['reliable', 'trustworthy', 'dependable'],negative_feedback = ['unreliable', 'dishonest', 'untrustworthy'],report = ['the student is reliable and dependable', 'the student is unreliable and dishonest', 'the student is trustworthy but late'],student_id = [10, 20, 30],k = 1) == [10]\n assert candidate(positive_feedback = ['inspired', 'motivated', 'eager'],negative_feedback = ['disinterested', 'apathetic', 'unmotivated'],report = ['the student is inspired and eager', 'the student is disinterested', 'the student is motivated', 'the student is apathetic', 'the student is unmotivated'],student_id = [6001, 6002, 6003, 6004, 6005],k = 4) == [6001, 6003, 6002, 6004]\n assert candidate(positive_feedback = ['innovative', 'creative', 'resourceful'],negative_feedback = ['lazy', 'disorganized', 'unfocused'],report = ['the student is innovative and creative', 'the student is lazy', 'the student is disorganized', 'the student is resourceful'],student_id = [2001, 2002, 2003, 2004],k = 3) == [2001, 2004, 2002]\n assert candidate(positive_feedback = ['helpful', 'cooperative', 'supportive'],negative_feedback = ['unhelpful', 'selfish', 'uncooperative'],report = ['the student is helpful and cooperative', 'the student is selfish and unhelpful', 'the student is supportive but mediocre'],student_id = [201, 202, 203],k = 3) == [201, 203, 202]\n assert candidate(positive_feedback = ['honest', 'truthful', 'sincere'],negative_feedback = ['liar', 'deceptive', 'dishonest'],report = ['the student is honest and truthful', 'the student is liar and deceptive', 'the student is sincere but sometimes forgetful'],student_id = [888, 887, 886],k = 2) == [888, 886]\n assert candidate(positive_feedback = ['innovative', 'creative', 'inspiring'],negative_feedback = ['unoriginal', 'boring', 'stupid'],report = ['the student is innovative and creative', 'the student is unoriginal and stupid', 'the student is inspiring'],student_id = [1001, 1002, 1003],k = 2) == [1001, 1003]\n assert candidate(positive_feedback = ['kind', 'polite', 'considerate'],negative_feedback = ['rude', 'impolite'],report = ['the student is kind and polite', 'the student is impolite', 'the student is rude', 'the student is considerate', 'the student is impolite but kind'],student_id = [101, 102, 103, 104, 105],k = 4) == [101, 104, 105, 102]\n assert candidate(positive_feedback = ['helpful', 'supportive', 'collaborative'],negative_feedback = ['unfriendly', 'rude', 'impolite'],report = ['helpful and supportive', 'the student is rude', 'collaborative efforts', 'impolite behavior noted', 'supportive actions'],student_id = [4001, 4002, 4003, 4004, 4005],k = 4) == [4001, 4003, 4005, 4002]\n assert candidate(positive_feedback = ['helpful', 'generous', 'compassionate'],negative_feedback = ['selfish', 'greedy', 'harsh'],report = ['the student is generous and helpful', 'the student is harsh', 'the student is greedy'],student_id = [2001, 2002, 2003],k = 3) == [2001, 2002, 2003]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'perfect'],negative_feedback = ['bad', 'poor', 'mediocre'],report = ['this is an excellent report', 'the student is poor', 'outstanding performance', 'mediocre work'],student_id = [1001, 1002, 1003, 1004],k = 2) == [1001, 1003]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'exceptional'],negative_feedback = ['poor', 'mediocre', 'bad'],report = ['the student is excellent and outstanding', 'the student is mediocre and bad', 'the student is exceptional'],student_id = [5, 6, 7],k = 2) == [5, 7]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'slow', 'inconsistent'],report = ['the student is efficient and productive', 'the student is productive and focused', 'the student is productive but inconsistent'],student_id = [6001, 6002, 6003],k = 2) == [6001, 6002]\n assert candidate(positive_feedback = ['excellent', 'outstanding', 'brilliant'],negative_feedback = ['poor', 'bad', 'terrible'],report = ['the student is excellent and outstanding', 'the student is brilliant', 'the student is poor but not bad', 'the student is terrible'],student_id = [10, 20, 30, 40],k = 3) == [10, 20, 40]\n assert candidate(positive_feedback = ['helpful', 'cooperative'],negative_feedback = ['selfish', 'unhelpful'],report = ['the student is helpful and cooperative', 'the student is selfish', 'the student is unhelpful', 'the student is helpful but unhelpful'],student_id = [100, 101, 102, 103],k = 2) == [100, 103]\n assert candidate(positive_feedback = ['efficient', 'resourceful', 'innovative'],negative_feedback = ['inefficient', 'wasteful', 'unproductive'],report = ['the student is inefficient and wasteful', 'the student is resourceful and innovative', 'the student is productive but not very innovative'],student_id = [2001, 2002, 2003],k = 3) == [2002, 2003, 2001]\n assert candidate(positive_feedback = ['dynamic', 'engaged', 'motivated'],negative_feedback = ['disinterested', 'unmotivated', 'apathetic'],report = ['dynamic performance', 'disinterested in work', 'engaged', 'apathetic attitude', 'motivated', 'dynamic'],student_id = [5001, 5002, 5003, 5004, 5005, 5006],k = 5) == [5001, 5003, 5005, 5006, 5002]\n assert candidate(positive_feedback = ['outstanding', 'excellent', 'genius'],negative_feedback = ['poor', 'dull', 'lazy'],report = ['the student is brilliant and excellent', 'the student is lazy but smart', 'the student is outstanding'],student_id = [501, 502, 503],k = 3) == [501, 503, 502]\n assert candidate(positive_feedback = ['efficient', 'productive', 'effective'],negative_feedback = ['lazy', 'inefficient', 'unproductive'],report = ['the student is lazy and inefficient', 'the student is productive and efficient', 'the student is effective but tired'],student_id = [301, 302, 303],k = 2) == [302, 303]\n assert candidate(positive_feedback = ['creative', 'innovative', 'resourceful'],negative_feedback = ['dull', 'boring', 'stagnant'],report = ['the student is innovative', 'the student is dull', 'the student is resourceful', 'the student is boring'],student_id = [3001, 3002, 3003, 3004],k = 2) == [3001, 3003]\n assert candidate(positive_feedback = ['helpful', 'compassionate', 'generous'],negative_feedback = ['selfish', 'greedy', 'cruel'],report = ['the student is helpful and compassionate', 'the student is generous', 'the student is selfish', 'the student is greedy', 'the student is cruel', 'the student is generous and helpful'],student_id = [4001, 4002, 4003, 4004, 4005, 4006],k = 5) == [4001, 4006, 4002, 4003, 4004]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'slow', 'inconsistent'],report = ['the student is efficient', 'the student is productive and focused', 'the student is unfocused and slow'],student_id = [2001, 2002, 2003],k = 2) == [2002, 2001]\n assert candidate(positive_feedback = ['eloquent', 'articulate', 'persuasive'],negative_feedback = ['confused', 'incoherent', 'unclear'],report = ['the student was eloquent and articulate', 'the student was unclear', 'the student was incoherent but tried his best'],student_id = [4001, 4002, 4003],k = 3) == [4001, 4002, 4003]\n assert candidate(positive_feedback = ['efficient', 'effective', 'productive'],negative_feedback = ['unproductive', 'slow', 'ineffective'],report = ['efficiency was very high', 'the work was slow', 'productive', 'ineffective methods used', 'effective results achieved'],student_id = [3001, 3002, 3003, 3004, 3005],k = 3) == [3003, 3005, 3001]\n assert candidate(positive_feedback = ['leader', 'motivator', 'teamplayer'],negative_feedback = ['coward', 'antisocial', 'uncooperative'],report = ['the student is a teamplayer and leader', 'the student is antisocial and coward', 'the student is cooperative and motivator'],student_id = [2001, 2002, 2003],k = 3) == [2001, 2003, 2002]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'slow', 'inconsistent'],report = ['the student is efficient and productive', 'the student is productive but unfocused', 'the student is productive and focused'],student_id = [8001, 8002, 8003],k = 2) == [8001, 8003]\n assert candidate(positive_feedback = ['resilient', 'strong', 'enduring'],negative_feedback = ['fragile', 'weak', 'endless'],report = ['the student is resilient and strong', 'the student is fragile and weak', 'the student is enduring'],student_id = [5001, 5002, 5003],k = 3) == [5001, 5003, 5002]\n assert candidate(positive_feedback = ['ambitious', 'aspirational', 'driven'],negative_feedback = ['unambitious', 'disinterested', 'apathetic'],report = ['the student is ambitious', 'the student is disinterested', 'the student is driven but also apathetic'],student_id = [5001, 5002, 5003],k = 2) == [5001, 5003]\n assert candidate(positive_feedback = ['curious', 'inquisitive', 'seeking'],negative_feedback = ['apathetic', 'indifferent', 'uninterested'],report = ['the student was curious and inquisitive', 'the student was uninterested', 'the student was apathetic but showed improvement'],student_id = [5001, 5002, 5003],k = 3) == [5001, 5002, 5003]\n assert candidate(positive_feedback = ['leader', 'initiative', 'confidence'],negative_feedback = ['follower', 'shy', 'insecure'],report = ['the student is a leader and takes initiative', 'the student is shy and insecure', 'the student is confident and proactive', 'the student is a follower but eager to learn'],student_id = [6001, 6002, 6003, 6004],k = 1) == [6001]\n assert candidate(positive_feedback = ['innovative', 'creative', 'brilliant'],negative_feedback = ['incompetent', 'lazy', 'unhelpful'],report = ['the student showed innovative thinking', 'incompetent work was submitted', 'lazy performance', 'creative solutions provided'],student_id = [2001, 2002, 2003, 2004],k = 3) == [2001, 2004, 2002]\n assert candidate(positive_feedback = ['disciplined', 'focused', 'organized'],negative_feedback = ['disorganized', 'distracted', 'undisciplined'],report = ['the student is disciplined and organized', 'the student is distracted and disorganized', 'the student is focused but forgetful'],student_id = [1001, 1002, 1003],k = 3) == [1001, 1003, 1002]\n assert candidate(positive_feedback = ['compassionate', 'empathetic', 'sympathetic'],negative_feedback = ['cruel', 'heartless', 'unfeeling'],report = ['the student is compassionate and empathetic', 'the student is cruel and heartless', 'the student is sympathetic but needs rest'],student_id = [666, 667, 668],k = 3) == [666, 668, 667]\n assert candidate(positive_feedback = ['proactive', 'initiative', 'leader'],negative_feedback = ['passive', 'follower', 'inactive'],report = ['the student is proactive', 'the student is passive', 'the student is initiative', 'the student is follower', 'the student is leader', 'the student is inactive'],student_id = [8001, 8002, 8003, 8004, 8005, 8006],k = 3) == [8001, 8003, 8005]\n assert candidate(positive_feedback = ['efficient', 'effective', 'productive'],negative_feedback = ['inefficient', 'lazy', 'slow'],report = ['the student is very efficient', 'the student is lazy and inefficient', 'the student is slow but effective'],student_id = [3001, 3002, 3003],k = 2) == [3001, 3003]\n assert candidate(positive_feedback = ['friendly', 'helpful'],negative_feedback = ['rude', 'mean', 'unkind'],report = ['the student is friendly and helpful', 'the student is unkind', 'the student is mean', 'the student is rude'],student_id = [15, 20, 25, 30],k = 2) == [15, 20]\n assert candidate(positive_feedback = ['ambitious', 'determined', 'persistent'],negative_feedback = ['procrastinator', 'inconsistent', 'lazy'],report = ['the student is ambitious and determined', 'the student is persistent', 'the student is a procrastinator', 'the student is inconsistent', 'the student is lazy but persistent'],student_id = [1001, 1002, 1003, 1004, 1005],k = 4) == [1001, 1002, 1005, 1003]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'slow', 'inconsistent'],report = ['the student is productive', 'the student is focused', 'the student is efficient'],student_id = [10001, 10002, 10003],k = 2) == [10001, 10002]\n assert candidate(positive_feedback = ['innovative', 'creative', 'resourceful'],negative_feedback = ['mediocre', 'unoriginal', 'unresourceful'],report = ['the student is innovative', 'the student is creative and resourceful', 'the student is mediocre', 'the student is unoriginal', 'the student is unresourceful', 'the student is innovative and unresourceful'],student_id = [5001, 5002, 5003, 5004, 5005, 5006],k = 2) == [5002, 5001]\n assert candidate(positive_feedback = ['efficient', 'productive', 'focused'],negative_feedback = ['unfocused', 'distraught', 'inefficient'],report = ['the student is efficient', 'the student is unfocused', 'the student is productive', 'the student is distracted'],student_id = [5001, 5002, 5003, 5004],k = 3) == [5001, 5003, 5004]\n assert candidate(positive_feedback = ['proactive', 'ambitious', 'determined'],negative_feedback = ['lazy', 'apathetic', 'indifferent'],report = ['the student is proactive and ambitious', 'the student is lazy and apathetic', 'the student is determined and works hard', 'the student is indifferent but willing to try'],student_id = [4001, 4002, 4003, 4004],k = 3) == [4001, 4003, 4004]\n assert candidate(positive_feedback = ['innovative', 'creative', 'ingenious'],negative_feedback = ['incompetent', 'dull', 'inept'],report = ['the student is incompetent and dull', 'the student is creative and innovative', 'the student is inept but tries hard'],student_id = [150, 151, 152],k = 2) == [151, 152]\n assert candidate(positive_feedback = ['ingenious', 'creative', 'resourceful'],negative_feedback = ['uncreative', 'inefficient', 'unproductive'],report = ['the student is ingenious and creative', 'the student is unproductive', 'the student is resourceful but inefficient'],student_id = [3001, 3002, 3003],k = 1) == [3001]\n assert candidate(positive_feedback = ['diligent', 'persevering', 'tenacious'],negative_feedback = ['lazy', 'indolent', 'procrastinating'],report = ['the student is diligent and persevering', 'the student is indolent', 'the student is tenacious but lazy'],student_id = [7001, 7002, 7003],k = 2) == [7001, 7003]\n assert candidate(positive_feedback = ['hardworking', 'dedicated', 'persistent'],negative_feedback = ['lazy', 'careless', 'unreliable'],report = ['the student is hardworking and dedicated', 'the student is lazy', 'the student is careless', 'the student is unreliable', 'the student is persistent but careless'],student_id = [201, 202, 203, 204, 205],k = 3) == [201, 205, 202]\n assert candidate(positive_feedback = ['motivated', 'driven'],negative_feedback = ['apathetic', 'indifferent'],report = ['the student is motivated', 'the student is driven', 'the student is apathetic', 'the student is indifferent', 'the student is motivated but apathetic', 'the student is driven but indifferent'],student_id = [9001, 9002, 9003, 9004, 9005, 9006],k = 3) == [9001, 9002, 9005]\n assert candidate(positive_feedback = ['smart', 'brilliant', 'studious'],negative_feedback = ['not', 'lazy', 'careless'],report = ['this student is not studious', 'the student is smart', 'the student is lazy but brilliant', 'the student is careless'],student_id = [1, 2, 3, 4],k = 3) == [2, 1, 3]\n assert candidate(positive_feedback = ['outstanding', 'excellent', 'remarkable'],negative_feedback = ['poor', 'bad', 'mediocre'],report = ['the student is outstanding and excellent', 'the student is mediocre', 'the student is poor'],student_id = [1001, 1002, 1003],k = 2) == [1001, 1002]\n assert candidate(positive_feedback = ['cooperative', 'collaborative', 'teamplayer'],negative_feedback = ['uncooperative', 'selfish', 'individualistic'],report = ['the student is cooperative', 'the student is uncooperative', 'the student is collaborative', 'the student is selfish', 'the student is teamplayer', 'the student is individualistic'],student_id = [7001, 7002, 7003, 7004, 7005, 7006],k = 2) == [7001, 7003]\n assert candidate(positive_feedback = ['curious', 'knowledgeable', 'inquisitive'],negative_feedback = ['ignorant', 'naive', 'uninformed'],report = ['the student is curious', 'the student is knowledgeable', 'the student is inquisitive', 'the student is ignorant', 'the student is naive', 'the student is uninformed', 'the student is curious and knowledgeable'],student_id = [5001, 5002, 5003, 5004, 5005, 5006, 5007],k = 3) == [5007, 5001, 5002]\n assert candidate(positive_feedback = ['perseverant', 'determined', 'ambitious'],negative_feedback = ['lazy', 'indifferent', 'apathetic'],report = ['the student is perseverant and ambitious', 'the student is lazy', 'the student is indifferent', 'the student is apathetic'],student_id = [4001, 4002, 4003, 4004],k = 1) == [4001]\n assert candidate(positive_feedback = ['outstanding', 'excellent', 'impressive'],negative_feedback = ['poor', 'bad', 'mediocre'],report = ['the student is poor but trying hard', 'the student is excellent and impressive', 'the student is mediocre but not bad'],student_id = [1001, 1002, 1003],k = 2) == [1002, 1001]\n", "comparison": "exact"}, "public_tests": ["[\"smart\",\"brilliant\",\"studious\"]\n[\"not\"]\n[\"this student is studious\",\"the student is smart\"]\n[1,2]\n2", "[\"smart\",\"brilliant\",\"studious\"]\n[\"not\"]\n[\"this student is not studious\",\"the student is smart\"]\n[1,2]\n2"], "hints": ["Hash the positive and negative feedback words separately.", "Calculate the points for each student’s feedback.", "Sort the students accordingly to find the top k among them."], "metadata": {"canonical_parameter_names": ["positive_feedback", "negative_feedback", "report", "student_id", "k"], "leetcode_dataset_entry_point": "Solution().topStudents", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:30+00:00", "tests_total": 82, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table", "string", "sorting", "heap-priority-queue"]}, "language": "php", "interface": {"raw_signature": "function topStudents($positive_feedback, $negative_feedback, $report, $student_id, $k) {", "container": "Solution", "callable": "topStudents", "parameters": [{"name": "positive_feedback", "type": "String[]"}, {"name": "negative_feedback", "type": "String[]"}, {"name": "report", "type": "String[]"}, {"name": "student_id", "type": "Integer[]"}, {"name": "k", "type": "Integer"}], "return_type": "Integer[]", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 2513, "task_id": "minimize-the-maximum-of-two-arrays", "difficulty": "Medium", "problem_description": "We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:\n\n- arr1 contains uniqueCnt1 distinct positive integers, each of which is not divisible by divisor1.\n- arr2 contains uniqueCnt2 distinct positive integers, each of which is not divisible by divisor2.\n- No integer is present in both arr1 and arr2.\n\nGiven divisor1, divisor2, uniqueCnt1, and uniqueCnt2, return the minimum possible maximum integer that can be present in either array.\n\nExample 1:\n\nInput: divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3\nOutput: 4\nExplanation:\nWe can distribute the first 4 natural numbers into arr1 and arr2.\narr1 = [1] and arr2 = [2,3,4].\nWe can see that both arrays satisfy all the conditions.\nSince the maximum value is 4, we return it.\n\nExample 2:\n\nInput: divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1\nOutput: 3\nExplanation:\nHere arr1 = [1,2], and arr2 = [3] satisfy all conditions.\nSince the maximum value is 3, we return it.\n\nExample 3:\n\nInput: divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2\nOutput: 15\nExplanation:\nHere, the final possible arrays can be arr1 = [1,3,5,7,9,11,13,15], and arr2 = [2,6].\nIt can be shown that it is not possible to obtain a lower maximum satisfying all conditions.\n\nConstraints:\n\n- 2 <= divisor1, divisor2 <= 10^5\n- 1 <= uniqueCnt1, uniqueCnt2 < 10^9\n- 2 <= uniqueCnt1 + uniqueCnt2 <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(divisor1 = 2,divisor2 = 7,uniqueCnt1 = 1,uniqueCnt2 = 3) == 4\n assert candidate(divisor1 = 2,divisor2 = 4,uniqueCnt1 = 8,uniqueCnt2 = 2) == 15\n assert candidate(divisor1 = 100,divisor2 = 101,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 200019803\n assert candidate(divisor1 = 100,divisor2 = 200,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 201005025\n assert candidate(divisor1 = 5,divisor2 = 10,uniqueCnt1 = 5,uniqueCnt2 = 5) == 11\n assert candidate(divisor1 = 7,divisor2 = 11,uniqueCnt1 = 10,uniqueCnt2 = 10) == 20\n assert candidate(divisor1 = 7,divisor2 = 13,uniqueCnt1 = 10,uniqueCnt2 = 10) == 20\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 2,uniqueCnt2 = 1) == 3\n assert candidate(divisor1 = 10,divisor2 = 15,uniqueCnt1 = 5,uniqueCnt2 = 6) == 11\n assert candidate(divisor1 = 7,divisor2 = 11,uniqueCnt1 = 3,uniqueCnt2 = 7) == 10\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 100454545\n assert candidate(divisor1 = 89,divisor2 = 97,uniqueCnt1 = 60000000,uniqueCnt2 = 40000000) == 100011584\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 20,uniqueCnt2 = 25) == 45\n assert candidate(divisor1 = 23,divisor2 = 29,uniqueCnt1 = 50000000,uniqueCnt2 = 30000000) == 80120120\n assert candidate(divisor1 = 13,divisor2 = 19,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 200813008\n assert candidate(divisor1 = 2,divisor2 = 3,uniqueCnt1 = 999999999,uniqueCnt2 = 1) == 1999999997\n assert candidate(divisor1 = 100000,divisor2 = 10000,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 100001000\n assert candidate(divisor1 = 30,divisor2 = 42,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 100478468\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 10000000,uniqueCnt2 = 20000000) == 30136363\n assert candidate(divisor1 = 45,divisor2 = 18,uniqueCnt1 = 200000000,uniqueCnt2 = 300000000) == 505617977\n assert candidate(divisor1 = 5,divisor2 = 7,uniqueCnt1 = 1,uniqueCnt2 = 999999999) == 1166666665\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 250000000,uniqueCnt2 = 250000000) == 502272727\n assert candidate(divisor1 = 61,divisor2 = 71,uniqueCnt1 = 70000000,uniqueCnt2 = 30000000) == 100023094\n assert candidate(divisor1 = 12,divisor2 = 18,uniqueCnt1 = 1000,uniqueCnt2 = 1000) == 2057\n assert candidate(divisor1 = 2,divisor2 = 5,uniqueCnt1 = 500000000,uniqueCnt2 = 499999999) == 1111111109\n assert candidate(divisor1 = 4,divisor2 = 6,uniqueCnt1 = 5,uniqueCnt2 = 8) == 14\n assert candidate(divisor1 = 4,divisor2 = 6,uniqueCnt1 = 300000000,uniqueCnt2 = 200000000) == 545454545\n assert candidate(divisor1 = 10000,divisor2 = 20000,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 100005000\n assert candidate(divisor1 = 8,divisor2 = 12,uniqueCnt1 = 40000000,uniqueCnt2 = 60000000) == 104347826\n assert candidate(divisor1 = 99999,divisor2 = 99998,uniqueCnt1 = 100000,uniqueCnt2 = 100000) == 200000\n assert candidate(divisor1 = 50000,divisor2 = 100000,uniqueCnt1 = 10000000,uniqueCnt2 = 10000000) == 20000200\n assert candidate(divisor1 = 29,divisor2 = 41,uniqueCnt1 = 60000000,uniqueCnt2 = 40000000) == 100084175\n assert candidate(divisor1 = 15,divisor2 = 20,uniqueCnt1 = 75000000,uniqueCnt2 = 25000000) == 101694915\n assert candidate(divisor1 = 19,divisor2 = 23,uniqueCnt1 = 150000000,uniqueCnt2 = 150000000) == 300688073\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 107142857\n assert candidate(divisor1 = 50000,divisor2 = 75000,uniqueCnt1 = 60000000,uniqueCnt2 = 40000000) == 100000666\n assert candidate(divisor1 = 20,divisor2 = 30,uniqueCnt1 = 500000000,uniqueCnt2 = 400000000) == 915254237\n assert candidate(divisor1 = 6,divisor2 = 8,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 104347826\n assert candidate(divisor1 = 100000,divisor2 = 50000,uniqueCnt1 = 50000000,uniqueCnt2 = 40000000) == 90000900\n assert candidate(divisor1 = 10,divisor2 = 15,uniqueCnt1 = 75000000,uniqueCnt2 = 25000000) == 103448275\n assert candidate(divisor1 = 100000,divisor2 = 100000,uniqueCnt1 = 450000000,uniqueCnt2 = 450000000) == 900009000\n assert candidate(divisor1 = 23,divisor2 = 37,uniqueCnt1 = 50000000,uniqueCnt2 = 49999999) == 100117646\n assert candidate(divisor1 = 23,divisor2 = 37,uniqueCnt1 = 45000000,uniqueCnt2 = 55000000) == 100117647\n assert candidate(divisor1 = 11,divisor2 = 13,uniqueCnt1 = 100,uniqueCnt2 = 150) == 251\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 214285714\n assert candidate(divisor1 = 1000,divisor2 = 500,uniqueCnt1 = 40000000,uniqueCnt2 = 60000000) == 100100100\n assert candidate(divisor1 = 4,divisor2 = 6,uniqueCnt1 = 100000000,uniqueCnt2 = 99999999) == 218181817\n assert candidate(divisor1 = 5,divisor2 = 7,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 102941176\n assert candidate(divisor1 = 17,divisor2 = 31,uniqueCnt1 = 99999999,uniqueCnt2 = 1) == 106249998\n assert candidate(divisor1 = 99998,divisor2 = 99999,uniqueCnt1 = 100000,uniqueCnt2 = 100000) == 200000\n assert candidate(divisor1 = 10,divisor2 = 15,uniqueCnt1 = 100000000,uniqueCnt2 = 1) == 111111111\n assert candidate(divisor1 = 4,divisor2 = 6,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 218181818\n assert candidate(divisor1 = 6,divisor2 = 8,uniqueCnt1 = 75000000,uniqueCnt2 = 25000000) == 104347826\n assert candidate(divisor1 = 77,divisor2 = 42,uniqueCnt1 = 500,uniqueCnt2 = 500) == 1002\n assert candidate(divisor1 = 11,divisor2 = 13,uniqueCnt1 = 20000000,uniqueCnt2 = 15000000) == 35246478\n assert candidate(divisor1 = 7,divisor2 = 14,uniqueCnt1 = 25000000,uniqueCnt2 = 25000000) == 53846153\n assert candidate(divisor1 = 15,divisor2 = 25,uniqueCnt1 = 80000000,uniqueCnt2 = 70000000) == 152027027\n assert candidate(divisor1 = 11,divisor2 = 13,uniqueCnt1 = 99999999,uniqueCnt2 = 99999999) == 201408448\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 100,uniqueCnt2 = 200) == 321\n assert candidate(divisor1 = 25,divisor2 = 40,uniqueCnt1 = 100,uniqueCnt2 = 150) == 251\n assert candidate(divisor1 = 6,divisor2 = 9,uniqueCnt1 = 15,uniqueCnt2 = 20) == 37\n assert candidate(divisor1 = 6,divisor2 = 9,uniqueCnt1 = 50000000,uniqueCnt2 = 50000000) == 105882352\n assert candidate(divisor1 = 23,divisor2 = 31,uniqueCnt1 = 200000000,uniqueCnt2 = 300000000) == 500702247\n assert candidate(divisor1 = 5,divisor2 = 6,uniqueCnt1 = 1000000,uniqueCnt2 = 500000) == 1551724\n assert candidate(divisor1 = 67,divisor2 = 89,uniqueCnt1 = 400000000,uniqueCnt2 = 400000000) == 800134183\n assert candidate(divisor1 = 11,divisor2 = 13,uniqueCnt1 = 200000000,uniqueCnt2 = 1) == 219999999\n assert candidate(divisor1 = 37,divisor2 = 41,uniqueCnt1 = 9876543,uniqueCnt2 = 1234567) == 11118439\n assert candidate(divisor1 = 7,divisor2 = 13,uniqueCnt1 = 300000000,uniqueCnt2 = 300000000) == 606666666\n assert candidate(divisor1 = 5,divisor2 = 7,uniqueCnt1 = 99999999,uniqueCnt2 = 1) == 124999998\n assert candidate(divisor1 = 97,divisor2 = 101,uniqueCnt1 = 1000000,uniqueCnt2 = 500000) == 1500153\n assert candidate(divisor1 = 10000,divisor2 = 100000,uniqueCnt1 = 90000000,uniqueCnt2 = 10000000) == 100001000\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 5,uniqueCnt2 = 10) == 15\n assert candidate(divisor1 = 10,divisor2 = 15,uniqueCnt1 = 100000000,uniqueCnt2 = 200000000) == 310344827\n assert candidate(divisor1 = 77,divisor2 = 42,uniqueCnt1 = 33000000,uniqueCnt2 = 66000000) == 99214750\n assert candidate(divisor1 = 6,divisor2 = 8,uniqueCnt1 = 99999999,uniqueCnt2 = 1) == 119999998\n assert candidate(divisor1 = 5,divisor2 = 10,uniqueCnt1 = 50,uniqueCnt2 = 50) == 111\n assert candidate(divisor1 = 101,divisor2 = 103,uniqueCnt1 = 1000000,uniqueCnt2 = 1000000) == 2000192\n assert candidate(divisor1 = 23,divisor2 = 31,uniqueCnt1 = 50000000,uniqueCnt2 = 30000000) == 80112359\n assert candidate(divisor1 = 11,divisor2 = 22,uniqueCnt1 = 100000000,uniqueCnt2 = 1) == 109999999\n assert candidate(divisor1 = 11,divisor2 = 22,uniqueCnt1 = 300000000,uniqueCnt2 = 300000000) == 628571428\n assert candidate(divisor1 = 23,divisor2 = 29,uniqueCnt1 = 100000,uniqueCnt2 = 100000) == 200300\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 100000000,uniqueCnt2 = 50000000) == 160714285\n assert candidate(divisor1 = 5,divisor2 = 3,uniqueCnt1 = 100,uniqueCnt2 = 150) == 267\n assert candidate(divisor1 = 7,divisor2 = 11,uniqueCnt1 = 10000000,uniqueCnt2 = 10000000) == 20263157\n assert candidate(divisor1 = 4,divisor2 = 6,uniqueCnt1 = 250000000,uniqueCnt2 = 250000000) == 545454545\n assert candidate(divisor1 = 8,divisor2 = 9,uniqueCnt1 = 2000000,uniqueCnt2 = 3000000) == 5070422\n assert candidate(divisor1 = 100000,divisor2 = 99999,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 200000000\n assert candidate(divisor1 = 10,divisor2 = 25,uniqueCnt1 = 50000000,uniqueCnt2 = 100000000) == 153061224\n assert candidate(divisor1 = 5,divisor2 = 15,uniqueCnt1 = 100000000,uniqueCnt2 = 50000000) == 160714285\n assert candidate(divisor1 = 5,divisor2 = 10,uniqueCnt1 = 50000000,uniqueCnt2 = 49999999) == 111111109\n assert candidate(divisor1 = 2,divisor2 = 3,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 239999999\n assert candidate(divisor1 = 2,divisor2 = 4,uniqueCnt1 = 99999999,uniqueCnt2 = 1) == 199999997\n assert candidate(divisor1 = 17,divisor2 = 29,uniqueCnt1 = 150000000,uniqueCnt2 = 150000000) == 300609756\n assert candidate(divisor1 = 9,divisor2 = 12,uniqueCnt1 = 250000000,uniqueCnt2 = 250000000) == 514285714\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 300000000,uniqueCnt2 = 200000000) == 502272727\n assert candidate(divisor1 = 3,divisor2 = 5,uniqueCnt1 = 500000000,uniqueCnt2 = 400000000) == 964285714\n assert candidate(divisor1 = 13,divisor2 = 17,uniqueCnt1 = 100000000,uniqueCnt2 = 100000000) == 200909090\n assert candidate(divisor1 = 71,divisor2 = 73,uniqueCnt1 = 10000000,uniqueCnt2 = 10000000) == 20003859\n assert candidate(divisor1 = 99,divisor2 = 101,uniqueCnt1 = 200000000,uniqueCnt2 = 300000000) == 500050010\n assert candidate(divisor1 = 3,divisor2 = 6,uniqueCnt1 = 100,uniqueCnt2 = 200) == 359\n assert candidate(divisor1 = 10,divisor2 = 15,uniqueCnt1 = 80000000,uniqueCnt2 = 20000000) == 103448275\n", "comparison": "exact"}, "public_tests": ["2\n7\n1\n3", "3\n5\n2\n1", "2\n4\n8\n2"], "hints": ["Use binary search to find smallest maximum element.", "Add numbers divisible by x in nums2 and vice versa."], "metadata": {"canonical_parameter_names": ["divisor1", "divisor2", "uniqueCnt1", "uniqueCnt2"], "leetcode_dataset_entry_point": "Solution().minimizeSet", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T20:55:32+00:00", "tests_total": 108, "tests_dropped": 7, "flags": [], "topic_tags": ["math", "binary-search", "number-theory", "least-common-multiple", "inclusion-exclusion-principle"]}, "language": "php", "interface": {"raw_signature": "function minimizeSet($divisor1, $divisor2, $uniqueCnt1, $uniqueCnt2) {", "container": "Solution", "callable": "minimizeSet", "parameters": [{"name": "divisor1", "type": "Integer"}, {"name": "divisor2", "type": "Integer"}, {"name": "uniqueCnt1", "type": "Integer"}, {"name": "uniqueCnt2", "type": "Integer"}], "return_type": "Integer", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}}